162587Sitojun/*	$FreeBSD$	*/
278064Sume/*	$KAME: if_gif.h,v 1.17 2000/09/11 11:36:41 sumikawa Exp $	*/
362587Sitojun
4139823Simp/*-
553541Sshin * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
653541Sshin * All rights reserved.
753541Sshin *
853541Sshin * Redistribution and use in source and binary forms, with or without
953541Sshin * modification, are permitted provided that the following conditions
1053541Sshin * are met:
1153541Sshin * 1. Redistributions of source code must retain the above copyright
1253541Sshin *    notice, this list of conditions and the following disclaimer.
1353541Sshin * 2. Redistributions in binary form must reproduce the above copyright
1453541Sshin *    notice, this list of conditions and the following disclaimer in the
1553541Sshin *    documentation and/or other materials provided with the distribution.
1653541Sshin * 3. Neither the name of the project nor the names of its contributors
1753541Sshin *    may be used to endorse or promote products derived from this software
1853541Sshin *    without specific prior written permission.
1953541Sshin *
2053541Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
2153541Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2253541Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2353541Sshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2453541Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2553541Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2653541Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2753541Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2853541Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2953541Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3053541Sshin * SUCH DAMAGE.
3153541Sshin */
3253541Sshin
3353541Sshin/*
3453541Sshin * if_gif.h
3553541Sshin */
3653541Sshin
3753541Sshin#ifndef _NET_IF_GIF_H_
3853541Sshin#define _NET_IF_GIF_H_
3953541Sshin
4062587Sitojun
4183997Sbrooks#ifdef _KERNEL
4262587Sitojun#include "opt_inet.h"
4383997Sbrooks#include "opt_inet6.h"
4462587Sitojun
4562587Sitojun#include <netinet/in.h>
4662587Sitojun/* xxx sigh, why route have struct route instead of pointer? */
4762587Sitojun
4862587Sitojunstruct encaptab;
4962587Sitojun
5083998Sbrooksextern	void (*ng_gif_input_p)(struct ifnet *ifp, struct mbuf **mp,
5183998Sbrooks		int af);
5283998Sbrooksextern	void (*ng_gif_input_orphan_p)(struct ifnet *ifp, struct mbuf *m,
5383998Sbrooks		int af);
5483998Sbrooksextern	int  (*ng_gif_output_p)(struct ifnet *ifp, struct mbuf **mp);
5583998Sbrooksextern	void (*ng_gif_attach_p)(struct ifnet *ifp);
5683998Sbrooksextern	void (*ng_gif_detach_p)(struct ifnet *ifp);
5783998Sbrooks
5853541Sshinstruct gif_softc {
59147256Sbrooks	struct ifnet	*gif_ifp;
60155037Sglebius	struct mtx	gif_mtx;
6162587Sitojun	struct sockaddr	*gif_psrc; /* Physical src addr */
6262587Sitojun	struct sockaddr	*gif_pdst; /* Physical dst addr */
6353541Sshin	union {
6462587Sitojun		struct route  gifscr_ro;    /* xxx */
6562587Sitojun#ifdef INET6
6662587Sitojun		struct route_in6 gifscr_ro6; /* xxx */
6762587Sitojun#endif
6853541Sshin	} gifsc_gifscr;
6962587Sitojun	int		gif_flags;
70178888Sjulian	u_int		gif_fibnum;
7162587Sitojun	const struct encaptab *encap_cookie4;
7262587Sitojun	const struct encaptab *encap_cookie6;
7383998Sbrooks	void		*gif_netgraph;	/* ng_gif(4) netgraph node info */
74193664Shrs	u_int		gif_options;
75105293Sume	LIST_ENTRY(gif_softc) gif_list; /* all gif's are linked */
7653541Sshin};
77147256Sbrooks#define	GIF2IFP(sc)	((sc)->gif_ifp)
78155037Sglebius#define	GIF_LOCK_INIT(sc)	mtx_init(&(sc)->gif_mtx, "gif softc",	\
79155037Sglebius				     NULL, MTX_DEF)
80155037Sglebius#define	GIF_LOCK_DESTROY(sc)	mtx_destroy(&(sc)->gif_mtx)
81155037Sglebius#define	GIF_LOCK(sc)		mtx_lock(&(sc)->gif_mtx)
82155037Sglebius#define	GIF_UNLOCK(sc)		mtx_unlock(&(sc)->gif_mtx)
83155037Sglebius#define	GIF_LOCK_ASSERT(sc)	mtx_assert(&(sc)->gif_mtx, MA_OWNED)
8453541Sshin
8562587Sitojun#define gif_ro gifsc_gifscr.gifscr_ro
8662587Sitojun#ifdef INET6
8762587Sitojun#define gif_ro6 gifsc_gifscr.gifscr_ro6
8862587Sitojun#endif
8953541Sshin
9062587Sitojun#define GIF_MTU		(1280)	/* Default MTU */
9153541Sshin#define	GIF_MTU_MIN	(1280)	/* Minimum MTU */
9253541Sshin#define	GIF_MTU_MAX	(8192)	/* Maximum MTU */
9353541Sshin
94127898Sru#define	MTAG_GIF	1080679712
95127898Sru#define	MTAG_GIF_CALLED	0
96127898Sru
97153621Sthompsastruct etherip_header {
98193664Shrs#if BYTE_ORDER == LITTLE_ENDIAN
99193664Shrs	u_int	eip_resvl:4,	/* reserved */
100193664Shrs		eip_ver:4;	/* version */
101193664Shrs#endif
102193664Shrs#if BYTE_ORDER == BIG_ENDIAN
103193664Shrs	u_int	eip_ver:4,	/* version */
104193664Shrs		eip_resvl:4;	/* reserved */
105193664Shrs#endif
106193664Shrs	u_int8_t eip_resvh;	/* reserved */
107193664Shrs} __packed;
108193664Shrs
109193664Shrs#define ETHERIP_VERSION			0x3
110189494Smarius/* mbuf adjust factor to force 32-bit alignment of IP header */
111189494Smarius#define	ETHERIP_ALIGN		2
112153621Sthompsa
11353541Sshin/* Prototypes */
11492725Salfredvoid gif_input(struct mbuf *, int, struct ifnet *);
115249925Sglebiusint gif_output(struct ifnet *, struct mbuf *, const struct sockaddr *,
116191148Skmacy	       struct route *);
11792725Salfredint gif_ioctl(struct ifnet *, u_long, caddr_t);
118105293Sumeint gif_set_tunnel(struct ifnet *, struct sockaddr *, struct sockaddr *);
119105293Sumevoid gif_delete_tunnel(struct ifnet *);
120105293Sumeint gif_encapcheck(const struct mbuf *, int, int, void *);
12183997Sbrooks#endif /* _KERNEL */
12283997Sbrooks
123193796Shrs#define GIFGOPTS	_IOWR('i', 150, struct ifreq)
124193664Shrs#define GIFSOPTS	_IOW('i', 151, struct ifreq)
125193664Shrs
126193664Shrs#define	GIF_ACCEPT_REVETHIP	0x0001
127193664Shrs#define	GIF_SEND_REVETHIP	0x0010
128193796Shrs#define	GIF_OPTMASK		(GIF_ACCEPT_REVETHIP|GIF_SEND_REVETHIP)
129193664Shrs
13053541Sshin#endif /* _NET_IF_GIF_H_ */
131