xref: /dragonfly/share/man/man4/ng_socket.4 (revision b40e316c)
1.\" Copyright (c) 1996-1999 Whistle Communications, Inc.
2.\" All rights reserved.
3.\"
4.\" Subject to the following obligations and disclaimer of warranty, use and
5.\" redistribution of this software, in source or object code forms, with or
6.\" without modifications are expressly permitted by Whistle Communications;
7.\" provided, however, that:
8.\" 1. Any and all reproductions of the source or object code must include the
9.\"    copyright notice above and the following disclaimer of warranties; and
10.\" 2. No rights are granted, in any manner or form, to use Whistle
11.\"    Communications, Inc. trademarks, including the mark "WHISTLE
12.\"    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
13.\"    such appears in the above copyright notice or in the software.
14.\"
15.\" THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
16.\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
17.\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
18.\" INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
19.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
20.\" WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
21.\" REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
22.\" SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
23.\" IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
24.\" RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
25.\" WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26.\" PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
27.\" SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30.\" THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
31.\" OF SUCH DAMAGE.
32.\"
33.\" Author: Archie Cobbs <archie@FreeBSD.org>
34.\"
35.\" $FreeBSD: src/share/man/man4/ng_socket.4,v 1.14.2.1 2001/12/21 09:00:51 ru Exp $
36.\" $DragonFly: src/share/man/man4/ng_socket.4,v 1.2 2003/06/17 04:36:59 dillon Exp $
37.\" $Whistle: ng_socket.8,v 1.5 1999/01/25 23:46:27 archie Exp $
38.\"
39.Dd January 19, 1999
40.Dt NG_SOCKET 4
41.Os
42.Sh NAME
43.Nm ng_socket
44.Nd netgraph socket node type
45.Sh SYNOPSIS
46.In netgraph/ng_message.h
47.In netgraph/ng_socket.h
48.Sh DESCRIPTION
49A
50.Nm socket
51node is both a
52.Bx
53socket and a netgraph node.  The
54.Nm
55node type allows user-mode processes to participate in the kernel
56.Xr netgraph 4
57networking subsystem using the
58.Bx
59socket interface. The process must have
60root privileges to be able to create netgraph sockets however once created,
61any process that has one may use it.
62.Pp
63A new
64.Nm
65node is created by creating a new socket of type
66.Dv NG_CONTROL
67in the protocol family
68.Dv PF_NETGRAPH ,
69using the
70.Xr socket 2
71system call.
72Any control messages received by the node
73and not having a cookie value of
74.Dv NGM_SOCKET_COOKIE
75are received  by the process, using
76.Xr recvfrom 2 ;
77the socket address argument is a
78.Dv "struct sockaddr_ng"
79containing the sender's netgraph address. Conversely, control messages
80can be sent to any node by calling
81.Xr sendto 2 ,
82supplying the recipient's address in a
83.Dv "struct sockaddr_ng" .
84The
85.Xr bind 2
86system call may be used to assign a global netgraph name to the node.
87.Pp
88To transmit and receive netgraph data packets, a
89.Dv NG_DATA
90socket must also be created using
91.Xr socket 2
92and associated with a
93.Nm
94node.
95.Dv NG_DATA sockets do not automatically
96have nodes associated with them; they are bound to a specific node via the
97.Xr connect 2
98system call. The address argument is the netgraph address of the
99.Nm
100node already created. Once a data socket is associated with a node,
101any data packets received by the node are read using
102.Xr recvfrom 2
103and any packets to be sent out from the node are written using
104.Xr sendto 2 .
105In the case of data sockets, the
106.Dv "struct sockaddr_ng"
107contains the name of the
108.Em hook
109on which the data was received or should be sent.
110.Pp
111As a special case, to allow netgraph data sockets to be used as stdin or stdout
112on naive programs, a
113.Xr sendto  2
114with a NULL sockaddr pointer, a
115.Xr send 2
116or a
117.Xr write 2
118will succeed in the case where there is exactly ONE hook  attached to
119the socket node, (and thus the path is unambiguous).
120.Pp
121There is a user library that simplifies using netgraph sockets; see
122.Xr netgraph 3 .
123.Sh HOOKS
124This node type supports hooks with arbitrary names (as long as
125they are unique) and always accepts hook connection requests.
126.Sh CONTROL MESSAGES
127This node type supports the generic control messages, plus the following:
128.Bl -tag -width foo
129.It Dv NGM_SOCK_CMD_NOLINGER
130When the last hook is removed from this node, it will shut down as
131if it had received a
132.Dv NGM_SHUTDOWN
133message. Attempts to access the sockets associated will return
134.Er ENOTCONN .
135.It Dv NGM_SOCK_CMD_LINGER
136This is the default mode. When the last hook is removed, the node will
137continue to exist, ready to accept new hooks until it
138is explicitly shut down.
139.El
140.Pp
141All other messages
142with neither the
143.Dv NGM_SOCKET_COOKIE
144or
145.Dv NGM_GENERIC_COOKIE
146will be passed unaltered up the
147.Dv NG_CONTROL
148socket.
149.Sh SHUTDOWN
150This node type shuts down and disappears when both the associated
151.Dv NG_CONTROL
152and
153.Dv NG_DATA
154sockets have been closed, or a
155.Dv NGM_SHUTDOWN
156control message is received. In the latter case, attempts to write
157to the still-open sockets will return
158.Er ENOTCONN .
159If the
160.Dv NGM_SOCK_CMD_NOLINGER
161message has been received, closure of the last hook will also initiate
162a shutdown of the node.
163.Sh BUGS
164It is not possible to reject the connection of a hook, though any
165data received on that hook can certainly be ignored.
166.Pp
167The controlling process is not notified of all events that an in-kernel node
168would be notified of, e.g. a new hook, or hook removal. We should define
169some node-initiated messages for this purpose (to be sent up the control
170socket).
171.Sh SEE ALSO
172.Xr socket 2 ,
173.Xr netgraph 3 ,
174.Xr netgraph 4 ,
175.Xr ng_ksocket 4 ,
176.Xr ngctl 8
177.Sh HISTORY
178The
179.Nm
180node type was implemented in
181.Fx 4.0 .
182.Sh AUTHORS
183.An Julian Elischer Aq julian@FreeBSD.org
184