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 /*- 5*51369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 6*51369649SPedro F. Giffuni * 782cd038dSYoshinobu Inoue * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 882cd038dSYoshinobu Inoue * All rights reserved. 982cd038dSYoshinobu Inoue * 1082cd038dSYoshinobu Inoue * Redistribution and use in source and binary forms, with or without 1182cd038dSYoshinobu Inoue * modification, are permitted provided that the following conditions 1282cd038dSYoshinobu Inoue * are met: 1382cd038dSYoshinobu Inoue * 1. Redistributions of source code must retain the above copyright 1482cd038dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer. 1582cd038dSYoshinobu Inoue * 2. Redistributions in binary form must reproduce the above copyright 1682cd038dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer in the 1782cd038dSYoshinobu Inoue * documentation and/or other materials provided with the distribution. 1882cd038dSYoshinobu Inoue * 3. Neither the name of the project nor the names of its contributors 1982cd038dSYoshinobu Inoue * may be used to endorse or promote products derived from this software 2082cd038dSYoshinobu Inoue * without specific prior written permission. 2182cd038dSYoshinobu Inoue * 2282cd038dSYoshinobu Inoue * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 2382cd038dSYoshinobu Inoue * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2482cd038dSYoshinobu Inoue * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2582cd038dSYoshinobu Inoue * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2682cd038dSYoshinobu Inoue * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2782cd038dSYoshinobu Inoue * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2882cd038dSYoshinobu Inoue * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2982cd038dSYoshinobu Inoue * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3082cd038dSYoshinobu Inoue * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3182cd038dSYoshinobu Inoue * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3282cd038dSYoshinobu Inoue * SUCH DAMAGE. 3382cd038dSYoshinobu Inoue */ 3482cd038dSYoshinobu Inoue 3582cd038dSYoshinobu Inoue #ifndef _NET_IF_GIF_H_ 3682cd038dSYoshinobu Inoue #define _NET_IF_GIF_H_ 3782cd038dSYoshinobu Inoue 3820af0ffaSBrooks Davis #ifdef _KERNEL 39686cdd19SJun-ichiro itojun Hagino #include "opt_inet.h" 4020af0ffaSBrooks Davis #include "opt_inet6.h" 41686cdd19SJun-ichiro itojun Hagino 42686cdd19SJun-ichiro itojun Hagino #include <netinet/in.h> 43686cdd19SJun-ichiro itojun Hagino 440b9f5f8aSAndrey V. Elsukov struct ip; 450b9f5f8aSAndrey V. Elsukov struct ip6_hdr; 46686cdd19SJun-ichiro itojun Hagino struct encaptab; 47686cdd19SJun-ichiro itojun Hagino 4894408d94SBrooks Davis extern void (*ng_gif_input_p)(struct ifnet *ifp, struct mbuf **mp, 4994408d94SBrooks Davis int af); 5094408d94SBrooks Davis extern void (*ng_gif_input_orphan_p)(struct ifnet *ifp, struct mbuf *m, 5194408d94SBrooks Davis int af); 5294408d94SBrooks Davis extern int (*ng_gif_output_p)(struct ifnet *ifp, struct mbuf **mp); 5394408d94SBrooks Davis extern void (*ng_gif_attach_p)(struct ifnet *ifp); 5494408d94SBrooks Davis extern void (*ng_gif_detach_p)(struct ifnet *ifp); 5594408d94SBrooks Davis 5682cd038dSYoshinobu Inoue struct gif_softc { 57fc74a9f9SBrooks Davis struct ifnet *gif_ifp; 580b9f5f8aSAndrey V. Elsukov struct rmlock gif_lock; 590b9f5f8aSAndrey V. Elsukov const struct encaptab *gif_ecookie; 600b9f5f8aSAndrey V. Elsukov int gif_family; 6182cd038dSYoshinobu Inoue int gif_flags; 628b07e49aSJulian Elischer u_int gif_fibnum; 63dbe59260SHiroki Sato u_int gif_options; 640b9f5f8aSAndrey V. Elsukov void *gif_netgraph; /* netgraph node info */ 650b9f5f8aSAndrey V. Elsukov union { 660b9f5f8aSAndrey V. Elsukov void *hdr; 670b9f5f8aSAndrey V. Elsukov struct ip *iphdr; 680b9f5f8aSAndrey V. Elsukov #ifdef INET6 690b9f5f8aSAndrey V. Elsukov struct ip6_hdr *ip6hdr; 700b9f5f8aSAndrey V. Elsukov #endif 710b9f5f8aSAndrey V. Elsukov } gif_uhdr; 729426aedfSHajimu UMEMOTO LIST_ENTRY(gif_softc) gif_list; /* all gif's are linked */ 7382cd038dSYoshinobu Inoue }; 74fc74a9f9SBrooks Davis #define GIF2IFP(sc) ((sc)->gif_ifp) 750b9f5f8aSAndrey V. Elsukov #define GIF_LOCK_INIT(sc) rm_init(&(sc)->gif_lock, "gif softc") 760b9f5f8aSAndrey V. Elsukov #define GIF_LOCK_DESTROY(sc) rm_destroy(&(sc)->gif_lock) 770b9f5f8aSAndrey V. Elsukov #define GIF_RLOCK_TRACKER struct rm_priotracker gif_tracker 780b9f5f8aSAndrey V. Elsukov #define GIF_RLOCK(sc) rm_rlock(&(sc)->gif_lock, &gif_tracker) 790b9f5f8aSAndrey V. Elsukov #define GIF_RUNLOCK(sc) rm_runlock(&(sc)->gif_lock, &gif_tracker) 800b9f5f8aSAndrey V. Elsukov #define GIF_RLOCK_ASSERT(sc) rm_assert(&(sc)->gif_lock, RA_RLOCKED) 810b9f5f8aSAndrey V. Elsukov #define GIF_WLOCK(sc) rm_wlock(&(sc)->gif_lock) 820b9f5f8aSAndrey V. Elsukov #define GIF_WUNLOCK(sc) rm_wunlock(&(sc)->gif_lock) 830b9f5f8aSAndrey V. Elsukov #define GIF_WLOCK_ASSERT(sc) rm_assert(&(sc)->gif_lock, RA_WLOCKED) 8482cd038dSYoshinobu Inoue 850b9f5f8aSAndrey V. Elsukov #define gif_iphdr gif_uhdr.iphdr 860b9f5f8aSAndrey V. Elsukov #define gif_hdr gif_uhdr.hdr 87686cdd19SJun-ichiro itojun Hagino #ifdef INET6 880b9f5f8aSAndrey V. Elsukov #define gif_ip6hdr gif_uhdr.ip6hdr 89686cdd19SJun-ichiro itojun Hagino #endif 9082cd038dSYoshinobu Inoue 9182cd038dSYoshinobu Inoue #define GIF_MTU (1280) /* Default MTU */ 9282cd038dSYoshinobu Inoue #define GIF_MTU_MIN (1280) /* Minimum MTU */ 9382cd038dSYoshinobu Inoue #define GIF_MTU_MAX (8192) /* Maximum MTU */ 9482cd038dSYoshinobu Inoue 9573ff045cSAndrew Thompson struct etherip_header { 96dbe59260SHiroki Sato #if BYTE_ORDER == LITTLE_ENDIAN 97dbe59260SHiroki Sato u_int eip_resvl:4, /* reserved */ 98dbe59260SHiroki Sato eip_ver:4; /* version */ 99dbe59260SHiroki Sato #endif 100dbe59260SHiroki Sato #if BYTE_ORDER == BIG_ENDIAN 101dbe59260SHiroki Sato u_int eip_ver:4, /* version */ 102dbe59260SHiroki Sato eip_resvl:4; /* reserved */ 103dbe59260SHiroki Sato #endif 104dbe59260SHiroki Sato u_int8_t eip_resvh; /* reserved */ 105dbe59260SHiroki Sato } __packed; 106dbe59260SHiroki Sato 107dbe59260SHiroki Sato #define ETHERIP_VERSION 0x3 108c89c8a10SMarius Strobl /* mbuf adjust factor to force 32-bit alignment of IP header */ 109c89c8a10SMarius Strobl #define ETHERIP_ALIGN 2 11073ff045cSAndrew Thompson 11182cd038dSYoshinobu Inoue /* Prototypes */ 1120b9f5f8aSAndrey V. Elsukov void gif_input(struct mbuf *, struct ifnet *, int, uint8_t); 11347e8d432SGleb Smirnoff int gif_output(struct ifnet *, struct mbuf *, const struct sockaddr *, 114279aa3d4SKip Macy struct route *); 1159426aedfSHajimu UMEMOTO int gif_encapcheck(const struct mbuf *, int, int, void *); 116f188f14dSAndrey V. Elsukov #ifdef INET 117f188f14dSAndrey V. Elsukov int in_gif_output(struct ifnet *, struct mbuf *, int, uint8_t); 118f188f14dSAndrey V. Elsukov int in_gif_encapcheck(const struct mbuf *, int, int, void *); 119f188f14dSAndrey V. Elsukov int in_gif_attach(struct gif_softc *); 120f188f14dSAndrey V. Elsukov #endif 121f188f14dSAndrey V. Elsukov #ifdef INET6 122f188f14dSAndrey V. Elsukov int in6_gif_output(struct ifnet *, struct mbuf *, int, uint8_t); 123f188f14dSAndrey V. Elsukov int in6_gif_encapcheck(const struct mbuf *, int, int, void *); 124f188f14dSAndrey V. Elsukov int in6_gif_attach(struct gif_softc *); 125f188f14dSAndrey V. Elsukov #endif 12620af0ffaSBrooks Davis #endif /* _KERNEL */ 12720af0ffaSBrooks Davis 128fb70e72bSHiroki Sato #define GIFGOPTS _IOWR('i', 150, struct ifreq) 129dbe59260SHiroki Sato #define GIFSOPTS _IOW('i', 151, struct ifreq) 130dbe59260SHiroki Sato 131c1b4f79dSAndrey V. Elsukov #define GIF_IGNORE_SOURCE 0x0002 132b1c250ffSHiroki Sato #define GIF_OPTMASK (GIF_IGNORE_SOURCE) 133dbe59260SHiroki Sato 13482cd038dSYoshinobu Inoue #endif /* _NET_IF_GIF_H_ */ 135