1 /* $NetBSD: if_gre.h,v 1.42 2011/11/29 17:28:45 drochner Exp $ */ 2 3 /* 4 * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Heiko W.Rupp <hwr@pilhuhn.de> 9 * 10 * This code is derived from software contributed to The NetBSD Foundation 11 * by David Young <dyoung@NetBSD.org> 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 * POSSIBILITY OF SUCH DAMAGE. 33 * 34 * This material is based upon work partially supported by NSF 35 * under Contract No. NSF CNS-0626584. 36 */ 37 38 #ifndef _NET_IF_GRE_H_ 39 #define _NET_IF_GRE_H_ 40 41 #include <sys/evcnt.h> 42 #include <sys/queue.h> 43 #include <sys/mutex.h> 44 #include <sys/condvar.h> 45 #include <sys/malloc.h> 46 #include <sys/mallocvar.h> 47 48 #ifdef _KERNEL 49 50 #include <sys/pcq.h> 51 52 struct gre_soparm { 53 struct socket *sp_so; 54 struct sockaddr_storage sp_src; /* source of gre packets */ 55 struct sockaddr_storage sp_dst; /* destination of gre packets */ 56 int sp_type; /* encapsulating socket type */ 57 int sp_proto; /* encapsulating protocol */ 58 bool sp_bysock; /* encapsulation configured by passing 59 * socket, not by SIOCSLIFPHYADDR 60 */ 61 }; 62 63 enum gre_state { 64 GRE_S_IDLE = 0 65 , GRE_S_IOCTL 66 , GRE_S_DIE 67 }; 68 69 struct gre_bufq { 70 pcq_t *bq_q; 71 volatile int bq_drops; 72 }; 73 74 enum gre_msg { 75 GRE_M_NONE = 0 76 , GRE_M_SETFP 77 , GRE_M_DELFP 78 , GRE_M_STOP 79 , GRE_M_OK 80 , GRE_M_ERR 81 }; 82 83 struct gre_softc { 84 struct ifnet sc_if; 85 kmutex_t sc_mtx; 86 kcondvar_t sc_condvar; 87 kcondvar_t sc_fp_condvar; 88 struct gre_bufq sc_snd; 89 struct gre_soparm sc_soparm; 90 volatile enum gre_state sc_state; 91 volatile int sc_waiters; 92 volatile int sc_fp_waiters; 93 void *sc_si; 94 95 struct evcnt sc_recv_ev; 96 struct evcnt sc_send_ev; 97 98 struct evcnt sc_block_ev; 99 struct evcnt sc_error_ev; 100 struct evcnt sc_pullup_ev; 101 struct evcnt sc_unsupp_ev; 102 struct evcnt sc_oflow_ev; 103 file_t * volatile sc_fp; 104 volatile enum gre_msg sc_msg; 105 int sc_fd; 106 }; 107 108 struct gre_h { 109 uint16_t flags; /* GRE flags */ 110 uint16_t ptype; /* protocol type of payload typically 111 * ethernet protocol type 112 */ 113 /* 114 * from here on: fields are optional, presence indicated by flags 115 * 116 u_int_16 checksum checksum (one-complements of GRE header 117 and payload 118 Present if (ck_pres | rt_pres == 1). 119 Valid if (ck_pres == 1). 120 u_int_16 offset offset from start of routing filed to 121 first octet of active SRE (see below). 122 Present if (ck_pres | rt_pres == 1). 123 Valid if (rt_pres == 1). 124 u_int_32 key inserted by encapsulator e.g. for 125 authentication 126 Present if (key_pres ==1 ). 127 u_int_32 seq_num Sequence number to allow for packet order 128 Present if (seq_pres ==1 ). 129 struct gre_sre[] routing Routing fileds (see below) 130 Present if (rt_pres == 1) 131 */ 132 } __packed; 133 134 #define GRE_CP 0x8000 /* Checksum Present */ 135 #define GRE_RP 0x4000 /* Routing Present */ 136 #define GRE_KP 0x2000 /* Key Present */ 137 #define GRE_SP 0x1000 /* Sequence Present */ 138 #define GRE_SS 0x0800 /* Strict Source Route */ 139 140 /* 141 * gre_sre defines a Source route Entry. These are needed if packets 142 * should be routed over more than one tunnel hop by hop 143 */ 144 struct gre_sre { 145 uint16_t sre_family; /* address family */ 146 u_char sre_offset; /* offset to first octet of active entry */ 147 u_char sre_length; /* number of octets in the SRE. 148 sre_lengthl==0 -> last entry. */ 149 u_char *sre_rtinfo; /* the routing information */ 150 }; 151 152 #define GRE_TTL 30 153 extern int ip_gre_ttl; 154 #endif /* _KERNEL */ 155 156 /* 157 * ioctls needed to manipulate the interface 158 */ 159 160 #define GRESADDRS _IOW('i', 101, struct ifreq) 161 #define GRESADDRD _IOW('i', 102, struct ifreq) 162 #define GREGADDRS _IOWR('i', 103, struct ifreq) 163 #define GREGADDRD _IOWR('i', 104, struct ifreq) 164 #define GRESPROTO _IOW('i' , 105, struct ifreq) 165 #define GREGPROTO _IOWR('i', 106, struct ifreq) 166 #define GRESSOCK _IOW('i' , 107, struct ifreq) 167 #define GREDSOCK _IOW('i' , 108, struct ifreq) 168 169 #endif /* !_NET_IF_GRE_H_ */ 170