mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +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;
|
iface = ((gnrc_netif_hdr_t *)netif->data)->if_pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pkt->next != NULL) && (pkt->next->type == GNRC_NETTYPE_IPV6) &&
|
for (ipv6 = pkt; ipv6 != NULL; ipv6 = ipv6->next) { /* find IPv6 header if already marked */
|
||||||
(pkt->next->size == sizeof(ipv6_hdr_t))) {
|
if ((ipv6->type == GNRC_NETTYPE_IPV6) && (ipv6->size == sizeof(ipv6_hdr_t)) &&
|
||||||
/* IP header was already marked. Take it. */
|
(ipv6_hdr_is(ipv6->data))) {
|
||||||
ipv6 = pkt->next;
|
break;
|
||||||
|
|
||||||
if (!ipv6_hdr_is(ipv6->data)) {
|
|
||||||
DEBUG("ipv6: Received packet was not IPv6, dropping packet\n");
|
|
||||||
gnrc_pktbuf_release(pkt);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
#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)) {
|
if (!ipv6_hdr_is(pkt->data)) {
|
||||||
DEBUG("ipv6: Received packet was not IPv6, dropping packet\n");
|
DEBUG("ipv6: Received packet was not IPv6, dropping packet\n");
|
||||||
gnrc_pktbuf_release(pkt);
|
gnrc_pktbuf_release(pkt);
|
||||||
@ -770,6 +759,14 @@ static void _receive(gnrc_pktsnip_t *pkt)
|
|||||||
return;
|
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 */
|
/* extract header */
|
||||||
hdr = (ipv6_hdr_t *)ipv6->data;
|
hdr = (ipv6_hdr_t *)ipv6->data;
|
||||||
@ -805,24 +802,33 @@ static void _receive(gnrc_pktsnip_t *pkt)
|
|||||||
}
|
}
|
||||||
/* TODO: check if receiving interface is router */
|
/* TODO: check if receiving interface is router */
|
||||||
else if (--(hdr->hl) > 0) { /* drop packets that *reach* Hop Limit 0 */
|
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");
|
DEBUG("ipv6: forward packet to next hop\n");
|
||||||
|
|
||||||
/* pkt might not be writable yet, if header was given above */
|
/* pkt might not be writable yet, if header was given above */
|
||||||
pkt = gnrc_pktbuf_start_write(tmp);
|
|
||||||
ipv6 = gnrc_pktbuf_start_write(ipv6);
|
ipv6 = gnrc_pktbuf_start_write(ipv6);
|
||||||
|
if (ipv6 == NULL) {
|
||||||
if ((ipv6 == NULL) || (pkt == NULL)) {
|
|
||||||
DEBUG("ipv6: unable to get write access to packet: dropping it\n");
|
DEBUG("ipv6: unable to get write access to packet: dropping it\n");
|
||||||
gnrc_pktbuf_release(tmp);
|
gnrc_pktbuf_release(pkt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
gnrc_pktbuf_remove_snip(pkt, ipv6->next); /* remove L2 headers around IPV6 */
|
||||||
gnrc_pktbuf_release(ipv6->next); /* remove headers around IPV6 */
|
while (ptr != NULL) { /* reverse packet order */
|
||||||
ipv6->next = pkt; /* reorder for sending */
|
gnrc_pktsnip_t *next;
|
||||||
pkt->next = NULL;
|
ptr = gnrc_pktbuf_start_write(ptr); /* duplicate if not already done */
|
||||||
_send(ipv6, false);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user