1 /* $OpenBSD: if_gre.h,v 1.4 2001/06/09 06:16:38 angelos Exp $ */ 2 /* $NetBSD: if_gre.h,v 1.5 1999/11/19 20:41:19 thorpej Exp $ */ 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 struct gre_softc { 44 struct ifnet sc_if; 45 int gre_unit; 46 int gre_flags; 47 struct in_addr g_src; /* source address of gre packets */ 48 struct in_addr g_dst; /* destination address of gre packets */ 49 struct route route; /* routing entry that determines, where a 50 encapsulated packet should go */ 51 u_char g_proto; /* protocol of encapsulator */ 52 }; 53 54 55 struct gre_h { 56 u_int16_t flags; /* GRE flags */ 57 u_int16_t ptype; /* protocol type of payload typically 58 Ether protocol type*/ 59 /* 60 * from here on: fields are optional, presence indicated by flags 61 * 62 u_int_16 checksum checksum (one-complements of GRE header 63 and payload 64 Present if (ck_pres | rt_pres == 1). 65 Valid if (ck_pres == 1). 66 u_int_16 offset offset from start of routing filed to 67 first octet of active SRE (see below). 68 Present if (ck_pres | rt_pres == 1). 69 Valid if (rt_pres == 1). 70 u_int_32 key inserted by encapsulator e.g. for 71 authentication 72 Present if (key_pres ==1 ). 73 u_int_32 seq_num Sequence number to allow for packet order 74 Present if (seq_pres ==1 ). 75 76 struct gre_sre[] routing Routing fileds (see below) 77 Present if (rt_pres == 1) 78 */ 79 } __attribute__((__packed__)); 80 81 struct greip { 82 struct ip gi_i; 83 struct gre_h gi_g; 84 } __attribute__((__packed__)); 85 86 #define gi_pr gi_i.ip_p 87 #define gi_len gi_i.ip_len 88 #define gi_src gi_i.ip_src 89 #define gi_dst gi_i.ip_dst 90 #define gi_ptype gi_g.ptype 91 #define gi_flags gi_g.flags 92 93 #define GRE_CP 0x8000 /* Checksum Present */ 94 #define GRE_RP 0x4000 /* Routing Present */ 95 #define GRE_KP 0x2000 /* Key Present */ 96 #define GRE_SP 0x1000 /* Sequence Present */ 97 #define GRE_SS 0x0800 /* Strict Source Route */ 98 99 /* gre_sre defines a Source route Entry. These are needed if packets 100 * should be routed over more than one tunnel hop by hop 101 */ 102 103 struct gre_sre { 104 u_int16_t sre_family; /* adress family */ 105 u_char sre_offset; /* offset to first octet of active entry */ 106 u_char sre_length; /* number of octets in the SRE. 107 sre_lengthl==0 -> last entry. */ 108 u_char *sre_rtinfo; /* the routing information */ 109 }; 110 111 struct greioctl { 112 int unit; 113 struct in_addr addr; 114 }; 115 116 /* for mobile encaps */ 117 118 struct mobile_h { 119 u_int16_t proto; /* protocol and S-bit */ 120 u_int16_t hcrc; /* header checksum */ 121 u_int32_t odst; /* original destination address */ 122 u_int32_t osrc; /* original source addr, if S-bit set */ 123 } __attribute__((__packed__)); 124 125 struct mobip_h { 126 struct ip mi; 127 struct mobile_h mh; 128 } __attribute__((__packed__)); 129 130 131 #define MOB_H_SIZ_S (sizeof(struct mobile_h) - sizeof(u_int32_t)) 132 #define MOB_H_SIZ_L (sizeof(struct mobile_h)) 133 #define MOB_H_SBIT 0x0080 134 135 136 /* 137 * ioctls needed to manipulate the interface 138 */ 139 140 #ifdef _KERNEL 141 extern struct gre_softc *gre; 142 extern int ngre; 143 extern int gre_allow; 144 extern int ip_mobile_allow; 145 146 void greattach __P((int)); 147 int gre_ioctl __P((struct ifnet *, u_long, caddr_t)); 148 int gre_output __P((struct ifnet *, struct mbuf *, struct sockaddr *, 149 struct rtentry *rt)); 150 u_short gre_in_cksum(u_short *p, u_int len); 151 #endif /* _KERNEL */ 152 #endif /* _NET_IF_GRE_H_ */ 153