xref: /dragonfly/sys/sys/socketops.h (revision 655933d6)
1 /*
2  * Copyright (c) 2003, 2004 Jeffrey M. Hsu.  All rights reserved.
3  * Copyright (c) 2003, 2004 The DragonFly Project.  All rights reserved.
4  *
5  * This code is derived from software contributed to The DragonFly Project
6  * by Jeffrey M. Hsu.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of The DragonFly Project nor the names of its
17  *    contributors may be used to endorse or promote products derived
18  *    from this software without specific, prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 
34 #ifndef _SYS_SOCKETOPS_H_
35 #define _SYS_SOCKETOPS_H_
36 
37 #ifndef _KERNEL
38 #error "This file should not be included by userland programs."
39 #endif
40 
41 #ifndef _SYS_PROTOSW_H_
42 #include <sys/protosw.h>
43 #endif
44 #ifndef _SYS_SOCKET_H_
45 #include <sys/socket.h>
46 #endif
47 #ifndef _SYS_SOCKETVAR_H_
48 #include <sys/socketvar.h>
49 #endif
50 
51 /*
52  * sosend() and soreceive() can block and also calls other pru_usrreq functions.
53  * They should not really be usrreq functions.  Always call them directly from
54  * the process context rather than passing a message to the protocol thread.
55  */
56 static __inline int
57 so_pru_sosend(struct socket *so, struct sockaddr *addr, struct uio *uio,
58 	      struct mbuf *top, struct mbuf *control, int flags,
59 	      struct thread *td)
60 {
61 	return ((*so->so_proto->pr_usrreqs->pru_sosend)(so, addr, uio, top,
62 		control, flags, td));
63 }
64 
65 static __inline int
66 so_pru_soreceive(struct socket *so, struct sockaddr **paddr, struct uio *uio,
67 		 struct sockbuf *sio, struct mbuf **controlp, int *flagsp)
68 {
69 	return ((*so->so_proto->pr_usrreqs->pru_soreceive)(so, paddr, uio, sio,
70 		controlp, flagsp));
71 }
72 
73 struct lwkt_port;
74 
75 void so_pru_abort_async (struct socket *so);
76 void so_pru_abort_direct (struct socket *so);
77 int so_pru_accept (struct socket *so, struct sockaddr **nam);
78 int so_pru_attach (struct socket *so, int proto, struct pru_attach_info *ai);
79 int so_pru_attach_direct(struct socket *so, int proto,
80 		struct pru_attach_info *ai);
81 int so_pru_attach_fast(struct socket *so, int proto,
82 		struct pru_attach_info *ai);
83 int so_pru_bind (struct socket *so, struct sockaddr *nam, struct thread *td);
84 int so_pru_connect (struct socket *so, struct sockaddr *nam, struct thread *td);
85 int so_pru_connect_async (struct socket *so, struct sockaddr *nam,
86 		struct thread *td);
87 int so_pru_connect2 (struct socket *so1, struct socket *so2, struct ucred *cred);
88 int so_pru_control_direct(struct socket *so, u_long cmd, caddr_t data,
89 		struct ifnet *ifp);
90 int so_pru_detach (struct socket *so);
91 int so_pru_detach_direct (struct socket *so);
92 int so_pru_disconnect (struct socket *so);
93 void so_pru_disconnect_direct (struct socket *so);
94 int so_pru_listen (struct socket *so, struct thread *td);
95 int so_pru_peeraddr (struct socket *so, struct sockaddr **nam);
96 int so_pru_rcvd (struct socket *so, int flags);
97 void so_pru_rcvd_async (struct socket *so);
98 void so_async_rcvd_reply (struct socket *so);
99 void so_async_rcvd_drop (struct socket *so);
100 int so_pru_rcvoob (struct socket *so, struct mbuf *m, int flags);
101 void so_pru_sync (struct socket *so);
102 int so_pru_send (struct socket *so, int flags, struct mbuf *m,
103 		struct sockaddr *addr, struct mbuf *control,
104 		struct thread *td);
105 void so_pru_send_async (struct socket *so, int flags, struct mbuf *m,
106 		struct sockaddr *addr, struct mbuf *control,
107 		struct thread *td);
108 int so_pru_sense (struct socket *so, struct stat *sb);
109 int so_pru_shutdown (struct socket *so);
110 int so_pru_sockaddr (struct socket *so, struct sockaddr **nam);
111 int so_pr_ctloutput(struct socket *so, struct sockopt *sopt);
112 struct lwkt_port *so_pr_ctlport(struct protosw *pr, int cmd,
113 		struct sockaddr *arg, void *extra, int *cpuid);
114 void so_pr_ctlinput(struct protosw *pr, int cmd,
115 		struct sockaddr *arg, void *extra);
116 void so_pr_ctlinput_direct(struct protosw *pr, int cmd,
117 		struct sockaddr *arg, void *extra);
118 
119 static __inline int
120 so_pru_senda(struct socket *so, int flags, struct mbuf *m,
121 	     struct sockaddr *addr, struct mbuf *control, struct thread *td)
122 {
123 	if (so->so_proto->pr_flags & PR_ASYNC_SEND) {
124 		so_pru_send_async(so, flags, m, addr, control, td);
125 		return 0;
126 	} else {
127 		return so_pru_send(so, flags, m, addr, control, td);
128 	}
129 }
130 
131 #endif	/* !_SYS_SOCKETOPS_H_ */
132