| 1 | /* $NetBSD: if_gre.h,v 1.43 2015/09/06 06:01:01 dholland 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/ioccom.h> |
| 42 | #include <sys/evcnt.h> |
| 43 | #include <sys/queue.h> |
| 44 | #include <sys/mutex.h> |
| 45 | #include <sys/condvar.h> |
| 46 | #include <sys/malloc.h> |
| 47 | #include <sys/mallocvar.h> |
| 48 | |
| 49 | #ifdef _KERNEL |
| 50 | |
| 51 | #include <sys/pcq.h> |
| 52 | |
| 53 | struct gre_soparm { |
| 54 | struct socket *sp_so; |
| 55 | struct sockaddr_storage sp_src; /* source of gre packets */ |
| 56 | struct sockaddr_storage sp_dst; /* destination of gre packets */ |
| 57 | int sp_type; /* encapsulating socket type */ |
| 58 | int sp_proto; /* encapsulating protocol */ |
| 59 | bool sp_bysock; /* encapsulation configured by passing |
| 60 | * socket, not by SIOCSLIFPHYADDR |
| 61 | */ |
| 62 | }; |
| 63 | |
| 64 | enum gre_state { |
| 65 | GRE_S_IDLE = 0 |
| 66 | , GRE_S_IOCTL |
| 67 | , GRE_S_DIE |
| 68 | }; |
| 69 | |
| 70 | struct gre_bufq { |
| 71 | pcq_t *bq_q; |
| 72 | volatile int bq_drops; |
| 73 | }; |
| 74 | |
| 75 | enum gre_msg { |
| 76 | GRE_M_NONE = 0 |
| 77 | , GRE_M_SETFP |
| 78 | , GRE_M_DELFP |
| 79 | , GRE_M_STOP |
| 80 | , GRE_M_OK |
| 81 | , GRE_M_ERR |
| 82 | }; |
| 83 | |
| 84 | struct gre_softc { |
| 85 | struct ifnet sc_if; |
| 86 | kmutex_t sc_mtx; |
| 87 | kcondvar_t sc_condvar; |
| 88 | kcondvar_t sc_fp_condvar; |
| 89 | struct gre_bufq sc_snd; |
| 90 | struct gre_soparm sc_soparm; |
| 91 | volatile enum gre_state sc_state; |
| 92 | volatile int sc_waiters; |
| 93 | volatile int sc_fp_waiters; |
| 94 | void *sc_si; |
| 95 | |
| 96 | struct evcnt sc_recv_ev; |
| 97 | struct evcnt sc_send_ev; |
| 98 | |
| 99 | struct evcnt sc_block_ev; |
| 100 | struct evcnt sc_error_ev; |
| 101 | struct evcnt sc_pullup_ev; |
| 102 | struct evcnt sc_unsupp_ev; |
| 103 | struct evcnt sc_oflow_ev; |
| 104 | file_t * volatile sc_fp; |
| 105 | volatile enum gre_msg sc_msg; |
| 106 | int sc_fd; |
| 107 | }; |
| 108 | |
| 109 | struct gre_h { |
| 110 | uint16_t flags; /* GRE flags */ |
| 111 | uint16_t ptype; /* protocol type of payload typically |
| 112 | * ethernet protocol type |
| 113 | */ |
| 114 | /* |
| 115 | * from here on: fields are optional, presence indicated by flags |
| 116 | * |
| 117 | u_int_16 checksum checksum (one-complements of GRE header |
| 118 | and payload |
| 119 | Present if (ck_pres | rt_pres == 1). |
| 120 | Valid if (ck_pres == 1). |
| 121 | u_int_16 offset offset from start of routing filed to |
| 122 | first octet of active SRE (see below). |
| 123 | Present if (ck_pres | rt_pres == 1). |
| 124 | Valid if (rt_pres == 1). |
| 125 | u_int_32 key inserted by encapsulator e.g. for |
| 126 | authentication |
| 127 | Present if (key_pres ==1 ). |
| 128 | u_int_32 seq_num Sequence number to allow for packet order |
| 129 | Present if (seq_pres ==1 ). |
| 130 | struct gre_sre[] routing Routing fileds (see below) |
| 131 | Present if (rt_pres == 1) |
| 132 | */ |
| 133 | } __packed; |
| 134 | |
| 135 | #define GRE_CP 0x8000 /* Checksum Present */ |
| 136 | #define GRE_RP 0x4000 /* Routing Present */ |
| 137 | #define GRE_KP 0x2000 /* Key Present */ |
| 138 | #define GRE_SP 0x1000 /* Sequence Present */ |
| 139 | #define GRE_SS 0x0800 /* Strict Source Route */ |
| 140 | |
| 141 | /* |
| 142 | * gre_sre defines a Source route Entry. These are needed if packets |
| 143 | * should be routed over more than one tunnel hop by hop |
| 144 | */ |
| 145 | struct gre_sre { |
| 146 | uint16_t sre_family; /* address family */ |
| 147 | u_char sre_offset; /* offset to first octet of active entry */ |
| 148 | u_char sre_length; /* number of octets in the SRE. |
| 149 | sre_lengthl==0 -> last entry. */ |
| 150 | u_char *sre_rtinfo; /* the routing information */ |
| 151 | }; |
| 152 | |
| 153 | #define GRE_TTL 30 |
| 154 | extern int ip_gre_ttl; |
| 155 | #endif /* _KERNEL */ |
| 156 | |
| 157 | /* |
| 158 | * ioctls needed to manipulate the interface |
| 159 | */ |
| 160 | |
| 161 | #define GRESADDRS _IOW('i', 101, struct ifreq) |
| 162 | #define GRESADDRD _IOW('i', 102, struct ifreq) |
| 163 | #define GREGADDRS _IOWR('i', 103, struct ifreq) |
| 164 | #define GREGADDRD _IOWR('i', 104, struct ifreq) |
| 165 | #define GRESPROTO _IOW('i' , 105, struct ifreq) |
| 166 | #define GREGPROTO _IOWR('i', 106, struct ifreq) |
| 167 | #define GRESSOCK _IOW('i' , 107, struct ifreq) |
| 168 | #define GREDSOCK _IOW('i' , 108, struct ifreq) |
| 169 | |
| 170 | #endif /* !_NET_IF_GRE_H_ */ |
| 171 | |