]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libnetgraph/netgraph.3
This commit was generated by cvs2svn to compensate for changes in r52894,
[FreeBSD/FreeBSD.git] / lib / libnetgraph / netgraph.3
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@whistle.com>
34 .\"
35 .\" $FreeBSD$
36 .\" $Whistle: netgraph.3,v 1.7 1999/01/25 07:14:06 archie Exp $
37 .\"
38 .Dd January 19, 1999
39 .Dt NETGRAPH 3
40 .Os FreeBSD 3
41 .Sh NAME
42 .Nm NgMkSockNode ,
43 .Nm NgNameNode ,
44 .Nm NgSendMsg ,
45 .Nm NgRecvMsg ,
46 .Nm NgSendData ,
47 .Nm NgRecvData ,
48 .Nm NgSetDebug ,
49 .Nm NgSetErrLog
50 .Nd Netgraph user library
51 .Sh SYNOPSIS
52 .Fd #include <netgraph.h>
53 .Ft int
54 .Fn NgMkSockNode "const char *name" "int *csp" "int *dsp"
55 .Ft int
56 .Fn NgNameNode "int cs" "const char *path" "const char *fmt" "..."
57 .Ft int
58 .Fn NgSendMsg "int cs" "const char *path" "int cookie" "int cmd" "const void *arg" "size_t arglen"
59 .Ft int
60 .Fn NgSendMsgReply "int cs" "const char *path" "struct ng_mesg *msg" "const void *arg" "size_t arglen"
61 .Ft int
62 .Fn NgRecvMsg "int cs" "struct ng_mesg *rep" "size_t replen" "char *path"
63 .Ft int
64 .Fn NgSendData "int ds" "const char *hook" "const u_char *buf" "size_t len"
65 .Ft int
66 .Fn NgRecvData "int ds" "u_char *buf" "size_t len" "char *hook"
67 .Ft int
68 .Fn NgSetDebug "int level"
69 .Ft void
70 .Fn NgSetErrLog "void (*log)(const char *fmt, ...)" "void (*logx)(const char *fmt, ...)"
71 .Sh DESCRIPTION
72 These functions facilitate user-mode program participation in the kernel
73 .Xr netgraph 4
74 graph-based networking system, by utilizing the netgraph
75 .Em socket
76 node type (see
77 .Xr ng_socket 8 ")."
78 .Pp
79 .Fn NgMkSockNode
80 should be called first, to create a new
81 .Em socket
82 type netgraph node with associated control and data sockets.  If
83 .Fa name
84 is non-NULL, the node will have that global name assigned to it.
85 .Fa "*csp"
86 and
87 .Fa "*dsp"
88 will be set to the newly opened control and data sockets
89 associated with the node; either
90 .Fa "csp"
91 or
92 .Fa "dsp"
93 may be NULL if only one socket is desired.
94 .Pp
95 .Fn NgNameNode
96 assigns a global name to the node addressed by
97 .Fa path .
98 .Pp
99 .Fn NgSendMsg
100 sends a control message from the socket node associated with control socket
101 .Fa cs
102 to the node addressed by
103 .Fa path .
104 The
105 .Fa cookie
106 indicates how to interpret
107 .Fa cmd ,
108 which indicates a specific command.
109 Extra argument data (if any) is specified by
110 .Fa arg
111 and
112 .Fa arglen .
113 The
114 .Fa cookie ,
115 .Fa cmd ,
116 and argument data are defined by the header file corresponding
117 to the type of the node being addressed.
118 .Pp
119 Use
120 .Fn NgSendMsgReply
121 to send reply to a previously received control message.
122 The original message header should be pointed to by
123 .Fa msg .
124 .Pp
125 .Fn NgRecvMsg
126 reads the next control message received by the node associated with
127 control socket
128 .Fa cs .
129 The message and any extra argument data must fit in
130 .Fa replen
131 bytes.
132 If
133 .Fa "path"
134 is non-NULL, it must point to a buffer of at least
135 .Dv "NG_PATHLEN + 1"
136 bytes, which will be filled in (and NUL terminated) with the path to
137 the node from which the message was received.
138 .Pp
139 .Fn NgSendData
140 writes a data packet out on the specified hook of the node corresponding
141 to data socket
142 .Fa ds .
143 The node must already be connected to some other node via that hook.
144 .Pp
145 .Fn NgRecvData
146 reads the next data packet (of up to
147 .Fa len
148 bytes) received by the node corresponding to data socket
149 .Fa ds
150 and stores it in
151 .Fa buf ,
152 which must be large enough to hold the entire packet.  If
153 .Fa "hook"
154 is non-NULL, it must point to a buffer of at least
155 .Dv "NG_HOOKLEN + 1"
156 bytes, which will be filled in (and NUL terminated) with the name of
157 the hook on which the data was received.
158 .Pp
159 .Fn NgSetDebug
160 and
161 .Fn NgSetErrLog
162 are used for debugging.
163 .Fn NgSetDebug
164 sets the debug level (if non-negative), and returns the old setting.
165 Higher debug levels result in more verbosity.  The default is zero.
166 All debug and error messages are logged via the functions
167 specified in the most recent call to
168 .Fn NgSetErrLog .
169 The default logging functions are
170 .Xr vwarn 3
171 and
172 .Xr vwarnx 3 .
173 .Pp
174 Note that
175 .Xr select 2
176 can be used on the data and the control sockets to detect the presence of
177 incoming data and control messages, respectively.
178 Data and control packets are always written and read atomically, i.e.,
179 in one whole piece.
180 .Pp
181 User mode programs must be linked with the
182 .Dv -lnetgraph
183 flag to link in this library.
184 .Sh INITIALIZATION
185 Netgraph is not part of the standard FreeBSD kernel. To enable it,
186 either your kernel must be compiled with ``options NETGRAPH''
187 in the kernel configuration file, or else the
188 .Xr netgraph 4
189 and
190 .Xr ng_socket 8
191 KLD modules must have been loaded via
192 .Xr kldload 8 .
193 .Sh DIAGNOSTICS
194 All functions except
195 .Fn NgSetDebug
196 and
197 .Fn NgSetErrLog
198 return -1 if there was an error and set errno accordingly.
199 .Sh SEE ALSO
200 .Xr netgraph 4 ,
201 .Xr socket 2 ,
202 .Xr select 2 ,
203 .Xr warnx 3 ,
204 .Xr ng_socket 8 .
205 .Sh HISTORY
206 The
207 .Em netgraph
208 system was designed and first implemented at Whistle Communications, Inc.
209 in a version FreeBSD 2.2 customized for the Whistle InterJet.
210 .Sh AUTHOR
211 .An Archie Cobbs <archie@whistle.com>