From 5a93a25158cc83a47b6026e4333078dcef2b2dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jani=20Hirsim=C3=A4ki?= Date: Mon, 12 Dec 2022 11:41:53 +0200 Subject: [PATCH] net: l2: ethernet: ethernet support for AF_PACKET/SOCK_RAW/IPPROTO_RAW MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Setting the protocol type for raw IP packets to be sent so that they can be passed to Ethernet. Signed-off-by: Jani Hirsimäki --- subsys/net/l2/ethernet/ethernet.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/subsys/net/l2/ethernet/ethernet.c b/subsys/net/l2/ethernet/ethernet.c index f5cd3bf0fd1..10bb808276a 100644 --- a/subsys/net/l2/ethernet/ethernet.c +++ b/subsys/net/l2/ethernet/ethernet.c @@ -667,6 +667,21 @@ static int ethernet_send(struct net_if *iface, struct net_pkt *pkt) net_pkt_lladdr_src(pkt)->len = sizeof(struct net_eth_addr); ptype = dst_addr->sll_protocol; + } else if (context && net_context_get_type(context) == SOCK_RAW && + net_context_get_proto(context) == IPPROTO_RAW) { + char type = (NET_IPV6_HDR(pkt)->vtc & 0xf0); + + switch (type) { + case 0x60: + ptype = htons(NET_ETH_PTYPE_IPV6); + break; + case 0x40: + ptype = htons(NET_ETH_PTYPE_IP); + break; + default: + ret = -ENOTSUP; + goto error; + } } else { goto send; }