mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #4507 from authmillenon/gnrc_ipv6/fix/no-order-assumptions
gnrc_ipv6: make no pre-assumption about any marked headers
This commit is contained in:
commit
b7a7578e21
@ -720,25 +720,14 @@ static void _receive(gnrc_pktsnip_t *pkt)
|
||||
iface = ((gnrc_netif_hdr_t *)netif->data)->if_pid;
|
||||
}
|
||||
|
||||
if ((pkt->next != NULL) && (pkt->next->type == GNRC_NETTYPE_IPV6) &&
|
||||
(pkt->next->size == sizeof(ipv6_hdr_t))) {
|
||||
/* IP header was already marked. Take it. */
|
||||
ipv6 = pkt->next;
|
||||
|
||||
if (!ipv6_hdr_is(ipv6->data)) {
|
||||
DEBUG("ipv6: Received packet was not IPv6, dropping packet\n");
|
||||
gnrc_pktbuf_release(pkt);
|
||||
return;
|
||||
for (ipv6 = pkt; ipv6 != NULL; ipv6 = ipv6->next) { /* find IPv6 header if already marked */
|
||||
if ((ipv6->type == GNRC_NETTYPE_IPV6) && (ipv6->size == sizeof(ipv6_hdr_t)) &&
|
||||
(ipv6_hdr_is(ipv6->data))) {
|
||||
break;
|
||||
}
|
||||
#ifdef MODULE_GNRC_IPV6_WHITELIST
|
||||
if (!gnrc_ipv6_whitelisted(&((ipv6_hdr_t *)(ipv6->data))->src)) {
|
||||
DEBUG("ipv6: Source address not whitelisted, dropping packet\n");
|
||||
gnrc_pktbuf_release(pkt);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
|
||||
if (ipv6 == NULL) {
|
||||
if (!ipv6_hdr_is(pkt->data)) {
|
||||
DEBUG("ipv6: Received packet was not IPv6, dropping packet\n");
|
||||
gnrc_pktbuf_release(pkt);
|
||||
@ -770,6 +759,14 @@ static void _receive(gnrc_pktsnip_t *pkt)
|
||||
return;
|
||||
}
|
||||
}
|
||||
#ifdef MODULE_GNRC_IPV6_WHITELIST
|
||||
else if (!gnrc_ipv6_whitelisted(&((ipv6_hdr_t *)(ipv6->data))->src)) {
|
||||
/* if ipv6 header already marked*/
|
||||
DEBUG("ipv6: Source address not whitelisted, dropping packet\n");
|
||||
gnrc_pktbuf_release(pkt);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* extract header */
|
||||
hdr = (ipv6_hdr_t *)ipv6->data;
|
||||
@ -805,24 +802,33 @@ static void _receive(gnrc_pktsnip_t *pkt)
|
||||
}
|
||||
/* TODO: check if receiving interface is router */
|
||||
else if (--(hdr->hl) > 0) { /* drop packets that *reach* Hop Limit 0 */
|
||||
gnrc_pktsnip_t *tmp = pkt;
|
||||
gnrc_pktsnip_t *reversed_pkt = NULL, *ptr = pkt;
|
||||
|
||||
DEBUG("ipv6: forward packet to next hop\n");
|
||||
|
||||
/* pkt might not be writable yet, if header was given above */
|
||||
pkt = gnrc_pktbuf_start_write(tmp);
|
||||
ipv6 = gnrc_pktbuf_start_write(ipv6);
|
||||
|
||||
if ((ipv6 == NULL) || (pkt == NULL)) {
|
||||
if (ipv6 == NULL) {
|
||||
DEBUG("ipv6: unable to get write access to packet: dropping it\n");
|
||||
gnrc_pktbuf_release(tmp);
|
||||
gnrc_pktbuf_release(pkt);
|
||||
return;
|
||||
}
|
||||
|
||||
gnrc_pktbuf_release(ipv6->next); /* remove headers around IPV6 */
|
||||
ipv6->next = pkt; /* reorder for sending */
|
||||
pkt->next = NULL;
|
||||
_send(ipv6, false);
|
||||
gnrc_pktbuf_remove_snip(pkt, ipv6->next); /* remove L2 headers around IPV6 */
|
||||
while (ptr != NULL) { /* reverse packet order */
|
||||
gnrc_pktsnip_t *next;
|
||||
ptr = gnrc_pktbuf_start_write(ptr); /* duplicate if not already done */
|
||||
if (ptr == NULL) {
|
||||
DEBUG("ipv6: unable to get write access to packet: dropping it\n");
|
||||
gnrc_pktbuf_release(reversed_pkt);
|
||||
gnrc_pktbuf_release(pkt);
|
||||
return;
|
||||
}
|
||||
next = ptr->next;
|
||||
ptr->next = reversed_pkt;
|
||||
reversed_pkt = ptr;
|
||||
ptr = next;
|
||||
}
|
||||
_send(reversed_pkt, false);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user