xref: /freebsd/share/man/man4/ng_socket.4 (revision 39beb93c)
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$
36.\" $Whistle: ng_socket.8,v 1.5 1999/01/25 23:46:27 archie Exp $
37.\"
38.Dd January 19, 1999
39.Dt NG_SOCKET 4
40.Os
41.Sh NAME
42.Nm ng_socket
43.Nd netgraph socket node type
44.Sh SYNOPSIS
45.In sys/types.h
46.In netgraph/ng_socket.h
47.Sh DESCRIPTION
48A
49.Nm socket
50node is both a
51.Bx
52socket and a netgraph node.
53The
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.
60The process must have
61root privileges to be able to create netgraph sockets however once created,
62any process that has one may use it.
63.Pp
64A new
65.Nm
66node is created by creating a new socket of type
67.Dv NG_CONTROL
68in the protocol family
69.Dv PF_NETGRAPH ,
70using the
71.Xr socket 2
72system call.
73Any control messages received by the node
74and not having a cookie value of
75.Dv NGM_SOCKET_COOKIE
76are received by the process, using
77.Xr recvfrom 2 ;
78the socket address argument is a
79.Dv "struct sockaddr_ng"
80containing the sender's netgraph address.
81Conversely, control messages can be sent to any node by calling
82.Xr sendto 2 ,
83supplying the recipient's address in a
84.Dv "struct sockaddr_ng" .
85The
86.Xr bind 2
87system call may be used to assign a global netgraph name to the node.
88.Pp
89To transmit and receive netgraph data packets, a
90.Dv NG_DATA
91socket must also be created using
92.Xr socket 2
93and associated with a
94.Nm
95node.
96.Dv NG_DATA sockets do not automatically
97have nodes associated with them; they are bound to a specific node via the
98.Xr connect 2
99system call.
100The address argument is the netgraph address of the
101.Nm
102node already created.
103Once a data socket is associated with a node,
104any data packets received by the node are read using
105.Xr recvfrom 2
106and any packets to be sent out from the node are written using
107.Xr sendto 2 .
108In the case of data sockets, the
109.Dv "struct sockaddr_ng"
110contains the name of the
111.Em hook
112on which the data was received or should be sent.
113.Pp
114As a special case, to allow netgraph data sockets to be used as stdin or stdout
115on naive programs, a
116.Xr sendto 2
117with a NULL sockaddr pointer, a
118.Xr send 2
119or a
120.Xr write 2
121will succeed in the case where there is exactly ONE hook attached to
122the socket node, (and thus the path is unambiguous).
123.Pp
124There is a user library that simplifies using netgraph sockets; see
125.Xr netgraph 3 .
126.Sh HOOKS
127This node type supports hooks with arbitrary names (as long as
128they are unique) and always accepts hook connection requests.
129.Sh CONTROL MESSAGES
130This node type supports the generic control messages, plus the following:
131.Bl -tag -width foo
132.It Dv NGM_SOCK_CMD_NOLINGER
133When the last hook is removed from this node, it will shut down as
134if it had received a
135.Dv NGM_SHUTDOWN
136message.
137Attempts to access the sockets associated will return
138.Er ENOTCONN .
139.It Dv NGM_SOCK_CMD_LINGER
140This is the default mode.
141When the last hook is removed, the node will
142continue to exist, ready to accept new hooks until it
143is explicitly shut down.
144.El
145.Pp
146All other messages
147with neither the
148.Dv NGM_SOCKET_COOKIE
149or
150.Dv NGM_GENERIC_COOKIE
151will be passed unaltered up the
152.Dv NG_CONTROL
153socket.
154.Sh SHUTDOWN
155This node type shuts down and disappears when both the associated
156.Dv NG_CONTROL
157and
158.Dv NG_DATA
159sockets have been closed, or a
160.Dv NGM_SHUTDOWN
161control message is received.
162In the latter case, attempts to write
163to the still-open sockets will return
164.Er ENOTCONN .
165If the
166.Dv NGM_SOCK_CMD_NOLINGER
167message has been received, closure of the last hook will also initiate
168a shutdown of the node.
169.Sh SEE ALSO
170.Xr socket 2 ,
171.Xr netgraph 3 ,
172.Xr netgraph 4 ,
173.Xr ng_ksocket 4 ,
174.Xr ngctl 8
175.Sh HISTORY
176The
177.Nm
178node type was implemented in
179.Fx 4.0 .
180.Sh AUTHORS
181.An Julian Elischer Aq julian@FreeBSD.org
182.Sh BUGS
183It is not possible to reject the connection of a hook, though any
184data received on that hook can certainly be ignored.
185.Pp
186The controlling process is not notified of all events that an in-kernel node
187would be notified of, e.g.\& a new hook, or hook removal.
188Some node-initiated messages should be defined for this purpose (to be
189sent up the control socket).
190