xref: /netbsd-src/sys/net/if_gre.h (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
1 /*	$NetBSD: if_gre.h,v 1.41 2011/11/02 01:17:59 dyoung Exp $ */
2 
3 /*
4  * Copyright (c) 1998, 2008 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@pilhuhn.de>
9  *
10  * This code is derived from software contributed to The NetBSD Foundation
11  * by David Young <dyoung@NetBSD.org>
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * This material is based upon work partially supported by NSF
35  * under Contract No. NSF CNS-0626584.
36  */
37 
38 #ifndef _NET_IF_GRE_H_
39 #define _NET_IF_GRE_H_
40 
41 #include <sys/evcnt.h>
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 #include <sys/pcq.h>
48 
49 #ifdef _KERNEL
50 struct gre_soparm {
51 	struct socket		*sp_so;
52 	struct sockaddr_storage sp_src;	/* source of gre packets */
53 	struct sockaddr_storage sp_dst;	/* destination of gre packets */
54 	int		sp_type;	/* encapsulating socket type */
55 	int		sp_proto;	/* encapsulating protocol */
56 	bool		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_DIE
65 };
66 
67 struct gre_bufq {
68 	pcq_t		*bq_q;
69 	volatile int	bq_drops;
70 };
71 
72 enum gre_msg {
73 	  GRE_M_NONE = 0
74 	, GRE_M_SETFP
75 	, GRE_M_DELFP
76 	, GRE_M_STOP
77 	, GRE_M_OK
78 	, GRE_M_ERR
79 };
80 
81 struct gre_softc {
82 	struct ifnet		sc_if;
83 	kmutex_t		sc_mtx;
84 	kcondvar_t		sc_condvar;
85 	kcondvar_t		sc_fp_condvar;
86 	struct gre_bufq		sc_snd;
87 	struct gre_soparm	sc_soparm;
88 	volatile enum gre_state	sc_state;
89 	volatile int		sc_waiters;
90 	volatile int		sc_fp_waiters;
91 	void			*sc_si;
92 
93 	struct evcnt		sc_recv_ev;
94 	struct evcnt		sc_send_ev;
95 
96 	struct evcnt		sc_block_ev;
97 	struct evcnt		sc_error_ev;
98 	struct evcnt		sc_pullup_ev;
99 	struct evcnt		sc_unsupp_ev;
100 	struct evcnt		sc_oflow_ev;
101 	file_t	* volatile	sc_fp;
102 	volatile enum gre_msg	sc_msg;
103 	int			sc_fd;
104 };
105 
106 struct gre_h {
107 	uint16_t flags;		/* GRE flags */
108 	uint16_t ptype;		/* protocol type of payload typically
109 				 * ethernet protocol type
110 				 */
111 /*
112  *  from here on: fields are optional, presence indicated by flags
113  *
114 	u_int_16 checksum	checksum (one-complements of GRE header
115 				and payload
116 				Present if (ck_pres | rt_pres == 1).
117 				Valid if (ck_pres == 1).
118 	u_int_16 offset		offset from start of routing filed to
119 				first octet of active SRE (see below).
120 				Present if (ck_pres | rt_pres == 1).
121 				Valid if (rt_pres == 1).
122 	u_int_32 key		inserted by encapsulator e.g. for
123 				authentication
124 				Present if (key_pres ==1 ).
125 	u_int_32 seq_num	Sequence number to allow for packet order
126 				Present if (seq_pres ==1 ).
127 	struct gre_sre[] routing Routing fileds (see below)
128 				Present if (rt_pres == 1)
129  */
130 } __packed;
131 
132 #define GRE_CP		0x8000  /* Checksum Present */
133 #define GRE_RP		0x4000  /* Routing Present */
134 #define GRE_KP		0x2000  /* Key Present */
135 #define GRE_SP		0x1000  /* Sequence Present */
136 #define GRE_SS		0x0800	/* Strict Source Route */
137 
138 /*
139  * gre_sre defines a Source route Entry. These are needed if packets
140  * should be routed over more than one tunnel hop by hop
141  */
142 struct gre_sre {
143 	uint16_t sre_family;	/* address family */
144 	u_char	sre_offset;	/* offset to first octet of active entry */
145 	u_char	sre_length;	/* number of octets in the SRE.
146 				   sre_lengthl==0 -> last entry. */
147 	u_char	*sre_rtinfo;	/* the routing information */
148 };
149 
150 #define	GRE_TTL	30
151 extern int ip_gre_ttl;
152 #endif /* _KERNEL */
153 
154 /*
155  * ioctls needed to manipulate the interface
156  */
157 
158 #define GRESADDRS	_IOW('i', 101, struct ifreq)
159 #define GRESADDRD	_IOW('i', 102, struct ifreq)
160 #define GREGADDRS	_IOWR('i', 103, struct ifreq)
161 #define GREGADDRD	_IOWR('i', 104, struct ifreq)
162 #define GRESPROTO	_IOW('i' , 105, struct ifreq)
163 #define GREGPROTO	_IOWR('i', 106, struct ifreq)
164 #define GRESSOCK	_IOW('i' , 107, struct ifreq)
165 #define GREDSOCK	_IOW('i' , 108, struct ifreq)
166 
167 #endif /* !_NET_IF_GRE_H_ */
168