1 .\" Copyright (c) 1996-1999 Whistle Communications, Inc.
2 .\" All rights reserved.
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.
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
33 .\" Author: Archie Cobbs <archie@whistle.com>
35 .\" $FreeBSD: src/lib/libnetgraph/netgraph.3,v 1.4.2.10 2002/12/29 16:35:36 schweikh Exp $
36 .\" $DragonFly: src/lib/libnetgraph/netgraph.3,v 1.5 2007/06/03 23:41:25 swildner Exp $
37 .\" $Whistle: netgraph.3,v 1.7 1999/01/25 07:14:06 archie Exp $
51 .Nm NgAllocRecvAsciiMsg ,
57 .Nd netgraph user library
63 .Fn NgMkSockNode "const char *name" "int *csp" "int *dsp"
65 .Fn NgNameNode "int cs" "const char *path" "const char *fmt" ...
68 .Fa "int cs" "const char *path" "int cookie" "int cmd" "const void *arg"
72 .Fn NgSendAsciiMsg "int cs" "const char *path" "const char *fmt" ...
75 .Fa "int cs" "const char *path" "struct ng_mesg *msg" "const void *arg"
79 .Fn NgRecvMsg "int cs" "struct ng_mesg *rep" "size_t replen" "char *path"
81 .Fn NgAllocRecvMsg "int cs" "struct ng_mesg **rep" "char *path"
83 .Fn NgRecvAsciiMsg "int cs" "struct ng_mesg *rep" "size_t replen" "char *path"
85 .Fn NgAllocRecvAsciiMsg "int cs" "struct ng_mesg **rep" "char *path"
87 .Fn NgSendData "int ds" "const char *hook" "const u_char *buf" "size_t len"
89 .Fn NgRecvData "int ds" "u_char *buf" "size_t len" "char *hook"
91 .Fn NgAllocRecvData "int ds" "u_char **buf" "char *hook"
93 .Fn NgSetDebug "int level"
96 .Fa "void \*[lp]*log\*[rp]\*[lp]const char *fmt, ...\*[rp]"
97 .Fa "void \*[lp]*logx\*[rp]\*[lp]const char *fmt, ...\*[rp]"
100 These functions facilitate user-mode program participation in the kernel
102 graph-based networking system, by utilizing the netgraph
109 function should be called first, to create a new
111 type netgraph node with associated control and data sockets.
115 .No non- Ns Dv NULL ,
116 the node will have that global name assigned to it.
121 arguments will be set to the newly opened control and data sockets
122 associated with the node; either
128 if only one socket is desired.
133 node type KLD if it is not already loaded.
137 function assigns a global name to the node addressed by
142 function sends a binary control message from the
144 node associated with control socket
146 to the node addressed by
150 indicates how to interpret
152 which indicates a specific command.
153 Extra argument data (if any) is specified by
159 and argument data are defined by the header file corresponding
160 to the type of the node being addressed.
161 The unique, non-negative token value chosen for use in the message
163 This value is typically used to associate replies.
167 to send reply to a previously received control message.
168 The original message header should be pointed to by
173 function performs the same function as
177 encoding of control messages.
180 function formats its input a la
182 and then sends the resulting
184 string to the node in a
187 The node returns a binary version of the
188 message, which is then sent back to the node just as with
192 the message token value is returned.
195 conversion may not be supported by all node types.
199 function reads the next control message received by the node associated with
202 The message and any extra argument data must fit in
208 .No non- Ns Dv NULL ,
209 it must point to a buffer of at least
211 bytes, which will be filled in (and
213 terminated) with the path to
214 the node from which the message was received.
216 The length of the control message is returned.
217 A return value of zero indicates that the socket was closed.
221 function works exactly like
223 except that the buffer for a message is dynamically allocated
224 to guarantee that a message is not truncated.
225 The size of the buffer is equal to the socket's receive buffer size.
226 The caller is responsible for freeing the buffer when it is no longer required.
230 function works exactly like
232 except that after the message is received, any binary arguments
237 request back to the originating node.
238 The result is the same as
240 with the exception that the reply arguments field will contain a
241 .Dv NUL Ns -terminated
243 version of the arguments (and the reply
244 header argument length field will be adjusted).
247 .Fn NgAllocRecvAsciiMsg
248 function works exactly like
250 except that the buffer for a message is dynamically allocated
251 to guarantee that a message is not truncated.
252 The size of the buffer is equal to the socket's receive buffer size.
253 The caller is responsible for freeing the buffer when it is no longer required.
257 function writes a data packet out on the specified hook of the node
258 corresponding to data socket
260 The node must already be connected to some other node via that hook.
264 function reads the next data packet (of up to
266 bytes) received by the node corresponding to data socket
270 which must be large enough to hold the entire packet.
274 .No non- Ns Dv NULL ,
275 it must point to a buffer of at least
277 bytes, which will be filled in (and
279 terminated) with the name of
280 the hook on which the data was received.
282 The length of the packet is returned.
283 A return value of zero indicates that the socket was closed.
287 function works exactly like
289 except that the buffer for a data packet is dynamically allocated
290 to guarantee that a data packet is not truncated.
291 The size of the buffer is equal to the socket's receive buffer size.
292 The caller is responsible for freeing the buffer when it is no longer required.
298 functions are used for debugging.
301 function sets the debug level (if non-negative), and returns the old setting.
302 Higher debug levels result in more verbosity.
304 All debug and error messages are logged via the functions
305 specified in the most recent call to
307 The default logging functions are
312 At debug level 3, the library attempts to display control message arguments
315 format; however, this results in additional messages being
316 sent which may interfere with debugging.
317 At even higher levels,
318 even these additional messages will be displayed, etc.
322 can be used on the data and the control sockets to detect the presence of
323 incoming data and control messages, respectively.
324 Data and control packets are always written and read atomically, i.e.,
327 User mode programs must be linked with the
329 flag to link in this library.
331 To enable netgraph in your kernel, either your kernel must be
333 .Cd "options NETGRAPH"
334 in the kernel configuration
339 KLD modules must have been loaded via
344 function returns the previous debug setting.
348 function has no return value.
350 All other functions return \-1 if there was an error and set
354 A return value of zero from
358 indicates that the netgraph socket has been closed.
364 the following additional errors are possible:
367 The node type does not know how to encode or decode the control message.
369 The encoded or decoded arguments were too long for the supplied buffer.
371 An unknown structure field was seen in an
375 The same structure field was specified twice in an
380 control message parse error or illegal value.
382 ASCII control message array or fixed width string buffer overflow.
394 system was designed and first implemented at Whistle Communications, Inc.\& in
397 customized for the Whistle InterJet.
399 .An "Archie Cobbs" Aq archie@FreeBSD.org