48 #include "contiki-default-conf.h" 53 #define LOG_MODULE "ICMPv6" 54 #define LOG_LEVEL LOG_LEVEL_IPV6 56 #define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)UIP_ICMP_PAYLOAD) 61 LIST(echo_reply_callback_list);
64 LIST(input_handler_list);
66 static uip_icmp6_input_handler_t *
67 input_handler_lookup(uint8_t type, uint8_t icode)
69 uip_icmp6_input_handler_t *handler = NULL;
71 for(handler =
list_head(input_handler_list);
74 if(handler->type == type &&
75 (handler->icode == icode ||
76 handler->icode == UIP_ICMP6_HANDLER_CODE_ANY)) {
87 uip_icmp6_input_handler_t *handler = input_handler_lookup(type, icode);
90 return UIP_ICMP6_INPUT_ERROR;
93 if(handler->handler == NULL) {
94 return UIP_ICMP6_INPUT_ERROR;
98 return UIP_ICMP6_INPUT_SUCCESS;
104 list_add(input_handler_list, handler);
108 echo_request_input(
void)
115 LOG_INFO(
"Received Echo Request from ");
145 LOG_INFO(
"Sending Echo Reply to ");
175 LOG_WARN(
"Unable to remove ext header before sending ICMPv6 ERROR message\n");
191 UIP_IP_BUF->vtc = 0x60;
192 UIP_IP_BUF->tcflow = 0;
193 UIP_IP_BUF->flow = 0;
194 UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
213 UIP_ICMP6_ERROR_BUF->param = uip_htonl(param);
214 uipbuf_set_len_field(UIP_IP_BUF,
uip_len - UIP_IPH_LEN);
220 LOG_WARN(
"Sending ICMPv6 ERROR message type %d code %d to ", type, code);
221 LOG_WARN_6ADDR(&UIP_IP_BUF->destipaddr);
223 LOG_WARN_6ADDR(&UIP_IP_BUF->srcipaddr);
237 uipbuf_set_len_field(
UIP_IP_BUF, UIP_ICMPH_LEN + payload_len);
239 memcpy(&
UIP_IP_BUF->destipaddr, dest,
sizeof(*dest));
248 uip_len = UIP_IPH_LEN + UIP_ICMPH_LEN + payload_len;
253 LOG_INFO(
"Sending ICMPv6 packet to ");
255 LOG_INFO_(
", type %u, code %u, len %u\n", type, code, payload_len);
261 echo_reply_input(
void)
266 LOG_INFO(
"Received Echo Reply from ");
280 struct uip_icmp6_echo_reply_notification *n;
281 for(n =
list_head(echo_reply_callback_list);
284 if(n->callback != NULL) {
285 n->callback(&sender, ttl,
286 (uint8_t *)UIP_ICMP_PAYLOAD,
287 uip_len -
sizeof(
struct uip_icmp_hdr) - UIP_IPH_LEN);
298 uip_icmp6_echo_reply_callback_t c)
300 if(n != NULL && c != NULL) {
302 list_add(echo_reply_callback_list, n);
313 UIP_ICMP6_HANDLER_CODE_ANY, echo_request_input);
315 UIP_ICMP6_HANDLER_CODE_ANY, echo_reply_input);
#define UIP_ICMP6_ERROR_LEN
ICMPv6 Error message constant part length.
#define UIP_IP_BUF
Direct access to IPv6 header.
uint8_t uip_last_proto
The final protocol after IPv6 extension headers: UIP_PROTO_TCP, UIP_PROTO_UDP or UIP_PROTO_ICMP6.
void uip_icmp6_echo_reply_callback_rm(struct uip_icmp6_echo_reply_notification *n)
Remove a callback function for ping replies.
Header file for ICMPv6 message and error handing (RFC 4443)
uint16_t uip_len
The length of the packet in the uip_buf buffer.
void tcpip_ipv6_output(void)
This function does address resolution and then calls tcpip_output.
#define UIP_ICMP_BUF
Direct access to ICMP, UDP, and TCP headers and payload, with implicit ext header offset (global uip_...
#define ICMP6_PARAM_PROB
ip6 header bad
void uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param)
Send an icmpv6 error message.
#define ICMP6_ECHO_REQUEST
Echo request.
#define UIP_LINK_MTU
The maximum transmission unit at the IP Layer.
Header file for IPv6-related data structures.
uint8_t uip_icmp6_input(uint8_t type, uint8_t icode)
Handle an incoming ICMPv6 message.
void uip_icmp6_echo_reply_callback_add(struct uip_icmp6_echo_reply_notification *n, uip_icmp6_echo_reply_callback_t c)
Add a callback function for ping replies.
uint16_t uip_ext_len
The length of the extension headers.
void * list_head(list_t list)
Get a pointer to the first element of a list.
#define uip_is_addr_unspecified(a)
Is IPv6 address a the unspecified address a is of type uip_ipaddr_t.
Routing driver header file
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
#define UIP_STAT(s)
The uIP TCP/IP statistics.
#define uip_is_addr_mcast(a)
is address a multicast address, see RFC 4291 a is of type uip_ipaddr_t*
void list_add(list_t list, void *item)
Add an item at the end of a list.
#define LIST(name)
Declare a linked list.
static uip_ipaddr_t tmp_ipaddr
temporary IP address
#define ICMP6_PARAMPROB_OPTION
unrecognized option
uip_ds6_netif_t uip_ds6_if
The single interface.
bool uip_remove_ext_hdr(void)
Removes all IPv6 extension headers from uip_buf, updates length fields (uip_len and uip_ext_len) ...
#define ICMP6_ECHO_REPLY
Echo reply.
uint16_t uip_icmp6chksum(void)
Calculate the ICMP checksum of the packet in uip_buf.
void uip_icmp6_register_input_handler(uip_icmp6_input_handler_t *handler)
Register a handler which can handle a specific ICMPv6 message type.
void uip_icmp6_init()
Initialise the uIP ICMPv6 core.
bool(* ext_header_remove)(void)
Removes all extension headers that pertain to the routing protocol.
void uip_icmp6_send(const uip_ipaddr_t *dest, int type, int code, int payload_len)
Send an icmpv6 message.
Header file for the logging system
void uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
Source address selection, see RFC 3484.
void list_remove(list_t list, void *item)
Remove a specific element from a list.
void * list_item_next(void *item)
Get the next item following this item.