162587Sitojun/* $FreeBSD$ */ 278064Sume/* $KAME: if_gif.h,v 1.17 2000/09/11 11:36:41 sumikawa Exp $ */ 362587Sitojun 4139823Simp/*- 553541Sshin * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 653541Sshin * All rights reserved. 753541Sshin * 853541Sshin * Redistribution and use in source and binary forms, with or without 953541Sshin * modification, are permitted provided that the following conditions 1053541Sshin * are met: 1153541Sshin * 1. Redistributions of source code must retain the above copyright 1253541Sshin * notice, this list of conditions and the following disclaimer. 1353541Sshin * 2. Redistributions in binary form must reproduce the above copyright 1453541Sshin * notice, this list of conditions and the following disclaimer in the 1553541Sshin * documentation and/or other materials provided with the distribution. 1653541Sshin * 3. Neither the name of the project nor the names of its contributors 1753541Sshin * may be used to endorse or promote products derived from this software 1853541Sshin * without specific prior written permission. 1953541Sshin * 2053541Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 2153541Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2253541Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2353541Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2453541Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2553541Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2653541Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2753541Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2853541Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2953541Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3053541Sshin * SUCH DAMAGE. 3153541Sshin */ 3253541Sshin 3353541Sshin#ifndef _NET_IF_GIF_H_ 3453541Sshin#define _NET_IF_GIF_H_ 3553541Sshin 3683997Sbrooks#ifdef _KERNEL 3762587Sitojun#include "opt_inet.h" 3883997Sbrooks#include "opt_inet6.h" 3962587Sitojun 4062587Sitojun#include <netinet/in.h> 4162587Sitojun 42276149Saestruct ip; 43276149Saestruct ip6_hdr; 4462587Sitojunstruct encaptab; 4562587Sitojun 4683998Sbrooksextern void (*ng_gif_input_p)(struct ifnet *ifp, struct mbuf **mp, 4783998Sbrooks int af); 4883998Sbrooksextern void (*ng_gif_input_orphan_p)(struct ifnet *ifp, struct mbuf *m, 4983998Sbrooks int af); 5083998Sbrooksextern int (*ng_gif_output_p)(struct ifnet *ifp, struct mbuf **mp); 5183998Sbrooksextern void (*ng_gif_attach_p)(struct ifnet *ifp); 5283998Sbrooksextern void (*ng_gif_detach_p)(struct ifnet *ifp); 5383998Sbrooks 5453541Sshinstruct gif_softc { 55276149Sae struct ifnet *gif_ifp; 56276149Sae struct rmlock gif_lock; 57276149Sae const struct encaptab *gif_ecookie; 58276149Sae int gif_family; 59276149Sae int gif_flags; 60276149Sae u_int gif_fibnum; 61276149Sae u_int gif_options; 62276149Sae void *gif_netgraph; /* netgraph node info */ 6353541Sshin union { 64276149Sae void *hdr; 65276149Sae struct ip *iphdr; 6662587Sitojun#ifdef INET6 67276149Sae struct ip6_hdr *ip6hdr; 6862587Sitojun#endif 69276149Sae } gif_uhdr; 70276149Sae LIST_ENTRY(gif_softc) gif_list; /* all gif's are linked */ 7153541Sshin}; 72147256Sbrooks#define GIF2IFP(sc) ((sc)->gif_ifp) 73276149Sae#define GIF_LOCK_INIT(sc) rm_init(&(sc)->gif_lock, "gif softc") 74276149Sae#define GIF_LOCK_DESTROY(sc) rm_destroy(&(sc)->gif_lock) 75276149Sae#define GIF_RLOCK_TRACKER struct rm_priotracker gif_tracker 76276149Sae#define GIF_RLOCK(sc) rm_rlock(&(sc)->gif_lock, &gif_tracker) 77276149Sae#define GIF_RUNLOCK(sc) rm_runlock(&(sc)->gif_lock, &gif_tracker) 78276149Sae#define GIF_RLOCK_ASSERT(sc) rm_assert(&(sc)->gif_lock, RA_RLOCKED) 79276149Sae#define GIF_WLOCK(sc) rm_wlock(&(sc)->gif_lock) 80276149Sae#define GIF_WUNLOCK(sc) rm_wunlock(&(sc)->gif_lock) 81276149Sae#define GIF_WLOCK_ASSERT(sc) rm_assert(&(sc)->gif_lock, RA_WLOCKED) 8253541Sshin 83276149Sae#define gif_iphdr gif_uhdr.iphdr 84276149Sae#define gif_hdr gif_uhdr.hdr 8562587Sitojun#ifdef INET6 86276149Sae#define gif_ip6hdr gif_uhdr.ip6hdr 8762587Sitojun#endif 8853541Sshin 8962587Sitojun#define GIF_MTU (1280) /* Default MTU */ 9053541Sshin#define GIF_MTU_MIN (1280) /* Minimum MTU */ 9153541Sshin#define GIF_MTU_MAX (8192) /* Maximum MTU */ 9253541Sshin 93153621Sthompsastruct etherip_header { 94193664Shrs#if BYTE_ORDER == LITTLE_ENDIAN 95193664Shrs u_int eip_resvl:4, /* reserved */ 96193664Shrs eip_ver:4; /* version */ 97193664Shrs#endif 98193664Shrs#if BYTE_ORDER == BIG_ENDIAN 99193664Shrs u_int eip_ver:4, /* version */ 100193664Shrs eip_resvl:4; /* reserved */ 101193664Shrs#endif 102193664Shrs u_int8_t eip_resvh; /* reserved */ 103193664Shrs} __packed; 104193664Shrs 105193664Shrs#define ETHERIP_VERSION 0x3 106189494Smarius/* mbuf adjust factor to force 32-bit alignment of IP header */ 107189494Smarius#define ETHERIP_ALIGN 2 108153621Sthompsa 10953541Sshin/* Prototypes */ 110276149Saevoid gif_input(struct mbuf *, struct ifnet *, int, uint8_t); 111249925Sglebiusint gif_output(struct ifnet *, struct mbuf *, const struct sockaddr *, 112191148Skmacy struct route *); 113105293Sumeint gif_encapcheck(const struct mbuf *, int, int, void *); 114284072Sae#ifdef INET 115284072Saeint in_gif_output(struct ifnet *, struct mbuf *, int, uint8_t); 116284072Saeint in_gif_encapcheck(const struct mbuf *, int, int, void *); 117284072Saeint in_gif_attach(struct gif_softc *); 118284072Sae#endif 119284072Sae#ifdef INET6 120284072Saeint in6_gif_output(struct ifnet *, struct mbuf *, int, uint8_t); 121284072Saeint in6_gif_encapcheck(const struct mbuf *, int, int, void *); 122284072Saeint in6_gif_attach(struct gif_softc *); 123284072Sae#endif 12483997Sbrooks#endif /* _KERNEL */ 12583997Sbrooks 126193796Shrs#define GIFGOPTS _IOWR('i', 150, struct ifreq) 127193664Shrs#define GIFSOPTS _IOW('i', 151, struct ifreq) 128193664Shrs 129283852Sae#define GIF_IGNORE_SOURCE 0x0002 130287730Shrs#define GIF_OPTMASK (GIF_IGNORE_SOURCE) 131193664Shrs 13253541Sshin#endif /* _NET_IF_GIF_H_ */ 133