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