diff --git a/net/ip/contiki/ip/tcpip.c b/net/ip/contiki/ip/tcpip.c index f637f807f06..585c5b01811 100644 --- a/net/ip/contiki/ip/tcpip.c +++ b/net/ip/contiki/ip/tcpip.c @@ -540,14 +540,23 @@ eventhandler(process_event_t ev, process_data_t data, struct net_buf *buf) }; } /*---------------------------------------------------------------------------*/ -void +uint8_t tcpip_input(struct net_buf *buf) { process_post_synch(&tcpip_process, PACKET_INPUT, NULL, buf); + if (uip_len(buf) == 0) { + /* This indicates that there was a parsing/other error + * in packet. + */ + return 0; + } + uip_len(buf) = 0; #if NETSTACK_CONF_WITH_IPV6 uip_ext_len(buf) = 0; #endif /*NETSTACK_CONF_WITH_IPV6*/ + + return 1; } /*---------------------------------------------------------------------------*/ #if NETSTACK_CONF_WITH_IPV6 diff --git a/net/ip/contiki/ip/tcpip.h b/net/ip/contiki/ip/tcpip.h index f0b53b186c1..3b2162ef188 100644 --- a/net/ip/contiki/ip/tcpip.h +++ b/net/ip/contiki/ip/tcpip.h @@ -333,9 +333,11 @@ CCIF extern process_event_t tcpip_event; * deliver an incoming packet to the TCP/IP stack. The * incoming packet must be present in the uip_buf buffer, * and the length of the packet must be in the global - * uip_len variable. + * uip_len variable. If 0 is returned, then there was + * an error in the packet and it is discarded. The caller + * can then release the net_buf */ -CCIF void tcpip_input(struct net_buf *buf); +CCIF uint8_t tcpip_input(struct net_buf *buf); /** * \brief Output packet to layer 2 diff --git a/net/ip/contiki/ipv6/uip6.c b/net/ip/contiki/ipv6/uip6.c index 4840251b6c3..95acd1c62d8 100644 --- a/net/ip/contiki/ipv6/uip6.c +++ b/net/ip/contiki/ipv6/uip6.c @@ -2325,11 +2325,6 @@ uip_process(struct net_buf *buf, uint8_t flag) return 1; drop: - /* If there is an error, then just return the buffer to pool */ - if (uip_len(buf) == 0) { - net_buf_put(buf); - } - uip_len(buf) = 0; uip_ext_len(buf) = 0; uip_ext_bitmap(buf) = 0; diff --git a/net/ip/net_init.c b/net/ip/net_init.c index e30d688fb04..8ba6f9478fd 100644 --- a/net/ip/net_init.c +++ b/net/ip/net_init.c @@ -352,7 +352,9 @@ static void net_rx_fiber(void) /* Check stack usage (no-op if not enabled) */ analyze_stacks(buf, &buf); - tcpip_input(buf); + if (!tcpip_input(buf)) { + net_buf_put(buf); + } } }