xref: /xnu-8792.61.2/bsd/sys/protosw.h (revision 42e220869062b56f8d7d0726fd4c88954f87902c)
1 /*
2  * Copyright (c) 2000-2021 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
29 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
30 /*
31  * Copyright (c) 1982, 1986, 1993
32  *	The Regents of the University of California.  All rights reserved.
33  *
34  * Redistribution and use in source and binary forms, with or without
35  * modification, are permitted provided that the following conditions
36  * are met:
37  * 1. Redistributions of source code must retain the above copyright
38  *    notice, this list of conditions and the following disclaimer.
39  * 2. Redistributions in binary form must reproduce the above copyright
40  *    notice, this list of conditions and the following disclaimer in the
41  *    documentation and/or other materials provided with the distribution.
42  * 3. All advertising materials mentioning features or use of this software
43  *    must display the following acknowledgement:
44  *	This product includes software developed by the University of
45  *	California, Berkeley and its contributors.
46  * 4. Neither the name of the University nor the names of its contributors
47  *    may be used to endorse or promote products derived from this software
48  *    without specific prior written permission.
49  *
50  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60  * SUCH DAMAGE.
61  *
62  *	@(#)protosw.h	8.1 (Berkeley) 6/2/93
63  * $FreeBSD: src/sys/sys/protosw.h,v 1.28.2.2 2001/07/03 11:02:01 ume Exp $
64  */
65 
66 #ifndef _SYS_PROTOSW_H_
67 #define _SYS_PROTOSW_H_
68 
69 #include <sys/appleapiopts.h>
70 #include <sys/cdefs.h>
71 
72 __ASSUME_PTR_ABI_SINGLE_BEGIN
73 
74 /* XXX: this will go away */
75 #define PR_SLOWHZ       2               /* 2 slow timeouts per second */
76 
77 /*
78  * The arguments to the ctlinput routine are
79  *      (*protosw[].pr_ctlinput)(cmd, sa, arg, ifnet);
80  * where `cmd' is one of the commands below, `sa' is a pointer to a sockaddr,
81  * `arg' is a `void *' argument used within a protocol family (typically
82  * that's a `struct ipctlparam *') and `ifp' is a pointer to the network interface.
83  */
84 #define PRC_IFDOWN              0       /* interface transition */
85 #define PRC_ROUTEDEAD           1       /* select new route if possible ??? */
86 #define PRC_IFUP                2       /* interface has come back up */
87 #define PRC_QUENCH2             3       /* DEC congestion bit says slow down */
88 #define PRC_QUENCH              4       /* some one said to slow down */
89 #define PRC_MSGSIZE             5       /* message size forced drop */
90 #define PRC_HOSTDEAD            6       /* host appears to be down */
91 #define PRC_HOSTUNREACH         7       /* deprecated (use PRC_UNREACH_HOST) */
92 #define PRC_UNREACH_NET         8       /* no route to network */
93 #define PRC_UNREACH_HOST        9       /* no route to host */
94 #define PRC_UNREACH_PROTOCOL    10      /* dst says bad protocol */
95 #define PRC_UNREACH_PORT        11      /* bad port # */
96 /* was PRC_UNREACH_NEEDFRAG	12         (use PRC_MSGSIZE) */
97 #define PRC_UNREACH_SRCFAIL     13      /* source route failed */
98 #define PRC_REDIRECT_NET        14      /* net routing redirect */
99 #define PRC_REDIRECT_HOST       15      /* host routing redirect */
100 #define PRC_REDIRECT_TOSNET     16      /* redirect for type of service & net */
101 #define PRC_REDIRECT_TOSHOST    17      /* redirect for tos & host */
102 #define PRC_TIMXCEED_INTRANS    18      /* packet lifetime expired in transit */
103 #define PRC_TIMXCEED_REASS      19      /* lifetime expired on reass q */
104 #define PRC_PARAMPROB           20      /* header incorrect */
105 #define PRC_UNREACH_ADMIN_PROHIB        21     /* packet administrativly prohibited */
106 
107 #define PRC_NCMDS               22
108 
109 #define PRC_IS_REDIRECT(cmd)    \
110 	((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
111 
112 #ifdef BSD_KERNEL_PRIVATE
113 #include <sys/eventhandler.h>
114 #endif
115 
116 #ifdef KERNEL_PRIVATE
117 #include <sys/socket.h>
118 #include <sys/socketvar.h>
119 #include <sys/queue.h>
120 #include <kern/locks.h>
121 
122 
123 /*
124  * argument type for the 3rd arg of pr_ctlinput()
125  * should be consulted only with AF_INET family.
126  *
127  * IPv4 ICMP IPv4 [exthdrs] finalhdr payload
128  * ^    ^    ^              ^
129  * |    |    |              ipc_off
130  * |    |    ipc_icmp_ip
131  * |    ipc_icmp
132  * ipc_m
133  *
134  */
135 struct ipctlparam {
136 	struct ip   *ipc_icmp_ip;  /* ip header of target packet. Must be the first field */
137 	struct mbuf *ipc_m;        /* start of mbuf chain */
138 	struct icmp *ipc_icmp;     /* icmp header of target packet */
139 	size_t       ipc_off;      /* offset of the target proto header */
140 };
141 
142 /* Forward declare these structures referenced from prototypes below. */
143 struct mbuf;
144 struct proc;
145 struct sockaddr;
146 struct socket;
147 struct sockopt;
148 struct socket_filter;
149 struct uio;
150 struct ifnet;
151 #ifdef XNU_KERNEL_PRIVATE
152 struct domain_old;
153 struct proc;
154 #endif /* XNU_KERNEL_PRIVATE */
155 
156 #pragma pack(4)
157 
158 #ifdef XNU_KERNEL_PRIVATE
159 /*
160  * Legacy protocol switch table.
161  *
162  * NOTE: Do not modify this structure, as there are modules outside of xnu
163  * which rely on the size and layout for binary compatibility.  This structure
164  * is simply used by the exported net_{add,del}_proto_old, pffindproto_old
165  * routines, and by the domain_old structure.  Internally, protocol switch
166  * tables are stored in the private variant of protosw defined down below.
167  */
168 struct protosw_old {
169 #else
170 struct protosw {
171 #endif /* !XNU_KERNEL_PRIVATE */
172 	short   pr_type;                /* socket type used for */
173 	struct  domain *pr_domain;      /* domain protocol a member of */
174 	short   pr_protocol;            /* protocol number */
175 	unsigned int pr_flags;          /* see below */
176 	/*
177 	 * protocol-protocol hooks
178 	 */
179 	void    (*pr_input)             /* input to protocol (from below) */
180 	(struct mbuf *, int len);
181 	int     (*pr_output)            /* output to protocol (from above) */
182 	(struct mbuf *m, struct socket *so);
183 	void    (*pr_ctlinput)          /* control input (from below) */
184 	(int, struct sockaddr *, void *, struct ifnet *);
185 	int     (*pr_ctloutput)         /* control output (from above) */
186 	(struct socket *, struct sockopt *);
187 	/*
188 	 * user-protocol hook
189 	 */
190 	void    *pr_ousrreq;
191 	/*
192 	 * utility hooks
193 	 */
194 	void    (*pr_init)(void);       /* initialization hook */
195 	void    (*pr_unused)(void);     /* placeholder - fasttimo is removed */
196 	void    (*pr_unused2)(void);    /* placeholder - slowtimo is removed */
197 	void    (*pr_drain)(void);      /* flush any excess space possible */
198 	int     (*pr_sysctl)            /* sysctl for protocol */
199 	(int *, u_int, void *, size_t *, void *, size_t);
200 #ifdef XNU_KERNEL_PRIVATE
201 	struct  pr_usrreqs_old *pr_usrreqs; /* supersedes pr_usrreq() */
202 #else
203 	struct  pr_usrreqs *pr_usrreqs; /* supersedes pr_usrreq() */
204 #endif /* !XNU_KERNEL_PRIVATE */
205 	int     (*pr_lock)              /* lock function for protocol */
206 	(struct socket *so, int refcnt, void *debug);
207 	int     (*pr_unlock)            /* unlock for protocol */
208 	(struct socket *so, int refcnt, void *debug);
209 	lck_mtx_t * __single (*pr_getlock)        /* retrieve protocol lock */
210 	(struct socket *so, int flags);
211 	/*
212 	 * Implant hooks
213 	 */
214 	TAILQ_HEAD(, socket_filter) pr_filter_head;
215 #ifdef XNU_KERNEL_PRIVATE
216 	struct protosw_old *pr_next;    /* chain for domain */
217 #else
218 	struct protosw *pr_next;        /* chain for domain */
219 #endif /* !XNU_KERNEL_PRIVATE */
220 	u_int32_t       reserved[1];    /* padding for future use */
221 };
222 
223 #pragma pack()
224 
225 #ifdef XNU_KERNEL_PRIVATE
226 /*
227  * Protocol switch table.
228  *
229  * Each protocol has a handle initializing one of these structures,
230  * which is used for protocol-protocol and system-protocol communication.
231  *
232  * A protocol is called through the pr_init entry before any other.
233  * The system will call the pr_drain entry if it is low on space and this
234  * should throw away any non-critical data.
235  *
236  * Protocols pass data between themselves as chains of mbufs using
237  * the pr_input and pr_output hooks.  Pr_input passes data up (towards
238  * the users) and pr_output passes it down (towards the interfaces); control
239  * information passes up and down on pr_ctlinput and pr_ctloutput.
240  * The protocol is responsible for the space occupied by any the
241  * arguments to these entries and must dispose it.
242  *
243  * The userreq routine interfaces protocols to the system and is
244  * described below.
245  *
246  * After a protocol is attached, its pr_domain will be set to the domain
247  * which the protocol belongs to, and its pr_protosw will be set to the
248  * address of the protosw instance.  The latter is useful for finding
249  * the real/original protosw instance, in the event so_proto is altered
250  * to point to an alternative/derivative protosw.  E.g. the list of
251  * socket filters is only applicable on the original protosw instance.
252  *
253  * Internal, private and extendable representation of protosw.
254  */
255 struct protosw {
256 	TAILQ_ENTRY(protosw) pr_entry; /* chain for domain */
257 	struct  domain *pr_domain;      /* domain protocol a member of */
258 	struct protosw *pr_protosw;     /* pointer to self */
259 	u_int16_t pr_type;              /* socket type used for */
260 	u_int16_t pr_protocol;          /* protocol number */
261 	u_int32_t pr_flags;             /* see below */
262 	/*
263 	 * protocol-protocol hooks
264 	 */
265 	void    (*pr_input)             /* input to protocol (from below) */
266 	(struct mbuf *, int len);
267 	int     (*pr_output)            /* output to protocol (from above) */
268 	(struct mbuf *m, struct socket *so);
269 	void    (*pr_ctlinput)          /* control input (from below) */
270 	(int, struct sockaddr *, void *, struct ifnet *);
271 	int     (*pr_ctloutput)         /* control output (from above) */
272 	(struct socket *, struct sockopt *);
273 	/*
274 	 * user-protocol hook
275 	 */
276 	struct  pr_usrreqs *pr_usrreqs; /* user request; see list below */
277 	/*
278 	 * utility hooks
279 	 */
280 	void    (*pr_init)              /* initialization hook */
281 	(struct protosw *, struct domain *);
282 	void    (*pr_drain)(void);      /* flush any excess space possible */
283 	int     (*pr_sysctl)            /* sysctl for protocol */
284 	(int *, u_int, void *, size_t *, void *, size_t);
285 	int     (*pr_lock)              /* lock function for protocol */
286 	(struct socket *so, int refcnt, void *debug);
287 	int     (*pr_unlock)            /* unlock for protocol */
288 	(struct socket *so, int refcnt, void *debug);
289 	lck_mtx_t * __single (*pr_getlock)        /* retrieve protocol lock */
290 	(struct socket *so, int flags);
291 	/*
292 	 * misc
293 	 */
294 	TAILQ_HEAD(, socket_filter) pr_filter_head;
295 	struct protosw_old *pr_old;
296 
297 	void    (*pr_update_last_owner) /* update last socket owner */
298 	(struct socket *so, struct proc *p, struct proc *ep);
299 
300 	void    (*pr_copy_last_owner) /* copy last socket from listener */
301 	(struct socket *so, struct socket *head);
302 };
303 
304 /*
305  * Values for the flags argument of pr_getlock
306  */
307 #define PR_F_WILLUNLOCK 0x01    /* Will unlock (e.g., msleep) after the pr_getlock call */
308 
309 #endif /* XNU_KERNEL_PRIVATE */
310 
311 /*
312  * Values for pr_flags.
313  * PR_ADDR requires PR_ATOMIC;
314  * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
315  * PR_IMPLOPCL means that the protocol allows sendto without prior connect,
316  *	and the protocol understands the MSG_EOF flag.  The first property is
317  *	is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed
318  *	anyhow).
319  */
320 #define PR_ATOMIC       0x01    /* exchange atomic messages only */
321 #define PR_ADDR         0x02    /* addresses given with messages */
322 #define PR_CONNREQUIRED 0x04    /* connection required by protocol */
323 #define PR_WANTRCVD     0x08    /* want PRU_RCVD calls */
324 #define PR_RIGHTS       0x10    /* passes capabilities */
325 #define PR_IMPLOPCL     0x20    /* implied open/close */
326 #define PR_LASTHDR      0x40    /* enforce ipsec policy; last header */
327 #define PR_PROTOLOCK    0x80    /* protocol takes care of it's own locking */
328 #define PR_PCBLOCK      0x100   /* protocol supports per pcb locking */
329 #define PR_DISPOSE      0x200   /* protocol requires late lists disposal */
330 #ifdef BSD_KERNEL_PRIVATE
331 #define PR_INITIALIZED  0x400   /* protocol has been initialized */
332 #define PR_ATTACHED     0x800   /* protocol is attached to a domain */
333 #define PR_MULTICONN    0x1000  /* supports multiple connect calls */
334 #define PR_EVCONNINFO   0x2000  /* protocol generates conninfo event */
335 #define PR_PRECONN_WRITE        0x4000  /* protocol supports preconnect write */
336 #define PR_DATA_IDEMPOTENT      0x8000  /* protocol supports idempotent data at connectx-time */
337 #define PR_OLD          0x10000000 /* added via net_add_proto */
338 
339 /* pseudo-public domain flags */
340 #define PRF_USERFLAGS                                                   \
341 	(PR_ATOMIC|PR_ADDR|PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS|       \
342 	PR_IMPLOPCL|PR_LASTHDR|PR_PROTOLOCK|PR_PCBLOCK|PR_DISPOSE)
343 #endif /* BSD_KERNEL_PRIVATE */
344 
345 #ifdef BSD_KERNEL_PRIVATE
346 #if SKYWALK
347 struct protoctl_ev_val {
348 	uint32_t val;
349 	uint32_t tcp_seq_number;
350 };
351 
352 extern void
353 protoctl_event_enqueue_nwk_wq_entry(struct ifnet *ifp, struct sockaddr *p_laddr,
354     struct sockaddr *p_raddr, uint16_t lport, uint16_t rport, uint8_t protocol,
355     uint32_t protoctl_event_code, struct protoctl_ev_val *p_protoctl_ev_val);
356 
357 struct protoctl_ev_val;
358 /* Proto event declarations */
359 extern struct eventhandler_lists_ctxt protoctl_evhdlr_ctxt;
360 typedef void (*protoctl_event_fn)(struct eventhandler_entry_arg, struct ifnet *,
361     struct sockaddr *, struct sockaddr*, uint16_t, uint16_t, uint8_t, uint32_t,
362     struct protoctl_ev_val *);
363 EVENTHANDLER_DECLARE(protoctl_event, protoctl_event_fn);
364 #endif /* SKYWALK */
365 #ifdef PRCREQUESTS
366 char    *prcrequests[] = {
367 	"IFDOWN", "ROUTEDEAD", "IFUP", "DEC-BIT-QUENCH2",
368 	"QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
369 	"NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
370 	"#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
371 	"TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
372 	"PARAMPROB", "ADMIN-UNREACH"
373 };
374 #endif /* PRCREQUESTS */
375 
376 /*
377  * The arguments to ctloutput are:
378  *	(*protosw[].pr_ctloutput)(req, so, level, optname, optval, p);
379  * req is one of the actions listed below, so is a (struct socket *),
380  * level is an indication of which protocol layer the option is intended.
381  * optname is a protocol dependent socket option request,
382  * optval is a pointer to a mbuf-chain pointer, for value-return results.
383  * The protocol is responsible for disposal of the mbuf chain *optval
384  * if supplied,
385  * the caller is responsible for any space held by *optval, when returned.
386  * A non-zero return from usrreq gives an
387  * UNIX error number which should be passed to higher level software.
388  */
389 #define PRCO_GETOPT     0
390 #define PRCO_SETOPT     1
391 
392 #define PRCO_NCMDS      2
393 
394 #ifdef PRCOREQUESTS
395 char    *prcorequests[] = {
396 	"GETOPT", "SETOPT",
397 };
398 #endif /* PRCOREQUESTS */
399 
400 /*
401  * In earlier BSD network stacks, a single pr_usrreq() function pointer was
402  * invoked with an operation number indicating what operation was desired.
403  * We now provide individual function pointers which protocols can implement,
404  * which offers a number of benefits (such as type checking for arguments).
405  * These older constants are still present in order to support TCP debugging.
406  */
407 #define PRU_ATTACH              0       /* attach protocol to up */
408 #define PRU_DETACH              1       /* detach protocol from up */
409 #define PRU_BIND                2       /* bind socket to address */
410 #define PRU_LISTEN              3       /* listen for connection */
411 #define PRU_CONNECT             4       /* establish connection to peer */
412 #define PRU_ACCEPT              5       /* accept connection from peer */
413 #define PRU_DISCONNECT          6       /* disconnect from peer */
414 #define PRU_SHUTDOWN            7       /* won't send any more data */
415 #define PRU_RCVD                8       /* have taken data; more room now */
416 #define PRU_SEND                9       /* send this data */
417 #define PRU_ABORT               10      /* abort (fast DISCONNECT, DETATCH) */
418 #define PRU_CONTROL             11      /* control operations on protocol */
419 #define PRU_SENSE               12      /* return status into m */
420 #define PRU_RCVOOB              13      /* retrieve out of band data */
421 #define PRU_SENDOOB             14      /* send out of band data */
422 #define PRU_SOCKADDR            15      /* fetch socket's address */
423 #define PRU_PEERADDR            16      /* fetch peer's address */
424 #define PRU_CONNECT2            17      /* connect two sockets */
425 /* begin for protocols internal use */
426 #define PRU_FASTTIMO            18      /* 200ms timeout */
427 #define PRU_SLOWTIMO            19      /* 500ms timeout */
428 #define PRU_PROTORCV            20      /* receive from below */
429 #define PRU_PROTOSEND           21      /* send to below */
430 /* end for protocol's internal use */
431 #define PRU_SEND_EOF            22      /* send and close */
432 #define PRU_NREQ                22
433 
434 #ifdef PRUREQUESTS
435 char *prurequests[] = {
436 	"ATTACH", "DETACH", "BIND", "LISTEN",
437 	"CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN",
438 	"RCVD", "SEND", "ABORT", "CONTROL",
439 	"SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
440 	"PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO",
441 	"PROTORCV", "PROTOSEND", "SEND_EOF",
442 };
443 #endif /* PRUREQUESTS */
444 #endif /* BSD_KERNEL_PRIVATE */
445 
446 struct stat;
447 struct ucred;
448 struct uio;
449 struct recv_msg_elem;
450 
451 #ifdef XNU_KERNEL_PRIVATE
452 /*
453  * Legacy user-protocol hooks.
454  *
455  * NOTE: Do not modify this structure, as there are modules outside of xnu
456  * which rely on the size and layout for binary compatibility.  This structure
457  * is simply used by the protosw_old structure.  Internally, user-protocol
458  * hooks use the private variant of pr_usrreqs defined down below.
459  */
460 struct pr_usrreqs_old {
461 #else
462 struct pr_usrreqs {
463 #endif /* !XNU_KERNEL_PRIVATE */
464 	int     (*pru_abort)(struct socket *so);
465 	int     (*pru_accept)(struct socket *so, struct sockaddr **nam);
466 	int     (*pru_attach)(struct socket *so, int proto, struct proc *p);
467 	int     (*pru_bind)(struct socket *so, struct sockaddr *nam,
468 	    struct proc *p);
469 	int     (*pru_connect)(struct socket *so, struct sockaddr *nam,
470 	    struct proc *p);
471 	int     (*pru_connect2)(struct socket *so1, struct socket *so2);
472 	int     (*pru_control)(struct socket *so, u_long cmd, caddr_t data,
473 	    struct ifnet *ifp, struct proc *p);
474 	int     (*pru_detach)(struct socket *so);
475 	int     (*pru_disconnect)(struct socket *so);
476 	int     (*pru_listen)(struct socket *so, struct proc *p);
477 	int     (*pru_peeraddr)(struct socket *so, struct sockaddr **nam);
478 	int     (*pru_rcvd)(struct socket *so, int flags);
479 	int     (*pru_rcvoob)(struct socket *so, struct mbuf *m, int flags);
480 	int     (*pru_send)(struct socket *so, int flags, struct mbuf *m,
481 	    struct sockaddr *addr, struct mbuf *control,
482 	    struct proc *p);
483 	int     (*pru_sense)(struct socket *so, void  *sb, int isstat64);
484 	int     (*pru_shutdown)(struct socket *so);
485 	int     (*pru_sockaddr)(struct socket *so, struct sockaddr **nam);
486 	int     (*pru_sosend)(struct socket *so, struct sockaddr *addr,
487 	    struct uio *uio, struct mbuf *top, struct mbuf *control,
488 	    int flags);
489 	// rdar://87088674
490 	int     (*pru_soreceive)(struct socket *so, struct sockaddr **paddr,
491 	    struct uio *uio, struct mbuf **mp0, struct mbuf *__single *controlp,
492 	    int *flagsp);
493 	int     (*pru_sopoll)(struct socket *so, int events,
494 	    struct ucred *cred, void *);
495 };
496 
497 #ifdef XNU_KERNEL_PRIVATE
498 /*
499  * If the ordering here looks odd, that's because it's alphabetical.  These
500  * should eventually be merged back into struct protosw.
501  *
502  * Internal, private and extendable representation of pr_usrreqs.
503  *
504  * NOTE: When adding new ones, also add default callbacks in pru_sanitize().
505  */
506 struct pr_usrreqs {
507 	uint32_t pru_flags;     /* see PRUF flags below */
508 	int     (*pru_abort)(struct socket *);
509 	int     (*pru_accept)(struct socket *, struct sockaddr **);
510 	int     (*pru_attach)(struct socket *, int proto, struct proc *);
511 	int     (*pru_bind)(struct socket *, struct sockaddr *, struct proc *);
512 	int     (*pru_connect)(struct socket *, struct sockaddr *,
513 	    struct proc *);
514 	int     (*pru_connect2)(struct socket *, struct socket *);
515 	int     (*pru_connectx)(struct socket *, struct sockaddr *,
516 	    struct sockaddr *, struct proc *, uint32_t,
517 	    sae_associd_t, sae_connid_t *, uint32_t, void *, uint32_t,
518 	    struct uio *, user_ssize_t *);
519 	int     (*pru_control)(struct socket *, u_long, caddr_t,
520 	    struct ifnet *, struct proc *);
521 	int     (*pru_detach)(struct socket *);
522 	int     (*pru_disconnect)(struct socket *);
523 	int     (*pru_disconnectx)(struct socket *,
524 	    sae_associd_t, sae_connid_t);
525 	int     (*pru_listen)(struct socket *, struct proc *);
526 	int     (*pru_peeraddr)(struct socket *, struct sockaddr **);
527 	int     (*pru_rcvd)(struct socket *, int);
528 	int     (*pru_rcvoob)(struct socket *, struct mbuf *, int);
529 	int     (*pru_send)(struct socket *, int, struct mbuf *,
530 	    struct sockaddr *, struct mbuf *, struct proc *);
531 	int     (*pru_send_list)(struct socket *, int, struct mbuf *,
532 	    struct sockaddr *, struct mbuf *, struct proc *);
533 #define PRUS_OOB        0x1
534 #define PRUS_EOF        0x2
535 #define PRUS_MORETOCOME 0x4
536 	int     (*pru_sense)(struct socket *, void *, int);
537 	int     (*pru_shutdown)(struct socket *);
538 	int     (*pru_sockaddr)(struct socket *, struct sockaddr **);
539 	int     (*pru_sopoll)(struct socket *, int, struct ucred *, void *);
540 	int     (*pru_soreceive)(struct socket *, struct sockaddr **,
541 	    struct uio *, struct mbuf **, struct mbuf **, int *);
542 	int     (*pru_soreceive_list)(struct socket *, struct recv_msg_elem *, u_int,
543 	    int *);
544 	int     (*pru_sosend)(struct socket *, struct sockaddr *,
545 	    struct uio *, struct mbuf *, struct mbuf *, int);
546 	int     (*pru_sosend_list)(struct socket *, struct uio **, u_int, int);
547 	int     (*pru_socheckopt)(struct socket *, struct sockopt *);
548 	int     (*pru_preconnect)(struct socket *so);
549 	int     (*pru_defunct)(struct socket *);
550 };
551 
552 /* Values for pru_flags  */
553 #define PRUF_OLD        0x10000000      /* added via net_add_proto */
554 
555 #ifdef BSD_KERNEL_PRIVATE
556 /*
557  * For faster access than net_uptime(), bypassing the initialization.
558  */
559 extern u_int64_t _net_uptime;
560 #endif /* BSD_KERNEL_PRIVATE */
561 #endif /* XNU_KERNEL_PRIVATE */
562 
563 __BEGIN_DECLS
564 extern int pru_abort_notsupp(struct socket *so);
565 extern int pru_accept_notsupp(struct socket *so, struct sockaddr **nam);
566 extern int pru_attach_notsupp(struct socket *so, int proto, struct proc *p);
567 extern int pru_bind_notsupp(struct socket *so, struct sockaddr *nam,
568     struct proc *p);
569 extern int pru_connect_notsupp(struct socket *so, struct sockaddr *nam,
570     struct proc *p);
571 extern int pru_connect2_notsupp(struct socket *so1, struct socket *so2);
572 #ifdef XNU_KERNEL_PRIVATE
573 extern int pru_connectx_notsupp(struct socket *, struct sockaddr *,
574     struct sockaddr *, struct proc *, uint32_t, sae_associd_t,
575     sae_connid_t *, uint32_t, void *, uint32_t, struct uio *, user_ssize_t *);
576 extern int pru_disconnectx_notsupp(struct socket *, sae_associd_t,
577     sae_connid_t);
578 extern int pru_socheckopt_null(struct socket *, struct sockopt *);
579 #endif /* XNU_KERNEL_PRIVATE */
580 extern int pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data,
581     struct ifnet *ifp, struct proc *p);
582 extern int pru_detach_notsupp(struct socket *so);
583 extern int pru_disconnect_notsupp(struct socket *so);
584 extern int pru_listen_notsupp(struct socket *so, struct proc *p);
585 extern int pru_peeraddr_notsupp(struct socket *so, struct sockaddr **nam);
586 extern int pru_rcvd_notsupp(struct socket *so, int flags);
587 extern int pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags);
588 extern int pru_send_notsupp(struct socket *so, int flags, struct mbuf *m,
589     struct sockaddr *addr, struct mbuf *control, struct proc *p);
590 extern int pru_send_list_notsupp(struct socket *so, int flags, struct mbuf *m,
591     struct sockaddr *addr, struct mbuf *control, struct proc *p);
592 extern int pru_sense_null(struct socket *so, void * sb, int isstat64);
593 extern int pru_shutdown_notsupp(struct socket *so);
594 extern int pru_sockaddr_notsupp(struct socket *so, struct sockaddr **nam);
595 extern int pru_sosend_notsupp(struct socket *so, struct sockaddr *addr,
596     struct uio *uio, struct mbuf *top, struct mbuf *control, int flags);
597 extern int pru_sosend_list_notsupp(struct socket *so, struct uio **uio,
598     u_int, int flags);
599 extern int pru_soreceive_notsupp(struct socket *so,
600     struct sockaddr **paddr, struct uio *uio, struct mbuf **mp0,
601     struct mbuf **controlp, int *flagsp);
602 extern int pru_soreceive_list_notsupp(struct socket *, struct recv_msg_elem *, u_int,
603     int *);
604 extern int pru_sopoll_notsupp(struct socket *so, int events,
605     struct ucred *cred, void *);
606 #ifdef XNU_KERNEL_PRIVATE
607 extern void pru_sanitize(struct pr_usrreqs *);
608 extern void domaininit(void);
609 extern void domainfin(void);
610 extern void pfctlinput(int, struct sockaddr *);
611 extern void pfctlinput2(int, struct sockaddr *, void *);
612 extern struct protosw *pffindproto_locked(int, int, int);
613 extern struct protosw *pffindprotonotype(int, int);
614 extern struct protosw *pffindtype(int, int);
615 extern struct protosw_old *pffindproto_old(int, int, int);
616 extern int net_add_proto(struct protosw *, struct domain *, int)
617 __XNU_INTERNAL(net_add_proto);
618 extern void net_init_proto(struct protosw *, struct domain *);
619 extern int net_del_proto(int, int, struct domain *)
620 __XNU_INTERNAL(net_del_proto);
621 extern int net_add_proto_old(struct protosw_old *, struct domain_old *);
622 extern int net_del_proto_old(int, int, struct domain_old *);
623 extern void net_update_uptime(void);
624 extern void net_update_uptime_with_time(const struct timeval *);
625 extern u_int64_t net_uptime(void);
626 extern u_int64_t net_uptime_ms(void);
627 extern void net_uptime2timeval(struct timeval *);
628 extern struct protosw *pffindproto(int family, int protocol, int type)
629 __XNU_INTERNAL(pffindproto);
630 #else
631 extern int net_add_proto(struct protosw *, struct domain *);
632 extern int net_del_proto(int, int, struct domain *);
633 extern struct protosw *pffindproto(int family, int protocol, int type);
634 #endif /* XNU_KERNEL_PRIVATE */
635 __END_DECLS
636 #endif /* KERNEL_PRIVATE */
637 
638 __ASSUME_PTR_ABI_SINGLE_END
639 
640 #endif  /* !_SYS_PROTOSW_H_ */
641