On Monday, August 14, 2023 5:35:28 PM CEST Simon Wunderlich wrote: > 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. > > [...] 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. > > +/** > > + * 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_SUCCESS or NET_RX_DROP on success or a negative error > > + * code on failure. NET_RX_SUCCESS if the received packet is supposed to > > be + * decapsulated and forwarded to the own soft interface, NET_RX_DROP > > otherwise. + */ > > +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); > > +} > > diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c > > index 34903df4fe93..e46ce83c516a 100644 > > --- a/net/batman-adv/originator.c > > +++ b/net/batman-adv/originator.c > > @@ -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); > > diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c > > index 163cd43c4821..f1061985149f 100644 > > --- a/net/batman-adv/routing.c > > +++ b/net/batman-adv/routing.c > > @@ -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_DROP if the skb is not consumed, NET_RX_SUCCESS > > otherwise. + */ > > +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; > > + > > + 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