FreeBSD/Linux Kernel Cross Reference
sys/sys/unpcb.h
1 /* $OpenBSD: unpcb.h,v 1.45 2022/11/26 17:51:18 mvs Exp $ */
2 /* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */
3
4 /*
5 * Copyright (c) 1982, 1986, 1989, 1993
6 * The Regents of the University of California. All rights reserved.
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 University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)unpcb.h 8.1 (Berkeley) 6/2/93
33 */
34
35 #include <sys/refcnt.h>
36
37 /*
38 * Protocol control block for an active
39 * instance of a UNIX internal protocol.
40 *
41 * A socket may be associated with an vnode in the
42 * file system. If so, the unp_vnode pointer holds
43 * a reference count to this vnode, which should be vrele'd
44 * when the socket goes away.
45 *
46 * A socket may be connected to another socket, in which
47 * case the control block of the socket to which it is connected
48 * is given by unp_conn.
49 *
50 * A socket may be referenced by a number of sockets (e.g. several
51 * sockets may be connected to a datagram socket.) These sockets
52 * are in a linked list starting with unp_refs, linked through
53 * unp_nextref and null-terminated. Note that a socket may be referenced
54 * by a number of other sockets and may also reference a socket (not
55 * necessarily one which is referencing it). This generates
56 * the need for unp_refs and unp_nextref to be separate fields.
57 *
58 * Stream sockets keep copies of receive sockbuf sb_cc and sb_mbcnt
59 * so that changes in the sockbuf may be computed to modify
60 * back pressure on the sender accordingly.
61 *
62 * Locks used to protect struct members:
63 * I immutable after creation
64 * G unp_gc_lock
65 * s socket lock
66 */
67
68
69 struct unpcb {
70 struct refcnt unp_refcnt; /* references to this pcb */
71 struct socket *unp_socket; /* [I] pointer back to socket */
72 struct vnode *unp_vnode; /* [s] if associated with file */
73 struct file *unp_file; /* [G] backpointer for unp_gc() */
74 struct unpcb *unp_conn; /* [s] control block of connected
75 socket */
76 ino_t unp_ino; /* [s] fake inode number */
77 SLIST_HEAD(,unpcb) unp_refs; /* [s] referencing socket linked list */
78 SLIST_ENTRY(unpcb) unp_nextref; /* [s] link in unp_refs list */
79 struct mbuf *unp_addr; /* [s] bound address of socket */
80 long unp_msgcount; /* [G] references from socket rcv buf */
81 long unp_gcrefs; /* [G] references from gc */
82 int unp_flags; /* [s] this unpcb contains peer eids */
83 int unp_gcflags; /* [G] garbage collector flags */
84 struct sockpeercred unp_connid;/* [s] id of peer process */
85 struct timespec unp_ctime; /* [I] holds creation time */
86 LIST_ENTRY(unpcb) unp_link; /* [G] link in per-AF list of sockets */
87 };
88
89 /*
90 * flag bits in unp_flags
91 */
92 #define UNP_FEIDS 0x01 /* unp_connid contains information */
93 #define UNP_FEIDSBIND 0x02 /* unp_connid was set by a bind */
94 #define UNP_BINDING 0x04 /* unp is binding now */
95 #define UNP_CONNECTING 0x08 /* unp is connecting now */
96
97 /*
98 * flag bits in unp_gcflags
99 */
100 #define UNP_GCDEAD 0x01 /* unp could be dead */
101
102 #define sotounpcb(so) ((struct unpcb *)((so)->so_pcb))
103
104 #ifdef _KERNEL
105
106 struct stat;
107
108 struct fdpass {
109 struct file *fp;
110 int flags;
111 };
112
113 extern const struct pr_usrreqs uipc_usrreqs;
114 extern const struct pr_usrreqs uipc_dgram_usrreqs;
115
116 int uipc_attach(struct socket *, int, int);
117 int uipc_detach(struct socket *);
118 int uipc_bind(struct socket *, struct mbuf *, struct proc *);
119 int uipc_listen(struct socket *);
120 int uipc_connect(struct socket *, struct mbuf *);
121 int uipc_accept(struct socket *, struct mbuf *);
122 int uipc_disconnect(struct socket *);
123 int uipc_shutdown(struct socket *);
124 int uipc_dgram_shutdown(struct socket *);
125 void uipc_rcvd(struct socket *);
126 int uipc_send(struct socket *, struct mbuf *, struct mbuf *,
127 struct mbuf *);
128 int uipc_dgram_send(struct socket *, struct mbuf *, struct mbuf *,
129 struct mbuf *);
130 void uipc_abort(struct socket *);
131 int uipc_sense(struct socket *, struct stat *);
132 int uipc_sockaddr(struct socket *, struct mbuf *);
133 int uipc_peeraddr(struct socket *, struct mbuf *);
134 int uipc_connect2(struct socket *, struct socket *);
135
136 void unp_init(void);
137 int unp_connect(struct socket *, struct mbuf *, struct proc *);
138 int unp_connect2(struct socket *, struct socket *);
139 void unp_detach(struct unpcb *);
140 void unp_disconnect(struct unpcb *);
141 void unp_gc(void *);
142 int unp_externalize(struct mbuf *, socklen_t, int);
143 int unp_internalize(struct mbuf *, struct proc *);
144 void unp_dispose(struct mbuf *);
145 #endif /* _KERNEL */
Cache object: 0b8935069e5f26b72d75dfd7994148ad
|