1139823Simp/*- 2103026Ssobomax * Copyright (c) 1998 The NetBSD Foundation, Inc. 3274246Sae * Copyright (c) 2014 Andrey V. Elsukov <ae@FreeBSD.org> 4103026Ssobomax * All rights reserved 5103026Ssobomax * 6103026Ssobomax * This code is derived from software contributed to The NetBSD Foundation 7103026Ssobomax * by Heiko W.Rupp <hwr@pilhuhn.de> 8103026Ssobomax * 9103026Ssobomax * Redistribution and use in source and binary forms, with or without 10103026Ssobomax * modification, are permitted provided that the following conditions 11103026Ssobomax * are met: 12103026Ssobomax * 1. Redistributions of source code must retain the above copyright 13103026Ssobomax * notice, this list of conditions and the following disclaimer. 14103026Ssobomax * 2. Redistributions in binary form must reproduce the above copyright 15103026Ssobomax * notice, this list of conditions and the following disclaimer in the 16103026Ssobomax * documentation and/or other materials provided with the distribution. 17125020Ssobomax * 18103026Ssobomax * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19103026Ssobomax * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20103026Ssobomax * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21103026Ssobomax * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22103026Ssobomax * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23103026Ssobomax * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24103026Ssobomax * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25103026Ssobomax * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26103026Ssobomax * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27103026Ssobomax * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28103026Ssobomax * POSSIBILITY OF SUCH DAMAGE. 29274246Sae * 30274246Sae * $NetBSD: if_gre.h,v 1.13 2003/11/10 08:51:52 wiz Exp $ 31274246Sae * $FreeBSD: stable/11/sys/net/if_gre.h 317403 2017-04-25 11:19:22Z ae $ 32103026Ssobomax */ 33103026Ssobomax 34274246Sae#ifndef _NET_IF_GRE_H_ 35274246Sae#define _NET_IF_GRE_H_ 36103026Ssobomax 37103120Ssobomax#ifdef _KERNEL 38274246Sae/* GRE header according to RFC 2784 and RFC 2890 */ 39274246Saestruct grehdr { 40274246Sae uint16_t gre_flags; /* GRE flags */ 41274246Sae#define GRE_FLAGS_CP 0x8000 /* checksum present */ 42274246Sae#define GRE_FLAGS_KP 0x2000 /* key present */ 43274246Sae#define GRE_FLAGS_SP 0x1000 /* sequence present */ 44274246Sae#define GRE_FLAGS_MASK (GRE_FLAGS_CP|GRE_FLAGS_KP|GRE_FLAGS_SP) 45274246Sae uint16_t gre_proto; /* protocol type */ 46274246Sae uint32_t gre_opts[0]; /* optional fields */ 47103842Salfred} __packed; 48103026Ssobomax 49274246Sae#ifdef INET 50103026Ssobomaxstruct greip { 51274246Sae struct ip gi_ip; 52274246Sae struct grehdr gi_gre; 53103842Salfred} __packed; 54274246Sae#endif 55103026Ssobomax 56274246Sae#ifdef INET6 57274246Saestruct greip6 { 58274246Sae struct ip6_hdr gi6_ip6; 59274246Sae struct grehdr gi6_gre; 60274246Sae} __packed; 61274246Sae#endif 62103026Ssobomax 63274246Saestruct gre_softc { 64274246Sae struct ifnet *gre_ifp; 65274246Sae LIST_ENTRY(gre_softc) gre_list; 66274246Sae struct rmlock gre_lock; 67274246Sae int gre_family; /* AF of delivery header */ 68274246Sae uint32_t gre_iseq; 69274246Sae uint32_t gre_oseq; 70274246Sae uint32_t gre_key; 71274246Sae uint32_t gre_options; 72274246Sae u_int gre_fibnum; 73274246Sae u_int gre_hlen; /* header size */ 74274246Sae union { 75274246Sae void *hdr; 76274246Sae#ifdef INET 77274246Sae struct greip *gihdr; 78274246Sae#endif 79274246Sae#ifdef INET6 80274246Sae struct greip6 *gi6hdr; 81274246Sae#endif 82274246Sae } gre_uhdr; 83274246Sae const struct encaptab *gre_ecookie; 84274246Sae}; 85274246Sae#define GRE2IFP(sc) ((sc)->gre_ifp) 86274246Sae#define GRE_LOCK_INIT(sc) rm_init(&(sc)->gre_lock, "gre softc") 87274246Sae#define GRE_LOCK_DESTROY(sc) rm_destroy(&(sc)->gre_lock) 88274246Sae#define GRE_RLOCK_TRACKER struct rm_priotracker gre_tracker 89274246Sae#define GRE_RLOCK(sc) rm_rlock(&(sc)->gre_lock, &gre_tracker) 90274246Sae#define GRE_RUNLOCK(sc) rm_runlock(&(sc)->gre_lock, &gre_tracker) 91274246Sae#define GRE_RLOCK_ASSERT(sc) rm_assert(&(sc)->gre_lock, RA_RLOCKED) 92274246Sae#define GRE_WLOCK(sc) rm_wlock(&(sc)->gre_lock) 93274246Sae#define GRE_WUNLOCK(sc) rm_wunlock(&(sc)->gre_lock) 94274246Sae#define GRE_WLOCK_ASSERT(sc) rm_assert(&(sc)->gre_lock, RA_WLOCKED) 95103026Ssobomax 96274246Sae#define gre_hdr gre_uhdr.hdr 97274246Sae#define gre_gihdr gre_uhdr.gihdr 98274246Sae#define gre_gi6hdr gre_uhdr.gi6hdr 99274246Sae#define gre_oip gre_gihdr->gi_ip 100274246Sae#define gre_oip6 gre_gi6hdr->gi6_ip6 101274246Sae 102276215Saeint gre_input(struct mbuf **, int *, int); 103276215Sae#ifdef INET 104276215Saeint in_gre_attach(struct gre_softc *); 105276215Saeint in_gre_output(struct mbuf *, int, int); 106276215Sae#endif 107276215Sae#ifdef INET6 108276215Saeint in6_gre_attach(struct gre_softc *); 109276215Saeint in6_gre_output(struct mbuf *, int, int); 110276215Sae#endif 111103026Ssobomax/* 112107670Ssobomax * CISCO uses special type for GRE tunnel created as part of WCCP 113107670Ssobomax * connection, while in fact those packets are just IPv4 encapsulated 114107670Ssobomax * into GRE. 115107670Ssobomax */ 116274246Sae#define ETHERTYPE_WCCP 0x883E 117103120Ssobomax#endif /* _KERNEL */ 118103120Ssobomax 119103026Ssobomax#define GRESADDRS _IOW('i', 101, struct ifreq) 120125020Ssobomax#define GRESADDRD _IOW('i', 102, struct ifreq) 121103026Ssobomax#define GREGADDRS _IOWR('i', 103, struct ifreq) 122103026Ssobomax#define GREGADDRD _IOWR('i', 104, struct ifreq) 123103026Ssobomax#define GRESPROTO _IOW('i' , 105, struct ifreq) 124103026Ssobomax#define GREGPROTO _IOWR('i', 106, struct ifreq) 125103026Ssobomax 126274246Sae#define GREGKEY _IOWR('i', 107, struct ifreq) 127274246Sae#define GRESKEY _IOW('i', 108, struct ifreq) 128274246Sae#define GREGOPTS _IOWR('i', 109, struct ifreq) 129274246Sae#define GRESOPTS _IOW('i', 110, struct ifreq) 130103026Ssobomax 131274246Sae#define GRE_ENABLE_CSUM 0x0001 132274246Sae#define GRE_ENABLE_SEQ 0x0002 133274246Sae#define GRE_OPTMASK (GRE_ENABLE_CSUM|GRE_ENABLE_SEQ) 134271918Shrs 135274246Sae#endif /* _NET_IF_GRE_H_ */ 136