Skip to content

Commit

Permalink
[SQUASH ME] ng_ipv6: fix receive
Browse files Browse the repository at this point in the history
Conflicts:
	sys/net/network_layer/ng_ipv6/ng_ipv6.c
  • Loading branch information
miri64 committed Mar 20, 2015
1 parent 16981c1 commit 6e1ca1d
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions sys/net/network_layer/ng_ipv6/ng_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ static bool is_router = false;
static inline bool _pkt_not_for_me(kernel_pid_t *netif, ng_ipv6_hdr_t *hdr)
{
if (*netif == KERNEL_PID_UNDEF) {
*netif = ng_ipv6_netif_find_addr(NULL, &hdr->dest);
return (*netif != KERNEL_PID_UNDEF);
*netif = ng_ipv6_netif_find_by_addr(NULL, &hdr->dest);
return (*netif == KERNEL_PID_UNDEF);
}
else {
return (ng_ipv6_netif_find_addr_local(*netif, &hdr->dest) != NULL);
return (ng_ipv6_netif_find_addr(*netif, &hdr->dest) == NULL);
}
}

Expand Down Expand Up @@ -150,6 +150,8 @@ static void _handle_send(ng_pktsnip_t *pkt, bool redirect, bool set_src)
#endif

default:
DEBUG("ipv6: Set next header to no next header.\n");
hdr->nh = NG_PROTNUM_IPV6_NONXT;
break;
}
}
Expand Down Expand Up @@ -260,23 +262,23 @@ static void _handle_send(ng_pktsnip_t *pkt, bool redirect, bool set_src)
return;
}

if (set_src && ng_ipv6_addr_is_unspecified(&hdr->src)) {
if (ng_ipv6_addr_is_multicast(&hdr->src) ||
(set_src && ng_ipv6_addr_is_unspecified(&hdr->src))) {
ng_ipv6_addr_t *src = ng_ipv6_netif_find_best_src_addr(iface, &hdr->dest);

if (src != NULL) {
DEBUG("ipv6: set packet source to %s\n",
ng_ipv6_addr_to_str(addr_str, src, sizeof(addr_str)));
memcpy(&hdr->src, src, sizeof(ng_ipv6_addr_t));
}

/* Otherwise leave unspecified */
}

DEBUG("ipv6: calculate checksum for upper header.\n");
DEBUG("ipv6: calculate checksum for upper header.\n");

if (ng_netreg_calculate_csum(NG_NETTYPE_IPV6, payload->type, pkt) < 0) {
DEBUG("ipv6: checksum calculation failed.\n");
return;
}
if (ng_netreg_calculate_csum(NG_NETTYPE_IPV6, payload->type, pkt) < 0) {
DEBUG("ipv6: checksum calculation failed.\n");
return;
}

_send_to_iface(iface, nc_entry->l2_addr, nc_entry->l2_addr_len,
Expand Down Expand Up @@ -324,6 +326,8 @@ static void _handle_receive(kernel_pid_t netif, ng_pktsnip_t *pkt)
return;
}

payload->type = NG_NETTYPE_UNDEF;

/* extract header */
hdr = (ng_ipv6_hdr_t *)ipv6->data;

Expand All @@ -348,10 +352,15 @@ static void _handle_receive(kernel_pid_t netif, ng_pktsnip_t *pkt)
if (_pkt_not_for_me(&netif, hdr)) { /* if packet is not for me */
/* redirect to next hop */
ng_pktbuf_hold(ipv6, 1);
ipv6->next = NULL;
ng_pktbuf_release(pkt); /* Drop everything except IPv6 */
_handle_send(ipv6, true, false);
}

/* IPv6 internal demuxing (ICMPv6, Extension headers etc.) */
receiver_type = ng_ipv6_demux(pkt, hdr->nh);
payload->type = receiver_type;

receiver_num = ng_netreg_num(receiver_type, NG_NETREG_DEMUX_CTX_ALL) +
ng_netreg_num(NG_NETTYPE_IPV6, hdr->nh);

Expand All @@ -361,9 +370,6 @@ static void _handle_receive(kernel_pid_t netif, ng_pktsnip_t *pkt)
return;
}

receiver_type = ng_ipv6_demux(pkt, hdr->nh);
payload->type = receiver_type;

ng_pktbuf_hold(pkt, receiver_num - 1);
/* IPv6 is not interested anymore so `- 1` */
_dispatch_received(receiver_type, NG_NETREG_DEMUX_CTX_ALL, pkt);
Expand Down Expand Up @@ -501,8 +507,8 @@ static int _toggle_address(ng_netapi_opt_t *conf)
return -EOVERFLOW;
}

if (ng_ipv6_netif_find_addr_local((kernel_pid_t)(conf->context),
(ng_ipv6_addr_t *)conf->data) == NULL) {
if (ng_ipv6_netif_find_addr((kernel_pid_t)(conf->context),
(ng_ipv6_addr_t *)conf->data) == NULL) {
DEBUG("ipv6: add address %s to interface %" PRIu16 "\n",
ng_ipv6_addr_to_str(addr_str, (ng_ipv6_addr_t *)conf->data,
sizeof(addr_str)),
Expand Down Expand Up @@ -679,6 +685,8 @@ ng_nettype_t ng_ipv6_demux(ng_pktsnip_t *pkt, uint8_t nh)

case NG_PROTNUM_ICMPV6:
DEBUG("ipv6: Received ICMPv6 packet.\n");
pkt->type = NG_NETTYPE_ICMPV6; /* preset needed for further
* handling*/
ng_icmpv6_demux(pkt);
return NG_NETTYPE_ICMPV6;
#endif
Expand Down Expand Up @@ -733,7 +741,7 @@ ng_pktsnip_t *ng_ipv6_hdr_build(ng_pktsnip_t *payload,
return NULL;
}

ipv6 = ng_pktbuf_add(NULL, NULL, sizeof(ng_ipv6_hdr_t),
ipv6 = ng_pktbuf_add(payload, NULL, sizeof(ng_ipv6_hdr_t),
NG_NETTYPE_IPV6);

if (ipv6 == NULL) {
Expand Down Expand Up @@ -767,8 +775,6 @@ ng_pktsnip_t *ng_ipv6_hdr_build(ng_pktsnip_t *payload,
hdr->nh = NG_PROTNUM_RESERVED;
hdr->hl = NG_IPV6_DEFAULT_HL;

payload->next = ipv6;

return ipv6;
}

Expand Down

0 comments on commit 6e1ca1d

Please sign in to comment.