xref: /freebsd/sys/net/if_gif.h (revision 009d82ee0fefdc797f55d25a50d3b6ebe61d56e4)
1686cdd19SJun-ichiro itojun Hagino /*	$FreeBSD$	*/
233841545SHajimu UMEMOTO /*	$KAME: if_gif.h,v 1.17 2000/09/11 11:36:41 sumikawa Exp $	*/
3686cdd19SJun-ichiro itojun Hagino 
4c398230bSWarner Losh /*-
551369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
651369649SPedro F. Giffuni  *
782cd038dSYoshinobu Inoue  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
8b941bc1dSAndrey V. Elsukov  * Copyright (c) 2018 Andrey V. Elsukov <ae@FreeBSD.org>
982cd038dSYoshinobu Inoue  * All rights reserved.
1082cd038dSYoshinobu Inoue  *
1182cd038dSYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
1282cd038dSYoshinobu Inoue  * modification, are permitted provided that the following conditions
1382cd038dSYoshinobu Inoue  * are met:
1482cd038dSYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
1582cd038dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
1682cd038dSYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
1782cd038dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
1882cd038dSYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
1982cd038dSYoshinobu Inoue  * 3. Neither the name of the project nor the names of its contributors
2082cd038dSYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
2182cd038dSYoshinobu Inoue  *    without specific prior written permission.
2282cd038dSYoshinobu Inoue  *
2382cd038dSYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
2482cd038dSYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2582cd038dSYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2682cd038dSYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2782cd038dSYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2882cd038dSYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2982cd038dSYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3082cd038dSYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3182cd038dSYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3282cd038dSYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3382cd038dSYoshinobu Inoue  * SUCH DAMAGE.
3482cd038dSYoshinobu Inoue  */
3582cd038dSYoshinobu Inoue 
3682cd038dSYoshinobu Inoue #ifndef _NET_IF_GIF_H_
3782cd038dSYoshinobu Inoue #define _NET_IF_GIF_H_
3882cd038dSYoshinobu Inoue 
3920af0ffaSBrooks Davis #ifdef _KERNEL
40686cdd19SJun-ichiro itojun Hagino 
410b9f5f8aSAndrey V. Elsukov struct ip;
420b9f5f8aSAndrey V. Elsukov struct ip6_hdr;
43686cdd19SJun-ichiro itojun Hagino 
4494408d94SBrooks Davis extern	void (*ng_gif_input_p)(struct ifnet *ifp, struct mbuf **mp,
4594408d94SBrooks Davis 		int af);
4694408d94SBrooks Davis extern	void (*ng_gif_input_orphan_p)(struct ifnet *ifp, struct mbuf *m,
4794408d94SBrooks Davis 		int af);
4894408d94SBrooks Davis extern	int  (*ng_gif_output_p)(struct ifnet *ifp, struct mbuf **mp);
4994408d94SBrooks Davis extern	void (*ng_gif_attach_p)(struct ifnet *ifp);
5094408d94SBrooks Davis extern	void (*ng_gif_detach_p)(struct ifnet *ifp);
5194408d94SBrooks Davis 
5282cd038dSYoshinobu Inoue struct gif_softc {
53fc74a9f9SBrooks Davis 	struct ifnet		*gif_ifp;
540b9f5f8aSAndrey V. Elsukov 	int			gif_family;
5582cd038dSYoshinobu Inoue 	int			gif_flags;
568b07e49aSJulian Elischer 	u_int			gif_fibnum;
57dbe59260SHiroki Sato 	u_int			gif_options;
580b9f5f8aSAndrey V. Elsukov 	void			*gif_netgraph;	/* netgraph node info */
590b9f5f8aSAndrey V. Elsukov 	union {
600b9f5f8aSAndrey V. Elsukov 		void		*hdr;
610b9f5f8aSAndrey V. Elsukov 		struct ip	*iphdr;
620b9f5f8aSAndrey V. Elsukov 		struct ip6_hdr	*ip6hdr;
630b9f5f8aSAndrey V. Elsukov 	} gif_uhdr;
6482cd038dSYoshinobu Inoue 
65b941bc1dSAndrey V. Elsukov 	CK_LIST_ENTRY(gif_softc) chain;
66*009d82eeSAndrey V. Elsukov 	CK_LIST_ENTRY(gif_softc) srchash;
67b941bc1dSAndrey V. Elsukov };
68b941bc1dSAndrey V. Elsukov CK_LIST_HEAD(gif_list, gif_softc);
69b941bc1dSAndrey V. Elsukov MALLOC_DECLARE(M_GIF);
70b941bc1dSAndrey V. Elsukov 
71b941bc1dSAndrey V. Elsukov #ifndef GIF_HASH_SIZE
72b941bc1dSAndrey V. Elsukov #define	GIF_HASH_SIZE	(1 << 4)
73b941bc1dSAndrey V. Elsukov #endif
74b941bc1dSAndrey V. Elsukov 
75b941bc1dSAndrey V. Elsukov #define	GIF2IFP(sc)	((sc)->gif_ifp)
760b9f5f8aSAndrey V. Elsukov #define	gif_iphdr	gif_uhdr.iphdr
770b9f5f8aSAndrey V. Elsukov #define	gif_hdr		gif_uhdr.hdr
780b9f5f8aSAndrey V. Elsukov #define	gif_ip6hdr	gif_uhdr.ip6hdr
7982cd038dSYoshinobu Inoue 
8082cd038dSYoshinobu Inoue #define GIF_MTU		(1280)	/* Default MTU */
8182cd038dSYoshinobu Inoue #define	GIF_MTU_MIN	(1280)	/* Minimum MTU */
8282cd038dSYoshinobu Inoue #define	GIF_MTU_MAX	(8192)	/* Maximum MTU */
8382cd038dSYoshinobu Inoue 
8473ff045cSAndrew Thompson struct etherip_header {
85dbe59260SHiroki Sato #if BYTE_ORDER == LITTLE_ENDIAN
86dbe59260SHiroki Sato 	u_int	eip_resvl:4,	/* reserved */
87dbe59260SHiroki Sato 		eip_ver:4;	/* version */
88dbe59260SHiroki Sato #endif
89dbe59260SHiroki Sato #if BYTE_ORDER == BIG_ENDIAN
90dbe59260SHiroki Sato 	u_int	eip_ver:4,	/* version */
91dbe59260SHiroki Sato 		eip_resvl:4;	/* reserved */
92dbe59260SHiroki Sato #endif
93dbe59260SHiroki Sato 	u_int8_t eip_resvh;	/* reserved */
94dbe59260SHiroki Sato } __packed;
95dbe59260SHiroki Sato 
96dbe59260SHiroki Sato #define ETHERIP_VERSION			0x3
97c89c8a10SMarius Strobl /* mbuf adjust factor to force 32-bit alignment of IP header */
98c89c8a10SMarius Strobl #define	ETHERIP_ALIGN		2
9973ff045cSAndrew Thompson 
1006573d758SMatt Macy #define	GIF_RLOCK()	struct epoch_tracker gif_et; epoch_enter_preempt(net_epoch_preempt, &gif_et)
1016573d758SMatt Macy #define	GIF_RUNLOCK()	epoch_exit_preempt(net_epoch_preempt, &gif_et)
102b941bc1dSAndrey V. Elsukov #define	GIF_WAIT()	epoch_wait_preempt(net_epoch_preempt)
103b941bc1dSAndrey V. Elsukov 
10482cd038dSYoshinobu Inoue /* Prototypes */
105b941bc1dSAndrey V. Elsukov struct gif_list *gif_hashinit(void);
106b941bc1dSAndrey V. Elsukov void gif_hashdestroy(struct gif_list *);
107b941bc1dSAndrey V. Elsukov 
1080b9f5f8aSAndrey V. Elsukov void gif_input(struct mbuf *, struct ifnet *, int, uint8_t);
10947e8d432SGleb Smirnoff int gif_output(struct ifnet *, struct mbuf *, const struct sockaddr *,
110279aa3d4SKip Macy 	       struct route *);
111b941bc1dSAndrey V. Elsukov 
112b941bc1dSAndrey V. Elsukov void in_gif_init(void);
113b941bc1dSAndrey V. Elsukov void in_gif_uninit(void);
114f188f14dSAndrey V. Elsukov int in_gif_output(struct ifnet *, struct mbuf *, int, uint8_t);
115b941bc1dSAndrey V. Elsukov int in_gif_ioctl(struct gif_softc *, u_long, caddr_t);
116b941bc1dSAndrey V. Elsukov int in_gif_setopts(struct gif_softc *, u_int);
117b941bc1dSAndrey V. Elsukov 
118b941bc1dSAndrey V. Elsukov void in6_gif_init(void);
119b941bc1dSAndrey V. Elsukov void in6_gif_uninit(void);
120f188f14dSAndrey V. Elsukov int in6_gif_output(struct ifnet *, struct mbuf *, int, uint8_t);
121b941bc1dSAndrey V. Elsukov int in6_gif_ioctl(struct gif_softc *, u_long, caddr_t);
122b941bc1dSAndrey V. Elsukov int in6_gif_setopts(struct gif_softc *, u_int);
12320af0ffaSBrooks Davis #endif /* _KERNEL */
12420af0ffaSBrooks Davis 
125fb70e72bSHiroki Sato #define GIFGOPTS	_IOWR('i', 150, struct ifreq)
126dbe59260SHiroki Sato #define GIFSOPTS	_IOW('i', 151, struct ifreq)
127dbe59260SHiroki Sato 
128c1b4f79dSAndrey V. Elsukov #define	GIF_IGNORE_SOURCE	0x0002
129b1c250ffSHiroki Sato #define	GIF_OPTMASK		(GIF_IGNORE_SOURCE)
130dbe59260SHiroki Sato 
13182cd038dSYoshinobu Inoue #endif /* _NET_IF_GIF_H_ */
132