1686cdd19SJun-ichiro itojun Hagino /* $FreeBSD$ */ 233841545SHajimu UMEMOTO /* $KAME: if_gif.h,v 1.17 2000/09/11 11:36:41 sumikawa Exp $ */ 3686cdd19SJun-ichiro itojun Hagino 4c398230bSWarner Losh /*- 582cd038dSYoshinobu Inoue * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 682cd038dSYoshinobu Inoue * All rights reserved. 782cd038dSYoshinobu Inoue * 882cd038dSYoshinobu Inoue * Redistribution and use in source and binary forms, with or without 982cd038dSYoshinobu Inoue * modification, are permitted provided that the following conditions 1082cd038dSYoshinobu Inoue * are met: 1182cd038dSYoshinobu Inoue * 1. Redistributions of source code must retain the above copyright 1282cd038dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer. 1382cd038dSYoshinobu Inoue * 2. Redistributions in binary form must reproduce the above copyright 1482cd038dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer in the 1582cd038dSYoshinobu Inoue * documentation and/or other materials provided with the distribution. 1682cd038dSYoshinobu Inoue * 3. Neither the name of the project nor the names of its contributors 1782cd038dSYoshinobu Inoue * may be used to endorse or promote products derived from this software 1882cd038dSYoshinobu Inoue * without specific prior written permission. 1982cd038dSYoshinobu Inoue * 2082cd038dSYoshinobu Inoue * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 2182cd038dSYoshinobu Inoue * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2282cd038dSYoshinobu Inoue * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2382cd038dSYoshinobu Inoue * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2482cd038dSYoshinobu Inoue * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2582cd038dSYoshinobu Inoue * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2682cd038dSYoshinobu Inoue * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2782cd038dSYoshinobu Inoue * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2882cd038dSYoshinobu Inoue * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2982cd038dSYoshinobu Inoue * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3082cd038dSYoshinobu Inoue * SUCH DAMAGE. 3182cd038dSYoshinobu Inoue */ 3282cd038dSYoshinobu Inoue 3382cd038dSYoshinobu Inoue #ifndef _NET_IF_GIF_H_ 3482cd038dSYoshinobu Inoue #define _NET_IF_GIF_H_ 3582cd038dSYoshinobu Inoue 3620af0ffaSBrooks Davis #ifdef _KERNEL 37686cdd19SJun-ichiro itojun Hagino #include "opt_inet.h" 3820af0ffaSBrooks Davis #include "opt_inet6.h" 39686cdd19SJun-ichiro itojun Hagino 40686cdd19SJun-ichiro itojun Hagino #include <netinet/in.h> 41686cdd19SJun-ichiro itojun Hagino 420b9f5f8aSAndrey V. Elsukov struct ip; 430b9f5f8aSAndrey V. Elsukov struct ip6_hdr; 44686cdd19SJun-ichiro itojun Hagino struct encaptab; 45686cdd19SJun-ichiro itojun Hagino 4694408d94SBrooks Davis extern void (*ng_gif_input_p)(struct ifnet *ifp, struct mbuf **mp, 4794408d94SBrooks Davis int af); 4894408d94SBrooks Davis extern void (*ng_gif_input_orphan_p)(struct ifnet *ifp, struct mbuf *m, 4994408d94SBrooks Davis int af); 5094408d94SBrooks Davis extern int (*ng_gif_output_p)(struct ifnet *ifp, struct mbuf **mp); 5194408d94SBrooks Davis extern void (*ng_gif_attach_p)(struct ifnet *ifp); 5294408d94SBrooks Davis extern void (*ng_gif_detach_p)(struct ifnet *ifp); 5394408d94SBrooks Davis 5482cd038dSYoshinobu Inoue struct gif_softc { 55fc74a9f9SBrooks Davis struct ifnet *gif_ifp; 560b9f5f8aSAndrey V. Elsukov struct rmlock gif_lock; 570b9f5f8aSAndrey V. Elsukov const struct encaptab *gif_ecookie; 580b9f5f8aSAndrey V. Elsukov int gif_family; 5982cd038dSYoshinobu Inoue int gif_flags; 608b07e49aSJulian Elischer u_int gif_fibnum; 61dbe59260SHiroki Sato u_int gif_options; 620b9f5f8aSAndrey V. Elsukov void *gif_netgraph; /* netgraph node info */ 630b9f5f8aSAndrey V. Elsukov union { 640b9f5f8aSAndrey V. Elsukov void *hdr; 650b9f5f8aSAndrey V. Elsukov struct ip *iphdr; 660b9f5f8aSAndrey V. Elsukov #ifdef INET6 670b9f5f8aSAndrey V. Elsukov struct ip6_hdr *ip6hdr; 680b9f5f8aSAndrey V. Elsukov #endif 690b9f5f8aSAndrey V. Elsukov } gif_uhdr; 709426aedfSHajimu UMEMOTO LIST_ENTRY(gif_softc) gif_list; /* all gif's are linked */ 7182cd038dSYoshinobu Inoue }; 72fc74a9f9SBrooks Davis #define GIF2IFP(sc) ((sc)->gif_ifp) 730b9f5f8aSAndrey V. Elsukov #define GIF_LOCK_INIT(sc) rm_init(&(sc)->gif_lock, "gif softc") 740b9f5f8aSAndrey V. Elsukov #define GIF_LOCK_DESTROY(sc) rm_destroy(&(sc)->gif_lock) 750b9f5f8aSAndrey V. Elsukov #define GIF_RLOCK_TRACKER struct rm_priotracker gif_tracker 760b9f5f8aSAndrey V. Elsukov #define GIF_RLOCK(sc) rm_rlock(&(sc)->gif_lock, &gif_tracker) 770b9f5f8aSAndrey V. Elsukov #define GIF_RUNLOCK(sc) rm_runlock(&(sc)->gif_lock, &gif_tracker) 780b9f5f8aSAndrey V. Elsukov #define GIF_RLOCK_ASSERT(sc) rm_assert(&(sc)->gif_lock, RA_RLOCKED) 790b9f5f8aSAndrey V. Elsukov #define GIF_WLOCK(sc) rm_wlock(&(sc)->gif_lock) 800b9f5f8aSAndrey V. Elsukov #define GIF_WUNLOCK(sc) rm_wunlock(&(sc)->gif_lock) 810b9f5f8aSAndrey V. Elsukov #define GIF_WLOCK_ASSERT(sc) rm_assert(&(sc)->gif_lock, RA_WLOCKED) 8282cd038dSYoshinobu Inoue 830b9f5f8aSAndrey V. Elsukov #define gif_iphdr gif_uhdr.iphdr 840b9f5f8aSAndrey V. Elsukov #define gif_hdr gif_uhdr.hdr 85686cdd19SJun-ichiro itojun Hagino #ifdef INET6 860b9f5f8aSAndrey V. Elsukov #define gif_ip6hdr gif_uhdr.ip6hdr 87686cdd19SJun-ichiro itojun Hagino #endif 8882cd038dSYoshinobu Inoue 8982cd038dSYoshinobu Inoue #define GIF_MTU (1280) /* Default MTU */ 9082cd038dSYoshinobu Inoue #define GIF_MTU_MIN (1280) /* Minimum MTU */ 9182cd038dSYoshinobu Inoue #define GIF_MTU_MAX (8192) /* Maximum MTU */ 9282cd038dSYoshinobu Inoue 938c7e1947SRuslan Ermilov #define MTAG_GIF 1080679712 948c7e1947SRuslan Ermilov #define MTAG_GIF_CALLED 0 958c7e1947SRuslan Ermilov 9673ff045cSAndrew Thompson struct etherip_header { 97dbe59260SHiroki Sato #if BYTE_ORDER == LITTLE_ENDIAN 98dbe59260SHiroki Sato u_int eip_resvl:4, /* reserved */ 99dbe59260SHiroki Sato eip_ver:4; /* version */ 100dbe59260SHiroki Sato #endif 101dbe59260SHiroki Sato #if BYTE_ORDER == BIG_ENDIAN 102dbe59260SHiroki Sato u_int eip_ver:4, /* version */ 103dbe59260SHiroki Sato eip_resvl:4; /* reserved */ 104dbe59260SHiroki Sato #endif 105dbe59260SHiroki Sato u_int8_t eip_resvh; /* reserved */ 106dbe59260SHiroki Sato } __packed; 107dbe59260SHiroki Sato 108dbe59260SHiroki Sato #define ETHERIP_VERSION 0x3 109c89c8a10SMarius Strobl /* mbuf adjust factor to force 32-bit alignment of IP header */ 110c89c8a10SMarius Strobl #define ETHERIP_ALIGN 2 11173ff045cSAndrew Thompson 11282cd038dSYoshinobu Inoue /* Prototypes */ 1130b9f5f8aSAndrey V. Elsukov void gif_input(struct mbuf *, struct ifnet *, int, uint8_t); 11447e8d432SGleb Smirnoff int gif_output(struct ifnet *, struct mbuf *, const struct sockaddr *, 115279aa3d4SKip Macy struct route *); 1169426aedfSHajimu UMEMOTO int gif_encapcheck(const struct mbuf *, int, int, void *); 117*f188f14dSAndrey V. Elsukov #ifdef INET 118*f188f14dSAndrey V. Elsukov int in_gif_output(struct ifnet *, struct mbuf *, int, uint8_t); 119*f188f14dSAndrey V. Elsukov int in_gif_encapcheck(const struct mbuf *, int, int, void *); 120*f188f14dSAndrey V. Elsukov int in_gif_attach(struct gif_softc *); 121*f188f14dSAndrey V. Elsukov #endif 122*f188f14dSAndrey V. Elsukov #ifdef INET6 123*f188f14dSAndrey V. Elsukov int in6_gif_output(struct ifnet *, struct mbuf *, int, uint8_t); 124*f188f14dSAndrey V. Elsukov int in6_gif_encapcheck(const struct mbuf *, int, int, void *); 125*f188f14dSAndrey V. Elsukov int in6_gif_attach(struct gif_softc *); 126*f188f14dSAndrey V. Elsukov #endif 12720af0ffaSBrooks Davis #endif /* _KERNEL */ 12820af0ffaSBrooks Davis 129fb70e72bSHiroki Sato #define GIFGOPTS _IOWR('i', 150, struct ifreq) 130dbe59260SHiroki Sato #define GIFSOPTS _IOW('i', 151, struct ifreq) 131dbe59260SHiroki Sato 132dbe59260SHiroki Sato #define GIF_ACCEPT_REVETHIP 0x0001 133dbe59260SHiroki Sato #define GIF_SEND_REVETHIP 0x0010 134fb70e72bSHiroki Sato #define GIF_OPTMASK (GIF_ACCEPT_REVETHIP|GIF_SEND_REVETHIP) 135dbe59260SHiroki Sato 13682cd038dSYoshinobu Inoue #endif /* _NET_IF_GIF_H_ */ 137