Skip to content

Commit

Permalink
[SQUASH ME] ng_ipv6: some adaptions
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Apr 16, 2015
1 parent 430fd37 commit f242596
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions sys/net/network_layer/ng_ipv6/ng_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit f242596

Please sign in to comment.