xref: /freebsd/lib/libnetgraph/netgraph.3 (revision 4cf49a43559ed9fdad601bdcccd2c55963008675)
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
72These functions facilitate user-mode program participation in the kernel
73.Xr netgraph 4
74graph-based networking system, by utilizing the netgraph
75.Em socket
76node type (see
77.Xr ng_socket 8 ")."
78.Pp
79.Fn NgMkSockNode
80should be called first, to create a new
81.Em socket
82type netgraph node with associated control and data sockets.  If
83.Fa name
84is non-NULL, the node will have that global name assigned to it.
85.Fa "*csp"
86and
87.Fa "*dsp"
88will be set to the newly opened control and data sockets
89associated with the node; either
90.Fa "csp"
91or
92.Fa "dsp"
93may be NULL if only one socket is desired.
94.Pp
95.Fn NgNameNode
96assigns a global name to the node addressed by
97.Fa path .
98.Pp
99.Fn NgSendMsg
100sends a control message from the socket node associated with control socket
101.Fa cs
102to the node addressed by
103.Fa path .
104The
105.Fa cookie
106indicates how to interpret
107.Fa cmd ,
108which indicates a specific command.
109Extra argument data (if any) is specified by
110.Fa arg
111and
112.Fa arglen .
113The
114.Fa cookie ,
115.Fa cmd ,
116and argument data are defined by the header file corresponding
117to the type of the node being addressed.
118.Pp
119Use
120.Fn NgSendMsgReply
121to send reply to a previously received control message.
122The original message header should be pointed to by
123.Fa msg .
124.Pp
125.Fn NgRecvMsg
126reads the next control message received by the node associated with
127control socket
128.Fa cs .
129The message and any extra argument data must fit in
130.Fa replen
131bytes.
132If
133.Fa "path"
134is non-NULL, it must point to a buffer of at least
135.Dv "NG_PATHLEN + 1"
136bytes, which will be filled in (and NUL terminated) with the path to
137the node from which the message was received.
138.Pp
139.Fn NgSendData
140writes a data packet out on the specified hook of the node corresponding
141to data socket
142.Fa ds .
143The node must already be connected to some other node via that hook.
144.Pp
145.Fn NgRecvData
146reads the next data packet (of up to
147.Fa len
148bytes) received by the node corresponding to data socket
149.Fa ds
150and stores it in
151.Fa buf ,
152which must be large enough to hold the entire packet.  If
153.Fa "hook"
154is non-NULL, it must point to a buffer of at least
155.Dv "NG_HOOKLEN + 1"
156bytes, which will be filled in (and NUL terminated) with the name of
157the hook on which the data was received.
158.Pp
159.Fn NgSetDebug
160and
161.Fn NgSetErrLog
162are used for debugging.
163.Fn NgSetDebug
164sets the debug level (if non-negative), and returns the old setting.
165Higher debug levels result in more verbosity.  The default is zero.
166All debug and error messages are logged via the functions
167specified in the most recent call to
168.Fn NgSetErrLog .
169The default logging functions are
170.Xr vwarn 3
171and
172.Xr vwarnx 3 .
173.Pp
174Note that
175.Xr select 2
176can be used on the data and the control sockets to detect the presence of
177incoming data and control messages, respectively.
178Data and control packets are always written and read atomically, i.e.,
179in one whole piece.
180.Pp
181User mode programs must be linked with the
182.Dv -lnetgraph
183flag to link in this library.
184.Sh INITIALIZATION
185Netgraph is not part of the standard FreeBSD kernel. To enable it,
186either your kernel must be compiled with ``options NETGRAPH''
187in the kernel configuration file, or else the
188.Xr netgraph 4
189and
190.Xr ng_socket 8
191KLD modules must have been loaded via
192.Xr kldload 8 .
193.Sh DIAGNOSTICS
194All functions except
195.Fn NgSetDebug
196and
197.Fn NgSetErrLog
198return -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
206The
207.Em netgraph
208system was designed and first implemented at Whistle Communications, Inc.
209in a version FreeBSD 2.2 customized for the Whistle InterJet.
210.Sh AUTHOR
211.An Archie Cobbs <archie@whistle.com>
212