/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2014 Apple Inc. All rights reserved.
*
- * @APPLE_LICENSE_HEADER_START@
- *
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
- *
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ *
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
*/
#ifndef _SYS_PROTOSW_H_
-#define _SYS_PROTOSW_H_
+#define _SYS_PROTOSW_H_
+
+#include <sys/appleapiopts.h>
+#include <sys/cdefs.h>
+
+/* XXX: this will go away */
+#define PR_SLOWHZ 2 /* 2 slow timeouts per second */
+
+#ifdef KERNEL_PRIVATE
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/queue.h>
+#include <kern/locks.h>
/* Forward declare these structures referenced from prototypes below. */
struct mbuf;
struct sockaddr;
struct socket;
struct sockopt;
+struct socket_filter;
+#ifdef XNU_KERNEL_PRIVATE
+struct domain_old;
+#endif /* XNU_KERNEL_PRIVATE */
-/*#ifdef _KERNEL*/
+#pragma pack(4)
+
+#ifdef XNU_KERNEL_PRIVATE
+/*
+ * Legacy protocol switch table.
+ *
+ * NOTE: Do not modify this structure, as there are modules outside of xnu
+ * which rely on the size and layout for binary compatibility. This structure
+ * is simply used by the exported net_{add,del}_proto_old, pffindproto_old
+ * routines, and by the domain_old structure. Internally, protocol switch
+ * tables are stored in the private variant of protosw defined down below.
+ */
+struct protosw_old {
+#else
+struct protosw {
+#endif /* !XNU_KERNEL_PRIVATE */
+ short pr_type; /* socket type used for */
+ struct domain *pr_domain; /* domain protocol a member of */
+ short pr_protocol; /* protocol number */
+ unsigned int pr_flags; /* see below */
+ /*
+ * protocol-protocol hooks
+ */
+ void (*pr_input) /* input to protocol (from below) */
+ (struct mbuf *, int len);
+ int (*pr_output) /* output to protocol (from above) */
+ (struct mbuf *m, struct socket *so);
+ void (*pr_ctlinput) /* control input (from below) */
+ (int, struct sockaddr *, void *);
+ int (*pr_ctloutput) /* control output (from above) */
+ (struct socket *, struct sockopt *);
+ /*
+ * user-protocol hook
+ */
+ void *pr_ousrreq;
+ /*
+ * utility hooks
+ */
+ void (*pr_init)(void); /* initialization hook */
+ void (*pr_unused)(void); /* placeholder - fasttimo is removed */
+ void (*pr_unused2)(void); /* placeholder - slowtimo is removed */
+ void (*pr_drain)(void); /* flush any excess space possible */
+ int (*pr_sysctl) /* sysctl for protocol */
+ (int *, u_int, void *, size_t *, void *, size_t);
+#ifdef XNU_KERNEL_PRIVATE
+ struct pr_usrreqs_old *pr_usrreqs; /* supersedes pr_usrreq() */
+#else
+ struct pr_usrreqs *pr_usrreqs; /* supersedes pr_usrreq() */
+#endif /* !XNU_KERNEL_PRIVATE */
+ int (*pr_lock) /* lock function for protocol */
+ (struct socket *so, int locktype, void *debug);
+ int (*pr_unlock) /* unlock for protocol */
+ (struct socket *so, int locktype, void *debug);
+ lck_mtx_t *(*pr_getlock) /* retrieve protocol lock */
+ (struct socket *so, int locktype);
+ /*
+ * Implant hooks
+ */
+ TAILQ_HEAD(, socket_filter) pr_filter_head;
+#ifdef XNU_KERNEL_PRIVATE
+ struct protosw_old *pr_next; /* chain for domain */
+#else
+ struct protosw *pr_next; /* chain for domain */
+#endif /* !XNU_KERNEL_PRIVATE */
+ u_int32_t reserved[1]; /* padding for future use */
+};
+
+#pragma pack()
+
+#ifdef XNU_KERNEL_PRIVATE
/*
* Protocol switch table.
*
* which is used for protocol-protocol and system-protocol communication.
*
* A protocol is called through the pr_init entry before any other.
- * Thereafter it is called every 200ms through the pr_fasttimo entry and
- * every 500ms through the pr_slowtimo for timer based actions.
- * The system will call the pr_drain entry if it is low on space and
- * this should throw away any non-critical data.
+ * The system will call the pr_drain entry if it is low on space and this
+ * should throw away any non-critical data.
*
* Protocols pass data between themselves as chains of mbufs using
* the pr_input and pr_output hooks. Pr_input passes data up (towards
*
* The userreq routine interfaces protocols to the system and is
* described below.
+ *
+ * After a protocol is attached, its pr_domain will be set to the domain
+ * which the protocol belongs to, and its pr_protosw will be set to the
+ * address of the protosw instance. The latter is useful for finding
+ * the real/original protosw instance, in the event so_proto is altered
+ * to point to an alternative/derivative protosw. E.g. the list of
+ * socket filters is only applicable on the original protosw instance.
+ *
+ * Internal, private and extendable representation of protosw.
*/
-
-#include <sys/appleapiopts.h>
-#include <sys/socketvar.h>
-#include <sys/queue.h>
-
-#ifdef __APPLE_API_UNSTABLE
struct protosw {
- short pr_type; /* socket type used for */
+ TAILQ_ENTRY(protosw) pr_entry; /* chain for domain */
struct domain *pr_domain; /* domain protocol a member of */
- short pr_protocol; /* protocol number */
- unsigned int pr_flags; /* see below */
-/* protocol-protocol hooks */
- void (*pr_input) __P((struct mbuf *, int len));
- /* input to protocol (from below) */
- int (*pr_output) __P((struct mbuf *m, struct socket *so));
- /* output to protocol (from above) */
- void (*pr_ctlinput)__P((int, struct sockaddr *, void *));
- /* control input (from below) */
- int (*pr_ctloutput)__P((struct socket *, struct sockopt *));
- /* control output (from above) */
-/* user-protocol hook */
- void *pr_ousrreq;
-/* utility hooks */
- void (*pr_init) __P((void)); /* initialization hook */
- void (*pr_fasttimo) __P((void));
- /* fast timeout (200ms) */
- void (*pr_slowtimo) __P((void));
- /* slow timeout (500ms) */
- void (*pr_drain) __P((void));
- /* flush any excess space possible */
-#if __APPLE__
- int (*pr_sysctl)(); /* sysctl for protocol */
-#endif
- struct pr_usrreqs *pr_usrreqs; /* supersedes pr_usrreq() */
-#if __APPLE__
-/* Implant hooks */
- TAILQ_HEAD(pr_sfilter, NFDescriptor) pr_sfilter;
- struct protosw *pr_next; /* Chain for domain */
- u_long reserved[4]; /* Padding for future use */
-#endif
+ struct protosw *pr_protosw; /* pointer to self */
+ u_int16_t pr_type; /* socket type used for */
+ u_int16_t pr_protocol; /* protocol number */
+ u_int32_t pr_flags; /* see below */
+ /*
+ * protocol-protocol hooks
+ */
+ void (*pr_input) /* input to protocol (from below) */
+ (struct mbuf *, int len);
+ int (*pr_output) /* output to protocol (from above) */
+ (struct mbuf *m, struct socket *so);
+ void (*pr_ctlinput) /* control input (from below) */
+ (int, struct sockaddr *, void *);
+ int (*pr_ctloutput) /* control output (from above) */
+ (struct socket *, struct sockopt *);
+ /*
+ * user-protocol hook
+ */
+ struct pr_usrreqs *pr_usrreqs; /* user request; see list below */
+ /*
+ * utility hooks
+ */
+ void (*pr_init) /* initialization hook */
+ (struct protosw *, struct domain *);
+ void (*pr_drain)(void); /* flush any excess space possible */
+ int (*pr_sysctl) /* sysctl for protocol */
+ (int *, u_int, void *, size_t *, void *, size_t);
+ int (*pr_lock) /* lock function for protocol */
+ (struct socket *so, int locktype, void *debug);
+ int (*pr_unlock) /* unlock for protocol */
+ (struct socket *so, int locktype, void *debug);
+ lck_mtx_t *(*pr_getlock) /* retrieve protocol lock */
+ (struct socket *so, int locktype);
+ /*
+ * misc
+ */
+ TAILQ_HEAD(, socket_filter) pr_filter_head;
+ struct protosw_old *pr_old;
};
-
-#define PR_SLOWHZ 2 /* 2 slow timeouts per second */
-#define PR_FASTHZ 5 /* 5 fast timeouts per second */
+#endif /* XNU_KERNEL_PRIVATE */
/*
* Values for pr_flags.
* is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed
* anyhow).
*/
-#define PR_ATOMIC 0x01 /* exchange atomic messages only */
-#define PR_ADDR 0x02 /* addresses given with messages */
-#define PR_CONNREQUIRED 0x04 /* connection required by protocol */
-#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
-#define PR_RIGHTS 0x10 /* passes capabilities */
-#define PR_IMPLOPCL 0x20 /* implied open/close */
-#define PR_LASTHDR 0x40 /* enforce ipsec policy; last header */
-
-/*
- * The arguments to usrreq are:
- * (*protosw[].pr_usrreq)(up, req, m, nam, opt);
- * where up is a (struct socket *), req is one of these requests,
- * m is a optional mbuf chain containing a message,
- * nam is an optional mbuf chain containing an address,
- * and opt is a pointer to a socketopt structure or nil.
- * The protocol is responsible for disposal of the mbuf chain m,
- * the caller is responsible for any space held by nam and opt.
- * A non-zero return from usrreq gives an
- * UNIX error number which should be passed to higher level software.
- */
-#define PRU_ATTACH 0 /* attach protocol to up */
-#define PRU_DETACH 1 /* detach protocol from up */
-#define PRU_BIND 2 /* bind socket to address */
-#define PRU_LISTEN 3 /* listen for connection */
-#define PRU_CONNECT 4 /* establish connection to peer */
-#define PRU_ACCEPT 5 /* accept connection from peer */
-#define PRU_DISCONNECT 6 /* disconnect from peer */
-#define PRU_SHUTDOWN 7 /* won't send any more data */
-#define PRU_RCVD 8 /* have taken data; more room now */
-#define PRU_SEND 9 /* send this data */
-#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */
-#define PRU_CONTROL 11 /* control operations on protocol */
-#define PRU_SENSE 12 /* return status into m */
-#define PRU_RCVOOB 13 /* retrieve out of band data */
-#define PRU_SENDOOB 14 /* send out of band data */
-#define PRU_SOCKADDR 15 /* fetch socket's address */
-#define PRU_PEERADDR 16 /* fetch peer's address */
-#define PRU_CONNECT2 17 /* connect two sockets */
-/* begin for protocols internal use */
-#define PRU_FASTTIMO 18 /* 200ms timeout */
-#define PRU_SLOWTIMO 19 /* 500ms timeout */
-#define PRU_PROTORCV 20 /* receive from below */
-#define PRU_PROTOSEND 21 /* send to below */
-/* end for protocol's internal use */
-#define PRU_SEND_EOF 22 /* send and close */
-#define PRU_NREQ 22
-
-#ifdef PRUREQUESTS
-char *prurequests[] = {
- "ATTACH", "DETACH", "BIND", "LISTEN",
- "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN",
- "RCVD", "SEND", "ABORT", "CONTROL",
- "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
- "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO",
- "PROTORCV", "PROTOSEND",
- "SEND_EOF",
-};
-#endif
-
-#ifdef KERNEL /* users shouldn't see this decl */
-
-struct ifnet;
-struct stat;
-struct ucred;
-struct uio;
-
-/*
- * If the ordering here looks odd, that's because it's alphabetical.
- * Having this structure separated out from the main protoswitch is allegedly
- * a big (12 cycles per call) lose on high-end CPUs. We will eventually
- * migrate this stuff back into the main structure.
- */
-struct pr_usrreqs {
- int (*pru_abort) __P((struct socket *so));
- int (*pru_accept) __P((struct socket *so, struct sockaddr **nam));
- int (*pru_attach) __P((struct socket *so, int proto,
- struct proc *p));
- int (*pru_bind) __P((struct socket *so, struct sockaddr *nam,
- struct proc *p));
- int (*pru_connect) __P((struct socket *so, struct sockaddr *nam,
- struct proc *p));
- int (*pru_connect2) __P((struct socket *so1, struct socket *so2));
- int (*pru_control) __P((struct socket *so, u_long cmd, caddr_t data,
- struct ifnet *ifp, struct proc *p));
- int (*pru_detach) __P((struct socket *so));
- int (*pru_disconnect) __P((struct socket *so));
- int (*pru_listen) __P((struct socket *so, struct proc *p));
- int (*pru_peeraddr) __P((struct socket *so,
- struct sockaddr **nam));
- int (*pru_rcvd) __P((struct socket *so, int flags));
- int (*pru_rcvoob) __P((struct socket *so, struct mbuf *m,
- int flags));
- int (*pru_send) __P((struct socket *so, int flags, struct mbuf *m,
- struct sockaddr *addr, struct mbuf *control,
- struct proc *p));
-#define PRUS_OOB 0x1
-#define PRUS_EOF 0x2
-#define PRUS_MORETOCOME 0x4
- int (*pru_sense) __P((struct socket *so, struct stat *sb));
- int (*pru_shutdown) __P((struct socket *so));
- int (*pru_sockaddr) __P((struct socket *so,
- struct sockaddr **nam));
-
- /*
- * These three added later, so they are out of order. They are used
- * for shortcutting (fast path input/output) in some protocols.
- * XXX - that's a lie, they are not implemented yet
- * Rather than calling sosend() etc. directly, calls are made
- * through these entry points. For protocols which still use
- * the generic code, these just point to those routines.
- */
- int (*pru_sosend) __P((struct socket *so, struct sockaddr *addr,
- struct uio *uio, struct mbuf *top,
- struct mbuf *control, int flags));
- int (*pru_soreceive) __P((struct socket *so,
- struct sockaddr **paddr,
- struct uio *uio, struct mbuf **mp0,
- struct mbuf **controlp, int *flagsp));
- int (*pru_sopoll) __P((struct socket *so, int events,
- struct ucred *cred, void *));
-};
-
-extern int pru_abort_notsupp(struct socket *so);
-extern int pru_accept_notsupp(struct socket *so, struct sockaddr **nam);
-extern int pru_attach_notsupp(struct socket *so, int proto,
- struct proc *p);
-extern int pru_bind_notsupp(struct socket *so, struct sockaddr *nam,
- struct proc *p);
-extern int pru_connect_notsupp(struct socket *so, struct sockaddr *nam,
- struct proc *p);
-extern int pru_connect2_notsupp(struct socket *so1, struct socket *so2);
-extern int pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data,
- struct ifnet *ifp, struct proc *p);
-extern int pru_detach_notsupp(struct socket *so);
-extern int pru_disconnect_notsupp(struct socket *so);
-extern int pru_listen_notsupp(struct socket *so, struct proc *p);
-extern int pru_peeraddr_notsupp(struct socket *so,
- struct sockaddr **nam);
-extern int pru_rcvd_notsupp(struct socket *so, int flags);
-extern int pru_rcvoob_notsupp(struct socket *so, struct mbuf *m,
- int flags);
-extern int pru_send_notsupp(struct socket *so, int flags, struct mbuf *m,
- struct sockaddr *addr, struct mbuf *control,
- struct proc *p);
-extern int pru_sense_null(struct socket *so, struct stat *sb);
-extern int pru_shutdown_notsupp(struct socket *so);
-extern int pru_sockaddr_notsupp(struct socket *so,
- struct sockaddr **nam);
-extern int pru_sosend_notsupp(struct socket *so, struct sockaddr *addr,
- struct uio *uio, struct mbuf *top,
- struct mbuf *control, int flags);
-extern int pru_soreceive_notsupp(struct socket *so,
- struct sockaddr **paddr,
- struct uio *uio, struct mbuf **mp0,
- struct mbuf **controlp, int *flagsp);
-extern int pru_sopoll_notsupp(struct socket *so, int events,
- struct ucred *cred);
-
+#define PR_ATOMIC 0x01 /* exchange atomic messages only */
+#define PR_ADDR 0x02 /* addresses given with messages */
+#define PR_CONNREQUIRED 0x04 /* connection required by protocol */
+#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
+#define PR_RIGHTS 0x10 /* passes capabilities */
+#define PR_IMPLOPCL 0x20 /* implied open/close */
+#define PR_LASTHDR 0x40 /* enforce ipsec policy; last header */
+#define PR_PROTOLOCK 0x80 /* protocol takes care of it's own locking */
+#define PR_PCBLOCK 0x100 /* protocol supports per pcb locking */
+#define PR_DISPOSE 0x200 /* protocol requires late lists disposal */
+#ifdef BSD_KERNEL_PRIVATE
+#define PR_INITIALIZED 0x400 /* protocol has been initialized */
+#define PR_ATTACHED 0x800 /* protocol is attached to a domain */
+#define PR_MULTICONN 0x1000 /* supports multiple connect calls */
+#define PR_EVCONNINFO 0x2000 /* protocol generates conninfo event */
+#define PR_OLD 0x10000000 /* added via net_add_proto */
-#endif /* KERNEL */
+/* pseudo-public domain flags */
+#define PRF_USERFLAGS \
+ (PR_ATOMIC|PR_ADDR|PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS| \
+ PR_IMPLOPCL|PR_LASTHDR|PR_PROTOLOCK|PR_PCBLOCK|PR_DISPOSE)
+#endif /* BSD_KERNEL_PRIVATE */
+#ifdef BSD_KERNEL_PRIVATE
/*
* The arguments to the ctlinput routine are
* (*protosw[].pr_ctlinput)(cmd, sa, arg);
*/
#define PRC_IFDOWN 0 /* interface transition */
#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
-#define PRC_IFUP 2 /* interface has come back up */
+#define PRC_IFUP 2 /* interface has come back up */
#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */
#define PRC_QUENCH 4 /* some one said to slow down */
#define PRC_MSGSIZE 5 /* message size forced drop */
#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
#define PRC_PARAMPROB 20 /* header incorrect */
-#define PRC_UNREACH_ADMIN_PROHIB 21 /* packet administrativly prohibited */
+#define PRC_UNREACH_ADMIN_PROHIB 21 /* packet administrativly prohibited */
#define PRC_NCMDS 22
"TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
"PARAMPROB", "ADMIN-UNREACH"
};
-#endif
+#endif /* PRCREQUESTS */
/*
* The arguments to ctloutput are:
char *prcorequests[] = {
"GETOPT", "SETOPT",
};
-#endif
+#endif /* PRCOREQUESTS */
-#ifdef KERNEL
-void pfctlinput __P((int, struct sockaddr *));
-void pfctlinput2 __P((int, struct sockaddr *, void *));
-struct protosw *pffindproto __P((int family, int protocol, int type));
-struct protosw *pffindtype __P((int family, int type));
+/*
+ * In earlier BSD network stacks, a single pr_usrreq() function pointer was
+ * invoked with an operation number indicating what operation was desired.
+ * We now provide individual function pointers which protocols can implement,
+ * which offers a number of benefits (such as type checking for arguments).
+ * These older constants are still present in order to support TCP debugging.
+ */
+#define PRU_ATTACH 0 /* attach protocol to up */
+#define PRU_DETACH 1 /* detach protocol from up */
+#define PRU_BIND 2 /* bind socket to address */
+#define PRU_LISTEN 3 /* listen for connection */
+#define PRU_CONNECT 4 /* establish connection to peer */
+#define PRU_ACCEPT 5 /* accept connection from peer */
+#define PRU_DISCONNECT 6 /* disconnect from peer */
+#define PRU_SHUTDOWN 7 /* won't send any more data */
+#define PRU_RCVD 8 /* have taken data; more room now */
+#define PRU_SEND 9 /* send this data */
+#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */
+#define PRU_CONTROL 11 /* control operations on protocol */
+#define PRU_SENSE 12 /* return status into m */
+#define PRU_RCVOOB 13 /* retrieve out of band data */
+#define PRU_SENDOOB 14 /* send out of band data */
+#define PRU_SOCKADDR 15 /* fetch socket's address */
+#define PRU_PEERADDR 16 /* fetch peer's address */
+#define PRU_CONNECT2 17 /* connect two sockets */
+/* begin for protocols internal use */
+#define PRU_FASTTIMO 18 /* 200ms timeout */
+#define PRU_SLOWTIMO 19 /* 500ms timeout */
+#define PRU_PROTORCV 20 /* receive from below */
+#define PRU_PROTOSEND 21 /* send to below */
+/* end for protocol's internal use */
+#define PRU_SEND_EOF 22 /* send and close */
+#define PRU_NREQ 22
-extern int net_add_proto(struct protosw *, struct domain *);
-extern int net_del_proto(int, int, struct domain *);
+#ifdef PRUREQUESTS
+char *prurequests[] = {
+ "ATTACH", "DETACH", "BIND", "LISTEN",
+ "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN",
+ "RCVD", "SEND", "ABORT", "CONTROL",
+ "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
+ "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO",
+ "PROTORCV", "PROTOSEND", "SEND_EOF",
+};
+#endif /* PRUREQUESTS */
+#endif /* BSD_KERNEL_PRIVATE */
+
+struct ifnet;
+struct stat;
+struct ucred;
+struct uio;
-/* Temp hack to link static domains together */
+#ifdef XNU_KERNEL_PRIVATE
+/*
+ * Legacy user-protocol hooks.
+ *
+ * NOTE: Do not modify this structure, as there are modules outside of xnu
+ * which rely on the size and layout for binary compatibility. This structure
+ * is simply used by the protosw_old structure. Internally, user-protocol
+ * hooks use the private variant of pr_usrreqs defined down below.
+ */
+struct pr_usrreqs_old {
+#else
+struct pr_usrreqs {
+#endif /* !XNU_KERNEL_PRIVATE */
+ int (*pru_abort)(struct socket *so);
+ int (*pru_accept)(struct socket *so, struct sockaddr **nam);
+ int (*pru_attach)(struct socket *so, int proto, struct proc *p);
+ int (*pru_bind)(struct socket *so, struct sockaddr *nam,
+ struct proc *p);
+ int (*pru_connect)(struct socket *so, struct sockaddr *nam,
+ struct proc *p);
+ int (*pru_connect2)(struct socket *so1, struct socket *so2);
+ int (*pru_control)(struct socket *so, u_long cmd, caddr_t data,
+ struct ifnet *ifp, struct proc *p);
+ int (*pru_detach)(struct socket *so);
+ int (*pru_disconnect)(struct socket *so);
+ int (*pru_listen)(struct socket *so, struct proc *p);
+ int (*pru_peeraddr)(struct socket *so, struct sockaddr **nam);
+ int (*pru_rcvd)(struct socket *so, int flags);
+ int (*pru_rcvoob)(struct socket *so, struct mbuf *m, int flags);
+ int (*pru_send)(struct socket *so, int flags, struct mbuf *m,
+ struct sockaddr *addr, struct mbuf *control,
+ struct proc *p);
+ int (*pru_sense)(struct socket *so, void *sb, int isstat64);
+ int (*pru_shutdown)(struct socket *so);
+ int (*pru_sockaddr)(struct socket *so, struct sockaddr **nam);
+ int (*pru_sosend)(struct socket *so, struct sockaddr *addr,
+ struct uio *uio, struct mbuf *top, struct mbuf *control,
+ int flags);
+ int (*pru_soreceive)(struct socket *so, struct sockaddr **paddr,
+ struct uio *uio, struct mbuf **mp0, struct mbuf **controlp,
+ int *flagsp);
+ int (*pru_sopoll)(struct socket *so, int events,
+ struct ucred *cred, void *);
+};
-#define LINK_PROTOS(psw) \
-static void link_ ## psw ## _protos() \
-{ \
- int i; \
- \
- for (i=0; i < ((sizeof(psw)/sizeof(psw[0])) - 1); i++) \
- psw[i].pr_next = &psw[i + 1]; \
-}
+#ifdef XNU_KERNEL_PRIVATE
+/*
+ * If the ordering here looks odd, that's because it's alphabetical. These
+ * should eventually be merged back into struct protosw.
+ *
+ * Internal, private and extendable representation of pr_usrreqs.
+ *
+ * NOTE: When adding new ones, also add default callbacks in pru_sanitize().
+ */
+struct pr_usrreqs {
+ uint32_t pru_flags; /* see PRUF flags below */
+ int (*pru_abort)(struct socket *);
+ int (*pru_accept)(struct socket *, struct sockaddr **);
+ int (*pru_attach)(struct socket *, int proto, struct proc *);
+ int (*pru_bind)(struct socket *, struct sockaddr *, struct proc *);
+ int (*pru_connect)(struct socket *, struct sockaddr *,
+ struct proc *);
+ int (*pru_connect2)(struct socket *, struct socket *);
+ int (*pru_connectx)(struct socket *, struct sockaddr_list **,
+ struct sockaddr_list **, struct proc *, uint32_t,
+ associd_t, connid_t *, uint32_t, void *, uint32_t);
+ int (*pru_control)(struct socket *, u_long, caddr_t,
+ struct ifnet *, struct proc *);
+ int (*pru_detach)(struct socket *);
+ int (*pru_disconnect)(struct socket *);
+ int (*pru_disconnectx)(struct socket *, associd_t, connid_t);
+ int (*pru_listen)(struct socket *, struct proc *);
+ int (*pru_peeloff)(struct socket *, associd_t, struct socket **);
+ int (*pru_peeraddr)(struct socket *, struct sockaddr **);
+ int (*pru_rcvd)(struct socket *, int);
+ int (*pru_rcvoob)(struct socket *, struct mbuf *, int);
+ int (*pru_send)(struct socket *, int, struct mbuf *,
+ struct sockaddr *, struct mbuf *, struct proc *);
+ int (*pru_send_list)(struct socket *, int, struct mbuf *,
+ struct sockaddr *, struct mbuf *, struct proc *);
+#define PRUS_OOB 0x1
+#define PRUS_EOF 0x2
+#define PRUS_MORETOCOME 0x4
+ int (*pru_sense)(struct socket *, void *, int);
+ int (*pru_shutdown)(struct socket *);
+ int (*pru_sockaddr)(struct socket *, struct sockaddr **);
+ int (*pru_sopoll)(struct socket *, int, struct ucred *, void *);
+ int (*pru_soreceive)(struct socket *, struct sockaddr **,
+ struct uio *, struct mbuf **, struct mbuf **, int *);
+ int (*pru_soreceive_list)(struct socket *, struct sockaddr **,
+ struct uio **, u_int, struct mbuf **, struct mbuf **, int *);
+ int (*pru_sosend)(struct socket *, struct sockaddr *,
+ struct uio *, struct mbuf *, struct mbuf *, int);
+ int (*pru_sosend_list)(struct socket *, struct sockaddr *,
+ struct uio **, u_int, struct mbuf *, struct mbuf *, int);
+ int (*pru_socheckopt)(struct socket *, struct sockopt *);
+};
-#endif
-#endif /* __APPLE_API_UNSTABLE */
+/* Values for pru_flags */
+#define PRUF_OLD 0x10000000 /* added via net_add_proto */
+
+#endif /* XNU_KERNEL_PRIVATE */
+
+__BEGIN_DECLS
+extern int pru_abort_notsupp(struct socket *so);
+extern int pru_accept_notsupp(struct socket *so, struct sockaddr **nam);
+extern int pru_attach_notsupp(struct socket *so, int proto, struct proc *p);
+extern int pru_bind_notsupp(struct socket *so, struct sockaddr *nam,
+ struct proc *p);
+extern int pru_connect_notsupp(struct socket *so, struct sockaddr *nam,
+ struct proc *p);
+extern int pru_connect2_notsupp(struct socket *so1, struct socket *so2);
+#ifdef XNU_KERNEL_PRIVATE
+extern int pru_connectx_notsupp(struct socket *, struct sockaddr_list **,
+ struct sockaddr_list **, struct proc *, uint32_t, associd_t, connid_t *,
+ uint32_t, void *, uint32_t);
+extern int pru_disconnectx_notsupp(struct socket *, associd_t, connid_t);
+extern int pru_socheckopt_null(struct socket *, struct sockopt *);
+extern int pru_peeloff_notsupp(struct socket *, associd_t, struct socket **);
+#endif /* XNU_KERNEL_PRIVATE */
+extern int pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data,
+ struct ifnet *ifp, struct proc *p);
+extern int pru_detach_notsupp(struct socket *so);
+extern int pru_disconnect_notsupp(struct socket *so);
+extern int pru_listen_notsupp(struct socket *so, struct proc *p);
+extern int pru_peeraddr_notsupp(struct socket *so, struct sockaddr **nam);
+extern int pru_rcvd_notsupp(struct socket *so, int flags);
+extern int pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags);
+extern int pru_send_notsupp(struct socket *so, int flags, struct mbuf *m,
+ struct sockaddr *addr, struct mbuf *control, struct proc *p);
+extern int pru_send_list_notsupp(struct socket *so, int flags, struct mbuf *m,
+ struct sockaddr *addr, struct mbuf *control, struct proc *p);
+extern int pru_sense_null(struct socket *so, void * sb, int isstat64);
+extern int pru_shutdown_notsupp(struct socket *so);
+extern int pru_sockaddr_notsupp(struct socket *so, struct sockaddr **nam);
+extern int pru_sosend_notsupp(struct socket *so, struct sockaddr *addr,
+ struct uio *uio, struct mbuf *top, struct mbuf *control, int flags);
+extern int pru_sosend_list_notsupp(struct socket *so, struct sockaddr *addr,
+ struct uio **uio, u_int, struct mbuf *top, struct mbuf *control, int flags);
+extern int pru_soreceive_notsupp(struct socket *so,
+ struct sockaddr **paddr, struct uio *uio, struct mbuf **mp0,
+ struct mbuf **controlp, int *flagsp);
+extern int pru_soreceive_list_notsupp(struct socket *so,
+ struct sockaddr **paddr, struct uio **uio, u_int, struct mbuf **mp0,
+ struct mbuf **controlp, int *flagsp);
+extern int pru_sopoll_notsupp(struct socket *so, int events,
+ struct ucred *cred, void *);
+#ifdef XNU_KERNEL_PRIVATE
+extern void pru_sanitize(struct pr_usrreqs *);
+extern void domaininit(void);
+extern void domainfin(void);
+extern void pfctlinput(int, struct sockaddr *);
+extern void pfctlinput2(int, struct sockaddr *, void *);
+extern struct protosw *pffindproto_locked(int, int, int);
+extern struct protosw *pffindprotonotype(int, int);
+extern struct protosw *pffindtype(int, int);
+extern struct protosw_old *pffindproto_old(int, int, int);
+extern int net_add_proto(struct protosw *, struct domain *, int);
+extern void net_init_proto(struct protosw *, struct domain *);
+extern int net_del_proto(int, int, struct domain *);
+extern int net_add_proto_old(struct protosw_old *, struct domain_old *);
+extern int net_del_proto_old(int, int, struct domain_old *);
+extern void net_update_uptime(void);
+extern void net_update_uptime_secs(uint64_t secs);
+extern u_int64_t net_uptime(void);
+extern void net_uptime2timeval(struct timeval *);
+#else
+extern int net_add_proto(struct protosw *, struct domain *);
+extern int net_del_proto(int, int, struct domain *);
+#endif /* XNU_KERNEL_PRIVATE */
+extern struct protosw *pffindproto(int family, int protocol, int type);
+__END_DECLS
+#endif /* KERNEL_PRIVATE */
#endif /* !_SYS_PROTOSW_H_ */