xref: /freebsd/sys/netinet6/ip6_var.h (revision 8ee127efb045caf5ad9522f3c63c7e18f9d7279f)
1caf43b02SWarner Losh /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
482cd038dSYoshinobu Inoue  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
582cd038dSYoshinobu Inoue  * All rights reserved.
682cd038dSYoshinobu Inoue  *
782cd038dSYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
882cd038dSYoshinobu Inoue  * modification, are permitted provided that the following conditions
982cd038dSYoshinobu Inoue  * are met:
1082cd038dSYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
1182cd038dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
1282cd038dSYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
1382cd038dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
1482cd038dSYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
1582cd038dSYoshinobu Inoue  * 3. Neither the name of the project nor the names of its contributors
1682cd038dSYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
1782cd038dSYoshinobu Inoue  *    without specific prior written permission.
1882cd038dSYoshinobu Inoue  *
1982cd038dSYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
2082cd038dSYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2182cd038dSYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2282cd038dSYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2382cd038dSYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2482cd038dSYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2582cd038dSYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2682cd038dSYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2782cd038dSYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2882cd038dSYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2982cd038dSYoshinobu Inoue  * SUCH DAMAGE.
30b48287a3SDavid E. O'Brien  *
31b48287a3SDavid E. O'Brien  *	$KAME: ip6_var.h,v 1.62 2001/05/03 14:51:48 itojun Exp $
3282cd038dSYoshinobu Inoue  */
3382cd038dSYoshinobu Inoue 
34caf43b02SWarner Losh /*-
3582cd038dSYoshinobu Inoue  * Copyright (c) 1982, 1986, 1993
3682cd038dSYoshinobu Inoue  *	The Regents of the University of California.  All rights reserved.
3782cd038dSYoshinobu Inoue  *
3882cd038dSYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
3982cd038dSYoshinobu Inoue  * modification, are permitted provided that the following conditions
4082cd038dSYoshinobu Inoue  * are met:
4182cd038dSYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
4282cd038dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
4382cd038dSYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
4482cd038dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
4582cd038dSYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
46fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
4782cd038dSYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
4882cd038dSYoshinobu Inoue  *    without specific prior written permission.
4982cd038dSYoshinobu Inoue  *
5082cd038dSYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
5182cd038dSYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5282cd038dSYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5382cd038dSYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5482cd038dSYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5582cd038dSYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5682cd038dSYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5782cd038dSYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5882cd038dSYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5982cd038dSYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6082cd038dSYoshinobu Inoue  * SUCH DAMAGE.
6182cd038dSYoshinobu Inoue  */
6282cd038dSYoshinobu Inoue 
6382cd038dSYoshinobu Inoue #ifndef _NETINET6_IP6_VAR_H_
6482cd038dSYoshinobu Inoue #define _NETINET6_IP6_VAR_H_
6582cd038dSYoshinobu Inoue 
66cb6bb230SMatt Macy #include <sys/epoch.h>
67cb6bb230SMatt Macy 
6821f08a07SBjoern A. Zeeb #ifdef _KERNEL
6921f08a07SBjoern A. Zeeb struct ip6asfrag;		/* frag6.c */
7021f08a07SBjoern A. Zeeb TAILQ_HEAD(ip6fraghead, ip6asfrag);
7121f08a07SBjoern A. Zeeb 
7282cd038dSYoshinobu Inoue /*
7382cd038dSYoshinobu Inoue  * IP6 reassembly queue structure.  Each fragment
7482cd038dSYoshinobu Inoue  * being reassembled is attached to one of these structures.
7582cd038dSYoshinobu Inoue  */
7682cd038dSYoshinobu Inoue struct	ip6q {
7721f08a07SBjoern A. Zeeb 	struct ip6fraghead ip6q_frags;
78686cdd19SJun-ichiro itojun Hagino 	u_int32_t	ip6q_ident;
795e9510e3SJINMEI Tatuya 	u_int8_t	ip6q_nxt;
805e9510e3SJINMEI Tatuya 	u_int8_t	ip6q_ecn;
81e32221a1SAlexander V. Chernikov 	u_int16_t	ip6q_ttl;
8282cd038dSYoshinobu Inoue 	struct in6_addr ip6q_src, ip6q_dst;
8321f08a07SBjoern A. Zeeb 	TAILQ_ENTRY(ip6q) ip6q_tq;
84686cdd19SJun-ichiro itojun Hagino 	int		ip6q_unfrglen;	/* len of unfragmentable part */
859888c401SHajimu UMEMOTO 	int		ip6q_nfrag;	/* # of fragments */
864b908c8bSRobert Watson 	struct label	*ip6q_label;
8782cd038dSYoshinobu Inoue };
8821f08a07SBjoern A. Zeeb #endif /* _KERNEL */
8982cd038dSYoshinobu Inoue 
9033cde130SBruce M Simpson /*
91aaa46574SAdrian Chadd  * IP6 reinjecting structure.
92aaa46574SAdrian Chadd  */
93aaa46574SAdrian Chadd struct ip6_direct_ctx {
94aaa46574SAdrian Chadd 	uint32_t	ip6dc_nxt;	/* next header to process */
95aaa46574SAdrian Chadd 	uint32_t	ip6dc_off;	/* offset to next header */
96aaa46574SAdrian Chadd };
97aaa46574SAdrian Chadd 
9859854ecfSHans Petter Selasky #if defined(_NETINET6_IN6_VAR_H_) && defined(_KERNEL)
99aaa46574SAdrian Chadd /*
10033cde130SBruce M Simpson  * Structure attached to inpcb.in6p_moptions and
10133cde130SBruce M Simpson  * passed to ip6_output when IPv6 multicast options are in use.
10233cde130SBruce M Simpson  * This structure is lazy-allocated.
10333cde130SBruce M Simpson  */
10482cd038dSYoshinobu Inoue struct ip6_moptions {
10582cd038dSYoshinobu Inoue 	struct	ifnet *im6o_multicast_ifp; /* ifp for outgoing multicasts */
10682cd038dSYoshinobu Inoue 	u_char	im6o_multicast_hlim;	/* hoplimit for outgoing multicasts */
10782cd038dSYoshinobu Inoue 	u_char	im6o_multicast_loop;	/* 1 >= hear sends if a member */
10859854ecfSHans Petter Selasky 	struct ip6_mfilter_head im6o_head; /* group membership list */
10982cd038dSYoshinobu Inoue };
11059854ecfSHans Petter Selasky #else
11159854ecfSHans Petter Selasky struct ip6_moptions;
11259854ecfSHans Petter Selasky #endif
11382cd038dSYoshinobu Inoue /*
11482cd038dSYoshinobu Inoue  * Control options for outgoing packets
11582cd038dSYoshinobu Inoue  */
11682cd038dSYoshinobu Inoue 
11782cd038dSYoshinobu Inoue /* Routing header related info */
11882cd038dSYoshinobu Inoue struct	ip6po_rhinfo {
11982cd038dSYoshinobu Inoue 	struct	ip6_rthdr *ip6po_rhi_rthdr; /* Routing header */
12082cd038dSYoshinobu Inoue 	struct	route_in6 ip6po_rhi_route; /* Route to the 1st hop */
12182cd038dSYoshinobu Inoue };
12282cd038dSYoshinobu Inoue #define ip6po_rthdr	ip6po_rhinfo.ip6po_rhi_rthdr
12382cd038dSYoshinobu Inoue #define ip6po_route	ip6po_rhinfo.ip6po_rhi_route
12482cd038dSYoshinobu Inoue 
125f95d4633SHajimu UMEMOTO /* Nexthop related info */
126f95d4633SHajimu UMEMOTO struct	ip6po_nhinfo {
127f95d4633SHajimu UMEMOTO 	struct	sockaddr *ip6po_nhi_nexthop;
128f95d4633SHajimu UMEMOTO 	struct	route_in6 ip6po_nhi_route; /* Route to the nexthop */
129f95d4633SHajimu UMEMOTO };
130f95d4633SHajimu UMEMOTO #define ip6po_nexthop	ip6po_nhinfo.ip6po_nhi_nexthop
131f95d4633SHajimu UMEMOTO #define ip6po_nextroute	ip6po_nhinfo.ip6po_nhi_route
132f95d4633SHajimu UMEMOTO 
133530c2c30SAndrew Gallatin /*
134530c2c30SAndrew Gallatin  * Note that fields with valid data must be flagged in ip6po_valid.
135530c2c30SAndrew Gallatin  * This is done to reduce cache misses in ip6_output().  Before
136530c2c30SAndrew Gallatin  * ip6po_valid, ip6_output needed to check all the individual fields
137530c2c30SAndrew Gallatin  * of ip6_pktopts needed to be checked themselves, and they are spread
138530c2c30SAndrew Gallatin  * across 4 cachelines. ip6_output() is currently the only consumer of
139530c2c30SAndrew Gallatin  * these flags, as it is in the critical path of every packet sent.
140530c2c30SAndrew Gallatin  */
14182cd038dSYoshinobu Inoue struct	ip6_pktopts {
142530c2c30SAndrew Gallatin 	uint32_t ip6po_valid;
143530c2c30SAndrew Gallatin #define IP6PO_VALID_HLIM	0x0001
144530c2c30SAndrew Gallatin #define IP6PO_VALID_PKTINFO	0x0002
145530c2c30SAndrew Gallatin #define IP6PO_VALID_NHINFO	0x0004
146530c2c30SAndrew Gallatin #define IP6PO_VALID_HBH		0x0008
147530c2c30SAndrew Gallatin #define IP6PO_VALID_DEST1	0x0010
148530c2c30SAndrew Gallatin #define IP6PO_VALID_RHINFO	0x0020
149530c2c30SAndrew Gallatin #define IP6PO_VALID_DEST2	0x0040
150530c2c30SAndrew Gallatin #define IP6PO_VALID_TC		0x0080
151530c2c30SAndrew Gallatin 
15282cd038dSYoshinobu Inoue 	int	ip6po_hlim;	/* Hoplimit for outgoing packets */
153f95d4633SHajimu UMEMOTO 	int	ip6po_tclass;	/* traffic class */
154f95d4633SHajimu UMEMOTO 
155f95d4633SHajimu UMEMOTO 	int	ip6po_minmtu;  /* fragment vs PMTU discovery policy */
156f95d4633SHajimu UMEMOTO #define IP6PO_MINMTU_MCASTONLY	-1 /* default; send at min MTU for multicast*/
157f95d4633SHajimu UMEMOTO #define IP6PO_MINMTU_DISABLE	 0 /* always perform pmtu disc */
158f95d4633SHajimu UMEMOTO #define IP6PO_MINMTU_ALL	 1 /* always send at min MTU */
159f95d4633SHajimu UMEMOTO 
160f95d4633SHajimu UMEMOTO 	int	ip6po_prefer_tempaddr;  /* whether temporary addresses are
161f95d4633SHajimu UMEMOTO 					   preferred as source address */
162f95d4633SHajimu UMEMOTO #define IP6PO_TEMPADDR_SYSTEM	-1 /* follow the system default */
163f95d4633SHajimu UMEMOTO #define IP6PO_TEMPADDR_NOTPREFER 0 /* not prefer temporary address */
164f95d4633SHajimu UMEMOTO #define IP6PO_TEMPADDR_PREFER	 1 /* prefer temporary address */
165f95d4633SHajimu UMEMOTO 
166f95d4633SHajimu UMEMOTO 	int ip6po_flags;
167f95d4633SHajimu UMEMOTO #if 0	/* parameters in this block is obsolete. do not reuse the values. */
168f95d4633SHajimu UMEMOTO #define IP6PO_REACHCONF	0x01	/* upper-layer reachability confirmation. */
169f95d4633SHajimu UMEMOTO #define IP6PO_MINMTU	0x02	/* use minimum MTU (IPV6_USE_MIN_MTU) */
170f95d4633SHajimu UMEMOTO #endif
171f95d4633SHajimu UMEMOTO #define IP6PO_DONTFRAG	0x04	/* disable fragmentation (IPV6_DONTFRAG) */
172f95d4633SHajimu UMEMOTO #define IP6PO_USECOA	0x08	/* use care of address */
173530c2c30SAndrew Gallatin 
174530c2c30SAndrew Gallatin 	struct	mbuf *ip6po_m;	/* Pointer to mbuf storing the data */
175530c2c30SAndrew Gallatin 
176530c2c30SAndrew Gallatin 	/* Outgoing IF/address information */
177530c2c30SAndrew Gallatin 	struct	in6_pktinfo *ip6po_pktinfo;
178530c2c30SAndrew Gallatin 
179530c2c30SAndrew Gallatin 	/* Next-hop address information */
180530c2c30SAndrew Gallatin 	struct	ip6po_nhinfo ip6po_nhinfo;
181530c2c30SAndrew Gallatin 
182530c2c30SAndrew Gallatin 	struct	ip6_hbh *ip6po_hbh; /* Hop-by-Hop options header */
183530c2c30SAndrew Gallatin 
184530c2c30SAndrew Gallatin 	/* Destination options header (before a routing header) */
185530c2c30SAndrew Gallatin 	struct	ip6_dest *ip6po_dest1;
186530c2c30SAndrew Gallatin 
187530c2c30SAndrew Gallatin 	/* Routing header related info. */
188530c2c30SAndrew Gallatin 	struct	ip6po_rhinfo ip6po_rhinfo;
189530c2c30SAndrew Gallatin 
190530c2c30SAndrew Gallatin 	/* Destination options header (after a routing header) */
191530c2c30SAndrew Gallatin 	struct	ip6_dest *ip6po_dest2;
19282cd038dSYoshinobu Inoue };
19382cd038dSYoshinobu Inoue 
19433841545SHajimu UMEMOTO /*
19533841545SHajimu UMEMOTO  * Control options for incoming packets
19633841545SHajimu UMEMOTO  */
19733841545SHajimu UMEMOTO 
19882cd038dSYoshinobu Inoue struct	ip6stat {
199c80211e3SAndrey V. Elsukov 	uint64_t ip6s_total;		/* total packets received */
200c80211e3SAndrey V. Elsukov 	uint64_t ip6s_tooshort;		/* packet too short */
201c80211e3SAndrey V. Elsukov 	uint64_t ip6s_toosmall;		/* not enough data */
202c80211e3SAndrey V. Elsukov 	uint64_t ip6s_fragments;	/* fragments received */
203c80211e3SAndrey V. Elsukov 	uint64_t ip6s_fragdropped;	/* frags dropped(dups, out of space) */
204c80211e3SAndrey V. Elsukov 	uint64_t ip6s_fragtimeout;	/* fragments timed out */
205c80211e3SAndrey V. Elsukov 	uint64_t ip6s_fragoverflow;	/* fragments that exceeded limit */
206c80211e3SAndrey V. Elsukov 	uint64_t ip6s_forward;		/* packets forwarded */
207c80211e3SAndrey V. Elsukov 	uint64_t ip6s_cantforward;	/* packets rcvd for unreachable dest */
208c80211e3SAndrey V. Elsukov 	uint64_t ip6s_redirectsent;	/* packets forwarded on same net */
209c80211e3SAndrey V. Elsukov 	uint64_t ip6s_delivered;	/* datagrams delivered to upper level*/
210c80211e3SAndrey V. Elsukov 	uint64_t ip6s_localout;		/* total ip packets generated here */
211c80211e3SAndrey V. Elsukov 	uint64_t ip6s_odropped;		/* lost packets due to nobufs, etc. */
212c80211e3SAndrey V. Elsukov 	uint64_t ip6s_reassembled;	/* total packets reassembled ok */
2132946a941STom Jones 	uint64_t ip6s_atomicfrags;	/* atomic fragments */
214c80211e3SAndrey V. Elsukov 	uint64_t ip6s_fragmented;	/* datagrams successfully fragmented */
215c80211e3SAndrey V. Elsukov 	uint64_t ip6s_ofragments;	/* output fragments created */
216c80211e3SAndrey V. Elsukov 	uint64_t ip6s_cantfrag;		/* don't fragment flag was set, etc. */
217c80211e3SAndrey V. Elsukov 	uint64_t ip6s_badoptions;	/* error in option processing */
218c80211e3SAndrey V. Elsukov 	uint64_t ip6s_noroute;		/* packets discarded due to no route */
219c80211e3SAndrey V. Elsukov 	uint64_t ip6s_badvers;		/* ip6 version != 6 */
220c80211e3SAndrey V. Elsukov 	uint64_t ip6s_rawout;		/* total raw ip packets generated */
221c80211e3SAndrey V. Elsukov 	uint64_t ip6s_badscope;		/* scope error */
222c80211e3SAndrey V. Elsukov 	uint64_t ip6s_notmember;	/* don't join this multicast group */
22343851aaeSAndrey V. Elsukov #define	IP6S_HDRCNT		256	/* headers count */
224c80211e3SAndrey V. Elsukov 	uint64_t ip6s_nxthist[IP6S_HDRCNT]; /* next header history */
225c80211e3SAndrey V. Elsukov 	uint64_t ip6s_m1;		/* one mbuf */
22643851aaeSAndrey V. Elsukov #define	IP6S_M2MMAX		32
227c80211e3SAndrey V. Elsukov 	uint64_t ip6s_m2m[IP6S_M2MMAX];	/* two or more mbuf */
228c80211e3SAndrey V. Elsukov 	uint64_t ip6s_mext1;		/* one ext mbuf */
229c80211e3SAndrey V. Elsukov 	uint64_t ip6s_mext2m;		/* two or more ext mbuf */
230c80211e3SAndrey V. Elsukov 	uint64_t ip6s_exthdrtoolong;	/* ext hdr are not contiguous */
231c80211e3SAndrey V. Elsukov 	uint64_t ip6s_nogif;		/* no match gif found */
232c80211e3SAndrey V. Elsukov 	uint64_t ip6s_toomanyhdr;	/* discarded due to too many headers */
233686cdd19SJun-ichiro itojun Hagino 
234686cdd19SJun-ichiro itojun Hagino 	/*
235686cdd19SJun-ichiro itojun Hagino 	 * statistics for improvement of the source address selection
236686cdd19SJun-ichiro itojun Hagino 	 * algorithm:
237686cdd19SJun-ichiro itojun Hagino 	 * XXX: hardcoded 16 = # of ip6 multicast scope types + 1
238686cdd19SJun-ichiro itojun Hagino 	 */
23943851aaeSAndrey V. Elsukov #define	IP6S_RULESMAX		16
24043851aaeSAndrey V. Elsukov #define	IP6S_SCOPECNT		16
241686cdd19SJun-ichiro itojun Hagino 	/* number of times that address selection fails */
242c80211e3SAndrey V. Elsukov 	uint64_t ip6s_sources_none;
243686cdd19SJun-ichiro itojun Hagino 	/* number of times that an address on the outgoing I/F is chosen */
244c80211e3SAndrey V. Elsukov 	uint64_t ip6s_sources_sameif[IP6S_SCOPECNT];
245686cdd19SJun-ichiro itojun Hagino 	/* number of times that an address on a non-outgoing I/F is chosen */
246c80211e3SAndrey V. Elsukov 	uint64_t ip6s_sources_otherif[IP6S_SCOPECNT];
247686cdd19SJun-ichiro itojun Hagino 	/*
248686cdd19SJun-ichiro itojun Hagino 	 * number of times that an address that has the same scope
249686cdd19SJun-ichiro itojun Hagino 	 * from the destination is chosen.
250686cdd19SJun-ichiro itojun Hagino 	 */
251c80211e3SAndrey V. Elsukov 	uint64_t ip6s_sources_samescope[IP6S_SCOPECNT];
252686cdd19SJun-ichiro itojun Hagino 	/*
253686cdd19SJun-ichiro itojun Hagino 	 * number of times that an address that has a different scope
254686cdd19SJun-ichiro itojun Hagino 	 * from the destination is chosen.
255686cdd19SJun-ichiro itojun Hagino 	 */
256c80211e3SAndrey V. Elsukov 	uint64_t ip6s_sources_otherscope[IP6S_SCOPECNT];
257d64ada50SJens Schweikhardt 	/* number of times that a deprecated address is chosen */
258c80211e3SAndrey V. Elsukov 	uint64_t ip6s_sources_deprecated[IP6S_SCOPECNT];
259686cdd19SJun-ichiro itojun Hagino 
260d6385b1cSHajimu UMEMOTO 	/* number of times that each rule of source selection is applied. */
261c80211e3SAndrey V. Elsukov 	uint64_t ip6s_sources_rule[IP6S_RULESMAX];
26282cd038dSYoshinobu Inoue };
26382cd038dSYoshinobu Inoue 
26482cd038dSYoshinobu Inoue #ifdef _KERNEL
265a786f679SAndrey V. Elsukov #include <sys/counter.h>
26660d8dbbeSKristof Provost #include <netinet/in_kdtrace.h>
267a786f679SAndrey V. Elsukov 
268a786f679SAndrey V. Elsukov VNET_PCPUSTAT_DECLARE(struct ip6stat, ip6stat);
269a786f679SAndrey V. Elsukov #define	IP6STAT_ADD(name, val)                                           \
27060d8dbbeSKristof Provost 	do {                                                             \
27160d8dbbeSKristof Provost 		MIB_SDT_PROBE1(ip6, count, name, (val));                 \
27260d8dbbeSKristof Provost 		VNET_PCPUSTAT_ADD(struct ip6stat, ip6stat, name, (val)); \
27360d8dbbeSKristof Provost 	} while (0)
274a786f679SAndrey V. Elsukov #define IP6STAT_SUB(name, val) IP6STAT_ADD(name, -(val))
27533cde130SBruce M Simpson #define	IP6STAT_INC(name)	IP6STAT_ADD(name, 1)
27660d8dbbeSKristof Provost #define IP6STAT_INC2(name, type)                                     \
27760d8dbbeSKristof Provost 	do {                                                         \
27860d8dbbeSKristof Provost 		MIB_SDT_PROBE2(ip6, count, name, 1, type);           \
27960d8dbbeSKristof Provost 		VNET_PCPUSTAT_ADD(struct ip6stat, ip6stat, name, 1); \
28060d8dbbeSKristof Provost 	} while (0)
28133cde130SBruce M Simpson #define IP6STAT_DEC(name) IP6STAT_SUB(name, 1)
28233cde130SBruce M Simpson #endif
28333cde130SBruce M Simpson 
28433cde130SBruce M Simpson #ifdef _KERNEL
28582cd038dSYoshinobu Inoue /* flags passed to ip6_output as last parameter */
2864ecbe331SSUZUKI Shinsuke #define	IPV6_UNSPECSRC		0x01	/* allow :: as the source address */
28782cd038dSYoshinobu Inoue #define	IPV6_FORWARDING		0x02	/* most of IPv6 header exists */
288686cdd19SJun-ichiro itojun Hagino #define	IPV6_MINMTU		0x04	/* use minimum MTU (IPV6_USE_MIN_MTU) */
28982cd038dSYoshinobu Inoue 
2902fcb030aSAndrew Thompson #ifdef __NO_STRICT_ALIGNMENT
2912fcb030aSAndrew Thompson #define IP6_HDR_ALIGNED_P(ip)	1
2922fcb030aSAndrew Thompson #else
2932fcb030aSAndrew Thompson #define IP6_HDR_ALIGNED_P(ip)	((((intptr_t) (ip)) & 3) == 0)
2942fcb030aSAndrew Thompson #endif
2952fcb030aSAndrew Thompson 
296eddfbb76SRobert Watson VNET_DECLARE(int, ip6_defhlim);		/* default hop limit */
297eddfbb76SRobert Watson VNET_DECLARE(int, ip6_defmcasthlim);	/* default multicast hop limit */
298eddfbb76SRobert Watson VNET_DECLARE(int, ip6_forwarding);	/* act as router? */
299eddfbb76SRobert Watson VNET_DECLARE(int, ip6_use_deprecated);	/* allow deprecated addr as source */
300eddfbb76SRobert Watson VNET_DECLARE(int, ip6_rr_prune);	/* router renumbering prefix
30182cd038dSYoshinobu Inoue 					 * walk list every 5 sec.    */
302eddfbb76SRobert Watson VNET_DECLARE(int, ip6_mcast_pmtu);	/* enable pMTU discovery for multicast? */
303eddfbb76SRobert Watson VNET_DECLARE(int, ip6_v6only);
30482cea7e6SBjoern A. Zeeb #define	V_ip6_defhlim			VNET(ip6_defhlim)
30582cea7e6SBjoern A. Zeeb #define	V_ip6_defmcasthlim		VNET(ip6_defmcasthlim)
30682cea7e6SBjoern A. Zeeb #define	V_ip6_forwarding		VNET(ip6_forwarding)
30782cea7e6SBjoern A. Zeeb #define	V_ip6_use_deprecated		VNET(ip6_use_deprecated)
30882cea7e6SBjoern A. Zeeb #define	V_ip6_rr_prune			VNET(ip6_rr_prune)
30982cea7e6SBjoern A. Zeeb #define	V_ip6_mcast_pmtu		VNET(ip6_mcast_pmtu)
31082cea7e6SBjoern A. Zeeb #define	V_ip6_v6only			VNET(ip6_v6only)
31182cea7e6SBjoern A. Zeeb 
312eddfbb76SRobert Watson VNET_DECLARE(struct socket *, ip6_mrouter);	/* multicast routing daemon */
313eddfbb76SRobert Watson VNET_DECLARE(int, ip6_sendredirects);	/* send IP redirects when forwarding? */
314eddfbb76SRobert Watson VNET_DECLARE(int, ip6_accept_rtadv);	/* Acts as a host not a router */
315e7fa8d0aSHiroki Sato VNET_DECLARE(int, ip6_no_radr);		/* No defroute from RA */
316e7fa8d0aSHiroki Sato VNET_DECLARE(int, ip6_norbit_raif);	/* Disable R-bit in NA on RA
317e7fa8d0aSHiroki Sato 					 * receiving IF. */
318049087a0SHiroki Sato VNET_DECLARE(int, ip6_rfc6204w3);	/* Accept defroute from RA even when
319049087a0SHiroki Sato 					   forwarding enabled */
320eddfbb76SRobert Watson VNET_DECLARE(int, ip6_hdrnestlimit);	/* upper limit of # of extension
321eddfbb76SRobert Watson 					 * headers */
322eddfbb76SRobert Watson VNET_DECLARE(int, ip6_dad_count);	/* DupAddrDetectionTransmits */
3231e77c105SRobert Watson #define	V_ip6_mrouter			VNET(ip6_mrouter)
3241e77c105SRobert Watson #define	V_ip6_sendredirects		VNET(ip6_sendredirects)
3251e77c105SRobert Watson #define	V_ip6_accept_rtadv		VNET(ip6_accept_rtadv)
326e7fa8d0aSHiroki Sato #define	V_ip6_no_radr			VNET(ip6_no_radr)
327e7fa8d0aSHiroki Sato #define	V_ip6_norbit_raif		VNET(ip6_norbit_raif)
328049087a0SHiroki Sato #define	V_ip6_rfc6204w3			VNET(ip6_rfc6204w3)
3291e77c105SRobert Watson #define	V_ip6_hdrnestlimit		VNET(ip6_hdrnestlimit)
3301e77c105SRobert Watson #define	V_ip6_dad_count			VNET(ip6_dad_count)
33182cea7e6SBjoern A. Zeeb 
33282cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip6_auto_flowlabel);
33382cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip6_auto_linklocal);
3341e77c105SRobert Watson #define	V_ip6_auto_flowlabel		VNET(ip6_auto_flowlabel)
3351e77c105SRobert Watson #define	V_ip6_auto_linklocal		VNET(ip6_auto_linklocal)
33682cea7e6SBjoern A. Zeeb 
33782cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip6_use_tempaddr);	/* Whether to use temporary addresses */
33882cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip6_prefer_tempaddr);	/* Whether to prefer temporary
33982cea7e6SBjoern A. Zeeb 					 * addresses in the source address
34082cea7e6SBjoern A. Zeeb 					 * selection */
3411e77c105SRobert Watson #define	V_ip6_use_tempaddr		VNET(ip6_use_tempaddr)
3421e77c105SRobert Watson #define	V_ip6_prefer_tempaddr		VNET(ip6_prefer_tempaddr)
34382cea7e6SBjoern A. Zeeb 
34482cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip6_use_defzone);	/* Whether to use the default scope
34582cea7e6SBjoern A. Zeeb 					 * zone when unspecified */
3461e77c105SRobert Watson #define	V_ip6_use_defzone		VNET(ip6_use_defzone)
3471b193af6SBjoern A. Zeeb 
348b252313fSGleb Smirnoff VNET_DECLARE(struct pfil_head *, inet6_pfil_head);
349b252313fSGleb Smirnoff #define	V_inet6_pfil_head	VNET(inet6_pfil_head)
350b252313fSGleb Smirnoff #define	PFIL_INET6_NAME		"inet6"
351b252313fSGleb Smirnoff 
3525ab15157SDoug Rabson VNET_DECLARE(struct pfil_head *, inet6_local_pfil_head);
3535ab15157SDoug Rabson #define	V_inet6_local_pfil_head	VNET(inet6_local_pfil_head)
3545ab15157SDoug Rabson #define	PFIL_INET6_LOCAL_NAME	"inet6-local"
3555ab15157SDoug Rabson 
35682cea7e6SBjoern A. Zeeb #ifdef IPSTEALTH
35782cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip6stealth);
35882cea7e6SBjoern A. Zeeb #define	V_ip6stealth			VNET(ip6stealth)
35982cea7e6SBjoern A. Zeeb #endif
3601b193af6SBjoern A. Zeeb 
3613eaffc62SPawel Biernacki VNET_DECLARE(bool, ip6_log_cannot_forward);
3623eaffc62SPawel Biernacki #define	V_ip6_log_cannot_forward	VNET(ip6_log_cannot_forward)
3633eaffc62SPawel Biernacki 
36482cd038dSYoshinobu Inoue extern struct	pr_usrreqs rip6_usrreqs;
36582cd038dSYoshinobu Inoue struct sockopt;
366686cdd19SJun-ichiro itojun Hagino 
36782cd038dSYoshinobu Inoue struct inpcb;
368b8039bf5SKristof Provost struct ucred;
36982cd038dSYoshinobu Inoue 
3706f56329aSXin LI int	icmp6_ctloutput(struct socket *, struct sockopt *sopt);
37182cd038dSYoshinobu Inoue 
3726f56329aSXin LI void	ip6_input(struct mbuf *);
373aaa46574SAdrian Chadd void	ip6_direct_input(struct mbuf *);
3746f56329aSXin LI void	ip6_freepcbopts(struct ip6_pktopts *);
37533cde130SBruce M Simpson 
3766f56329aSXin LI int	ip6_unknown_opt(u_int8_t *, struct mbuf *, int);
37768e0e5a6SAndrey V. Elsukov int	ip6_get_prevhdr(const struct mbuf *, int);
3780be18915SAdrian Chadd int	ip6_nexthdr(const struct mbuf *, int, int, int *);
3790be18915SAdrian Chadd int	ip6_lasthdr(const struct mbuf *, int, int, int *);
38033841545SHajimu UMEMOTO 
3816be2e366SBruce M Simpson extern int	(*ip6_mforward)(struct ip6_hdr *, struct ifnet *,
3826be2e366SBruce M Simpson     struct mbuf *);
3836be2e366SBruce M Simpson 
3846f56329aSXin LI int	ip6_process_hopopts(struct mbuf *, u_int8_t *, int, u_int32_t *,
3856f56329aSXin LI 				 u_int32_t *);
38648d48eb9SBjoern A. Zeeb struct mbuf	**ip6_savecontrol_v4(struct inpcb *, struct mbuf *,
38748d48eb9SBjoern A. Zeeb 	    struct mbuf **, int *);
3886f56329aSXin LI void	ip6_savecontrol(struct inpcb *, struct mbuf *, struct mbuf **);
3898f1beb88SAndrey V. Elsukov void	ip6_notify_pmtu(struct inpcb *, struct sockaddr_in6 *, u_int32_t);
3906f56329aSXin LI int	ip6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
39182cd038dSYoshinobu Inoue 
3926f56329aSXin LI void	ip6_forward(struct mbuf *, int);
39382cd038dSYoshinobu Inoue 
39456a5f52eSGleb Smirnoff void	ip6_mloopback(struct ifnet *, struct mbuf *);
3956f56329aSXin LI int	ip6_output(struct mbuf *, struct ip6_pktopts *,
39633841545SHajimu UMEMOTO 			struct route_in6 *,
39733841545SHajimu UMEMOTO 			int,
3985d846453SSam Leffler 			struct ip6_moptions *, struct ifnet **,
3996f56329aSXin LI 			struct inpcb *);
4006f56329aSXin LI int	ip6_ctloutput(struct socket *, struct sockopt *);
4016f56329aSXin LI int	ip6_raw_ctloutput(struct socket *, struct sockopt *);
4026f56329aSXin LI void	ip6_initpktopts(struct ip6_pktopts *);
4036f56329aSXin LI int	ip6_setpktopts(struct mbuf *, struct ip6_pktopts *,
4046f56329aSXin LI 	struct ip6_pktopts *, struct ucred *, int);
4056f56329aSXin LI void	ip6_clearpktopts(struct ip6_pktopts *, int);
4066f56329aSXin LI struct ip6_pktopts *ip6_copypktopts(struct ip6_pktopts *, int);
4076f56329aSXin LI int	ip6_optlen(struct inpcb *);
4080b438b0fSGleb Smirnoff int	ip6_deletefraghdr(struct mbuf *, int, int);
40979831849SKristof Provost int	ip6_fragment(struct ifnet *, struct mbuf *, int, u_char, int,
41079831849SKristof Provost 			uint32_t);
41182cd038dSYoshinobu Inoue 
4126f56329aSXin LI int	route6_input(struct mbuf **, int *, int);
41382cd038dSYoshinobu Inoue 
4146f56329aSXin LI void	frag6_init(void);
41567a10c46SBjoern A. Zeeb void	frag6_destroy(void);
4166f56329aSXin LI int	frag6_input(struct mbuf **, int *, int);
417*8ee127efSSHENGYI HONG void	frag6_drain(void *, int);
41882cd038dSYoshinobu Inoue 
4196f56329aSXin LI void	rip6_init(void);
4206f56329aSXin LI int	rip6_ctloutput(struct socket *, struct sockopt *);
4216f56329aSXin LI int	rip6_usrreq(struct socket *,
4226f56329aSXin LI 	    int, struct mbuf *, struct mbuf *, struct mbuf *, struct thread *);
42382cd038dSYoshinobu Inoue 
4246f56329aSXin LI int	dest6_input(struct mbuf **, int *, int);
4256f56329aSXin LI int	none_input(struct mbuf **, int *, int);
4268373d51dSHajimu UMEMOTO 
427601c0b8bSAlexander V. Chernikov int	in6_selectsrc_socket(struct sockaddr_in6 *, struct ip6_pktopts *,
428601c0b8bSAlexander V. Chernikov     struct inpcb *, struct ucred *, int, struct in6_addr *, int *);
429601c0b8bSAlexander V. Chernikov int	in6_selectsrc_addr(uint32_t, const struct in6_addr *,
430601c0b8bSAlexander V. Chernikov     uint32_t, struct ifnet *, struct in6_addr *, int *);
4316f56329aSXin LI int in6_selectroute(struct sockaddr_in6 *, struct ip6_pktopts *,
432d6385b1cSHajimu UMEMOTO 	struct ip6_moptions *, struct route_in6 *, struct ifnet **,
433983066f0SAlexander V. Chernikov 	struct nhop_object **, u_int, uint32_t);
4346f56329aSXin LI u_int32_t ip6_randomid(void);
4356f56329aSXin LI u_int32_t ip6_randomflowlabel(void);
436aaf2cfc0SVANHULLEBUS Yvan void in6_delayed_cksum(struct mbuf *m, uint32_t plen, u_short offset);
43724b96f35SGleb Smirnoff 
43835b6e52cSPawel Biernacki int	ip6_log_ratelimit(void);
43935b6e52cSPawel Biernacki 
44046ddeb6bSGleb Smirnoff /*
44146ddeb6bSGleb Smirnoff  * Argument type for the last arg of ip6proto_ctlinput_t().
44246ddeb6bSGleb Smirnoff  *
44346ddeb6bSGleb Smirnoff  * IPv6 ICMP IPv6 [exthdrs] finalhdr payload
44446ddeb6bSGleb Smirnoff  * ^    ^    ^              ^
44546ddeb6bSGleb Smirnoff  * |    |    ip6c_ip6       ip6c_off
44646ddeb6bSGleb Smirnoff  * |    ip6c_icmp6
44746ddeb6bSGleb Smirnoff  * ip6c_m
44846ddeb6bSGleb Smirnoff  *
449fcb3f813SGleb Smirnoff  * ip6c_finaldst's sin6_addr usually points to ip6c_ip6->ip6_dst.  If the
450fcb3f813SGleb Smirnoff  * original * (internal) packet carries a routing header, it may point the
451fcb3f813SGleb Smirnoff  * final * destination address in the routing header.
45246ddeb6bSGleb Smirnoff  *
45346ddeb6bSGleb Smirnoff  * ip6c_src: ip6c_ip6->ip6_src + scope info + flowlabel in ip6c_ip6
45446ddeb6bSGleb Smirnoff  *	(beware of flowlabel, if you try to compare it against others)
45546ddeb6bSGleb Smirnoff  * ip6c_dst: ip6c_finaldst + scope info
45646ddeb6bSGleb Smirnoff  */
45746ddeb6bSGleb Smirnoff struct ip6ctlparam {
45846ddeb6bSGleb Smirnoff 	struct mbuf *ip6c_m;		/* start of mbuf chain */
45946ddeb6bSGleb Smirnoff 	struct icmp6_hdr *ip6c_icmp6;	/* icmp6 header of target packet */
46046ddeb6bSGleb Smirnoff 	struct ip6_hdr *ip6c_ip6;	/* ip6 header of target packet */
46146ddeb6bSGleb Smirnoff 	int ip6c_off;			/* offset of the target proto header */
46246ddeb6bSGleb Smirnoff 	struct sockaddr_in6 *ip6c_src;	/* srcaddr w/ additional info */
46346ddeb6bSGleb Smirnoff 	struct sockaddr_in6 *ip6c_dst;	/* (final) dstaddr w/ additional info */
464fcb3f813SGleb Smirnoff 	struct sockaddr_in6 *ip6c_finaldst;	/* final destination address */
46546ddeb6bSGleb Smirnoff 	void *ip6c_cmdarg;		/* control command dependent data */
46646ddeb6bSGleb Smirnoff 	u_int8_t ip6c_nxt;		/* final next header field */
46746ddeb6bSGleb Smirnoff };
46846ddeb6bSGleb Smirnoff 
46924b96f35SGleb Smirnoff typedef int	ip6proto_input_t(struct mbuf **, int *, int);
470fcb3f813SGleb Smirnoff typedef void	ip6proto_ctlinput_t(struct ip6ctlparam *);
47124b96f35SGleb Smirnoff int	ip6proto_register(uint8_t, ip6proto_input_t, ip6proto_ctlinput_t);
47224b96f35SGleb Smirnoff int	ip6proto_unregister(uint8_t);
47324b96f35SGleb Smirnoff #define	IP6PROTO_REGISTER(prot, input, ctl)	do {			\
47424b96f35SGleb Smirnoff 	int error __diagused;						\
47524b96f35SGleb Smirnoff 	error = ip6proto_register(prot, input, ctl);			\
47624b96f35SGleb Smirnoff 	MPASS(error == 0);						\
47724b96f35SGleb Smirnoff } while (0)
47843d39ca7SGleb Smirnoff 
47943d39ca7SGleb Smirnoff ip6proto_input_t	rip6_input;
48043d39ca7SGleb Smirnoff ip6proto_ctlinput_t	rip6_ctlinput;
48143d39ca7SGleb Smirnoff 
48282cd038dSYoshinobu Inoue #endif /* _KERNEL */
48382cd038dSYoshinobu Inoue 
48482cd038dSYoshinobu Inoue #endif /* !_NETINET6_IP6_VAR_H_ */
485