xref: /freebsd/sys/netinet6/ip6_var.h (revision d6b92ffa)
1 /*-
2  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
16  *
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
27  * SUCH DAMAGE.
28  *
29  *	$KAME: ip6_var.h,v 1.62 2001/05/03 14:51:48 itojun Exp $
30  */
31 
32 /*-
33  * Copyright (c) 1982, 1986, 1993
34  *	The Regents of the University of California.  All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
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  * 3. 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.
47  *
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
58  * SUCH DAMAGE.
59  *
60  *	@(#)ip_var.h	8.1 (Berkeley) 6/10/93
61  * $FreeBSD$
62  */
63 
64 #ifndef _NETINET6_IP6_VAR_H_
65 #define _NETINET6_IP6_VAR_H_
66 
67 /*
68  * IP6 reassembly queue structure.  Each fragment
69  * being reassembled is attached to one of these structures.
70  */
71 struct	ip6q {
72 	struct ip6asfrag *ip6q_down;
73 	struct ip6asfrag *ip6q_up;
74 	u_int32_t	ip6q_ident;
75 	u_int8_t	ip6q_nxt;
76 	u_int8_t	ip6q_ecn;
77 	u_int8_t	ip6q_ttl;
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 */
82 #ifdef notyet
83 	u_char		*ip6q_nxtp;
84 #endif
85 	int		ip6q_nfrag;	/* # of fragments */
86 	struct label	*ip6q_label;
87 };
88 
89 struct	ip6asfrag {
90 	struct ip6asfrag *ip6af_down;
91 	struct ip6asfrag *ip6af_up;
92 	struct mbuf	*ip6af_m;
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 */
97 };
98 
99 #define IP6_REASS_MBUF(ip6af) (*(struct mbuf **)&((ip6af)->ip6af_m))
100 
101 /*
102  * IP6 reinjecting structure.
103  */
104 struct ip6_direct_ctx {
105 	uint32_t	ip6dc_nxt;	/* next header to process */
106 	uint32_t	ip6dc_off;	/* offset to next header */
107 };
108 
109 /*
110  * Structure attached to inpcb.in6p_moptions and
111  * passed to ip6_output when IPv6 multicast options are in use.
112  * This structure is lazy-allocated.
113  */
114 struct ip6_moptions {
115 	struct	ifnet *im6o_multicast_ifp; /* ifp for outgoing multicasts */
116 	u_char	im6o_multicast_hlim;	/* hoplimit for outgoing multicasts */
117 	u_char	im6o_multicast_loop;	/* 1 >= hear sends if a member */
118 	u_short	im6o_num_memberships;	/* no. memberships this socket */
119 	u_short	im6o_max_memberships;	/* max memberships this socket */
120 	struct	in6_multi **im6o_membership;	/* group memberships */
121 	struct	in6_mfilter *im6o_mfilters;	/* source filters */
122 };
123 
124 /*
125  * Control options for outgoing packets
126  */
127 
128 /* Routing header related info */
129 struct	ip6po_rhinfo {
130 	struct	ip6_rthdr *ip6po_rhi_rthdr; /* Routing header */
131 	struct	route_in6 ip6po_rhi_route; /* Route to the 1st hop */
132 };
133 #define ip6po_rthdr	ip6po_rhinfo.ip6po_rhi_rthdr
134 #define ip6po_route	ip6po_rhinfo.ip6po_rhi_route
135 
136 /* Nexthop related info */
137 struct	ip6po_nhinfo {
138 	struct	sockaddr *ip6po_nhi_nexthop;
139 	struct	route_in6 ip6po_nhi_route; /* Route to the nexthop */
140 };
141 #define ip6po_nexthop	ip6po_nhinfo.ip6po_nhi_nexthop
142 #define ip6po_nextroute	ip6po_nhinfo.ip6po_nhi_route
143 
144 struct	ip6_pktopts {
145 	struct	mbuf *ip6po_m;	/* Pointer to mbuf storing the data */
146 	int	ip6po_hlim;	/* Hoplimit for outgoing packets */
147 
148 	/* Outgoing IF/address information */
149 	struct	in6_pktinfo *ip6po_pktinfo;
150 
151 	/* Next-hop address information */
152 	struct	ip6po_nhinfo ip6po_nhinfo;
153 
154 	struct	ip6_hbh *ip6po_hbh; /* Hop-by-Hop options header */
155 
156 	/* Destination options header (before a routing header) */
157 	struct	ip6_dest *ip6po_dest1;
158 
159 	/* Routing header related info. */
160 	struct	ip6po_rhinfo ip6po_rhinfo;
161 
162 	/* Destination options header (after a routing header) */
163 	struct	ip6_dest *ip6po_dest2;
164 
165 	int	ip6po_tclass;	/* traffic class */
166 
167 	int	ip6po_minmtu;  /* fragment vs PMTU discovery policy */
168 #define IP6PO_MINMTU_MCASTONLY	-1 /* default; send at min MTU for multicast*/
169 #define IP6PO_MINMTU_DISABLE	 0 /* always perform pmtu disc */
170 #define IP6PO_MINMTU_ALL	 1 /* always send at min MTU */
171 
172 	int	ip6po_prefer_tempaddr;  /* whether temporary addresses are
173 					   preferred as source address */
174 #define IP6PO_TEMPADDR_SYSTEM	-1 /* follow the system default */
175 #define IP6PO_TEMPADDR_NOTPREFER 0 /* not prefer temporary address */
176 #define IP6PO_TEMPADDR_PREFER	 1 /* prefer temporary address */
177 
178 	int ip6po_flags;
179 #if 0	/* parameters in this block is obsolete. do not reuse the values. */
180 #define IP6PO_REACHCONF	0x01	/* upper-layer reachability confirmation. */
181 #define IP6PO_MINMTU	0x02	/* use minimum MTU (IPV6_USE_MIN_MTU) */
182 #endif
183 #define IP6PO_DONTFRAG	0x04	/* disable fragmentation (IPV6_DONTFRAG) */
184 #define IP6PO_USECOA	0x08	/* use care of address */
185 };
186 
187 /*
188  * Control options for incoming packets
189  */
190 
191 struct	ip6stat {
192 	uint64_t ip6s_total;		/* total packets received */
193 	uint64_t ip6s_tooshort;		/* packet too short */
194 	uint64_t ip6s_toosmall;		/* not enough data */
195 	uint64_t ip6s_fragments;	/* fragments received */
196 	uint64_t ip6s_fragdropped;	/* frags dropped(dups, out of space) */
197 	uint64_t ip6s_fragtimeout;	/* fragments timed out */
198 	uint64_t ip6s_fragoverflow;	/* fragments that exceeded limit */
199 	uint64_t ip6s_forward;		/* packets forwarded */
200 	uint64_t ip6s_cantforward;	/* packets rcvd for unreachable dest */
201 	uint64_t ip6s_redirectsent;	/* packets forwarded on same net */
202 	uint64_t ip6s_delivered;	/* datagrams delivered to upper level*/
203 	uint64_t ip6s_localout;		/* total ip packets generated here */
204 	uint64_t ip6s_odropped;		/* lost packets due to nobufs, etc. */
205 	uint64_t ip6s_reassembled;	/* total packets reassembled ok */
206 	uint64_t ip6s_fragmented;	/* datagrams successfully fragmented */
207 	uint64_t ip6s_ofragments;	/* output fragments created */
208 	uint64_t ip6s_cantfrag;		/* don't fragment flag was set, etc. */
209 	uint64_t ip6s_badoptions;	/* error in option processing */
210 	uint64_t ip6s_noroute;		/* packets discarded due to no route */
211 	uint64_t ip6s_badvers;		/* ip6 version != 6 */
212 	uint64_t ip6s_rawout;		/* total raw ip packets generated */
213 	uint64_t ip6s_badscope;		/* scope error */
214 	uint64_t ip6s_notmember;	/* don't join this multicast group */
215 #define	IP6S_HDRCNT		256	/* headers count */
216 	uint64_t ip6s_nxthist[IP6S_HDRCNT]; /* next header history */
217 	uint64_t ip6s_m1;		/* one mbuf */
218 #define	IP6S_M2MMAX		32
219 	uint64_t ip6s_m2m[IP6S_M2MMAX];	/* two or more mbuf */
220 	uint64_t ip6s_mext1;		/* one ext mbuf */
221 	uint64_t ip6s_mext2m;		/* two or more ext mbuf */
222 	uint64_t ip6s_exthdrtoolong;	/* ext hdr are not contiguous */
223 	uint64_t ip6s_nogif;		/* no match gif found */
224 	uint64_t ip6s_toomanyhdr;	/* discarded due to too many headers */
225 
226 	/*
227 	 * statistics for improvement of the source address selection
228 	 * algorithm:
229 	 * XXX: hardcoded 16 = # of ip6 multicast scope types + 1
230 	 */
231 #define	IP6S_RULESMAX		16
232 #define	IP6S_SCOPECNT		16
233 	/* number of times that address selection fails */
234 	uint64_t ip6s_sources_none;
235 	/* number of times that an address on the outgoing I/F is chosen */
236 	uint64_t ip6s_sources_sameif[IP6S_SCOPECNT];
237 	/* number of times that an address on a non-outgoing I/F is chosen */
238 	uint64_t ip6s_sources_otherif[IP6S_SCOPECNT];
239 	/*
240 	 * number of times that an address that has the same scope
241 	 * from the destination is chosen.
242 	 */
243 	uint64_t ip6s_sources_samescope[IP6S_SCOPECNT];
244 	/*
245 	 * number of times that an address that has a different scope
246 	 * from the destination is chosen.
247 	 */
248 	uint64_t ip6s_sources_otherscope[IP6S_SCOPECNT];
249 	/* number of times that a deprecated address is chosen */
250 	uint64_t ip6s_sources_deprecated[IP6S_SCOPECNT];
251 
252 	/* number of times that each rule of source selection is applied. */
253 	uint64_t ip6s_sources_rule[IP6S_RULESMAX];
254 };
255 
256 #ifdef _KERNEL
257 #include <sys/counter.h>
258 
259 VNET_PCPUSTAT_DECLARE(struct ip6stat, ip6stat);
260 #define	IP6STAT_ADD(name, val)	\
261     VNET_PCPUSTAT_ADD(struct ip6stat, ip6stat, name, (val))
262 #define	IP6STAT_SUB(name, val)	IP6STAT_ADD(name, -(val))
263 #define	IP6STAT_INC(name)	IP6STAT_ADD(name, 1)
264 #define	IP6STAT_DEC(name)	IP6STAT_SUB(name, 1)
265 #endif
266 
267 #ifdef _KERNEL
268 /* flags passed to ip6_output as last parameter */
269 #define	IPV6_UNSPECSRC		0x01	/* allow :: as the source address */
270 #define	IPV6_FORWARDING		0x02	/* most of IPv6 header exists */
271 #define	IPV6_MINMTU		0x04	/* use minimum MTU (IPV6_USE_MIN_MTU) */
272 
273 #ifdef __NO_STRICT_ALIGNMENT
274 #define IP6_HDR_ALIGNED_P(ip)	1
275 #else
276 #define IP6_HDR_ALIGNED_P(ip)	((((intptr_t) (ip)) & 3) == 0)
277 #endif
278 
279 VNET_DECLARE(int, ip6_defhlim);		/* default hop limit */
280 VNET_DECLARE(int, ip6_defmcasthlim);	/* default multicast hop limit */
281 VNET_DECLARE(int, ip6_forwarding);	/* act as router? */
282 VNET_DECLARE(int, ip6_use_deprecated);	/* allow deprecated addr as source */
283 VNET_DECLARE(int, ip6_rr_prune);	/* router renumbering prefix
284 					 * walk list every 5 sec.    */
285 VNET_DECLARE(int, ip6_mcast_pmtu);	/* enable pMTU discovery for multicast? */
286 VNET_DECLARE(int, ip6_v6only);
287 #define	V_ip6_defhlim			VNET(ip6_defhlim)
288 #define	V_ip6_defmcasthlim		VNET(ip6_defmcasthlim)
289 #define	V_ip6_forwarding		VNET(ip6_forwarding)
290 #define	V_ip6_use_deprecated		VNET(ip6_use_deprecated)
291 #define	V_ip6_rr_prune			VNET(ip6_rr_prune)
292 #define	V_ip6_mcast_pmtu		VNET(ip6_mcast_pmtu)
293 #define	V_ip6_v6only			VNET(ip6_v6only)
294 
295 VNET_DECLARE(struct socket *, ip6_mrouter);	/* multicast routing daemon */
296 VNET_DECLARE(int, ip6_sendredirects);	/* send IP redirects when forwarding? */
297 VNET_DECLARE(int, ip6_maxfragpackets);	/* Maximum packets in reassembly
298 					 * queue */
299 VNET_DECLARE(int, ip6_maxfrags);	/* Maximum fragments in reassembly
300 					 * queue */
301 VNET_DECLARE(int, ip6_accept_rtadv);	/* Acts as a host not a router */
302 VNET_DECLARE(int, ip6_no_radr);		/* No defroute from RA */
303 VNET_DECLARE(int, ip6_norbit_raif);	/* Disable R-bit in NA on RA
304 					 * receiving IF. */
305 VNET_DECLARE(int, ip6_rfc6204w3);	/* Accept defroute from RA even when
306 					   forwarding enabled */
307 VNET_DECLARE(int, ip6_log_interval);
308 VNET_DECLARE(time_t, ip6_log_time);
309 VNET_DECLARE(int, ip6_hdrnestlimit);	/* upper limit of # of extension
310 					 * headers */
311 VNET_DECLARE(int, ip6_dad_count);	/* DupAddrDetectionTransmits */
312 #define	V_ip6_mrouter			VNET(ip6_mrouter)
313 #define	V_ip6_sendredirects		VNET(ip6_sendredirects)
314 #define	V_ip6_maxfragpackets		VNET(ip6_maxfragpackets)
315 #define	V_ip6_maxfrags			VNET(ip6_maxfrags)
316 #define	V_ip6_accept_rtadv		VNET(ip6_accept_rtadv)
317 #define	V_ip6_no_radr			VNET(ip6_no_radr)
318 #define	V_ip6_norbit_raif		VNET(ip6_norbit_raif)
319 #define	V_ip6_rfc6204w3			VNET(ip6_rfc6204w3)
320 #define	V_ip6_log_interval		VNET(ip6_log_interval)
321 #define	V_ip6_log_time			VNET(ip6_log_time)
322 #define	V_ip6_hdrnestlimit		VNET(ip6_hdrnestlimit)
323 #define	V_ip6_dad_count			VNET(ip6_dad_count)
324 
325 VNET_DECLARE(int, ip6_auto_flowlabel);
326 VNET_DECLARE(int, ip6_auto_linklocal);
327 #define	V_ip6_auto_flowlabel		VNET(ip6_auto_flowlabel)
328 #define	V_ip6_auto_linklocal		VNET(ip6_auto_linklocal)
329 
330 VNET_DECLARE(int, ip6_use_tempaddr);	/* Whether to use temporary addresses */
331 VNET_DECLARE(int, ip6_prefer_tempaddr);	/* Whether to prefer temporary
332 					 * addresses in the source address
333 					 * selection */
334 #define	V_ip6_use_tempaddr		VNET(ip6_use_tempaddr)
335 #define	V_ip6_prefer_tempaddr		VNET(ip6_prefer_tempaddr)
336 
337 VNET_DECLARE(int, ip6_use_defzone);	/* Whether to use the default scope
338 					 * zone when unspecified */
339 #define	V_ip6_use_defzone		VNET(ip6_use_defzone)
340 
341 VNET_DECLARE (struct pfil_head, inet6_pfil_hook);	/* packet filter hooks */
342 #define	V_inet6_pfil_hook	VNET(inet6_pfil_hook)
343 #ifdef IPSTEALTH
344 VNET_DECLARE(int, ip6stealth);
345 #define	V_ip6stealth			VNET(ip6stealth)
346 #endif
347 
348 extern struct	pr_usrreqs rip6_usrreqs;
349 struct sockopt;
350 
351 struct inpcb;
352 
353 int	icmp6_ctloutput(struct socket *, struct sockopt *sopt);
354 
355 struct in6_ifaddr;
356 void	ip6_init(void);
357 int	ip6proto_register(short);
358 int	ip6proto_unregister(short);
359 
360 void	ip6_input(struct mbuf *);
361 void	ip6_direct_input(struct mbuf *);
362 void	ip6_freepcbopts(struct ip6_pktopts *);
363 
364 int	ip6_unknown_opt(u_int8_t *, struct mbuf *, int);
365 char *	ip6_get_prevhdr(const struct mbuf *, int);
366 int	ip6_nexthdr(const struct mbuf *, int, int, int *);
367 int	ip6_lasthdr(const struct mbuf *, int, int, int *);
368 
369 extern int	(*ip6_mforward)(struct ip6_hdr *, struct ifnet *,
370     struct mbuf *);
371 
372 int	ip6_process_hopopts(struct mbuf *, u_int8_t *, int, u_int32_t *,
373 				 u_int32_t *);
374 struct mbuf	**ip6_savecontrol_v4(struct inpcb *, struct mbuf *,
375 	    struct mbuf **, int *);
376 void	ip6_savecontrol(struct inpcb *, struct mbuf *, struct mbuf **);
377 void	ip6_notify_pmtu(struct inpcb *, struct sockaddr_in6 *, u_int32_t);
378 int	ip6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
379 
380 void	ip6_forward(struct mbuf *, int);
381 
382 void	ip6_mloopback(struct ifnet *, struct mbuf *);
383 int	ip6_output(struct mbuf *, struct ip6_pktopts *,
384 			struct route_in6 *,
385 			int,
386 			struct ip6_moptions *, struct ifnet **,
387 			struct inpcb *);
388 int	ip6_ctloutput(struct socket *, struct sockopt *);
389 int	ip6_raw_ctloutput(struct socket *, struct sockopt *);
390 void	ip6_initpktopts(struct ip6_pktopts *);
391 int	ip6_setpktopts(struct mbuf *, struct ip6_pktopts *,
392 	struct ip6_pktopts *, struct ucred *, int);
393 void	ip6_clearpktopts(struct ip6_pktopts *, int);
394 struct ip6_pktopts *ip6_copypktopts(struct ip6_pktopts *, int);
395 int	ip6_optlen(struct inpcb *);
396 int	ip6_deletefraghdr(struct mbuf *, int, int);
397 int	ip6_fragment(struct ifnet *, struct mbuf *, int, u_char, int,
398 			uint32_t);
399 
400 int	route6_input(struct mbuf **, int *, int);
401 
402 void	frag6_init(void);
403 int	frag6_input(struct mbuf **, int *, int);
404 void	frag6_slowtimo(void);
405 void	frag6_drain(void);
406 
407 void	rip6_init(void);
408 int	rip6_input(struct mbuf **, int *, int);
409 void	rip6_ctlinput(int, struct sockaddr *, void *);
410 int	rip6_ctloutput(struct socket *, struct sockopt *);
411 int	rip6_output(struct mbuf *, struct socket *, ...);
412 int	rip6_usrreq(struct socket *,
413 	    int, struct mbuf *, struct mbuf *, struct mbuf *, struct thread *);
414 
415 int	dest6_input(struct mbuf **, int *, int);
416 int	none_input(struct mbuf **, int *, int);
417 
418 int	in6_selectsrc_socket(struct sockaddr_in6 *, struct ip6_pktopts *,
419     struct inpcb *, struct ucred *, int, struct in6_addr *, int *);
420 int	in6_selectsrc_addr(uint32_t, const struct in6_addr *,
421     uint32_t, struct ifnet *, struct in6_addr *, int *);
422 int in6_selectroute(struct sockaddr_in6 *, struct ip6_pktopts *,
423 	struct ip6_moptions *, struct route_in6 *, struct ifnet **,
424 	struct rtentry **);
425 int	in6_selectroute_fib(struct sockaddr_in6 *, struct ip6_pktopts *,
426 	    struct ip6_moptions *, struct route_in6 *, struct ifnet **,
427 	    struct rtentry **, u_int);
428 u_int32_t ip6_randomid(void);
429 u_int32_t ip6_randomflowlabel(void);
430 void in6_delayed_cksum(struct mbuf *m, uint32_t plen, u_short offset);
431 #endif /* _KERNEL */
432 
433 #endif /* !_NETINET6_IP6_VAR_H_ */
434