From aaccd37a2f62f72006cd7c7b23bdcaea31df1dfc Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 20 Nov 2013 23:41:21 +0100 Subject: [PATCH] calculate RPL checksum right before sending the ICMP packet --- sys/net/rpl/rpl.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/sys/net/rpl/rpl.c b/sys/net/rpl/rpl.c index d86ffb0fad..a03d650cd0 100644 --- a/sys/net/rpl/rpl.c +++ b/sys/net/rpl/rpl.c @@ -29,6 +29,7 @@ #include "trickle.h" #include "sixlowpan.h" +#include "net_help.h" #define ENABLE_DEBUG (0) #if ENABLE_DEBUG @@ -268,6 +269,7 @@ void rpl_init_root(void) void send_DIO(ipv6_addr_t *destination) { + DEBUG("Send DIO\n"); mutex_lock(&rpl_send_mutex); rpl_dodag_t *mydodag; icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); @@ -282,7 +284,6 @@ void send_DIO(ipv6_addr_t *destination) icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL; icmp_send_buf->code = ICMP_CODE_DIO; - icmp_send_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6); rpl_send_dio_buf = get_rpl_send_dio_buf(); memset(rpl_send_dio_buf, 0, sizeof(*rpl_send_dio_buf)); @@ -311,34 +312,33 @@ void send_DIO(ipv6_addr_t *destination) rpl_send_opt_dodag_conf_buf->default_lifetime = mydodag->default_lifetime; rpl_send_opt_dodag_conf_buf->lifetime_unit = mydodag->lifetime_unit; - opt_hdr_len += RPL_OPT_LEN + RPL_OPT_DODAG_CONF_LEN; - uint16_t plen = ICMPV6_HDR_LEN + DIO_BASE_LEN + opt_hdr_len; - rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6, NULL); + rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6); mutex_unlock(&rpl_send_mutex); } void send_DIS(ipv6_addr_t *destination) { + DEBUG("Send DIS\n"); mutex_lock(&rpl_send_mutex); icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL; icmp_send_buf->code = ICMP_CODE_DIS; - icmp_send_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6); rpl_send_dis_buf = get_rpl_send_dis_buf(); uint16_t plen = ICMPV6_HDR_LEN + DIS_BASE_LEN; - rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6, NULL); + rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6); mutex_unlock(&rpl_send_mutex); } void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index) { + DEBUG("Send DAO\n"); if (i_am_root) { return; } @@ -359,7 +359,6 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL; icmp_send_buf->code = ICMP_CODE_DAO; - icmp_send_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6); if (my_dodag == NULL) { mutex_unlock(&rpl_send_mutex); @@ -423,7 +422,7 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, opt_len += RPL_OPT_TRANSIT_LEN + 2; uint16_t plen = ICMPV6_HDR_LEN + DAO_BASE_LEN + opt_len; - rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6, NULL); + rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6); mutex_unlock(&rpl_send_mutex); if (continue_index > 1) { @@ -433,6 +432,7 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, void send_DAO_ACK(ipv6_addr_t *destination) { + DEBUG("Send DAO ACK\n"); rpl_dodag_t *my_dodag; my_dodag = rpl_get_my_dodag(); @@ -445,7 +445,6 @@ void send_DAO_ACK(ipv6_addr_t *destination) icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL; icmp_send_buf->code = ICMP_CODE_DAO_ACK; - icmp_send_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6); rpl_send_dao_ack_buf = get_rpl_send_dao_ack_buf(); rpl_send_dao_ack_buf->rpl_instanceid = my_dodag->instance->id; @@ -454,7 +453,7 @@ void send_DAO_ACK(ipv6_addr_t *destination) rpl_send_dao_ack_buf->status = 0; uint16_t plen = ICMPV6_HDR_LEN + DAO_ACK_LEN; - rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6, NULL); + rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6); mutex_unlock(&rpl_send_mutex); } @@ -886,8 +885,7 @@ void recv_rpl_dao_ack(void) } -/* TODO: tcp_socket unused? */ -void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_t next_header, void *tcp_socket) +void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_t next_header) { uint8_t *p_ptr; ipv6_send_buf = get_rpl_send_ipv6_buf(); @@ -904,6 +902,10 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_ memcpy(&(ipv6_send_buf->destaddr), destination, 16); ipv6_iface_get_best_src_addr(&(ipv6_send_buf->srcaddr), &(ipv6_send_buf->destaddr)); + icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); + icmp_send_buf->checksum = 0; + icmp_send_buf->checksum = ~ipv6_csum(ipv6_send_buf, (uint8_t*) icmp_send_buf, ipv6_send_buf->length, IPV6_PROTO_NUM_ICMPV6); + /* The packet was "assembled" in rpl.c. Therefore rpl_send_buf was used. * Therefore memcpy is not needed because the payload is at the * right memory location already. */