]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/modules/netgraph/socket/ng_socket.4
Add reference to new netgraph node type "ksocket".
[FreeBSD/FreeBSD.git] / sys / modules / netgraph / socket / ng_socket.4
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@whistle.com>
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 8
40 .Os FreeBSD 4.0
41 .Sh NAME
42 .Nm ng_socket
43 .Nd netgraph socket node type
44 .Sh SYNOPSIS
45 .Fd #include <netgraph/ng_message.h>
46 .Fd #include <netgraph/ng_socket.h>
47 .Sh DESCRIPTION
48 A
49 .Nm socket
50 node is both a BSD socket and a netgraph node.  The
51 .Nm socket
52 node type allows user-mode processes to participate in the kernel
53 .Xr netgraph 4
54 networking subsystem using the BSD socket interface.
55 .Pp
56 A new
57 .Nm socket
58 node is created by creating a new socket of type
59 .Dv NG_CONTROL
60 in the protocol family
61 .Dv PF_NETGRAPH ,
62 using the
63 .Xr socket 2
64 system call.
65 Any control messages received by the node 
66 and not having a cookie value of 
67 .Dv NGM_SOCKET_COOKIE
68 are received  by the process, using
69 .Xr recvfrom 2 ;
70 the socket address argument is a
71 .Dv "struct sockaddr_ng"
72 containing the sender's netgraph address. Conversely, control messages
73 can be sent to any node by calling
74 .Xr sendto 2 ,
75 supplying the recipient's address in a
76 .Dv "struct sockaddr_ng" .
77 The
78 .Xr bind 2
79 system call may be used to assign a global netgraph name to the node.
80 .Pp
81 To transmit and receive netgraph data packets, a
82 .Dv NG_DATA
83 socket must also be created using
84 .Xr socket 2
85 and associated with a
86 .Nm socket
87 node.
88 .Dv NG_DATA sockets do not automatically
89 have nodes associated with them; they are bound to a specific node via the
90 .Xr connect 2
91 system call. The address argument is the netgraph address of the
92 .Nm socket
93 node already created. Once a data socket is associated with a node,
94 any data packets received by the node are read using
95 .Xr recvfrom 2
96 and any packets to be sent out from the node are written using
97 .Xr sendto 2 .
98 In the case of data sockets, the
99 .Dv "struct sockaddr_ng"
100 contains the name of the
101 .Em hook
102 on which the data was received or should be sent.
103 .Pp
104 There is a user library that simplifies using netgraph sockets; see
105 .Xr netgraph 3 .
106 .Sh HOOKS
107 This node type supports hooks with arbitrary names (as long as
108 they are unique) and always accepts hook connection requests.
109 .Sh CONTROL MESSAGES
110 This node type supports the generic control messages, plus the following:
111 .Bl -tag -width foo
112 .It Dv NGM_SOCK_CMD_NOLINGER
113 When the last hook is removed from this node, it will shut down as
114 if it had received a 
115 .Dv NGM_SHUTDOWN
116 message. Attempts to access the sockets associated will return
117 .Er ENOTCONN .
118 .It Dv NGM_SOCK_CMD_LINGER
119 This is the default mode. When the last hook is removed, the node will
120 continue to exist, ready to accept new hooks until it
121 is explicitly shut down.
122 .El
123 .Pp
124 All other messages
125 with neither the
126 .Dv NGM_SOCKET_COOKIE
127 or
128 .Dv NGM_GENERIC_COOKIE
129 will be passed unaltered up the 
130 .Dv NG_CONTROL 
131 socket.
132 .Sh SHUTDOWN
133 This node type shuts down and disappears when both the associated
134 .Dv NG_CONTROL
135 and
136 .Dv NG_DATA
137 sockets have been closed, or a
138 .Dv NGM_SHUTDOWN
139 control message is received. In the latter case, attempts to write
140 to the still-open sockets will return
141 .Er ENOTCONN .
142 If the 
143 .Dv NGM_SOCK_CMD_NOLINGER
144 message has been received, closure of the last hook will also initiate
145 a shutdown of the node.
146 .Sh BUGS
147 It is not possible to reject the connection of a hook, though any
148 data received on that hook can certainly be ignored.
149 .Pp
150 The controlling process is not notified of all events that an in-kernel node
151 would be notified of, e.g. a new hook, or hook removal. We should define
152 some node-initiated messages for this purpose (to be sent up the control
153 socket).
154 .Sh SEE ALSO
155 .Xr socket 2 ,
156 .Xr netgraph 3 ,
157 .Xr netgraph 4 ,
158 .Xr ng_ksocket 8 ,
159 .Xr ngctl 8 .
160 .Sh AUTHOR
161 Julian Elischer <julian@whistle.com>