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