Skip to content

Commit eb4df01

Browse files
ankohuuacassis
authored andcommitted
net/ipforward: Forbid non-forwardable multicast scopes.
RFC 3171 reserves 224.0.0.0/24 for link-local IPv4 multicast scope, so packets in this range must not be forwarded by routers, regardless of the TTL value. IPv6 also defines multicast scopes that must not be forwarded beyond the local topology. In particular, interface-local and link-local multicast destinations must not be routed across interfaces. Add IPv4/IPv6 scope checks so non-forwardable multicast packets are rejected before entering the multicast forwarding path. Signed-off-by: Shunchao Hu <ankohuu@gmail.com>
1 parent 08a1953 commit eb4df01

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

net/ipforward/ipv4_forward.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,18 @@ void ipv4_forward_broadcast(FAR struct net_driver_s *dev,
634634
return;
635635
}
636636

637+
/* Do not forward link-local multicast packets (224.0.0.0/24).
638+
* Per RFC 3171, addresses in 224.0.0.0/24 are reserved for
639+
* link-local scope and MUST NOT be forwarded by any router,
640+
* regardless of TTL.
641+
*/
642+
643+
if ((net_ip4addr_conv32(ipv4->destipaddr) &
644+
HTONL(0xffffff00)) == HTONL(0xe0000000))
645+
{
646+
return;
647+
}
648+
637649
/* Don't bother if the TTL would expire */
638650

639651
if (ipv4->ttl > 1)

net/ipforward/ipv6_forward.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,17 @@ void ipv6_forward_broadcast(FAR struct net_driver_s *dev,
810810
return;
811811
}
812812

813+
/* Do not forward reserved, interface-local, or link-local multicast
814+
* destinations (ffx0::/16, ffx1::/16, ffx2::/16).
815+
*/
816+
817+
if (((ipv6->destipaddr[0] & HTONS(0xff0f)) == HTONS(0xff00)) ||
818+
((ipv6->destipaddr[0] & HTONS(0xff0f)) == HTONS(0xff01)) ||
819+
((ipv6->destipaddr[0] & HTONS(0xff0f)) == HTONS(0xff02)))
820+
{
821+
return;
822+
}
823+
813824
/* Don't bother if the TTL would expire */
814825

815826
if (ipv6->ttl > 1)

0 commit comments

Comments
 (0)