xref: /freebsd/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.h (revision 2b743a9e9ddc6736208dc8ca1ce06ce64ad20a19)
1 /*-
2  * Copyright (c) 2006 Shteryana Shopova <syrinx@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * Bridge MIB implementation for SNMPd.
27  *
28  * $FreeBSD$
29  */
30 
31 #ifndef	SNMP_BRIDGE_H
32 #define	SNMP_BRIDGE_H
33 
34 #define	SNMP_BRIDGE_ID_LEN	8
35 
36 typedef uint8_t	port_id[2];
37 typedef u_char	bridge_id[SNMP_BRIDGE_ID_LEN];
38 
39 #define	SNMP_BRIDGE_MAX_PRIORITY	65535
40 
41 #define	SNMP_BRIDGE_MIN_AGE_TIME	10
42 #define	SNMP_BRIDGE_MAX_AGE_TIME	1000000
43 
44 #define	SNMP_BRIDGE_MIN_TXHC		1
45 #define	SNMP_BRIDGE_MAX_TXHC		10
46 
47 #define	SNMP_BRIDGE_MIN_MAGE		600
48 #define	SNMP_BRIDGE_MAX_MAGE		4000
49 
50 #define	SNMP_BRIDGE_MIN_HTIME		100
51 #define	SNMP_BRIDGE_MAX_HTIME		1000
52 
53 #define	SNMP_BRIDGE_MIN_FDELAY		400
54 #define	SNMP_BRIDGE_MAX_FDELAY		3000
55 
56 #define	SNMP_PORT_PATHCOST_OBSOLETE	65535
57 #define	SNMP_PORT_MIN_PATHCOST		0
58 #define	SNMP_PORT_MAX_PATHCOST		200000000
59 #define	SNMP_PORT_PATHCOST_AUTO		0
60 
61 #define	SNMP_BRIDGE_DATA_MAXAGE		10
62 #define	SNMP_BRIDGE_DATA_MAXAGE_MIN	1
63 #define	SNMP_BRIDGE_DATA_MAXAGE_MAX	300
64 
65 /* By default poll kernel data every 5 minutes. */
66 #define	SNMP_BRIDGE_POLL_INTERVAL	(5 * 60)
67 #define	SNMP_BRIDGE_POLL_INTERVAL_MIN	1
68 #define	SNMP_BRIDGE_POLL_INTERVAL_MAX	3600
69 
70 /* Poll for a topology change once every 30 seconds. */
71 #define	SNMP_BRIDGE_TC_POLL_INTERVAL	30
72 
73 struct bridge_if *bridge_get_default(void);
74 
75 void bridge_set_default(struct bridge_if *bif);
76 
77 const char *bridge_get_default_name(void);
78 
79 int bridge_get_data_maxage(void);
80 
81 /*
82  * Bridge Addresses Table.
83  */
84 struct tp_entry {
85 	uint32_t		sysindex;	/* The bridge if sysindex. */
86 	int32_t			port_no;
87 	enum TpFdbStatus	status;
88 	uint8_t			tp_addr[ETHER_ADDR_LEN];
89 	uint8_t			flags;
90 	TAILQ_ENTRY(tp_entry)	tp_e;
91 };
92 
93 /*
94  * Bridge ports.
95  * The bridge port system interface index is used for a
96  * port number. Transparent bridging statistics and STP
97  * information for a port are also contained here.
98  */
99 struct bridge_port {
100 	/* dot1dBase subtree objects. */
101 	uint32_t	sysindex;	/* The bridge interface sysindex. */
102 	int32_t		port_no;	/* The bridge member system index. */
103 	int32_t		if_idx;		/* SNMP ifIndex from mibII. */
104 	int8_t		span_enable;	/* Span flag set - private MIB. */
105 	struct asn_oid	circuit;	/* Unused. */
106 	uint32_t	dly_ex_drops;	/* Drops on output. */
107 	uint32_t	dly_mtu_drops;	/* MTU exceeded drops. */
108 	int32_t		status;		/* The entry status. */
109 
110 	/* dot1dStp subtree objects. */
111 	int32_t		path_cost;
112 	int32_t		priority;
113 	int32_t		design_cost;
114 	uint32_t	fwd_trans;
115 	char		p_name[IFNAMSIZ]; /* Not in BRIDGE-MIB. */
116 	enum StpPortState	state;
117 	enum dot1dStpPortEnable	enable;
118 	port_id		design_port;
119 	bridge_id	design_root;
120 	bridge_id	design_bridge;
121 
122 	/* rstpMib extensions. */
123 	int32_t		admin_path_cost;
124 	enum TruthValue	proto_migr;
125 	enum TruthValue	admin_edge;
126 	enum TruthValue	oper_edge;
127 	enum TruthValue	oper_ptp;
128 	enum StpPortAdminPointToPointType	admin_ptp;
129 
130 	/* dot1dTp subtree objects. */
131 	int32_t		max_info;
132 	int32_t		in_frames;
133 	int32_t		out_frames;
134 	int32_t		in_drops;
135 
136 	uint8_t		flags;
137 	TAILQ_ENTRY(bridge_port) b_p;
138 };
139 
140 /*
141  * A bridge interface.
142  * The system interface index of the bridge is not required neither by the
143  * standard BRIDGE-MIB nor by the private BEGEMOT-BRIDGE-MIB, but is used
144  * as key for looking up the other info for this bridge.
145  */
146 struct bridge_if {
147 	/* dot1dBase subtree objects. */
148 	uint32_t	sysindex;	/* The system interface index. */
149 	int32_t		num_ports;	/* Number of ports. */
150 	enum BaseType	br_type;	/* Bridge type. */
151 	enum RowStatus	if_status;	/* Bridge status. */
152 	char		bif_name[IFNAMSIZ]; /* Bridge interface name. */
153 	struct ether_addr br_addr;	/* Bridge address. */
154 	struct bridge_port *f_bp;	/* This bridge's first entry
155 					 * in the base ports TAILQ. */
156 	/* dot1dStp subtree objects. */
157 	int32_t		priority;
158 	int32_t		root_cost;
159 	int32_t		root_port;
160 	int32_t		max_age;	/* Current max age. */
161 	int32_t		hello_time;	/* Current hello time. */
162 	int32_t		fwd_delay;	/* Current forward delay. */
163 	int32_t		hold_time;
164 	int32_t		bridge_max_age;	/* Configured max age. */
165 	int32_t		bridge_hello_time; /* Configured hello time. */
166 	int32_t		bridge_fwd_delay; /* Configured forward delay. */
167 	int32_t		tx_hold_count;
168 	uint32_t	top_changes;
169 	enum dot1dStpVersion	stp_version;
170 	enum dot1dStpProtocolSpecification prot_spec;
171 	struct timeval	last_tc_time;
172 	bridge_id	design_root;
173 
174 	/* dot1dTp subtree objects. */
175 	int32_t		lrnt_drops;	/* Dropped addresses. */
176 	int32_t		age_time;	/* Address entry timeout. */
177 	int32_t		num_addrs;	/* Current # of addresses in cache. */
178 	int32_t		max_addrs;	/* Max # of addresses in cache. */
179 	struct tp_entry	 *f_tpa;	/* This bridge's first entry in
180 					 * the tp addresses TAILQ. */
181 
182 	time_t		entry_age;
183 	time_t		ports_age;
184 	time_t		addrs_age;
185 	TAILQ_ENTRY(bridge_if) b_if;
186 };
187 
188 void bridge_ifs_fini(void);
189 
190 struct bridge_if *bridge_if_find_ifs(uint32_t sysindex);
191 
192 struct bridge_if *bridge_if_find_ifname(const char *b_name);
193 
194 const char *bridge_if_find_name(uint32_t sysindex);
195 
196 int bridge_compare_sysidx(uint32_t i1, uint32_t i2);
197 
198 int bridge_attach_newif(struct mibif *ifp);
199 
200 struct bridge_if *bridge_first_bif(void);
201 
202 struct bridge_if *bridge_next_bif(struct bridge_if *b_pr);
203 
204 void bridge_remove_bif(struct bridge_if *bif);
205 
206 void bridge_update_all_ports(void);
207 
208 void bridge_update_all_addrs(void);
209 
210 void bridge_update_all_ifs(void);
211 
212 void bridge_update_all(void *arg);
213 
214 void bridge_update_tc_time(void *arg);
215 
216 void bridge_ifs_dump(void);
217 
218 /* Bridge ports. */
219 void bridge_ports_update_listage(void);
220 
221 void bridge_ports_fini(void);
222 
223 void bridge_members_free(struct bridge_if *bif);
224 
225 struct bridge_port *bridge_new_port(struct mibif *mif, struct bridge_if *bif);
226 
227 void bridge_port_remove(struct bridge_port *bp, struct bridge_if *bif);
228 
229 struct bridge_port *bridge_port_bif_first(struct bridge_if *bif);
230 
231 struct bridge_port *bridge_port_bif_next(struct bridge_port *bp);
232 
233 struct bridge_port *bridge_port_find(int32_t if_idx, struct bridge_if *bif);
234 
235 void bridge_port_getinfo_mibif(struct mibif *m_if, struct bridge_port *bp);
236 
237 int bridge_getinfo_bif_ports(struct bridge_if *bif);
238 
239 int bridge_update_memif(struct bridge_if *bif);
240 
241 void bridge_ports_dump(struct bridge_if *bif);
242 
243 /* Bridge addresses. */
244 void bridge_addrs_update_listage(void);
245 
246 void bridge_addrs_fini(void);
247 
248 void bridge_addrs_free(struct bridge_if *bif);
249 
250 struct tp_entry *bridge_new_addrs(uint8_t *mac, struct bridge_if *bif);
251 
252 void bridge_addrs_remove(struct tp_entry *te, struct bridge_if *bif);
253 
254 struct tp_entry *bridge_addrs_find(uint8_t *mac, struct bridge_if *bif);
255 
256 struct tp_entry *bridge_addrs_bif_first(struct bridge_if *bif);
257 
258 struct tp_entry *bridge_addrs_bif_next(struct tp_entry *te);
259 
260 int bridge_getinfo_bif_addrs(struct bridge_if *bif);
261 
262 int bridge_update_addrs(struct bridge_if *bif);
263 
264 void bridge_addrs_dump(struct bridge_if *bif);
265 
266 /* Bridge PF. */
267 
268 void bridge_pf_dump(void);
269 
270 /* System specific. */
271 
272 /* Open the socket for the ioctls. */
273 int bridge_ioctl_init(void);
274 
275 /* Load bridge kernel module. */
276 int bridge_kmod_load(void);
277 
278 /* Get the bridge interface information. */
279 int bridge_getinfo_bif(struct bridge_if *bif);
280 
281 /* Get the bridge interface STP parameters. */
282 int bridge_get_op_param(struct bridge_if *bif);
283 
284 /* Set the bridge priority. */
285 int bridge_set_priority(struct bridge_if *bif, int32_t priority);
286 
287 /* Set the bridge max age. */
288 int bridge_set_maxage(struct bridge_if *bif, int32_t max_age);
289 
290 /* Set the bridge hello time.*/
291 int bridge_set_hello_time(struct bridge_if *bif, int32_t hello_time);
292 
293 /* Set the bridge forward delay.*/
294 int bridge_set_forward_delay(struct bridge_if *bif, int32_t fwd_delay);
295 
296 /* Set the bridge address cache max age. */
297 int bridge_set_aging_time(struct bridge_if *bif, int32_t age_time);
298 
299 /* Set the max number of entries in the bridge address cache. */
300 int bridge_set_max_cache(struct bridge_if *bif, int32_t max_cache);
301 
302 /* Set the bridge TX hold count. */
303 int bridge_set_tx_hold_count(struct bridge_if *bif, int32_t tx_hc);
304 
305 /* Set the bridge STP protocol version. */
306 int bridge_set_stp_version(struct bridge_if *bif, int32_t stp_proto);
307 
308 /* Set the bridge interface status to up/down. */
309 int bridge_set_if_up(const char* b_name, int8_t up);
310 
311 /* Create a bridge interface. */
312 int bridge_create(const char *b_name);
313 
314 /* Destroy a bridge interface. */
315 int bridge_destroy(const char *b_name);
316 
317 /* Fetch the bridge mac address. */
318 u_char *bridge_get_basemac(const char *bif_name, u_char *mac, size_t mlen);
319 
320 /* Set a bridge member priority. */
321 int bridge_port_set_priority(const char *bif_name, struct bridge_port *bp,
322     int32_t priority);
323 
324 /* Set a bridge member STP-enabled flag. */
325 int bridge_port_set_stp_enable(const char *bif_name, struct bridge_port *bp,
326     uint32_t enable);
327 
328 /* Set a bridge member STP path cost. */
329 int bridge_port_set_path_cost(const char *bif_name, struct bridge_port *bp,
330     int32_t path_cost);
331 
332 /* Set admin point-to-point link. */
333 int bridge_port_set_admin_ptp(const char *bif_name, struct bridge_port *bp,
334     uint32_t admin_ptp);
335 
336 /* Set admin edge. */
337 int bridge_port_set_admin_edge(const char *bif_name, struct bridge_port *bp,
338     uint32_t enable);
339 
340 /* Add a bridge member port. */
341 int bridge_port_addm(struct bridge_port *bp, const char *b_name);
342 
343 /* Delete a bridge member port. */
344 int bridge_port_delm(struct bridge_port *bp, const char *b_name);
345 
346 /* Get the current value from the module for bridge PF control. */
347 int32_t bridge_get_pfval(uint8_t which);
348 
349 /* Get/Set a bridge PF control. */
350 int32_t bridge_do_pfctl(int32_t bridge_ctl, enum snmp_op op, int32_t *val);
351 
352 #endif /* SNMP_BRIDGE_H */
353