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