Skip to content

Commit b76ffd6

Browse files
lmaciejonczykcarlescufi
authored andcommitted
[nrf fromtree] net: openthread: filter ipv6 fragments
If OPENTHREAD_IP6_FRAGM is enabled the IPv6 fragments are handled in OpenThread stack but also forwarder unconditionally to the Zephyr uplayers. It causes additional packets processing and leads to errors like unrecognized next header type or duplicate ping reply. What more these errors generate additional traffic which jam channel and decrease latency for packets required fragmentation. This commit add filtering IPv6 fragments when data fragmentation and reassembling is enabled in OpenThread. Signed-off-by: Lukasz Maciejonczyk <[email protected]> (cherry picked from commit c9effd0)
1 parent e6b432e commit b76ffd6

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

subsys/net/l2/openthread/openthread.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,20 @@ static void openthread_process(struct k_work *work)
297297
openthread_api_mutex_unlock(ot_context);
298298
}
299299

300-
static enum net_verdict openthread_recv(struct net_if *iface,
301-
struct net_pkt *pkt)
300+
static bool is_ipv6_frag(struct net_pkt *pkt)
301+
{
302+
NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(ipv6_access, struct net_ipv6_hdr);
303+
struct net_ipv6_hdr *hdr;
304+
305+
hdr = (struct net_ipv6_hdr *)net_pkt_get_data(pkt, &ipv6_access);
306+
if (!hdr) {
307+
return false;
308+
}
309+
310+
return hdr->nexthdr == NET_IPV6_NEXTHDR_FRAG ? true : false;
311+
}
312+
313+
static enum net_verdict openthread_recv(struct net_if *iface, struct net_pkt *pkt)
302314
{
303315
struct openthread_context *ot_context = net_if_l2_data(iface);
304316

@@ -310,6 +322,10 @@ static enum net_verdict openthread_recv(struct net_if *iface,
310322
net_pkt_hexdump(pkt, "Injected IPv6 packet");
311323
}
312324

325+
if (IS_ENABLED(CONFIG_OPENTHREAD_IP6_FRAGM) && is_ipv6_frag(pkt)) {
326+
return NET_DROP;
327+
}
328+
313329
return NET_CONTINUE;
314330
}
315331

0 commit comments

Comments
 (0)