2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
31 * @(#)protosw.h 8.1 (Berkeley) 6/2/93
35 #ifndef _SYS_PROTOSW_H_
36 #define _SYS_PROTOSW_H_
38 #include <sys/queue.h>
40 /* Forward declare these structures referenced from prototypes below. */
50 * Protocol switch table.
52 * Each protocol has a handle initializing one of these structures,
53 * which is used for protocol-protocol and system-protocol communication.
55 * In retrospect, it would be a lot nicer to use an interface
56 * similar to the vnode VOP interface.
63 /* USE THESE FOR YOUR PROTOTYPES ! */
64 typedef int pr_ctloutput_t(struct socket *, struct sockopt *);
65 typedef void pr_abort_t(struct socket *);
66 typedef int pr_accept_t(struct socket *, struct sockaddr **);
67 typedef int pr_attach_t(struct socket *, int, struct thread *);
68 typedef int pr_bind_t(struct socket *, struct sockaddr *, struct thread *);
69 typedef int pr_connect_t(struct socket *, struct sockaddr *,
71 typedef int pr_connect2_t(struct socket *, struct socket *);
72 typedef int pr_control_t(struct socket *, unsigned long, void *,
73 struct ifnet *, struct thread *);
74 typedef void pr_detach_t(struct socket *);
75 typedef int pr_disconnect_t(struct socket *);
76 typedef int pr_listen_t(struct socket *, int, struct thread *);
77 typedef int pr_peeraddr_t(struct socket *, struct sockaddr **);
78 typedef int pr_rcvd_t(struct socket *, int);
79 typedef int pr_rcvoob_t(struct socket *, struct mbuf *, int);
83 PRUS_MORETOCOME = 0x4,
87 typedef int pr_send_t(struct socket *, int, struct mbuf *,
88 struct sockaddr *, struct mbuf *, struct thread *);
89 typedef int pr_ready_t(struct socket *, struct mbuf *, int);
90 typedef int pr_sense_t(struct socket *, struct stat *);
91 typedef int pr_shutdown_t(struct socket *);
92 typedef int pr_flush_t(struct socket *, int);
93 typedef int pr_sockaddr_t(struct socket *, struct sockaddr **);
94 typedef int pr_sosend_t(struct socket *, struct sockaddr *, struct uio *,
95 struct mbuf *, struct mbuf *, int, struct thread *);
96 typedef int pr_soreceive_t(struct socket *, struct sockaddr **,
97 struct uio *, struct mbuf **, struct mbuf **, int *);
98 typedef int pr_sopoll_t(struct socket *, int, struct ucred *,
100 typedef void pr_sosetlabel_t(struct socket *);
101 typedef void pr_close_t(struct socket *);
102 typedef int pr_bindat_t(int, struct socket *, struct sockaddr *,
104 typedef int pr_connectat_t(int, struct socket *, struct sockaddr *,
106 typedef int pr_aio_queue_t(struct socket *, struct kaiocb *);
109 short pr_type; /* socket type used for */
110 short pr_protocol; /* protocol number */
111 short pr_flags; /* see below */
113 struct domain *pr_domain; /* domain protocol a member of */
115 pr_soreceive_t *pr_soreceive; /* recv(2) */
116 pr_rcvd_t *pr_rcvd; /* soreceive_generic() if PR_WANTRCVD */
117 pr_sosend_t *pr_sosend; /* send(2) */
118 pr_send_t *pr_send; /* send(2) via sosend_generic() */
119 pr_ready_t *pr_ready; /* sendfile/ktls readyness */
120 pr_sopoll_t *pr_sopoll; /* poll(2) */
122 pr_attach_t *pr_attach; /* creation: socreate(), sonewconn() */
123 pr_detach_t *pr_detach; /* destruction: sofree() */
124 pr_connect_t *pr_connect; /* connect(2) */
125 pr_disconnect_t *pr_disconnect; /* sodisconnect() */
126 pr_close_t *pr_close; /* close(2) */
127 pr_shutdown_t *pr_shutdown; /* shutdown(2) */
128 pr_abort_t *pr_abort; /* abrupt tear down: soabort() */
129 pr_aio_queue_t *pr_aio_queue; /* aio(9) */
131 pr_bind_t *pr_bind; /* bind(2) */
132 pr_bindat_t *pr_bindat; /* bindat(2) */
133 pr_listen_t *pr_listen; /* listen(2) */
134 pr_accept_t *pr_accept; /* accept(2) */
135 pr_connectat_t *pr_connectat; /* connectat(2) */
136 pr_connect2_t *pr_connect2; /* socketpair(2) */
137 pr_control_t *pr_control; /* ioctl(2) */
138 pr_rcvoob_t *pr_rcvoob; /* soreceive_rcvoob() */
140 pr_ctloutput_t *pr_ctloutput; /* control output (from above) */
141 pr_peeraddr_t *pr_peeraddr; /* getpeername(2) */
142 pr_sockaddr_t *pr_sockaddr; /* getsockname(2) */
143 pr_sense_t *pr_sense; /* stat(2) */
144 pr_flush_t *pr_flush; /* XXXGL: merge with pr_shutdown_t! */
145 pr_sosetlabel_t *pr_sosetlabel; /* MAC, XXXGL: remove */
150 * Values for pr_flags.
151 * PR_ADDR requires PR_ATOMIC;
152 * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
153 * PR_IMPLOPCL means that the protocol allows sendto without prior connect,
154 * and the protocol understands the MSG_EOF flag. The first property is
155 * is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed
157 * PR_SOCKBUF requires protocol to initialize and destroy its socket buffers
158 * in its pr_attach and pr_detach.
160 #define PR_ATOMIC 0x01 /* exchange atomic messages only */
161 #define PR_ADDR 0x02 /* addresses given with messages */
162 #define PR_CONNREQUIRED 0x04 /* connection required by protocol */
163 #define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
164 #define PR_RIGHTS 0x10 /* passes capabilities */
165 #define PR_IMPLOPCL 0x20 /* implied open/close */
166 /* was PR_LASTHDR 0x40 enforce ipsec policy; last header */
167 #define PR_CAPATTACH 0x80 /* socket can attach in cap mode */
168 #define PR_SOCKBUF 0x100 /* private implementation of buffers */
171 * The arguments to the ctlinput routine are
172 * (*protosw[].pr_ctlinput)(cmd, sa, arg);
173 * where cmd is one of the commands below, sa is a pointer to a sockaddr,
174 * and arg is a `void *' argument used within a protocol family.
176 #define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
177 /* was PRC_QUENCH2 3 DEC congestion bit says slow down */
178 /* was PRC_QUENCH 4 Deprecated by RFC 6633 */
179 #define PRC_MSGSIZE 5 /* message size forced drop */
180 #define PRC_HOSTDEAD 6 /* host appears to be down */
181 #define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */
182 #define PRC_UNREACH_NET 8 /* no route to network */
183 #define PRC_UNREACH_HOST 9 /* no route to host */
184 #define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */
185 #define PRC_UNREACH_PORT 11 /* bad port # */
186 /* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */
187 #define PRC_UNREACH_SRCFAIL 13 /* source route failed */
188 #define PRC_REDIRECT_NET 14 /* net routing redirect */
189 #define PRC_REDIRECT_HOST 15 /* host routing redirect */
190 #define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */
191 #define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */
192 #define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
193 #define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
194 #define PRC_PARAMPROB 20 /* header incorrect */
195 #define PRC_UNREACH_ADMIN_PROHIB 21 /* packet administrativly prohibited */
199 #define PRC_IS_REDIRECT(cmd) \
200 ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
203 char *prcrequests[] = {
204 "IFDOWN", "ROUTEDEAD", "IFUP", "DEC-BIT-QUENCH2",
205 "QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
206 "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
207 "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
208 "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
209 "PARAMPROB", "ADMIN-UNREACH"
214 * The arguments to ctloutput are:
215 * (*protosw[].pr_ctloutput)(req, so, level, optname, optval, p);
216 * req is one of the actions listed below, so is a (struct socket *),
217 * level is an indication of which protocol layer the option is intended.
218 * optname is a protocol dependent socket option request,
219 * optval is a pointer to a mbuf-chain pointer, for value-return results.
220 * The protocol is responsible for disposal of the mbuf chain *optval
222 * the caller is responsible for any space held by *optval, when returned.
223 * A non-zero return from ctloutput gives an
224 * UNIX error number which should be passed to higher level software.
226 #define PRCO_GETOPT 0
227 #define PRCO_SETOPT 1
232 char *prcorequests[] = {
238 struct domain *pffinddomain(int family);
239 struct protosw *pffindtype(int family, int type);
240 int protosw_register(struct domain *, struct protosw *);
241 int protosw_unregister(struct protosw *);
243 /* Domains that are known to be avaliable for protosw_register(). */
244 extern struct domain inetdomain;
245 extern struct domain inet6domain;