if_gre.h revision 1.41 1 1.41 dyoung /* $NetBSD: if_gre.h,v 1.41 2011/11/02 01:17:59 dyoung 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.34 dyoung #include <sys/evcnt.h>
42 1.6 thorpej #include <sys/queue.h>
43 1.22 dyoung #include <sys/mutex.h>
44 1.22 dyoung #include <sys/condvar.h>
45 1.27 dyoung #include <sys/malloc.h>
46 1.27 dyoung #include <sys/mallocvar.h>
47 1.41 dyoung #include <sys/pcq.h>
48 1.6 thorpej
49 1.17 dyoung #ifdef _KERNEL
50 1.17 dyoung struct gre_soparm {
51 1.37 dyoung struct socket *sp_so;
52 1.27 dyoung struct sockaddr_storage sp_src; /* source of gre packets */
53 1.27 dyoung struct sockaddr_storage sp_dst; /* destination of gre packets */
54 1.27 dyoung int sp_type; /* encapsulating socket type */
55 1.27 dyoung int sp_proto; /* encapsulating protocol */
56 1.37 dyoung bool sp_bysock; /* encapsulation configured by passing
57 1.27 dyoung * socket, not by SIOCSLIFPHYADDR
58 1.27 dyoung */
59 1.17 dyoung };
60 1.17 dyoung
61 1.27 dyoung enum gre_state {
62 1.27 dyoung GRE_S_IDLE = 0
63 1.30 dyoung , GRE_S_IOCTL
64 1.27 dyoung , GRE_S_DIE
65 1.27 dyoung };
66 1.27 dyoung
67 1.27 dyoung struct gre_bufq {
68 1.41 dyoung pcq_t *bq_q;
69 1.27 dyoung volatile int bq_drops;
70 1.27 dyoung };
71 1.27 dyoung
72 1.37 dyoung enum gre_msg {
73 1.37 dyoung GRE_M_NONE = 0
74 1.37 dyoung , GRE_M_SETFP
75 1.37 dyoung , GRE_M_DELFP
76 1.37 dyoung , GRE_M_STOP
77 1.37 dyoung , GRE_M_OK
78 1.37 dyoung , GRE_M_ERR
79 1.37 dyoung };
80 1.37 dyoung
81 1.1 hwr struct gre_softc {
82 1.17 dyoung struct ifnet sc_if;
83 1.22 dyoung kmutex_t sc_mtx;
84 1.27 dyoung kcondvar_t sc_condvar;
85 1.37 dyoung kcondvar_t sc_fp_condvar;
86 1.27 dyoung struct gre_bufq sc_snd;
87 1.18 dyoung struct gre_soparm sc_soparm;
88 1.27 dyoung volatile enum gre_state sc_state;
89 1.27 dyoung volatile int sc_waiters;
90 1.37 dyoung volatile int sc_fp_waiters;
91 1.27 dyoung void *sc_si;
92 1.27 dyoung
93 1.27 dyoung struct evcnt sc_recv_ev;
94 1.27 dyoung struct evcnt sc_send_ev;
95 1.27 dyoung
96 1.27 dyoung struct evcnt sc_block_ev;
97 1.27 dyoung struct evcnt sc_error_ev;
98 1.27 dyoung struct evcnt sc_pullup_ev;
99 1.27 dyoung struct evcnt sc_unsupp_ev;
100 1.27 dyoung struct evcnt sc_oflow_ev;
101 1.37 dyoung file_t * volatile sc_fp;
102 1.37 dyoung volatile enum gre_msg sc_msg;
103 1.37 dyoung int sc_fd;
104 1.14 perry };
105 1.25 dyoung
106 1.1 hwr struct gre_h {
107 1.27 dyoung uint16_t flags; /* GRE flags */
108 1.27 dyoung uint16_t ptype; /* protocol type of payload typically
109 1.27 dyoung * ethernet protocol type
110 1.27 dyoung */
111 1.14 perry /*
112 1.14 perry * from here on: fields are optional, presence indicated by flags
113 1.1 hwr *
114 1.9 itojun u_int_16 checksum checksum (one-complements of GRE header
115 1.9 itojun and payload
116 1.9 itojun Present if (ck_pres | rt_pres == 1).
117 1.9 itojun Valid if (ck_pres == 1).
118 1.9 itojun u_int_16 offset offset from start of routing filed to
119 1.9 itojun first octet of active SRE (see below).
120 1.9 itojun Present if (ck_pres | rt_pres == 1).
121 1.9 itojun Valid if (rt_pres == 1).
122 1.9 itojun u_int_32 key inserted by encapsulator e.g. for
123 1.9 itojun authentication
124 1.9 itojun Present if (key_pres ==1 ).
125 1.9 itojun u_int_32 seq_num Sequence number to allow for packet order
126 1.9 itojun Present if (seq_pres ==1 ).
127 1.9 itojun struct gre_sre[] routing Routing fileds (see below)
128 1.9 itojun Present if (rt_pres == 1)
129 1.9 itojun */
130 1.32 perry } __packed;
131 1.1 hwr
132 1.9 itojun #define GRE_CP 0x8000 /* Checksum Present */
133 1.9 itojun #define GRE_RP 0x4000 /* Routing Present */
134 1.9 itojun #define GRE_KP 0x2000 /* Key Present */
135 1.9 itojun #define GRE_SP 0x1000 /* Sequence Present */
136 1.1 hwr #define GRE_SS 0x0800 /* Strict Source Route */
137 1.1 hwr
138 1.9 itojun /*
139 1.9 itojun * gre_sre defines a Source route Entry. These are needed if packets
140 1.9 itojun * should be routed over more than one tunnel hop by hop
141 1.1 hwr */
142 1.1 hwr struct gre_sre {
143 1.35 matt uint16_t sre_family; /* address family */
144 1.9 itojun u_char sre_offset; /* offset to first octet of active entry */
145 1.14 perry u_char sre_length; /* number of octets in the SRE.
146 1.9 itojun sre_lengthl==0 -> last entry. */
147 1.9 itojun u_char *sre_rtinfo; /* the routing information */
148 1.1 hwr };
149 1.1 hwr
150 1.10 martin #define GRE_TTL 30
151 1.10 martin extern int ip_gre_ttl;
152 1.17 dyoung #endif /* _KERNEL */
153 1.2 hwr
154 1.14 perry /*
155 1.14 perry * ioctls needed to manipulate the interface
156 1.2 hwr */
157 1.2 hwr
158 1.9 itojun #define GRESADDRS _IOW('i', 101, struct ifreq)
159 1.14 perry #define GRESADDRD _IOW('i', 102, struct ifreq)
160 1.9 itojun #define GREGADDRS _IOWR('i', 103, struct ifreq)
161 1.9 itojun #define GREGADDRD _IOWR('i', 104, struct ifreq)
162 1.9 itojun #define GRESPROTO _IOW('i' , 105, struct ifreq)
163 1.9 itojun #define GREGPROTO _IOWR('i', 106, struct ifreq)
164 1.18 dyoung #define GRESSOCK _IOW('i' , 107, struct ifreq)
165 1.18 dyoung #define GREDSOCK _IOW('i' , 108, struct ifreq)
166 1.2 hwr
167 1.15 elad #endif /* !_NET_IF_GRE_H_ */
168