Implementation of a Stateless Multicast Packet Type
v6 cover Implementation of a Stateless Multicast Packet Type
Hi,
The following patchset implements a stateless, TVLV capable batman-adv multicast packet type.
The new batman-adv multicast packet type allows to contain several originator destination MAC addresses within a TVLV. Routers on the way will potentially split the batman-adv multicast packet and adjust its tracker TVLV contents.
Routing decisions are still based on the selected BATMAN IV or BATMAN V routing algorithm. So this new batman-adv multicast packet type retains the same loop-free properties.
The purpose of this new packet type is to allow to forward an IP multicast packet with less transmissions / overhead than the multicast-via-multiple-unicasts approach. Or to reach a lot more destinations (currently up to 196, depending on the payload size, see Wiki documentation for details) than with the default multicast fanout for the via-unicasts approach.
This will allow using applications like mDNS again in several Freifunk communities. And with less transmissions will also make more bulky multicast applications, like media streaming (to an assessable amount of receivers) a lot more feasible.
This approach is way simpler than the original multicast (tracker) packet approach we envisioned years ago. As it involves no maintenance of an extra, state based multicast routing table. However the TVLV capability should allow to extend things later, to split control and data plane a bit more for instance, to further increase the number of destinations, to further reduce overhead.
A compact overview can be found in the Wiki here, including limitations:
https://www.open-mesh.org/projects/batman-adv/wiki/Multicast-Packet-Type
Regards, Linus
---
Changelog v6:
* PATCH 2/3:
* add missing include of linux/compiler.h for the newly added likely() in v5
* added kerneldoc for @num_dests_pushed to
the in v5 newly added batadv_mcast_forw_push_adjust_padding()
* updated kerneldoc of batadv_mcast_forw_push_adjust_padding(), original text was wrongly copy & pasted from batadv_mcast_forw_push_est_padding() without adjustments
* PATCH 3/3:
* added missing "static" attribute to the newly added batadv_mcast_forw_shrink_align_offset() in v5
Changelog v5:
* removed patches 1/5 + 2/5, as they were already applied
* rebased to current main branch
* changed padding behaviour:
* now 2 bytes padding on the end of the multicast tracker TVLV, if number of destination nodes is even
* as number of destination nodes might change between initial check until after pushing them, functions to post-adjust padding after pushing were added
* added/fixed TTL handling
* removed skb_pull() bailing from sub-functions of batadv_mcast_forw_push(), to only have a single skb_pull() to keep track of in batadv_mcast_forw_push() to revert the changes to the skb; instead a "unsigned short *tvlv_len" is passsed along in batadv_mcast_.*push.*() functions to keep track of how many bytes were pushed
* moved + verified skb->ip_summed invalidation
* batadv_mcast_forw_shrink_tracker() xmas tree ordering
* reword batadv_mcast_forw_push_dest() "Return:" kerneldoc
* fixed spelling: outter -> outer
Changelog v4:
* PATCH 4/5:
* add missing include for linux/types.h in multicast.h
* add missing kerneldoc for @bat_priv in batadv_mcast_forw_push_dest() and batadv_mcast_forw_push_tvlvs()
* use sizeof_field(type, field) instead of sizeof(((type *)0)->field) in batadv_mcast_forw_push_dest()
* PATCH 5/5:
* rename num_dests_remove to num_dests_reduce in batadv_mcast_forw_shrink_align_offse() to fix kerneldocs and for consistency
* fix typo in kerneldoc in batadv_mcast_forw_shrink_update_headers()
-> @num_dest_reduce -> @num_dests_reduce
* use sizeof_field(type, field) instead of sizeof(((type *)0)->field) in batadv_mcast_forw_shrink_align_offset()
Changelog v3:
* PATCH 1/5:
* remove now obsolete includes
* PATCH 2/5:
* fix batadv_tvlv_handler_register() in network-coding.c
* add missing include for linux/skbuff.h
* move variable declarations out of the switch case
in batadv_tvlv_call_handler()
* PATCH 3/5:
* remove unnecessary include of multicast.h in routing.c
* add a few missing includes to multicast_forw.c (linux/byteorder/generic.h, linux/errno.h, linux/gfp.h, linux/stddef.h uapi/linux/batadv_packet.h, multicast.h)
* PATCH 4/5:
* add missing rcu_read_unlock() in error case before returning in batadv_mcast_forw_push_dests_list()
* remove unnecessary include of soft-interface.h in multicast_forw.c
* add a few missing includes to multicast_forw.c (linux/bug.h, linux/build_bug.h, linux/limits.h, linux/rculist.h, linux/rcupdate.h, linux/string.h)
* make batadv_mcast_forw_mode_by_count() static
* fix return types in the declaration of batadv_mcast_forw_packet_hdrlen() and batadv_mcast_forw_push() in multicast.h
* fix typo in commit message: "that the are capable of"
-> "that the*y* are capable of"
* PATCH 5/5:
* make batadv_mcast_forw_shrink_pack_dests() adhere to 80 characters per line for consistency
* add a "continue" statement after the jump label in batadv_mcast_forw_shrink_pack_dests() to silence the sparse error "error: label at end of compound statement"
Changelog v2:
* Add "[PATCH v2 0/5]" prefix to title of cover letter, so that Patchwork can hopefully find it - no other changes
PATCH v6 1/3 batman-adv: mcast: implement multicast packet reception and forwarding
Implement functionality to receive and forward a new TVLV capable multicast packet type.
The new batman-adv multicast packet type allows to contain several originator destination addresses within a TVLV. Routers on the way will potentially split the batman-adv multicast packet and adjust its tracker TVLV contents.
Routing decisions are still based on the selected BATMAN IV or BATMAN V routing algorithm. So this new batman-adv multicast packet type retains the same loop-free properties.
Also a new OGM multicast TVLV flag is introduced to signal to other nodes that we are capable of handling a batman-adv multicast packet and multicast tracker TVLV. And that all of our hard interfaces have an MTU of at least 1280 bytes (IPv6 minimum MTU), as a simple solution for now to avoid MTU issues while forwarding.
--- include/uapi/linux/batadv_packet.h | 45 ++++- net/batman-adv/Makefile | 1 + net/batman-adv/main.c | 2 + net/batman-adv/multicast.c | 48 +++++- net/batman-adv/multicast.h | 5 + net/batman-adv/multicast_forw.c | 256 +++++++++++++++++++++++++++++ net/batman-adv/originator.c | 1 + net/batman-adv/routing.c | 70 ++++++++ net/batman-adv/routing.h | 11 ++ net/batman-adv/soft-interface.c | 12 ++ net/batman-adv/types.h | 64 ++++++++ 11 files changed, 504 insertions(+), 11 deletions(-) create mode 100644 net/batman-adv/multicast_forw.c
include/uapi/linux/batadv_packet.h +39 -6
@@ -116,6 +116,9 @@ enum batadv_icmp_packettype {* only need routable IPv4 multicast packets we signed up for explicitly * @BATADV_MCAST_WANT_NO_RTR6: we have no IPv6 multicast router and therefore * only need routable IPv6 multicast packets we signed up for explicitly +* @BATADV_MCAST_HAVE_MC_PTYPE_CAPA: we can parse, receive and forward +* batman-adv multicast packets with a multicast tracker TVLV. And all our +* hard interfaces have an MTU of at least 1280 bytes. */ enum batadv_mcast_flags {BATADV_MCAST_WANT_ALL_UNSNOOPABLES =1UL <<0 ,
@@ -123,6 +126,7 @@ enum batadv_mcast_flags {BATADV_MCAST_WANT_ALL_IPV6 =1UL <<2 ,BATADV_MCAST_WANT_NO_RTR4 =1UL <<3 ,BATADV_MCAST_WANT_NO_RTR6 =1UL <<4 , + BATADV_MCAST_HAVE_MC_PTYPE_CAPA = 1UL << 5, };/* tt data subtypes */
@@ -174,14 +178,16 @@ enum batadv_bla_claimframe {* @BATADV_TVLV_TT: translation table tvlv * @BATADV_TVLV_ROAM: roaming advertisement tvlv * @BATADV_TVLV_MCAST: multicast capability tvlv +* @BATADV_TVLV_MCAST_TRACKER: multicast tracker tvlv */ enum batadv_tvlv_type { -BATADV_TVLV_GW =0x01 , -BATADV_TVLV_DAT =0x02 , -BATADV_TVLV_NC =0x03 , -BATADV_TVLV_TT =0x04 , -BATADV_TVLV_ROAM =0x05 , -BATADV_TVLV_MCAST =0x06 , +BATADV_TVLV_GW =0x01 , +BATADV_TVLV_DAT =0x02 , +BATADV_TVLV_NC =0x03 , +BATADV_TVLV_TT =0x04 , +BATADV_TVLV_ROAM =0x05 , +BATADV_TVLV_MCAST =0x06 , +BATADV_TVLV_MCAST_TRACKER =0x07 , };#pragma pack(2)
@@ -487,6 +493,25 @@ struct batadv_bcast_packet {*/ }; +/** +* struct batadv_mcast_packet - multicast packet for network payload +* @packet_type: batman-adv packet type, part of the general header +* @version: batman-adv protocol version, part of the general header +* @ttl: time to live for this packet, part of the general header +* @reserved: reserved byte for alignment +* @tvlv_len: length of the appended tvlv buffer (in bytes) +*/ +struct batadv_mcast_packet { +__u8 packet_type; +__u8 version; +__u8 ttl; +__u8 reserved; +__be16 tvlv_len; +/* "4 bytes boundary + 2 bytes" long to make the payload after the +* following ethernet header again 4 bytes boundary aligned +*/ +}; +/** * struct batadv_coded_packet - network coded packet * @packet_type: batman-adv packet type, part of the general header
@@ -628,6 +653,14 @@ struct batadv_tvlv_mcast_data { __u8 reserved[3]; }; +/** +* struct batadv_tvlv_mcast_tracker - payload of a multicast tracker tvlv +* @num_dests: number of subsequent destination originator MAC addresses +*/ +struct batadv_tvlv_mcast_tracker { +__be16 num_dests; +}; +#pragma pack()#endif /* _UAPI_LINUX_BATADV_PACKET_H_ */
net/batman-adv/Makefile +1 -0
@@ -20,6 +20,7 @@ batman-adv-y += hash.o batman-adv-$(CONFIG_BATMAN_ADV_DEBUG) += log.o batman-adv-y += main.o batman-adv-$(CONFIG_BATMAN_ADV_MCAST) += multicast.o +batman-adv-$(CONFIG_BATMAN_ADV_MCAST) += multicast_forw.o batman-adv-y += netlink.o batman-adv-$(CONFIG_BATMAN_ADV_NC) += network-coding.o batman-adv-y += originator.o
net/batman-adv/main.c +2 -0
@@ -532,6 +532,8 @@ static void batadv_recv_handler_init(void)/* broadcast packet */ batadv_rx_handler[BATADV_BCAST ] = batadv_recv_bcast_packet; +/* multicast packet */ + batadv_rx_handler[BATADV_MCAST ] = batadv_recv_mcast_packet;/* unicast packets ... */ /* unicast with 4 addresses packet */
net/batman-adv/multicast.c +43 -5
84 lines not on this page · raw message
net/batman-adv/multicast.h +5 -0
@@ -52,6 +52,11 @@ void batadv_mcast_free(struct batadv_priv *bat_priv);void batadv_mcast_purge_orig (struct batadv_orig_node *orig_node); +/* multicast_forw.c */ + +int batadv_mcast_forw_tracker_tvlv_handler (struct batadv_priv *bat_priv, +struct sk_buff *skb); +#else static inline enum batadv_forw_mode
net/batman-adv/multicast_forw.c new file +256 -0
256 lines not on this page · raw message
net/batman-adv/originator.c +1 -0
@@ -942,6 +942,7 @@ struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv,#ifdef CONFIG_BATMAN_ADV_MCAST orig_node->mcast_flags =BATADV_MCAST_WANT_NO_RTR4 ; orig_node->mcast_flags |=BATADV_MCAST_WANT_NO_RTR6 ; + orig_node->mcast_flags |=BATADV_MCAST_HAVE_MC_PTYPE_CAPA ;INIT_HLIST_NODE (&orig_node->mcast_want_all_unsnoopables_node);INIT_HLIST_NODE (&orig_node->mcast_want_all_ipv4_node);INIT_HLIST_NODE (&orig_node->mcast_want_all_ipv6_node);
net/batman-adv/routing.c +70 -0
73 lines not on this page · raw message
net/batman-adv/routing.h +11 -0
@@ -27,6 +27,17 @@ int batadv_recv_frag_packet(struct sk_buff *skb, struct batadv_hard_iface *iface);int batadv_recv_bcast_packet (struct sk_buff *skb,struct batadv_hard_iface *recv_if); +#ifdef CONFIG_BATMAN_ADV_MCAST +int batadv_recv_mcast_packet (struct sk_buff *skb, +struct batadv_hard_iface *recv_if); +#else +static inline int batadv_recv_mcast_packet (struct sk_buff *skb, +struct batadv_hard_iface *recv_if) +{ +kfree_skb (skb); +return NET_RX_DROP ; +} +#endif int batadv_recv_tt_query (struct sk_buff *skb,struct batadv_hard_iface *recv_if); int batadv_recv_roam_adv(struct sk_buff *skb,
net/batman-adv/soft-interface.c +12 -0
@@ -922,6 +922,18 @@ static const struct { { "tt_response_rx" }, { "tt_roam_adv_tx" }, { "tt_roam_adv_rx" }, +#ifdef CONFIG_BATMAN_ADV_MCAST + { "mcast_tx" }, + { "mcast_tx_bytes" }, + { "mcast_tx_local" }, + { "mcast_tx_local_bytes" }, + { "mcast_rx" }, + { "mcast_rx_bytes" }, + { "mcast_rx_local" }, + { "mcast_rx_local_bytes" }, + { "mcast_fwd" }, + { "mcast_fwd_bytes" }, +#endif #ifdef CONFIG_BATMAN_ADV_DAT { "dat_get_tx" }, { "dat_get_rx" },
net/batman-adv/types.h +64 -0
70 lines not on this page · raw message
Signature · 1 line
2.40.1
Re: [PATCH v6 1/3] batman-adv: mcast: implement multicast packet reception and forwarding
Quoted 19 lines · On Thursday, 20 July 2023 06:35:53 CEST Linus Lüssing wrote:
Implement functionality to receive and forward a new TVLV capable multicast packet type.
The new batman-adv multicast packet type allows to contain several originator destination addresses within a TVLV. Routers on the way will potentially split the batman-adv multicast packet and adjust its tracker TVLV contents.
Routing decisions are still based on the selected BATMAN IV or BATMAN V routing algorithm. So this new batman-adv multicast packet type retains the same loop-free properties.
Also a new OGM multicast TVLV flag is introduced to signal to other nodes that we are capable of handling a batman-adv multicast packet and multicast tracker TVLV. And that all of our hard interfaces have an MTU of at least 1280 bytes (IPv6 minimum MTU), as a simple solution for now to avoid MTU issues while forwarding.
Signed-off-by Linus Lüssing <[email protected]>
Quoted 14 lines
--- include/uapi/linux/batadv_packet.h | 45 ++++- net/batman-adv/Makefile | 1 + net/batman-adv/main.c | 2 + net/batman-adv/multicast.c | 48 +++++- net/batman-adv/multicast.h | 5 + net/batman-adv/multicast_forw.c | 256 +++++++++++++++++++++++++++++ net/batman-adv/originator.c | 1 + net/batman-adv/routing.c | 70 ++++++++ net/batman-adv/routing.h | 11 ++ net/batman-adv/soft-interface.c | 12 ++ net/batman-adv/types.h | 64 ++++++++ 11 files changed, 504 insertions(+), 11 deletions(-) create mode 100644 net/batman-adv/multicast_forw.c
Simon Wunderlich
maintainerRe: [PATCH v6 1/3] batman-adv: mcast: implement multicast packet reception and forwarding
In reply to Linus LüssingQuoted 15 lines · CEST Linus Lüssing
[...]
net/batman-adv/multicast_forw.c new file +3
-0+ +/** +* batadv_mcast_forw_orig_to_neigh() - get next hop neighbor to an orig address + * @bat_priv: the bat priv with all the soft interface information
+ * @orig_addr: the originator MAC address to search the best next hop router for + *
+ * Return: A neighbor node which is the best router towards the given originator + * address.
+ */(quoted diff) +2
-0+static struct batadv_neigh_node * +batadv_mcast_forw_orig_to_neigh(struct batadv_priv *bat_priv, u8
*orig_addr) +{net/batman-adv/multicast_forw.c new file +2
-0+struct batadv_neigh_node *neigh_node; +struct batadv_orig_node *orig_node;
net/batman-adv/multicast_forw.c line 50
Quoted 10 lines
net/batman-adv/multicast_forw.c new file +10
-0+ + orig_node =batadv_orig_hash_find (bat_priv, orig_addr); +if (!orig_node) +return NULL ; + + neigh_node =batadv_find_router (bat_priv, orig_node,NULL ); +batadv_orig_node_put (orig_node); + +return neigh_node; +}
I was wondering if this shouldn't be a generic function rather than a multicast-specific function. It doesn't do anything multicast specific. I couldn't find something similar in other code though.
Quoted 51 lines
net/batman-adv/multicast_forw.c new file +11
-0+ +/** +* batadv_mcast_forw_scrub_dests() - scrub destinations in a tracker TVLV +* @bat_priv: the bat priv with all the soft interface information +* @comp_neigh: next hop neighbor to scrub+collect destinations for +* @dest: start MAC entry in original skb's tracker TVLV +* @next_dest: start MAC entry in to be sent skb's tracker TVLV +* @num_dests: number of remaining destination MAC entries to iterate over +* +* This sorts destination entries into either the original batman-adv +* multicast packet or the skb (copy) that is going to be sent to
comp_neigh+ * next.
+ *
+ * In preparation for the next, to be (unicast) transmitted batman-adv multicast + * packet skb to be sent to the given neighbor node, tries to collect all + * originator MAC addresses that have the given neighbor node as their next hop + * in the to be transmitted skb (copy), whichnext_destpoints into. That is we + * zero all destination entries innext_destwhich do not havecomp_neighas + * their next hop. And zero all destination entries in the original skb that + * would havecomp_neighas their next hop (to avoid redundant transmissions and + * duplicated payload later).
+ */net/batman-adv/multicast_forw.c new file +29
-0+static void +batadv_mcast_forw_scrub_dests (struct batadv_priv *bat_priv, +struct batadv_neigh_node *comp_neigh,u8 *dest, +u8 *next_dest,u16 num_dests) +{ +struct batadv_neigh_node *next_neigh; + +/* skip first entry, this is what we are comparing with */ +eth_zero_addr (dest); + dest +=ETH_ALEN ; + next_dest +=ETH_ALEN ; + num_dests--; + +batadv_mcast_forw_tracker_for_each_dest (next_dest, num_dests) { +if (is_zero_ether_addr (next_dest)) + goto scrub_next; + +if (is_multicast_ether_addr (next_dest)) { +eth_zero_addr (dest); +eth_zero_addr (next_dest); + goto scrub_next; + } + + next_neigh =batadv_mcast_forw_orig_to_neigh (bat_priv, + next_dest); +if (!next_neigh) { +eth_zero_addr (next_dest); + goto scrub_next; + }
net/batman-adv/multicast_forw.c line 111
Quoted 10 lines
net/batman-adv/multicast_forw.c new file +10
-0+ +/* Is this for our next packet to transmit? */ +if (batadv_compare_eth (next_neigh->addr, comp_neigh->addr)) +eth_zero_addr (dest); +else +eth_zero_addr (next_dest); + +batadv_neigh_node_put (next_neigh); +scrub_next: + dest +=ETH_ALEN ;
I've read through that multiple times now, and I don't understand why next_dest isn't getting incremented within each iteration in the same way as dest. Is this a bug or am I missing something? Might be nicer to use one counter which is increased instead of two pointeres, e.g. &dest[counter] and &next_dest[counter] or similar to avoid those kind of bugs.
Quoted 71 lines
[...]
+/**
+ *batadv_mcast_forw_tracker_tvlv_handler()- handle an mcast tracker tvlv
+ * @bat_priv: the bat priv with all the soft interface information
+ * @skb: the received batman-adv multicast packet
+ *
+ * Parses the tracker TVLV of an incoming batman-adv multicast packet and
+ * forwards the packet as indicated in this TVLV.
+ *
+ * Caller needs to set the skb network header to the start of the multicast
+ * tracker TVLV (excluding the generic TVLV header) and the skb transport header + * to the next byte after this multicast tracker TVLV.
+ *
+ * Caller needs to free the skb.
+ *
+ * Return:NET_RX_SUCCESSorNET_RX_DROPon success or a negative error
+ * code on failure.NET_RX_SUCCESSif the received packet is supposed to be
+ * decapsulated and forwarded to the own soft interface,NET_RX_DROPotherwise. + */net/batman-adv/multicast_forw.c new file +5
-0+int batadv_mcast_forw_tracker_tvlv_handler (struct batadv_priv *bat_priv, +struct sk_buff *skb) +{ +return batadv_mcast_forw_packet (bat_priv, skb, false); +}net/batman-adv/originator.c +0
-0@@ -942,6 +942,7 @@ struct batadv_orig_node *batadv_orig_node_new(struct
batadv_priv*bat_priv, #ifdefCONFIG_BATMAN_ADV_MCASTnet/batman-adv/originator.c +1
-0orig_node->mcast_flags =BATADV_MCAST_WANT_NO_RTR4 ; orig_node->mcast_flags |=BATADV_MCAST_WANT_NO_RTR6 ; + orig_node->mcast_flags |=BATADV_MCAST_HAVE_MC_PTYPE_CAPA ;INIT_HLIST_NODE (&orig_node->mcast_want_all_unsnoopables_node);INIT_HLIST_NODE (&orig_node->mcast_want_all_ipv4_node);INIT_HLIST_NODE (&orig_node->mcast_want_all_ipv6_node);net/batman-adv/routing.c +4
-0@@ -1270,3 +1270,73 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,batadv_orig_node_put (orig_node);return ret; } + +#ifdef CONFIG_BATMAN_ADV_MCAST +/** +* batadv_recv_mcast_packet() - process received batman-adv multicast packet + * @skb: the received batman-adv multicast packet
+ * @recv_if: interface that the skb is received on
+ *
+ * Parses the given, received batman-adv multicast packet. Depending on the
+ * contents of its TVLV forwards it and/or decapsulates it to hand it to the + * soft interface.
+ *
+ * Return:NET_RX_DROPif the skb is not consumed,NET_RX_SUCCESSotherwise. + */net/batman-adv/routing.c +14
-0+int batadv_recv_mcast_packet (struct sk_buff *skb, +struct batadv_hard_iface *recv_if) +{ +struct batadv_priv *bat_priv =netdev_priv (recv_if->soft_iface); +struct batadv_mcast_packet *mcast_packet; +int hdr_size =sizeof (*mcast_packet); +unsigned char *tvlv_buff; +int ret =NET_RX_DROP ; +u16 tvlv_buff_len; + +if (batadv_check_unicast_packet (bat_priv, skb, hdr_size) <0 ) + goto free_skb; + +/* create a copy of the skb, if needed, to modify it. */
net/batman-adv/routing.c int batadv_recv_bcast_packet(struct sk_buff *skb, · line 1309
Quoted 10 lines
net/batman-adv/routing.c +10
-0+if (skb_cow (skb,ETH_HLEN ) <0 ) + goto free_skb; + +/* packet needs to be linearized to access the tvlv content */ +if (skb_linearize (skb) <0 ) + goto free_skb; + + mcast_packet = (struct batadv_mcast_packet *)skb->data; +if (mcast_packet->ttl-- <2 ) + goto free_skb;
More of a nit (since we do the same check in broadcasts), but if ttl == 0 on the incoming packet, then we will actually forward it with ttl =255 and that's a bit stupid ...
Cheers,
Simon
Simon Wunderlich
maintainerRe: [PATCH v6 1/3] batman-adv: mcast: implement multicast packet reception and forwarding
Quoted 6 lines · CEST Simon Wunderlich
I've read through that multiple times now, and I don't understand why
next_destisn't getting incremented within each iteration in the same way as dest. Is this a bug or am I missing something? Might be nicer to use one counter which is increased instead of two pointeres, e.g. &dest[counter] and &next_dest[counter] or similar to avoid those kind of bugs.Quoted 1 line
[...]
Discussed with Sven, next_dest is actually the iterator so it should be incremented at the other place.
I still think this is very hard to read, both Sven and I spent quite some time with pen and paper to understand this function. I would appreciate if it could be simplified.
Quoted 78 lines
Quoted 78 lines
+/**
+ *batadv_mcast_forw_tracker_tvlv_handler()- handle an mcast tracker tvlv
+ * @bat_priv: the bat priv with all the soft interface information
+ * @skb: the received batman-adv multicast packet
+ *
+ * Parses the tracker TVLV of an incoming batman-adv multicast packet and
+ * forwards the packet as indicated in this TVLV.
+ *
+ * Caller needs to set the skb network header to the start of the multicast + * tracker TVLV (excluding the generic TVLV header) and the skb transport header + * to the next byte after this multicast tracker TVLV.
+ *
+ * Caller needs to free the skb.
+ *
+ * Return:NET_RX_SUCCESSorNET_RX_DROPon success or a negative error
+ * code on failure.NET_RX_SUCCESSif the received packet is supposed to be + * decapsulated and forwarded to the own soft interface,NET_RX_DROPotherwise. + */net/batman-adv/multicast_forw.c new file +5
-0+int batadv_mcast_forw_tracker_tvlv_handler (struct batadv_priv *bat_priv, +struct sk_buff *skb) +{ +return batadv_mcast_forw_packet (bat_priv, skb, false); +}net/batman-adv/originator.c +0
-0@@ -942,6 +942,7 @@ struct batadv_orig_node *batadv_orig_node_new(struct
batadv_priv*bat_priv, #ifdefCONFIG_BATMAN_ADV_MCASTorig_node->mcast_flags=BATADV_MCAST_WANT_NO_RTR4;orig_node->mcast_flags|=BATADV_MCAST_WANT_NO_RTR6;
+orig_node->mcast_flags|=BATADV_MCAST_HAVE_MC_PTYPE_CAPA;INIT_HLIST_NODE(&orig_node->mcast_want_all_unsnoopables_node);INIT_HLIST_NODE(&orig_node->mcast_want_all_ipv4_node);INIT_HLIST_NODE(&orig_node->mcast_want_all_ipv6_node);net/batman-adv/routing.c +4
-0@@ -1270,3 +1270,73 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,batadv_orig_node_put (orig_node);return ret; } + +#ifdef CONFIG_BATMAN_ADV_MCAST +/** +* batadv_recv_mcast_packet() - process received batman-adv multicast packet + * @skb: the received batman-adv multicast packet
+ * @recv_if: interface that the skb is received on
+ *
+ * Parses the given, received batman-adv multicast packet. Depending on the + * contents of its TVLV forwards it and/or decapsulates it to hand it to the + * soft interface.
+ *
+ * Return:NET_RX_DROPif the skb is not consumed,NET_RX_SUCCESSotherwise. + */net/batman-adv/routing.c +20
-0+int batadv_recv_mcast_packet (struct sk_buff *skb, +struct batadv_hard_iface *recv_if) +{ +struct batadv_priv *bat_priv =netdev_priv (recv_if->soft_iface); +struct batadv_mcast_packet *mcast_packet; +int hdr_size =sizeof (*mcast_packet); +unsigned char *tvlv_buff; +int ret =NET_RX_DROP ; +u16 tvlv_buff_len; + +if (batadv_check_unicast_packet (bat_priv, skb, hdr_size) <0 ) + goto free_skb; + +/* create a copy of the skb, if needed, to modify it. */ +if (skb_cow (skb,ETH_HLEN ) <0 ) + goto free_skb; + +/* packet needs to be linearized to access the tvlv content */ +if (skb_linearize (skb) <0 ) + goto free_skb;
Quoted 8 lines
net/batman-adv/routing.c int batadv_recv_bcast_packet(struct sk_buff *skb, · line 1309
Quoted 4 lines
net/batman-adv/routing.c +4
-0+ + mcast_packet = (struct batadv_mcast_packet *)skb->data; +if (mcast_packet->ttl-- <2 ) + goto free_skb;More of a nit (since we do the same check in broadcasts), but if ttl == 0 on the incoming packet, then we will actually forward it with ttl =255 and that's a bit stupid ...
Mistake on my end on this one, the original value should be used for the comparison so this is okay.
Cheers,
Simon
PATCH v6 2/3 batman-adv: mcast: implement multicast packet generation
In reply to Linus LüssingImplement the preparation of a batman-adv multicast packet and use this under certain conditions.
For one thing this implements the capability to push a complete batman-adv multicast packet header, including a tracker TVLV with all originator destinations that have signaled interest in it, onto a given ethernet frame with an IP multicast packet inside.
For another checks are implemented to determine if encapsulating a multicast packet in this new batman-adv multicast packet type and using it is feasible. Those checks are:
1) Have all nodes signaled that they are capable of handling the new batman-adv multicast packet type?
2) Do all active hard interfaces of all nodes, including us, have an MTU of at least 1280 bytes?
3) Does a complete multicast packet header with all its destination addresses fit onto the given multicast packet / ethernet frame and does not exceed 1280 bytes?
If all checks passed then the new batman-adv multicast packet type will be used for transmission and distribution. Otherwise we fall back to one or more batman-adv unicast packet transmissions, if possible. Or if not possible we will fall back to classic flooding through a batman-adv broadcast packet.
--- net/batman-adv/multicast.c | 79 +++- net/batman-adv/multicast.h | 25 +- net/batman-adv/multicast_forw.c | 727 ++++++++++++++++++++++++++++++++ net/batman-adv/soft-interface.c | 6 +- net/batman-adv/types.h | 6 + 5 files changed, 835 insertions(+), 8 deletions(-)
net/batman-adv/multicast.c +74 -5
@@ -1177,17 +1177,62 @@ static int batadv_mcast_forw_rtr_count(struct batadv_priv *bat_priv, } } +/** +* batadv_mcast_forw_mode_by_count() - get forwarding mode by count +* @bat_priv: the bat priv with all the soft interface information +* @skb: the multicast packet to check +* @vid: the vlan identifier +* @is_routable: stores whether the destination is routable +* @count: the number of originators the multicast packet need to be sent to +* +* For a multicast packet with multiple destination originators, checks which +* mode to use. For BATADV_FORW_MCAST it also encapsulates the packet with a +* complete batman-adv multicast header. +* +* Return: +* BATADV_FORW_MCAST: If all nodes have multicast packet routing +* capabilities and an MTU >= 1280 on all hard interfaces (including us) +* and the encapsulated multicast packet with all destination addresses +* would still fit into an 1280 bytes batman-adv multicast packet +* (excluding the outer ethernet frame) and we could successfully push +* the full batman-adv multicast packet header. +* BATADV_FORW_UCASTS: If the packet cannot be sent in a batman-adv +* multicast packet and the amount of batman-adv unicast packets needed +* is smaller or equal to the configured multicast fanout. +* BATADV_FORW_BCAST: Otherwise. +*/ +static enum batadv_forw_mode +batadv_mcast_forw_mode_by_count (struct batadv_priv *bat_priv, +struct sk_buff *skb,unsigned short vid, +int is_routable,int count) +{ +unsigned int mcast_hdrlen =batadv_mcast_forw_packet_hdrlen (count); +u8 own_tvlv_flags = bat_priv->mcast.mla_flags.tvlv_flags; + +if (!atomic_read (&bat_priv->mcast.num_no_mc_ptype_capa) && + own_tvlv_flags &BATADV_MCAST_HAVE_MC_PTYPE_CAPA && + skb->len + mcast_hdrlen <=IPV6_MIN_MTU && +batadv_mcast_forw_push (bat_priv, skb, vid, is_routable, count)) +return BATADV_FORW_MCAST ; + +if (count <=atomic_read (&bat_priv->multicast_fanout)) +return BATADV_FORW_UCASTS ; + +return BATADV_FORW_BCAST ; +} +/** * batadv_mcast_forw_mode() - check on how to forward a multicast packet * @bat_priv: the bat priv with all the soft interface information * @skb: the multicast packet to check +* @vid: the vlan identifier * @is_routable: stores whether the destination is routable * * Return: The forwarding mode as enum batadv_forw_mode. */ enum batadv_forw_mode batadv_mcast_forw_mode (struct batadv_priv *bat_priv,struct sk_buff *skb, -int *is_routable) +unsigned short vid,int *is_routable) {int ret, tt_count, ip_count, unsnoop_count, total_count;bool is_unsnoopable = false;
@@ -1217,10 +1262,8 @@ batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb,else if (unsnoop_count)return BATADV_FORW_BCAST ; -if (total_count <=atomic_read (&bat_priv->multicast_fanout)) -return BATADV_FORW_UCASTS ; - -return BATADV_FORW_BCAST ; +return batadv_mcast_forw_mode_by_count (bat_priv, skb, vid, *is_routable, + total_count); }/**
@@ -1780,6 +1823,31 @@ static void batadv_mcast_want_rtr6_update(struct batadv_priv *bat_priv, } } +/** +* batadv_mcast_have_mc_ptype_update() - update multicast packet type counter +* @bat_priv: the bat priv with all the soft interface information +* @orig: the orig_node which multicast state might have changed of +* @mcast_flags: flags indicating the new multicast state +* +* If the BATADV_MCAST_HAVE_MC_PTYPE_CAPA flag of this originator, orig, has +* toggled then this method updates the counter accordingly. +*/ +static void batadv_mcast_have_mc_ptype_update (struct batadv_priv *bat_priv, +struct batadv_orig_node *orig, +u8 mcast_flags) +{ +lockdep_assert_held (&orig->mcast_handler_lock); + +/* switched from flag set to unset */ +if (!(mcast_flags &BATADV_MCAST_HAVE_MC_PTYPE_CAPA ) && + orig->mcast_flags &BATADV_MCAST_HAVE_MC_PTYPE_CAPA ) +atomic_inc (&bat_priv->mcast.num_no_mc_ptype_capa); +/* switched from flag unset to set */ +else if (mcast_flags &BATADV_MCAST_HAVE_MC_PTYPE_CAPA && + !(orig->mcast_flags &BATADV_MCAST_HAVE_MC_PTYPE_CAPA )) +atomic_dec (&bat_priv->mcast.num_no_mc_ptype_capa); +} +/** * batadv_mcast_tvlv_flags_get() - get multicast flags from an OGM TVLV * @enabled: whether the originator has multicast TVLV support enabled
@@ -1848,6 +1916,7 @@ static void batadv_mcast_tvlv_ogm_handler(struct batadv_priv *bat_priv,batadv_mcast_want_ipv6_update (bat_priv, orig, mcast_flags);batadv_mcast_want_rtr4_update (bat_priv, orig, mcast_flags);batadv_mcast_want_rtr6_update (bat_priv, orig, mcast_flags); +batadv_mcast_have_mc_ptype_update (bat_priv, orig, mcast_flags); orig->mcast_flags = mcast_flags;spin_unlock_bh (&orig->mcast_handler_lock);
net/batman-adv/multicast.h +23 -2
@@ -11,6 +11,7 @@#include <linux/netlink.h> #include <linux/skbuff.h> +#include <linux/types.h> /** * enum batadv_forw_mode - the way a packet should be forwarded as
@@ -28,6 +29,12 @@ enum batadv_forw_mode {*/ BATADV_FORW_UCASTS , +/** +* @BATADV_FORW_MCAST: forward the packet to some nodes via a +* batman-adv multicast packet +*/ +BATADV_FORW_MCAST , +/** @BATADV_FORW_NONE: don't forward, drop it */ BATADV_FORW_NONE, };
@@ -36,7 +43,7 @@ enum batadv_forw_mode {enum batadv_forw_mode batadv_mcast_forw_mode (struct batadv_priv *bat_priv,struct sk_buff *skb, -int *is_routable); +unsigned short vid,int *is_routable);int batadv_mcast_forw_send (struct batadv_priv *bat_priv,struct sk_buff *skb,unsigned short vid,int is_routable);
@@ -57,11 +64,18 @@ void batadv_mcast_purge_orig(struct batadv_orig_node *orig_node);int batadv_mcast_forw_tracker_tvlv_handler (struct batadv_priv *bat_priv,struct sk_buff *skb); +unsigned int batadv_mcast_forw_packet_hdrlen (unsigned int num_dests); + +bool batadv_mcast_forw_push (struct batadv_priv *bat_priv,struct sk_buff *skb, +unsigned short vid,int is_routable,int count); + +int batadv_mcast_forw_mcsend (struct batadv_priv *bat_priv,struct sk_buff *skb); +#else static inline enum batadv_forw_mode batadv_mcast_forw_mode (struct batadv_priv *bat_priv,struct sk_buff *skb, -int *is_routable) +unsigned short vid,int *is_routable) {return BATADV_FORW_BCAST ; }
@@ -99,6 +113,13 @@ static inline void batadv_mcast_purge_orig(struct batadv_orig_node *orig_node) { } +static inline int batadv_mcast_forw_mcsend (struct batadv_priv *bat_priv, +struct sk_buff *skb) +{ +kfree_skb (skb); +return NET_XMIT_DROP ; +} +#endif /* CONFIG_BATMAN_ADV_MCAST */ #endif /* _NET_BATMAN_ADV_MULTICAST_H_ */
net/batman-adv/multicast_forw.c +727 -0
754 lines not on this page · raw message
net/batman-adv/soft-interface.c +5 -1
@@ -298,12 +298,13 @@ static netdev_tx_t batadv_interface_tx(struct sk_buff *skb, send:if (do_bcast && !is_broadcast_ether_addr (ethhdr->h_dest)) { - forw_mode =batadv_mcast_forw_mode (bat_priv, skb, + forw_mode =batadv_mcast_forw_mode (bat_priv, skb, vid, &mcast_is_routable);switch (forw_mode) {case BATADV_FORW_BCAST :break ;case BATADV_FORW_UCASTS : +case BATADV_FORW_MCAST : do_bcast = false;break ;case BATADV_FORW_NONE :
@@ -362,6 +363,8 @@ static netdev_tx_t batadv_interface_tx(struct sk_buff *skb, }else if (forw_mode ==BATADV_FORW_UCASTS ) { ret =batadv_mcast_forw_send (bat_priv, skb, vid, mcast_is_routable); + }else if (forw_mode ==BATADV_FORW_MCAST ) { + ret =batadv_mcast_forw_mcsend (bat_priv, skb); }else {if (batadv_dat_snoop_outgoing_arp_request (bat_priv, skb))
@@ -759,6 +762,7 @@ static int batadv_softif_init_late(struct net_device *dev)atomic_set (&bat_priv->mcast.num_want_all_unsnoopables,0 );atomic_set (&bat_priv->mcast.num_want_all_ipv4,0 );atomic_set (&bat_priv->mcast.num_want_all_ipv6,0 ); +atomic_set (&bat_priv->mcast.num_no_mc_ptype_capa,0 );#endif atomic_set (&bat_priv->gw.mode,BATADV_GW_MODE_OFF );atomic_set (&bat_priv->gw.bandwidth_down,100 );
net/batman-adv/types.h +6 -0
@@ -1342,6 +1342,12 @@ struct batadv_priv_mcast {/** @num_want_all_rtr6: counter for items in want_all_rtr6_list */ atomic_t num_want_all_rtr6; +/** +* @num_no_mc_ptype_capa: counter for number of nodes without the +* BATADV_MCAST_HAVE_MC_PTYPE_CAPA flag +*/ +atomic_t num_no_mc_ptype_capa; +/** * @want_lists_lock: lock for protecting modifications to mcasts * want_all_{unsnoopables,ipv4,ipv6}_list (traversals are rcu-locked)
Signature · 1 line
2.40.1
Re: [PATCH v6 2/3] batman-adv: mcast: implement multicast packet generation
Quoted 26 lines · On Thursday, 20 July 2023 06:35:54 CEST Linus Lüssing wrote:
Implement the preparation of a batman-adv multicast packet and use this under certain conditions.
For one thing this implements the capability to push a complete batman-adv multicast packet header, including a tracker TVLV with all originator destinations that have signaled interest in it, onto a given ethernet frame with an IP multicast packet inside.
For another checks are implemented to determine if encapsulating a multicast packet in this new batman-adv multicast packet type and using it is feasible. Those checks are:
1) Have all nodes signaled that they are capable of handling the new batman-adv multicast packet type?
2) Do all active hard interfaces of all nodes, including us, have an MTU of at least 1280 bytes?
3) Does a complete multicast packet header with all its destination addresses fit onto the given multicast packet / ethernet frame and does not exceed 1280 bytes?If all checks passed then the new batman-adv multicast packet type will be used for transmission and distribution. Otherwise we fall back to one or more batman-adv unicast packet transmissions, if possible. Or if not possible we will fall back to classic flooding through a batman-adv broadcast packet.
Quoted 8 lines
Signed-off-by Linus Lüssing <[email protected]>--- net/batman-adv/multicast.c | 79 +++- net/batman-adv/multicast.h | 25 +- net/batman-adv/multicast_forw.c | 727 ++++++++++++++++++++++++++++++++ net/batman-adv/soft-interface.c | 6 +- net/batman-adv/types.h | 6 + 5 files changed, 835 insertions(+), 8 deletions(-)
Quoted 10 lines
net/batman-adv/multicast_forw.c +10
-0+/** +* batadv_mcast_forw_scrape() - remove bytes within skb data +* @skb: the skb to remove bytes from +* @offset: the offset from the skb data from which to scrape +* @len: the amount of bytes to scrape starting from the offset +* +* Scrapes/removes len bytes from the given skb at the given offset from the +* skb data. +* +* Caller needs to ensure that the region from the skb data's start up
net/batman-adv/multicast_forw.c line 372
Quoted 10 lines
net/batman-adv/multicast_forw.c +10
-0+* to/including the to be removed bytes are linearized. +*/ +static void batadv_mcast_forw_scrape (struct sk_buff *skb, +unsigned short offset, +unsigned short len) +{ +char *to =skb_pull (skb, len), *from = to - len; + +memmove (to, from, offset); +}
Just because I remembered it when reading a comment: SKB_LINEAR_ASSERT(skb) might be a good idea in places like this. Not all over the place but actually in the code which operates on the buffer and assumes the skbuff to be linearized. skb_put would do such a check (because it is a put at the end of the skb) but not an skb_pull.
Kind regards,
Sven
PATCH v6 3/3 batman-adv: mcast: shrink tracker packet after scrubbing
In reply to Linus LüssingRemove all zero MAC address entries (00:00:00:00:00:00) from a multicast packet's tracker TVLV before transmitting it and update all headers accordingly. This way, instead of keeping the multicast packet at a constant size throughout its journey through the mesh, it will become more lightweight, smaller with every interested receiver on the way and on each splitting intersection. Which can save some valuable bandwidth.
--- net/batman-adv/multicast_forw.c | 195 ++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+)
net/batman-adv/multicast_forw.c +195 -0
@@ -712,6 +712,200 @@ batadv_mcast_forw_scrub_dests(struct batadv_priv *bat_priv, } } +/** +* batadv_mcast_forw_shrink_pack_dests() - pack destinations of a tracker TVLV +* @skb: the batman-adv multicast packet to compact destinations in +* +* Compacts the originator destination MAC addresses in the multicast tracker +* TVLV of the given multicast packet. This is done by moving all non-zero +* MAC addresses in direction of the skb head and all zero MAC addresses in skb +* tail direction, within the multicast tracker TVLV. +* +* Return: The number of consecutive zero MAC address destinations which are +* now at the end of the multicast tracker TVLV. +*/ +static int batadv_mcast_forw_shrink_pack_dests (struct sk_buff *skb) +{ +struct batadv_tvlv_mcast_tracker *mcast_tracker; +u16 num_dests_slot, num_dests_filler; +unsigned char *skb_net_hdr; +u8 *slot, *filler; + + skb_net_hdr =skb_network_header (skb); + mcast_tracker = (struct batadv_tvlv_mcast_tracker *)skb_net_hdr; + num_dests_slot =ntohs (mcast_tracker->num_dests); + + slot = (u8 *)mcast_tracker +sizeof (*mcast_tracker); + +if (!num_dests_slot) +return 0 ; + + num_dests_filler = num_dests_slot -1 ; + filler = slot +ETH_ALEN ; + +batadv_mcast_forw_tracker_for_each_dest (slot, num_dests_slot) { +/* find an empty slot */ +if (!is_zero_ether_addr (slot)) +continue ; + +/* keep filler ahead of slot */ +if (filler <= slot) { + num_dests_filler = num_dests_slot -1 ; + filler = slot +ETH_ALEN ; + } + +/* find a candidate to fill the empty slot */ +batadv_mcast_forw_tracker_for_each_dest (filler, + num_dests_filler) { +if (is_zero_ether_addr (filler)) +continue ; + +ether_addr_copy (slot, filler); +eth_zero_addr (filler); + goto cont_next_slot; + } + +/* could not find a filler, we can stop +* - and must not advance the slot pointer! +*/ +if (!num_dests_filler) +break ; + +cont_next_slot: +continue ; + } + +/* num_dests_slot is the amount of reduced destinations */ +return num_dests_slot; +} + +/** +* batadv_mcast_forw_shrink_align_offset() - get new alignment offset +* @num_dests_old: the old, to be updated amount of destination nodes +* @num_dests_reduce: the number of destinations that were removed +* +* Calculates the amount of potential extra alignment offset that is needed to +* adjust the TVLV padding after the change in destination nodes. +* +* Return: +* 0: If no change to padding is needed. +* 2: If padding needs to be removed. +* -2: If padding needs to be added. +*/ +static short +batadv_mcast_forw_shrink_align_offset (unsigned int num_dests_old, +unsigned int num_dests_reduce) +{ +/* even amount of removed destinations -> no alignment change */ +if (!(num_dests_reduce %2 )) +return 0 ; + +/* even to odd amount of destinations -> remove padding */ +if (!(num_dests_old %2 )) +return 2 ; + +/* odd to even amount of destinations -> add padding */ +return -2 ; +} + +/** +* batadv_mcast_forw_shrink_update_headers() - update shrunk mc packet headers +* @skb: the batman-adv multicast packet to update headers of +* @num_dests_reduce: the number of destinations that were removed +* +* This updates any fields of a batman-adv multicast packet that are affected +* by the reduced number of destinations in the multicast tracket TVLV. In +* particular this updates: +* +* The num_dest field of the multicast tracker TVLV. +* The TVLV length field of the according generic TVLV header. +* The batman-adv multicast packet's total TVLV length field. +* +* Return: The offset in skb's tail direction at which the new batman-adv +* multicast packet header needs to start. +*/ +static unsigned int +batadv_mcast_forw_shrink_update_headers (struct sk_buff *skb, +unsigned int num_dests_reduce) +{ +struct batadv_tvlv_mcast_tracker *mcast_tracker; +struct batadv_mcast_packet *mcast_packet; +struct batadv_tvlv_hdr *tvlv_hdr; +unsigned char *skb_net_hdr; +unsigned int offset; +short align_offset; +u16 num_dests; + + skb_net_hdr =skb_network_header (skb); + mcast_tracker = (struct batadv_tvlv_mcast_tracker *)skb_net_hdr; + num_dests =ntohs (mcast_tracker->num_dests); + + align_offset =batadv_mcast_forw_shrink_align_offset (num_dests, + num_dests_reduce); + offset =ETH_ALEN * num_dests_reduce + align_offset; + num_dests -= num_dests_reduce; + +/* update tracker header */ + mcast_tracker->num_dests =htons (num_dests); + +/* update tracker's tvlv header's length field */ + tvlv_hdr = (struct batadv_tvlv_hdr *)(skb_network_header (skb) - +sizeof (*tvlv_hdr)); + tvlv_hdr->len =htons (ntohs (tvlv_hdr->len) - offset); + +/* update multicast packet header's tvlv length field */ + mcast_packet = (struct batadv_mcast_packet *)skb->data; + mcast_packet->tvlv_len =htons (ntohs (mcast_packet->tvlv_len) - offset); + +return offset; +} + +/** +* batadv_mcast_forw_shrink_move_headers() - move multicast headers by offset +* @skb: the batman-adv multicast packet to move headers for +* @offset: a non-negative offset to move headers by, towards the skb tail +* +* Moves the batman-adv multicast packet header, its multicast tracker TVLV and +* any TVLVs in between by the given offset in direction towards the tail. +*/ +static void +batadv_mcast_forw_shrink_move_headers (struct sk_buff *skb,unsigned int offset) +{ +struct batadv_tvlv_mcast_tracker *mcast_tracker; +unsigned char *skb_net_hdr; +unsigned int len; +u16 num_dests; + + skb_net_hdr =skb_network_header (skb); + mcast_tracker = (struct batadv_tvlv_mcast_tracker *)skb_net_hdr; + num_dests =ntohs (mcast_tracker->num_dests); + len =skb_network_offset (skb) +sizeof (*mcast_tracker); + len += num_dests *ETH_ALEN ; + +batadv_mcast_forw_scrape (skb, len, offset); +} + +/** +* batadv_mcast_forw_shrink_tracker() - remove zero addresses in a tracker tvlv +* @skb: the batman-adv multicast packet to (potentially) shrink +* +* Removes all destinations with a zero MAC addresses (00:00:00:00:00:00) from +* the given batman-adv multicast packet's tracker TVLV and updates headers +* accordingly to maintain a valid batman-adv multicast packet. +*/ +static void batadv_mcast_forw_shrink_tracker (struct sk_buff *skb) +{ +unsigned int offset; +u16 dests_reduced; + + dests_reduced =batadv_mcast_forw_shrink_pack_dests (skb); +if (!dests_reduced) +return ; + + offset =batadv_mcast_forw_shrink_update_headers (skb, dests_reduced); +batadv_mcast_forw_shrink_move_headers (skb, offset); +} +/** * batadv_mcast_forw_packet() - forward a batman-adv multicast packet * @bat_priv: the bat priv with all the soft interface information
@@ -798,6 +992,7 @@ static int batadv_mcast_forw_packet(struct batadv_priv *bat_priv,batadv_mcast_forw_scrub_dests (bat_priv, neigh_node, dest, next_dest, num_dests); +batadv_mcast_forw_shrink_tracker (nexthop_skb);batadv_inc_counter (bat_priv,BATADV_CNT_MCAST_TX ); batadv_add_counter(bat_priv, BATADV_CNT_MCAST_TX_BYTES,
Signature · 1 line
2.40.1
Re: [PATCH v6 3/3] batman-adv: mcast: shrink tracker packet after scrubbing
Quoted 11 lines · On Thursday, 20 July 2023 06:35:55 CEST Linus Lüssing wrote:
Remove all zero MAC address entries (00:00:00:00:00:00) from a multicast packet's tracker TVLV before transmitting it and update all headers accordingly. This way, instead of keeping the multicast packet at a constant size throughout its journey through the mesh, it will become more lightweight, smaller with every interested receiver on the way and on each splitting intersection. Which can save some valuable bandwidth.
Signed-off-by Linus Lüssing <[email protected]>--- net/batman-adv/multicast_forw.c | 195 ++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+)
Kind regards,
Sven
Simon Wunderlich
maintainerRe: [PATCH v6 3/3] batman-adv: mcast: shrink tracker packet after scrubbing
In reply to Linus LüssingQuoted 61 lines · CEST Linus Lüssing
Remove all zero MAC address entries (00:00:00:00:00:00) from a multicast packet's tracker TVLV before transmitting it and update all headers accordingly. This way, instead of keeping the multicast packet at a constant size throughout its journey through the mesh, it will become more lightweight, smaller with every interested receiver on the way and on each splitting intersection. Which can save some valuable bandwidth.
Signed-off-by Linus Lüssing <[email protected]>--- net/batman-adv/multicast_forw.c | 195 ++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+)(quoted diff) +0
-0
b/net/batman-adv/multicast_forw.cindexd0f75a63de2a..d7b1aabd4b72100644net/batman-adv/multicast_forw.c +2
-0@@ -712,6 +712,200 @@ batadv_mcast_forw_scrub_dests(struct batadv_priv *bat_priv, } } +/** +* batadv_mcast_forw_shrink_pack_dests() - pack destinations of a tracker TVLV + * @skb: the batman-adv multicast packet to compact destinations in + *
+ * Compacts the originator destination MAC addresses in the multicast tracker + * TVLV of the given multicast packet. This is done by moving all non-zero + * MAC addresses in direction of the skb head and all zero MAC addresses in skb + * tail direction, within the multicast tracker TVLV.
+ *
+ * Return: The number of consecutive zero MAC address destinations which are + * now at the end of the multicast tracker TVLV.
+ */net/batman-adv/multicast_forw.c +29
-0+static int batadv_mcast_forw_shrink_pack_dests (struct sk_buff *skb) +{ +struct batadv_tvlv_mcast_tracker *mcast_tracker; +u16 num_dests_slot, num_dests_filler; +unsigned char *skb_net_hdr; +u8 *slot, *filler; + + skb_net_hdr =skb_network_header (skb); + mcast_tracker = (struct batadv_tvlv_mcast_tracker *)skb_net_hdr; + num_dests_slot =ntohs (mcast_tracker->num_dests); + + slot = (u8 *)mcast_tracker +sizeof (*mcast_tracker); + +if (!num_dests_slot) +return 0 ; + + num_dests_filler = num_dests_slot -1 ; + filler = slot +ETH_ALEN ; + +batadv_mcast_forw_tracker_for_each_dest (slot, num_dests_slot) { +/* find an empty slot */ +if (!is_zero_ether_addr (slot)) +continue ; + +/* keep filler ahead of slot */ +if (filler <= slot) { + num_dests_filler = num_dests_slot -1 ; + filler = slot +ETH_ALEN ; + }
net/batman-adv/multicast_forw.c batadv_mcast_forw_scrub_dests(struct batadv_priv *bat_priv, · line 765
Quoted 10 lines
net/batman-adv/multicast_forw.c +10
-0+ +/* find a candidate to fill the empty slot */ +batadv_mcast_forw_tracker_for_each_dest (filler, + num_dests_filler) { +if (is_zero_ether_addr (filler)) +continue ; + +ether_addr_copy (slot, filler); +eth_zero_addr (filler); + goto cont_next_slot;
goto is redundant, just continue
net/batman-adv/multicast_forw.c batadv_mcast_forw_scrub_dests(struct batadv_priv *bat_priv, · line 773
Quoted 8 lines
net/batman-adv/multicast_forw.c +8
-0+ } + +/* could not find a filler, we can stop +* - and must not advance the slot pointer! +*/ +if (!num_dests_filler) +break ; +
This label can then be removed as well.
I'm wondering why we need to keep all those pointers and do the pointer magic in the first place? can't we just make two nested functions like this:
for (all entries)
if zero-entry:
for (all entries)
if non-zero-entry
swap()
(I find this current function very hard to read)
Cheers,
Simon
Sven Eckelmann
maintainerOn Thursday, 20 July 2023 06:35:52 CEST Linus Lüssing wrote:
[...]
Quoted 6 lines
The purpose of this new packet type is to allow to forward an IP multicast packet with less transmissions / overhead than the multicast-via-multiple-unicasts approach. Or to reach a lot more destinations (currently up to 196, depending on the payload size, see Wiki documentation for details) than with the default multicast fanout for the via-unicasts approach.
Please don't forget that batctl's tcpdump+wireshark also requires support for parsing it. Most likely, this was not added yet to not confuse third parties in case the packet format changes.
I have now acked the various patches and have queued them up for submission to net-next. But it would be good when Simon also checks them.
And we must also first release 2023.2 (including submission for net + net-next) before these patches can be added to the batman-adv repository.
Kind regards,
Sven
Sven Eckelmann
maintainerQuoted 2 lines · On Saturday, 29 July 2023 13:11:28 CEST Sven Eckelmann wrote:
I have now acked the various patches and have queued them up for submission to net-next. But it would be good when Simon also checks them.
Just discussed with Simon, and he had some good points regarding the readability of some functions (not so much actual functionality problems)
Kind regards,
Sven