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