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
This commit is contained in:
David van Moolenbroek 2016-03-13 15:55:44 +00:00
parent 1122b28691
commit 7ecc6a9247
16 changed files with 2888 additions and 23 deletions

View File

@ -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

View File

@ -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++

View File

@ -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

View File

@ -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);

View File

@ -1,6 +1,6 @@
INCSDIR= /usr/include/net
INCS+= hton.h if.h netlib.h
INCS+= hton.h netlib.h
SUBDIR+= gen

View File

@ -1,6 +0,0 @@
#ifndef _NET_IF_H_
#define _NET_IF_H_
#define IFF_UP 0x0001 /* interface is up */
#endif /* _NET_IF_H_ */

View File

@ -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];
}
}

View File

@ -2,7 +2,7 @@
.include <bsd.own.mk>
SUBDIR= arch dev fs \
SUBDIR= altq arch dev fs \
net netinet netinet6 \
\
sys ufs uvm

11
sys/altq/Makefile Normal file
View File

@ -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 <bsd.kinc.mk>

177
sys/altq/if_altq.h Normal file
View File

@ -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_ */

View File

@ -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)

1290
sys/net/dlt.h Normal file

File diff suppressed because it is too large Load Diff

1056
sys/net/if.h Normal file

File diff suppressed because it is too large Load Diff

132
sys/net/if_arp.h Normal file
View File

@ -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_ */

128
sys/net/if_dl.h Normal file
View File

@ -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 <sys/ansi.h>
#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 <sys/cdefs.h>
__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_ */

73
sys/net/pfil.h Normal file
View File

@ -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 <sys/queue.h>
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_ */