ip6_var.h revision 62587
1208625Sjkim/*	$FreeBSD: head/sys/netinet6/ip6_var.h 62587 2000-07-04 16:35:15Z itojun $	*/
2208625Sjkim/*	$KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $	*/
3208625Sjkim
4208625Sjkim/*
5208625Sjkim * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6208625Sjkim * All rights reserved.
7208625Sjkim *
8208625Sjkim * Redistribution and use in source and binary forms, with or without
9208625Sjkim * modification, are permitted provided that the following conditions
10208625Sjkim * are met:
11208625Sjkim * 1. Redistributions of source code must retain the above copyright
12208625Sjkim *    notice, this list of conditions and the following disclaimer.
13208625Sjkim * 2. Redistributions in binary form must reproduce the above copyright
14208625Sjkim *    notice, this list of conditions and the following disclaimer in the
15208625Sjkim *    documentation and/or other materials provided with the distribution.
16208625Sjkim * 3. Neither the name of the project nor the names of its contributors
17208625Sjkim *    may be used to endorse or promote products derived from this software
18208625Sjkim *    without specific prior written permission.
19208625Sjkim *
20208625Sjkim * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21208625Sjkim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22208625Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23208625Sjkim * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24208625Sjkim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25208625Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26208625Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27208625Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28208625Sjkim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29208625Sjkim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30208625Sjkim * SUCH DAMAGE.
31208625Sjkim */
32208625Sjkim
33208625Sjkim/*
34208625Sjkim * Copyright (c) 1982, 1986, 1993
35208625Sjkim *	The Regents of the University of California.  All rights reserved.
36208625Sjkim *
37208625Sjkim * Redistribution and use in source and binary forms, with or without
38208625Sjkim * modification, are permitted provided that the following conditions
39208625Sjkim * are met:
40208625Sjkim * 1. Redistributions of source code must retain the above copyright
41208625Sjkim *    notice, this list of conditions and the following disclaimer.
42208625Sjkim * 2. Redistributions in binary form must reproduce the above copyright
43208625Sjkim *    notice, this list of conditions and the following disclaimer in the
44208625Sjkim *    documentation and/or other materials provided with the distribution.
45208625Sjkim * 3. All advertising materials mentioning features or use of this software
46208625Sjkim *    must display the following acknowledgement:
47208625Sjkim *	This product includes software developed by the University of
48208625Sjkim *	California, Berkeley and its contributors.
49208625Sjkim * 4. Neither the name of the University nor the names of its contributors
50208625Sjkim *    may be used to endorse or promote products derived from this software
51208625Sjkim *    without specific prior written permission.
52208625Sjkim *
53208625Sjkim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54208625Sjkim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55208625Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56208625Sjkim * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57208625Sjkim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58208625Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59208625Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60208625Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61208625Sjkim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62208625Sjkim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63208625Sjkim * SUCH DAMAGE.
64208625Sjkim *
65208625Sjkim *	@(#)ip_var.h	8.1 (Berkeley) 6/10/93
66208625Sjkim */
67208625Sjkim
68208625Sjkim#ifndef _NETINET6_IP6_VAR_H_
69208625Sjkim#define _NETINET6_IP6_VAR_H_
70208625Sjkim
71208625Sjkim/*
72208625Sjkim * IP6 reassembly queue structure.  Each fragment
73208625Sjkim * being reassembled is attached to one of these structures.
74208625Sjkim */
75208625Sjkimstruct	ip6q {
76208625Sjkim	u_int32_t	ip6q_head;
77208625Sjkim	u_int16_t	ip6q_len;
78208625Sjkim	u_int8_t	ip6q_nxt;	/* ip6f_nxt in first fragment */
79208625Sjkim	u_int8_t	ip6q_hlim;
80208625Sjkim	struct ip6asfrag *ip6q_down;
81208625Sjkim	struct ip6asfrag *ip6q_up;
82208625Sjkim	u_int32_t	ip6q_ident;
83208625Sjkim	u_int8_t	ip6q_arrive;
84208625Sjkim	u_int8_t	ip6q_ttl;
85208625Sjkim	struct in6_addr	ip6q_src, ip6q_dst;
86208625Sjkim	struct ip6q	*ip6q_next;
87208625Sjkim	struct ip6q	*ip6q_prev;
88208625Sjkim	int		ip6q_unfrglen;	/* len of unfragmentable part */
89208625Sjkim#ifdef notyet
90208625Sjkim	u_char		*ip6q_nxtp;
91208625Sjkim#endif
92208625Sjkim};
93208625Sjkim
94208625Sjkimstruct	ip6asfrag {
95208625Sjkim	u_int32_t	ip6af_head;
96208625Sjkim	u_int16_t	ip6af_len;
97208625Sjkim	u_int8_t	ip6af_nxt;
98208625Sjkim	u_int8_t	ip6af_hlim;
99208625Sjkim	/* must not override the above members during reassembling */
100208625Sjkim	struct ip6asfrag *ip6af_down;
101208625Sjkim	struct ip6asfrag *ip6af_up;
102208625Sjkim	struct mbuf	*ip6af_m;
103208625Sjkim	int		ip6af_offset;	/* offset in ip6af_m to next header */
104208625Sjkim	int		ip6af_frglen;	/* fragmentable part length */
105208625Sjkim	int		ip6af_off;	/* fragment offset */
106208625Sjkim	u_int16_t	ip6af_mff;	/* more fragment bit in frag off */
107208625Sjkim};
108208625Sjkim
109208625Sjkim#define IP6_REASS_MBUF(ip6af) (*(struct mbuf **)&((ip6af)->ip6af_m))
110208625Sjkim
111208625Sjkimstruct	ip6_moptions {
112208625Sjkim	struct	ifnet *im6o_multicast_ifp; /* ifp for outgoing multicasts */
113208625Sjkim	u_char	im6o_multicast_hlim;	/* hoplimit for outgoing multicasts */
114208625Sjkim	u_char	im6o_multicast_loop;	/* 1 >= hear sends if a member */
115208625Sjkim	LIST_HEAD(, in6_multi_mship) im6o_memberships;
116208625Sjkim};
117208625Sjkim
118208625Sjkim/*
119209746Sjkim * Control options for outgoing packets
120209746Sjkim */
121208625Sjkim
122208625Sjkim/* Routing header related info */
123208625Sjkimstruct	ip6po_rhinfo {
124208625Sjkim	struct	ip6_rthdr *ip6po_rhi_rthdr; /* Routing header */
125208625Sjkim	struct	route_in6 ip6po_rhi_route; /* Route to the 1st hop */
126208625Sjkim};
127208625Sjkim#define ip6po_rthdr	ip6po_rhinfo.ip6po_rhi_rthdr
128208625Sjkim#define ip6po_route	ip6po_rhinfo.ip6po_rhi_route
129208625Sjkim
130208625Sjkimstruct	ip6_pktopts {
131208625Sjkim	struct	mbuf *ip6po_m;	/* Pointer to mbuf storing the data */
132208625Sjkim	int	ip6po_hlim;		/* Hoplimit for outgoing packets */
133208625Sjkim	struct	in6_pktinfo *ip6po_pktinfo; /* Outgoing IF/address information */
134208625Sjkim	struct	sockaddr *ip6po_nexthop;	/* Next-hop address */
135208625Sjkim	struct	ip6_hbh *ip6po_hbh; /* Hop-by-Hop options header */
136208625Sjkim	struct	ip6_dest *ip6po_dest1; /* Destination options header(1st part) */
137208625Sjkim	struct	ip6po_rhinfo ip6po_rhinfo; /* Routing header related info. */
138208625Sjkim	struct	ip6_dest *ip6po_dest2; /* Destination options header(2nd part) */
139208625Sjkim};
140208625Sjkim
141208625Sjkimstruct	ip6stat {
142208625Sjkim	u_quad_t ip6s_total;		/* total packets received */
143208625Sjkim	u_quad_t ip6s_tooshort;		/* packet too short */
144208625Sjkim	u_quad_t ip6s_toosmall;		/* not enough data */
145208625Sjkim	u_quad_t ip6s_fragments;	/* fragments received */
146208625Sjkim	u_quad_t ip6s_fragdropped;	/* frags dropped(dups, out of space) */
147208625Sjkim	u_quad_t ip6s_fragtimeout;	/* fragments timed out */
148208625Sjkim	u_quad_t ip6s_fragoverflow;	/* fragments that exceeded limit */
149208625Sjkim	u_quad_t ip6s_forward;		/* packets forwarded */
150208625Sjkim	u_quad_t ip6s_cantforward;	/* packets rcvd for unreachable dest */
151208625Sjkim	u_quad_t ip6s_redirectsent;	/* packets forwarded on same net */
152208625Sjkim	u_quad_t ip6s_delivered;	/* datagrams delivered to upper level*/
153208625Sjkim	u_quad_t ip6s_localout;		/* total ip packets generated here */
154208625Sjkim	u_quad_t ip6s_odropped;		/* lost packets due to nobufs, etc. */
155208625Sjkim	u_quad_t ip6s_reassembled;	/* total packets reassembled ok */
156208625Sjkim	u_quad_t ip6s_fragmented;	/* datagrams sucessfully fragmented */
157208625Sjkim	u_quad_t ip6s_ofragments;	/* output fragments created */
158208625Sjkim	u_quad_t ip6s_cantfrag;		/* don't fragment flag was set, etc. */
159208625Sjkim	u_quad_t ip6s_badoptions;	/* error in option processing */
160208625Sjkim	u_quad_t ip6s_noroute;		/* packets discarded due to no route */
161208625Sjkim	u_quad_t ip6s_badvers;		/* ip6 version != 6 */
162208625Sjkim	u_quad_t ip6s_rawout;		/* total raw ip packets generated */
163208625Sjkim	u_quad_t ip6s_badscope;		/* scope error */
164208625Sjkim	u_quad_t ip6s_notmember;	/* don't join this multicast group */
165208625Sjkim	u_quad_t ip6s_nxthist[256];	/* next header history */
166208625Sjkim	u_quad_t ip6s_m1;		/* one mbuf */
167208625Sjkim	u_quad_t ip6s_m2m[32];		/* two or more mbuf */
168208625Sjkim	u_quad_t ip6s_mext1;		/* one ext mbuf */
169208625Sjkim	u_quad_t ip6s_mext2m;		/* two or more ext mbuf */
170208625Sjkim	u_quad_t ip6s_exthdrtoolong;	/* ext hdr are not continuous */
171208625Sjkim	u_quad_t ip6s_nogif;		/* no match gif found */
172208625Sjkim	u_quad_t ip6s_toomanyhdr;	/* discarded due to too many headers */
173208625Sjkim	/* XXX the following two items are not really AF_INET6 thing */
174208625Sjkim	u_quad_t ip6s_exthdrget;	/* # of calls to IP6_EXTHDR_GET */
175208625Sjkim	u_quad_t ip6s_exthdrget0;	/* # of calls to IP6_EXTHDR_GET0 */
176208625Sjkim	u_quad_t ip6s_pulldown;		/* # of calls to m_pulldown */
177208625Sjkim	u_quad_t ip6s_pulldown_copy;	/* # of mbuf copies in m_pulldown */
178208625Sjkim	u_quad_t ip6s_pulldown_alloc;	/* # of mbuf allocs in m_pulldown */
179208625Sjkim	u_quad_t ip6s_pullup;		/* # of calls to m_pullup */
180208625Sjkim	u_quad_t ip6s_pullup_copy;	/* # of possible m_pullup copies */
181208625Sjkim	u_quad_t ip6s_pullup_alloc;	/* # of possible m_pullup mallocs */
182208625Sjkim	u_quad_t ip6s_pullup_fail;	/* # of possible m_pullup failures */
183208625Sjkim	u_quad_t ip6s_pullup2;		/* # of calls to m_pullup2 */
184208625Sjkim	u_quad_t ip6s_pullup2_copy;	/* # of possible m_pullup2 copies */
185208625Sjkim	u_quad_t ip6s_pullup2_alloc;	/* # of possible m_pullup2 mallocs */
186209734Sjkim	u_quad_t ip6s_pullup2_fail;	/* # of possible m_pullup2 failures */
187209734Sjkim
188209734Sjkim	/*
189209734Sjkim	 * statistics for improvement of the source address selection
190208625Sjkim	 * algorithm:
191208625Sjkim	 * XXX: hardcoded 16 = # of ip6 multicast scope types + 1
192208625Sjkim	 */
193208625Sjkim	/* number of times that address selection fails */
194208625Sjkim	u_quad_t ip6s_sources_none;
195208625Sjkim	/* number of times that an address on the outgoing I/F is chosen */
196208625Sjkim	u_quad_t ip6s_sources_sameif[16];
197208625Sjkim	/* number of times that an address on a non-outgoing I/F is chosen */
198208625Sjkim	u_quad_t ip6s_sources_otherif[16];
199208625Sjkim	/*
200208625Sjkim	 * number of times that an address that has the same scope
201208625Sjkim	 * from the destination is chosen.
202208625Sjkim	 */
203208625Sjkim	u_quad_t ip6s_sources_samescope[16];
204208625Sjkim	/*
205208625Sjkim	 * number of times that an address that has a different scope
206208625Sjkim	 * from the destination is chosen.
207208625Sjkim	 */
208209734Sjkim	u_quad_t ip6s_sources_otherscope[16];
209208625Sjkim	/* number of times that an deprecated address is chosen */
210208625Sjkim	u_quad_t ip6s_sources_deprecated[16];
211208625Sjkim
212208625Sjkim	u_quad_t ip6s_forward_cachehit;
213208625Sjkim	u_quad_t ip6s_forward_cachemiss;
214208625Sjkim};
215208625Sjkim
216208625Sjkim#ifdef _KERNEL
217208625Sjkim/* flags passed to ip6_output as last parameter */
218208625Sjkim#define	IPV6_DADOUTPUT		0x01	/* DAD */
219208625Sjkim#define	IPV6_FORWARDING		0x02	/* most of IPv6 header exists */
220208625Sjkim#define	IPV6_MINMTU		0x04	/* use minimum MTU (IPV6_USE_MIN_MTU) */
221208625Sjkim
222208625Sjkimextern struct	ip6stat ip6stat;	/* statistics */
223208625Sjkimextern u_int32_t ip6_id;		/* fragment identifier */
224208625Sjkimextern int	ip6_defhlim;		/* default hop limit */
225208625Sjkimextern int	ip6_defmcasthlim;	/* default multicast hop limit */
226208625Sjkimextern int	ip6_forwarding;		/* act as router? */
227208625Sjkimextern int	ip6_forward_srcrt;	/* forward src-routed? */
228208625Sjkimextern int	ip6_gif_hlim;		/* Hop limit for gif encap packet */
229208625Sjkimextern int	ip6_use_deprecated;	/* allow deprecated addr as source */
230208625Sjkimextern int	ip6_rr_prune;		/* router renumbering prefix
231208625Sjkim					 * walk list every 5 sec.    */
232208625Sjkimextern int	ip6_mapped_addr_on;
233208625Sjkim
234208625Sjkimextern struct socket *ip6_mrouter; 	/* multicast routing daemon */
235208625Sjkimextern int	ip6_sendredirects;	/* send IP redirects when forwarding? */
236208625Sjkimextern int	ip6_maxfragpackets; /* Maximum packets in reassembly queue */
237208625Sjkimextern int	ip6_sourcecheck;	/* Verify source interface */
238208625Sjkimextern int	ip6_sourcecheck_interval; /* Interval between log messages */
239208625Sjkimextern int	ip6_accept_rtadv;	/* Acts as a host not a router */
240208625Sjkimextern int	ip6_keepfaith;		/* Firewall Aided Internet Translator */
241208625Sjkimextern int	ip6_log_interval;
242208625Sjkimextern time_t	ip6_log_time;
243208625Sjkimextern int	ip6_hdrnestlimit; /* upper limit of # of extension headers */
244208625Sjkimextern int	ip6_dad_count;		/* DupAddrDetectionTransmits */
245208625Sjkim
246208625Sjkimextern u_int32_t ip6_flow_seq;
247208625Sjkimextern int ip6_auto_flowlabel;
248208625Sjkim
249208625Sjkimextern struct	pr_usrreqs rip6_usrreqs;
250208625Sjkimstruct sockopt;
251209734Sjkim
252209734Sjkimstruct inpcb;
253209734Sjkim
254208625Sjkimint	icmp6_ctloutput __P((struct socket *, struct sockopt *sopt));
255208625Sjkim
256208625Sjkimvoid	ip6_init __P((void));
257208625Sjkimvoid	ip6intr __P((void));
258208625Sjkimvoid	ip6_input __P((struct mbuf *));
259208625Sjkimvoid	ip6_freemoptions __P((struct ip6_moptions *));
260208625Sjkimint	ip6_unknown_opt __P((u_int8_t *, struct mbuf *, int));
261208625Sjkimchar *	ip6_get_prevhdr __P((struct mbuf *, int));
262208625Sjkimint	ip6_nexthdr __P((struct mbuf *, int, int, int *));
263208625Sjkimint	ip6_lasthdr __P((struct mbuf *, int, int, int *));
264208625Sjkimint	ip6_mforward __P((struct ip6_hdr *, struct ifnet *, struct mbuf *));
265208625Sjkimint	ip6_process_hopopts __P((struct mbuf *, u_int8_t *, int, u_int32_t *,
266208625Sjkim				 u_int32_t *));
267208625Sjkimvoid	ip6_savecontrol __P((struct inpcb *, struct mbuf **, struct ip6_hdr *,
268208625Sjkim		struct mbuf *));
269208625Sjkimint	ip6_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
270208625Sjkim
271208625Sjkimvoid	ip6_forward __P((struct mbuf *, int));
272208625Sjkim
273208625Sjkimvoid	ip6_mloopback __P((struct ifnet *, struct mbuf *, struct sockaddr_in6 *));
274208625Sjkimint	ip6_output __P((struct mbuf *, struct ip6_pktopts *,
275208625Sjkim			struct route_in6 *, int,
276208625Sjkim			struct ip6_moptions *, struct ifnet **));
277208625Sjkimint	ip6_ctloutput __P((struct socket *, struct sockopt *sopt));
278208625Sjkimint	ip6_setpktoptions __P((struct mbuf *, struct ip6_pktopts *, int));
279208625Sjkimvoid	ip6_clearpktopts __P((struct ip6_pktopts *, int, int));
280208625Sjkimstruct ip6_pktopts *ip6_copypktopts __P((struct ip6_pktopts *, int));
281208625Sjkimint	ip6_optlen __P((struct inpcb *));
282208625Sjkim
283208625Sjkimint	route6_input __P((struct mbuf **, int *, int));
284208625Sjkim
285208625Sjkimvoid	frag6_init __P((void));
286208625Sjkimint	frag6_input __P((struct mbuf **, int *, int));
287208625Sjkimvoid	frag6_slowtimo __P((void));
288208625Sjkimvoid	frag6_drain __P((void));
289208625Sjkim
290208625Sjkimvoid	rip6_init __P((void));
291208625Sjkimint	rip6_input __P((struct mbuf **mp, int *offp, int proto));
292208625Sjkimvoid	rip6_ctlinput __P((int, struct sockaddr *, void *));
293208625Sjkimint	rip6_ctloutput __P((struct socket *so, struct sockopt *sopt));
294208625Sjkimint	rip6_output __P((struct mbuf *, ...));
295208625Sjkimint	rip6_usrreq __P((struct socket *,
296208625Sjkim	    int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *));
297208625Sjkim
298208625Sjkimint	dest6_input __P((struct mbuf **, int *, int));
299208625Sjkimint	none_input __P((struct mbuf **, int *, int));
300208625Sjkim#endif /* _KERNEL */
301208625Sjkim
302208625Sjkim#endif /* !_NETINET6_IP6_VAR_H_ */
303208625Sjkim