if_gre.h revision 1.45 1 1.45 roy /* $NetBSD: if_gre.h,v 1.45 2021/02/03 05:51:40 roy Exp $ */
2 1.1 hwr
3 1.1 hwr /*
4 1.38 dyoung * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
5 1.36 martin * All rights reserved.
6 1.1 hwr *
7 1.1 hwr * This code is derived from software contributed to The NetBSD Foundation
8 1.1 hwr * by Heiko W.Rupp <hwr (at) pilhuhn.de>
9 1.1 hwr *
10 1.38 dyoung * This code is derived from software contributed to The NetBSD Foundation
11 1.38 dyoung * by David Young <dyoung (at) NetBSD.org>
12 1.38 dyoung *
13 1.1 hwr * Redistribution and use in source and binary forms, with or without
14 1.1 hwr * modification, are permitted provided that the following conditions
15 1.1 hwr * are met:
16 1.1 hwr * 1. Redistributions of source code must retain the above copyright
17 1.1 hwr * notice, this list of conditions and the following disclaimer.
18 1.1 hwr * 2. Redistributions in binary form must reproduce the above copyright
19 1.1 hwr * notice, this list of conditions and the following disclaimer in the
20 1.1 hwr * documentation and/or other materials provided with the distribution.
21 1.14 perry *
22 1.1 hwr * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 1.1 hwr * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 1.1 hwr * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 1.1 hwr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 1.1 hwr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.1 hwr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.1 hwr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.1 hwr * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.1 hwr * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.1 hwr * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.1 hwr * POSSIBILITY OF SUCH DAMAGE.
33 1.38 dyoung *
34 1.38 dyoung * This material is based upon work partially supported by NSF
35 1.38 dyoung * under Contract No. NSF CNS-0626584.
36 1.1 hwr */
37 1.1 hwr
38 1.15 elad #ifndef _NET_IF_GRE_H_
39 1.15 elad #define _NET_IF_GRE_H_
40 1.1 hwr
41 1.43 dholland #include <sys/ioccom.h>
42 1.34 dyoung #include <sys/evcnt.h>
43 1.6 thorpej #include <sys/queue.h>
44 1.22 dyoung #include <sys/mutex.h>
45 1.22 dyoung #include <sys/condvar.h>
46 1.27 dyoung #include <sys/malloc.h>
47 1.27 dyoung #include <sys/mallocvar.h>
48 1.42 drochner
49 1.42 drochner #ifdef _KERNEL
50 1.42 drochner
51 1.41 dyoung #include <sys/pcq.h>
52 1.6 thorpej
53 1.17 dyoung struct gre_soparm {
54 1.37 dyoung struct socket *sp_so;
55 1.27 dyoung struct sockaddr_storage sp_src; /* source of gre packets */
56 1.27 dyoung struct sockaddr_storage sp_dst; /* destination of gre packets */
57 1.27 dyoung int sp_type; /* encapsulating socket type */
58 1.27 dyoung int sp_proto; /* encapsulating protocol */
59 1.37 dyoung bool sp_bysock; /* encapsulation configured by passing
60 1.27 dyoung * socket, not by SIOCSLIFPHYADDR
61 1.27 dyoung */
62 1.17 dyoung };
63 1.17 dyoung
64 1.27 dyoung enum gre_state {
65 1.27 dyoung GRE_S_IDLE = 0
66 1.30 dyoung , GRE_S_IOCTL
67 1.27 dyoung , GRE_S_DIE
68 1.27 dyoung };
69 1.27 dyoung
70 1.27 dyoung struct gre_bufq {
71 1.41 dyoung pcq_t *bq_q;
72 1.27 dyoung volatile int bq_drops;
73 1.27 dyoung };
74 1.27 dyoung
75 1.37 dyoung enum gre_msg {
76 1.37 dyoung GRE_M_NONE = 0
77 1.37 dyoung , GRE_M_SETFP
78 1.37 dyoung , GRE_M_DELFP
79 1.37 dyoung , GRE_M_STOP
80 1.37 dyoung , GRE_M_OK
81 1.37 dyoung , GRE_M_ERR
82 1.37 dyoung };
83 1.37 dyoung
84 1.1 hwr struct gre_softc {
85 1.17 dyoung struct ifnet sc_if;
86 1.22 dyoung kmutex_t sc_mtx;
87 1.27 dyoung kcondvar_t sc_condvar;
88 1.37 dyoung kcondvar_t sc_fp_condvar;
89 1.27 dyoung struct gre_bufq sc_snd;
90 1.18 dyoung struct gre_soparm sc_soparm;
91 1.27 dyoung volatile enum gre_state sc_state;
92 1.27 dyoung volatile int sc_waiters;
93 1.37 dyoung volatile int sc_fp_waiters;
94 1.27 dyoung void *sc_si;
95 1.27 dyoung
96 1.27 dyoung struct evcnt sc_recv_ev;
97 1.27 dyoung struct evcnt sc_send_ev;
98 1.27 dyoung
99 1.27 dyoung struct evcnt sc_block_ev;
100 1.27 dyoung struct evcnt sc_error_ev;
101 1.27 dyoung struct evcnt sc_pullup_ev;
102 1.27 dyoung struct evcnt sc_unsupp_ev;
103 1.27 dyoung struct evcnt sc_oflow_ev;
104 1.37 dyoung file_t * volatile sc_fp;
105 1.37 dyoung volatile enum gre_msg sc_msg;
106 1.37 dyoung int sc_fd;
107 1.14 perry };
108 1.25 dyoung
109 1.1 hwr struct gre_h {
110 1.27 dyoung uint16_t flags; /* GRE flags */
111 1.27 dyoung uint16_t ptype; /* protocol type of payload typically
112 1.27 dyoung * ethernet protocol type
113 1.27 dyoung */
114 1.14 perry /*
115 1.14 perry * from here on: fields are optional, presence indicated by flags
116 1.1 hwr *
117 1.9 itojun u_int_16 checksum checksum (one-complements of GRE header
118 1.9 itojun and payload
119 1.9 itojun Present if (ck_pres | rt_pres == 1).
120 1.9 itojun Valid if (ck_pres == 1).
121 1.9 itojun u_int_16 offset offset from start of routing filed to
122 1.9 itojun first octet of active SRE (see below).
123 1.9 itojun Present if (ck_pres | rt_pres == 1).
124 1.9 itojun Valid if (rt_pres == 1).
125 1.9 itojun u_int_32 key inserted by encapsulator e.g. for
126 1.9 itojun authentication
127 1.9 itojun Present if (key_pres ==1 ).
128 1.9 itojun u_int_32 seq_num Sequence number to allow for packet order
129 1.9 itojun Present if (seq_pres ==1 ).
130 1.9 itojun struct gre_sre[] routing Routing fileds (see below)
131 1.9 itojun Present if (rt_pres == 1)
132 1.9 itojun */
133 1.45 roy };
134 1.1 hwr
135 1.9 itojun #define GRE_CP 0x8000 /* Checksum Present */
136 1.9 itojun #define GRE_RP 0x4000 /* Routing Present */
137 1.9 itojun #define GRE_KP 0x2000 /* Key Present */
138 1.9 itojun #define GRE_SP 0x1000 /* Sequence Present */
139 1.1 hwr #define GRE_SS 0x0800 /* Strict Source Route */
140 1.1 hwr
141 1.9 itojun /*
142 1.9 itojun * gre_sre defines a Source route Entry. These are needed if packets
143 1.9 itojun * should be routed over more than one tunnel hop by hop
144 1.1 hwr */
145 1.1 hwr struct gre_sre {
146 1.35 matt uint16_t sre_family; /* address family */
147 1.9 itojun u_char sre_offset; /* offset to first octet of active entry */
148 1.14 perry u_char sre_length; /* number of octets in the SRE.
149 1.9 itojun sre_lengthl==0 -> last entry. */
150 1.9 itojun u_char *sre_rtinfo; /* the routing information */
151 1.1 hwr };
152 1.1 hwr
153 1.10 martin #define GRE_TTL 30
154 1.10 martin extern int ip_gre_ttl;
155 1.17 dyoung #endif /* _KERNEL */
156 1.2 hwr
157 1.14 perry /*
158 1.14 perry * ioctls needed to manipulate the interface
159 1.2 hwr */
160 1.2 hwr
161 1.44 msaitoh #define GRESADDRS _IOW('i', 101, struct ifreq)
162 1.44 msaitoh #define GRESADDRD _IOW('i', 102, struct ifreq)
163 1.9 itojun #define GREGADDRS _IOWR('i', 103, struct ifreq)
164 1.9 itojun #define GREGADDRD _IOWR('i', 104, struct ifreq)
165 1.44 msaitoh #define GRESPROTO _IOW('i', 105, struct ifreq)
166 1.9 itojun #define GREGPROTO _IOWR('i', 106, struct ifreq)
167 1.44 msaitoh #define GRESSOCK _IOW('i', 107, struct ifreq)
168 1.44 msaitoh #define GREDSOCK _IOW('i', 108, struct ifreq)
169 1.2 hwr
170 1.15 elad #endif /* !_NET_IF_GRE_H_ */
171