aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntonio Quartulli <a@unstable.cc>2016-05-02 13:45:34 -0400
committerSimon Wunderlich <sw@simonwunderlich.de>2016-06-30 04:29:43 -0400
commitf0d97253fb5fe87a7a91e7dc1ba4becf9d89d896 (patch)
tree27471c975778b980fb4f06f1b8dc555f6ea32296
parentd9f179877e50ae2681fe7b0b83e0d9f63b6165ad (diff)
batman-adv: remove ogm_emit and ogm_schedule API calls
The ogm_emit and ogm_schedule API calls were rather tight to the B.A.T.M.A.N. IV logic and therefore rather difficult to use with other algorithm implementations. Remove such calls and move the surrounding logic into the B.A.T.M.A.N. IV specific code. Signed-off-by: Antonio Quartulli <a@unstable.cc> Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch> Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
-rw-r--r--net/batman-adv/bat_iv_ogm.c69
-rw-r--r--net/batman-adv/bat_v.c10
-rw-r--r--net/batman-adv/hard-interface.c3
-rw-r--r--net/batman-adv/main.c2
-rw-r--r--net/batman-adv/send.c61
-rw-r--r--net/batman-adv/send.h4
-rw-r--r--net/batman-adv/types.h4
7 files changed, 67 insertions, 86 deletions
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index aa11296e6bf8..4815db978c27 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -30,6 +30,7 @@
30#include <linux/if_ether.h> 30#include <linux/if_ether.h>
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/jiffies.h> 32#include <linux/jiffies.h>
33#include <linux/kernel.h>
33#include <linux/list.h> 34#include <linux/list.h>
34#include <linux/kref.h> 35#include <linux/kref.h>
35#include <linux/lockdep.h> 36#include <linux/lockdep.h>
@@ -58,6 +59,8 @@
58#include "send.h" 59#include "send.h"
59#include "translation-table.h" 60#include "translation-table.h"
60 61
62static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work);
63
61/** 64/**
62 * enum batadv_dup_status - duplicate status 65 * enum batadv_dup_status - duplicate status
63 * @BATADV_NO_DUP: the packet is no duplicate 66 * @BATADV_NO_DUP: the packet is no duplicate
@@ -731,7 +734,7 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
731 734
732 /* start timer for this packet */ 735 /* start timer for this packet */
733 INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work, 736 INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work,
734 batadv_send_outstanding_bat_ogm_packet); 737 batadv_iv_send_outstanding_bat_ogm_packet);
735 queue_delayed_work(batadv_event_workqueue, 738 queue_delayed_work(batadv_event_workqueue,
736 &forw_packet_aggr->delayed_work, 739 &forw_packet_aggr->delayed_work,
737 send_time - jiffies); 740 send_time - jiffies);
@@ -938,6 +941,19 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
938 u16 tvlv_len = 0; 941 u16 tvlv_len = 0;
939 unsigned long send_time; 942 unsigned long send_time;
940 943
944 if ((hard_iface->if_status == BATADV_IF_NOT_IN_USE) ||
945 (hard_iface->if_status == BATADV_IF_TO_BE_REMOVED))
946 return;
947
948 /* the interface gets activated here to avoid race conditions between
949 * the moment of activating the interface in
950 * hardif_activate_interface() where the originator mac is set and
951 * outdated packets (especially uninitialized mac addresses) in the
952 * packet queue
953 */
954 if (hard_iface->if_status == BATADV_IF_TO_BE_ACTIVATED)
955 hard_iface->if_status = BATADV_IF_ACTIVE;
956
941 primary_if = batadv_primary_if_get_selected(bat_priv); 957 primary_if = batadv_primary_if_get_selected(bat_priv);
942 958
943 if (hard_iface == primary_if) { 959 if (hard_iface == primary_if) {
@@ -1779,6 +1795,45 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
1779 batadv_orig_node_put(orig_node); 1795 batadv_orig_node_put(orig_node);
1780} 1796}
1781 1797
1798static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work)
1799{
1800 struct delayed_work *delayed_work;
1801 struct batadv_forw_packet *forw_packet;
1802 struct batadv_priv *bat_priv;
1803
1804 delayed_work = to_delayed_work(work);
1805 forw_packet = container_of(delayed_work, struct batadv_forw_packet,
1806 delayed_work);
1807 bat_priv = netdev_priv(forw_packet->if_incoming->soft_iface);
1808 spin_lock_bh(&bat_priv->forw_bat_list_lock);
1809 hlist_del(&forw_packet->list);
1810 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
1811
1812 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
1813 goto out;
1814
1815 batadv_iv_ogm_emit(forw_packet);
1816
1817 /* we have to have at least one packet in the queue to determine the
1818 * queues wake up time unless we are shutting down.
1819 *
1820 * only re-schedule if this is the "original" copy, e.g. the OGM of the
1821 * primary interface should only be rescheduled once per period, but
1822 * this function will be called for the forw_packet instances of the
1823 * other secondary interfaces as well.
1824 */
1825 if (forw_packet->own &&
1826 forw_packet->if_incoming == forw_packet->if_outgoing)
1827 batadv_iv_ogm_schedule(forw_packet->if_incoming);
1828
1829out:
1830 /* don't count own packet */
1831 if (!forw_packet->own)
1832 atomic_inc(&bat_priv->batman_queue_left);
1833
1834 batadv_forw_packet_free(forw_packet);
1835}
1836
1782static int batadv_iv_ogm_receive(struct sk_buff *skb, 1837static int batadv_iv_ogm_receive(struct sk_buff *skb,
1783 struct batadv_hard_iface *if_incoming) 1838 struct batadv_hard_iface *if_incoming)
1784{ 1839{
@@ -1795,7 +1850,8 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
1795 /* did we receive a B.A.T.M.A.N. IV OGM packet on an interface 1850 /* did we receive a B.A.T.M.A.N. IV OGM packet on an interface
1796 * that does not have B.A.T.M.A.N. IV enabled ? 1851 * that does not have B.A.T.M.A.N. IV enabled ?
1797 */ 1852 */
1798 if (bat_priv->bat_algo_ops->bat_ogm_emit != batadv_iv_ogm_emit) 1853 if (bat_priv->bat_algo_ops->bat_iface_enable !=
1854 batadv_iv_ogm_iface_enable)
1799 return NET_RX_DROP; 1855 return NET_RX_DROP;
1800 1856
1801 batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX); 1857 batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX);
@@ -2053,14 +2109,19 @@ out:
2053 return ret; 2109 return ret;
2054} 2110}
2055 2111
2112static void batadv_iv_iface_activate(struct batadv_hard_iface *hard_iface)
2113{
2114 /* begin scheduling originator messages on that interface */
2115 batadv_iv_ogm_schedule(hard_iface);
2116}
2117
2056static struct batadv_algo_ops batadv_batman_iv __read_mostly = { 2118static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
2057 .name = "BATMAN_IV", 2119 .name = "BATMAN_IV",
2120 .bat_iface_activate = batadv_iv_iface_activate,
2058 .bat_iface_enable = batadv_iv_ogm_iface_enable, 2121 .bat_iface_enable = batadv_iv_ogm_iface_enable,
2059 .bat_iface_disable = batadv_iv_ogm_iface_disable, 2122 .bat_iface_disable = batadv_iv_ogm_iface_disable,
2060 .bat_iface_update_mac = batadv_iv_ogm_iface_update_mac, 2123 .bat_iface_update_mac = batadv_iv_ogm_iface_update_mac,
2061 .bat_primary_iface_set = batadv_iv_ogm_primary_iface_set, 2124 .bat_primary_iface_set = batadv_iv_ogm_primary_iface_set,
2062 .bat_ogm_schedule = batadv_iv_ogm_schedule,
2063 .bat_ogm_emit = batadv_iv_ogm_emit,
2064 .bat_neigh_cmp = batadv_iv_ogm_neigh_cmp, 2125 .bat_neigh_cmp = batadv_iv_ogm_neigh_cmp,
2065 .bat_neigh_is_similar_or_better = batadv_iv_ogm_neigh_is_sob, 2126 .bat_neigh_is_similar_or_better = batadv_iv_ogm_neigh_is_sob,
2066 .bat_neigh_print = batadv_iv_neigh_print, 2127 .bat_neigh_print = batadv_iv_neigh_print,
diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c
index 0a12e5cdd65d..c16cd44a3b4c 100644
--- a/net/batman-adv/bat_v.c
+++ b/net/batman-adv/bat_v.c
@@ -119,14 +119,6 @@ batadv_v_hardif_neigh_init(struct batadv_hardif_neigh_node *hardif_neigh)
119 batadv_v_elp_throughput_metric_update); 119 batadv_v_elp_throughput_metric_update);
120} 120}
121 121
122static void batadv_v_ogm_schedule(struct batadv_hard_iface *hard_iface)
123{
124}
125
126static void batadv_v_ogm_emit(struct batadv_forw_packet *forw_packet)
127{
128}
129
130/** 122/**
131 * batadv_v_orig_print_neigh - print neighbors for the originator table 123 * batadv_v_orig_print_neigh - print neighbors for the originator table
132 * @orig_node: the orig_node for which the neighbors are printed 124 * @orig_node: the orig_node for which the neighbors are printed
@@ -340,8 +332,6 @@ static struct batadv_algo_ops batadv_batman_v __read_mostly = {
340 .bat_iface_update_mac = batadv_v_iface_update_mac, 332 .bat_iface_update_mac = batadv_v_iface_update_mac,
341 .bat_primary_iface_set = batadv_v_primary_iface_set, 333 .bat_primary_iface_set = batadv_v_primary_iface_set,
342 .bat_hardif_neigh_init = batadv_v_hardif_neigh_init, 334 .bat_hardif_neigh_init = batadv_v_hardif_neigh_init,
343 .bat_ogm_emit = batadv_v_ogm_emit,
344 .bat_ogm_schedule = batadv_v_ogm_schedule,
345 .bat_orig_print = batadv_v_orig_print, 335 .bat_orig_print = batadv_v_orig_print,
346 .bat_neigh_cmp = batadv_v_neigh_cmp, 336 .bat_neigh_cmp = batadv_v_neigh_cmp,
347 .bat_neigh_is_similar_or_better = batadv_v_neigh_is_sob, 337 .bat_neigh_is_similar_or_better = batadv_v_neigh_is_sob,
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 8c2f39962fa5..db2009d84a25 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -553,9 +553,6 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
553 553
554 batadv_hardif_recalc_extra_skbroom(soft_iface); 554 batadv_hardif_recalc_extra_skbroom(soft_iface);
555 555
556 /* begin scheduling originator messages on that interface */
557 batadv_schedule_bat_ogm(hard_iface);
558
559out: 556out:
560 return 0; 557 return 0;
561 558
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 5f2974bd1227..627d14ececaf 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -569,8 +569,6 @@ int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
569 !bat_algo_ops->bat_iface_disable || 569 !bat_algo_ops->bat_iface_disable ||
570 !bat_algo_ops->bat_iface_update_mac || 570 !bat_algo_ops->bat_iface_update_mac ||
571 !bat_algo_ops->bat_primary_iface_set || 571 !bat_algo_ops->bat_primary_iface_set ||
572 !bat_algo_ops->bat_ogm_schedule ||
573 !bat_algo_ops->bat_ogm_emit ||
574 !bat_algo_ops->bat_neigh_cmp || 572 !bat_algo_ops->bat_neigh_cmp ||
575 !bat_algo_ops->bat_neigh_is_similar_or_better) { 573 !bat_algo_ops->bat_neigh_is_similar_or_better) {
576 pr_info("Routing algo '%s' does not implement required ops\n", 574 pr_info("Routing algo '%s' does not implement required ops\n",
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index b1a4e8a811c8..59e695b5cfbd 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -428,27 +428,7 @@ int batadv_send_skb_via_gw(struct batadv_priv *bat_priv, struct sk_buff *skb,
428 orig_node, vid); 428 orig_node, vid);
429} 429}
430 430
431void batadv_schedule_bat_ogm(struct batadv_hard_iface *hard_iface) 431void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet)
432{
433 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
434
435 if ((hard_iface->if_status == BATADV_IF_NOT_IN_USE) ||
436 (hard_iface->if_status == BATADV_IF_TO_BE_REMOVED))
437 return;
438
439 /* the interface gets activated here to avoid race conditions between
440 * the moment of activating the interface in
441 * hardif_activate_interface() where the originator mac is set and
442 * outdated packets (especially uninitialized mac addresses) in the
443 * packet queue
444 */
445 if (hard_iface->if_status == BATADV_IF_TO_BE_ACTIVATED)
446 hard_iface->if_status = BATADV_IF_ACTIVE;
447
448 bat_priv->bat_algo_ops->bat_ogm_schedule(hard_iface);
449}
450
451static void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet)
452{ 432{
453 kfree_skb(forw_packet->skb); 433 kfree_skb(forw_packet->skb);
454 if (forw_packet->if_incoming) 434 if (forw_packet->if_incoming)
@@ -604,45 +584,6 @@ out:
604 atomic_inc(&bat_priv->bcast_queue_left); 584 atomic_inc(&bat_priv->bcast_queue_left);
605} 585}
606 586
607void batadv_send_outstanding_bat_ogm_packet(struct work_struct *work)
608{
609 struct delayed_work *delayed_work;
610 struct batadv_forw_packet *forw_packet;
611 struct batadv_priv *bat_priv;
612
613 delayed_work = to_delayed_work(work);
614 forw_packet = container_of(delayed_work, struct batadv_forw_packet,
615 delayed_work);
616 bat_priv = netdev_priv(forw_packet->if_incoming->soft_iface);
617 spin_lock_bh(&bat_priv->forw_bat_list_lock);
618 hlist_del(&forw_packet->list);
619 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
620
621 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
622 goto out;
623
624 bat_priv->bat_algo_ops->bat_ogm_emit(forw_packet);
625
626 /* we have to have at least one packet in the queue to determine the
627 * queues wake up time unless we are shutting down.
628 *
629 * only re-schedule if this is the "original" copy, e.g. the OGM of the
630 * primary interface should only be rescheduled once per period, but
631 * this function will be called for the forw_packet instances of the
632 * other secondary interfaces as well.
633 */
634 if (forw_packet->own &&
635 forw_packet->if_incoming == forw_packet->if_outgoing)
636 batadv_schedule_bat_ogm(forw_packet->if_incoming);
637
638out:
639 /* don't count own packet */
640 if (!forw_packet->own)
641 atomic_inc(&bat_priv->batman_queue_left);
642
643 batadv_forw_packet_free(forw_packet);
644}
645
646void 587void
647batadv_purge_outstanding_packets(struct batadv_priv *bat_priv, 588batadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
648 const struct batadv_hard_iface *hard_iface) 589 const struct batadv_hard_iface *hard_iface)
diff --git a/net/batman-adv/send.h b/net/batman-adv/send.h
index 6fd7270d8ce6..7cecb7563b45 100644
--- a/net/batman-adv/send.h
+++ b/net/batman-adv/send.h
@@ -26,8 +26,8 @@
26#include "packet.h" 26#include "packet.h"
27 27
28struct sk_buff; 28struct sk_buff;
29struct work_struct;
30 29
30void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet);
31int batadv_send_skb_to_orig(struct sk_buff *skb, 31int batadv_send_skb_to_orig(struct sk_buff *skb,
32 struct batadv_orig_node *orig_node, 32 struct batadv_orig_node *orig_node,
33 struct batadv_hard_iface *recv_if); 33 struct batadv_hard_iface *recv_if);
@@ -38,11 +38,9 @@ int batadv_send_broadcast_skb(struct sk_buff *skb,
38 struct batadv_hard_iface *hard_iface); 38 struct batadv_hard_iface *hard_iface);
39int batadv_send_unicast_skb(struct sk_buff *skb, 39int batadv_send_unicast_skb(struct sk_buff *skb,
40 struct batadv_neigh_node *neigh_node); 40 struct batadv_neigh_node *neigh_node);
41void batadv_schedule_bat_ogm(struct batadv_hard_iface *hard_iface);
42int batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv, 41int batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv,
43 const struct sk_buff *skb, 42 const struct sk_buff *skb,
44 unsigned long delay); 43 unsigned long delay);
45void batadv_send_outstanding_bat_ogm_packet(struct work_struct *work);
46void 44void
47batadv_purge_outstanding_packets(struct batadv_priv *bat_priv, 45batadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
48 const struct batadv_hard_iface *hard_iface); 46 const struct batadv_hard_iface *hard_iface);
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 114d1509946b..b70b6ae5edae 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -1269,8 +1269,6 @@ struct batadv_forw_packet {
1269 * @bat_iface_update_mac: (re-)init mac addresses of the protocol information 1269 * @bat_iface_update_mac: (re-)init mac addresses of the protocol information
1270 * belonging to this hard-interface 1270 * belonging to this hard-interface
1271 * @bat_primary_iface_set: called when primary interface is selected / changed 1271 * @bat_primary_iface_set: called when primary interface is selected / changed
1272 * @bat_ogm_schedule: prepare a new outgoing OGM for the send queue
1273 * @bat_ogm_emit: send scheduled OGM
1274 * @bat_hardif_neigh_init: called on creation of single hop entry 1272 * @bat_hardif_neigh_init: called on creation of single hop entry
1275 * @bat_neigh_cmp: compare the metrics of two neighbors for their respective 1273 * @bat_neigh_cmp: compare the metrics of two neighbors for their respective
1276 * outgoing interfaces 1274 * outgoing interfaces
@@ -1294,8 +1292,6 @@ struct batadv_algo_ops {
1294 void (*bat_iface_disable)(struct batadv_hard_iface *hard_iface); 1292 void (*bat_iface_disable)(struct batadv_hard_iface *hard_iface);
1295 void (*bat_iface_update_mac)(struct batadv_hard_iface *hard_iface); 1293 void (*bat_iface_update_mac)(struct batadv_hard_iface *hard_iface);
1296 void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface); 1294 void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);
1297 void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);
1298 void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
1299 /* neigh_node handling API */ 1295 /* neigh_node handling API */
1300 void (*bat_hardif_neigh_init)(struct batadv_hardif_neigh_node *neigh); 1296 void (*bat_hardif_neigh_init)(struct batadv_hardif_neigh_node *neigh);
1301 int (*bat_neigh_cmp)(struct batadv_neigh_node *neigh1, 1297 int (*bat_neigh_cmp)(struct batadv_neigh_node *neigh1,