]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/unpcb.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / bsd / sys / unpcb.h
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
8ad349bb 4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
1c79356b 5 *
8ad349bb
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
1c79356b
A
29 */
30/*
31 * Copyright (c) 1982, 1986, 1989, 1993
32 * The Regents of the University of California. All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)unpcb.h 8.1 (Berkeley) 6/2/93
63 */
64
65#ifndef _SYS_UNPCB_H_
66#define _SYS_UNPCB_H_
67
9bccf70c 68#include <sys/appleapiopts.h>
1c79356b
A
69#include <sys/queue.h>
70#include <sys/un.h>
91447636 71#include <sys/ucred.h>
1c79356b
A
72
73/*
74 * Protocol control block for an active
75 * instance of a UNIX internal protocol.
76 *
77 * A socket may be associated with an vnode in the
78 * file system. If so, the unp_vnode pointer holds
79 * a reference count to this vnode, which should be irele'd
80 * when the socket goes away.
81 *
82 * A socket may be connected to another socket, in which
83 * case the control block of the socket to which it is connected
84 * is given by unp_conn.
85 *
86 * A socket may be referenced by a number of sockets (e.g. several
87 * sockets may be connected to a datagram socket.) These sockets
88 * are in a linked list starting with unp_refs, linked through
89 * unp_nextref and null-terminated. Note that a socket may be referenced
90 * by a number of other sockets and may also reference a socket (not
91 * necessarily one which is referencing it). This generates
92 * the need for unp_refs and unp_nextref to be separate fields.
93 *
94 * Stream sockets keep copies of receive sockbuf sb_cc and sb_mbcnt
95 * so that changes in the sockbuf may be computed to modify
96 * back pressure on the sender accordingly.
97 */
91447636
A
98
99typedef u_quad_t unp_gen_t;
100
101#ifdef PRIVATE
1c79356b 102LIST_HEAD(unp_head, unpcb);
91447636
A
103#ifdef KERNEL
104#define sotounpcb(so) ((struct unpcb *)((so)->so_pcb))
1c79356b
A
105
106struct unpcb {
107 LIST_ENTRY(unpcb) unp_link; /* glue on list of all PCBs */
108 struct socket *unp_socket; /* pointer back to socket */
109 struct vnode *unp_vnode; /* if associated with file */
110 ino_t unp_ino; /* fake inode number */
111 struct unpcb *unp_conn; /* control block of connected socket */
112 struct unp_head unp_refs; /* referencing socket linked list */
113 LIST_ENTRY(unpcb) unp_reflink; /* link in unp_refs list */
114 struct sockaddr_un *unp_addr; /* bound address of socket */
115 int unp_cc; /* copy of rcv.sb_cc */
116 int unp_mbcnt; /* copy of rcv.sb_mbcnt */
117 unp_gen_t unp_gencnt; /* generation count of this instance */
91447636
A
118 int unp_flags; /* flags */
119 struct xucred unp_peercred; /* peer credentials, if applicable */
1c79356b 120};
91447636 121#endif /* KERNEL */
1c79356b 122
91447636
A
123/*
124 * Flags in unp_flags.
125 *
126 * UNP_HAVEPC - indicates that the unp_peercred member is filled in
127 * and is really the credentials of the connected peer. This is used
128 * to determine whether the contents should be sent to the user or
129 * not.
130 *
131 * UNP_HAVEPCCACHED - indicates that the unp_peercred member is filled
132 * in, but does *not* contain the credentials of the connected peer
133 * (there may not even be a peer). This is set in unp_listen() when
134 * it fills in unp_peercred for later consumption by unp_connect().
135 */
136#define UNP_HAVEPC 0x001
137#define UNP_HAVEPCCACHED 0x002
138
139#ifdef KERNEL
140struct unpcb_compat {
141#else /* KERNEL */
142#define unpcb_compat unpcb
143struct unpcb {
144#endif /* KERNEL */
145 LIST_ENTRY(unpcb_compat) unp_link; /* glue on list of all PCBs */
146 struct socket *unp_socket; /* pointer back to socket */
147 struct vnode *unp_vnode; /* if associated with file */
148 ino_t unp_ino; /* fake inode number */
149 struct unpcb_compat *unp_conn; /* control block of connected socket */
150 struct unp_head unp_refs; /* referencing socket linked list */
151 LIST_ENTRY(unpcb_compat) unp_reflink; /* link in unp_refs list */
152 struct sockaddr_un *unp_addr; /* bound address of socket */
153 int unp_cc; /* copy of rcv.sb_cc */
154 int unp_mbcnt; /* copy of rcv.sb_mbcnt */
155 unp_gen_t unp_gencnt; /* generation count of this instance */
156};
1c79356b
A
157
158/* Hack alert -- this structure depends on <sys/socketvar.h>. */
91447636
A
159#ifdef _SYS_SOCKETVAR_H_
160struct xunpcb {
161 size_t xu_len; /* length of this structure */
162 struct unpcb_compat *xu_unpp; /* to help netstat, fstat */
163 struct unpcb_compat xu_unp; /* our information */
164 union {
165 struct sockaddr_un xuu_addr; /* our bound address */
166 char xu_dummy1[256];
167 } xu_au;
168#define xu_addr xu_au.xuu_addr
169 union {
170 struct sockaddr_un xuu_caddr; /* their bound address */
171 char xu_dummy2[256];
172 } xu_cau;
173#define xu_caddr xu_cau.xuu_caddr
174 struct xsocket xu_socket;
175 u_quad_t xu_alignment_hack;
1c79356b 176};
91447636
A
177#endif /* _SYS_SOCKETVAR_H_ */
178#endif /* PRIVATE */
1c79356b
A
179
180struct xunpgen {
181 size_t xug_len;
182 u_int xug_count;
183 unp_gen_t xug_gen;
184 so_gen_t xug_sogen;
185};
1c79356b
A
186
187#endif /* _SYS_UNPCB_H_ */