diff options
Diffstat (limited to 'freebsd/sys/net/if_gre.h')
-rw-r--r-- | freebsd/sys/net/if_gre.h | 215 |
1 files changed, 83 insertions, 132 deletions
diff --git a/freebsd/sys/net/if_gre.h b/freebsd/sys/net/if_gre.h index 74d16b1c..806b0cb8 100644 --- a/freebsd/sys/net/if_gre.h +++ b/freebsd/sys/net/if_gre.h @@ -1,8 +1,6 @@ -/* $NetBSD: if_gre.h,v 1.13 2003/11/10 08:51:52 wiz Exp $ */ -/* $FreeBSD$ */ - /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. + * Copyright (c) 2014 Andrey V. Elsukov <ae@FreeBSD.org> * All rights reserved * * This code is derived from software contributed to The NetBSD Foundation @@ -28,158 +26,111 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: if_gre.h,v 1.13 2003/11/10 08:51:52 wiz Exp $ + * $FreeBSD$ */ -#ifndef _NET_IF_GRE_H -#define _NET_IF_GRE_H +#ifndef _NET_IF_GRE_H_ +#define _NET_IF_GRE_H_ -#include <sys/ioccom.h> #ifdef _KERNEL -#include <sys/queue.h> - -/* - * Version of the WCCP, need to be configured manually since - * header for version 2 is the same but IP payload is prepended - * with additional 4-bytes field. - */ -typedef enum { - WCCP_V1 = 0, - WCCP_V2 -} wccp_ver_t; - -struct gre_softc { - struct ifnet *sc_ifp; - LIST_ENTRY(gre_softc) sc_list; - int gre_unit; - int gre_flags; - u_int gre_fibnum; /* use this fib for envelopes */ - struct in_addr g_src; /* source address of gre packets */ - struct in_addr g_dst; /* destination address of gre packets */ - struct route route; /* routing entry that determines, where a - encapsulated packet should go */ - u_char g_proto; /* protocol of encapsulator */ - - const struct encaptab *encap; /* encapsulation cookie */ - - uint32_t key; /* key included in outgoing GRE packets */ - /* zero means none */ - - wccp_ver_t wccp_ver; /* version of the WCCP */ -}; -#define GRE2IFP(sc) ((sc)->sc_ifp) - - -struct gre_h { - u_int16_t flags; /* GRE flags */ - u_int16_t ptype; /* protocol type of payload typically - Ether protocol type*/ - uint32_t options[0]; /* optional options */ -/* - * from here on: fields are optional, presence indicated by flags - * - u_int_16 checksum checksum (one-complements of GRE header - and payload - Present if (ck_pres | rt_pres == 1). - Valid if (ck_pres == 1). - u_int_16 offset offset from start of routing filed to - first octet of active SRE (see below). - Present if (ck_pres | rt_pres == 1). - Valid if (rt_pres == 1). - u_int_32 key inserted by encapsulator e.g. for - authentication - Present if (key_pres ==1 ). - u_int_32 seq_num Sequence number to allow for packet order - Present if (seq_pres ==1 ). - struct gre_sre[] routing Routing fileds (see below) - Present if (rt_pres == 1) - */ +/* GRE header according to RFC 2784 and RFC 2890 */ +struct grehdr { + uint16_t gre_flags; /* GRE flags */ +#define GRE_FLAGS_CP 0x8000 /* checksum present */ +#define GRE_FLAGS_KP 0x2000 /* key present */ +#define GRE_FLAGS_SP 0x1000 /* sequence present */ +#define GRE_FLAGS_MASK (GRE_FLAGS_CP|GRE_FLAGS_KP|GRE_FLAGS_SP) + uint16_t gre_proto; /* protocol type */ + uint32_t gre_opts[0]; /* optional fields */ } __packed; +#ifdef INET struct greip { - struct ip gi_i; - struct gre_h gi_g; + struct ip gi_ip; + struct grehdr gi_gre; } __packed; +#endif -#define gi_pr gi_i.ip_p -#define gi_len gi_i.ip_len -#define gi_src gi_i.ip_src -#define gi_dst gi_i.ip_dst -#define gi_ptype gi_g.ptype -#define gi_flags gi_g.flags -#define gi_options gi_g.options - -#define GRE_CP 0x8000 /* Checksum Present */ -#define GRE_RP 0x4000 /* Routing Present */ -#define GRE_KP 0x2000 /* Key Present */ -#define GRE_SP 0x1000 /* Sequence Present */ -#define GRE_SS 0x0800 /* Strict Source Route */ +#ifdef INET6 +struct greip6 { + struct ip6_hdr gi6_ip6; + struct grehdr gi6_gre; +} __packed; +#endif +struct gre_softc { + struct ifnet *gre_ifp; + LIST_ENTRY(gre_softc) gre_list; + struct rmlock gre_lock; + int gre_family; /* AF of delivery header */ + uint32_t gre_iseq; + uint32_t gre_oseq; + uint32_t gre_key; + uint32_t gre_options; + uint32_t gre_mtu; + u_int gre_fibnum; + u_int gre_hlen; /* header size */ + union { + void *hdr; +#ifdef INET + struct greip *gihdr; +#endif +#ifdef INET6 + struct greip6 *gi6hdr; +#endif + } gre_uhdr; + const struct encaptab *gre_ecookie; +}; +#define GRE2IFP(sc) ((sc)->gre_ifp) +#define GRE_LOCK_INIT(sc) rm_init(&(sc)->gre_lock, "gre softc") +#define GRE_LOCK_DESTROY(sc) rm_destroy(&(sc)->gre_lock) +#define GRE_RLOCK_TRACKER struct rm_priotracker gre_tracker +#define GRE_RLOCK(sc) rm_rlock(&(sc)->gre_lock, &gre_tracker) +#define GRE_RUNLOCK(sc) rm_runlock(&(sc)->gre_lock, &gre_tracker) +#define GRE_RLOCK_ASSERT(sc) rm_assert(&(sc)->gre_lock, RA_RLOCKED) +#define GRE_WLOCK(sc) rm_wlock(&(sc)->gre_lock) +#define GRE_WUNLOCK(sc) rm_wunlock(&(sc)->gre_lock) +#define GRE_WLOCK_ASSERT(sc) rm_assert(&(sc)->gre_lock, RA_WLOCKED) + +#define gre_hdr gre_uhdr.hdr +#define gre_gihdr gre_uhdr.gihdr +#define gre_gi6hdr gre_uhdr.gi6hdr +#define gre_oip gre_gihdr->gi_ip +#define gre_oip6 gre_gi6hdr->gi6_ip6 + +int gre_input(struct mbuf **, int *, int); +#ifdef INET +int in_gre_attach(struct gre_softc *); +int in_gre_output(struct mbuf *, int, int); +#endif +#ifdef INET6 +int in6_gre_attach(struct gre_softc *); +int in6_gre_output(struct mbuf *, int, int); +#endif /* * CISCO uses special type for GRE tunnel created as part of WCCP * connection, while in fact those packets are just IPv4 encapsulated * into GRE. */ -#define WCCP_PROTOCOL_TYPE 0x883E - -/* - * gre_sre defines a Source route Entry. These are needed if packets - * should be routed over more than one tunnel hop by hop - */ -struct gre_sre { - u_int16_t sre_family; /* address family */ - u_char sre_offset; /* offset to first octet of active entry */ - u_char sre_length; /* number of octets in the SRE. - sre_lengthl==0 -> last entry. */ - u_char *sre_rtinfo; /* the routing information */ -}; - -struct greioctl { - int unit; - struct in_addr addr; -}; - -/* for mobile encaps */ - -struct mobile_h { - u_int16_t proto; /* protocol and S-bit */ - u_int16_t hcrc; /* header checksum */ - u_int32_t odst; /* original destination address */ - u_int32_t osrc; /* original source addr, if S-bit set */ -} __packed; - -struct mobip_h { - struct ip mi; - struct mobile_h mh; -} __packed; - - -#define MOB_H_SIZ_S (sizeof(struct mobile_h) - sizeof(u_int32_t)) -#define MOB_H_SIZ_L (sizeof(struct mobile_h)) -#define MOB_H_SBIT 0x0080 - -#define GRE_TTL 30 - +#define ETHERTYPE_WCCP 0x883E #endif /* _KERNEL */ -/* - * ioctls needed to manipulate the interface - */ - #define GRESADDRS _IOW('i', 101, struct ifreq) #define GRESADDRD _IOW('i', 102, struct ifreq) #define GREGADDRS _IOWR('i', 103, struct ifreq) #define GREGADDRD _IOWR('i', 104, struct ifreq) #define GRESPROTO _IOW('i' , 105, struct ifreq) #define GREGPROTO _IOWR('i', 106, struct ifreq) -#define GREGKEY _IOWR('i', 107, struct ifreq) -#define GRESKEY _IOW('i', 108, struct ifreq) -#ifdef _KERNEL -LIST_HEAD(gre_softc_head, gre_softc); -extern struct mtx gre_mtx; -extern struct gre_softc_head gre_softc_list; +#define GREGKEY _IOWR('i', 107, struct ifreq) +#define GRESKEY _IOW('i', 108, struct ifreq) +#define GREGOPTS _IOWR('i', 109, struct ifreq) +#define GRESOPTS _IOW('i', 110, struct ifreq) -u_int16_t gre_in_cksum(u_int16_t *, u_int); -#endif /* _KERNEL */ +#define GRE_ENABLE_CSUM 0x0001 +#define GRE_ENABLE_SEQ 0x0002 +#define GRE_OPTMASK (GRE_ENABLE_CSUM|GRE_ENABLE_SEQ) -#endif +#endif /* _NET_IF_GRE_H_ */ |