The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/modules/netgraph/socket/ng_socket.4

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 .\" Copyright (c) 1996-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 .\" $Whistle: ng_socket.8,v 1.5 1999/01/25 23:46:27 archie Exp $
   37 .\"
   38 .Dd January 19, 1999
   39 .Dt NG_SOCKET 4
   40 .Os FreeBSD
   41 .Sh NAME
   42 .Nm ng_socket
   43 .Nd netgraph socket node type
   44 .Sh SYNOPSIS
   45 .Fd #include <netgraph/ng_message.h>
   46 .Fd #include <netgraph/ng_socket.h>
   47 .Sh DESCRIPTION
   48 A
   49 .Nm socket
   50 node is both a BSD socket and a netgraph node.  The
   51 .Nm
   52 node type allows user-mode processes to participate in the kernel
   53 .Xr netgraph 4
   54 networking subsystem using the BSD socket interface. The process must have
   55 root privileges to be able to create netgraph sockets however once created,
   56 any process that has one may use it.
   57 .Pp
   58 A new
   59 .Nm
   60 node is created by creating a new socket of type
   61 .Dv NG_CONTROL
   62 in the protocol family
   63 .Dv PF_NETGRAPH ,
   64 using the
   65 .Xr socket 2
   66 system call.
   67 Any control messages received by the node 
   68 and not having a cookie value of 
   69 .Dv NGM_SOCKET_COOKIE
   70 are received  by the process, using
   71 .Xr recvfrom 2 ;
   72 the socket address argument is a
   73 .Dv "struct sockaddr_ng"
   74 containing the sender's netgraph address. Conversely, control messages
   75 can be sent to any node by calling
   76 .Xr sendto 2 ,
   77 supplying the recipient's address in a
   78 .Dv "struct sockaddr_ng" .
   79 The
   80 .Xr bind 2
   81 system call may be used to assign a global netgraph name to the node.
   82 .Pp
   83 To transmit and receive netgraph data packets, a
   84 .Dv NG_DATA
   85 socket must also be created using
   86 .Xr socket 2
   87 and associated with a
   88 .Nm
   89 node.
   90 .Dv NG_DATA sockets do not automatically
   91 have nodes associated with them; they are bound to a specific node via the
   92 .Xr connect 2
   93 system call. The address argument is the netgraph address of the
   94 .Nm
   95 node already created. Once a data socket is associated with a node,
   96 any data packets received by the node are read using
   97 .Xr recvfrom 2
   98 and any packets to be sent out from the node are written using
   99 .Xr sendto 2 .
  100 In the case of data sockets, the
  101 .Dv "struct sockaddr_ng"
  102 contains the name of the
  103 .Em hook
  104 on which the data was received or should be sent.
  105 .Pp
  106 As a special case, to allow netgraph data sockets to be used as stdin or stdout
  107 on naive programs, a
  108 .Xr sendto  2
  109 with a NULL sockaddr pointer, a 
  110 .Xr send 2
  111 or a 
  112 .Xr write 2
  113 will succeed in the case where there is exactly ONE hook  attached to
  114 the socket node, (and thus the path is unambiguous).
  115 .Pp
  116 There is a user library that simplifies using netgraph sockets; see
  117 .Xr netgraph 3 .
  118 .Sh HOOKS
  119 This node type supports hooks with arbitrary names (as long as
  120 they are unique) and always accepts hook connection requests.
  121 .Sh CONTROL MESSAGES
  122 This node type supports the generic control messages, plus the following:
  123 .Bl -tag -width foo
  124 .It Dv NGM_SOCK_CMD_NOLINGER
  125 When the last hook is removed from this node, it will shut down as
  126 if it had received a 
  127 .Dv NGM_SHUTDOWN
  128 message. Attempts to access the sockets associated will return
  129 .Er ENOTCONN .
  130 .It Dv NGM_SOCK_CMD_LINGER
  131 This is the default mode. When the last hook is removed, the node will
  132 continue to exist, ready to accept new hooks until it
  133 is explicitly shut down.
  134 .El
  135 .Pp
  136 All other messages
  137 with neither the
  138 .Dv NGM_SOCKET_COOKIE
  139 or
  140 .Dv NGM_GENERIC_COOKIE
  141 will be passed unaltered up the 
  142 .Dv NG_CONTROL 
  143 socket.
  144 .Sh SHUTDOWN
  145 This node type shuts down and disappears when both the associated
  146 .Dv NG_CONTROL
  147 and
  148 .Dv NG_DATA
  149 sockets have been closed, or a
  150 .Dv NGM_SHUTDOWN
  151 control message is received. In the latter case, attempts to write
  152 to the still-open sockets will return
  153 .Er ENOTCONN .
  154 If the 
  155 .Dv NGM_SOCK_CMD_NOLINGER
  156 message has been received, closure of the last hook will also initiate
  157 a shutdown of the node.
  158 .Sh BUGS
  159 It is not possible to reject the connection of a hook, though any
  160 data received on that hook can certainly be ignored.
  161 .Pp
  162 The controlling process is not notified of all events that an in-kernel node
  163 would be notified of, e.g. a new hook, or hook removal. We should define
  164 some node-initiated messages for this purpose (to be sent up the control
  165 socket).
  166 .Sh SEE ALSO
  167 .Xr socket 2 ,
  168 .Xr netgraph 3 ,
  169 .Xr netgraph 4 ,
  170 .Xr ng_ksocket 4 ,
  171 .Xr ngctl 8
  172 .Sh HISTORY
  173 The
  174 .Nm
  175 node type was implemented in
  176 .Fx 4.0 .
  177 .Sh AUTHORS
  178 .An Julian Elischer Aq julian@freebsd.org

Cache object: 7d91705c9c15e224478069584f33fa98


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.