diff --git a/net/ip/contiki/ip/tcpip.c b/net/ip/contiki/ip/tcpip.c index 305e2014224..7ae49bdf9d4 100644 --- a/net/ip/contiki/ip/tcpip.c +++ b/net/ip/contiki/ip/tcpip.c @@ -183,9 +183,10 @@ check_for_tcp_syn(struct net_buf *buf) #endif /* UIP_TCP || UIP_CONF_IP_FORWARD */ } /*---------------------------------------------------------------------------*/ -static void +static uint8_t packet_input(struct net_buf *buf) { + uint8_t ret = 0; #if UIP_CONF_IP_FORWARD if(uip_len > 0) { tcpip_is_forwarding = 1; @@ -211,8 +212,8 @@ packet_input(struct net_buf *buf) #else /* UIP_CONF_IP_FORWARD */ if(uip_len(buf) > 0) { check_for_tcp_syn(buf); - uip_input(buf); - if(uip_len(buf) > 0) { + ret = uip_input(buf); + if(ret && uip_len(buf) > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(buf); #else /* UIP_CONF_TCP_SPLIT */ @@ -227,6 +228,7 @@ packet_input(struct net_buf *buf) } } #endif /* UIP_CONF_IP_FORWARD */ + return ret; } /*---------------------------------------------------------------------------*/ #if UIP_TCP @@ -533,7 +535,12 @@ eventhandler(process_event_t ev, process_data_t data, struct net_buf *buf) #endif /* UIP_UDP */ case PACKET_INPUT: - packet_input(buf); + if (!packet_input(buf)) { + /* failure, discard the net_buf here because the + * return value cannot be passed to driver any longer + */ + net_buf_put(buf); + } break; }; } @@ -692,6 +699,8 @@ tcpip_ipv6_output(struct net_buf *buf) stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000); nbr->nscount = 1; } + + return 1; /* packet was passed to network successfully */ #endif /* UIP_ND6_SEND_NA */ } else { #if UIP_ND6_SEND_NA @@ -741,7 +750,7 @@ tcpip_ipv6_output(struct net_buf *buf) return ret; } - return; + return 0; /* discard packet */ } /* Multicast IP destination address. */ ret = tcpip_output(buf, NULL); diff --git a/net/ip/contiki/ip/uip.h b/net/ip/contiki/ip/uip.h index cb20100b3f1..11cf8422b48 100644 --- a/net/ip/contiki/ip/uip.h +++ b/net/ip/contiki/ip/uip.h @@ -1544,7 +1544,7 @@ uip_ext_hdr_options_process(); */ * * The actual uIP function which does all the work. */ -void uip_process(struct net_buf *buf, uint8_t flag); +uint8_t uip_process(struct net_buf *buf, uint8_t flag); /* The following flags are passed as an argument to the uip_process() function. They are used to distinguish between the two cases where diff --git a/net/ip/contiki/ipv6/sicslowpan.c b/net/ip/contiki/ipv6/sicslowpan.c index 70aecac034d..b4ff084ac24 100644 --- a/net/ip/contiki/ipv6/sicslowpan.c +++ b/net/ip/contiki/ipv6/sicslowpan.c @@ -1602,7 +1602,7 @@ output(struct net_buf *buf, const uip_lladdr_t *localdest) * \note We do not check for overlapping sicslowpan fragments * (it is a SHALL in the RFC 4944 and should never happen) */ -static void +static uint8_t input(struct net_buf *buf) { /* size of the IP packet (read from fragment) */ @@ -1713,7 +1713,7 @@ input(struct net_buf *buf) * being reassembled or the packet is not a fragment. */ PRINTFI("sicslowpan input: Dropping 6lowpan packet that is not a fragment of the packet currently being reassembled\n"); - return; + return 0; } } else { /* @@ -1724,7 +1724,7 @@ input(struct net_buf *buf) /* We are currently not reassembling a packet, but have received a packet fragment * that is not the first one. */ if(is_fragment && !first_fragment) { - return; + return 0; } sicslowpan_len(buf) = frag_size; @@ -1771,7 +1771,7 @@ input(struct net_buf *buf) /* unknown header */ PRINTFI("sicslowpan input: unknown dispatch: %u\n", PACKETBUF_HC1_PTR(buf)[PACKETBUF_HC1_DISPATCH]); - return; + return 0; } @@ -1787,7 +1787,7 @@ input(struct net_buf *buf) */ if(packetbuf_datalen(buf) < uip_packetbuf_hdr_len(buf)) { PRINTF("SICSLOWPAN: packet dropped due to header > total packet\n"); - return; + return 0; } uip_packetbuf_payload_len(buf) = packetbuf_datalen(buf) - uip_packetbuf_hdr_len(buf); @@ -1800,7 +1800,7 @@ input(struct net_buf *buf) "SICSLOWPAN: packet dropped, minimum required SICSLOWPAN_IP_BUF size: %d+%d+%d+%d=%d (current size: %d)\n", UIP_LLH_LEN, uip_uncomp_hdr_len(buf), (uint16_t)(frag_offset << 3), uip_packetbuf_payload_len(buf), req_size, sizeof(sicslowpan_buf(buf))); - return; + return 0; } } @@ -1865,9 +1865,11 @@ input(struct net_buf *buf) #endif tcpip_input(buf); + return 1; #if SICSLOWPAN_CONF_FRAG } #endif /* SICSLOWPAN_CONF_FRAG */ + return 0; } /** @} */ diff --git a/net/ip/contiki/ipv6/uip6.c b/net/ip/contiki/ipv6/uip6.c index 7adef4200f8..f3029a62ed2 100644 --- a/net/ip/contiki/ipv6/uip6.c +++ b/net/ip/contiki/ipv6/uip6.c @@ -949,7 +949,7 @@ ext_hdr_options_process(struct net_buf *buf) /*---------------------------------------------------------------------------*/ -void +uint8_t uip_process(struct net_buf *buf, uint8_t flag) { #if UIP_TCP @@ -2321,7 +2321,7 @@ uip_process(struct net_buf *buf, uint8_t flag) UIP_STAT(++uip_stat.ip.sent); /* Return and let the caller do the actual transmission. */ uip_flags(buf) = 0; - return; + return 1; drop: /* If there is an error, then just return the buffer to pool */ @@ -2333,7 +2333,7 @@ uip_process(struct net_buf *buf, uint8_t flag) uip_ext_len(buf) = 0; uip_ext_bitmap(buf) = 0; uip_flags(buf) = 0; - return; + return 0; } /*---------------------------------------------------------------------------*/ uint16_t diff --git a/net/ip/contiki/llsec/llsec.h b/net/ip/contiki/llsec/llsec.h index 01c948ca80c..6ae55b1616f 100644 --- a/net/ip/contiki/llsec/llsec.h +++ b/net/ip/contiki/llsec/llsec.h @@ -85,7 +85,7 @@ struct llsec_driver { * Decrypts incoming frames; * filters out injected or replayed frames. */ - void (* input)(struct net_buf *buf); + uint8_t (* input)(struct net_buf *buf); /** Returns the security-related overhead per frame in bytes */ uint8_t (* get_overhead)(void); diff --git a/net/ip/contiki/llsec/nullsec.c b/net/ip/contiki/llsec/nullsec.c index 62521781eca..7f72e029336 100644 --- a/net/ip/contiki/llsec/nullsec.c +++ b/net/ip/contiki/llsec/nullsec.c @@ -80,10 +80,10 @@ on_frame_created(void) return 1; } /*---------------------------------------------------------------------------*/ -static void +static uint8_t input(struct net_buf *buf) { - NETSTACK_NETWORK.input(buf); + return NETSTACK_NETWORK.input(buf); } /*---------------------------------------------------------------------------*/ static uint8_t diff --git a/net/ip/contiki/mac/csma.c b/net/ip/contiki/mac/csma.c index 91bb130d9e7..60a380e8e2c 100644 --- a/net/ip/contiki/mac/csma.c +++ b/net/ip/contiki/mac/csma.c @@ -428,12 +428,13 @@ send_packet(struct net_buf *buf, mac_callback_t sent, void *ptr) PRINTF("csma: could not allocate neighbor, dropping packet\n"); } mac_call_sent_callback(buf, sent, ptr, MAC_TX_ERR, 1); + return 0; } /*---------------------------------------------------------------------------*/ -static void +static uint8_t input_packet(struct net_buf *buf) { - NETSTACK_LLSEC.input(buf); + return NETSTACK_LLSEC.input(buf); } /*---------------------------------------------------------------------------*/ static int diff --git a/net/ip/contiki/mac/mac.h b/net/ip/contiki/mac/mac.h index 6c81d8d2f0a..34ae7f3c5ac 100644 --- a/net/ip/contiki/mac/mac.h +++ b/net/ip/contiki/mac/mac.h @@ -63,7 +63,7 @@ struct mac_driver { uint8_t (* send)(struct net_buf *buf, mac_callback_t sent_callback, void *ptr); /** Callback for getting notified of incoming packet. */ - void (* input)(struct net_buf *buf); + uint8_t (* input)(struct net_buf *buf); /** Turn the MAC layer on. */ int (* on)(void); diff --git a/net/ip/contiki/mac/rdc.h b/net/ip/contiki/mac/rdc.h index a3400b69e4b..acf280e1368 100644 --- a/net/ip/contiki/mac/rdc.h +++ b/net/ip/contiki/mac/rdc.h @@ -79,7 +79,7 @@ struct rdc_driver { uint8_t (* send_list)(struct net_buf *buf, mac_callback_t sent_callback, void *ptr, struct rdc_buf_list *list); /** Callback for getting notified of incoming packet. */ - void (* input)(struct net_buf *buf); + uint8_t (* input)(struct net_buf *buf); /** Turn the MAC layer on. */ int (* on)(void); diff --git a/net/ip/contiki/mac/sicslowmac/sicslowmac.c b/net/ip/contiki/mac/sicslowmac/sicslowmac.c index db0e22494b7..01eb719c6b4 100644 --- a/net/ip/contiki/mac/sicslowmac/sicslowmac.c +++ b/net/ip/contiki/mac/sicslowmac/sicslowmac.c @@ -200,7 +200,7 @@ send_list(struct net_buf *buf, mac_callback_t sent, void *ptr, struct rdc_buf_li return 1; } /*---------------------------------------------------------------------------*/ -static void +static uint8_t input_packet(struct net_buf *buf) { frame802154_t frame; @@ -239,13 +239,12 @@ input_packet(struct net_buf *buf) PRINTF(" receiver "); PRINTLLADDR(packetbuf_addr(buf, PACKETBUF_ADDR_RECEIVER)); PRINTF(" len %u\n", packetbuf_datalen(buf)); - NETSTACK_MAC.input(buf); - return; + return NETSTACK_MAC.input(buf); } else { PRINTF("6MAC: failed to parse hdr\n"); } error: - net_buf_put(buf); + return 0; } /*---------------------------------------------------------------------------*/ static int diff --git a/net/ip/contiki/netstack.h b/net/ip/contiki/netstack.h index 648cbcbdbd5..ff81eec6b51 100644 --- a/net/ip/contiki/netstack.h +++ b/net/ip/contiki/netstack.h @@ -123,7 +123,7 @@ struct network_driver { void (* init)(void); /** Callback for getting notified of incoming packet. */ - void (* input)(struct net_buf *buf); + uint8_t (* input)(struct net_buf *buf); }; extern const struct network_driver NETSTACK_NETWORK; diff --git a/net/ip/contiki/uip-driver.c b/net/ip/contiki/uip-driver.c index 0434798d68b..81daea3a9fd 100644 --- a/net/ip/contiki/uip-driver.c +++ b/net/ip/contiki/uip-driver.c @@ -75,7 +75,7 @@ init(void) tcpip_set_outputfunc(uip_driver_send); } /*--------------------------------------------------------------------*/ -static void +static uint8_t input(struct net_buf *buf) { PRINTF("uip-driver(%p): input %d bytes\n", buf, packetbuf_datalen(buf)); @@ -84,9 +84,11 @@ input(struct net_buf *buf) memcpy(&uip_buf(buf)[UIP_LLH_LEN], packetbuf_dataptr(buf), packetbuf_datalen(buf)); uip_len(buf) = packetbuf_datalen(buf); tcpip_input(buf); + return 1; } else { PRINTF("datalen %d MAX %d\n", packetbuf_datalen(buf), UIP_BUFSIZE - UIP_LLH_LEN); UIP_LOG("uip-driver: too long packet discarded"); + return 0; } } /*--------------------------------------------------------------------*/