1139823Simp/*-
2103026Ssobomax * Copyright (c) 1998 The NetBSD Foundation, Inc.
3284066Sae * Copyright (c) 2014 Andrey V. Elsukov <ae@FreeBSD.org>
4103026Ssobomax * All rights reserved
5103026Ssobomax *
6103026Ssobomax * This code is derived from software contributed to The NetBSD Foundation
7103026Ssobomax * by Heiko W.Rupp <hwr@pilhuhn.de>
8103026Ssobomax *
9103026Ssobomax * Redistribution and use in source and binary forms, with or without
10103026Ssobomax * modification, are permitted provided that the following conditions
11103026Ssobomax * are met:
12103026Ssobomax * 1. Redistributions of source code must retain the above copyright
13103026Ssobomax *    notice, this list of conditions and the following disclaimer.
14103026Ssobomax * 2. Redistributions in binary form must reproduce the above copyright
15103026Ssobomax *    notice, this list of conditions and the following disclaimer in the
16103026Ssobomax *    documentation and/or other materials provided with the distribution.
17125020Ssobomax *
18103026Ssobomax * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19103026Ssobomax * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20103026Ssobomax * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21103026Ssobomax * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22103026Ssobomax * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23103026Ssobomax * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24103026Ssobomax * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25103026Ssobomax * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26103026Ssobomax * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27103026Ssobomax * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28103026Ssobomax * POSSIBILITY OF SUCH DAMAGE.
29284066Sae *
30284066Sae * $NetBSD: if_gre.h,v 1.13 2003/11/10 08:51:52 wiz Exp $
31284066Sae * $FreeBSD$
32103026Ssobomax */
33103026Ssobomax
34284066Sae#ifndef _NET_IF_GRE_H_
35284066Sae#define _NET_IF_GRE_H_
36103026Ssobomax
37103120Ssobomax#ifdef _KERNEL
38284066Sae/* GRE header according to RFC 2784 and RFC 2890 */
39284066Saestruct grehdr {
40284066Sae	uint16_t	gre_flags;	/* GRE flags */
41284066Sae#define	GRE_FLAGS_CP	0x8000		/* checksum present */
42284066Sae#define	GRE_FLAGS_KP	0x2000		/* key present */
43284066Sae#define	GRE_FLAGS_SP	0x1000		/* sequence present */
44284066Sae#define	GRE_FLAGS_MASK	(GRE_FLAGS_CP|GRE_FLAGS_KP|GRE_FLAGS_SP)
45284066Sae	uint16_t	gre_proto;	/* protocol type */
46284066Sae	uint32_t	gre_opts[0];	/* optional fields */
47103842Salfred} __packed;
48103026Ssobomax
49284066Sae#ifdef INET
50103026Ssobomaxstruct greip {
51284066Sae	struct ip	gi_ip;
52284066Sae	struct grehdr	gi_gre;
53103842Salfred} __packed;
54284066Sae#endif
55103026Ssobomax
56284066Sae#ifdef INET6
57284066Saestruct greip6 {
58284066Sae	struct ip6_hdr	gi6_ip6;
59284066Sae	struct grehdr	gi6_gre;
60284066Sae} __packed;
61284066Sae#endif
62103026Ssobomax
63284066Saestruct gre_softc {
64284066Sae	struct ifnet		*gre_ifp;
65284066Sae	LIST_ENTRY(gre_softc)	gre_list;
66284066Sae	struct rmlock		gre_lock;
67284066Sae	int			gre_family;	/* AF of delivery header */
68284066Sae	uint32_t		gre_iseq;
69284066Sae	uint32_t		gre_oseq;
70284066Sae	uint32_t		gre_key;
71284066Sae	uint32_t		gre_options;
72284066Sae	uint32_t		gre_mtu;
73284066Sae	u_int			gre_fibnum;
74284066Sae	u_int			gre_hlen;	/* header size */
75284066Sae	union {
76284066Sae		void		*hdr;
77284066Sae#ifdef INET
78284066Sae		struct greip	*gihdr;
79284066Sae#endif
80284066Sae#ifdef INET6
81284066Sae		struct greip6	*gi6hdr;
82284066Sae#endif
83284066Sae	} gre_uhdr;
84284066Sae	const struct encaptab	*gre_ecookie;
85284066Sae};
86284066Sae#define	GRE2IFP(sc)		((sc)->gre_ifp)
87284066Sae#define	GRE_LOCK_INIT(sc)	rm_init(&(sc)->gre_lock, "gre softc")
88284066Sae#define	GRE_LOCK_DESTROY(sc)	rm_destroy(&(sc)->gre_lock)
89284066Sae#define	GRE_RLOCK_TRACKER	struct rm_priotracker gre_tracker
90284066Sae#define	GRE_RLOCK(sc)		rm_rlock(&(sc)->gre_lock, &gre_tracker)
91284066Sae#define	GRE_RUNLOCK(sc)		rm_runlock(&(sc)->gre_lock, &gre_tracker)
92284066Sae#define	GRE_RLOCK_ASSERT(sc)	rm_assert(&(sc)->gre_lock, RA_RLOCKED)
93284066Sae#define	GRE_WLOCK(sc)		rm_wlock(&(sc)->gre_lock)
94284066Sae#define	GRE_WUNLOCK(sc)		rm_wunlock(&(sc)->gre_lock)
95284066Sae#define	GRE_WLOCK_ASSERT(sc)	rm_assert(&(sc)->gre_lock, RA_WLOCKED)
96103026Ssobomax
97284066Sae#define	gre_hdr			gre_uhdr.hdr
98284066Sae#define	gre_gihdr		gre_uhdr.gihdr
99284066Sae#define	gre_gi6hdr		gre_uhdr.gi6hdr
100284066Sae#define	gre_oip			gre_gihdr->gi_ip
101284066Sae#define	gre_oip6		gre_gi6hdr->gi6_ip6
102284066Sae
103284072Saeint	gre_input(struct mbuf **, int *, int);
104284072Sae#ifdef INET
105284072Saeint	in_gre_attach(struct gre_softc *);
106284072Saeint	in_gre_output(struct mbuf *, int, int);
107284072Sae#endif
108284072Sae#ifdef INET6
109284072Saeint	in6_gre_attach(struct gre_softc *);
110284072Saeint	in6_gre_output(struct mbuf *, int, int);
111284072Sae#endif
112103026Ssobomax/*
113107670Ssobomax * CISCO uses special type for GRE tunnel created as part of WCCP
114107670Ssobomax * connection, while in fact those packets are just IPv4 encapsulated
115107670Ssobomax * into GRE.
116107670Ssobomax */
117284066Sae#define ETHERTYPE_WCCP		0x883E
118103120Ssobomax#endif /* _KERNEL */
119103120Ssobomax
120103026Ssobomax#define GRESADDRS	_IOW('i', 101, struct ifreq)
121125020Ssobomax#define GRESADDRD	_IOW('i', 102, struct ifreq)
122103026Ssobomax#define GREGADDRS	_IOWR('i', 103, struct ifreq)
123103026Ssobomax#define GREGADDRD	_IOWR('i', 104, struct ifreq)
124103026Ssobomax#define GRESPROTO	_IOW('i' , 105, struct ifreq)
125103026Ssobomax#define GREGPROTO	_IOWR('i', 106, struct ifreq)
126103026Ssobomax
127284066Sae#define	GREGKEY		_IOWR('i', 107, struct ifreq)
128284066Sae#define	GRESKEY		_IOW('i', 108, struct ifreq)
129284066Sae#define	GREGOPTS	_IOWR('i', 109, struct ifreq)
130284066Sae#define	GRESOPTS	_IOW('i', 110, struct ifreq)
131103026Ssobomax
132284066Sae#define	GRE_ENABLE_CSUM		0x0001
133284066Sae#define	GRE_ENABLE_SEQ		0x0002
134284066Sae#define	GRE_OPTMASK		(GRE_ENABLE_CSUM|GRE_ENABLE_SEQ)
135284018Sae
136284066Sae#endif /* _NET_IF_GRE_H_ */
137