.\" Copyright (c) 2002 Iscanet Internet Services srl .\" All rights reserved. .\" .\" Subject to the following obligations and disclaimer of warranty, use and .\" redistribution of this software, in source or object code forms, with or .\" without modifications are expressly permitted by Whistle Communications; .\" provided, however, that: .\" 1. Any and all reproductions of the source or object code must include the .\" copyright notice above and the following disclaimer of warranties; and .\" 2. No rights are granted, in any manner or form, to use Whistle .\" Communications, Inc. trademarks, including the mark "WHISTLE .\" COMMUNICATIONS" on advertising, endorsements, or otherwise except as .\" such appears in the above copyright notice or in the software. .\" .\" THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND .\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO .\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, .\" INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. .\" WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY .\" REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS .\" SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. .\" IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES .\" RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING .\" WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, .\" PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR .\" SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY .\" OF SUCH DAMAGE. .\" .\" Author: Rocco Lucia .\" .\" $Id: ng_fwdswitch.4,v 1.1.1.1 2002/05/27 09:04:27 rlucia Exp $ .\" .Dd May 22, 2002 .Dt NG_FWDSWITCH 4 .Os .Sh NAME .Nm ng_fwdswitch .Nd basic packet forwarding netgraph node type .Sh SYNOPSIS .In netgraph/ng_fwdswitch.h .Sh DESCRIPTION The .Nm fwdswitch provides a simple mechanism to forward packets over several links based on a custom forwarding table. In hooks are named as .Dv in0 , .Dv in1 , etc. while out hooks are named as .Dv out0 , .Dv out1 , etc. IP Packets coming into the .Dv in hooks will be checked against a table and will be fastforwarded to one of the .Dv out hooks. The filter is only able to catch packets checking its source or destination address against a specified IP network/netmask. Packets which are not caught by the filter or non-IP packets will be forwarded to the designated default out hook. Packets incoming in the .Dv out hooks will be silently discarded. Not a single packet will ever be forwarded to the .Dv in hooks. .Pp Each of the connected many links may be considered to be up or down. Packets are never delivered out a many hook that is down. How a link is determined to be up or down depends on the node's configured link failure detection algorithm. .Sh LINK FAILURE DETECTION At this time, the only algorithm for determining when a link has failed, other than the hook being disconnected, is the ``manual'' algorithm: the node is explicitly told which of the links are up via the .Dv NGM_FWDSWITCH_SET_CONFIG control message (see below). Newly connected links are down until configured otherwise. .Pp .Sh HOOKS This node type supports up to NG_FWDSWITCH_MAX_INPUTS hooks named .Dv in0 , .Dv in1 , etc., and up to .Dv NG_FWDSWITCH_MAX_LINKS hooks named .Dv out0 , .Dv out1 , etc. .Sh CONTROL MESSAGES This node type supports the generic control messages, plus the following: .Bl -tag -width foo .It Dv NGM_FWDSWITCH_SET_CONFIG Sets the node configuration using a .Dv "struct ng_fwdswitch_link_config" as the control message argument: .Bd -literal -offset 0n /* Node configuration structure */ struct ng_fwdswitch_config { u_int32_t xmitAlg; /* how to distribute packets */ u_int32_t failAlg; /* how to detect link failure */ u_char enabledLinks[NG_FWDSWITCH_MAX_LINKS]; }; .Ed .Pp Currently, the only valid setting for the .Dv xmitAlg field is .Dv NG_ONE2MANY_XMIT_ROUNDROBIN ; this is also the default setting. The only valid setting for .Dv failAlg is .Dv NG_FWDSWITCH_FAIL_MANUAL ; this is also the default setting. .It Dv NGM_FWDSWITCH_GET_CONFIG Returns the current node configuration in a .Dv "struct ng_fwdswitch_link_config" . .It Dv NGM_FWDSWITCH_SET_FWDCONFIG This commands loads into the node the forwarding table which will be used to deliver packets. The commands takes as argument the .Dv "struct ng_fwdswotch_fwdconfig" as the control message argument: .Bd -literal -offset 0n /* Forwarding switch configuration structure */ struct ng_fwdswitch_fwdconfig { int32_t fwd_table_len; /* number of filters */ struct ng_fwdswitch_fwdconfig_entry fwd_table[0]; /* forwarding table */ }; .Ed .Pp .It Dv NGM_FWDSWITCH_GET_FWDCONFIG Returns the current node configuration in a .Dv "struct ng_fwdswitch_fwdconfig" . .It Dv NGM_FWDSWITCH_GET_STATS This command takes a 32 bit link number as an argument and returns a .Dv "struct ng_fwdswitch_link_stats" containing statistics for the corresponding .Dv out link, which may or may not be currently connected: .Bd -literal -offset 0n /* Statistics structure (one for each link) */ struct ng_fwdswitch_link_stats { u_int64_t recvOctets; /* total octets rec'd on link */ u_int64_t recvPackets; /* total pkts rec'd on link */ u_int64_t xmitOctets; /* total octets xmit'd on link */ u_int64_t xmitPackets; /* total pkts xmit'd on link */ }; .Ed .Pp To access statistics for the .Dv in0 and .Dv in1 links, use the link number .Dv -1 and .Dv -2. .It Dv NGM_FWDSWITCH_CLR_STATS This command takes a 32 bit link number as an argument and clears the statistics for that link. .It Dv NGM_FWDSWITCH_GETCLR_STATS Same as .Dv NGM_FWDSWITCH_GET_STATS , but also atomically clears the statistics for the link as well. .El .Sh SHUTDOWN This node shuts down upon receipt of a .Dv NGM_SHUTDOWN control message, or when all hooks have been disconnected. .Sh EXAMPLES In this example we will configure a couple of Ethernet interfaces as inputs whose packets will be forwarded to four output interfaces: .Bd -literal -offset 0n # Plumb nodes together ngctl mkpeer ti0: fwdswitch lower in0 ngctl name ti0:lower fswitch0 ngctl connect ti1: fswitch0: lower in1 ngctl connect xl0: fswitch0: lower out0 ngctl connect xl1: fswitch0: lower out1 ngctl connect xl2: fswitch0: lower out2 ngctl connect xl3: fswitch0: lower out3 # Allow xl0 through xl3 to recv ti0 and ti1 frames ngctl msg ti0: setpromisc 1 ngctl msg ti1: setpromisc 1 ngctl msg xl0: setautosrc 0 ngctl msg xl1: setautosrc 0 ngctl msg xl2: setautosrc 0 ngctl msg xl3: setautosrc 0 # Configure all four links as up ngctl msg fswitch0: \\ setconfig "{ xmitAlg=1 failAlg=1 enabledLinks=[ 1 1 1 1 ] }" # Setup the packet switch ngctl msg fswitch0: \\ setfwdconfig "{ defaultlink=2 fwdtable_len=4 \\ { ipaddr=192.168.0.0 netmask=255.255.255.0 dstlink=0 } \\ { ipaddr=192.168.1.0 netmask=255.255.255.0 dstlink=1 } \\ { ipaddr=192.168.2.0 netmask=255.255.255.128 dstlink=2 } \\ { ipaddr=192.168.2.128 netmask=255.255.255.128 dstlink=3 } ] }" .Ed .Pp .Sh BUGS Some nasty bugs will panic your kernel. .Sh SEE ALSO .Xr netgraph 4 , .Xr ng_ether 4 , .Xr ng_one2many 4 , .Xr ngctl 8 .Sh HISTORY The .Nm node type has never seen light into FreeBSD. .Sh AUTHORS .An Rocco Lucia Aq rlucia@iscanet.com