xref: /freebsd/share/man/man4/ng_ksocket.4 (revision 6b3455a7665208c366849f0b2b3bc916fb97516e)
1.\" Copyright (c) 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.\"
37.Dd June 8, 2004
38.Dt NG_KSOCKET 4
39.Os
40.Sh NAME
41.Nm ng_ksocket
42.Nd kernel socket netgraph node type
43.Sh SYNOPSIS
44.In netgraph/ng_ksocket.h
45.Sh DESCRIPTION
46A
47.Nm ksocket
48node is both a netgraph node and a
49.Bx
50socket.
51The
52.Nm
53node type allows one to open a socket inside the kernel and have
54it appear as a Netgraph node.
55The
56.Nm
57node type is the reverse of the socket node type (see
58.Xr ng_socket 4 ) :
59whereas the socket node type enables the user-level manipulation (via
60a socket) of what is normally a kernel-level entity (the associated
61Netgraph node), the
62.Nm
63node type enables the kernel-level manipulation (via a Netgraph node) of
64what is normally a user-level entity (the associated socket).
65.Pp
66A
67.Nm
68node allows at most one hook connection.
69Connecting to the node is
70equivalent to opening the associated socket.
71The name given to the hook
72determines what kind of socket the node will open (see below).
73When the hook is disconnected and/or the node is shutdown, the
74associated socket is closed.
75.Sh HOOKS
76This node type supports a single hook connection at a time.
77The name of the hook must be of the form
78.Em <family>/<type>/<proto> ,
79where the
80.Em family ,
81.Em type ,
82and
83.Em proto
84are the decimal equivalent of the same arguments to
85.Xr socket 2 .
86Alternately, aliases for the commonly used values are accepted as
87well.
88For example
89.Dv inet/dgram/udp
90is a more readable but equivalent version of
91.Dv 2/2/17 .
92.Pp
93Data received into socket is sent out via hook.
94Data received on hook is sent out from socket, if the latter is
95connected (an
96.Dv NGM_KSOCKET_CONNECT
97was sent to node before).
98If socket is not connected, destination
99.Vt "struct sockaddr"
100must be supplied in an mbuf tag with cookie
101.Dv NGM_KSOCKET_COOKIE
102and type
103.Dv NG_KSOCKET_TAG_SOCKADDR
104attached to data.
105Otherwise
106.Nm
107will return
108.Er ENOTCONN
109to sender.
110.Sh CONTROL MESSAGES
111This node type supports the generic control messages, plus the following:
112.Bl -tag -width foo
113.It Dv NGM_KSOCKET_BIND
114This functions exactly like the
115.Xr bind 2
116system call.
117The
118.Vt "struct sockaddr"
119socket address parameter should be supplied as an argument.
120.It Dv NGM_KSOCKET_LISTEN
121This functions exactly like the
122.Xr listen 2
123system call.
124The backlog parameter (a single 32 bit
125.Dv int )
126should be supplied as an argument.
127.It Dv NGM_KSOCKET_CONNECT
128This functions exactly like the
129.Xr connect 2
130system call.
131The
132.Vt "struct sockaddr"
133destination address parameter should be supplied as an argument.
134.It Dv NGM_KSOCKET_ACCEPT
135Currently unimplemented.
136.It Dv NGM_KSOCKET_GETNAME
137Equivalent to the
138.Xr getsockname 2
139system call.
140The name is returned as a
141.Vt "struct sockaddr"
142in the arguments field of the reply.
143.It Dv NGM_KSOCKET_GETPEERNAME
144Equivalent to the
145.Xr getpeername 2
146system call.
147The name is returned as a
148.Vt "struct sockaddr"
149in the arguments field of the reply.
150.It Dv NGM_KSOCKET_SETOPT
151Equivalent to the
152.Xr setsockopt 2
153system call, except that the option name, level, and value are passed in a
154.Vt "struct ng_ksocket_sockopt" .
155.It Dv NGM_KSOCKET_GETOPT
156Equivalent to the
157.Xr getsockopt 2
158system call, except that the option is passed in a
159.Vt "struct ng_ksocket_sockopt" .
160When sending this command, the
161.Dv value
162field should be empty; upon return, it will contain the
163retrieved value.
164.El
165.Sh ASCII FORM CONTROL MESSAGES
166For control messages that pass a
167.Vt "struct sockaddr"
168in the argument field, the normal
169.Tn ASCII
170equivalent of the C structure
171is an acceptable form.
172For the
173.Dv PF_INET
174and
175.Dv PF_LOCAL
176address families, a more convenient form is also used, which is
177the protocol family name, followed by a slash, followed by the actual
178address.
179For
180.Dv PF_INET ,
181the address is an IP address followed by an optional colon and port number.
182For
183.Dv PF_LOCAL ,
184the address is the pathname as a doubly quoted string.
185.Pp
186Examples:
187.Bl -tag -width XXXXXXXXXX
188.It Dv PF_LOCAL
189local/"/tmp/foo.socket"
190.It Dv PF_INET
191inet/192.168.1.1:1234
192.It Other
193.Dv "\&{ family=16 len=16 data=[0x70 0x00 0x01 0x23] \&}"
194.El
195.Pp
196For control messages that pass a
197.Vt "struct ng_ksocket_sockopt" ,
198the normal
199.Tn ASCII
200form for that structure is used.
201In the future, more
202convenient encoding of the more common socket options may be supported.
203.Sh SHUTDOWN
204This node shuts down upon receipt of a
205.Dv NGM_SHUTDOWN
206control message, or when the hook is disconnected.
207Shutdown of the node closes the associated socket.
208.Sh SEE ALSO
209.Xr socket 2 ,
210.Xr netgraph 4 ,
211.Xr ng_socket 4 ,
212.Xr ngctl 8 ,
213.Xr mbuf_tags 9
214.Sh HISTORY
215The
216.Nm
217node type was implemented in
218.Fx 4.0 .
219.Sh AUTHORS
220.An Archie Cobbs Aq archie@FreeBSD.org
221