Skip to content

Commit f0d9725

Browse files
ordexsimonwunderlich
authored andcommitted
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 <[email protected]> Signed-off-by: Marek Lindner <[email protected]> Signed-off-by: Sven Eckelmann <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]>
1 parent d9f1798 commit f0d9725

File tree

7 files changed

+67
-86
lines changed

7 files changed

+67
-86
lines changed

net/batman-adv/bat_iv_ogm.c

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/if_ether.h>
3131
#include <linux/init.h>
3232
#include <linux/jiffies.h>
33+
#include <linux/kernel.h>
3334
#include <linux/list.h>
3435
#include <linux/kref.h>
3536
#include <linux/lockdep.h>
@@ -58,6 +59,8 @@
5859
#include "send.h"
5960
#include "translation-table.h"
6061

62+
static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work);
63+
6164
/**
6265
* enum batadv_dup_status - duplicate status
6366
* @BATADV_NO_DUP: the packet is no duplicate
@@ -731,7 +734,7 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
731734

732735
/* start timer for this packet */
733736
INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work,
734-
batadv_send_outstanding_bat_ogm_packet);
737+
batadv_iv_send_outstanding_bat_ogm_packet);
735738
queue_delayed_work(batadv_event_workqueue,
736739
&forw_packet_aggr->delayed_work,
737740
send_time - jiffies);
@@ -938,6 +941,19 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
938941
u16 tvlv_len = 0;
939942
unsigned long send_time;
940943

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+
941957
primary_if = batadv_primary_if_get_selected(bat_priv);
942958

943959
if (hard_iface == primary_if) {
@@ -1779,6 +1795,45 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
17791795
batadv_orig_node_put(orig_node);
17801796
}
17811797

1798+
static 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+
1829+
out:
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+
17821837
static int batadv_iv_ogm_receive(struct sk_buff *skb,
17831838
struct batadv_hard_iface *if_incoming)
17841839
{
@@ -1795,7 +1850,8 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
17951850
/* did we receive a B.A.T.M.A.N. IV OGM packet on an interface
17961851
* that does not have B.A.T.M.A.N. IV enabled ?
17971852
*/
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)
17991855
return NET_RX_DROP;
18001856

18011857
batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX);
@@ -2053,14 +2109,19 @@ batadv_iv_ogm_neigh_is_sob(struct batadv_neigh_node *neigh1,
20532109
return ret;
20542110
}
20552111

2112+
static 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+
20562118
static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
20572119
.name = "BATMAN_IV",
2120+
.bat_iface_activate = batadv_iv_iface_activate,
20582121
.bat_iface_enable = batadv_iv_ogm_iface_enable,
20592122
.bat_iface_disable = batadv_iv_ogm_iface_disable,
20602123
.bat_iface_update_mac = batadv_iv_ogm_iface_update_mac,
20612124
.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,
20642125
.bat_neigh_cmp = batadv_iv_ogm_neigh_cmp,
20652126
.bat_neigh_is_similar_or_better = batadv_iv_ogm_neigh_is_sob,
20662127
.bat_neigh_print = batadv_iv_neigh_print,

net/batman-adv/bat_v.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,6 @@ batadv_v_hardif_neigh_init(struct batadv_hardif_neigh_node *hardif_neigh)
119119
batadv_v_elp_throughput_metric_update);
120120
}
121121

122-
static void batadv_v_ogm_schedule(struct batadv_hard_iface *hard_iface)
123-
{
124-
}
125-
126-
static void batadv_v_ogm_emit(struct batadv_forw_packet *forw_packet)
127-
{
128-
}
129-
130122
/**
131123
* batadv_v_orig_print_neigh - print neighbors for the originator table
132124
* @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 = {
340332
.bat_iface_update_mac = batadv_v_iface_update_mac,
341333
.bat_primary_iface_set = batadv_v_primary_iface_set,
342334
.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,
345335
.bat_orig_print = batadv_v_orig_print,
346336
.bat_neigh_cmp = batadv_v_neigh_cmp,
347337
.bat_neigh_is_similar_or_better = batadv_v_neigh_is_sob,

net/batman-adv/hard-interface.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,6 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
553553

554554
batadv_hardif_recalc_extra_skbroom(soft_iface);
555555

556-
/* begin scheduling originator messages on that interface */
557-
batadv_schedule_bat_ogm(hard_iface);
558-
559556
out:
560557
return 0;
561558

net/batman-adv/main.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,6 @@ int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
569569
!bat_algo_ops->bat_iface_disable ||
570570
!bat_algo_ops->bat_iface_update_mac ||
571571
!bat_algo_ops->bat_primary_iface_set ||
572-
!bat_algo_ops->bat_ogm_schedule ||
573-
!bat_algo_ops->bat_ogm_emit ||
574572
!bat_algo_ops->bat_neigh_cmp ||
575573
!bat_algo_ops->bat_neigh_is_similar_or_better) {
576574
pr_info("Routing algo '%s' does not implement required ops\n",

net/batman-adv/send.c

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -428,27 +428,7 @@ int batadv_send_skb_via_gw(struct batadv_priv *bat_priv, struct sk_buff *skb,
428428
orig_node, vid);
429429
}
430430

431-
void batadv_schedule_bat_ogm(struct batadv_hard_iface *hard_iface)
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-
451-
static void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet)
431+
void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet)
452432
{
453433
kfree_skb(forw_packet->skb);
454434
if (forw_packet->if_incoming)
@@ -604,45 +584,6 @@ static void batadv_send_outstanding_bcast_packet(struct work_struct *work)
604584
atomic_inc(&bat_priv->bcast_queue_left);
605585
}
606586

607-
void 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-
638-
out:
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-
646587
void
647588
batadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
648589
const struct batadv_hard_iface *hard_iface)

net/batman-adv/send.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#include "packet.h"
2727

2828
struct sk_buff;
29-
struct work_struct;
3029

30+
void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet);
3131
int batadv_send_skb_to_orig(struct sk_buff *skb,
3232
struct batadv_orig_node *orig_node,
3333
struct batadv_hard_iface *recv_if);
@@ -38,11 +38,9 @@ int batadv_send_broadcast_skb(struct sk_buff *skb,
3838
struct batadv_hard_iface *hard_iface);
3939
int batadv_send_unicast_skb(struct sk_buff *skb,
4040
struct batadv_neigh_node *neigh_node);
41-
void batadv_schedule_bat_ogm(struct batadv_hard_iface *hard_iface);
4241
int batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv,
4342
const struct sk_buff *skb,
4443
unsigned long delay);
45-
void batadv_send_outstanding_bat_ogm_packet(struct work_struct *work);
4644
void
4745
batadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
4846
const struct batadv_hard_iface *hard_iface);

net/batman-adv/types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,8 +1269,6 @@ struct batadv_forw_packet {
12691269
* @bat_iface_update_mac: (re-)init mac addresses of the protocol information
12701270
* belonging to this hard-interface
12711271
* @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
12741272
* @bat_hardif_neigh_init: called on creation of single hop entry
12751273
* @bat_neigh_cmp: compare the metrics of two neighbors for their respective
12761274
* outgoing interfaces
@@ -1294,8 +1292,6 @@ struct batadv_algo_ops {
12941292
void (*bat_iface_disable)(struct batadv_hard_iface *hard_iface);
12951293
void (*bat_iface_update_mac)(struct batadv_hard_iface *hard_iface);
12961294
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);
12991295
/* neigh_node handling API */
13001296
void (*bat_hardif_neigh_init)(struct batadv_hardif_neigh_node *neigh);
13011297
int (*bat_neigh_cmp)(struct batadv_neigh_node *neigh1,

0 commit comments

Comments
 (0)