The following commit has been merged in the merge/master branch: commit 9ab5287fbffe88a2f6bd88c7a3421c60d4945e2b Merge: 82d8951950705a640dc80ba81e7499b2c8cf37bf a03748760887f866252363b8029d65770927f45c Author: Marek Lindner lindner_marek@yahoo.de Date: Mon Feb 13 16:47:16 2012 +0800
Merge remote-tracking branch 'origin/standalone/next' into merge/master
Conflicts: net/batman-adv/CHANGELOG net/batman-adv/Makefile net/batman-adv/Makefile.kbuild net/batman-adv/README net/batman-adv/compat.c net/batman-adv/compat.h net/batman-adv/sysfs-class-net-mesh
diff --combined Documentation/ABI/testing/sysfs-class-net-mesh index b020014,b218e0f..b218e0f --- a/Documentation/ABI/testing/sysfs-class-net-mesh +++ b/Documentation/ABI/testing/sysfs-class-net-mesh @@@ -65,6 -65,13 +65,13 @@@ Description Defines the penalty which will be applied to an originator message's tq-field on every hop.
+ What: /sys/class/net/<mesh_iface>/mesh/routing_algo + Date: Dec 2011 + Contact: Marek Lindner lindner_marek@yahoo.de + Description: + Defines the routing procotol this mesh instance + uses to find the optimal paths through the mesh. + What: /sys/class/net/<mesh_iface>/mesh/vis_mode Date: May 2010 Contact: Marek Lindner lindner_marek@yahoo.de diff --combined Documentation/networking/batman-adv.txt index fe18d50,01db663..01db663 --- a/Documentation/networking/batman-adv.txt +++ b/Documentation/networking/batman-adv.txt @@@ -1,5 -1,3 +1,3 @@@ - [state: 13-11-2011] - BATMAN-ADV ----------
@@@ -72,6 -70,7 +70,7 @@@ folder # ap_isolation gw_bandwidth hop_penalty # bonding gw_mode orig_interval
+ There is a special folder for debugging information:
# ls /sys/kernel/debug/batman_adv/bat0/ diff --combined net/batman-adv/Makefile index ce68611,4e392eb..4e392eb --- a/net/batman-adv/Makefile +++ b/net/batman-adv/Makefile @@@ -1,5 -1,5 +1,5 @@@ # - # Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + # Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: # # Marek Lindner, Simon Wunderlich # diff --combined net/batman-adv/bat_algo.h index 7cdfe62,9852a68..9852a68 --- a/net/batman-adv/bat_algo.h +++ b/net/batman-adv/bat_algo.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2011-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * @@@ -19,10 -19,9 +19,9 @@@ * */
- #ifndef _NET_BATMAN_ADV_RING_BUFFER_H_ - #define _NET_BATMAN_ADV_RING_BUFFER_H_ + #ifndef _NET_BATMAN_ADV_BAT_ALGO_H_ + #define _NET_BATMAN_ADV_BAT_ALGO_H_
- void ring_buffer_set(uint8_t lq_recv[], uint8_t *lq_index, uint8_t value); - uint8_t ring_buffer_avg(const uint8_t lq_recv[]); + int bat_iv_init(void);
- #endif /* _NET_BATMAN_ADV_RING_BUFFER_H_ */ + #endif /* _NET_BATMAN_ADV_BAT_ALGO_H_ */ diff --combined net/batman-adv/bat_debugfs.c index d0af9bf,c3b0548..c3b0548 --- a/net/batman-adv/bat_debugfs.c +++ b/net/batman-adv/bat_debugfs.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2010-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2010-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * @@@ -221,6 -221,11 +221,11 @@@ static void debug_log_cleanup(struct ba } #endif
+ static int bat_algorithms_open(struct inode *inode, struct file *file) + { + return single_open(file, bat_algo_seq_print_text, NULL); + } + static int originators_open(struct inode *inode, struct file *file) { struct net_device *net_dev = (struct net_device *)inode->i_private; @@@ -274,6 -279,7 +279,7 @@@ struct bat_debuginfo bat_debuginfo_##_n } \ };
+ static BAT_DEBUGINFO(routing_algos, S_IRUGO, bat_algorithms_open); static BAT_DEBUGINFO(originators, S_IRUGO, originators_open); static BAT_DEBUGINFO(gateways, S_IRUGO, gateways_open); static BAT_DEBUGINFO(softif_neigh, S_IRUGO, softif_neigh_open); @@@ -293,9 -299,25 +299,25 @@@ static struct bat_debuginfo *mesh_debug
void debugfs_init(void) { + struct bat_debuginfo *bat_debug; + struct dentry *file; + bat_debugfs = debugfs_create_dir(DEBUGFS_BAT_SUBDIR, NULL); if (bat_debugfs == ERR_PTR(-ENODEV)) bat_debugfs = NULL; + + if (!bat_debugfs) + goto out; + + bat_debug = &bat_debuginfo_routing_algos; + file = debugfs_create_file(bat_debug->attr.name, + S_IFREG | bat_debug->attr.mode, + bat_debugfs, NULL, &bat_debug->fops); + if (!file) + pr_err("Can't add debugfs file: %s\n", bat_debug->attr.name); + + out: + return; }
void debugfs_destroy(void) diff --combined net/batman-adv/bat_debugfs.h index bc9cda3,d605c67..d605c67 --- a/net/batman-adv/bat_debugfs.h +++ b/net/batman-adv/bat_debugfs.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2010-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2010-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * diff --combined net/batman-adv/bat_iv_ogm.c index 3512e25,2b66dae..2b66dae --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * @@@ -20,7 -20,6 +20,6 @@@ */
#include "main.h" - #include "bat_ogm.h" #include "translation-table.h" #include "ring_buffer.h" #include "originator.h" @@@ -29,8 -28,9 +28,9 @@@ #include "gateway_client.h" #include "hard-interface.h" #include "send.h" + #include "bat_algo.h"
- void bat_ogm_init(struct hard_iface *hard_iface) + static void bat_iv_ogm_init(struct hard_iface *hard_iface) { struct batman_ogm_packet *batman_ogm_packet;
@@@ -38,25 -38,25 +38,25 @@@ hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; - batman_ogm_packet->packet_type = BAT_OGM; - batman_ogm_packet->version = COMPAT_VERSION; + batman_ogm_packet->header.packet_type = BAT_OGM; + batman_ogm_packet->header.version = COMPAT_VERSION; + batman_ogm_packet->header.ttl = 2; batman_ogm_packet->flags = NO_FLAGS; - batman_ogm_packet->ttl = 2; batman_ogm_packet->tq = TQ_MAX_VALUE; batman_ogm_packet->tt_num_changes = 0; batman_ogm_packet->ttvn = 0; }
- void bat_ogm_init_primary(struct hard_iface *hard_iface) + static void bat_iv_ogm_init_primary(struct hard_iface *hard_iface) { struct batman_ogm_packet *batman_ogm_packet;
batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; batman_ogm_packet->flags = PRIMARIES_FIRST_HOP; - batman_ogm_packet->ttl = TTL; + batman_ogm_packet->header.ttl = TTL; }
- void bat_ogm_update_mac(struct hard_iface *hard_iface) + static void bat_iv_ogm_update_mac(struct hard_iface *hard_iface) { struct batman_ogm_packet *batman_ogm_packet;
@@@ -68,7 -68,7 +68,7 @@@ }
/* when do we schedule our own ogm to be sent */ - static unsigned long bat_ogm_emit_send_time(const struct bat_priv *bat_priv) + static unsigned long bat_iv_ogm_emit_send_time(const struct bat_priv *bat_priv) { return jiffies + msecs_to_jiffies( atomic_read(&bat_priv->orig_interval) - @@@ -76,7 -76,7 +76,7 @@@ }
/* when do we schedule a ogm packet to be sent */ - static unsigned long bat_ogm_fwd_send_time(void) + static unsigned long bat_iv_ogm_fwd_send_time(void) { return jiffies + msecs_to_jiffies(random32() % (JITTER/2)); } @@@ -89,8 -89,8 +89,8 @@@ static uint8_t hop_penalty(uint8_t tq, }
/* is there another aggregated packet here? */ - static int bat_ogm_aggr_packet(int buff_pos, int packet_len, - int tt_num_changes) + static int bat_iv_ogm_aggr_packet(int buff_pos, int packet_len, + int tt_num_changes) { int next_buff_pos = buff_pos + BATMAN_OGM_LEN + tt_len(tt_num_changes);
@@@ -99,8 -99,8 +99,8 @@@ }
/* send a batman ogm to a given interface */ - static void bat_ogm_send_to_if(struct forw_packet *forw_packet, - struct hard_iface *hard_iface) + static void bat_iv_ogm_send_to_if(struct forw_packet *forw_packet, + struct hard_iface *hard_iface) { struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); char *fwd_str; @@@ -117,8 -117,8 +117,8 @@@ batman_ogm_packet = (struct batman_ogm_packet *)forw_packet->skb->data;
/* adjust all flags and log packets */ - while (bat_ogm_aggr_packet(buff_pos, forw_packet->packet_len, - batman_ogm_packet->tt_num_changes)) { + while (bat_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len, + batman_ogm_packet->tt_num_changes)) {
/* we might have aggregated direct link packets with an * ordinary base packet */ @@@ -137,7 -137,7 +137,7 @@@ fwd_str, (packet_num > 0 ? "aggregated " : ""), batman_ogm_packet->orig, ntohl(batman_ogm_packet->seqno), - batman_ogm_packet->tq, batman_ogm_packet->ttl, + batman_ogm_packet->tq, batman_ogm_packet->header.ttl, (batman_ogm_packet->flags & DIRECTLINK ? "on" : "off"), batman_ogm_packet->ttvn, hard_iface->net_dev->name, @@@ -157,7 -157,7 +157,7 @@@ }
/* send a batman ogm packet */ - void bat_ogm_emit(struct forw_packet *forw_packet) + static void bat_iv_ogm_emit(struct forw_packet *forw_packet) { struct hard_iface *hard_iface; struct net_device *soft_iface; @@@ -188,7 -188,7 +188,7 @@@
/* multihomed peer assumed */ /* non-primary OGMs are only broadcasted on their interface */ - if ((directlink && (batman_ogm_packet->ttl == 1)) || + if ((directlink && (batman_ogm_packet->header.ttl == 1)) || (forw_packet->own && (forw_packet->if_incoming != primary_if))) {
/* FIXME: what about aggregated packets ? */ @@@ -198,7 -198,7 +198,7 @@@ (forw_packet->own ? "Sending own" : "Forwarding"), batman_ogm_packet->orig, ntohl(batman_ogm_packet->seqno), - batman_ogm_packet->ttl, + batman_ogm_packet->header.ttl, forw_packet->if_incoming->net_dev->name, forw_packet->if_incoming->net_dev->dev_addr);
@@@ -216,7 -216,7 +216,7 @@@ if (hard_iface->soft_iface != soft_iface) continue;
- bat_ogm_send_to_if(forw_packet, hard_iface); + bat_iv_ogm_send_to_if(forw_packet, hard_iface); } rcu_read_unlock();
@@@ -226,13 -226,13 +226,13 @@@ out }
/* return true if new_packet can be aggregated with forw_packet */ - static bool bat_ogm_can_aggregate(const struct batman_ogm_packet + static bool bat_iv_ogm_can_aggregate(const struct batman_ogm_packet *new_batman_ogm_packet, - struct bat_priv *bat_priv, - int packet_len, unsigned long send_time, - bool directlink, - const struct hard_iface *if_incoming, - const struct forw_packet *forw_packet) + struct bat_priv *bat_priv, + int packet_len, unsigned long send_time, + bool directlink, + const struct hard_iface *if_incoming, + const struct forw_packet *forw_packet) { struct batman_ogm_packet *batman_ogm_packet; int aggregated_bytes = forw_packet->packet_len + packet_len; @@@ -272,7 -272,7 +272,7 @@@ * are flooded through the net */ if ((!directlink) && (!(batman_ogm_packet->flags & DIRECTLINK)) && - (batman_ogm_packet->ttl != 1) && + (batman_ogm_packet->header.ttl != 1) &&
/* own packets originating non-primary * interfaces leave only that interface */ @@@ -285,7 -285,7 +285,7 @@@ /* if the incoming packet is sent via this one * interface only - we still can aggregate */ if ((directlink) && - (new_batman_ogm_packet->ttl == 1) && + (new_batman_ogm_packet->header.ttl == 1) && (forw_packet->if_incoming == if_incoming) &&
/* packets from direct neighbors or @@@ -306,11 -306,11 +306,11 @@@ out }
/* create a new aggregated packet and add this packet to it */ - static void bat_ogm_aggregate_new(const unsigned char *packet_buff, - int packet_len, unsigned long send_time, - bool direct_link, - struct hard_iface *if_incoming, - int own_packet) + static void bat_iv_ogm_aggregate_new(const unsigned char *packet_buff, + int packet_len, unsigned long send_time, + bool direct_link, + struct hard_iface *if_incoming, + int own_packet) { struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); struct forw_packet *forw_packet_aggr; @@@ -385,9 -385,9 +385,9 @@@ out }
/* aggregate a new packet into the existing ogm packet */ - static void bat_ogm_aggregate(struct forw_packet *forw_packet_aggr, - const unsigned char *packet_buff, - int packet_len, bool direct_link) + static void bat_iv_ogm_aggregate(struct forw_packet *forw_packet_aggr, + const unsigned char *packet_buff, + int packet_len, bool direct_link) { unsigned char *skb_buff;
@@@ -402,10 -402,10 +402,10 @@@ (1 << forw_packet_aggr->num_packets); }
- static void bat_ogm_queue_add(struct bat_priv *bat_priv, - unsigned char *packet_buff, - int packet_len, struct hard_iface *if_incoming, - int own_packet, unsigned long send_time) + static void bat_iv_ogm_queue_add(struct bat_priv *bat_priv, + unsigned char *packet_buff, + int packet_len, struct hard_iface *if_incoming, + int own_packet, unsigned long send_time) { /** * _aggr -> pointer to the packet we want to aggregate with @@@ -425,11 -425,11 +425,11 @@@ if ((atomic_read(&bat_priv->aggregated_ogms)) && (!own_packet)) { hlist_for_each_entry(forw_packet_pos, tmp_node, &bat_priv->forw_bat_list, list) { - if (bat_ogm_can_aggregate(batman_ogm_packet, - bat_priv, packet_len, - send_time, direct_link, - if_incoming, - forw_packet_pos)) { + if (bat_iv_ogm_can_aggregate(batman_ogm_packet, + bat_priv, packet_len, + send_time, direct_link, + if_incoming, + forw_packet_pos)) { forw_packet_aggr = forw_packet_pos; break; } @@@ -451,27 -451,27 +451,27 @@@ (atomic_read(&bat_priv->aggregated_ogms))) send_time += msecs_to_jiffies(MAX_AGGREGATION_MS);
- bat_ogm_aggregate_new(packet_buff, packet_len, - send_time, direct_link, - if_incoming, own_packet); + bat_iv_ogm_aggregate_new(packet_buff, packet_len, + send_time, direct_link, + if_incoming, own_packet); } else { - bat_ogm_aggregate(forw_packet_aggr, packet_buff, packet_len, - direct_link); + bat_iv_ogm_aggregate(forw_packet_aggr, packet_buff, + packet_len, direct_link); spin_unlock_bh(&bat_priv->forw_bat_list_lock); } }
- static void bat_ogm_forward(struct orig_node *orig_node, - const struct ethhdr *ethhdr, - struct batman_ogm_packet *batman_ogm_packet, - int directlink, struct hard_iface *if_incoming) + static void bat_iv_ogm_forward(struct orig_node *orig_node, + const struct ethhdr *ethhdr, + struct batman_ogm_packet *batman_ogm_packet, + int directlink, struct hard_iface *if_incoming) { struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); struct neigh_node *router; uint8_t in_tq, in_ttl, tq_avg = 0; uint8_t tt_num_changes;
- if (batman_ogm_packet->ttl <= 1) { + if (batman_ogm_packet->header.ttl <= 1) { bat_dbg(DBG_BATMAN, bat_priv, "ttl exceeded\n"); return; } @@@ -479,10 -479,10 +479,10 @@@ router = orig_node_get_router(orig_node);
in_tq = batman_ogm_packet->tq; - in_ttl = batman_ogm_packet->ttl; + in_ttl = batman_ogm_packet->header.ttl; tt_num_changes = batman_ogm_packet->tt_num_changes;
- batman_ogm_packet->ttl--; + batman_ogm_packet->header.ttl--; memcpy(batman_ogm_packet->prev_sender, ethhdr->h_source, ETH_ALEN);
/* rebroadcast tq of our best ranking neighbor to ensure the rebroadcast @@@ -494,7 -494,8 +494,8 @@@ batman_ogm_packet->tq = router->tq_avg;
if (router->last_ttl) - batman_ogm_packet->ttl = router->last_ttl - 1; + batman_ogm_packet->header.ttl = + router->last_ttl - 1; }
tq_avg = router->tq_avg; @@@ -510,7 -511,7 +511,7 @@@ "Forwarding packet: tq_orig: %i, tq_avg: %i, " "tq_forw: %i, ttl_orig: %i, ttl_forw: %i\n", in_tq, tq_avg, batman_ogm_packet->tq, in_ttl - 1, - batman_ogm_packet->ttl); + batman_ogm_packet->header.ttl);
batman_ogm_packet->seqno = htonl(batman_ogm_packet->seqno); batman_ogm_packet->tt_crc = htons(batman_ogm_packet->tt_crc); @@@ -522,12 -523,13 +523,13 @@@ else batman_ogm_packet->flags &= ~DIRECTLINK;
- bat_ogm_queue_add(bat_priv, (unsigned char *)batman_ogm_packet, - BATMAN_OGM_LEN + tt_len(tt_num_changes), - if_incoming, 0, bat_ogm_fwd_send_time()); + bat_iv_ogm_queue_add(bat_priv, (unsigned char *)batman_ogm_packet, + BATMAN_OGM_LEN + tt_len(tt_num_changes), + if_incoming, 0, bat_iv_ogm_fwd_send_time()); }
- void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes) + static void bat_iv_ogm_schedule(struct hard_iface *hard_iface, + int tt_num_changes) { struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); struct batman_ogm_packet *batman_ogm_packet; @@@ -564,21 -566,22 +566,22 @@@ atomic_inc(&hard_iface->seqno);
slide_own_bcast_window(hard_iface); - bat_ogm_queue_add(bat_priv, hard_iface->packet_buff, - hard_iface->packet_len, hard_iface, 1, - bat_ogm_emit_send_time(bat_priv)); + bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff, + hard_iface->packet_len, hard_iface, 1, + bat_iv_ogm_emit_send_time(bat_priv));
if (primary_if) hardif_free_ref(primary_if); }
- static void bat_ogm_orig_update(struct bat_priv *bat_priv, - struct orig_node *orig_node, - const struct ethhdr *ethhdr, - const struct batman_ogm_packet + static void bat_iv_ogm_orig_update(struct bat_priv *bat_priv, + struct orig_node *orig_node, + const struct ethhdr *ethhdr, + const struct batman_ogm_packet *batman_ogm_packet, - struct hard_iface *if_incoming, - const unsigned char *tt_buff, int is_duplicate) + struct hard_iface *if_incoming, + const unsigned char *tt_buff, + int is_duplicate) { struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL; struct neigh_node *router = NULL; @@@ -642,8 -645,8 +645,8 @@@ spin_unlock_bh(&neigh_node->tq_lock);
if (!is_duplicate) { - orig_node->last_ttl = batman_ogm_packet->ttl; - neigh_node->last_ttl = batman_ogm_packet->ttl; + orig_node->last_ttl = batman_ogm_packet->header.ttl; + neigh_node->last_ttl = batman_ogm_packet->header.ttl; }
bonding_candidate_add(orig_node, neigh_node); @@@ -683,7 -686,7 +686,7 @@@ update_tt /* I have to check for transtable changes only if the OGM has been * sent through a primary interface */ if (((batman_ogm_packet->orig != ethhdr->h_source) && - (batman_ogm_packet->ttl > 2)) || + (batman_ogm_packet->header.ttl > 2)) || (batman_ogm_packet->flags & PRIMARIES_FIRST_HOP)) tt_update_orig(bat_priv, orig_node, tt_buff, batman_ogm_packet->tt_num_changes, @@@ -713,10 -716,10 +716,10 @@@ out neigh_node_free_ref(router); }
- static int bat_ogm_calc_tq(struct orig_node *orig_node, - struct orig_node *orig_neigh_node, - struct batman_ogm_packet *batman_ogm_packet, - struct hard_iface *if_incoming) + static int bat_iv_ogm_calc_tq(struct orig_node *orig_node, + struct orig_node *orig_neigh_node, + struct batman_ogm_packet *batman_ogm_packet, + struct hard_iface *if_incoming) { struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); struct neigh_node *neigh_node = NULL, *tmp_neigh_node; @@@ -825,10 -828,10 +828,10 @@@ out * -1 the packet is old and has been received while the seqno window * was protected. Caller should drop it. */ - static int bat_ogm_update_seqnos(const struct ethhdr *ethhdr, - const struct batman_ogm_packet + static int bat_iv_ogm_update_seqnos(const struct ethhdr *ethhdr, + const struct batman_ogm_packet *batman_ogm_packet, - const struct hard_iface *if_incoming) + const struct hard_iface *if_incoming) { struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); struct orig_node *orig_node; @@@ -890,10 -893,10 +893,10 @@@ out return ret; }
- static void bat_ogm_process(const struct ethhdr *ethhdr, - struct batman_ogm_packet *batman_ogm_packet, - const unsigned char *tt_buff, - struct hard_iface *if_incoming) + static void bat_iv_ogm_process(const struct ethhdr *ethhdr, + struct batman_ogm_packet *batman_ogm_packet, + const unsigned char *tt_buff, + struct hard_iface *if_incoming) { struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); struct hard_iface *hard_iface; @@@ -918,7 -921,7 +921,7 @@@ * packet in an aggregation. Here we expect that the padding * is always zero (or not 0x01) */ - if (batman_ogm_packet->packet_type != BAT_OGM) + if (batman_ogm_packet->header.packet_type != BAT_OGM) return;
/* could be changed by schedule_own_packet() */ @@@ -938,8 -941,8 +941,8 @@@ batman_ogm_packet->prev_sender, batman_ogm_packet->seqno, batman_ogm_packet->ttvn, batman_ogm_packet->tt_crc, batman_ogm_packet->tt_num_changes, batman_ogm_packet->tq, - batman_ogm_packet->ttl, batman_ogm_packet->version, - has_directlink_flag); + batman_ogm_packet->header.ttl, + batman_ogm_packet->header.version, has_directlink_flag);
rcu_read_lock(); list_for_each_entry_rcu(hard_iface, &hardif_list, list) { @@@ -966,10 -969,10 +969,10 @@@ } rcu_read_unlock();
- if (batman_ogm_packet->version != COMPAT_VERSION) { + if (batman_ogm_packet->header.version != COMPAT_VERSION) { bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: incompatible batman version (%i)\n", - batman_ogm_packet->version); + batman_ogm_packet->header.version); return; }
@@@ -1031,8 -1034,8 +1034,8 @@@ if (!orig_node) return;
- is_duplicate = bat_ogm_update_seqnos(ethhdr, batman_ogm_packet, - if_incoming); + is_duplicate = bat_iv_ogm_update_seqnos(ethhdr, batman_ogm_packet, + if_incoming);
if (is_duplicate == -1) { bat_dbg(DBG_BATMAN, bat_priv, @@@ -1081,8 -1084,8 +1084,8 @@@ goto out_neigh; }
- is_bidirectional = bat_ogm_calc_tq(orig_node, orig_neigh_node, - batman_ogm_packet, if_incoming); + is_bidirectional = bat_iv_ogm_calc_tq(orig_node, orig_neigh_node, + batman_ogm_packet, if_incoming);
bonding_save_primary(orig_node, orig_neigh_node, batman_ogm_packet);
@@@ -1091,17 -1094,17 +1094,17 @@@ if (is_bidirectional && (!is_duplicate || ((orig_node->last_real_seqno == batman_ogm_packet->seqno) && - (orig_node->last_ttl - 3 <= batman_ogm_packet->ttl)))) - bat_ogm_orig_update(bat_priv, orig_node, ethhdr, - batman_ogm_packet, if_incoming, - tt_buff, is_duplicate); + (orig_node->last_ttl - 3 <= batman_ogm_packet->header.ttl)))) + bat_iv_ogm_orig_update(bat_priv, orig_node, ethhdr, + batman_ogm_packet, if_incoming, + tt_buff, is_duplicate);
/* is single hop (direct) neighbor */ if (is_single_hop_neigh) {
/* mark direct link on incoming interface */ - bat_ogm_forward(orig_node, ethhdr, batman_ogm_packet, - 1, if_incoming); + bat_iv_ogm_forward(orig_node, ethhdr, batman_ogm_packet, + 1, if_incoming);
bat_dbg(DBG_BATMAN, bat_priv, "Forwarding packet: " "rebroadcast neighbor packet with direct link flag\n"); @@@ -1123,7 -1126,8 +1126,8 @@@
bat_dbg(DBG_BATMAN, bat_priv, "Forwarding packet: rebroadcast originator packet\n"); - bat_ogm_forward(orig_node, ethhdr, batman_ogm_packet, 0, if_incoming); + bat_iv_ogm_forward(orig_node, ethhdr, batman_ogm_packet, + 0, if_incoming);
out_neigh: if ((orig_neigh_node) && (!is_single_hop_neigh)) @@@ -1139,13 -1143,17 +1143,17 @@@ out orig_node_free_ref(orig_node); }
- void bat_ogm_receive(const struct ethhdr *ethhdr, unsigned char *packet_buff, - int packet_len, struct hard_iface *if_incoming) + static void bat_iv_ogm_receive(struct hard_iface *if_incoming, + struct sk_buff *skb) { struct batman_ogm_packet *batman_ogm_packet; - int buff_pos = 0; - unsigned char *tt_buff; + struct ethhdr *ethhdr; + int buff_pos = 0, packet_len; + unsigned char *tt_buff, *packet_buff;
+ packet_len = skb_headlen(skb); + ethhdr = (struct ethhdr *)skb_mac_header(skb); + packet_buff = skb->data; batman_ogm_packet = (struct batman_ogm_packet *)packet_buff;
/* unpack the aggregated packets and process them one by one */ @@@ -1157,14 -1165,29 +1165,29 @@@
tt_buff = packet_buff + buff_pos + BATMAN_OGM_LEN;
- bat_ogm_process(ethhdr, batman_ogm_packet, - tt_buff, if_incoming); + bat_iv_ogm_process(ethhdr, batman_ogm_packet, + tt_buff, if_incoming);
buff_pos += BATMAN_OGM_LEN + tt_len(batman_ogm_packet->tt_num_changes);
batman_ogm_packet = (struct batman_ogm_packet *) (packet_buff + buff_pos); - } while (bat_ogm_aggr_packet(buff_pos, packet_len, - batman_ogm_packet->tt_num_changes)); + } while (bat_iv_ogm_aggr_packet(buff_pos, packet_len, + batman_ogm_packet->tt_num_changes)); + } + + static struct bat_algo_ops batman_iv __read_mostly = { + .name = "BATMAN IV", + .bat_ogm_init = bat_iv_ogm_init, + .bat_ogm_init_primary = bat_iv_ogm_init_primary, + .bat_ogm_update_mac = bat_iv_ogm_update_mac, + .bat_ogm_schedule = bat_iv_ogm_schedule, + .bat_ogm_emit = bat_iv_ogm_emit, + .bat_ogm_receive = bat_iv_ogm_receive, + }; + + int __init bat_iv_init(void) + { + return bat_algo_register(&batman_iv); } diff --combined net/batman-adv/bat_sysfs.c index c25492f,7317729..7317729 --- a/net/batman-adv/bat_sysfs.c +++ b/net/batman-adv/bat_sysfs.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2010-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2010-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * @@@ -272,6 -272,13 +272,13 @@@ static ssize_t store_vis_mode(struct ko return count; }
+ static ssize_t show_bat_algo(struct kobject *kobj, struct attribute *attr, + char *buff) + { + struct bat_priv *bat_priv = kobj_to_batpriv(kobj); + return sprintf(buff, "%s\n", bat_priv->bat_algo_ops->name); + } + static void post_gw_deselect(struct net_device *net_dev) { struct bat_priv *bat_priv = netdev_priv(net_dev); @@@ -382,6 -389,7 +389,7 @@@ BAT_ATTR_BOOL(bonding, S_IRUGO | S_IWUS BAT_ATTR_BOOL(fragmentation, S_IRUGO | S_IWUSR, update_min_mtu); BAT_ATTR_BOOL(ap_isolation, S_IRUGO | S_IWUSR, NULL); static BAT_ATTR(vis_mode, S_IRUGO | S_IWUSR, show_vis_mode, store_vis_mode); + static BAT_ATTR(routing_algo, S_IRUGO, show_bat_algo, NULL); static BAT_ATTR(gw_mode, S_IRUGO | S_IWUSR, show_gw_mode, store_gw_mode); BAT_ATTR_UINT(orig_interval, S_IRUGO | S_IWUSR, 2 * JITTER, INT_MAX, NULL); BAT_ATTR_UINT(hop_penalty, S_IRUGO | S_IWUSR, 0, TQ_MAX_VALUE, NULL); @@@ -399,6 -407,7 +407,7 @@@ static struct bat_attribute *mesh_attrs &bat_attr_fragmentation, &bat_attr_ap_isolation, &bat_attr_vis_mode, + &bat_attr_routing_algo, &bat_attr_gw_mode, &bat_attr_orig_interval, &bat_attr_hop_penalty, diff --combined net/batman-adv/bat_sysfs.h index a3f75a7,fece77a..fece77a --- a/net/batman-adv/bat_sysfs.h +++ b/net/batman-adv/bat_sysfs.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2010-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2010-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * diff --combined net/batman-adv/bitarray.c index 9bc63b2,e63069d..e63069d --- a/net/batman-adv/bitarray.c +++ b/net/batman-adv/bitarray.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2006-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2006-2012 B.A.T.M.A.N. contributors: * * Simon Wunderlich, Marek Lindner * diff --combined net/batman-adv/bitarray.h index 9c04422,c613572..c613572 --- a/net/batman-adv/bitarray.h +++ b/net/batman-adv/bitarray.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2006-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2006-2012 B.A.T.M.A.N. contributors: * * Simon Wunderlich, Marek Lindner * diff --combined net/batman-adv/gateway_client.c index 24403a7,65a77a1..65a77a1 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2009-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2009-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * @@@ -396,7 -396,7 +396,7 @@@ void gw_node_purge(struct bat_priv *bat { struct gw_node *gw_node, *curr_gw; struct hlist_node *node, *node_tmp; - unsigned long timeout = 2 * PURGE_TIMEOUT * HZ; + unsigned long timeout = msecs_to_jiffies(2 * PURGE_TIMEOUT); int do_deselect = 0;
curr_gw = gw_get_selected_gw_node(bat_priv); diff --combined net/batman-adv/gateway_client.h index e1edba0,bf56a5a..bf56a5a --- a/net/batman-adv/gateway_client.h +++ b/net/batman-adv/gateway_client.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2009-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2009-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * diff --combined net/batman-adv/gateway_common.c index c4ac7b0,7f79e15..7f79e15 --- a/net/batman-adv/gateway_common.c +++ b/net/batman-adv/gateway_common.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2009-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2009-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * diff --combined net/batman-adv/gateway_common.h index 55e527a,b8fb11c..b8fb11c --- a/net/batman-adv/gateway_common.h +++ b/net/batman-adv/gateway_common.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2009-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2009-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * diff --combined net/batman-adv/hard-interface.c index 7704df4,41826b9..41826b9 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * @@@ -28,7 -28,6 +28,6 @@@ #include "bat_sysfs.h" #include "originator.h" #include "hash.h" - #include "bat_ogm.h"
#include <linux/if_arp.h>
@@@ -147,7 -146,7 +146,7 @@@ static void primary_if_select(struct ba if (!new_hard_iface) return;
- bat_ogm_init_primary(new_hard_iface); + bat_priv->bat_algo_ops->bat_ogm_init_primary(new_hard_iface); primary_if_update_addr(bat_priv); }
@@@ -233,7 -232,7 +232,7 @@@ static void hardif_activate_interface(s
bat_priv = netdev_priv(hard_iface->soft_iface);
- bat_ogm_update_mac(hard_iface); + bat_priv->bat_algo_ops->bat_ogm_update_mac(hard_iface); hard_iface->if_status = IF_TO_BE_ACTIVATED;
/** @@@ -281,6 -280,14 +280,14 @@@ int hardif_enable_interface(struct hard if (!atomic_inc_not_zero(&hard_iface->refcount)) goto out;
+ /* hard-interface is part of a bridge */ + if (hard_iface->net_dev->priv_flags & IFF_BRIDGE_PORT) + pr_err("You are about to enable batman-adv on '%s' which " + "already is part of a bridge. Unless you know exactly " + "what you are doing this is probably wrong and won't " + "work the way you think it would.\n", + hard_iface->net_dev->name); + soft_iface = dev_get_by_name(&init_net, iface_name);
if (!soft_iface) { @@@ -307,7 -314,7 +314,7 @@@ hard_iface->soft_iface = soft_iface; bat_priv = netdev_priv(hard_iface->soft_iface);
- bat_ogm_init(hard_iface); + bat_priv->bat_algo_ops->bat_ogm_init(hard_iface);
if (!hard_iface->packet_buff) { bat_err(hard_iface->soft_iface, "Can't add interface packet " @@@ -527,9 -534,10 +534,10 @@@ static int hard_if_event(struct notifie goto hardif_put;
check_known_mac_addr(hard_iface->net_dev); - bat_ogm_update_mac(hard_iface);
bat_priv = netdev_priv(hard_iface->soft_iface); + bat_priv->bat_algo_ops->bat_ogm_update_mac(hard_iface); + primary_if = primary_if_get_selected(bat_priv); if (!primary_if) goto hardif_put; @@@ -590,17 -598,17 +598,17 @@@ static int batman_skb_recv(struct sk_bu
batman_ogm_packet = (struct batman_ogm_packet *)skb->data;
- if (batman_ogm_packet->version != COMPAT_VERSION) { + if (batman_ogm_packet->header.version != COMPAT_VERSION) { bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: incompatible batman version (%i)\n", - batman_ogm_packet->version); + batman_ogm_packet->header.version); goto err_free; }
/* all receive handlers return whether they received or reused * the supplied skb. if not, we have to free the skb. */
- switch (batman_ogm_packet->packet_type) { + switch (batman_ogm_packet->header.packet_type) { /* batman originator packet */ case BAT_OGM: ret = recv_bat_ogm_packet(skb, hard_iface); diff --combined net/batman-adv/hard-interface.h index 67f78d1,e68c565..e68c565 --- a/net/batman-adv/hard-interface.h +++ b/net/batman-adv/hard-interface.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * diff --combined net/batman-adv/hash.c index d1da29d,117687b..117687b --- a/net/batman-adv/hash.c +++ b/net/batman-adv/hash.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2006-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2006-2012 B.A.T.M.A.N. contributors: * * Simon Wunderlich, Marek Lindner * diff --combined net/batman-adv/hash.h index 4768717,d4bd786..d4bd786 --- a/net/batman-adv/hash.h +++ b/net/batman-adv/hash.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2006-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2006-2012 B.A.T.M.A.N. contributors: * * Simon Wunderlich, Marek Lindner * diff --combined net/batman-adv/icmp_socket.c index d9c1e7b,9b755f9..9b755f9 --- a/net/batman-adv/icmp_socket.c +++ b/net/batman-adv/icmp_socket.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * @@@ -191,7 -191,7 +191,7 @@@ static ssize_t bat_socket_write(struct goto free_skb; }
- if (icmp_packet->packet_type != BAT_ICMP) { + if (icmp_packet->header.packet_type != BAT_ICMP) { bat_dbg(DBG_BATMAN, bat_priv, "Error - can't send packet from char device: " "got bogus packet type (expected: BAT_ICMP)\n"); @@@ -209,9 -209,9 +209,9 @@@
icmp_packet->uid = socket_client->index;
- if (icmp_packet->version != COMPAT_VERSION) { + if (icmp_packet->header.version != COMPAT_VERSION) { icmp_packet->msg_type = PARAMETER_PROBLEM; - icmp_packet->version = COMPAT_VERSION; + icmp_packet->header.version = COMPAT_VERSION; bat_socket_add_packet(socket_client, icmp_packet, packet_len); goto free_skb; } diff --combined net/batman-adv/icmp_socket.h index 462b190,380ed4c..380ed4c --- a/net/batman-adv/icmp_socket.h +++ b/net/batman-adv/icmp_socket.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * diff --combined net/batman-adv/main.c index fb87bdc,08f3b3a..08f3b3a --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * @@@ -32,11 -32,14 +32,14 @@@ #include "gateway_client.h" #include "vis.h" #include "hash.h" + #include "bat_algo.h"
/* List manipulations on hardif_list have to be rtnl_lock()'ed, * list traversals just rcu-locked */ struct list_head hardif_list; + char bat_routing_algo[20] = "BATMAN IV"; + static struct hlist_head bat_algo_list;
unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
@@@ -45,6 -48,9 +48,9 @@@ struct workqueue_struct *bat_event_work static int __init batman_init(void) { INIT_LIST_HEAD(&hardif_list); + INIT_HLIST_HEAD(&bat_algo_list); + + bat_iv_init();
/* the name should not be longer than 10 chars - see * http://lwn.net/Articles/23634/ */ @@@ -170,9 -176,110 +176,110 @@@ int is_my_mac(const uint8_t *addr } rcu_read_unlock(); return 0; + } + + static struct bat_algo_ops *bat_algo_get(char *name) + { + struct bat_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp; + struct hlist_node *node; + + hlist_for_each_entry(bat_algo_ops_tmp, node, &bat_algo_list, list) { + if (strcmp(bat_algo_ops_tmp->name, name) != 0) + continue; + + bat_algo_ops = bat_algo_ops_tmp; + break; + } + + return bat_algo_ops; + } + + int bat_algo_register(struct bat_algo_ops *bat_algo_ops) + { + struct bat_algo_ops *bat_algo_ops_tmp; + int ret = -1; + + bat_algo_ops_tmp = bat_algo_get(bat_algo_ops->name); + if (bat_algo_ops_tmp) { + pr_info("Trying to register already registered routing " + "algorithm: %s\n", bat_algo_ops->name); + goto out; + } + + /* all algorithms must implement all ops (for now) */ + if (!bat_algo_ops->bat_ogm_init || + !bat_algo_ops->bat_ogm_init_primary || + !bat_algo_ops->bat_ogm_update_mac || + !bat_algo_ops->bat_ogm_schedule || + !bat_algo_ops->bat_ogm_emit || + !bat_algo_ops->bat_ogm_receive) { + pr_info("Routing algo '%s' does not implement required ops\n", + bat_algo_ops->name); + goto out; + } + + INIT_HLIST_NODE(&bat_algo_ops->list); + hlist_add_head(&bat_algo_ops->list, &bat_algo_list); + ret = 0; + + out: + return ret; + } + + int bat_algo_select(struct bat_priv *bat_priv, char *name) + { + struct bat_algo_ops *bat_algo_ops; + int ret = -1; + + bat_algo_ops = bat_algo_get(name); + if (!bat_algo_ops) + goto out; + + bat_priv->bat_algo_ops = bat_algo_ops; + ret = 0; + + out: + return ret; + } + + int bat_algo_seq_print_text(struct seq_file *seq, void *offset) + { + struct bat_algo_ops *bat_algo_ops; + struct hlist_node *node; + + seq_printf(seq, "Available routing algorithms:\n"); + + hlist_for_each_entry(bat_algo_ops, node, &bat_algo_list, list) { + seq_printf(seq, "%s\n", bat_algo_ops->name); + } + + return 0; + } + + static int param_set_ra(const char *val, const struct kernel_param *kp) + { + struct bat_algo_ops *bat_algo_ops;
+ bat_algo_ops = bat_algo_get((char *)val); + if (!bat_algo_ops) { + pr_err("Routing algorithm '%s' is not supported\n", val); + return -EINVAL; + } + + return param_set_copystring(val, kp); }
+ static const struct kernel_param_ops param_ops_ra = { + .set = param_set_ra, + .get = param_get_string, + }; + + static struct kparam_string __param_string_ra = { + .maxlen = sizeof(bat_routing_algo), + .string = bat_routing_algo, + }; + + module_param_cb(routing_algo, ¶m_ops_ra, &__param_string_ra, 0644); module_init(batman_init); module_exit(batman_exit);
diff --combined net/batman-adv/main.h index 86354e0,0000000..1468788 mode 100644,000000..100644 --- a/net/batman-adv/main.h +++ b/net/batman-adv/main.h @@@ -1,227 -1,0 +1,243 @@@ +/* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: ++ * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA + * + */ + +#ifndef _NET_BATMAN_ADV_MAIN_H_ +#define _NET_BATMAN_ADV_MAIN_H_ + +#define DRIVER_AUTHOR "Marek Lindner lindner_marek@yahoo.de, " \ + "Simon Wunderlich siwu@hrz.tu-chemnitz.de" +#define DRIVER_DESC "B.A.T.M.A.N. advanced" +#define DRIVER_DEVICE "batman-adv" + +#ifndef SOURCE_VERSION - #define SOURCE_VERSION "2012.0.0" ++#define SOURCE_VERSION "2012.1.0" +#endif + +/* B.A.T.M.A.N. parameters */ + +#define TQ_MAX_VALUE 255 +#define JITTER 20 + + /* Time To Live of broadcast messages */ +#define TTL 50 + +/* purge originators after time in seconds if no valid packet comes in + * -> TODO: check influence on TQ_LOCAL_WINDOW_SIZE */ - #define PURGE_TIMEOUT 200 - #define TT_LOCAL_TIMEOUT 3600 /* in seconds */ - #define TT_CLIENT_ROAM_TIMEOUT 600 ++#define PURGE_TIMEOUT 200000 /* 200 seconds */ ++#define TT_LOCAL_TIMEOUT 3600000 /* in miliseconds */ ++#define TT_CLIENT_ROAM_TIMEOUT 600000 /* in miliseconds */ +/* sliding packet range of received originator messages in sequence numbers + * (should be a multiple of our word size) */ +#define TQ_LOCAL_WINDOW_SIZE 64 - #define TT_REQUEST_TIMEOUT 3 /* seconds we have to keep pending tt_req */ ++#define TT_REQUEST_TIMEOUT 3000 /* miliseconds we have to keep ++ * pending tt_req */ + +#define TQ_GLOBAL_WINDOW_SIZE 5 +#define TQ_LOCAL_BIDRECT_SEND_MINIMUM 1 +#define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1 +#define TQ_TOTAL_BIDRECT_LIMIT 1 + +#define TT_OGM_APPEND_MAX 3 /* number of OGMs sent with the last tt diff */ + - #define ROAMING_MAX_TIME 20 /* Time in which a client can roam at most - * ROAMING_MAX_COUNT times */ ++#define ROAMING_MAX_TIME 20000 /* Time in which a client can roam at most ++ * ROAMING_MAX_COUNT times in miliseconds*/ +#define ROAMING_MAX_COUNT 5 + +#define NO_FLAGS 0 + +#define NULL_IFINDEX 0 /* dummy ifindex used to avoid iface checks */ + +#define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE) + +#define LOG_BUF_LEN 8192 /* has to be a power of 2 */ + +#define VIS_INTERVAL 5000 /* 5 seconds */ + +/* how much worse secondary interfaces may be to be considered as bonding + * candidates */ +#define BONDING_TQ_THRESHOLD 50 + +/* should not be bigger than 512 bytes or change the size of + * forw_packet->direct_link_flags */ +#define MAX_AGGREGATION_BYTES 512 +#define MAX_AGGREGATION_MS 100 + +#define SOFTIF_NEIGH_TIMEOUT 180000 /* 3 minutes */ + +/* don't reset again within 30 seconds */ +#define RESET_PROTECTION_MS 30000 +#define EXPECTED_SEQNO_RANGE 65536 + +enum mesh_state { + MESH_INACTIVE, + MESH_ACTIVE, + MESH_DEACTIVATING +}; + +#define BCAST_QUEUE_LEN 256 +#define BATMAN_QUEUE_LEN 256 + +enum uev_action { + UEV_ADD = 0, + UEV_DEL, + UEV_CHANGE +}; + +enum uev_type { + UEV_GW = 0 +}; + +#define GW_THRESHOLD 50 + +/* + * Debug Messages + */ +#ifdef pr_fmt +#undef pr_fmt +#endif +/* Append 'batman-adv: ' before kernel messages */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +/* all messages related to routing / flooding / broadcasting / etc */ +enum dbg_level { + DBG_BATMAN = 1 << 0, + DBG_ROUTES = 1 << 1, /* route added / changed / deleted */ + DBG_TT = 1 << 2, /* translation table operations */ + DBG_ALL = 7 +}; + + +/* + * Vis + */ + +/* + * Kernel headers + */ + +#include <linux/mutex.h> /* mutex */ +#include <linux/module.h> /* needed by all modules */ +#include <linux/netdevice.h> /* netdevice */ +#include <linux/etherdevice.h> /* ethernet address classification */ +#include <linux/if_ether.h> /* ethernet header */ +#include <linux/poll.h> /* poll_table */ +#include <linux/kthread.h> /* kernel threads */ +#include <linux/pkt_sched.h> /* schedule types */ +#include <linux/workqueue.h> /* workqueue */ +#include <linux/slab.h> +#include <net/sock.h> /* struct sock */ +#include <linux/jiffies.h> +#include <linux/seq_file.h> +#include "types.h" + ++extern char bat_routing_algo[]; +extern struct list_head hardif_list; + +extern unsigned char broadcast_addr[]; +extern struct workqueue_struct *bat_event_workqueue; + +int mesh_init(struct net_device *soft_iface); +void mesh_free(struct net_device *soft_iface); +void inc_module_count(void); +void dec_module_count(void); +int is_my_mac(const uint8_t *addr); ++int bat_algo_register(struct bat_algo_ops *bat_algo_ops); ++int bat_algo_select(struct bat_priv *bat_priv, char *name); ++int bat_algo_seq_print_text(struct seq_file *seq, void *offset); + +#ifdef CONFIG_BATMAN_ADV_DEBUG +int debug_log(struct bat_priv *bat_priv, const char *fmt, ...) __printf(2, 3); + +#define bat_dbg(type, bat_priv, fmt, arg...) \ + do { \ + if (atomic_read(&bat_priv->log_level) & type) \ + debug_log(bat_priv, fmt, ## arg); \ + } \ + while (0) +#else /* !CONFIG_BATMAN_ADV_DEBUG */ +__printf(3, 4) +static inline void bat_dbg(int type __always_unused, + struct bat_priv *bat_priv __always_unused, + const char *fmt __always_unused, ...) +{ +} +#endif + +#define bat_info(net_dev, fmt, arg...) \ + do { \ + struct net_device *_netdev = (net_dev); \ + struct bat_priv *_batpriv = netdev_priv(_netdev); \ + bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \ + pr_info("%s: " fmt, _netdev->name, ## arg); \ + } while (0) +#define bat_err(net_dev, fmt, arg...) \ + do { \ + struct net_device *_netdev = (net_dev); \ + struct bat_priv *_batpriv = netdev_priv(_netdev); \ + bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \ + pr_err("%s: " fmt, _netdev->name, ## arg); \ + } while (0) + +/** + * returns 1 if they are the same ethernet addr + * + * note: can't use compare_ether_addr() as it requires aligned memory + */ + +static inline int compare_eth(const void *data1, const void *data2) +{ + return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); +} + ++/** ++ * has_timed_out - compares current time (jiffies) and timestamp + timeout ++ * @timestamp: base value to compare with (in jiffies) ++ * @timeout: added to base value before comparing (in milliseconds) ++ * ++ * Returns true if current time is after timestamp + timeout ++ */ ++static inline bool has_timed_out(unsigned long timestamp, unsigned int timeout) ++{ ++ return time_is_before_jiffies(timestamp + msecs_to_jiffies(timeout)); ++} + +#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) + +/* Returns the smallest signed integer in two's complement with the sizeof x */ +#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u))) + +/* Checks if a sequence number x is a predecessor/successor of y. + * they handle overflows/underflows and can correctly check for a + * predecessor/successor unless the variable sequence number has grown by + * more then 2**(bitwidth(x)-1)-1. + * This means that for a uint8_t with the maximum value 255, it would think: + * - when adding nothing - it is neither a predecessor nor a successor + * - before adding more than 127 to the starting value - it is a predecessor, + * - when adding 128 - it is neither a predecessor nor a successor, + * - after adding more than 127 to the starting value - it is a successor */ +#define seq_before(x, y) ({typeof(x) _d1 = (x); \ + typeof(y) _d2 = (y); \ + typeof(x) _dummy = (_d1 - _d2); \ + (void) (&_d1 == &_d2); \ + _dummy > smallest_signed_int(_dummy); }) +#define seq_after(x, y) seq_before(y, x) + +#endif /* _NET_BATMAN_ADV_MAIN_H_ */ diff --combined net/batman-adv/originator.c index 0bc2045,c2e46b5..c2e46b5 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2009-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2009-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * @@@ -219,6 -219,7 +219,7 @@@ struct orig_node *get_orig_node(struct /* extra reference for return */ atomic_set(&orig_node->refcount, 2);
+ orig_node->tt_initialised = false; orig_node->tt_poss_change = false; orig_node->bat_priv = bat_priv; memcpy(orig_node->orig, addr, ETH_ALEN); @@@ -281,8 -282,7 +282,7 @@@ static bool purge_orig_neighbors(struc hlist_for_each_entry_safe(neigh_node, node, node_tmp, &orig_node->neigh_list, list) {
- if ((time_after(jiffies, - neigh_node->last_valid + PURGE_TIMEOUT * HZ)) || + if ((has_timed_out(neigh_node->last_valid, PURGE_TIMEOUT)) || (neigh_node->if_incoming->if_status == IF_INACTIVE) || (neigh_node->if_incoming->if_status == IF_NOT_IN_USE) || (neigh_node->if_incoming->if_status == IF_TO_BE_REMOVED)) { @@@ -326,9 -326,7 +326,7 @@@ static bool purge_orig_node(struct bat_ { struct neigh_node *best_neigh_node;
- if (time_after(jiffies, - orig_node->last_valid + 2 * PURGE_TIMEOUT * HZ)) { - + if (has_timed_out(orig_node->last_valid, 2 * PURGE_TIMEOUT)) { bat_dbg(DBG_BATMAN, bat_priv, "Originator timeout: originator %pM, last_valid %lu\n", orig_node->orig, (orig_node->last_valid / HZ)); @@@ -371,8 -369,8 +369,8 @@@ static void _purge_orig(struct bat_pri continue; }
- if (time_after(jiffies, orig_node->last_frag_packet + - msecs_to_jiffies(FRAG_TIMEOUT))) + if (has_timed_out(orig_node->last_frag_packet, + FRAG_TIMEOUT)) frag_list_free(&orig_node->frag_list); } spin_unlock_bh(list_lock); diff --combined net/batman-adv/originator.h index 67765ff,3fe2eda..3fe2eda --- a/net/batman-adv/originator.h +++ b/net/batman-adv/originator.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * diff --combined net/batman-adv/packet.h index 4d9e54c,441f3db..441f3db --- a/net/batman-adv/packet.h +++ b/net/batman-adv/packet.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * @@@ -90,10 -90,14 +90,14 @@@ enum tt_client_flags TT_CLIENT_PENDING = 1 << 10 };
- struct batman_ogm_packet { + struct batman_header { uint8_t packet_type; uint8_t version; /* batman version field */ uint8_t ttl; + } __packed; + + struct batman_ogm_packet { + struct batman_header header; uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */ uint32_t seqno; uint8_t orig[6]; @@@ -108,9 -112,7 +112,7 @@@ #define BATMAN_OGM_LEN sizeof(struct batman_ogm_packet)
struct icmp_packet { - uint8_t packet_type; - uint8_t version; /* batman version field */ - uint8_t ttl; + struct batman_header header; uint8_t msg_type; /* see ICMP message types above */ uint8_t dst[6]; uint8_t orig[6]; @@@ -124,9 -126,7 +126,7 @@@ /* icmp_packet_rr must start with all fields from imcp_packet * as this is assumed by code that handles ICMP packets */ struct icmp_packet_rr { - uint8_t packet_type; - uint8_t version; /* batman version field */ - uint8_t ttl; + struct batman_header header; uint8_t msg_type; /* see ICMP message types above */ uint8_t dst[6]; uint8_t orig[6]; @@@ -137,17 -137,13 +137,13 @@@ } __packed;
struct unicast_packet { - uint8_t packet_type; - uint8_t version; /* batman version field */ - uint8_t ttl; + struct batman_header header; uint8_t ttvn; /* destination translation table version number */ uint8_t dest[6]; } __packed;
struct unicast_frag_packet { - uint8_t packet_type; - uint8_t version; /* batman version field */ - uint8_t ttl; + struct batman_header header; uint8_t ttvn; /* destination translation table version number */ uint8_t dest[6]; uint8_t flags; @@@ -157,18 -153,14 +153,14 @@@ } __packed;
struct bcast_packet { - uint8_t packet_type; - uint8_t version; /* batman version field */ - uint8_t ttl; + struct batman_header header; uint8_t reserved; uint32_t seqno; uint8_t orig[6]; } __packed;
struct vis_packet { - uint8_t packet_type; - uint8_t version; /* batman version field */ - uint8_t ttl; /* TTL */ + struct batman_header header; uint8_t vis_type; /* which type of vis-participant sent this? */ uint32_t seqno; /* sequence number */ uint8_t entries; /* number of entries behind this struct */ @@@ -179,9 -171,7 +171,7 @@@ } __packed;
struct tt_query_packet { - uint8_t packet_type; - uint8_t version; /* batman version field */ - uint8_t ttl; + struct batman_header header; /* the flag field is a combination of: * - TT_REQUEST or TT_RESPONSE * - TT_FULL_TABLE */ @@@ -202,9 -192,7 +192,7 @@@ } __packed;
struct roam_adv_packet { - uint8_t packet_type; - uint8_t version; - uint8_t ttl; + struct batman_header header; uint8_t reserved; uint8_t dst[ETH_ALEN]; uint8_t src[ETH_ALEN]; diff --combined net/batman-adv/ring_buffer.c index f1ccfa7,fd63951..fd63951 --- a/net/batman-adv/ring_buffer.c +++ b/net/batman-adv/ring_buffer.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * diff --combined net/batman-adv/ring_buffer.h index 7cdfe62,8b58bd8..8b58bd8 --- a/net/batman-adv/ring_buffer.h +++ b/net/batman-adv/ring_buffer.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * diff --combined net/batman-adv/routing.c index 773e606,cf9a2f6..cf9a2f6 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * @@@ -29,7 -29,6 +29,6 @@@ #include "originator.h" #include "vis.h" #include "unicast.h" - #include "bat_ogm.h"
void slide_own_bcast_window(struct hard_iface *hard_iface) { @@@ -232,8 -231,7 +231,7 @@@ int window_protected(struct bat_priv *b { if ((seq_num_diff <= -TQ_LOCAL_WINDOW_SIZE) || (seq_num_diff >= EXPECTED_SEQNO_RANGE)) { - if (time_after(jiffies, *last_reset + - msecs_to_jiffies(RESET_PROTECTION_MS))) { + if (has_timed_out(*last_reset, RESET_PROTECTION_MS)) {
*last_reset = jiffies; bat_dbg(DBG_BATMAN, bat_priv, @@@ -248,6 -246,7 +246,7 @@@
int recv_bat_ogm_packet(struct sk_buff *skb, struct hard_iface *hard_iface) { + struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); struct ethhdr *ethhdr;
/* drop packet if it has not necessary minimum size */ @@@ -272,9 -271,7 +271,7 @@@ if (skb_linearize(skb) < 0) return NET_RX_DROP;
- ethhdr = (struct ethhdr *)skb_mac_header(skb); - - bat_ogm_receive(ethhdr, skb->data, skb_headlen(skb), hard_iface); + bat_priv->bat_algo_ops->bat_ogm_receive(hard_iface, skb);
kfree_skb(skb); return NET_RX_SUCCESS; @@@ -320,7 -317,7 +317,7 @@@ static int recv_my_icmp_packet(struct b memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN); memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr, ETH_ALEN); icmp_packet->msg_type = ECHO_REPLY; - icmp_packet->ttl = TTL; + icmp_packet->header.ttl = TTL;
send_skb_packet(skb, router->if_incoming, router->addr); ret = NET_RX_SUCCESS; @@@ -376,7 -373,7 +373,7 @@@ static int recv_icmp_ttl_exceeded(struc memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN); memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr, ETH_ALEN); icmp_packet->msg_type = TTL_EXCEEDED; - icmp_packet->ttl = TTL; + icmp_packet->header.ttl = TTL;
send_skb_packet(skb, router->if_incoming, router->addr); ret = NET_RX_SUCCESS; @@@ -441,7 -438,7 +438,7 @@@ int recv_icmp_packet(struct sk_buff *sk return recv_my_icmp_packet(bat_priv, skb, hdr_size);
/* TTL exceeded */ - if (icmp_packet->ttl < 2) + if (icmp_packet->header.ttl < 2) return recv_icmp_ttl_exceeded(bat_priv, skb);
/* get routing information */ @@@ -460,7 -457,7 +457,7 @@@ icmp_packet = (struct icmp_packet_rr *)skb->data;
/* decrement ttl */ - icmp_packet->ttl--; + icmp_packet->header.ttl--;
/* route it */ send_skb_packet(skb, router->if_incoming, router->addr); @@@ -815,7 -812,7 +812,7 @@@ int route_unicast_packet(struct sk_buf unicast_packet = (struct unicast_packet *)skb->data;
/* TTL exceeded */ - if (unicast_packet->ttl < 2) { + if (unicast_packet->header.ttl < 2) { pr_debug("Warning - can't forward unicast packet from %pM to " "%pM: ttl exceeded\n", ethhdr->h_source, unicast_packet->dest); @@@ -840,7 -837,7 +837,7 @@@
unicast_packet = (struct unicast_packet *)skb->data;
- if (unicast_packet->packet_type == BAT_UNICAST && + if (unicast_packet->header.packet_type == BAT_UNICAST && atomic_read(&bat_priv->fragmentation) && skb->len > neigh_node->if_incoming->net_dev->mtu) { ret = frag_send_skb(skb, bat_priv, @@@ -848,7 -845,7 +845,7 @@@ goto out; }
- if (unicast_packet->packet_type == BAT_UNICAST_FRAG && + if (unicast_packet->header.packet_type == BAT_UNICAST_FRAG && frag_can_reassemble(skb, neigh_node->if_incoming->net_dev->mtu)) {
ret = frag_reassemble_skb(skb, bat_priv, &new_skb); @@@ -867,7 -864,7 +864,7 @@@ }
/* decrement ttl */ - unicast_packet->ttl--; + unicast_packet->header.ttl--;
/* route it */ send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); @@@ -1041,7 -1038,7 +1038,7 @@@ int recv_bcast_packet(struct sk_buff *s if (is_my_mac(bcast_packet->orig)) goto out;
- if (bcast_packet->ttl < 2) + if (bcast_packet->header.ttl < 2) goto out;
orig_node = orig_hash_find(bat_priv, bcast_packet->orig); diff --combined net/batman-adv/routing.h index 7aaee0f,92ac100..92ac100 --- a/net/batman-adv/routing.h +++ b/net/batman-adv/routing.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * diff --combined net/batman-adv/send.c index 8a684eb,4137580..4137580 --- a/net/batman-adv/send.c +++ b/net/batman-adv/send.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * @@@ -28,7 -28,6 +28,6 @@@ #include "vis.h" #include "gateway_common.h" #include "originator.h" - #include "bat_ogm.h"
static void send_outstanding_bcast_packet(struct work_struct *work);
@@@ -168,7 -167,7 +167,7 @@@ void schedule_bat_ogm(struct hard_ifac if (primary_if) hardif_free_ref(primary_if);
- bat_ogm_schedule(hard_iface, tt_num_changes); + bat_priv->bat_algo_ops->bat_ogm_schedule(hard_iface, tt_num_changes); }
static void forw_packet_free(struct forw_packet *forw_packet) @@@ -234,7 -233,7 +233,7 @@@ int add_bcast_packet_to_list(struct bat
/* as we have a copy now, it is safe to decrease the TTL */ bcast_packet = (struct bcast_packet *)newskb->data; - bcast_packet->ttl--; + bcast_packet->header.ttl--;
skb_reset_mac_header(newskb);
@@@ -318,7 -317,7 +317,7 @@@ void send_outstanding_bat_ogm_packet(st if (atomic_read(&bat_priv->mesh_state) == MESH_DEACTIVATING) goto out;
- bat_ogm_emit(forw_packet); + bat_priv->bat_algo_ops->bat_ogm_emit(forw_packet);
/** * we have to have at least one packet in the queue diff --combined net/batman-adv/send.h index c8ca3ef,824ef06..824ef06 --- a/net/batman-adv/send.h +++ b/net/batman-adv/send.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * diff --combined net/batman-adv/soft-interface.c index 987c75a,2ffdc74..2ffdc74 --- a/net/batman-adv/soft-interface.c +++ b/net/batman-adv/soft-interface.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * @@@ -396,8 -396,8 +396,8 @@@ void softif_neigh_purge(struct bat_pri hlist_for_each_entry_safe(softif_neigh, node_tmp, node_tmp2, &softif_neigh_vid->softif_neigh_list, list) { - if ((!time_after(jiffies, softif_neigh->last_seen + - msecs_to_jiffies(SOFTIF_NEIGH_TIMEOUT))) && + if ((!has_timed_out(softif_neigh->last_seen, + SOFTIF_NEIGH_TIMEOUT)) && (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE)) continue;
@@@ -457,10 -457,10 +457,10 @@@ static void softif_batman_recv(struct s batman_ogm_packet = (struct batman_ogm_packet *) (skb->data + ETH_HLEN);
- if (batman_ogm_packet->version != COMPAT_VERSION) + if (batman_ogm_packet->header.version != COMPAT_VERSION) goto out;
- if (batman_ogm_packet->packet_type != BAT_OGM) + if (batman_ogm_packet->header.packet_type != BAT_OGM) goto out;
if (!(batman_ogm_packet->flags & PRIMARIES_FIRST_HOP)) @@@ -632,11 -632,11 +632,11 @@@ static int interface_tx(struct sk_buff goto dropped;
bcast_packet = (struct bcast_packet *)skb->data; - bcast_packet->version = COMPAT_VERSION; - bcast_packet->ttl = TTL; + bcast_packet->header.version = COMPAT_VERSION; + bcast_packet->header.ttl = TTL;
/* batman packet type: broadcast */ - bcast_packet->packet_type = BAT_BCAST; + bcast_packet->header.packet_type = BAT_BCAST;
/* hw address of first interface is the orig mac because only * this mac is known throughout the mesh */ @@@ -725,8 -725,8 +725,8 @@@ void interface_rx(struct net_device *so skb_push(skb, hdr_size); unicast_packet = (struct unicast_packet *)skb->data;
- if ((unicast_packet->packet_type != BAT_UNICAST) && - (unicast_packet->packet_type != BAT_UNICAST_FRAG)) + if ((unicast_packet->header.packet_type != BAT_UNICAST) && + (unicast_packet->header.packet_type != BAT_UNICAST_FRAG)) goto dropped;
skb_reset_mac_header(skb); @@@ -855,6 -855,10 +855,10 @@@ struct net_device *softif_create(const bat_priv->primary_if = NULL; bat_priv->num_ifaces = 0;
+ ret = bat_algo_select(bat_priv, bat_routing_algo); + if (ret < 0) + goto unreg_soft_iface; + ret = sysfs_add_meshif(soft_iface); if (ret < 0) goto unreg_soft_iface; diff --combined net/batman-adv/soft-interface.h index 001546f,756eab5..756eab5 --- a/net/batman-adv/soft-interface.h +++ b/net/batman-adv/soft-interface.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner * diff --combined net/batman-adv/translation-table.c index 58361ed,9a6f315..9a6f315 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * @@@ -108,14 -108,6 +108,6 @@@ static struct tt_global_entry *tt_globa
}
- static bool is_out_of_time(unsigned long starting_time, unsigned long timeout) - { - unsigned long deadline; - deadline = starting_time + msecs_to_jiffies(timeout); - - return time_after(jiffies, deadline); - } - static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry) { if (atomic_dec_and_test(&tt_local_entry->common.refcount)) @@@ -218,6 -210,11 +210,11 @@@ void tt_local_add(struct net_device *so if (compare_eth(addr, soft_iface->dev_addr)) tt_local_entry->common.flags |= TT_CLIENT_NOPURGE;
+ /* The local entry has to be marked as NEW to avoid to send it in + * a full table response going out before the next ttvn increment + * (consistency check) */ + tt_local_entry->common.flags |= TT_CLIENT_NEW; + hash_added = hash_add(bat_priv->tt_local_hash, compare_tt, choose_orig, &tt_local_entry->common, &tt_local_entry->common.hash_entry); @@@ -230,11 -227,6 +227,6 @@@
tt_local_event(bat_priv, addr, tt_local_entry->common.flags);
- /* The local entry has to be marked as NEW to avoid to send it in - * a full table response going out before the next ttvn increment - * (consistency check) */ - tt_local_entry->common.flags |= TT_CLIENT_NEW; - /* remove address from global hash if present */ tt_global_entry = tt_global_hash_find(bat_priv, addr);
@@@ -363,7 -355,7 +355,7 @@@ out
static void tt_local_set_pending(struct bat_priv *bat_priv, struct tt_local_entry *tt_local_entry, - uint16_t flags) + uint16_t flags, const char *message) { tt_local_event(bat_priv, tt_local_entry->common.addr, tt_local_entry->common.flags | flags); @@@ -372,6 -364,9 +364,9 @@@ * to be kept in the table in order to send it in a full table * response issued before the net ttvn increment (consistency check) */ tt_local_entry->common.flags |= TT_CLIENT_PENDING; + + bat_dbg(DBG_TT, bat_priv, "Local tt entry (%pM) pending to be removed: " + "%s\n", tt_local_entry->common.addr, message); }
void tt_local_remove(struct bat_priv *bat_priv, const uint8_t *addr, @@@ -384,10 -379,7 +379,7 @@@ goto out;
tt_local_set_pending(bat_priv, tt_local_entry, TT_CLIENT_DEL | - (roaming ? TT_CLIENT_ROAM : NO_FLAGS)); - - bat_dbg(DBG_TT, bat_priv, "Local tt entry (%pM) pending to be removed: " - "%s\n", tt_local_entry->common.addr, message); + (roaming ? TT_CLIENT_ROAM : NO_FLAGS), message); out: if (tt_local_entry) tt_local_entry_free_ref(tt_local_entry); @@@ -420,15 -412,12 +412,12 @@@ static void tt_local_purge(struct bat_p if (tt_local_entry->common.flags & TT_CLIENT_PENDING) continue;
- if (!is_out_of_time(tt_local_entry->last_seen, - TT_LOCAL_TIMEOUT * 1000)) + if (!has_timed_out(tt_local_entry->last_seen, + TT_LOCAL_TIMEOUT)) continue;
tt_local_set_pending(bat_priv, tt_local_entry, - TT_CLIENT_DEL); - bat_dbg(DBG_TT, bat_priv, "Local tt entry (%pM) " - "pending to be removed: timed out\n", - tt_local_entry->common.addr); + TT_CLIENT_DEL, "timed out"); } spin_unlock_bh(list_lock); } @@@ -614,7 -603,7 +603,7 @@@ int tt_global_seq_print_text(struct seq struct tt_global_entry, common); seq_printf(seq, " * %pM (%3u) via %pM (%3u) " - "[%c%c%c]\n", + "[%c%c]\n", tt_global_entry->common.addr, tt_global_entry->ttvn, tt_global_entry->orig_node->orig, @@@ -624,8 -613,6 +613,6 @@@ (tt_global_entry->common.flags & TT_CLIENT_ROAM ? 'R' : '.'), (tt_global_entry->common.flags & - TT_CLIENT_PENDING ? 'X' : '.'), - (tt_global_entry->common.flags & TT_CLIENT_WIFI ? 'W' : '.')); } rcu_read_unlock(); @@@ -665,29 -652,31 +652,31 @@@ void tt_global_del(struct bat_priv *bat struct tt_local_entry *tt_local_entry = NULL;
tt_global_entry = tt_global_hash_find(bat_priv, addr); - if (!tt_global_entry) + if (!tt_global_entry || tt_global_entry->orig_node != orig_node) goto out;
- if (tt_global_entry->orig_node == orig_node) { - if (roaming) { - /* if we are deleting a global entry due to a roam - * event, there are two possibilities: - * 1) the client roamed from node A to node B => we mark - * it with TT_CLIENT_ROAM, we start a timer and we - * wait for node B to claim it. In case of timeout - * the entry is purged. - * 2) the client roamed to us => we can directly delete - * the global entry, since it is useless now. */ - tt_local_entry = tt_local_hash_find(bat_priv, - tt_global_entry->common.addr); - if (!tt_local_entry) { - tt_global_entry->common.flags |= TT_CLIENT_ROAM; - tt_global_entry->roam_at = jiffies; - goto out; - } - } - _tt_global_del(bat_priv, tt_global_entry, message); + if (!roaming) + goto out_del; + + /* if we are deleting a global entry due to a roam + * event, there are two possibilities: + * 1) the client roamed from node A to node B => we mark + * it with TT_CLIENT_ROAM, we start a timer and we + * wait for node B to claim it. In case of timeout + * the entry is purged. + * 2) the client roamed to us => we can directly delete + * the global entry, since it is useless now. */ + tt_local_entry = tt_local_hash_find(bat_priv, + tt_global_entry->common.addr); + if (!tt_local_entry) { + tt_global_entry->common.flags |= TT_CLIENT_ROAM; + tt_global_entry->roam_at = jiffies; + goto out; } + + out_del: + _tt_global_del(bat_priv, tt_global_entry, message); + out: if (tt_global_entry) tt_global_entry_free_ref(tt_global_entry); @@@ -733,6 -722,7 +722,7 @@@ void tt_global_del_orig(struct bat_pri spin_unlock_bh(list_lock); } atomic_set(&orig_node->tt_size, 0); + orig_node->tt_initialised = false; }
static void tt_global_roam_purge(struct bat_priv *bat_priv) @@@ -757,8 -747,8 +747,8 @@@ common); if (!(tt_global_entry->common.flags & TT_CLIENT_ROAM)) continue; - if (!is_out_of_time(tt_global_entry->roam_at, - TT_CLIENT_ROAM_TIMEOUT * 1000)) + if (!has_timed_out(tt_global_entry->roam_at, + TT_CLIENT_ROAM_TIMEOUT)) continue;
bat_dbg(DBG_TT, bat_priv, "Deleting global " @@@ -846,11 -836,6 +836,6 @@@ struct orig_node *transtable_search(str if (!atomic_inc_not_zero(&tt_global_entry->orig_node->refcount)) goto out;
- /* A global client marked as PENDING has already moved from that - * originator */ - if (tt_global_entry->common.flags & TT_CLIENT_PENDING) - goto out; - orig_node = tt_global_entry->orig_node;
out: @@@ -977,8 -962,7 +962,7 @@@ static void tt_req_purge(struct bat_pri
spin_lock_bh(&bat_priv->tt_req_list_lock); list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) { - if (is_out_of_time(node->issued_at, - TT_REQUEST_TIMEOUT * 1000)) { + if (has_timed_out(node->issued_at, TT_REQUEST_TIMEOUT)) { list_del(&node->list); kfree(node); } @@@ -996,8 -980,8 +980,8 @@@ static struct tt_req_node *new_tt_req_n spin_lock_bh(&bat_priv->tt_req_list_lock); list_for_each_entry(tt_req_node_tmp, &bat_priv->tt_req_list, list) { if (compare_eth(tt_req_node_tmp, orig_node) && - !is_out_of_time(tt_req_node_tmp->issued_at, - TT_REQUEST_TIMEOUT * 1000)) + !has_timed_out(tt_req_node_tmp->issued_at, + TT_REQUEST_TIMEOUT)) goto unlock; }
@@@ -1134,11 -1118,11 +1118,11 @@@ static int send_tt_request(struct bat_p tt_request = (struct tt_query_packet *)skb_put(skb, sizeof(struct tt_query_packet));
- tt_request->packet_type = BAT_TT_QUERY; - tt_request->version = COMPAT_VERSION; + tt_request->header.packet_type = BAT_TT_QUERY; + tt_request->header.version = COMPAT_VERSION; memcpy(tt_request->src, primary_if->net_dev->dev_addr, ETH_ALEN); memcpy(tt_request->dst, dst_orig_node->orig, ETH_ALEN); - tt_request->ttl = TTL; + tt_request->header.ttl = TTL; tt_request->ttvn = ttvn; tt_request->tt_data = tt_crc; tt_request->flags = TT_REQUEST; @@@ -1264,9 -1248,9 +1248,9 @@@ static bool send_other_tt_response(stru tt_response = (struct tt_query_packet *)skb->data; }
- tt_response->packet_type = BAT_TT_QUERY; - tt_response->version = COMPAT_VERSION; - tt_response->ttl = TTL; + tt_response->header.packet_type = BAT_TT_QUERY; + tt_response->header.version = COMPAT_VERSION; + tt_response->header.ttl = TTL; memcpy(tt_response->src, req_dst_orig_node->orig, ETH_ALEN); memcpy(tt_response->dst, tt_request->src, ETH_ALEN); tt_response->flags = TT_RESPONSE; @@@ -1381,9 -1365,9 +1365,9 @@@ static bool send_my_tt_response(struct tt_response = (struct tt_query_packet *)skb->data; }
- tt_response->packet_type = BAT_TT_QUERY; - tt_response->version = COMPAT_VERSION; - tt_response->ttl = TTL; + tt_response->header.packet_type = BAT_TT_QUERY; + tt_response->header.version = COMPAT_VERSION; + tt_response->header.ttl = TTL; memcpy(tt_response->src, primary_if->net_dev->dev_addr, ETH_ALEN); memcpy(tt_response->dst, tt_request->src, ETH_ALEN); tt_response->flags = TT_RESPONSE; @@@ -1450,6 -1434,7 +1434,7 @@@ static void _tt_update_changes(struct b */ return; } + orig_node->tt_initialised = true; }
static void tt_fill_gtable(struct bat_priv *bat_priv, @@@ -1589,8 -1574,7 +1574,7 @@@ static void tt_roam_purge(struct bat_pr
spin_lock_bh(&bat_priv->tt_roam_list_lock); list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) { - if (!is_out_of_time(node->first_time, - ROAMING_MAX_TIME * 1000)) + if (!has_timed_out(node->first_time, ROAMING_MAX_TIME)) continue;
list_del(&node->list); @@@ -1617,8 -1601,7 +1601,7 @@@ static bool tt_check_roam_count(struct if (!compare_eth(tt_roam_node->addr, client)) continue;
- if (is_out_of_time(tt_roam_node->first_time, - ROAMING_MAX_TIME * 1000)) + if (has_timed_out(tt_roam_node->first_time, ROAMING_MAX_TIME)) continue;
if (!atomic_dec_not_zero(&tt_roam_node->counter)) @@@ -1669,9 -1652,9 +1652,9 @@@ void send_roam_adv(struct bat_priv *bat roam_adv_packet = (struct roam_adv_packet *)skb_put(skb, sizeof(struct roam_adv_packet));
- roam_adv_packet->packet_type = BAT_ROAM_ADV; - roam_adv_packet->version = COMPAT_VERSION; - roam_adv_packet->ttl = TTL; + roam_adv_packet->header.packet_type = BAT_ROAM_ADV; + roam_adv_packet->header.version = COMPAT_VERSION; + roam_adv_packet->header.ttl = TTL; primary_if = primary_if_get_selected(bat_priv); if (!primary_if) goto out; @@@ -1854,8 -1837,10 +1837,10 @@@ void tt_update_orig(struct bat_priv *ba uint8_t orig_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn); bool full_table = true;
- /* the ttvn increased by one -> we can apply the attached changes */ - if (ttvn - orig_ttvn == 1) { + /* orig table not initialised AND first diff is in the OGM OR the ttvn + * increased by one -> we can apply the attached changes */ + if ((!orig_node->tt_initialised && ttvn == 1) || + ttvn - orig_ttvn == 1) { /* the OGM could not contain the changes due to their size or * because they have already been sent TT_OGM_APPEND_MAX times. * In this case send a tt request */ @@@ -1889,7 -1874,8 +1874,8 @@@ } else { /* if we missed more than one change or our tables are not * in sync anymore -> request fresh tt data */ - if (ttvn != orig_ttvn || orig_node->tt_crc != tt_crc) { + if (!orig_node->tt_initialised || ttvn != orig_ttvn || + orig_node->tt_crc != tt_crc) { request_table: bat_dbg(DBG_TT, bat_priv, "TT inconsistency for %pM. " "Need to retrieve the correct information " diff --combined net/batman-adv/translation-table.h index 30efd49,c753633..c753633 --- a/net/batman-adv/translation-table.h +++ b/net/batman-adv/translation-table.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * diff --combined net/batman-adv/types.h index e9eb043,302efb5..302efb5 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * @@@ -81,6 -81,7 +81,7 @@@ struct orig_node int16_t tt_buff_len; spinlock_t tt_buff_lock; /* protects tt_buff */ atomic_t tt_size; + bool tt_initialised; /* The tt_poss_change flag is used to detect an ongoing roaming phase. * If true, then I sent a Roaming_adv to this orig_node and I have to * inspect every packet directed to it to check whether it is still @@@ -205,6 -206,7 +206,7 @@@ struct bat_priv atomic_t gw_reselect; struct hard_iface __rcu *primary_if; /* rcu protected pointer */ struct vis_info *my_vis_info; + struct bat_algo_ops *bat_algo_ops; };
struct socket_client { @@@ -343,4 -345,23 +345,23 @@@ struct softif_neigh struct rcu_head rcu; };
+ struct bat_algo_ops { + struct hlist_node list; + char *name; + /* init OGM when hard-interface is enabled */ + void (*bat_ogm_init)(struct hard_iface *hard_iface); + /* init primary OGM when primary interface is selected */ + void (*bat_ogm_init_primary)(struct hard_iface *hard_iface); + /* init mac addresses of the OGM belonging to this hard-interface */ + void (*bat_ogm_update_mac)(struct hard_iface *hard_iface); + /* prepare a new outgoing OGM for the send queue */ + void (*bat_ogm_schedule)(struct hard_iface *hard_iface, + int tt_num_changes); + /* send scheduled OGM */ + void (*bat_ogm_emit)(struct forw_packet *forw_packet); + /* receive incoming OGM */ + void (*bat_ogm_receive)(struct hard_iface *if_incoming, + struct sk_buff *skb); + }; + #endif /* _NET_BATMAN_ADV_TYPES_H_ */ diff --combined net/batman-adv/unicast.c index 07d1c1d,0897dfa..0897dfa --- a/net/batman-adv/unicast.c +++ b/net/batman-adv/unicast.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2010-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2010-2012 B.A.T.M.A.N. contributors: * * Andreas Langer * @@@ -67,7 -67,7 +67,7 @@@ static struct sk_buff *frag_merge_packe
memmove(skb->data + uni_diff, skb->data, hdr_len); unicast_packet = (struct unicast_packet *) skb_pull(skb, uni_diff); - unicast_packet->packet_type = BAT_UNICAST; + unicast_packet->header.packet_type = BAT_UNICAST;
return skb;
@@@ -251,9 -251,9 +251,9 @@@ int frag_send_skb(struct sk_buff *skb,
memcpy(frag1, &tmp_uc, sizeof(tmp_uc));
- frag1->ttl--; - frag1->version = COMPAT_VERSION; - frag1->packet_type = BAT_UNICAST_FRAG; + frag1->header.ttl--; + frag1->header.version = COMPAT_VERSION; + frag1->header.packet_type = BAT_UNICAST_FRAG;
memcpy(frag1->orig, primary_if->net_dev->dev_addr, ETH_ALEN); memcpy(frag2, frag1, sizeof(*frag2)); @@@ -320,11 -320,11 +320,11 @@@ find_router
unicast_packet = (struct unicast_packet *)skb->data;
- unicast_packet->version = COMPAT_VERSION; + unicast_packet->header.version = COMPAT_VERSION; /* batman packet type: unicast */ - unicast_packet->packet_type = BAT_UNICAST; + unicast_packet->header.packet_type = BAT_UNICAST; /* set unicast ttl */ - unicast_packet->ttl = TTL; + unicast_packet->header.ttl = TTL; /* copy the destination for faster routing */ memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN); /* set the destination tt version number */ @@@ -335,7 -335,7 +335,7 @@@ data_len + sizeof(*unicast_packet) > neigh_node->if_incoming->net_dev->mtu) { /* send frag skb decreases ttl */ - unicast_packet->ttl++; + unicast_packet->header.ttl++; ret = frag_send_skb(skb, bat_priv, neigh_node->if_incoming, neigh_node->addr); goto out; diff --combined net/batman-adv/unicast.h index 8fd5535,a9faf6b..a9faf6b --- a/net/batman-adv/unicast.h +++ b/net/batman-adv/unicast.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2010-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2010-2012 B.A.T.M.A.N. contributors: * * Andreas Langer * diff --combined net/batman-adv/vis.c index cc3b9f2,c4a5b8c..c4a5b8c --- a/net/batman-adv/vis.c +++ b/net/batman-adv/vis.c @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2008-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2008-2012 B.A.T.M.A.N. contributors: * * Simon Wunderlich * @@@ -617,7 -617,7 +617,7 @@@ static int generate_vis_packet(struct b packet->vis_type = atomic_read(&bat_priv->vis_mode);
memcpy(packet->target_orig, broadcast_addr, ETH_ALEN); - packet->ttl = TTL; + packet->header.ttl = TTL; packet->seqno = htonl(ntohl(packet->seqno) + 1); packet->entries = 0; skb_trim(info->skb_packet, sizeof(*packet)); @@@ -714,8 -714,7 +714,7 @@@ static void purge_vis_packets(struct ba if (info == bat_priv->my_vis_info) continue;
- if (time_after(jiffies, - info->first_seen + VIS_TIMEOUT * HZ)) { + if (has_timed_out(info->first_seen, VIS_TIMEOUT)) { hlist_del(node); send_list_del(info); kref_put(&info->refcount, free_info); @@@ -818,19 -817,19 +817,19 @@@ static void send_vis_packet(struct bat_ goto out;
packet = (struct vis_packet *)info->skb_packet->data; - if (packet->ttl < 2) { + if (packet->header.ttl < 2) { pr_debug("Error - can't send vis packet: ttl exceeded\n"); goto out; }
memcpy(packet->sender_orig, primary_if->net_dev->dev_addr, ETH_ALEN); - packet->ttl--; + packet->header.ttl--;
if (is_broadcast_ether_addr(packet->target_orig)) broadcast_vis_packet(bat_priv, info); else unicast_vis_packet(bat_priv, info); - packet->ttl++; /* restore TTL */ + packet->header.ttl++; /* restore TTL */
out: if (primary_if) @@@ -910,9 -909,9 +909,9 @@@ int vis_init(struct bat_priv *bat_priv INIT_LIST_HEAD(&bat_priv->my_vis_info->send_list); kref_init(&bat_priv->my_vis_info->refcount); bat_priv->my_vis_info->bat_priv = bat_priv; - packet->version = COMPAT_VERSION; - packet->packet_type = BAT_VIS; - packet->ttl = TTL; + packet->header.version = COMPAT_VERSION; + packet->header.packet_type = BAT_VIS; + packet->header.ttl = TTL; packet->seqno = 0; packet->entries = 0;
diff --combined net/batman-adv/vis.h index 31b820d,ee2e46e..ee2e46e --- a/net/batman-adv/vis.h +++ b/net/batman-adv/vis.h @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (C) 2008-2011 B.A.T.M.A.N. contributors: + * Copyright (C) 2008-2012 B.A.T.M.A.N. contributors: * * Simon Wunderlich, Marek Lindner * @@@ -22,7 -22,8 +22,8 @@@ #ifndef _NET_BATMAN_ADV_VIS_H_ #define _NET_BATMAN_ADV_VIS_H_
- #define VIS_TIMEOUT 200 /* timeout of vis packets in seconds */ + #define VIS_TIMEOUT 200000 /* timeout of vis packets + * in miliseconds */
int vis_seq_print_text(struct seq_file *seq, void *offset); void receive_server_sync_packet(struct bat_priv *bat_priv,