| 1 | /*- |
| 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * |
| 4 | * Copyright (c) 1982, 1986, 1993 |
| 5 | *	The Regents of the University of California. All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. Neither the name of the University nor the names of its contributors |
| 16 | * may be used to endorse or promote products derived from this software |
| 17 | * without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 29 | * SUCH DAMAGE. |
| 30 | */ |
| 31 | |
| 32 | #ifndef _SYS_PROTOSW_H_ |
| 33 | #define _SYS_PROTOSW_H_ |
| 34 | #if defined(_KERNEL) || defined(_WANT_PROTOSW) |
| 35 | /* |
| 36 | * Protocol switch table. |
| 37 | * |
| 38 | * Each protocol has a handle initializing one of these structures, |
| 39 | * which is used for protocol-protocol and system-protocol communication. |
| 40 | * |
| 41 | * In retrospect, it would be a lot nicer to use an interface |
| 42 | * similar to the vnode VOP interface. |
| 43 | */ |
| 44 | struct socket; |
| 45 | struct sockopt; |
| 46 | struct thread; |
| 47 | struct sockaddr; |
| 48 | struct ifnet; |
| 49 | struct mbuf; |
| 50 | struct stat; |
| 51 | struct ucred; |
| 52 | struct uio; |
| 53 | struct kaiocb; |
| 54 | struct knote; |
| 55 | enum shutdown_how; |
| 56 | |
| 57 | /* USE THESE FOR YOUR PROTOTYPES ! */ |
| 58 | typedef int	pr_ctloutput_t(struct socket *, struct sockopt *); |
| 59 | typedef int	pr_setsbopt_t(struct socket *, struct sockopt *); |
| 60 | typedef void	pr_abort_t(struct socket *); |
| 61 | typedef int	pr_accept_t(struct socket *, struct sockaddr *); |
| 62 | typedef int	pr_attach_t(struct socket *, int, struct thread *); |
| 63 | typedef int	pr_bind_t(struct socket *, struct sockaddr *, struct thread *); |
| 64 | typedef int	pr_connect_t(struct socket *, struct sockaddr *, |
| 65 | 		 struct thread *); |
| 66 | typedef int	pr_connect2_t(struct socket *, struct socket *); |
| 67 | typedef int	pr_control_t(struct socket *, unsigned long, void *, |
| 68 | 		 struct ifnet *, struct thread *); |
| 69 | typedef void	pr_detach_t(struct socket *); |
| 70 | typedef int	pr_disconnect_t(struct socket *); |
| 71 | typedef int	pr_listen_t(struct socket *, int, struct thread *); |
| 72 | typedef int	pr_peeraddr_t(struct socket *, struct sockaddr *); |
| 73 | typedef int	pr_rcvd_t(struct socket *, int); |
| 74 | typedef int	pr_rcvoob_t(struct socket *, struct mbuf *, int); |
| 75 | typedef enum { |
| 76 | 	PRUS_OOB =		0x1, |
| 77 | 	PRUS_EOF =		0x2, |
| 78 | 	PRUS_MORETOCOME =	0x4, |
| 79 | 	PRUS_NOTREADY =		0x8, |
| 80 | 	PRUS_IPV6 =		0x10, |
| 81 | } pr_send_flags_t; |
| 82 | typedef int	pr_send_t(struct socket *, int, struct mbuf *, |
| 83 | 		 struct sockaddr *, struct mbuf *, struct thread *); |
| 84 | typedef	int	pr_sendfile_wait_t(struct socket *, off_t, int *); |
| 85 | typedef int	pr_ready_t(struct socket *, struct mbuf *, int); |
| 86 | typedef int	pr_sense_t(struct socket *, struct stat *); |
| 87 | typedef int	pr_shutdown_t(struct socket *, enum shutdown_how); |
| 88 | typedef int	pr_sockaddr_t(struct socket *, struct sockaddr *); |
| 89 | typedef int	pr_sosend_t(struct socket *, struct sockaddr *, struct uio *, |
| 90 | 		 struct mbuf *, struct mbuf *, int, struct thread *); |
| 91 | typedef int	pr_soreceive_t(struct socket *, struct sockaddr **, |
| 92 | 		 struct uio *, struct mbuf **, struct mbuf **, int *); |
| 93 | typedef int	pr_sopoll_t(struct socket *, int, struct thread *); |
| 94 | typedef int	pr_kqfilter_t(struct socket *, struct knote *); |
| 95 | typedef void	pr_sosetlabel_t(struct socket *); |
| 96 | typedef void	pr_close_t(struct socket *); |
| 97 | typedef int	pr_bindat_t(int, struct socket *, struct sockaddr *, |
| 98 | 		 struct thread *); |
| 99 | typedef int	pr_connectat_t(int, struct socket *, struct sockaddr *, |
| 100 | 		 struct thread *); |
| 101 | typedef int	pr_aio_queue_t(struct socket *, struct kaiocb *); |
| 102 | typedef int	pr_chmod_t(struct socket *, __mode_t, struct ucred *, |
| 103 | 		 struct thread *); |
| 104 | |
| 105 | struct protosw { |
| 106 | 	short	pr_type;		/* socket type used for */ |
| 107 | 	short	pr_protocol;		/* protocol number */ |
| 108 | 	short	pr_flags;		/* see below */ |
| 109 | 	short	pr_unused; |
| 110 | 	struct	domain	*pr_domain;	/* domain protocol a member of */ |
| 111 | |
| 112 | 	pr_soreceive_t	*pr_soreceive;	/* recv(2) */ |
| 113 | 	pr_sosend_t	*pr_sosend;	/* send(2) */ |
| 114 | 	pr_send_t	*pr_send;	/* send(2) via sosend_generic() */ |
| 115 | 	pr_sendfile_wait_t *pr_sendfile_wait;	/* sendfile helper */ |
| 116 | 	pr_ready_t	*pr_ready;	/* sendfile/ktls readyness */ |
| 117 | 	pr_sopoll_t	*pr_sopoll;	/* poll(2) */ |
| 118 | /* Cache line #2 */ |
| 119 | 	pr_attach_t	*pr_attach;	/* creation: socreate(), sonewconn() */ |
| 120 | 	pr_detach_t	*pr_detach;	/* destruction: sofree() */ |
| 121 | 	pr_connect_t	*pr_connect;	/* connect(2) */ |
| 122 | 	pr_disconnect_t	*pr_disconnect;	/* sodisconnect() */ |
| 123 | 	pr_close_t	*pr_close;	/* close(2) */ |
| 124 | 	pr_shutdown_t	*pr_shutdown;	/* shutdown(2) */ |
| 125 | 	pr_rcvd_t	*pr_rcvd;	/* soreceive_generic() if PR_WANTRCVD */ |
| 126 | 	pr_aio_queue_t	*pr_aio_queue;	/* aio(9) */ |
| 127 | /* Cache line #3 */ |
| 128 | 	pr_bind_t	*pr_bind;	/* bind(2) */ |
| 129 | 	pr_bindat_t	*pr_bindat;	/* bindat(2) */ |
| 130 | 	pr_listen_t	*pr_listen;	/* listen(2) */ |
| 131 | 	pr_accept_t	*pr_accept;	/* accept(2) */ |
| 132 | 	pr_connectat_t	*pr_connectat;	/* connectat(2) */ |
| 133 | 	pr_connect2_t	*pr_connect2;	/* socketpair(2) */ |
| 134 | 	pr_control_t	*pr_control;	/* ioctl(2) */ |
| 135 | 	pr_rcvoob_t	*pr_rcvoob;	/* soreceive_rcvoob() */ |
| 136 | /* Cache line #4 */ |
| 137 | 	pr_abort_t	*pr_abort;	/* abrupt tear down: soabort() */ |
| 138 | 	pr_ctloutput_t	*pr_ctloutput;	/* control output (from above) */ |
| 139 | 	pr_peeraddr_t	*pr_peeraddr;	/* getpeername(2) */ |
| 140 | 	pr_sockaddr_t	*pr_sockaddr;	/* getsockname(2) */ |
| 141 | 	pr_sense_t	*pr_sense;	/* stat(2) */ |
| 142 | 	pr_sosetlabel_t	*pr_sosetlabel;	/* MAC, XXXGL: remove */ |
| 143 | 	pr_setsbopt_t	*pr_setsbopt;	/* Socket buffer ioctls */ |
| 144 | 	pr_chmod_t	*pr_chmod;	/* fchmod(2) */ |
| 145 | 	pr_kqfilter_t	*pr_kqfilter;	/* kevent(2) */ |
| 146 | }; |
| 147 | #endif	/* defined(_KERNEL) || defined(_WANT_PROTOSW) */ |
| 148 | #ifdef _KERNEL |
| 149 | |
| 150 | /* |
| 151 | * Values for pr_flags. |
| 152 | * PR_ADDR requires PR_ATOMIC; |
| 153 | * PR_ADDR and PR_CONNREQUIRED are mutually exclusive. |
| 154 | * PR_IMPLOPCL means that the protocol allows sendto without prior connect, |
| 155 | *	and the protocol understands the MSG_EOF flag. The first property is |
| 156 | *	is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed |
| 157 | *	anyhow). |
| 158 | * PR_SOCKBUF requires protocol to initialize and destroy its socket buffers |
| 159 | * in its pr_attach and pr_detach. |
| 160 | */ |
| 161 | #define	PR_ATOMIC	0x01		/* exchange atomic messages only */ |
| 162 | #define	PR_ADDR		0x02		/* addresses given with messages */ |
| 163 | #define	PR_CONNREQUIRED	0x04		/* connection required by protocol */ |
| 164 | #define	PR_WANTRCVD	0x08		/* want PRU_RCVD calls */ |
| 165 | /* was	PR_RIGHTS	0x10		 passes capabilities */ |
| 166 | #define PR_IMPLOPCL	0x20		/* implied open/close */ |
| 167 | /* was	PR_LASTHDR	0x40		 enforce ipsec policy; last header */ |
| 168 | #define	PR_CAPATTACH	0x80		/* socket can attach in cap mode */ |
| 169 | #define	PR_SOCKBUF	0x100		/* private implementation of buffers */ |
| 170 | |
| 171 | struct domain *pffinddomain(int family); |
| 172 | struct protosw *pffindproto(int family, int type, int proto); |
| 173 | int protosw_register(struct domain *, struct protosw *); |
| 174 | int protosw_unregister(struct protosw *); |
| 175 | |
| 176 | /* Domains that are known to be avaliable for protosw_register(). */ |
| 177 | extern struct domain inetdomain; |
| 178 | extern struct domain inet6domain; |
| 179 | #endif |
| 180 | #endif |