xref: /netbsd/sys/sys/unpcb.h (revision 4246d3ca)
1 /*	$NetBSD: unpcb.h,v 1.18 2016/04/06 19:45:46 roy 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. 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  */
33 
34 #ifndef _SYS_UNPCB_H_
35 #define _SYS_UNPCB_H_
36 
37 #include <sys/un.h>
38 #include <sys/mutex.h>
39 
40 /*
41  * Protocol control block for an active
42  * instance of a UNIX internal protocol.
43  *
44  * A socket may be associated with an vnode in the
45  * file system.  If so, the unp_vnode pointer holds
46  * a reference count to this vnode, which should be irele'd
47  * when the socket goes away.
48  *
49  * A socket may be connected to another socket, in which
50  * case the control block of the socket to which it is connected
51  * is given by unp_conn.
52  *
53  * A socket may be referenced by a number of sockets (e.g. several
54  * sockets may be connected to a datagram socket.)  These sockets
55  * are in a linked list starting with unp_refs, linked through
56  * unp_nextref and null-terminated.  Note that a socket may be referenced
57  * by a number of other sockets and may also reference a socket (not
58  * necessarily one which is referencing it).  This generates
59  * the need for unp_refs and unp_nextref to be separate fields.
60  *
61  * Stream sockets keep copies of receive sockbuf sb_cc and sb_mbcnt
62  * so that changes in the sockbuf may be computed to modify
63  * back pressure on the sender accordingly.
64  *
65  * The unp_ctime holds the creation time of the socket: it might be part of
66  * a socketpair created by pipe(2), and POSIX requires pipe(2) to initialize
67  * a stat structure's st_[acm]time members with the pipe's creation time.
68  * N.B.: updating st_[am]time when reading/writing the pipe is not required,
69  *       so we just use a single timespec and do not implement that.
70  */
71 struct	unpcb {
72 	struct	socket *unp_socket;	/* pointer back to socket */
73 	struct	vnode *unp_vnode;	/* if associated with file */
74 	ino_t	unp_ino;		/* fake inode number */
75 	struct	unpcb *unp_conn;	/* control block of connected socket */
76 	struct	unpcb *unp_refs;	/* referencing socket linked list */
77 	struct 	unpcb *unp_nextref;	/* link in unp_refs list */
78 	struct	sockaddr_un *unp_addr;	/* bound address of socket */
79 	kmutex_t *unp_streamlock;	/* lock for est. stream connections */
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 	struct	unpcbid unp_connid; 	/* pid and eids of peer */
86 };
87 
88 /*
89  * Flags in unp_flags.
90  *
91  * UNP_EIDSVALID - indicates that the unp_connid member is filled in
92  * and is really the effective ids of the connected peer.  This is used
93  * to determine whether the contents should be sent to the user or
94  * not.
95  *
96  * UNP_EIDSBIND - indicates that the unp_connid member is filled
97  * in with data for the listening process.  This is set up in unp_bind() when
98  * it fills in unp_connid for later consumption by unp_connect().
99  */
100 #define	UNP_OWANTCRED	0x0001		/* credentials wanted */
101 #define	UNP_CONNWAIT	0x0002		/* connect blocks until accepted */
102 #define	UNP_EIDSVALID	0x0004		/* unp_connid contains valid data */
103 #define	UNP_EIDSBIND	0x0008		/* unp_connid was set by bind() */
104 #define	UNP_BUSY	0x0010		/* busy connecting or binding */
105 #define	UNP_WANTCRED	0x0020		/* credentials wanted */
106 
107 #define	sotounpcb(so)	((struct unpcb *)((so)->so_pcb))
108 
109 #endif /* !_SYS_UNPCB_H_ */
110