batman-adv: provide orig_node routing API
PATCH v8 1/2 batman-adv: provide orig_node routing API
From: 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)
---
changes from v7:
- removed batadv_orig_node_del_if() (it has been accidentally re-introduced during the last rebase)
Cheers,
bat_iv_ogm.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ originator.c | 102 +++++++---------------------------------------- types.h | 11 ++++++ 3 files changed, 151 insertions(+), 88 deletions(-)
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 )
originator.c +14 -88
143 lines not on this page · raw message
types.h +11 -0
@@ -999,6 +999,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;
@@ -1015,6 +1021,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.1.5
PATCH v8 2/2 batman-adv: adapt the TT component to use the new API functions
From: Antonio Quartulli <[email protected]>
--- translation-table.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-)
translation-table.c +24 -11
@@ -1339,18 +1339,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) {
@@ -1358,26 +1360,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;
@@ -1390,7 +1403,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);
@@ -1479,7 +1492,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 (); }
@@ -1867,7 +1880,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.1.5
Marek Lindner
AppliedRe: [B.A.T.M.A.N.] [PATCHv8 2/2] batman-adv: adapt the TT component to use the new API functions
Quoted 6 lines · On Tuesday, September 03, 2013 17:10:24 Antonio Quartulli wrote:
From: Antonio Quartulli <[email protected]>
Signed-off-by Antonio Quartulli <[email protected]>--- translation-table.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-)
Applied in revision a468009.
Thanks,
Marek
Marek Lindner
AppliedQuoted 25 lines · On Tuesday, September 03, 2013 17:10:23 Antonio Quartulli wrote:
From: Antonio Quartulli <[email protected]>
Some operations executed on an
orig_nodedepends on the current routing algorithm being used. To easily make this mechanism routing algorithm agnostic add aorig_nodespecific 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 anorig_nodewhen a new hard interface is added)
-orig_del_if(to change the inner state of anorig_nodewhen an hard interface is removed)Signed-off-by Antonio Quartulli <[email protected]>---
changes from v7:
- removedbatadv_orig_node_del_if()(it has been accidentally re-introduced during the last rebase)
Quoted 8 lines
Cheers,
bat_iv_ogm.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ originator.c | 102 +++++++---------------------------------------- types.h | 11 ++++++ 3 files changed, 151 insertions(+), 88 deletions(-)
Applied in revision fdafa7d.
Thanks,
Marek