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 * 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 477735aeb9SMaxim Sobolev /* 487735aeb9SMaxim Sobolev * Version of the WCCP, need to be configured manually since 497735aeb9SMaxim Sobolev * header for version 2 is the same but IP payload is prepended 507735aeb9SMaxim Sobolev * with additional 4-bytes field. 517735aeb9SMaxim Sobolev */ 527735aeb9SMaxim Sobolev typedef enum { 537735aeb9SMaxim Sobolev WCCP_V1 = 0, 547735aeb9SMaxim Sobolev WCCP_V2 557735aeb9SMaxim Sobolev } wccp_ver_t; 567735aeb9SMaxim Sobolev 578e96e13eSMaxim Sobolev struct gre_softc { 58fc74a9f9SBrooks Davis struct ifnet *sc_ifp; 598e96e13eSMaxim Sobolev LIST_ENTRY(gre_softc) sc_list; 608e96e13eSMaxim Sobolev int gre_unit; 618e96e13eSMaxim Sobolev int gre_flags; 628e96e13eSMaxim Sobolev struct in_addr g_src; /* source address of gre packets */ 638e96e13eSMaxim Sobolev struct in_addr g_dst; /* destination address of gre packets */ 648e96e13eSMaxim Sobolev struct route route; /* routing entry that determines, where a 658e96e13eSMaxim Sobolev encapsulated packet should go */ 668e96e13eSMaxim Sobolev u_char g_proto; /* protocol of encapsulator */ 678e96e13eSMaxim Sobolev 688e96e13eSMaxim Sobolev const struct encaptab *encap; /* encapsulation cookie */ 698e96e13eSMaxim Sobolev 708e96e13eSMaxim Sobolev int called; /* infinite recursion preventer */ 717735aeb9SMaxim Sobolev 727735aeb9SMaxim Sobolev wccp_ver_t wccp_ver; /* version of the WCCP */ 738e96e13eSMaxim Sobolev }; 74fc74a9f9SBrooks Davis #define GRE2IFP(sc) ((sc)->sc_ifp) 758e96e13eSMaxim Sobolev 768e96e13eSMaxim Sobolev 778e96e13eSMaxim Sobolev struct gre_h { 788e96e13eSMaxim Sobolev u_int16_t flags; /* GRE flags */ 798e96e13eSMaxim Sobolev u_int16_t ptype; /* protocol type of payload typically 808e96e13eSMaxim Sobolev Ether protocol type*/ 818e96e13eSMaxim Sobolev /* 828e96e13eSMaxim Sobolev * from here on: fields are optional, presence indicated by flags 838e96e13eSMaxim Sobolev * 848e96e13eSMaxim Sobolev u_int_16 checksum checksum (one-complements of GRE header 858e96e13eSMaxim Sobolev and payload 868e96e13eSMaxim Sobolev Present if (ck_pres | rt_pres == 1). 878e96e13eSMaxim Sobolev Valid if (ck_pres == 1). 888e96e13eSMaxim Sobolev u_int_16 offset offset from start of routing filed to 898e96e13eSMaxim Sobolev first octet of active SRE (see below). 908e96e13eSMaxim Sobolev Present if (ck_pres | rt_pres == 1). 918e96e13eSMaxim Sobolev Valid if (rt_pres == 1). 928e96e13eSMaxim Sobolev u_int_32 key inserted by encapsulator e.g. for 938e96e13eSMaxim Sobolev authentication 948e96e13eSMaxim Sobolev Present if (key_pres ==1 ). 958e96e13eSMaxim Sobolev u_int_32 seq_num Sequence number to allow for packet order 968e96e13eSMaxim Sobolev Present if (seq_pres ==1 ). 978e96e13eSMaxim Sobolev struct gre_sre[] routing Routing fileds (see below) 988e96e13eSMaxim Sobolev Present if (rt_pres == 1) 998e96e13eSMaxim Sobolev */ 100ebc82cbbSAlfred Perlstein } __packed; 1018e96e13eSMaxim Sobolev 1028e96e13eSMaxim Sobolev struct greip { 1038e96e13eSMaxim Sobolev struct ip gi_i; 1048e96e13eSMaxim Sobolev struct gre_h gi_g; 105ebc82cbbSAlfred Perlstein } __packed; 1068e96e13eSMaxim Sobolev 1078e96e13eSMaxim Sobolev #define gi_pr gi_i.ip_p 1088e96e13eSMaxim Sobolev #define gi_len gi_i.ip_len 1098e96e13eSMaxim Sobolev #define gi_src gi_i.ip_src 1108e96e13eSMaxim Sobolev #define gi_dst gi_i.ip_dst 1118e96e13eSMaxim Sobolev #define gi_ptype gi_g.ptype 1128e96e13eSMaxim Sobolev #define gi_flags gi_g.flags 1138e96e13eSMaxim Sobolev 1148e96e13eSMaxim Sobolev #define GRE_CP 0x8000 /* Checksum Present */ 1158e96e13eSMaxim Sobolev #define GRE_RP 0x4000 /* Routing Present */ 1168e96e13eSMaxim Sobolev #define GRE_KP 0x2000 /* Key Present */ 1178e96e13eSMaxim Sobolev #define GRE_SP 0x1000 /* Sequence Present */ 1188e96e13eSMaxim Sobolev #define GRE_SS 0x0800 /* Strict Source Route */ 1198e96e13eSMaxim Sobolev 1208e96e13eSMaxim Sobolev /* 12116199bf2SMaxim Sobolev * CISCO uses special type for GRE tunnel created as part of WCCP 12216199bf2SMaxim Sobolev * connection, while in fact those packets are just IPv4 encapsulated 12316199bf2SMaxim Sobolev * into GRE. 12416199bf2SMaxim Sobolev */ 12516199bf2SMaxim Sobolev #define WCCP_PROTOCOL_TYPE 0x883E 12616199bf2SMaxim Sobolev 12716199bf2SMaxim Sobolev /* 1288e96e13eSMaxim Sobolev * gre_sre defines a Source route Entry. These are needed if packets 1298e96e13eSMaxim Sobolev * should be routed over more than one tunnel hop by hop 1308e96e13eSMaxim Sobolev */ 1318e96e13eSMaxim Sobolev struct gre_sre { 13273d7ddbcSMaxim Sobolev u_int16_t sre_family; /* address family */ 1338e96e13eSMaxim Sobolev u_char sre_offset; /* offset to first octet of active entry */ 1348e96e13eSMaxim Sobolev u_char sre_length; /* number of octets in the SRE. 1358e96e13eSMaxim Sobolev sre_lengthl==0 -> last entry. */ 1368e96e13eSMaxim Sobolev u_char *sre_rtinfo; /* the routing information */ 1378e96e13eSMaxim Sobolev }; 1388e96e13eSMaxim Sobolev 1398e96e13eSMaxim Sobolev struct greioctl { 1408e96e13eSMaxim Sobolev int unit; 1418e96e13eSMaxim Sobolev struct in_addr addr; 1428e96e13eSMaxim Sobolev }; 1438e96e13eSMaxim Sobolev 1448e96e13eSMaxim Sobolev /* for mobile encaps */ 1458e96e13eSMaxim Sobolev 1468e96e13eSMaxim Sobolev struct mobile_h { 1478e96e13eSMaxim Sobolev u_int16_t proto; /* protocol and S-bit */ 1488e96e13eSMaxim Sobolev u_int16_t hcrc; /* header checksum */ 1498e96e13eSMaxim Sobolev u_int32_t odst; /* original destination address */ 1508e96e13eSMaxim Sobolev u_int32_t osrc; /* original source addr, if S-bit set */ 151ebc82cbbSAlfred Perlstein } __packed; 1528e96e13eSMaxim Sobolev 1538e96e13eSMaxim Sobolev struct mobip_h { 1548e96e13eSMaxim Sobolev struct ip mi; 1558e96e13eSMaxim Sobolev struct mobile_h mh; 156ebc82cbbSAlfred Perlstein } __packed; 1578e96e13eSMaxim Sobolev 1588e96e13eSMaxim Sobolev 1598e96e13eSMaxim Sobolev #define MOB_H_SIZ_S (sizeof(struct mobile_h) - sizeof(u_int32_t)) 1608e96e13eSMaxim Sobolev #define MOB_H_SIZ_L (sizeof(struct mobile_h)) 1618e96e13eSMaxim Sobolev #define MOB_H_SBIT 0x0080 1628e96e13eSMaxim Sobolev 1638e96e13eSMaxim Sobolev #define GRE_TTL 30 1648e96e13eSMaxim Sobolev 165ccd6d236SMaxim Sobolev #endif /* _KERNEL */ 166ccd6d236SMaxim Sobolev 1678e96e13eSMaxim Sobolev /* 1688e96e13eSMaxim Sobolev * ioctls needed to manipulate the interface 1698e96e13eSMaxim Sobolev */ 1708e96e13eSMaxim Sobolev 1718e96e13eSMaxim Sobolev #define GRESADDRS _IOW('i', 101, struct ifreq) 1728e96e13eSMaxim Sobolev #define GRESADDRD _IOW('i', 102, struct ifreq) 1738e96e13eSMaxim Sobolev #define GREGADDRS _IOWR('i', 103, struct ifreq) 1748e96e13eSMaxim Sobolev #define GREGADDRD _IOWR('i', 104, struct ifreq) 1758e96e13eSMaxim Sobolev #define GRESPROTO _IOW('i' , 105, struct ifreq) 1768e96e13eSMaxim Sobolev #define GREGPROTO _IOWR('i', 106, struct ifreq) 1778e96e13eSMaxim Sobolev 1788e96e13eSMaxim Sobolev #ifdef _KERNEL 1798e96e13eSMaxim Sobolev LIST_HEAD(gre_softc_head, gre_softc); 180bdae44a8SRobert Watson extern struct mtx gre_mtx; 1818e96e13eSMaxim Sobolev extern struct gre_softc_head gre_softc_list; 1828e96e13eSMaxim Sobolev 18373d7ddbcSMaxim Sobolev u_int16_t gre_in_cksum(u_int16_t *, u_int); 1848e96e13eSMaxim Sobolev #endif /* _KERNEL */ 1858e96e13eSMaxim Sobolev 1868e96e13eSMaxim Sobolev #endif 187