2008-10-14 11:42:33 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2001-2003, Adam Dunkels.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
|
|
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the uIP TCP/IP stack.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-11-08 01:15:42 +01:00
|
|
|
/**
|
2015-02-15 19:02:07 +01:00
|
|
|
* \addtogroup uip6
|
|
|
|
* @{
|
2014-11-08 01:15:42 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-02-15 19:02:07 +01:00
|
|
|
* \file
|
|
|
|
* ICMPv6 (RFC 4443) implementation, with message and error handling
|
2015-11-03 04:19:47 +01:00
|
|
|
* \author Julien Abeille <jabeille@cisco.com>
|
2015-02-15 19:02:07 +01:00
|
|
|
* \author Mathilde Durvy <mdurvy@cisco.com>
|
2014-11-08 01:15:42 +01:00
|
|
|
*/
|
|
|
|
|
2008-10-14 11:42:33 +02:00
|
|
|
#include <string.h>
|
2013-11-22 09:17:54 +01:00
|
|
|
#include "net/ipv6/uip-ds6.h"
|
|
|
|
#include "net/ipv6/uip-icmp6.h"
|
2013-03-17 22:54:12 +01:00
|
|
|
#include "contiki-default-conf.h"
|
2008-10-14 11:42:33 +02:00
|
|
|
|
|
|
|
#define DEBUG 0
|
|
|
|
#if DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
2012-02-17 23:45:13 +01:00
|
|
|
#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
|
2008-10-14 11:42:33 +02:00
|
|
|
#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",lladdr->addr[0], lladdr->addr[1], lladdr->addr[2], lladdr->addr[3],lladdr->addr[4], lladdr->addr[5])
|
|
|
|
#else
|
|
|
|
#define PRINTF(...)
|
|
|
|
#define PRINT6ADDR(addr)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
|
|
|
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
|
|
|
#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len])
|
2011-07-11 16:53:02 +02:00
|
|
|
#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
|
|
|
#define UIP_FIRST_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLIPH_LEN])
|
2008-10-14 11:42:33 +02:00
|
|
|
|
2011-07-11 16:53:02 +02:00
|
|
|
#if UIP_CONF_IPV6_RPL
|
2011-12-08 15:42:19 +01:00
|
|
|
#include "rpl/rpl.h"
|
2011-07-11 16:53:02 +02:00
|
|
|
#endif /* UIP_CONF_IPV6_RPL */
|
|
|
|
|
2014-02-01 00:46:57 +01:00
|
|
|
/** \brief temporary IP address */
|
|
|
|
static uip_ipaddr_t tmp_ipaddr;
|
|
|
|
|
2013-11-16 16:23:43 +01:00
|
|
|
LIST(echo_reply_callback_list);
|
2014-03-08 22:24:50 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* List of input handlers */
|
|
|
|
LIST(input_handler_list);
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static uip_icmp6_input_handler_t *
|
|
|
|
input_handler_lookup(uint8_t type, uint8_t icode)
|
|
|
|
{
|
|
|
|
uip_icmp6_input_handler_t *handler = NULL;
|
|
|
|
|
|
|
|
for(handler = list_head(input_handler_list);
|
|
|
|
handler != NULL;
|
|
|
|
handler = list_item_next(handler)) {
|
|
|
|
if(handler->type == type &&
|
|
|
|
(handler->icode == icode ||
|
|
|
|
handler->icode == UIP_ICMP6_HANDLER_CODE_ANY)) {
|
|
|
|
return handler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
uint8_t
|
|
|
|
uip_icmp6_input(uint8_t type, uint8_t icode)
|
|
|
|
{
|
|
|
|
uip_icmp6_input_handler_t *handler = input_handler_lookup(type, icode);
|
|
|
|
|
|
|
|
if(handler == NULL) {
|
|
|
|
return UIP_ICMP6_INPUT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(handler->handler == NULL) {
|
|
|
|
return UIP_ICMP6_INPUT_ERROR;
|
|
|
|
}
|
2013-11-16 16:23:43 +01:00
|
|
|
|
2014-03-08 22:24:50 +01:00
|
|
|
handler->handler();
|
|
|
|
return UIP_ICMP6_INPUT_SUCCESS;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
uip_icmp6_register_input_handler(uip_icmp6_input_handler_t *handler)
|
|
|
|
{
|
|
|
|
list_add(input_handler_list, handler);
|
|
|
|
}
|
2010-04-30 15:22:21 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-03-08 22:31:53 +01:00
|
|
|
static void
|
|
|
|
echo_request_input(void)
|
2008-10-14 11:42:33 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* we send an echo reply. It is trivial if there was no extension
|
|
|
|
* headers in the request otherwise we need to remove the extension
|
|
|
|
* headers and change a few fields
|
|
|
|
*/
|
2015-11-25 16:39:27 +01:00
|
|
|
PRINTF("Received Echo Request from ");
|
2008-10-14 11:42:33 +02:00
|
|
|
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
2015-11-25 16:39:27 +01:00
|
|
|
PRINTF(" to ");
|
2008-10-14 11:42:33 +02:00
|
|
|
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
|
|
|
|
PRINTF("\n");
|
2011-07-11 16:53:02 +02:00
|
|
|
|
2008-10-14 11:42:33 +02:00
|
|
|
/* IP header */
|
2010-03-15 17:41:24 +01:00
|
|
|
UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit;
|
2008-10-14 11:42:33 +02:00
|
|
|
|
|
|
|
if(uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)){
|
|
|
|
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &UIP_IP_BUF->srcipaddr);
|
2010-03-15 17:41:24 +01:00
|
|
|
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
|
2008-10-14 11:42:33 +02:00
|
|
|
} else {
|
|
|
|
uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF->srcipaddr);
|
|
|
|
uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
|
|
|
|
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &tmp_ipaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(uip_ext_len > 0) {
|
2016-02-01 18:02:33 +01:00
|
|
|
/* Remove extension headers if any */
|
|
|
|
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
|
|
|
|
uip_len -= uip_ext_len;
|
|
|
|
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
|
|
|
|
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
|
|
|
|
/* move the echo request payload (starting after the icmp header)
|
|
|
|
* to the new location in the reply.
|
|
|
|
* The shift is equal to the length of the extension headers present
|
|
|
|
* Note: UIP_ICMP_BUF still points to the echo request at this stage
|
|
|
|
*/
|
|
|
|
memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - uip_ext_len,
|
|
|
|
(uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN,
|
|
|
|
(uip_len - UIP_IPH_LEN - UIP_ICMPH_LEN));
|
|
|
|
uip_ext_len = 0;
|
|
|
|
}
|
|
|
|
|
2008-10-14 11:42:33 +02:00
|
|
|
/* Below is important for the correctness of UIP_ICMP_BUF and the
|
|
|
|
* checksum
|
|
|
|
*/
|
2011-07-11 16:53:02 +02:00
|
|
|
|
2008-10-14 11:42:33 +02:00
|
|
|
/* Note: now UIP_ICMP_BUF points to the beginning of the echo reply */
|
|
|
|
UIP_ICMP_BUF->type = ICMP6_ECHO_REPLY;
|
|
|
|
UIP_ICMP_BUF->icode = 0;
|
|
|
|
UIP_ICMP_BUF->icmpchksum = 0;
|
|
|
|
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
|
2011-07-11 16:53:02 +02:00
|
|
|
|
2015-11-25 16:39:27 +01:00
|
|
|
PRINTF("Sending Echo Reply to ");
|
2008-10-14 11:42:33 +02:00
|
|
|
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
|
2015-11-25 16:39:27 +01:00
|
|
|
PRINTF(" from ");
|
2008-10-14 11:42:33 +02:00
|
|
|
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
|
|
|
PRINTF("\n");
|
|
|
|
UIP_STAT(++uip_stat.icmp.sent);
|
|
|
|
return;
|
|
|
|
}
|
2010-04-30 15:22:21 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-10-14 11:42:33 +02:00
|
|
|
void
|
2012-02-17 23:45:13 +01:00
|
|
|
uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) {
|
2016-03-10 11:33:40 +01:00
|
|
|
/* 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) {
|
2015-06-15 10:25:58 +02:00
|
|
|
uip_clear_buf();
|
2011-07-11 16:53:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2016-03-10 11:33:40 +01:00
|
|
|
if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128) {
|
2015-06-15 10:25:58 +02:00
|
|
|
uip_clear_buf();
|
2011-07-11 16:53:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2010-03-15 17:41:24 +01:00
|
|
|
}
|
|
|
|
|
2011-07-11 16:53:02 +02:00
|
|
|
#if UIP_CONF_IPV6_RPL
|
2016-03-10 11:35:51 +01:00
|
|
|
rpl_remove_header();
|
|
|
|
#else
|
2011-07-11 16:53:02 +02:00
|
|
|
uip_ext_len = 0;
|
|
|
|
#endif /* UIP_CONF_IPV6_RPL */
|
|
|
|
|
2008-10-14 11:42:33 +02:00
|
|
|
/* remember data of original packet before shifting */
|
2011-07-11 16:53:02 +02:00
|
|
|
uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF->destipaddr);
|
|
|
|
|
2008-10-14 11:42:33 +02:00
|
|
|
uip_len += UIP_IPICMPH_LEN + UIP_ICMP6_ERROR_LEN;
|
2011-07-11 16:53:02 +02:00
|
|
|
|
2016-03-10 11:33:40 +01:00
|
|
|
if(uip_len > UIP_LINK_MTU) {
|
2011-07-11 16:53:02 +02:00
|
|
|
uip_len = UIP_LINK_MTU;
|
2016-03-10 11:33:40 +01:00
|
|
|
}
|
2008-10-14 11:42:33 +02:00
|
|
|
|
2011-07-11 16:53:02 +02:00
|
|
|
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);
|
2008-10-14 11:42:33 +02:00
|
|
|
|
|
|
|
UIP_IP_BUF->vtc = 0x60;
|
|
|
|
UIP_IP_BUF->tcflow = 0;
|
|
|
|
UIP_IP_BUF->flow = 0;
|
2011-07-11 16:53:02 +02:00
|
|
|
if (uip_ext_len) {
|
|
|
|
UIP_FIRST_EXT_BUF->next = UIP_PROTO_ICMP6;
|
|
|
|
} else {
|
|
|
|
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
|
|
|
|
}
|
2010-03-15 17:41:24 +01:00
|
|
|
UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit;
|
2008-10-14 11:42:33 +02:00
|
|
|
|
|
|
|
/* the source should not be unspecified nor multicast, the check for
|
|
|
|
multicast is done in uip_process */
|
|
|
|
if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)){
|
2015-06-15 10:25:58 +02:00
|
|
|
uip_clear_buf();
|
2008-10-14 11:42:33 +02:00
|
|
|
return;
|
|
|
|
}
|
2011-07-11 16:53:02 +02:00
|
|
|
|
2008-10-14 11:42:33 +02:00
|
|
|
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &UIP_IP_BUF->srcipaddr);
|
|
|
|
|
|
|
|
if(uip_is_addr_mcast(&tmp_ipaddr)){
|
|
|
|
if(type == ICMP6_PARAM_PROB && code == ICMP6_PARAMPROB_OPTION){
|
2010-03-15 17:41:24 +01:00
|
|
|
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &tmp_ipaddr);
|
2008-10-14 11:42:33 +02:00
|
|
|
} else {
|
2015-06-15 10:25:58 +02:00
|
|
|
uip_clear_buf();
|
2008-10-14 11:42:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2010-03-11 19:07:37 +01:00
|
|
|
#if UIP_CONF_ROUTER
|
|
|
|
/* need to pick a source that corresponds to this node */
|
2010-03-15 17:41:24 +01:00
|
|
|
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &tmp_ipaddr);
|
2010-03-11 19:07:37 +01:00
|
|
|
#else
|
|
|
|
uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &tmp_ipaddr);
|
|
|
|
#endif
|
2008-10-14 11:42:33 +02:00
|
|
|
}
|
2011-07-11 16:53:02 +02:00
|
|
|
|
2008-10-14 11:42:33 +02:00
|
|
|
UIP_ICMP_BUF->type = type;
|
|
|
|
UIP_ICMP_BUF->icode = code;
|
2010-10-19 20:29:03 +02:00
|
|
|
UIP_ICMP6_ERROR_BUF->param = uip_htonl(param);
|
2008-10-14 11:42:33 +02:00
|
|
|
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
|
|
|
|
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
|
|
|
|
UIP_ICMP_BUF->icmpchksum = 0;
|
|
|
|
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
|
|
|
|
|
|
|
|
UIP_STAT(++uip_stat.icmp.sent);
|
|
|
|
|
2015-11-25 16:39:27 +01:00
|
|
|
PRINTF("Sending ICMPv6 ERROR message type %d code %d to ", type, code);
|
2008-10-14 11:42:33 +02:00
|
|
|
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
|
2015-11-25 16:39:27 +01:00
|
|
|
PRINTF(" from ");
|
2008-10-14 11:42:33 +02:00
|
|
|
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
|
|
|
PRINTF("\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-30 15:22:21 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2013-11-16 16:23:43 +01:00
|
|
|
uip_icmp6_send(const uip_ipaddr_t *dest, int type, int code, int payload_len)
|
2010-04-30 15:22:21 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
UIP_IP_BUF->vtc = 0x60;
|
|
|
|
UIP_IP_BUF->tcflow = 0;
|
|
|
|
UIP_IP_BUF->flow = 0;
|
|
|
|
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
|
|
|
|
UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit;
|
2010-11-03 12:56:11 +01:00
|
|
|
UIP_IP_BUF->len[0] = (UIP_ICMPH_LEN + payload_len) >> 8;
|
|
|
|
UIP_IP_BUF->len[1] = (UIP_ICMPH_LEN + payload_len) & 0xff;
|
2010-04-30 15:22:21 +02:00
|
|
|
|
|
|
|
memcpy(&UIP_IP_BUF->destipaddr, dest, sizeof(*dest));
|
|
|
|
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
|
|
|
|
|
|
|
|
UIP_ICMP_BUF->type = type;
|
|
|
|
UIP_ICMP_BUF->icode = code;
|
|
|
|
|
|
|
|
UIP_ICMP_BUF->icmpchksum = 0;
|
|
|
|
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
|
|
|
|
|
|
|
|
uip_len = UIP_IPH_LEN + UIP_ICMPH_LEN + payload_len;
|
2015-11-03 04:19:47 +01:00
|
|
|
|
|
|
|
UIP_STAT(++uip_stat.icmp.sent);
|
|
|
|
UIP_STAT(++uip_stat.ip.sent);
|
|
|
|
|
2010-04-30 15:22:21 +02:00
|
|
|
tcpip_ipv6_output();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-03-08 22:31:53 +01:00
|
|
|
static void
|
|
|
|
echo_reply_input(void)
|
2013-11-16 16:23:43 +01:00
|
|
|
{
|
|
|
|
int ttl;
|
|
|
|
uip_ipaddr_t sender;
|
2016-02-01 18:02:33 +01:00
|
|
|
|
|
|
|
PRINTF("Received Echo Reply from ");
|
|
|
|
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
|
|
|
PRINTF(" to ");
|
|
|
|
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
|
|
|
|
PRINTF("\n");
|
2013-11-16 16:23:43 +01:00
|
|
|
|
|
|
|
uip_ipaddr_copy(&sender, &UIP_IP_BUF->srcipaddr);
|
|
|
|
ttl = UIP_IP_BUF->ttl;
|
|
|
|
|
|
|
|
if(uip_ext_len > 0) {
|
2016-02-01 18:02:33 +01:00
|
|
|
/* Remove extension headers if any */
|
|
|
|
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
|
|
|
|
uip_len -= uip_ext_len;
|
|
|
|
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
|
|
|
|
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
|
|
|
|
/* move the echo reply payload (starting after the icmp header)
|
|
|
|
* to the new location in the reply. The shift is equal to the
|
|
|
|
* length of the extension headers present Note: UIP_ICMP_BUF
|
|
|
|
* still points to the echo request at this stage
|
|
|
|
*/
|
|
|
|
memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - uip_ext_len,
|
|
|
|
(uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN,
|
|
|
|
(uip_len - UIP_IPH_LEN - UIP_ICMPH_LEN));
|
|
|
|
uip_ext_len = 0;
|
2013-11-16 16:23:43 +01:00
|
|
|
}
|
2010-04-30 15:22:21 +02:00
|
|
|
|
2013-11-16 16:23:43 +01:00
|
|
|
/* Call all registered applications to let them know an echo reply
|
|
|
|
has been received. */
|
|
|
|
{
|
|
|
|
struct uip_icmp6_echo_reply_notification *n;
|
|
|
|
for(n = list_head(echo_reply_callback_list);
|
|
|
|
n != NULL;
|
|
|
|
n = list_item_next(n)) {
|
|
|
|
if(n->callback != NULL) {
|
|
|
|
n->callback(&sender, ttl,
|
|
|
|
(uint8_t *)&UIP_ICMP_BUF[sizeof(struct uip_icmp_hdr)],
|
|
|
|
uip_len - sizeof(struct uip_icmp_hdr) - UIP_IPH_LEN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 22:31:53 +01:00
|
|
|
|
2015-06-15 10:25:58 +02:00
|
|
|
uip_clear_buf();
|
2013-11-16 16:23:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
uip_icmp6_echo_reply_callback_add(struct uip_icmp6_echo_reply_notification *n,
|
|
|
|
uip_icmp6_echo_reply_callback_t c)
|
|
|
|
{
|
|
|
|
if(n != NULL && c != NULL) {
|
|
|
|
n->callback = c;
|
|
|
|
list_add(echo_reply_callback_list, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
uip_icmp6_echo_reply_callback_rm(struct uip_icmp6_echo_reply_notification *n)
|
|
|
|
{
|
|
|
|
list_remove(echo_reply_callback_list, n);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-03-08 22:31:53 +01:00
|
|
|
UIP_ICMP6_HANDLER(echo_request_handler, ICMP6_ECHO_REQUEST,
|
|
|
|
UIP_ICMP6_HANDLER_CODE_ANY, echo_request_input);
|
|
|
|
UIP_ICMP6_HANDLER(echo_reply_handler, ICMP6_ECHO_REPLY,
|
|
|
|
UIP_ICMP6_HANDLER_CODE_ANY, echo_reply_input);
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
uip_icmp6_init()
|
|
|
|
{
|
|
|
|
/* Register Echo Request and Reply handlers */
|
|
|
|
uip_icmp6_register_input_handler(&echo_request_handler);
|
|
|
|
uip_icmp6_register_input_handler(&echo_reply_handler);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-10-14 11:42:33 +02:00
|
|
|
/** @} */
|