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 struct domain *pr_domain; /* domain protocol a member of */
111 short pr_protocol; /* protocol number */
112 short pr_flags; /* see below */
113 /* protocol-protocol hooks */
114 pr_ctloutput_t *pr_ctloutput; /* control output (from above) */
117 struct pr_usrreqs *pr_usrreqs; /* user-protocol hook */
122 * This number should be defined again within each protocol family to avoid
125 #define PROTO_SPACER 32767 /* spacer for loadable protocols */
128 * Values for pr_flags.
129 * PR_ADDR requires PR_ATOMIC;
130 * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
131 * PR_IMPLOPCL means that the protocol allows sendto without prior connect,
132 * and the protocol understands the MSG_EOF flag. The first property is
133 * is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed
135 * PR_SOCKBUF requires protocol to initialize and destroy its socket buffers
136 * in its pr_attach and pr_detach.
138 #define PR_ATOMIC 0x01 /* exchange atomic messages only */
139 #define PR_ADDR 0x02 /* addresses given with messages */
140 #define PR_CONNREQUIRED 0x04 /* connection required by protocol */
141 #define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
142 #define PR_RIGHTS 0x10 /* passes capabilities */
143 #define PR_IMPLOPCL 0x20 /* implied open/close */
144 /* was PR_LASTHDR 0x40 enforce ipsec policy; last header */
145 #define PR_CAPATTACH 0x80 /* socket can attach in cap mode */
146 #define PR_SOCKBUF 0x100 /* private implementation of buffers */
148 #ifdef _KERNEL /* users shouldn't see this decl */
156 * If the ordering here looks odd, that's because it's alphabetical. These
157 * should eventually be merged back into struct protosw.
159 * Some fields initialized to defaults if they are NULL.
162 pr_abort_t *pru_abort;
163 pr_accept_t *pru_accept;
164 pr_attach_t *pru_attach;
166 pr_connect_t *pru_connect;
167 pr_connect2_t *pru_connect2;
168 pr_control_t *pru_control;
169 pr_detach_t *pru_detach;
170 pr_disconnect_t *pru_disconnect;
171 pr_listen_t *pru_listen;
172 pr_peeraddr_t *pru_peeraddr;
174 pr_rcvoob_t *pru_rcvoob;
176 pr_ready_t *pru_ready;
177 pr_sense_t *pru_sense;
178 pr_shutdown_t *pru_shutdown;
179 pr_flush_t *pru_flush;
180 pr_sockaddr_t *pru_sockaddr;
181 pr_sosend_t *pru_sosend;
182 pr_soreceive_t *pru_soreceive;
183 pr_sopoll_t *pru_sopoll;
184 pr_sosetlabel_t *pru_sosetlabel;
185 pr_close_t *pru_close;
186 pr_bindat_t *pru_bindat;
187 pr_connectat_t *pru_connectat;
188 pr_aio_queue_t *pru_aio_queue;
192 * All nonvoid pru_*() functions below return EOPNOTSUPP.
194 int pru_accept_notsupp(struct socket *so, struct sockaddr **nam);
195 int pru_aio_queue_notsupp(struct socket *so, struct kaiocb *job);
196 int pru_attach_notsupp(struct socket *so, int proto, struct thread *td);
197 int pru_bind_notsupp(struct socket *so, struct sockaddr *nam,
199 int pru_bindat_notsupp(int fd, struct socket *so, struct sockaddr *nam,
201 int pru_connect_notsupp(struct socket *so, struct sockaddr *nam,
203 int pru_connectat_notsupp(int fd, struct socket *so, struct sockaddr *nam,
205 int pru_connect2_notsupp(struct socket *so1, struct socket *so2);
206 int pru_control_notsupp(struct socket *so, u_long cmd, void *data,
207 struct ifnet *ifp, struct thread *td);
208 int pru_disconnect_notsupp(struct socket *so);
209 int pru_listen_notsupp(struct socket *so, int backlog, struct thread *td);
210 int pru_peeraddr_notsupp(struct socket *so, struct sockaddr **nam);
211 int pru_rcvd_notsupp(struct socket *so, int flags);
212 int pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags);
213 int pru_send_notsupp(struct socket *so, int flags, struct mbuf *m,
214 struct sockaddr *addr, struct mbuf *control, struct thread *td);
215 int pru_ready_notsupp(struct socket *so, struct mbuf *m, int count);
216 int pru_sense_null(struct socket *so, struct stat *sb);
217 int pru_shutdown_notsupp(struct socket *so);
218 int pru_sockaddr_notsupp(struct socket *so, struct sockaddr **nam);
219 int pru_sosend_notsupp(struct socket *so, struct sockaddr *addr,
220 struct uio *uio, struct mbuf *top, struct mbuf *control, int flags,
222 int pru_soreceive_notsupp(struct socket *so, struct sockaddr **paddr,
223 struct uio *uio, struct mbuf **mp0, struct mbuf **controlp,
225 int pru_sopoll_notsupp(struct socket *so, int events, struct ucred *cred,
231 * The arguments to the ctlinput routine are
232 * (*protosw[].pr_ctlinput)(cmd, sa, arg);
233 * where cmd is one of the commands below, sa is a pointer to a sockaddr,
234 * and arg is a `void *' argument used within a protocol family.
236 #define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
237 /* was PRC_QUENCH2 3 DEC congestion bit says slow down */
238 /* was PRC_QUENCH 4 Deprecated by RFC 6633 */
239 #define PRC_MSGSIZE 5 /* message size forced drop */
240 #define PRC_HOSTDEAD 6 /* host appears to be down */
241 #define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */
242 #define PRC_UNREACH_NET 8 /* no route to network */
243 #define PRC_UNREACH_HOST 9 /* no route to host */
244 #define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */
245 #define PRC_UNREACH_PORT 11 /* bad port # */
246 /* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */
247 #define PRC_UNREACH_SRCFAIL 13 /* source route failed */
248 #define PRC_REDIRECT_NET 14 /* net routing redirect */
249 #define PRC_REDIRECT_HOST 15 /* host routing redirect */
250 #define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */
251 #define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */
252 #define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
253 #define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
254 #define PRC_PARAMPROB 20 /* header incorrect */
255 #define PRC_UNREACH_ADMIN_PROHIB 21 /* packet administrativly prohibited */
259 #define PRC_IS_REDIRECT(cmd) \
260 ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
263 char *prcrequests[] = {
264 "IFDOWN", "ROUTEDEAD", "IFUP", "DEC-BIT-QUENCH2",
265 "QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
266 "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
267 "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
268 "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
269 "PARAMPROB", "ADMIN-UNREACH"
274 * The arguments to ctloutput are:
275 * (*protosw[].pr_ctloutput)(req, so, level, optname, optval, p);
276 * req is one of the actions listed below, so is a (struct socket *),
277 * level is an indication of which protocol layer the option is intended.
278 * optname is a protocol dependent socket option request,
279 * optval is a pointer to a mbuf-chain pointer, for value-return results.
280 * The protocol is responsible for disposal of the mbuf chain *optval
282 * the caller is responsible for any space held by *optval, when returned.
283 * A non-zero return from ctloutput gives an
284 * UNIX error number which should be passed to higher level software.
286 #define PRCO_GETOPT 0
287 #define PRCO_SETOPT 1
292 char *prcorequests[] = {
298 struct domain *pffinddomain(int family);
299 struct protosw *pffindproto(int family, int protocol, int type);
300 struct protosw *pffindtype(int family, int type);
301 int pf_proto_register(int family, struct protosw *npr);
302 int pf_proto_unregister(int family, int protocol, int type);