From f21051b72829aa254ef2cb5b09417506410d1a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jani=20Hirsim=C3=A4ki?= Date: Mon, 13 Feb 2023 11:30:11 +0200 Subject: [PATCH] net: iface: bypassing IP stack with SOCK_RAW sockets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bypass the IP stack and go directly to L2 with SOCK_RAW/IPPROTO_RAW sockets in net_if_send_data(). Signed-off-by: Jani Hirsimäki --- subsys/net/ip/net_if.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 1392140b28..fbb0b63f55 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -481,6 +481,13 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt) } #endif + /* Bypass the IP stack with SOCK_RAW/IPPROTO_RAW sockets */ + if (IS_ENABLED(CONFIG_NET_SOCKETS_PACKET) && + context && net_context_get_type(context) == SOCK_RAW && + net_context_get_proto(context) == IPPROTO_RAW) { + goto done; + } + /* If the ll dst address is not set check if it is present in the nbr * cache. */