if_gre.h revision 103026
1103026Ssobomax/*	$NetBSD: if_gre.h,v 1.10 2002/02/24 17:22:20 martin Exp $ */
2103026Ssobomax/*	 $FreeBSD: head/sys/net/if_gre.h 103026 2002-09-06 17:12:50Z sobomax $ */
3103026Ssobomax
4103026Ssobomax/*
5103026Ssobomax * Copyright (c) 1998 The NetBSD Foundation, Inc.
6103026Ssobomax * All rights reserved
7103026Ssobomax *
8103026Ssobomax * This code is derived from software contributed to The NetBSD Foundation
9103026Ssobomax * by Heiko W.Rupp <hwr@pilhuhn.de>
10103026Ssobomax *
11103026Ssobomax * Redistribution and use in source and binary forms, with or without
12103026Ssobomax * modification, are permitted provided that the following conditions
13103026Ssobomax * are met:
14103026Ssobomax * 1. Redistributions of source code must retain the above copyright
15103026Ssobomax *    notice, this list of conditions and the following disclaimer.
16103026Ssobomax * 2. Redistributions in binary form must reproduce the above copyright
17103026Ssobomax *    notice, this list of conditions and the following disclaimer in the
18103026Ssobomax *    documentation and/or other materials provided with the distribution.
19103026Ssobomax * 3. All advertising materials mentioning features or use of this software
20103026Ssobomax *    must display the following acknowledgement:
21103026Ssobomax *        This product includes software developed by the NetBSD
22103026Ssobomax *        Foundation, Inc. and its contributors.
23103026Ssobomax * 4. Neither the name of The NetBSD Foundation nor the names of its
24103026Ssobomax *    contributors may be used to endorse or promote products derived
25103026Ssobomax *    from this software without specific prior written permission.
26103026Ssobomax *
27103026Ssobomax * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28103026Ssobomax * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29103026Ssobomax * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30103026Ssobomax * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31103026Ssobomax * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32103026Ssobomax * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33103026Ssobomax * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34103026Ssobomax * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35103026Ssobomax * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36103026Ssobomax * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37103026Ssobomax * POSSIBILITY OF SUCH DAMAGE.
38103026Ssobomax */
39103026Ssobomax
40103026Ssobomax#ifndef _NET_IF_GRE_H
41103026Ssobomax#define _NET_IF_GRE_H
42103026Ssobomax
43103026Ssobomax#include <sys/ioccom.h>
44103026Ssobomax#include <sys/queue.h>
45103026Ssobomax
46103026Ssobomaxstruct gre_softc {
47103026Ssobomax	struct ifnet sc_if;
48103026Ssobomax	LIST_ENTRY(gre_softc) sc_list;
49103026Ssobomax	int gre_unit;
50103026Ssobomax	int gre_flags;
51103026Ssobomax	struct in_addr g_src;	/* source address of gre packets */
52103026Ssobomax	struct in_addr g_dst;	/* destination address of gre packets */
53103026Ssobomax	struct route route;	/* routing entry that determines, where a
54103026Ssobomax				   encapsulated packet should go */
55103026Ssobomax	u_char g_proto;		/* protocol of encapsulator */
56103026Ssobomax
57103026Ssobomax	const struct encaptab *encap;	/* encapsulation cookie */
58103026Ssobomax
59103026Ssobomax	int called;		/* infinite recursion preventer */
60103026Ssobomax};
61103026Ssobomax
62103026Ssobomax
63103026Ssobomaxstruct gre_h {
64103026Ssobomax	u_int16_t flags;	/* GRE flags */
65103026Ssobomax	u_int16_t ptype;	/* protocol type of payload typically
66103026Ssobomax				   Ether protocol type*/
67103026Ssobomax/*
68103026Ssobomax *  from here on: fields are optional, presence indicated by flags
69103026Ssobomax *
70103026Ssobomax	u_int_16 checksum	checksum (one-complements of GRE header
71103026Ssobomax				and payload
72103026Ssobomax				Present if (ck_pres | rt_pres == 1).
73103026Ssobomax				Valid if (ck_pres == 1).
74103026Ssobomax	u_int_16 offset		offset from start of routing filed to
75103026Ssobomax				first octet of active SRE (see below).
76103026Ssobomax				Present if (ck_pres | rt_pres == 1).
77103026Ssobomax				Valid if (rt_pres == 1).
78103026Ssobomax	u_int_32 key		inserted by encapsulator e.g. for
79103026Ssobomax				authentication
80103026Ssobomax				Present if (key_pres ==1 ).
81103026Ssobomax	u_int_32 seq_num	Sequence number to allow for packet order
82103026Ssobomax				Present if (seq_pres ==1 ).
83103026Ssobomax	struct gre_sre[] routing Routing fileds (see below)
84103026Ssobomax				Present if (rt_pres == 1)
85103026Ssobomax */
86103026Ssobomax} __attribute__((__packed__));
87103026Ssobomax
88103026Ssobomaxstruct greip {
89103026Ssobomax	struct ip gi_i;
90103026Ssobomax	struct gre_h  gi_g;
91103026Ssobomax} __attribute__((__packed__));
92103026Ssobomax
93103026Ssobomax#define gi_pr		gi_i.ip_p
94103026Ssobomax#define gi_len		gi_i.ip_len
95103026Ssobomax#define gi_src		gi_i.ip_src
96103026Ssobomax#define gi_dst		gi_i.ip_dst
97103026Ssobomax#define gi_ptype	gi_g.ptype
98103026Ssobomax#define gi_flags	gi_g.flags
99103026Ssobomax
100103026Ssobomax#define GRE_CP		0x8000  /* Checksum Present */
101103026Ssobomax#define GRE_RP		0x4000  /* Routing Present */
102103026Ssobomax#define GRE_KP		0x2000  /* Key Present */
103103026Ssobomax#define GRE_SP		0x1000  /* Sequence Present */
104103026Ssobomax#define GRE_SS		0x0800	/* Strict Source Route */
105103026Ssobomax
106103026Ssobomax/*
107103026Ssobomax * gre_sre defines a Source route Entry. These are needed if packets
108103026Ssobomax * should be routed over more than one tunnel hop by hop
109103026Ssobomax */
110103026Ssobomaxstruct gre_sre {
111103026Ssobomax	u_int16_t sre_family;	/* adress family */
112103026Ssobomax	u_char	sre_offset;	/* offset to first octet of active entry */
113103026Ssobomax	u_char	sre_length;	/* number of octets in the SRE.
114103026Ssobomax				   sre_lengthl==0 -> last entry. */
115103026Ssobomax	u_char	*sre_rtinfo;	/* the routing information */
116103026Ssobomax};
117103026Ssobomax
118103026Ssobomaxstruct greioctl {
119103026Ssobomax	int unit;
120103026Ssobomax	struct in_addr addr;
121103026Ssobomax};
122103026Ssobomax
123103026Ssobomax/* for mobile encaps */
124103026Ssobomax
125103026Ssobomaxstruct mobile_h {
126103026Ssobomax	u_int16_t proto;		/* protocol and S-bit */
127103026Ssobomax	u_int16_t hcrc;			/* header checksum */
128103026Ssobomax	u_int32_t odst;			/* original destination address */
129103026Ssobomax	u_int32_t osrc;			/* original source addr, if S-bit set */
130103026Ssobomax} __attribute__((__packed__));
131103026Ssobomax
132103026Ssobomaxstruct mobip_h {
133103026Ssobomax	struct ip	mi;
134103026Ssobomax	struct mobile_h	mh;
135103026Ssobomax} __attribute__((__packed__));
136103026Ssobomax
137103026Ssobomax
138103026Ssobomax#define MOB_H_SIZ_S		(sizeof(struct mobile_h) - sizeof(u_int32_t))
139103026Ssobomax#define MOB_H_SIZ_L		(sizeof(struct mobile_h))
140103026Ssobomax#define MOB_H_SBIT	0x0080
141103026Ssobomax
142103026Ssobomax#define	GRE_TTL	30
143103026Ssobomaxextern int ip_gre_ttl;
144103026Ssobomax
145103026Ssobomax/*
146103026Ssobomax * ioctls needed to manipulate the interface
147103026Ssobomax */
148103026Ssobomax
149103026Ssobomax#define GRESADDRS	_IOW('i', 101, struct ifreq)
150103026Ssobomax#define GRESADDRD	_IOW('i', 102, struct ifreq)
151103026Ssobomax#define GREGADDRS	_IOWR('i', 103, struct ifreq)
152103026Ssobomax#define GREGADDRD	_IOWR('i', 104, struct ifreq)
153103026Ssobomax#define GRESPROTO	_IOW('i' , 105, struct ifreq)
154103026Ssobomax#define GREGPROTO	_IOWR('i', 106, struct ifreq)
155103026Ssobomax
156103026Ssobomax#ifdef _KERNEL
157103026SsobomaxLIST_HEAD(gre_softc_head, gre_softc);
158103026Ssobomaxextern struct gre_softc_head gre_softc_list;
159103026Ssobomax
160103026Ssobomaxint	gre_ioctl __P((struct ifnet *, u_long, caddr_t));
161103026Ssobomaxint	gre_output __P((struct ifnet *, struct mbuf *, struct sockaddr *,
162103026Ssobomax	    struct rtentry *rt));
163103026Ssobomaxu_short	gre_in_cksum(u_short *p, u_int len);
164103026Ssobomax#endif /* _KERNEL */
165103026Ssobomax
166103026Ssobomax#endif
167