1 /* Copyright (C) 1991,92,93,94,95,96,97,2000 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3 
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8 
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18 
19 /*
20  * $Id: $
21  * $DateTime: $
22  * $Change: $
23  */
24 
25 #ifndef _NETINET_ICMP6_H
26 #define _NETINET_ICMP6_H 1
27 
28 #include <inttypes.h>
29 #include <string.h>
30 #include <sys/types.h>
31 #include <netinet/in.h>
32 
33 #define ICMP6_FILTER 1
34 
35 #define ICMP6_FILTER_BLOCK		1
36 #define ICMP6_FILTER_PASS		2
37 #define ICMP6_FILTER_BLOCKOTHERS	3
38 #define ICMP6_FILTER_PASSONLY		4
39 
40 struct icmp6_filter
41   {
42     uint32_t data[8];
43   };
44 
45 struct icmp6_hdr
46   {
47     uint8_t     icmp6_type;   /* type field */
48     uint8_t     icmp6_code;   /* code field */
49     uint16_t    icmp6_cksum;  /* checksum field */
50     union
51       {
52 	uint32_t  icmp6_un_data32[1]; /* type-specific field */
53 	uint16_t  icmp6_un_data16[2]; /* type-specific field */
54 	uint8_t   icmp6_un_data8[4];  /* type-specific field */
55       } icmp6_dataun;
56   };
57 
58 #define icmp6_data32    icmp6_dataun.icmp6_un_data32
59 #define icmp6_data16    icmp6_dataun.icmp6_un_data16
60 #define icmp6_data8     icmp6_dataun.icmp6_un_data8
61 #define icmp6_pptr      icmp6_data32[0]  /* parameter prob */
62 #define icmp6_mtu       icmp6_data32[0]  /* packet too big */
63 #define icmp6_id        icmp6_data16[0]  /* echo request/reply */
64 #define icmp6_seq       icmp6_data16[1]  /* echo request/reply */
65 #define icmp6_maxdelay  icmp6_data16[0]  /* mcast group membership */
66 
67 #define ICMP6_DST_UNREACH             1
68 #define ICMP6_PACKET_TOO_BIG          2
69 #define ICMP6_TIME_EXCEEDED           3
70 #define ICMP6_PARAM_PROB              4
71 
72 #define ICMP6_INFOMSG_MASK  0x80    /* all informational messages */
73 
74 #define ICMP6_ECHO_REQUEST          128
75 #define ICMP6_ECHO_REPLY            129
76 #define ICMP6_MEMBERSHIP_QUERY      130
77 #define ICMP6_MEMBERSHIP_REPORT     131
78 #define ICMP6_MEMBERSHIP_REDUCTION  132
79 
80 #define ICMP6_DST_UNREACH_NOROUTE     0 /* no route to destination */
81 #define ICMP6_DST_UNREACH_ADMIN       1 /* communication with destination */
82                                         /* administratively prohibited */
83 #define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /* not a neighbor */
84 #define ICMP6_DST_UNREACH_BEYONDSCOPE 2	/* beyond scope of source address */
85 #define ICMP6_DST_UNREACH_ADDR        3 /* address unreachable */
86 #define ICMP6_DST_UNREACH_NOPORT      4 /* bad port */
87 
88 #define ICMP6_TIME_EXCEED_TRANSIT     0 /* Hop Limit == 0 in transit */
89 #define ICMP6_TIME_EXCEED_REASSEMBLY  1 /* Reassembly time out */
90 
91 #define ICMP6_PARAMPROB_HEADER        0 /* erroneous header field */
92 #define ICMP6_PARAMPROB_NEXTHEADER    1 /* unrecognized Next Header */
93 #define ICMP6_PARAMPROB_OPTION        2 /* unrecognized IPv6 option */
94 
95 #define ICMP6_FILTER_WILLPASS(type, filterp) \
96 	((((filterp)->data[(type) >> 5]) & (1 << ((type) & 31))) == 0)
97 
98 #define ICMP6_FILTER_WILLBLOCK(type, filterp) \
99 	((((filterp)->data[(type) >> 5]) & (1 << ((type) & 31))) != 0)
100 
101 #define ICMP6_FILTER_SETPASS(type, filterp) \
102 	((((filterp)->data[(type) >> 5]) &= ~(1 << ((type) & 31))))
103 
104 #define ICMP6_FILTER_SETBLOCK(type, filterp) \
105 	((((filterp)->data[(type) >> 5]) |=  (1 << ((type) & 31))))
106 
107 #define ICMP6_FILTER_SETPASSALL(filterp) \
108 	memset (filterp, 0, sizeof (struct icmp6_filter));
109 
110 #define ICMP6_FILTER_SETBLOCKALL(filterp) \
111 	memset (filterp, 0xFF, sizeof (struct icmp6_filter));
112 
113 #define ND_ROUTER_SOLICIT           133
114 #define ND_ROUTER_ADVERT            134
115 #define ND_NEIGHBOR_SOLICIT         135
116 #define ND_NEIGHBOR_ADVERT          136
117 #define ND_REDIRECT                 137
118 
119 struct nd_router_solicit      /* router solicitation */
120   {
121     struct icmp6_hdr  nd_rs_hdr;
122     /* could be followed by options */
123   };
124 
125 #define nd_rs_type               nd_rs_hdr.icmp6_type
126 #define nd_rs_code               nd_rs_hdr.icmp6_code
127 #define nd_rs_cksum              nd_rs_hdr.icmp6_cksum
128 #define nd_rs_reserved           nd_rs_hdr.icmp6_data32[0]
129 
130 struct nd_router_advert       /* router advertisement */
131   {
132     struct icmp6_hdr  nd_ra_hdr;
133     uint32_t   nd_ra_reachable;   /* reachable time */
134     uint32_t   nd_ra_retransmit;  /* retransmit timer */
135     /* could be followed by options */
136   };
137 
138 #define nd_ra_type               nd_ra_hdr.icmp6_type
139 #define nd_ra_code               nd_ra_hdr.icmp6_code
140 #define nd_ra_cksum              nd_ra_hdr.icmp6_cksum
141 #define nd_ra_curhoplimit        nd_ra_hdr.icmp6_data8[0]
142 #define nd_ra_flags_reserved     nd_ra_hdr.icmp6_data8[1]
143 #define ND_RA_FLAG_MANAGED       0x80
144 #define ND_RA_FLAG_OTHER         0x40
145 #define ND_RA_FLAG_HOME_AGENT    0x20
146 #define nd_ra_router_lifetime    nd_ra_hdr.icmp6_data16[1]
147 
148 struct nd_neighbor_solicit    /* neighbor solicitation */
149   {
150     struct icmp6_hdr  nd_ns_hdr;
151     struct in6_addr   nd_ns_target; /* target address */
152     /* could be followed by options */
153   };
154 
155 #define nd_ns_type               nd_ns_hdr.icmp6_type
156 #define nd_ns_code               nd_ns_hdr.icmp6_code
157 #define nd_ns_cksum              nd_ns_hdr.icmp6_cksum
158 #define nd_ns_reserved           nd_ns_hdr.icmp6_data32[0]
159 
160 struct nd_neighbor_advert     /* neighbor advertisement */
161   {
162     struct icmp6_hdr  nd_na_hdr;
163     struct in6_addr   nd_na_target; /* target address */
164     /* could be followed by options */
165   };
166 
167 #define nd_na_type               nd_na_hdr.icmp6_type
168 #define nd_na_code               nd_na_hdr.icmp6_code
169 #define nd_na_cksum              nd_na_hdr.icmp6_cksum
170 #define nd_na_flags_reserved     nd_na_hdr.icmp6_data32[0]
171 #if     BYTE_ORDER == BIG_ENDIAN
172 #define ND_NA_FLAG_ROUTER        0x80000000
173 #define ND_NA_FLAG_SOLICITED     0x40000000
174 #define ND_NA_FLAG_OVERRIDE      0x20000000
175 #else   /* BYTE_ORDER == LITTLE_ENDIAN */
176 #define ND_NA_FLAG_ROUTER        0x00000080
177 #define ND_NA_FLAG_SOLICITED     0x00000040
178 #define ND_NA_FLAG_OVERRIDE      0x00000020
179 #endif
180 
181 struct nd_redirect            /* redirect */
182   {
183     struct icmp6_hdr  nd_rd_hdr;
184     struct in6_addr   nd_rd_target; /* target address */
185     struct in6_addr   nd_rd_dst;    /* destination address */
186     /* could be followed by options */
187   };
188 
189 #define nd_rd_type               nd_rd_hdr.icmp6_type
190 #define nd_rd_code               nd_rd_hdr.icmp6_code
191 #define nd_rd_cksum              nd_rd_hdr.icmp6_cksum
192 #define nd_rd_reserved           nd_rd_hdr.icmp6_data32[0]
193 
194 struct nd_opt_hdr             /* Neighbor discovery option header */
195   {
196     uint8_t  nd_opt_type;
197     uint8_t  nd_opt_len;        /* in units of 8 octets */
198     /* followed by option specific data */
199   };
200 
201 #define  ND_OPT_SOURCE_LINKADDR       1
202 #define  ND_OPT_TARGET_LINKADDR       2
203 #define  ND_OPT_PREFIX_INFORMATION    3
204 #define  ND_OPT_REDIRECTED_HEADER     4
205 #define  ND_OPT_MTU                   5
206 #define  ND_OPT_RTR_ADV_INTERVAL      7
207 #define  ND_OPT_HOME_AGENT_INFO       8
208 
209 struct nd_opt_prefix_info     /* prefix information */
210   {
211     uint8_t   nd_opt_pi_type;
212     uint8_t   nd_opt_pi_len;
213     uint8_t   nd_opt_pi_prefix_len;
214     uint8_t   nd_opt_pi_flags_reserved;
215     uint32_t  nd_opt_pi_valid_time;
216     uint32_t  nd_opt_pi_preferred_time;
217     uint32_t  nd_opt_pi_reserved2;
218     struct in6_addr  nd_opt_pi_prefix;
219   };
220 
221 #define ND_OPT_PI_FLAG_ONLINK        0x80
222 #define ND_OPT_PI_FLAG_AUTO          0x40
223 #define ND_OPT_PI_FLAG_RADDR         0x20
224 
225 struct nd_opt_rd_hdr          /* redirected header */
226   {
227     uint8_t   nd_opt_rh_type;
228     uint8_t   nd_opt_rh_len;
229     uint16_t  nd_opt_rh_reserved1;
230     uint32_t  nd_opt_rh_reserved2;
231     /* followed by IP header and data */
232   };
233 
234 struct nd_opt_mtu             /* MTU option */
235   {
236     uint8_t   nd_opt_mtu_type;
237     uint8_t   nd_opt_mtu_len;
238     uint16_t  nd_opt_mtu_reserved;
239     uint32_t  nd_opt_mtu_mtu;
240   };
241 
242 /* Mobile IPv6 extension: Advertisement Interval.  */
243 struct nd_opt_adv_interval
244   {
245     uint8_t   nd_opt_adv_interval_type;
246     uint8_t   nd_opt_adv_interval_len;
247     uint16_t  nd_opt_adv_interval_reserved;
248     uint32_t  nd_opt_adv_interval_ival;
249   };
250 
251 /* Mobile IPv6 extension: Home Agent Info.  */
252 struct nd_opt_home_agent_info
253   {
254     uint8_t   nd_opt_home_agent_info_type;
255     uint8_t   nd_opt_home_agent_info_len;
256     uint16_t  nd_opt_home_agent_info_reserved;
257     int16_t   nd_opt_home_agent_info_preference;
258     uint16_t  nd_opt_home_agent_info_lifetime;
259   };
260 
261 #endif /* netinet/icmpv6.h */
262