Skip to content

Commit

Permalink
batman-adv: split routing API data structure in subobjects
Browse files Browse the repository at this point in the history
The routing API data structure contains several function
pointers that can easily be grouped together based on the
component they work with.

Split the API in subobjects in order to improve definition readability.

At the same time, remove the "bat_" prefix from the API object and
its fields names. These are batman-adv private structs and there is no
need to always prepend such prefix, which only makes function invocations
much much longer.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Reviewed-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
  • Loading branch information
Antonio Quartulli authored and Simon Wunderlich committed Jul 4, 2016
1 parent 33a3bb4 commit 29824a5
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 124 deletions.
14 changes: 7 additions & 7 deletions net/batman-adv/bat_algo.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
}

/* all algorithms must implement all ops (for now) */
if (!bat_algo_ops->bat_iface_enable ||
!bat_algo_ops->bat_iface_disable ||
!bat_algo_ops->bat_iface_update_mac ||
!bat_algo_ops->bat_primary_iface_set ||
!bat_algo_ops->bat_neigh_cmp ||
!bat_algo_ops->bat_neigh_is_similar_or_better) {
if (!bat_algo_ops->iface.enable ||
!bat_algo_ops->iface.disable ||
!bat_algo_ops->iface.update_mac ||
!bat_algo_ops->iface.primary_set ||
!bat_algo_ops->neigh.cmp ||
!bat_algo_ops->neigh.is_similar_or_better) {
pr_info("Routing algo '%s' does not implement required ops\n",
bat_algo_ops->name);
return -EINVAL;
Expand All @@ -90,7 +90,7 @@ int batadv_algo_select(struct batadv_priv *bat_priv, char *name)
if (!bat_algo_ops)
return -EINVAL;

bat_priv->bat_algo_ops = bat_algo_ops;
bat_priv->algo_ops = bat_algo_ops;

return 0;
}
Expand Down
33 changes: 19 additions & 14 deletions net/batman-adv/bat_iv_ogm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1853,8 +1853,7 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
/* did we receive a B.A.T.M.A.N. IV OGM packet on an interface
* that does not have B.A.T.M.A.N. IV enabled ?
*/
if (bat_priv->bat_algo_ops->bat_iface_enable !=
batadv_iv_ogm_iface_enable)
if (bat_priv->algo_ops->iface.enable != batadv_iv_ogm_iface_enable)
return NET_RX_DROP;

batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX);
Expand Down Expand Up @@ -2120,18 +2119,24 @@ static void batadv_iv_iface_activate(struct batadv_hard_iface *hard_iface)

static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
.name = "BATMAN_IV",
.bat_iface_activate = batadv_iv_iface_activate,
.bat_iface_enable = batadv_iv_ogm_iface_enable,
.bat_iface_disable = batadv_iv_ogm_iface_disable,
.bat_iface_update_mac = batadv_iv_ogm_iface_update_mac,
.bat_primary_iface_set = batadv_iv_ogm_primary_iface_set,
.bat_neigh_cmp = batadv_iv_ogm_neigh_cmp,
.bat_neigh_is_similar_or_better = batadv_iv_ogm_neigh_is_sob,
.bat_neigh_print = batadv_iv_neigh_print,
.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,
.iface = {
.activate = batadv_iv_iface_activate,
.enable = batadv_iv_ogm_iface_enable,
.disable = batadv_iv_ogm_iface_disable,
.update_mac = batadv_iv_ogm_iface_update_mac,
.primary_set = batadv_iv_ogm_primary_iface_set,
},
.neigh = {
.cmp = batadv_iv_ogm_neigh_cmp,
.is_similar_or_better = batadv_iv_ogm_neigh_is_sob,
.print = batadv_iv_neigh_print,
},
.orig = {
.print = batadv_iv_ogm_orig_print,
.free = batadv_iv_ogm_orig_free,
.add_if = batadv_iv_ogm_orig_add_if,
.del_if = batadv_iv_ogm_orig_del_if,
},
};

int __init batadv_iv_init(void)
Expand Down
26 changes: 16 additions & 10 deletions net/batman-adv/bat_v.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,22 @@ static bool batadv_v_neigh_is_sob(struct batadv_neigh_node *neigh1,

static struct batadv_algo_ops batadv_batman_v __read_mostly = {
.name = "BATMAN_V",
.bat_iface_activate = batadv_v_iface_activate,
.bat_iface_enable = batadv_v_iface_enable,
.bat_iface_disable = batadv_v_iface_disable,
.bat_iface_update_mac = batadv_v_iface_update_mac,
.bat_primary_iface_set = batadv_v_primary_iface_set,
.bat_hardif_neigh_init = batadv_v_hardif_neigh_init,
.bat_orig_print = batadv_v_orig_print,
.bat_neigh_cmp = batadv_v_neigh_cmp,
.bat_neigh_is_similar_or_better = batadv_v_neigh_is_sob,
.bat_neigh_print = batadv_v_neigh_print,
.iface = {
.activate = batadv_v_iface_activate,
.enable = batadv_v_iface_enable,
.disable = batadv_v_iface_disable,
.update_mac = batadv_v_iface_update_mac,
.primary_set = batadv_v_primary_iface_set,
},
.neigh = {
.hardif_init = batadv_v_hardif_neigh_init,
.cmp = batadv_v_neigh_cmp,
.is_similar_or_better = batadv_v_neigh_is_sob,
.print = batadv_v_neigh_print,
},
.orig = {
.print = batadv_v_orig_print,
},
};

/**
Expand Down
2 changes: 1 addition & 1 deletion net/batman-adv/bat_v_elp.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ int batadv_v_elp_packet_recv(struct sk_buff *skb,
/* did we receive a B.A.T.M.A.N. V ELP packet on an interface
* that does not have B.A.T.M.A.N. V ELP enabled ?
*/
if (strcmp(bat_priv->bat_algo_ops->name, "BATMAN_V") != 0)
if (strcmp(bat_priv->algo_ops->name, "BATMAN_V") != 0)
return NET_RX_DROP;

elp_packet = (struct batadv_elp_packet *)skb->data;
Expand Down
2 changes: 1 addition & 1 deletion net/batman-adv/bat_v_ogm.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ int batadv_v_ogm_packet_recv(struct sk_buff *skb,
/* did we receive a OGM2 packet on an interface that does not have
* B.A.T.M.A.N. V enabled ?
*/
if (strcmp(bat_priv->bat_algo_ops->name, "BATMAN_V") != 0)
if (strcmp(bat_priv->algo_ops->name, "BATMAN_V") != 0)
return NET_RX_DROP;

if (!batadv_check_management_packet(skb, if_incoming, BATADV_OGM2_HLEN))
Expand Down
16 changes: 8 additions & 8 deletions net/batman-adv/hard-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static void batadv_primary_if_select(struct batadv_priv *bat_priv,
if (!new_hard_iface)
goto out;

bat_priv->bat_algo_ops->bat_primary_iface_set(new_hard_iface);
bat_priv->algo_ops->iface.primary_set(new_hard_iface);
batadv_primary_if_update_addr(bat_priv, curr_hard_iface);

out:
Expand Down Expand Up @@ -394,7 +394,7 @@ batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface)

bat_priv = netdev_priv(hard_iface->soft_iface);

bat_priv->bat_algo_ops->bat_iface_update_mac(hard_iface);
bat_priv->algo_ops->iface.update_mac(hard_iface);
hard_iface->if_status = BATADV_IF_TO_BE_ACTIVATED;

/* the first active interface becomes our primary interface or
Expand All @@ -409,8 +409,8 @@ batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface)

batadv_update_min_mtu(hard_iface->soft_iface);

if (bat_priv->bat_algo_ops->bat_iface_activate)
bat_priv->bat_algo_ops->bat_iface_activate(hard_iface);
if (bat_priv->algo_ops->iface.activate)
bat_priv->algo_ops->iface.activate(hard_iface);

out:
if (primary_if)
Expand Down Expand Up @@ -508,7 +508,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
if (ret)
goto err_dev;

ret = bat_priv->bat_algo_ops->bat_iface_enable(hard_iface);
ret = bat_priv->algo_ops->iface.enable(hard_iface);
if (ret < 0)
goto err_upper;

Expand All @@ -517,7 +517,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
hard_iface->if_status = BATADV_IF_INACTIVE;
ret = batadv_orig_hash_add_if(hard_iface, bat_priv->num_ifaces);
if (ret < 0) {
bat_priv->bat_algo_ops->bat_iface_disable(hard_iface);
bat_priv->algo_ops->iface.disable(hard_iface);
bat_priv->num_ifaces--;
hard_iface->if_status = BATADV_IF_NOT_IN_USE;
goto err_upper;
Expand Down Expand Up @@ -598,7 +598,7 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
batadv_hardif_put(new_if);
}

bat_priv->bat_algo_ops->bat_iface_disable(hard_iface);
bat_priv->algo_ops->iface.disable(hard_iface);
hard_iface->if_status = BATADV_IF_NOT_IN_USE;

/* delete all references to this hard_iface */
Expand Down Expand Up @@ -783,7 +783,7 @@ static int batadv_hard_if_event(struct notifier_block *this,
batadv_check_known_mac_addr(hard_iface->net_dev);

bat_priv = netdev_priv(hard_iface->soft_iface);
bat_priv->bat_algo_ops->bat_iface_update_mac(hard_iface);
bat_priv->algo_ops->iface.update_mac(hard_iface);

primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if)
Expand Down
2 changes: 1 addition & 1 deletion net/batman-adv/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ batadv_netlink_mesh_info_put(struct sk_buff *msg, struct net_device *soft_iface)

if (nla_put_string(msg, BATADV_ATTR_VERSION, BATADV_SOURCE_VERSION) ||
nla_put_string(msg, BATADV_ATTR_ALGO_NAME,
bat_priv->bat_algo_ops->name) ||
bat_priv->algo_ops->name) ||
nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, soft_iface->ifindex) ||
nla_put_string(msg, BATADV_ATTR_MESH_IFNAME, soft_iface->name) ||
nla_put(msg, BATADV_ATTR_MESH_ADDRESS, ETH_ALEN,
Expand Down
49 changes: 23 additions & 26 deletions net/batman-adv/originator.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ batadv_hardif_neigh_create(struct batadv_hard_iface *hard_iface,

kref_init(&hardif_neigh->refcount);

if (bat_priv->bat_algo_ops->bat_hardif_neigh_init)
bat_priv->bat_algo_ops->bat_hardif_neigh_init(hardif_neigh);
if (bat_priv->algo_ops->neigh.hardif_init)
bat_priv->algo_ops->neigh.hardif_init(hardif_neigh);

hlist_add_head(&hardif_neigh->list, &hard_iface->neigh_list);

Expand Down Expand Up @@ -706,17 +706,17 @@ int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset)
seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n",
BATADV_SOURCE_VERSION, primary_if->net_dev->name,
primary_if->net_dev->dev_addr, net_dev->name,
bat_priv->bat_algo_ops->name);
bat_priv->algo_ops->name);

batadv_hardif_put(primary_if);

if (!bat_priv->bat_algo_ops->bat_neigh_print) {
if (!bat_priv->algo_ops->neigh.print) {
seq_puts(seq,
"No printing function for this routing protocol\n");
return 0;
}

bat_priv->bat_algo_ops->bat_neigh_print(bat_priv, seq);
bat_priv->algo_ops->neigh.print(bat_priv, seq);
return 0;
}

Expand Down Expand Up @@ -767,8 +767,8 @@ static void batadv_orig_node_free_rcu(struct rcu_head *rcu)

batadv_frag_purge_orig(orig_node, NULL);

if (orig_node->bat_priv->bat_algo_ops->bat_orig_free)
orig_node->bat_priv->bat_algo_ops->bat_orig_free(orig_node);
if (orig_node->bat_priv->algo_ops->orig.free)
orig_node->bat_priv->algo_ops->orig.free(orig_node);

kfree(orig_node->tt_buff);
kfree(orig_node);
Expand Down Expand Up @@ -1097,12 +1097,12 @@ batadv_find_best_neighbor(struct batadv_priv *bat_priv,
struct batadv_hard_iface *if_outgoing)
{
struct batadv_neigh_node *best = NULL, *neigh;
struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;
struct batadv_algo_ops *bao = bat_priv->algo_ops;

rcu_read_lock();
hlist_for_each_entry_rcu(neigh, &orig_node->neigh_list, list) {
if (best && (bao->bat_neigh_cmp(neigh, if_outgoing,
best, if_outgoing) <= 0))
if (best && (bao->neigh.cmp(neigh, if_outgoing, best,
if_outgoing) <= 0))
continue;

if (!kref_get_unless_zero(&neigh->refcount))
Expand Down Expand Up @@ -1254,18 +1254,17 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)
seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n",
BATADV_SOURCE_VERSION, primary_if->net_dev->name,
primary_if->net_dev->dev_addr, net_dev->name,
bat_priv->bat_algo_ops->name);
bat_priv->algo_ops->name);

batadv_hardif_put(primary_if);

if (!bat_priv->bat_algo_ops->bat_orig_print) {
if (!bat_priv->algo_ops->orig.print) {
seq_puts(seq,
"No printing function for this routing protocol\n");
return 0;
}

bat_priv->bat_algo_ops->bat_orig_print(bat_priv, seq,
BATADV_IF_DEFAULT);
bat_priv->algo_ops->orig.print(bat_priv, seq, BATADV_IF_DEFAULT);

return 0;
}
Expand All @@ -1292,7 +1291,7 @@ int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset)
}

bat_priv = netdev_priv(hard_iface->soft_iface);
if (!bat_priv->bat_algo_ops->bat_orig_print) {
if (!bat_priv->algo_ops->orig.print) {
seq_puts(seq,
"No printing function for this routing protocol\n");
goto out;
Expand All @@ -1306,9 +1305,9 @@ int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset)
seq_printf(seq, "[B.A.T.M.A.N. adv %s, IF/MAC: %s/%pM (%s %s)]\n",
BATADV_SOURCE_VERSION, hard_iface->net_dev->name,
hard_iface->net_dev->dev_addr,
hard_iface->soft_iface->name, bat_priv->bat_algo_ops->name);
hard_iface->soft_iface->name, bat_priv->algo_ops->name);

bat_priv->bat_algo_ops->bat_orig_print(bat_priv, seq, hard_iface);
bat_priv->algo_ops->orig.print(bat_priv, seq, hard_iface);

out:
if (hard_iface)
Expand All @@ -1320,7 +1319,7 @@ int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
int max_if_num)
{
struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;
struct batadv_algo_ops *bao = bat_priv->algo_ops;
struct batadv_hashtable *hash = bat_priv->orig_hash;
struct hlist_head *head;
struct batadv_orig_node *orig_node;
Expand All @@ -1336,9 +1335,8 @@ int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
rcu_read_lock();
hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
ret = 0;
if (bao->bat_orig_add_if)
ret = bao->bat_orig_add_if(orig_node,
max_if_num);
if (bao->orig.add_if)
ret = bao->orig.add_if(orig_node, max_if_num);
if (ret == -ENOMEM)
goto err;
}
Expand All @@ -1360,7 +1358,7 @@ int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
struct hlist_head *head;
struct batadv_hard_iface *hard_iface_tmp;
struct batadv_orig_node *orig_node;
struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;
struct batadv_algo_ops *bao = bat_priv->algo_ops;
u32 i;
int ret;

Expand All @@ -1373,10 +1371,9 @@ int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
rcu_read_lock();
hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
ret = 0;
if (bao->bat_orig_del_if)
ret = bao->bat_orig_del_if(orig_node,
max_if_num,
hard_iface->if_num);
if (bao->orig.del_if)
ret = bao->orig.del_if(orig_node, max_if_num,
hard_iface->if_num);
if (ret == -ENOMEM)
goto err;
}
Expand Down
8 changes: 4 additions & 4 deletions net/batman-adv/routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ batadv_find_router(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node,
struct batadv_hard_iface *recv_if)
{
struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;
struct batadv_algo_ops *bao = bat_priv->algo_ops;
struct batadv_neigh_node *first_candidate_router = NULL;
struct batadv_neigh_node *next_candidate_router = NULL;
struct batadv_neigh_node *router, *cand_router = NULL;
Expand Down Expand Up @@ -536,9 +536,9 @@ batadv_find_router(struct batadv_priv *bat_priv,
/* alternative candidate should be good enough to be
* considered
*/
if (!bao->bat_neigh_is_similar_or_better(cand_router,
cand->if_outgoing,
router, recv_if))
if (!bao->neigh.is_similar_or_better(cand_router,
cand->if_outgoing, router,
recv_if))
goto next;

/* don't use the same router twice */
Expand Down
2 changes: 1 addition & 1 deletion net/batman-adv/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ static ssize_t batadv_show_bat_algo(struct kobject *kobj,
{
struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);

return sprintf(buff, "%s\n", bat_priv->bat_algo_ops->name);
return sprintf(buff, "%s\n", bat_priv->algo_ops->name);
}

static void batadv_post_gw_reselect(struct net_device *net_dev)
Expand Down
6 changes: 3 additions & 3 deletions net/batman-adv/translation-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ batadv_transtable_best_orig(struct batadv_priv *bat_priv,
struct batadv_tt_global_entry *tt_global_entry)
{
struct batadv_neigh_node *router, *best_router = NULL;
struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;
struct batadv_algo_ops *bao = bat_priv->algo_ops;
struct hlist_head *head;
struct batadv_tt_orig_list_entry *orig_entry, *best_entry = NULL;

Expand All @@ -1558,8 +1558,8 @@ batadv_transtable_best_orig(struct batadv_priv *bat_priv,
continue;

if (best_router &&
bao->bat_neigh_cmp(router, BATADV_IF_DEFAULT,
best_router, BATADV_IF_DEFAULT) <= 0) {
bao->neigh.cmp(router, BATADV_IF_DEFAULT, best_router,
BATADV_IF_DEFAULT) <= 0) {
batadv_neigh_node_put(router);
continue;
}
Expand Down
Loading

0 comments on commit 29824a5

Please sign in to comment.