]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - sys/net/if_gre.h
MFC r297884
[FreeBSD/stable/8.git] / sys / net / if_gre.h
1 /*      $NetBSD: if_gre.h,v 1.13 2003/11/10 08:51:52 wiz Exp $ */
2 /*       $FreeBSD$ */
3
4 /*-
5  * Copyright (c) 1998 The NetBSD Foundation, Inc.
6  * All rights reserved
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Heiko W.Rupp <hwr@pilhuhn.de>
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *        This product includes software developed by the NetBSD
22  *        Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39
40 #ifndef _NET_IF_GRE_H
41 #define _NET_IF_GRE_H
42
43 #include <sys/ioccom.h>
44 #ifdef _KERNEL
45 #include <sys/queue.h>
46
47 /*
48  * Version of the WCCP, need to be configured manually since
49  * header for version 2 is the same but IP payload is prepended
50  * with additional 4-bytes field.
51  */
52 typedef enum {
53         WCCP_V1 = 0,
54         WCCP_V2
55 } wccp_ver_t;
56
57 struct gre_softc {
58         struct ifnet *sc_ifp;
59         LIST_ENTRY(gre_softc) sc_list;
60         int gre_unit;
61         int gre_flags;
62         u_int   gre_fibnum;     /* use this fib for envelopes */
63         struct in_addr g_src;   /* source address of gre packets */
64         struct in_addr g_dst;   /* destination address of gre packets */
65         struct route route;     /* routing entry that determines, where a
66                                    encapsulated packet should go */
67         u_char g_proto;         /* protocol of encapsulator */
68
69         const struct encaptab *encap;   /* encapsulation cookie */
70
71         uint32_t key;           /* key included in outgoing GRE packets */
72                                 /* zero means none */
73
74         wccp_ver_t wccp_ver;    /* version of the WCCP */
75 };
76 #define GRE2IFP(sc)     ((sc)->sc_ifp)
77
78
79 struct gre_h {
80         u_int16_t flags;        /* GRE flags */
81         u_int16_t ptype;        /* protocol type of payload typically
82                                    Ether protocol type*/
83         uint32_t options[0];    /* optional options */
84 /*
85  *  from here on: fields are optional, presence indicated by flags
86  *
87         u_int_16 checksum       checksum (one-complements of GRE header
88                                 and payload
89                                 Present if (ck_pres | rt_pres == 1).
90                                 Valid if (ck_pres == 1).
91         u_int_16 offset         offset from start of routing filed to
92                                 first octet of active SRE (see below).
93                                 Present if (ck_pres | rt_pres == 1).
94                                 Valid if (rt_pres == 1).
95         u_int_32 key            inserted by encapsulator e.g. for
96                                 authentication
97                                 Present if (key_pres ==1 ).
98         u_int_32 seq_num        Sequence number to allow for packet order
99                                 Present if (seq_pres ==1 ).
100         struct gre_sre[] routing Routing fileds (see below)
101                                 Present if (rt_pres == 1)
102  */
103 } __packed;
104
105 struct greip {
106         struct ip gi_i;
107         struct gre_h  gi_g;
108 } __packed;
109
110 #define gi_pr           gi_i.ip_p
111 #define gi_len          gi_i.ip_len
112 #define gi_src          gi_i.ip_src
113 #define gi_dst          gi_i.ip_dst
114 #define gi_ptype        gi_g.ptype
115 #define gi_flags        gi_g.flags
116 #define gi_options      gi_g.options
117
118 #define GRE_CP          0x8000  /* Checksum Present */
119 #define GRE_RP          0x4000  /* Routing Present */
120 #define GRE_KP          0x2000  /* Key Present */
121 #define GRE_SP          0x1000  /* Sequence Present */
122 #define GRE_SS          0x0800  /* Strict Source Route */
123
124 /*
125  * CISCO uses special type for GRE tunnel created as part of WCCP
126  * connection, while in fact those packets are just IPv4 encapsulated
127  * into GRE.
128  */
129 #define WCCP_PROTOCOL_TYPE      0x883E
130
131 /*
132  * gre_sre defines a Source route Entry. These are needed if packets
133  * should be routed over more than one tunnel hop by hop
134  */
135 struct gre_sre {
136         u_int16_t sre_family;   /* address family */
137         u_char  sre_offset;     /* offset to first octet of active entry */
138         u_char  sre_length;     /* number of octets in the SRE.
139                                    sre_lengthl==0 -> last entry. */
140         u_char  *sre_rtinfo;    /* the routing information */
141 };
142
143 struct greioctl {
144         int unit;
145         struct in_addr addr;
146 };
147
148 /* for mobile encaps */
149
150 struct mobile_h {
151         u_int16_t proto;                /* protocol and S-bit */
152         u_int16_t hcrc;                 /* header checksum */
153         u_int32_t odst;                 /* original destination address */
154         u_int32_t osrc;                 /* original source addr, if S-bit set */
155 } __packed;
156
157 struct mobip_h {
158         struct ip       mi;
159         struct mobile_h mh;
160 } __packed;
161
162
163 #define MOB_H_SIZ_S             (sizeof(struct mobile_h) - sizeof(u_int32_t))
164 #define MOB_H_SIZ_L             (sizeof(struct mobile_h))
165 #define MOB_H_SBIT      0x0080
166
167 #define GRE_TTL 30
168
169 #endif /* _KERNEL */
170
171 /*
172  * ioctls needed to manipulate the interface
173  */
174
175 #define GRESADDRS       _IOW('i', 101, struct ifreq)
176 #define GRESADDRD       _IOW('i', 102, struct ifreq)
177 #define GREGADDRS       _IOWR('i', 103, struct ifreq)
178 #define GREGADDRD       _IOWR('i', 104, struct ifreq)
179 #define GRESPROTO       _IOW('i' , 105, struct ifreq)
180 #define GREGPROTO       _IOWR('i', 106, struct ifreq)
181 #define GREGKEY         _IOWR('i', 107, struct ifreq)
182 #define GRESKEY         _IOW('i', 108, struct ifreq)
183
184 #ifdef _KERNEL
185 LIST_HEAD(gre_softc_head, gre_softc);
186 extern struct mtx gre_mtx;
187 extern struct gre_softc_head gre_softc_list;
188
189 u_int16_t       gre_in_cksum(u_int16_t *, u_int);
190 #endif /* _KERNEL */
191
192 #endif