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