Skip to content

Commit 586c89b

Browse files
zhhyu7xiaoxiang781216
authored andcommitted
icmp6: add icmp6-related definition
adapts to third-party code compilation. in the process of porting ConnMan, we encounter some situations where the structure is not defined, or the returned data types do not match the expectations. Refer to the common implementation of other systems and add relevant definitions. Signed-off-by: zhanghongyu <[email protected]>
1 parent e565868 commit 586c89b

File tree

1 file changed

+364
-0
lines changed

1 file changed

+364
-0
lines changed

include/netinet/icmp6.h

Lines changed: 364 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,364 @@
1+
/****************************************************************************
2+
* include/netinet/icmp6.h
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
#ifndef _INCLUDE_NETINET_ICMP6_H
22+
#define _INCLUDE_NETINET_ICMP6_H
23+
24+
/****************************************************************************
25+
* Included Files
26+
****************************************************************************/
27+
28+
#include <string.h>
29+
#include <sys/types.h>
30+
#include <netinet/in.h>
31+
32+
/****************************************************************************
33+
* Pre-processor Definitions
34+
****************************************************************************/
35+
36+
#define ICMP6_FILTER 1
37+
38+
#define ICMP6_FILTER_BLOCK 1
39+
#define ICMP6_FILTER_PASS 2
40+
#define ICMP6_FILTER_BLOCKOTHERS 3
41+
#define ICMP6_FILTER_PASSONLY 4
42+
43+
struct icmp6_filter
44+
{
45+
uint32_t icmp6_filt[8];
46+
};
47+
48+
struct icmp6_hdr
49+
{
50+
uint8_t icmp6_type; /* type field */
51+
uint8_t icmp6_code; /* code field */
52+
uint16_t icmp6_cksum; /* checksum field */
53+
union
54+
{
55+
uint32_t icmp6_un_data32[1]; /* type-specific field */
56+
uint16_t icmp6_un_data16[2]; /* type-specific field */
57+
uint8_t icmp6_un_data8[4]; /* type-specific field */
58+
} icmp6_dataun;
59+
};
60+
61+
#define icmp6_data32 icmp6_dataun.icmp6_un_data32
62+
#define icmp6_data16 icmp6_dataun.icmp6_un_data16
63+
#define icmp6_data8 icmp6_dataun.icmp6_un_data8
64+
#define icmp6_pptr icmp6_data32[0] /* parameter prob */
65+
#define icmp6_mtu icmp6_data32[0] /* packet too big */
66+
#define icmp6_id icmp6_data16[0] /* echo request/reply */
67+
#define icmp6_seq icmp6_data16[1] /* echo request/reply */
68+
#define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */
69+
70+
#define ICMP6_DST_UNREACH 1
71+
#define ICMP6_PACKET_TOO_BIG 2
72+
#define ICMP6_TIME_EXCEEDED 3
73+
#define ICMP6_PARAM_PROB 4
74+
75+
#define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */
76+
77+
#define ICMP6_ECHO_REQUEST 128
78+
#define ICMP6_ECHO_REPLY 129
79+
#define MLD_LISTENER_QUERY 130
80+
#define MLD_LISTENER_REPORT 131
81+
#define MLD_LISTENER_REDUCTION 132
82+
83+
#define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */
84+
#define ICMP6_DST_UNREACH_ADMIN 1 /* communication with destination */
85+
/* administratively prohibited */
86+
#define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */
87+
#define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */
88+
#define ICMP6_DST_UNREACH_NOPORT 4 /* bad port */
89+
90+
#define ICMP6_TIME_EXCEED_TRANSIT 0 /* Hop Limit == 0 in transit */
91+
#define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* Reassembly time out */
92+
93+
#define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */
94+
#define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized Next Header */
95+
#define ICMP6_PARAMPROB_OPTION 2 /* unrecognized IPv6 option */
96+
97+
#define ICMP6_FILTER_WILLPASS(type, filterp) \
98+
((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
99+
100+
#define ICMP6_FILTER_WILLBLOCK(type, filterp) \
101+
((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
102+
103+
#define ICMP6_FILTER_SETPASS(type, filterp) \
104+
((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))))
105+
106+
#define ICMP6_FILTER_SETBLOCK(type, filterp) \
107+
((((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31))))
108+
109+
#define ICMP6_FILTER_SETPASSALL(filterp) \
110+
memset(filterp, 0, sizeof (struct icmp6_filter));
111+
112+
#define ICMP6_FILTER_SETBLOCKALL(filterp) \
113+
memset(filterp, 0xFF, sizeof (struct icmp6_filter));
114+
115+
#define ND_ROUTER_SOLICIT 133
116+
#define ND_ROUTER_ADVERT 134
117+
#define ND_NEIGHBOR_SOLICIT 135
118+
#define ND_NEIGHBOR_ADVERT 136
119+
#define ND_REDIRECT 137
120+
121+
struct nd_router_solicit /* router solicitation */
122+
{
123+
struct icmp6_hdr nd_rs_hdr;
124+
125+
/* could be followed by options */
126+
};
127+
128+
#define nd_rs_type nd_rs_hdr.icmp6_type
129+
#define nd_rs_code nd_rs_hdr.icmp6_code
130+
#define nd_rs_cksum nd_rs_hdr.icmp6_cksum
131+
#define nd_rs_reserved nd_rs_hdr.icmp6_data32[0]
132+
133+
struct nd_router_advert /* router advertisement */
134+
{
135+
struct icmp6_hdr nd_ra_hdr;
136+
uint32_t nd_ra_reachable; /* reachable time */
137+
uint32_t nd_ra_retransmit; /* retransmit timer */
138+
139+
/* could be followed by options */
140+
};
141+
142+
#define nd_ra_type nd_ra_hdr.icmp6_type
143+
#define nd_ra_code nd_ra_hdr.icmp6_code
144+
#define nd_ra_cksum nd_ra_hdr.icmp6_cksum
145+
#define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0]
146+
#define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1]
147+
#define ND_RA_FLAG_MANAGED 0x80
148+
#define ND_RA_FLAG_OTHER 0x40
149+
#define ND_RA_FLAG_HOME_AGENT 0x20
150+
#define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1]
151+
152+
struct nd_neighbor_solicit /* neighbor solicitation */
153+
{
154+
struct icmp6_hdr nd_ns_hdr;
155+
struct in6_addr nd_ns_target; /* target address */
156+
157+
/* could be followed by options */
158+
};
159+
160+
#define nd_ns_type nd_ns_hdr.icmp6_type
161+
#define nd_ns_code nd_ns_hdr.icmp6_code
162+
#define nd_ns_cksum nd_ns_hdr.icmp6_cksum
163+
#define nd_ns_reserved nd_ns_hdr.icmp6_data32[0]
164+
165+
struct nd_neighbor_advert /* neighbor advertisement */
166+
{
167+
struct icmp6_hdr nd_na_hdr;
168+
struct in6_addr nd_na_target; /* target address */
169+
170+
/* could be followed by options */
171+
};
172+
173+
#define nd_na_type nd_na_hdr.icmp6_type
174+
#define nd_na_code nd_na_hdr.icmp6_code
175+
#define nd_na_cksum nd_na_hdr.icmp6_cksum
176+
#define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0]
177+
#if __BYTE_ORDER == __BIG_ENDIAN
178+
#define ND_NA_FLAG_ROUTER 0x80000000
179+
#define ND_NA_FLAG_SOLICITED 0x40000000
180+
#define ND_NA_FLAG_OVERRIDE 0x20000000
181+
#else /* __BYTE_ORDER == __LITTLE_ENDIAN */
182+
#define ND_NA_FLAG_ROUTER 0x00000080
183+
#define ND_NA_FLAG_SOLICITED 0x00000040
184+
#define ND_NA_FLAG_OVERRIDE 0x00000020
185+
#endif
186+
187+
struct nd_redirect /* redirect */
188+
{
189+
struct icmp6_hdr nd_rd_hdr;
190+
struct in6_addr nd_rd_target; /* target address */
191+
struct in6_addr nd_rd_dst; /* destination address */
192+
193+
/* could be followed by options */
194+
};
195+
196+
#define nd_rd_type nd_rd_hdr.icmp6_type
197+
#define nd_rd_code nd_rd_hdr.icmp6_code
198+
#define nd_rd_cksum nd_rd_hdr.icmp6_cksum
199+
#define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
200+
201+
struct nd_opt_hdr /* Neighbor discovery option header */
202+
{
203+
uint8_t nd_opt_type;
204+
uint8_t nd_opt_len; /* in units of 8 octets */
205+
206+
/* followed by option specific data */
207+
};
208+
209+
#define ND_OPT_SOURCE_LINKADDR 1
210+
#define ND_OPT_TARGET_LINKADDR 2
211+
#define ND_OPT_PREFIX_INFORMATION 3
212+
#define ND_OPT_REDIRECTED_HEADER 4
213+
#define ND_OPT_MTU 5
214+
#define ND_OPT_RTR_ADV_INTERVAL 7
215+
#define ND_OPT_HOME_AGENT_INFO 8
216+
217+
struct nd_opt_prefix_info /* prefix information */
218+
{
219+
uint8_t nd_opt_pi_type;
220+
uint8_t nd_opt_pi_len;
221+
uint8_t nd_opt_pi_prefix_len;
222+
uint8_t nd_opt_pi_flags_reserved;
223+
uint32_t nd_opt_pi_valid_time;
224+
uint32_t nd_opt_pi_preferred_time;
225+
uint32_t nd_opt_pi_reserved2;
226+
struct in6_addr nd_opt_pi_prefix;
227+
};
228+
229+
#define ND_OPT_PI_FLAG_ONLINK 0x80
230+
#define ND_OPT_PI_FLAG_AUTO 0x40
231+
#define ND_OPT_PI_FLAG_RADDR 0x20
232+
233+
struct nd_opt_rd_hdr /* redirected header */
234+
{
235+
uint8_t nd_opt_rh_type;
236+
uint8_t nd_opt_rh_len;
237+
uint16_t nd_opt_rh_reserved1;
238+
uint32_t nd_opt_rh_reserved2;
239+
240+
/* followed by IP header and data */
241+
};
242+
243+
struct nd_opt_mtu /* MTU option */
244+
{
245+
uint8_t nd_opt_mtu_type;
246+
uint8_t nd_opt_mtu_len;
247+
uint16_t nd_opt_mtu_reserved;
248+
uint32_t nd_opt_mtu_mtu;
249+
};
250+
251+
struct mld_hdr
252+
{
253+
struct icmp6_hdr mld_icmp6_hdr;
254+
struct in6_addr mld_addr; /* multicast address */
255+
};
256+
257+
#define mld_type mld_icmp6_hdr.icmp6_type
258+
#define mld_code mld_icmp6_hdr.icmp6_code
259+
#define mld_cksum mld_icmp6_hdr.icmp6_cksum
260+
#define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0]
261+
#define mld_reserved mld_icmp6_hdr.icmp6_data16[1]
262+
263+
#define ICMP6_ROUTER_RENUMBERING 138
264+
265+
struct icmp6_router_renum /* router renumbering header */
266+
{
267+
struct icmp6_hdr rr_hdr;
268+
uint8_t rr_segnum;
269+
uint8_t rr_flags;
270+
uint16_t rr_maxdelay;
271+
uint32_t rr_reserved;
272+
};
273+
274+
#define rr_type rr_hdr.icmp6_type
275+
#define rr_code rr_hdr.icmp6_code
276+
#define rr_cksum rr_hdr.icmp6_cksum
277+
#define rr_seqnum rr_hdr.icmp6_data32[0]
278+
279+
/* Router renumbering flags */
280+
#define ICMP6_RR_FLAGS_TEST 0x80
281+
#define ICMP6_RR_FLAGS_REQRESULT 0x40
282+
#define ICMP6_RR_FLAGS_FORCEAPPLY 0x20
283+
#define ICMP6_RR_FLAGS_SPECSITE 0x10
284+
#define ICMP6_RR_FLAGS_PREVDONE 0x08
285+
286+
struct rr_pco_match /* match prefix part */
287+
{
288+
uint8_t rpm_code;
289+
uint8_t rpm_len;
290+
uint8_t rpm_ordinal;
291+
uint8_t rpm_matchlen;
292+
uint8_t rpm_minlen;
293+
uint8_t rpm_maxlen;
294+
uint16_t rpm_reserved;
295+
struct in6_addr rpm_prefix;
296+
};
297+
298+
/* PCO code values */
299+
#define RPM_PCO_ADD 1
300+
#define RPM_PCO_CHANGE 2
301+
#define RPM_PCO_SETGLOBAL 3
302+
303+
struct rr_pco_use /* use prefix part */
304+
{
305+
uint8_t rpu_uselen;
306+
uint8_t rpu_keeplen;
307+
uint8_t rpu_ramask;
308+
uint8_t rpu_raflags;
309+
uint32_t rpu_vltime;
310+
uint32_t rpu_pltime;
311+
uint32_t rpu_flags;
312+
struct in6_addr rpu_prefix;
313+
};
314+
315+
#define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x20
316+
#define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x10
317+
318+
#if __BYTE_ORDER == __BIG_ENDIAN
319+
# define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000
320+
# define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000
321+
#elif __BYTE_ORDER == __LITTLE_ENDIAN
322+
# define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80
323+
# define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40
324+
#endif
325+
326+
struct rr_result /* router renumbering result message */
327+
{
328+
uint16_t rrr_flags;
329+
uint8_t rrr_ordinal;
330+
uint8_t rrr_matchedlen;
331+
uint32_t rrr_ifid;
332+
struct in6_addr rrr_prefix;
333+
};
334+
335+
#if __BYTE_ORDER == __BIG_ENDIAN
336+
# define ICMP6_RR_RESULT_FLAGS_OOB 0x0002
337+
# define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001
338+
#elif __BYTE_ORDER == __LITTLE_ENDIAN
339+
# define ICMP6_RR_RESULT_FLAGS_OOB 0x0200
340+
# define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100
341+
#endif
342+
343+
/* Mobile IPv6 extension: Advertisement Interval. */
344+
345+
struct nd_opt_adv_interval
346+
{
347+
uint8_t nd_opt_adv_interval_type;
348+
uint8_t nd_opt_adv_interval_len;
349+
uint16_t nd_opt_adv_interval_reserved;
350+
uint32_t nd_opt_adv_interval_ival;
351+
};
352+
353+
/* Mobile IPv6 extension: Home Agent Info. */
354+
355+
struct nd_opt_home_agent_info
356+
{
357+
uint8_t nd_opt_home_agent_info_type;
358+
uint8_t nd_opt_home_agent_info_len;
359+
uint16_t nd_opt_home_agent_info_reserved;
360+
uint16_t nd_opt_home_agent_info_preference;
361+
uint16_t nd_opt_home_agent_info_lifetime;
362+
};
363+
364+
#endif /* netinet/icmpv6.h */

0 commit comments

Comments
 (0)