1c398230bSWarner Losh /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3fe267a55SPedro F. Giffuni * 48e96e13eSMaxim Sobolev * Copyright (c) 1998 The NetBSD Foundation, Inc. 5f325335cSAndrey V. Elsukov * Copyright (c) 2014 Andrey V. Elsukov <ae@FreeBSD.org> 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 * 208e96e13eSMaxim Sobolev * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 218e96e13eSMaxim Sobolev * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 228e96e13eSMaxim Sobolev * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 238e96e13eSMaxim Sobolev * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 248e96e13eSMaxim Sobolev * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 258e96e13eSMaxim Sobolev * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 268e96e13eSMaxim Sobolev * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 278e96e13eSMaxim Sobolev * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 288e96e13eSMaxim Sobolev * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 298e96e13eSMaxim Sobolev * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 308e96e13eSMaxim Sobolev * POSSIBILITY OF SUCH DAMAGE. 31f325335cSAndrey V. Elsukov * 32f325335cSAndrey V. Elsukov * $NetBSD: if_gre.h,v 1.13 2003/11/10 08:51:52 wiz Exp $ 338e96e13eSMaxim Sobolev */ 348e96e13eSMaxim Sobolev 35f325335cSAndrey V. Elsukov #ifndef _NET_IF_GRE_H_ 36f325335cSAndrey V. Elsukov #define _NET_IF_GRE_H_ 378e96e13eSMaxim Sobolev 38ccd6d236SMaxim Sobolev #ifdef _KERNEL 39f325335cSAndrey V. Elsukov /* GRE header according to RFC 2784 and RFC 2890 */ 40f325335cSAndrey V. Elsukov struct grehdr { 41f325335cSAndrey V. Elsukov uint16_t gre_flags; /* GRE flags */ 42f325335cSAndrey V. Elsukov #define GRE_FLAGS_CP 0x8000 /* checksum present */ 43f325335cSAndrey V. Elsukov #define GRE_FLAGS_KP 0x2000 /* key present */ 44f325335cSAndrey V. Elsukov #define GRE_FLAGS_SP 0x1000 /* sequence present */ 45f325335cSAndrey V. Elsukov #define GRE_FLAGS_MASK (GRE_FLAGS_CP|GRE_FLAGS_KP|GRE_FLAGS_SP) 46f325335cSAndrey V. Elsukov uint16_t gre_proto; /* protocol type */ 47f325335cSAndrey V. Elsukov uint32_t gre_opts[0]; /* optional fields */ 48f325335cSAndrey V. Elsukov } __packed; 498e96e13eSMaxim Sobolev 50f325335cSAndrey V. Elsukov #ifdef INET 51f325335cSAndrey V. Elsukov struct greip { 52f325335cSAndrey V. Elsukov struct ip gi_ip; 53f325335cSAndrey V. Elsukov struct grehdr gi_gre; 54f325335cSAndrey V. Elsukov } __packed; 55aee793eeSAndrey V. Elsukov 56aee793eeSAndrey V. Elsukov struct greudp { 57aee793eeSAndrey V. Elsukov struct ip gi_ip; 58aee793eeSAndrey V. Elsukov struct udphdr gi_udp; 59aee793eeSAndrey V. Elsukov struct grehdr gi_gre; 60aee793eeSAndrey V. Elsukov } __packed; 61aee793eeSAndrey V. Elsukov #endif /* INET */ 62f325335cSAndrey V. Elsukov 63f325335cSAndrey V. Elsukov #ifdef INET6 64f325335cSAndrey V. Elsukov struct greip6 { 65f325335cSAndrey V. Elsukov struct ip6_hdr gi6_ip6; 66f325335cSAndrey V. Elsukov struct grehdr gi6_gre; 67f325335cSAndrey V. Elsukov } __packed; 68aee793eeSAndrey V. Elsukov 69aee793eeSAndrey V. Elsukov struct greudp6 { 70aee793eeSAndrey V. Elsukov struct ip6_hdr gi6_ip6; 71aee793eeSAndrey V. Elsukov struct udphdr gi6_udp; 72aee793eeSAndrey V. Elsukov struct grehdr gi6_gre; 73aee793eeSAndrey V. Elsukov } __packed; 74aee793eeSAndrey V. Elsukov #endif /* INET6 */ 75aee793eeSAndrey V. Elsukov 76aee793eeSAndrey V. Elsukov CK_LIST_HEAD(gre_list, gre_softc); 77aee793eeSAndrey V. Elsukov CK_LIST_HEAD(gre_sockets, gre_socket); 78aee793eeSAndrey V. Elsukov struct gre_socket { 79aee793eeSAndrey V. Elsukov struct socket *so; 80aee793eeSAndrey V. Elsukov struct gre_list list; 81aee793eeSAndrey V. Elsukov CK_LIST_ENTRY(gre_socket) chain; 82aee793eeSAndrey V. Elsukov struct epoch_context epoch_ctx; 83aee793eeSAndrey V. Elsukov }; 847735aeb9SMaxim Sobolev 858e96e13eSMaxim Sobolev struct gre_softc { 86f325335cSAndrey V. Elsukov struct ifnet *gre_ifp; 87f325335cSAndrey V. Elsukov int gre_family; /* AF of delivery header */ 88f325335cSAndrey V. Elsukov uint32_t gre_iseq; 89f325335cSAndrey V. Elsukov uint32_t gre_oseq; 90f325335cSAndrey V. Elsukov uint32_t gre_key; 91f325335cSAndrey V. Elsukov uint32_t gre_options; 92aee793eeSAndrey V. Elsukov uint32_t gre_csumflags; 93aee793eeSAndrey V. Elsukov uint32_t gre_port; 94f325335cSAndrey V. Elsukov u_int gre_fibnum; 95f325335cSAndrey V. Elsukov u_int gre_hlen; /* header size */ 96f325335cSAndrey V. Elsukov union { 97f325335cSAndrey V. Elsukov void *hdr; 98f325335cSAndrey V. Elsukov #ifdef INET 99aee793eeSAndrey V. Elsukov struct greip *iphdr; 100aee793eeSAndrey V. Elsukov struct greudp *udphdr; 101f325335cSAndrey V. Elsukov #endif 102f325335cSAndrey V. Elsukov #ifdef INET6 103aee793eeSAndrey V. Elsukov struct greip6 *ip6hdr; 104aee793eeSAndrey V. Elsukov struct greudp6 *udp6hdr; 105f325335cSAndrey V. Elsukov #endif 106f325335cSAndrey V. Elsukov } gre_uhdr; 107aee793eeSAndrey V. Elsukov struct gre_socket *gre_so; 108a5185adeSAndrey V. Elsukov 109a5185adeSAndrey V. Elsukov CK_LIST_ENTRY(gre_softc) chain; 11019873f47SAndrey V. Elsukov CK_LIST_ENTRY(gre_softc) srchash; 1118e96e13eSMaxim Sobolev }; 112a5185adeSAndrey V. Elsukov MALLOC_DECLARE(M_GRE); 113a5185adeSAndrey V. Elsukov 114a5185adeSAndrey V. Elsukov #ifndef GRE_HASH_SIZE 115a5185adeSAndrey V. Elsukov #define GRE_HASH_SIZE (1 << 4) 116a5185adeSAndrey V. Elsukov #endif 117a5185adeSAndrey V. Elsukov 118f325335cSAndrey V. Elsukov #define GRE2IFP(sc) ((sc)->gre_ifp) 11919873f47SAndrey V. Elsukov #define GRE_RLOCK_TRACKER struct epoch_tracker gre_et 12019873f47SAndrey V. Elsukov #define GRE_RLOCK() epoch_enter_preempt(net_epoch_preempt, &gre_et) 1216573d758SMatt Macy #define GRE_RUNLOCK() epoch_exit_preempt(net_epoch_preempt, &gre_et) 122a5185adeSAndrey V. Elsukov #define GRE_WAIT() epoch_wait_preempt(net_epoch_preempt) 1238e96e13eSMaxim Sobolev 124f325335cSAndrey V. Elsukov #define gre_hdr gre_uhdr.hdr 125aee793eeSAndrey V. Elsukov #define gre_iphdr gre_uhdr.iphdr 126aee793eeSAndrey V. Elsukov #define gre_ip6hdr gre_uhdr.ip6hdr 127aee793eeSAndrey V. Elsukov #define gre_udphdr gre_uhdr.udphdr 128aee793eeSAndrey V. Elsukov #define gre_udp6hdr gre_uhdr.udp6hdr 129aee793eeSAndrey V. Elsukov 130aee793eeSAndrey V. Elsukov #define gre_oip gre_iphdr->gi_ip 131aee793eeSAndrey V. Elsukov #define gre_udp gre_udphdr->gi_udp 132aee793eeSAndrey V. Elsukov #define gre_oip6 gre_ip6hdr->gi6_ip6 133aee793eeSAndrey V. Elsukov #define gre_udp6 gre_udp6hdr->gi6_udp 1348e96e13eSMaxim Sobolev 135a5185adeSAndrey V. Elsukov struct gre_list *gre_hashinit(void); 136a5185adeSAndrey V. Elsukov void gre_hashdestroy(struct gre_list *); 137a5185adeSAndrey V. Elsukov 1386d8fdfa9SAndrey V. Elsukov int gre_input(struct mbuf *, int, int, void *); 139aee793eeSAndrey V. Elsukov void gre_update_hdr(struct gre_softc *, struct grehdr *); 140aee793eeSAndrey V. Elsukov void gre_update_udphdr(struct gre_softc *, struct udphdr *, uint16_t); 141aee793eeSAndrey V. Elsukov void gre_sofree(epoch_context_t); 142a5185adeSAndrey V. Elsukov 143a5185adeSAndrey V. Elsukov void in_gre_init(void); 144a5185adeSAndrey V. Elsukov void in_gre_uninit(void); 145aee793eeSAndrey V. Elsukov int in_gre_setopts(struct gre_softc *, u_long, uint32_t); 146a5185adeSAndrey V. Elsukov int in_gre_ioctl(struct gre_softc *, u_long, caddr_t); 147f188f14dSAndrey V. Elsukov int in_gre_output(struct mbuf *, int, int); 148a5185adeSAndrey V. Elsukov 149a5185adeSAndrey V. Elsukov void in6_gre_init(void); 150a5185adeSAndrey V. Elsukov void in6_gre_uninit(void); 151aee793eeSAndrey V. Elsukov int in6_gre_setopts(struct gre_softc *, u_long, uint32_t); 152a5185adeSAndrey V. Elsukov int in6_gre_ioctl(struct gre_softc *, u_long, caddr_t); 153aee793eeSAndrey V. Elsukov int in6_gre_output(struct mbuf *, int, int, uint32_t); 1548e96e13eSMaxim Sobolev /* 15516199bf2SMaxim Sobolev * CISCO uses special type for GRE tunnel created as part of WCCP 15616199bf2SMaxim Sobolev * connection, while in fact those packets are just IPv4 encapsulated 15716199bf2SMaxim Sobolev * into GRE. 15816199bf2SMaxim Sobolev */ 159f325335cSAndrey V. Elsukov #define ETHERTYPE_WCCP 0x883E 160ccd6d236SMaxim Sobolev #endif /* _KERNEL */ 161ccd6d236SMaxim Sobolev 1628e96e13eSMaxim Sobolev #define GRESADDRS _IOW('i', 101, struct ifreq) 1638e96e13eSMaxim Sobolev #define GRESADDRD _IOW('i', 102, struct ifreq) 1648e96e13eSMaxim Sobolev #define GREGADDRS _IOWR('i', 103, struct ifreq) 1658e96e13eSMaxim Sobolev #define GREGADDRD _IOWR('i', 104, struct ifreq) 1668e96e13eSMaxim Sobolev #define GRESPROTO _IOW('i' , 105, struct ifreq) 1678e96e13eSMaxim Sobolev #define GREGPROTO _IOWR('i', 106, struct ifreq) 168f325335cSAndrey V. Elsukov 169131c55bcSAndrew Thompson #define GREGKEY _IOWR('i', 107, struct ifreq) 170131c55bcSAndrew Thompson #define GRESKEY _IOW('i', 108, struct ifreq) 171f325335cSAndrey V. Elsukov #define GREGOPTS _IOWR('i', 109, struct ifreq) 172f325335cSAndrey V. Elsukov #define GRESOPTS _IOW('i', 110, struct ifreq) 173aee793eeSAndrey V. Elsukov #define GREGPORT _IOWR('i', 111, struct ifreq) 174aee793eeSAndrey V. Elsukov #define GRESPORT _IOW('i', 112, struct ifreq) 175aee793eeSAndrey V. Elsukov 176aee793eeSAndrey V. Elsukov /* GRE-in-UDP encapsulation destination port as defined in RFC8086 */ 177aee793eeSAndrey V. Elsukov #define GRE_UDPPORT 4754 1788e96e13eSMaxim Sobolev 179f325335cSAndrey V. Elsukov #define GRE_ENABLE_CSUM 0x0001 180f325335cSAndrey V. Elsukov #define GRE_ENABLE_SEQ 0x0002 181aee793eeSAndrey V. Elsukov #define GRE_UDPENCAP 0x0004 182aee793eeSAndrey V. Elsukov #define GRE_OPTMASK (GRE_ENABLE_CSUM|GRE_ENABLE_SEQ|GRE_UDPENCAP) 18389c58b73SHiroki Sato 184f325335cSAndrey V. Elsukov #endif /* _NET_IF_GRE_H_ */ 185