if_gre.h revision 1.30 1 /* $NetBSD: if_gre.h,v 1.30 2007/10/06 03:30:26 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/device.h>
43 #include <sys/queue.h>
44 #include <sys/mutex.h>
45 #include <sys/condvar.h>
46 #include <sys/malloc.h>
47 #include <sys/mallocvar.h>
48
49 #ifdef _KERNEL
50 struct gre_soparm {
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 int sp_fd;
56 int sp_bysock; /* encapsulation configured by passing
57 * socket, not by SIOCSLIFPHYADDR
58 */
59 };
60
61 enum gre_state {
62 GRE_S_IDLE = 0
63 , GRE_S_IOCTL
64 , GRE_S_DOCONF
65 , GRE_S_DIE
66 };
67
68 #define __cacheline_aligned __attribute__((__aligned__(CACHE_LINE_SIZE)))
69
70 struct gre_bufq {
71 volatile int bq_prodidx;
72 volatile int bq_considx;
73 size_t bq_len __cacheline_aligned;
74 size_t bq_lenmask;
75 volatile int bq_drops;
76 struct mbuf **bq_buf;
77 };
78
79 MALLOC_DECLARE(M_GRE_BUFQ);
80
81 struct gre_softc {
82 struct ifnet sc_if;
83 kmutex_t sc_mtx;
84 kcondvar_t sc_condvar;
85 struct gre_bufq sc_snd;
86 struct gre_soparm sc_soparm;
87 struct lwp *sc_lwp;
88 volatile enum gre_state sc_state;
89 volatile int sc_waiters;
90 volatile int sc_upcalls;
91 void *sc_si;
92 struct socket *sc_so;
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 };
103
104 struct gre_h {
105 uint16_t flags; /* GRE flags */
106 uint16_t ptype; /* protocol type of payload typically
107 * ethernet protocol type
108 */
109 /*
110 * from here on: fields are optional, presence indicated by flags
111 *
112 u_int_16 checksum checksum (one-complements of GRE header
113 and payload
114 Present if (ck_pres | rt_pres == 1).
115 Valid if (ck_pres == 1).
116 u_int_16 offset offset from start of routing filed to
117 first octet of active SRE (see below).
118 Present if (ck_pres | rt_pres == 1).
119 Valid if (rt_pres == 1).
120 u_int_32 key inserted by encapsulator e.g. for
121 authentication
122 Present if (key_pres ==1 ).
123 u_int_32 seq_num Sequence number to allow for packet order
124 Present if (seq_pres ==1 ).
125 struct gre_sre[] routing Routing fileds (see below)
126 Present if (rt_pres == 1)
127 */
128 } __attribute__((__packed__));
129
130 #define GRE_CP 0x8000 /* Checksum Present */
131 #define GRE_RP 0x4000 /* Routing Present */
132 #define GRE_KP 0x2000 /* Key Present */
133 #define GRE_SP 0x1000 /* Sequence Present */
134 #define GRE_SS 0x0800 /* Strict Source Route */
135
136 /*
137 * gre_sre defines a Source route Entry. These are needed if packets
138 * should be routed over more than one tunnel hop by hop
139 */
140 struct gre_sre {
141 u_int16_t sre_family; /* address family */
142 u_char sre_offset; /* offset to first octet of active entry */
143 u_char sre_length; /* number of octets in the SRE.
144 sre_lengthl==0 -> last entry. */
145 u_char *sre_rtinfo; /* the routing information */
146 };
147
148 #define GRE_TTL 30
149 extern int ip_gre_ttl;
150 #endif /* _KERNEL */
151
152 /*
153 * ioctls needed to manipulate the interface
154 */
155
156 #define GRESADDRS _IOW('i', 101, struct ifreq)
157 #define GRESADDRD _IOW('i', 102, struct ifreq)
158 #define GREGADDRS _IOWR('i', 103, struct ifreq)
159 #define GREGADDRD _IOWR('i', 104, struct ifreq)
160 #define GRESPROTO _IOW('i' , 105, struct ifreq)
161 #define GREGPROTO _IOWR('i', 106, struct ifreq)
162 #define GRESSOCK _IOW('i' , 107, struct ifreq)
163 #define GREDSOCK _IOW('i' , 108, struct ifreq)
164
165 #endif /* !_NET_IF_GRE_H_ */
166