xref: /freebsd/sys/net/if_gre.h (revision f5147e312f43a9050468de539aeafa072caa1a60)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * Copyright (c) 2014 Andrey V. Elsukov <ae@FreeBSD.org>
6  * All rights reserved
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Heiko W.Rupp <hwr@pilhuhn.de>
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  * $NetBSD: if_gre.h,v 1.13 2003/11/10 08:51:52 wiz Exp $
33  * $FreeBSD$
34  */
35 
36 #ifndef _NET_IF_GRE_H_
37 #define _NET_IF_GRE_H_
38 
39 #ifdef _KERNEL
40 /* GRE header according to RFC 2784 and RFC 2890 */
41 struct grehdr {
42 	uint16_t	gre_flags;	/* GRE flags */
43 #define	GRE_FLAGS_CP	0x8000		/* checksum present */
44 #define	GRE_FLAGS_KP	0x2000		/* key present */
45 #define	GRE_FLAGS_SP	0x1000		/* sequence present */
46 #define	GRE_FLAGS_MASK	(GRE_FLAGS_CP|GRE_FLAGS_KP|GRE_FLAGS_SP)
47 	uint16_t	gre_proto;	/* protocol type */
48 	uint32_t	gre_opts[0];	/* optional fields */
49 } __packed;
50 
51 #ifdef INET
52 struct greip {
53 	struct ip	gi_ip;
54 	struct grehdr	gi_gre;
55 } __packed;
56 #endif
57 
58 #ifdef INET6
59 struct greip6 {
60 	struct ip6_hdr	gi6_ip6;
61 	struct grehdr	gi6_gre;
62 } __packed;
63 #endif
64 
65 struct gre_softc {
66 	struct ifnet		*gre_ifp;
67 	LIST_ENTRY(gre_softc)	gre_list;
68 	struct rmlock		gre_lock;
69 	int			gre_family;	/* AF of delivery header */
70 	uint32_t		gre_iseq;
71 	uint32_t		gre_oseq;
72 	uint32_t		gre_key;
73 	uint32_t		gre_options;
74 	u_int			gre_fibnum;
75 	u_int			gre_hlen;	/* header size */
76 	union {
77 		void		*hdr;
78 #ifdef INET
79 		struct greip	*gihdr;
80 #endif
81 #ifdef INET6
82 		struct greip6	*gi6hdr;
83 #endif
84 	} gre_uhdr;
85 	const struct encaptab	*gre_ecookie;
86 };
87 #define	GRE2IFP(sc)		((sc)->gre_ifp)
88 #define	GRE_LOCK_INIT(sc)	rm_init(&(sc)->gre_lock, "gre softc")
89 #define	GRE_LOCK_DESTROY(sc)	rm_destroy(&(sc)->gre_lock)
90 #define	GRE_RLOCK_TRACKER	struct rm_priotracker gre_tracker
91 #define	GRE_RLOCK(sc)		rm_rlock(&(sc)->gre_lock, &gre_tracker)
92 #define	GRE_RUNLOCK(sc)		rm_runlock(&(sc)->gre_lock, &gre_tracker)
93 #define	GRE_RLOCK_ASSERT(sc)	rm_assert(&(sc)->gre_lock, RA_RLOCKED)
94 #define	GRE_WLOCK(sc)		rm_wlock(&(sc)->gre_lock)
95 #define	GRE_WUNLOCK(sc)		rm_wunlock(&(sc)->gre_lock)
96 #define	GRE_WLOCK_ASSERT(sc)	rm_assert(&(sc)->gre_lock, RA_WLOCKED)
97 
98 #define	gre_hdr			gre_uhdr.hdr
99 #define	gre_gihdr		gre_uhdr.gihdr
100 #define	gre_gi6hdr		gre_uhdr.gi6hdr
101 #define	gre_oip			gre_gihdr->gi_ip
102 #define	gre_oip6		gre_gi6hdr->gi6_ip6
103 
104 int	gre_input(struct mbuf **, int *, int);
105 #ifdef INET
106 int	in_gre_attach(struct gre_softc *);
107 int	in_gre_output(struct mbuf *, int, int);
108 #endif
109 #ifdef INET6
110 int	in6_gre_attach(struct gre_softc *);
111 int	in6_gre_output(struct mbuf *, int, int);
112 #endif
113 /*
114  * CISCO uses special type for GRE tunnel created as part of WCCP
115  * connection, while in fact those packets are just IPv4 encapsulated
116  * into GRE.
117  */
118 #define ETHERTYPE_WCCP		0x883E
119 #endif /* _KERNEL */
120 
121 #define GRESADDRS	_IOW('i', 101, struct ifreq)
122 #define GRESADDRD	_IOW('i', 102, struct ifreq)
123 #define GREGADDRS	_IOWR('i', 103, struct ifreq)
124 #define GREGADDRD	_IOWR('i', 104, struct ifreq)
125 #define GRESPROTO	_IOW('i' , 105, struct ifreq)
126 #define GREGPROTO	_IOWR('i', 106, struct ifreq)
127 
128 #define	GREGKEY		_IOWR('i', 107, struct ifreq)
129 #define	GRESKEY		_IOW('i', 108, struct ifreq)
130 #define	GREGOPTS	_IOWR('i', 109, struct ifreq)
131 #define	GRESOPTS	_IOW('i', 110, struct ifreq)
132 
133 #define	GRE_ENABLE_CSUM		0x0001
134 #define	GRE_ENABLE_SEQ		0x0002
135 #define	GRE_OPTMASK		(GRE_ENABLE_CSUM|GRE_ENABLE_SEQ)
136 
137 #endif /* _NET_IF_GRE_H_ */
138