2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * $KAME: ip6_var.h,v 1.62 2001/05/03 14:51:48 itojun Exp $
33 * Copyright (c) 1982, 1986, 1993
34 * The Regents of the University of California. All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)ip_var.h 8.1 (Berkeley) 6/10/93
64 #ifndef _NETINET6_IP6_VAR_H_
65 #define _NETINET6_IP6_VAR_H_
68 * IP6 reassembly queue structure. Each fragment
69 * being reassembled is attached to one of these structures.
72 struct ip6asfrag *ip6q_down;
73 struct ip6asfrag *ip6q_up;
78 struct in6_addr ip6q_src, ip6q_dst;
79 struct ip6q *ip6q_next;
80 struct ip6q *ip6q_prev;
81 int ip6q_unfrglen; /* len of unfragmentable part */
85 int ip6q_nfrag; /* # of fragments */
86 struct label *ip6q_label;
90 struct ip6asfrag *ip6af_down;
91 struct ip6asfrag *ip6af_up;
93 int ip6af_offset; /* offset in ip6af_m to next header */
94 int ip6af_frglen; /* fragmentable part length */
95 int ip6af_off; /* fragment offset */
96 u_int16_t ip6af_mff; /* more fragment bit in frag off */
99 #define IP6_REASS_MBUF(ip6af) (*(struct mbuf **)&((ip6af)->ip6af_m))
102 * Structure attached to inpcb.in6p_moptions and
103 * passed to ip6_output when IPv6 multicast options are in use.
104 * This structure is lazy-allocated.
106 struct ip6_moptions {
107 struct ifnet *im6o_multicast_ifp; /* ifp for outgoing multicasts */
108 u_char im6o_multicast_hlim; /* hoplimit for outgoing multicasts */
109 u_char im6o_multicast_loop; /* 1 >= hear sends if a member */
110 u_short im6o_num_memberships; /* no. memberships this socket */
111 u_short im6o_max_memberships; /* max memberships this socket */
112 struct in6_multi **im6o_membership; /* group memberships */
113 struct in6_mfilter *im6o_mfilters; /* source filters */
117 * Control options for outgoing packets
120 /* Routing header related info */
121 struct ip6po_rhinfo {
122 struct ip6_rthdr *ip6po_rhi_rthdr; /* Routing header */
123 struct route_in6 ip6po_rhi_route; /* Route to the 1st hop */
125 #define ip6po_rthdr ip6po_rhinfo.ip6po_rhi_rthdr
126 #define ip6po_route ip6po_rhinfo.ip6po_rhi_route
128 /* Nexthop related info */
129 struct ip6po_nhinfo {
130 struct sockaddr *ip6po_nhi_nexthop;
131 struct route_in6 ip6po_nhi_route; /* Route to the nexthop */
133 #define ip6po_nexthop ip6po_nhinfo.ip6po_nhi_nexthop
134 #define ip6po_nextroute ip6po_nhinfo.ip6po_nhi_route
137 struct mbuf *ip6po_m; /* Pointer to mbuf storing the data */
138 int ip6po_hlim; /* Hoplimit for outgoing packets */
140 /* Outgoing IF/address information */
141 struct in6_pktinfo *ip6po_pktinfo;
143 /* Next-hop address information */
144 struct ip6po_nhinfo ip6po_nhinfo;
146 struct ip6_hbh *ip6po_hbh; /* Hop-by-Hop options header */
148 /* Destination options header (before a routing header) */
149 struct ip6_dest *ip6po_dest1;
151 /* Routing header related info. */
152 struct ip6po_rhinfo ip6po_rhinfo;
154 /* Destination options header (after a routing header) */
155 struct ip6_dest *ip6po_dest2;
157 int ip6po_tclass; /* traffic class */
159 int ip6po_minmtu; /* fragment vs PMTU discovery policy */
160 #define IP6PO_MINMTU_MCASTONLY -1 /* default; send at min MTU for multicast*/
161 #define IP6PO_MINMTU_DISABLE 0 /* always perform pmtu disc */
162 #define IP6PO_MINMTU_ALL 1 /* always send at min MTU */
164 int ip6po_prefer_tempaddr; /* whether temporary addresses are
165 preferred as source address */
166 #define IP6PO_TEMPADDR_SYSTEM -1 /* follow the system default */
167 #define IP6PO_TEMPADDR_NOTPREFER 0 /* not prefer temporary address */
168 #define IP6PO_TEMPADDR_PREFER 1 /* prefer temporary address */
171 #if 0 /* parameters in this block is obsolete. do not reuse the values. */
172 #define IP6PO_REACHCONF 0x01 /* upper-layer reachability confirmation. */
173 #define IP6PO_MINMTU 0x02 /* use minimum MTU (IPV6_USE_MIN_MTU) */
175 #define IP6PO_DONTFRAG 0x04 /* disable fragmentation (IPV6_DONTFRAG) */
176 #define IP6PO_USECOA 0x08 /* use care of address */
180 * Control options for incoming packets
184 u_quad_t ip6s_total; /* total packets received */
185 u_quad_t ip6s_tooshort; /* packet too short */
186 u_quad_t ip6s_toosmall; /* not enough data */
187 u_quad_t ip6s_fragments; /* fragments received */
188 u_quad_t ip6s_fragdropped; /* frags dropped(dups, out of space) */
189 u_quad_t ip6s_fragtimeout; /* fragments timed out */
190 u_quad_t ip6s_fragoverflow; /* fragments that exceeded limit */
191 u_quad_t ip6s_forward; /* packets forwarded */
192 u_quad_t ip6s_cantforward; /* packets rcvd for unreachable dest */
193 u_quad_t ip6s_redirectsent; /* packets forwarded on same net */
194 u_quad_t ip6s_delivered; /* datagrams delivered to upper level*/
195 u_quad_t ip6s_localout; /* total ip packets generated here */
196 u_quad_t ip6s_odropped; /* lost packets due to nobufs, etc. */
197 u_quad_t ip6s_reassembled; /* total packets reassembled ok */
198 u_quad_t ip6s_fragmented; /* datagrams successfully fragmented */
199 u_quad_t ip6s_ofragments; /* output fragments created */
200 u_quad_t ip6s_cantfrag; /* don't fragment flag was set, etc. */
201 u_quad_t ip6s_badoptions; /* error in option processing */
202 u_quad_t ip6s_noroute; /* packets discarded due to no route */
203 u_quad_t ip6s_badvers; /* ip6 version != 6 */
204 u_quad_t ip6s_rawout; /* total raw ip packets generated */
205 u_quad_t ip6s_badscope; /* scope error */
206 u_quad_t ip6s_notmember; /* don't join this multicast group */
207 #define IP6S_HDRCNT 256 /* headers count */
208 u_quad_t ip6s_nxthist[IP6S_HDRCNT]; /* next header history */
209 u_quad_t ip6s_m1; /* one mbuf */
210 #define IP6S_M2MMAX 32
211 u_quad_t ip6s_m2m[IP6S_M2MMAX]; /* two or more mbuf */
212 u_quad_t ip6s_mext1; /* one ext mbuf */
213 u_quad_t ip6s_mext2m; /* two or more ext mbuf */
214 u_quad_t ip6s_exthdrtoolong; /* ext hdr are not contiguous */
215 u_quad_t ip6s_nogif; /* no match gif found */
216 u_quad_t ip6s_toomanyhdr; /* discarded due to too many headers */
219 * statistics for improvement of the source address selection
221 * XXX: hardcoded 16 = # of ip6 multicast scope types + 1
223 #define IP6S_RULESMAX 16
224 #define IP6S_SCOPECNT 16
225 /* number of times that address selection fails */
226 u_quad_t ip6s_sources_none;
227 /* number of times that an address on the outgoing I/F is chosen */
228 u_quad_t ip6s_sources_sameif[IP6S_SCOPECNT];
229 /* number of times that an address on a non-outgoing I/F is chosen */
230 u_quad_t ip6s_sources_otherif[IP6S_SCOPECNT];
232 * number of times that an address that has the same scope
233 * from the destination is chosen.
235 u_quad_t ip6s_sources_samescope[IP6S_SCOPECNT];
237 * number of times that an address that has a different scope
238 * from the destination is chosen.
240 u_quad_t ip6s_sources_otherscope[IP6S_SCOPECNT];
241 /* number of times that a deprecated address is chosen */
242 u_quad_t ip6s_sources_deprecated[IP6S_SCOPECNT];
244 /* number of times that each rule of source selection is applied. */
245 u_quad_t ip6s_sources_rule[IP6S_RULESMAX];
249 #define IP6STAT_ADD(name, val) V_ip6stat.name += (val)
250 #define IP6STAT_SUB(name, val) V_ip6stat.name -= (val)
251 #define IP6STAT_INC(name) IP6STAT_ADD(name, 1)
252 #define IP6STAT_DEC(name) IP6STAT_SUB(name, 1)
257 * IPv6 onion peeling state.
258 * it will be initialized when we come into ip6_input().
259 * XXX do not make it a kitchen sink!
262 u_int32_t ip6a_flags;
263 #define IP6A_SWAP 0x01 /* swapped home/care-of on packet */
264 #define IP6A_HASEEN 0x02 /* HA was present */
265 #define IP6A_BRUID 0x04 /* BR Unique Identifier was present */
266 #define IP6A_RTALERTSEEN 0x08 /* rtalert present */
269 struct in6_addr ip6a_careof; /* care-of address of the peer */
270 struct in6_addr ip6a_home; /* home address of the peer */
271 u_int16_t ip6a_bruid; /* BR unique identifier */
274 struct in6_ifaddr *ip6a_dstia6; /* my ifaddr that matches ip6_dst */
277 u_int16_t ip6a_rtalert; /* rtalert option value */
280 * decapsulation history will be here.
281 * with IPsec it may not be accurate.
287 /* flags passed to ip6_output as last parameter */
288 #define IPV6_UNSPECSRC 0x01 /* allow :: as the source address */
289 #define IPV6_FORWARDING 0x02 /* most of IPv6 header exists */
290 #define IPV6_MINMTU 0x04 /* use minimum MTU (IPV6_USE_MIN_MTU) */
292 #define M_IP6_NEXTHOP M_PROTO7 /* explicit ip nexthop */
294 #ifdef __NO_STRICT_ALIGNMENT
295 #define IP6_HDR_ALIGNED_P(ip) 1
297 #define IP6_HDR_ALIGNED_P(ip) ((((intptr_t) (ip)) & 3) == 0)
300 VNET_DECLARE(struct ip6stat, ip6stat); /* statistics */
301 VNET_DECLARE(int, ip6_defhlim); /* default hop limit */
302 VNET_DECLARE(int, ip6_defmcasthlim); /* default multicast hop limit */
303 VNET_DECLARE(int, ip6_forwarding); /* act as router? */
304 VNET_DECLARE(int, ip6_use_deprecated); /* allow deprecated addr as source */
305 VNET_DECLARE(int, ip6_rr_prune); /* router renumbering prefix
306 * walk list every 5 sec. */
307 VNET_DECLARE(int, ip6_mcast_pmtu); /* enable pMTU discovery for multicast? */
308 VNET_DECLARE(int, ip6_v6only);
309 #define V_ip6stat VNET(ip6stat)
310 #define V_ip6_defhlim VNET(ip6_defhlim)
311 #define V_ip6_defmcasthlim VNET(ip6_defmcasthlim)
312 #define V_ip6_forwarding VNET(ip6_forwarding)
313 #define V_ip6_use_deprecated VNET(ip6_use_deprecated)
314 #define V_ip6_rr_prune VNET(ip6_rr_prune)
315 #define V_ip6_mcast_pmtu VNET(ip6_mcast_pmtu)
316 #define V_ip6_v6only VNET(ip6_v6only)
318 VNET_DECLARE(struct socket *, ip6_mrouter); /* multicast routing daemon */
319 VNET_DECLARE(int, ip6_sendredirects); /* send IP redirects when forwarding? */
320 VNET_DECLARE(int, ip6_maxfragpackets); /* Maximum packets in reassembly
322 VNET_DECLARE(int, ip6_maxfrags); /* Maximum fragments in reassembly
324 VNET_DECLARE(int, ip6_accept_rtadv); /* Acts as a host not a router */
325 VNET_DECLARE(int, ip6_no_radr); /* No defroute from RA */
326 VNET_DECLARE(int, ip6_norbit_raif); /* Disable R-bit in NA on RA
328 VNET_DECLARE(int, ip6_rfc6204w3); /* Accept defroute from RA even when
329 forwarding enabled */
330 VNET_DECLARE(int, ip6_keepfaith); /* Firewall Aided Internet Translator */
331 VNET_DECLARE(int, ip6_log_interval);
332 VNET_DECLARE(time_t, ip6_log_time);
333 VNET_DECLARE(int, ip6_hdrnestlimit); /* upper limit of # of extension
335 VNET_DECLARE(int, ip6_dad_count); /* DupAddrDetectionTransmits */
336 #define V_ip6_mrouter VNET(ip6_mrouter)
337 #define V_ip6_sendredirects VNET(ip6_sendredirects)
338 #define V_ip6_maxfragpackets VNET(ip6_maxfragpackets)
339 #define V_ip6_maxfrags VNET(ip6_maxfrags)
340 #define V_ip6_accept_rtadv VNET(ip6_accept_rtadv)
341 #define V_ip6_no_radr VNET(ip6_no_radr)
342 #define V_ip6_norbit_raif VNET(ip6_norbit_raif)
343 #define V_ip6_rfc6204w3 VNET(ip6_rfc6204w3)
344 #define V_ip6_keepfaith VNET(ip6_keepfaith)
345 #define V_ip6_log_interval VNET(ip6_log_interval)
346 #define V_ip6_log_time VNET(ip6_log_time)
347 #define V_ip6_hdrnestlimit VNET(ip6_hdrnestlimit)
348 #define V_ip6_dad_count VNET(ip6_dad_count)
350 VNET_DECLARE(int, ip6_auto_flowlabel);
351 VNET_DECLARE(int, ip6_auto_linklocal);
352 #define V_ip6_auto_flowlabel VNET(ip6_auto_flowlabel)
353 #define V_ip6_auto_linklocal VNET(ip6_auto_linklocal)
355 VNET_DECLARE(int, ip6_use_tempaddr); /* Whether to use temporary addresses */
356 VNET_DECLARE(int, ip6_prefer_tempaddr); /* Whether to prefer temporary
357 * addresses in the source address
359 #define V_ip6_use_tempaddr VNET(ip6_use_tempaddr)
360 #define V_ip6_prefer_tempaddr VNET(ip6_prefer_tempaddr)
362 VNET_DECLARE(int, ip6_use_defzone); /* Whether to use the default scope
363 * zone when unspecified */
364 #define V_ip6_use_defzone VNET(ip6_use_defzone)
366 VNET_DECLARE (struct pfil_head, inet6_pfil_hook); /* packet filter hooks */
367 #define V_inet6_pfil_hook VNET(inet6_pfil_hook)
369 VNET_DECLARE(int, ip6stealth);
370 #define V_ip6stealth VNET(ip6stealth)
373 extern struct pr_usrreqs rip6_usrreqs;
378 int icmp6_ctloutput(struct socket *, struct sockopt *sopt);
383 void ip6_destroy(void);
385 int ip6proto_register(short);
386 int ip6proto_unregister(short);
388 void ip6_input(struct mbuf *);
389 struct in6_ifaddr *ip6_getdstifaddr(struct mbuf *);
390 void ip6_freepcbopts(struct ip6_pktopts *);
392 int ip6_unknown_opt(u_int8_t *, struct mbuf *, int);
393 char * ip6_get_prevhdr(struct mbuf *, int);
394 int ip6_nexthdr(struct mbuf *, int, int, int *);
395 int ip6_lasthdr(struct mbuf *, int, int, int *);
398 struct ip6aux *ip6_findaux(struct mbuf *);
401 extern int (*ip6_mforward)(struct ip6_hdr *, struct ifnet *,
404 int ip6_process_hopopts(struct mbuf *, u_int8_t *, int, u_int32_t *,
406 struct mbuf **ip6_savecontrol_v4(struct inpcb *, struct mbuf *,
407 struct mbuf **, int *);
408 void ip6_savecontrol(struct inpcb *, struct mbuf *, struct mbuf **);
409 void ip6_notify_pmtu(struct inpcb *, struct sockaddr_in6 *,
411 int ip6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
413 void ip6_forward(struct mbuf *, int);
415 void ip6_mloopback(struct ifnet *, struct mbuf *, struct sockaddr_in6 *);
416 int ip6_output(struct mbuf *, struct ip6_pktopts *,
419 struct ip6_moptions *, struct ifnet **,
421 int ip6_ctloutput(struct socket *, struct sockopt *);
422 int ip6_raw_ctloutput(struct socket *, struct sockopt *);
423 void ip6_initpktopts(struct ip6_pktopts *);
424 int ip6_setpktopts(struct mbuf *, struct ip6_pktopts *,
425 struct ip6_pktopts *, struct ucred *, int);
426 void ip6_clearpktopts(struct ip6_pktopts *, int);
427 struct ip6_pktopts *ip6_copypktopts(struct ip6_pktopts *, int);
428 int ip6_optlen(struct inpcb *);
430 int route6_input(struct mbuf **, int *, int);
432 void frag6_init(void);
433 int frag6_input(struct mbuf **, int *, int);
434 void frag6_slowtimo(void);
435 void frag6_drain(void);
437 void rip6_init(void);
438 int rip6_input(struct mbuf **, int *, int);
439 void rip6_ctlinput(int, struct sockaddr *, void *);
440 int rip6_ctloutput(struct socket *, struct sockopt *);
441 int rip6_output(struct mbuf *, ...);
442 int rip6_usrreq(struct socket *,
443 int, struct mbuf *, struct mbuf *, struct mbuf *, struct thread *);
445 int dest6_input(struct mbuf **, int *, int);
446 int none_input(struct mbuf **, int *, int);
448 int in6_selectsrc(struct sockaddr_in6 *, struct ip6_pktopts *,
449 struct inpcb *inp, struct route_in6 *, struct ucred *cred,
450 struct ifnet **, struct in6_addr *);
451 int in6_selectroute(struct sockaddr_in6 *, struct ip6_pktopts *,
452 struct ip6_moptions *, struct route_in6 *, struct ifnet **,
454 int in6_selectroute_fib(struct sockaddr_in6 *, struct ip6_pktopts *,
455 struct ip6_moptions *, struct route_in6 *, struct ifnet **,
456 struct rtentry **, u_int);
457 u_int32_t ip6_randomid(void);
458 u_int32_t ip6_randomflowlabel(void);
461 #endif /* !_NETINET6_IP6_VAR_H_ */