pull request: batman-adv 2013-10-23
Subsystems (3)
Hello David,
this is another set of changes intended for net-next/linux-3.13. (probably our last pull request for this cycle)
Patches 1 and 2 reshape two of our main data structures in a way that they can easily be extended in the future to accommodate new routing protocols.
Patches from 3 to 9 improve our routing protocol API and its users so that all the protocol-related code is not mixed up with the other components anymore.
Patch 10 limits the local Translation Table maximum size to a value such that it can be fully transfered over the air if needed. This value depends on fragmentation being enabled or not and on the mtu values.
Patch 11 makes batman-adv send a uevent in case of soft-interface destruction while a "bat-Gateway" was configured (this informs userspace about the GW not being available anymore).
Patches 13 and 14 enable the TT component to detect non-mesh client flag changes at runtime (till now those flags where set upon client detection and were not changed anymore).
Patch 16 is a generalisation of our user-to-kernel space communication (and viceversa) used to exchange ICMP packets to send/received to/from the mesh network. Now it can easily accommodate new ICMP packet types without breaking the existing userspace API anymore.
Remaining patches are minor changes and cleanups.
Please pull or let me know of any problem.
Thanks a lot,
Antonio
The following changes since commit 47d4ab91e4472723f181075c81627374ca86816c:
macvlan: resolve ENOENT errors on creation (2013-10-22 19:22:09 -0400)
are available in the git repository at:
git://git.open-mesh.org/linux-merge.git tags/batman-adv-for-davem
for you to fetch changes up to da6b8c20a5b8c7edce95c95fa2356300691094f5:
batman-adv: generalize batman-adv icmp packet handling (2013-10-23 17:03:47 +0200)
----------------------------------------------------------------
Included changes:
- data structure reshaping to accommodate multiple routing protocol implementations
- routing protocol API enhancement
- send to userspace the event "batman-adv Gateway loss" in case of soft-iface destruction and a "batman-adv Gateway" was configured
- improve the TT component to support and advertise runtime flag changes
- minor code refactoring
- make the ICMP kernel-to-userspace communication more generic
----------------------------------------------------------------
Antonio Quartulli (13):
batman-adv: make struct batadv_neigh_node algorithm agnostic
batman-adv: make struct batadv_orig_node algorithm agnostic
batman-adv: add bat_orig_print API function
batman-adv: add bat_neigh_cmp API function
batman-adv: add bat_neigh_is_equiv_or_better API function
batman-adv: adapt bonding to use the new API functions
batman-adv: adapt the neighbor purging routine to use the new API functions
batman-adv: provide orig_node routing API
batman-adv: adapt the TT component to use the new API functions
batman-adv: send GW_DEL event in case of soft-iface destruction
batman-adv: invoke dev_get_by_index() outside of is_wifi_iface()
batman-adv: improve the TT component to support runtime flag changes
batman-adv: include the sync-flags when compute the global/local table CRC
Marek Lindner (1):
batman-adv: limit local translation table max size
Simon Wunderlich (2):
batman-adv: Start new development cycle
batman-adv: generalize batman-adv icmp packet handling
net/batman-adv/bat_iv_ogm.c | 399 ++++++++++++++++++++++++++++++++----- net/batman-adv/gateway_client.c | 16 +- net/batman-adv/hard-interface.c | 83 ++++---- net/batman-adv/hard-interface.h | 2 +- net/batman-adv/icmp_socket.c | 128 +++++++----- net/batman-adv/icmp_socket.h | 2 +- net/batman-adv/main.c | 4 +- net/batman-adv/main.h | 8 +- net/batman-adv/network-coding.c | 8 +- net/batman-adv/originator.c | 249 ++++++----------------- net/batman-adv/originator.h | 6 +- net/batman-adv/packet.h | 7 +- net/batman-adv/routing.c | 159 +++++++++------ net/batman-adv/routing.h | 3 +- net/batman-adv/soft-interface.c | 12 +- net/batman-adv/translation-table.c | 235 +++++++++++++++++++--- net/batman-adv/translation-table.h | 3 +- net/batman-adv/types.h | 109 +++++++--- 18 files changed, 956 insertions(+), 477 deletions(-)
PATCH 1/16 batman-adv: make struct batadv_neigh_node algorithm agnostic
In reply to a message not in the archiveFrom: Antonio Quartulli <[email protected]>
some of the fields in struct batadv_neigh_node are strictly related to the B.A.T.M.A.N. IV algorithm. In order to make the struct usable by any routing algorithm it has to be split and made more generic
--- net/batman-adv/bat_iv_ogm.c | 60 +++++++++++++++++++++----------------- net/batman-adv/gateway_client.c | 16 +++++----- net/batman-adv/network-coding.c | 8 +++-- net/batman-adv/originator.c | 33 ++++++++++++++------- net/batman-adv/originator.h | 3 +- net/batman-adv/routing.c | 9 ++++-- net/batman-adv/translation-table.c | 4 +-- net/batman-adv/types.h | 41 ++++++++++++++++---------- 8 files changed, 103 insertions(+), 71 deletions(-)
net/batman-adv/bat_iv_ogm.c +33 -27
@@ -93,16 +93,18 @@ batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,struct batadv_orig_node *orig_node, struct batadv_orig_node *orig_neigh) { + struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);struct batadv_neigh_node *neigh_node; - neigh_node =batadv_neigh_node_new (hard_iface, neigh_addr); + neigh_node =batadv_neigh_node_new (hard_iface, neigh_addr, orig_node);if (!neigh_node) goto out; -INIT_LIST_HEAD (&neigh_node->bonding_list); +spin_lock_init (&neigh_node->bat_iv.lq_update_lock); - neigh_node->orig_node = orig_neigh; - neigh_node->if_incoming = hard_iface; +batadv_dbg (BATADV_DBG_BATMAN , bat_priv, +"Creating new neighbor %pM for orig_node %pM on interface %s\n" , + neigh_addr, orig_node->orig, hard_iface->net_dev->name);spin_lock_bh (&orig_node->neigh_list_lock);hlist_add_head_rcu (&neigh_node->list, &orig_node->neigh_list);
@@ -755,12 +757,12 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,if (dup_status !=BATADV_NO_DUP )continue ; -spin_lock_bh (&tmp_neigh_node->lq_update_lock); -batadv_ring_buffer_set (tmp_neigh_node->tq_recv, - &tmp_neigh_node->tq_index,0 ); - tq_avg =batadv_ring_buffer_avg (tmp_neigh_node->tq_recv); - tmp_neigh_node->tq_avg = tq_avg; -spin_unlock_bh (&tmp_neigh_node->lq_update_lock); +spin_lock_bh (&tmp_neigh_node->bat_iv.lq_update_lock); +batadv_ring_buffer_set (tmp_neigh_node->bat_iv.tq_recv, + &tmp_neigh_node->bat_iv.tq_index,0 ); + tq_avg =batadv_ring_buffer_avg (tmp_neigh_node->bat_iv.tq_recv); + tmp_neigh_node->bat_iv.tq_avg = tq_avg; +spin_unlock_bh (&tmp_neigh_node->bat_iv.lq_update_lock); }if (!neigh_node) {
@@ -785,12 +787,13 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv, neigh_node->last_seen = jiffies; -spin_lock_bh (&neigh_node->lq_update_lock); -batadv_ring_buffer_set (neigh_node->tq_recv, - &neigh_node->tq_index, +spin_lock_bh (&neigh_node->bat_iv.lq_update_lock); +batadv_ring_buffer_set (neigh_node->bat_iv.tq_recv, + &neigh_node->bat_iv.tq_index, batadv_ogm_packet->tq); - neigh_node->tq_avg =batadv_ring_buffer_avg (neigh_node->tq_recv); -spin_unlock_bh (&neigh_node->lq_update_lock); + tq_avg =batadv_ring_buffer_avg (neigh_node->bat_iv.tq_recv); + neigh_node->bat_iv.tq_avg = tq_avg; +spin_unlock_bh (&neigh_node->bat_iv.lq_update_lock);if (dup_status ==BATADV_NO_DUP ) { orig_node->last_ttl = batadv_ogm_packet->header.ttl;
@@ -807,13 +810,13 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv, goto out;/* if this neighbor does not offer a better TQ we won't consider it */ -if (router && (router->tq_avg > neigh_node->tq_avg)) +if (router && (router->bat_iv.tq_avg > neigh_node->bat_iv.tq_avg)) goto out;/* if the TQ is the same and the link not more symmetric we * won't consider it either */ -if (router && (neigh_node->tq_avg == router->tq_avg)) { +if (router && (neigh_node->bat_iv.tq_avg == router->bat_iv.tq_avg)) { orig_node_tmp = router->orig_node;spin_lock_bh (&orig_node_tmp->ogm_cnt_lock); if_num = router->if_incoming->if_num;
@@ -892,7 +895,7 @@ static int batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,/* find packet count of corresponding one hop neighbor */ spin_lock_bh (&orig_node->ogm_cnt_lock); orig_eq_count = orig_neigh_node->bcast_own_sum[if_incoming->if_num]; - neigh_rq_count = neigh_node->real_packet_count; + neigh_rq_count = neigh_node->bat_iv.real_packet_count;spin_unlock_bh (&orig_node->ogm_cnt_lock);/* pay attention to not get a value bigger than 100 % */
@@ -975,6 +978,7 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,uint32_t seqno =ntohl (batadv_ogm_packet->seqno);uint8_t *neigh_addr;uint8_t packet_count; +unsigned long *bitmap; orig_node =batadv_get_orig_node (bat_priv, batadv_ogm_packet->orig);if (!orig_node)
@@ -995,7 +999,7 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,hlist_for_each_entry_rcu (tmp_neigh_node, &orig_node->neigh_list, list) { neigh_addr = tmp_neigh_node->addr; - is_dup =batadv_test_bit (tmp_neigh_node->real_bits, + is_dup =batadv_test_bit (tmp_neigh_node->bat_iv.real_bits, orig_node->last_real_seqno, seqno);
@@ -1011,13 +1015,13 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr, }/* if the window moved, set the update flag. */ - need_update |=batadv_bit_get_packet (bat_priv, - tmp_neigh_node->real_bits, + bitmap = tmp_neigh_node->bat_iv.real_bits; + need_update |=batadv_bit_get_packet (bat_priv, bitmap, seq_diff, set_mark); - packet_count =bitmap_weight (tmp_neigh_node->real_bits, + packet_count =bitmap_weight (tmp_neigh_node->bat_iv.real_bits,BATADV_TQ_LOCAL_WINDOW_SIZE ); - tmp_neigh_node->real_packet_count = packet_count; + tmp_neigh_node->bat_iv.real_packet_count = packet_count; }rcu_read_unlock ();
@@ -1041,7 +1045,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr, {struct batadv_priv *bat_priv =netdev_priv (if_incoming->soft_iface);struct batadv_hard_iface *hard_iface; -struct batadv_orig_node *orig_neigh_node, *orig_node; +struct batadv_orig_node *orig_neigh_node, *orig_node, *orig_node_tmp;struct batadv_neigh_node *router =NULL , *router_router =NULL ;struct batadv_neigh_node *orig_neigh_router =NULL ;int has_directlink_flag;
@@ -1192,10 +1196,12 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr, } router =batadv_orig_node_get_router (orig_node); -if (router) - router_router =batadv_orig_node_get_router (router->orig_node); +if (router) { + orig_node_tmp = router->orig_node; + router_router =batadv_orig_node_get_router (orig_node_tmp); + } -if ((router && router->tq_avg !=0 ) && +if ((router && router->bat_iv.tq_avg !=0 ) && (batadv_compare_eth (router->addr, ethhdr->h_source))) is_from_best_next_hop = true;
net/batman-adv/gateway_client.c +8 -8
@@ -137,7 +137,7 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv)if (!atomic_inc_not_zero (&gw_node->refcount)) goto next; - tq_avg = router->tq_avg; + tq_avg = router->bat_iv.tq_avg;switch (atomic_read (&bat_priv->gw_sel_class)) {case 1 :/* fast connection */
@@ -256,7 +256,7 @@ void batadv_gw_election(struct batadv_priv *bat_priv) next_gw->bandwidth_down /10 , next_gw->bandwidth_down %10 , next_gw->bandwidth_up /10 , - next_gw->bandwidth_up % 10, router->tq_avg); + next_gw->bandwidth_up % 10, router->bat_iv.tq_avg);batadv_throw_uevent (bat_priv,BATADV_UEV_GW ,BATADV_UEV_ADD , gw_addr); }else {
@@ -266,7 +266,7 @@ void batadv_gw_election(struct batadv_priv *bat_priv) next_gw->bandwidth_down /10 , next_gw->bandwidth_down %10 , next_gw->bandwidth_up /10 , - next_gw->bandwidth_up % 10, router->tq_avg); + next_gw->bandwidth_up % 10, router->bat_iv.tq_avg);batadv_throw_uevent (bat_priv,BATADV_UEV_GW ,BATADV_UEV_CHANGE , gw_addr); }
@@ -305,8 +305,8 @@ void batadv_gw_check_election(struct batadv_priv *bat_priv,if (!router_orig) goto out; - gw_tq_avg = router_gw->tq_avg; - orig_tq_avg = router_orig->tq_avg; + gw_tq_avg = router_gw->bat_iv.tq_avg; + orig_tq_avg = router_orig->bat_iv.tq_avg;/* the TQ value has to be better */ if (orig_tq_avg < gw_tq_avg)
@@ -528,7 +528,7 @@ static int batadv_write_buffer_text(struct batadv_priv *bat_priv, ret = seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %u.%u/%u.%u MBit\n", (curr_gw == gw_node ? "=>" : " "), gw_node->orig_node->orig, - router->tq_avg, router->addr, + router->bat_iv.tq_avg, router->addr, router->if_incoming->net_dev->name, gw_node->bandwidth_down / 10, gw_node->bandwidth_down % 10,
@@ -792,7 +792,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,if (!neigh_curr) goto out; - curr_tq_avg = neigh_curr->tq_avg; + curr_tq_avg = neigh_curr->bat_iv.tq_avg;break ;case BATADV_GW_MODE_OFF :default :
@@ -803,7 +803,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,if (!neigh_old) goto out; -if (curr_tq_avg - neigh_old->tq_avg >BATADV_GW_THRESHOLD ) +if (curr_tq_avg - neigh_old->bat_iv.tq_avg >BATADV_GW_THRESHOLD ) out_of_range = true; out:
net/batman-adv/network-coding.c +5 -3
@@ -1003,7 +1003,7 @@ static bool batadv_nc_code_packets(struct batadv_priv *bat_priv,struct batadv_nc_packet *nc_packet, struct batadv_neigh_node *neigh_node) { - uint8_t tq_weighted_neigh, tq_weighted_coding; + uint8_t tq_weighted_neigh, tq_weighted_coding, tq_tmp;struct sk_buff *skb_dest, *skb_src;struct batadv_unicast_packet *packet1;struct batadv_unicast_packet *packet2;
@@ -1028,8 +1028,10 @@ static bool batadv_nc_code_packets(struct batadv_priv *bat_priv,if (!router_coding) goto out; - tq_weighted_neigh =batadv_nc_random_weight_tq (router_neigh->tq_avg); - tq_weighted_coding =batadv_nc_random_weight_tq (router_coding->tq_avg); + tq_tmp =batadv_nc_random_weight_tq (router_neigh->bat_iv.tq_avg); + tq_weighted_neigh = tq_tmp; + tq_tmp =batadv_nc_random_weight_tq (router_coding->bat_iv.tq_avg); + tq_weighted_coding = tq_tmp;/* Select one destination for the MAC-header dst-field based on * weighted TQ-values.
net/batman-adv/originator.c +22 -11
@@ -172,11 +172,20 @@ batadv_orig_node_get_router(struct batadv_orig_node *orig_node)return router; } +/** +* batadv_neigh_node_new - create and init a new neigh_node object +* @hard_iface: the interface where the neighbour is connected to +* @neigh_addr: the mac address of the neighbour interface +* @orig_node: originator object representing the neighbour +* +* Allocates a new neigh_node object and initialises all the generic fields. +* Returns the new object or NULL on failure. +*/ struct batadv_neigh_node *batadv_neigh_node_new (struct batadv_hard_iface *hard_iface, -const uint8_t *neigh_addr) +const uint8_t *neigh_addr, +struct batadv_orig_node *orig_node) { -struct batadv_priv *bat_priv =netdev_priv (hard_iface->soft_iface);struct batadv_neigh_node *neigh_node; neigh_node =kzalloc (sizeof (*neigh_node),GFP_ATOMIC );
@@ -186,15 +195,14 @@ batadv_neigh_node_new(struct batadv_hard_iface *hard_iface,INIT_HLIST_NODE (&neigh_node->list);memcpy (neigh_node->addr, neigh_addr,ETH_ALEN ); -spin_lock_init (&neigh_node->lq_update_lock); + neigh_node->if_incoming = hard_iface; + neigh_node->orig_node = orig_node; + +INIT_LIST_HEAD (&neigh_node->bonding_list);/* extra reference for return */ atomic_set (&neigh_node->refcount,2 ); -batadv_dbg (BATADV_DBG_BATMAN , bat_priv, -"Creating new neighbor %pM on interface %s\n" , neigh_addr, - hard_iface->net_dev->name); - out:return neigh_node; }
@@ -401,6 +409,7 @@ batadv_purge_orig_neighbors(struct batadv_priv *bat_priv,bool neigh_purged = false;unsigned long last_seen;struct batadv_hard_iface *if_incoming; +uint8_t best_metric =0 ; *best_neigh_node =NULL ;
@@ -436,8 +445,10 @@ batadv_purge_orig_neighbors(struct batadv_priv *bat_priv,batadv_neigh_node_free_ref (neigh_node); }else {if ((!*best_neigh_node) || - (neigh_node->tq_avg > (*best_neigh_node)->tq_avg)) + (neigh_node->bat_iv.tq_avg > best_metric)) { *best_neigh_node = neigh_node; + best_metric = neigh_node->bat_iv.tq_avg; + } } }
@@ -557,7 +568,7 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)if (!neigh_node)continue ; -if (neigh_node->tq_avg ==0 ) +if (neigh_node->bat_iv.tq_avg ==0 ) goto next; last_seen_jiffies = jiffies - orig_node->last_seen;
@@ -567,7 +578,7 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)seq_printf (seq,"%pM %4i.%03is (%3i) %pM [%10s]:" , orig_node->orig, last_seen_secs, - last_seen_msecs, neigh_node->tq_avg, + last_seen_msecs, neigh_node->bat_iv.tq_avg, neigh_node->addr, neigh_node->if_incoming->net_dev->name);
@@ -575,7 +586,7 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset) &orig_node->neigh_list, list) {seq_printf (seq," %pM (%3i)" , neigh_node_tmp->addr, - neigh_node_tmp->tq_avg); + neigh_node_tmp->bat_iv.tq_avg); }seq_puts (seq,"\n" );
net/batman-adv/originator.h +2 -1
@@ -31,7 +31,8 @@ struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv, const uint8_t *addr);struct batadv_neigh_node *batadv_neigh_node_new (struct batadv_hard_iface *hard_iface, -const uint8_t *neigh_addr); +const uint8_t *neigh_addr, +struct batadv_orig_node *orig_node);void batadv_neigh_node_free_ref (struct batadv_neigh_node *neigh_node);struct batadv_neigh_node *batadv_orig_node_get_router (struct batadv_orig_node *orig_node);
net/batman-adv/routing.c +6 -3
@@ -119,7 +119,7 @@ void batadv_bonding_candidate_add(struct batadv_orig_node *orig_node, struct batadv_neigh_node *neigh_node) {struct batadv_neigh_node *tmp_neigh_node, *router =NULL ; -uint8_t interference_candidate =0 ; +uint8_t interference_candidate =0 , tq;spin_lock_bh (&orig_node->neigh_list_lock);
@@ -132,8 +132,10 @@ void batadv_bonding_candidate_add(struct batadv_orig_node *orig_node,if (!router) goto candidate_del; +/* ... and is good enough to be considered */ -if (neigh_node->tq_avg < router->tq_avg -BATADV_BONDING_TQ_THRESHOLD ) + tq = router->bat_iv.tq_avg -BATADV_BONDING_TQ_THRESHOLD ; +if (neigh_node->bat_iv.tq_avg < tq) goto candidate_del;/* check if we have another candidate with the same mac address or
@@ -502,7 +504,8 @@ batadv_find_ifalter_router(struct batadv_orig_node *primary_orig,if (tmp_neigh_node->if_incoming == recv_if)continue ; -if (router && tmp_neigh_node->tq_avg <= router->tq_avg) +if (router && + tmp_neigh_node->bat_iv.tq_avg <= router->bat_iv.tq_avg)continue ;if (!atomic_inc_not_zero (&tmp_neigh_node->refcount))
net/batman-adv/translation-table.c +2 -2
@@ -1299,9 +1299,9 @@ batadv_transtable_best_orig(struct batadv_tt_global_entry *tt_global_entry)if (!router)continue ; -if (router->tq_avg > best_tq) { +if (router->bat_iv.tq_avg > best_tq) { best_entry = orig_entry; - best_tq = router->tq_avg; + best_tq = router->bat_iv.tq_avg; }batadv_neigh_node_free_ref (router);
net/batman-adv/types.h +25 -16
65 lines not on this page · raw message
Signature · 1 line
1.8.4
PATCH 2/16 batman-adv: make struct batadv_orig_node algorithm agnostic
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]>
some of the struct batadv_orig_node members are B.A.T.M.A.N. IV specific and therefore they are moved in a algorithm specific substruct in order to make batadv_orig_node routing algorithm agnostic
--- net/batman-adv/bat_iv_ogm.c | 108 +++++++++++++++++++++++++++++++++----------- net/batman-adv/originator.c | 89 ++++++++++++++---------------------- net/batman-adv/originator.h | 3 +- net/batman-adv/types.h | 30 +++++++----- 4 files changed, 135 insertions(+), 95 deletions(-)
net/batman-adv/bat_iv_ogm.c +81 -27
@@ -87,6 +87,57 @@ static uint8_t batadv_ring_buffer_avg(const uint8_t lq_recv[])return (uint8_t )(sum / count); } +/** +* batadv_iv_ogm_orig_get - retrieve or create (if does not exist) an originator +* @bat_priv: the bat priv with all the soft interface information +* @addr: mac address of the originator +* +* Returns the originator object corresponding to the passed mac address or NULL +* on failure. +* If the object does not exists it is created an initialised. +*/ +static struct batadv_orig_node * +batadv_iv_ogm_orig_get (struct batadv_priv *bat_priv,const uint8_t *addr) +{ +struct batadv_orig_node *orig_node; +int size, hash_added; + + orig_node =batadv_orig_hash_find (bat_priv, addr); +if (orig_node) +return orig_node; + + orig_node =batadv_orig_node_new (bat_priv, addr); +if (!orig_node) +return NULL ; + +spin_lock_init (&orig_node->bat_iv.ogm_cnt_lock); + + size = bat_priv->num_ifaces *sizeof (unsigned long ) *BATADV_NUM_WORDS ; + orig_node->bat_iv.bcast_own =kzalloc (size,GFP_ATOMIC ); +if (!orig_node->bat_iv.bcast_own) + goto free_orig_node; + + size = bat_priv->num_ifaces *sizeof (uint8_t ); + orig_node->bat_iv.bcast_own_sum =kzalloc (size,GFP_ATOMIC ); +if (!orig_node->bat_iv.bcast_own_sum) + goto free_bcast_own; + + hash_added =batadv_hash_add (bat_priv->orig_hash, batadv_compare_orig, + batadv_choose_orig, orig_node, + &orig_node->hash_entry); +if (hash_added !=0 ) + goto free_bcast_own; + +return orig_node; + +free_bcast_own: +kfree (orig_node->bat_iv.bcast_own); +free_orig_node: +batadv_orig_node_free_ref (orig_node); + +return NULL ; +} +static struct batadv_neigh_node * batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface, const uint8_t *neigh_addr,
@@ -663,20 +714,22 @@ batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface)uint32_t i;size_t word_index;uint8_t *w; +int if_num;for (i =0 ; i < hash->size; i++) { head = &hash->table[i];rcu_read_lock ();hlist_for_each_entry_rcu (orig_node, head, hash_entry) { -spin_lock_bh (&orig_node->ogm_cnt_lock); +spin_lock_bh (&orig_node->bat_iv.ogm_cnt_lock); word_index = hard_iface->if_num *BATADV_NUM_WORDS ; - word = &(orig_node->bcast_own[word_index]); + word = &(orig_node->bat_iv.bcast_own[word_index]);batadv_bit_get_packet (bat_priv, word,1 ,0 ); - w = &orig_node->bcast_own_sum[hard_iface->if_num]; + if_num = hard_iface->if_num; + w = &orig_node->bat_iv.bcast_own_sum[if_num]; *w =bitmap_weight (word,BATADV_TQ_LOCAL_WINDOW_SIZE ); -spin_unlock_bh (&orig_node->ogm_cnt_lock); +spin_unlock_bh (&orig_node->bat_iv.ogm_cnt_lock); }rcu_read_unlock (); }
@@ -768,7 +821,7 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,if (!neigh_node) {struct batadv_orig_node *orig_tmp; - orig_tmp =batadv_get_orig_node (bat_priv, ethhdr->h_source); + orig_tmp =batadv_iv_ogm_orig_get (bat_priv, ethhdr->h_source);if (!orig_tmp) goto unlock;
@@ -818,16 +871,16 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,*/ if (router && (neigh_node->bat_iv.tq_avg == router->bat_iv.tq_avg)) { orig_node_tmp = router->orig_node; -spin_lock_bh (&orig_node_tmp->ogm_cnt_lock); +spin_lock_bh (&orig_node_tmp->bat_iv.ogm_cnt_lock); if_num = router->if_incoming->if_num; - sum_orig = orig_node_tmp->bcast_own_sum[if_num]; -spin_unlock_bh (&orig_node_tmp->ogm_cnt_lock); + sum_orig = orig_node_tmp->bat_iv.bcast_own_sum[if_num]; +spin_unlock_bh (&orig_node_tmp->bat_iv.ogm_cnt_lock); orig_node_tmp = neigh_node->orig_node; -spin_lock_bh (&orig_node_tmp->ogm_cnt_lock); +spin_lock_bh (&orig_node_tmp->bat_iv.ogm_cnt_lock); if_num = neigh_node->if_incoming->if_num; - sum_neigh = orig_node_tmp->bcast_own_sum[if_num]; -spin_unlock_bh (&orig_node_tmp->ogm_cnt_lock); + sum_neigh = orig_node_tmp->bat_iv.bcast_own_sum[if_num]; +spin_unlock_bh (&orig_node_tmp->bat_iv.ogm_cnt_lock);if (sum_orig >= sum_neigh) goto out;
@@ -855,7 +908,7 @@ static int batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,uint8_t total_count;uint8_t orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;unsigned int neigh_rq_inv_cube, neigh_rq_max_cube; -int tq_asym_penalty, inv_asym_penalty, ret =0 ; +int tq_asym_penalty, inv_asym_penalty, if_num, ret =0 ;unsigned int combined_tq;/* find corresponding one hop neighbor */
@@ -893,10 +946,11 @@ static int batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node, orig_node->last_seen = jiffies;/* find packet count of corresponding one hop neighbor */ -spin_lock_bh (&orig_node->ogm_cnt_lock); - orig_eq_count = orig_neigh_node->bcast_own_sum[if_incoming->if_num]; +spin_lock_bh (&orig_node->bat_iv.ogm_cnt_lock); + if_num = if_incoming->if_num; + orig_eq_count = orig_neigh_node->bat_iv.bcast_own_sum[if_num]; neigh_rq_count = neigh_node->bat_iv.real_packet_count; -spin_unlock_bh (&orig_node->ogm_cnt_lock); +spin_unlock_bh (&orig_node->bat_iv.ogm_cnt_lock);/* pay attention to not get a value bigger than 100 % */ if (orig_eq_count > neigh_rq_count)
@@ -980,11 +1034,11 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,uint8_t packet_count;unsigned long *bitmap; - orig_node =batadv_get_orig_node (bat_priv, batadv_ogm_packet->orig); + orig_node =batadv_iv_ogm_orig_get (bat_priv, batadv_ogm_packet->orig);if (!orig_node)return BATADV_NO_DUP ; -spin_lock_bh (&orig_node->ogm_cnt_lock); +spin_lock_bh (&orig_node->bat_iv.ogm_cnt_lock); seq_diff = seqno - orig_node->last_real_seqno;/* signalize caller that the packet is to be dropped. */
@@ -1033,7 +1087,7 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr, } out: -spin_unlock_bh (&orig_node->ogm_cnt_lock); +spin_unlock_bh (&orig_node->bat_iv.ogm_cnt_lock);batadv_orig_node_free_ref (orig_node);return ret; }
@@ -1129,8 +1183,8 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,int16_t if_num;uint8_t *weight; - orig_neigh_node =batadv_get_orig_node (bat_priv, - ethhdr->h_source); + orig_neigh_node =batadv_iv_ogm_orig_get (bat_priv, + ethhdr->h_source);if (!orig_neigh_node)return ;
@@ -1144,15 +1198,15 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr, if_num = if_incoming->if_num; offset = if_num *BATADV_NUM_WORDS ; -spin_lock_bh (&orig_neigh_node->ogm_cnt_lock); - word = &(orig_neigh_node->bcast_own[offset]); +spin_lock_bh (&orig_neigh_node->bat_iv.ogm_cnt_lock); + word = &(orig_neigh_node->bat_iv.bcast_own[offset]); bit_pos = if_incoming_seqno -2 ; bit_pos -=ntohl (batadv_ogm_packet->seqno);batadv_set_bit (word, bit_pos); - weight = &orig_neigh_node->bcast_own_sum[if_num]; + weight = &orig_neigh_node->bat_iv.bcast_own_sum[if_num]; *weight =bitmap_weight (word,BATADV_TQ_LOCAL_WINDOW_SIZE ); -spin_unlock_bh (&orig_neigh_node->ogm_cnt_lock); +spin_unlock_bh (&orig_neigh_node->bat_iv.ogm_cnt_lock); } batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
@@ -1175,7 +1229,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,return ; } - orig_node =batadv_get_orig_node (bat_priv, batadv_ogm_packet->orig); + orig_node =batadv_iv_ogm_orig_get (bat_priv, batadv_ogm_packet->orig);if (!orig_node)return ;
@@ -1225,8 +1279,8 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,if (is_single_hop_neigh) orig_neigh_node = orig_node;else - orig_neigh_node =batadv_get_orig_node (bat_priv, - ethhdr->h_source); + orig_neigh_node =batadv_iv_ogm_orig_get (bat_priv, + ethhdr->h_source);if (!orig_neigh_node) goto out;
net/batman-adv/originator.c +33 -56
190 lines not on this page · raw message
net/batman-adv/originator.h +2 -1
@@ -22,12 +22,13 @@#include "hash.h" +int batadv_compare_orig (const struct hlist_node *node,const void *data2);int batadv_originator_init (struct batadv_priv *bat_priv);void batadv_originator_free (struct batadv_priv *bat_priv);void batadv_purge_orig_ref (struct batadv_priv *bat_priv);void batadv_orig_node_free_ref (struct batadv_orig_node *orig_node);void batadv_orig_node_free_ref_now (struct batadv_orig_node *orig_node); -struct batadv_orig_node *batadv_get_orig_node (struct batadv_priv *bat_priv, +struct batadv_orig_node *batadv_orig_node_new (struct batadv_priv *bat_priv,const uint8_t *addr);struct batadv_neigh_node * batadv_neigh_node_new(struct batadv_hard_iface *hard_iface,
net/batman-adv/types.h +19 -11
@@ -133,14 +133,28 @@ struct batadv_orig_node_vlan { };/** +* struct batadv_orig_bat_iv - B.A.T.M.A.N. IV private orig_node members +* @bcast_own: bitfield containing the number of our OGMs this orig_node +* rebroadcasted "back" to us (relative to last_real_seqno) +* @bcast_own_sum: counted result of bcast_own +* @ogm_cnt_lock: lock protecting bcast_own, bcast_own_sum, +* neigh_node->bat_iv.real_bits & neigh_node->bat_iv.real_packet_count +*/ +struct batadv_orig_bat_iv { +unsigned long *bcast_own; +uint8_t *bcast_own_sum; +/* ogm_cnt_lock protects: bcast_own, bcast_own_sum, +* neigh_node->bat_iv.real_bits & neigh_node->bat_iv.real_packet_count +*/ +spinlock_t ogm_cnt_lock; +}; + +/** * struct batadv_orig_node - structure for orig_list maintaining nodes of mesh * @orig: originator ethernet address * @primary_addr: hosts primary interface address * @router: router that should be used to reach this originator * @batadv_dat_addr_t: address of the orig node in the distributed hash -* @bcast_own: bitfield containing the number of our OGMs this orig_node -* rebroadcasted "back" to us (relative to last_real_seqno) -* @bcast_own_sum: counted result of bcast_own * @last_seen: time when last packet from this node was received * @bcast_seqno_reset: time when the broadcast seqno window was reset * @batman_seqno_reset: time when the batman seqno window was reset
@@ -166,8 +180,6 @@ struct batadv_orig_node_vlan {* @neigh_list_lock: lock protecting neigh_list, router and bonding_list * @hash_entry: hlist node for batadv_priv::orig_hash * @bat_priv: pointer to soft_iface this orig node belongs to -* @ogm_cnt_lock: lock protecting bcast_own, bcast_own_sum, -* neigh_node->real_bits & neigh_node->real_packet_count * @bcast_seqno_lock: lock protecting bcast_bits & last_bcast_seqno * @bond_candidates: how many candidates are available * @bond_list: list of bonding candidates
@@ -181,6 +193,7 @@ struct batadv_orig_node_vlan {* @vlan_list: a list of orig_node_vlan structs, one per VLAN served by the * originator represented by this object * @vlan_list_lock: lock protecting vlan_list +* @bat_iv: B.A.T.M.A.N. IV private structure */ struct batadv_orig_node {uint8_t orig[ETH_ALEN ];
@@ -189,8 +202,6 @@ struct batadv_orig_node {#ifdef CONFIG_BATMAN_ADV_DAT batadv_dat_addr_t dat_addr;#endif -unsigned long *bcast_own; -uint8_t *bcast_own_sum;unsigned long last_seen;unsigned long bcast_seqno_reset;unsigned long batman_seqno_reset;
@@ -211,10 +222,6 @@ struct batadv_orig_node {spinlock_t neigh_list_lock;struct hlist_node hash_entry;struct batadv_priv *bat_priv; -/* ogm_cnt_lock protects: bcast_own, bcast_own_sum, -* neigh_node->real_bits & neigh_node->real_packet_count -*/ -spinlock_t ogm_cnt_lock;/* bcast_seqno_lock protects: bcast_bits & last_bcast_seqno */ spinlock_t bcast_seqno_lock;atomic_t bond_candidates;
@@ -230,6 +237,7 @@ struct batadv_orig_node {struct batadv_frag_table_entry fragments[BATADV_FRAG_BUFFER_COUNT ];struct list_head vlan_list;spinlock_t vlan_list_lock;/* protects vlan_list */ +struct batadv_orig_bat_iv bat_iv; };/**
Signature · 1 line
1.8.4
PATCH 3/16 batman-adv: add bat_orig_print API function
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]>
Each routing protocol has its own metric and private variables, therefore it is useful to introduce a new API for originator information printing.
This API needs to be implemented by each protocol in order to provide its specific originator table output.
--- net/batman-adv/bat_iv_ogm.c | 65 ++++++++++++++++++++++++++++++++++++++++++++ net/batman-adv/originator.c | 66 +++++++-------------------------------------- net/batman-adv/types.h | 3 +++ 3 files changed, 78 insertions(+), 56 deletions(-)
net/batman-adv/bat_iv_ogm.c +65 -0
@@ -1411,6 +1411,70 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,return NET_RX_SUCCESS ; } +/** +* batadv_iv_ogm_orig_print - print the originator table +* @bat_priv: the bat priv with all the soft interface information +* @seq: debugfs table seq_file struct +*/ +static void batadv_iv_ogm_orig_print (struct batadv_priv *bat_priv, +struct seq_file *seq) +{ +struct batadv_neigh_node *neigh_node, *neigh_node_tmp; +struct batadv_hashtable *hash = bat_priv->orig_hash; +int last_seen_msecs, last_seen_secs; +struct batadv_orig_node *orig_node; +unsigned long last_seen_jiffies; +struct hlist_head *head; +int batman_count =0 ; +uint32_t i; + +seq_printf (seq," %-15s %s (%s/%i) %17s [%10s]: %20s ...\n" , +"Originator" ,"last-seen" ,"#" ,BATADV_TQ_MAX_VALUE , +"Nexthop" ,"outgoingIF" ,"Potential nexthops" ); + +for (i =0 ; i < hash->size; i++) { + head = &hash->table[i]; + +rcu_read_lock (); +hlist_for_each_entry_rcu (orig_node, head, hash_entry) { + neigh_node =batadv_orig_node_get_router (orig_node); +if (!neigh_node) +continue ; + +if (neigh_node->bat_iv.tq_avg ==0 ) + goto next; + + last_seen_jiffies = jiffies - orig_node->last_seen; + last_seen_msecs =jiffies_to_msecs (last_seen_jiffies); + last_seen_secs = last_seen_msecs /1000 ; + last_seen_msecs = last_seen_msecs %1000 ; + +seq_printf (seq,"%pM %4i.%03is (%3i) %pM [%10s]:" , + orig_node->orig, last_seen_secs, + last_seen_msecs, neigh_node->bat_iv.tq_avg, + neigh_node->addr, + neigh_node->if_incoming->net_dev->name); + +hlist_for_each_entry_rcu (neigh_node_tmp, + &orig_node->neigh_list, list) { +seq_printf (seq," %pM (%3i)" , + neigh_node_tmp->addr, + neigh_node_tmp->bat_iv.tq_avg); + } + +seq_puts (seq,"\n" ); + batman_count++; + +next: +batadv_neigh_node_free_ref (neigh_node); + } +rcu_read_unlock (); + } + +if (batman_count ==0 ) +seq_puts (seq,"No batman nodes in range ...\n" ); +} +static struct batadv_algo_ops batadv_batman_iv__read_mostly = { .name ="BATMAN_IV" , .bat_iface_enable = batadv_iv_ogm_iface_enable,
@@ -1419,6 +1483,7 @@ static struct batadv_algo_ops batadv_batman_iv __read_mostly = { .bat_primary_iface_set = batadv_iv_ogm_primary_iface_set, .bat_ogm_schedule = batadv_iv_ogm_schedule, .bat_ogm_emit = batadv_iv_ogm_emit, + .bat_orig_print = batadv_iv_ogm_orig_print, };int __init batadv_iv_init (void )
net/batman-adv/originator.c +10 -56
83 lines not on this page · raw message
net/batman-adv/types.h +3 -0
@@ -992,6 +992,7 @@ struct batadv_forw_packet {* @bat_primary_iface_set: called when primary interface is selected / changed * @bat_ogm_schedule: prepare a new outgoing OGM for the send queue * @bat_ogm_emit: send scheduled OGM +* @bat_orig_print: print the originator table (optional) */ struct batadv_algo_ops {struct hlist_node list;
@@ -1002,6 +1003,8 @@ struct batadv_algo_ops {void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet); +/* orig_node handling API */ +void (*bat_orig_print)(struct batadv_priv *priv,struct seq_file *seq); };/**
Signature · 1 line
1.8.4
PATCH 4/16 batman-adv: add bat_neigh_cmp API function
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]>
This new API allows to compare the two neighbours based on the metric avoiding the user to deal with any routing algorithm specific detail
--- net/batman-adv/bat_iv_ogm.c | 20 ++++++++++++++++++++ net/batman-adv/main.c | 3 ++- net/batman-adv/types.h | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-)
net/batman-adv/bat_iv_ogm.c +20 -0
@@ -1475,6 +1475,25 @@ next:seq_puts (seq,"No batman nodes in range ...\n" ); } +/** +* batadv_iv_ogm_neigh_cmp - compare the metrics of two neighbors +* @neigh1: the first neighbor object of the comparison +* @neigh2: the second neighbor object of the comparison +* +* Returns a value less, equal to or greater than 0 if the metric via neigh1 is +* lower, the same as or higher than the metric via neigh2 +*/ +static int batadv_iv_ogm_neigh_cmp (struct batadv_neigh_node *neigh1, +struct batadv_neigh_node *neigh2) +{ +uint8_t tq1, tq2; + + tq1 = neigh1->bat_iv.tq_avg; + tq2 = neigh2->bat_iv.tq_avg; + +return tq1 - tq2; +} +static struct batadv_algo_ops batadv_batman_iv__read_mostly = { .name ="BATMAN_IV" , .bat_iface_enable = batadv_iv_ogm_iface_enable,
@@ -1483,6 +1502,7 @@ static struct batadv_algo_ops batadv_batman_iv __read_mostly = { .bat_primary_iface_set = batadv_iv_ogm_primary_iface_set, .bat_ogm_schedule = batadv_iv_ogm_schedule, .bat_ogm_emit = batadv_iv_ogm_emit, + .bat_neigh_cmp = batadv_iv_ogm_neigh_cmp, .bat_orig_print = batadv_iv_ogm_orig_print, };
net/batman-adv/main.c +2 -1
@@ -501,7 +501,8 @@ int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops) !bat_algo_ops->bat_iface_update_mac || !bat_algo_ops->bat_primary_iface_set || !bat_algo_ops->bat_ogm_schedule || - !bat_algo_ops->bat_ogm_emit) { + !bat_algo_ops->bat_ogm_emit || + !bat_algo_ops->bat_neigh_cmp) {pr_info ("Routing algo '%s' does not implement required ops\n" , bat_algo_ops->name); ret = -EINVAL ;
net/batman-adv/types.h +3 -0
@@ -992,6 +992,7 @@ struct batadv_forw_packet {* @bat_primary_iface_set: called when primary interface is selected / changed * @bat_ogm_schedule: prepare a new outgoing OGM for the send queue * @bat_ogm_emit: send scheduled OGM +* @bat_neigh_cmp: compare the metrics of two neighbors * @bat_orig_print: print the originator table (optional) */ struct batadv_algo_ops {
@@ -1003,6 +1004,8 @@ struct batadv_algo_ops {void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet); +int (*bat_neigh_cmp)(struct batadv_neigh_node *neigh1, +struct batadv_neigh_node *neigh2);/* orig_node handling API */ void (*bat_orig_print)(struct batadv_priv *priv,struct seq_file *seq); };
Signature · 1 line
1.8.4
PATCH 5/16 batman-adv: add bat_neigh_is_equiv_or_better API function
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]>
Each routing protocol has its own metric semantic and therefore is the protocol itself the only component able to compare two metrics to check their "similarity".
This new API allows each routing protocol to implement its own logic and make the external code protocol agnostic.
--- net/batman-adv/bat_iv_ogm.c | 18 ++++++++++++++++++ net/batman-adv/main.c | 3 ++- net/batman-adv/main.h | 6 ++++++ net/batman-adv/types.h | 4 ++++ 4 files changed, 30 insertions(+), 1 deletion(-)
net/batman-adv/bat_iv_ogm.c +18 -0
@@ -1494,6 +1494,23 @@ static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1,return tq1 - tq2; } +/** +* batadv_iv_ogm_neigh_is_eob - check if neigh1 is equally good or better than +* neigh2 from the metric prospective +* @neigh1: the first neighbor object of the comparison +* @neigh2: the second neighbor object of the comparison +* +* Returns true if the metric via neigh1 is equally good or better than the +* metric via neigh2, false otherwise. +*/ +static bool batadv_iv_ogm_neigh_is_eob (struct batadv_neigh_node *neigh1, +struct batadv_neigh_node *neigh2) +{ +int diff =batadv_iv_ogm_neigh_cmp (neigh1, neigh2); + +return diff > -BATADV_TQ_SIMILARITY_THRESHOLD ; +} +static struct batadv_algo_ops batadv_batman_iv__read_mostly = { .name ="BATMAN_IV" , .bat_iface_enable = batadv_iv_ogm_iface_enable,
@@ -1503,6 +1520,7 @@ static struct batadv_algo_ops batadv_batman_iv __read_mostly = { .bat_ogm_schedule = batadv_iv_ogm_schedule, .bat_ogm_emit = batadv_iv_ogm_emit, .bat_neigh_cmp = batadv_iv_ogm_neigh_cmp, + .bat_neigh_is_equiv_or_better = batadv_iv_ogm_neigh_is_eob, .bat_orig_print = batadv_iv_ogm_orig_print, };
net/batman-adv/main.c +2 -1
@@ -502,7 +502,8 @@ int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops) !bat_algo_ops->bat_primary_iface_set || !bat_algo_ops->bat_ogm_schedule || !bat_algo_ops->bat_ogm_emit || - !bat_algo_ops->bat_neigh_cmp) { + !bat_algo_ops->bat_neigh_cmp || + !bat_algo_ops->bat_neigh_is_equiv_or_better) {pr_info ("Routing algo '%s' does not implement required ops\n" , bat_algo_ops->name); ret = -EINVAL ;
net/batman-adv/main.h +6 -0
@@ -86,6 +86,12 @@/* numbers of originator to contact for any PUT/GET DHT operation */ #define BATADV_DAT_CANDIDATES_NUM 3 +/** +* BATADV_TQ_SIMILARITY_THRESHOLD - TQ points that a secondary metric can differ +* at most from the primary one in order to be still considered acceptable +*/ +#define BATADV_TQ_SIMILARITY_THRESHOLD 50 +/* how much worse secondary interfaces may be to be considered as bonding * candidates */
net/batman-adv/types.h +4 -0
@@ -993,6 +993,8 @@ struct batadv_forw_packet {* @bat_ogm_schedule: prepare a new outgoing OGM for the send queue * @bat_ogm_emit: send scheduled OGM * @bat_neigh_cmp: compare the metrics of two neighbors +* @bat_neigh_is_equiv_or_better: check if neigh1 is equally good or +* better than neigh2 from the metric prospective * @bat_orig_print: print the originator table (optional) */ struct batadv_algo_ops {
@@ -1006,6 +1008,8 @@ struct batadv_algo_ops {void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);int (*bat_neigh_cmp)(struct batadv_neigh_node *neigh1,struct batadv_neigh_node *neigh2); +bool (*bat_neigh_is_equiv_or_better)(struct batadv_neigh_node *neigh1, +struct batadv_neigh_node *neigh2);/* orig_node handling API */ void (*bat_orig_print)(struct batadv_priv *priv,struct seq_file *seq); };
Signature · 1 line
1.8.4
PATCH 6/16 batman-adv: adapt bonding to use the new API functions
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]>
--- net/batman-adv/bat_iv_ogm.c | 2 +- net/batman-adv/routing.c | 42 +++++++++++++++++++++++++++++------------- net/batman-adv/routing.h | 3 ++- 3 files changed, 32 insertions(+), 15 deletions(-)
net/batman-adv/bat_iv_ogm.c +1 -1
@@ -853,7 +853,7 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv, neigh_node->last_ttl = batadv_ogm_packet->header.ttl; } -batadv_bonding_candidate_add (orig_node, neigh_node); +batadv_bonding_candidate_add (bat_priv, orig_node, neigh_node);/* if this neighbor already is our next hop there is nothing * to change
net/batman-adv/routing.c +29 -13
81 lines not on this page · raw message
net/batman-adv/routing.h +2 -1
@@ -48,7 +48,8 @@ batadv_find_router(struct batadv_priv *bat_priv, const struct batadv_hard_iface *recv_if);void batadv_bonding_candidate_del (struct batadv_orig_node *orig_node,struct batadv_neigh_node *neigh_node); -void batadv_bonding_candidate_add (struct batadv_orig_node *orig_node, +void batadv_bonding_candidate_add (struct batadv_priv *bat_priv, +struct batadv_orig_node *orig_node,struct batadv_neigh_node *neigh_node); void batadv_bonding_save_primary(const struct batadv_orig_node *orig_node, struct batadv_orig_node *orig_neigh_node,
Signature · 1 line
1.8.4
PATCH 7/16 batman-adv: adapt the neighbor purging routine to use the new API functions
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]>
--- net/batman-adv/originator.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
net/batman-adv/originator.c +9 -8
@@ -378,16 +378,16 @@ free_orig_node:static bool batadv_purge_orig_neighbors (struct batadv_priv *bat_priv,struct batadv_orig_node *orig_node, -struct batadv_neigh_node **best_neigh_node) +struct batadv_neigh_node **best_neigh) { +struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;struct hlist_node *node_tmp;struct batadv_neigh_node *neigh_node;bool neigh_purged = false;unsigned long last_seen;struct batadv_hard_iface *if_incoming; -uint8_t best_metric =0 ; - *best_neigh_node =NULL ; + *best_neigh =NULL ;spin_lock_bh (&orig_node->neigh_list_lock);
@@ -420,11 +420,12 @@ batadv_purge_orig_neighbors(struct batadv_priv *bat_priv,batadv_bonding_candidate_del (orig_node, neigh_node);batadv_neigh_node_free_ref (neigh_node); }else { -if ((!*best_neigh_node) || - (neigh_node->bat_iv.tq_avg > best_metric)) { - *best_neigh_node = neigh_node; - best_metric = neigh_node->bat_iv.tq_avg; - } +/* store the best_neighbour if this is the first +* iteration or if a better neighbor has been found +*/ +if (!*best_neigh || + bao->bat_neigh_cmp (neigh_node, *best_neigh) >0 ) + *best_neigh = neigh_node; } }
Signature · 1 line
1.8.4
PATCH 8/16 batman-adv: provide orig_node routing API
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]>
Some operations executed on an orig_node depends on the current routing algorithm being used. To easily make this mechanism routing algorithm agnostic add a orig_node specific API that each algorithm can populate with its own routines.
Such routines are then invoked by the code when needed, without knowing which routing algorithm is currently in use
With this patch 3 API functions are added:
- orig_free (to free routing depending internal structs)
- orig_add_if (to change the inner state of an orig_node when a new hard interface is added)
- orig_del_if (to change the inner state of an orig_node when an hard interface is removed)
--- net/batman-adv/bat_iv_ogm.c | 126 ++++++++++++++++++++++++++++++++++++++++++++ net/batman-adv/originator.c | 102 +++++------------------------------ net/batman-adv/types.h | 11 ++++ 3 files changed, 151 insertions(+), 88 deletions(-)
net/batman-adv/bat_iv_ogm.c +126 -0
@@ -88,6 +88,129 @@ static uint8_t batadv_ring_buffer_avg(const uint8_t lq_recv[]) }/** +* batadv_iv_ogm_orig_free - free the private resources allocated for this +* orig_node +* @orig_node: the orig_node for which the resources have to be free'd +*/ +static void batadv_iv_ogm_orig_free (struct batadv_orig_node *orig_node) +{ +kfree (orig_node->bat_iv.bcast_own); +kfree (orig_node->bat_iv.bcast_own_sum); +} + +/** +* batadv_iv_ogm_orig_add_if - change the private structures of the orig_node to +* include the new hard-interface +* @orig_node: the orig_node that has to be changed +* @max_if_num: the current amount of interfaces +* +* Returns 0 on success, a negative error code otherwise. +*/ +static int batadv_iv_ogm_orig_add_if (struct batadv_orig_node *orig_node, +int max_if_num) +{ +void *data_ptr; +size_t data_size, old_size; +int ret = -ENOMEM ; + +spin_lock_bh (&orig_node->bat_iv.ogm_cnt_lock); + + data_size = max_if_num *sizeof (unsigned long ) *BATADV_NUM_WORDS ; + old_size = (max_if_num -1 ) *sizeof (unsigned long ) *BATADV_NUM_WORDS ; + data_ptr =kmalloc (data_size,GFP_ATOMIC ); +if (!data_ptr) + goto unlock; + +memcpy (data_ptr, orig_node->bat_iv.bcast_own, old_size); +kfree (orig_node->bat_iv.bcast_own); + orig_node->bat_iv.bcast_own = data_ptr; + + data_ptr =kmalloc (max_if_num *sizeof (uint8_t ),GFP_ATOMIC ); +if (!data_ptr) { +kfree (orig_node->bat_iv.bcast_own); + goto unlock; + } + +memcpy (data_ptr, orig_node->bat_iv.bcast_own_sum, + (max_if_num -1 ) *sizeof (uint8_t )); +kfree (orig_node->bat_iv.bcast_own_sum); + orig_node->bat_iv.bcast_own_sum = data_ptr; + + ret =0 ; + +unlock: +spin_unlock_bh (&orig_node->bat_iv.ogm_cnt_lock); + +return ret; +} + +/** +* batadv_iv_ogm_orig_del_if - change the private structures of the orig_node to +* exclude the removed interface +* @orig_node: the orig_node that has to be changed +* @max_if_num: the current amount of interfaces +* @del_if_num: the index of the interface being removed +* +* Returns 0 on success, a negative error code otherwise. +*/ +static int batadv_iv_ogm_orig_del_if (struct batadv_orig_node *orig_node, +int max_if_num,int del_if_num) +{ +int chunk_size, ret = -ENOMEM , if_offset; +void *data_ptr =NULL ; + +spin_lock_bh (&orig_node->bat_iv.ogm_cnt_lock); + +/* last interface was removed */ +if (max_if_num ==0 ) + goto free_bcast_own; + + chunk_size =sizeof (unsigned long ) *BATADV_NUM_WORDS ; + data_ptr =kmalloc (max_if_num * chunk_size,GFP_ATOMIC ); +if (!data_ptr) + goto unlock; + +/* copy first part */ +memcpy (data_ptr, orig_node->bat_iv.bcast_own, del_if_num * chunk_size); + +/* copy second part */ +memcpy ((char *)data_ptr + del_if_num * chunk_size, + orig_node->bat_iv.bcast_own + ((del_if_num +1 ) * chunk_size), + (max_if_num - del_if_num) * chunk_size); + +free_bcast_own: +kfree (orig_node->bat_iv.bcast_own); + orig_node->bat_iv.bcast_own = data_ptr; + +if (max_if_num ==0 ) + goto free_own_sum; + + data_ptr =kmalloc (max_if_num *sizeof (uint8_t ),GFP_ATOMIC ); +if (!data_ptr) { +kfree (orig_node->bat_iv.bcast_own); + goto unlock; + } + +memcpy (data_ptr, orig_node->bat_iv.bcast_own_sum, + del_if_num *sizeof (uint8_t )); + + if_offset = (del_if_num +1 ) *sizeof (uint8_t ); +memcpy ((char *)data_ptr + del_if_num *sizeof (uint8_t ), + orig_node->bat_iv.bcast_own_sum + if_offset, + (max_if_num - del_if_num) *sizeof (uint8_t )); + +free_own_sum: +kfree (orig_node->bat_iv.bcast_own_sum); + orig_node->bat_iv.bcast_own_sum = data_ptr; + + ret =0 ; +unlock: +spin_unlock_bh (&orig_node->bat_iv.ogm_cnt_lock); + +return ret; +} + +/** * batadv_iv_ogm_orig_get - retrieve or create (if does not exist) an originator * @bat_priv: the bat priv with all the soft interface information * @addr: mac address of the originator
@@ -1522,6 +1645,9 @@ static struct batadv_algo_ops batadv_batman_iv __read_mostly = { .bat_neigh_cmp = batadv_iv_ogm_neigh_cmp, .bat_neigh_is_equiv_or_better = batadv_iv_ogm_neigh_is_eob, .bat_orig_print = batadv_iv_ogm_orig_print, + .bat_orig_free = batadv_iv_ogm_orig_free, + .bat_orig_add_if = batadv_iv_ogm_orig_add_if, + .bat_orig_del_if = batadv_iv_ogm_orig_del_if, };int __init batadv_iv_init (void )
net/batman-adv/originator.c +14 -88
143 lines not on this page · raw message
net/batman-adv/types.h +11 -0
@@ -996,6 +996,12 @@ struct batadv_forw_packet {* @bat_neigh_is_equiv_or_better: check if neigh1 is equally good or * better than neigh2 from the metric prospective * @bat_orig_print: print the originator table (optional) +* @bat_orig_free: free the resources allocated by the routing algorithm for an +* orig_node object +* @bat_orig_add_if: ask the routing algorithm to apply the needed changes to +* the orig_node due to a new hard-interface being added into the mesh +* @bat_orig_del_if: ask the routing algorithm to apply the needed changes to +* the orig_node due to an hard-interface being removed from the mesh */ struct batadv_algo_ops {struct hlist_node list;
@@ -1012,6 +1018,11 @@ struct batadv_algo_ops { struct batadv_neigh_node *neigh2);/* orig_node handling API */ void (*bat_orig_print)(struct batadv_priv *priv,struct seq_file *seq); +void (*bat_orig_free)(struct batadv_orig_node *orig_node); +int (*bat_orig_add_if)(struct batadv_orig_node *orig_node, +int max_if_num); +int (*bat_orig_del_if)(struct batadv_orig_node *orig_node, +int max_if_num,int del_if_num); };/**
Signature · 1 line
1.8.4
PATCH 9/16 batman-adv: adapt the TT component to use the new API functions
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]>
--- net/batman-adv/translation-table.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-)
net/batman-adv/translation-table.c +24 -11
@@ -1280,18 +1280,20 @@ out: }/* batadv_transtable_best_orig - Get best originator list entry from tt entry +* @bat_priv: the bat priv with all the soft interface information * @tt_global_entry: global translation table entry to be analyzed * * This functon assumes the caller holds rcu_read_lock(). * Returns best originator list entry or NULL on errors. */ static struct batadv_tt_orig_list_entry * -batadv_transtable_best_orig (struct batadv_tt_global_entry *tt_global_entry) +batadv_transtable_best_orig (struct batadv_priv *bat_priv, +struct batadv_tt_global_entry *tt_global_entry) { -struct batadv_neigh_node *router =NULL ; +struct batadv_neigh_node *router, *best_router =NULL ; +struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;struct hlist_head *head;struct batadv_tt_orig_list_entry *orig_entry, *best_entry =NULL ; -int best_tq =0 ; head = &tt_global_entry->orig_list;hlist_for_each_entry_rcu (orig_entry, head, list) {
@@ -1299,26 +1301,37 @@ batadv_transtable_best_orig(struct batadv_tt_global_entry *tt_global_entry)if (!router)continue ; -if (router->bat_iv.tq_avg > best_tq) { - best_entry = orig_entry; - best_tq = router->bat_iv.tq_avg; +if (best_router && + bao->bat_neigh_cmp (router, best_router) <=0 ) { +batadv_neigh_node_free_ref (router); +continue ; } -batadv_neigh_node_free_ref (router); +/* release the refcount for the "old" best */ +if (best_router) +batadv_neigh_node_free_ref (best_router); + + best_entry = orig_entry; + best_router = router; } +if (best_router) +batadv_neigh_node_free_ref (best_router); +return best_entry; }/* batadv_tt_global_print_entry - print all orig nodes who announce the address * for this global entry +* @bat_priv: the bat priv with all the soft interface information * @tt_global_entry: global translation table entry to be printed * @seq: debugfs table seq_file struct * * This functon assumes the caller holds rcu_read_lock(). */ static void -batadv_tt_global_print_entry (struct batadv_tt_global_entry *tt_global_entry, +batadv_tt_global_print_entry (struct batadv_priv *bat_priv, +struct batadv_tt_global_entry *tt_global_entry,struct seq_file *seq) {struct batadv_tt_orig_list_entry *orig_entry, *best_entry;
@@ -1331,7 +1344,7 @@ batadv_tt_global_print_entry(struct batadv_tt_global_entry *tt_global_entry, tt_common_entry = &tt_global_entry->common; flags = tt_common_entry->flags; - best_entry =batadv_transtable_best_orig (tt_global_entry); + best_entry =batadv_transtable_best_orig (bat_priv, tt_global_entry);if (best_entry) { vlan =batadv_orig_node_vlan_get (best_entry->orig_node, tt_common_entry->vid);
@@ -1420,7 +1433,7 @@ int batadv_tt_global_seq_print_text(struct seq_file *seq, void *offset) tt_global =container_of (tt_common_entry, struct batadv_tt_global_entry, common); -batadv_tt_global_print_entry (tt_global, seq); +batadv_tt_global_print_entry (bat_priv, tt_global, seq); }rcu_read_unlock (); }
@@ -1808,7 +1821,7 @@ struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv, goto out;rcu_read_lock (); - best_entry =batadv_transtable_best_orig (tt_global_entry); + best_entry =batadv_transtable_best_orig (bat_priv, tt_global_entry);/* found anything? */ if (best_entry) orig_node = best_entry->orig_node;
Signature · 1 line
1.8.4
PATCH 10/16 batman-adv: limit local translation table max size
In reply to Antonio QuartulliFrom: Marek Lindner <[email protected]>
The local translation table size is limited by what can be transferred from one node to another via a full table request.
The number of entries fitting into a full table request depend on whether the fragmentation is enabled or not. Therefore this patch introduces a max table size check and refuses to add more local clients when that size is reached. Moreover, if the max full table packet size changes (MTU change or fragmentation is disabled) the local table is downsized instantaneously.
--- net/batman-adv/hard-interface.c | 41 ++++++---- net/batman-adv/soft-interface.c | 12 ++- net/batman-adv/translation-table.c | 150 +++++++++++++++++++++++++++++++++---- net/batman-adv/translation-table.h | 3 +- net/batman-adv/types.h | 3 + 5 files changed, 173 insertions(+), 36 deletions(-)
net/batman-adv/hard-interface.c +26 -15
@@ -266,16 +266,9 @@ static void batadv_check_known_mac_addr(const struct net_device *net_dev)int batadv_hardif_min_mtu (struct net_device *soft_iface) { -const struct batadv_priv *bat_priv =netdev_priv (soft_iface); +struct batadv_priv *bat_priv =netdev_priv (soft_iface);const struct batadv_hard_iface *hard_iface; -/* allow big frames if all devices are capable to do so -* (have MTU > 1500 + batadv_max_header_len()) -*/ int min_mtu =ETH_DATA_LEN ; -int max_header_len =batadv_max_header_len (); - -if (atomic_read (&bat_priv->fragmentation)) - goto out;rcu_read_lock ();list_for_each_entry_rcu (hard_iface, &batadv_hardif_list, list) {
@@ -286,22 +279,40 @@ int batadv_hardif_min_mtu(struct net_device *soft_iface)if (hard_iface->soft_iface != soft_iface)continue ; - min_mtu =min_t (int, hard_iface->net_dev->mtu - max_header_len, - min_mtu); + min_mtu =min_t (int, hard_iface->net_dev->mtu, min_mtu); }rcu_read_unlock (); + +atomic_set (&bat_priv->packet_size_max, min_mtu); + +if (atomic_read (&bat_priv->fragmentation) ==0 ) + goto out; + +/* with fragmentation enabled the maximum size of internally generated +* packets such as translation table exchanges or tvlv containers, etc +* has to be calculated +*/ + min_mtu =min_t (int, min_mtu,BATADV_FRAG_MAX_FRAG_SIZE ); + min_mtu -=sizeof (struct batadv_frag_packet ); + min_mtu *=BATADV_FRAG_MAX_FRAGMENTS ; +atomic_set (&bat_priv->packet_size_max, min_mtu); + +/* with fragmentation enabled we can fragment external packets easily */ + min_mtu =min_t (int, min_mtu,ETH_DATA_LEN ); + out: -return min_mtu; +return min_mtu -batadv_max_header_len (); }/* adjusts the MTU if a new interface with a smaller MTU appeared. */ void batadv_update_min_mtu (struct net_device *soft_iface) { -int min_mtu; + soft_iface->mtu =batadv_hardif_min_mtu (soft_iface); - min_mtu =batadv_hardif_min_mtu (soft_iface); -if (soft_iface->mtu != min_mtu) - soft_iface->mtu = min_mtu; +/* Check if the local translate table should be cleaned up to match a +* new (and smaller) MTU. +*/ +batadv_tt_local_resize_to_mtu (soft_iface); } static void
net/batman-adv/soft-interface.c +8 -4
@@ -166,7 +166,7 @@ static int batadv_interface_tx(struct sk_buff *skb,unsigned int header_len =0 ;int data_len = skb->len, ret;unsigned long brd_delay =1 ; -bool do_bcast = false; +bool do_bcast = false, client_added;unsigned short vid;uint32_t seqno;
@@ -196,9 +196,12 @@ static int batadv_interface_tx(struct sk_buff *skb, ethhdr = (struct ethhdr *)skb->data;/* Register the client MAC in the transtable */ -if (!is_multicast_ether_addr (ethhdr->h_source)) -batadv_tt_local_add (soft_iface, ethhdr->h_source, vid, - skb->skb_iif); +if (!is_multicast_ether_addr (ethhdr->h_source)) { + client_added =batadv_tt_local_add (soft_iface, ethhdr->h_source, + vid, skb->skb_iif); +if (!client_added) + goto dropped; + }/* don't accept stp packets. STP does not help in meshes. * better use the bridge loop avoidance ...
@@ -674,6 +677,7 @@ static int batadv_softif_init_late(struct net_device *dev)atomic_set (&bat_priv->log_level,0 );#endif atomic_set (&bat_priv->fragmentation,1 ); +atomic_set (&bat_priv->packet_size_max,ETH_DATA_LEN );atomic_set (&bat_priv->bcast_queue_left,BATADV_BCAST_QUEUE_LEN );atomic_set (&bat_priv->batman_queue_left,BATADV_BATMAN_QUEUE_LEN );
net/batman-adv/translation-table.c +134 -16
248 lines not on this page · raw message
net/batman-adv/translation-table.h +2 -1
@@ -21,7 +21,7 @@#define _NET_BATMAN_ADV_TRANSLATION_TABLE_H_int batadv_tt_init (struct batadv_priv *bat_priv); -void batadv_tt_local_add (struct net_device *soft_iface,const uint8_t *addr, +bool batadv_tt_local_add (struct net_device *soft_iface,const uint8_t *addr,unsigned short vid,int ifindex); uint16_t batadv_tt_local_remove(struct batadv_priv *bat_priv, const uint8_t *addr, unsigned short vid,
@@ -45,6 +45,7 @@ bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv, uint8_t *addr, unsigned short vid);bool batadv_tt_local_client_is_roaming (struct batadv_priv *bat_priv,uint8_t *addr,unsigned short vid); +void batadv_tt_local_resize_to_mtu (struct net_device *soft_iface); bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv, struct batadv_orig_node *orig_node, const unsigned char *addr,
net/batman-adv/types.h +3 -0
@@ -612,6 +612,8 @@ struct batadv_softif_vlan {* @aggregated_ogms: bool indicating whether OGM aggregation is enabled * @bonding: bool indicating whether traffic bonding is enabled * @fragmentation: bool indicating whether traffic fragmentation is enabled +* @packet_size_max: max packet size that can be transmitted via +* multiple fragmented skbs or a single frame if fragmentation is disabled * @frag_seqno: incremental counter to identify chains of egress fragments * @bridge_loop_avoidance: bool indicating whether bridge loop avoidance is * enabled
@@ -658,6 +660,7 @@ struct batadv_priv {atomic_t aggregated_ogms;atomic_t bonding;atomic_t fragmentation; +atomic_t packet_size_max;atomic_t frag_seqno;#ifdef CONFIG_BATMAN_ADV_BLA atomic_t bridge_loop_avoidance;
Signature · 1 line
1.8.4
PATCH 11/16 batman-adv: send GW_DEL event in case of soft-iface destruction
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]>
In case of soft_iface destruction send a GW DEL event to userspace so that applications which are listening for GW events are informed about the lost of connectivity and can react accordingly.
--- net/batman-adv/hard-interface.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/batman-adv/hard-interface.c +7 -2
@@ -28,6 +28,7 @@#include "originator.h" #include "hash.h" #include "bridge_loop_avoidance.h" +#include "gateway_client.h" #include <linux/if_arp.h> #include <linux/if_ether.h>
@@ -535,8 +536,12 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,dev_put (hard_iface->soft_iface);/* nobody uses this interface anymore */ -if (!bat_priv->num_ifaces && autodel ==BATADV_IF_CLEANUP_AUTO ) -batadv_softif_destroy_sysfs (hard_iface->soft_iface); +if (!bat_priv->num_ifaces) { +batadv_gw_check_client_stop (bat_priv); + +if (autodel ==BATADV_IF_CLEANUP_AUTO ) +batadv_softif_destroy_sysfs (hard_iface->soft_iface); + }netdev_upper_dev_unlink (hard_iface->net_dev, hard_iface->soft_iface); hard_iface->soft_iface =NULL ;
Signature · 1 line
1.8.4
PATCH 12/16 batman-adv: invoke dev_get_by_index() outside of is_wifi_iface()
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]>
Upcoming changes need to perform other checks on the incoming net_device struct.
To avoid performing dev_get_by_index() for each and every check, it is better to move it outside of is_wifi_iface() and search the netdev object once only.
--- net/batman-adv/hard-interface.c | 33 ++++----------------------------- net/batman-adv/hard-interface.h | 2 +- net/batman-adv/translation-table.c | 8 +++++++- 3 files changed, 12 insertions(+), 31 deletions(-)
net/batman-adv/hard-interface.c +4 -29
@@ -125,8 +125,11 @@ static int batadv_is_valid_iface(const struct net_device *net_dev)* * Returns true if the net device is a 802.11 wireless device, false otherwise. */ -static bool batadv_is_wifi_netdev (struct net_device *net_device) +bool batadv_is_wifi_netdev (struct net_device *net_device) { +if (!net_device) +return false; +#ifdef CONFIG_WIRELESS_EXT /* pre-cfg80211 drivers have to implement WEXT, so it is possible to * check for wireless_handlers != NULL
@@ -142,34 +145,6 @@ static bool batadv_is_wifi_netdev(struct net_device *net_device)return false; } -/** -* batadv_is_wifi_iface - check if the given interface represented by ifindex -* is a wifi interface -* @ifindex: interface index to check -* -* Returns true if the interface represented by ifindex is a 802.11 wireless -* device, false otherwise. -*/ -bool batadv_is_wifi_iface (int ifindex) -{ -struct net_device *net_device =NULL ; -bool ret = false; - -if (ifindex ==BATADV_NULL_IFINDEX ) - goto out; - - net_device =dev_get_by_index (&init_net, ifindex); -if (!net_device) - goto out; - - ret =batadv_is_wifi_netdev (net_device); - -out: -if (net_device) -dev_put (net_device); -return ret; -} -static struct batadv_hard_iface *batadv_hardif_get_active (const struct net_device *soft_iface) {
net/batman-adv/hard-interface.h +1 -1
@@ -41,6 +41,7 @@ enum batadv_hard_if_cleanup {extern struct notifier_block batadv_hard_if_notifier; +bool batadv_is_wifi_netdev (struct net_device *net_device);struct batadv_hard_iface *batadv_hardif_get_by_netdev (const struct net_device *net_dev); int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
@@ -51,7 +52,6 @@ void batadv_hardif_remove_interfaces(void);int batadv_hardif_min_mtu (struct net_device *soft_iface);void batadv_update_min_mtu (struct net_device *soft_iface);void batadv_hardif_free_rcu (struct rcu_head *rcu); -bool batadv_is_wifi_iface (int ifindex);static inline void batadv_hardif_free_ref (struct batadv_hard_iface *hard_iface)
net/batman-adv/translation-table.c +7 -1
@@ -477,11 +477,15 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr,struct batadv_priv *bat_priv =netdev_priv (soft_iface);struct batadv_tt_local_entry *tt_local;struct batadv_tt_global_entry *tt_global; +struct net_device *in_dev =NULL ;struct hlist_head *head;struct batadv_tt_orig_list_entry *orig_entry;int hash_added, table_size, packet_size_max;bool ret = false, roamed_back = false; +if (ifindex !=BATADV_NULL_IFINDEX ) + in_dev =dev_get_by_index (&init_net, ifindex); + tt_local =batadv_tt_local_hash_find (bat_priv, addr, vid); tt_global =batadv_tt_global_hash_find (bat_priv, addr, vid);
@@ -542,7 +546,7 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr,*/ tt_local->common.flags =BATADV_TT_CLIENT_NEW ; tt_local->common.vid = vid; -if (batadv_is_wifi_iface (ifindex)) +if (batadv_is_wifi_netdev (in_dev)) tt_local->common.flags |=BATADV_TT_CLIENT_WIFI ;atomic_set (&tt_local->common.refcount,2 ); tt_local->last_seen = jiffies;
@@ -595,6 +599,8 @@ check_roaming: ret = true; out: +if (in_dev) +dev_put (in_dev);if (tt_local)batadv_tt_local_entry_free_ref (tt_local);if (tt_global)
Signature · 1 line
1.8.4
PATCH 13/16 batman-adv: improve the TT component to support runtime flag changes
In reply to a message not in the archiveFrom: Antonio Quartulli <[email protected]>
Some flags (i.e. the WIFI flag) may change after that the related client has already been announced. However it is useful to informa the rest of the network about this change.
Add a runtime-flag-switch detection mechanism and re-announce the related TT entry to advertise the new flag value.
This mechanism can be easily exploited by future flags that may need the same treatment.
--- net/batman-adv/translation-table.c | 25 ++++++++++++++++++++++++- net/batman-adv/types.h | 6 ++++++ 2 files changed, 30 insertions(+), 1 deletion(-)
net/batman-adv/translation-table.c +24 -1
@@ -358,6 +358,13 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv, goto del;if (del_op_requested && !del_op_entry) goto del; + +/* this is a second add in the same originator interval. It +* means that flags have been changed: update them! +*/ +if (!del_op_requested && !del_op_entry) + entry->change.flags = flags; +continue ; del:list_del (&entry->list);
@@ -482,6 +489,7 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr,struct batadv_tt_orig_list_entry *orig_entry;int hash_added, table_size, packet_size_max;bool ret = false, roamed_back = false; +uint8_t remote_flags;if (ifindex !=BATADV_NULL_IFINDEX ) in_dev =dev_get_by_index (&init_net, ifindex);
@@ -596,8 +604,23 @@ check_roaming: } } - ret = true; +/* store the current remote flags before altering them. This helps +* understanding is flags are changing or not +*/ + remote_flags = tt_local->common.flags &BATADV_TT_REMOTE_MASK ; + +if (batadv_is_wifi_netdev (in_dev)) + tt_local->common.flags |=BATADV_TT_CLIENT_WIFI ; +else + tt_local->common.flags &= ~BATADV_TT_CLIENT_WIFI ; +/* if any "dynamic" flag has been modified, resend an ADD event for this +* entry so that all the nodes can get the new flags +*/ +if (remote_flags ^ (tt_local->common.flags &BATADV_TT_REMOTE_MASK )) +batadv_tt_local_event (bat_priv, tt_local,BATADV_NO_FLAGS ); + + ret = true; out:if (in_dev)dev_put (in_dev);
net/batman-adv/types.h +6 -0
@@ -36,6 +36,12 @@#endif /* CONFIG_BATMAN_ADV_DAT */ /** +* BATADV_TT_REMOTE_MASK - bitmask selecting the flags that are sent over the +* wire only +*/ +#define BATADV_TT_REMOTE_MASK 0x00FF + +/** * struct batadv_hard_iface_bat_iv - per hard interface B.A.T.M.A.N. IV data * @ogm_buff: buffer holding the OGM packet * @ogm_buff_len: length of the OGM packet buffer
Signature · 1 line
1.8.4
PATCH 14/16 batman-adv: include the sync-flags when compute the global/local table CRC
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]>
Flags covered by TT_SYNC_MASK are kept in sync among the nodes in the network and therefore they have to be considered while computing the global/local table CRC.
In this way a generic originator is able to understand if its table contains the correct flags or not.
Bits from 4 to 7 in the TT flags fields are now reserved for "synchronized" flags only.
This allows future developers to add more flags of this type without breaking compatibility.
It's important to note that not all the remote TT flags are synchronised. This comes from the fact that some flags are used to inject an information once only.
--- net/batman-adv/packet.h | 5 +++-- net/batman-adv/translation-table.c | 19 +++++++++++++++++++ net/batman-adv/types.h | 6 ++++++ 3 files changed, 28 insertions(+), 2 deletions(-)
net/batman-adv/packet.h +3 -2
@@ -110,12 +110,13 @@ enum batadv_tt_data_flags {/* BATADV_TT_CLIENT flags. * Flags from BIT(0) to BIT(7) are sent on the wire, while flags from BIT(8) to -* BIT(15) are used for local computation only +* BIT(15) are used for local computation only. +* Flags from BIT(4) to BIT(7) are kept in sync with the rest of the network. */ enum batadv_tt_client_flags {BATADV_TT_CLIENT_DEL =BIT (0 ),BATADV_TT_CLIENT_ROAM =BIT (1 ), -BATADV_TT_CLIENT_WIFI =BIT (2 ), +BATADV_TT_CLIENT_WIFI =BIT (4 ),BATADV_TT_CLIENT_NOPURGE =BIT (8 ),BATADV_TT_CLIENT_NEW =BIT (9 ),BATADV_TT_CLIENT_PENDING =BIT (10 ),
net/batman-adv/translation-table.c +19 -0
@@ -1959,6 +1959,7 @@ static uint32_t batadv_tt_global_crc(struct batadv_priv *bat_priv,struct batadv_tt_global_entry *tt_global;struct hlist_head *head;uint32_t i, crc_tmp, crc =0 ; +uint8_t flags;for (i =0 ; i < hash->size; i++) { head = &hash->table[i];
@@ -1997,6 +1998,13 @@ static uint32_t batadv_tt_global_crc(struct batadv_priv *bat_priv, crc_tmp =crc32c (0 , &tt_common->vid,sizeof (tt_common->vid)); + +/* compute the CRC on flags that have to be kept in sync +* among nodes +*/ + flags = tt_common->flags &BATADV_TT_SYNC_MASK ; + crc_tmp =crc32c (crc_tmp, &flags,sizeof (flags)); + crc ^=crc32c (crc_tmp, tt_common->addr,ETH_ALEN ); }rcu_read_unlock ();
@@ -2022,6 +2030,7 @@ static uint32_t batadv_tt_local_crc(struct batadv_priv *bat_priv,struct batadv_tt_common_entry *tt_common;struct hlist_head *head;uint32_t i, crc_tmp, crc =0 ; +uint8_t flags;for (i =0 ; i < hash->size; i++) { head = &hash->table[i];
@@ -2042,6 +2051,13 @@ static uint32_t batadv_tt_local_crc(struct batadv_priv *bat_priv, crc_tmp =crc32c (0 , &tt_common->vid,sizeof (tt_common->vid)); + +/* compute the CRC on flags that have to be kept in sync +* among nodes +*/ + flags = tt_common->flags &BATADV_TT_SYNC_MASK ; + crc_tmp =crc32c (crc_tmp, &flags,sizeof (flags)); + crc ^=crc32c (crc_tmp, tt_common->addr,ETH_ALEN ); }rcu_read_unlock ();
@@ -3524,6 +3540,9 @@ int batadv_tt_init(struct batadv_priv *bat_priv) {int ret; +/* synchronized flags must be remote */ +BUILD_BUG_ON (!(BATADV_TT_SYNC_MASK &BATADV_TT_REMOTE_MASK )); + ret =batadv_tt_local_init (bat_priv);if (ret <0 )return ret;
net/batman-adv/types.h +6 -0
@@ -42,6 +42,12 @@#define BATADV_TT_REMOTE_MASK 0x00FF/** +* BATADV_TT_SYNC_MASK - bitmask of the flags that need to be kept in sync +* among the nodes. These flags are used to compute the global/local CRC +*/ +#define BATADV_TT_SYNC_MASK 0x00F0 + +/** * struct batadv_hard_iface_bat_iv - per hard interface B.A.T.M.A.N. IV data * @ogm_buff: buffer holding the OGM packet * @ogm_buff_len: length of the OGM packet buffer
Signature · 1 line
1.8.4
PATCH 15/16 batman-adv: Start new development cycle
In reply to Antonio QuartulliFrom: Simon Wunderlich <[email protected]>
--- net/batman-adv/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/main.h +1 -1
@@ -26,7 +26,7 @@#define BATADV_DRIVER_DEVICE "batman-adv"#ifndef BATADV_SOURCE_VERSION -#define BATADV_SOURCE_VERSION "2013.4.0" +#define BATADV_SOURCE_VERSION "2013.5.0"#endif /* B.A.T.M.A.N. parameters */
Signature · 1 line
1.8.4
PATCH 16/16 batman-adv: generalize batman-adv icmp packet handling
In reply to Antonio QuartulliFrom: Simon Wunderlich <[email protected]>
Instead of handling icmp packets only up to length of icmp_packet_rr, the code should handle any icmp length size. Therefore the length truncating is moved to when the packet is actually sent to userspace (this does not support lengths longer than icmp_packet_rr yet). Longer packets are forwarded without truncating.
This patch also cleans up some parts where the icmp header struct could be used instead of other icmp_packet(_rr) structs to make the code more readable.
--- net/batman-adv/icmp_socket.c | 128 +++++++++++++++++++++++++++---------------- net/batman-adv/icmp_socket.h | 2 +- net/batman-adv/packet.h | 2 + net/batman-adv/routing.c | 120 ++++++++++++++++++++++++---------------- net/batman-adv/types.h | 2 +- 5 files changed, 157 insertions(+), 97 deletions(-)
net/batman-adv/icmp_socket.c +80 -48
@@ -29,7 +29,7 @@static struct batadv_socket_client *batadv_socket_client_hash[256 ];static void batadv_socket_add_packet (struct batadv_socket_client *socket_client, -struct batadv_icmp_packet_rr *icmp_packet, +struct batadv_icmp_header *icmph,size_t icmp_len);void batadv_socket_init (void )
@@ -155,13 +155,13 @@ static ssize_t batadv_socket_write(struct file *file, const char __user *buff,struct batadv_priv *bat_priv = socket_client->bat_priv;struct batadv_hard_iface *primary_if =NULL ;struct sk_buff *skb; -struct batadv_icmp_packet_rr *icmp_packet; - +struct batadv_icmp_packet_rr *icmp_packet_rr; +struct batadv_icmp_header *icmp_header;struct batadv_orig_node *orig_node =NULL ;struct batadv_neigh_node *neigh_node =NULL ;size_t packet_len =sizeof (struct batadv_icmp_packet ); -if (len <sizeof (struct batadv_icmp_packet )) { +if (len <sizeof (struct batadv_icmp_header )) {batadv_dbg (BATADV_DBG_BATMAN , bat_priv,"Error - can't send packet from char device: invalid packet size\n" );return -EINVAL ;
@@ -174,8 +174,10 @@ static ssize_t batadv_socket_write(struct file *file, const char __user *buff, goto out; } -if (len >=sizeof (struct batadv_icmp_packet_rr )) - packet_len =sizeof (struct batadv_icmp_packet_rr ); +if (len >=BATADV_ICMP_MAX_PACKET_SIZE ) + packet_len =BATADV_ICMP_MAX_PACKET_SIZE ; +else + packet_len = len; skb =netdev_alloc_skb_ip_align (NULL , packet_len +ETH_HLEN );if (!skb) {
@@ -185,67 +187,78 @@ static ssize_t batadv_socket_write(struct file *file, const char __user *buff, skb->priority =TC_PRIO_CONTROL ;skb_reserve (skb,ETH_HLEN ); - icmp_packet = (struct batadv_icmp_packet_rr *)skb_put (skb, packet_len); + icmp_header = (struct batadv_icmp_header *)skb_put (skb, packet_len); -if (copy_from_user (icmp_packet, buff, packet_len)) { +if (copy_from_user (icmp_header, buff, packet_len)) { len = -EFAULT ; goto free_skb; } -if (icmp_packet->icmph.header.packet_type !=BATADV_ICMP ) { +if (icmp_header->header.packet_type !=BATADV_ICMP ) {batadv_dbg (BATADV_DBG_BATMAN , bat_priv,"Error - can't send packet from char device: got bogus packet type (expected: BAT_ICMP)\n" ); len = -EINVAL ; goto free_skb; } -if (icmp_packet->icmph.msg_type !=BATADV_ECHO_REQUEST ) { +switch (icmp_header->msg_type) { +case BATADV_ECHO_REQUEST : +if (len <sizeof (struct batadv_icmp_packet )) { +batadv_dbg (BATADV_DBG_BATMAN , bat_priv, +"Error - can't send packet from char device: invalid packet size\n" ); + len = -EINVAL ; + goto free_skb; + } + +if (atomic_read (&bat_priv->mesh_state) !=BATADV_MESH_ACTIVE ) + goto dst_unreach; + + orig_node =batadv_orig_hash_find (bat_priv, icmp_header->dst); +if (!orig_node) + goto dst_unreach; + + neigh_node =batadv_orig_node_get_router (orig_node); +if (!neigh_node) + goto dst_unreach; + +if (!neigh_node->if_incoming) + goto dst_unreach; + +if (neigh_node->if_incoming->if_status !=BATADV_IF_ACTIVE ) + goto dst_unreach; + + icmp_packet_rr = (struct batadv_icmp_packet_rr *)icmp_header; +if (packet_len ==sizeof (*icmp_packet_rr)) +memcpy (icmp_packet_rr->rr, + neigh_node->if_incoming->net_dev->dev_addr, +ETH_ALEN ); + +break ; +default :batadv_dbg (BATADV_DBG_BATMAN , bat_priv, -"Error - can't send packet from char device: got bogus message type (expected: ECHO_REQUEST)\n" ); +"Error - can't send packet from char device: got unknown message type\n" ); len = -EINVAL ; goto free_skb; } - icmp_packet->icmph.uid = socket_client->index; + icmp_header->uid = socket_client->index; -if (icmp_packet->icmph.header.version !=BATADV_COMPAT_VERSION ) { - icmp_packet->icmph.msg_type =BATADV_PARAMETER_PROBLEM ; - icmp_packet->icmph.header.version =BATADV_COMPAT_VERSION ; -batadv_socket_add_packet (socket_client, icmp_packet, +if (icmp_header->header.version !=BATADV_COMPAT_VERSION ) { + icmp_header->msg_type =BATADV_PARAMETER_PROBLEM ; + icmp_header->header.version =BATADV_COMPAT_VERSION ; +batadv_socket_add_packet (socket_client, icmp_header, packet_len); goto free_skb; } -if (atomic_read (&bat_priv->mesh_state) !=BATADV_MESH_ACTIVE ) - goto dst_unreach; - - orig_node =batadv_orig_hash_find (bat_priv, icmp_packet->icmph.dst); -if (!orig_node) - goto dst_unreach; - - neigh_node =batadv_orig_node_get_router (orig_node); -if (!neigh_node) - goto dst_unreach; - -if (!neigh_node->if_incoming) - goto dst_unreach; - -if (neigh_node->if_incoming->if_status !=BATADV_IF_ACTIVE ) - goto dst_unreach; - -memcpy (icmp_packet->icmph.orig, - primary_if->net_dev->dev_addr,ETH_ALEN ); - -if (packet_len ==sizeof (struct batadv_icmp_packet_rr )) -memcpy (icmp_packet->rr, - neigh_node->if_incoming->net_dev->dev_addr,ETH_ALEN ); +memcpy (icmp_header->orig, primary_if->net_dev->dev_addr,ETH_ALEN );batadv_send_skb_packet (skb, neigh_node->if_incoming, neigh_node->addr); goto out; dst_unreach: - icmp_packet->icmph.msg_type =BATADV_DESTINATION_UNREACHABLE ; -batadv_socket_add_packet (socket_client, icmp_packet, packet_len); + icmp_header->msg_type =BATADV_DESTINATION_UNREACHABLE ; +batadv_socket_add_packet (socket_client, icmp_header, packet_len); free_skb:kfree_skb (skb); out:
@@ -298,27 +311,40 @@ err:return -ENOMEM ; } +/** +* batadv_socket_receive_packet - schedule an icmp packet to be sent to userspace +* on an icmp socket. +* @socket_client: the socket this packet belongs to +* @icmph: pointer to the header of the icmp packet +* @icmp_len: total length of the icmp packet +*/ static void batadv_socket_add_packet (struct batadv_socket_client *socket_client, -struct batadv_icmp_packet_rr *icmp_packet, +struct batadv_icmp_header *icmph,size_t icmp_len) {struct batadv_socket_packet *socket_packet; +size_t len; socket_packet =kmalloc (sizeof (*socket_packet),GFP_ATOMIC );if (!socket_packet)return ; + len = icmp_len; +/* check the maximum length before filling the buffer */ +if (len >sizeof (socket_packet->icmp_packet)) + len =sizeof (socket_packet->icmp_packet); +INIT_LIST_HEAD (&socket_packet->list); -memcpy (&socket_packet->icmp_packet, icmp_packet, icmp_len); - socket_packet->icmp_len = icmp_len; +memcpy (&socket_packet->icmp_packet, icmph, len); + socket_packet->icmp_len = len;spin_lock_bh (&socket_client->lock);/* while waiting for the lock the socket_client could have been * deleted */ -if (!batadv_socket_client_hash[icmp_packet->icmph.uid]) { +if (!batadv_socket_client_hash[icmph->uid]) {spin_unlock_bh (&socket_client->lock);kfree (socket_packet);return ;
@@ -342,12 +368,18 @@ static void batadv_socket_add_packet(struct batadv_socket_client *socket_client,wake_up (&socket_client->queue_wait); } -void batadv_socket_receive_packet (struct batadv_icmp_packet_rr *icmp_packet, +/** +* batadv_socket_receive_packet - schedule an icmp packet to be received +* locally and sent to userspace. +* @icmph: pointer to the header of the icmp packet +* @icmp_len: total length of the icmp packet +*/ +void batadv_socket_receive_packet (struct batadv_icmp_header *icmph,size_t icmp_len) {struct batadv_socket_client *hash; - hash = batadv_socket_client_hash[icmp_packet->icmph.uid]; + hash = batadv_socket_client_hash[icmph->uid];if (hash) -batadv_socket_add_packet (hash, icmp_packet, icmp_len); +batadv_socket_add_packet (hash, icmph, icmp_len); }
net/batman-adv/icmp_socket.h +1 -1
@@ -24,7 +24,7 @@void batadv_socket_init (void );int batadv_socket_setup (struct batadv_priv *bat_priv); -void batadv_socket_receive_packet (struct batadv_icmp_packet_rr *icmp_packet, +void batadv_socket_receive_packet (struct batadv_icmp_header *icmph,size_t icmp_len);#endif /* _NET_BATMAN_ADV_ICMP_SOCKET_H_ */
net/batman-adv/packet.h +2 -0
@@ -239,6 +239,8 @@ struct batadv_icmp_packet_rr {uint8_t rr[BATADV_RR_LEN ][ETH_ALEN ]; }; +#define BATADV_ICMP_MAX_PACKET_SIZE sizeof(struct batadv_icmp_packet_rr) +/* All packet headers in front of an ethernet header have to be completely * divisible by 2 but not by 4 to make the payload after the ethernet * header again 4 bytes boundary aligned.
net/batman-adv/routing.c +73 -47
174 lines not on this page · raw message
net/batman-adv/types.h +1 -1
@@ -749,7 +749,7 @@ struct batadv_socket_client {struct batadv_socket_packet {struct list_head list;size_t icmp_len; -struct batadv_icmp_packet_rr icmp_packet; +uint8_t icmp_packet[BATADV_ICMP_MAX_PACKET_SIZE ]; };/**
Signature · 1 line
1.8.4
Re: [PATCH 03/16] batman-adv: add bat_orig_print API function
In reply to Antonio QuartulliQuoted 6 lines · Antonio Quartulli
Each routing protocol has its own metric and private variables, therefore it is useful to introduce a new API for originator information printing.
This API needs to be implemented by each protocol in order to provide its specific originator table output.
[]
net/batman-adv/bat_iv_ogm.c static int batadv_iv_ogm_receive(struct sk_buff *skb, · line 1420
Quoted 2 lines
net/batman-adv/bat_iv_ogm.c +2
-0+static void batadv_iv_ogm_orig_print (struct batadv_priv *bat_priv, +struct seq_file *seq)
[]
net/batman-adv/bat_iv_ogm.c static int batadv_iv_ogm_receive(struct sk_buff *skb, · line 1433
Quoted 3 lines
net/batman-adv/bat_iv_ogm.c +3
-0+seq_printf (seq," %-15s %s (%s/%i) %17s [%10s]: %20s ...\n" , +"Originator" ,"last-seen" ,"#" ,BATADV_TQ_MAX_VALUE , +"Nexthop" ,"outgoingIF" ,"Potential nexthops" );
This header printf really doesn't add much with the formatting sizes. It's pretty obscure why some of these are sized and others not sized. For instance: %-15s doesn't refer to a mac address size. Perhaps it'd be better to just emit the fixed string just using BATADV_TO_MAX_VALUE. It'd also be easier to find via grep.
Re: [PATCH 03/16] batman-adv: add bat_orig_print API function
Quoted 11 lines · Joe Perches
Quoted 6 lines · Antonio Quartulli
Each routing protocol has its own metric and private variables, therefore it is useful to introduce a new API for originator information printing.
This API needs to be implemented by each protocol in order to provide its specific originator table output.
[]
net/batman-adv/bat_iv_ogm.c static int batadv_iv_ogm_receive(struct sk_buff *skb, · line 1420
Quoted 2 lines
net/batman-adv/bat_iv_ogm.c +2
-0+static void batadv_iv_ogm_orig_print (struct batadv_priv *bat_priv, +struct seq_file *seq)[]
Quoted 9 lines
net/batman-adv/bat_iv_ogm.c static int batadv_iv_ogm_receive(struct sk_buff *skb, · line 1433
Quoted 3 lines
net/batman-adv/bat_iv_ogm.c +3
-0+seq_printf (seq," %-15s %s (%s/%i) %17s [%10s]: %20s ...\n" , +"Originator" ,"last-seen" ,"#" ,BATADV_TQ_MAX_VALUE , +"Nexthop" ,"outgoingIF" ,"Potential nexthops" );This header printf really doesn't add much with the formatting sizes. It's pretty obscure why some of these are sized and others not sized. For instance: %-15s doesn't refer to a mac address size. Perhaps it'd be better to just emit the fixed string just using
BATADV_TO_MAX_VALUE. It'd also be easier to find via grep.
This string is printed out of a debugfs file and follows a format that we have been using for long time (this patch is just moving this code from one point to another).
I didn't get what you mean with BATADV_TO_MAX_VALUE (maybe you meant BATADV_TQ_MAX_VALUE? but even in this case I don't get it).
The sized parameters in the format string are such that this header is correctly aligned with the entries of the table that follow.
Moreover we tried to keep this table human readable as much as possible.
Here you have an example of what we get (this output is not printed with exactly that format string because it belongs to an older batman-adv version)
[B.A.T.M.A.N. adv 2013.3.0, MainIF/MAC: mesh0/xx:xx:xx:xx:xx:xx (bat0)]
Originator last-seen (#/255) Nexthop [outgoingIF]: Potential nexthops ...
yyyy 4.720s (247) yyyy [ mesh0]: aaaaa (221) bbbbbb (200)
aaaaa 4.270s (237) ddddd [ mesh0]: aaaa (195) vvvvvv (215)
bbbbbb 4.480s (248) cccccc [ mesh0]: bbbb (213) cccccc (200)
ccccc 0.480s (255) bbbbb [ mesh0]: cccc (217) dddddd (190)
dddddd 1.050s (223) dddddd [ mesh0]: dddddd (191) eeee (203)If the width of your terminal is adequate you get a nice table which is rather helpful for debugging purposes.
Regards,
Signature · 1 line
Antonio Quartulli
Re: [PATCH 03/16] batman-adv: add bat_orig_print API function
In reply to a message not in the archiveQuoted 22 lines · Antonio Quartulli
Quoted 11 lines · Joe Perches
Quoted 6 lines · Antonio Quartulli
Each routing protocol has its own metric and private variables, therefore it is useful to introduce a new API for originator information printing.
This API needs to be implemented by each protocol in order to provide its specific originator table output.
[]
net/batman-adv/bat_iv_ogm.c static int batadv_iv_ogm_receive(struct sk_buff *skb, · line 1420
Quoted 2 lines
net/batman-adv/bat_iv_ogm.c +2
-0+static void batadv_iv_ogm_orig_print (struct batadv_priv *bat_priv, +struct seq_file *seq)[]
Quoted 9 lines
net/batman-adv/bat_iv_ogm.c static int batadv_iv_ogm_receive(struct sk_buff *skb, · line 1433
Quoted 3 lines
net/batman-adv/bat_iv_ogm.c +3
-0+seq_printf (seq," %-15s %s (%s/%i) %17s [%10s]: %20s ...\n" , +"Originator" ,"last-seen" ,"#" ,BATADV_TQ_MAX_VALUE , +"Nexthop" ,"outgoingIF" ,"Potential nexthops" );This header printf really doesn't add much with the formatting sizes. It's pretty obscure why some of these are sized and others not sized. For instance: %-15s doesn't refer to a mac address size. Perhaps it'd be better to just emit the fixed string just using
BATADV_TO_MAX_VALUE. It'd also be easier to find via grep.
Quoted 3 lines
This string is printed out of a debugfs file and follows a format that we have been using for long time (this patch is just moving this code from one point to another).
I saw.
Quoted 2 lines
I didn't get what you mean with
BATADV_TO_MAX_VALUE(maybe you meantBATADV_TQ_MAX_VALUE? but even in this case I don't get it).
Yeah, TQ not TO. Both look similar with squiggles underneath them when using spell checking.
It's a #define, all the others are fixed strings.
Anyway, using
seq_printf(seq, " Originator last-seen (#/%d) Nexthop [outgoingIF]: Potential nexthops ...\n", BATADV_TQ_MAX_VALUE);
is probably trivially smaller overall code size too.
Your code, you decide...
cheers, Joe
Re: [PATCH 03/16] batman-adv: add bat_orig_print API function
Quoted 35 lines · Joe Perches
Quoted 22 lines · Antonio Quartulli
Quoted 11 lines · Joe Perches
Quoted 6 lines · Antonio Quartulli
Each routing protocol has its own metric and private variables, therefore it is useful to introduce a new API for originator information printing.
This API needs to be implemented by each protocol in order to provide its specific originator table output.
[]
net/batman-adv/bat_iv_ogm.c static int batadv_iv_ogm_receive(struct sk_buff *skb, · line 1420
Quoted 2 lines
net/batman-adv/bat_iv_ogm.c +2
-0+static void batadv_iv_ogm_orig_print (struct batadv_priv *bat_priv, +struct seq_file *seq)[]
Quoted 9 lines
net/batman-adv/bat_iv_ogm.c static int batadv_iv_ogm_receive(struct sk_buff *skb, · line 1433
Quoted 3 lines
net/batman-adv/bat_iv_ogm.c +3
-0+seq_printf (seq," %-15s %s (%s/%i) %17s [%10s]: %20s ...\n" , +"Originator" ,"last-seen" ,"#" ,BATADV_TQ_MAX_VALUE , +"Nexthop" ,"outgoingIF" ,"Potential nexthops" );This header printf really doesn't add much with the formatting sizes. It's pretty obscure why some of these are sized and others not sized. For instance: %-15s doesn't refer to a mac address size. Perhaps it'd be better to just emit the fixed string just using
BATADV_TO_MAX_VALUE. It'd also be easier to find via grep.Quoted 3 lines
This string is printed out of a debugfs file and follows a format that we have been using for long time (this patch is just moving this code from one point to another).
I saw.
Quoted 2 lines
I didn't get what you mean with
BATADV_TO_MAX_VALUE(maybe you meantBATADV_TQ_MAX_VALUE? but even in this case I don't get it).Yeah, TQ not TO. Both look similar with squiggles underneath them when using spell checking.
Quoted 8 lines
It's a #define, all the others are fixed strings.
Anyway, using
seq_printf(seq, " Originator last-seen (#/%d) Nexthop [outgoingIF]: Potential nexthops ...\n", BATADV_TQ_MAX_VALUE);is probably trivially smaller overall code size too.
Your code, you decide...
Now I fully understand your point.
Honestly I agree with you, but this string is there since a while and I'd like to get a feedback from the other guys before changing it.
If for David it is not a problem I'd like keep it like that and I'll discuss and possibly add this change (this is not the only header in the code printed this way) later.
Thanks a lot for your feedback!
Cheers,
Signature · 1 line
Antonio Quartulli
David Miller
maintainerFrom: Antonio Quartulli <[email protected]>
Date: Wed, 23 Oct 2013 18:04:47 +0200
Quoted 21 lines
this is another set of changes intended for net-next/linux-3.13. (probably our last pull request for this cycle)
Patches 1 and 2 reshape two of our main data structures in a way that they can easily be extended in the future to accommodate new routing protocols.
Patches from 3 to 9 improve our routing protocol API and its users so that all the protocol-related code is not mixed up with the other components anymore.
Patch 10 limits the local Translation Table maximum size to a value such that it can be fully transfered over the air if needed. This value depends on fragmentation being enabled or not and on the mtu values.
Patch 11 makes batman-adv send a uevent in case of soft-interface destruction while a "bat-Gateway" was configured (this informs userspace about the GW not being available anymore).
Patches 13 and 14 enable the TT component to detect non-mesh client flag changes at runtime (till now those flags where set upon client detection and were not changed anymore).
Quoted 6 lines
Patch 16 is a generalisation of our user-to-kernel space communication (and viceversa) used to exchange ICMP packets to send/received to/from the mesh network. Now it can easily accommodate new ICMP packet types without breaking the existing userspace API anymore.
Remaining patches are minor changes and cleanups.
Pulled, thanks Antonio.