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