xref: /freebsd/share/man/man4/ng_ksocket.4 (revision 753d686d34e90c2a4fe6afa14bd5f19d94f17699)
1f7045ac0SArchie Cobbs.\" Copyright (c) 1999 Whistle Communications, Inc.
2f7045ac0SArchie Cobbs.\" All rights reserved.
3f7045ac0SArchie Cobbs.\"
4f7045ac0SArchie Cobbs.\" Subject to the following obligations and disclaimer of warranty, use and
5f7045ac0SArchie Cobbs.\" redistribution of this software, in source or object code forms, with or
6f7045ac0SArchie Cobbs.\" without modifications are expressly permitted by Whistle Communications;
7f7045ac0SArchie Cobbs.\" provided, however, that:
8f7045ac0SArchie Cobbs.\" 1. Any and all reproductions of the source or object code must include the
9f7045ac0SArchie Cobbs.\"    copyright notice above and the following disclaimer of warranties; and
10f7045ac0SArchie Cobbs.\" 2. No rights are granted, in any manner or form, to use Whistle
11f7045ac0SArchie Cobbs.\"    Communications, Inc. trademarks, including the mark "WHISTLE
12f7045ac0SArchie Cobbs.\"    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
13f7045ac0SArchie Cobbs.\"    such appears in the above copyright notice or in the software.
14f7045ac0SArchie Cobbs.\"
15f7045ac0SArchie Cobbs.\" THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
16f7045ac0SArchie Cobbs.\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
17f7045ac0SArchie Cobbs.\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
18f7045ac0SArchie Cobbs.\" INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
19f7045ac0SArchie Cobbs.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
20f7045ac0SArchie Cobbs.\" WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
21f7045ac0SArchie Cobbs.\" REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
22f7045ac0SArchie Cobbs.\" SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
23f7045ac0SArchie Cobbs.\" IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
24f7045ac0SArchie Cobbs.\" RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
25f7045ac0SArchie Cobbs.\" WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26f7045ac0SArchie Cobbs.\" PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
27f7045ac0SArchie Cobbs.\" SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
28f7045ac0SArchie Cobbs.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29f7045ac0SArchie Cobbs.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30f7045ac0SArchie Cobbs.\" THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
31f7045ac0SArchie Cobbs.\" OF SUCH DAMAGE.
32f7045ac0SArchie Cobbs.\"
33eddc45e7SJeroen Ruigrok van der Werven.\" Author: Archie Cobbs <archie@FreeBSD.org>
34f7045ac0SArchie Cobbs.\"
35f7045ac0SArchie Cobbs.\" $FreeBSD$
36f7045ac0SArchie Cobbs.\"
37f7045ac0SArchie Cobbs.Dd November 15, 1999
38bec35b9aSArchie Cobbs.Dt NG_KSOCKET 4
393d45e180SRuslan Ermilov.Os
40f7045ac0SArchie Cobbs.Sh NAME
41f7045ac0SArchie Cobbs.Nm ng_ksocket
42f7045ac0SArchie Cobbs.Nd kernel socket netgraph node type
43f7045ac0SArchie Cobbs.Sh SYNOPSIS
44f7045ac0SArchie Cobbs.Fd #include <netgraph/ng_ksocket.h>
45f7045ac0SArchie Cobbs.Sh DESCRIPTION
46f7045ac0SArchie CobbsA
47f7045ac0SArchie Cobbs.Nm ksocket
48753d686dSRuslan Ermilovnode is both a netgraph node and a
49753d686dSRuslan Ermilov.Bx
50753d686dSRuslan Ermilovsocket.  The
5151291597SJulian Elischer.Nm
52f7045ac0SArchie Cobbsnode type allows one to open a socket inside the kernel and have
53f7045ac0SArchie Cobbsit appear as a Netgraph node.  The
5451291597SJulian Elischer.Nm
55f7045ac0SArchie Cobbsnode type is the reverse of the socket node type (see
56bec35b9aSArchie Cobbs.Xr ng_socket 4 ) :
57f7045ac0SArchie Cobbswhereas the socket node type enables the user-level manipulation (via
588e078873SArchie Cobbsa socket) of what is normally a kernel-level entity (the associated
598e078873SArchie CobbsNetgraph node), the
6051291597SJulian Elischer.Nm
61f7045ac0SArchie Cobbsnode type enables the kernel-level manipulation (via a Netgraph node) of
628e078873SArchie Cobbswhat is normally a user-level entity (the associated socket).
63f7045ac0SArchie Cobbs.Pp
64f7045ac0SArchie CobbsA
6551291597SJulian Elischer.Nm
66f7045ac0SArchie Cobbsnode allows at most one hook connection.  Connecting to the node is
67f7045ac0SArchie Cobbsequivalent to opening the associated socket.  The name given to the hook
688e078873SArchie Cobbsdetermines what kind of socket the node will open (see below).
69f7045ac0SArchie CobbsWhen the hook is disconnected and/or the node is shutdown, the
70f7045ac0SArchie Cobbsassociated socket is closed.
71f7045ac0SArchie Cobbs.Sh HOOKS
72f7045ac0SArchie CobbsThis node type supports a single hook connection at a time.
73f7045ac0SArchie CobbsThe name of the hook must be of the form
74c2d03ea8SRuslan Ermilov.Em <family>/<type>/<proto> ,
75f7045ac0SArchie Cobbswhere the
76c2d03ea8SRuslan Ermilov.Em family ,
77c2d03ea8SRuslan Ermilov.Em type ,
78f7045ac0SArchie Cobbsand
79c2d03ea8SRuslan Ermilov.Em proto
80f7045ac0SArchie Cobbsare the decimal equivalent of the same arguments to
81f7045ac0SArchie Cobbs.Xr socket 2 .
82f7045ac0SArchie CobbsAlternately, aliases for the commonly used values are accepted as
83f7045ac0SArchie Cobbswell.  For example
84f7045ac0SArchie Cobbs.Dv inet/dgram/udp
85f7045ac0SArchie Cobbsis a more readable but equivalent version of
86f7045ac0SArchie Cobbs.Dv 2/2/17 .
87f7045ac0SArchie Cobbs.Sh CONTROL MESSAGES
88f7045ac0SArchie CobbsThis node type supports the generic control messages, plus the following:
89f7045ac0SArchie Cobbs.Bl -tag -width foo
90f7045ac0SArchie Cobbs.It Dv NGM_KSOCKET_BIND
91f7045ac0SArchie CobbsThis functions exactly like the
92f7045ac0SArchie Cobbs.Xr bind 2
93f7045ac0SArchie Cobbssystem call.  The
94f7045ac0SArchie Cobbs.Dv "struct sockaddr"
95f7045ac0SArchie Cobbssocket address parameter should be supplied as an argument.
96f7045ac0SArchie Cobbs.It Dv NGM_KSOCKET_LISTEN
97f7045ac0SArchie CobbsThis functions exactly like the
98f7045ac0SArchie Cobbs.Xr listen 2
998e078873SArchie Cobbssystem call.  The backlog paramter (a single 32 bit
100f7045ac0SArchie Cobbs.Dv int )
101f7045ac0SArchie Cobbsshould be supplied as an argument.
102f7045ac0SArchie Cobbs.It Dv NGM_KSOCKET_CONNECT
103f7045ac0SArchie CobbsThis functions exactly like the
104f7045ac0SArchie Cobbs.Xr connect 2
105f7045ac0SArchie Cobbssystem call.  The
106f7045ac0SArchie Cobbs.Dv "struct sockaddr"
1078e078873SArchie Cobbsdestination address parameter should be supplied as an argument.
108f7045ac0SArchie Cobbs.It Dv NGM_KSOCKET_ACCEPT
109f7045ac0SArchie CobbsCurrently unimplemented.
110f7045ac0SArchie Cobbs.It Dv NGM_KSOCKET_GETNAME
1118e078873SArchie CobbsEquivalent to the
112000d5619SMaxim Sobolev.Xr getsockname 2
1138e078873SArchie Cobbssystem call.  The name is returned as a
1148e078873SArchie Cobbs.Dv "struct sockaddr"
1158e078873SArchie Cobbsin the arguments field of the reply.
116f7045ac0SArchie Cobbs.It Dv NGM_KSOCKET_GETPEERNAME
1178e078873SArchie CobbsEquivalent to the
1188e078873SArchie Cobbs.Xr getpeername 2
1198e078873SArchie Cobbssystem call.  The name is returned as a
1208e078873SArchie Cobbs.Dv "struct sockaddr"
1218e078873SArchie Cobbsin the arguments field of the reply.
122f7045ac0SArchie Cobbs.It Dv NGM_KSOCKET_SETOPT
1238e078873SArchie CobbsEquivalent to the
1248e078873SArchie Cobbs.Xr setsockopt 2
1258e078873SArchie Cobbssystem call, except that the option name, level, and value are passed in a
1268e078873SArchie Cobbs.Dv "struct ng_ksocket_sockopt" .
127f7045ac0SArchie Cobbs.It Dv NGM_KSOCKET_GETOPT
1288e078873SArchie CobbsEquivalent to the
1298e078873SArchie Cobbs.Xr getsockopt 2
1308e078873SArchie Cobbssystem call, except that the option is passed in a
1318e078873SArchie Cobbs.Dv "struct ng_ksocket_sockopt" .
1328e078873SArchie CobbsWhen sending this command, the
1338e078873SArchie Cobbs.Dv value
1348e078873SArchie Cobbsfield should be empty; upon return, it will contain the
1358e078873SArchie Cobbsretrieved value.
136f7045ac0SArchie Cobbs.El
1378e078873SArchie Cobbs.Sh ASCII FORM CONTROL MESSAGES
1388e078873SArchie CobbsFor control messages that pass a
1398e078873SArchie Cobbs.Dv "struct sockaddr"
14051291597SJulian Elischerin the argument field, the normal
14151291597SJulian Elischer.Tn ASCII
14251291597SJulian Elischerequivalent of the C structure
1438e078873SArchie Cobbsis an acceptable form.  For the
1448e078873SArchie Cobbs.Dv PF_INET
1458e078873SArchie Cobbsand
1468e078873SArchie Cobbs.Dv PF_LOCAL
1478e078873SArchie Cobbsaddress families, a more convenient form is also used, which is
1488e078873SArchie Cobbsthe protocol family name, followed by a slash, followed by the actual
1498e078873SArchie Cobbsaddress.  For
1508e078873SArchie Cobbs.Dv PF_INET ,
1518e078873SArchie Cobbsthe address is an IP address followed by an optional colon and port number.
1528e078873SArchie CobbsFor
1538e078873SArchie Cobbs.Dv PF_LOCAL ,
1548e078873SArchie Cobbsthe address is the pathname as a doubly quoted string.
1558e078873SArchie Cobbs.Pp
1568e078873SArchie CobbsExamples:
1578e078873SArchie Cobbs.Bl -tag -width XXXXXXXXXX
1588e078873SArchie Cobbs.It Dv PF_LOCAL
1598e078873SArchie Cobbslocal/"/tmp/foo.socket"
160ef02c1e5SArchie Cobbs.It Dv PF_INET
161ef02c1e5SArchie Cobbsinet/192.168.1.1:1234
1628e078873SArchie Cobbs.It Other
163ef02c1e5SArchie Cobbs.Dv "\&{ family=16 len=16 data=[0x70 0x00 0x01 0x23] \&}"
1648e078873SArchie Cobbs.El
1658e078873SArchie Cobbs.Pp
1668e078873SArchie CobbsFor control messages that pass a
1678e078873SArchie Cobbs.Dv "struct ng_ksocket_sockopt" ,
16851291597SJulian Elischerthe normal
16951291597SJulian Elischer.Tn ASCII
17051291597SJulian Elischerform for that structure is used.  In the future, more
1718e078873SArchie Cobbsconvenient encoding of the more common socket options may be supported.
172f7045ac0SArchie Cobbs.Sh SHUTDOWN
173f7045ac0SArchie CobbsThis node shuts down upon receipt of a
174f7045ac0SArchie Cobbs.Dv NGM_SHUTDOWN
175f7045ac0SArchie Cobbscontrol message, or when the hook is disconnected.
176f7045ac0SArchie CobbsShutdown of the node closes the associated socket.
177f7045ac0SArchie Cobbs.Sh SEE ALSO
178f7045ac0SArchie Cobbs.Xr socket 2 ,
179f7045ac0SArchie Cobbs.Xr netgraph 4 ,
180bec35b9aSArchie Cobbs.Xr ng_socket 4 ,
181bec35b9aSArchie Cobbs.Xr ngctl 8
18251291597SJulian Elischer.Sh HISTORY
18351291597SJulian ElischerThe
18451291597SJulian Elischer.Nm
18551291597SJulian Elischernode type was implemented in
18651291597SJulian Elischer.Fx 4.0 .
18751291597SJulian Elischer.Sh AUTHORS
188eddc45e7SJeroen Ruigrok van der Werven.An Archie Cobbs Aq archie@FreeBSD.org
189