From f2425961b7b7ae73a988f122a3c249a4681b4373 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 16 Apr 2015 18:26:03 +0200 Subject: [PATCH] [SQUASH ME] ng_ipv6: some adaptions --- sys/net/network_layer/ng_ipv6/ng_ipv6.c | 48 ++++++++++++++++--------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/sys/net/network_layer/ng_ipv6/ng_ipv6.c b/sys/net/network_layer/ng_ipv6/ng_ipv6.c index ec9324f717ab..fca4be25c387 100644 --- a/sys/net/network_layer/ng_ipv6/ng_ipv6.c +++ b/sys/net/network_layer/ng_ipv6/ng_ipv6.c @@ -153,9 +153,7 @@ static void _ipv6_send_unicast(kernel_pid_t iface, uint8_t *dst_l2addr, * is long enough and only then to throw away the header. This causes * to much overhead IMHO */ DEBUG("ipv6: removed old interface header\n"); - netif = pkt; - LL_DELETE(pkt, netif); - ng_pktbuf_release(netif); + pkt = ng_pktbuf_remove_snip(pkt, pkt); } DEBUG("ipv6: add to interface header to packet\n"); @@ -300,7 +298,7 @@ static void _ipv6_send_multicast(kernel_pid_t iface, ng_pktsnip_t *pkt, DEBUG("ipv6: send multicast over interface %" PRIkernel_pid "\n", ifs[i]); /* mark as multicast */ - ((ng_netif_hdr_t *)pkt->data)->flags |= NG_NETIF_HDR_FLAGS_MULTICAST; + ((ng_netif_hdr_t *)netif->data)->flags |= NG_NETIF_HDR_FLAGS_MULTICAST; /* and send to interface */ ng_netapi_send(iface, pkt); } @@ -421,26 +419,42 @@ static void _ipv6_receive(kernel_pid_t iface, ng_pktsnip_t *pkt) LL_SEARCH_SCALAR(pkt, payload, type, NG_NETTYPE_IPV6); /* is it a valid IPv6 packet? */ - if (!ng_ipv6_hdr_is_ipv6_hdr(payload->data)) { - DEBUG("ipv6: Received packet was not IPv6, dropping packet\n"); - ng_pktbuf_release(pkt); - return; - } - - payload = _start_write(payload); if (payload == NULL) { DEBUG("ipv6: unable to get write access to packet, dropping packet\n"); return; } - ipv6 = ng_pktbuf_add(payload, payload->data, sizeof(ng_ipv6_hdr_t), - NG_NETTYPE_IPV6); + if ((payload->next != NULL) && (payload->next->type == NG_NETTYPE_IPV6) && + (payload->next->size == sizeof(ng_ipv6_hdr_t))) { + /* IP header was already marked. Take it. */ + ipv6 = payload->next->data; - if (ipv6 == NULL) { - DEBUG("ipv6: error marking IPv6 header, dropping packet\n"); - ng_pktbuf_release(pkt); - return; + if (!ng_ipv6_hdr_is_ipv6_hdr(ipv6->data)) { + DEBUG("ipv6: Received packet was not IPv6, dropping packet\n"); + ng_pktbuf_release(pkt); + return; + } + + payload = _start_write(payload); + } + else { + if (!ng_ipv6_hdr_is_ipv6_hdr(payload->data)) { + DEBUG("ipv6: Received packet was not IPv6, dropping packet\n"); + ng_pktbuf_release(pkt); + return; + } + + payload = _start_write(payload); + + ipv6 = ng_pktbuf_add(payload, payload->data, sizeof(ng_ipv6_hdr_t), + NG_NETTYPE_IPV6); + + if (ipv6 == NULL) { + DEBUG("ipv6: error marking IPv6 header, dropping packet\n"); + ng_pktbuf_release(pkt); + return; + } } /* extract header */