Skip to content

Commit 2fbc694

Browse files
kderdanordicjm
authored andcommitted
[nrf fromtree] net: ipv6: mcast_routing: hop limit handling
While forwarding a multicast packet decrement hop limit in a common net buffer. Also, packets with hop limit equal to 0 should not be forwarded. Signed-off-by: Konrad Derda <[email protected]> (cherry picked from commit 30c38179e8998253195de58f3b8fb394cd26b092)
1 parent 4c996ec commit 2fbc694

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

subsys/net/ip/ipv6.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,15 @@ static enum net_verdict ipv6_forward_mcast_packet(struct net_pkt *pkt,
411411
#if defined(CONFIG_NET_ROUTE_MCAST)
412412
int routed;
413413

414-
/* check if routing loop could be created or if the destination is of
415-
* interface local scope or if from link local source
414+
/* Continue processing without forwarding if:
415+
* 1. routing loop could be created
416+
* 2. the destination is of interface local scope
417+
* 3. is from link local source
418+
* 4. hop limit is or would become zero
416419
*/
417-
if (net_ipv6_is_addr_mcast((struct in6_addr *)hdr->src) ||
418-
net_ipv6_is_addr_mcast_iface((struct in6_addr *)hdr->dst) ||
419-
net_ipv6_is_ll_addr((struct in6_addr *)hdr->src)) {
420+
if (net_ipv6_is_addr_mcast((struct in6_addr *)hdr->src) ||
421+
net_ipv6_is_addr_mcast_iface((struct in6_addr *)hdr->dst) ||
422+
net_ipv6_is_ll_addr((struct in6_addr *)hdr->src) || hdr->hop_limit <= 1) {
420423
return NET_CONTINUE;
421424
}
422425

subsys/net/ip/route.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,11 +815,16 @@ static void propagate_mld_event(struct net_route_entry_mcast *route, bool route_
815815
#define propagate_mld_event(...)
816816
#endif /* CONFIG_NET_MCAST_ROUTE_MLD_REPORTS */
817817

818-
int net_route_mcast_forward_packet(struct net_pkt *pkt,
819-
const struct net_ipv6_hdr *hdr)
818+
int net_route_mcast_forward_packet(struct net_pkt *pkt, struct net_ipv6_hdr *hdr)
820819
{
821820
int ret = 0, err = 0;
822821

822+
/* At this point, the original pkt has already stored the hop limit in its metadata.
823+
* Change its value in a common buffer so the forwardee has a proper count. As we have
824+
* a direct access to the buffer there is no need to perform read/write operations.
825+
*/
826+
hdr->hop_limit--;
827+
823828
ARRAY_FOR_EACH_PTR(route_mcast_entries, route) {
824829
struct net_pkt *pkt_cpy = NULL;
825830

subsys/net/ip/route.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ typedef void (*net_route_mcast_cb_t)(struct net_route_entry_mcast *entry,
224224
* value in case of an error.
225225
*/
226226
int net_route_mcast_forward_packet(struct net_pkt *pkt,
227-
const struct net_ipv6_hdr *hdr);
227+
struct net_ipv6_hdr *hdr);
228228

229229
/**
230230
* @brief Go through all the multicast routing entries and call callback

0 commit comments

Comments
 (0)