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