]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/net/if_gre.h
MFC r345177:
[FreeBSD/FreeBSD.git] / sys / net / if_gre.h
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         u_int                   gre_fibnum;
73         u_int                   gre_hlen;       /* header size */
74         union {
75                 void            *hdr;
76 #ifdef INET
77                 struct greip    *gihdr;
78 #endif
79 #ifdef INET6
80                 struct greip6   *gi6hdr;
81 #endif
82         } gre_uhdr;
83         const struct encaptab   *gre_ecookie;
84 };
85 #define GRE2IFP(sc)             ((sc)->gre_ifp)
86 #define GRE_LOCK_INIT(sc)       rm_init(&(sc)->gre_lock, "gre softc")
87 #define GRE_LOCK_DESTROY(sc)    rm_destroy(&(sc)->gre_lock)
88 #define GRE_RLOCK_TRACKER       struct rm_priotracker gre_tracker
89 #define GRE_RLOCK(sc)           rm_rlock(&(sc)->gre_lock, &gre_tracker)
90 #define GRE_RUNLOCK(sc)         rm_runlock(&(sc)->gre_lock, &gre_tracker)
91 #define GRE_RLOCK_ASSERT(sc)    rm_assert(&(sc)->gre_lock, RA_RLOCKED)
92 #define GRE_WLOCK(sc)           rm_wlock(&(sc)->gre_lock)
93 #define GRE_WUNLOCK(sc)         rm_wunlock(&(sc)->gre_lock)
94 #define GRE_WLOCK_ASSERT(sc)    rm_assert(&(sc)->gre_lock, RA_WLOCKED)
95
96 #define gre_hdr                 gre_uhdr.hdr
97 #define gre_gihdr               gre_uhdr.gihdr
98 #define gre_gi6hdr              gre_uhdr.gi6hdr
99 #define gre_oip                 gre_gihdr->gi_ip
100 #define gre_oip6                gre_gi6hdr->gi6_ip6
101
102 int     gre_input(struct mbuf **, int *, int);
103 #ifdef INET
104 int     in_gre_attach(struct gre_softc *);
105 int     in_gre_output(struct mbuf *, int, int);
106 #endif
107 #ifdef INET6
108 int     in6_gre_attach(struct gre_softc *);
109 int     in6_gre_output(struct mbuf *, int, int);
110 #endif
111 /*
112  * CISCO uses special type for GRE tunnel created as part of WCCP
113  * connection, while in fact those packets are just IPv4 encapsulated
114  * into GRE.
115  */
116 #define ETHERTYPE_WCCP          0x883E
117 #endif /* _KERNEL */
118
119 #define GRESADDRS       _IOW('i', 101, struct ifreq)
120 #define GRESADDRD       _IOW('i', 102, struct ifreq)
121 #define GREGADDRS       _IOWR('i', 103, struct ifreq)
122 #define GREGADDRD       _IOWR('i', 104, struct ifreq)
123 #define GRESPROTO       _IOW('i' , 105, struct ifreq)
124 #define GREGPROTO       _IOWR('i', 106, struct ifreq)
125
126 #define GREGKEY         _IOWR('i', 107, struct ifreq)
127 #define GRESKEY         _IOW('i', 108, struct ifreq)
128 #define GREGOPTS        _IOWR('i', 109, struct ifreq)
129 #define GRESOPTS        _IOW('i', 110, struct ifreq)
130
131 #define GRE_ENABLE_CSUM         0x0001
132 #define GRE_ENABLE_SEQ          0x0002
133 #define GRE_OPTMASK             (GRE_ENABLE_CSUM|GRE_ENABLE_SEQ)
134
135 #endif /* _NET_IF_GRE_H_ */