From 710e82facafab95ee11b48be65230cb753db4552 Mon Sep 17 00:00:00 2001 From: Marcus Shawcroft Date: Wed, 22 Jun 2016 09:43:12 +0100 Subject: [PATCH] net: Tighten ETHERTYPE decode. The uip stack processes received packets by calling net_recv() but does not discard packets marked with an ethertype other than IPv4 or IPv6 resulting in confusion further up the stack. Discard non IPv4/v6 packets from further processing by the IP stack. Change-Id: Ic62f8d12b02da197b1abc774a581bff30330080c Signed-off-by: Marcus Shawcroft --- net/ip/net_driver_ethernet.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/net/ip/net_driver_ethernet.c b/net/ip/net_driver_ethernet.c index 5279a12961f..c6391fb1d97 100644 --- a/net/ip/net_driver_ethernet.c +++ b/net/ip/net_driver_ethernet.c @@ -98,9 +98,9 @@ static int net_driver_ethernet_send(struct net_buf *buf) void net_driver_ethernet_recv(struct net_buf *buf) { -#ifdef CONFIG_NETWORKING_WITH_IPV4 struct uip_eth_hdr *eth_hdr = (struct uip_eth_hdr *)uip_buf(buf); +#ifdef CONFIG_NETWORKING_WITH_IPV4 if (eth_hdr->type == uip_htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(buf); @@ -127,9 +127,15 @@ void net_driver_ethernet_recv(struct net_buf *buf) ip_buf_unref(buf); } else #endif - - if (net_recv(buf) != 0) { - NET_ERR("Unexpected return value from net_recv.\n"); + if (eth_hdr->type == uip_htons(UIP_ETHTYPE_IP) || + eth_hdr->type == uip_htons(UIP_ETHTYPE_IPV6)) { + if (net_recv(buf) != 0) { + NET_ERR("Unexpected return value from net_recv.\n"); + ip_buf_unref(buf); + } + } else { + NET_DBG("Dropping unknown ethertype %x\n", + uip_ntohs(eth_hdr->type)); ip_buf_unref(buf); } }