1 #ifndef _NETINET_ICMP6_H
2 #define _NETINET_ICMP6_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include <stdint.h>
9 #include <string.h>
10 #include <sys/types.h>
11 #include <netinet/in.h>
12 #include <endian.h>
13 
14 #define ICMP6_FILTER 1
15 
16 #define ICMP6_FILTER_BLOCK		1
17 #define ICMP6_FILTER_PASS		2
18 #define ICMP6_FILTER_BLOCKOTHERS	3
19 #define ICMP6_FILTER_PASSONLY		4
20 
21 struct icmp6_filter {
22 	uint32_t icmp6_filt[8];
23 };
24 
25 struct icmp6_hdr {
26 	uint8_t     icmp6_type;
27 	uint8_t     icmp6_code;
28 	uint16_t    icmp6_cksum;
29 	union {
30 		uint32_t  icmp6_un_data32[1];
31 		uint16_t  icmp6_un_data16[2];
32 		uint8_t   icmp6_un_data8[4];
33 	} icmp6_dataun;
34 };
35 
36 #define icmp6_data32    icmp6_dataun.icmp6_un_data32
37 #define icmp6_data16    icmp6_dataun.icmp6_un_data16
38 #define icmp6_data8     icmp6_dataun.icmp6_un_data8
39 #define icmp6_pptr      icmp6_data32[0]
40 #define icmp6_mtu       icmp6_data32[0]
41 #define icmp6_id        icmp6_data16[0]
42 #define icmp6_seq       icmp6_data16[1]
43 #define icmp6_maxdelay  icmp6_data16[0]
44 
45 #define ICMP6_DST_UNREACH             1
46 #define ICMP6_PACKET_TOO_BIG          2
47 #define ICMP6_TIME_EXCEEDED           3
48 #define ICMP6_PARAM_PROB              4
49 
50 #define ICMP6_INFOMSG_MASK  0x80
51 
52 #define ICMP6_ECHO_REQUEST          128
53 #define ICMP6_ECHO_REPLY            129
54 #define MLD_LISTENER_QUERY          130
55 #define MLD_LISTENER_REPORT         131
56 #define MLD_LISTENER_REDUCTION      132
57 
58 #define ICMP6_DST_UNREACH_NOROUTE     0
59 #define ICMP6_DST_UNREACH_ADMIN       1
60 #define ICMP6_DST_UNREACH_BEYONDSCOPE 2
61 #define ICMP6_DST_UNREACH_ADDR        3
62 #define ICMP6_DST_UNREACH_NOPORT      4
63 
64 #define ICMP6_TIME_EXCEED_TRANSIT     0
65 #define ICMP6_TIME_EXCEED_REASSEMBLY  1
66 
67 #define ICMP6_PARAMPROB_HEADER        0
68 #define ICMP6_PARAMPROB_NEXTHEADER    1
69 #define ICMP6_PARAMPROB_OPTION        2
70 
71 #define ICMP6_FILTER_WILLPASS(type, filterp) \
72 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
73 
74 #define ICMP6_FILTER_WILLBLOCK(type, filterp) \
75 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
76 
77 #define ICMP6_FILTER_SETPASS(type, filterp) \
78 	((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))))
79 
80 #define ICMP6_FILTER_SETBLOCK(type, filterp) \
81 	((((filterp)->icmp6_filt[(type) >> 5]) |=  (1 << ((type) & 31))))
82 
83 #define ICMP6_FILTER_SETPASSALL(filterp) \
84 	memset (filterp, 0, sizeof (struct icmp6_filter));
85 
86 #define ICMP6_FILTER_SETBLOCKALL(filterp) \
87 	memset (filterp, 0xFF, sizeof (struct icmp6_filter));
88 
89 #define ND_ROUTER_SOLICIT           133
90 #define ND_ROUTER_ADVERT            134
91 #define ND_NEIGHBOR_SOLICIT         135
92 #define ND_NEIGHBOR_ADVERT          136
93 #define ND_REDIRECT                 137
94 
95 struct nd_router_solicit {
96 	struct icmp6_hdr  nd_rs_hdr;
97 };
98 
99 #define nd_rs_type               nd_rs_hdr.icmp6_type
100 #define nd_rs_code               nd_rs_hdr.icmp6_code
101 #define nd_rs_cksum              nd_rs_hdr.icmp6_cksum
102 #define nd_rs_reserved           nd_rs_hdr.icmp6_data32[0]
103 
104 struct nd_router_advert {
105 	struct icmp6_hdr  nd_ra_hdr;
106 	uint32_t   nd_ra_reachable;
107 	uint32_t   nd_ra_retransmit;
108 };
109 
110 #define nd_ra_type               nd_ra_hdr.icmp6_type
111 #define nd_ra_code               nd_ra_hdr.icmp6_code
112 #define nd_ra_cksum              nd_ra_hdr.icmp6_cksum
113 #define nd_ra_curhoplimit        nd_ra_hdr.icmp6_data8[0]
114 #define nd_ra_flags_reserved     nd_ra_hdr.icmp6_data8[1]
115 #define ND_RA_FLAG_MANAGED       0x80
116 #define ND_RA_FLAG_OTHER         0x40
117 #define ND_RA_FLAG_HOME_AGENT    0x20
118 #define nd_ra_router_lifetime    nd_ra_hdr.icmp6_data16[1]
119 
120 struct nd_neighbor_solicit {
121 	struct icmp6_hdr  nd_ns_hdr;
122 	struct in6_addr   nd_ns_target;
123 };
124 
125 #define nd_ns_type               nd_ns_hdr.icmp6_type
126 #define nd_ns_code               nd_ns_hdr.icmp6_code
127 #define nd_ns_cksum              nd_ns_hdr.icmp6_cksum
128 #define nd_ns_reserved           nd_ns_hdr.icmp6_data32[0]
129 
130 struct nd_neighbor_advert {
131 	struct icmp6_hdr  nd_na_hdr;
132 	struct in6_addr   nd_na_target;
133 };
134 
135 #define nd_na_type               nd_na_hdr.icmp6_type
136 #define nd_na_code               nd_na_hdr.icmp6_code
137 #define nd_na_cksum              nd_na_hdr.icmp6_cksum
138 #define nd_na_flags_reserved     nd_na_hdr.icmp6_data32[0]
139 #if     __BYTE_ORDER == __BIG_ENDIAN
140 #define ND_NA_FLAG_ROUTER        0x80000000
141 #define ND_NA_FLAG_SOLICITED     0x40000000
142 #define ND_NA_FLAG_OVERRIDE      0x20000000
143 #else
144 #define ND_NA_FLAG_ROUTER        0x00000080
145 #define ND_NA_FLAG_SOLICITED     0x00000040
146 #define ND_NA_FLAG_OVERRIDE      0x00000020
147 #endif
148 
149 struct nd_redirect {
150 	struct icmp6_hdr  nd_rd_hdr;
151 	struct in6_addr   nd_rd_target;
152 	struct in6_addr   nd_rd_dst;
153 };
154 
155 #define nd_rd_type               nd_rd_hdr.icmp6_type
156 #define nd_rd_code               nd_rd_hdr.icmp6_code
157 #define nd_rd_cksum              nd_rd_hdr.icmp6_cksum
158 #define nd_rd_reserved           nd_rd_hdr.icmp6_data32[0]
159 
160 struct nd_opt_hdr {
161 	uint8_t  nd_opt_type;
162 	uint8_t  nd_opt_len;
163 };
164 
165 #define ND_OPT_SOURCE_LINKADDR		1
166 #define ND_OPT_TARGET_LINKADDR		2
167 #define ND_OPT_PREFIX_INFORMATION	3
168 #define ND_OPT_REDIRECTED_HEADER	4
169 #define ND_OPT_MTU			5
170 #define ND_OPT_RTR_ADV_INTERVAL		7
171 #define ND_OPT_HOME_AGENT_INFO		8
172 
173 struct nd_opt_prefix_info {
174 	uint8_t   nd_opt_pi_type;
175 	uint8_t   nd_opt_pi_len;
176 	uint8_t   nd_opt_pi_prefix_len;
177 	uint8_t   nd_opt_pi_flags_reserved;
178 	uint32_t  nd_opt_pi_valid_time;
179 	uint32_t  nd_opt_pi_preferred_time;
180 	uint32_t  nd_opt_pi_reserved2;
181 	struct in6_addr  nd_opt_pi_prefix;
182 };
183 
184 #define ND_OPT_PI_FLAG_ONLINK	0x80
185 #define ND_OPT_PI_FLAG_AUTO	0x40
186 #define ND_OPT_PI_FLAG_RADDR	0x20
187 
188 struct nd_opt_rd_hdr {
189 	uint8_t   nd_opt_rh_type;
190 	uint8_t   nd_opt_rh_len;
191 	uint16_t  nd_opt_rh_reserved1;
192 	uint32_t  nd_opt_rh_reserved2;
193 };
194 
195 struct nd_opt_mtu {
196 	uint8_t   nd_opt_mtu_type;
197 	uint8_t   nd_opt_mtu_len;
198 	uint16_t  nd_opt_mtu_reserved;
199 	uint32_t  nd_opt_mtu_mtu;
200 };
201 
202 struct mld_hdr {
203 	struct icmp6_hdr    mld_icmp6_hdr;
204 	struct in6_addr     mld_addr;
205 };
206 
207 #define mld_type        mld_icmp6_hdr.icmp6_type
208 #define mld_code        mld_icmp6_hdr.icmp6_code
209 #define mld_cksum       mld_icmp6_hdr.icmp6_cksum
210 #define mld_maxdelay    mld_icmp6_hdr.icmp6_data16[0]
211 #define mld_reserved    mld_icmp6_hdr.icmp6_data16[1]
212 
213 #define ICMP6_ROUTER_RENUMBERING    138
214 
215 struct icmp6_router_renum {
216 	struct icmp6_hdr    rr_hdr;
217 	uint8_t             rr_segnum;
218 	uint8_t             rr_flags;
219 	uint16_t            rr_maxdelay;
220 	uint32_t            rr_reserved;
221 };
222 
223 #define rr_type		rr_hdr.icmp6_type
224 #define rr_code         rr_hdr.icmp6_code
225 #define rr_cksum        rr_hdr.icmp6_cksum
226 #define rr_seqnum       rr_hdr.icmp6_data32[0]
227 
228 #define ICMP6_RR_FLAGS_TEST             0x80
229 #define ICMP6_RR_FLAGS_REQRESULT        0x40
230 #define ICMP6_RR_FLAGS_FORCEAPPLY       0x20
231 #define ICMP6_RR_FLAGS_SPECSITE         0x10
232 #define ICMP6_RR_FLAGS_PREVDONE         0x08
233 
234 struct rr_pco_match {
235 	uint8_t             rpm_code;
236 	uint8_t             rpm_len;
237 	uint8_t             rpm_ordinal;
238 	uint8_t             rpm_matchlen;
239 	uint8_t             rpm_minlen;
240 	uint8_t             rpm_maxlen;
241 	uint16_t            rpm_reserved;
242 	struct in6_addr     rpm_prefix;
243 };
244 
245 #define RPM_PCO_ADD             1
246 #define RPM_PCO_CHANGE          2
247 #define RPM_PCO_SETGLOBAL       3
248 
249 struct rr_pco_use {
250 	uint8_t             rpu_uselen;
251 	uint8_t             rpu_keeplen;
252 	uint8_t             rpu_ramask;
253 	uint8_t             rpu_raflags;
254 	uint32_t            rpu_vltime;
255 	uint32_t            rpu_pltime;
256 	uint32_t            rpu_flags;
257 	struct in6_addr     rpu_prefix;
258 };
259 
260 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK  0x20
261 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO    0x10
262 
263 #if __BYTE_ORDER == __BIG_ENDIAN
264 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000
265 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000
266 #else
267 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80
268 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40
269 #endif
270 
271 struct rr_result {
272 	uint16_t            rrr_flags;
273 	uint8_t             rrr_ordinal;
274 	uint8_t             rrr_matchedlen;
275 	uint32_t            rrr_ifid;
276 	struct in6_addr     rrr_prefix;
277 };
278 
279 #if __BYTE_ORDER == __BIG_ENDIAN
280 #define ICMP6_RR_RESULT_FLAGS_OOB       0x0002
281 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001
282 #else
283 #define ICMP6_RR_RESULT_FLAGS_OOB       0x0200
284 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100
285 #endif
286 
287 struct nd_opt_adv_interval {
288 	uint8_t   nd_opt_adv_interval_type;
289 	uint8_t   nd_opt_adv_interval_len;
290 	uint16_t  nd_opt_adv_interval_reserved;
291 	uint32_t  nd_opt_adv_interval_ival;
292 };
293 
294 struct nd_opt_home_agent_info {
295 	uint8_t   nd_opt_home_agent_info_type;
296 	uint8_t   nd_opt_home_agent_info_len;
297 	uint16_t  nd_opt_home_agent_info_reserved;
298 	uint16_t  nd_opt_home_agent_info_preference;
299 	uint16_t  nd_opt_home_agent_info_lifetime;
300 };
301 
302 #ifdef __cplusplus
303 }
304 #endif
305 
306 #endif
307