Skip to content

Commit ecb5db6

Browse files
Cristib05jhedberg
authored andcommitted
samples: net: openthread: border_router: Fix packet forwarding bug
This commit fixes an issue introduced in #97531. Multicast routes added by application are now set to have a prefix length of 16 bits instead of 128. This will allow multicast routing to all IPv6 addresses from those groups. For the OpenThread multicast listener callback, route length will be set to 128 bits, as a MLD event is expected when an address is subscribed. Route lookup has been removed since one will always be found as the application registers multicast routes with same scope, but with a smaller prefix length. Fixed issue regarding packet forwarding and BBR state. Previously, code was covering only the case wehn BBR was secondary and packet was received from backbone interface. A secondary BBR should not forward a multicast packet from OT interface to backbone interface and vice versa. Improved unicast forwarding function to return from the beginning if the packet has a multicast destination. Signed-off-by: Cristian Bulacu <[email protected]>
1 parent 74b3617 commit ecb5db6

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

subsys/net/l2/openthread/openthread_border_router.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,8 @@ static void ot_bbr_multicast_listener_handler(void *context,
282282
memcpy(recv_addr.s6_addr, address->mFields.m32, sizeof(otIp6Address));
283283

284284
if (event == OT_BACKBONE_ROUTER_MULTICAST_LISTENER_ADDED) {
285-
entry = net_route_mcast_lookup(&recv_addr);
286-
if (entry == NULL) {
287-
entry = net_route_mcast_add(ot_context->iface, &recv_addr,
288-
NUM_BITS(struct in6_addr));
289-
}
285+
entry = net_route_mcast_add(ot_context->iface, &recv_addr,
286+
NUM_BITS(struct in6_addr));
290287
if (entry != NULL) {
291288
/*
292289
* No need to perform mcast_lookup explicitly as it's already done in
@@ -466,14 +463,15 @@ static bool openthread_border_router_can_forward_multicast(struct net_pkt *pkt)
466463
}
467464

468465
if (net_ipv6_is_addr_mcast_raw(hdr->dst)) {
466+
/* A secondary BBR should not forward onto an external iface
467+
* or from external network.
468+
*/
469+
if (otBackboneRouterGetState(instance) == OT_BACKBONE_ROUTER_STATE_SECONDARY ||
470+
otBackboneRouterGetState(instance) == OT_BACKBONE_ROUTER_STATE_DISABLED) {
471+
return false;
472+
}
469473
/* AIL to Thread network message */
470474
if (net_pkt_orig_iface(pkt) == ail_iface_ptr) {
471-
if (otBackboneRouterGetState(instance) ==
472-
OT_BACKBONE_ROUTER_STATE_SECONDARY ||
473-
otBackboneRouterGetState(instance) ==
474-
OT_BACKBONE_ROUTER_STATE_DISABLED) {
475-
return false;
476-
}
477475
if (openthread_border_router_has_multicast_listener(hdr->dst)) {
478476
return true;
479477
}
@@ -510,6 +508,10 @@ static bool openthread_border_router_check_unicast_packet_forwarding_policy(stru
510508
return false;
511509
}
512510

511+
if (net_ipv6_is_addr_mcast_raw(hdr->dst)) {
512+
return false;
513+
}
514+
513515
/*
514516
* This is the case when a packet from OpenThread stack is sent via UDP platform.
515517
* Packet will be eventually returned to OpenThread interface, but it won't have
@@ -594,8 +596,8 @@ static void openthread_border_router_add_route_to_multicast_groups(void)
594596

595597
ARRAY_FOR_EACH(mcast_group_idx, i) {
596598

597-
net_ipv6_addr_create(&addr, (0xff << 8) | mcast_group_idx[i], 0, 0, 0, 0, 0, 0, 1);
598-
entry = net_route_mcast_add(ail_iface_ptr, &addr, NUM_BITS(struct in6_addr));
599+
net_ipv6_addr_create(&addr, (0xff << 8) | mcast_group_idx[i], 0, 0, 0, 0, 0, 0, 0);
600+
entry = net_route_mcast_add(ail_iface_ptr, &addr, 16);
599601
if (entry != NULL) {
600602
mcast_addr = net_if_ipv6_maddr_add(ail_iface_ptr,
601603
(const struct in6_addr *)&addr);

0 commit comments

Comments
 (0)