if_gre.h revision 1.37 1 /* $NetBSD: if_gre.h,v 1.37 2008/05/09 20:14:07 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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _NET_IF_GRE_H_
33 #define _NET_IF_GRE_H_
34
35 #include <sys/evcnt.h>
36 #include <sys/queue.h>
37 #include <sys/mutex.h>
38 #include <sys/condvar.h>
39 #include <sys/malloc.h>
40 #include <sys/mallocvar.h>
41
42 #ifdef _KERNEL
43 struct gre_soparm {
44 struct socket *sp_so;
45 struct sockaddr_storage sp_src; /* source of gre packets */
46 struct sockaddr_storage sp_dst; /* destination of gre packets */
47 int sp_type; /* encapsulating socket type */
48 int sp_proto; /* encapsulating protocol */
49 bool sp_bysock; /* encapsulation configured by passing
50 * socket, not by SIOCSLIFPHYADDR
51 */
52 };
53
54 enum gre_state {
55 GRE_S_IDLE = 0
56 , GRE_S_IOCTL
57 , GRE_S_DIE
58 };
59
60 #define __cacheline_aligned __attribute__((__aligned__(CACHE_LINE_SIZE)))
61
62 struct gre_bufq {
63 volatile int bq_prodidx;
64 volatile int bq_considx;
65 size_t bq_len __cacheline_aligned;
66 size_t bq_lenmask;
67 volatile int bq_drops;
68 struct mbuf **bq_buf;
69 };
70
71 MALLOC_DECLARE(M_GRE_BUFQ);
72
73 enum gre_msg {
74 GRE_M_NONE = 0
75 , GRE_M_SETFP
76 , GRE_M_DELFP
77 , GRE_M_STOP
78 , GRE_M_OK
79 , GRE_M_ERR
80 };
81
82 struct gre_softc {
83 struct ifnet sc_if;
84 kmutex_t sc_mtx;
85 kcondvar_t sc_condvar;
86 kcondvar_t sc_fp_condvar;
87 struct gre_bufq sc_snd;
88 struct gre_soparm sc_soparm;
89 volatile enum gre_state sc_state;
90 volatile int sc_waiters;
91 volatile int sc_fp_waiters;
92 void *sc_si;
93
94 struct evcnt sc_recv_ev;
95 struct evcnt sc_send_ev;
96
97 struct evcnt sc_block_ev;
98 struct evcnt sc_error_ev;
99 struct evcnt sc_pullup_ev;
100 struct evcnt sc_unsupp_ev;
101 struct evcnt sc_oflow_ev;
102 file_t * volatile sc_fp;
103 volatile enum gre_msg sc_msg;
104 int sc_fd;
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 } __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 uint16_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