Broadcast Avoidances, Neighborhood Hash
Hi,
Here's the second broadcast avoidance patchset (rebased on the former one).
Hopefully, those two patchsets together should be an automatic approach and replacement for the (non-upstream) no-rebroadcast flag patch and the cases it is currently used for.
Documentation:
* https://www.open-mesh.org/projects/batman-adv/wiki/Broadcast-Avoidances
Branch:
* https://git.open-mesh.org/batman-adv.git/shortlog/refs/heads/linus/neighhash
Regards, Linus
PATCH 1/3 batman-adv: Store and transmit own neighborhood hash
Adds a sha512 hash as a TVLV to an ELP packet. Hash is the "sum" of all neighbors (ordered alphabetically, concatenated, binary) a node sees on a specific interface.
Furthermore, the best and worst TX metric of all these neighbors on an interface are added to the TVLV.
---
Note: This patch throws two checkpatch warnings which are faulty, though.
--- net/batman-adv/Kconfig | 1 + net/batman-adv/bat_v.c | 27 ++++++- net/batman-adv/bat_v.h | 5 ++ net/batman-adv/bat_v_elp.c | 175 ++++++++++++++++++++++++++++++++++++++++++++ net/batman-adv/bat_v_elp.h | 2 + net/batman-adv/log.c | 4 +- net/batman-adv/main.c | 1 + net/batman-adv/originator.c | 47 +++++++++++- net/batman-adv/packet.h | 26 +++++++ net/batman-adv/types.h | 8 ++ 10 files changed, 289 insertions(+), 7 deletions(-)
net/batman-adv/Kconfig +1 -0
@@ -18,6 +18,7 @@ config BATMAN_ADV config BATMAN_ADV_BATMAN_V bool "B.A.T.M.A.N. V protocol (experimental)" depends on BATMAN_ADV && CFG80211=y || (CFG80211=m && BATMAN_ADV=m) + depends on CRYPTO_SHA512 default n help This option enables the B.A.T.M.A.N. V protocol, the successor
net/batman-adv/bat_v.c +24 -3
@@ -1070,11 +1070,17 @@ static struct batadv_algo_ops batadv_batman_v __read_mostly = {*/ void batadv_v_hardif_init (struct batadv_hard_iface *hard_iface) { +struct batadv_hard_iface_bat_v *bat_v = &hard_iface->bat_v; +/* enable link throughput auto-detection by setting the throughput * override to zero */ -atomic_set (&hard_iface->bat_v.throughput_override,0 ); -atomic_set (&hard_iface->bat_v.elp_interval,500 ); +atomic_set (&bat_v->throughput_override,0 ); +atomic_set (&bat_v->elp_interval,500 ); + + bat_v->min_throughput =0 ; + bat_v->max_throughput = (~(u32 )0 ); +memset (bat_v->neigh_hash,0 ,sizeof (bat_v->neigh_hash)); }/**
@@ -1108,6 +1114,14 @@ void batadv_v_mesh_free(struct batadv_priv *bat_priv) }/** +* batadv_v_free - free the B.A.T.M.A.N. V global, mesh independent resources +*/ +void batadv_v_free (void ) +{ +batadv_v_elp_free (); +} + +/** * batadv_v_init - B.A.T.M.A.N. V initialization function * * Description: Takes care of initializing all the subcomponents.
@@ -1119,11 +1133,15 @@ int __init batadv_v_init(void) {int ret; + ret =batadv_v_elp_init (); +if (ret <0 ) +return ret; +/* B.A.T.M.A.N. V echo location protocol packet */ ret =batadv_recv_handler_register (BATADV_ELP , batadv_v_elp_packet_recv);if (ret <0 ) -return ret; + goto elp_free; ret =batadv_recv_handler_register (BATADV_OGM2 , batadv_v_ogm_packet_recv);
@@ -1136,6 +1154,9 @@ int __init batadv_v_init(void)return ret; +elp_free: +batadv_v_elp_free (); + ogm_unregister:batadv_recv_handler_unregister (BATADV_OGM2 );
net/batman-adv/bat_v.h +5 -0
@@ -23,6 +23,7 @@#ifdef CONFIG_BATMAN_ADV_BATMAN_V int batadv_v_init (void ); +void batadv_v_free (void );void batadv_v_hardif_init (struct batadv_hard_iface *hardif);int batadv_v_mesh_init (struct batadv_priv *bat_priv);void batadv_v_mesh_free (struct batadv_priv *bat_priv);
@@ -34,6 +35,10 @@ static inline int batadv_v_init(void)return 0 ; } +static inline void batadv_v_free (void ) +{ +} +static inline void batadv_v_hardif_init (struct batadv_hard_iface *hardif) { }
net/batman-adv/bat_v_elp.c +175 -0
225 lines not on this page · raw message
net/batman-adv/bat_v_elp.h +2 -0
@@ -23,6 +23,8 @@struct sk_buff ;struct work_struct ; +int batadv_v_elp_init (void ); +void batadv_v_elp_free (void );int batadv_v_elp_iface_enable (struct batadv_hard_iface *hard_iface);void batadv_v_elp_iface_disable (struct batadv_hard_iface *hard_iface); void batadv_v_elp_iface_activate(struct batadv_hard_iface *primary_iface,
net/batman-adv/log.c +2 -2
@@ -66,7 +66,7 @@ static int batadv_fdebug_log(struct batadv_priv_debug_log *debug_log, const char *fmt, ...) {va_list args; -static char debug_log_buf[256 ]; +static char debug_log_buf[512 ];char *p;if (!debug_log)
@@ -90,7 +90,7 @@ static int batadv_fdebug_log(struct batadv_priv_debug_log *debug_log,int batadv_debug_log (struct batadv_priv *bat_priv,const char *fmt, ...) {va_list args; -char tmp_log_buf[256 ]; +char tmp_log_buf[512 ];va_start (args, fmt);vscnprintf (tmp_log_buf,sizeof (tmp_log_buf), fmt, args);
net/batman-adv/main.c +1 -0
@@ -135,6 +135,7 @@ static void __exit batadv_exit(void)rcu_barrier ();batadv_tt_cache_destroy (); +batadv_v_free (); }int batadv_mesh_init (struct net_device *soft_iface)
net/batman-adv/originator.c +45 -2
65 lines not on this page · raw message
net/batman-adv/packet.h +26 -0
@@ -19,6 +19,7 @@#define _NET_BATMAN_ADV_PACKET_H_#include <asm/byteorder.h> +#include <crypto/sha.h> #include <linux/types.h> #define batadv_tp_is_error (n) ((u8)n > 127 ? 1 : 0)
@@ -163,6 +164,14 @@ enum batadv_tvlv_type { BATADV_TVLV_MCAST = 0x06, }; +/** +* enum batadv_tvlv_elp_type - tvlv type definitions for ELP messages +* @BATADV_TVLV_NHH: neighborhood hash +*/ +enum batadv_tvlv_elp_type { +BATADV_TVLV_NHH =0x01 , +}; +#pragma pack(2)/* the destination hardware field in the ARP frame is used to * transport the claim type and the group id
@@ -240,6 +249,8 @@ struct batadv_ogm2_packet {* @orig: originator mac address * @seqno: sequence number * @elp_interval: currently used ELP sending interval in ms +* @reserved: reserved bytes for alignment +* @tvlv_len: length of tvlv data following the elp header */ struct batadv_elp_packet {u8 packet_type;
@@ -247,6 +258,8 @@ struct batadv_elp_packet {u8 orig[ETH_ALEN ];__be32 seqno;__be32 elp_interval; +__be16 reserved; +__be16 tvlv_len; };#define BATADV_ELP_HLEN sizeof(struct batadv_elp_packet)
@@ -628,4 +641,17 @@ struct batadv_tvlv_mcast_data { u8 reserved[3]; }; +/** +* batadv_tvlv_nhh_data - neighborhood hash data +* @min_throughput: worst of all TX throughputs this neighbor has to others +* @max_throughput: best of all TX throughputs this neighbor has to others +* @neigh_hash: a sha512 hash of all neighbors this neighbor sees +* (hash over the alphabetically ordered, concatenated, binary representation) +*/ +struct batadv_tvlv_nhh_data { +__be32 min_throughput; +__be32 max_throughput; +u8 neigh_hash[SHA512_DIGEST_SIZE ]; +}; +#endif /* _NET_BATMAN_ADV_PACKET_H_ */
net/batman-adv/types.h +8 -0
@@ -22,6 +22,7 @@#error only "main.h" can be included directly#endif +#include <crypto/sha.h> #include <linux/average.h> #include <linux/bitops.h> #include <linux/compiler.h>
@@ -108,6 +109,10 @@ enum batadv_v_hard_iface_flags {* @elp_wq: workqueue used to schedule ELP transmissions * @throughput_override: throughput override to disable link auto-detection * @flags: interface specific flags +* @min_throughput: worst of all TX throughputs this neighbor has to others +* @max_throughput: best of all TX throughputs this neighbor has to others +* @neigh_hash: a sha512 hash of all neighbors this neighbor sees +* (hash over the alphabetically ordered, concatenated, binary representation) */ struct batadv_hard_iface_bat_v {atomic_t elp_interval;
@@ -116,6 +121,9 @@ struct batadv_hard_iface_bat_v {struct delayed_work elp_wq;atomic_t throughput_override;u8 flags; +u32 min_throughput; +u32 max_throughput; +u8 neigh_hash[SHA512_DIGEST_SIZE ]; };/**
Signature · 1 line
2.1.4
Sven Eckelmann
maintainerRe: [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Store and transmit own neighborhood hash
[...]
net/batman-adv/Kconfig config BATMAN_ADV · line 24
Quoted 12 lines
net/batman-adv/Kconfig +1
-0@@ -18,6 +18,7 @@ config BATMAN_ADV config BATMAN_ADV_BATMAN_V bool "B.A.T.M.A.N. V protocol (experimental)" depends on BATMAN_ADV && CFG80211=y || (CFG80211=m && BATMAN_ADV=m) + depends on CRYPTO_SHA512 default n help This option enables the B.A.T.M.A.N. V protocol, the successor
Nearly everyone else seems to select the crypto sha512 module (maybe we should do the same?):
crypto/Kconfig: select CRYPTO_SHA512
crypto/Kconfig: select CRYPTO_SHA512
crypto/Kconfig: select CRYPTO_SHA512 crypto/Kconfig: select CRYPTO_SHA512 drivers/crypto/Kconfig: select CRYPTO_SHA512 drivers/crypto/chelsio/Kconfig: select CRYPTO_SHA512
drivers/crypto/qat/Kconfig: select CRYPTO_SHA512
drivers/staging/lustre/lustre/Kconfig: select CRYPTO_SHA512
init/Kconfig: select CRYPTO_SHA512
init/Kconfig: select CRYPTO_SHA512
security/integrity/ima/Kconfig: depends on CRYPTO_SHA512 && !IMA_TEMPLATE
Kind regards,
Sven
Re: [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Store and transmit own neighborhood hash
In reply to Linus LüssingOn Dienstag, 20. September 2016 14:12:43 CEST Linus Lüssing wrote:
[...]
Quoted 52 lines
/**
+ *batadv_hardif_neigh_get_pre- get the predecessor of a neighbor node
+ * @hard_iface: the interface this neighbour is connected to
+ * @neigh_addr: address of the neighbour to retrieve the predecessor for
+ *
+ * Tries to find the neighbor node which has an address closest to but
+ * smaller than theneigh_addrprovided. In other words, tries to
+ * find a potential predecessor of a given MAC address.
+ *
+ * Return: The alphabetical predecessor of a neighbor node. Returns NULL
+ * if no such predecessor exists.
+ */net/batman-adv/originator.c +27
-1+static struct batadv_hardif_neigh_node * +batadv_hardif_neigh_get_pre (struct batadv_hard_iface *hard_iface, +const u8 *neigh_addr) +{ +struct batadv_hardif_neigh_node *tmp_hardif_neigh, *hardif_neigh =NULL ; + +rcu_read_lock (); +hlist_for_each_entry_rcu (tmp_hardif_neigh, &hard_iface->neigh_list, + list) { +if (memcmp (tmp_hardif_neigh->addr, neigh_addr,ETH_ALEN ) >=0 ) +break ; + +if (!kref_get_unless_zero (&tmp_hardif_neigh->refcount)) +continue ; + +if (hardif_neigh) +batadv_hardif_neigh_put (hardif_neigh); + + hardif_neigh = tmp_hardif_neigh; + } +rcu_read_unlock (); + +return hardif_neigh; +} + +/** * batadv_hardif_neigh_create - create a hardif neighbour node * @hard_iface: the interface this neighbour is connected to * @neigh_addr: the interface address of the neighbour to retrieve @@ -522,7 +559,7 @@ batadv_hardif_neigh_create(struct batadv_hard_iface *hard_iface, struct batadv_orig_node *orig_node) {struct batadv_priv *bat_priv =netdev_priv (hard_iface->soft_iface); -struct batadv_hardif_neigh_node *hardif_neigh =NULL ; +struct batadv_hardif_neigh_node *hardif_neigh =NULL , *pre_neigh;spin_lock_bh (&hard_iface->neigh_list_lock);@@ -547,7 +584,13 @@ batadv_hardif_neigh_create(struct batadv_hard_iface *hard_iface,if (bat_priv->algo_ops->neigh.hardif_init)
net/batman-adv/originator.c batadv_hardif_neigh_create(struct batadv_hard_iface *hard_iface, · line 593
Quoted 10 lines
net/batman-adv/originator.c +7
-1bat_priv->algo_ops->neigh.hardif_init (hardif_neigh); -hlist_add_head (&hardif_neigh->list, &hard_iface->neigh_list); + pre_neigh =batadv_hardif_neigh_get_pre (hard_iface, neigh_addr); +if (!pre_neigh) { +hlist_add_head (&hardif_neigh->list, &hard_iface->neigh_list); + }else { +hlist_add_behind (&hardif_neigh->list, &pre_neigh->list); +batadv_hardif_neigh_put (pre_neigh); + }
I personally would have liked to see this in a separate patch. But there are more important things here.
First you have to use hlist_add_head_rcu and hlist_add_behind_rcu here because the readers use RCU to access the list. I think it would also be more appropriate to replace the rcu_read_lock in the batadv_hardif_neigh_get_pre function and instead use lockdep to mark the function as "requires hard_iface->neigh_list_lock".
Stuff to other parts will follow later.
Kind regards,
Sven
Re: [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Store and transmit own neighborhood hash
Quoted 5 lines · Sven Eckelmann
First you have to use
hlist_add_head_rcuandhlist_add_behind_rcuhere because the readers use RCU to access the list. I think it would also be more appropriate to replace thercu_read_lockin thebatadv_hardif_neigh_get_prefunction and instead use lockdep to mark the function as "requireshard_iface->neigh_list_lock".
Hm, I'm currently wondering... isn't this a bug we already have now, then? Shouldn't this have been an hlist_add_head_rcu() in the first place?
Re: [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Store and transmit own neighborhood hash
Quoted 10 lines · Linus Lüssing
Quoted 5 lines · Sven Eckelmann
First you have to use
hlist_add_head_rcuandhlist_add_behind_rcuhere because the readers use RCU to access the list. I think it would also be more appropriate to replace thercu_read_lockin thebatadv_hardif_neigh_get_prefunction and instead use lockdep to mark the function as "requireshard_iface->neigh_list_lock".Hm, I'm currently wondering... isn't this a bug we already have now, then? Shouldn't this have been an
hlist_add_head_rcu()in the first place?
Now saw your patch for maint - so ignore my last comment :D.
Re: [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Store and transmit own neighborhood hash
In reply to Sven EckelmannQuoted 68 lines · Sven Eckelmann
On Dienstag, 20. September 2016 14:12:43 CEST Linus Lüssing wrote:
[...]Quoted 52 lines
/**
+ *batadv_hardif_neigh_get_pre- get the predecessor of a neighbor node
+ * @hard_iface: the interface this neighbour is connected to
+ * @neigh_addr: address of the neighbour to retrieve the predecessor for
+ *
+ * Tries to find the neighbor node which has an address closest to but
+ * smaller than theneigh_addrprovided. In other words, tries to
+ * find a potential predecessor of a given MAC address.
+ *
+ * Return: The alphabetical predecessor of a neighbor node. Returns NULL
+ * if no such predecessor exists.
+ */net/batman-adv/originator.c +27
-1+static struct batadv_hardif_neigh_node * +batadv_hardif_neigh_get_pre (struct batadv_hard_iface *hard_iface, +const u8 *neigh_addr) +{ +struct batadv_hardif_neigh_node *tmp_hardif_neigh, *hardif_neigh =NULL ; + +rcu_read_lock (); +hlist_for_each_entry_rcu (tmp_hardif_neigh, &hard_iface->neigh_list, + list) { +if (memcmp (tmp_hardif_neigh->addr, neigh_addr,ETH_ALEN ) >=0 ) +break ; + +if (!kref_get_unless_zero (&tmp_hardif_neigh->refcount)) +continue ; + +if (hardif_neigh) +batadv_hardif_neigh_put (hardif_neigh); + + hardif_neigh = tmp_hardif_neigh; + } +rcu_read_unlock (); + +return hardif_neigh; +} + +/** * batadv_hardif_neigh_create - create a hardif neighbour node * @hard_iface: the interface this neighbour is connected to * @neigh_addr: the interface address of the neighbour to retrieve @@ -522,7 +559,7 @@ batadv_hardif_neigh_create(struct batadv_hard_iface *hard_iface, struct batadv_orig_node *orig_node) {struct batadv_priv *bat_priv =netdev_priv (hard_iface->soft_iface); -struct batadv_hardif_neigh_node *hardif_neigh =NULL ; +struct batadv_hardif_neigh_node *hardif_neigh =NULL , *pre_neigh;spin_lock_bh (&hard_iface->neigh_list_lock);@@ -547,7 +584,13 @@ batadv_hardif_neigh_create(struct batadv_hard_iface *hard_iface,if (bat_priv->algo_ops->neigh.hardif_init)net/batman-adv/originator.c batadv_hardif_neigh_create(struct batadv_hard_iface *hard_iface, · line 593
Quoted 10 lines
net/batman-adv/originator.c +7
-1bat_priv->algo_ops->neigh.hardif_init (hardif_neigh); -hlist_add_head (&hardif_neigh->list, &hard_iface->neigh_list); + pre_neigh =batadv_hardif_neigh_get_pre (hard_iface, neigh_addr); +if (!pre_neigh) { +hlist_add_head (&hardif_neigh->list, &hard_iface->neigh_list); + }else { +hlist_add_behind (&hardif_neigh->list, &pre_neigh->list); +batadv_hardif_neigh_put (pre_neigh); + }I personally would have liked to see this in a separate patch. But there are more important things here.
Quoted 5 lines
First you have to use
hlist_add_head_rcuandhlist_add_behind_rcuhere because the readers use RCU to access the list. I think it would also be more appropriate to replace thercu_read_lockin thebatadv_hardif_neigh_get_prefunction and instead use lockdep to mark the function as "requireshard_iface->neigh_list_lock".
PS: In v2, I haven't changed batadv_hardif_neigh_get_pre() to a non-rcu variant with lockdep. You are right, rcu isn't really necessary in this context, but I kind of like being able to have a function on one screen and seeing immediately whether it works or not, without needing to scroll.
And I liked keeping it similar to batadv_hardif_neigh_get().
Does that make sense?
Re: [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Store and transmit own neighborhood hash
In reply to Linus LüssingOn Dienstag, 20. September 2016 14:12:43 CEST Linus Lüssing wrote:
[...]
Quoted 12 lines
/**
+ *batadv_v_elp_update_neigh_hash- updates neighborhood hash related data
+ * @hard_iface: interface which the data has to be prepared for
+ *
+ * Firstly, this function updates the neighborhood hash of a hard interface.
+ * That is it resummarizes the present neighborhood into one compact hash
+ * representation.
+ *
+ * Secondly, minimum and maximum throughput values within this neighorhood are
+ * updated.
+ */net/batman-adv/bat_v_elp.c +1
-0+static void batadv_v_elp_update_neigh_hash (struct batadv_hard_iface *hard_iface)
net/batman-adv/bat_v_elp.c static void batadv_v_elp_start_timer(struct batadv_hard_iface *hard_iface) · line 92
Quoted 10 lines
net/batman-adv/bat_v_elp.c +10
-0+{ +struct batadv_priv *bat_priv =netdev_priv (hard_iface->soft_iface); +struct batadv_hardif_neigh_node *hardif_neigh; +struct ewma_throughput *ewma_throughput; +u8 *own_addr = hard_iface->net_dev->dev_addr; +u32 min_throughput = ~((u32 )0 ), max_throughput =0 ; +u32 throughput; +int ret; + +SHASH_DESC_ON_STACK (shash, tfm);
This macro doesn't exist on Linux < v3.18. Can you please add it to compat-include/crypto/hash.h?
[...]
net/batman-adv/packet.h struct batadv_tvlv_mcast_data { · line 656
Quoted 13 lines
net/batman-adv/packet.h +13
-0+/** +* batadv_tvlv_nhh_data - neighborhood hash data +* @min_throughput: worst of all TX throughputs this neighbor has to others +* @max_throughput: best of all TX throughputs this neighbor has to others +* @neigh_hash: a sha512 hash of all neighbors this neighbor sees +* (hash over the alphabetically ordered, concatenated, binary representation) +*/ +struct batadv_tvlv_nhh_data { +__be32 min_throughput; +__be32 max_throughput; +u8 neigh_hash[SHA512_DIGEST_SIZE ]; +}; +
Please use "struct batadv_tvlv_nhh_data - neighborhood hash data" in kernel-doc block
Kind regards,
Sven
Re: [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Store and transmit own neighborhood hash
In reply to Linus LüssingOn Dienstag, 20. September 2016 14:12:43 CEST Linus Lüssing wrote:
[...]
Quoted 4 lines
net/batman-adv/bat_v.c +0
-0
[...]
net/batman-adv/bat_v.c static struct batadv_algo_ops batadv_batman_v __read_mostly = { · line 1083
Quoted 1 line
net/batman-adv/bat_v.c +1
-0+memset (bat_v->neigh_hash,0 ,sizeof (bat_v->neigh_hash));
Include <linux/string.h> is missing for it. Can you please add while resending the patch?
[...]
Quoted 4 lines
net/batman-adv/bat_v_elp.c +0
-0
[...]
net/batman-adv/bat_v_elp.c static void batadv_v_elp_start_timer(struct batadv_hard_iface *hard_iface) · line 164
Quoted 3 lines
net/batman-adv/bat_v_elp.c +3
-0+pr_warn_once ("An error occurred while calculating neighbor hash for %s\n" , + hard_iface->net_dev->name); +}
Please include linux/printk.h for pr_warn_once.
[...]
net/batman-adv/bat_v_elp.c out: · line 693
Quoted 5 lines
net/batman-adv/bat_v_elp.c +5
-0+int batadv_v_elp_init (void ) +{ + tfm =crypto_alloc_shash ("sha512" ,0 ,0 ); +if (IS_ERR (tfm)) +return PTR_ERR (tfm);
These two require linux/err.h
[...]
Quoted 5 lines
int
batadv_mesh_init(struct net_device *soft_iface)net/batman-adv/originator.c +0
-0
[...]
net/batman-adv/originator.c batadv_neigh_node_get(const struct batadv_orig_node *orig_node, · line 533
Quoted 2 lines
net/batman-adv/originator.c +2
-0+if (memcmp (tmp_hardif_neigh->addr, neigh_addr,ETH_ALEN ) >=0 ) +break ;
memset requires linux/string.h
Kind regards,
Sven
PATCH 2/3 batman-adv: Introduce packet type independent TVLV handler API
In reply to Linus LüssingInstead of having one TVLV registration function for OGMs and one for unicast packets, this patch adds a new, generic tvlv handler registratiorn function, which simply uses a packet type as parameter.
For now, this patch only migrates the multicast and gateway tvlv handlers to this new API, as these two have been tested and verified to work by the author.
The benefits of this new API:
* A more unified TVLV handling
* Easier to add TVLV capabilities to any new, upcoming packet type
* Does not rely on linearized skb data
Further ToDos (for later patches):
* Insert handler hooks for unicast_tvlv packets too and migrate BATADV_TVLV_{DAT,NC,TT,ROAM} to new API after further testing.
* Remove old TVLV handler API
--- net/batman-adv/bat_iv_ogm.c | 8 +- net/batman-adv/bat_v_ogm.c | 17 +- net/batman-adv/distributed-arp-table.c | 4 +- net/batman-adv/gateway_common.c | 44 +++-- net/batman-adv/multicast.c | 37 ++-- net/batman-adv/network-coding.c | 4 +- net/batman-adv/tvlv.c | 324 ++++++++++++++++++++++++++++++--- net/batman-adv/tvlv.h | 22 ++- net/batman-adv/types.h | 24 ++- 9 files changed, 405 insertions(+), 79 deletions(-)
net/batman-adv/bat_iv_ogm.c +7 -1
@@ -1491,7 +1491,7 @@ batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset, }if (if_outgoing ==BATADV_IF_DEFAULT ) -batadv_tvlv_ogm_receive (bat_priv, ogm_packet, orig_node); +batadv_tvlv_ogm_receive (bat_priv, skb, orig_node);/* if sender is a direct neighbor the sender mac equals * originator mac
@@ -1832,6 +1832,8 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb, ogm_offset =0 ; ogm_packet = (struct batadv_ogm_packet *)skb->data; +WARN_ON (skb_network_offset (skb) !=0 ); +/* unpack the aggregated packets and process them one by one */ while (batadv_iv_ogm_aggr_packet (ogm_offset,skb_headlen (skb), ogm_packet->tvlv_len)) {
@@ -1842,8 +1844,12 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb, packet_pos = skb->data + ogm_offset; ogm_packet = (struct batadv_ogm_packet *)packet_pos; + +skb_set_network_header (skb, ogm_offset); } +skb_reset_network_header (skb); +kfree_skb (skb);return NET_RX_SUCCESS ; }
net/batman-adv/bat_v_ogm.c +12 -5
@@ -594,7 +594,7 @@ out:/** * batadv_v_ogm_process_per_outif - process a batman v OGM for an outgoing if * @bat_priv: the bat priv with all the soft interface information -* @ethhdr: the Ethernet header of the OGM2 +* @skb: the skb containing the OGM2 * @ogm2: OGM2 structure * @orig_node: Originator structure for which the OGM has been received * @neigh_node: the neigh_node through with the OGM has been received
@@ -603,13 +603,16 @@ out:*/ static void batadv_v_ogm_process_per_outif (struct batadv_priv *bat_priv, -const struct ethhdr *ethhdr, +const struct sk_buff *skb,const struct batadv_ogm2_packet *ogm2,struct batadv_orig_node *orig_node,struct batadv_neigh_node *neigh_node,struct batadv_hard_iface *if_incoming,struct batadv_hard_iface *if_outgoing) { +void *ctx =batadv_tvlv_ogm_pack_ctx (orig_node); +const struct ethhdr *ethhdr =eth_hdr (skb); +unsigned int tvlv_offset =sizeof (*ogm2);int seqno_age;bool forward;
@@ -623,11 +626,15 @@ batadv_v_ogm_process_per_outif(struct batadv_priv *bat_priv,return ;/* only unknown & newer OGMs contain TVLVs we are interested in */ -if ((seqno_age >0 ) && (if_outgoing ==BATADV_IF_DEFAULT )) +if ((seqno_age >0 ) && (if_outgoing ==BATADV_IF_DEFAULT )) { +batadv_tvlv_containers_process2 (bat_priv, skb,BATADV_OGM2 , + tvlv_offset, +ntohs (ogm2->tvlv_len), ctx);batadv_tvlv_containers_process (bat_priv, true, orig_node,NULL ,NULL , (unsigned char *)(ogm2 +1 ),ntohs (ogm2->tvlv_len)); + }/* if the metric update went through, update routes if needed */ forward = batadv_v_ogm_route_update(bat_priv, ethhdr, ogm2, orig_node,
@@ -728,7 +735,7 @@ static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset, path_throughput =min_t (u32, link_throughput, ogm_throughput); ogm_packet->throughput =htonl (path_throughput); -batadv_v_ogm_process_per_outif (bat_priv, ethhdr, ogm_packet, orig_node, +batadv_v_ogm_process_per_outif (bat_priv, skb, ogm_packet, orig_node, neigh_node, if_incoming,BATADV_IF_DEFAULT );
@@ -772,7 +779,7 @@ static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset,continue ; } -batadv_v_ogm_process_per_outif (bat_priv, ethhdr, ogm_packet, +batadv_v_ogm_process_per_outif (bat_priv, skb, ogm_packet, orig_node, neigh_node, if_incoming, hard_iface);
net/batman-adv/distributed-arp-table.c +2 -2
@@ -734,7 +734,7 @@ static void batadv_dat_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,u8 flags, void *tvlv_value, u16 tvlv_value_len) { - if (flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND) + if (flags & BATADV_TVLV_HANDLER_CIFNOTFND) clear_bit(BATADV_ORIG_CAPA_HAS_DAT, &orig->capabilities); else set_bit(BATADV_ORIG_CAPA_HAS_DAT, &orig->capabilities);
@@ -776,7 +776,7 @@ int batadv_dat_init(struct batadv_priv *bat_priv)batadv_tvlv_handler_register (bat_priv, batadv_dat_tvlv_ogm_handler_v1,NULL ,BATADV_TVLV_DAT ,1 , -BATADV_TVLV_HANDLER_OGM_CIFNOTFND ); +BATADV_TVLV_HANDLER_CIFNOTFND );batadv_dat_tvlv_container_update (bat_priv);return 0 ; }
net/batman-adv/gateway_common.c +27 -17
78 lines not on this page · raw message
net/batman-adv/multicast.c +23 -14
@@ -1070,23 +1070,23 @@ static void batadv_mcast_want_ipv6_update(struct batadv_priv *bat_priv,/** * batadv_mcast_tvlv_ogm_handler - process incoming multicast tvlv container * @bat_priv: the bat priv with all the soft interface information -* @orig: the orig_node of the ogm -* @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags) * @tvlv_value: tvlv buffer containing the multicast data * @tvlv_value_len: tvlv buffer length +* @ctx: handler specific context information (here: orig_node) +* +* Return: Always NET_RX_SUCCESS. */ -static void batadv_mcast_tvlv_ogm_handler (struct batadv_priv *bat_priv, -struct batadv_orig_node *orig, -u8 flags, -void *tvlv_value, -u16 tvlv_value_len) +static int batadv_mcast_tvlv_ogm_handler (struct batadv_priv *bat_priv, +void *tvlv_value, +u16 tvlv_value_len, +void *ctx) { -bool orig_mcast_enabled = !(flags &BATADV_TVLV_HANDLER_OGM_CIFNOTFND ); +struct batadv_orig_node *orig =batadv_tvlv_ogm_unpack_ctx (ctx); +bool orig_mcast_enabled = !!tvlv_value;u8 mcast_flags =BATADV_NO_FLAGS ;bool orig_initialized; -if (orig_mcast_enabled && tvlv_value && - (tvlv_value_len >=sizeof (mcast_flags))) +if (orig_mcast_enabled && (tvlv_value_len >=sizeof (mcast_flags))) mcast_flags = *(u8 *)tvlv_value;spin_lock_bh (&orig->mcast_handler_lock);
@@ -1121,6 +1121,8 @@ static void batadv_mcast_tvlv_ogm_handler(struct batadv_priv *bat_priv, orig->mcast_flags = mcast_flags;spin_unlock_bh (&orig->mcast_handler_lock); + +return NET_RX_SUCCESS ; }/**
@@ -1129,9 +1131,12 @@ static void batadv_mcast_tvlv_ogm_handler(struct batadv_priv *bat_priv,*/ void batadv_mcast_init (struct batadv_priv *bat_priv) { -batadv_tvlv_handler_register (bat_priv, batadv_mcast_tvlv_ogm_handler, -NULL ,BATADV_TVLV_MCAST ,2 , -BATADV_TVLV_HANDLER_OGM_CIFNOTFND ); +batadv_tvlv_handler_register2 (bat_priv, batadv_mcast_tvlv_ogm_handler, +BATADV_IV_OGM ,BATADV_TVLV_MCAST ,2 , +BATADV_TVLV_HANDLER_CIFNOTFND ); +batadv_tvlv_handler_register2 (bat_priv, batadv_mcast_tvlv_ogm_handler, +BATADV_OGM2 ,BATADV_TVLV_MCAST ,2 , +BATADV_TVLV_HANDLER_CIFNOTFND ); }#ifdef CONFIG_BATMAN_ADV_DEBUGFS
@@ -1244,7 +1249,11 @@ int batadv_mcast_flags_seq_print_text(struct seq_file *seq, void *offset)void batadv_mcast_free (struct batadv_priv *bat_priv) {batadv_tvlv_container_unregister (bat_priv,BATADV_TVLV_MCAST ,2 ); -batadv_tvlv_handler_unregister (bat_priv,BATADV_TVLV_MCAST ,2 ); + +batadv_tvlv_handler_unregister2 (bat_priv,BATADV_IV_OGM , +BATADV_TVLV_MCAST ,2 ); +batadv_tvlv_handler_unregister2 (bat_priv,BATADV_OGM2 , +BATADV_TVLV_MCAST ,2 );spin_lock_bh (&bat_priv->tt.commit_lock);batadv_mcast_mla_tt_retract (bat_priv,NULL );
net/batman-adv/network-coding.c +2 -2
@@ -138,7 +138,7 @@ static void batadv_nc_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,u8 flags, void *tvlv_value, u16 tvlv_value_len) { - if (flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND) + if (flags & BATADV_TVLV_HANDLER_CIFNOTFND) clear_bit(BATADV_ORIG_CAPA_HAS_NC, &orig->capabilities); else set_bit(BATADV_ORIG_CAPA_HAS_NC, &orig->capabilities);
@@ -177,7 +177,7 @@ int batadv_nc_mesh_init(struct batadv_priv *bat_priv)batadv_tvlv_handler_register (bat_priv, batadv_nc_tvlv_ogm_handler_v1,NULL ,BATADV_TVLV_NC ,1 , -BATADV_TVLV_HANDLER_OGM_CIFNOTFND ); +BATADV_TVLV_HANDLER_CIFNOTFND );batadv_nc_tvlv_container_update (bat_priv);return 0 ;
net/batman-adv/tvlv.c +298 -26
435 lines not on this page · raw message
net/batman-adv/tvlv.h +19 -3
@@ -30,12 +30,21 @@ void batadv_tvlv_container_register(struct batadv_priv *bat_priv,u16 batadv_tvlv_container_ogm_append (struct batadv_priv *bat_priv,unsigned char **packet_buff,int *packet_buff_len,int packet_min_len); +void *batadv_tvlv_ogm_pack_ctx (struct batadv_orig_node *orig_node); +struct batadv_orig_node *batadv_tvlv_ogm_unpack_ctx (void *ctx);void batadv_tvlv_ogm_receive (struct batadv_priv *bat_priv, -struct batadv_ogm_packet *batadv_ogm_packet, +const struct sk_buff *skb,struct batadv_orig_node *orig_node);void batadv_tvlv_container_unregister (struct batadv_priv *bat_priv,u8 type,u8 version); +void batadv_tvlv_handler_register2 (struct batadv_priv *bat_priv, +int (*handler)(struct batadv_priv *bat_priv, +void *tvlv_value, +u16 tvlv_value_len, +void *ctx), +u8 packet_type,u8 tvlv_type, +u8 tvlv_version,u8 flags); void batadv_tvlv_handler_register(struct batadv_priv *bat_priv, void (*optr)(struct batadv_priv *bat_priv, struct batadv_orig_node *orig,
@@ -46,14 +55,21 @@ void batadv_tvlv_handler_register(struct batadv_priv *bat_priv, u8 *src, u8 *dst, void *tvlv_value, u16 tvlv_value_len), - u8 type, u8 version, u8 flags); + u8 tvlv_type, u8 tvlv_version, u8 flags); +void batadv_tvlv_handler_unregister2 (struct batadv_priv *bat_priv, +u8 packet_type,u8 tvlv_type, +u8 tvlv_version);void batadv_tvlv_handler_unregister (struct batadv_priv *bat_priv, -u8 type,u8 version); +u8 tvlv_type,u8 tvlv_version);int batadv_tvlv_containers_process (struct batadv_priv *bat_priv,bool ogm_source,struct batadv_orig_node *orig_node,u8 *src,u8 *dst,void *tvlv_buff,u16 tvlv_buff_len); +int batadv_tvlv_containers_process2 (struct batadv_priv *bat_priv, +const struct sk_buff *skb,u8 packet_type, +unsigned int tvlv_offset, +u16 tvlv_value_len,void *ctx);void batadv_tvlv_unicast_send (struct batadv_priv *bat_priv,u8 *src,u8 *dst,u8 type,u8 version,void *tvlv_value,u16 tvlv_value_len);
net/batman-adv/types.h +15 -9
@@ -1584,8 +1584,11 @@ struct batadv_tvlv_container {* incoming OGM packets * @unicast_handler: handler callback which is given the tvlv payload to process * on incoming unicast tvlv packets -* @type: tvlv type this handler feels responsible for -* @version: tvlv version this handler feels responsible for +* @handler: handler callback which is given the tvlv payload to process on +* incoming packets of the given packet type +* @packet_type: packet type this handler feels responsible for +* @tvlv_type: tvlv type this handler feels responsible for +* @tvlv_version: tvlv version this handler feels responsible for * @flags: tvlv handler flags * @refcount: number of contexts the object is used * @rcu: struct used for freeing in an RCU-safe manner
@@ -1598,8 +1601,11 @@ struct batadv_tvlv_handler {int (*unicast_handler)(struct batadv_priv *bat_priv,u8 *src,u8 *dst,void *tvlv_value,u16 tvlv_value_len); -u8 type; -u8 version; +int (*handler)(struct batadv_priv *bat_priv,void *tvlv_value, +u16 tvlv_value_len,void *ctx); +int packet_type; +u8 tvlv_type; +u8 tvlv_version;u8 flags;struct kref refcount;struct rcu_head rcu;
@@ -1607,15 +1613,15 @@ struct batadv_tvlv_handler {/** * enum batadv_tvlv_handler_flags - tvlv handler flags definitions -* @BATADV_TVLV_HANDLER_OGM_CIFNOTFND: tvlv ogm processing function will call +* @BATADV_TVLV_HANDLER_CIFNOTFND: tvlv processing function will call * this handler even if its type was not found (with no data) -* @BATADV_TVLV_HANDLER_OGM_CALLED: interval tvlv handling flag - the API marks +* @BATADV_TVLV_HANDLER_CALLED: internal tvlv handling flag - the API marks * a handler as being called, so it won't be called if the -* BATADV_TVLV_HANDLER_OGM_CIFNOTFND flag was set +* BATADV_TVLV_HANDLER_CIFNOTFND flag was set */ enum batadv_tvlv_handler_flags { -BATADV_TVLV_HANDLER_OGM_CIFNOTFND =BIT (1 ), -BATADV_TVLV_HANDLER_OGM_CALLED =BIT (2 ), +BATADV_TVLV_HANDLER_CIFNOTFND =BIT (1 ), +BATADV_TVLV_HANDLER_CALLED =BIT (2 ), };/**
Signature · 1 line
2.1.4
Re: [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: Introduce packet type independent TVLV handler API
On Dienstag, 20. September 2016 14:12:44 CEST Linus Lüssing wrote:
[...]
net/batman-adv/tvlv.c int batadv_tvlv_containers_process(struct batadv_priv *bat_priv, · line 644
Quoted 13 lines
net/batman-adv/tvlv.c +13
-0+/** +* batadv_tvlv_ogm_unpack_ctx - unpack context received with a TVLV handler call +* @orig_node: An orig_node to pack +* +* This unpacks the context received within an OGM TVLV handler, here the +* orig_node the packet came from. +* +* Return: The orig_node the packet came from. +*/ +struct batadv_orig_node *batadv_tvlv_ogm_unpack_ctx (void *ctx) +{ +return (struct batadv_orig_node *)ctx; +}
The function doesn't have a parameter orig_node but it is documented in the kernel-doc block. Instead the ctx should be documented.
[...]
Quoted 5 lines
/**
+ *batadv_tvlv_handler_unregister2- unregister a tvlv handler
+ * @bat_priv: the bat priv with all the soft interface information
+ * @tvlv_type: packet type to unregistered for
+ * @tvlv_type: tvlv handler type to be unregistered
tvlv_type is documented twice - and differently.
Kind regards,
Sven
Re: [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: Introduce packet type independent TVLV handler API
In reply to Linus LüssingOn Dienstag, 20. September 2016 14:12:44 CEST Linus Lüssing wrote:
[...]
Quoted 4 lines
net/batman-adv/tvlv.c +0
-0
[...]
net/batman-adv/tvlv.c static int batadv_tvlv_call_handler(struct batadv_priv *bat_priv, · line 522
Quoted 4 lines
net/batman-adv/tvlv.c +4
-0+if (tvlv_value_cont_len >sizeof (tvlv_value_buff)) { +pr_warn_once ("batman-adv: TVLVs greater than 128 bytes unsupported for now, ignoring\n" ); + goto skip_handler_call; + }
Please add the include of linux/printk.h for pr_warn_once.
[...]
net/batman-adv/tvlv.c int batadv_tvlv_containers_process(struct batadv_priv *bat_priv, · line 628
Quoted 1 line
net/batman-adv/tvlv.c +1
-0+WARN_ON (!orig_node);
Please add the include of linux/bug.h for pr_warn_once.
Quoted 5 lines
net/batman-adv/tvlv.h +0
-0
net/batman-adv/tvlv.h void batadv_tvlv_container_register(struct batadv_priv *bat_priv, · line 37
Quoted 9 lines
net/batman-adv/tvlv.h +3
-1@@ -30,12 +30,21 @@ void batadv_tvlv_container_register(struct batadv_priv *bat_priv,u16 batadv_tvlv_container_ogm_append (struct batadv_priv *bat_priv,unsigned char **packet_buff,int *packet_buff_len,int packet_min_len); +void *batadv_tvlv_ogm_pack_ctx (struct batadv_orig_node *orig_node); +struct batadv_orig_node *batadv_tvlv_ogm_unpack_ctx (void *ctx);void batadv_tvlv_ogm_receive (struct batadv_priv *bat_priv, -struct batadv_ogm_packet *batadv_ogm_packet, +const struct sk_buff *skb,struct batadv_orig_node *orig_node);
The forward declaration for "struct batadv_ogm_packet;" should now be replaced with "struct sk_buff;"
Thanks,
Sven
PATCH 3/3 batman-adv: Evaluate and use neighborhood hash TVLV
In reply to Linus LüssingThis patch aims to reduce protocol overhead for BATMAN V by avoiding rebroadcasts of OGM2 and broadcast packets in neighborhoods where every neighbor "sees" another.
This is done by parsing and storing the new information provided by the ELP specific neighborhood hash TVLV.
We then use this new information to detect certain scenarios where a rebroadcast of OGM2 and broadcast packets on the incoming interface is unncessary.
In a nutshell the detection checks whether all neighbors see each other by comparing their with a neighbors hash. If so, then a node deciding to rebroadcast will check whether either the ingress side or the egress side might be a bottleneck metric wise. In other words, whether a rebroadcast might not enhance any throughput.
--- net/batman-adv/bat_v.c | 40 ++++- net/batman-adv/bat_v_elp.c | 315 +++++++++++++++++++++++++++++++++++++++- net/batman-adv/bat_v_elp.h | 10 ++ net/batman-adv/bat_v_ogm.c | 19 ++- net/batman-adv/bat_v_ogm.h | 4 + net/batman-adv/hard-interface.c | 47 +++--- net/batman-adv/hard-interface.h | 6 +- net/batman-adv/send.c | 8 +- net/batman-adv/types.h | 17 +++ 9 files changed, 431 insertions(+), 35 deletions(-)
net/batman-adv/bat_v.c +36 -4
@@ -125,6 +125,9 @@ static void batadv_v_hardif_neigh_init(struct batadv_hardif_neigh_node *hardif_neigh) {ewma_throughput_init (&hardif_neigh->bat_v.throughput); + hardif_neigh->bat_v.min_throughput =0 ; +memset (hardif_neigh->bat_v.neigh_hash,0 , +sizeof (hardif_neigh->bat_v.neigh_hash));INIT_WORK (&hardif_neigh->bat_v.metric_work, batadv_v_elp_throughput_metric_update); }
@@ -171,14 +174,33 @@ batadv_v_hardif_neigh_print(struct seq_file *seq, {int last_secs, last_msecs;u32 throughput; +char nhh_avoid_ogm ='.' , nhh_avoid_bcast ='.' ; +bool same_hash; + + same_hash =batadv_v_elp_nhh_cmp (hardif_neigh); + +if (same_hash) { +if (batadv_v_elp_rx_ingress_bad (hardif_neigh)) + nhh_avoid_ogm ='A' ; + +if (batadv_v_elp_rx_egress_bad (hardif_neigh)) + nhh_avoid_ogm = (nhh_avoid_ogm =='.' ) ?'B' :'C' ; + +if (batadv_v_elp_tx_ingress_bad (hardif_neigh)) + nhh_avoid_bcast ='X' ; + +if (batadv_v_elp_tx_egress_bad (hardif_neigh)) + nhh_avoid_bcast = (nhh_avoid_bcast =='.' ) ?'Y' :'Z' ; + } last_secs =jiffies_to_msecs (jiffies - hardif_neigh->last_seen) /1000 ; last_msecs =jiffies_to_msecs (jiffies - hardif_neigh->last_seen) %1000 ; throughput =ewma_throughput_read (&hardif_neigh->bat_v.throughput); -seq_printf (seq,"%pM %4i.%03is (%9u.%1u) [%10s]\n" , +seq_printf (seq,"%pM %4i.%03is (%9u.%1u) [%10s] [%c%c%c]\n" , hardif_neigh->addr, last_secs, last_msecs, throughput /10 , - throughput %10 , hardif_neigh->if_incoming->net_dev->name); + throughput %10 , hardif_neigh->if_incoming->net_dev->name, + same_hash ?'H' :'.' , nhh_avoid_ogm, nhh_avoid_bcast); }/**
@@ -195,7 +217,7 @@ static void batadv_v_neigh_print(struct batadv_priv *bat_priv,int batman_count =0 ;seq_puts (seq, -" Neighbor last-seen ( throughput) [ IF]\n" ); +" Neighbor last-seen ( throughput) [ IF] NHH-flags\n" );rcu_read_lock ();list_for_each_entry_rcu (hard_iface, &batadv_hardif_list, list) {
@@ -1038,6 +1060,7 @@ static struct batadv_algo_ops batadv_batman_v __read_mostly = { }, .neigh = { .hardif_init = batadv_v_hardif_neigh_init, + .hardif_no_broadcast = batadv_v_elp_no_broadcast, .cmp = batadv_v_neigh_cmp, .is_similar_or_better = batadv_v_neigh_is_sob,#ifdef CONFIG_BATMAN_ADV_DEBUGFS
@@ -1080,6 +1103,9 @@ void batadv_v_hardif_init(struct batadv_hard_iface *hard_iface) bat_v->min_throughput =0 ; bat_v->max_throughput = (~(u32 )0 ); + bat_v->min_throughput_other =0 ; + bat_v->max_throughput_other = ~((u32 )0 ); +memset (bat_v->neigh_hash,0 ,sizeof (bat_v->neigh_hash)); }
@@ -1094,9 +1120,15 @@ int batadv_v_mesh_init(struct batadv_priv *bat_priv) {int ret =0 ; + ret =batadv_v_elp_mesh_init (bat_priv); +if (ret <0 ) +return ret; + ret =batadv_v_ogm_init (bat_priv); -if (ret <0 ) +if (ret <0 ) { +batadv_v_elp_mesh_free (bat_priv);return ret; + }/* set default throughput difference threshold to 5Mbps */ atomic_set (&bat_priv->gw.sel_class,50 );
net/batman-adv/bat_v_elp.c +312 -3
387 lines not on this page · raw message
net/batman-adv/bat_v_elp.h +10 -0
@@ -23,6 +23,8 @@struct sk_buff ;struct work_struct ; +int batadv_v_elp_mesh_init (struct batadv_priv *bat_priv); +void batadv_v_elp_mesh_free (struct batadv_priv *bat_priv);int batadv_v_elp_init (void );void batadv_v_elp_free (void );int batadv_v_elp_iface_enable (struct batadv_hard_iface *hard_iface);
@@ -32,6 +34,14 @@ void batadv_v_elp_iface_activate(struct batadv_hard_iface *primary_iface,void batadv_v_elp_primary_iface_set (struct batadv_hard_iface *primary_iface);int batadv_v_elp_packet_recv (struct sk_buff *skb,struct batadv_hard_iface *if_incoming); +bool batadv_v_elp_nhh_cmp (struct batadv_hardif_neigh_node *hardif_neigh); +bool batadv_v_elp_rx_ingress_bad (struct batadv_hardif_neigh_node *hardif_neigh); +bool batadv_v_elp_rx_egress_bad (struct batadv_hardif_neigh_node *hardif_neigh); +bool batadv_v_elp_tx_ingress_bad (struct batadv_hardif_neigh_node *hardif_neigh); +bool batadv_v_elp_tx_egress_bad (struct batadv_hardif_neigh_node *hardif_neigh); +bool batadv_v_elp_no_broadcast (struct batadv_hard_iface *if_outgoing, +struct batadv_hardif_neigh_node *hardif_neigh, +bool inverse_metric);void batadv_v_elp_throughput_metric_update (struct work_struct *work);#endif /* _NET_BATMAN_ADV_BAT_V_ELP_H_ */
net/batman-adv/bat_v_ogm.c +13 -6
@@ -43,6 +43,7 @@#include "hard-interface.h" #include "hash.h" #include "log.h" +#include "bat_v_ogm.h" #include "originator.h" #include "packet.h" #include "routing.h"
@@ -183,7 +184,7 @@ static void batadv_v_ogm_send(struct work_struct *work)if (!kref_get_unless_zero (&hard_iface->refcount))continue ; - ret =batadv_hardif_no_broadcast (hard_iface,NULL ,NULL ); + ret =batadv_hardif_no_broadcast (hard_iface,NULL ,NULL , true);if (ret) {char *type;
@@ -197,6 +198,9 @@ static void batadv_v_ogm_send(struct work_struct *work)case BATADV_HARDIF_BCAST_DUPORIG : type ="single neighbor is originator" ;break ; +case BATADV_HARDIF_BCAST_WORSENHH : + type ="worse neighborhood metric" ; +break ;default : type ="unknown" ; }
@@ -289,10 +293,10 @@ void batadv_v_ogm_primary_iface_set(struct batadv_hard_iface *primary_iface)* * Return: the penalised throughput metric. */ -static u32 batadv_v_forward_penalty (struct batadv_priv *bat_priv, -struct batadv_hard_iface *if_incoming, -struct batadv_hard_iface *if_outgoing, -u32 throughput) +u32 batadv_v_forward_penalty (struct batadv_priv *bat_priv, +struct batadv_hard_iface *if_incoming, +struct batadv_hard_iface *if_outgoing, +u32 throughput) {int hop_penalty =atomic_read (&bat_priv->hop_penalty);int hop_penalty_max =BATADV_TQ_MAX_VALUE ;
@@ -752,7 +756,7 @@ static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset, ret =batadv_hardif_no_broadcast (hard_iface, ogm_packet->orig, - hardif_neigh->orig); + hardif_neigh, true);if (ret) {char *type;
@@ -767,6 +771,9 @@ static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset,case BATADV_HARDIF_BCAST_DUPORIG : type ="single neighbor is originator" ;break ; +case BATADV_HARDIF_BCAST_WORSENHH : + type ="worse neighborhood metric" ; +break ;default : type ="unknown" ; }
net/batman-adv/bat_v_ogm.h +4 -0
@@ -30,6 +30,10 @@ int batadv_v_ogm_iface_enable(struct batadv_hard_iface *hard_iface);struct batadv_orig_node *batadv_v_ogm_orig_get (struct batadv_priv *bat_priv,const u8 *addr);void batadv_v_ogm_primary_iface_set (struct batadv_hard_iface *primary_iface); +u32 batadv_v_forward_penalty (struct batadv_priv *bat_priv, +struct batadv_hard_iface *if_incoming, +struct batadv_hard_iface *if_outgoing, +u32 throughput);int batadv_v_ogm_packet_recv (struct sk_buff *skb,struct batadv_hard_iface *if_incoming);
net/batman-adv/hard-interface.c +30 -17
72 lines not on this page · raw message
net/batman-adv/hard-interface.h +5 -1
@@ -45,12 +45,14 @@ enum batadv_hard_if_state {* @BATADV_HARDIF_BCAST_NORECIPIENT: Broadcast not needed, there is no recipient * @BATADV_HARDIF_BCAST_DUPFWD: There is just the neighbor we got it from * @BATADV_HARDIF_BCAST_DUPORIG: There is just the originator +* @BATADV_HARDIF_BCAST_WORSENHH: ELP detected a worse neighborhood metric */ enum batadv_hard_if_bcast {BATADV_HARDIF_BCAST_OK =0 ,BATADV_HARDIF_BCAST_NORECIPIENT ,BATADV_HARDIF_BCAST_DUPFWD ,BATADV_HARDIF_BCAST_DUPORIG , +BATADV_HARDIF_BCAST_WORSENHH , };/**
@@ -78,7 +80,9 @@ int batadv_hardif_min_mtu(struct net_device *soft_iface);void batadv_update_min_mtu (struct net_device *soft_iface);void batadv_hardif_release (struct kref *ref);int batadv_hardif_no_broadcast (struct batadv_hard_iface *if_outgoing, -u8 *orig_addr,u8 *orig_neigh); +u8 *orig_addr, +struct batadv_hardif_neigh_node *hardif_neigh, +bool inverse_metric);/** * batadv_hardif_put - decrement the hard interface refcounter and possibly
net/batman-adv/send.c +4 -4
@@ -786,7 +786,6 @@ static void batadv_send_outstanding_bcast_packet(struct work_struct *work)struct net_device *soft_iface;struct batadv_priv *bat_priv;u8 *neigh_addr; -u8 *orig_neigh;unsigned long send_time = jiffies +msecs_to_jiffies (5 );int ret =0 ;
@@ -821,10 +820,8 @@ static void batadv_send_outstanding_bcast_packet(struct work_struct *work) neigh_addr); } - orig_neigh = neigh_node ? neigh_node->orig :NULL ; - ret =batadv_hardif_no_broadcast (hard_iface, bcast_packet->orig, - orig_neigh); + neigh_node, false);if (ret) {char *type;
@@ -839,6 +836,9 @@ static void batadv_send_outstanding_bcast_packet(struct work_struct *work)case BATADV_HARDIF_BCAST_DUPORIG : type ="single neighbor is originator" ;break ; +case BATADV_HARDIF_BCAST_WORSENHH : + type ="worse neighborhood metric" ; +break ;default : type ="unknown" ; }
net/batman-adv/types.h +17 -0
@@ -111,6 +111,8 @@ enum batadv_v_hard_iface_flags {* @flags: interface specific flags * @min_throughput: worst of all TX throughputs this neighbor has to others * @max_throughput: best of all TX throughputs this neighbor has to others +* @min_throughput_other: worst of all min_throughput's of other neighbors +* @max_throughput_other: worst of all max_throughput's of other neighbors * @neigh_hash: a sha512 hash of all neighbors this neighbor sees * (hash over the alphabetically ordered, concatenated, binary representation) */
@@ -123,6 +125,8 @@ struct batadv_hard_iface_bat_v {u8 flags;u32 min_throughput;u32 max_throughput; +u32 min_throughput_other; +u32 max_throughput_other;u8 neigh_hash[SHA512_DIGEST_SIZE ]; };
@@ -401,6 +405,10 @@ DECLARE_EWMA(throughput, 1024, 8)* @throughput: ewma link throughput towards this neighbor * @elp_interval: time interval between two ELP transmissions * @elp_latest_seqno: latest and best known ELP sequence number +* @min_throughput: worst of all TX throughputs this neighbor has to others +* @max_throughput: best of all TX throughputs this neighbor has to others +* @neigh_hash: a sha512 hash of all neighbors this neighbor sees +* (hash over the alphabetically ordered, concatenated, binary representation) * @last_unicast_tx: when the last unicast packet has been sent to this neighbor * @metric_work: work queue callback item for metric update */
@@ -408,6 +416,9 @@ struct batadv_hardif_neigh_node_bat_v {struct ewma_throughput throughput;u32 elp_interval;u32 elp_latest_seqno; +u32 min_throughput; +u32 max_throughput; +u8 neigh_hash[SHA512_DIGEST_SIZE ];unsigned long last_unicast_tx;struct work_struct metric_work; };
@@ -1426,6 +1437,8 @@ struct batadv_algo_iface_ops {* struct batadv_algo_neigh_ops - mesh algorithm callbacks (neighbour specific) * @hardif_init: called on creation of single hop entry * (optional) +* @hardif_no_broadcast: algorithm specific check(s) regarding rebroadcasts +* (optional) * @cmp: compare the metrics of two neighbors for their respective outgoing * interfaces * @is_similar_or_better: check if neigh1 is equally similar or better than
@@ -1435,6 +1448,10 @@ struct batadv_algo_iface_ops {*/ struct batadv_algo_neigh_ops {void (*hardif_init)(struct batadv_hardif_neigh_node *neigh); +bool (*hardif_no_broadcast) + (struct batadv_hard_iface *if_outgoing, +struct batadv_hardif_neigh_node *hardif_neigh, +bool inverse_metric); int (*cmp)(struct batadv_neigh_node *neigh1, struct batadv_hard_iface *if_outgoing1, struct batadv_neigh_node *neigh2,
Signature · 1 line
2.1.4
Re: [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Evaluate and use neighborhood hash TVLV
net/batman-adv/types.h struct batadv_algo_iface_ops { · line 1457
Quoted 11 lines · On Dienstag, 20. September 2016 14:12:45 CEST Linus Lüssing wrote:
net/batman-adv/types.h +4
-0@@ -1435,6 +1448,10 @@ struct batadv_algo_iface_ops {*/ struct batadv_algo_neigh_ops {void (*hardif_init)(struct batadv_hardif_neigh_node *neigh); +bool (*hardif_no_broadcast) + (struct batadv_hard_iface *if_outgoing, +struct batadv_hardif_neigh_node *hardif_neigh, +bool inverse_metric); int (*cmp)(struct batadv_neigh_node *neigh1, struct batadv_hard_iface *if_outgoing1, struct batadv_neigh_node *neigh2,
Can you shorten hardif_neigh a little bit to avoid this slightly confusing line break after "hardif_no_broadcast)"? Many tools like checkpatch or kernel-doc go crazy about it :)
Thanks,
Sven
Re: [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Evaluate and use neighborhood hash TVLV
In reply to Linus LüssingOn Dienstag, 20. September 2016 14:12:45 CEST Linus Lüssing wrote:
[...]
net/batman-adv/bat_v_elp.c void batadv_v_elp_primary_iface_set(struct batadv_hard_iface *primary_iface) · line 634
Quoted 12 lines
net/batman-adv/bat_v_elp.c +2
-0+/** * batadv_v_elp_neigh_update - update an ELP neighbour node * @bat_priv: the bat priv with all the soft interface information * @neigh_addr: the neighbour interface address @@ -581,6 +628,7 @@ void batadv_v_elp_primary_iface_set(struct batadv_hard_iface *primary_iface)* ELP packet. */ static void batadv_v_elp_neigh_update (struct batadv_priv *bat_priv, +struct sk_buff *skb,u8 *neigh_addr,struct batadv_hard_iface *if_incoming,struct batadv_elp_packet *elp_packet)
skb parameter was added but the kernel-doc header was not added.
Kind regards,
Sven
Re: [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Evaluate and use neighborhood hash TVLV
In reply to Linus LüssingQuoted 4 lines · On Dienstag, 20. September 2016 14:12:45 CEST Linus Lüssing wrote:
net/batman-adv/bat_v.c +0
-0
[...]
net/batman-adv/bat_v.c
Quoted 3 lines
net/batman-adv/bat_v.c +3
-0+ hardif_neigh =batadv_v_elp_unpack_ctx (ctx); +if (WARN_ON (!hardif_neigh)) +return NET_RX_DROP ;
Please include linux/bug.h for WARN_ON.
Quoted 3 lines
index ed5936c..69a9a94 100644
net/batman-adv/bat_v_elp.h +0
-0
[...]
net/batman-adv/bat_v_elp.h void batadv_v_elp_iface_activate(struct batadv_hard_iface *primary_iface, · line 44
Quoted 8 lines
net/batman-adv/bat_v_elp.h +8
-0+bool batadv_v_elp_nhh_cmp (struct batadv_hardif_neigh_node *hardif_neigh); +bool batadv_v_elp_rx_ingress_bad (struct batadv_hardif_neigh_node *hardif_neigh); +bool batadv_v_elp_rx_egress_bad (struct batadv_hardif_neigh_node *hardif_neigh); +bool batadv_v_elp_tx_ingress_bad (struct batadv_hardif_neigh_node *hardif_neigh); +bool batadv_v_elp_tx_egress_bad (struct batadv_hardif_neigh_node *hardif_neigh); +bool batadv_v_elp_no_broadcast (struct batadv_hard_iface *if_outgoing, +struct batadv_hardif_neigh_node *hardif_neigh, +bool inverse_metric);
Please include linux/types.h for bool.
net/batman-adv/bat_v_ogm.c line 49
Quoted 12 lines
net/batman-adv/bat_v_ogm.c +1
-0@@ -43,6 +43,7 @@#include "hard-interface.h" #include "hash.h" #include "log.h" +#include "bat_v_ogm.h" #include "originator.h" #include "packet.h" #include "routing.h"
Please remove this duplicate include. bat_v_ogm.h is the first include in this file :)
Thanks,
Sven
Quoted 8 lines · Linus Lüssing
Hi,
Here's the second broadcast avoidance patchset (rebased on the former one).
Hopefully, those two patchsets together should be an automatic approach and replacement for the (non-upstream) no-rebroadcast flag patch and the cases it is currently used for.
Quoted 7 lines
Documentation:
* https://www.open-mesh.org/projects/batman-adv/wiki/Broadcast-AvoidancesBranch:
* https://git.open-mesh.org/batman-adv.git/shortlog/refs/heads/linus/neighhashRegards, Linus
PS: Before I forget, Kudos to Henning who had dropped the idea of using a hash while we were discussing this rebroadcasting topic during dinner at WBMv9.