From: David van Moolenbroek Date: Sun, 13 Mar 2016 15:55:44 +0000 (+0000) Subject: libc: enable all functionality in net/ X-Git-Url: http://zhaoyanbai.com/repos/pkcs11-tokens.html?a=commitdiff_plain;h=refs%2Fchanges%2F10%2F3310%2F1;p=minix.git libc: enable all functionality in net/ Some functions in lib/libc/net were disabled on MINIX3 only, but with a few added header files they build just fine, even though some of them rely on system functionality that has not yet been implemented. Since the functionality is unlikely to be used in practice (because it typically requires the use of protocol families that themselves are not yet supported, such as IPv6), already enabling it right now helps in building packages that rely on the functionality being present at compile time, while not posing any practical risk of breaking the same packages at run time. Change-Id: Idee8e3963c9e300bde9575429f0e77b0565acaef --- diff --git a/distrib/sets/lists/minix-comp/mi b/distrib/sets/lists/minix-comp/mi index 3b2d39e9b..4dd3f5499 100644 --- a/distrib/sets/lists/minix-comp/mi +++ b/distrib/sets/lists/minix-comp/mi @@ -42,6 +42,8 @@ ./usr/include minix-comp ./usr/include/a.out.h minix-comp ./usr/include/aio.h minix-comp +./usr/include/altq minix-comp +./usr/include/altq/if_altq.h minix-comp ./usr/include/ar.h minix-comp ./usr/include/archive.h minix-comp ./usr/include/archive_entry.h minix-comp @@ -1268,6 +1270,7 @@ ./usr/include/msdosfs/msdosfsmount.h minix-comp ./usr/include/ndbm.h minix-comp ./usr/include/net minix-comp +./usr/include/net/dlt.h minix-comp ./usr/include/net/ethertypes.h minix-comp ./usr/include/net/gen minix-comp ./usr/include/net/gen/arp_io.h minix-comp @@ -1301,8 +1304,11 @@ ./usr/include/net/gen/vjhc.h minix-comp ./usr/include/net/hton.h minix-comp ./usr/include/net/if.h minix-comp +./usr/include/net/if_arp.h minix-comp +./usr/include/net/if_dl.h minix-comp ./usr/include/net/if_ether.h minix-comp ./usr/include/net/netlib.h minix-comp +./usr/include/net/pfil.h minix-comp ./usr/include/net/radix.h minix-comp ./usr/include/net/route.h minix-comp ./usr/include/netconfig.h minix-comp diff --git a/etc/mtree/NetBSD.dist.base b/etc/mtree/NetBSD.dist.base index e9a0f16ad..efc7f3abf 100644 --- a/etc/mtree/NetBSD.dist.base +++ b/etc/mtree/NetBSD.dist.base @@ -71,6 +71,7 @@ ./usr/games ./usr/games/hide gname=games mode=0750 ./usr/include +./usr/include/altq ./usr/include/arpa ./usr/include/atf-c ./usr/include/atf-c++ diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc index 3c57af133..bf65717a1 100644 --- a/lib/libc/net/Makefile.inc +++ b/lib/libc/net/Makefile.inc @@ -11,17 +11,16 @@ CPPFLAGS.setsockopt.c+= -D_MINIX_SYSTEM=1 .endif .PATH: ${ARCHDIR}/net ${.CURDIR}/net -# Not supported by minix: iso_addr.c link_addr.c sockatmark.c SRCS+= base64.c ethers.c gethnamaddr.c getifaddrs.c \ getnetnamadr.c getnetent.c getpeereid.c \ getprotobyname.c getprotobynumber.c getprotoent.c \ getprotobyname_r.c getprotobynumber_r.c getprotoent_r.c \ getservbyname.c getservbyport.c getservent.c \ getservbyname_r.c getservbyport_r.c getservent_r.c \ - \ + iso_addr.c linkaddr.c \ nsdispatch.c nslexer.l nsparser.y nsap_addr.c \ rcmd.c recv.c send.c sethostent.c \ -# sockatmark.c + sockatmark.c .if (${MKHESIOD} != "no") SRCS+= hesiod.c @@ -31,9 +30,7 @@ SRCS+= getaddrinfo.c getnameinfo.c .if (${USE_INET6} != "no") SRCS+= ip6opt.c rthdr.c vars6.c inet6_scopeid.c .endif -.if !defined(__MINIX) SRCS+= if_indextoname.c if_nameindex.c if_nametoindex.c -.endif LPREFIX=_nsyy YPREFIX=_nsyy diff --git a/minix/include/minix/netsock.h b/minix/include/minix/netsock.h index 1a53813ef..63ad4c532 100644 --- a/minix/include/minix/netsock.h +++ b/minix/include/minix/netsock.h @@ -107,16 +107,16 @@ struct socket { */ int socket_open(devminor_t minor); -#define get_sock_num(x) ((long int) ((x) - socket)) +#define get_sock_num(x) ((long int) ((x) - socket_array)) #define is_valid_sock_num(x) (x < MAX_SOCKETS) -#define get_sock(x) &socket[x] +#define get_sock(x) &socket_array[x] #define MAX_SOCKETS 255 /* FIXME as log as the sockets are identified by the minor device number 255 is ok */ #define MAX_DEVS 5 #define RESERVED (SOCK_TYPES + MAX_DEVS) /* rounded to 8 */ -extern struct socket socket[MAX_SOCKETS]; +extern struct socket socket_array[MAX_SOCKETS]; void socket_request(message * m, int ipc_status); void mq_process(void); diff --git a/minix/include/net/Makefile b/minix/include/net/Makefile index 68716bbc1..33007e56c 100644 --- a/minix/include/net/Makefile +++ b/minix/include/net/Makefile @@ -1,6 +1,6 @@ INCSDIR= /usr/include/net -INCS+= hton.h if.h netlib.h +INCS+= hton.h netlib.h SUBDIR+= gen diff --git a/minix/include/net/if.h b/minix/include/net/if.h deleted file mode 100644 index 39446f23f..000000000 --- a/minix/include/net/if.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _NET_IF_H_ -#define _NET_IF_H_ - -#define IFF_UP 0x0001 /* interface is up */ - -#endif /* _NET_IF_H_ */ diff --git a/minix/lib/libnetsock/socket.c b/minix/lib/libnetsock/socket.c index 2635ef07e..2207fdd54 100644 --- a/minix/lib/libnetsock/socket.c +++ b/minix/lib/libnetsock/socket.c @@ -40,7 +40,7 @@ char * netsock_user_name = NULL; ##__VA_ARGS__) -struct socket socket[MAX_SOCKETS]; +struct socket socket_array[MAX_SOCKETS]; static int netsock_open(devminor_t minor, int access, endpoint_t user_endpt); static int netsock_close(devminor_t minor); @@ -249,10 +249,10 @@ struct socket * get_unused_sock(void) int i; for (i = SOCK_TYPES + MAX_DEVS; i < MAX_SOCKETS; i++) { - if (socket[i].ops == NULL) { + if (socket_array[i].ops == NULL) { /* clear it all */ - memset(&socket[i], 0, sizeof(struct socket)); - return &socket[i]; + memset(&socket_array[i], 0, sizeof(struct socket)); + return &socket_array[i]; } } diff --git a/sys/Makefile b/sys/Makefile index 2698467d2..41bb31a4f 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -2,7 +2,7 @@ .include -SUBDIR= arch dev fs \ +SUBDIR= altq arch dev fs \ net netinet netinet6 \ \ sys ufs uvm diff --git a/sys/altq/Makefile b/sys/altq/Makefile new file mode 100644 index 000000000..30b1d19b1 --- /dev/null +++ b/sys/altq/Makefile @@ -0,0 +1,11 @@ +# $NetBSD: Makefile,v 1.3 2006/10/12 19:59:08 peter Exp $ + +INCSDIR= /usr/include/altq + +INCS= \ + \ + \ + \ + if_altq.h + +.include diff --git a/sys/altq/if_altq.h b/sys/altq/if_altq.h new file mode 100644 index 000000000..1858e9df2 --- /dev/null +++ b/sys/altq/if_altq.h @@ -0,0 +1,177 @@ +/* $NetBSD: if_altq.h,v 1.14 2014/07/01 10:16:02 ozaki-r Exp $ */ +/* $KAME: if_altq.h,v 1.12 2005/04/13 03:44:25 suz Exp $ */ + +/* + * Copyright (C) 1997-2003 + * Sony Computer Science Laboratories Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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. + */ +#ifndef _ALTQ_IF_ALTQ_H_ +#define _ALTQ_IF_ALTQ_H_ + +#if defined(_KERNEL_OPT) +#include "opt_altq_enabled.h" +#endif + +struct altq_pktattr; struct tb_regulator; struct top_cdnr; + +/* + * Structure defining a queue for a network interface. + */ +struct ifaltq { + /* fields compatible with struct ifqueue */ + struct mbuf *ifq_head; + struct mbuf *ifq_tail; + int ifq_len; + int ifq_maxlen; + int ifq_drops; + kmutex_t *ifq_lock; + + /* alternate queueing related fields */ + int altq_type; /* discipline type */ + int altq_flags; /* flags (e.g. ready, in-use) */ + void *altq_disc; /* for discipline-specific use */ + struct ifnet *altq_ifp; /* back pointer to interface */ + + int (*altq_enqueue)(struct ifaltq *, struct mbuf *, + struct altq_pktattr *); + struct mbuf *(*altq_dequeue)(struct ifaltq *, int); + int (*altq_request)(struct ifaltq *, int, void *); + + /* classifier fields */ + void *altq_clfier; /* classifier-specific use */ + void *(*altq_classify)(void *, struct mbuf *, int); + + /* token bucket regulator */ + struct tb_regulator *altq_tbr; + + /* input traffic conditioner (doesn't belong to the output queue...) */ + struct top_cdnr *altq_cdnr; +}; + + +#ifdef _KERNEL + +/* + * packet attributes used by queueing disciplines. + * pattr_class is a discipline-dependent scheduling class that is + * set by a classifier. + * pattr_hdr and pattr_af may be used by a discipline to access + * the header within a mbuf. (e.g. ECN needs to update the CE bit) + * note that pattr_hdr could be stale after m_pullup, though link + * layer output routines usually don't use m_pullup. link-level + * compression also invalidates these fields. thus, pattr_hdr needs + * to be verified when a discipline touches the header. + */ +struct altq_pktattr { + void *pattr_class; /* sched class set by classifier */ + int pattr_af; /* address family */ + void * pattr_hdr; /* saved header position in mbuf */ +}; + +/* + * mbuf tag to carry a queue id (and hints for ECN). + */ +struct altq_tag { + u_int32_t qid; /* queue id */ + /* hints for ecn */ + int af; /* address family */ + void *hdr; /* saved header position in mbuf */ +}; + +/* + * a token-bucket regulator limits the rate that a network driver can + * dequeue packets from the output queue. + * modern cards are able to buffer a large amount of packets and dequeue + * too many packets at a time. this bursty dequeue behavior makes it + * impossible to schedule packets by queueing disciplines. + * a token-bucket is used to control the burst size in a device + * independent manner. + */ +struct tb_regulator { + int64_t tbr_rate; /* (scaled) token bucket rate */ + int64_t tbr_depth; /* (scaled) token bucket depth */ + + int64_t tbr_token; /* (scaled) current token */ + int64_t tbr_filluptime; /* (scaled) time to fill up bucket */ + u_int64_t tbr_last; /* last time token was updated */ + + int tbr_lastop; /* last dequeue operation type + needed for poll-and-dequeue */ +}; + +/* if_altqflags */ +#define ALTQF_READY 0x01 /* driver supports alternate queueing */ +#define ALTQF_ENABLED 0x02 /* altq is in use */ +#define ALTQF_CLASSIFY 0x04 /* classify packets */ +#define ALTQF_CNDTNING 0x08 /* altq traffic conditioning is enabled */ +#define ALTQF_DRIVER1 0x40 /* driver specific */ + +/* if_altqflags set internally only: */ +#define ALTQF_CANTCHANGE (ALTQF_READY) + +/* altq_dequeue 2nd arg */ +#define ALTDQ_REMOVE 1 /* dequeue mbuf from the queue */ +#define ALTDQ_POLL 2 /* don't dequeue mbuf from the queue */ + +/* altq request types (currently only purge is defined) */ +#define ALTRQ_PURGE 1 /* purge all packets */ + +#define ALTQ_IS_READY(ifq) ((ifq)->altq_flags & ALTQF_READY) +#define ALTQ_IS_ENABLED(ifq) ((ifq)->altq_flags & ALTQF_ENABLED) +#define ALTQ_NEEDS_CLASSIFY(ifq) ((ifq)->altq_flags & ALTQF_CLASSIFY) +#define ALTQ_IS_CNDTNING(ifq) ((ifq)->altq_flags & ALTQF_CNDTNING) + +#define ALTQ_SET_CNDTNING(ifq) ((ifq)->altq_flags |= ALTQF_CNDTNING) +#define ALTQ_CLEAR_CNDTNING(ifq) ((ifq)->altq_flags &= ~ALTQF_CNDTNING) +#define ALTQ_IS_ATTACHED(ifq) ((ifq)->altq_disc != NULL) + +#define ALTQ_ENQUEUE(ifq, m, pa, err) \ + (err) = (*(ifq)->altq_enqueue)((ifq),(m),(pa)) +#define ALTQ_DEQUEUE(ifq, m) \ + (m) = (*(ifq)->altq_dequeue)((ifq), ALTDQ_REMOVE) +#define ALTQ_POLL(ifq, m) \ + (m) = (*(ifq)->altq_dequeue)((ifq), ALTDQ_POLL) +#define ALTQ_PURGE(ifq) \ + (void)(*(ifq)->altq_request)((ifq), ALTRQ_PURGE, (void *)0) +#define ALTQ_IS_EMPTY(ifq) ((ifq)->ifq_len == 0) +#define TBR_IS_ENABLED(ifq) ((ifq)->altq_tbr != NULL) + +extern int altq_attach(struct ifaltq *, int, void *, + int (*)(struct ifaltq *, struct mbuf *, + struct altq_pktattr *), + struct mbuf *(*)(struct ifaltq *, int), + int (*)(struct ifaltq *, int, void *), + void *, + void *(*)(void *, struct mbuf *, int)); +extern int altq_detach(struct ifaltq *); +extern int altq_enable(struct ifaltq *); +extern int altq_disable(struct ifaltq *); +extern struct mbuf *tbr_dequeue(struct ifaltq *, int); +extern int (*altq_input)(struct mbuf *, int); +#if 1 /* ALTQ3_CLFIER_COMPAT */ +void altq_etherclassify(struct ifaltq *, struct mbuf *, struct altq_pktattr *); +#endif +#endif /* _KERNEL */ + +#endif /* _ALTQ_IF_ALTQ_H_ */ diff --git a/sys/net/Makefile b/sys/net/Makefile index f84d9ef6b..f1b3b9a19 100644 --- a/sys/net/Makefile +++ b/sys/net/Makefile @@ -2,12 +2,12 @@ INCSDIR= /usr/include/net -INCS= ethertypes.h \ - if_ether.h \ +INCS= dlt.h ethertypes.h if.h if_arp.h \ + if_dl.h if_ether.h \ \ \ \ - radix.h \ + pfil.h radix.h \ route.h .if !defined(__MINIX) diff --git a/sys/net/dlt.h b/sys/net/dlt.h new file mode 100644 index 000000000..c3f5b5b5e --- /dev/null +++ b/sys/net/dlt.h @@ -0,0 +1,1290 @@ +/* $NetBSD: dlt.h,v 1.16 2015/03/31 21:42:16 christos Exp $ */ + +/*- + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from the Stanford/CMU enet packet filter, + * (net/enet.c) distributed as part of 4.3BSD, and code contributed + * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence + * Berkeley Laboratory. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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. + * + * @(#)bpf.h 7.1 (Berkeley) 5/7/91 + * + * @(#) Header: /tcpdump/master/libpcap/pcap/bpf.h,v 1.32 2008-12-23 20:13:29 guy Exp (LBL) + */ + +#ifndef _NET_DLT_H_ +#define _NET_DLT_H_ +/* + * Link-layer header type codes. + * + * Do *NOT* add new values to this list without asking + * "tcpdump-workers@lists.tcpdump.org" for a value. Otherwise, you run + * the risk of using a value that's already being used for some other + * purpose, and of having tools that read libpcap-format captures not + * being able to handle captures with your new DLT_ value, with no hope + * that they will ever be changed to do so (as that would destroy their + * ability to read captures using that value for that other purpose). + * + * See + * + * http://www.tcpdump.org/linktypes.html + * + * for detailed descriptions of some of these link-layer header types. + */ + +/* + * These are the types that are the same on all platforms, and that + * have been defined by for ages. + */ +#define DLT_NULL 0 /* BSD loopback encapsulation */ +#define DLT_EN10MB 1 /* Ethernet (10Mb) */ +#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */ +#define DLT_AX25 3 /* Amateur Radio AX.25 */ +#define DLT_PRONET 4 /* Proteon ProNET Token Ring */ +#define DLT_CHAOS 5 /* Chaos */ +#define DLT_IEEE802 6 /* 802.5 Token Ring */ +#define DLT_ARCNET 7 /* ARCNET, with BSD-style header */ +#define DLT_SLIP 8 /* Serial Line IP */ +#define DLT_PPP 9 /* Point-to-point Protocol */ +#define DLT_FDDI 10 /* FDDI */ + +/* + * These are types that are different on some platforms, and that + * have been defined by for ages. We use #ifdefs to + * detect the BSDs that define them differently from the traditional + * libpcap + * + * XXX - DLT_ATM_RFC1483 is 13 in BSD/OS, and DLT_RAW is 14 in BSD/OS, + * but I don't know what the right #define is for BSD/OS. + */ +#define DLT_ATM_RFC1483 11 /* LLC-encapsulated ATM */ + +#ifdef __OpenBSD__ +#define DLT_RAW 14 /* raw IP */ +#else +#define DLT_RAW 12 /* raw IP */ +#endif + +/* + * Given that the only OS that currently generates BSD/OS SLIP or PPP + * is, well, BSD/OS, arguably everybody should have chosen its values + * for DLT_SLIP_BSDOS and DLT_PPP_BSDOS, which are 15 and 16, but they + * didn't. So it goes. + */ +#if defined(__NetBSD__) || defined(__FreeBSD__) +#ifndef DLT_SLIP_BSDOS +#define DLT_SLIP_BSDOS 13 /* BSD/OS Serial Line IP */ +#define DLT_PPP_BSDOS 14 /* BSD/OS Point-to-point Protocol */ +#define DLT_HIPPI 15 /* HIPPI */ +#define DLT_HDLC 16 /* HDLC framing */ +#endif +#else +#define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */ +#define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */ +#endif + +/* + * 17 was used for DLT_PFLOG in OpenBSD; it no longer is. + * + * It was DLT_LANE8023 in SuSE 6.3, so we defined LINKTYPE_PFLOG + * as 117 so that pflog captures would use a link-layer header type + * value that didn't collide with any other values. On all + * platforms other than OpenBSD, we defined DLT_PFLOG as 117, + * and we mapped between LINKTYPE_PFLOG and DLT_PFLOG. + * + * OpenBSD eventually switched to using 117 for DLT_PFLOG as well. + * + * Don't use 17 for anything else. + */ +#if defined(__OpenBSD__) || defined(__NetBSD__) +#define DLT_OLD_PFLOG 17 +#endif + +/* + * 18 is used for DLT_PFSYNC in OpenBSD, NetBSD, DragonFly BSD and + * Mac OS X; don't use it for anything else. (FreeBSD uses 121, + * which collides with DLT_HHDLC, even though it doesn't use 18 + * for anything and doesn't appear to have ever used it for anything.) + * + * We define it as 18 on those platforms; it is, unfortunately, used + * for DLT_CIP in Suse 6.3, so we don't define it as DLT_PFSYNC + * in general. As the packet format for it, like that for + * DLT_PFLOG, is not only OS-dependent but OS-version-dependent, + * we don't support printing it in tcpdump except on OSes that + * have the relevant header files, so it's not that useful on + * other platforms. + */ +#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__) +#define DLT_PFSYNC 18 +#endif + +#define DLT_ATM_CLIP 19 /* Linux Classical-IP over ATM */ + +/* + * Apparently Redback uses this for its SmartEdge 400/800. I hope + * nobody else decided to use it, too. + */ +#define DLT_REDBACK_SMARTEDGE 32 + +/* + * These values are defined by NetBSD; other platforms should refrain from + * using them for other purposes, so that NetBSD savefiles with link + * types of 50 or 51 can be read as this type on all platforms. + */ +#define DLT_PPP_SERIAL 50 /* PPP over serial with HDLC encapsulation */ +#define DLT_PPP_ETHER 51 /* PPP over Ethernet */ + +/* + * The Axent Raptor firewall - now the Symantec Enterprise Firewall - uses + * a link-layer type of 99 for the tcpdump it supplies. The link-layer + * header has 6 bytes of unknown data, something that appears to be an + * Ethernet type, and 36 bytes that appear to be 0 in at least one capture + * I've seen. + */ +#define DLT_SYMANTEC_FIREWALL 99 + +/* + * Values between 100 and 103 are used in capture file headers as + * link-layer header type LINKTYPE_ values corresponding to DLT_ types + * that differ between platforms; don't use those values for new DLT_ + * new types. + */ + +/* + * Values starting with 104 are used for newly-assigned link-layer + * header type values; for those link-layer header types, the DLT_ + * value returned by pcap_datalink() and passed to pcap_open_dead(), + * and the LINKTYPE_ value that appears in capture files, are the + * same. + * + * DLT_MATCHING_MIN is the lowest such value; DLT_MATCHING_MAX is + * the highest such value. + */ +#define DLT_MATCHING_MIN 104 + +/* + * This value was defined by libpcap 0.5; platforms that have defined + * it with a different value should define it here with that value - + * a link type of 104 in a save file will be mapped to DLT_C_HDLC, + * whatever value that happens to be, so programs will correctly + * handle files with that link type regardless of the value of + * DLT_C_HDLC. + * + * The name DLT_C_HDLC was used by BSD/OS; we use that name for source + * compatibility with programs written for BSD/OS. + * + * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well, + * for source compatibility with programs written for libpcap 0.5. + */ +#define DLT_C_HDLC 104 /* Cisco HDLC */ +#define DLT_CHDLC DLT_C_HDLC + +#define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */ + +/* + * 106 is reserved for Linux Classical IP over ATM; it's like DLT_RAW, + * except when it isn't. (I.e., sometimes it's just raw IP, and + * sometimes it isn't.) We currently handle it as DLT_LINUX_SLL, + * so that we don't have to worry about the link-layer header.) + */ + +/* + * Frame Relay; BSD/OS has a DLT_FR with a value of 11, but that collides + * with other values. + * DLT_FR and DLT_FRELAY packets start with the Q.922 Frame Relay header + * (DLCI, etc.). + */ +#define DLT_FRELAY 107 + +/* + * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except + * that the AF_ type in the link-layer header is in network byte order. + * + * DLT_LOOP is 12 in OpenBSD, but that's DLT_RAW in other OSes, so + * we don't use 12 for it in OSes other than OpenBSD. + */ +#ifdef __OpenBSD__ +#define DLT_LOOP 12 +#else +#define DLT_LOOP 108 +#endif + +/* + * Encapsulated packets for IPsec; DLT_ENC is 13 in OpenBSD, but that's + * DLT_SLIP_BSDOS in NetBSD, so we don't use 13 for it in OSes other + * than OpenBSD. + */ +#ifdef __OpenBSD__ +#define DLT_ENC 13 +#else +#define DLT_ENC 109 +#endif + +/* + * Values between 110 and 112 are reserved for use in capture file headers + * as link-layer types corresponding to DLT_ types that might differ + * between platforms; don't use those values for new DLT_ types + * other than the corresponding DLT_ types. + */ + +/* + * This is for Linux cooked sockets. + */ +#define DLT_LINUX_SLL 113 + +/* + * Apple LocalTalk hardware. + */ +#define DLT_LTALK 114 + +/* + * Acorn Econet. + */ +#define DLT_ECONET 115 + +/* + * Reserved for use with OpenBSD ipfilter. + */ +#define DLT_IPFILTER 116 + +/* + * OpenBSD DLT_PFLOG. + */ +#define DLT_PFLOG 117 + +/* + * Registered for Cisco-internal use. + */ +#define DLT_CISCO_IOS 118 + +/* + * For 802.11 cards using the Prism II chips, with a link-layer + * header including Prism monitor mode information plus an 802.11 + * header. + */ +#define DLT_PRISM_HEADER 119 + +/* + * Reserved for Aironet 802.11 cards, with an Aironet link-layer header + * (see Doug Ambrisko's FreeBSD patches). + */ +#define DLT_AIRONET_HEADER 120 + +/* + * Sigh. + * + * This was reserved for Siemens HiPath HDLC on 2002-01-25, as + * requested by Tomas Kukosa. + * + * On 2004-02-25, a FreeBSD checkin to sys/net/bpf.h was made that + * assigned 121 as DLT_PFSYNC. Its libpcap does DLT_ <-> LINKTYPE_ + * mapping, so it probably supports capturing on the pfsync device + * but not saving the captured data to a pcap file. + * + * OpenBSD, from which pf came, however, uses 18 for DLT_PFSYNC; + * their libpcap does no DLT_ <-> LINKTYPE_ mapping, so it would + * use 18 in pcap files as well. + * + * NetBSD and DragonFly BSD also use 18 for DLT_PFSYNC; their + * libpcaps do DLT_ <-> LINKTYPE_ mapping, and neither has an entry + * for DLT_PFSYNC, so it might not be able to write out dump files + * with 18 as the link-layer header type. (Earlier versions might + * not have done mapping, in which case they'd work the same way + * OpenBSD does.) + * + * Mac OS X defines it as 18, but doesn't appear to use it as of + * Mac OS X 10.7.3. Its libpcap does DLT_ <-> LINKTYPE_ mapping. + * + * We'll define DLT_PFSYNC as 121 on FreeBSD and define it as 18 on + * all other platforms. We'll define DLT_HHDLC as 121 on everything + * except for FreeBSD; anybody who wants to compile, on FreeBSD, code + * that uses DLT_HHDLC is out of luck. + * + * We'll define LINKTYPE_PFSYNC as 18, *even on FreeBSD*, and map + * it, so that savefiles won't use 121 for PFSYNC - they'll all + * use 18. Code that uses pcap_datalink() to determine the link-layer + * header type of a savefile won't, when built and run on FreeBSD, + * be able to distinguish between LINKTYPE_PFSYNC and LINKTYPE_HHDLC + * capture files; code that doesn't, such as the code in Wireshark, + * will be able to distinguish between them. + */ +#ifdef __FreeBSD__ +#define DLT_PFSYNC 121 +#else +#define DLT_HHDLC 121 +#endif + +/* + * This is for RFC 2625 IP-over-Fibre Channel. + * + * This is not for use with raw Fibre Channel, where the link-layer + * header starts with a Fibre Channel frame header; it's for IP-over-FC, + * where the link-layer header starts with an RFC 2625 Network_Header + * field. + */ +#define DLT_IP_OVER_FC 122 + +/* + * This is for Full Frontal ATM on Solaris with SunATM, with a + * pseudo-header followed by an AALn PDU. + * + * There may be other forms of Full Frontal ATM on other OSes, + * with different pseudo-headers. + * + * If ATM software returns a pseudo-header with VPI/VCI information + * (and, ideally, packet type information, e.g. signalling, ILMI, + * LANE, LLC-multiplexed traffic, etc.), it should not use + * DLT_ATM_RFC1483, but should get a new DLT_ value, so tcpdump + * and the like don't have to infer the presence or absence of a + * pseudo-header and the form of the pseudo-header. + */ +#define DLT_SUNATM 123 /* Solaris+SunATM */ + +/* + * Reserved as per request from Kent Dahlgren + * for private use. + */ +#define DLT_RIO 124 /* RapidIO */ +#define DLT_PCI_EXP 125 /* PCI Express */ +#define DLT_AURORA 126 /* Xilinx Aurora link layer */ + +/* + * Header for 802.11 plus a number of bits of link-layer information + * including radio information, used by some recent BSD drivers as + * well as the madwifi Atheros driver for Linux. + */ +#define DLT_IEEE802_11_RADIO 127 /* 802.11 plus radiotap radio header */ + +/* + * Reserved for the TZSP encapsulation, as per request from + * Chris Waters + * TZSP is a generic encapsulation for any other link type, + * which includes a means to include meta-information + * with the packet, e.g. signal strength and channel + * for 802.11 packets. + */ +#define DLT_TZSP 128 /* Tazmen Sniffer Protocol */ + +/* + * BSD's ARCNET headers have the source host, destination host, + * and type at the beginning of the packet; that's what's handed + * up to userland via BPF. + * + * Linux's ARCNET headers, however, have a 2-byte offset field + * between the host IDs and the type; that's what's handed up + * to userland via PF_PACKET sockets. + * + * We therefore have to have separate DLT_ values for them. + */ +#define DLT_ARCNET_LINUX 129 /* ARCNET */ + +/* + * Juniper-private data link types, as per request from + * Hannes Gredler . The DLT_s are used + * for passing on chassis-internal metainformation such as + * QOS profiles, etc.. + */ +#define DLT_JUNIPER_MLPPP 130 +#define DLT_JUNIPER_MLFR 131 +#define DLT_JUNIPER_ES 132 +#define DLT_JUNIPER_GGSN 133 +#define DLT_JUNIPER_MFR 134 +#define DLT_JUNIPER_ATM2 135 +#define DLT_JUNIPER_SERVICES 136 +#define DLT_JUNIPER_ATM1 137 + +/* + * Apple IP-over-IEEE 1394, as per a request from Dieter Siegmund + * . The header that's presented is an Ethernet-like + * header: + * + * #define FIREWIRE_EUI64_LEN 8 + * struct firewire_header { + * u_char firewire_dhost[FIREWIRE_EUI64_LEN]; + * u_char firewire_shost[FIREWIRE_EUI64_LEN]; + * u_short firewire_type; + * }; + * + * with "firewire_type" being an Ethernet type value, rather than, + * for example, raw GASP frames being handed up. + */ +#define DLT_APPLE_IP_OVER_IEEE1394 138 + +/* + * Various SS7 encapsulations, as per a request from Jeff Morriss + * and subsequent discussions. + */ +#define DLT_MTP2_WITH_PHDR 139 /* pseudo-header with various info, followed by MTP2 */ +#define DLT_MTP2 140 /* MTP2, without pseudo-header */ +#define DLT_MTP3 141 /* MTP3, without pseudo-header or MTP2 */ +#define DLT_SCCP 142 /* SCCP, without pseudo-header or MTP2 or MTP3 */ + +/* + * DOCSIS MAC frames. + */ +#define DLT_DOCSIS 143 + +/* + * Linux-IrDA packets. Protocol defined at http://www.irda.org. + * Those packets include IrLAP headers and above (IrLMP...), but + * don't include Phy framing (SOF/EOF/CRC & byte stuffing), because Phy + * framing can be handled by the hardware and depend on the bitrate. + * This is exactly the format you would get capturing on a Linux-IrDA + * interface (irdaX), but not on a raw serial port. + * Note the capture is done in "Linux-cooked" mode, so each packet include + * a fake packet header (struct sll_header). This is because IrDA packet + * decoding is dependant on the direction of the packet (incomming or + * outgoing). + * When/if other platform implement IrDA capture, we may revisit the + * issue and define a real DLT_IRDA... + * Jean II + */ +#define DLT_LINUX_IRDA 144 + +/* + * Reserved for IBM SP switch and IBM Next Federation switch. + */ +#define DLT_IBM_SP 145 +#define DLT_IBM_SN 146 + +/* + * Reserved for private use. If you have some link-layer header type + * that you want to use within your organization, with the capture files + * using that link-layer header type not ever be sent outside your + * organization, you can use these values. + * + * No libpcap release will use these for any purpose, nor will any + * tcpdump release use them, either. + * + * Do *NOT* use these in capture files that you expect anybody not using + * your private versions of capture-file-reading tools to read; in + * particular, do *NOT* use them in products, otherwise you may find that + * people won't be able to use tcpdump, or snort, or Ethereal, or... to + * read capture files from your firewall/intrusion detection/traffic + * monitoring/etc. appliance, or whatever product uses that DLT_ value, + * and you may also find that the developers of those applications will + * not accept patches to let them read those files. + * + * Also, do not use them if somebody might send you a capture using them + * for *their* private type and tools using them for *your* private type + * would have to read them. + * + * Instead, ask "tcpdump-workers@lists.tcpdump.org" for a new DLT_ value, + * as per the comment above, and use the type you're given. + */ +#define DLT_USER0 147 +#define DLT_USER1 148 +#define DLT_USER2 149 +#define DLT_USER3 150 +#define DLT_USER4 151 +#define DLT_USER5 152 +#define DLT_USER6 153 +#define DLT_USER7 154 +#define DLT_USER8 155 +#define DLT_USER9 156 +#define DLT_USER10 157 +#define DLT_USER11 158 +#define DLT_USER12 159 +#define DLT_USER13 160 +#define DLT_USER14 161 +#define DLT_USER15 162 + +/* + * For future use with 802.11 captures - defined by AbsoluteValue + * Systems to store a number of bits of link-layer information + * including radio information: + * + * http://www.shaftnet.org/~pizza/software/capturefrm.txt + * + * but it might be used by some non-AVS drivers now or in the + * future. + */ +#define DLT_IEEE802_11_RADIO_AVS 163 /* 802.11 plus AVS radio header */ + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . The DLT_s are used + * for passing on chassis-internal metainformation such as + * QOS profiles, etc.. + */ +#define DLT_JUNIPER_MONITOR 164 + +/* + * BACnet MS/TP frames. + */ +#define DLT_BACNET_MS_TP 165 + +/* + * Another PPP variant as per request from Karsten Keil . + * + * This is used in some OSes to allow a kernel socket filter to distinguish + * between incoming and outgoing packets, on a socket intended to + * supply pppd with outgoing packets so it can do dial-on-demand and + * hangup-on-lack-of-demand; incoming packets are filtered out so they + * don't cause pppd to hold the connection up (you don't want random + * input packets such as port scans, packets from old lost connections, + * etc. to force the connection to stay up). + * + * The first byte of the PPP header (0xff03) is modified to accomodate + * the direction - 0x00 = IN, 0x01 = OUT. + */ +#define DLT_PPP_PPPD 166 + +/* + * Names for backwards compatibility with older versions of some PPP + * software; new software should use DLT_PPP_PPPD. + */ +#define DLT_PPP_WITH_DIRECTION DLT_PPP_PPPD +#define DLT_LINUX_PPP_WITHDIRECTION DLT_PPP_PPPD + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . The DLT_s are used + * for passing on chassis-internal metainformation such as + * QOS profiles, cookies, etc.. + */ +#define DLT_JUNIPER_PPPOE 167 +#define DLT_JUNIPER_PPPOE_ATM 168 + +#define DLT_GPRS_LLC 169 /* GPRS LLC */ +#define DLT_GPF_T 170 /* GPF-T (ITU-T G.7041/Y.1303) */ +#define DLT_GPF_F 171 /* GPF-F (ITU-T G.7041/Y.1303) */ + +/* + * Requested by Oolan Zimmer for use in Gcom's T1/E1 line + * monitoring equipment. + */ +#define DLT_GCOM_T1E1 172 +#define DLT_GCOM_SERIAL 173 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . The DLT_ is used + * for internal communication to Physical Interface Cards (PIC) + */ +#define DLT_JUNIPER_PIC_PEER 174 + +/* + * Link types requested by Gregor Maier of Endace + * Measurement Systems. They add an ERF header (see + * http://www.endace.com/support/EndaceRecordFormat.pdf) in front of + * the link-layer header. + */ +#define DLT_ERF_ETH 175 /* Ethernet */ +#define DLT_ERF_POS 176 /* Packet-over-SONET */ + +/* + * Requested by Daniele Orlandi for raw LAPD + * for vISDN (http://www.orlandi.com/visdn/). Its link-layer header + * includes additional information before the LAPD header, so it's + * not necessarily a generic LAPD header. + */ +#define DLT_LINUX_LAPD 177 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . + * The DLT_ are used for prepending meta-information + * like interface index, interface name + * before standard Ethernet, PPP, Frelay & C-HDLC Frames + */ +#define DLT_JUNIPER_ETHER 178 +#define DLT_JUNIPER_PPP 179 +#define DLT_JUNIPER_FRELAY 180 +#define DLT_JUNIPER_CHDLC 181 + +/* + * Multi Link Frame Relay (FRF.16) + */ +#define DLT_MFR 182 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . + * The DLT_ is used for internal communication with a + * voice Adapter Card (PIC) + */ +#define DLT_JUNIPER_VP 183 + +/* + * Arinc 429 frames. + * DLT_ requested by Gianluca Varenni . + * Every frame contains a 32bit A429 label. + * More documentation on Arinc 429 can be found at + * http://www.condoreng.com/support/downloads/tutorials/ARINCTutorial.pdf + */ +#define DLT_A429 184 + +/* + * Arinc 653 Interpartition Communication messages. + * DLT_ requested by Gianluca Varenni . + * Please refer to the A653-1 standard for more information. + */ +#define DLT_A653_ICM 185 + +/* + * USB packets, beginning with a USB setup header; requested by + * Paolo Abeni . + */ +#define DLT_USB 186 + +/* + * Bluetooth HCI UART transport layer (part H:4); requested by + * Paolo Abeni. + */ +#define DLT_BLUETOOTH_HCI_H4 187 + +/* + * IEEE 802.16 MAC Common Part Sublayer; requested by Maria Cruz + * . + */ +#define DLT_IEEE802_16_MAC_CPS 188 + +/* + * USB packets, beginning with a Linux USB header; requested by + * Paolo Abeni . + */ +#define DLT_USB_LINUX 189 + +/* + * Controller Area Network (CAN) v. 2.0B packets. + * DLT_ requested by Gianluca Varenni . + * Used to dump CAN packets coming from a CAN Vector board. + * More documentation on the CAN v2.0B frames can be found at + * http://www.can-cia.org/downloads/?269 + */ +#define DLT_CAN20B 190 + +/* + * IEEE 802.15.4, with address fields padded, as is done by Linux + * drivers; requested by Juergen Schimmer. + */ +#define DLT_IEEE802_15_4_LINUX 191 + +/* + * Per Packet Information encapsulated packets. + * DLT_ requested by Gianluca Varenni . + */ +#define DLT_PPI 192 + +/* + * Header for 802.16 MAC Common Part Sublayer plus a radiotap radio header; + * requested by Charles Clancy. + */ +#define DLT_IEEE802_16_MAC_CPS_RADIO 193 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . + * The DLT_ is used for internal communication with a + * integrated service module (ISM). + */ +#define DLT_JUNIPER_ISM 194 + +/* + * IEEE 802.15.4, exactly as it appears in the spec (no padding, no + * nothing); requested by Mikko Saarnivala . + * For this one, we expect the FCS to be present at the end of the frame; + * if the frame has no FCS, DLT_IEEE802_15_4_NOFCS should be used. + */ +#define DLT_IEEE802_15_4 195 + +/* + * Various link-layer types, with a pseudo-header, for SITA + * (http://www.sita.aero/); requested by Fulko Hew (fulko.hew@gmail.com). + */ +#define DLT_SITA 196 + +/* + * Various link-layer types, with a pseudo-header, for Endace DAG cards; + * encapsulates Endace ERF records. Requested by Stephen Donnelly + * . + */ +#define DLT_ERF 197 + +/* + * Special header prepended to Ethernet packets when capturing from a + * u10 Networks board. Requested by Phil Mulholland + * . + */ +#define DLT_RAIF1 198 + +/* + * IPMB packet for IPMI, beginning with the I2C slave address, followed + * by the netFn and LUN, etc.. Requested by Chanthy Toeung + * . + */ +#define DLT_IPMB 199 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . + * The DLT_ is used for capturing data on a secure tunnel interface. + */ +#define DLT_JUNIPER_ST 200 + +/* + * Bluetooth HCI UART transport layer (part H:4), with pseudo-header + * that includes direction information; requested by Paolo Abeni. + */ +#define DLT_BLUETOOTH_HCI_H4_WITH_PHDR 201 + +/* + * AX.25 packet with a 1-byte KISS header; see + * + * http://www.ax25.net/kiss.htm + * + * as per Richard Stearn . + */ +#define DLT_AX25_KISS 202 + +/* + * LAPD packets from an ISDN channel, starting with the address field, + * with no pseudo-header. + * Requested by Varuna De Silva . + */ +#define DLT_LAPD 203 + +/* + * Variants of various link-layer headers, with a one-byte direction + * pseudo-header prepended - zero means "received by this host", + * non-zero (any non-zero value) means "sent by this host" - as per + * Will Barker . + */ +#define DLT_PPP_WITH_DIR 204 /* PPP - don't confuse with DLT_PPP_WITH_DIRECTION */ +#define DLT_C_HDLC_WITH_DIR 205 /* Cisco HDLC */ +#define DLT_FRELAY_WITH_DIR 206 /* Frame Relay */ +#define DLT_LAPB_WITH_DIR 207 /* LAPB */ + +/* + * 208 is reserved for an as-yet-unspecified proprietary link-layer + * type, as requested by Will Barker. + */ + +/* + * IPMB with a Linux-specific pseudo-header; as requested by Alexey Neyman + * . + */ +#define DLT_IPMB_LINUX 209 + +/* + * FlexRay automotive bus - http://www.flexray.com/ - as requested + * by Hannes Kaelber . + */ +#define DLT_FLEXRAY 210 + +/* + * Media Oriented Systems Transport (MOST) bus for multimedia + * transport - http://www.mostcooperation.com/ - as requested + * by Hannes Kaelber . + */ +#define DLT_MOST 211 + +/* + * Local Interconnect Network (LIN) bus for vehicle networks - + * http://www.lin-subbus.org/ - as requested by Hannes Kaelber + * . + */ +#define DLT_LIN 212 + +/* + * X2E-private data link type used for serial line capture, + * as requested by Hannes Kaelber . + */ +#define DLT_X2E_SERIAL 213 + +/* + * X2E-private data link type used for the Xoraya data logger + * family, as requested by Hannes Kaelber . + */ +#define DLT_X2E_XORAYA 214 + +/* + * IEEE 802.15.4, exactly as it appears in the spec (no padding, no + * nothing), but with the PHY-level data for non-ASK PHYs (4 octets + * of 0 as preamble, one octet of SFD, one octet of frame length+ + * reserved bit, and then the MAC-layer data, starting with the + * frame control field). + * + * Requested by Max Filippov . + */ +#define DLT_IEEE802_15_4_NONASK_PHY 215 + +/* + * David Gibson requested this for + * captures from the Linux kernel /dev/input/eventN devices. This + * is used to communicate keystrokes and mouse movements from the + * Linux kernel to display systems, such as Xorg. + */ +#define DLT_LINUX_EVDEV 216 + +/* + * GSM Um and Abis interfaces, preceded by a "gsmtap" header. + * + * Requested by Harald Welte . + */ +#define DLT_GSMTAP_UM 217 +#define DLT_GSMTAP_ABIS 218 + +/* + * MPLS, with an MPLS label as the link-layer header. + * Requested by Michele Marchetto on behalf + * of OpenBSD. + */ +#define DLT_MPLS 219 + +/* + * USB packets, beginning with a Linux USB header, with the USB header + * padded to 64 bytes; required for memory-mapped access. + */ +#define DLT_USB_LINUX_MMAPPED 220 + +/* + * DECT packets, with a pseudo-header; requested by + * Matthias Wenzel . + */ +#define DLT_DECT 221 + +/* + * From: "Lidwa, Eric (GSFC-582.0)[SGT INC]" + * Date: Mon, 11 May 2009 11:18:30 -0500 + * + * DLT_AOS. We need it for AOS Space Data Link Protocol. + * I have already written dissectors for but need an OK from + * legal before I can submit a patch. + * + */ +#define DLT_AOS 222 + +/* + * Wireless HART (Highway Addressable Remote Transducer) + * From the HART Communication Foundation + * IES/PAS 62591 + * + * Requested by Sam Roberts . + */ +#define DLT_WIHART 223 + +/* + * Fibre Channel FC-2 frames, beginning with a Frame_Header. + * Requested by Kahou Lei . + */ +#define DLT_FC_2 224 + +/* + * Fibre Channel FC-2 frames, beginning with an encoding of the + * SOF, and ending with an encoding of the EOF. + * + * The encodings represent the frame delimiters as 4-byte sequences + * representing the corresponding ordered sets, with K28.5 + * represented as 0xBC, and the D symbols as the corresponding + * byte values; for example, SOFi2, which is K28.5 - D21.5 - D1.2 - D21.2, + * is represented as 0xBC 0xB5 0x55 0x55. + * + * Requested by Kahou Lei . + */ +#define DLT_FC_2_WITH_FRAME_DELIMS 225 + +/* + * Solaris ipnet pseudo-header; requested by Darren Reed . + * + * The pseudo-header starts with a one-byte version number; for version 2, + * the pseudo-header is: + * + * struct dl_ipnetinfo { + * u_int8_t dli_version; + * u_int8_t dli_family; + * u_int16_t dli_htype; + * u_int32_t dli_pktlen; + * u_int32_t dli_ifindex; + * u_int32_t dli_grifindex; + * u_int32_t dli_zsrc; + * u_int32_t dli_zdst; + * }; + * + * dli_version is 2 for the current version of the pseudo-header. + * + * dli_family is a Solaris address family value, so it's 2 for IPv4 + * and 26 for IPv6. + * + * dli_htype is a "hook type" - 0 for incoming packets, 1 for outgoing + * packets, and 2 for packets arriving from another zone on the same + * machine. + * + * dli_pktlen is the length of the packet data following the pseudo-header + * (so the captured length minus dli_pktlen is the length of the + * pseudo-header, assuming the entire pseudo-header was captured). + * + * dli_ifindex is the interface index of the interface on which the + * packet arrived. + * + * dli_grifindex is the group interface index number (for IPMP interfaces). + * + * dli_zsrc is the zone identifier for the source of the packet. + * + * dli_zdst is the zone identifier for the destination of the packet. + * + * A zone number of 0 is the global zone; a zone number of 0xffffffff + * means that the packet arrived from another host on the network, not + * from another zone on the same machine. + * + * An IPv4 or IPv6 datagram follows the pseudo-header; dli_family indicates + * which of those it is. + */ +#define DLT_IPNET 226 + +/* + * CAN (Controller Area Network) frames, with a pseudo-header as supplied + * by Linux SocketCAN. See Documentation/networking/can.txt in the Linux + * source. + * + * Requested by Felix Obenhuber . + */ +#define DLT_CAN_SOCKETCAN 227 + +/* + * Raw IPv4/IPv6; different from DLT_RAW in that the DLT_ value specifies + * whether it's v4 or v6. Requested by Darren Reed . + */ +#define DLT_IPV4 228 +#define DLT_IPV6 229 + +/* + * IEEE 802.15.4, exactly as it appears in the spec (no padding, no + * nothing), and with no FCS at the end of the frame; requested by + * Jon Smirl . + */ +#define DLT_IEEE802_15_4_NOFCS 230 + +/* + * Raw D-Bus: + * + * http://www.freedesktop.org/wiki/Software/dbus + * + * messages: + * + * http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages + * + * starting with the endianness flag, followed by the message type, etc., + * but without the authentication handshake before the message sequence: + * + * http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol + * + * Requested by Martin Vidner . + */ +#define DLT_DBUS 231 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . + */ +#define DLT_JUNIPER_VS 232 +#define DLT_JUNIPER_SRX_E2E 233 +#define DLT_JUNIPER_FIBRECHANNEL 234 + +/* + * DVB-CI (DVB Common Interface for communication between a PC Card + * module and a DVB receiver). See + * + * http://www.kaiser.cx/pcap-dvbci.html + * + * for the specification. + * + * Requested by Martin Kaiser . + */ +#define DLT_DVB_CI 235 + +/* + * Variant of 3GPP TS 27.010 multiplexing protocol (similar to, but + * *not* the same as, 27.010). Requested by Hans-Christoph Schemmel + * . + */ +#define DLT_MUX27010 236 + +/* + * STANAG 5066 D_PDUs. Requested by M. Baris Demiray + * . + */ +#define DLT_STANAG_5066_D_PDU 237 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . + */ +#define DLT_JUNIPER_ATM_CEMIC 238 + +/* + * NetFilter LOG messages + * (payload of netlink NFNL_SUBSYS_ULOG/NFULNL_MSG_PACKET packets) + * + * Requested by Jakub Zawadzki + */ +#define DLT_NFLOG 239 + +/* + * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type + * for Ethernet packets with a 4-byte pseudo-header and always + * with the payload including the FCS, as supplied by their + * netANALYZER hardware and software. + * + * Requested by Holger P. Frommer + */ +#define DLT_NETANALYZER 240 + +/* + * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type + * for Ethernet packets with a 4-byte pseudo-header and FCS and + * with the Ethernet header preceded by 7 bytes of preamble and + * 1 byte of SFD, as supplied by their netANALYZER hardware and + * software. + * + * Requested by Holger P. Frommer + */ +#define DLT_NETANALYZER_TRANSPARENT 241 + +/* + * IP-over-Infiniband, as specified by RFC 4391. + * + * Requested by Petr Sumbera . + */ +#define DLT_IPOIB 242 + +/* + * MPEG-2 transport stream (ISO 13818-1/ITU-T H.222.0). + * + * Requested by Guy Martin . + */ +#define DLT_MPEG_2_TS 243 + +/* + * ng4T GmbH's UMTS Iub/Iur-over-ATM and Iub/Iur-over-IP format as + * used by their ng40 protocol tester. + * + * Requested by Jens Grimmer . + */ +#define DLT_NG40 244 + +/* + * Pseudo-header giving adapter number and flags, followed by an NFC + * (Near-Field Communications) Logical Link Control Protocol (LLCP) PDU, + * as specified by NFC Forum Logical Link Control Protocol Technical + * Specification LLCP 1.1. + * + * Requested by Mike Wakerly . + */ +#define DLT_NFC_LLCP 245 + +/* + * 245 is used as LINKTYPE_PFSYNC; do not use it for any other purpose. + * + * DLT_PFSYNC has different values on different platforms, and all of + * them collide with something used elsewhere. On platforms that + * don't already define it, define it as 245. + */ +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__) && !defined(__APPLE__) +#define DLT_PFSYNC 246 +#endif + + +/* + * Raw InfiniBand packets, starting with the Local Routing Header. + * + * Requested by Oren Kladnitsky . + */ +#define DLT_INFINIBAND 247 + +/* + * SCTP, with no lower-level protocols (i.e., no IPv4 or IPv6). + * + * Requested by Michael Tuexen . + */ +#define DLT_SCTP 248 + +/* + * USB packets, beginning with a USBPcap header. + * + * Requested by Tomasz Mon + */ +#define DLT_USBPCAP 249 + +/* + * Schweitzer Engineering Laboratories "RTAC" product serial-line + * packets. + * + * Requested by Chris Bontje . + */ +#define DLT_RTAC_SERIAL 250 + +/* + * Bluetooth Low Energy air interface link-layer packets. + * + * Requested by Mike Kershaw . + */ +#define DLT_BLUETOOTH_LE_LL 251 + +/* + * DLT type for upper-protocol layer PDU saves from wireshark. + * + * the actual contents are determined by two TAGs stored with each + * packet: + * EXP_PDU_TAG_LINKTYPE the link type (LINKTYPE_ value) of the + * original packet. + * + * EXP_PDU_TAG_PROTO_NAME the name of the wireshark dissector + * that can make sense of the data stored. + */ +#define DLT_WIRESHARK_UPPER_PDU 252 + +/* + * DLT type for the netlink protocol (nlmon devices). + */ +#define DLT_NETLINK 253 + +/* + * Bluetooth Linux Monitor headers for the BlueZ stack. + */ +#define DLT_BLUETOOTH_LINUX_MONITOR 254 + +/* + * Bluetooth Basic Rate/Enhanced Data Rate baseband packets, as + * captured by Ubertooth. + */ +#define DLT_BLUETOOTH_BREDR_BB 255 + +/* + * Bluetooth Low Energy link layer packets, as captured by Ubertooth. + */ +#define DLT_BLUETOOTH_LE_LL_WITH_PHDR 256 + +/* + * PROFIBUS data link layer. + */ +#define DLT_PROFIBUS_DL 257 + +/* + * Apple's DLT_PKTAP headers. + * + * Sadly, the folks at Apple either had no clue that the DLT_USERn values + * are for internal use within an organization and partners only, and + * didn't know that the right way to get a link-layer header type is to + * ask tcpdump.org for one, or knew and didn't care, so they just + * used DLT_USER2, which causes problems for everything except for + * their version of tcpdump. + * + * So I'll just give them one; hopefully this will show up in a + * libpcap release in time for them to get this into 10.10 Big Sur + * or whatever Mavericks' successor is called. LINKTYPE_PKTAP + * will be 258 *even on OS X*; that is *intentional*, so that + * PKTAP files look the same on *all* OSes (different OSes can have + * different numerical values for a given DLT_, but *MUST NOT* have + * different values for what goes in a file, as files can be moved + * between OSes!). + * + * When capturing, on a system with a Darwin-based OS, on a device + * that returns 149 (DLT_USER2 and Apple's DLT_PKTAP) with this + * version of libpcap, the DLT_ value for the pcap_t will be DLT_PKTAP, + * and that will continue to be DLT_USER2 on Darwin-based OSes. That way, + * binary compatibility with Mavericks is preserved for programs using + * this version of libpcap. This does mean that if you were using + * DLT_USER2 for some capture device on OS X, you can't do so with + * this version of libpcap, just as you can't with Apple's libpcap - + * on OS X, they define DLT_PKTAP to be DLT_USER2, so programs won't + * be able to distinguish between PKTAP and whatever you were using + * DLT_USER2 for. + * + * If the program saves the capture to a file using this version of + * libpcap's pcap_dump code, the LINKTYPE_ value in the file will be + * LINKTYPE_PKTAP, which will be 258, even on Darwin-based OSes. + * That way, the file will *not* be a DLT_USER2 file. That means + * that the latest version of tcpdump, when built with this version + * of libpcap, and sufficiently recent versions of Wireshark will + * be able to read those files and interpret them correctly; however, + * Apple's version of tcpdump in OS X 10.9 won't be able to handle + * them. (Hopefully, Apple will pick up this version of libpcap, + * and the corresponding version of tcpdump, so that tcpdump will + * be able to handle the old LINKTYPE_USER2 captures *and* the new + * LINKTYPE_PKTAP captures.) + */ +#ifdef __APPLE__ +#define DLT_PKTAP DLT_USER2 +#else +#define DLT_PKTAP 258 +#endif + +/* + * Ethernet packets preceded by a header giving the last 6 octets + * of the preamble specified by 802.3-2012 Clause 65, section + * 65.1.3.2 "Transmit". + */ +#define DLT_EPON 259 + +/* + * IPMI trace packets, as specified by Table 3-20 "Trace Data Block Format" + * in the PICMG HPM.2 specification. + */ +#define DLT_IPMI_HPM_2 260 + +/* + * per Joshua Wright , formats for Zwave captures. + */ +#define DLT_ZWAVE_R1_R2 261 +#define DLT_ZWAVE_R3 262 + +/* + * per Steve Karg , formats for Wattstopper + * Digital Lighting Management room bus serial protocol captures. + */ +#define DLT_WATTSTOPPER_DLM 263 + +#define DLT_MATCHING_MAX 263 /* highest value in the "matching" range */ + +/* + * DLT and savefile link type values are split into a class and + * a member of that class. A class value of 0 indicates a regular + * DLT_/LINKTYPE_ value. + */ +#define DLT_CLASS(x) ((x) & 0x03ff0000) + +/* + * NetBSD-specific generic "raw" link type. The class value indicates + * that this is the generic raw type, and the lower 16 bits are the + * address family we're dealing with. Those values are NetBSD-specific; + * do not assume that they correspond to AF_ values for your operating + * system. + */ +#define DLT_CLASS_NETBSD_RAWAF 0x02240000 +#define DLT_NETBSD_RAWAF(af) (DLT_CLASS_NETBSD_RAWAF | (af)) +#define DLT_NETBSD_RAWAF_AF(x) ((x) & 0x0000ffff) +#define DLT_IS_NETBSD_RAWAF(x) (DLT_CLASS(x) == DLT_CLASS_NETBSD_RAWAF) + +#endif /* !_NET_DLT_H_ */ diff --git a/sys/net/if.h b/sys/net/if.h new file mode 100644 index 000000000..ba28c5f8c --- /dev/null +++ b/sys/net/if.h @@ -0,0 +1,1056 @@ +/* $NetBSD: if.h,v 1.193 2015/10/02 03:08:26 ozaki-r Exp $ */ + +/*- + * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by William Studenmund and Jason R. Thorpe. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * 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. + */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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. + * + * @(#)if.h 8.3 (Berkeley) 2/9/95 + */ + +#ifndef _NET_IF_H_ +#define _NET_IF_H_ + +#if !defined(_KERNEL) && !defined(_STANDALONE) +#include +#endif + +#include + +/* + * Length of interface external name, including terminating '\0'. + * Note: this is the same size as a generic device's external name. + */ +#define IF_NAMESIZE 16 + +#if defined(_NETBSD_SOURCE) + +#include +#include +#include + +#include +#include +#ifdef _KERNEL +#include +#endif + +/* + * Always include ALTQ glue here -- we use the ALTQ interface queue + * structure even when ALTQ is not configured into the kernel so that + * the size of struct ifnet does not changed based on the option. The + * ALTQ queue structure is API-compatible with the legacy ifqueue. + */ +#include + +/* + * Structures defining a network interface, providing a packet + * transport mechanism (ala level 0 of the PUP protocols). + * + * Each interface accepts output datagrams of a specified maximum + * length, and provides higher level routines with input datagrams + * received from its medium. + * + * Output occurs when the routine if_output is called, with four parameters: + * (*ifp->if_output)(ifp, m, dst, rt) + * Here m is the mbuf chain to be sent and dst is the destination address. + * The output routine encapsulates the supplied datagram if necessary, + * and then transmits it on its medium. + * + * On input, each interface unwraps the data received by it, and either + * places it on the input queue of a internetwork datagram routine + * and posts the associated software interrupt, or passes the datagram to a raw + * packet input routine. + * + * Routines exist for locating interfaces by their addresses + * or for locating a interface on a certain network, as well as more general + * routing and gateway routines maintaining information used to locate + * interfaces. These routines live in the files if.c and route.c + */ +#include + +#if defined(_KERNEL_OPT) +#include "opt_compat_netbsd.h" +#include "opt_gateway.h" +#endif + +struct mbuf; +struct proc; +struct rtentry; +struct socket; +struct ether_header; +struct ifaddr; +struct ifnet; +struct rt_addrinfo; + +#define IFNAMSIZ IF_NAMESIZE + +/* + * Structure describing a `cloning' interface. + */ +struct if_clone { + LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */ + const char *ifc_name; /* name of device, e.g. `gif' */ + size_t ifc_namelen; /* length of name */ + + int (*ifc_create)(struct if_clone *, int); + int (*ifc_destroy)(struct ifnet *); +}; + +#define IF_CLONE_INITIALIZER(name, create, destroy) \ + { { NULL, NULL }, name, sizeof(name) - 1, create, destroy } + +/* + * Structure used to query names of interface cloners. + */ +struct if_clonereq { + int ifcr_total; /* total cloners (out) */ + int ifcr_count; /* room for this many in user buffer */ + char *ifcr_buffer; /* buffer for cloner names */ +}; + +/* + * Structure defining statistics and other data kept regarding a network + * interface. + */ +struct if_data { + /* generic interface information */ + u_char ifi_type; /* ethernet, tokenring, etc. */ + u_char ifi_addrlen; /* media address length */ + u_char ifi_hdrlen; /* media header length */ + int ifi_link_state; /* current link state */ + uint64_t ifi_mtu; /* maximum transmission unit */ + uint64_t ifi_metric; /* routing metric (external only) */ + uint64_t ifi_baudrate; /* linespeed */ + /* volatile statistics */ + uint64_t ifi_ipackets; /* packets received on interface */ + uint64_t ifi_ierrors; /* input errors on interface */ + uint64_t ifi_opackets; /* packets sent on interface */ + uint64_t ifi_oerrors; /* output errors on interface */ + uint64_t ifi_collisions; /* collisions on csma interfaces */ + uint64_t ifi_ibytes; /* total number of octets received */ + uint64_t ifi_obytes; /* total number of octets sent */ + uint64_t ifi_imcasts; /* packets received via multicast */ + uint64_t ifi_omcasts; /* packets sent via multicast */ + uint64_t ifi_iqdrops; /* dropped on input, this interface */ + uint64_t ifi_noproto; /* destined for unsupported protocol */ + struct timespec ifi_lastchange;/* last operational state change */ +}; + +/* + * Values for if_link_state. + */ +#define LINK_STATE_UNKNOWN 0 /* link invalid/unknown */ +#define LINK_STATE_DOWN 1 /* link is down */ +#define LINK_STATE_UP 2 /* link is up */ + +/* + * Structure defining a queue for a network interface. + */ +struct ifqueue { + struct mbuf *ifq_head; + struct mbuf *ifq_tail; + int ifq_len; + int ifq_maxlen; + int ifq_drops; + kmutex_t *ifq_lock; +}; + +struct ifnet_lock; + +#ifdef _KERNEL +#include +#include +#include +#ifdef GATEWAY +#include +#else +#include +#endif + +struct ifnet_lock { + kmutex_t il_lock; /* Protects the critical section. */ + uint64_t il_nexit; /* Counts threads across all CPUs who + * have exited the critical section. + * Access to il_nexit is synchronized + * by il_lock. + */ + percpu_t *il_nenter; /* Counts threads on each CPU who have + * entered or who wait to enter the + * critical section protected by il_lock. + * Synchronization is not required. + */ + kcondvar_t il_emptied; /* The ifnet_lock user must arrange for + * the last threads in the critical + * section to signal this condition variable + * before they leave. + */ +}; +#endif /* _KERNEL */ + +/* + * Structure defining a queue for a network interface. + * + * (Would like to call this struct ``if'', but C isn't PL/1.) + */ +TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */ + +struct bridge_softc; +struct bridge_iflist; +struct callout; +struct krwlock; + +typedef struct ifnet { + void *if_softc; /* lower-level data for this if */ + TAILQ_ENTRY(ifnet) if_list; /* all struct ifnets are chained */ + TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */ + char if_xname[IFNAMSIZ]; /* external name (name + unit) */ + int if_pcount; /* number of promiscuous listeners */ + struct bpf_if *if_bpf; /* packet filter structure */ + u_short if_index; /* numeric abbreviation for this if */ + short if_timer; /* time 'til if_slowtimo called */ + short if_flags; /* up/down, broadcast, etc. */ + short if__pad1; /* be nice to m68k ports */ + struct if_data if_data; /* statistics and other data about if */ + /* + * Procedure handles. If you add more of these, don't forget the + * corresponding NULL stub in if.c. + */ + int (*if_output) /* output routine (enqueue) */ + (struct ifnet *, struct mbuf *, const struct sockaddr *, + struct rtentry *); + void (*if_input) /* input routine (from h/w driver) */ + (struct ifnet *, struct mbuf *); + void (*if_start) /* initiate output routine */ + (struct ifnet *); + int (*if_ioctl) /* ioctl routine */ + (struct ifnet *, u_long, void *); + int (*if_init) /* init routine */ + (struct ifnet *); + void (*if_stop) /* stop routine */ + (struct ifnet *, int); + void (*if_slowtimo) /* timer routine */ + (struct ifnet *); +#define if_watchdog if_slowtimo + void (*if_drain) /* routine to release resources */ + (struct ifnet *); + struct ifaltq if_snd; /* output queue (includes altq) */ + struct ifaddr *if_dl; /* identity of this interface. */ + const struct sockaddr_dl *if_sadl; /* pointer to sockaddr_dl + * of if_dl + */ + /* if_hwdl: h/w identity + * + * May be NULL. If not NULL, it is the address assigned + * to the interface by the manufacturer, so it very likely + * to be unique. It MUST NOT be deleted. It is highly + * suitable for deriving the EUI64 for the interface. + */ + struct ifaddr *if_hwdl; + const uint8_t *if_broadcastaddr;/* linklevel broadcast bytestring */ + struct bridge_softc *if_bridge; /* bridge glue */ + struct bridge_iflist *if_bridgeif; /* shortcut to interface list entry */ + int if_dlt; /* data link type () */ + pfil_head_t * if_pfil; /* filtering point */ + uint64_t if_capabilities; /* interface capabilities */ + uint64_t if_capenable; /* capabilities enabled */ + union { + void * carp_s; /* carp structure (used by !carp ifs) */ + struct ifnet *carp_d;/* ptr to carpdev (used by carp ifs) */ + } if_carp_ptr; +#define if_carp if_carp_ptr.carp_s +#define if_carpdev if_carp_ptr.carp_d + /* + * These are pre-computed based on an interfaces enabled + * capabilities, for speed elsewhere. + */ + int if_csum_flags_tx; /* M_CSUM_* flags for Tx */ + int if_csum_flags_rx; /* M_CSUM_* flags for Rx */ + + void *if_afdata[AF_MAX]; + struct mowner *if_mowner; /* who owns mbufs for this interface */ + + void *if_agrprivate; /* used only when #if NAGR > 0 */ + + /* + * pf specific data, used only when #if NPF > 0. + */ + void *if_pf_kif; /* pf interface abstraction */ + void *if_pf_groups; /* pf interface groups */ + /* + * During an ifnet's lifetime, it has only one if_index, but + * and if_index is not sufficient to identify an ifnet + * because during the lifetime of the system, many ifnets may occupy a + * given if_index. Let us tell different ifnets at the same + * if_index apart by their if_index_gen, a unique number that each ifnet + * is assigned when it if_attach()s. Now, the kernel can use the + * pair (if_index, if_index_gen) as a weak reference to an ifnet. + */ + uint64_t if_index_gen; /* generation number for the ifnet + * at if_index: if two ifnets' index + * and generation number are both the + * same, they are the same ifnet. + */ + struct sysctllog *if_sysctl_log; + int (*if_initaddr)(struct ifnet *, struct ifaddr *, bool); + int (*if_mcastop)(struct ifnet *, const unsigned long, + const struct sockaddr *); + int (*if_setflags)(struct ifnet *, const short); + struct ifnet_lock *if_ioctl_lock; +#ifdef _KERNEL /* XXX kvm(3) */ + struct callout *if_slowtimo_ch; +#endif +#ifdef GATEWAY + struct kmutex *if_afdata_lock; +#else + struct krwlock *if_afdata_lock; +#endif +} ifnet_t; + +#define if_mtu if_data.ifi_mtu +#define if_type if_data.ifi_type +#define if_addrlen if_data.ifi_addrlen +#define if_hdrlen if_data.ifi_hdrlen +#define if_metric if_data.ifi_metric +#define if_link_state if_data.ifi_link_state +#define if_baudrate if_data.ifi_baudrate +#define if_ipackets if_data.ifi_ipackets +#define if_ierrors if_data.ifi_ierrors +#define if_opackets if_data.ifi_opackets +#define if_oerrors if_data.ifi_oerrors +#define if_collisions if_data.ifi_collisions +#define if_ibytes if_data.ifi_ibytes +#define if_obytes if_data.ifi_obytes +#define if_imcasts if_data.ifi_imcasts +#define if_omcasts if_data.ifi_omcasts +#define if_iqdrops if_data.ifi_iqdrops +#define if_noproto if_data.ifi_noproto +#define if_lastchange if_data.ifi_lastchange + +#define IFF_UP 0x0001 /* interface is up */ +#define IFF_BROADCAST 0x0002 /* broadcast address valid */ +#define IFF_DEBUG 0x0004 /* turn on debugging */ +#define IFF_LOOPBACK 0x0008 /* is a loopback net */ +#define IFF_POINTOPOINT 0x0010 /* interface is point-to-point link */ +#define IFF_NOTRAILERS 0x0020 /* avoid use of trailers */ +#define IFF_RUNNING 0x0040 /* resources allocated */ +#define IFF_NOARP 0x0080 /* no address resolution protocol */ +#define IFF_PROMISC 0x0100 /* receive all packets */ +#define IFF_ALLMULTI 0x0200 /* receive all multicast packets */ +#define IFF_OACTIVE 0x0400 /* transmission in progress */ +#define IFF_SIMPLEX 0x0800 /* can't hear own transmissions */ +#define IFF_LINK0 0x1000 /* per link layer defined bit */ +#define IFF_LINK1 0x2000 /* per link layer defined bit */ +#define IFF_LINK2 0x4000 /* per link layer defined bit */ +#define IFF_MULTICAST 0x8000 /* supports multicast */ + +#define IFFBITS \ + "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS" \ + "\7RUNNING\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX" \ + "\15LINK0\16LINK1\17LINK2\20MULTICAST" + +/* flags set internally only: */ +#define IFF_CANTCHANGE \ + (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\ + IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_PROMISC) + +/* + * Some convenience macros used for setting ifi_baudrate. + */ +#define IF_Kbps(x) ((x) * 1000ULL) /* kilobits/sec. */ +#define IF_Mbps(x) (IF_Kbps((x) * 1000ULL)) /* megabits/sec. */ +#define IF_Gbps(x) (IF_Mbps((x) * 1000ULL)) /* gigabits/sec. */ + +/* Capabilities that interfaces can advertise. */ + /* 0x01 .. 0x40 were previously used */ +#define IFCAP_TSOv4 0x00080 /* can do TCPv4 segmentation offload */ +#define IFCAP_CSUM_IPv4_Rx 0x00100 /* can do IPv4 header checksums (Rx) */ +#define IFCAP_CSUM_IPv4_Tx 0x00200 /* can do IPv4 header checksums (Tx) */ +#define IFCAP_CSUM_TCPv4_Rx 0x00400 /* can do IPv4/TCP checksums (Rx) */ +#define IFCAP_CSUM_TCPv4_Tx 0x00800 /* can do IPv4/TCP checksums (Tx) */ +#define IFCAP_CSUM_UDPv4_Rx 0x01000 /* can do IPv4/UDP checksums (Rx) */ +#define IFCAP_CSUM_UDPv4_Tx 0x02000 /* can do IPv4/UDP checksums (Tx) */ +#define IFCAP_CSUM_TCPv6_Rx 0x04000 /* can do IPv6/TCP checksums (Rx) */ +#define IFCAP_CSUM_TCPv6_Tx 0x08000 /* can do IPv6/TCP checksums (Tx) */ +#define IFCAP_CSUM_UDPv6_Rx 0x10000 /* can do IPv6/UDP checksums (Rx) */ +#define IFCAP_CSUM_UDPv6_Tx 0x20000 /* can do IPv6/UDP checksums (Tx) */ +#define IFCAP_TSOv6 0x40000 /* can do TCPv6 segmentation offload */ +#define IFCAP_LRO 0x80000 /* can do Large Receive Offload */ +#define IFCAP_MASK 0xfff80 /* currently valid capabilities */ + +#define IFCAPBITS \ + "\020" \ + "\10TSO4" \ + "\11IP4CSUM_Rx" \ + "\12IP4CSUM_Tx" \ + "\13TCP4CSUM_Rx" \ + "\14TCP4CSUM_Tx" \ + "\15UDP4CSUM_Rx" \ + "\16UDP4CSUM_Tx" \ + "\17TCP6CSUM_Rx" \ + "\20TCP6CSUM_Tx" \ + "\21UDP6CSUM_Rx" \ + "\22UDP6CSUM_Tx" \ + "\23TSO6" \ + "\24LRO" \ + +#ifdef GATEWAY +#define IF_AFDATA_LOCK_INIT(ifp) \ + do { \ + (ifp)->if_afdata_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET); \ + } while (0) + +#define IF_AFDATA_WLOCK(ifp) mutex_enter((ifp)->if_afdata_lock) +#define IF_AFDATA_RLOCK(ifp) mutex_enter((ifp)->if_afdata_lock) +#define IF_AFDATA_WUNLOCK(ifp) mutex_exit((ifp)->if_afdata_lock) +#define IF_AFDATA_RUNLOCK(ifp) mutex_exit((ifp)->if_afdata_lock) +#define IF_AFDATA_LOCK(ifp) IF_AFDATA_WLOCK(ifp) +#define IF_AFDATA_UNLOCK(ifp) IF_AFDATA_WUNLOCK(ifp) +#define IF_AFDATA_TRYLOCK(ifp) mutex_tryenter((ifp)->if_afdata_lock) +#define IF_AFDATA_DESTROY(ifp) mutex_destroy((ifp)->if_afdata_lock) + +#define IF_AFDATA_LOCK_ASSERT(ifp) \ + KASSERT(mutex_owned((ifp)->if_afdata_lock)) +#define IF_AFDATA_RLOCK_ASSERT(ifp) \ + KASSERT(mutex_owned((ifp)->if_afdata_lock)) +#define IF_AFDATA_WLOCK_ASSERT(ifp) \ + KASSERT(mutex_owned((ifp)->if_afdata_lock)) +#define IF_AFDATA_UNLOCK_ASSERT(ifp) \ + KASSERT(!mutex_owned((ifp)->if_afdata_lock)) + +#else /* GATEWAY */ +#define IF_AFDATA_LOCK_INIT(ifp) \ + do {(ifp)->if_afdata_lock = rw_obj_alloc();} while (0) + +#define IF_AFDATA_WLOCK(ifp) rw_enter((ifp)->if_afdata_lock, RW_WRITER) +#define IF_AFDATA_RLOCK(ifp) rw_enter((ifp)->if_afdata_lock, RW_READER) +#define IF_AFDATA_WUNLOCK(ifp) rw_exit((ifp)->if_afdata_lock) +#define IF_AFDATA_RUNLOCK(ifp) rw_exit((ifp)->if_afdata_lock) +#define IF_AFDATA_LOCK(ifp) IF_AFDATA_WLOCK(ifp) +#define IF_AFDATA_UNLOCK(ifp) IF_AFDATA_WUNLOCK(ifp) +#define IF_AFDATA_TRYLOCK(ifp) rw_tryenter((ifp)->if_afdata_lock, RW_WRITER) +#define IF_AFDATA_DESTROY(ifp) rw_destroy((ifp)->if_afdata_lock) + +#define IF_AFDATA_LOCK_ASSERT(ifp) \ + KASSERT(rw_lock_held((ifp)->if_afdata_lock)) +#define IF_AFDATA_RLOCK_ASSERT(ifp) \ + KASSERT(rw_read_held((ifp)->if_afdata_lock)) +#define IF_AFDATA_WLOCK_ASSERT(ifp) \ + KASSERT(rw_write_held((ifp)->if_afdata_lock)) +#define IF_AFDATA_UNLOCK_ASSERT(ifp) \ + KASSERT(!rw_lock_held((ifp)->if_afdata_lock)) +#endif /* GATEWAY */ + +#define IFQ_LOCK(_ifq) if ((_ifq)->ifq_lock) mutex_enter((_ifq)->ifq_lock) +#define IFQ_UNLOCK(_ifq) if ((_ifq)->ifq_lock) mutex_exit((_ifq)->ifq_lock) + +/* + * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) + * input routines have queues of messages stored on ifqueue structures + * (defined above). Entries are added to and deleted from these structures + * by these macros, which should be called with ipl raised to splnet(). + */ +#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) +#define IF_DROP(ifq) ((ifq)->ifq_drops++) +#define IF_ENQUEUE(ifq, m) do { \ + (m)->m_nextpkt = 0; \ + if ((ifq)->ifq_tail == 0) \ + (ifq)->ifq_head = m; \ + else \ + (ifq)->ifq_tail->m_nextpkt = m; \ + (ifq)->ifq_tail = m; \ + (ifq)->ifq_len++; \ +} while (/*CONSTCOND*/0) +#define IF_PREPEND(ifq, m) do { \ + (m)->m_nextpkt = (ifq)->ifq_head; \ + if ((ifq)->ifq_tail == 0) \ + (ifq)->ifq_tail = (m); \ + (ifq)->ifq_head = (m); \ + (ifq)->ifq_len++; \ +} while (/*CONSTCOND*/0) +#define IF_DEQUEUE(ifq, m) do { \ + (m) = (ifq)->ifq_head; \ + if (m) { \ + if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \ + (ifq)->ifq_tail = 0; \ + (m)->m_nextpkt = 0; \ + (ifq)->ifq_len--; \ + } \ +} while (/*CONSTCOND*/0) +#define IF_POLL(ifq, m) ((m) = (ifq)->ifq_head) +#define IF_PURGE(ifq) \ +do { \ + struct mbuf *__m0; \ + \ + for (;;) { \ + IF_DEQUEUE((ifq), __m0); \ + if (__m0 == NULL) \ + break; \ + else \ + m_freem(__m0); \ + } \ +} while (/*CONSTCOND*/ 0) +#define IF_IS_EMPTY(ifq) ((ifq)->ifq_len == 0) + +#ifndef IFQ_MAXLEN +#define IFQ_MAXLEN 256 +#endif +#define IFNET_SLOWHZ 1 /* granularity is 1 second */ + +/* + * Structure defining statistics and other data kept regarding an address + * on a network interface. + */ +struct ifaddr_data { + int64_t ifad_inbytes; + int64_t ifad_outbytes; +}; + +/* + * The ifaddr structure contains information about one address + * of an interface. They are maintained by the different address families, + * are allocated and attached when an address is set, and are linked + * together so all addresses for an interface can be located. + */ +struct ifaddr { + struct sockaddr *ifa_addr; /* address of interface */ + struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ +#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ + struct sockaddr *ifa_netmask; /* used to determine subnet */ + struct ifnet *ifa_ifp; /* back-pointer to interface */ + TAILQ_ENTRY(ifaddr) ifa_list; /* list of addresses for interface */ + struct ifaddr_data ifa_data; /* statistics on the address */ + void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */ + (int, struct rtentry *, const struct rt_addrinfo *); + u_int ifa_flags; /* mostly rt_flags for cloning */ + int ifa_refcnt; /* count of references */ + int ifa_metric; /* cost of going out this interface */ + struct ifaddr *(*ifa_getifa)(struct ifaddr *, + const struct sockaddr *); + uint32_t *ifa_seqno; + int16_t ifa_preference; /* preference level for this address */ +}; +#define IFA_ROUTE RTF_UP /* (0x01) route installed */ + +/* + * Message format for use in obtaining information about interfaces from + * sysctl and the routing socket. We need to force 64-bit alignment if we + * aren't using compatiblity definitons. + */ +#if !defined(_KERNEL) || !defined(COMPAT_RTSOCK) +#define __align64 __aligned(sizeof(uint64_t)) +#else +#define __align64 +#endif +struct if_msghdr { + u_short ifm_msglen __align64; + /* to skip over non-understood messages */ + u_char ifm_version; /* future binary compatibility */ + u_char ifm_type; /* message type */ + int ifm_addrs; /* like rtm_addrs */ + int ifm_flags; /* value of if_flags */ + u_short ifm_index; /* index for associated ifp */ + struct if_data ifm_data __align64; + /* statistics and other data about if */ +}; + +/* + * Message format for use in obtaining information about interface addresses + * from sysctl and the routing socket. + */ +struct ifa_msghdr { + u_short ifam_msglen __align64; + /* to skip over non-understood messages */ + u_char ifam_version; /* future binary compatibility */ + u_char ifam_type; /* message type */ + int ifam_addrs; /* like rtm_addrs */ + int ifam_flags; /* value of ifa_flags */ + int ifam_metric; /* value of ifa_metric */ + u_short ifam_index; /* index for associated ifp */ +}; + +/* + * Message format announcing the arrival or departure of a network interface. + */ +struct if_announcemsghdr { + u_short ifan_msglen __align64; + /* to skip over non-understood messages */ + u_char ifan_version; /* future binary compatibility */ + u_char ifan_type; /* message type */ + u_short ifan_index; /* index for associated ifp */ + char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + u_short ifan_what; /* what type of announcement */ +}; + +#define IFAN_ARRIVAL 0 /* interface arrival */ +#define IFAN_DEPARTURE 1 /* interface departure */ + +#undef __align64 + +/* + * Interface request structure used for socket + * ioctl's. All interface ioctl's must have parameter + * definitions which begin with ifr_name. The + * remainder may be interface specific. + */ +struct ifreq { + char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + union { + struct sockaddr ifru_addr; + struct sockaddr ifru_dstaddr; + struct sockaddr ifru_broadaddr; + struct sockaddr_storage ifru_space; + short ifru_flags; + int ifru_addrflags; + int ifru_metric; + int ifru_mtu; + int ifru_dlt; + u_int ifru_value; + void * ifru_data; + struct { + uint32_t b_buflen; + void *b_buf; + } ifru_b; + } ifr_ifru; +#define ifr_addr ifr_ifru.ifru_addr /* address */ +#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ +#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ +#define ifr_space ifr_ifru.ifru_space /* sockaddr_storage */ +#define ifr_flags ifr_ifru.ifru_flags /* flags */ +#define ifr_addrflags ifr_ifru.ifru_addrflags /* addr flags */ +#define ifr_metric ifr_ifru.ifru_metric /* metric */ +#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */ +#define ifr_dlt ifr_ifru.ifru_dlt /* data link type (DLT_*) */ +#define ifr_value ifr_ifru.ifru_value /* generic value */ +#define ifr_media ifr_ifru.ifru_metric /* media options (overload) */ +#define ifr_data ifr_ifru.ifru_data /* for use by interface + * XXX deprecated + */ +#define ifr_buf ifr_ifru.ifru_b.b_buf /* new interface ioctls */ +#define ifr_buflen ifr_ifru.ifru_b.b_buflen +#define ifr_index ifr_ifru.ifru_value /* interface index, BSD */ +#define ifr_ifindex ifr_index /* interface index, linux */ +}; + +#ifdef _KERNEL +#define ifreq_setdstaddr ifreq_setaddr +#define ifreq_setbroadaddr ifreq_setaddr +#define ifreq_getdstaddr ifreq_getaddr +#define ifreq_getbroadaddr ifreq_getaddr + +static inline const struct sockaddr * +/*ARGSUSED*/ +ifreq_getaddr(u_long cmd, const struct ifreq *ifr) +{ + return &ifr->ifr_addr; +} +#endif /* _KERNEL */ + +struct ifcapreq { + char ifcr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + uint64_t ifcr_capabilities; /* supported capabiliites */ + uint64_t ifcr_capenable; /* capabilities enabled */ +}; + +struct ifaliasreq { + char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + struct sockaddr ifra_addr; + struct sockaddr ifra_dstaddr; +#define ifra_broadaddr ifra_dstaddr + struct sockaddr ifra_mask; +}; + +struct ifdatareq { + char ifdr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + struct if_data ifdr_data; +}; + +struct ifmediareq { + char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + int ifm_current; /* current media options */ + int ifm_mask; /* don't care mask */ + int ifm_status; /* media status */ + int ifm_active; /* active options */ + int ifm_count; /* # entries in ifm_ulist + array */ + int *ifm_ulist; /* media words */ +}; + + +struct ifdrv { + char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + unsigned long ifd_cmd; + size_t ifd_len; + void *ifd_data; +}; +#define IFLINKSTR_QUERYLEN 0x01 +#define IFLINKSTR_UNSET 0x02 + +/* + * Structure used in SIOCGIFCONF request. + * Used to retrieve interface configuration + * for machine (useful for programs which + * must know all networks accessible). + */ +struct ifconf { + int ifc_len; /* size of associated buffer */ + union { + void * ifcu_buf; + struct ifreq *ifcu_req; + } ifc_ifcu; +#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ +#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ +}; + +/* + * Structure for SIOC[AGD]LIFADDR + */ +struct if_laddrreq { + char iflr_name[IFNAMSIZ]; + unsigned int flags; +#define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */ +#define IFLR_ACTIVE 0x4000 /* in/out: link-layer address activation */ +#define IFLR_FACTORY 0x2000 /* in/out: factory link-layer address */ + unsigned int prefixlen; /* in/out */ + struct sockaddr_storage addr; /* in/out */ + struct sockaddr_storage dstaddr; /* out */ +}; + +/* + * Structure for SIOC[SG]IFADDRPREF + */ +struct if_addrprefreq { + char ifap_name[IFNAMSIZ]; + int16_t ifap_preference; /* in/out */ + struct sockaddr_storage ifap_addr; /* in/out */ +}; + +#include + +#endif /* _NETBSD_SOURCE */ + +#ifdef _KERNEL +#ifdef ALTQ +#define ALTQ_DECL(x) x +#define ALTQ_COMMA , + +#define IFQ_ENQUEUE(ifq, m, pattr, err) \ +do { \ + IFQ_LOCK((ifq)); \ + if (ALTQ_IS_ENABLED((ifq))) \ + ALTQ_ENQUEUE((ifq), (m), (pattr), (err)); \ + else { \ + if (IF_QFULL((ifq))) { \ + m_freem((m)); \ + (err) = ENOBUFS; \ + } else { \ + IF_ENQUEUE((ifq), (m)); \ + (err) = 0; \ + } \ + } \ + if ((err)) \ + (ifq)->ifq_drops++; \ + IFQ_UNLOCK((ifq)); \ +} while (/*CONSTCOND*/ 0) + +#define IFQ_DEQUEUE(ifq, m) \ +do { \ + IFQ_LOCK((ifq)); \ + if (TBR_IS_ENABLED((ifq))) \ + (m) = tbr_dequeue((ifq), ALTDQ_REMOVE); \ + else if (ALTQ_IS_ENABLED((ifq))) \ + ALTQ_DEQUEUE((ifq), (m)); \ + else \ + IF_DEQUEUE((ifq), (m)); \ + IFQ_UNLOCK((ifq)); \ +} while (/*CONSTCOND*/ 0) + +#define IFQ_POLL(ifq, m) \ +do { \ + IFQ_LOCK((ifq)); \ + if (TBR_IS_ENABLED((ifq))) \ + (m) = tbr_dequeue((ifq), ALTDQ_POLL); \ + else if (ALTQ_IS_ENABLED((ifq))) \ + ALTQ_POLL((ifq), (m)); \ + else \ + IF_POLL((ifq), (m)); \ + IFQ_UNLOCK((ifq)); \ +} while (/*CONSTCOND*/ 0) + +#define IFQ_PURGE(ifq) \ +do { \ + IFQ_LOCK((ifq)); \ + if (ALTQ_IS_ENABLED((ifq))) \ + ALTQ_PURGE((ifq)); \ + else \ + IF_PURGE((ifq)); \ + IFQ_UNLOCK((ifq)); \ +} while (/*CONSTCOND*/ 0) + +#define IFQ_SET_READY(ifq) \ +do { \ + (ifq)->altq_flags |= ALTQF_READY; \ +} while (/*CONSTCOND*/ 0) + +#define IFQ_CLASSIFY(ifq, m, af, pattr) \ +do { \ + IFQ_LOCK((ifq)); \ + if (ALTQ_IS_ENABLED((ifq))) { \ + if (ALTQ_NEEDS_CLASSIFY((ifq))) \ + (pattr)->pattr_class = (*(ifq)->altq_classify) \ + ((ifq)->altq_clfier, (m), (af)); \ + (pattr)->pattr_af = (af); \ + (pattr)->pattr_hdr = mtod((m), void *); \ + } \ + IFQ_UNLOCK((ifq)); \ +} while (/*CONSTCOND*/ 0) +#else /* ! ALTQ */ +#define ALTQ_DECL(x) /* nothing */ +#define ALTQ_COMMA + +#define IFQ_ENQUEUE(ifq, m, pattr, err) \ +do { \ + IFQ_LOCK((ifq)); \ + if (IF_QFULL((ifq))) { \ + m_freem((m)); \ + (err) = ENOBUFS; \ + } else { \ + IF_ENQUEUE((ifq), (m)); \ + (err) = 0; \ + } \ + if ((err)) \ + (ifq)->ifq_drops++; \ + IFQ_UNLOCK((ifq)); \ +} while (/*CONSTCOND*/ 0) + +#define IFQ_DEQUEUE(ifq, m) \ +do { \ + IFQ_LOCK((ifq)); \ + IF_DEQUEUE((ifq), (m)); \ + IFQ_UNLOCK((ifq)); \ +} while (/*CONSTCOND*/ 0) + +#define IFQ_POLL(ifq, m) \ +do { \ + IFQ_LOCK((ifq)); \ + IF_POLL((ifq), (m)); \ + IFQ_UNLOCK((ifq)); \ +} while (/*CONSTCOND*/ 0) + +#define IFQ_PURGE(ifq) \ +do { \ + IFQ_LOCK((ifq)); \ + IF_PURGE((ifq)); \ + IFQ_UNLOCK((ifq)); \ +} while (/*CONSTCOND*/ 0) + +#define IFQ_SET_READY(ifq) /* nothing */ + +#define IFQ_CLASSIFY(ifq, m, af, pattr) /* nothing */ + +#endif /* ALTQ */ + +#define IFQ_IS_EMPTY(ifq) IF_IS_EMPTY((ifq)) +#define IFQ_INC_LEN(ifq) ((ifq)->ifq_len++) +#define IFQ_DEC_LEN(ifq) (--(ifq)->ifq_len) +#define IFQ_INC_DROPS(ifq) ((ifq)->ifq_drops++) +#define IFQ_SET_MAXLEN(ifq, len) ((ifq)->ifq_maxlen = (len)) + +#include +MALLOC_DECLARE(M_IFADDR); +MALLOC_DECLARE(M_IFMADDR); + +int ifreq_setaddr(u_long, struct ifreq *, const struct sockaddr *); + +struct ifnet *if_alloc(u_char); +void if_free(struct ifnet *); +void if_initname(struct ifnet *, const char *, int); +struct ifaddr *if_dl_create(const struct ifnet *, const struct sockaddr_dl **); +void if_activate_sadl(struct ifnet *, struct ifaddr *, + const struct sockaddr_dl *); +void if_set_sadl(struct ifnet *, const void *, u_char, bool); +void if_alloc_sadl(struct ifnet *); +void if_initialize(struct ifnet *); +void if_register(struct ifnet *); +void if_attach(struct ifnet *); /* Deprecated. Use if_initialize and if_register */ +void if_attachdomain(void); +void if_deactivate(struct ifnet *); +void if_purgeaddrs(struct ifnet *, int, void (*)(struct ifaddr *)); +void if_detach(struct ifnet *); +void if_down(struct ifnet *); +void if_link_state_change(struct ifnet *, int); +void if_up(struct ifnet *); +void ifinit(void); +void ifinit1(void); +int ifaddrpref_ioctl(struct socket *, u_long, void *, struct ifnet *); +extern int (*ifioctl)(struct socket *, u_long, void *, struct lwp *); +int ifioctl_common(struct ifnet *, u_long, void *); +int ifpromisc(struct ifnet *, int); +struct ifnet *ifunit(const char *); +int if_addr_init(ifnet_t *, struct ifaddr *, bool); +int if_do_dad(struct ifnet *); +int if_mcast_op(ifnet_t *, const unsigned long, const struct sockaddr *); +int if_flags_set(struct ifnet *, const short); +int if_clone_list(int, char *, int *); + +void ifa_insert(struct ifnet *, struct ifaddr *); +void ifa_remove(struct ifnet *, struct ifaddr *); + +void ifaref(struct ifaddr *); +void ifafree(struct ifaddr *); + +struct ifaddr *ifa_ifwithaddr(const struct sockaddr *); +struct ifaddr *ifa_ifwithaf(int); +struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *); +struct ifaddr *ifa_ifwithnet(const struct sockaddr *); +struct ifaddr *ifa_ifwithladdr(const struct sockaddr *); +struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *, + const struct sockaddr *); +struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *); +void ifafree(struct ifaddr *); +void link_rtrequest(int, struct rtentry *, const struct rt_addrinfo *); +void p2p_rtrequest(int, struct rtentry *, const struct rt_addrinfo *); + +void if_clone_attach(struct if_clone *); +void if_clone_detach(struct if_clone *); + +int ifq_enqueue(struct ifnet *, struct mbuf * ALTQ_COMMA + ALTQ_DECL(struct altq_pktattr *)); +int ifq_enqueue2(struct ifnet *, struct ifqueue *, struct mbuf * ALTQ_COMMA + ALTQ_DECL(struct altq_pktattr *)); + +int loioctl(struct ifnet *, u_long, void *); +void loopattach(int); +int looutput(struct ifnet *, + struct mbuf *, const struct sockaddr *, struct rtentry *); +void lortrequest(int, struct rtentry *, const struct rt_addrinfo *); + +/* + * These are exported because they're an easy way to tell if + * an interface is going away without having to burn a flag. + */ +int if_nulloutput(struct ifnet *, struct mbuf *, + const struct sockaddr *, struct rtentry *); +void if_nullinput(struct ifnet *, struct mbuf *); +void if_nullstart(struct ifnet *); +int if_nullioctl(struct ifnet *, u_long, void *); +int if_nullinit(struct ifnet *); +void if_nullstop(struct ifnet *, int); +void if_nullslowtimo(struct ifnet *); +#define if_nullwatchdog if_nullslowtimo +void if_nulldrain(struct ifnet *); +#else +struct if_nameindex { + unsigned int if_index; /* 1, 2, ... */ + char *if_name; /* null terminated name: "le0", ... */ +}; + +#include +__BEGIN_DECLS +unsigned int if_nametoindex(const char *); +char * if_indextoname(unsigned int, char *); +struct if_nameindex * if_nameindex(void); +void if_freenameindex(struct if_nameindex *); +__END_DECLS +#endif /* _KERNEL */ /* XXX really ALTQ? */ + +#ifdef _KERNEL + +#define IFNET_FIRST() TAILQ_FIRST(&ifnet_list) +#define IFNET_EMPTY() TAILQ_EMPTY(&ifnet_list) +#define IFNET_NEXT(__ifp) TAILQ_NEXT((__ifp), if_list) +#define IFNET_FOREACH(__ifp) TAILQ_FOREACH(__ifp, &ifnet_list, if_list) +#define IFADDR_FIRST(__ifp) TAILQ_FIRST(&(__ifp)->if_addrlist) +#define IFADDR_NEXT(__ifa) TAILQ_NEXT((__ifa), ifa_list) +#define IFADDR_FOREACH(__ifa, __ifp) TAILQ_FOREACH(__ifa, \ + &(__ifp)->if_addrlist, ifa_list) +#define IFADDR_FOREACH_SAFE(__ifa, __ifp, __nifa) \ + TAILQ_FOREACH_SAFE(__ifa, \ + &(__ifp)->if_addrlist, ifa_list, __nifa) +#define IFADDR_EMPTY(__ifp) TAILQ_EMPTY(&(__ifp)->if_addrlist) + +extern struct ifnet_head ifnet_list; +extern struct ifnet *lo0ifp; + +ifnet_t * if_byindex(u_int); + +/* + * ifq sysctl support + */ +int sysctl_ifq(int *name, u_int namelen, void *oldp, + size_t *oldlenp, void *newp, size_t newlen, + struct ifqueue *ifq); +/* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */ +#define IFQCTL_LEN 1 +#define IFQCTL_MAXLEN 2 +#define IFQCTL_PEAK 3 +#define IFQCTL_DROPS 4 +#define IFQCTL_MAXID 5 + +#endif /* _KERNEL */ + +#ifdef _NETBSD_SOURCE +/* + * sysctl for ifq (per-protocol packet input queue variant of ifqueue) + */ +#define CTL_IFQ_NAMES { \ + { 0, 0 }, \ + { "len", CTLTYPE_INT }, \ + { "maxlen", CTLTYPE_INT }, \ + { "peak", CTLTYPE_INT }, \ + { "drops", CTLTYPE_INT }, \ +} +#endif /* _NETBSD_SOURCE */ +#endif /* !_NET_IF_H_ */ diff --git a/sys/net/if_arp.h b/sys/net/if_arp.h new file mode 100644 index 000000000..ddcc62250 --- /dev/null +++ b/sys/net/if_arp.h @@ -0,0 +1,132 @@ +/* $NetBSD: if_arp.h,v 1.30 2015/08/31 08:05:20 ozaki-r Exp $ */ + +/* + * Copyright (c) 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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. + * + * @(#)if_arp.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NET_IF_ARP_H_ +#define _NET_IF_ARP_H_ +/* + * Address Resolution Protocol. + * + * See RFC 826 for protocol description. ARP packets are variable + * in size; the arphdr structure defines the fixed-length portion. + * Protocol type values are the same as those for 10 Mb/s Ethernet. + * It is followed by the variable-sized fields ar_sha, arp_spa, + * arp_tha and arp_tpa in that order, according to the lengths + * specified. Field names used correspond to RFC 826. + */ +struct arphdr { + uint16_t ar_hrd; /* format of hardware address */ +#define ARPHRD_ETHER 1 /* ethernet hardware format */ +#define ARPHRD_IEEE802 6 /* IEEE 802 hardware format */ +#define ARPHRD_ARCNET 7 /* ethernet hardware format */ +#define ARPHRD_FRELAY 15 /* frame relay hardware format */ +#define ARPHRD_STRIP 23 /* Ricochet Starmode Radio hardware format */ +#define ARPHRD_IEEE1394 24 /* IEEE 1394 (FireWire) hardware format */ + uint16_t ar_pro; /* format of protocol address */ + uint8_t ar_hln; /* length of hardware address */ + uint8_t ar_pln; /* length of protocol address */ + uint16_t ar_op; /* one of: */ +#define ARPOP_REQUEST 1 /* request to resolve address */ +#define ARPOP_REPLY 2 /* response to previous request */ +#define ARPOP_REVREQUEST 3 /* request protocol address given hardware */ +#define ARPOP_REVREPLY 4 /* response giving protocol address */ +#define ARPOP_INVREQUEST 8 /* request to identify peer */ +#define ARPOP_INVREPLY 9 /* response identifying peer */ +/* + * The remaining fields are variable in size, + * according to the sizes above. + */ +#ifdef COMMENT_ONLY + uint8_t ar_sha[]; /* sender hardware address */ + uint8_t ar_spa[]; /* sender protocol address */ + uint8_t ar_tha[]; /* target hardware address */ + uint8_t ar_tpa[]; /* target protocol address */ +#endif +#define ar_sha(ap) (((char *)((ap)+1))+0) +#define ar_spa(ap) (((char *)((ap)+1))+(ap)->ar_hln) +#define ar_tha(ap) \ + (ntohs((ap)->ar_hrd) == ARPHRD_IEEE1394 \ + ? NULL : (((char *)((ap)+1))+(ap)->ar_hln+(ap)->ar_pln)) +#define ar_tpa(ap) \ + (ntohs((ap)->ar_hrd) == ARPHRD_IEEE1394 \ + ? (((char *)((ap)+1))+(ap)->ar_hln+(ap)->ar_pln) \ + : (((char *)((ap)+1))+(ap)->ar_hln+(ap)->ar_pln+(ap)->ar_hln)) +} __packed; + + +/* + * ARP ioctl request + */ +struct arpreq { + struct sockaddr arp_pa; /* protocol address */ + struct sockaddr arp_ha; /* hardware address */ + int arp_flags; /* flags */ +}; +/* arp_flags and at_flags field values */ +#define ATF_INUSE 0x01 /* entry in use */ +#define ATF_COM 0x02 /* completed entry (enaddr valid) */ +#define ATF_PERM 0x04 /* permanent entry */ +#define ATF_PUBL 0x08 /* publish entry (respond for other host) */ +#define ATF_USETRAILERS 0x10 /* has requested trailers */ + +/* + * Kernel statistics about arp + */ +#define ARP_STAT_SNDTOTAL 0 /* total packets sent */ +#define ARP_STAT_SNDREPLY 1 /* replies sent */ +#define ARP_STAT_SENDREQUEST 2 /* requests sent */ +#define ARP_STAT_RCVTOTAL 3 /* total packets received */ +#define ARP_STAT_RCVREQUEST 4 /* valid requests received */ +#define ARP_STAT_RCVREPLY 5 /* replies received */ +#define ARP_STAT_RCVMCAST 6 /* multicast/broadcast received */ +#define ARP_STAT_RCVBADPROTO 7 /* unknown protocol type received */ +#define ARP_STAT_RCVBADLEN 8 /* bad (short) length received */ +#define ARP_STAT_RCVZEROTPA 9 /* received w/ null target ip */ +#define ARP_STAT_RCVZEROSPA 10 /* received w/ null source ip */ +#define ARP_STAT_RCVNOINT 11 /* couldn't map to interface */ +#define ARP_STAT_RCVLOCALSHA 12 /* received from local hw address */ +#define ARP_STAT_RCVBCASTSHA 13 /* received w/ broadcast src */ +#define ARP_STAT_RCVLOCALSPA 14 /* received for a local ip [dup!] */ +#define ARP_STAT_RCVOVERPERM 15 /* attempts to overwrite static info */ +#define ARP_STAT_RCVOVERINT 16 /* attempts to overwrite wrong if */ +#define ARP_STAT_RCVOVER 17 /* entries overwritten! */ +#define ARP_STAT_RCVLENCHG 18 /* changes in hw address len */ +#define ARP_STAT_DFRTOTAL 19 /* deferred pending ARP resolution */ +#define ARP_STAT_DFRSENT 20 /* deferred, then sent */ +#define ARP_STAT_DFRDROPPED 21 /* deferred, then dropped */ +#define ARP_STAT_ALLOCFAIL 22 /* failures to allocate llinfo */ + +#define ARP_NSTATS 23 + +void arp_stat_add(int, uint64_t); + +#endif /* !_NET_IF_ARP_H_ */ diff --git a/sys/net/if_dl.h b/sys/net/if_dl.h new file mode 100644 index 000000000..3e18b9b0f --- /dev/null +++ b/sys/net/if_dl.h @@ -0,0 +1,128 @@ +/* $NetBSD: if_dl.h,v 1.26 2014/12/03 01:31:37 christos Exp $ */ + +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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. + * + * @(#)if_dl.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * A Link-Level Sockaddr may specify the interface in one of two + * ways: either by means of a system-provided index number (computed + * anew and possibly differently on every reboot), or by a human-readable + * string such as "il0" (for managerial convenience). + * + * Census taking actions, such as something akin to SIOCGCONF would return + * both the index and the human name. + * + * High volume transactions (such as giving a link-level ``from'' address + * in a recvfrom or recvmsg call) may be likely only to provide the indexed + * form, (which requires fewer copy operations and less space). + * + * The form and interpretation of the link-level address is purely a matter + * of convention between the device driver and its consumers; however, it is + * expected that all drivers for an interface of a given if_type will agree. + */ + +#ifndef _NET_IF_DL_H_ +#define _NET_IF_DL_H_ + +#include + +#ifndef sa_family_t +typedef __sa_family_t sa_family_t; +#define sa_family_t __sa_family_t +#endif +#ifndef socklen_t +typedef __socklen_t socklen_t; +#define socklen_t __socklen_t +#endif + +struct dl_addr { + uint8_t dl_type; /* interface type */ + uint8_t dl_nlen; /* interface name length, no trailing 0 reqd. */ + uint8_t dl_alen; /* link level address length */ + uint8_t dl_slen; /* link layer selector length */ + /* + * minimum work area, can be larger; contains both if name + * and ll address + */ + char dl_data[12]; +}; + +/* + * Structure of a Link-Level sockaddr: + */ +struct sockaddr_dl { + uint8_t sdl_len; /* Total length of sockaddr */ + sa_family_t sdl_family; /* AF_LINK */ + uint16_t sdl_index; /* if != 0, system given index for interface */ + struct dl_addr sdl_addr; +#define sdl_type sdl_addr.dl_type +#define sdl_nlen sdl_addr.dl_nlen +#define sdl_alen sdl_addr.dl_alen +#define sdl_slen sdl_addr.dl_slen +#define sdl_data sdl_addr.dl_data +}; + +#define satosdl(__sa) ((struct sockaddr_dl *)(__sa)) +#define satocsdl(__sa) ((const struct sockaddr_dl *)(__sa)) + +/* We do arithmetic directly with these, so keep them char instead of void */ +#define LLADDR(s) ((char *)((s)->sdl_data + (s)->sdl_nlen)) +#define CLLADDR(s) ((const char *)((s)->sdl_data + (s)->sdl_nlen)) + +#ifdef _KERNEL +uint8_t sockaddr_dl_measure(uint8_t, uint8_t); +struct sockaddr *sockaddr_dl_alloc(uint16_t, uint8_t, + const void *, uint8_t, const void *, uint8_t, int); +struct sockaddr_dl *sockaddr_dl_init(struct sockaddr_dl *, socklen_t, uint16_t, + uint8_t, const void *, uint8_t, const void *, uint8_t); +struct sockaddr_dl *sockaddr_dl_setaddr(struct sockaddr_dl *, socklen_t, + const void *, uint8_t); +#else + +#include + +__BEGIN_DECLS +void link_addr(const char *, struct sockaddr_dl *); +char *link_ntoa(const struct sockaddr_dl *); +__END_DECLS + +#endif /* !_KERNEL */ + +#if defined(_KERNEL) || defined(_TEST) +// 255 xx: + 255 'a' + / + # + 3 digits + NUL +#define LINK_ADDRSTRLEN ((255 * 4) + 5) + +int dl_print(char *, size_t, const struct dl_addr *); +#define DL_PRINT(b, a) (dl_print((b), sizeof(b), (a)), (b)) +int sdl_print(char *, size_t, const void *); +#endif + +#endif /* !_NET_IF_DL_H_ */ diff --git a/sys/net/pfil.h b/sys/net/pfil.h new file mode 100644 index 000000000..cd74e8ffe --- /dev/null +++ b/sys/net/pfil.h @@ -0,0 +1,73 @@ +/* $NetBSD: pfil.h,v 1.31 2013/06/29 21:06:58 rmind Exp $ */ + +/* + * Copyright (c) 1996 Matthew R. Green + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN 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. + */ + +#ifndef _NET_PFIL_H_ +#define _NET_PFIL_H_ + +#include + +struct mbuf; +struct ifnet; + +/* + * The packet filter hooks are designed for anything to call them to + * possibly intercept the packet. + */ +typedef int (*pfil_func_t)(void *, struct mbuf **, struct ifnet *, int); + +#define PFIL_IN 0x00000001 +#define PFIL_OUT 0x00000002 +#define PFIL_ALL (PFIL_IN|PFIL_OUT) +#define PFIL_IFADDR 0x00000008 +#define PFIL_IFNET 0x00000010 + +/* events notified by PFIL_IFNET */ +#define PFIL_IFNET_ATTACH 0 +#define PFIL_IFNET_DETACH 1 + +#define PFIL_TYPE_AF 1 /* key is AF_* type */ +#define PFIL_TYPE_IFNET 2 /* key is ifnet pointer */ + +typedef struct pfil_head pfil_head_t; + +#ifdef _KERNEL + +int pfil_run_hooks(pfil_head_t *, struct mbuf **, struct ifnet *, int); +int pfil_add_hook(pfil_func_t, void *, int, pfil_head_t *); +int pfil_remove_hook(pfil_func_t, void *, int, pfil_head_t *); + +pfil_head_t * pfil_head_create(int, void *); +void pfil_head_destroy(pfil_head_t *); +pfil_head_t * pfil_head_get(int, void *); + +/* Packet filtering hook for interfaces (in sys/net/if.c module). */ +extern pfil_head_t *if_pfil; + +#endif /* _KERNEL */ + +#endif /* !_NET_PFIL_H_ */