1123992Ssobomax/*	$NetBSD: if_gre.h,v 1.13 2003/11/10 08:51:52 wiz Exp $ */
2103026Ssobomax/*	 $FreeBSD$ */
3103026Ssobomax
4139823Simp/*-
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.
19125020Ssobomax *
20103026Ssobomax * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21103026Ssobomax * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22103026Ssobomax * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23103026Ssobomax * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24103026Ssobomax * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25103026Ssobomax * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26103026Ssobomax * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27103026Ssobomax * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28103026Ssobomax * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29103026Ssobomax * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30103026Ssobomax * POSSIBILITY OF SUCH DAMAGE.
31103026Ssobomax */
32103026Ssobomax
33103026Ssobomax#ifndef _NET_IF_GRE_H
34103026Ssobomax#define _NET_IF_GRE_H
35103026Ssobomax
36103026Ssobomax#include <sys/ioccom.h>
37103120Ssobomax#ifdef _KERNEL
38103026Ssobomax#include <sys/queue.h>
39103026Ssobomax
40125024Ssobomax/*
41125024Ssobomax * Version of the WCCP, need to be configured manually since
42125024Ssobomax * header for version 2 is the same but IP payload is prepended
43125024Ssobomax * with additional 4-bytes field.
44125024Ssobomax */
45125024Ssobomaxtypedef enum {
46125024Ssobomax	WCCP_V1 = 0,
47125024Ssobomax	WCCP_V2
48125024Ssobomax} wccp_ver_t;
49125024Ssobomax
50103026Ssobomaxstruct gre_softc {
51147256Sbrooks	struct ifnet *sc_ifp;
52103026Ssobomax	LIST_ENTRY(gre_softc) sc_list;
53103026Ssobomax	int gre_unit;
54103026Ssobomax	int gre_flags;
55178888Sjulian	u_int	gre_fibnum;	/* use this fib for envelopes */
56103026Ssobomax	struct in_addr g_src;	/* source address of gre packets */
57103026Ssobomax	struct in_addr g_dst;	/* destination address of gre packets */
58103026Ssobomax	struct route route;	/* routing entry that determines, where a
59103026Ssobomax				   encapsulated packet should go */
60103026Ssobomax	u_char g_proto;		/* protocol of encapsulator */
61103026Ssobomax
62103026Ssobomax	const struct encaptab *encap;	/* encapsulation cookie */
63103026Ssobomax
64179894Sthompsa	uint32_t key;		/* key included in outgoing GRE packets */
65179894Sthompsa				/* zero means none */
66179894Sthompsa
67125024Ssobomax	wccp_ver_t wccp_ver;	/* version of the WCCP */
68125020Ssobomax};
69147256Sbrooks#define	GRE2IFP(sc)	((sc)->sc_ifp)
70103026Ssobomax
71103026Ssobomax
72103026Ssobomaxstruct gre_h {
73103026Ssobomax	u_int16_t flags;	/* GRE flags */
74125020Ssobomax	u_int16_t ptype;	/* protocol type of payload typically
75103026Ssobomax				   Ether protocol type*/
76179894Sthompsa	uint32_t options[0];	/* optional options */
77125020Ssobomax/*
78125020Ssobomax *  from here on: fields are optional, presence indicated by flags
79103026Ssobomax *
80103026Ssobomax	u_int_16 checksum	checksum (one-complements of GRE header
81103026Ssobomax				and payload
82103026Ssobomax				Present if (ck_pres | rt_pres == 1).
83103026Ssobomax				Valid if (ck_pres == 1).
84103026Ssobomax	u_int_16 offset		offset from start of routing filed to
85103026Ssobomax				first octet of active SRE (see below).
86103026Ssobomax				Present if (ck_pres | rt_pres == 1).
87103026Ssobomax				Valid if (rt_pres == 1).
88103026Ssobomax	u_int_32 key		inserted by encapsulator e.g. for
89103026Ssobomax				authentication
90103026Ssobomax				Present if (key_pres ==1 ).
91103026Ssobomax	u_int_32 seq_num	Sequence number to allow for packet order
92103026Ssobomax				Present if (seq_pres ==1 ).
93103026Ssobomax	struct gre_sre[] routing Routing fileds (see below)
94103026Ssobomax				Present if (rt_pres == 1)
95103026Ssobomax */
96103842Salfred} __packed;
97103026Ssobomax
98103026Ssobomaxstruct greip {
99103026Ssobomax	struct ip gi_i;
100103026Ssobomax	struct gre_h  gi_g;
101103842Salfred} __packed;
102103026Ssobomax
103103026Ssobomax#define gi_pr		gi_i.ip_p
104103026Ssobomax#define gi_len		gi_i.ip_len
105103026Ssobomax#define gi_src		gi_i.ip_src
106103026Ssobomax#define gi_dst		gi_i.ip_dst
107103026Ssobomax#define gi_ptype	gi_g.ptype
108103026Ssobomax#define gi_flags	gi_g.flags
109179894Sthompsa#define gi_options	gi_g.options
110103026Ssobomax
111103026Ssobomax#define GRE_CP		0x8000  /* Checksum Present */
112103026Ssobomax#define GRE_RP		0x4000  /* Routing Present */
113103026Ssobomax#define GRE_KP		0x2000  /* Key Present */
114103026Ssobomax#define GRE_SP		0x1000  /* Sequence Present */
115103026Ssobomax#define GRE_SS		0x0800	/* Strict Source Route */
116103026Ssobomax
117103026Ssobomax/*
118107670Ssobomax * CISCO uses special type for GRE tunnel created as part of WCCP
119107670Ssobomax * connection, while in fact those packets are just IPv4 encapsulated
120107670Ssobomax * into GRE.
121107670Ssobomax */
122107670Ssobomax#define WCCP_PROTOCOL_TYPE	0x883E
123107670Ssobomax
124107670Ssobomax/*
125103026Ssobomax * gre_sre defines a Source route Entry. These are needed if packets
126103026Ssobomax * should be routed over more than one tunnel hop by hop
127103026Ssobomax */
128103026Ssobomaxstruct gre_sre {
129123992Ssobomax	u_int16_t sre_family;	/* address family */
130103026Ssobomax	u_char	sre_offset;	/* offset to first octet of active entry */
131125020Ssobomax	u_char	sre_length;	/* number of octets in the SRE.
132103026Ssobomax				   sre_lengthl==0 -> last entry. */
133103026Ssobomax	u_char	*sre_rtinfo;	/* the routing information */
134103026Ssobomax};
135103026Ssobomax
136103026Ssobomaxstruct greioctl {
137103026Ssobomax	int unit;
138103026Ssobomax	struct in_addr addr;
139103026Ssobomax};
140103026Ssobomax
141103026Ssobomax/* for mobile encaps */
142103026Ssobomax
143103026Ssobomaxstruct mobile_h {
144103026Ssobomax	u_int16_t proto;		/* protocol and S-bit */
145103026Ssobomax	u_int16_t hcrc;			/* header checksum */
146103026Ssobomax	u_int32_t odst;			/* original destination address */
147103026Ssobomax	u_int32_t osrc;			/* original source addr, if S-bit set */
148103842Salfred} __packed;
149103026Ssobomax
150103026Ssobomaxstruct mobip_h {
151103026Ssobomax	struct ip	mi;
152103026Ssobomax	struct mobile_h	mh;
153103842Salfred} __packed;
154103026Ssobomax
155103026Ssobomax
156103026Ssobomax#define MOB_H_SIZ_S		(sizeof(struct mobile_h) - sizeof(u_int32_t))
157103026Ssobomax#define MOB_H_SIZ_L		(sizeof(struct mobile_h))
158103026Ssobomax#define MOB_H_SBIT	0x0080
159103026Ssobomax
160103026Ssobomax#define	GRE_TTL	30
161103026Ssobomax
162103120Ssobomax#endif /* _KERNEL */
163103120Ssobomax
164125020Ssobomax/*
165125020Ssobomax * ioctls needed to manipulate the interface
166103026Ssobomax */
167103026Ssobomax
168103026Ssobomax#define GRESADDRS	_IOW('i', 101, struct ifreq)
169125020Ssobomax#define GRESADDRD	_IOW('i', 102, struct ifreq)
170103026Ssobomax#define GREGADDRS	_IOWR('i', 103, struct ifreq)
171103026Ssobomax#define GREGADDRD	_IOWR('i', 104, struct ifreq)
172103026Ssobomax#define GRESPROTO	_IOW('i' , 105, struct ifreq)
173103026Ssobomax#define GREGPROTO	_IOWR('i', 106, struct ifreq)
174179894Sthompsa#define GREGKEY		_IOWR('i', 107, struct ifreq)
175179894Sthompsa#define GRESKEY		_IOW('i', 108, struct ifreq)
176103026Ssobomax
177103026Ssobomax#ifdef _KERNEL
178103026SsobomaxLIST_HEAD(gre_softc_head, gre_softc);
179127307Srwatsonextern struct mtx gre_mtx;
180103026Ssobomaxextern struct gre_softc_head gre_softc_list;
181103026Ssobomax
182123992Ssobomaxu_int16_t	gre_in_cksum(u_int16_t *, u_int);
183103026Ssobomax#endif /* _KERNEL */
184103026Ssobomax
185103026Ssobomax#endif
186