diff options
author | ru <ru@FreeBSD.org> | 2004-07-02 08:52:09 +0000 |
---|---|---|
committer | ru <ru@FreeBSD.org> | 2004-07-02 08:52:09 +0000 |
commit | 41d36aefb38f8bad41cc9b6e44161f63fb8404b2 (patch) | |
tree | 94a25b1fd008d156bc5483d4ce40ee0d19648028 /share/man/man4 | |
parent | 5d8d5641262180b8c504204b8fb978a5193958e3 (diff) | |
download | FreeBSD-src-41d36aefb38f8bad41cc9b6e44161f63fb8404b2.zip FreeBSD-src-41d36aefb38f8bad41cc9b6e44161f63fb8404b2.tar.gz |
Markup overhaul and minor word smithing.
Diffstat (limited to 'share/man/man4')
-rw-r--r-- | share/man/man4/netgraph.4 | 882 |
1 files changed, 483 insertions, 399 deletions
diff --git a/share/man/man4/netgraph.4 b/share/man/man4/netgraph.4 index af47c6b..a81d2d2 100644 --- a/share/man/man4/netgraph.4 +++ b/share/man/man4/netgraph.4 @@ -33,23 +33,24 @@ .\" Authors: Julian Elischer <julian@FreeBSD.org> .\" Archie Cobbs <archie@FreeBSD.org> .\" -.\" $FreeBSD$ .\" $Whistle: netgraph.4,v 1.7 1999/01/28 23:54:52 julian Exp $ +.\" $FreeBSD$ .\" .Dd July 1, 2004 .Dt NETGRAPH 4 .Os .Sh NAME .Nm netgraph -.Nd graph based kernel networking subsystem +.Nd "graph based kernel networking subsystem" .Sh DESCRIPTION The .Nm system provides a uniform and modular system for the implementation -of kernel objects which perform various networking functions. The objects, -known as +of kernel objects which perform various networking functions. +The objects, known as .Em nodes , -can be arranged into arbitrarily complicated graphs. Nodes have +can be arranged into arbitrarily complicated graphs. +Nodes have .Em hooks which are used to connect two nodes together, forming the edges in the graph. Nodes communicate along the edges to process data, implement protocols, etc. @@ -60,15 +61,15 @@ is to supplement rather than replace the existing kernel networking infrastructure. It provides: .Pp -.Bl -bullet -compact -offset 2n +.Bl -bullet -compact .It -A flexible way of combining protocol and link level drivers +A flexible way of combining protocol and link level drivers. .It -A modular way to implement new protocols +A modular way to implement new protocols. .It -A common framework for kernel entities to inter-communicate +A common framework for kernel entities to inter-communicate. .It -A reasonably fast, kernel-based implementation +A reasonably fast, kernel-based implementation. .El .Ss Nodes and Types The most fundamental concept in @@ -87,8 +88,9 @@ type name. The type implies what the node does and how it may be connected to other nodes. .Pp -In object-oriented language, types are classes and nodes are instances -of their respective class. All node types are subclasses of the generic node +In object-oriented language, types are classes, and nodes are instances +of their respective class. +All node types are subclasses of the generic node type, and hence inherit certain common functionality and capabilities (e.g., the ability to have an .Tn ASCII @@ -99,43 +101,47 @@ Nodes may be assigned a globally unique name which can be used to refer to the node. The name must not contain the characters -.Dq .\& +.Ql .\& or -.Dq \&: +.Ql \&: , and is limited to -.Dv "NG_NODESIZ" -characters (including NUL byte). +.Dv NG_NODESIZ +characters (including the terminating +.Dv NUL +character). .Pp Each node instance has a unique .Em ID number -which is expressed as a 32-bit hex value. +which is expressed as a 32-bit hexadecimal value. This value may be used to refer to a node when there is no .Tn ASCII name assigned to it. .Ss Hooks Nodes are connected to other nodes by connecting a pair of .Em hooks , -one from each node. Data flows bidirectionally between nodes along +one from each node. +Data flows bidirectionally between nodes along connected pairs of hooks. A node may have as many hooks as it needs, and may assign whatever meaning it wants to a hook. .Pp Hooks have these properties: -.Pp -.Bl -bullet -compact -offset 2n +.Bl -bullet .It A hook has an .Tn ASCII name which is unique among all hooks on that node (other hooks on other nodes may have the same name). -The name must not contain a -.Dq .\& -or a -.Dq \&: +The name must not contain the characters +.Ql .\& +or +.Ql \&: , and is limited to -.Dv "NG_HOOKSIZ" -characters (including NUL byte). +.Dv NG_HOOKSIZ +characters (including the terminating +.Dv NUL +character). .It A hook is always connected to another hook. That is, hooks are @@ -147,33 +153,39 @@ by the input queueing system, rather than being delivered directly. This can be used when the data is sent from an interrupt handler, and processing must be quick so as not to block other interrupts. .It -A hook may supply over-riding receive data and receive message functions +A hook may supply overriding receive data and receive message functions which should be used for data and messages received through that hook in preference to the general node-wide methods. .El .Pp A node may decide to assign special meaning to some hooks. For example, connecting to the hook named -.Dq debug +.Va debug might trigger the node to start sending debugging information to that hook. .Ss Data Flow Two types of information flow between nodes: data messages and control messages. -Data messages are passed in mbuf chains along the edges +Data messages are passed in +.Vt mbuf chains +along the edges in the graph, one edge at a time. -The first mbuf in a chain must have the +The first +.Vt mbuf +in a chain must have the .Dv M_PKTHDR -flag set. Each node decides how to handle data coming in on its hooks. +flag set. +Each node decides how to handle data coming in on its hooks. .Pp Along with data, nodes can also receive control messages. There are generic and type-specific control messages. Control messages have a common -header format, followed by type-specific data, and are binary structures +header format, followed by a type-specific data, and are binary structures for efficiency. -However, node types also may support conversion of the +However, node types may also support conversion of the type specific data between binary and .Tn ASCII +formats, for debugging and human interface purposes (see the .Dv NGM_ASCII2BINARY and @@ -202,7 +214,8 @@ The two types of .Tn ASCII addressing may be combined, by specifying an absolute start node and a sequence -of hooks. Only the +of hooks. +Only the .Tn ASCII addressing modes are available to control programs outside the kernel, as use of direct pointers is limited of course to kernel modules. @@ -220,28 +233,31 @@ indicating the type of the message, i.e., how to interpret it. Typically each type defines a unique typecookie for the messages that it understands. However, a node may choose to recognize and -implement more than one type of message. +implement more than one type of messages. .Pp If a message is delivered to an address that implies that it arrived -at that node through a particular hook, (as opposed to having been directly -addressed using its ID or global name), then that hook is identified to the +at that node through a particular hook (as opposed to having been directly +addressed using its ID or global name) then that hook is identified to the receiving node. -This allows a message to be rerouted or passed on, should +This allows a message to be re-routed or passed on, should a node decide that this is required, in much the same way that data packets -are passed around between nodes. A set of standard +are passed around between nodes. +A set of standard messages for flow control and link management purposes are defined by the base system that are usually passed around in this manner. Flow control message would usually travel in the opposite direction to the data to which they pertain. -.Ss Netgraph is (usually) Functional +.Ss Netgraph is (Usually) Functional In order to minimize latency, most .Nm operations are functional. That is, data and control messages are delivered by making function calls rather than by using queues and mailboxes. For example, if node -A wishes to send a data mbuf to neighboring node B, it calls the +A wishes to send a data +.Vt mbuf +to neighboring node B, it calls the generic .Nm data delivery function. @@ -252,8 +268,10 @@ method. There are exceptions to this. .Pp Each node has an input queue, and some operations can be considered to -be 'writers' in that they alter the state of the node. -Obviously in an SMP +be +.Em writers +in that they alter the state of the node. +Obviously, in an SMP world it would be bad if the state of a node were changed while another data packet were transiting the node. For this purpose, the input queue implements a @@ -270,24 +288,24 @@ be a writer, or even that packets leaving or entering across a particular hook should always be queued, rather than delivered directly (often useful for interrupt routines who want to get back to the hardware quickly). By default, all control message packets are considered to be writers -unless specifically declared to be a reader in their definition. (see -NGM_READONLY in -.Pa ng_message.h ) +unless specifically declared to be a reader in their definition. +(See +.Dv NGM_READONLY +in +.In ng_message.h . ) .Pp While this mode of operation results in good performance, it has a few implications for node developers: -.Pp -.Bl -bullet -compact -offset 2n +.Bl -bullet .It Whenever a node delivers a data or control message, the node may need to allow for the possibility of receiving a returning message before the original delivery function call returns. .It -.Nm +.Nm Netgraph provides internal synchronization between nodes. Data always enters a -.Nm .Dq graph at an .Em edge node . @@ -305,7 +323,7 @@ and node type. In these .Em edge nodes , -the calling thread directly executes code in the node and from that code, +the calling thread directly executes code in the node, and from that code calls upon the .Nm framework to deliver data across some edge @@ -326,26 +344,28 @@ a special thread that is activated when there are such items queued. .It -It's possible for an infinite loop to occur if the graph contains cycles. +It is possible for an infinite loop to occur if the graph contains cycles. .El .Pp So far, these issues have not proven problematical in practice. -.Ss Interaction With Other Parts of the Kernel +.Ss Interaction with Other Parts of the Kernel A node may have a hidden interaction with other components of the kernel outside of the .Nm subsystem, such as device hardware, -kernel protocol stacks, etc. In fact, one of the benefits of +kernel protocol stacks, etc. +In fact, one of the benefits of .Nm is the ability to join disparate kernel networking entities together in a consistent communication framework. .Pp -An example is the node type -.Em socket -which is both a netgraph node and a +An example is the +.Vt socket +node type which is both a +.Nm +node and a .Xr socket 2 -.Bx -socket in the protocol family +in the protocol family .Dv PF_NETGRAPH . Socket nodes allow user processes to participate in .Nm . @@ -357,10 +377,10 @@ Another example is a device driver that presents a node interface to the hardware. .Ss Node Methods Nodes are notified of the following actions via function calls -to the following node methods +to the following node methods, and may accept or reject that action (by returning the appropriate error code): -.Bl -tag -width xxx +.Bl -tag -width 2n .It Creation of a new node The constructor for the type is called. If creation of a new node is allowed, constructor method may allocate any @@ -374,21 +394,26 @@ device name is assigned here as well. .It Creation of a new hook The hook is created and tentatively linked to the node, and the node is told about the name that will be -used to describe this hook. The node sets up any special data structures +used to describe this hook. +The node sets up any special data structures it needs, or may reject the connection, based on the name of the hook. .It Successful connection of two hooks After both ends have accepted their hooks, and the links have been made, the nodes get a chance to -find out who their peer is across the link and can then decide to reject -the connection. Tear-down is automatic. This is also the time at which +find out who their peer is across the link, and can then decide to reject +the connection. +Tear-down is automatic. +This is also the time at which a node may decide whether to set a particular hook (or its peer) into +the .Em queueing mode. .It Destruction of a hook -The node is notified of a broken connection. The node may consider some hooks +The node is notified of a broken connection. +The node may consider some hooks to be critical to operation and others to be expendable: the disconnection of one hook may be an acceptable event while for another it -may affect a total shutdown for the node. +may effect a total shutdown for the node. .It Preshutdown of a node This method is called before real shutdown, which is discussed below. While in this method, the node is fully operational and can send a @@ -400,81 +425,101 @@ node type does. .It Shutdown of a node This method allows a node to clean up and to ensure that any actions that need to be performed -at this time are taken. The method is called by the generic (i.e., superclass) +at this time are taken. +The method is called by the generic (i.e., superclass) node destructor which will get rid of the generic components of the node. Some nodes (usually associated with a piece of hardware) may be .Em persistent in that a shutdown breaks all edges and resets the node, -but doesn't remove it. In this case the shutdown method should not +but does not remove it. +In this case, the shutdown method should not free its resources, but rather, clean up and then clear the -.Em NG_INVALID -flag to signal the generic code that the shutdown is aborted. In -the case where the shutdown is started by the node itself due to hardware -removal or unloading, (via ng_rmnode_self()) it should set the -.Em NG_REALLY_DIE +.Dv NG_INVALID +flag to signal the generic code that the shutdown is aborted. +In the case where the shutdown is started by the node itself due to hardware +removal or unloading (via +.Fn ng_rmnode_self ) , +it should set the +.Dv NG_REALLY_DIE flag to signal to its own shutdown method that it is not to persist. .El .Ss Sending and Receiving Data Two other methods are also supported by all nodes: -.Bl -tag -width xxx +.Bl -tag -width 2n .It Receive data message A -.Em Netgraph queueable request item , +.Nm +.Em queueable request item , usually referred to as an .Em item , is received by this function. -The item contains a pointer to an mbuf. +The item contains a pointer to an +.Vt mbuf . .Pp -The node is notified on which hook the item arrived, +The node is notified on which hook the item has arrived, and can use this information in its processing decision. The receiving node must always .Fn NG_FREE_M -the mbuf chain on completion or error, or pass it on to another node +the +.Vt mbuf chain +on completion or error, or pass it on to another node (or kernel module) which will then be responsible for freeing it. -Similarly the +Similarly, the .Em item must be freed if it is not to be passed on to another node, by using the .Fn NG_FREE_ITEM macro. -If the item still holds references to mbufs at the time of +If the item still holds references to +.Vt mbufs +at the time of freeing then they will also be appropriately freed. -Therefore, if there is any chance that the mbuf will be +Therefore, if there is any chance that the +.Vt mbuf +will be changed or freed separately from the item, it is very important that it be retrieved using the .Fn NGI_GET_M macro that also removes the reference within the item. (Or multiple frees of the same object will occur.) .Pp -If it is only required to examine the contents of the mbufs, +If it is only required to examine the contents of the +.Vt mbufs , then it is possible to use the .Fn NGI_M -macro to both read and rewrite mbuf pointer inside the item. +macro to both read and rewrite +.Vt mbuf +pointer inside the item. .Pp -If developer needs to pass any meta information along with the mbuf chain, +If developer needs to pass any meta information along with the +.Vt mbuf chain , he should use .Xr mbuf_tags 9 framework. .Bf -symbolic +Note that old .Nm -specific meta-data is obsoleted now. +specific meta-data format is obsoleted now. .Ef .Pp The receiving node may decide to defer the data by queueing it in the .Nm -NETISR system (see below). It achieves this by setting the +NETISR system (see below). +It achieves this by setting the .Dv HK_QUEUE flag in the flags word of the hook on which that data will arrive. The infrastructure will respect that bit and queue the data for delivery at -a later time, rather than deliver it directly. A node may decide to set +a later time, rather than deliver it directly. +A node may decide to set the bit on the .Em peer node, so that its own output packets are queued. .Pp The node may elect to nominate a different receive data function -for data received on a particular hook, to simplify coding. It uses -the +for data received on a particular hook, to simplify coding. +It uses the .Fn NG_HOOK_SET_RCVDATA hook fn -macro to do this. The function receives the same arguments in every way +macro to do this. +The function receives the same arguments in every way other than it will receive all (and only) packets from that hook. .It Receive control message This method is called when a control message is addressed to the node. @@ -489,8 +534,9 @@ which also removes the reference within the item. If the Item still holds a reference to the message when it is freed (using the .Fn NG_FREE_ITEM -macro), then the message will also be freed appropriately. If the -reference has been removed the node must free the message itself using the +macro), then the message will also be freed appropriately. +If the +reference has been removed, the node must free the message itself using the .Fn NG_FREE_MSG macro. A return address is always supplied, giving the address of the node @@ -500,13 +546,13 @@ The return address is retrieved from the using the .Fn NGI_RETADDR macro and is of type -.Em ng_ID_t . +.Vt ng_ID_t . All control messages and replies are -allocated with -.Fn malloc +allocated with the +.Xr malloc 9 type .Dv M_NETGRAPH_MSG , -however it is more usual to use the +however it is more convenient to use the .Fn NG_MKMESSAGE and .Fn NG_MKRESPONSE @@ -521,15 +567,16 @@ messages, and status change messages, where the node may want to forward the message out another hook to that on which it arrived. .Pp The node may elect to nominate a different receive message function -for messages received on a particular hook, to simplify coding. It uses -the +for messages received on a particular hook, to simplify coding. +It uses the .Fn NG_HOOK_SET_RCVMSG hook fn -macro to do this. The function receives the same arguments in every way +macro to do this. +The function receives the same arguments in every way other than it will receive all (and only) messages from that hook. .El .Pp Much use has been made of reference counts, so that nodes being -free'd of all references are automatically freed, and this behaviour +freed of all references are automatically freed, and this behaviour has been tested and debugged to present a consistent and trustworthy framework for the .Dq type module @@ -538,42 +585,47 @@ writer to use. The .Nm framework provides an unambiguous and simple to use method of specifically -addressing any single node in the graph. The naming of a node is +addressing any single node in the graph. +The naming of a node is independent of its type, in that another node, or external component need not know anything about the node's type in order to address it so as -to send it a generic message type. Node and hook names should be +to send it a generic message type. +Node and hook names should be chosen so as to make addresses meaningful. .Pp -Addresses are either absolute or relative. An absolute address begins -with a node name, (or ID), followed by a colon, followed by a sequence of hook -names separated by periods. This addresses the node reached by starting +Addresses are either absolute or relative. +An absolute address begins +with a node name or ID, followed by a colon, followed by a sequence of hook +names separated by periods. +This addresses the node reached by starting at the named node and following the specified sequence of hooks. A relative address includes only the sequence of hook names, implicitly starting hook traversal at the local node. .Pp There are a couple of special possibilities for the node name. The name -.Dq .\& +.Ql .\& (referred to as -.Dq \&.: ) +.Ql .: ) always refers to the local node. Also, nodes that have no global name may be addressed by their ID numbers, -by enclosing the hex representation of the ID number within square brackets. -Here are some examples of valid netgraph addresses: -.Bd -literal -offset 4n -compact - - .: - [3f]: - foo: - .:hook1 - foo:hook1.hook2 - [d80]:hook1 +by enclosing the hexadecimal representation of the ID number within +the square brackets. +Here are some examples of valid +.Nm +addresses: +.Bd -literal -offset indent +\&.: +[3f]: +foo: +\&.:hook1 +foo:hook1.hook2 +[d80]:hook1 .Ed .Pp -Consider the following set of nodes might be created for a site with +The following set of nodes might be created for a site with a single physical frame relay line having two active logical DLCI channels, -with RFC-1490 frames on DLCI 16 and PPP frames over DLCI 20: -.Pp +with RFC 1490 frames on DLCI 16 and PPP frames over DLCI 20: .Bd -literal [type SYNC ] [type FRAME] [type RFC1490] [ "Frame1" ](uplink)<-->(data)[<un-named>](dlci16)<-->(mux)[<un-named> ] @@ -586,21 +638,21 @@ with RFC-1490 frames on DLCI 16 and PPP frames over DLCI 20: .Pp One could always send a control message to node C from anywhere by using the name -.Em "Frame1:uplink.dlci16" . +.Dq Li Frame1:uplink.dlci16 . In this case, node C would also be notified that the message reached it via its hook -.Dq mux . +.Va mux . Similarly, -.Em "Frame1:uplink.dlci20" +.Dq Li Frame1:uplink.dlci20 could reliably be used to reach node D, and node A could refer to node B as -.Em ".:uplink" , +.Dq Li .:uplink , or simply -.Em "uplink" . +.Dq Li uplink . Conversely, B can refer to A as -.Em "data" . +.Dq Li data . The address -.Em "mux.data" +.Dq Li mux.data could be used by both nodes C and D to address a message to node A. .Pp Note that this is only for @@ -615,31 +667,31 @@ Data messages are .Em only routed one hop at a time, by specifying the departing hook, with each node making -the next routing decision. So when B receives a frame on hook -.Dq data +the next routing decision. +So when B receives a frame on hook +.Va data , it decodes the frame relay header to determine the DLCI, and then forwards the unwrapped frame to either C or D. .Pp In a similar way, flow control messages may be routed in the reverse -direction to outgoing data. For example a "buffer nearly full" message from -.Em "Frame1: -would be passed to node -.Em B +direction to outgoing data. +For example a +.Dq "buffer nearly full" +message from +.Dq Li Frame1: +would be passed to node B which might decide to send similar messages to both nodes -.Em C -and -.Em D . +C and D. The nodes would use -.Em "Direct hook pointer" -addressing to route the messages. The message may have travelled from -.Em "Frame1: -to -.Em B +.Em "direct hook pointer" +addressing to route the messages. +The message may have travelled from +.Dq Li Frame1: +to B as a synchronous reply, saving time and cycles. .Pp A similar graph might be used to represent multi-link PPP running over an ISDN line: -.Pp .Bd -literal [ type BRI ](B1)<--->(link1)[ type MPP ] [ "ISDN1" ](B2)<--->(link2)[ (no name) ] @@ -652,10 +704,10 @@ over an ISDN line: .Ed .Ss Netgraph Structures Structures are defined in -.Pa sys/netgraph/netgraph.h +.In netgraph/netgraph.h (for kernel structures only of interest to nodes) and -.Pa sys/netgraph/ng_message.h +.In netgraph/ng_message.h (for message definitions also of interest to user programs). .Pp The two basic object types that are of interest to node authors are @@ -664,141 +716,117 @@ and .Em hooks . These two objects have the following properties that are also of interest to the node writers. -.Bl -tag -width xxx -.It struct ng_node -Node authors should always use the following typedef to declare +.Bl -tag -width 2n +.It Vt "struct ng_node" +Node authors should always use the following +.Ic typedef +to declare their pointers, and should never actually declare the structure. .Pp -typedef struct ng_node *node_p; +.Fd "typedef struct ng_node *node_p;" .Pp The following properties are associated with a node, and can be accessed in the following manner: -.Bl -bullet -compact -offset 2n -.Pp -.It -Validity -.Pp +.Bl -tag -width 2n +.It Validity A driver or interrupt routine may want to check whether -the node is still valid. It is assumed that the caller holds a reference +the node is still valid. +It is assumed that the caller holds a reference on the node so it will not have been freed, however it may have been -disabled or otherwise shut down. Using the -.Fn NG_NODE_IS_VALID "node" -macro will return this state. Eventually it should be almost impossible +disabled or otherwise shut down. +Using the +.Fn NG_NODE_IS_VALID node +macro will return this state. +Eventually it should be almost impossible for code to run in an invalid node but at this time that work has not been completed. -.Pp -.It -node ID -.Pp -Of type -.Em ng_ID_t , +.It Node ID Pq Vt ng_ID_t This property can be retrieved using the macro -.Fn NG_NODE_ID "node" . -.Pp -.It -node name -.Pp -Optional globally unique name, null terminated string. If there +.Fn NG_NODE_ID node . +.It Node name +Optional globally unique name, +.Dv NUL +terminated string. +If there is a value in here, it is the name of the node. -.Pp -if -.Fn ( NG_NODE_NAME "node" -[0]) .... -.Pp -if (strcmp( -.Fn NG_NODE_NAME "node" , -"fred")) ... -.Pp -.It -A node dependent opaque cookie -.Pp -You may place anything of type -.Em pointer -here. -Use the macros +.Bd -literal -offset indent +if (NG_NODE_NAME(node)[0] != '\e0') ... + +if (strcmp(NG_NODE_NAME(node), "fred") == 0) ... +.Ed +.It A node dependent opaque cookie +Anything of the pointer type can be placed here. +The macros .Fn NG_NODE_SET_PRIVATE node value and -.Fn NG_NODE_PRIVATE "node" -to set and retrieve this property. -.Pp -.It -number of hooks -.Pp -Use -.Fn NG_NODE_NUMHOOKS "node" +.Fn NG_NODE_PRIVATE node +set and retrieve this property, respectively. +.It Number of hooks +The +.Fn NG_NODE_NUMHOOKS node +macro is used to retrieve this value. -.Pp -.It -hooks -.Pp +.It Hooks The node may have a number of hooks. A traversal method is provided to allow all the hooks to be tested for some condition. .Fn NG_NODE_FOREACH_HOOK node fn arg rethook -where fn is a function that will be called for each hook +where +.Fa fn +is a function that will be called for each hook with the form .Fn fn hook arg -and returning 0 to terminate the search. If the search is terminated, then -.Em rethook +and returning 0 to terminate the search. +If the search is terminated, then +.Fa rethook will be set to the hook at which the search was terminated. .El -.It struct ng_hook -Node authors should always use the following typedef to declare +.It Vt "struct ng_hook" +Node authors should always use the following +.Ic typedef +to declare their hook pointers. .Pp -typedef struct ng_hook *hook_p; +.Fd "typedef struct ng_hook *hook_p;" .Pp The following properties are associated with a hook, and can be accessed in the following manner: -.Bl -bullet -compact -offset 2n -.Pp -.It -A hook dependent opaque cookie. -.Pp -You may place anything of type -.Em pointer -here. -Use the macros +.Bl -tag -width 2n +.It A hook dependent opaque cookie +Anything of the pointer type can be placed here. +The macros .Fn NG_HOOK_SET_PRIVATE hook value and -.Fn NG_HOOK_PRIVATE "hook" -to set and retrieve this property. -.Pp -.It -An associate node. -.Pp -You may use the macro -.Fn NG_HOOK_NODE "hook" -to find the associated node. -.Pp -.It -A peer hook -.Pp -The other hook in this connected pair. Of type hook_p. You can -use -.Fn NG_HOOK_PEER "hook" -to find the peer. -.Pp -.It -references -.Pp -.Fn NG_HOOK_REF "hook" +.Fn NG_HOOK_PRIVATE hook +set and retrieve this property, respectively. +.It \&An associate node +The macro +.Fn NG_HOOK_NODE hook +finds the associated node. +.It A peer hook Pq Vt hook_p +The other hook in this connected pair. +The +.Fn NG_HOOK_PEER hook +macro finds the peer. +.It References +The +.Fn NG_HOOK_REF hook and -.Fn NG_HOOK_UNREF "hook" +.Fn NG_HOOK_UNREF hook +macros increment and decrement the hook reference count accordingly. After decrement you should always assume the hook has been freed unless you have another reference still valid. -.Pp -.It -Over-ride receive functions. -.Pp +.It Override receive functions The .Fn NG_HOOK_SET_RCVDATA hook fn and .Fn NG_HOOK_SET_RCVMSG hook fn -macros can be used to set over-ride methods that will be used in preference -to the generic receive data and receive message functions. To unset these -use the macros to set them to NULL. They will only be used for data and +macros can be used to set override methods that will be used in preference +to the generic receive data and receive message functions. +To unset these, use the macros to set them to +.Dv NULL . +They will only be used for data and messages received on the hook on which they are set. .El .Pp @@ -808,7 +836,8 @@ of hooks for each node is handled automatically by the subsystem. Typically a node's private info contains a back-pointer to the node or hook structure, which counts as a new reference that must be included -in the reference count for the node. When the node constructor is called +in the reference count for the node. +When the node constructor is called, there is already a reference for this calculated in, so that when the node is destroyed, it should remember to do a .Fn NG_NODE_UNREF @@ -818,7 +847,7 @@ From a hook you can obtain the corresponding node, and from a node, it is possible to traverse all the active hooks. .Pp A current example of how to define a node can always be seen in -.Em sys/netgraph/ng_sample.c +.Pa src/sys/netgraph/ng_sample.c and should be used as a starting point for new node writers. .El .Ss Netgraph Message Structure @@ -848,25 +877,28 @@ struct ng_mesg { .Pp Control messages have the fixed header shown above, followed by a variable length data section which depends on the type cookie -and the command. Each field is explained below: -.Bl -tag -width xxx -.It Dv version -Indicates the version of the netgraph message protocol itself. The current version is +and the command. +Each field is explained below: +.Bl -tag -width indent +.It Va version +Indicates the version of the +.Nm +message protocol itself. +The current version is .Dv NG_VERSION . -.It Dv arglen +.It Va arglen This is the length of any extra arguments, which begin at -.Dv data . -.It Dv flags +.Va data . +.It Va flags Indicates whether this is a command or a response control message. -.It Dv token +.It Va token The -.Dv token +.Va token is a means by which a sender can match a reply message to the corresponding command message; the reply always has the same token. -.Pp -.It Dv typecookie +.It Va typecookie The corresponding node type's unique 32-bit value. -If a node doesn't recognize the type cookie it must reject the message +If a node does not recognize the type cookie it must reject the message by returning .Er EINVAL . .Pp @@ -878,85 +910,92 @@ receiver; when an incompatible change in the header file is made, the typecookie .Em must be changed. -The de facto method for generating unique type cookies is to take the -seconds from the epoch at the time the header file is written +The de-facto method for generating unique type cookies is to take the +seconds from the Epoch at the time the header file is written (i.e., the output of -.Dv "date -u +'%s'" ) . +.Dq Nm date Fl u Li +%s ) . .Pp There is a predefined typecookie .Dv NGM_GENERIC_COOKIE for the -.Dq generic +.Vt generic node type, and a corresponding set of generic messages which all nodes understand. The handling of these messages is automatic. -.It Dv command -The identifier for the message command. This is type specific, +.It Va command +The identifier for the message command. +This is type specific, and is defined in the same header file as the typecookie. -.It Dv cmdstr +.It Va cmdstr Room for a short human readable version of -.Dq command +.Va command (for debugging purposes only). .El .Pp Some modules may choose to implement messages from more than one of the header files and thus recognize more than one type cookie. .Ss Control Message ASCII Form -Control messages are in binary format for efficiency. However, for +Control messages are in binary format for efficiency. +However, for debugging and human interface purposes, and if the node type supports it, control messages may be converted to and from an equivalent .Tn ASCII -form. The +form. +The .Tn ASCII form is similar to the binary form, with two exceptions: -.Pp -.Bl -tag -compact -width xxx -.It o +.Bl -enum +.It The -.Dv cmdstr +.Va cmdstr header field must contain the .Tn ASCII name of the command, corresponding to the -.Dv cmd +.Va cmd header field. -.It o -The -.Dv args -field contains a NUL-terminated +.It +The arguments field contains a +.Dv NUL Ns +-terminated .Tn ASCII string version of the message arguments. .El .Pp In general, the arguments field of a control message can be any -arbitrary C data type. Netgraph includes parsing routines to support +arbitrary C data type. +.Nm Netgraph +includes parsing routines to support some pre-defined datatypes in .Tn ASCII with this simple syntax: -.Pp -.Bl -tag -compact -width xxx -.It o +.Bl -bullet +.It Integer types are represented by base 8, 10, or 16 numbers. -.It o +.It Strings are enclosed in double quotes and respect the normal C language backslash escapes. -.It o +.It IP addresses have the obvious form. -.It o +.It Arrays are enclosed in square brackets, with the elements listed -consecutively starting at index zero. An element may have an optional -index and equals sign preceding it. Whenever an element +consecutively starting at index zero. +An element may have an optional index and equals sign +.Pq Ql = +preceding it. +Whenever an element does not have an explicit index, the index is implicitly the previous element's index plus one. -.It o +.It Structures are enclosed in curly braces, and each field is specified in the form -.Dq fieldname=value . -.It o +.Ar fieldname Ns = Ns Ar value . +.It Any array element or structure field whose value is equal to its .Dq default value -may be omitted. For integer types, the default value +may be omitted. +For integer types, the default value is usually zero; for string types, the empty string. -.It o +.It Array elements and structure fields may be specified in any order. .El .Pp @@ -964,15 +1003,14 @@ Each node type may define its own arbitrary types by providing the necessary routines to parse and unparse. .Tn ASCII forms defined -for a specific node type are documented in the documentation for -that node type. +for a specific node type are documented in the corresponding man page. .Ss Generic Control Messages There are a number of standard predefined messages that will work for any node, as they are supported directly by the framework itself. These are defined in -.Pa ng_message.h +.In netgraph/ng_message.h along with the basic layout of messages and other similar information. -.Bl -tag -width xxx +.Bl -tag -width indent .It Dv NGM_CONNECT Connect to another node, using the supplied hook names on either end. .It Dv NGM_MKPEER @@ -986,10 +1024,12 @@ The node must disconnect all of its hooks. This may result in neighbors shutting themselves down, and possibly a cascading shutdown of the entire connected graph. .It Dv NGM_NAME -Assign a name to a node. Nodes can exist without having a name, and this +Assign a name to a node. +Nodes can exist without having a name, and this is the default for nodes created using the .Dv NGM_MKPEER -method. Such nodes can only be addressed relatively or by their ID number. +method. +Such nodes can only be addressed relatively or by their ID number. .It Dv NGM_RMHOOK Ask the node to break a hook connection to one of its neighbours. Both nodes will have their @@ -997,9 +1037,11 @@ Both nodes will have their method invoked. Either node may elect to totally shut down as a result. .It Dv NGM_NODEINFO -Asks the target node to describe itself. The four returned fields +Asks the target node to describe itself. +The four returned fields are the node name (if named), the node type, the node ID and the -number of hooks attached. The ID is an internal number unique to that node. +number of hooks attached. +The ID is an internal number unique to that node. .It Dv NGM_LISTHOOKS This returns the information given by .Dv NGM_NODEINFO , @@ -1008,7 +1050,7 @@ includes an array of fields describing each link, and the description for the node at the far end of that link. .It Dv NGM_LISTNAMES This returns an array of node descriptions (as for -.Dv NGM_NODEINFO ")" +.Dv NGM_NODEINFO ) where each entry of the array describes a named node. All named nodes will be described. .It Dv NGM_LISTNODES @@ -1016,15 +1058,21 @@ This is the same as .Dv NGM_LISTNAMES except that all nodes are listed regardless of whether they have a name or not. .It Dv NGM_LISTTYPES -This returns a list of all currently installed netgraph types. +This returns a list of all currently installed +.Nm +types. .It Dv NGM_TEXT_STATUS The node may return a text formatted status message. The status information is determined entirely by the node type. -It is the only "generic" message +It is the only +.Dq generic +message that requires any support within the node itself and as such the node may -elect to not support this message. The text response must be less than +elect to not support this message. +The text response must be less than .Dv NG_TEXTRESPONSE -bytes in length (presently 1024). This can be used to return general +bytes in length (presently 1024). +This can be used to return general status information in human readable form. .It Dv NGM_BINARY2ASCII This message converts a binary control message to its @@ -1033,7 +1081,8 @@ form. The entire control message to be converted is contained within the arguments field of the .Dv NGM_BINARY2ASCII -message itself. If successful, the reply will contain the same control +message itself. +If successful, the reply will contain the same control message in .Tn ASCII form. @@ -1050,30 +1099,33 @@ form, is contained in the arguments section of the .Dv NGM_ASCII2BINARY and need only have the -.Dv flags , -.Dv cmdstr , +.Va flags , cmdstr , and -.Dv arglen -header fields filled in, plus the NUL-terminated string version of -the arguments in the arguments field. If successful, the reply +.Va arglen +header fields filled in, plus the +.Dv NUL Ns +-terminated string version of +the arguments in the arguments field. +If successful, the reply contains the binary version of the control message. .El .Ss Flow Control Messages In addition to the control messages that affect nodes with respect to the graph, there are also a number of -.Em Flow-control -messages defined. At present these are -.Em NOT +.Em flow control +messages defined. +At present these are +.Em not handled automatically by the system, so nodes need to handle them if they are going to be used in a graph utilising flow control, and will be in the likely path of these messages. -The default action of a node that doesn't understand these messages should +The default action of a node that does not understand these messages should be to pass them onto the next node. Hopefully some helper functions will assist in this eventually. These messages are also defined in -.Pa sys/netgraph/ng_message.h +.In netgraph/ng_message.h and have a separate cookie -.Em NG_FLOW_COOKIE +.Dv NG_FLOW_COOKIE to help identify them. They will not be covered in depth here. .Sh INITIALIZATION @@ -1084,16 +1136,15 @@ into the kernel or else loaded dynamically as a KLD via .Xr kldload 8 . In the former case, include .Pp -.Dl options NETGRAPH +.D1 Cd "options NETGRAPH" .Pp in your kernel configuration file. You may also include selected node types in the kernel compilation, for example: -.Bd -literal -offset indent -options NETGRAPH -options NETGRAPH_SOCKET -options NETGRAPH_ECHO -.Ed +.Pp +.D1 Cd "options NETGRAPH" +.D1 Cd "options NETGRAPH_SOCKET" +.D1 Cd "options NETGRAPH_ECHO" .Pp Once the .Nm @@ -1104,20 +1155,22 @@ Moreover, .Nm knows how to automatically do this; when a request to create a new node of unknown type -.Em type +.Ar type is made, .Nm will attempt to load the KLD module -.Pa ng_type.ko . +.Pa ng_ Ns Ao Ar type Ac Ns Pa .ko . .Pp Types can also be installed at boot time, as certain device drivers -may want to export each instance of the device as a netgraph node. +may want to export each instance of the device as a +.Nm +node. .Pp In general, new types can be installed at any time from within the kernel by calling .Fn ng_newtype , supplying a pointer to the type's -.Dv struct ng_type +.Vt "struct ng_type" structure. .Pp The @@ -1126,7 +1179,7 @@ macro automates this process by using a linker set. .Sh EXISTING NODE TYPES Several node types currently exist. Each is fully documented in its own man page: -.Bl -tag -width xxx +.Bl -tag -width indent .It SOCKET The socket type implements two new sockets in the new protocol domain .Dv PF_NETGRAPH . @@ -1147,112 +1200,126 @@ Data and control messages are passed using the .Xr sendto 2 and .Xr recvfrom 2 -calls, using a -.Dv struct sockaddr_ng +system calls, using a +.Vt "struct sockaddr_ng" socket address. -.Pp .It HOLE Responds only to generic messages and is a .Dq black hole -for data, Useful for testing. Always accepts new hooks. -.Pp +for data. +Useful for testing. +Always accepts new hooks. .It ECHO Responds only to generic messages and always echoes data back through the -hook from which it arrived. Returns any non generic messages as their -own response. Useful for testing. Always accepts new hooks. -.Pp +hook from which it arrived. +Returns any non-generic messages as their own response. +Useful for testing. +Always accepts new hooks. .It TEE This node is useful for .Dq snooping . It has 4 hooks: -.Dv left , -.Dv right , -.Dv left2right , +.Va left , right , left2right , and -.Dv right2left . -Data entering from the right is passed to the left and duplicated on -.Dv right2left , -and data entering from the left is passed to the right and -duplicated on -.Dv left2right . +.Va right2left . +Data entering from the +.Va right +is passed to the +.Va left +and duplicated on +.Va right2left , +and data entering from the +.Va left +is passed to the +.Va right +and duplicated on +.Va left2right . Data entering from -.Dv left2right -is sent to the right and data from -.Dv right2left -to left. -.Pp +.Va left2right +is sent to the +.Va right +and data from +.Va right2left +to +.Va left . .It RFC1490 MUX Encapsulates/de-encapsulates frames encoded according to RFC 1490. Has a hook for the encapsulated packets -.Pq Dq downstream +.Pq Va downstream and one hook for each protocol (i.e., IP, PPP, etc.). -.Pp .It FRAME RELAY MUX Encapsulates/de-encapsulates Frame Relay frames. Has a hook for the encapsulated packets -.Pq Dq downstream +.Pq Va downstream and one hook for each DLCI. -.Pp .It FRAME RELAY LMI Automatically handles frame relay .Dq LMI (link management interface) operations and packets. Automatically probes and detects which of several LMI standards is in use at the exchange. -.Pp .It TTY -This node is also a line discipline. It simply converts between mbuf -frames and sequential serial data, allowing a tty to appear as a netgraph -node. It has a programmable +This node is also a line discipline. +It simply converts between +.Vt mbuf +frames and sequential serial data, allowing a TTY to appear as a +.Nm +node. +It has a programmable .Dq hotkey character. -.Pp .It ASYNC This node encapsulates and de-encapsulates asynchronous frames -according to RFC 1662. This is used in conjunction with the TTY node +according to RFC 1662. +This is used in conjunction with the TTY node type for supporting PPP links over asynchronous serial lines. -.Pp .It ETHERNET This node is attached to every Ethernet interface in the system. It allows capturing raw Ethernet frames from the network, as well as sending frames out of the interface. -.Pp .It INTERFACE -This node is also a system networking interface. It has hooks representing +This node is also a system networking interface. +It has hooks representing each protocol family (IP, AppleTalk, IPX, etc.) and appears in the output of .Xr ifconfig 8 . The interfaces are named -.Em ng0 , -.Em ng1 , +.Dq Li ng0 , +.Dq Li ng1 , etc. .It ONE2MANY -This node implements a simple round-robin multiplexer. It can be used +This node implements a simple round-robin multiplexer. +It can be used for example to make several LAN ports act together to get a higher speed link between two machines. -.It Various PPP related nodes. -There is a full multilink PPP implementation that runs in Netgraph. +.It Various PPP related nodes +There is a full multilink PPP implementation that runs in +.Nm . The -.Em Mpd +.Pa net/mpd port can use these modules to make a very low latency high -capacity ppp system. It also supports -.Em PPTP -vpns using the -.Em PPTP -node. +capacity PPP system. +It also supports +.Tn PPTP +VPNs using the PPTP node. .It PPPOE -A server and client side implementation of PPPoE. Used in conjunction with +A server and client side implementation of PPPoE. +Used in conjunction with either .Xr ppp 8 or the -.Em mpd port . +.Pa net/mpd +port. .It BRIDGE -This node, together with the ethernet nodes allows a very flexible +This node, together with the Ethernet nodes, allows a very flexible bridging system to be implemented. .It KSOCKET This intriguing node looks like a socket to the system but diverts -all data to and from the netgraph system for further processing. This allows +all data to and from the +.Nm +system for further processing. +This allows such things as UDP tunnels to be almost trivially implemented from the command line. .El @@ -1266,59 +1333,74 @@ If it does not exist, .Er ENOENT will be returned. .Pp -All data messages are mbuf chains with the M_PKTHDR flag set. +All data messages are +.Vt mbuf chains +with the +.Dv M_PKTHDR +flag set. .Pp Nodes are responsible for freeing what they allocate. There are three exceptions: -.Bl -tag -width xxxx -.It 1 -Mbufs sent across a data link are never to be freed by the sender. In the +.Bl -enum +.It +.Vt Mbufs +sent across a data link are never to be freed by the sender. +In the case of error, they should be considered freed. -.It 2 +.It Messages sent using one of .Fn NG_SEND_MSG_* family macros are freed by the recipient. As in the case above, the addresses associated with the message are freed by whatever allocated them so the recipient should copy them if it wants to keep that information. -.It 3 -Both control messages and data are delivered and queued with -a netgraph +.It +Both control messages and data are delivered and queued with a +.Nm .Em item . The item must be freed using -.Fn NG_FREE_ITEM "item" +.Fn NG_FREE_ITEM item or passed on to another node. .El .Sh FILES -.Bl -tag -width xxxxx -compact -.It Pa /sys/netgraph/netgraph.h +.Bl -tag -width indent +.It In netgraph/netgraph.h Definitions for use solely within the kernel by .Nm nodes. -.It Pa /sys/netgraph/ng_message.h +.It In netgraph/ng_message.h Definitions needed by any file that needs to deal with .Nm messages. -.It Pa /sys/netgraph/ng_socket.h +.It In netgraph/ng_socket.h Definitions needed to use .Nm -socket type nodes. -.It Pa /sys/netgraph/ng_{type}.h +.Vt socket +type nodes. +.It In netgraph/ng_ Ns Ao Ar type Ac Ns Pa .h Definitions needed to use .Nm -{type} +.Ar type nodes, including the type cookie definition. .It Pa /boot/kernel/netgraph.ko -Netgraph subsystem loadable KLD module. -.It Pa /boot/kernel/ng_{type}.ko -Loadable KLD module for node type {type}. -.It Pa /sys/netgraph/ng_sample.c -Skeleton netgraph node. +The +.Nm +subsystem loadable KLD module. +.It Pa /boot/kernel/ng_ Ns Ao Ar type Ac Ns Pa .ko +Loadable KLD module for node type +.Ar type . +.It Pa src/sys/netgraph/ng_sample.c +Skeleton +.Nm +node. Use this as a starting point for new node types. .El .Sh USER MODE SUPPORT There is a library for supporting user-mode programs that wish -to interact with the netgraph system. See +to interact with the +.Nm +system. +See .Xr netgraph 3 for details. .Pp @@ -1332,13 +1414,15 @@ There are a few useful techniques for debugging new node types. First, implementing new node types in user-mode first makes debugging easier. The -.Em tee +.Vt tee node type is also useful for debugging, especially in conjunction with .Xr ngctl 8 and .Xr nghook 8 . .Pp -Also look in /usr/share/examples/netgraph for solutions to several +Also look in +.Pa /usr/share/examples/netgraph +for solutions to several common networking problems, solved using .Nm . .Sh SEE ALSO |