xref: /freebsd/sys/net/if_gre.h (revision 73d7ddbc5692314aab047957de303444503e8d57)
173d7ddbcSMaxim Sobolev /*	$NetBSD: if_gre.h,v 1.13 2003/11/10 08:51:52 wiz Exp $ */
28e96e13eSMaxim Sobolev /*	 $FreeBSD$ */
38e96e13eSMaxim Sobolev 
48e96e13eSMaxim Sobolev /*
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  * 3. All advertising materials mentioning features or use of this software
208e96e13eSMaxim Sobolev  *    must display the following acknowledgement:
218e96e13eSMaxim Sobolev  *        This product includes software developed by the NetBSD
228e96e13eSMaxim Sobolev  *        Foundation, Inc. and its contributors.
238e96e13eSMaxim Sobolev  * 4. Neither the name of The NetBSD Foundation nor the names of its
248e96e13eSMaxim Sobolev  *    contributors may be used to endorse or promote products derived
258e96e13eSMaxim Sobolev  *    from this software without specific prior written permission.
268e96e13eSMaxim Sobolev  *
278e96e13eSMaxim Sobolev  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
288e96e13eSMaxim Sobolev  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
298e96e13eSMaxim Sobolev  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
308e96e13eSMaxim Sobolev  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
318e96e13eSMaxim Sobolev  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
328e96e13eSMaxim Sobolev  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
338e96e13eSMaxim Sobolev  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
348e96e13eSMaxim Sobolev  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
358e96e13eSMaxim Sobolev  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
368e96e13eSMaxim Sobolev  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
378e96e13eSMaxim Sobolev  * POSSIBILITY OF SUCH DAMAGE.
388e96e13eSMaxim Sobolev  */
398e96e13eSMaxim Sobolev 
408e96e13eSMaxim Sobolev #ifndef _NET_IF_GRE_H
418e96e13eSMaxim Sobolev #define _NET_IF_GRE_H
428e96e13eSMaxim Sobolev 
438e96e13eSMaxim Sobolev #include <sys/ioccom.h>
44ccd6d236SMaxim Sobolev #ifdef _KERNEL
458e96e13eSMaxim Sobolev #include <sys/queue.h>
468e96e13eSMaxim Sobolev 
478e96e13eSMaxim Sobolev struct gre_softc {
488e96e13eSMaxim Sobolev 	struct ifnet sc_if;
498e96e13eSMaxim Sobolev 	LIST_ENTRY(gre_softc) sc_list;
508e96e13eSMaxim Sobolev 	int gre_unit;
518e96e13eSMaxim Sobolev 	int gre_flags;
528e96e13eSMaxim Sobolev 	struct in_addr g_src;	/* source address of gre packets */
538e96e13eSMaxim Sobolev 	struct in_addr g_dst;	/* destination address of gre packets */
548e96e13eSMaxim Sobolev 	struct route route;	/* routing entry that determines, where a
558e96e13eSMaxim Sobolev 				   encapsulated packet should go */
568e96e13eSMaxim Sobolev 	u_char g_proto;		/* protocol of encapsulator */
578e96e13eSMaxim Sobolev 
588e96e13eSMaxim Sobolev 	const struct encaptab *encap;	/* encapsulation cookie */
598e96e13eSMaxim Sobolev 
608e96e13eSMaxim Sobolev 	int called;		/* infinite recursion preventer */
618e96e13eSMaxim Sobolev };
628e96e13eSMaxim Sobolev 
638e96e13eSMaxim Sobolev 
648e96e13eSMaxim Sobolev struct gre_h {
658e96e13eSMaxim Sobolev 	u_int16_t flags;	/* GRE flags */
668e96e13eSMaxim Sobolev 	u_int16_t ptype;	/* protocol type of payload typically
678e96e13eSMaxim Sobolev 				   Ether protocol type*/
688e96e13eSMaxim Sobolev /*
698e96e13eSMaxim Sobolev  *  from here on: fields are optional, presence indicated by flags
708e96e13eSMaxim Sobolev  *
718e96e13eSMaxim Sobolev 	u_int_16 checksum	checksum (one-complements of GRE header
728e96e13eSMaxim Sobolev 				and payload
738e96e13eSMaxim Sobolev 				Present if (ck_pres | rt_pres == 1).
748e96e13eSMaxim Sobolev 				Valid if (ck_pres == 1).
758e96e13eSMaxim Sobolev 	u_int_16 offset		offset from start of routing filed to
768e96e13eSMaxim Sobolev 				first octet of active SRE (see below).
778e96e13eSMaxim Sobolev 				Present if (ck_pres | rt_pres == 1).
788e96e13eSMaxim Sobolev 				Valid if (rt_pres == 1).
798e96e13eSMaxim Sobolev 	u_int_32 key		inserted by encapsulator e.g. for
808e96e13eSMaxim Sobolev 				authentication
818e96e13eSMaxim Sobolev 				Present if (key_pres ==1 ).
828e96e13eSMaxim Sobolev 	u_int_32 seq_num	Sequence number to allow for packet order
838e96e13eSMaxim Sobolev 				Present if (seq_pres ==1 ).
848e96e13eSMaxim Sobolev 	struct gre_sre[] routing Routing fileds (see below)
858e96e13eSMaxim Sobolev 				Present if (rt_pres == 1)
868e96e13eSMaxim Sobolev  */
87ebc82cbbSAlfred Perlstein } __packed;
888e96e13eSMaxim Sobolev 
898e96e13eSMaxim Sobolev struct greip {
908e96e13eSMaxim Sobolev 	struct ip gi_i;
918e96e13eSMaxim Sobolev 	struct gre_h  gi_g;
92ebc82cbbSAlfred Perlstein } __packed;
938e96e13eSMaxim Sobolev 
948e96e13eSMaxim Sobolev #define gi_pr		gi_i.ip_p
958e96e13eSMaxim Sobolev #define gi_len		gi_i.ip_len
968e96e13eSMaxim Sobolev #define gi_src		gi_i.ip_src
978e96e13eSMaxim Sobolev #define gi_dst		gi_i.ip_dst
988e96e13eSMaxim Sobolev #define gi_ptype	gi_g.ptype
998e96e13eSMaxim Sobolev #define gi_flags	gi_g.flags
1008e96e13eSMaxim Sobolev 
1018e96e13eSMaxim Sobolev #define GRE_CP		0x8000  /* Checksum Present */
1028e96e13eSMaxim Sobolev #define GRE_RP		0x4000  /* Routing Present */
1038e96e13eSMaxim Sobolev #define GRE_KP		0x2000  /* Key Present */
1048e96e13eSMaxim Sobolev #define GRE_SP		0x1000  /* Sequence Present */
1058e96e13eSMaxim Sobolev #define GRE_SS		0x0800	/* Strict Source Route */
1068e96e13eSMaxim Sobolev 
1078e96e13eSMaxim Sobolev /*
10816199bf2SMaxim Sobolev  * CISCO uses special type for GRE tunnel created as part of WCCP
10916199bf2SMaxim Sobolev  * connection, while in fact those packets are just IPv4 encapsulated
11016199bf2SMaxim Sobolev  * into GRE.
11116199bf2SMaxim Sobolev  */
11216199bf2SMaxim Sobolev #define WCCP_PROTOCOL_TYPE	0x883E
11316199bf2SMaxim Sobolev 
11416199bf2SMaxim Sobolev /*
1158e96e13eSMaxim Sobolev  * gre_sre defines a Source route Entry. These are needed if packets
1168e96e13eSMaxim Sobolev  * should be routed over more than one tunnel hop by hop
1178e96e13eSMaxim Sobolev  */
1188e96e13eSMaxim Sobolev struct gre_sre {
11973d7ddbcSMaxim Sobolev 	u_int16_t sre_family;	/* address family */
1208e96e13eSMaxim Sobolev 	u_char	sre_offset;	/* offset to first octet of active entry */
1218e96e13eSMaxim Sobolev 	u_char	sre_length;	/* number of octets in the SRE.
1228e96e13eSMaxim Sobolev 				   sre_lengthl==0 -> last entry. */
1238e96e13eSMaxim Sobolev 	u_char	*sre_rtinfo;	/* the routing information */
1248e96e13eSMaxim Sobolev };
1258e96e13eSMaxim Sobolev 
1268e96e13eSMaxim Sobolev struct greioctl {
1278e96e13eSMaxim Sobolev 	int unit;
1288e96e13eSMaxim Sobolev 	struct in_addr addr;
1298e96e13eSMaxim Sobolev };
1308e96e13eSMaxim Sobolev 
1318e96e13eSMaxim Sobolev /* for mobile encaps */
1328e96e13eSMaxim Sobolev 
1338e96e13eSMaxim Sobolev struct mobile_h {
1348e96e13eSMaxim Sobolev 	u_int16_t proto;		/* protocol and S-bit */
1358e96e13eSMaxim Sobolev 	u_int16_t hcrc;			/* header checksum */
1368e96e13eSMaxim Sobolev 	u_int32_t odst;			/* original destination address */
1378e96e13eSMaxim Sobolev 	u_int32_t osrc;			/* original source addr, if S-bit set */
138ebc82cbbSAlfred Perlstein } __packed;
1398e96e13eSMaxim Sobolev 
1408e96e13eSMaxim Sobolev struct mobip_h {
1418e96e13eSMaxim Sobolev 	struct ip	mi;
1428e96e13eSMaxim Sobolev 	struct mobile_h	mh;
143ebc82cbbSAlfred Perlstein } __packed;
1448e96e13eSMaxim Sobolev 
1458e96e13eSMaxim Sobolev 
1468e96e13eSMaxim Sobolev #define MOB_H_SIZ_S		(sizeof(struct mobile_h) - sizeof(u_int32_t))
1478e96e13eSMaxim Sobolev #define MOB_H_SIZ_L		(sizeof(struct mobile_h))
1488e96e13eSMaxim Sobolev #define MOB_H_SBIT	0x0080
1498e96e13eSMaxim Sobolev 
1508e96e13eSMaxim Sobolev #define	GRE_TTL	30
1518e96e13eSMaxim Sobolev 
152ccd6d236SMaxim Sobolev #endif /* _KERNEL */
153ccd6d236SMaxim Sobolev 
1548e96e13eSMaxim Sobolev /*
1558e96e13eSMaxim Sobolev  * ioctls needed to manipulate the interface
1568e96e13eSMaxim Sobolev  */
1578e96e13eSMaxim Sobolev 
1588e96e13eSMaxim Sobolev #define GRESADDRS	_IOW('i', 101, struct ifreq)
1598e96e13eSMaxim Sobolev #define GRESADDRD	_IOW('i', 102, struct ifreq)
1608e96e13eSMaxim Sobolev #define GREGADDRS	_IOWR('i', 103, struct ifreq)
1618e96e13eSMaxim Sobolev #define GREGADDRD	_IOWR('i', 104, struct ifreq)
1628e96e13eSMaxim Sobolev #define GRESPROTO	_IOW('i' , 105, struct ifreq)
1638e96e13eSMaxim Sobolev #define GREGPROTO	_IOWR('i', 106, struct ifreq)
1648e96e13eSMaxim Sobolev 
1658e96e13eSMaxim Sobolev #ifdef _KERNEL
1668e96e13eSMaxim Sobolev LIST_HEAD(gre_softc_head, gre_softc);
1678e96e13eSMaxim Sobolev extern struct gre_softc_head gre_softc_list;
1688e96e13eSMaxim Sobolev 
16973d7ddbcSMaxim Sobolev u_int16_t	gre_in_cksum(u_int16_t *, u_int);
1708e96e13eSMaxim Sobolev #endif /* _KERNEL */
1718e96e13eSMaxim Sobolev 
1728e96e13eSMaxim Sobolev #endif
173