1*3b2bd0f6Slogwang /*
2*3b2bd0f6Slogwang  * ng_bridge.h
3*3b2bd0f6Slogwang  */
4*3b2bd0f6Slogwang 
5*3b2bd0f6Slogwang /*-
6*3b2bd0f6Slogwang  * Copyright (c) 2000 Whistle Communications, Inc.
7*3b2bd0f6Slogwang  * All rights reserved.
8*3b2bd0f6Slogwang  *
9*3b2bd0f6Slogwang  * Subject to the following obligations and disclaimer of warranty, use and
10*3b2bd0f6Slogwang  * redistribution of this software, in source or object code forms, with or
11*3b2bd0f6Slogwang  * without modifications are expressly permitted by Whistle Communications;
12*3b2bd0f6Slogwang  * provided, however, that:
13*3b2bd0f6Slogwang  * 1. Any and all reproductions of the source or object code must include the
14*3b2bd0f6Slogwang  *    copyright notice above and the following disclaimer of warranties; and
15*3b2bd0f6Slogwang  * 2. No rights are granted, in any manner or form, to use Whistle
16*3b2bd0f6Slogwang  *    Communications, Inc. trademarks, including the mark "WHISTLE
17*3b2bd0f6Slogwang  *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
18*3b2bd0f6Slogwang  *    such appears in the above copyright notice or in the software.
19*3b2bd0f6Slogwang  *
20*3b2bd0f6Slogwang  * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
21*3b2bd0f6Slogwang  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
22*3b2bd0f6Slogwang  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
23*3b2bd0f6Slogwang  * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
24*3b2bd0f6Slogwang  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
25*3b2bd0f6Slogwang  * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
26*3b2bd0f6Slogwang  * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
27*3b2bd0f6Slogwang  * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
28*3b2bd0f6Slogwang  * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
29*3b2bd0f6Slogwang  * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
30*3b2bd0f6Slogwang  * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
31*3b2bd0f6Slogwang  * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
32*3b2bd0f6Slogwang  * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
33*3b2bd0f6Slogwang  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34*3b2bd0f6Slogwang  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35*3b2bd0f6Slogwang  * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
36*3b2bd0f6Slogwang  * OF SUCH DAMAGE.
37*3b2bd0f6Slogwang  *
38*3b2bd0f6Slogwang  * Author: Archie Cobbs <[email protected]>
39*3b2bd0f6Slogwang  *
40*3b2bd0f6Slogwang  * $FreeBSD$
41*3b2bd0f6Slogwang  */
42*3b2bd0f6Slogwang 
43*3b2bd0f6Slogwang #ifndef _NETGRAPH_NG_BRIDGE_H_
44*3b2bd0f6Slogwang #define _NETGRAPH_NG_BRIDGE_H_
45*3b2bd0f6Slogwang 
46*3b2bd0f6Slogwang /* Node type name and magic cookie */
47*3b2bd0f6Slogwang #define NG_BRIDGE_NODE_TYPE		"bridge"
48*3b2bd0f6Slogwang #define NGM_BRIDGE_COOKIE		967239368
49*3b2bd0f6Slogwang 
50*3b2bd0f6Slogwang /* Hook names */
51*3b2bd0f6Slogwang #define NG_BRIDGE_HOOK_LINK_PREFIX	"link"	 /* append decimal integer */
52*3b2bd0f6Slogwang #define NG_BRIDGE_HOOK_LINK_FMT		"link%d" /* for use with printf(3) */
53*3b2bd0f6Slogwang 
54*3b2bd0f6Slogwang /* Maximum number of supported links */
55*3b2bd0f6Slogwang #define NG_BRIDGE_MAX_LINKS		32
56*3b2bd0f6Slogwang 
57*3b2bd0f6Slogwang /* Node configuration structure */
58*3b2bd0f6Slogwang struct ng_bridge_config {
59*3b2bd0f6Slogwang 	u_char		ipfw[NG_BRIDGE_MAX_LINKS]; 	/* enable ipfw */
60*3b2bd0f6Slogwang 	u_char		debugLevel;		/* debug level */
61*3b2bd0f6Slogwang 	u_int32_t	loopTimeout;		/* link loopback mute time */
62*3b2bd0f6Slogwang 	u_int32_t	maxStaleness;		/* max host age before nuking */
63*3b2bd0f6Slogwang 	u_int32_t	minStableAge;		/* min time for a stable host */
64*3b2bd0f6Slogwang };
65*3b2bd0f6Slogwang 
66*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
67*3b2bd0f6Slogwang #define NG_BRIDGE_CONFIG_TYPE_INFO(ainfo)	{		\
68*3b2bd0f6Slogwang 	  { "ipfw",		(ainfo)			},	\
69*3b2bd0f6Slogwang 	  { "debugLevel",	&ng_parse_uint8_type	},	\
70*3b2bd0f6Slogwang 	  { "loopTimeout",	&ng_parse_uint32_type	},	\
71*3b2bd0f6Slogwang 	  { "maxStaleness",	&ng_parse_uint32_type	},	\
72*3b2bd0f6Slogwang 	  { "minStableAge",	&ng_parse_uint32_type	},	\
73*3b2bd0f6Slogwang 	  { NULL }						\
74*3b2bd0f6Slogwang }
75*3b2bd0f6Slogwang 
76*3b2bd0f6Slogwang /* Statistics structure (one for each link) */
77*3b2bd0f6Slogwang struct ng_bridge_link_stats {
78*3b2bd0f6Slogwang 	u_int64_t	recvOctets;	/* total octets rec'd on link */
79*3b2bd0f6Slogwang 	u_int64_t	recvPackets;	/* total pkts rec'd on link */
80*3b2bd0f6Slogwang 	u_int64_t	recvMulticasts;	/* multicast pkts rec'd on link */
81*3b2bd0f6Slogwang 	u_int64_t	recvBroadcasts;	/* broadcast pkts rec'd on link */
82*3b2bd0f6Slogwang 	u_int64_t	recvUnknown;	/* pkts rec'd with unknown dest addr */
83*3b2bd0f6Slogwang 	u_int64_t	recvRunts;	/* pkts rec'd less than 14 bytes */
84*3b2bd0f6Slogwang 	u_int64_t	recvInvalid;	/* pkts rec'd with bogus source addr */
85*3b2bd0f6Slogwang 	u_int64_t	xmitOctets;	/* total octets xmit'd on link */
86*3b2bd0f6Slogwang 	u_int64_t	xmitPackets;	/* total pkts xmit'd on link */
87*3b2bd0f6Slogwang 	u_int64_t	xmitMulticasts;	/* multicast pkts xmit'd on link */
88*3b2bd0f6Slogwang 	u_int64_t	xmitBroadcasts;	/* broadcast pkts xmit'd on link */
89*3b2bd0f6Slogwang 	u_int64_t	loopDrops;	/* pkts dropped due to loopback */
90*3b2bd0f6Slogwang 	u_int64_t	loopDetects;	/* number of loop detections */
91*3b2bd0f6Slogwang 	u_int64_t	memoryFailures;	/* times couldn't get mem or mbuf */
92*3b2bd0f6Slogwang };
93*3b2bd0f6Slogwang 
94*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
95*3b2bd0f6Slogwang #define NG_BRIDGE_STATS_TYPE_INFO	{			\
96*3b2bd0f6Slogwang 	  { "recvOctets",	&ng_parse_uint64_type	},	\
97*3b2bd0f6Slogwang 	  { "recvPackets",	&ng_parse_uint64_type	},	\
98*3b2bd0f6Slogwang 	  { "recvMulticast",	&ng_parse_uint64_type	},	\
99*3b2bd0f6Slogwang 	  { "recvBroadcast",	&ng_parse_uint64_type	},	\
100*3b2bd0f6Slogwang 	  { "recvUnknown",	&ng_parse_uint64_type	},	\
101*3b2bd0f6Slogwang 	  { "recvRunts",	&ng_parse_uint64_type	},	\
102*3b2bd0f6Slogwang 	  { "recvInvalid",	&ng_parse_uint64_type	},	\
103*3b2bd0f6Slogwang 	  { "xmitOctets",	&ng_parse_uint64_type	},	\
104*3b2bd0f6Slogwang 	  { "xmitPackets",	&ng_parse_uint64_type	},	\
105*3b2bd0f6Slogwang 	  { "xmitMulticasts",	&ng_parse_uint64_type	},	\
106*3b2bd0f6Slogwang 	  { "xmitBroadcasts",	&ng_parse_uint64_type	},	\
107*3b2bd0f6Slogwang 	  { "loopDrops",	&ng_parse_uint64_type	},	\
108*3b2bd0f6Slogwang 	  { "loopDetects",	&ng_parse_uint64_type	},	\
109*3b2bd0f6Slogwang 	  { "memoryFailures",	&ng_parse_uint64_type	},	\
110*3b2bd0f6Slogwang 	  { NULL }						\
111*3b2bd0f6Slogwang }
112*3b2bd0f6Slogwang 
113*3b2bd0f6Slogwang /* Structure describing a single host */
114*3b2bd0f6Slogwang struct ng_bridge_host {
115*3b2bd0f6Slogwang 	u_char		addr[6];	/* ethernet address */
116*3b2bd0f6Slogwang 	u_int16_t	linkNum;	/* link where addr can be found */
117*3b2bd0f6Slogwang 	u_int16_t	age;		/* seconds ago entry was created */
118*3b2bd0f6Slogwang 	u_int16_t	staleness;	/* seconds ago host last heard from */
119*3b2bd0f6Slogwang };
120*3b2bd0f6Slogwang 
121*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
122*3b2bd0f6Slogwang #define NG_BRIDGE_HOST_TYPE_INFO(entype)	{		\
123*3b2bd0f6Slogwang 	  { "addr",		(entype)		},	\
124*3b2bd0f6Slogwang 	  { "linkNum",		&ng_parse_uint16_type	},	\
125*3b2bd0f6Slogwang 	  { "age",		&ng_parse_uint16_type	},	\
126*3b2bd0f6Slogwang 	  { "staleness",	&ng_parse_uint16_type	},	\
127*3b2bd0f6Slogwang 	  { NULL }						\
128*3b2bd0f6Slogwang }
129*3b2bd0f6Slogwang 
130*3b2bd0f6Slogwang /* Structure returned by NGM_BRIDGE_GET_TABLE */
131*3b2bd0f6Slogwang struct ng_bridge_host_ary {
132*3b2bd0f6Slogwang 	u_int32_t		numHosts;
133*3b2bd0f6Slogwang 	struct ng_bridge_host	hosts[];
134*3b2bd0f6Slogwang };
135*3b2bd0f6Slogwang 
136*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
137*3b2bd0f6Slogwang #define NG_BRIDGE_HOST_ARY_TYPE_INFO(harytype)	{		\
138*3b2bd0f6Slogwang 	  { "numHosts",		&ng_parse_uint32_type	},	\
139*3b2bd0f6Slogwang 	  { "hosts",		(harytype)		},	\
140*3b2bd0f6Slogwang 	  { NULL }						\
141*3b2bd0f6Slogwang }
142*3b2bd0f6Slogwang 
143*3b2bd0f6Slogwang /* Netgraph control messages */
144*3b2bd0f6Slogwang enum {
145*3b2bd0f6Slogwang 	NGM_BRIDGE_SET_CONFIG = 1,	/* set node configuration */
146*3b2bd0f6Slogwang 	NGM_BRIDGE_GET_CONFIG,		/* get node configuration */
147*3b2bd0f6Slogwang 	NGM_BRIDGE_RESET,		/* reset (forget) all information */
148*3b2bd0f6Slogwang 	NGM_BRIDGE_GET_STATS,		/* get link stats */
149*3b2bd0f6Slogwang 	NGM_BRIDGE_CLR_STATS,		/* clear link stats */
150*3b2bd0f6Slogwang 	NGM_BRIDGE_GETCLR_STATS,	/* atomically get & clear link stats */
151*3b2bd0f6Slogwang 	NGM_BRIDGE_GET_TABLE,		/* get link table */
152*3b2bd0f6Slogwang 	NGM_BRIDGE_SET_PERSISTENT,	/* set persistent mode */
153*3b2bd0f6Slogwang };
154*3b2bd0f6Slogwang 
155*3b2bd0f6Slogwang #endif /* _NETGRAPH_NG_BRIDGE_H_ */
156*3b2bd0f6Slogwang 
157