if_gre.h revision 1.28 1 /* $NetBSD: if_gre.h,v 1.28 2007/10/05 04:55:10 dyoung Exp $ */
2
3 /*
4 * Copyright (c) 1998 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 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #ifndef _NET_IF_GRE_H_
40 #define _NET_IF_GRE_H_
41
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 sockaddr_storage sp_src; /* source of gre packets */
51 struct sockaddr_storage sp_dst; /* destination of gre packets */
52 int sp_type; /* encapsulating socket type */
53 int sp_proto; /* encapsulating protocol */
54 int sp_fd;
55 int 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_CONF
63 , GRE_S_WORK
64 , GRE_S_KCONF
65 , GRE_S_DIE
66 , GRE_S_DEAD
67 };
68
69 #define __cacheline_aligned __attribute__((__aligned__(CACHE_LINE_SIZE)))
70
71 struct gre_bufq {
72 volatile int bq_prodidx;
73 volatile int bq_considx;
74 size_t bq_len __cacheline_aligned;
75 size_t bq_lenmask;
76 volatile int bq_drops;
77 struct mbuf **bq_buf;
78 };
79
80 MALLOC_DECLARE(M_GRE_BUFQ);
81
82 struct gre_softc {
83 struct ifnet sc_if;
84 kmutex_t sc_mtx;
85 kcondvar_t sc_condvar;
86 struct gre_bufq sc_snd;
87 struct gre_soparm sc_soparm;
88 struct gre_soparm sc_newsoparm;
89 struct lwp *sc_lwp;
90 volatile enum gre_state sc_state;
91 volatile int sc_waiters;
92 volatile int sc_upcalls;
93 void *sc_si;
94 struct socket *sc_so;
95
96 struct evcnt sc_recv_ev;
97 struct evcnt sc_send_ev;
98 struct evcnt sc_wakeup_ev;
99
100 struct evcnt sc_block_ev;
101 struct evcnt sc_error_ev;
102 struct evcnt sc_pullup_ev;
103 struct evcnt sc_unsupp_ev;
104 struct evcnt sc_oflow_ev;
105 };
106
107 struct gre_h {
108 uint16_t flags; /* GRE flags */
109 uint16_t ptype; /* protocol type of payload typically
110 * ethernet protocol type
111 */
112 /*
113 * from here on: fields are optional, presence indicated by flags
114 *
115 u_int_16 checksum checksum (one-complements of GRE header
116 and payload
117 Present if (ck_pres | rt_pres == 1).
118 Valid if (ck_pres == 1).
119 u_int_16 offset offset from start of routing filed to
120 first octet of active SRE (see below).
121 Present if (ck_pres | rt_pres == 1).
122 Valid if (rt_pres == 1).
123 u_int_32 key inserted by encapsulator e.g. for
124 authentication
125 Present if (key_pres ==1 ).
126 u_int_32 seq_num Sequence number to allow for packet order
127 Present if (seq_pres ==1 ).
128 struct gre_sre[] routing Routing fileds (see below)
129 Present if (rt_pres == 1)
130 */
131 } __attribute__((__packed__));
132
133 #define GRE_CP 0x8000 /* Checksum Present */
134 #define GRE_RP 0x4000 /* Routing Present */
135 #define GRE_KP 0x2000 /* Key Present */
136 #define GRE_SP 0x1000 /* Sequence Present */
137 #define GRE_SS 0x0800 /* Strict Source Route */
138
139 /*
140 * gre_sre defines a Source route Entry. These are needed if packets
141 * should be routed over more than one tunnel hop by hop
142 */
143 struct gre_sre {
144 u_int16_t sre_family; /* address family */
145 u_char sre_offset; /* offset to first octet of active entry */
146 u_char sre_length; /* number of octets in the SRE.
147 sre_lengthl==0 -> last entry. */
148 u_char *sre_rtinfo; /* the routing information */
149 };
150
151 #define GRE_TTL 30
152 extern int ip_gre_ttl;
153 #endif /* _KERNEL */
154
155 /*
156 * ioctls needed to manipulate the interface
157 */
158
159 #define GRESADDRS _IOW('i', 101, struct ifreq)
160 #define GRESADDRD _IOW('i', 102, struct ifreq)
161 #define GREGADDRS _IOWR('i', 103, struct ifreq)
162 #define GREGADDRD _IOWR('i', 104, struct ifreq)
163 #define GRESPROTO _IOW('i' , 105, struct ifreq)
164 #define GREGPROTO _IOWR('i', 106, struct ifreq)
165 #define GRESSOCK _IOW('i' , 107, struct ifreq)
166 #define GREDSOCK _IOW('i' , 108, struct ifreq)
167
168 #endif /* !_NET_IF_GRE_H_ */
169