xref: /freebsd/sys/net/if_gre.h (revision 89c58b73e0f809d2734a44e17ed46abb0ab31b04)
173d7ddbcSMaxim Sobolev /*	$NetBSD: if_gre.h,v 1.13 2003/11/10 08:51:52 wiz Exp $ */
28e96e13eSMaxim Sobolev /*	 $FreeBSD$ */
38e96e13eSMaxim Sobolev 
4c398230bSWarner Losh /*-
58e96e13eSMaxim Sobolev  * Copyright (c) 1998 The NetBSD Foundation, Inc.
68e96e13eSMaxim Sobolev  * All rights reserved
78e96e13eSMaxim Sobolev  *
88e96e13eSMaxim Sobolev  * This code is derived from software contributed to The NetBSD Foundation
98e96e13eSMaxim Sobolev  * by Heiko W.Rupp <hwr@pilhuhn.de>
108e96e13eSMaxim Sobolev  *
118e96e13eSMaxim Sobolev  * Redistribution and use in source and binary forms, with or without
128e96e13eSMaxim Sobolev  * modification, are permitted provided that the following conditions
138e96e13eSMaxim Sobolev  * are met:
148e96e13eSMaxim Sobolev  * 1. Redistributions of source code must retain the above copyright
158e96e13eSMaxim Sobolev  *    notice, this list of conditions and the following disclaimer.
168e96e13eSMaxim Sobolev  * 2. Redistributions in binary form must reproduce the above copyright
178e96e13eSMaxim Sobolev  *    notice, this list of conditions and the following disclaimer in the
188e96e13eSMaxim Sobolev  *    documentation and/or other materials provided with the distribution.
198e96e13eSMaxim Sobolev  *
208e96e13eSMaxim Sobolev  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
218e96e13eSMaxim Sobolev  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
228e96e13eSMaxim Sobolev  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
238e96e13eSMaxim Sobolev  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
248e96e13eSMaxim Sobolev  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
258e96e13eSMaxim Sobolev  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
268e96e13eSMaxim Sobolev  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
278e96e13eSMaxim Sobolev  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
288e96e13eSMaxim Sobolev  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
298e96e13eSMaxim Sobolev  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
308e96e13eSMaxim Sobolev  * POSSIBILITY OF SUCH DAMAGE.
318e96e13eSMaxim Sobolev  */
328e96e13eSMaxim Sobolev 
338e96e13eSMaxim Sobolev #ifndef _NET_IF_GRE_H
348e96e13eSMaxim Sobolev #define _NET_IF_GRE_H
358e96e13eSMaxim Sobolev 
368e96e13eSMaxim Sobolev #include <sys/ioccom.h>
37ccd6d236SMaxim Sobolev #ifdef _KERNEL
388e96e13eSMaxim Sobolev #include <sys/queue.h>
398e96e13eSMaxim Sobolev 
407735aeb9SMaxim Sobolev /*
417735aeb9SMaxim Sobolev  * Version of the WCCP, need to be configured manually since
427735aeb9SMaxim Sobolev  * header for version 2 is the same but IP payload is prepended
437735aeb9SMaxim Sobolev  * with additional 4-bytes field.
447735aeb9SMaxim Sobolev  */
457735aeb9SMaxim Sobolev typedef enum {
467735aeb9SMaxim Sobolev 	WCCP_V1 = 0,
477735aeb9SMaxim Sobolev 	WCCP_V2
487735aeb9SMaxim Sobolev } wccp_ver_t;
497735aeb9SMaxim Sobolev 
508e96e13eSMaxim Sobolev struct gre_softc {
51fc74a9f9SBrooks Davis 	struct ifnet *sc_ifp;
528e96e13eSMaxim Sobolev 	LIST_ENTRY(gre_softc) sc_list;
538e96e13eSMaxim Sobolev 	int gre_unit;
548e96e13eSMaxim Sobolev 	int gre_flags;
558b07e49aSJulian Elischer 	u_int	gre_fibnum;	/* use this fib for envelopes */
568e96e13eSMaxim Sobolev 	struct in_addr g_src;	/* source address of gre packets */
578e96e13eSMaxim Sobolev 	struct in_addr g_dst;	/* destination address of gre packets */
588e96e13eSMaxim Sobolev 	struct route route;	/* routing entry that determines, where a
598e96e13eSMaxim Sobolev 				   encapsulated packet should go */
608e96e13eSMaxim Sobolev 	u_char g_proto;		/* protocol of encapsulator */
618e96e13eSMaxim Sobolev 
628e96e13eSMaxim Sobolev 	const struct encaptab *encap;	/* encapsulation cookie */
638e96e13eSMaxim Sobolev 
64131c55bcSAndrew Thompson 	uint32_t key;		/* key included in outgoing GRE packets */
65131c55bcSAndrew Thompson 				/* zero means none */
66131c55bcSAndrew Thompson 
677735aeb9SMaxim Sobolev 	wccp_ver_t wccp_ver;	/* version of the WCCP */
688e96e13eSMaxim Sobolev };
69fc74a9f9SBrooks Davis #define	GRE2IFP(sc)	((sc)->sc_ifp)
708e96e13eSMaxim Sobolev 
718e96e13eSMaxim Sobolev 
728e96e13eSMaxim Sobolev struct gre_h {
738e96e13eSMaxim Sobolev 	u_int16_t flags;	/* GRE flags */
748e96e13eSMaxim Sobolev 	u_int16_t ptype;	/* protocol type of payload typically
758e96e13eSMaxim Sobolev 				   Ether protocol type*/
76131c55bcSAndrew Thompson 	uint32_t options[0];	/* optional options */
778e96e13eSMaxim Sobolev /*
788e96e13eSMaxim Sobolev  *  from here on: fields are optional, presence indicated by flags
798e96e13eSMaxim Sobolev  *
808e96e13eSMaxim Sobolev 	u_int_16 checksum	checksum (one-complements of GRE header
818e96e13eSMaxim Sobolev 				and payload
828e96e13eSMaxim Sobolev 				Present if (ck_pres | rt_pres == 1).
838e96e13eSMaxim Sobolev 				Valid if (ck_pres == 1).
848e96e13eSMaxim Sobolev 	u_int_16 offset		offset from start of routing filed to
858e96e13eSMaxim Sobolev 				first octet of active SRE (see below).
868e96e13eSMaxim Sobolev 				Present if (ck_pres | rt_pres == 1).
878e96e13eSMaxim Sobolev 				Valid if (rt_pres == 1).
888e96e13eSMaxim Sobolev 	u_int_32 key		inserted by encapsulator e.g. for
898e96e13eSMaxim Sobolev 				authentication
908e96e13eSMaxim Sobolev 				Present if (key_pres ==1 ).
918e96e13eSMaxim Sobolev 	u_int_32 seq_num	Sequence number to allow for packet order
928e96e13eSMaxim Sobolev 				Present if (seq_pres ==1 ).
938e96e13eSMaxim Sobolev 	struct gre_sre[] routing Routing fileds (see below)
948e96e13eSMaxim Sobolev 				Present if (rt_pres == 1)
958e96e13eSMaxim Sobolev  */
96ebc82cbbSAlfred Perlstein } __packed;
978e96e13eSMaxim Sobolev 
988e96e13eSMaxim Sobolev struct greip {
998e96e13eSMaxim Sobolev 	struct ip gi_i;
1008e96e13eSMaxim Sobolev 	struct gre_h  gi_g;
101ebc82cbbSAlfred Perlstein } __packed;
1028e96e13eSMaxim Sobolev 
1038e96e13eSMaxim Sobolev #define gi_pr		gi_i.ip_p
1048e96e13eSMaxim Sobolev #define gi_len		gi_i.ip_len
1058e96e13eSMaxim Sobolev #define gi_src		gi_i.ip_src
1068e96e13eSMaxim Sobolev #define gi_dst		gi_i.ip_dst
1078e96e13eSMaxim Sobolev #define gi_ptype	gi_g.ptype
1088e96e13eSMaxim Sobolev #define gi_flags	gi_g.flags
109131c55bcSAndrew Thompson #define gi_options	gi_g.options
1108e96e13eSMaxim Sobolev 
1118e96e13eSMaxim Sobolev #define GRE_CP		0x8000  /* Checksum Present */
1128e96e13eSMaxim Sobolev #define GRE_RP		0x4000  /* Routing Present */
1138e96e13eSMaxim Sobolev #define GRE_KP		0x2000  /* Key Present */
1148e96e13eSMaxim Sobolev #define GRE_SP		0x1000  /* Sequence Present */
1158e96e13eSMaxim Sobolev #define GRE_SS		0x0800	/* Strict Source Route */
1168e96e13eSMaxim Sobolev 
1178e96e13eSMaxim Sobolev /*
11816199bf2SMaxim Sobolev  * CISCO uses special type for GRE tunnel created as part of WCCP
11916199bf2SMaxim Sobolev  * connection, while in fact those packets are just IPv4 encapsulated
12016199bf2SMaxim Sobolev  * into GRE.
12116199bf2SMaxim Sobolev  */
12216199bf2SMaxim Sobolev #define WCCP_PROTOCOL_TYPE	0x883E
12316199bf2SMaxim Sobolev 
12416199bf2SMaxim Sobolev /*
1258e96e13eSMaxim Sobolev  * gre_sre defines a Source route Entry. These are needed if packets
1268e96e13eSMaxim Sobolev  * should be routed over more than one tunnel hop by hop
1278e96e13eSMaxim Sobolev  */
1288e96e13eSMaxim Sobolev struct gre_sre {
12973d7ddbcSMaxim Sobolev 	u_int16_t sre_family;	/* address family */
1308e96e13eSMaxim Sobolev 	u_char	sre_offset;	/* offset to first octet of active entry */
1318e96e13eSMaxim Sobolev 	u_char	sre_length;	/* number of octets in the SRE.
1328e96e13eSMaxim Sobolev 				   sre_lengthl==0 -> last entry. */
1338e96e13eSMaxim Sobolev 	u_char	*sre_rtinfo;	/* the routing information */
1348e96e13eSMaxim Sobolev };
1358e96e13eSMaxim Sobolev 
1368e96e13eSMaxim Sobolev struct greioctl {
1378e96e13eSMaxim Sobolev 	int unit;
1388e96e13eSMaxim Sobolev 	struct in_addr addr;
1398e96e13eSMaxim Sobolev };
1408e96e13eSMaxim Sobolev 
1418e96e13eSMaxim Sobolev /* for mobile encaps */
1428e96e13eSMaxim Sobolev 
1438e96e13eSMaxim Sobolev struct mobile_h {
1448e96e13eSMaxim Sobolev 	u_int16_t proto;		/* protocol and S-bit */
1458e96e13eSMaxim Sobolev 	u_int16_t hcrc;			/* header checksum */
1468e96e13eSMaxim Sobolev 	u_int32_t odst;			/* original destination address */
1478e96e13eSMaxim Sobolev 	u_int32_t osrc;			/* original source addr, if S-bit set */
148ebc82cbbSAlfred Perlstein } __packed;
1498e96e13eSMaxim Sobolev 
1508e96e13eSMaxim Sobolev struct mobip_h {
1518e96e13eSMaxim Sobolev 	struct ip	mi;
1528e96e13eSMaxim Sobolev 	struct mobile_h	mh;
153ebc82cbbSAlfred Perlstein } __packed;
1548e96e13eSMaxim Sobolev 
1558e96e13eSMaxim Sobolev 
1568e96e13eSMaxim Sobolev #define MOB_H_SIZ_S		(sizeof(struct mobile_h) - sizeof(u_int32_t))
1578e96e13eSMaxim Sobolev #define MOB_H_SIZ_L		(sizeof(struct mobile_h))
1588e96e13eSMaxim Sobolev #define MOB_H_SBIT	0x0080
1598e96e13eSMaxim Sobolev 
1608e96e13eSMaxim Sobolev #define	GRE_TTL	30
1618e96e13eSMaxim Sobolev 
162ccd6d236SMaxim Sobolev #endif /* _KERNEL */
163ccd6d236SMaxim Sobolev 
1648e96e13eSMaxim Sobolev /*
1658e96e13eSMaxim Sobolev  * ioctls needed to manipulate the interface
1668e96e13eSMaxim Sobolev  */
1678e96e13eSMaxim Sobolev 
1688e96e13eSMaxim Sobolev #define GRESADDRS	_IOW('i', 101, struct ifreq)
1698e96e13eSMaxim Sobolev #define GRESADDRD	_IOW('i', 102, struct ifreq)
1708e96e13eSMaxim Sobolev #define GREGADDRS	_IOWR('i', 103, struct ifreq)
1718e96e13eSMaxim Sobolev #define GREGADDRD	_IOWR('i', 104, struct ifreq)
1728e96e13eSMaxim Sobolev #define GRESPROTO	_IOW('i' , 105, struct ifreq)
1738e96e13eSMaxim Sobolev #define GREGPROTO	_IOWR('i', 106, struct ifreq)
174131c55bcSAndrew Thompson #define GREGKEY		_IOWR('i', 107, struct ifreq)
175131c55bcSAndrew Thompson #define GRESKEY		_IOW('i', 108, struct ifreq)
1768e96e13eSMaxim Sobolev 
1778e96e13eSMaxim Sobolev #ifdef _KERNEL
1788e96e13eSMaxim Sobolev LIST_HEAD(gre_softc_head, gre_softc);
179*89c58b73SHiroki Sato VNET_DECLARE(struct gre_softc_head, gre_softc_list);
180*89c58b73SHiroki Sato #define	V_gre_softc_list	VNET(gre_softc_list)
181*89c58b73SHiroki Sato 
182*89c58b73SHiroki Sato VNET_DECLARE(struct mtx, gre_mtx);
183*89c58b73SHiroki Sato #define	V_gre_mtx	VNET(gre_mtx)
184*89c58b73SHiroki Sato #define	GRE_LIST_LOCK_INIT(x)		mtx_init(&V_gre_mtx, "gre_mtx", NULL, \
185*89c58b73SHiroki Sato 					    MTX_DEF)
186*89c58b73SHiroki Sato #define	GRE_LIST_LOCK_DESTROY(x)	mtx_destroy(&V_gre_mtx)
187*89c58b73SHiroki Sato #define	GRE_LIST_LOCK(x)		mtx_lock(&V_gre_mtx)
188*89c58b73SHiroki Sato #define	GRE_LIST_UNLOCK(x)		mtx_unlock(&V_gre_mtx)
1898e96e13eSMaxim Sobolev 
19073d7ddbcSMaxim Sobolev u_int16_t	gre_in_cksum(u_int16_t *, u_int);
1918e96e13eSMaxim Sobolev #endif /* _KERNEL */
1928e96e13eSMaxim Sobolev 
1938e96e13eSMaxim Sobolev #endif
194