xref: /netbsd/sys/sys/unpcb.h (revision bf9ec67e)
1 /*	$NetBSD: unpcb.h,v 1.11 1998/01/07 22:49:47 thorpej Exp $	*/
2 
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. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	@(#)unpcb.h	8.1 (Berkeley) 6/2/93
36  */
37 
38 #ifndef _SYS_UNPCB_H_
39 #define _SYS_UNPCB_H_
40 
41 /*
42  * Protocol control block for an active
43  * instance of a UNIX internal protocol.
44  *
45  * A socket may be associated with an vnode in the
46  * file system.  If so, the unp_vnode pointer holds
47  * a reference count to this vnode, which should be irele'd
48  * when the socket goes away.
49  *
50  * A socket may be connected to another socket, in which
51  * case the control block of the socket to which it is connected
52  * is given by unp_conn.
53  *
54  * A socket may be referenced by a number of sockets (e.g. several
55  * sockets may be connected to a datagram socket.)  These sockets
56  * are in a linked list starting with unp_refs, linked through
57  * unp_nextref and null-terminated.  Note that a socket may be referenced
58  * by a number of other sockets and may also reference a socket (not
59  * necessarily one which is referencing it).  This generates
60  * the need for unp_refs and unp_nextref to be separate fields.
61  *
62  * Stream sockets keep copies of receive sockbuf sb_cc and sb_mbcnt
63  * so that changes in the sockbuf may be computed to modify
64  * back pressure on the sender accordingly.
65  *
66  * The unp_ctime holds the creation time of the socket: it might be part of
67  * a socketpair created by pipe(2), and POSIX requires pipe(2) to initialize
68  * a stat structure's st_[acm]time members with the pipe's creation time.
69  * N.B.: updating st_[am]time when reading/writing the pipe is not required,
70  *       so we just use a single timespec and do not implement that.
71  */
72 struct	unpcb {
73 	struct	socket *unp_socket;	/* pointer back to socket */
74 	struct	vnode *unp_vnode;	/* if associated with file */
75 	ino_t	unp_ino;		/* fake inode number */
76 	struct	unpcb *unp_conn;	/* control block of connected socket */
77 	struct	unpcb *unp_refs;	/* referencing socket linked list */
78 	struct 	unpcb *unp_nextref;	/* link in unp_refs list */
79 	struct	sockaddr_un *unp_addr;	/* bound address of socket */
80 	size_t	unp_addrlen;		/* size of socket address */
81 	int	unp_cc;			/* copy of rcv.sb_cc */
82 	int	unp_mbcnt;		/* copy of rcv.sb_mbcnt */
83 	struct	timespec unp_ctime;	/* holds creation time */
84 	int	unp_flags;		/* misc flags; see below*/
85 };
86 
87 /* unp_flags */
88 #define	UNP_WANTCRED	0x0001		/* credentials wanted */
89 
90 #define	sotounpcb(so)	((struct unpcb *)((so)->so_pcb))
91 
92 #endif /* !_SYS_UNPCB_H_ */
93