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