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 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. For example 88.Dv inet/dgram/udp 89is a more readable but equivalent version of 90.Dv 2/2/17 . 91.Sh CONTROL MESSAGES 92This node type supports the generic control messages, plus the following: 93.Bl -tag -width foo 94.It Dv NGM_KSOCKET_BIND 95This functions exactly like the 96.Xr bind 2 97system call. 98The 99.Dv "struct sockaddr" 100socket address parameter should be supplied as an argument. 101.It Dv NGM_KSOCKET_LISTEN 102This functions exactly like the 103.Xr listen 2 104system call. 105The backlog parameter (a single 32 bit 106.Dv int ) 107should be supplied as an argument. 108.It Dv NGM_KSOCKET_CONNECT 109This functions exactly like the 110.Xr connect 2 111system call. 112The 113.Dv "struct sockaddr" 114destination address parameter should be supplied as an argument. 115.It Dv NGM_KSOCKET_ACCEPT 116Currently unimplemented. 117.It Dv NGM_KSOCKET_GETNAME 118Equivalent to the 119.Xr getsockname 2 120system call. 121The name is returned as a 122.Dv "struct sockaddr" 123in the arguments field of the reply. 124.It Dv NGM_KSOCKET_GETPEERNAME 125Equivalent to the 126.Xr getpeername 2 127system call. 128The name is returned as a 129.Dv "struct sockaddr" 130in the arguments field of the reply. 131.It Dv NGM_KSOCKET_SETOPT 132Equivalent to the 133.Xr setsockopt 2 134system call, except that the option name, level, and value are passed in a 135.Dv "struct ng_ksocket_sockopt" . 136.It Dv NGM_KSOCKET_GETOPT 137Equivalent to the 138.Xr getsockopt 2 139system call, except that the option is passed in a 140.Dv "struct ng_ksocket_sockopt" . 141When sending this command, the 142.Dv value 143field should be empty; upon return, it will contain the 144retrieved value. 145.El 146.Sh ASCII FORM CONTROL MESSAGES 147For control messages that pass a 148.Dv "struct sockaddr" 149in the argument field, the normal 150.Tn ASCII 151equivalent of the C structure 152is an acceptable form. 153For the 154.Dv PF_INET 155and 156.Dv PF_LOCAL 157address families, a more convenient form is also used, which is 158the protocol family name, followed by a slash, followed by the actual 159address. 160For 161.Dv PF_INET , 162the address is an IP address followed by an optional colon and port number. 163For 164.Dv PF_LOCAL , 165the address is the pathname as a doubly quoted string. 166.Pp 167Examples: 168.Bl -tag -width XXXXXXXXXX 169.It Dv PF_LOCAL 170local/"/tmp/foo.socket" 171.It Dv PF_INET 172inet/192.168.1.1:1234 173.It Other 174.Dv "\&{ family=16 len=16 data=[0x70 0x00 0x01 0x23] \&}" 175.El 176.Pp 177For control messages that pass a 178.Dv "struct ng_ksocket_sockopt" , 179the normal 180.Tn ASCII 181form for that structure is used. 182In the future, more 183convenient encoding of the more common socket options may be supported. 184.Sh SHUTDOWN 185This node shuts down upon receipt of a 186.Dv NGM_SHUTDOWN 187control message, or when the hook is disconnected. 188Shutdown of the node closes the associated socket. 189.Sh SEE ALSO 190.Xr socket 2 , 191.Xr netgraph 4 , 192.Xr ng_socket 4 , 193.Xr ngctl 8 194.Sh HISTORY 195The 196.Nm 197node type was implemented in 198.Fx 4.0 . 199.Sh AUTHORS 200.An Archie Cobbs Aq archie@FreeBSD.org 201