1 /******************************************************************************
2 * Copyright (c) 2013 IBM Corporation
4 * This program and the accompanying materials
5 * are made available under the terms of the BSD License
6 * which accompanies this distribution, and is available at
7 * http://www.opensource.org/licenses/bsd-license.php
10 * IBM Corporation - initial implementation
11 *****************************************************************************/
17 #include <netlib/ethernet.h>
18 #include <netlib/ipv6.h>
20 #define __ICMPV6_DEBUG__
22 #ifdef __ICMPV6_DEBUG__
23 #define ICMPV6_DEBUG_PRINT(format, ...) printf(format, ## __VA_ARGS__)
25 #define ICMPV6_DEBUG_PRINT(format, ...)
28 #define ICMPv6_HEADER_SIZE 4 /* Size of common fields */
29 #define IPTYPE_ICMPV6 0x3a
31 /* Error message types */
32 #define ICMPV6_DEST_UNREACHABLE 1 /* Destination unreachable */
33 #define ICMPV6_PACKET_TOO_BIG 2 /* Packet too big */
34 #define ICMPV6_TIME_EXCEEDED 3 /* Time exceeded */
35 #define ICMPV6_PARAM_PROBLEM 4 /* Parameter problem */
37 /* Informational message types */
38 #define ICMPV6_ECHO_REQUEST 128 /* Echo request */
39 #define ICMPV6_ECHO_REPLY 129 /* Echo reply */
40 #define ICMPV6_MCAST_LISTENER_QUERY 130 /* Multicast listener query */
41 #define ICMPV6_MCAST_LISTENER_REPORT 131 /* Multicast listener report */
42 #define ICMPv6 MCAST_LISTENER_DONE 132 /* Multicast listener done */
43 #define ICMPV6_ROUTER_SOLICITATION 133 /* Router solicitation */
44 #define ICMPV6_ROUTER_ADVERTISEMENT 134 /* Router advertisement */
45 #define ICMPV6_NEIGHBOUR_SOLICITATION 135 /* Neighbor solicitation */
46 #define ICMPV6_NEIGHBOUR_ADVERTISEMENT 136 /* Neighbor advertisement */
47 #define ICMPV6_REDIRECT_MSG 137 /* Redirect message */
49 /******** Functions *******************/
50 int8_t handle_icmpv6 (int fd, struct ethhdr *etherhdr, uint8_t *ip6_packet);
51 void send_neighbour_solicitation(int fd, ip6_addr_t *target_ip6);
52 void send_router_solicitation(int fd);
53 int is_ra_received(void);
55 /* Prefix information */
56 struct option_prefix {
59 uint8_t prefix_length;
65 uint32_t valid_lifetime;
66 uint32_t preferred_lifetime;
69 } __attribute((packed));
71 /* Neighbour advertisement/solicitation flags */
73 uint8_t is_router:1, /* sender (we) is a router */
74 na_is_solicited:1, /* this NA was solicited (asked for) */
75 override:1, /* receiver shall override its cache entries */
77 }__attribute((packed));
79 /* Source/Target Link-layer address */
80 struct option_ll_address{
83 uint8_t mac[ETH_ALEN];
84 } __attribute((packed));
86 struct neighbour_solicitation {
92 struct option_ll_address lladdr;
93 } __attribute((packed));
95 struct neighbour_advertisement {
101 struct option_ll_address lladdr;
102 } __attribute((packed));
104 struct router_solicitation {
106 struct option_ll_address lladdr;
107 } __attribute((packed));
109 struct router_advertisement {
110 uint8_t curr_hop_limit;
116 uint16_t router_lifetime;
117 uint32_t reachable_time;
118 uint32_t retrans_timer;
119 struct option_prefix prefix;
120 struct option_ll_address ll_addr;
121 } __attribute((packed));
128 struct neighbour_solicitation nghb_solicit;
129 struct neighbour_advertisement nghb_adv;
130 struct router_solicitation router_solicit;
131 struct router_advertisement ra;
133 } __attribute((packed));