]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/unpcb.h
MFV r331695, 331700: 9166 zfs storage pool checkpoint
[FreeBSD/FreeBSD.git] / sys / sys / unpcb.h
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1982, 1986, 1989, 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  *      @(#)unpcb.h     8.1 (Berkeley) 6/2/93
32  * $FreeBSD$
33  */
34
35 #ifndef _SYS_UNPCB_H_
36 #define _SYS_UNPCB_H_
37
38 typedef uint64_t unp_gen_t;
39
40 #if defined(_KERNEL) || defined(_WANT_UNPCB)
41 #include <sys/queue.h>
42 #include <sys/ucred.h>
43
44 /*
45  * Protocol control block for an active
46  * instance of a UNIX internal protocol.
47  *
48  * A socket may be associated with a vnode in the
49  * filesystem.  If so, the unp_vnode pointer holds
50  * a reference count to this vnode, which should be irele'd
51  * when the socket goes away.
52  *
53  * A socket may be connected to another socket, in which
54  * case the control block of the socket to which it is connected
55  * is given by unp_conn.
56  *
57  * A socket may be referenced by a number of sockets (e.g. several
58  * sockets may be connected to a datagram socket.)  These sockets
59  * are in a linked list starting with unp_refs, linked through
60  * unp_nextref and null-terminated.  Note that a socket may be referenced
61  * by a number of other sockets and may also reference a socket (not
62  * necessarily one which is referencing it).  This generates
63  * the need for unp_refs and unp_nextref to be separate fields.
64  *
65  * Stream sockets keep copies of receive sockbuf sb_cc and sb_mbcnt
66  * so that changes in the sockbuf may be computed to modify
67  * back pressure on the sender accordingly.
68  */
69 LIST_HEAD(unp_head, unpcb);
70
71 struct unpcb {
72         LIST_ENTRY(unpcb) unp_link;     /* glue on list of all PCBs */
73         struct  socket *unp_socket;     /* pointer back to socket */
74         struct  file *unp_file;         /* back-pointer to file for gc. */
75         struct  vnode *unp_vnode;       /* if associated with file */
76         ino_t   unp_ino;                /* fake inode number */
77         struct  unpcb *unp_conn;        /* control block of connected socket */
78         struct  unp_head unp_refs;      /* referencing socket linked list */
79         LIST_ENTRY(unpcb) unp_reflink;  /* link in unp_refs list */
80         struct  sockaddr_un *unp_addr;  /* bound address of socket */
81         unp_gen_t unp_gencnt;           /* generation count of this instance */
82         short   unp_flags;              /* flags */
83         short   unp_gcflag;             /* Garbage collector flags. */
84         struct  xucred unp_peercred;    /* peer credentials, if applicable */
85         u_int   unp_refcount;
86         u_int   unp_msgcount;           /* references from message queue */
87         struct  mtx unp_mtx;            /* mutex */
88 };
89
90 /*
91  * Flags in unp_flags.
92  *
93  * UNP_HAVEPC - indicates that the unp_peercred member is filled in
94  * and is really the credentials of the connected peer.  This is used
95  * to determine whether the contents should be sent to the user or
96  * not.
97  */
98 #define UNP_HAVEPC                      0x001
99 #define UNP_WANTCRED                    0x004   /* credentials wanted */
100 #define UNP_CONNWAIT                    0x008   /* connect blocks until accepted */
101
102 /*
103  * These flags are used to handle non-atomicity in connect() and bind()
104  * operations on a socket: in particular, to avoid races between multiple
105  * threads or processes operating simultaneously on the same socket.
106  */
107 #define UNP_CONNECTING                  0x010   /* Currently connecting. */
108 #define UNP_BINDING                     0x020   /* Currently binding. */
109 #define UNP_NASCENT                     0x040   /* Newborn child socket. */
110
111 /*
112  * Flags in unp_gcflag.
113  */
114 #define UNPGC_REF                       0x1     /* unpcb has external ref. */
115 #define UNPGC_DEAD                      0x2     /* unpcb might be dead. */
116 #define UNPGC_SCANNED                   0x4     /* Has been scanned. */
117 #define UNPGC_IGNORE_RIGHTS             0x8     /* Attached rights are freed */
118
119 #define sotounpcb(so)   ((struct unpcb *)((so)->so_pcb))
120
121 #endif  /* _KERNEL || _WANT_UNPCB */
122
123 /*
124  * UNPCB structure exported to user-land via sysctl(3).
125  *
126  * Fields prefixed with "xu_" are unique to the export structure, and fields
127  * with "unp_" or other prefixes match corresponding fields of 'struct unpcb'.
128  *
129  * Legend:
130  * (s) - used by userland utilities in src
131  * (p) - used by utilities in ports
132  * (3) - is known to be used by third party software not in ports
133  * (n) - no known usage
134  *
135  * Evil hack: declare only if sys/socketvar.h have been included.
136  */
137 #ifdef  _SYS_SOCKETVAR_H_
138 struct xunpcb {
139         size_t          xu_len;                 /* length of this structure */
140         void            *xu_unpp;               /* to help netstat, fstat */
141         void            *unp_vnode;             /* (s) */
142         void            *unp_conn;              /* (s) */
143         void            *xu_firstref;           /* (s) */
144         void            *xu_nextref;            /* (s) */
145         unp_gen_t       unp_gencnt;             /* (s) */
146         int64_t         xu_spare64[8];
147         int32_t         xu_spare32[8];
148         union {
149                 struct  sockaddr_un xu_addr;    /* our bound address */
150                 char    xu_dummy1[256];
151         };
152         union {
153                 struct  sockaddr_un xu_caddr;   /* their bound address */
154                 char    xu_dummy2[256];
155         };
156         struct xsocket  xu_socket;
157 } __aligned(8);
158
159 struct xunpgen {
160         size_t  xug_len;
161         u_int   xug_count;
162         unp_gen_t xug_gen;
163         so_gen_t xug_sogen;
164 } __aligned(8);;
165 #endif /* _SYS_SOCKETVAR_H_ */
166
167 #endif /* _SYS_UNPCB_H_ */