From add5a8be6708cafc1bf065f7629e82fdf5707dab Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 10 Mar 2016 11:33:40 +0100 Subject: [PATCH 1/5] Code style --- core/net/ipv6/uip-icmp6.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/net/ipv6/uip-icmp6.c b/core/net/ipv6/uip-icmp6.c index 05f18a026..157ed0edb 100644 --- a/core/net/ipv6/uip-icmp6.c +++ b/core/net/ipv6/uip-icmp6.c @@ -206,15 +206,14 @@ echo_request_input(void) /*---------------------------------------------------------------------------*/ void uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) { - - /* check if originating packet is not an ICMP error*/ - if (uip_ext_len) { - if(UIP_EXT_BUF->next == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128){ + /* check if originating packet is not an ICMP error */ + if(uip_ext_len) { + if(UIP_EXT_BUF->next == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128) { uip_clear_buf(); return; } } else { - if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128){ + if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128) { uip_clear_buf(); return; } @@ -231,8 +230,9 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) { uip_len += UIP_IPICMPH_LEN + UIP_ICMP6_ERROR_LEN; - if(uip_len > UIP_LINK_MTU) + if(uip_len > UIP_LINK_MTU) { uip_len = UIP_LINK_MTU; + } memmove((uint8_t *)UIP_ICMP6_ERROR_BUF + uip_ext_len + UIP_ICMP6_ERROR_LEN, (void *)UIP_IP_BUF, uip_len - UIP_IPICMPH_LEN - uip_ext_len - UIP_ICMP6_ERROR_LEN); From 9930756d7c5ac0cd38fb0a523c596265ccc7cea6 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 10 Mar 2016 11:34:23 +0100 Subject: [PATCH 2/5] uip6: restore proto after calling remove_ext_hdr --- core/net/ipv6/uip6.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/net/ipv6/uip6.c b/core/net/ipv6/uip6.c index 5cbf39203..55bebcfb5 100644 --- a/core/net/ipv6/uip6.c +++ b/core/net/ipv6/uip6.c @@ -1473,6 +1473,7 @@ uip_process(uint8_t flag) udp_input: remove_ext_hdr(); + UIP_IP_BUF->proto = UIP_PROTO_UDP; PRINTF("Receiving UDP packet\n"); @@ -1593,6 +1594,7 @@ uip_process(uint8_t flag) tcp_input: remove_ext_hdr(); + UIP_IP_BUF->proto = UIP_PROTO_TCP; UIP_STAT(++uip_stat.tcp.recv); PRINTF("Receiving TCP packet\n"); From 5886bdea31b065b410e92aa68e113cfde4587f61 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 10 Mar 2016 11:35:51 +0100 Subject: [PATCH 3/5] uip_icmp6_error_output: remove and add RPL ext header instead of inverting it, so that the payload of the returned ICMP error matches the original packet --- core/net/ipv6/uip-icmp6.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/net/ipv6/uip-icmp6.c b/core/net/ipv6/uip-icmp6.c index 157ed0edb..80d7a5582 100644 --- a/core/net/ipv6/uip-icmp6.c +++ b/core/net/ipv6/uip-icmp6.c @@ -220,8 +220,8 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) { } #if UIP_CONF_IPV6_RPL - uip_ext_len = rpl_invert_header(); -#else /* UIP_CONF_IPV6_RPL */ + rpl_remove_header(); +#else uip_ext_len = 0; #endif /* UIP_CONF_IPV6_RPL */ @@ -280,6 +280,10 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) { UIP_ICMP_BUF->icmpchksum = 0; UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum(); +#if UIP_CONF_IPV6_RPL + rpl_insert_header(); +#endif /* UIP_CONF_IPV6_RPL */ + UIP_STAT(++uip_stat.icmp.sent); PRINTF("Sending ICMPv6 ERROR message type %d code %d to ", type, code); From 06e984a02eb66acf5f5647b73a87bc0721f44f1d Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 10 Mar 2016 11:40:30 +0100 Subject: [PATCH 4/5] uip6: enable sending of "port unreachable" ICMPv6 message --- core/net/ipv6/uip6.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/net/ipv6/uip6.c b/core/net/ipv6/uip6.c index 55bebcfb5..057d6173a 100644 --- a/core/net/ipv6/uip6.c +++ b/core/net/ipv6/uip6.c @@ -1529,12 +1529,8 @@ uip_process(uint8_t flag) PRINTF("udp: no matching connection found\n"); UIP_STAT(++uip_stat.udp.drop); -#if UIP_UDP_SEND_UNREACH_NOPORT uip_icmp6_error_output(ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT, 0); goto send; -#else - goto drop; -#endif udp_found: PRINTF("In udp_found\n"); From 3fa25eac8c8aa787dba4dc92433cfef2eddef856 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 10 Mar 2016 11:41:06 +0100 Subject: [PATCH 5/5] uip6: fix bug that caused the payload of ICMPv6 messages not to match that of the original packet --- core/net/ipv6/uip6.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/net/ipv6/uip6.c b/core/net/ipv6/uip6.c index 057d6173a..7e9ab0016 100644 --- a/core/net/ipv6/uip6.c +++ b/core/net/ipv6/uip6.c @@ -1482,8 +1482,6 @@ uip_process(uint8_t flag) work. If the application sets uip_slen, it has a packet to send. */ #if UIP_UDP_CHECKSUMS - uip_len = uip_len - UIP_IPUDPH_LEN; - uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN]; /* XXX hack: UDP/IPv6 receivers should drop packets with UDP checksum 0. Here, we explicitly receive UDP packets with checksum 0. This is to be able to debug code that for one reason or @@ -1496,8 +1494,6 @@ uip_process(uint8_t flag) uip_udpchksum()); goto drop; } -#else /* UIP_UDP_CHECKSUMS */ - uip_len = uip_len - UIP_IPUDPH_LEN; #endif /* UIP_UDP_CHECKSUMS */ /* Make sure that the UDP destination port number is not zero. */ @@ -1536,6 +1532,8 @@ uip_process(uint8_t flag) PRINTF("In udp_found\n"); UIP_STAT(++uip_stat.udp.recv); + uip_len = uip_len - UIP_IPUDPH_LEN; + uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN]; uip_conn = NULL; uip_flags = UIP_NEWDATA; uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN];