]>
Commit | Line | Data |
---|---|---|
863d2662 | 1 | diff -urN linux-2.2.19/CREDITS linux-2.2.19br/CREDITS |
2 | --- linux-2.2.19/CREDITS Sun Mar 25 18:37:29 2001 | |
3 | +++ linux-2.2.19br/CREDITS Tue Apr 3 11:32:55 2001 | |
4 | @@ -346,6 +346,13 @@ | |
5 | S: Orlando, Florida | |
6 | S: USA | |
7 | ||
8 | +N: Lennert Buytenhek | |
9 | +E: buytenh@gnu.org | |
10 | +D: Rewrite of the ethernet bridging code | |
11 | +S: Ravenhorst 58B | |
12 | +S: 2317 AK Leiden | |
13 | +S: The Netherlands | |
14 | + | |
15 | N: Michael Callahan | |
16 | E: callahan@maths.ox.ac.uk | |
17 | D: PPP for Linux | |
18 | diff -urN linux-2.2.19/Documentation/Configure.help linux-2.2.19br/Documentation/Configure.help | |
19 | --- linux-2.2.19/Documentation/Configure.help Sun Mar 25 18:37:29 2001 | |
20 | +++ linux-2.2.19br/Documentation/Configure.help Tue Apr 3 11:32:55 2001 | |
21 | @@ -3632,24 +3632,26 @@ | |
22 | This is a Logical Link Layer protocol used for X.25 connections over | |
23 | Ethernet, using ordinary Ethernet cards. | |
24 | ||
25 | -Bridging (EXPERIMENTAL) | |
26 | +802.1d Ethernet Bridging | |
27 | CONFIG_BRIDGE | |
28 | If you say Y here, then your Linux box will be able to act as an | |
29 | Ethernet bridge, which means that the different Ethernet segments it | |
30 | is connected to will appear as one Ethernet to the participants. | |
31 | Several such bridges can work together to create even larger | |
32 | - networks of Ethernets using the IEEE802.1 spanning tree algorithm. | |
33 | + networks of Ethernets using the IEEE 802.1d spanning tree protocol. | |
34 | As this is a standard, Linux bridges will interwork properly with | |
35 | other third party bridge products. | |
36 | ||
37 | - In order to use this, you'll need the bridge configuration tools | |
38 | - available from http://lrp.plain.co.nz/tarballs/bridgex-0.30.tar.gz | |
39 | + In order to use the ethernet bridge, you'll need the bridge configuration | |
40 | + tools available from http://www.math.leidenuniv.nl/~buytenh/bridge. Please | |
41 | + read the documentation for more information. | |
42 | + | |
43 | Note that if your box acts as a bridge, it probably contains several | |
44 | - Ethernet devices, but the kernel is not able to recognize more than | |
45 | - one ISA ethernet card at boot time without help; for details read | |
46 | - the Ethernet-HOWTO, available via FTP (user: anonymous) | |
47 | - in ftp://metalab.unc.edu/pub/Linux/docs/HOWTO. The Bridging code is | |
48 | - still in test. If unsure, say N. | |
49 | + Ethernet devices, but the kernel is not able to recognize more than one | |
50 | + at boot time without help; for details read the Ethernet-HOWTO, available | |
51 | + via FTP (user: anonymous) in ftp://metalab.unc.edu/pub/Linux/docs/HOWTO. | |
52 | + | |
53 | + If unsure, say N. | |
54 | ||
55 | Frame Diverter (EXPERIMENTAL) | |
56 | CONFIG_NET_DIVERT | |
57 | diff -urN linux-2.2.19/Documentation/networking/bridge.txt linux-2.2.19br/Documentation/networking/bridge.txt | |
58 | --- linux-2.2.19/Documentation/networking/bridge.txt Thu Jan 1 01:00:00 1970 | |
59 | +++ linux-2.2.19br/Documentation/networking/bridge.txt Tue Apr 3 11:32:55 2001 | |
60 | @@ -0,0 +1,11 @@ | |
61 | +In order to use the ethernet bridging functionality you'll need the | |
62 | +userspace tools available at http://www.math.leidenuniv.nl/~buytenh/bridge. | |
63 | +The tarball available there contains extensive documentation, but if you | |
64 | +still have questions, don't hesitate to post to the mailing list (more info | |
65 | +at http://www.math.leidenuniv.nl/mailman/listinfo/bridge). You can also mail | |
66 | +me at buytenh@gnu.org. | |
67 | + | |
68 | + | |
69 | + | |
70 | +Lennert Buytenhek | |
71 | +<buytenh@gnu.org> | |
72 | diff -urN linux-2.2.19/MAINTAINERS linux-2.2.19br/MAINTAINERS | |
73 | --- linux-2.2.19/MAINTAINERS Sun Mar 25 18:37:29 2001 | |
74 | +++ linux-2.2.19br/MAINTAINERS Tue Apr 3 11:32:55 2001 | |
75 | @@ -371,6 +371,13 @@ | |
76 | L: linux-net@vger.kernel.org | |
77 | S: Maintained | |
78 | ||
79 | +ETHERNET BRIDGE | |
80 | +P: Lennert Buytenhek | |
81 | +M: buytenh@gnu.org | |
82 | +L: bridge@math.leidenuniv.nl | |
83 | +W: http://www.math.leidenuniv.nl/~buytenh/bridge | |
84 | +S: Maintained | |
85 | + | |
86 | ETHERTEAM 16I DRIVER | |
87 | P: Mika Kuoppala | |
88 | M: miku@iki.fi | |
89 | diff -urN linux-2.2.19/Makefile linux-2.2.19br/Makefile | |
90 | --- linux-2.2.19/Makefile Sun Mar 25 18:39:55 2001 | |
91 | +++ linux-2.2.19br/Makefile Tue Apr 3 11:33:22 2001 | |
92 | @@ -1,7 +1,7 @@ | |
93 | VERSION = 2 | |
94 | PATCHLEVEL = 2 | |
95 | SUBLEVEL = 19 | |
96 | -EXTRAVERSION = | |
97 | +EXTRAVERSION = br | |
98 | ||
99 | ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/) | |
100 | ||
101 | diff -urN linux-2.2.19/drivers/char/planb.c linux-2.2.19br/drivers/char/planb.c | |
102 | --- linux-2.2.19/drivers/char/planb.c Sun Mar 25 18:31:27 2001 | |
103 | +++ linux-2.2.19br/drivers/char/planb.c Sun Mar 25 18:31:27 2001 | |
104 | @@ -1390,7 +1390,7 @@ | |
105 | ||
106 | cmd_tab_data_end: | |
107 | tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->intr_stat), | |
108 | - (fr << 2) | PLANB_FRM_IRQ | PLANB_GEN_IRQ); | |
109 | + (fr << 2) | PlANB_FRM_IRQ | PLANB_GEN_IRQ); | |
110 | /* stop it */ | |
111 | tab_cmd_dbdma(c1, DBDMA_STOP, 0); | |
112 | ||
113 | diff -urN linux-2.2.19/include/linux/if_bridge.h linux-2.2.19br/include/linux/if_bridge.h | |
114 | --- linux-2.2.19/include/linux/if_bridge.h Thu Jan 1 01:00:00 1970 | |
115 | +++ linux-2.2.19br/include/linux/if_bridge.h Tue Apr 3 11:32:55 2001 | |
116 | @@ -0,0 +1,110 @@ | |
117 | +/* | |
118 | + * Linux ethernet bridge | |
119 | + * | |
120 | + * Authors: | |
121 | + * Lennert Buytenhek <buytenh@gnu.org> | |
122 | + * | |
123 | + * $Id$ | |
124 | + * | |
125 | + * This program is free software; you can redistribute it and/or | |
126 | + * modify it under the terms of the GNU General Public License | |
127 | + * as published by the Free Software Foundation; either version | |
128 | + * 2 of the License, or (at your option) any later version. | |
129 | + */ | |
130 | + | |
131 | +#ifndef _LINUX_IF_BRIDGE_H | |
132 | +#define _LINUX_IF_BRIDGE_H | |
133 | + | |
134 | +#include <linux/types.h> | |
135 | + | |
136 | +#define BRCTL_VERSION 1 | |
137 | + | |
138 | +#define BRCTL_GET_VERSION 0 | |
139 | +#define BRCTL_GET_BRIDGES 1 | |
140 | +#define BRCTL_ADD_BRIDGE 2 | |
141 | +#define BRCTL_DEL_BRIDGE 3 | |
142 | +#define BRCTL_ADD_IF 4 | |
143 | +#define BRCTL_DEL_IF 5 | |
144 | +#define BRCTL_GET_BRIDGE_INFO 6 | |
145 | +#define BRCTL_GET_PORT_LIST 7 | |
146 | +#define BRCTL_SET_BRIDGE_FORWARD_DELAY 8 | |
147 | +#define BRCTL_SET_BRIDGE_HELLO_TIME 9 | |
148 | +#define BRCTL_SET_BRIDGE_MAX_AGE 10 | |
149 | +#define BRCTL_SET_AGEING_TIME 11 | |
150 | +#define BRCTL_SET_GC_INTERVAL 12 | |
151 | +#define BRCTL_GET_PORT_INFO 13 | |
152 | +#define BRCTL_SET_BRIDGE_STP_STATE 14 | |
153 | +#define BRCTL_SET_BRIDGE_PRIORITY 15 | |
154 | +#define BRCTL_SET_PORT_PRIORITY 16 | |
155 | +#define BRCTL_SET_PATH_COST 17 | |
156 | +#define BRCTL_GET_FDB_ENTRIES 18 | |
157 | + | |
158 | +#define BR_STATE_DISABLED 0 | |
159 | +#define BR_STATE_LISTENING 1 | |
160 | +#define BR_STATE_LEARNING 2 | |
161 | +#define BR_STATE_FORWARDING 3 | |
162 | +#define BR_STATE_BLOCKING 4 | |
163 | + | |
164 | +struct __bridge_info | |
165 | +{ | |
166 | + __u64 designated_root; | |
167 | + __u64 bridge_id; | |
168 | + __u32 root_path_cost; | |
169 | + __u32 max_age; | |
170 | + __u32 hello_time; | |
171 | + __u32 forward_delay; | |
172 | + __u32 bridge_max_age; | |
173 | + __u32 bridge_hello_time; | |
174 | + __u32 bridge_forward_delay; | |
175 | + __u8 topology_change; | |
176 | + __u8 topology_change_detected; | |
177 | + __u8 root_port; | |
178 | + __u8 stp_enabled; | |
179 | + __u32 ageing_time; | |
180 | + __u32 gc_interval; | |
181 | + __u32 hello_timer_value; | |
182 | + __u32 tcn_timer_value; | |
183 | + __u32 topology_change_timer_value; | |
184 | + __u32 gc_timer_value; | |
185 | +}; | |
186 | + | |
187 | +struct __port_info | |
188 | +{ | |
189 | + __u64 designated_root; | |
190 | + __u64 designated_bridge; | |
191 | + __u16 port_id; | |
192 | + __u16 designated_port; | |
193 | + __u32 path_cost; | |
194 | + __u32 designated_cost; | |
195 | + __u8 state; | |
196 | + __u8 top_change_ack; | |
197 | + __u8 config_pending; | |
198 | + __u8 unused0; | |
199 | + __u32 message_age_timer_value; | |
200 | + __u32 forward_delay_timer_value; | |
201 | + __u32 hold_timer_value; | |
202 | +}; | |
203 | + | |
204 | +struct __fdb_entry | |
205 | +{ | |
206 | + __u8 mac_addr[6]; | |
207 | + __u8 port_no; | |
208 | + __u8 is_local; | |
209 | + __u32 ageing_timer_value; | |
210 | + __u32 unused; | |
211 | +}; | |
212 | + | |
213 | +#ifdef __KERNEL__ | |
214 | + | |
215 | +#include <linux/netdevice.h> | |
216 | + | |
217 | +struct net_bridge; | |
218 | +struct net_bridge_port; | |
219 | + | |
220 | +extern int br_init(void); | |
221 | +extern int (*br_ioctl_hook)(unsigned long arg); | |
222 | +extern void (*br_handle_frame_hook)(struct sk_buff *skb); | |
223 | + | |
224 | +#endif | |
225 | + | |
226 | +#endif | |
227 | diff -urN linux-2.2.19/include/linux/netdevice.h linux-2.2.19br/include/linux/netdevice.h | |
228 | --- linux-2.2.19/include/linux/netdevice.h Sun Mar 25 18:31:03 2001 | |
229 | +++ linux-2.2.19br/include/linux/netdevice.h Tue Apr 3 11:32:55 2001 | |
230 | @@ -270,9 +270,6 @@ | |
231 | struct Qdisc *qdisc_list; | |
232 | unsigned long tx_queue_len; /* Max frames per queue allowed */ | |
233 | ||
234 | - /* Bridge stuff */ | |
235 | - int bridge_port_id; | |
236 | - | |
237 | /* Pointers to interface service routines. */ | |
238 | int (*open)(struct device *dev); | |
239 | int (*stop)(struct device *dev); | |
240 | @@ -309,6 +306,9 @@ | |
241 | unsigned char *haddr); | |
242 | int (*neigh_setup)(struct device *dev, struct neigh_parms *); | |
243 | int (*accept_fastpath)(struct device *, struct dst_entry*); | |
244 | + | |
245 | + /* bridge stuff */ | |
246 | + struct net_bridge_port *br_port; | |
247 | ||
248 | #ifdef CONFIG_NET_FASTROUTE | |
249 | /* Really, this semaphore may be necessary and for not fastroute code; | |
250 | diff -urN linux-2.2.19/include/linux/skbuff.h linux-2.2.19br/include/linux/skbuff.h | |
251 | --- linux-2.2.19/include/linux/skbuff.h Sun Mar 25 18:31:03 2001 | |
252 | +++ linux-2.2.19br/include/linux/skbuff.h Tue Apr 3 11:32:55 2001 | |
253 | @@ -83,7 +83,6 @@ | |
254 | unsigned char is_clone, /* We are a clone */ | |
255 | cloned, /* head may be cloned (check refcnt to be sure). */ | |
256 | pkt_type, /* Packet class */ | |
257 | - pkt_bridged, /* Tracker for bridging */ | |
258 | ip_summed; /* Driver fed us an IP checksum */ | |
259 | __u32 priority; /* Packet queueing priority */ | |
260 | atomic_t users; /* User count - see datagram.c,tcp.c */ | |
261 | diff -urN linux-2.2.19/include/net/br.h linux-2.2.19br/include/net/br.h | |
262 | --- linux-2.2.19/include/net/br.h Sun Mar 25 18:31:08 2001 | |
263 | +++ linux-2.2.19br/include/net/br.h Thu Jan 1 01:00:00 1970 | |
264 | @@ -1,331 +0,0 @@ | |
265 | -/* | |
266 | - * Constants and structure definitions for the bridging code | |
267 | - */ | |
268 | - | |
269 | -#if !defined(One) | |
270 | -#define Zero 0 | |
271 | -#define One 1 | |
272 | -#endif /* !defined(One) */ | |
273 | - | |
274 | -#if !defined(TRUE) | |
275 | -#define FALSE 0 | |
276 | -#define TRUE 1 | |
277 | -#endif /* !defined(TRUE) */ | |
278 | - | |
279 | -/** port states. **/ | |
280 | -#define Disabled 0 /* (4.4 5) */ | |
281 | -#define Listening 1 /* (4.4.2) */ | |
282 | -#define Learning 2 /* (4.4.3) */ | |
283 | -#define Forwarding 3 /* (4 4 4) */ | |
284 | -#define Blocking 4 /* (4.4.1) */ | |
285 | - | |
286 | - | |
287 | -/* MAG Yich! Easiest way of giving a configurable number of ports | |
288 | - * If you want more than 32, change BR_MAX_PORTS and recompile brcfg! | |
289 | - */ | |
290 | -#define BR_MAX_PORTS (32) | |
291 | -#if CONFIG_BRIDGE_NUM_PORTS > BR_MAX_PORTS | |
292 | -#undef CONFIG_BRIDGE_NUM_PORTS | |
293 | -#define CONFIG_BRIDGE_NUM_PORTS BR_MAX_PORTS | |
294 | -#endif | |
295 | -#define No_of_ports CONFIG_BRIDGE_NUM_PORTS | |
296 | -/* arbitrary choice, to allow the code below to compile */ | |
297 | - | |
298 | -#define All_ports (No_of_ports + 1) | |
299 | - | |
300 | -/* | |
301 | - * We time out our entries in the FDB after this many seconds. | |
302 | - */ | |
303 | -#define FDB_TIMEOUT 20 /* JRP: 20s as NSC bridge code, was 300 for Linux */ | |
304 | - | |
305 | -/* | |
306 | - * the following defines are the initial values used when the | |
307 | - * bridge is booted. These may be overridden when this bridge is | |
308 | - * not the root bridge. These are the recommended default values | |
309 | - * from the 802.1d specification. | |
310 | - */ | |
311 | -#define BRIDGE_MAX_AGE 20 | |
312 | -#define BRIDGE_HELLO_TIME 2 | |
313 | -#define BRIDGE_FORWARD_DELAY 15 | |
314 | -#define HOLD_TIME 1 | |
315 | - | |
316 | -/* broacast/multicast storm limitation. This per source. */ | |
317 | -#define MAX_MCAST_PER_PERIOD 32 | |
318 | -#define MCAST_HOLD_TIME (10*HZ/100) | |
319 | - | |
320 | -#define Default_path_cost 10 | |
321 | - | |
322 | -/* | |
323 | - * minimum increment possible to avoid underestimating age, allows for BPDU | |
324 | - * transmission time | |
325 | - */ | |
326 | -#define Message_age_increment 1 | |
327 | - | |
328 | -#define No_port 0 | |
329 | -/* | |
330 | - * reserved value for Bridge's root port parameter indicating no root port, | |
331 | - * used when Bridge is the root - also used to indicate the source when | |
332 | - * a frame is being generated by a higher layer protocol on this host | |
333 | - */ | |
334 | - | |
335 | -/** Configuration BPDU Parameters (4.5.1) **/ | |
336 | - | |
337 | -typedef struct { | |
338 | - union { | |
339 | - struct { | |
340 | - unsigned short priority; | |
341 | - unsigned char ula[6]; | |
342 | - } p_u; | |
343 | - unsigned int id[2]; | |
344 | - } bi; | |
345 | -} bridge_id_t; | |
346 | - | |
347 | -#define BRIDGE_PRIORITY bi.p_u.priority | |
348 | -#define BRIDGE_ID_ULA bi.p_u.ula | |
349 | -#define BRIDGE_ID bi.id | |
350 | - | |
351 | -/* JRP: on the network the flags field is between "type" and "root_id" | |
352 | - * this is unfortunated! To make the code portable to a RISC machine | |
353 | - * the pdus are now massaged a little bit for processing | |
354 | - */ | |
355 | -#define TOPOLOGY_CHANGE 0x01 | |
356 | -#define TOPOLOGY_CHANGE_ACK 0x80 | |
357 | -#define BRIDGE_BPDU_8021_CONFIG_SIZE 35 /* real size */ | |
358 | -#define BRIDGE_BPDU_8021_CONFIG_FLAG_OFFSET 4 | |
359 | -#define BRIDGE_BPDU_8021_PROTOCOL_ID 0 | |
360 | -#define BRIDGE_BPDU_8021_PROTOCOL_VERSION_ID 0 | |
361 | -#define BRIDGE_LLC1_HS 3 | |
362 | -#define BRIDGE_LLC1_DSAP 0x42 | |
363 | -#define BRIDGE_LLC1_SSAP 0x42 | |
364 | -#define BRIDGE_LLC1_CTRL 0x03 | |
365 | - | |
366 | -typedef struct { | |
367 | - unsigned short protocol_id; | |
368 | - unsigned char protocol_version_id; | |
369 | - unsigned char type; | |
370 | - bridge_id_t root_id; /* (4.5.1.1) */ | |
371 | - unsigned int root_path_cost; /* (4.5.1.2) */ | |
372 | - bridge_id_t bridge_id; /* (4.5.1.3) */ | |
373 | - unsigned short port_id; /* (4.5.1.4) */ | |
374 | - unsigned short message_age; /* (4.5.1.5) */ | |
375 | - unsigned short max_age; /* (4.5.1.6) */ | |
376 | - unsigned short hello_time; /* (4.5.1.7) */ | |
377 | - unsigned short forward_delay; /* (4.5.1.8) */ | |
378 | - unsigned char top_change_ack; | |
379 | - unsigned char top_change; | |
380 | -} Config_bpdu; | |
381 | - | |
382 | -#ifdef __LITTLE_ENDIAN | |
383 | -#define config_bpdu_hton(config_bpdu) \ | |
384 | - (config_bpdu)->root_path_cost = htonl((config_bpdu)->root_path_cost); \ | |
385 | - (config_bpdu)->port_id = htons((config_bpdu)->port_id); \ | |
386 | - (config_bpdu)->message_age = htons((config_bpdu)->message_age); \ | |
387 | - (config_bpdu)->max_age = htons((config_bpdu)->max_age); \ | |
388 | - (config_bpdu)->hello_time = htons((config_bpdu)->hello_time); \ | |
389 | - (config_bpdu)->forward_delay = htons((config_bpdu)->forward_delay); | |
390 | -#else | |
391 | -#define config_bpdu_hton(config_bpdu) | |
392 | -#endif | |
393 | -#define config_bpdu_ntoh config_bpdu_hton | |
394 | - | |
395 | - | |
396 | -/** Topology Change Notification BPDU Parameters (4.5.2) **/ | |
397 | - | |
398 | -typedef struct { | |
399 | - unsigned short protocol_id; | |
400 | - unsigned char protocol_version_id; | |
401 | - unsigned char type; | |
402 | -} Tcn_bpdu; | |
403 | - | |
404 | -#define BPDU_TYPE_CONFIG 0 | |
405 | -#define BPDU_TYPE_TOPO_CHANGE 128 | |
406 | - | |
407 | -/** Bridge Parameters (4.5.3) **/ | |
408 | -typedef struct { | |
409 | - bridge_id_t designated_root; /* (4.5.3.1) */ | |
410 | - unsigned int root_path_cost; /* (4.5.3.2) */ | |
411 | - unsigned int root_port; /* (4.5.3.3) */ | |
412 | - unsigned short max_age; /* (4.5.3.4) */ | |
413 | - unsigned short hello_time; /* (4.5.3.5) */ | |
414 | - unsigned short forward_delay; /* (4.5.3.6) */ | |
415 | - bridge_id_t bridge_id; /* (4.5.3.7) */ | |
416 | - unsigned short bridge_max_age; /* (4.5.3.8) */ | |
417 | - unsigned short bridge_hello_time; /* (4.5.3.9) */ | |
418 | - unsigned short bridge_forward_delay; /* (4.5.3.10) */ | |
419 | - unsigned int top_change_detected; /* (4.5.3.11) */ | |
420 | - unsigned int top_change; /* (4.5.3.12) */ | |
421 | - unsigned short topology_change_time; /* (4.5.3.13) */ | |
422 | - unsigned short hold_time; /* (4.5.3.14) */ | |
423 | - unsigned int instance; | |
424 | -} Bridge_data; | |
425 | - | |
426 | -/** Port Parameters (4.5.5) **/ | |
427 | -typedef struct { | |
428 | - unsigned short port_id; /* (4.5.5.1) */ | |
429 | - unsigned int state; /* (4.5.5.2) */ | |
430 | - unsigned int path_cost; /* (4.5.5.3) */ | |
431 | - bridge_id_t designated_root; /* (4.5.5.4) */ | |
432 | - unsigned int designated_cost; /* (4.5.5.5) */ | |
433 | - bridge_id_t designated_bridge; /* (4.5.5.6) */ | |
434 | - unsigned short designated_port; /* (4.5.5.7) */ | |
435 | - unsigned int top_change_ack; /* (4.5.5.8) */ | |
436 | - unsigned int config_pending; /* (4.5.5.9) */ | |
437 | - bridge_id_t ifmac; | |
438 | - unsigned int admin_state; | |
439 | - char ifname[IFNAMSIZ]; /* Make life easier for brcfg */ | |
440 | - struct device *dev; | |
441 | - struct fdb *fdb; /* head of per port fdb chain */ | |
442 | -} Port_data; | |
443 | - | |
444 | - | |
445 | - | |
446 | -/** types to support timers for this pseudo-implementation. **/ | |
447 | -typedef struct { | |
448 | - unsigned int active; /* timer in use. */ | |
449 | - unsigned int value; /* current value of timer, | |
450 | - * counting up. */ | |
451 | -} Timer; | |
452 | - | |
453 | -struct fdb { | |
454 | - unsigned char ula[6]; | |
455 | - unsigned char pad[2]; | |
456 | - unsigned short port; | |
457 | - unsigned int timer; | |
458 | - unsigned short flags; | |
459 | -#define FDB_ENT_VALID 0x01 | |
460 | - unsigned short mcast_count; | |
461 | - unsigned int mcast_timer; /* oldest xxxxxcast */ | |
462 | - | |
463 | -/* AVL tree of all addresses, sorted by address */ | |
464 | - short fdb_avl_height; | |
465 | - struct fdb *fdb_avl_left; | |
466 | - struct fdb *fdb_avl_right; | |
467 | -/* linked list of addresses for each port */ | |
468 | - struct fdb *fdb_next; | |
469 | -}; | |
470 | - | |
471 | -/* data returned on BRCMD_DISPLAY_FDB */ | |
472 | -struct fdb_info { | |
473 | - unsigned char ula[6]; | |
474 | - unsigned char port; | |
475 | - unsigned char flags; | |
476 | - unsigned int timer; | |
477 | -}; | |
478 | -struct fdb_info_hdr { | |
479 | - int copied; /* nb of entries copied to user */ | |
480 | - int not_copied; /* when user buffer is too small */ | |
481 | - int cmd_time; | |
482 | -}; | |
483 | - | |
484 | -#define IS_BRIDGED 0x2e | |
485 | - | |
486 | - | |
487 | -#define BR_MAX_PROTOCOLS 32 | |
488 | -#define BR_MAX_PROT_STATS BR_MAX_PROTOCOLS | |
489 | - | |
490 | -/* policy values for policy field */ | |
491 | -#define BR_ACCEPT 1 | |
492 | -#define BR_REJECT 0 | |
493 | - | |
494 | -/* JRP: extra statistics for debug */ | |
495 | -typedef struct { | |
496 | - /* br_receive_frame counters */ | |
497 | - int port_disable_up_stack; | |
498 | - int rcv_bpdu; | |
499 | - int notForwarding; | |
500 | - int forwarding_up_stack; | |
501 | - int unknown_state; | |
502 | - | |
503 | - /* br_tx_frame counters */ | |
504 | - int port_disable; | |
505 | - int port_not_disable; | |
506 | - | |
507 | - /* br_forward counters */ | |
508 | - int local_multicast; | |
509 | - int forwarded_multicast; /* up stack as well */ | |
510 | - int flood_unicast; | |
511 | - int aged_flood_unicast; | |
512 | - int forwarded_unicast; | |
513 | - int forwarded_unicast_up_stack; | |
514 | - int forwarded_ip_up_stack; | |
515 | - int forwarded_ip_up_stack_lie; /* received on alternate device */ | |
516 | - int arp_for_local_mac; | |
517 | - int drop_same_port; | |
518 | - int drop_same_port_aged; | |
519 | - int drop_multicast; | |
520 | -} br_stats_counter; | |
521 | - | |
522 | -struct br_stat { | |
523 | - unsigned int flags; | |
524 | - Bridge_data bridge_data; | |
525 | - unsigned int policy; | |
526 | - unsigned int exempt_protocols; | |
527 | - unsigned short protocols[BR_MAX_PROTOCOLS]; | |
528 | - unsigned short prot_id[BR_MAX_PROT_STATS]; /* Protocol encountered */ | |
529 | - unsigned int prot_counter[BR_MAX_PROT_STATS]; /* How many packets ? */ | |
530 | - br_stats_counter packet_cnts; | |
531 | - unsigned int num_ports; | |
532 | - Port_data port_data[BR_MAX_PORTS + 1]; | |
533 | -}; | |
534 | - | |
535 | -/* defined flags for br_stat.flags */ | |
536 | -#define BR_UP 0x0001 /* bridging enabled */ | |
537 | -#define BR_DEBUG 0x0002 /* debugging enabled */ | |
538 | -#define BR_PROT_STATS 0x0004 /* protocol statistics enabled */ | |
539 | -#define BR_STP_DISABLED 0x0008 /* Spanning tree protocol disabled */ | |
540 | - | |
541 | -struct br_cf { | |
542 | - unsigned int cmd; | |
543 | - unsigned int arg1; | |
544 | - unsigned int arg2; | |
545 | -}; | |
546 | - | |
547 | -/* defined cmds */ | |
548 | -#define BRCMD_BRIDGE_ENABLE 1 | |
549 | -#define BRCMD_BRIDGE_DISABLE 2 | |
550 | -#define BRCMD_PORT_ENABLE 3 /* arg1 = port */ | |
551 | -#define BRCMD_PORT_DISABLE 4 /* arg1 = port */ | |
552 | -#define BRCMD_SET_BRIDGE_PRIORITY 5 /* arg1 = priority */ | |
553 | -#define BRCMD_SET_PORT_PRIORITY 6 /* arg1 = port, arg2 = priority */ | |
554 | -#define BRCMD_SET_PATH_COST 7 /* arg1 = port, arg2 = cost */ | |
555 | -#define BRCMD_DISPLAY_FDB 8 | |
556 | -#define BRCMD_ENABLE_DEBUG 9 | |
557 | -#define BRCMD_DISABLE_DEBUG 10 | |
558 | -#define BRCMD_SET_POLICY 11 /* arg1 = default policy (1==bridge all) */ | |
559 | -#define BRCMD_EXEMPT_PROTOCOL 12 /* arg1 = protocol (see net/if_ether.h) */ | |
560 | -#define BRCMD_ENABLE_PROT_STATS 13 | |
561 | -#define BRCMD_DISABLE_PROT_STATS 14 | |
562 | -#define BRCMD_ZERO_PROT_STATS 15 | |
563 | -#define BRCMD_TOGGLE_STP 16 | |
564 | -#define BRCMD_IF_ENABLE 17 /* arg1 = if_index */ | |
565 | -#define BRCMD_IF_DISABLE 18 /* arg1 = if_index */ | |
566 | -#define BRCMD_SET_IF_PRIORITY 19 /* arg1 = if_index, arg2 = priority */ | |
567 | -#define BRCMD_SET_IF_PATH_COST 20 /* arg1 = if_index, arg2 = cost */ | |
568 | - | |
569 | -/* prototypes of exported bridging functions... */ | |
570 | - | |
571 | -#ifdef __KERNEL__ | |
572 | -void br_init(void); | |
573 | -int br_receive_frame(struct sk_buff *skb); /* 3.5 */ | |
574 | -int br_tx_frame(struct sk_buff *skb); | |
575 | -int brg_init(void); | |
576 | -int br_ioctl(unsigned int cmd, void *arg); | |
577 | -void requeue_fdb(struct fdb *node, int new_port); | |
578 | - | |
579 | -struct fdb *br_avl_find_addr(unsigned char addr[6]); | |
580 | -struct fdb *br_avl_insert (struct fdb * new_node); | |
581 | -void sprintf_avl (char **pbuffer, struct fdb * tree, off_t *pos,int* len, off_t offset, int length); | |
582 | -int br_tree_get_info(char *buffer, char **start, off_t offset, int length, int dummy); | |
583 | -void br_avl_delete_by_port(int port); | |
584 | -int br_call_bridge(struct sk_buff *skb, unsigned short type); | |
585 | -void br_spacedevice_register(void); | |
586 | - | |
587 | -/* externs */ | |
588 | - | |
589 | -extern struct br_stat br_stats; | |
590 | -extern Port_data port_info[]; | |
591 | - | |
592 | -#endif | |
593 | - | |
594 | - | |
595 | - | |
596 | diff -urN linux-2.2.19/net/Config.in linux-2.2.19br/net/Config.in | |
597 | --- linux-2.2.19/net/Config.in Sun Mar 25 18:37:41 2001 | |
598 | +++ linux-2.2.19br/net/Config.in Tue Apr 3 11:32:57 2001 | |
599 | @@ -31,6 +31,7 @@ | |
600 | source net/ipx/Config.in | |
601 | fi | |
602 | tristate 'Appletalk DDP' CONFIG_ATALK | |
603 | +tristate '802.1d Ethernet Bridging' CONFIG_BRIDGE | |
604 | if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then | |
605 | # tristate 'DECnet Support (NOT YET FUNCTIONAL)' CONFIG_DECNET | |
606 | # if [ "$CONFIG_DECNET" != "n" ]; then | |
607 | @@ -38,10 +39,6 @@ | |
608 | # fi | |
609 | tristate 'CCITT X.25 Packet Layer (EXPERIMENTAL)' CONFIG_X25 | |
610 | tristate 'LAPB Data Link Driver (EXPERIMENTAL)' CONFIG_LAPB | |
611 | - bool 'Bridging (EXPERIMENTAL)' CONFIG_BRIDGE | |
612 | - if [ "$CONFIG_BRIDGE" != "n" ]; then | |
613 | - int ' Maximum number of bridged interfaces' CONFIG_BRIDGE_NUM_PORTS 8 | |
614 | - fi | |
615 | bool 'Frame Diverter (EXPERIMENTAL)' CONFIG_NET_DIVERT | |
616 | bool '802.2 LLC (EXPERIMENTAL)' CONFIG_LLC | |
617 | # if [ "$CONFIG_LLC" = "y" ]; then | |
618 | diff -urN linux-2.2.19/net/Makefile linux-2.2.19br/net/Makefile | |
619 | --- linux-2.2.19/net/Makefile Sun Mar 25 18:31:11 2001 | |
620 | +++ linux-2.2.19br/net/Makefile Tue Apr 3 11:32:57 2001 | |
621 | @@ -59,6 +59,10 @@ | |
622 | ||
623 | ifeq ($(CONFIG_BRIDGE),y) | |
624 | SUB_DIRS += bridge | |
625 | +else | |
626 | + ifeq ($(CONFIG_BRIDGE),m) | |
627 | + MOD_SUB_DIRS += bridge | |
628 | + endif | |
629 | endif | |
630 | ||
631 | ifeq ($(CONFIG_IPX),y) | |
632 | diff -urN linux-2.2.19/net/README linux-2.2.19br/net/README | |
633 | --- linux-2.2.19/net/README Sun Mar 25 18:31:11 2001 | |
634 | +++ linux-2.2.19br/net/README Tue Apr 3 11:32:57 2001 | |
635 | @@ -7,6 +7,7 @@ | |
636 | [token ring ] p.norton@computer.org | |
637 | appletalk Jay.Schulist@spacs.k12.wi.us | |
638 | ax25 g4klx@g4klx.demon.co.uk | |
639 | +bridge buytenh@gnu.org | |
640 | core alan@lxorguk.ukuu.org.uk | |
641 | decnet SteveW@ACM.org | |
642 | ethernet alan@lxorguk.ukuu.org.uk | |
643 | diff -urN linux-2.2.19/net/bridge/Makefile linux-2.2.19br/net/bridge/Makefile | |
644 | --- linux-2.2.19/net/bridge/Makefile Sun Mar 25 18:31:13 2001 | |
645 | +++ linux-2.2.19br/net/bridge/Makefile Tue Apr 3 11:32:57 2001 | |
646 | @@ -1,5 +1,5 @@ | |
647 | # | |
648 | -# Makefile for the Linux Bridge layer. | |
649 | +# Makefile for the IEEE 802.1d ethernet bridging layer. | |
650 | # | |
651 | # Note! Dependencies are done automagically by 'make dep', which also | |
652 | # removes any old dependencies. DON'T put your own dependencies here | |
653 | @@ -7,15 +7,10 @@ | |
654 | # | |
655 | # Note 2! The CFLAGS definition is now in the main makefile... | |
656 | ||
657 | -O_TARGET := bridge.o | |
658 | -O_OBJS := br.o br_tree.o | |
659 | -M_OBJS := $(O_TARGET) | |
660 | - | |
661 | -ifeq ($(CONFIG_SYSCTL),y) | |
662 | -O_OBJS += sysctl_net_bridge.o | |
663 | -endif | |
664 | +O_TARGET := bridge.o | |
665 | +O_OBJS := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \ | |
666 | + br_ioctl.o br_notify.o br_stp.o br_stp_bpdu.o \ | |
667 | + br_stp_if.o br_stp_timer.o | |
668 | +M_OBJS := $(O_TARGET) | |
669 | ||
670 | include $(TOPDIR)/Rules.make | |
671 | - | |
672 | -tar: | |
673 | - tar -cvf /dev/f1 . | |
674 | diff -urN linux-2.2.19/net/bridge/br.c linux-2.2.19br/net/bridge/br.c | |
675 | --- linux-2.2.19/net/bridge/br.c Sun Mar 25 18:31:13 2001 | |
676 | +++ linux-2.2.19br/net/bridge/br.c Tue Apr 3 11:32:57 2001 | |
677 | @@ -1,2775 +1,67 @@ | |
678 | /* | |
679 | - * Linux NET3 Bridge Support | |
680 | + * Generic parts | |
681 | + * Linux ethernet bridge | |
682 | * | |
683 | - * Originally by John Hayes (Network Plumbing). | |
684 | - * Minor hacks to get it to run with 1.3.x by Alan Cox <Alan.Cox@linux.org> | |
685 | - * More hacks to be able to switch protocols on and off by Christoph Lameter | |
686 | - * <clameter@debian.org> | |
687 | - * Software and more Documentation for the bridge is available from ftp.debian.org | |
688 | - * in the bridgex package | |
689 | + * Authors: | |
690 | + * Lennert Buytenhek <buytenh@gnu.org> | |
691 | + * | |
692 | + * $Id$ | |
693 | * | |
694 | * This program is free software; you can redistribute it and/or | |
695 | * modify it under the terms of the GNU General Public License | |
696 | * as published by the Free Software Foundation; either version | |
697 | * 2 of the License, or (at your option) any later version. | |
698 | - * | |
699 | - * Fixes: | |
700 | - * Yury Shevchuk : Bridge with non bridging ports | |
701 | - * Jean-Rene Peulve: jr.peulve@aix.pacwan.net Jan/Feb 98 | |
702 | - * support Linux 2.0 | |
703 | - * Handle Receive config bpdu | |
704 | - * kick mark_bh to send Spanning Tree pdus | |
705 | - * bridgeId comparison using htonl() | |
706 | - * make STP interoperable with other vendors | |
707 | - * wrong test in root_selection() | |
708 | - * add more STP debug info | |
709 | - * some performance improvments | |
710 | - * do not clear bridgeId.mac while setting priority | |
711 | - * do not reset port priority when starting bridge | |
712 | - * make port priority from user value and port number | |
713 | - * maintains user port state out of device state | |
714 | - * broacast/multicast storm limitation | |
715 | - * forwarding statistics | |
716 | - * stop br_tick when bridge is turn off | |
717 | - * add local MACs in avl_tree to forward up stack | |
718 | - * fake receive on right port for IP/ARP | |
719 | - * ages tree even if packet does not cross bridge | |
720 | - * add BRCMD_DISPLAY_FDB (ioctl for now) | |
721 | - * | |
722 | - * Alan Cox: Merged Jean-Rene's stuff, reformatted stuff a bit | |
723 | - * so blame me first if its broken ;) | |
724 | - * | |
725 | - * Robert Pintarelli: fixed bug in bpdu time values | |
726 | - * | |
727 | - * Matthew Grant: start ports disabled. | |
728 | - * auto-promiscuous mode on port enable/disable | |
729 | - * fleshed out interface event handling, interfaces | |
730 | - * now register with bridge on module load as well as ifup | |
731 | - * port control ioctls with ifindex support | |
732 | - * brg0 logical ethernet interface | |
733 | - * reworked brcfg to take interface arguments | |
734 | - * added support for changing the hardware address | |
735 | - * generally made bridge a lot more usable. | |
736 | - * | |
737 | - * Todo: | |
738 | - * Use a netlink notifier so a daemon can maintain the bridge | |
739 | - * port group (could we also do multiple groups ????). | |
740 | - * A nice /proc file interface. | |
741 | - * Put the path costs in the port info and devices. | |
742 | - * Put the bridge port number in the device structure for speed. | |
743 | - * Bridge SNMP stats. | |
744 | - * | |
745 | */ | |
746 | - | |
747 | -#include <linux/config.h> | |
748 | -#include <linux/module.h> | |
749 | -#include <linux/errno.h> | |
750 | -#include <linux/types.h> | |
751 | -#include <linux/socket.h> | |
752 | -#include <linux/in.h> | |
753 | ||
754 | +#include <linux/module.h> | |
755 | #include <linux/kernel.h> | |
756 | -#include <linux/sched.h> | |
757 | -#include <linux/timer.h> | |
758 | -#include <linux/malloc.h> | |
759 | -#include <linux/string.h> | |
760 | -#include <linux/net.h> | |
761 | -#include <linux/inet.h> | |
762 | +#include <linux/miscdevice.h> | |
763 | #include <linux/netdevice.h> | |
764 | -#include <linux/inetdevice.h> | |
765 | #include <linux/etherdevice.h> | |
766 | -#include <linux/skbuff.h> | |
767 | -#include <linux/if_arp.h> | |
768 | -#include <linux/ip.h> | |
769 | -#include <linux/version.h> | |
770 | #include <linux/init.h> | |
771 | +#include <linux/if_bridge.h> | |
772 | #include <asm/uaccess.h> | |
773 | -#include <asm/system.h> | |
774 | -#include <linux/rtnetlink.h> | |
775 | -#include <net/br.h> | |
776 | -#include <linux/proc_fs.h> | |
777 | -#include <linux/delay.h> | |
778 | - | |
779 | -#ifndef min | |
780 | -#define min(a, b) (((a) <= (b)) ? (a) : (b)) | |
781 | -#endif | |
782 | - | |
783 | -static void transmit_config(int port_no); | |
784 | -static int root_bridge(void); | |
785 | -static int supersedes_port_info(int port_no, Config_bpdu *config); | |
786 | -static void record_config_information(int port_no, Config_bpdu *config); | |
787 | -static void record_config_timeout_values(Config_bpdu *config); | |
788 | -static void config_bpdu_generation(void); | |
789 | -static int designated_port(int port_no); | |
790 | -static void reply(int port_no); | |
791 | -static void transmit_tcn(void); | |
792 | -static void configuration_update(void); | |
793 | -static void root_selection(void); | |
794 | -static void designated_port_selection(void); | |
795 | -static void become_designated_port(int port_no); | |
796 | -static void port_state_selection(void); | |
797 | -static void make_forwarding(int port_no); | |
798 | -static void topology_change_detection(void); | |
799 | -static void topology_change_acknowledged(void); | |
800 | -static void acknowledge_topology_change(int port_no); | |
801 | -static void make_blocking(int port_no); | |
802 | -static void set_port_state(int port_no, int state); | |
803 | -static void received_config_bpdu(int port_no, Config_bpdu *config); | |
804 | -static void received_tcn_bpdu(int port_no, Tcn_bpdu *tcn); | |
805 | -static void hello_timer_expiry(void); | |
806 | -static void message_age_timer_expiry(int port_no); | |
807 | -static void forward_delay_timer_expiry(int port_no); | |
808 | -static int designated_for_some_port(void); | |
809 | -static void tcn_timer_expiry(void); | |
810 | -static void topology_change_timer_expiry(void); | |
811 | -static void hold_timer_expiry(int port_no); | |
812 | -static void br_init_port(int port_no); | |
813 | -static void enable_port(int port_no); | |
814 | -static void disable_port(int port_no); | |
815 | -static void set_bridge_priority(bridge_id_t *new_bridge_id); | |
816 | -static void set_port_priority(int port_no); | |
817 | -static void set_path_cost(int port_no, unsigned short path_cost); | |
818 | -static void start_hello_timer(void); | |
819 | -static void stop_hello_timer(void); | |
820 | -static int hello_timer_expired(void); | |
821 | -static void start_tcn_timer(void); | |
822 | -static void stop_tcn_timer(void); | |
823 | -static int tcn_timer_expired(void); | |
824 | -static void start_topology_change_timer(void); | |
825 | -static void stop_topology_change_timer(void); | |
826 | -static int topology_change_timer_expired(void); | |
827 | -static void start_message_age_timer(int port_no, unsigned short message_age); | |
828 | -static void stop_message_age_timer(int port_no); | |
829 | -static int message_age_timer_expired(int port_no); | |
830 | -static void start_forward_delay_timer(int port_no); | |
831 | -static void stop_forward_delay_timer(int port_no); | |
832 | -static int forward_delay_timer_expired(int port_no); | |
833 | -static void start_hold_timer(int port_no); | |
834 | -static void stop_hold_timer(int port_no); | |
835 | -static int hold_timer_expired(int port_no); | |
836 | -static int br_device_event(struct notifier_block *dnot, unsigned long event, void *ptr); | |
837 | -static void br_tick(unsigned long arg); | |
838 | -static int br_forward(struct sk_buff *skb, int port); /* 3.7 */ | |
839 | -static int br_port_cost(struct device *dev); /* 4.10.2 */ | |
840 | -static void br_bpdu(struct sk_buff *skb, int port); /* consumes skb */ | |
841 | -static int br_cmp(unsigned int *a, unsigned int *b); | |
842 | -static int send_tcn_bpdu(int port_no, Tcn_bpdu *bpdu); | |
843 | -static int send_config_bpdu(int port_no, Config_bpdu *config_bpdu); | |
844 | -static int find_port(struct device *dev); | |
845 | -static void br_add_local_mac(unsigned char *mac); | |
846 | -static int br_flood(struct sk_buff *skb, int port); | |
847 | -static int br_drop(struct sk_buff *skb); | |
848 | -static int br_learn(struct sk_buff *skb, int port); /* 3.8 */ | |
849 | -static int br_protocol_ok(unsigned short protocol); | |
850 | -static int br_find_port(int ifindex); | |
851 | -static void br_get_ifnames(void); | |
852 | -static int brg_rx(struct sk_buff *skb, int port); | |
853 | - | |
854 | -static unsigned char bridge_ula[ETH_ALEN] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 }; | |
855 | -static Bridge_data bridge_info; /* (4.5.3) */ | |
856 | -Port_data port_info[All_ports]; /* (4.5.5) */ | |
857 | - | |
858 | -/* MAG: Maximum port registered - used to speed up flooding and to make | |
859 | - * have a large ports array more efficient | |
860 | - */ | |
861 | -static int max_port_used = 0; | |
862 | - | |
863 | -/* JRP: fdb cache 1/port save kmalloc/kfree on every frame */ | |
864 | -struct fdb *newfdb[All_ports]; | |
865 | -int allocated_fdb_cnt = 0; | |
866 | - | |
867 | -/* broacast/multicast storm limitation */ | |
868 | -int max_mcast_per_period = MAX_MCAST_PER_PERIOD; | |
869 | -int mcast_hold_time = MCAST_HOLD_TIME; | |
870 | - | |
871 | -/* JRP: next two bpdu are copied to skbuff so we need only 1 of each */ | |
872 | -static Config_bpdu config_bpdu; | |
873 | -static Tcn_bpdu tcn_bpdu; | |
874 | -static unsigned char port_priority[All_ports]; | |
875 | -static unsigned char user_port_state[All_ports]; | |
876 | - | |
877 | -static Timer hello_timer; /* (4.5.4.1) */ | |
878 | -static Timer tcn_timer; /* (4.5.4.2) */ | |
879 | -static Timer topology_change_timer; /* (4.5.4.3) */ | |
880 | -static Timer message_age_timer[All_ports]; /* (4.5.6.1) */ | |
881 | -static Timer forward_delay_timer[All_ports]; /* (4.5.6.2) */ | |
882 | -static Timer hold_timer[All_ports]; /* (4.5.6.3) */ | |
883 | - | |
884 | -/* entries timeout after this many seconds */ | |
885 | -unsigned int fdb_aging_time = FDB_TIMEOUT; | |
886 | - | |
887 | -struct br_stat br_stats; | |
888 | -#define br_stats_cnt br_stats.packet_cnts | |
889 | - | |
890 | -static struct timer_list tl; /* for 1 second timer... */ | |
891 | - | |
892 | -/* | |
893 | - * the following structure is required so that we receive | |
894 | - * event notifications when network devices are enabled and | |
895 | - * disabled (ifconfig up and down). | |
896 | - */ | |
897 | -static struct notifier_block br_dev_notifier={ | |
898 | - br_device_event, | |
899 | - NULL, | |
900 | - 0 | |
901 | -}; | |
902 | - | |
903 | - | |
904 | -/* | |
905 | - * the following data is for the bridge network device | |
906 | - */ | |
907 | -struct brg_if { | |
908 | - struct device dev; | |
909 | - char name[IFNAMSIZ]; | |
910 | -}; | |
911 | -static struct brg_if brg_if; | |
912 | - | |
913 | -/* | |
914 | - * Here to save linkage? problems | |
915 | - */ | |
916 | - | |
917 | -static inline int find_port(struct device *dev) | |
918 | -{ | |
919 | - int i; | |
920 | - | |
921 | - for (i = One; i <= No_of_ports; i++) | |
922 | - if (port_info[i].dev == dev) | |
923 | - return(i); | |
924 | - return(0); | |
925 | -} | |
926 | - | |
927 | -/* | |
928 | - * Implementation of Protocol specific bridging | |
929 | - * | |
930 | - * The protocols to be bridged or not to be bridged are stored in a hashed array. This is the old type | |
931 | - * of unlinked hash array where one simply takes the next cell if the one the hash function points to | |
932 | - * is occupied. | |
933 | - */ | |
934 | - | |
935 | -#define BR_PROTOCOL_HASH(x) (x % BR_MAX_PROTOCOLS) | |
936 | - | |
937 | -/* Checks if that protocol type is to be bridged */ | |
938 | - | |
939 | -static int inline br_protocol_ok(unsigned short protocol) | |
940 | -{ | |
941 | - unsigned x; | |
942 | - | |
943 | - /* See if protocol statistics are to be kept */ | |
944 | - if (br_stats.flags & BR_PROT_STATS) | |
945 | - { | |
946 | - for(x=0;x<BR_MAX_PROT_STATS && br_stats.prot_id[x]!=protocol && br_stats.prot_id[x];x++); | |
947 | - if (x<BR_MAX_PROT_STATS) | |
948 | - { | |
949 | - br_stats.prot_id[x]=protocol;br_stats.prot_counter[x]++; | |
950 | - } | |
951 | - } | |
952 | - | |
953 | - for (x=BR_PROTOCOL_HASH(protocol); br_stats.protocols[x]!=0;) | |
954 | - { | |
955 | - if (br_stats.protocols[x]==protocol) | |
956 | - return !br_stats.policy; | |
957 | - x++; | |
958 | - if (x==BR_MAX_PROTOCOLS) | |
959 | - x=0; | |
960 | - } | |
961 | - return br_stats.policy; | |
962 | -} | |
963 | - | |
964 | -/* Add a protocol to be handled opposite to the standard policy of the bridge */ | |
965 | - | |
966 | -static int br_add_exempt_protocol(unsigned short p) | |
967 | -{ | |
968 | - unsigned x; | |
969 | - if (p == 0) return -EINVAL; | |
970 | - if (br_stats.exempt_protocols > BR_MAX_PROTOCOLS-2) return -EXFULL; | |
971 | - for (x=BR_PROTOCOL_HASH(p);br_stats.protocols[x]!=0;) { | |
972 | - if (br_stats.protocols[x]==p) return 0; /* Attempt to add the protocol a second time */ | |
973 | - x++; | |
974 | - if (x==BR_MAX_PROTOCOLS) x=0; | |
975 | - } | |
976 | - br_stats.protocols[x]=p; | |
977 | - br_stats.exempt_protocols++; | |
978 | - return 0; | |
979 | -} | |
980 | - | |
981 | -/* Valid Policies are 0=No Protocols bridged 1=Bridge all protocols */ | |
982 | -static int br_set_policy(int policy) | |
983 | -{ | |
984 | - if (policy>1) return -EINVAL; | |
985 | - br_stats.policy=policy; | |
986 | - /* Policy change means initializing the exempt table */ | |
987 | - memset(br_stats.protocols,0,sizeof(br_stats.protocols)); | |
988 | - br_stats.exempt_protocols = 0; | |
989 | - return 0; | |
990 | -} | |
991 | - | |
992 | - | |
993 | -/** Elements of Procedure (4.6) **/ | |
994 | - | |
995 | -/* | |
996 | - * this section of code was graciously borrowed from the IEEE 802.1d | |
997 | - * specification section 4.9.1 starting on pg 69. It has been | |
998 | - * modified somewhat to fit within our framework and structure. It | |
999 | - * implements the spanning tree algorithm that is the heart of the | |
1000 | - * 802.1d bridging protocol. | |
1001 | - */ | |
1002 | - | |
1003 | -static void transmit_config(int port_no) /* (4.6.1) */ | |
1004 | -{ | |
1005 | - if (hold_timer[port_no].active) { /* (4.6.1.3.1) */ | |
1006 | - port_info[port_no].config_pending = TRUE; /* (4.6.1.3.1) */ | |
1007 | - } else { /* (4.6.1.3.2) */ | |
1008 | - config_bpdu.type = BPDU_TYPE_CONFIG; | |
1009 | - config_bpdu.root_id = bridge_info.designated_root; | |
1010 | - /* (4.6.1.3.2(1)) */ | |
1011 | - config_bpdu.root_path_cost = bridge_info.root_path_cost; | |
1012 | - /* (4.6.1.3.2(2)) */ | |
1013 | - config_bpdu.bridge_id = bridge_info.bridge_id; | |
1014 | - /* (4.6.1.3.2(3)) */ | |
1015 | - config_bpdu.port_id = port_info[port_no].port_id; | |
1016 | - /* | |
1017 | - * (4.6.1.3.2(4)) | |
1018 | - */ | |
1019 | - if (root_bridge()) { | |
1020 | - config_bpdu.message_age = Zero; /* (4.6.1.3.2(5)) */ | |
1021 | - } else { | |
1022 | - config_bpdu.message_age | |
1023 | - = (message_age_timer[bridge_info.root_port].value | |
1024 | - + Message_age_increment) << 8; /* (4.6.1.3.2(6)) */ | |
1025 | - } | |
1026 | - | |
1027 | - config_bpdu.max_age = bridge_info.max_age << 8;/* (4.6.1.3.2(7)) */ | |
1028 | - config_bpdu.hello_time = bridge_info.hello_time << 8; | |
1029 | - config_bpdu.forward_delay = bridge_info.forward_delay << 8; | |
1030 | - config_bpdu.top_change_ack = | |
1031 | - port_info[port_no].top_change_ack; | |
1032 | - /* (4.6.1.3.2(8)) */ | |
1033 | - port_info[port_no].top_change_ack = 0; | |
1034 | - | |
1035 | - config_bpdu.top_change = | |
1036 | - bridge_info.top_change; /* (4.6.1.3.2(9)) */ | |
1037 | - | |
1038 | - send_config_bpdu(port_no, &config_bpdu); | |
1039 | - port_info[port_no].config_pending = FALSE; /* (4.6.1.3.2(10)) */ | |
1040 | - start_hold_timer(port_no); /* (4.6.1.3.2(11)) */ | |
1041 | - } | |
1042 | -/* JRP: we want the frame to be xmitted even if no other traffic. | |
1043 | - * net_bh() will do a dev_transmit() that kicks all devices | |
1044 | - */ | |
1045 | - mark_bh(NET_BH); | |
1046 | -} | |
1047 | - | |
1048 | -static int root_bridge(void) | |
1049 | -{ | |
1050 | - return (br_cmp(bridge_info.designated_root.BRIDGE_ID, | |
1051 | - bridge_info.bridge_id.BRIDGE_ID)?FALSE:TRUE); | |
1052 | -} | |
1053 | - | |
1054 | -static int supersedes_port_info(int port_no, Config_bpdu *config) /* (4.6.2.2) */ | |
1055 | -{ | |
1056 | - return ( | |
1057 | - (br_cmp(config->root_id.BRIDGE_ID, | |
1058 | - port_info[port_no].designated_root.BRIDGE_ID) < 0) /* (4.6.2.2.1) */ | |
1059 | - || | |
1060 | - ((br_cmp(config->root_id.BRIDGE_ID, | |
1061 | - port_info[port_no].designated_root.BRIDGE_ID) == 0 | |
1062 | - ) | |
1063 | - && | |
1064 | - ((config->root_path_cost | |
1065 | - < port_info[port_no].designated_cost /* (4.6.2.2.2) */ | |
1066 | - ) | |
1067 | - || | |
1068 | - ((config->root_path_cost | |
1069 | - == port_info[port_no].designated_cost | |
1070 | - ) | |
1071 | - && | |
1072 | - ((br_cmp(config->bridge_id.BRIDGE_ID, | |
1073 | - port_info[port_no].designated_bridge.BRIDGE_ID) < 0 /* (4.6.2.2.3) */ | |
1074 | - ) | |
1075 | - || | |
1076 | - ((br_cmp(config->bridge_id.BRIDGE_ID, | |
1077 | - port_info[port_no].designated_bridge.BRIDGE_ID) == 0 | |
1078 | - ) /* (4.6.2.2.4) */ | |
1079 | - && | |
1080 | - ((br_cmp(config->bridge_id.BRIDGE_ID, | |
1081 | - bridge_info.bridge_id.BRIDGE_ID) != 0 | |
1082 | - ) /* (4.6.2.2.4(1)) */ | |
1083 | - || | |
1084 | - (config->port_id <= | |
1085 | - port_info[port_no].designated_port | |
1086 | - ) /* (4.6.2.2.4(2)) */ | |
1087 | - )))))) | |
1088 | - ); | |
1089 | -} | |
1090 | - | |
1091 | -static void record_config_information(int port_no, Config_bpdu *config) /* (4.6.2) */ | |
1092 | -{ | |
1093 | - port_info[port_no].designated_root = config->root_id; /* (4.6.2.3.1) */ | |
1094 | - port_info[port_no].designated_cost = config->root_path_cost; | |
1095 | - port_info[port_no].designated_bridge = config->bridge_id; | |
1096 | - port_info[port_no].designated_port = config->port_id; | |
1097 | - start_message_age_timer(port_no, config->message_age); /* (4.6.2.3.2) */ | |
1098 | -} | |
1099 | - | |
1100 | -static void record_config_timeout_values(Config_bpdu *config) /* (4.6.3) */ | |
1101 | -{ | |
1102 | - bridge_info.max_age = config->max_age >> 8; /* (4.6.3.3) */ | |
1103 | - bridge_info.hello_time = config->hello_time >> 8; | |
1104 | - bridge_info.forward_delay = config->forward_delay >> 8; | |
1105 | - bridge_info.top_change = config->top_change >> 8; | |
1106 | -} | |
1107 | - | |
1108 | -static void config_bpdu_generation(void) | |
1109 | -{ /* (4.6.4) */ | |
1110 | - int port_no; | |
1111 | - for (port_no = One; port_no <= No_of_ports; port_no++) { /* (4.6.4.3) */ | |
1112 | - if (designated_port(port_no) /* (4.6.4.3) */ | |
1113 | - && | |
1114 | - (port_info[port_no].state != Disabled) | |
1115 | - ) { | |
1116 | - transmit_config(port_no); /* (4.6.4.3) */ | |
1117 | - } /* (4.6.1.2) */ | |
1118 | - } | |
1119 | -} | |
1120 | - | |
1121 | -static int designated_port(int port_no) | |
1122 | -{ | |
1123 | - return ((br_cmp(port_info[port_no].designated_bridge.BRIDGE_ID, | |
1124 | - bridge_info.bridge_id.BRIDGE_ID) == 0 | |
1125 | - ) | |
1126 | - && | |
1127 | - (port_info[port_no].designated_port | |
1128 | - == port_info[port_no].port_id | |
1129 | - ) | |
1130 | - ); | |
1131 | -} | |
1132 | - | |
1133 | -static void reply(int port_no) /* (4.6.5) */ | |
1134 | -{ | |
1135 | - transmit_config(port_no); /* (4.6.5.3) */ | |
1136 | -} | |
1137 | - | |
1138 | -static void transmit_tcn(void) | |
1139 | -{ /* (4.6.6) */ | |
1140 | - int port_no; | |
1141 | - | |
1142 | - port_no = bridge_info.root_port; | |
1143 | - tcn_bpdu.type = BPDU_TYPE_TOPO_CHANGE; | |
1144 | - send_tcn_bpdu(port_no, &tcn_bpdu); /* (4.6.6.3) */ | |
1145 | -} | |
1146 | - | |
1147 | -static void configuration_update(void) /* (4.6.7) */ | |
1148 | -{ | |
1149 | - root_selection(); /* (4.6.7.3.1) */ | |
1150 | - /* (4.6.8.2) */ | |
1151 | - designated_port_selection(); /* (4.6.7.3.2) */ | |
1152 | - /* (4.6.9.2) */ | |
1153 | -} | |
1154 | - | |
1155 | -static void root_selection(void) | |
1156 | -{ /* (4.6.8) */ | |
1157 | - int root_port; | |
1158 | - int port_no; | |
1159 | - root_port = No_port; | |
1160 | - for (port_no = One; port_no <= No_of_ports; port_no++) { /* (4.6.8.3.1) */ | |
1161 | - if (((!designated_port(port_no)) | |
1162 | - && | |
1163 | - (port_info[port_no].state != Disabled) | |
1164 | - && | |
1165 | - (br_cmp(port_info[port_no].designated_root.BRIDGE_ID, | |
1166 | - bridge_info.bridge_id.BRIDGE_ID) < 0) | |
1167 | - ) | |
1168 | - && | |
1169 | - ((root_port == No_port) | |
1170 | - || | |
1171 | - (br_cmp(port_info[port_no].designated_root.BRIDGE_ID, | |
1172 | - port_info[root_port].designated_root.BRIDGE_ID) < 0 | |
1173 | - ) | |
1174 | - || | |
1175 | - ((br_cmp(port_info[port_no].designated_root.BRIDGE_ID, | |
1176 | - port_info[root_port].designated_root.BRIDGE_ID) == 0 | |
1177 | - ) | |
1178 | - && | |
1179 | - (((port_info[port_no].designated_cost | |
1180 | - + port_info[port_no].path_cost | |
1181 | - ) | |
1182 | - < | |
1183 | - (port_info[root_port].designated_cost | |
1184 | - + port_info[root_port].path_cost | |
1185 | - ) /* (4.6.8.3.1(2)) */ | |
1186 | - ) | |
1187 | - || | |
1188 | - (((port_info[port_no].designated_cost | |
1189 | - + port_info[port_no].path_cost | |
1190 | - ) | |
1191 | - == | |
1192 | - (port_info[root_port].designated_cost | |
1193 | - + port_info[root_port].path_cost | |
1194 | - ) | |
1195 | - ) | |
1196 | - && | |
1197 | - ((br_cmp(port_info[port_no].designated_bridge.BRIDGE_ID, | |
1198 | - port_info[root_port].designated_bridge.BRIDGE_ID) < 0 | |
1199 | - ) /* (4.6.8.3.1(3)) */ | |
1200 | - || | |
1201 | - ((br_cmp(port_info[port_no].designated_bridge.BRIDGE_ID, | |
1202 | - port_info[root_port].designated_bridge.BRIDGE_ID) == 0 | |
1203 | - ) | |
1204 | - && | |
1205 | - ((port_info[port_no].designated_port | |
1206 | - < port_info[root_port].designated_port | |
1207 | - ) /* (4.6.8.3.1(4)) */ | |
1208 | - || | |
1209 | - ((port_info[port_no].designated_port | |
1210 | -/* JRP: was missing an "=" ! */ == port_info[root_port].designated_port | |
1211 | - ) | |
1212 | - && | |
1213 | - (port_info[port_no].port_id | |
1214 | - < port_info[root_port].port_id | |
1215 | - ) /* (4.6.8.3.1(5)) */ | |
1216 | - ))))))))) { | |
1217 | - root_port = port_no; | |
1218 | - } | |
1219 | - } | |
1220 | - bridge_info.root_port = root_port; /* (4.6.8.3.1) */ | |
1221 | - | |
1222 | - if (root_port == No_port) { /* (4.6.8.3.2) */ | |
1223 | -#ifdef DEBUG_STP | |
1224 | - if (br_stats.flags & BR_DEBUG) | |
1225 | - printk(KERN_DEBUG "root_selection: becomes root\n"); | |
1226 | -#endif | |
1227 | - bridge_info.designated_root = bridge_info.bridge_id; | |
1228 | - /* (4.6.8.3.2(1)) */ | |
1229 | - bridge_info.root_path_cost = Zero;/* (4.6.8.3.2(2)) */ | |
1230 | - } else { /* (4.6.8.3.3) */ | |
1231 | - bridge_info.designated_root = port_info[root_port].designated_root; | |
1232 | - /* (4.6.8.3.3(1)) */ | |
1233 | - bridge_info.root_path_cost = (port_info[root_port].designated_cost | |
1234 | - + port_info[root_port].path_cost | |
1235 | - ); /* (4.6.8.3.3(2)) */ | |
1236 | - } | |
1237 | -} | |
1238 | - | |
1239 | -static void designated_port_selection(void) | |
1240 | -{ /* (4.6.9) */ | |
1241 | - int port_no; | |
1242 | - | |
1243 | - for (port_no = One; port_no <= No_of_ports; port_no++) { /* (4.6.9.3) */ | |
1244 | - if(port_info[port_no].state == Disabled) | |
1245 | - continue; | |
1246 | - if (designated_port(port_no) /* (4.6.9.3.1) */ | |
1247 | - || | |
1248 | - ( | |
1249 | - br_cmp(port_info[port_no].designated_root.BRIDGE_ID, | |
1250 | - bridge_info.designated_root.BRIDGE_ID) != 0 | |
1251 | - ) | |
1252 | - || | |
1253 | - (bridge_info.root_path_cost | |
1254 | - < port_info[port_no].designated_cost | |
1255 | - ) /* (4.6.9.3.3) */ | |
1256 | - || | |
1257 | - ((bridge_info.root_path_cost | |
1258 | - == port_info[port_no].designated_cost | |
1259 | - ) | |
1260 | - && | |
1261 | - ((br_cmp(bridge_info.bridge_id.BRIDGE_ID, | |
1262 | - port_info[port_no].designated_bridge.BRIDGE_ID) < 0 | |
1263 | - ) /* (4.6.9.3.4) */ | |
1264 | - || | |
1265 | - ((br_cmp(bridge_info.bridge_id.BRIDGE_ID, | |
1266 | - port_info[port_no].designated_bridge.BRIDGE_ID) == 0 | |
1267 | - ) | |
1268 | - && | |
1269 | - (port_info[port_no].port_id | |
1270 | - <= port_info[port_no].designated_port | |
1271 | - ) /* (4.6.9.3.5) */ | |
1272 | - )))) { | |
1273 | - become_designated_port(port_no); /* (4.6.10.3.2.2) */ | |
1274 | - } | |
1275 | - } | |
1276 | -} | |
1277 | - | |
1278 | -static void become_designated_port(int port_no) | |
1279 | -{ /* (4.6.10) */ | |
1280 | - | |
1281 | - /* (4.6.10.3.1) */ | |
1282 | - port_info[port_no].designated_root = bridge_info.designated_root; | |
1283 | - /* (4.6.10.3.2) */ | |
1284 | - port_info[port_no].designated_cost = bridge_info.root_path_cost; | |
1285 | - /* (4.6.10.3.3) */ | |
1286 | - port_info[port_no].designated_bridge = bridge_info.bridge_id; | |
1287 | - /* (4.6.10.3.4) */ | |
1288 | - port_info[port_no].designated_port = port_info[port_no].port_id; | |
1289 | -} | |
1290 | - | |
1291 | -static void port_state_selection(void) | |
1292 | -{ /* (4.6.11) */ | |
1293 | - int port_no; | |
1294 | - char *state_str; | |
1295 | - for (port_no = One; port_no <= No_of_ports; port_no++) { | |
1296 | - | |
1297 | - if(port_info[port_no].state == Disabled) | |
1298 | - continue; | |
1299 | - if (port_no == bridge_info.root_port) { /* (4.6.11.3.1) */ | |
1300 | - state_str = "root"; | |
1301 | - port_info[port_no].config_pending = FALSE; /* (4.6.11.3.1(1)) */ | |
1302 | - port_info[port_no].top_change_ack = 0; | |
1303 | - make_forwarding(port_no); /* (4.6.11.3.1(2)) */ | |
1304 | - } else if (designated_port(port_no)) { /* (4.6.11.3.2) */ | |
1305 | - state_str = "designated"; | |
1306 | - stop_message_age_timer(port_no); /* (4.6.11.3.2(1)) */ | |
1307 | - make_forwarding(port_no); /* (4.6.11.3.2(2)) */ | |
1308 | - } else { /* (4.6.11.3.3) */ | |
1309 | - state_str = "blocking"; | |
1310 | - port_info[port_no].config_pending = FALSE; /* (4.6.11.3.3(1)) */ | |
1311 | - port_info[port_no].top_change_ack = 0; | |
1312 | - make_blocking(port_no); /* (4.6.11.3.3(2)) */ | |
1313 | - } | |
1314 | -#ifdef DEBUG_STP | |
1315 | - if (br_stats.flags & BR_DEBUG) | |
1316 | - printk(KERN_DEBUG "port_state_selection: becomes %s port %d\n", | |
1317 | - state_str, port_no); | |
1318 | -#endif | |
1319 | - | |
1320 | - } | |
1321 | - | |
1322 | -} | |
1323 | - | |
1324 | -static void make_forwarding(int port_no) | |
1325 | -{ /* (4.6.12) */ | |
1326 | - if (port_info[port_no].state == Blocking) { /* (4.6.12.3) */ | |
1327 | - set_port_state(port_no, Listening); /* (4.6.12.3.1) */ | |
1328 | - start_forward_delay_timer(port_no); /* (4.6.12.3.2) */ | |
1329 | - } | |
1330 | -} | |
1331 | - | |
1332 | -static void topology_change_detection(void) | |
1333 | -{ /* (4.6.14) */ | |
1334 | -#ifdef DEBUG_STP | |
1335 | - if ((br_stats.flags & BR_DEBUG) | |
1336 | - && (bridge_info.top_change_detected == 0)) | |
1337 | - printk(KERN_DEBUG "topology_change_detected\n"); | |
1338 | -#endif | |
1339 | - if (root_bridge()) { /* (4.6.14.3.1) */ | |
1340 | - bridge_info.top_change = 1; | |
1341 | - start_topology_change_timer(); /* (4.6.14.3.1(2)) */ | |
1342 | - } else if (!(bridge_info.top_change_detected)) { | |
1343 | - transmit_tcn(); /* (4.6.14.3.2(1)) */ | |
1344 | - start_tcn_timer(); /* (4.6.14.3.2(2)) */ | |
1345 | - } | |
1346 | - bridge_info.top_change_detected = 1; /* (4.6.14.3.3) */ | |
1347 | -} | |
1348 | - | |
1349 | -static void topology_change_acknowledged(void) | |
1350 | -{ /* (4.6.15) */ | |
1351 | -#ifdef DEBUG_STP | |
1352 | - if (br_stats.flags & BR_DEBUG) | |
1353 | - printk(KERN_DEBUG "topology_change_acked\n"); | |
1354 | -#endif | |
1355 | - bridge_info.top_change_detected = 0; /* (4.6.15.3.1) */ | |
1356 | - stop_tcn_timer(); /* (4.6.15.3.2) */ | |
1357 | -} | |
1358 | - | |
1359 | -static void acknowledge_topology_change(int port_no) | |
1360 | -{ /* (4.6.16) */ | |
1361 | - port_info[port_no].top_change_ack = 1; | |
1362 | - transmit_config(port_no); /* (4.6.16.3.2) */ | |
1363 | -} | |
1364 | - | |
1365 | -static void make_blocking(int port_no) /* (4.6.13) */ | |
1366 | -{ | |
1367 | - | |
1368 | - if ((port_info[port_no].state != Disabled) | |
1369 | - && | |
1370 | - (port_info[port_no].state != Blocking) | |
1371 | - /* (4.6.13.3) */ | |
1372 | - ) { | |
1373 | - if ((port_info[port_no].state == Forwarding) | |
1374 | - || | |
1375 | - (port_info[port_no].state == Learning) | |
1376 | - ) { | |
1377 | - topology_change_detection(); /* (4.6.13.3.1) */ | |
1378 | - /* (4.6.14.2.3) */ | |
1379 | - } | |
1380 | - set_port_state(port_no, Blocking);/* (4.6.13.3.2) */ | |
1381 | - stop_forward_delay_timer(port_no);/* (4.6.13.3.3) */ | |
1382 | - } | |
1383 | -} | |
1384 | - | |
1385 | -static void set_port_state(int port_no, int state) | |
1386 | -{ | |
1387 | - port_info[port_no].state = state; | |
1388 | -} | |
1389 | - | |
1390 | -static void received_config_bpdu(int port_no, Config_bpdu *config) /* (4.7.1) */ | |
1391 | -{ | |
1392 | - int root; | |
1393 | - | |
1394 | - root = root_bridge(); | |
1395 | - if (port_info[port_no].state != Disabled) { | |
1396 | +#include "br_private.h" | |
1397 | ||
1398 | -#ifdef DEBUG_STP | |
1399 | - if (br_stats.flags & BR_DEBUG) | |
1400 | - printk(KERN_DEBUG "received_config_bpdu: port %d\n", | |
1401 | - port_no); | |
1402 | -#endif | |
1403 | - if (supersedes_port_info(port_no, config)) { /* (4.7.1.1) *//* (4. | |
1404 | - * 6.2.2) */ | |
1405 | - record_config_information(port_no, config); /* (4.7.1.1.1) */ | |
1406 | - /* (4.6.2.2) */ | |
1407 | - configuration_update(); /* (4.7.1.1.2) */ | |
1408 | - /* (4.6.7.2.1) */ | |
1409 | - port_state_selection(); /* (4.7.1.1.3) */ | |
1410 | - /* (4.6.11.2.1) */ | |
1411 | - if ((!root_bridge()) && root) { /* (4.7.1.1.4) */ | |
1412 | - stop_hello_timer(); | |
1413 | - if (bridge_info.top_change_detected) { /* (4.7.1.1.5 */ | |
1414 | - stop_topology_change_timer(); | |
1415 | - transmit_tcn(); /* (4.6.6.1) */ | |
1416 | - start_tcn_timer(); | |
1417 | - } | |
1418 | - } | |
1419 | - if (port_no == bridge_info.root_port) { | |
1420 | - record_config_timeout_values(config); /* (4.7.1.1.6) */ | |
1421 | - /* (4.6.3.2) */ | |
1422 | - config_bpdu_generation(); /* (4.6.4.2.1) */ | |
1423 | - if (config->top_change_ack) { /* (4.7.1.1.7) */ | |
1424 | - topology_change_acknowledged(); /* (4.6.15.2) */ | |
1425 | - } | |
1426 | - } | |
1427 | - } else if (designated_port(port_no)) { /* (4.7.1.2) */ | |
1428 | - reply(port_no); /* (4.7.1.2.1) */ | |
1429 | - /* (4.6.5.2) */ | |
1430 | - } | |
1431 | - } | |
1432 | -} | |
1433 | - | |
1434 | -static void received_tcn_bpdu(int port_no, Tcn_bpdu *tcn) /* (4.7.2) */ | |
1435 | -{ | |
1436 | - if (port_info[port_no].state != Disabled) { | |
1437 | -#ifdef DEBUG_STP | |
1438 | - if (br_stats.flags & BR_DEBUG) | |
1439 | - printk(KERN_DEBUG "received_tcn_bpdu: port %d\n", | |
1440 | - port_no); | |
1441 | -#endif | |
1442 | - if (designated_port(port_no)) { | |
1443 | - topology_change_detection(); /* (4.7.2.1) */ | |
1444 | - /* (4.6.14.2.1) */ | |
1445 | - acknowledge_topology_change(port_no); /* (4.7.2.2) */ | |
1446 | - } /* (4.6.16.2) */ | |
1447 | - } | |
1448 | -} | |
1449 | - | |
1450 | -static void hello_timer_expiry(void) | |
1451 | -{ /* (4.7.3) */ | |
1452 | - config_bpdu_generation(); /* (4.6.4.2.2) */ | |
1453 | - start_hello_timer(); | |
1454 | -} | |
1455 | - | |
1456 | -static void message_age_timer_expiry(int port_no) /* (4.7.4) */ | |
1457 | +void br_dec_use_count() | |
1458 | { | |
1459 | - int root; | |
1460 | - root = root_bridge(); | |
1461 | - | |
1462 | -#ifdef DEBUG_STP | |
1463 | - if (br_stats.flags & BR_DEBUG) | |
1464 | - printk(KERN_DEBUG "message_age_timer_expiry: port %d\n", | |
1465 | - port_no); | |
1466 | -#endif | |
1467 | - become_designated_port(port_no); /* (4.7.4.1) */ | |
1468 | - /* (4.6.10.2.1) */ | |
1469 | - configuration_update(); /* (4.7.4.2) */ | |
1470 | - /* (4.6.7.2.2) */ | |
1471 | - port_state_selection(); /* (4.7.4.3) */ | |
1472 | - /* (4.6.11.2.2) */ | |
1473 | - if ((root_bridge()) && (!root)) { /* (4.7.4.4) */ | |
1474 | - | |
1475 | - bridge_info.max_age = bridge_info.bridge_max_age; /* (4.7.4.4.1) */ | |
1476 | - bridge_info.hello_time = bridge_info.bridge_hello_time; | |
1477 | - bridge_info.forward_delay = bridge_info.bridge_forward_delay; | |
1478 | - topology_change_detection(); /* (4.7.4.4.2) */ | |
1479 | - /* (4.6.14.2.4) */ | |
1480 | - stop_tcn_timer(); /* (4.7.4.4.3) */ | |
1481 | - config_bpdu_generation(); /* (4.7.4.4.4) */ | |
1482 | - /* (4.6.4.4.3) */ | |
1483 | - start_hello_timer(); | |
1484 | - } | |
1485 | + MOD_DEC_USE_COUNT; | |
1486 | } | |
1487 | ||
1488 | -static void forward_delay_timer_expiry(int port_no) /* (4.7.5) */ | |
1489 | +void br_inc_use_count() | |
1490 | { | |
1491 | - if (port_info[port_no].state == Listening) | |
1492 | - { /* (4.7.5.1) */ | |
1493 | - set_port_state(port_no, Learning); /* (4.7.5.1.1) */ | |
1494 | - start_forward_delay_timer(port_no); /* (4.7.5.1.2) */ | |
1495 | - } | |
1496 | - else if (port_info[port_no].state == Learning) | |
1497 | - { | |
1498 | - /* (4.7.5.2) */ | |
1499 | - set_port_state(port_no, Forwarding); /* (4.7.5.2.1) */ | |
1500 | - if (designated_for_some_port()) | |
1501 | - { /* (4.7.5.2.2) */ | |
1502 | - topology_change_detection(); /* (4.6.14.2.2) */ | |
1503 | - | |
1504 | - } | |
1505 | - } | |
1506 | + MOD_INC_USE_COUNT; | |
1507 | } | |
1508 | ||
1509 | -static int designated_for_some_port(void) | |
1510 | +__initfunc(int br_init(void)) | |
1511 | { | |
1512 | - int port_no; | |
1513 | - | |
1514 | - for (port_no = One; port_no <= No_of_ports; port_no++) | |
1515 | - { | |
1516 | - if(port_info[port_no].state == Disabled) | |
1517 | - continue; | |
1518 | - if ((br_cmp(port_info[port_no].designated_bridge.BRIDGE_ID, | |
1519 | - bridge_info.bridge_id.BRIDGE_ID) == 0)) | |
1520 | - { | |
1521 | - return (TRUE); | |
1522 | - } | |
1523 | - } | |
1524 | - return (FALSE); | |
1525 | -} | |
1526 | + printk(KERN_INFO "NET4: Ethernet Bridge 008 for NET4.0\n"); | |
1527 | ||
1528 | -static void tcn_timer_expiry(void) | |
1529 | -{ /* (4.7.6) */ | |
1530 | - transmit_tcn(); /* (4.7.6.1) */ | |
1531 | - start_tcn_timer(); /* (4.7.6.2) */ | |
1532 | -} | |
1533 | - | |
1534 | -static void topology_change_timer_expiry(void) | |
1535 | -{ /* (4.7.7) */ | |
1536 | - bridge_info.top_change_detected = 0; /* (4.7.7.1) */ | |
1537 | - bridge_info.top_change = 0; | |
1538 | - /* (4.7.7.2) */ | |
1539 | -} | |
1540 | - | |
1541 | -static void hold_timer_expiry(int port_no) /* (4.7.8) */ | |
1542 | -{ | |
1543 | - if (port_info[port_no].config_pending) | |
1544 | - { | |
1545 | - transmit_config(port_no); /* (4.7.8.1) */ | |
1546 | - } /* (4.6.1.2.3) */ | |
1547 | -} | |
1548 | - | |
1549 | -/* Vova Oksman: Write the buffer (contents of the Bridge table) */ | |
1550 | -/* to a PROCfs file */ | |
1551 | -int br_tree_get_info(char *buffer, char **start, off_t offset, int length, int dummy) | |
1552 | -{ | |
1553 | - int size; | |
1554 | - int len=0; | |
1555 | - off_t pos=0; | |
1556 | - char* pbuffer; | |
1557 | - | |
1558 | - if(0==offset) | |
1559 | - { | |
1560 | - /* first time write the header */ | |
1561 | - size = sprintf(buffer,"%s","MAC address Device Flags Age (sec.)\n"); | |
1562 | - len=size; | |
1563 | - } | |
1564 | - | |
1565 | - pbuffer=&buffer[len]; | |
1566 | - sprintf_avl(&pbuffer,NULL,&pos,&len,offset,length); | |
1567 | - | |
1568 | - *start = buffer+len-(pos-offset); /* Start of wanted data */ | |
1569 | - len = pos-offset; /* Start slop */ | |
1570 | - if (len>length) | |
1571 | - len = length; /* Ending slop */ | |
1572 | - | |
1573 | - return len; | |
1574 | -} | |
1575 | -#ifdef CONFIG_PROC_FS | |
1576 | -struct proc_dir_entry proc_net_bridge= { | |
1577 | - PROC_NET_BRIDGE, 6, "bridge", | |
1578 | - S_IFREG | S_IRUGO, 1, 0, 0, | |
1579 | - 0, &proc_net_inode_operations, | |
1580 | - br_tree_get_info | |
1581 | -}; | |
1582 | + br_handle_frame_hook = br_handle_frame; | |
1583 | +#ifdef CONFIG_INET | |
1584 | + br_ioctl_hook = br_ioctl_deviceless_stub; | |
1585 | #endif | |
1586 | -__initfunc(void br_init(void)) | |
1587 | -{ /* (4.8.1) */ | |
1588 | - int port_no; | |
1589 | - | |
1590 | - printk(KERN_INFO "NET4: Ethernet Bridge 007 for NET4.0\n"); | |
1591 | - | |
1592 | - /* Set up brg device information */ | |
1593 | - bridge_info.instance = 0; | |
1594 | - brg_init(); | |
1595 | - | |
1596 | - max_port_used = 0; | |
1597 | - | |
1598 | - /* | |
1599 | - * Form initial topology change time. | |
1600 | - * The topology change timer is only used if this is the root bridge. | |
1601 | - */ | |
1602 | - | |
1603 | - bridge_info.topology_change_time = BRIDGE_MAX_AGE + BRIDGE_FORWARD_DELAY; /* (4.5.3.13) */ | |
1604 | - | |
1605 | - bridge_info.designated_root = bridge_info.bridge_id; /* (4.8.1.1) */ | |
1606 | - bridge_info.root_path_cost = Zero; | |
1607 | - bridge_info.root_port = No_port; | |
1608 | -#ifdef DEBUG_STP | |
1609 | - printk(KERN_INFO "br_init: becomes root\n"); | |
1610 | -#endif | |
1611 | - | |
1612 | - bridge_info.bridge_max_age = BRIDGE_MAX_AGE; | |
1613 | - bridge_info.bridge_hello_time = BRIDGE_HELLO_TIME; | |
1614 | - bridge_info.bridge_forward_delay = BRIDGE_FORWARD_DELAY; | |
1615 | - bridge_info.hold_time = HOLD_TIME; | |
1616 | - | |
1617 | - bridge_info.max_age = bridge_info.bridge_max_age; /* (4.8.1.2) */ | |
1618 | - bridge_info.hello_time = bridge_info.bridge_hello_time; | |
1619 | - bridge_info.forward_delay = bridge_info.bridge_forward_delay; | |
1620 | - | |
1621 | - bridge_info.top_change_detected = 0; | |
1622 | - bridge_info.top_change = 0; | |
1623 | - stop_tcn_timer(); | |
1624 | - stop_topology_change_timer(); | |
1625 | - memset(newfdb, 0, sizeof(newfdb)); | |
1626 | - for (port_no = One; port_no <= No_of_ports; port_no++) { /* (4.8.1.4) */ | |
1627 | - /* initial state = Disable */ | |
1628 | - user_port_state[port_no] = Disabled; | |
1629 | - port_priority[port_no] = 128; | |
1630 | - br_init_port(port_no); | |
1631 | - disable_port(port_no); | |
1632 | - } | |
1633 | -#if 0 /* JRP: We are not UP ! Wait for the start command */ | |
1634 | - port_state_selection(); /* (4.8.1.5) */ | |
1635 | - config_bpdu_generation(); /* (4.8.1.6) */ | |
1636 | - /* initialize system timer */ | |
1637 | - tl.expires = jiffies+HZ; /* 1 second */ | |
1638 | - tl.function = br_tick; | |
1639 | - add_timer(&tl); | |
1640 | -#endif | |
1641 | - | |
1642 | - register_netdevice_notifier(&br_dev_notifier); | |
1643 | - br_stats.flags = 0; /*BR_UP | BR_DEBUG*/; /* enable bridge */ | |
1644 | - br_stats.policy = BR_ACCEPT; /* Enable bridge to accpet all protocols */ | |
1645 | - br_stats.exempt_protocols = 0; | |
1646 | - /*start_hello_timer();*/ | |
1647 | - /* Vova Oksman: register the function for the PROCfs "bridge" file */ | |
1648 | -#ifdef CONFIG_PROC_FS | |
1649 | - proc_net_register(&proc_net_bridge); | |
1650 | -#endif | |
1651 | -} | |
1652 | - | |
1653 | -static inline unsigned short make_port_id(int port_no) | |
1654 | -{ | |
1655 | - return (port_priority[port_no] << 8) | port_no; | |
1656 | -} | |
1657 | - | |
1658 | -static void br_init_port(int port_no) | |
1659 | -{ | |
1660 | - port_info[port_no].port_id = make_port_id(port_no); | |
1661 | - become_designated_port(port_no); /* (4.8.1.4.1) */ | |
1662 | - set_port_state(port_no, Blocking); /* (4.8.1.4.2) */ | |
1663 | - port_info[port_no].top_change_ack = 0; | |
1664 | - port_info[port_no].config_pending = FALSE;/* (4.8.1.4.4) */ | |
1665 | - stop_message_age_timer(port_no); /* (4.8.1.4.5) */ | |
1666 | - stop_forward_delay_timer(port_no); /* (4.8.1.4.6) */ | |
1667 | - stop_hold_timer(port_no); /* (4.8.1.4.7) */ | |
1668 | -} | |
1669 | - | |
1670 | -static void enable_port(int port_no) /* (4.8.2) */ | |
1671 | -{ | |
1672 | - br_init_port(port_no); | |
1673 | - port_state_selection(); /* (4.8.2.7) */ | |
1674 | -} /* */ | |
1675 | - | |
1676 | -static void disable_port(int port_no) /* (4.8.3) */ | |
1677 | -{ | |
1678 | - int root; | |
1679 | - | |
1680 | - root = root_bridge(); | |
1681 | - become_designated_port(port_no); /* (4.8.3.1) */ | |
1682 | - set_port_state(port_no, Disabled); /* (4.8.3.2) */ | |
1683 | - port_info[port_no].top_change_ack = 0; | |
1684 | - port_info[port_no].config_pending = FALSE;/* (4.8.3.4) */ | |
1685 | - stop_message_age_timer(port_no); /* (4.8.3.5) */ | |
1686 | - stop_forward_delay_timer(port_no); /* (4.8.3.6) */ | |
1687 | - configuration_update(); | |
1688 | - port_state_selection(); /* (4.8.3.7) */ | |
1689 | - if ((root_bridge()) && (!root)) { /* (4.8.3.8) */ | |
1690 | - bridge_info.max_age = bridge_info.bridge_max_age; /* (4.8.3.8.1) */ | |
1691 | - bridge_info.hello_time = bridge_info.bridge_hello_time; | |
1692 | - bridge_info.forward_delay = bridge_info.bridge_forward_delay; | |
1693 | - topology_change_detection(); /* (4.8.3.8.2) */ | |
1694 | - stop_tcn_timer(); /* (4.8.3.8.3) */ | |
1695 | - config_bpdu_generation(); /* (4.8.3.8.4) */ | |
1696 | - start_hello_timer(); | |
1697 | - } | |
1698 | -} | |
1699 | - | |
1700 | - | |
1701 | -static void set_bridge_priority(bridge_id_t *new_bridge_id) | |
1702 | - /* (4.8.4) */ | |
1703 | -{ | |
1704 | - | |
1705 | - int root; | |
1706 | - int port_no; | |
1707 | - root = root_bridge(); | |
1708 | - for (port_no = One; port_no <= No_of_ports; port_no++) { /* (4.8.4.2) */ | |
1709 | - if(port_info[port_no].state == Disabled) | |
1710 | - continue; | |
1711 | - if (designated_port(port_no)) { | |
1712 | - port_info[port_no].designated_bridge = *new_bridge_id; | |
1713 | - } | |
1714 | - } | |
1715 | - | |
1716 | - bridge_info.bridge_id = *new_bridge_id; /* (4.8.4.3) */ | |
1717 | - configuration_update(); /* (4.8.4.4) */ | |
1718 | - port_state_selection(); /* (4.8.4.5) */ | |
1719 | - if ((root_bridge()) && (!root)) { /* (4.8.4.6) */ | |
1720 | - bridge_info.max_age = bridge_info.bridge_max_age; /* (4.8.4.6.1) */ | |
1721 | - bridge_info.hello_time = bridge_info.bridge_hello_time; | |
1722 | - bridge_info.forward_delay = bridge_info.bridge_forward_delay; | |
1723 | - topology_change_detection(); /* (4.8.4.6.2) */ | |
1724 | - stop_tcn_timer(); /* (4.8.4.6.3) */ | |
1725 | - config_bpdu_generation(), /* (4.8.4.6.4) */ | |
1726 | - start_hello_timer(); | |
1727 | - } | |
1728 | -} | |
1729 | - | |
1730 | -static void set_port_priority(int port_no) | |
1731 | - /* (4.8.5) */ | |
1732 | -{int new_port_id = make_port_id(port_no); | |
1733 | - | |
1734 | - if (designated_port(port_no)) { /* (4.8.5.2) */ | |
1735 | - port_info[port_no].designated_port = new_port_id; | |
1736 | - } | |
1737 | - port_info[port_no].port_id = new_port_id; /* (4.8.5.3) */ | |
1738 | - if ((br_cmp(bridge_info.bridge_id.BRIDGE_ID, | |
1739 | - port_info[port_no].designated_bridge.BRIDGE_ID) == 0 | |
1740 | - ) | |
1741 | - && | |
1742 | - (port_info[port_no].port_id | |
1743 | - < port_info[port_no].designated_port | |
1744 | - | |
1745 | - ) | |
1746 | - ) | |
1747 | - { | |
1748 | - become_designated_port(port_no); /* (4.8.5.4.1) */ | |
1749 | - port_state_selection(); /* (4.8.5.4.2) */ | |
1750 | - } | |
1751 | -} | |
1752 | - | |
1753 | -static void set_path_cost(int port_no, unsigned short path_cost) | |
1754 | - /* (4.8.6) */ | |
1755 | -{ | |
1756 | - port_info[port_no].path_cost = path_cost; /* (4.8.6.1) */ | |
1757 | - configuration_update(); /* (4.8.6.2) */ | |
1758 | - port_state_selection(); /* (4.8.6.3) */ | |
1759 | -} | |
1760 | - | |
1761 | -static void br_tick(unsigned long arg) | |
1762 | -{ | |
1763 | - int port_no; | |
1764 | - | |
1765 | - if(!(br_stats.flags & BR_UP)) | |
1766 | - return; /* JRP: we have been shot down */ | |
1767 | - | |
1768 | - if (hello_timer_expired()) | |
1769 | - hello_timer_expiry(); | |
1770 | - | |
1771 | - if (tcn_timer_expired()) | |
1772 | - tcn_timer_expiry(); | |
1773 | - | |
1774 | - if (topology_change_timer_expired()) | |
1775 | - topology_change_timer_expiry(); | |
1776 | - | |
1777 | - for (port_no = One; port_no <= No_of_ports; port_no++) | |
1778 | - { | |
1779 | - if(port_info[port_no].state == Disabled) | |
1780 | - continue; | |
1781 | - | |
1782 | - if (forward_delay_timer_expired(port_no)) | |
1783 | - forward_delay_timer_expiry(port_no); | |
1784 | - | |
1785 | - if (message_age_timer_expired(port_no)) | |
1786 | - message_age_timer_expiry(port_no); | |
1787 | - | |
1788 | - if (hold_timer_expired(port_no)) | |
1789 | - hold_timer_expiry(port_no); | |
1790 | - } | |
1791 | - /* call me again sometime... */ | |
1792 | - tl.expires = jiffies+HZ; /* 1 second */ | |
1793 | - tl.function = br_tick; | |
1794 | - add_timer(&tl); | |
1795 | -} | |
1796 | - | |
1797 | -static void start_hello_timer(void) | |
1798 | -{ | |
1799 | - hello_timer.value = 0; | |
1800 | - hello_timer.active = TRUE; | |
1801 | -} | |
1802 | - | |
1803 | -static void stop_hello_timer(void) | |
1804 | -{ | |
1805 | - hello_timer.active = FALSE; | |
1806 | -} | |
1807 | - | |
1808 | -static int hello_timer_expired(void) | |
1809 | -{ | |
1810 | - if (hello_timer.active && (++hello_timer.value >= bridge_info.hello_time)) | |
1811 | - { | |
1812 | - hello_timer.active = FALSE; | |
1813 | - return (TRUE); | |
1814 | - } | |
1815 | - return (FALSE); | |
1816 | -} | |
1817 | - | |
1818 | -static void start_tcn_timer(void) | |
1819 | -{ | |
1820 | - tcn_timer.value = 0; | |
1821 | - tcn_timer.active = TRUE; | |
1822 | -} | |
1823 | - | |
1824 | -static void stop_tcn_timer(void) | |
1825 | -{ | |
1826 | - tcn_timer.active = FALSE; | |
1827 | -} | |
1828 | - | |
1829 | -static int tcn_timer_expired(void) | |
1830 | -{ | |
1831 | - if (tcn_timer.active && (++tcn_timer.value >= bridge_info.bridge_hello_time)) | |
1832 | - { | |
1833 | - tcn_timer.active = FALSE; | |
1834 | - return (TRUE); | |
1835 | - } | |
1836 | - return (FALSE); | |
1837 | - | |
1838 | -} | |
1839 | - | |
1840 | -static void start_topology_change_timer(void) | |
1841 | -{ | |
1842 | - topology_change_timer.value = 0; | |
1843 | - topology_change_timer.active = TRUE; | |
1844 | -} | |
1845 | - | |
1846 | -static void stop_topology_change_timer(void) | |
1847 | -{ | |
1848 | - topology_change_timer.active = FALSE; | |
1849 | -} | |
1850 | - | |
1851 | -static int topology_change_timer_expired(void) | |
1852 | -{ | |
1853 | - if (topology_change_timer.active | |
1854 | - && (++topology_change_timer.value >= bridge_info.topology_change_time )) | |
1855 | - { | |
1856 | - topology_change_timer.active = FALSE; | |
1857 | - return (TRUE); | |
1858 | - } | |
1859 | - return (FALSE); | |
1860 | -} | |
1861 | - | |
1862 | -static void start_message_age_timer(int port_no, unsigned short message_age) | |
1863 | -{ | |
1864 | - message_age_timer[port_no].value = message_age; | |
1865 | - message_age_timer[port_no].active = TRUE; | |
1866 | -} | |
1867 | - | |
1868 | -static void stop_message_age_timer(int port_no) | |
1869 | -{ | |
1870 | - message_age_timer[port_no].active = FALSE; | |
1871 | -} | |
1872 | - | |
1873 | -static int message_age_timer_expired(int port_no) | |
1874 | -{ | |
1875 | - if (message_age_timer[port_no].active && (++message_age_timer[port_no].value >= bridge_info.max_age)) | |
1876 | - { | |
1877 | - message_age_timer[port_no].active = FALSE; | |
1878 | - return (TRUE); | |
1879 | - } | |
1880 | - return (FALSE); | |
1881 | -} | |
1882 | - | |
1883 | -static void start_forward_delay_timer(int port_no) | |
1884 | -{ | |
1885 | - forward_delay_timer[port_no].value = 0; | |
1886 | - forward_delay_timer[port_no].active = TRUE; | |
1887 | -} | |
1888 | - | |
1889 | -static void stop_forward_delay_timer(int port_no) | |
1890 | -{ | |
1891 | - forward_delay_timer[port_no].active = FALSE; | |
1892 | -} | |
1893 | - | |
1894 | -static int forward_delay_timer_expired(int port_no) | |
1895 | -{ | |
1896 | - if (forward_delay_timer[port_no].active && (++forward_delay_timer[port_no].value >= bridge_info.forward_delay)) | |
1897 | - { | |
1898 | - forward_delay_timer[port_no].active = FALSE; | |
1899 | - return (TRUE); | |
1900 | - } | |
1901 | - return (FALSE); | |
1902 | -} | |
1903 | + register_netdevice_notifier(&br_device_notifier); | |
1904 | ||
1905 | -static void start_hold_timer(int port_no) | |
1906 | -{ | |
1907 | - hold_timer[port_no].value = 0; | |
1908 | - hold_timer[port_no].active = TRUE; | |
1909 | -} | |
1910 | - | |
1911 | -static void stop_hold_timer(int port_no) | |
1912 | -{ | |
1913 | - hold_timer[port_no].active = FALSE; | |
1914 | -} | |
1915 | - | |
1916 | -static int hold_timer_expired(int port_no) | |
1917 | -{ | |
1918 | - if (hold_timer[port_no].active && | |
1919 | - (++hold_timer[port_no].value >= bridge_info.hold_time)) | |
1920 | - { | |
1921 | - hold_timer[port_no].active = FALSE; | |
1922 | - return (TRUE); | |
1923 | - } | |
1924 | - return (FALSE); | |
1925 | - | |
1926 | -} | |
1927 | - | |
1928 | -static struct sk_buff *alloc_bridge_skb(int port_no, int pdu_size, char *pdu_name) | |
1929 | -{ | |
1930 | - struct sk_buff *skb; | |
1931 | - struct device *dev = port_info[port_no].dev; | |
1932 | - struct ethhdr *eth; | |
1933 | - int size = dev->hard_header_len + BRIDGE_LLC1_HS + pdu_size; | |
1934 | - unsigned char *llc_buffer; | |
1935 | - int pad_size = 60 - size; | |
1936 | - | |
1937 | - size = 60; /* minimum Ethernet frame - CRC */ | |
1938 | - | |
1939 | - if (port_info[port_no].state == Disabled) | |
1940 | - { | |
1941 | - printk(KERN_DEBUG "send_%s_bpdu: port %i not valid\n", pdu_name, port_no); | |
1942 | - return NULL; | |
1943 | - } | |
1944 | - | |
1945 | - skb = alloc_skb(size, GFP_ATOMIC); | |
1946 | - if (skb == NULL) | |
1947 | - { | |
1948 | - printk(KERN_DEBUG "send_%s_bpdu: no skb available\n", pdu_name); | |
1949 | - return NULL; | |
1950 | - } | |
1951 | - skb->dev = dev; | |
1952 | - skb->mac.raw = skb->nh.raw = skb_put(skb,size); | |
1953 | - memset(skb->nh.raw + 60 - pad_size, 0xa5, pad_size); | |
1954 | - eth = skb->mac.ethernet; | |
1955 | - memcpy(eth->h_dest, bridge_ula, ETH_ALEN); | |
1956 | - memcpy(eth->h_source, dev->dev_addr, ETH_ALEN); | |
1957 | - | |
1958 | - if (br_stats.flags & BR_DEBUG) | |
1959 | - printk(KERN_DEBUG "send_%s_bpdu: port %i src %02x:%02x:%02x:%02x:%02x:%02x\n", | |
1960 | - pdu_name, | |
1961 | - port_no, | |
1962 | - eth->h_source[0], | |
1963 | - eth->h_source[1], | |
1964 | - eth->h_source[2], | |
1965 | - eth->h_source[3], | |
1966 | - eth->h_source[4], | |
1967 | - eth->h_source[5]); | |
1968 | -#if 0 | |
1969 | - /* 8038 is used in older DEC spanning tree protocol which uses a | |
1970 | - * different pdu layout as well | |
1971 | - */ | |
1972 | - eth->h_proto = htons(0x8038); | |
1973 | -#endif | |
1974 | - eth->h_proto = htons(pdu_size + BRIDGE_LLC1_HS); | |
1975 | - | |
1976 | - skb->nh.raw += skb->dev->hard_header_len; | |
1977 | - llc_buffer = skb->nh.raw; | |
1978 | - *llc_buffer++ = BRIDGE_LLC1_DSAP; | |
1979 | - *llc_buffer++ = BRIDGE_LLC1_SSAP; | |
1980 | - *llc_buffer++ = BRIDGE_LLC1_CTRL; | |
1981 | - /* set nh.raw to where the bpdu starts */ | |
1982 | - skb->nh.raw += BRIDGE_LLC1_HS; | |
1983 | - | |
1984 | - /* mark that we've been here... */ | |
1985 | - skb->pkt_bridged = IS_BRIDGED; | |
1986 | - return skb; | |
1987 | -} | |
1988 | - | |
1989 | -static int send_config_bpdu(int port_no, Config_bpdu *config_bpdu) | |
1990 | -{ | |
1991 | - struct sk_buff *skb; | |
1992 | - | |
1993 | - /* | |
1994 | - * Keep silent when disabled or when STP disabled | |
1995 | - */ | |
1996 | - | |
1997 | - if(!(br_stats.flags & BR_UP) || (br_stats.flags & BR_STP_DISABLED)) | |
1998 | - return -1; | |
1999 | - | |
2000 | - /* | |
2001 | - * Create and send the message | |
2002 | - */ | |
2003 | - | |
2004 | - skb = alloc_bridge_skb(port_no, BRIDGE_BPDU_8021_CONFIG_SIZE, | |
2005 | - "config"); | |
2006 | - if (skb == NULL) | |
2007 | - return(-1); | |
2008 | - | |
2009 | - /* copy fields before "flags" */ | |
2010 | - memcpy(skb->nh.raw, config_bpdu, BRIDGE_BPDU_8021_CONFIG_FLAG_OFFSET); | |
2011 | - | |
2012 | - /* build the "flags" field */ | |
2013 | - *(skb->nh.raw+BRIDGE_BPDU_8021_CONFIG_FLAG_OFFSET) = 0; | |
2014 | - if (config_bpdu->top_change_ack) | |
2015 | - *(skb->nh.raw+BRIDGE_BPDU_8021_CONFIG_FLAG_OFFSET) |= 0x80; | |
2016 | - if (config_bpdu->top_change) | |
2017 | - *(skb->nh.raw+BRIDGE_BPDU_8021_CONFIG_FLAG_OFFSET) |= 0x01; | |
2018 | - | |
2019 | - config_bpdu_hton(config_bpdu); | |
2020 | - /* copy the rest */ | |
2021 | - memcpy(skb->nh.raw+BRIDGE_BPDU_8021_CONFIG_FLAG_OFFSET+1, | |
2022 | - (char*)&(config_bpdu->root_id), | |
2023 | - BRIDGE_BPDU_8021_CONFIG_SIZE-1-BRIDGE_BPDU_8021_CONFIG_FLAG_OFFSET); | |
2024 | - | |
2025 | - dev_queue_xmit(skb); | |
2026 | - return(0); | |
2027 | -} | |
2028 | - | |
2029 | -static int send_tcn_bpdu(int port_no, Tcn_bpdu *bpdu) | |
2030 | -{ | |
2031 | - struct sk_buff *skb; | |
2032 | - | |
2033 | - /* | |
2034 | - * Keep silent when disabled or when STP disabled | |
2035 | - */ | |
2036 | - | |
2037 | - if(!(br_stats.flags & BR_UP) || (br_stats.flags & BR_STP_DISABLED)) | |
2038 | - return -1; | |
2039 | - | |
2040 | - | |
2041 | - skb = alloc_bridge_skb(port_no, sizeof(Tcn_bpdu), "tcn"); | |
2042 | - if (skb == NULL) | |
2043 | - return(-1); | |
2044 | - | |
2045 | - memcpy(skb->nh.raw, bpdu, sizeof(Tcn_bpdu)); | |
2046 | - | |
2047 | - dev_queue_xmit(skb); | |
2048 | - return(0); | |
2049 | -} | |
2050 | - | |
2051 | -static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr) | |
2052 | -{ | |
2053 | - struct device *dev = ptr; | |
2054 | - int i; | |
2055 | - | |
2056 | - /* check for loopback devices */ | |
2057 | - if (dev->flags & IFF_LOOPBACK) | |
2058 | - return(NOTIFY_DONE); | |
2059 | - | |
2060 | - if (dev == &brg_if.dev) | |
2061 | - return(NOTIFY_DONE); /* Don't attach the brg device to a port! */ | |
2062 | - | |
2063 | - switch (event) | |
2064 | - { | |
2065 | - case NETDEV_DOWN: | |
2066 | - if (br_stats.flags & BR_DEBUG) | |
2067 | - printk(KERN_DEBUG "br_device_event: NETDEV_DOWN...\n"); | |
2068 | - /* find our device and mark it down */ | |
2069 | - for (i = One; i <= No_of_ports; i++) | |
2070 | - { | |
2071 | - if (port_info[i].dev == dev) | |
2072 | - { | |
2073 | - disable_port(i); | |
2074 | - return NOTIFY_DONE; | |
2075 | - break; | |
2076 | - } | |
2077 | - } | |
2078 | - break; | |
2079 | - case NETDEV_UP: | |
2080 | - if (br_stats.flags & BR_DEBUG) | |
2081 | - printk(KERN_DEBUG "br_device_event: NETDEV_UP...\n"); | |
2082 | - /* Only handle ethernet ports */ | |
2083 | - if(dev->type!=ARPHRD_ETHER && dev->type!=ARPHRD_LOOPBACK) | |
2084 | - return NOTIFY_DONE; | |
2085 | - /* look up an unused device and enable it */ | |
2086 | - for (i = One; i <= No_of_ports; i++) | |
2087 | - { | |
2088 | - if (port_info[i].dev == NULL || port_info[i].dev == dev) | |
2089 | - { | |
2090 | - port_info[i].dev = dev; | |
2091 | - port_info[i].port_id = i; | |
2092 | - dev->bridge_port_id = i; | |
2093 | - if( i > max_port_used ) | |
2094 | - max_port_used = i; | |
2095 | - /* set bridge addr from 1st device addr */ | |
2096 | - if (((htonl(bridge_info.bridge_id.BRIDGE_ID[0])&0xffff) == 0) && | |
2097 | - (bridge_info.bridge_id.BRIDGE_ID[1] == 0)) | |
2098 | - { | |
2099 | - memcpy(bridge_info.bridge_id.BRIDGE_ID_ULA, dev->dev_addr, 6); | |
2100 | - if(bridge_info.bridge_id.BRIDGE_PRIORITY == 0) | |
2101 | - bridge_info.bridge_id.BRIDGE_PRIORITY = htons(32768); | |
2102 | - set_bridge_priority(&bridge_info.bridge_id); | |
2103 | - } | |
2104 | - /* Add local MAC address */ | |
2105 | - br_add_local_mac(dev->dev_addr); | |
2106 | - /* Save MAC address for latter change address events */ | |
2107 | - memcpy(port_info[i].ifmac.BRIDGE_ID_ULA, dev->dev_addr, 6); | |
2108 | - if((br_stats.flags & BR_UP) && | |
2109 | - (user_port_state[i] != Disabled)) | |
2110 | - { | |
2111 | - /* don't start if user said so */ | |
2112 | - enable_port(i); | |
2113 | - set_path_cost(i, br_port_cost(dev)); | |
2114 | - set_port_priority(i); | |
2115 | - if (br_stats.flags & BR_STP_DISABLED) | |
2116 | - port_info[i].state = Forwarding; | |
2117 | - else | |
2118 | - make_forwarding(i); | |
2119 | - } | |
2120 | - return NOTIFY_DONE; | |
2121 | - break; | |
2122 | - } | |
2123 | - } | |
2124 | - break; | |
2125 | - case NETDEV_REGISTER: | |
2126 | - if (br_stats.flags & BR_DEBUG) | |
2127 | - printk(KERN_DEBUG "br_device_event: NETDEV_REGISTER...\n"); | |
2128 | - /* printk(KERN_ERR "br_device_event: NETDEV_REGISTER...\n"); */ | |
2129 | - /* printk(KERN_ERR "br_device_event: dev->type: 0x%X\n", dev->type); */ | |
2130 | - /* Only handle ethernet ports */ | |
2131 | - if(dev->type!=ARPHRD_ETHER && dev->type!=ARPHRD_LOOPBACK) | |
2132 | - return NOTIFY_DONE; | |
2133 | - /* printk(KERN_ERR "br_device_event: Looking for port...\n"); */ | |
2134 | - for (i = One; i <= No_of_ports; i++) | |
2135 | - { | |
2136 | - if (port_info[i].dev == NULL || port_info[i].dev == dev) | |
2137 | - { | |
2138 | - /* printk(KERN_ERR "br_device_event: Found port %d\n", i); */ | |
2139 | - port_info[i].dev = dev; | |
2140 | - port_info[i].port_id = i; | |
2141 | - dev->bridge_port_id = i; | |
2142 | - if( i > max_port_used ) | |
2143 | - max_port_used = i; | |
2144 | - /* handle local MAC address minuplations */ | |
2145 | - br_add_local_mac(dev->dev_addr); | |
2146 | - memcpy(port_info[i].ifmac.BRIDGE_ID_ULA, dev->dev_addr, 6); | |
2147 | - return NOTIFY_DONE; | |
2148 | - break; | |
2149 | - } | |
2150 | - } | |
2151 | - break; | |
2152 | - case NETDEV_UNREGISTER: | |
2153 | - if (br_stats.flags & BR_DEBUG) | |
2154 | - printk(KERN_DEBUG "br_device_event: NETDEV_UNREGISTER...\n"); | |
2155 | - i = find_port(dev); | |
2156 | - if (i > 0) { | |
2157 | - br_avl_delete_by_port(i); | |
2158 | - memset(port_info[i].ifmac.BRIDGE_ID_ULA, 0, 6); | |
2159 | - port_info[i].dev = NULL; | |
2160 | - } | |
2161 | - break; | |
2162 | - case NETDEV_CHANGEADDR: | |
2163 | - if (br_stats.flags & BR_DEBUG) | |
2164 | - printk(KERN_DEBUG "br_device_event: NETDEV_CHANGEADDR...\n"); | |
2165 | - i = find_port(dev); | |
2166 | - if (i <= 0) | |
2167 | - break; | |
2168 | - if (memcmp(port_info[i].ifmac.BRIDGE_ID_ULA, dev->dev_addr, 6) != 0) | |
2169 | - break; /* Don't worry about a change of hardware broadcast address! */ | |
2170 | - if (dev->start) { | |
2171 | - printk(KERN_CRIT "br_device_event: NETDEV_CHANGEADDR on busy device %s - FIX DRIVER!\n", | |
2172 | - dev->name); | |
2173 | - /* return NOTIFY_BAD; It SHOULD be this, but I want to be friendly... */ | |
2174 | - return NOTIFY_DONE; | |
2175 | - } | |
2176 | - br_avl_delete_by_port(i); | |
2177 | - memset(port_info[i].ifmac.BRIDGE_ID_ULA, 0, 6); | |
2178 | - break; | |
2179 | - } | |
2180 | - return NOTIFY_DONE; | |
2181 | -} | |
2182 | - | |
2183 | -/* Routine to loop over device list and register | |
2184 | - * interfaces to bridge. Called from last part of net_dev_init just before | |
2185 | - * bootp/rarp interface setup | |
2186 | - */ | |
2187 | -void br_spacedevice_register(void) | |
2188 | -{ | |
2189 | - struct device *dev; | |
2190 | - for( dev = dev_base; dev != NULL; dev = dev->next) | |
2191 | - { | |
2192 | - br_device_event(NULL, NETDEV_REGISTER, dev); | |
2193 | - } | |
2194 | -} | |
2195 | - | |
2196 | - | |
2197 | -/* This is for SPEED in the kernel in net_bh.c */ | |
2198 | - | |
2199 | -int br_call_bridge(struct sk_buff *skb, unsigned short type) | |
2200 | -{ | |
2201 | - int port; | |
2202 | - struct device *dev; | |
2203 | - | |
2204 | -#if 0 /* Checked first in handle_bridge to save expense of function call */ | |
2205 | - if(!(br_stats.flags & BR_UP)) | |
2206 | - return 0; | |
2207 | -#endif | |
2208 | - | |
2209 | - dev = skb->dev; | |
2210 | - | |
2211 | - /* Check for brg0 device | |
2212 | - */ | |
2213 | - if (dev == &brg_if.dev) | |
2214 | - return 0; | |
2215 | - | |
2216 | - port = dev->bridge_port_id; | |
2217 | - | |
2218 | - if(!port) | |
2219 | - return 0; | |
2220 | - | |
2221 | - /* Sanity - make sure we are not leaping off into fairy space! */ | |
2222 | - if ( port < 0 || port > max_port_used || port_info[port].dev != dev) { | |
2223 | - if (net_ratelimit()) | |
2224 | - printk(KERN_CRIT "br_call_bridge: device %s has invalid port ID %d!\n", | |
2225 | - dev->name, | |
2226 | - dev->bridge_port_id); | |
2227 | - return 0; | |
2228 | - } | |
2229 | - | |
2230 | - if(user_port_state[port] == Disabled) | |
2231 | - return 0; | |
2232 | - | |
2233 | - if (!br_protocol_ok(ntohs(type))) | |
2234 | - return 0; | |
2235 | - | |
2236 | - return 1; | |
2237 | - | |
2238 | -} | |
2239 | - | |
2240 | - | |
2241 | -/* | |
2242 | - * following routine is called when a frame is received | |
2243 | - * from an interface, it returns 1 when it consumes the | |
2244 | - * frame, 0 when it does not | |
2245 | - */ | |
2246 | - | |
2247 | -int br_receive_frame(struct sk_buff *skb) /* 3.5 */ | |
2248 | -{ | |
2249 | - int port, ret; | |
2250 | - Port_data *p; | |
2251 | - struct ethhdr *eth; | |
2252 | - struct device *dev; | |
2253 | - | |
2254 | - /* sanity */ | |
2255 | - if (!skb) { | |
2256 | - printk(KERN_CRIT "br_receive_frame: no skb!\n"); | |
2257 | - return(1); | |
2258 | - } | |
2259 | - | |
2260 | - dev = skb->dev; | |
2261 | - | |
2262 | - /* Check for brg0 device | |
2263 | - */ | |
2264 | - if (dev == &brg_if.dev) | |
2265 | - return 0; | |
2266 | - | |
2267 | - skb->pkt_bridged = IS_BRIDGED; | |
2268 | - | |
2269 | - /* check for loopback */ | |
2270 | - if (dev->flags & IFF_LOOPBACK) | |
2271 | - return 0 ; | |
2272 | - | |
2273 | -#if 0 | |
2274 | - port = find_port(dev); | |
2275 | -#else | |
2276 | - port = dev->bridge_port_id; | |
2277 | -#endif | |
2278 | - | |
2279 | - if(!port) | |
2280 | - return 0; | |
2281 | - | |
2282 | - /* Hand off to brg_rx BEFORE we screw up the skb */ | |
2283 | - if(brg_rx(skb, port)) | |
2284 | - return(1); | |
2285 | - | |
2286 | - skb->nh.raw = skb->mac.raw; | |
2287 | - eth = skb->mac.ethernet; | |
2288 | - p = &port_info[port]; | |
2289 | - | |
2290 | - if(p->state == Disabled) | |
2291 | - { | |
2292 | - /* We are here if BR_UP even if this port is Disabled. | |
2293 | - * Send everything up | |
2294 | - */ | |
2295 | - skb->pkt_type = PACKET_HOST; | |
2296 | - ++br_stats_cnt.port_disable_up_stack; | |
2297 | - return(0); /* pass frame up our stack (this will */ | |
2298 | - /* happen in net_bh() in dev.c) */ | |
2299 | - } | |
2300 | - | |
2301 | - /* Here only if not disable. | |
2302 | - * Remark: only frames going up will show up in NIT (tcpdump) | |
2303 | - */ | |
2304 | - | |
2305 | - /* JRP: even if port is Blocking we need to process the Spanning Tree | |
2306 | - * frames to keep the port in that state | |
2307 | - */ | |
2308 | - if (memcmp(eth->h_dest, bridge_ula, ETH_ALEN) == 0) | |
2309 | - { | |
2310 | - ++br_stats_cnt.rcv_bpdu; | |
2311 | - br_bpdu(skb, port); /* br_bpdu consumes skb */ | |
2312 | - return(1); | |
2313 | - } | |
2314 | - switch (p->state) | |
2315 | - { | |
2316 | - case Learning: | |
2317 | - if((ret = br_learn(skb, port))) | |
2318 | - { /* 3.8 */ | |
2319 | - if (ret > 0) ++br_stats_cnt.drop_multicast; | |
2320 | - return br_drop(skb); | |
2321 | - } | |
2322 | - /* fall through */ | |
2323 | - case Listening: | |
2324 | - /* fall through */ | |
2325 | - case Blocking: | |
2326 | - ++br_stats_cnt.notForwarding; | |
2327 | - return(br_drop(skb)); | |
2328 | - /* | |
2329 | - case Disabled: is now handled before this switch ! | |
2330 | - Keep the break to allow GCC to use a jmp table. | |
2331 | - */ | |
2332 | - break; | |
2333 | - case Forwarding: | |
2334 | - if((ret = br_learn(skb, port))) { /* 3.8 */ | |
2335 | - if (ret > 0) ++br_stats_cnt.drop_multicast; | |
2336 | - return br_drop(skb); | |
2337 | - } | |
2338 | - /* Now this frame came from one of bridged | |
2339 | - ports this means we should attempt to forward it. | |
2340 | - JRP: local addresses are now in the AVL tree, | |
2341 | - br_forward will pass frames up if it matches | |
2342 | - one of our local MACs or if it is a multicast | |
2343 | - group address. | |
2344 | - br_forward() will not consume the frame if this | |
2345 | - is the case */ | |
2346 | - return(br_forward(skb, port)); | |
2347 | - default: | |
2348 | - printk(KERN_DEBUG "br_receive_frame: port [%i] unknown state [%i]\n", | |
2349 | - port, p->state); | |
2350 | - ++br_stats_cnt.unknown_state; | |
2351 | - return(br_drop(skb)); /* discard frame */ | |
2352 | - } | |
2353 | -} | |
2354 | - | |
2355 | -/* | |
2356 | - * the following routine is called to transmit frames from the host | |
2357 | - * stack. it returns 1 when it consumes the frame and | |
2358 | - * 0 when it does not. | |
2359 | - */ | |
2360 | - | |
2361 | -int br_tx_frame(struct sk_buff *skb) /* 3.5 */ | |
2362 | -{ | |
2363 | - int port; | |
2364 | - struct ethhdr *eth; | |
2365 | - | |
2366 | - /* sanity */ | |
2367 | - if (!skb) | |
2368 | - { | |
2369 | - printk(KERN_CRIT "br_tx_frame: no skb!\n"); | |
2370 | - return(0); | |
2371 | - } | |
2372 | - | |
2373 | - if (!skb->dev) | |
2374 | - { | |
2375 | - printk(KERN_CRIT "br_tx_frame: no dev!\n"); | |
2376 | - return(0); | |
2377 | - } | |
2378 | - | |
2379 | - /* check for loopback */ | |
2380 | - if (skb->dev->flags & IFF_LOOPBACK) | |
2381 | - return(0); | |
2382 | - | |
2383 | - /* if bridging is not enabled on the port we are going to send | |
2384 | - to, we have nothing to do with this frame, hands off */ | |
2385 | - if (((port=find_port(skb->dev))==0)||(port_info[port].state==Disabled)) { | |
2386 | - ++br_stats_cnt.port_disable; | |
2387 | - return(0); | |
2388 | - } | |
2389 | - ++br_stats_cnt.port_not_disable; | |
2390 | - skb->mac.raw = skb->nh.raw = skb->data; | |
2391 | - eth = skb->mac.ethernet; | |
2392 | - port = 0; /* an impossible port (locally generated) */ | |
2393 | - if (br_stats.flags & BR_DEBUG) | |
2394 | - printk(KERN_DEBUG "br_tx_fr : port %i src %02x:%02x:%02x:%02x:%02x:%02x" | |
2395 | - " dest %02x:%02x:%02x:%02x:%02x:%02x\n", | |
2396 | - port, | |
2397 | - eth->h_source[0], | |
2398 | - eth->h_source[1], | |
2399 | - eth->h_source[2], | |
2400 | - eth->h_source[3], | |
2401 | - eth->h_source[4], | |
2402 | - eth->h_source[5], | |
2403 | - eth->h_dest[0], | |
2404 | - eth->h_dest[1], | |
2405 | - eth->h_dest[2], | |
2406 | - eth->h_dest[3], | |
2407 | - eth->h_dest[4], | |
2408 | - eth->h_dest[5]); | |
2409 | - return(br_forward(skb, port)); | |
2410 | -} | |
2411 | - | |
2412 | -static void br_add_local_mac(unsigned char *mac) | |
2413 | -{ | |
2414 | - struct fdb *f; | |
2415 | - f = (struct fdb *)kmalloc(sizeof(struct fdb), GFP_ATOMIC); | |
2416 | - if (!f) | |
2417 | - { | |
2418 | - printk(KERN_CRIT "br_add_local_mac: unable to malloc fdb\n"); | |
2419 | - return; | |
2420 | - } | |
2421 | - f->port = 0; /* dest port == 0 =>local */ | |
2422 | - memcpy(f->ula, mac, 6); | |
2423 | - f->timer = 0; /* will not aged anyway */ | |
2424 | - f->flags = 0; /* not valid => br_forward special route */ | |
2425 | - /* | |
2426 | - * add entity to AVL tree. If entity already | |
2427 | - * exists in the tree, update the fields with | |
2428 | - * what we have here. | |
2429 | - */ | |
2430 | - if (br_avl_insert(f) != NULL) | |
2431 | - { | |
2432 | - /* Already in */ | |
2433 | - kfree(f); | |
2434 | - } | |
2435 | -} | |
2436 | - | |
2437 | -/* Avoid broadcast loop by limiting the number of broacast frames per | |
2438 | - * period. The idea is to limit this per source | |
2439 | - * returns: 0 if limit is not reached | |
2440 | - * 1 if frame should be dropped | |
2441 | - */ | |
2442 | - | |
2443 | -static inline int mcast_quench(struct fdb *f) | |
2444 | -{ | |
2445 | - if(f->mcast_count++ == 0) /* first time */ | |
2446 | - f->mcast_timer = jiffies; | |
2447 | - else { | |
2448 | - if(f->mcast_count > max_mcast_per_period) { | |
2449 | - if(time_after(jiffies, f->mcast_timer + mcast_hold_time)) | |
2450 | - f->mcast_count = 0; | |
2451 | - else return 1; | |
2452 | - } | |
2453 | - } | |
2454 | - return 0; | |
2455 | -} | |
2456 | - | |
2457 | -/* | |
2458 | - * this routine returns 0 when it learns (or updates) from the | |
2459 | - * frame, and 1 if we must dropped the frame due to multicast | |
2460 | - * limitations, or -1 because of not enough memory. | |
2461 | - * | |
2462 | - * NB Can be called when skb->nh.raw is NOT set up when | |
2463 | - * receiving frames on brg0 via brg_rx | |
2464 | - */ | |
2465 | - | |
2466 | -static int br_learn(struct sk_buff *skb, int port) /* 3.8 */ | |
2467 | -{ | |
2468 | - struct fdb *f, *oldfdb; | |
2469 | - Port_data *p = &port_info[port]; | |
2470 | - struct ethhdr *eth = skb->mac.ethernet; | |
2471 | - | |
2472 | - /* JRP: no reason to check port state again. We are called by | |
2473 | - * br_receive_frame() only when in Learning or Forwarding | |
2474 | - * Remark: code not realigned yet to keep diffs smaller | |
2475 | - */ | |
2476 | - | |
2477 | - /* don't keep group addresses in the tree */ | |
2478 | - if (eth->h_source[0] & 0x01) | |
2479 | - return 0; | |
2480 | - | |
2481 | - if((f= newfdb[port]) == NULL) | |
2482 | - { | |
2483 | - newfdb[port] = f = (struct fdb *)kmalloc(sizeof(struct fdb), GFP_ATOMIC); | |
2484 | - if (!f) | |
2485 | - { | |
2486 | - printk(KERN_WARNING "br_learn: unable to malloc fdb\n"); | |
2487 | - return(-1); /* this drops the frame */ | |
2488 | - } | |
2489 | - } | |
2490 | - f->port = port; /* source port */ | |
2491 | - memcpy(f->ula, eth->h_source, 6); | |
2492 | - f->timer = CURRENT_TIME; | |
2493 | - f->flags = FDB_ENT_VALID; | |
2494 | - /* | |
2495 | - * add entity to AVL tree. If entity already | |
2496 | - * exists in the tree, update the fields with | |
2497 | - * what we have here. | |
2498 | - */ | |
2499 | - if ((oldfdb = br_avl_insert(f))) | |
2500 | - { | |
2501 | - /* update if !NULL */ | |
2502 | - if((eth->h_dest[0] & 0x01) && /* multicast */ mcast_quench(oldfdb)) | |
2503 | - return 1; | |
2504 | - return 0; | |
2505 | - } | |
2506 | - newfdb[port] = NULL; /* force kmalloc next time */ | |
2507 | - f->mcast_count = 0; | |
2508 | - /* add to head of port chain */ | |
2509 | - f->fdb_next = p->fdb; | |
2510 | - p->fdb = f; | |
2511 | - allocated_fdb_cnt++; | |
2512 | return 0; | |
2513 | } | |
2514 | ||
2515 | -/* JRP: always called under br_receive_frame(). No need for Q protection. */ | |
2516 | - | |
2517 | -void requeue_fdb(struct fdb *node, int new_port) | |
2518 | -{ | |
2519 | - Port_data *p = &port_info[node->port]; | |
2520 | - | |
2521 | - /* dequeue */ | |
2522 | - if(p->fdb == node) | |
2523 | - p->fdb = node->fdb_next; | |
2524 | - else | |
2525 | - { | |
2526 | - struct fdb *prev; | |
2527 | - | |
2528 | - for(prev = p->fdb; prev; prev = prev->fdb_next) | |
2529 | - if (prev->fdb_next == node) | |
2530 | - break; | |
2531 | - | |
2532 | - if(prev != NULL) | |
2533 | - prev->fdb_next = node->fdb_next; | |
2534 | - else | |
2535 | - { | |
2536 | - /* Forget about this update. */ | |
2537 | - printk(KERN_ERR "br:requeue_fdb\n"); | |
2538 | - return; | |
2539 | - } | |
2540 | - } | |
2541 | - /* enqueue */ | |
2542 | - node->port = new_port; | |
2543 | - node->fdb_next = port_info[new_port].fdb; | |
2544 | - port_info[new_port].fdb = node; | |
2545 | -} | |
2546 | - | |
2547 | -/* | |
2548 | - * this routine always consumes the frame | |
2549 | - */ | |
2550 | - | |
2551 | -static int br_drop(struct sk_buff *skb) | |
2552 | -{ | |
2553 | - kfree_skb(skb); | |
2554 | - return(1); | |
2555 | -} | |
2556 | - | |
2557 | -/* | |
2558 | - * this routine always consumes the frame | |
2559 | - */ | |
2560 | - | |
2561 | -static int br_dev_drop(struct sk_buff *skb) | |
2562 | -{ | |
2563 | - dev_kfree_skb(skb); | |
2564 | - return(1); | |
2565 | -} | |
2566 | - | |
2567 | -/* | |
2568 | - * Forward the frame SKB to proper port[s]. PORT is the port that the | |
2569 | - * frame has come from; we will not send the frame back there. PORT == 0 | |
2570 | - * means we have been called from br_tx_fr(), not from br_receive_frame(). | |
2571 | - * | |
2572 | - * this routine returns 1 if it consumes the frame, 0 | |
2573 | - * if not... | |
2574 | - */ | |
2575 | - | |
2576 | -static int br_forward(struct sk_buff *skb, int port) /* 3.7 */ | |
2577 | -{ | |
2578 | - struct fdb *f; | |
2579 | - | |
2580 | - /* | |
2581 | - * flood all ports with frames destined for a group | |
2582 | - * address. If frame came from above, drop it, | |
2583 | - * otherwise it will be handled in br_receive_frame() | |
2584 | - * Multicast frames will also need to be seen | |
2585 | - * by our upper layers. | |
2586 | - */ | |
2587 | - if (skb->mac.ethernet->h_dest[0] & 0x01) | |
2588 | - { | |
2589 | - /* group address */ | |
2590 | - br_flood(skb, port); | |
2591 | - /* | |
2592 | - * External groups are fed out via the normal source | |
2593 | - * This probably should be dropped since the flood will | |
2594 | - * have sent it anyway. | |
2595 | - */ | |
2596 | - if (port == 0) | |
2597 | - { | |
2598 | - /* Locally generated */ | |
2599 | - ++br_stats_cnt.local_multicast; | |
2600 | - return(br_dev_drop(skb)); | |
2601 | - } | |
2602 | - ++br_stats_cnt.forwarded_multicast; | |
2603 | - return(0); | |
2604 | - } | |
2605 | - else | |
2606 | - { | |
2607 | - /* unicast frame, locate port to forward to */ | |
2608 | - f = br_avl_find_addr(skb->mac.ethernet->h_dest); | |
2609 | - /* | |
2610 | - * Send flood and drop. | |
2611 | - */ | |
2612 | - if (!f || !(f->flags & FDB_ENT_VALID)) | |
2613 | - { | |
2614 | - if(f && (f->port == 0)) | |
2615 | - { | |
2616 | - skb->pkt_type = PACKET_HOST; | |
2617 | - ++br_stats_cnt.forwarded_unicast_up_stack; | |
2618 | - return(0); | |
2619 | - } | |
2620 | - /* not found or too old; flood all ports */ | |
2621 | - ++br_stats_cnt.flood_unicast; | |
2622 | - br_flood(skb, port); | |
2623 | - return(br_dev_drop(skb)); | |
2624 | - } | |
2625 | - /* | |
2626 | - * Sending | |
2627 | - */ | |
2628 | - if (f->port!=port && port_info[f->port].state == Forwarding) | |
2629 | - { | |
2630 | - /* Has entry expired? */ | |
2631 | - if (f->timer + fdb_aging_time < CURRENT_TIME) | |
2632 | - { | |
2633 | - /* timer expired, invalidate entry */ | |
2634 | - f->flags &= ~FDB_ENT_VALID; | |
2635 | - if (br_stats.flags & BR_DEBUG) | |
2636 | - printk(KERN_DEBUG "fdb entry expired...\n"); | |
2637 | - /* | |
2638 | - * Send flood and drop original | |
2639 | - */ | |
2640 | - ++br_stats_cnt.aged_flood_unicast; | |
2641 | - br_flood(skb, port); | |
2642 | - return(br_dev_drop(skb)); | |
2643 | - } | |
2644 | - ++br_stats_cnt.forwarded_unicast; | |
2645 | - /* mark that's we've been here... */ | |
2646 | - skb->pkt_bridged = IS_BRIDGED; | |
2647 | - | |
2648 | - /* reset the skb->ip pointer */ | |
2649 | - skb->nh.raw = skb->data + ETH_HLEN; | |
2650 | - | |
2651 | - /* | |
2652 | - * Send the buffer out. | |
2653 | - */ | |
2654 | - | |
2655 | - skb->dev=port_info[f->port].dev; | |
2656 | - | |
2657 | - /* | |
2658 | - * We send this still locked | |
2659 | - */ | |
2660 | - skb->priority = 1; | |
2661 | - dev_queue_xmit(skb); | |
2662 | - return(1); /* skb has been consumed */ | |
2663 | - } | |
2664 | - else | |
2665 | - { | |
2666 | - /* JRP: Needs to aged entry as well, if topology changes | |
2667 | - * the entry would not age. Got this while swapping | |
2668 | - * two cables ! | |
2669 | - * | |
2670 | - * Has entry expired? | |
2671 | - */ | |
2672 | - | |
2673 | - if (f->timer + fdb_aging_time < CURRENT_TIME) | |
2674 | - { | |
2675 | - /* timer expired, invalidate entry */ | |
2676 | - f->flags &= ~FDB_ENT_VALID; | |
2677 | - if (br_stats.flags & BR_DEBUG) | |
2678 | - printk(KERN_DEBUG "fdb entry expired...\n"); | |
2679 | - ++br_stats_cnt.drop_same_port_aged; | |
2680 | - } | |
2681 | - else ++br_stats_cnt.drop_same_port; | |
2682 | - /* | |
2683 | - * Arrived on the right port, we discard | |
2684 | - */ | |
2685 | - return(br_dev_drop(skb)); | |
2686 | - } | |
2687 | - } | |
2688 | -} | |
2689 | - | |
2690 | -/* | |
2691 | - * this routine sends a copy of the frame to all forwarding ports | |
2692 | - * with the exception of the port given. This routine never | |
2693 | - * consumes the original frame. | |
2694 | - */ | |
2695 | - | |
2696 | -static int br_flood(struct sk_buff *skb, int port) | |
2697 | -{ | |
2698 | - int i; | |
2699 | - struct sk_buff *nskb; | |
2700 | - | |
2701 | - for (i = One; i <= No_of_ports; i++) | |
2702 | - { | |
2703 | - if (i == port) /* don't send back where we got it */ | |
2704 | - continue; | |
2705 | - if (i > max_port_used) | |
2706 | - /* Don't go scanning empty port entries */ | |
2707 | - break; | |
2708 | - if (port_info[i].state == Forwarding) | |
2709 | - { | |
2710 | - nskb = skb_clone(skb, GFP_ATOMIC); | |
2711 | - if(nskb==NULL) | |
2712 | - continue; | |
2713 | - /* mark that's we've been here... */ | |
2714 | - nskb->pkt_bridged = IS_BRIDGED; | |
2715 | - /* Send to each port in turn */ | |
2716 | - nskb->dev= port_info[i].dev; | |
2717 | - /* To get here we must have done ARP already, | |
2718 | - or have a received valid MAC header */ | |
2719 | - | |
2720 | -/* printk(KERN_DEBUG "Flood to port %d\n",i);*/ | |
2721 | - nskb->nh.raw = nskb->data + ETH_HLEN; | |
2722 | - nskb->priority = 1; | |
2723 | - dev_queue_xmit(nskb); | |
2724 | - } | |
2725 | - } | |
2726 | - return(0); | |
2727 | -} | |
2728 | - | |
2729 | -/* | |
2730 | - * FIXME: This needs to come from the device structs, eg for | |
2731 | - * 10,100,1Gbit ethernet. | |
2732 | - */ | |
2733 | - | |
2734 | -static int br_port_cost(struct device *dev) /* 4.10.2 */ | |
2735 | -{ | |
2736 | - if (strncmp(dev->name, "lec", 3) == 0) /* ATM Lan Emulation (LANE) */ | |
2737 | - return(7); /* 155 Mbs */ | |
2738 | - if (strncmp(dev->name, "eth", 3) == 0) /* ethernet */ | |
2739 | - return(100); | |
2740 | - if (strncmp(dev->name, "plip",4) == 0) /* plip */ | |
2741 | - return (1600); | |
2742 | - return(100); /* default */ | |
2743 | -} | |
2744 | - | |
2745 | -/* | |
2746 | - * this routine always consumes the skb | |
2747 | - */ | |
2748 | - | |
2749 | -static void br_bpdu(struct sk_buff *skb, int port) /* consumes skb */ | |
2750 | -{ | |
2751 | - char *bufp = skb->data + ETH_HLEN; | |
2752 | - Tcn_bpdu *bpdu = (Tcn_bpdu *) (bufp + BRIDGE_LLC1_HS); | |
2753 | - Config_bpdu rcv_bpdu; | |
2754 | - | |
2755 | - if(!(br_stats.flags & BR_STP_DISABLED) && | |
2756 | - (*bufp++ == BRIDGE_LLC1_DSAP) && (*bufp++ == BRIDGE_LLC1_SSAP) && | |
2757 | - (*bufp++ == BRIDGE_LLC1_CTRL) && | |
2758 | - (bpdu->protocol_id == BRIDGE_BPDU_8021_PROTOCOL_ID) && | |
2759 | - (bpdu->protocol_version_id == BRIDGE_BPDU_8021_PROTOCOL_VERSION_ID)) | |
2760 | - { | |
2761 | - | |
2762 | - switch (bpdu->type) | |
2763 | - { | |
2764 | - case BPDU_TYPE_CONFIG: | |
2765 | - /* realign for portability to RISC */ | |
2766 | - memcpy((char*)&rcv_bpdu, bufp, | |
2767 | - BRIDGE_BPDU_8021_CONFIG_FLAG_OFFSET); | |
2768 | - bufp+= BRIDGE_BPDU_8021_CONFIG_FLAG_OFFSET; | |
2769 | - rcv_bpdu.top_change_ack = | |
2770 | - (*bufp & TOPOLOGY_CHANGE_ACK) != 0; | |
2771 | - rcv_bpdu.top_change = | |
2772 | - (*bufp & TOPOLOGY_CHANGE) != 0; | |
2773 | - bufp++; | |
2774 | - memcpy((char*)&rcv_bpdu.root_id, bufp, | |
2775 | - BRIDGE_BPDU_8021_CONFIG_SIZE-1 | |
2776 | - -BRIDGE_BPDU_8021_CONFIG_FLAG_OFFSET); | |
2777 | - config_bpdu_ntoh(&rcv_bpdu); | |
2778 | - received_config_bpdu(port, &rcv_bpdu); | |
2779 | - break; | |
2780 | - | |
2781 | - case BPDU_TYPE_TOPO_CHANGE: | |
2782 | - received_tcn_bpdu(port, bpdu); | |
2783 | - break; | |
2784 | - default: | |
2785 | - printk(KERN_DEBUG "br_bpdu: received unknown bpdu, type = %i\n", bpdu->type); | |
2786 | - /* break; */ | |
2787 | - } | |
2788 | - } | |
2789 | - br_drop(skb); | |
2790 | -} | |
2791 | - | |
2792 | -struct fdb_info *get_fdb_info(int user_buf_size, int *copied,int *notcopied) | |
2793 | -{ | |
2794 | - int fdb_size, i, built = 0; | |
2795 | - struct fdb_info *fdbi, *fdbis; | |
2796 | - | |
2797 | - *copied = user_buf_size - sizeof(struct fdb_info_hdr); | |
2798 | - *copied /= sizeof(struct fdb_info); | |
2799 | - *copied = min(*copied, allocated_fdb_cnt); | |
2800 | - *notcopied = allocated_fdb_cnt - *copied; | |
2801 | - if(*copied == 0) | |
2802 | - return NULL; | |
2803 | - fdb_size = *copied * sizeof(struct fdb_info); | |
2804 | - fdbis = kmalloc(fdb_size, GFP_KERNEL); | |
2805 | - if(fdbis == NULL) | |
2806 | - return NULL; | |
2807 | - fdbi = fdbis; | |
2808 | - | |
2809 | - for(i=One; i<=No_of_ports;i++) | |
2810 | - { | |
2811 | - struct fdb *fdb; | |
2812 | - | |
2813 | - cli(); | |
2814 | - fdb = port_info[i].fdb; | |
2815 | - while(fdb) | |
2816 | - { | |
2817 | - memcpy(fdbi->ula, fdb->ula, ETH_ALEN); | |
2818 | - fdbi->port = fdb->port; | |
2819 | - fdbi->flags = fdb->flags; | |
2820 | - fdbi->timer = fdb->timer; | |
2821 | - fdbi++; | |
2822 | - if(++built == *copied) | |
2823 | - { | |
2824 | - sti(); | |
2825 | - return fdbis; | |
2826 | - } | |
2827 | - fdb = fdb->fdb_next; | |
2828 | - } | |
2829 | - sti(); | |
2830 | - } | |
2831 | - printk(KERN_DEBUG "get_fdb_info: built=%d\n", built); | |
2832 | - return fdbis; | |
2833 | -} | |
2834 | - | |
2835 | - | |
2836 | -/* Fill in interface names in port_info structure | |
2837 | - */ | |
2838 | -static void br_get_ifdata(void) { | |
2839 | - int i; | |
2840 | - | |
2841 | - for(i=One;i<=No_of_ports; i++) { | |
2842 | - | |
2843 | - port_info[i].admin_state = user_port_state[i]; | |
2844 | - | |
2845 | - /* memset IS needed. Kernel strncpy does NOT NULL terminate | |
2846 | - * strings when limit reached | |
2847 | - */ | |
2848 | - memset(port_info[i].ifname, 0, IFNAMSIZ); | |
2849 | - if( port_info[i].dev == 0 ) | |
2850 | - continue; | |
2851 | - strncpy(port_info[i].ifname, port_info[i].dev->name, IFNAMSIZ-1); | |
2852 | - /* Being paranoid */ | |
2853 | - port_info[i].ifname[IFNAMSIZ-1] = '\0'; | |
2854 | - } | |
2855 | -} | |
2856 | - | |
2857 | -/* Given an interface index, loop over port array to see if configured. If | |
2858 | - so, return port number, otherwise error */ | |
2859 | -static int br_find_port(int ifindex) | |
2860 | -{ | |
2861 | - int i; | |
2862 | - | |
2863 | - for(i=1; i <= No_of_ports; i++) { | |
2864 | - if (port_info[i].dev == 0) | |
2865 | - continue; | |
2866 | - if (port_info[i].dev->ifindex == ifindex) | |
2867 | - return(i); | |
2868 | - } | |
2869 | - | |
2870 | - return -EUNATCH; /* Tell me if this is incorrect error code for this case */ | |
2871 | -} | |
2872 | - | |
2873 | - | |
2874 | -int br_ioctl(unsigned int cmd, void *arg) | |
2875 | -{ | |
2876 | - int err, i, ifflags; | |
2877 | - struct br_cf bcf; | |
2878 | - bridge_id_t new_id; | |
2879 | - struct device *dev; | |
2880 | - | |
2881 | - switch(cmd) | |
2882 | - { | |
2883 | - case SIOCGIFBR: /* get bridging control blocks */ | |
2884 | - memcpy(&br_stats.bridge_data, &bridge_info, sizeof(Bridge_data)); | |
2885 | - | |
2886 | - /* Fill in interface names in port_info*/ | |
2887 | - br_get_ifdata(); | |
2888 | - | |
2889 | - br_stats.num_ports = No_of_ports; | |
2890 | - memcpy(&br_stats.port_data, &port_info, sizeof(Port_data)*All_ports); | |
2891 | - | |
2892 | - err = copy_to_user(arg, &br_stats, sizeof(struct br_stat)); | |
2893 | - if (err) | |
2894 | - { | |
2895 | - err = -EFAULT; | |
2896 | - } | |
2897 | - return err; | |
2898 | - case SIOCSIFBR: | |
2899 | - err = copy_from_user(&bcf, arg, sizeof(struct br_cf)); | |
2900 | - if (err) | |
2901 | - return -EFAULT; | |
2902 | - if (bcf.cmd != BRCMD_DISPLAY_FDB && !suser()) | |
2903 | - return -EPERM; | |
2904 | - switch (bcf.cmd) | |
2905 | - { | |
2906 | - case BRCMD_BRIDGE_ENABLE: | |
2907 | - if (br_stats.flags & BR_UP) | |
2908 | - return(-EALREADY); | |
2909 | - printk(KERN_DEBUG "br: enabling bridging function\n"); | |
2910 | - br_stats.flags |= BR_UP; /* enable bridge */ | |
2911 | - for(i=One;i<=No_of_ports; i++) | |
2912 | - { | |
2913 | - /* don't start if user said so */ | |
2914 | - if((user_port_state[i] != Disabled) | |
2915 | - && port_info[i].dev) | |
2916 | - { | |
2917 | - enable_port(i); | |
2918 | - } | |
2919 | - } | |
2920 | - port_state_selection(); /* (4.8.1.5) */ | |
2921 | - if (br_stats.flags & BR_STP_DISABLED) | |
2922 | - for(i=One;i<=No_of_ports; i++) | |
2923 | - if((user_port_state[i] != Disabled) && port_info[i].dev) | |
2924 | - port_info[i].state = Forwarding; | |
2925 | - config_bpdu_generation(); /* (4.8.1.6) */ | |
2926 | - /* initialize system timer */ | |
2927 | - tl.expires = jiffies+HZ; /* 1 second */ | |
2928 | - tl.function = br_tick; | |
2929 | - add_timer(&tl); | |
2930 | - start_hello_timer(); | |
2931 | - break; | |
2932 | - case BRCMD_BRIDGE_DISABLE: | |
2933 | - if (!(br_stats.flags & BR_UP)) | |
2934 | - return(-EALREADY); | |
2935 | - printk(KERN_DEBUG "br: disabling bridging function\n"); | |
2936 | - br_stats.flags &= ~BR_UP; /* disable bridge */ | |
2937 | - stop_hello_timer(); | |
2938 | - for (i = One; i <= No_of_ports; i++) | |
2939 | - if (port_info[i].state != Disabled) | |
2940 | - disable_port(i); | |
2941 | - break; | |
2942 | - case BRCMD_TOGGLE_STP: | |
2943 | - printk(KERN_DEBUG "br: %s spanning tree protcol\n", | |
2944 | - (br_stats.flags & BR_STP_DISABLED) ? "enabling" : "disabling"); | |
2945 | - if (br_stats.flags & BR_STP_DISABLED) { /* enable STP */ | |
2946 | - for(i=One;i<=No_of_ports; i++) | |
2947 | - if((user_port_state[i] != Disabled) && port_info[i].dev) | |
2948 | - enable_port(i); | |
2949 | - } else { /* STP was enabled, now disable it */ | |
2950 | - for (i = One; i <= No_of_ports; i++) | |
2951 | - if (port_info[i].state != Disabled && port_info[i].dev) | |
2952 | - port_info[i].state = Forwarding; | |
2953 | - } | |
2954 | - br_stats.flags ^= BR_STP_DISABLED; | |
2955 | - break; | |
2956 | - case BRCMD_IF_ENABLE: | |
2957 | - bcf.arg1 = br_find_port(bcf.arg1); | |
2958 | - if ((signed)bcf.arg1 < 0) | |
2959 | - return(bcf.arg1); | |
2960 | - case BRCMD_PORT_ENABLE: | |
2961 | - if (port_info[bcf.arg1].dev == 0) | |
2962 | - return(-EINVAL); | |
2963 | - if (user_port_state[bcf.arg1] != Disabled) | |
2964 | - return(-EALREADY); | |
2965 | - printk(KERN_DEBUG "br: enabling port %i\n",bcf.arg1); | |
2966 | - dev = port_info[bcf.arg1].dev; | |
2967 | - ifflags = (dev->flags&~(IFF_PROMISC|IFF_ALLMULTI)) | |
2968 | - |(dev->gflags&(IFF_PROMISC|IFF_ALLMULTI)); | |
2969 | - dev_change_flags(dev, ifflags|IFF_PROMISC); | |
2970 | - user_port_state[bcf.arg1] = ~Disabled; | |
2971 | - if(br_stats.flags & BR_UP) | |
2972 | - enable_port(bcf.arg1); | |
2973 | - break; | |
2974 | - case BRCMD_IF_DISABLE: | |
2975 | - bcf.arg1 = br_find_port(bcf.arg1); | |
2976 | - if ((signed)bcf.arg1 < 0) | |
2977 | - return(bcf.arg1); | |
2978 | - case BRCMD_PORT_DISABLE: | |
2979 | - if (port_info[bcf.arg1].dev == 0) | |
2980 | - return(-EINVAL); | |
2981 | - if (user_port_state[bcf.arg1] == Disabled) | |
2982 | - return(-EALREADY); | |
2983 | - printk(KERN_DEBUG "br: disabling port %i\n",bcf.arg1); | |
2984 | - user_port_state[bcf.arg1] = Disabled; | |
2985 | - if(br_stats.flags & BR_UP) | |
2986 | - disable_port(bcf.arg1); | |
2987 | - dev = port_info[bcf.arg1].dev; | |
2988 | - ifflags = (dev->flags&~(IFF_PROMISC|IFF_ALLMULTI)) | |
2989 | - |(dev->gflags&(IFF_PROMISC|IFF_ALLMULTI)); | |
2990 | - dev_change_flags(port_info[bcf.arg1].dev, ifflags & ~IFF_PROMISC); | |
2991 | - break; | |
2992 | - case BRCMD_SET_BRIDGE_PRIORITY: | |
2993 | - new_id = bridge_info.bridge_id; | |
2994 | - new_id.BRIDGE_PRIORITY = htons(bcf.arg1); | |
2995 | - set_bridge_priority(&new_id); | |
2996 | - break; | |
2997 | - case BRCMD_SET_IF_PRIORITY: | |
2998 | - bcf.arg1 = br_find_port(bcf.arg1); | |
2999 | - if ((signed)bcf.arg1 < 0) | |
3000 | - return(bcf.arg1); | |
3001 | - case BRCMD_SET_PORT_PRIORITY: | |
3002 | - if((port_info[bcf.arg1].dev == 0) | |
3003 | - || (bcf.arg2 & ~0xff)) | |
3004 | - return(-EINVAL); | |
3005 | - port_priority[bcf.arg1] = bcf.arg2; | |
3006 | - set_port_priority(bcf.arg1); | |
3007 | - break; | |
3008 | - case BRCMD_SET_IF_PATH_COST: | |
3009 | - bcf.arg1 = br_find_port(bcf.arg1); | |
3010 | - if ((signed)bcf.arg1 < 0) | |
3011 | - return(bcf.arg1); | |
3012 | - case BRCMD_SET_PATH_COST: | |
3013 | - if (port_info[bcf.arg1].dev == 0) | |
3014 | - return(-EINVAL); | |
3015 | - set_path_cost(bcf.arg1, bcf.arg2); | |
3016 | - break; | |
3017 | - case BRCMD_ENABLE_DEBUG: | |
3018 | - br_stats.flags |= BR_DEBUG; | |
3019 | - break; | |
3020 | - case BRCMD_DISABLE_DEBUG: | |
3021 | - br_stats.flags &= ~BR_DEBUG; | |
3022 | - break; | |
3023 | - case BRCMD_SET_POLICY: | |
3024 | - return br_set_policy(bcf.arg1); | |
3025 | - case BRCMD_EXEMPT_PROTOCOL: | |
3026 | - return br_add_exempt_protocol(bcf.arg1); | |
3027 | - case BRCMD_ENABLE_PROT_STATS: | |
3028 | - br_stats.flags |= BR_PROT_STATS; | |
3029 | - break; | |
3030 | - case BRCMD_DISABLE_PROT_STATS: | |
3031 | - br_stats.flags &= ~BR_PROT_STATS; | |
3032 | - break; | |
3033 | - case BRCMD_ZERO_PROT_STATS: | |
3034 | - memset(&br_stats.prot_id,0,sizeof(br_stats.prot_id)); | |
3035 | - memset(&br_stats.prot_counter,0,sizeof(br_stats.prot_counter)); | |
3036 | - break; | |
3037 | - case BRCMD_DISPLAY_FDB: | |
3038 | - { | |
3039 | - struct fdb_info_hdr *user_buf = (void*) bcf.arg1; | |
3040 | - struct fdb_info *u_fdbs, *fdbis; | |
3041 | - int copied, notcopied; | |
3042 | - u32 j = CURRENT_TIME; | |
3043 | - | |
3044 | - if(bcf.arg2<sizeof(struct fdb_info_hdr)) | |
3045 | - return -EINVAL; | |
3046 | - put_user(j, &user_buf->cmd_time); | |
3047 | - if(allocated_fdb_cnt == 0) | |
3048 | - { | |
3049 | - put_user(0, &user_buf->copied); | |
3050 | - put_user(0, &user_buf->not_copied); | |
3051 | - return 0; | |
3052 | - } | |
3053 | - fdbis = get_fdb_info(bcf.arg2, &copied, ¬copied); | |
3054 | - put_user(copied, &user_buf->copied); | |
3055 | - put_user(notcopied, &user_buf->not_copied); | |
3056 | - if(!fdbis) | |
3057 | - return -ENOMEM; | |
3058 | - u_fdbs = (struct fdb_info *) (user_buf+1); | |
3059 | - err = copy_to_user(u_fdbs, fdbis, copied*sizeof(struct fdb_info)); | |
3060 | - kfree(fdbis); | |
3061 | - if (err) | |
3062 | - { | |
3063 | - err = -EFAULT; | |
3064 | - } | |
3065 | - return err; | |
3066 | - } | |
3067 | - default: | |
3068 | - return -EINVAL; | |
3069 | - } | |
3070 | - return(0); | |
3071 | - default: | |
3072 | - return -EINVAL; | |
3073 | - } | |
3074 | - /*NOTREACHED*/ | |
3075 | - return 0; | |
3076 | -} | |
3077 | - | |
3078 | -static int br_cmp(unsigned int *a, unsigned int *b) | |
3079 | -{ | |
3080 | - int i; | |
3081 | - for (i=0; i<2; i++) | |
3082 | - { | |
3083 | - /* JRP: compares prty then MAC address in memory byte order | |
3084 | - * OK optimizer does htonl() only once per long ! | |
3085 | - */ | |
3086 | - if (htonl(a[i]) < htonl(b[i])) | |
3087 | - return(-1); | |
3088 | - if (htonl(a[i]) > htonl(b[i])) | |
3089 | - return(1); | |
3090 | - } | |
3091 | - return(0); | |
3092 | -} | |
3093 | - | |
3094 | - | |
3095 | - | |
3096 | - | |
3097 | -/* -------------------------------------------------------------------------------- | |
3098 | - * | |
3099 | - * | |
3100 | - * Bridge network device here for future modularization - device structures | |
3101 | - * must be 'static' inside bridge instance | |
3102 | - * Modelled after sch_teql.c | |
3103 | - * | |
3104 | - */ | |
3105 | - | |
3106 | - | |
3107 | - | |
3108 | -/* | |
3109 | - * Index to functions. | |
3110 | - */ | |
3111 | - | |
3112 | -int brg_probe(struct device *dev); | |
3113 | -static int brg_open(struct device *dev); | |
3114 | -static int brg_start_xmit(struct sk_buff *skb, struct device *dev); | |
3115 | -static int brg_close(struct device *dev); | |
3116 | -static struct net_device_stats *brg_get_stats(struct device *dev); | |
3117 | -static void brg_set_multicast_list(struct device *dev); | |
3118 | - | |
3119 | -/* | |
3120 | - * Board-specific info in dev->priv. | |
3121 | - */ | |
3122 | - | |
3123 | -struct net_local | |
3124 | -{ | |
3125 | - __u32 groups; | |
3126 | - struct net_device_stats stats; | |
3127 | -}; | |
3128 | - | |
3129 | - | |
3130 | - | |
3131 | - | |
3132 | -/* | |
3133 | - * To call this a probe is a bit misleading, however for real | |
3134 | - * hardware it would have to check what was present. | |
3135 | - */ | |
3136 | - | |
3137 | -__initfunc(int brg_probe(struct device *dev)) | |
3138 | -{ | |
3139 | - unsigned int bogomips; | |
3140 | - struct timeval utime; | |
3141 | - | |
3142 | - printk(KERN_INFO "%s: network interface for Ethernet Bridge 007/NET4.0\n", dev->name); | |
3143 | - | |
3144 | - /* | |
3145 | - * Initialize the device structure. | |
3146 | - */ | |
3147 | - | |
3148 | - dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL); | |
3149 | - if (dev->priv == NULL) | |
3150 | - return -ENOMEM; | |
3151 | - memset(dev->priv, 0, sizeof(struct net_local)); | |
3152 | - | |
3153 | - /* Set up MAC address based on BogoMIPs figure for first CPU and time | |
3154 | - */ | |
3155 | - bogomips = (loops_per_jiffy+2500)/500000/HZ ; | |
3156 | - get_fast_time(&utime); | |
3157 | - | |
3158 | - /* Ummmm.... YES! */ | |
3159 | - dev->dev_addr[0] = '\xFE'; | |
3160 | - dev->dev_addr[1] = '\xFD'; | |
3161 | - dev->dev_addr[2] = (bridge_info.instance & 0x0F) << 4; | |
3162 | - dev->dev_addr[2] |= ((utime.tv_sec & 0x000F0000) >> 16); | |
3163 | - dev->dev_addr[3] = bogomips & 0xFF; | |
3164 | - dev->dev_addr[4] = (utime.tv_sec & 0x0000FF00) >> 8; | |
3165 | - dev->dev_addr[5] = (utime.tv_sec & 0x000000FF); | |
3166 | - | |
3167 | - printk(KERN_INFO "%s: generated MAC address %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", | |
3168 | - dev->name, | |
3169 | - dev->dev_addr[0], | |
3170 | - dev->dev_addr[1], | |
3171 | - dev->dev_addr[2], | |
3172 | - dev->dev_addr[3], | |
3173 | - dev->dev_addr[4], | |
3174 | - dev->dev_addr[5]); | |
3175 | - | |
3176 | - | |
3177 | - printk(KERN_INFO "%s: attached to bridge instance %lu\n", dev->name, dev->base_addr); | |
3178 | - | |
3179 | - /* | |
3180 | - * The brg specific entries in the device structure. | |
3181 | - */ | |
3182 | - | |
3183 | - dev->open = brg_open; | |
3184 | - dev->hard_start_xmit = brg_start_xmit; | |
3185 | - dev->stop = brg_close; | |
3186 | - dev->get_stats = brg_get_stats; | |
3187 | - dev->set_multicast_list = brg_set_multicast_list; | |
3188 | - | |
3189 | - /* | |
3190 | - * Setup the generic properties | |
3191 | - */ | |
3192 | - | |
3193 | - ether_setup(dev); | |
3194 | - dev->tx_queue_len = 0; | |
3195 | - return 0; | |
3196 | -} | |
3197 | - | |
3198 | -/* | |
3199 | - * Open/initialize the board. | |
3200 | - */ | |
3201 | - | |
3202 | -static int brg_open(struct device *dev) | |
3203 | -{ | |
3204 | - if (br_stats.flags & BR_DEBUG) | |
3205 | - printk(KERN_DEBUG "%s: Doing brg_open()...", dev->name); | |
3206 | - | |
3207 | - if (memcmp(dev->dev_addr, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0) | |
3208 | - return -EFAULT; | |
3209 | - | |
3210 | - dev->start = 1; | |
3211 | - dev->tbusy = 0; | |
3212 | - return 0; | |
3213 | -} | |
3214 | - | |
3215 | -static unsigned brg_mc_hash(__u8 *dest) | |
3216 | -{ | |
3217 | - unsigned idx = 0; | |
3218 | - idx ^= dest[0]; | |
3219 | - idx ^= dest[1]; | |
3220 | - idx ^= dest[2]; | |
3221 | - idx ^= dest[3]; | |
3222 | - idx ^= dest[4]; | |
3223 | - idx ^= dest[5]; | |
3224 | - return 1U << (idx&0x1F); | |
3225 | -} | |
3226 | - | |
3227 | -static void brg_set_multicast_list(struct device *dev) | |
3228 | -{ | |
3229 | - unsigned groups = ~0; | |
3230 | - struct net_local *lp = (struct net_local *)dev->priv; | |
3231 | - | |
3232 | - if (!(dev->flags&(IFF_PROMISC|IFF_ALLMULTI))) { | |
3233 | - struct dev_mc_list *dmi; | |
3234 | - | |
3235 | - groups = brg_mc_hash(dev->broadcast); | |
3236 | - | |
3237 | - for (dmi=dev->mc_list; dmi; dmi=dmi->next) { | |
3238 | - if (dmi->dmi_addrlen != 6) | |
3239 | - continue; | |
3240 | - groups |= brg_mc_hash(dmi->dmi_addr); | |
3241 | - } | |
3242 | - } | |
3243 | - lp->groups = groups; | |
3244 | -} | |
3245 | - | |
3246 | -/* | |
3247 | - * We transmit by throwing the packet at the bridge. | |
3248 | - */ | |
3249 | - | |
3250 | -static int brg_start_xmit(struct sk_buff *skb, struct device *dev) | |
3251 | -{ | |
3252 | - struct net_local *lp = (struct net_local *)dev->priv; | |
3253 | - struct ethhdr *eth = (struct ethhdr*)skb->data; | |
3254 | - int port; | |
3255 | - | |
3256 | - /* Deal with the bridge being disabled */ | |
3257 | - if(!(br_stats.flags & BR_UP)) { | |
3258 | - /* Either this */ | |
3259 | - /* lp->stats.tx_errors++; */ /* this condition is NOT an error */ | |
3260 | - /* or this (implied by RFC 2233) */ | |
3261 | - lp->stats.tx_dropped++; | |
3262 | - dev_kfree_skb(skb); | |
3263 | - return 0; | |
3264 | - } | |
3265 | - | |
3266 | - lp->stats.tx_bytes+=skb->len; | |
3267 | - lp->stats.tx_packets++; | |
3268 | - | |
3269 | -#if 0 | |
3270 | - ++br_stats_cnt.port_not_disable; | |
3271 | -#endif | |
3272 | - skb->mac.raw = skb->nh.raw = skb->data; | |
3273 | - eth = skb->mac.ethernet; | |
3274 | - port = 0; /* an impossible port (locally generated) */ | |
3275 | - | |
3276 | - if (br_stats.flags & BR_DEBUG) | |
3277 | - printk(KERN_DEBUG "%s: brg_start_xmit - src %02x:%02x:%02x:%02x:%02x:%02x" | |
3278 | - " dest %02x:%02x:%02x:%02x:%02x:%02x\n", | |
3279 | - dev->name, | |
3280 | - eth->h_source[0], | |
3281 | - eth->h_source[1], | |
3282 | - eth->h_source[2], | |
3283 | - eth->h_source[3], | |
3284 | - eth->h_source[4], | |
3285 | - eth->h_source[5], | |
3286 | - eth->h_dest[0], | |
3287 | - eth->h_dest[1], | |
3288 | - eth->h_dest[2], | |
3289 | - eth->h_dest[3], | |
3290 | - eth->h_dest[4], | |
3291 | - eth->h_dest[5]); | |
3292 | - | |
3293 | - /* Forward the packet ! */ | |
3294 | - if(br_forward(skb, port)) | |
3295 | - return(0); | |
3296 | - | |
3297 | - /* Throw packet initially */ | |
3298 | - dev_kfree_skb(skb); | |
3299 | - return 0; | |
3300 | -} | |
3301 | - | |
3302 | - | |
3303 | -/* | |
3304 | - * The typical workload of the driver: | |
3305 | - * Handle the ether interface interrupts. | |
3306 | - * | |
3307 | - * (In this case handle the packets posted from the bridge) | |
3308 | - */ | |
3309 | - | |
3310 | -static int brg_rx(struct sk_buff *skb, int port) | |
3311 | -{ | |
3312 | - struct device *dev = &brg_if.dev; | |
3313 | - struct net_local *lp = (struct net_local *)dev->priv; | |
3314 | - struct ethhdr *eth = (struct ethhdr*)(skb->data); | |
3315 | - int len = skb->len; | |
3316 | - int clone = 0; | |
3317 | - | |
3318 | - if (br_stats.flags & BR_DEBUG) | |
3319 | - printk(KERN_DEBUG "%s: brg_rx()\n", dev->name); | |
3320 | - | |
3321 | - /* Get out of here if the bridge interface is not up | |
3322 | - */ | |
3323 | - if(!(dev->flags & IFF_UP)) | |
3324 | - return(0); | |
3325 | - | |
3326 | - /* Check that the port that this thing came off is in the forwarding state | |
3327 | - * We sould only listen to the same address scope we will transmit to. | |
3328 | - */ | |
3329 | - if(port_info[port].state != Forwarding) | |
3330 | - return(0); | |
3331 | - | |
3332 | - /* Is this for us? - broadcast/mulitcast/promiscuous packets need cloning, | |
3333 | - * with uni-cast we eat the packet | |
3334 | - */ | |
3335 | - clone = 0; | |
3336 | - if (dev->flags & IFF_PROMISC) { | |
3337 | - clone = 1; | |
3338 | - } | |
3339 | - else if (eth->h_dest[0]&1) { | |
3340 | - if (!(dev->flags&(IFF_ALLMULTI)) | |
3341 | - && !(brg_mc_hash(eth->h_dest)&lp->groups)) | |
3342 | - return(0); | |
3343 | - clone = 1; | |
3344 | - } | |
3345 | - else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN) != 0) { | |
3346 | - return(0); | |
3347 | - } | |
3348 | - | |
3349 | - /* Clone things here - we want to be transparent before we check packet data | |
3350 | - * integrity | |
3351 | - */ | |
3352 | - if(clone) { | |
3353 | - struct sk_buff *skb2 = skb; | |
3354 | - skb = skb_clone(skb2, GFP_ATOMIC); | |
3355 | - if (skb == NULL) { | |
3356 | - return(0); | |
3357 | - } | |
3358 | - | |
3359 | - } | |
3360 | - else { | |
3361 | - /* Learn source addresses for unicast non-promiscuous | |
3362 | - * frames for brg0 | |
3363 | - */ | |
3364 | - if(br_learn(skb, port)) { | |
3365 | - return br_drop(skb); | |
3366 | - } | |
3367 | - } | |
3368 | - | |
3369 | - /* Check packet length | |
3370 | - */ | |
3371 | - if (len < 16) { | |
3372 | - printk(KERN_DEBUG "%s : rx len = %d\n", dev->name, len); | |
3373 | - kfree_skb(skb); | |
3374 | - return(!clone); | |
3375 | - } | |
3376 | - | |
3377 | - if (br_stats.flags & BR_DEBUG) | |
3378 | - printk(KERN_DEBUG "%s: brg_rx - src %02x:%02x:%02x:%02x:%02x:%02x" | |
3379 | - " dest %02x:%02x:%02x:%02x:%02x:%02x\n", | |
3380 | - dev->name, | |
3381 | - eth->h_source[0], | |
3382 | - eth->h_source[1], | |
3383 | - eth->h_source[2], | |
3384 | - eth->h_source[3], | |
3385 | - eth->h_source[4], | |
3386 | - eth->h_source[5], | |
3387 | - eth->h_dest[0], | |
3388 | - eth->h_dest[1], | |
3389 | - eth->h_dest[2], | |
3390 | - eth->h_dest[3], | |
3391 | - eth->h_dest[4], | |
3392 | - eth->h_dest[5]); | |
3393 | - | |
3394 | - /* Do it */ | |
3395 | - skb->pkt_type = PACKET_HOST; | |
3396 | - skb->dev = dev; | |
3397 | - skb->protocol=eth_type_trans(skb,dev); | |
3398 | - memset(skb->cb, 0, sizeof(skb->cb)); | |
3399 | - lp->stats.rx_packets++; | |
3400 | - lp->stats.rx_bytes+=len; | |
3401 | - netif_rx(skb); | |
3402 | - return(!clone); | |
3403 | -} | |
3404 | - | |
3405 | -static int brg_close(struct device *dev) | |
3406 | -{ | |
3407 | - if (br_stats.flags & BR_DEBUG) | |
3408 | - printk(KERN_DEBUG "%s: Shutting down.\n", dev->name); | |
3409 | - | |
3410 | - dev->tbusy = 1; | |
3411 | - dev->start = 0; | |
3412 | - | |
3413 | - return 0; | |
3414 | -} | |
3415 | - | |
3416 | -static struct net_device_stats *brg_get_stats(struct device *dev) | |
3417 | -{ | |
3418 | - struct net_local *lp = (struct net_local *)dev->priv; | |
3419 | - return &lp->stats; | |
3420 | -} | |
3421 | - | |
3422 | -/* | |
3423 | - * | |
3424 | - */ | |
3425 | +#ifdef MODULE | |
3426 | +EXPORT_NO_SYMBOLS; | |
3427 | ||
3428 | -__initfunc(int brg_init(void)) | |
3429 | +int init_module(void) | |
3430 | { | |
3431 | - int err; | |
3432 | - | |
3433 | - memset(&brg_if, 0, sizeof(brg_if)); | |
3434 | - | |
3435 | - rtnl_lock(); | |
3436 | - | |
3437 | - brg_if.dev.base_addr = bridge_info.instance; | |
3438 | - sprintf (brg_if.name, "brg%d", bridge_info.instance); | |
3439 | - brg_if.dev.name = (void*)&brg_if.name; | |
3440 | - if(dev_get(brg_if.name)) { | |
3441 | - printk(KERN_INFO "%s already loaded.\n", brg_if.name); | |
3442 | - return -EBUSY; | |
3443 | - } | |
3444 | - brg_if.dev.init = brg_probe; | |
3445 | - | |
3446 | - err = register_netdevice(&brg_if.dev); | |
3447 | - rtnl_unlock(); | |
3448 | - return err; | |
3449 | + return br_init(); | |
3450 | } | |
3451 | ||
3452 | - | |
3453 | -#if 0 /* Its here if we ever need it... */ | |
3454 | -#ifdef MODULE | |
3455 | - | |
3456 | void cleanup_module(void) | |
3457 | { | |
3458 | - | |
3459 | - /* | |
3460 | - * Unregister the device | |
3461 | - */ | |
3462 | - rtnl_lock(); | |
3463 | - unregister_netdevice(&the_master.dev); | |
3464 | - rtnl_unlock(); | |
3465 | - | |
3466 | - /* | |
3467 | - * Free up the private structure. | |
3468 | - */ | |
3469 | - | |
3470 | - kfree(brg_if.dev.priv); | |
3471 | - brg_if.dev.priv = NULL; /* gets re-allocated by brg_probe */ | |
3472 | + unregister_netdevice_notifier(&br_device_notifier); | |
3473 | +#ifdef CONFIG_INET | |
3474 | + br_ioctl_hook = NULL; | |
3475 | +#endif | |
3476 | + br_handle_frame_hook = NULL; | |
3477 | + synchronize_bh(); | |
3478 | } | |
3479 | - | |
3480 | -#endif /* MODULE */ | |
3481 | ||
3482 | #endif | |
3483 | diff -urN linux-2.2.19/net/bridge/br_device.c linux-2.2.19br/net/bridge/br_device.c | |
3484 | --- linux-2.2.19/net/bridge/br_device.c Thu Jan 1 01:00:00 1970 | |
3485 | +++ linux-2.2.19br/net/bridge/br_device.c Tue Apr 3 11:32:57 2001 | |
3486 | @@ -0,0 +1,126 @@ | |
3487 | +/* | |
3488 | + * Device handling code | |
3489 | + * Linux ethernet bridge | |
3490 | + * | |
3491 | + * Authors: | |
3492 | + * Lennert Buytenhek <buytenh@gnu.org> | |
3493 | + * | |
3494 | + * $Id$ | |
3495 | + * | |
3496 | + * This program is free software; you can redistribute it and/or | |
3497 | + * modify it under the terms of the GNU General Public License | |
3498 | + * as published by the Free Software Foundation; either version | |
3499 | + * 2 of the License, or (at your option) any later version. | |
3500 | + */ | |
3501 | + | |
3502 | +#include <linux/config.h> | |
3503 | +#include <linux/kernel.h> | |
3504 | +#include <linux/netdevice.h> | |
3505 | +#include <linux/if_bridge.h> | |
3506 | +#include <asm/uaccess.h> | |
3507 | +#include "br_private.h" | |
3508 | + | |
3509 | +static int br_dev_do_ioctl(struct device *dev, struct ifreq *rq, int cmd) | |
3510 | +{ | |
3511 | + unsigned long args[4]; | |
3512 | + unsigned long *data; | |
3513 | + | |
3514 | + if (cmd != SIOCDEVPRIVATE) | |
3515 | + return -EOPNOTSUPP; | |
3516 | + | |
3517 | + data = (unsigned long *)rq->ifr_data; | |
3518 | + if (copy_from_user(args, data, 4*sizeof(unsigned long))) | |
3519 | + return -EFAULT; | |
3520 | + | |
3521 | + return br_ioctl(dev->priv, args[0], args[1], args[2], args[3]); | |
3522 | +} | |
3523 | + | |
3524 | +static struct net_device_stats *br_dev_get_stats(struct device *dev) | |
3525 | +{ | |
3526 | + struct net_bridge *br; | |
3527 | + | |
3528 | + br = dev->priv; | |
3529 | + | |
3530 | + return &br->statistics; | |
3531 | +} | |
3532 | + | |
3533 | +static int br_dev_xmit(struct sk_buff *skb, struct device *dev) | |
3534 | +{ | |
3535 | + struct net_bridge *br; | |
3536 | + unsigned char *dest; | |
3537 | + struct net_bridge_fdb_entry *dst; | |
3538 | + | |
3539 | + br = dev->priv; | |
3540 | + br->statistics.tx_packets++; | |
3541 | + br->statistics.tx_bytes += skb->len; | |
3542 | + | |
3543 | + dest = skb->data; | |
3544 | + | |
3545 | + if (dest[0] & 1) { | |
3546 | + br_flood(br, skb, 0); | |
3547 | + return 0; | |
3548 | + } | |
3549 | + | |
3550 | + if ((dst = br_fdb_get(br, dest)) != NULL) { | |
3551 | + br_forward(dst->dst, skb); | |
3552 | + br_fdb_put(dst); | |
3553 | + return 0; | |
3554 | + } | |
3555 | + | |
3556 | + br_flood(br, skb, 0); | |
3557 | + return 0; | |
3558 | +} | |
3559 | + | |
3560 | +static int br_dev_open(struct device *dev) | |
3561 | +{ | |
3562 | + struct net_bridge *br; | |
3563 | + | |
3564 | + dev->start = 1; | |
3565 | + dev->tbusy = 0; | |
3566 | + | |
3567 | + br = dev->priv; | |
3568 | + read_lock(&br->lock); | |
3569 | + br_stp_enable_bridge(br); | |
3570 | + read_unlock(&br->lock); | |
3571 | + | |
3572 | + return 0; | |
3573 | +} | |
3574 | + | |
3575 | +static void br_dev_set_multicast_list(struct device *dev) | |
3576 | +{ | |
3577 | +} | |
3578 | + | |
3579 | +static int br_dev_stop(struct device *dev) | |
3580 | +{ | |
3581 | + struct net_bridge *br; | |
3582 | + | |
3583 | + br = dev->priv; | |
3584 | + read_lock(&br->lock); | |
3585 | + br_stp_disable_bridge(br); | |
3586 | + read_unlock(&br->lock); | |
3587 | + | |
3588 | + dev->start = 0; | |
3589 | + dev->tbusy = 1; | |
3590 | + | |
3591 | + return 0; | |
3592 | +} | |
3593 | + | |
3594 | +static int br_dev_accept_fastpath(struct device *dev, struct dst_entry *dst) | |
3595 | +{ | |
3596 | + return -1; | |
3597 | +} | |
3598 | + | |
3599 | +void br_dev_setup(struct device *dev) | |
3600 | +{ | |
3601 | + memset(dev->dev_addr, 0, ETH_ALEN); | |
3602 | + | |
3603 | + dev->do_ioctl = br_dev_do_ioctl; | |
3604 | + dev->get_stats = br_dev_get_stats; | |
3605 | + dev->hard_start_xmit = br_dev_xmit; | |
3606 | + dev->open = br_dev_open; | |
3607 | + dev->set_multicast_list = br_dev_set_multicast_list; | |
3608 | + dev->stop = br_dev_stop; | |
3609 | + dev->accept_fastpath = br_dev_accept_fastpath; | |
3610 | + dev->tx_queue_len = 0; | |
3611 | + dev->set_mac_address = NULL; | |
3612 | +} | |
3613 | diff -urN linux-2.2.19/net/bridge/br_fdb.c linux-2.2.19br/net/bridge/br_fdb.c | |
3614 | --- linux-2.2.19/net/bridge/br_fdb.c Thu Jan 1 01:00:00 1970 | |
3615 | +++ linux-2.2.19br/net/bridge/br_fdb.c Tue Apr 3 11:32:57 2001 | |
3616 | @@ -0,0 +1,320 @@ | |
3617 | +/* | |
3618 | + * Forwarding database | |
3619 | + * Linux ethernet bridge | |
3620 | + * | |
3621 | + * Authors: | |
3622 | + * Lennert Buytenhek <buytenh@gnu.org> | |
3623 | + * | |
3624 | + * $Id$ | |
3625 | + * | |
3626 | + * This program is free software; you can redistribute it and/or | |
3627 | + * modify it under the terms of the GNU General Public License | |
3628 | + * as published by the Free Software Foundation; either version | |
3629 | + * 2 of the License, or (at your option) any later version. | |
3630 | + */ | |
3631 | + | |
3632 | +#include <linux/config.h> | |
3633 | +#include <linux/kernel.h> | |
3634 | +#include <linux/if_bridge.h> | |
3635 | +#include <asm/atomic.h> | |
3636 | +#include <asm/spinlock.h> | |
3637 | +#include <asm/uaccess.h> | |
3638 | +#include "br_private.h" | |
3639 | + | |
3640 | +static __inline__ unsigned long __timeout(struct net_bridge *br) | |
3641 | +{ | |
3642 | + unsigned long timeout; | |
3643 | + | |
3644 | + timeout = jiffies - br->ageing_time; | |
3645 | + if (br->topology_change) | |
3646 | + timeout = jiffies - br->forward_delay; | |
3647 | + | |
3648 | + return timeout; | |
3649 | +} | |
3650 | + | |
3651 | +static __inline__ int has_expired(struct net_bridge *br, | |
3652 | + struct net_bridge_fdb_entry *fdb) | |
3653 | +{ | |
3654 | + if (!fdb->is_static && | |
3655 | + time_before_eq(fdb->ageing_timer, __timeout(br))) | |
3656 | + return 1; | |
3657 | + | |
3658 | + return 0; | |
3659 | +} | |
3660 | + | |
3661 | +static __inline__ void copy_fdb(struct __fdb_entry *ent, struct net_bridge_fdb_entry *f) | |
3662 | +{ | |
3663 | + memset(ent, 0, sizeof(struct __fdb_entry)); | |
3664 | + memcpy(ent->mac_addr, f->addr.addr, ETH_ALEN); | |
3665 | + ent->port_no = f->dst?f->dst->port_no:0; | |
3666 | + ent->is_local = f->is_local; | |
3667 | + ent->ageing_timer_value = 0; | |
3668 | + if (!f->is_static) | |
3669 | + ent->ageing_timer_value = jiffies - f->ageing_timer; | |
3670 | +} | |
3671 | + | |
3672 | +static __inline__ int br_mac_hash(unsigned char *mac) | |
3673 | +{ | |
3674 | + unsigned long x; | |
3675 | + | |
3676 | + x = mac[0]; | |
3677 | + x = (x << 2) ^ mac[1]; | |
3678 | + x = (x << 2) ^ mac[2]; | |
3679 | + x = (x << 2) ^ mac[3]; | |
3680 | + x = (x << 2) ^ mac[4]; | |
3681 | + x = (x << 2) ^ mac[5]; | |
3682 | + | |
3683 | + x ^= x >> 8; | |
3684 | + | |
3685 | + return x & (BR_HASH_SIZE - 1); | |
3686 | +} | |
3687 | + | |
3688 | +static __inline__ void __hash_link(struct net_bridge *br, | |
3689 | + struct net_bridge_fdb_entry *ent, | |
3690 | + int hash) | |
3691 | +{ | |
3692 | + ent->next_hash = br->hash[hash]; | |
3693 | + if (ent->next_hash != NULL) | |
3694 | + ent->next_hash->pprev_hash = &ent->next_hash; | |
3695 | + br->hash[hash] = ent; | |
3696 | + ent->pprev_hash = &br->hash[hash]; | |
3697 | +} | |
3698 | + | |
3699 | +static __inline__ void __hash_unlink(struct net_bridge_fdb_entry *ent) | |
3700 | +{ | |
3701 | + *(ent->pprev_hash) = ent->next_hash; | |
3702 | + if (ent->next_hash != NULL) | |
3703 | + ent->next_hash->pprev_hash = ent->pprev_hash; | |
3704 | + ent->next_hash = NULL; | |
3705 | + ent->pprev_hash = NULL; | |
3706 | +} | |
3707 | + | |
3708 | + | |
3709 | + | |
3710 | +void br_fdb_changeaddr(struct net_bridge_port *p, unsigned char *newaddr) | |
3711 | +{ | |
3712 | + struct net_bridge *br; | |
3713 | + int i; | |
3714 | + | |
3715 | + br = p->br; | |
3716 | + write_lock_bh(&br->hash_lock); | |
3717 | + for (i=0;i<BR_HASH_SIZE;i++) { | |
3718 | + struct net_bridge_fdb_entry *f; | |
3719 | + | |
3720 | + f = br->hash[i]; | |
3721 | + while (f != NULL) { | |
3722 | + if (f->dst == p && f->is_local) { | |
3723 | + __hash_unlink(f); | |
3724 | + memcpy(f->addr.addr, newaddr, ETH_ALEN); | |
3725 | + __hash_link(br, f, br_mac_hash(newaddr)); | |
3726 | + write_unlock_bh(&br->hash_lock); | |
3727 | + return; | |
3728 | + } | |
3729 | + f = f->next_hash; | |
3730 | + } | |
3731 | + } | |
3732 | + write_unlock_bh(&br->hash_lock); | |
3733 | +} | |
3734 | + | |
3735 | +void br_fdb_cleanup(struct net_bridge *br) | |
3736 | +{ | |
3737 | + int i; | |
3738 | + unsigned long timeout; | |
3739 | + | |
3740 | + timeout = __timeout(br); | |
3741 | + | |
3742 | + write_lock_bh(&br->hash_lock); | |
3743 | + for (i=0;i<BR_HASH_SIZE;i++) { | |
3744 | + struct net_bridge_fdb_entry *f; | |
3745 | + | |
3746 | + f = br->hash[i]; | |
3747 | + while (f != NULL) { | |
3748 | + struct net_bridge_fdb_entry *g; | |
3749 | + | |
3750 | + g = f->next_hash; | |
3751 | + if (!f->is_static && | |
3752 | + time_before_eq(f->ageing_timer, timeout)) { | |
3753 | + __hash_unlink(f); | |
3754 | + br_fdb_put(f); | |
3755 | + } | |
3756 | + f = g; | |
3757 | + } | |
3758 | + } | |
3759 | + write_unlock_bh(&br->hash_lock); | |
3760 | +} | |
3761 | + | |
3762 | +void br_fdb_delete_by_port(struct net_bridge *br, struct net_bridge_port *p) | |
3763 | +{ | |
3764 | + int i; | |
3765 | + | |
3766 | + write_lock_bh(&br->hash_lock); | |
3767 | + for (i=0;i<BR_HASH_SIZE;i++) { | |
3768 | + struct net_bridge_fdb_entry *f; | |
3769 | + | |
3770 | + f = br->hash[i]; | |
3771 | + while (f != NULL) { | |
3772 | + struct net_bridge_fdb_entry *g; | |
3773 | + | |
3774 | + g = f->next_hash; | |
3775 | + if (f->dst == p) { | |
3776 | + __hash_unlink(f); | |
3777 | + br_fdb_put(f); | |
3778 | + } | |
3779 | + f = g; | |
3780 | + } | |
3781 | + } | |
3782 | + write_unlock_bh(&br->hash_lock); | |
3783 | +} | |
3784 | + | |
3785 | +struct net_bridge_fdb_entry *br_fdb_get(struct net_bridge *br, unsigned char *addr) | |
3786 | +{ | |
3787 | + struct net_bridge_fdb_entry *fdb; | |
3788 | + | |
3789 | + read_lock_bh(&br->hash_lock); | |
3790 | + fdb = br->hash[br_mac_hash(addr)]; | |
3791 | + while (fdb != NULL) { | |
3792 | + if (!memcmp(fdb->addr.addr, addr, ETH_ALEN)) { | |
3793 | + if (!has_expired(br, fdb)) { | |
3794 | + atomic_inc(&fdb->use_count); | |
3795 | + read_unlock_bh(&br->hash_lock); | |
3796 | + return fdb; | |
3797 | + } | |
3798 | + | |
3799 | + read_unlock_bh(&br->hash_lock); | |
3800 | + return NULL; | |
3801 | + } | |
3802 | + | |
3803 | + fdb = fdb->next_hash; | |
3804 | + } | |
3805 | + | |
3806 | + read_unlock_bh(&br->hash_lock); | |
3807 | + return NULL; | |
3808 | +} | |
3809 | + | |
3810 | +void br_fdb_put(struct net_bridge_fdb_entry *ent) | |
3811 | +{ | |
3812 | + if (atomic_dec_and_test(&ent->use_count)) | |
3813 | + kfree(ent); | |
3814 | +} | |
3815 | + | |
3816 | +int br_fdb_get_entries(struct net_bridge *br, | |
3817 | + unsigned char *_buf, | |
3818 | + int maxnum, | |
3819 | + int offset) | |
3820 | +{ | |
3821 | + int i; | |
3822 | + int num; | |
3823 | + struct __fdb_entry *walk; | |
3824 | + | |
3825 | + num = 0; | |
3826 | + walk = (struct __fdb_entry *)_buf; | |
3827 | + | |
3828 | + read_lock_bh(&br->hash_lock); | |
3829 | + for (i=0;i<BR_HASH_SIZE;i++) { | |
3830 | + struct net_bridge_fdb_entry *f; | |
3831 | + | |
3832 | + f = br->hash[i]; | |
3833 | + while (f != NULL && num < maxnum) { | |
3834 | + struct __fdb_entry ent; | |
3835 | + int err; | |
3836 | + struct net_bridge_fdb_entry *g; | |
3837 | + | |
3838 | + if (has_expired(br, f)) { | |
3839 | + f = f->next_hash; | |
3840 | + continue; | |
3841 | + } | |
3842 | + | |
3843 | + if (offset) { | |
3844 | + offset--; | |
3845 | + f = f->next_hash; | |
3846 | + continue; | |
3847 | + } | |
3848 | + | |
3849 | + copy_fdb(&ent, f); | |
3850 | + | |
3851 | + atomic_inc(&f->use_count); | |
3852 | + read_unlock_bh(&br->hash_lock); | |
3853 | + err = copy_to_user(walk, &ent, sizeof(struct __fdb_entry)); | |
3854 | + read_lock_bh(&br->hash_lock); | |
3855 | + | |
3856 | + g = f->next_hash; | |
3857 | + br_fdb_put(f); | |
3858 | + | |
3859 | + if (err) | |
3860 | + goto out_fault; | |
3861 | + | |
3862 | + if (f->next_hash == NULL && | |
3863 | + f->pprev_hash == NULL) | |
3864 | + goto out_disappeared; | |
3865 | + | |
3866 | + num++; | |
3867 | + walk++; | |
3868 | + | |
3869 | + f = g; | |
3870 | + } | |
3871 | + } | |
3872 | + | |
3873 | + out: | |
3874 | + read_unlock_bh(&br->hash_lock); | |
3875 | + return num; | |
3876 | + | |
3877 | + out_disappeared: | |
3878 | + num = -EAGAIN; | |
3879 | + goto out; | |
3880 | + | |
3881 | + out_fault: | |
3882 | + num = -EFAULT; | |
3883 | + goto out; | |
3884 | +} | |
3885 | + | |
3886 | +static __inline__ void __fdb_possibly_replace(struct net_bridge_fdb_entry *fdb, | |
3887 | + struct net_bridge_port *source, | |
3888 | + int is_local) | |
3889 | +{ | |
3890 | + if (!fdb->is_static || is_local) { | |
3891 | + fdb->dst = source; | |
3892 | + fdb->is_local = is_local; | |
3893 | + fdb->is_static = is_local; | |
3894 | + fdb->ageing_timer = jiffies; | |
3895 | + } | |
3896 | +} | |
3897 | + | |
3898 | +void br_fdb_insert(struct net_bridge *br, | |
3899 | + struct net_bridge_port *source, | |
3900 | + unsigned char *addr, | |
3901 | + int is_local) | |
3902 | +{ | |
3903 | + struct net_bridge_fdb_entry *fdb; | |
3904 | + int hash; | |
3905 | + | |
3906 | + hash = br_mac_hash(addr); | |
3907 | + | |
3908 | + write_lock_bh(&br->hash_lock); | |
3909 | + fdb = br->hash[hash]; | |
3910 | + while (fdb != NULL) { | |
3911 | + if (!memcmp(fdb->addr.addr, addr, ETH_ALEN)) { | |
3912 | + __fdb_possibly_replace(fdb, source, is_local); | |
3913 | + write_unlock_bh(&br->hash_lock); | |
3914 | + return; | |
3915 | + } | |
3916 | + | |
3917 | + fdb = fdb->next_hash; | |
3918 | + } | |
3919 | + | |
3920 | + fdb = kmalloc(sizeof(*fdb), GFP_ATOMIC); | |
3921 | + if (fdb == NULL) { | |
3922 | + write_unlock_bh(&br->hash_lock); | |
3923 | + return; | |
3924 | + } | |
3925 | + | |
3926 | + memcpy(fdb->addr.addr, addr, ETH_ALEN); | |
3927 | + atomic_set(&fdb->use_count, 1); | |
3928 | + fdb->dst = source; | |
3929 | + fdb->is_local = is_local; | |
3930 | + fdb->is_static = is_local; | |
3931 | + fdb->ageing_timer = jiffies; | |
3932 | + | |
3933 | + __hash_link(br, fdb, hash); | |
3934 | + | |
3935 | + write_unlock_bh(&br->hash_lock); | |
3936 | +} | |
3937 | diff -urN linux-2.2.19/net/bridge/br_forward.c linux-2.2.19br/net/bridge/br_forward.c | |
3938 | --- linux-2.2.19/net/bridge/br_forward.c Thu Jan 1 01:00:00 1970 | |
3939 | +++ linux-2.2.19br/net/bridge/br_forward.c Tue Apr 3 11:32:57 2001 | |
3940 | @@ -0,0 +1,98 @@ | |
3941 | +/* | |
3942 | + * Forwarding decision | |
3943 | + * Linux ethernet bridge | |
3944 | + * | |
3945 | + * Authors: | |
3946 | + * Lennert Buytenhek <buytenh@gnu.org> | |
3947 | + * | |
3948 | + * $Id$ | |
3949 | + * | |
3950 | + * This program is free software; you can redistribute it and/or | |
3951 | + * modify it under the terms of the GNU General Public License | |
3952 | + * as published by the Free Software Foundation; either version | |
3953 | + * 2 of the License, or (at your option) any later version. | |
3954 | + */ | |
3955 | + | |
3956 | +#include <linux/config.h> | |
3957 | +#include <linux/kernel.h> | |
3958 | +#include <linux/netdevice.h> | |
3959 | +#include <linux/inetdevice.h> | |
3960 | +#include <linux/skbuff.h> | |
3961 | +#include <linux/firewall.h> | |
3962 | +#include <linux/if_bridge.h> | |
3963 | +#include "br_private.h" | |
3964 | + | |
3965 | +static inline int should_forward(struct net_bridge_port *p, struct sk_buff *skb) | |
3966 | +{ | |
3967 | + if (skb->dev != p->dev && p->state == BR_STATE_FORWARDING) | |
3968 | + return 1; | |
3969 | + | |
3970 | + return 0; | |
3971 | +} | |
3972 | + | |
3973 | +static void __br_forward(struct net_bridge_port *to, struct sk_buff *skb) | |
3974 | +{ | |
3975 | + skb->dev = to->dev; | |
3976 | + dev_queue_xmit(skb); | |
3977 | +} | |
3978 | + | |
3979 | +void br_forward(struct net_bridge_port *to, struct sk_buff *skb) | |
3980 | +{ | |
3981 | + if (should_forward(to, skb)) { | |
3982 | + __br_forward(to, skb); | |
3983 | + return; | |
3984 | + } | |
3985 | + | |
3986 | + kfree_skb(skb); | |
3987 | +} | |
3988 | + | |
3989 | +void br_flood(struct net_bridge *br, struct sk_buff *skb, int clone) | |
3990 | +{ | |
3991 | + struct net_bridge_port *p; | |
3992 | + struct net_bridge_port *prev; | |
3993 | + | |
3994 | + if (clone) { | |
3995 | + struct sk_buff *skb2; | |
3996 | + | |
3997 | + if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) { | |
3998 | + br->statistics.tx_dropped++; | |
3999 | + return; | |
4000 | + } | |
4001 | + | |
4002 | + skb = skb2; | |
4003 | + } | |
4004 | + | |
4005 | + prev = NULL; | |
4006 | + | |
4007 | + read_lock(&br->lock); | |
4008 | + p = br->port_list; | |
4009 | + while (p != NULL) { | |
4010 | + if (should_forward(p, skb)) { | |
4011 | + if (prev != NULL) { | |
4012 | + struct sk_buff *skb2; | |
4013 | + | |
4014 | + if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) { | |
4015 | + br->statistics.tx_dropped++; | |
4016 | + kfree_skb(skb); | |
4017 | + read_unlock(&br->lock); | |
4018 | + return; | |
4019 | + } | |
4020 | + | |
4021 | + __br_forward(prev, skb2); | |
4022 | + } | |
4023 | + | |
4024 | + prev = p; | |
4025 | + } | |
4026 | + | |
4027 | + p = p->next; | |
4028 | + } | |
4029 | + | |
4030 | + if (prev != NULL) { | |
4031 | + __br_forward(prev, skb); | |
4032 | + read_unlock(&br->lock); | |
4033 | + return; | |
4034 | + } | |
4035 | + | |
4036 | + read_unlock(&br->lock); | |
4037 | + kfree_skb(skb); | |
4038 | +} | |
4039 | diff -urN linux-2.2.19/net/bridge/br_if.c linux-2.2.19br/net/bridge/br_if.c | |
4040 | --- linux-2.2.19/net/bridge/br_if.c Thu Jan 1 01:00:00 1970 | |
4041 | +++ linux-2.2.19br/net/bridge/br_if.c Tue Apr 3 11:32:57 2001 | |
4042 | @@ -0,0 +1,296 @@ | |
4043 | +/* | |
4044 | + * Userspace interface | |
4045 | + * Linux ethernet bridge | |
4046 | + * | |
4047 | + * Authors: | |
4048 | + * Lennert Buytenhek <buytenh@gnu.org> | |
4049 | + * | |
4050 | + * $Id$ | |
4051 | + * | |
4052 | + * This program is free software; you can redistribute it and/or | |
4053 | + * modify it under the terms of the GNU General Public License | |
4054 | + * as published by the Free Software Foundation; either version | |
4055 | + * 2 of the License, or (at your option) any later version. | |
4056 | + */ | |
4057 | + | |
4058 | +#include <linux/config.h> | |
4059 | +#include <linux/kernel.h> | |
4060 | +#include <linux/if_arp.h> | |
4061 | +#include <linux/if_bridge.h> | |
4062 | +#include <linux/inetdevice.h> | |
4063 | +#include <asm/uaccess.h> | |
4064 | +#include "br_private.h" | |
4065 | + | |
4066 | +static struct net_bridge *bridge_list; | |
4067 | + | |
4068 | +static int br_initial_port_cost(struct device *dev) | |
4069 | +{ | |
4070 | + if (!strncmp(dev->name, "lec", 3)) | |
4071 | + return 7; | |
4072 | + | |
4073 | + if (!strncmp(dev->name, "eth", 3)) | |
4074 | + return 100; /* FIXME handle 100Mbps */ | |
4075 | + | |
4076 | + if (!strncmp(dev->name, "plip", 4)) | |
4077 | + return 2500; | |
4078 | + | |
4079 | + return 100; | |
4080 | +} | |
4081 | + | |
4082 | +/* called under bridge lock */ | |
4083 | +static int __br_del_if(struct net_bridge *br, struct device *dev) | |
4084 | +{ | |
4085 | + struct net_bridge_port *p; | |
4086 | + struct net_bridge_port **pptr; | |
4087 | + | |
4088 | + if ((p = dev->br_port) == NULL) | |
4089 | + return -EINVAL; | |
4090 | + | |
4091 | + br_stp_disable_port(p); | |
4092 | + | |
4093 | + dev_set_promiscuity(dev, -1); | |
4094 | + if (dev->ip_ptr != NULL) { | |
4095 | + struct in_device *idev = dev->ip_ptr; | |
4096 | + idev->cnf.hidden = 0; | |
4097 | + } | |
4098 | + | |
4099 | + dev->br_port = NULL; | |
4100 | + | |
4101 | + pptr = &br->port_list; | |
4102 | + while (*pptr != NULL) { | |
4103 | + if (*pptr == p) { | |
4104 | + *pptr = p->next; | |
4105 | + break; | |
4106 | + } | |
4107 | + | |
4108 | + pptr = &((*pptr)->next); | |
4109 | + } | |
4110 | + | |
4111 | + br_fdb_delete_by_port(br, p); | |
4112 | + kfree(p); | |
4113 | + | |
4114 | + return 0; | |
4115 | +} | |
4116 | + | |
4117 | +static struct net_bridge **__find_br(char *name) | |
4118 | +{ | |
4119 | + struct net_bridge **b; | |
4120 | + struct net_bridge *br; | |
4121 | + | |
4122 | + b = &bridge_list; | |
4123 | + while ((br = *b) != NULL) { | |
4124 | + if (!strncmp(br->name, name, IFNAMSIZ)) | |
4125 | + return b; | |
4126 | + | |
4127 | + b = &(br->next); | |
4128 | + } | |
4129 | + | |
4130 | + return NULL; | |
4131 | +} | |
4132 | + | |
4133 | +static void del_ifs(struct net_bridge *br) | |
4134 | +{ | |
4135 | + write_lock_bh(&br->lock); | |
4136 | + while (br->port_list != NULL) | |
4137 | + __br_del_if(br, br->port_list->dev); | |
4138 | + write_unlock_bh(&br->lock); | |
4139 | +} | |
4140 | + | |
4141 | +static struct net_bridge *new_nb(char *name) | |
4142 | +{ | |
4143 | + struct net_bridge *br; | |
4144 | + struct device *dev; | |
4145 | + | |
4146 | + if ((br = kmalloc(sizeof(*br), GFP_KERNEL)) == NULL) | |
4147 | + return NULL; | |
4148 | + | |
4149 | + memset(br, 0, sizeof(*br)); | |
4150 | + dev = &br->dev; | |
4151 | + | |
4152 | + strncpy(br->name, name, IFNAMSIZ); | |
4153 | + dev->priv = br; | |
4154 | + dev->name = br->name; | |
4155 | + ether_setup(dev); | |
4156 | + br_dev_setup(dev); | |
4157 | + | |
4158 | + br->lock = RW_LOCK_UNLOCKED; | |
4159 | + br->hash_lock = RW_LOCK_UNLOCKED; | |
4160 | + | |
4161 | + br->bridge_id.prio[0] = 0x80; | |
4162 | + br->bridge_id.prio[1] = 0x00; | |
4163 | + memset(br->bridge_id.addr, 0, ETH_ALEN); | |
4164 | + | |
4165 | + br->stp_enabled = 1; | |
4166 | + br->designated_root = br->bridge_id; | |
4167 | + br->root_path_cost = 0; | |
4168 | + br->root_port = 0; | |
4169 | + br->bridge_max_age = br->max_age = 20 * HZ; | |
4170 | + br->bridge_hello_time = br->hello_time = 2 * HZ; | |
4171 | + br->bridge_forward_delay = br->forward_delay = 15 * HZ; | |
4172 | + br->topology_change = 0; | |
4173 | + br->topology_change_detected = 0; | |
4174 | + br_timer_clear(&br->hello_timer); | |
4175 | + br_timer_clear(&br->tcn_timer); | |
4176 | + br_timer_clear(&br->topology_change_timer); | |
4177 | + | |
4178 | + br->ageing_time = 300 * HZ; | |
4179 | + br->gc_interval = 4 * HZ; | |
4180 | + | |
4181 | + return br; | |
4182 | +} | |
4183 | + | |
4184 | +/* called under bridge lock */ | |
4185 | +static struct net_bridge_port *new_nbp(struct net_bridge *br, struct device *dev) | |
4186 | +{ | |
4187 | + int i; | |
4188 | + struct net_bridge_port *p; | |
4189 | + | |
4190 | + p = kmalloc(sizeof(*p), GFP_KERNEL); | |
4191 | + if (p == NULL) | |
4192 | + return p; | |
4193 | + | |
4194 | + memset(p, 0, sizeof(*p)); | |
4195 | + p->br = br; | |
4196 | + p->dev = dev; | |
4197 | + p->path_cost = br_initial_port_cost(dev); | |
4198 | + p->priority = 0x80; | |
4199 | + | |
4200 | + dev->br_port = p; | |
4201 | + | |
4202 | + for (i=1;i<255;i++) | |
4203 | + if (br_get_port(br, i) == NULL) | |
4204 | + break; | |
4205 | + | |
4206 | + if (i == 255) { | |
4207 | + kfree(p); | |
4208 | + return NULL; | |
4209 | + } | |
4210 | + | |
4211 | + p->port_no = i; | |
4212 | + br_init_port(p); | |
4213 | + p->state = BR_STATE_DISABLED; | |
4214 | + | |
4215 | + p->next = br->port_list; | |
4216 | + br->port_list = p; | |
4217 | + | |
4218 | + return p; | |
4219 | +} | |
4220 | + | |
4221 | +int br_add_bridge(char *name) | |
4222 | +{ | |
4223 | + struct net_bridge *br; | |
4224 | + | |
4225 | + if ((br = new_nb(name)) == NULL) | |
4226 | + return -ENOMEM; | |
4227 | + | |
4228 | + if (dev_get(name) != NULL) { | |
4229 | + kfree(br); | |
4230 | + return -EEXIST; | |
4231 | + } | |
4232 | + | |
4233 | + br->next = bridge_list; | |
4234 | + bridge_list = br; | |
4235 | + | |
4236 | + br_inc_use_count(); | |
4237 | + register_netdevice(&br->dev); | |
4238 | + | |
4239 | + return 0; | |
4240 | +} | |
4241 | + | |
4242 | +int br_del_bridge(char *name) | |
4243 | +{ | |
4244 | + struct net_bridge **b; | |
4245 | + struct net_bridge *br; | |
4246 | + | |
4247 | + if ((b = __find_br(name)) == NULL) | |
4248 | + return -ENXIO; | |
4249 | + | |
4250 | + br = *b; | |
4251 | + | |
4252 | + if (br->dev.flags & IFF_UP) | |
4253 | + return -EBUSY; | |
4254 | + | |
4255 | + del_ifs(br); | |
4256 | + | |
4257 | + *b = br->next; | |
4258 | + | |
4259 | + unregister_netdevice(&br->dev); | |
4260 | + kfree(br); | |
4261 | + br_dec_use_count(); | |
4262 | + | |
4263 | + return 0; | |
4264 | +} | |
4265 | + | |
4266 | +int br_add_if(struct net_bridge *br, struct device *dev) | |
4267 | +{ | |
4268 | + struct net_bridge_port *p; | |
4269 | + | |
4270 | + if (dev->br_port != NULL) | |
4271 | + return -EBUSY; | |
4272 | + | |
4273 | + if (dev->flags & IFF_LOOPBACK || dev->type != ARPHRD_ETHER) | |
4274 | + return -EINVAL; | |
4275 | + | |
4276 | + write_lock_bh(&br->lock); | |
4277 | + if ((p = new_nbp(br, dev)) == NULL) { | |
4278 | + write_unlock_bh(&br->lock); | |
4279 | + return -EXFULL; | |
4280 | + } | |
4281 | + | |
4282 | + if (dev->ip_ptr != NULL) { | |
4283 | + struct in_device *idev = dev->ip_ptr; | |
4284 | + idev->cnf.hidden = 1; | |
4285 | + } | |
4286 | + dev_set_promiscuity(dev, 1); | |
4287 | + | |
4288 | + br_stp_recalculate_bridge_id(br); | |
4289 | + br_fdb_insert(br, p, dev->dev_addr, 1); | |
4290 | + if ((br->dev.flags & IFF_UP) && (dev->flags & IFF_UP)) | |
4291 | + br_stp_enable_port(p); | |
4292 | + write_unlock_bh(&br->lock); | |
4293 | + | |
4294 | + return 0; | |
4295 | +} | |
4296 | + | |
4297 | +int br_del_if(struct net_bridge *br, struct device *dev) | |
4298 | +{ | |
4299 | + int retval; | |
4300 | + | |
4301 | + write_lock_bh(&br->lock); | |
4302 | + retval = __br_del_if(br, dev); | |
4303 | + br_stp_recalculate_bridge_id(br); | |
4304 | + write_unlock_bh(&br->lock); | |
4305 | + | |
4306 | + return retval; | |
4307 | +} | |
4308 | + | |
4309 | +int br_get_bridge_ifindices(int *indices, int num) | |
4310 | +{ | |
4311 | + struct net_bridge *br; | |
4312 | + int i; | |
4313 | + | |
4314 | + i = 0; | |
4315 | + | |
4316 | + br = bridge_list; | |
4317 | + for (i=0;i<num;i++) { | |
4318 | + if (br == NULL) | |
4319 | + break; | |
4320 | + | |
4321 | + indices[i] = br->dev.ifindex; | |
4322 | + br = br->next; | |
4323 | + } | |
4324 | + | |
4325 | + return i; | |
4326 | +} | |
4327 | + | |
4328 | +/* called under ioctl_lock */ | |
4329 | +void br_get_port_ifindices(struct net_bridge *br, int *ifindices) | |
4330 | +{ | |
4331 | + struct net_bridge_port *p; | |
4332 | + | |
4333 | + p = br->port_list; | |
4334 | + while (p != NULL) { | |
4335 | + ifindices[p->port_no] = p->dev->ifindex; | |
4336 | + p = p->next; | |
4337 | + } | |
4338 | +} | |
4339 | diff -urN linux-2.2.19/net/bridge/br_input.c linux-2.2.19br/net/bridge/br_input.c | |
4340 | --- linux-2.2.19/net/bridge/br_input.c Thu Jan 1 01:00:00 1970 | |
4341 | +++ linux-2.2.19br/net/bridge/br_input.c Tue Apr 3 11:32:57 2001 | |
4342 | @@ -0,0 +1,135 @@ | |
4343 | +/* | |
4344 | + * Handle incoming frames | |
4345 | + * Linux ethernet bridge | |
4346 | + * | |
4347 | + * Authors: | |
4348 | + * Lennert Buytenhek <buytenh@gnu.org> | |
4349 | + * | |
4350 | + * $Id$ | |
4351 | + * | |
4352 | + * This program is free software; you can redistribute it and/or | |
4353 | + * modify it under the terms of the GNU General Public License | |
4354 | + * as published by the Free Software Foundation; either version | |
4355 | + * 2 of the License, or (at your option) any later version. | |
4356 | + * | |
4357 | + * Changes: 2000/02/03 [AF] Arne Fitzenreiter <arne.fitzenreiter@gmx.de> | |
4358 | + * Bugfix - Multicast & Promiscious Mode | |
4359 | + * | |
4360 | + */ | |
4361 | + | |
4362 | +#include <linux/config.h> | |
4363 | +#include <linux/kernel.h> | |
4364 | +#include <linux/netdevice.h> | |
4365 | +#include <linux/etherdevice.h> | |
4366 | +#include <linux/if_bridge.h> | |
4367 | +#include "br_private.h" | |
4368 | + | |
4369 | +unsigned char bridge_ula[6] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 }; | |
4370 | + | |
4371 | +static void br_pass_frame_up(struct net_bridge *br, struct sk_buff *skb) | |
4372 | +{ | |
4373 | + br->statistics.rx_packets++; | |
4374 | + br->statistics.rx_bytes += skb->len; | |
4375 | + | |
4376 | + skb->dev = &br->dev; | |
4377 | + skb->pkt_type = PACKET_HOST; | |
4378 | + skb_pull(skb, skb->mac.raw - skb->data); | |
4379 | + skb->protocol = eth_type_trans(skb, &br->dev); | |
4380 | + netif_rx(skb); | |
4381 | +} | |
4382 | + | |
4383 | +void br_handle_frame(struct sk_buff *skb) | |
4384 | +{ | |
4385 | + struct net_bridge *br; | |
4386 | + unsigned char *dest; | |
4387 | + struct net_bridge_fdb_entry *dst; | |
4388 | + struct net_bridge_port *p; | |
4389 | + int passedup; | |
4390 | + | |
4391 | + dest = skb->mac.ethernet->h_dest; | |
4392 | + | |
4393 | + p = skb->dev->br_port; | |
4394 | + br = p->br; | |
4395 | + passedup = 0; | |
4396 | + | |
4397 | + if (!(br->dev.flags & IFF_UP) || | |
4398 | + p->state == BR_STATE_DISABLED) | |
4399 | + goto freeandout; | |
4400 | + | |
4401 | + skb_push(skb, skb->data - skb->mac.raw); | |
4402 | + | |
4403 | + if (br->dev.flags & IFF_PROMISC) { | |
4404 | + struct sk_buff *skb2; | |
4405 | + | |
4406 | + skb2 = skb_clone(skb, GFP_ATOMIC); | |
4407 | + if (skb2) { | |
4408 | + passedup = 1; | |
4409 | + br_pass_frame_up(br, skb2); | |
4410 | + } | |
4411 | + } | |
4412 | + | |
4413 | + if (skb->mac.ethernet->h_source[0] & 1) | |
4414 | + goto freeandout; | |
4415 | + | |
4416 | + if (!passedup && | |
4417 | + (dest[0] & 1) && | |
4418 | + (br->dev.flags & IFF_ALLMULTI || br->dev.mc_list != NULL)) { | |
4419 | + struct sk_buff *skb2; | |
4420 | + | |
4421 | + skb2 = skb_clone(skb, GFP_ATOMIC); | |
4422 | + if (skb2) { | |
4423 | + passedup = 1; | |
4424 | + br_pass_frame_up(br, skb2); | |
4425 | + } | |
4426 | + } | |
4427 | + | |
4428 | + if (br->stp_enabled && | |
4429 | + !memcmp(dest, bridge_ula, 5) && | |
4430 | + !(dest[5] & 0xF0)) | |
4431 | + goto handle_special_frame; | |
4432 | + | |
4433 | + if (p->state == BR_STATE_LEARNING || | |
4434 | + p->state == BR_STATE_FORWARDING) | |
4435 | + br_fdb_insert(br, p, skb->mac.ethernet->h_source, 0); | |
4436 | + | |
4437 | + if (p->state != BR_STATE_FORWARDING) | |
4438 | + goto freeandout; | |
4439 | + | |
4440 | + if (dest[0] & 1) { | |
4441 | + br_flood(br, skb, 1); | |
4442 | + if (!passedup) | |
4443 | + br_pass_frame_up(br, skb); | |
4444 | + else | |
4445 | + kfree_skb(skb); | |
4446 | + return; | |
4447 | + } | |
4448 | + | |
4449 | + dst = br_fdb_get(br, dest); | |
4450 | + | |
4451 | + if (dst != NULL && dst->is_local) { | |
4452 | + if (!passedup) | |
4453 | + br_pass_frame_up(br, skb); | |
4454 | + else | |
4455 | + kfree_skb(skb); | |
4456 | + br_fdb_put(dst); | |
4457 | + return; | |
4458 | + } | |
4459 | + | |
4460 | + if (dst != NULL) { | |
4461 | + br_forward(dst->dst, skb); | |
4462 | + br_fdb_put(dst); | |
4463 | + return; | |
4464 | + } | |
4465 | + | |
4466 | + br_flood(br, skb, 0); | |
4467 | + return; | |
4468 | + | |
4469 | + handle_special_frame: | |
4470 | + if (!dest[5]) { | |
4471 | + br_stp_handle_bpdu(skb); | |
4472 | + return; | |
4473 | + } | |
4474 | + | |
4475 | + freeandout: | |
4476 | + kfree_skb(skb); | |
4477 | +} | |
4478 | diff -urN linux-2.2.19/net/bridge/br_ioctl.c linux-2.2.19br/net/bridge/br_ioctl.c | |
4479 | --- linux-2.2.19/net/bridge/br_ioctl.c Thu Jan 1 01:00:00 1970 | |
4480 | +++ linux-2.2.19br/net/bridge/br_ioctl.c Tue Apr 3 11:32:57 2001 | |
4481 | @@ -0,0 +1,264 @@ | |
4482 | +/* | |
4483 | + * Ioctl handler | |
4484 | + * Linux ethernet bridge | |
4485 | + * | |
4486 | + * Authors: | |
4487 | + * Lennert Buytenhek <buytenh@gnu.org> | |
4488 | + * | |
4489 | + * $Id$ | |
4490 | + * | |
4491 | + * This program is free software; you can redistribute it and/or | |
4492 | + * modify it under the terms of the GNU General Public License | |
4493 | + * as published by the Free Software Foundation; either version | |
4494 | + * 2 of the License, or (at your option) any later version. | |
4495 | + */ | |
4496 | + | |
4497 | +#include <linux/config.h> | |
4498 | +#include <linux/kernel.h> | |
4499 | +#include <linux/if_bridge.h> | |
4500 | +#include <linux/inetdevice.h> | |
4501 | +#include <asm/uaccess.h> | |
4502 | +#include "br_private.h" | |
4503 | + | |
4504 | +static int br_ioctl_device(struct net_bridge *br, | |
4505 | + unsigned int cmd, | |
4506 | + unsigned long arg0, | |
4507 | + unsigned long arg1, | |
4508 | + unsigned long arg2) | |
4509 | +{ | |
4510 | + if (br == NULL) | |
4511 | + return -EINVAL; | |
4512 | + | |
4513 | + switch (cmd) | |
4514 | + { | |
4515 | + case BRCTL_ADD_IF: | |
4516 | + case BRCTL_DEL_IF: | |
4517 | + { | |
4518 | + struct device *dev; | |
4519 | + | |
4520 | + dev = dev_get_by_index(arg0); | |
4521 | + if (dev == NULL) | |
4522 | + return -EINVAL; | |
4523 | + | |
4524 | + if (cmd == BRCTL_ADD_IF) | |
4525 | + return br_add_if(br, dev); | |
4526 | + | |
4527 | + return br_del_if(br, dev); | |
4528 | + } | |
4529 | + | |
4530 | + case BRCTL_GET_BRIDGE_INFO: | |
4531 | + { | |
4532 | + struct __bridge_info b; | |
4533 | + | |
4534 | + memset(&b, 0, sizeof(struct __bridge_info)); | |
4535 | + memcpy(&b.designated_root, &br->designated_root, 8); | |
4536 | + memcpy(&b.bridge_id, &br->bridge_id, 8); | |
4537 | + b.root_path_cost = br->root_path_cost; | |
4538 | + b.max_age = br->max_age; | |
4539 | + b.hello_time = br->hello_time; | |
4540 | + b.forward_delay = br->forward_delay; | |
4541 | + b.bridge_max_age = br->bridge_max_age; | |
4542 | + b.bridge_hello_time = br->bridge_hello_time; | |
4543 | + b.bridge_forward_delay = br->bridge_forward_delay; | |
4544 | + b.topology_change = br->topology_change; | |
4545 | + b.topology_change_detected = br->topology_change_detected; | |
4546 | + b.root_port = br->root_port; | |
4547 | + b.stp_enabled = br->stp_enabled; | |
4548 | + b.ageing_time = br->ageing_time; | |
4549 | + b.gc_interval = br->gc_interval; | |
4550 | + b.hello_timer_value = br_timer_get_residue(&br->hello_timer); | |
4551 | + b.tcn_timer_value = br_timer_get_residue(&br->tcn_timer); | |
4552 | + b.topology_change_timer_value = br_timer_get_residue(&br->topology_change_timer); | |
4553 | + b.gc_timer_value = br_timer_get_residue(&br->gc_timer); | |
4554 | + | |
4555 | + if (copy_to_user((void *)arg0, &b, sizeof(b))) | |
4556 | + return -EFAULT; | |
4557 | + | |
4558 | + return 0; | |
4559 | + } | |
4560 | + | |
4561 | + case BRCTL_GET_PORT_LIST: | |
4562 | + { | |
4563 | + int i; | |
4564 | + int indices[256]; | |
4565 | + | |
4566 | + for (i=0;i<256;i++) | |
4567 | + indices[i] = 0; | |
4568 | + | |
4569 | + br_get_port_ifindices(br, indices); | |
4570 | + if (copy_to_user((void *)arg0, indices, 256*sizeof(int))) | |
4571 | + return -EFAULT; | |
4572 | + | |
4573 | + return 0; | |
4574 | + } | |
4575 | + | |
4576 | + case BRCTL_SET_BRIDGE_FORWARD_DELAY: | |
4577 | + br->bridge_forward_delay = arg0; | |
4578 | + if (br_is_root_bridge(br)) | |
4579 | + br->forward_delay = arg0; | |
4580 | + return 0; | |
4581 | + | |
4582 | + case BRCTL_SET_BRIDGE_HELLO_TIME: | |
4583 | + br->bridge_hello_time = arg0; | |
4584 | + if (br_is_root_bridge(br)) | |
4585 | + br->hello_time = arg0; | |
4586 | + return 0; | |
4587 | + | |
4588 | + case BRCTL_SET_BRIDGE_MAX_AGE: | |
4589 | + br->bridge_max_age = arg0; | |
4590 | + if (br_is_root_bridge(br)) | |
4591 | + br->max_age = arg0; | |
4592 | + return 0; | |
4593 | + | |
4594 | + case BRCTL_SET_AGEING_TIME: | |
4595 | + br->ageing_time = arg0; | |
4596 | + return 0; | |
4597 | + | |
4598 | + case BRCTL_SET_GC_INTERVAL: | |
4599 | + br->gc_interval = arg0; | |
4600 | + return 0; | |
4601 | + | |
4602 | + case BRCTL_GET_PORT_INFO: | |
4603 | + { | |
4604 | + struct __port_info p; | |
4605 | + struct net_bridge_port *pt; | |
4606 | + | |
4607 | + if ((pt = br_get_port(br, arg1)) == NULL) | |
4608 | + return -EINVAL; | |
4609 | + | |
4610 | + memset(&p, 0, sizeof(struct __port_info)); | |
4611 | + memcpy(&p.designated_root, &pt->designated_root, 8); | |
4612 | + memcpy(&p.designated_bridge, &pt->designated_bridge, 8); | |
4613 | + p.port_id = pt->port_id; | |
4614 | + p.designated_port = pt->designated_port; | |
4615 | + p.path_cost = pt->path_cost; | |
4616 | + p.designated_cost = pt->designated_cost; | |
4617 | + p.state = pt->state; | |
4618 | + p.top_change_ack = pt->topology_change_ack; | |
4619 | + p.config_pending = pt->config_pending; | |
4620 | + p.message_age_timer_value = br_timer_get_residue(&pt->message_age_timer); | |
4621 | + p.forward_delay_timer_value = br_timer_get_residue(&pt->forward_delay_timer); | |
4622 | + p.hold_timer_value = br_timer_get_residue(&pt->hold_timer); | |
4623 | + | |
4624 | + if (copy_to_user((void *)arg0, &p, sizeof(p))) | |
4625 | + return -EFAULT; | |
4626 | + | |
4627 | + return 0; | |
4628 | + } | |
4629 | + | |
4630 | + case BRCTL_SET_BRIDGE_STP_STATE: | |
4631 | + br->stp_enabled = arg0?1:0; | |
4632 | + return 0; | |
4633 | + | |
4634 | + case BRCTL_SET_BRIDGE_PRIORITY: | |
4635 | + br_stp_set_bridge_priority(br, arg0); | |
4636 | + return 0; | |
4637 | + | |
4638 | + case BRCTL_SET_PORT_PRIORITY: | |
4639 | + { | |
4640 | + struct net_bridge_port *p; | |
4641 | + | |
4642 | + if ((p = br_get_port(br, arg0)) == NULL) | |
4643 | + return -EINVAL; | |
4644 | + br_stp_set_port_priority(p, arg1); | |
4645 | + return 0; | |
4646 | + } | |
4647 | + | |
4648 | + case BRCTL_SET_PATH_COST: | |
4649 | + { | |
4650 | + struct net_bridge_port *p; | |
4651 | + | |
4652 | + if ((p = br_get_port(br, arg0)) == NULL) | |
4653 | + return -EINVAL; | |
4654 | + br_stp_set_path_cost(p, arg1); | |
4655 | + return 0; | |
4656 | + } | |
4657 | + | |
4658 | + case BRCTL_GET_FDB_ENTRIES: | |
4659 | + return br_fdb_get_entries(br, (void *)arg0, arg1, arg2); | |
4660 | + } | |
4661 | + | |
4662 | + return -EOPNOTSUPP; | |
4663 | +} | |
4664 | + | |
4665 | +static int br_ioctl_deviceless(unsigned int cmd, | |
4666 | + unsigned long arg0, | |
4667 | + unsigned long arg1) | |
4668 | +{ | |
4669 | + switch (cmd) | |
4670 | + { | |
4671 | + case BRCTL_GET_VERSION: | |
4672 | + return BRCTL_VERSION; | |
4673 | + | |
4674 | + case BRCTL_GET_BRIDGES: | |
4675 | + { | |
4676 | + int i; | |
4677 | + int indices[64]; | |
4678 | + | |
4679 | + for (i=0;i<64;i++) | |
4680 | + indices[i] = 0; | |
4681 | + | |
4682 | + if (arg1 > 64) | |
4683 | + arg1 = 64; | |
4684 | + arg1 = br_get_bridge_ifindices(indices, arg1); | |
4685 | + if (copy_to_user((void *)arg0, indices, arg1*sizeof(int))) | |
4686 | + return -EFAULT; | |
4687 | + | |
4688 | + return arg1; | |
4689 | + } | |
4690 | + | |
4691 | + case BRCTL_ADD_BRIDGE: | |
4692 | + case BRCTL_DEL_BRIDGE: | |
4693 | + { | |
4694 | + char buf[IFNAMSIZ]; | |
4695 | + | |
4696 | + if (copy_from_user(buf, (void *)arg0, IFNAMSIZ)) | |
4697 | + return -EFAULT; | |
4698 | + | |
4699 | + buf[IFNAMSIZ-1] = 0; | |
4700 | + | |
4701 | + if (cmd == BRCTL_ADD_BRIDGE) | |
4702 | + return br_add_bridge(buf); | |
4703 | + | |
4704 | + return br_del_bridge(buf); | |
4705 | + } | |
4706 | + } | |
4707 | + | |
4708 | + return -EOPNOTSUPP; | |
4709 | +} | |
4710 | + | |
4711 | +static struct semaphore ioctl_mutex = MUTEX; | |
4712 | + | |
4713 | +int br_ioctl_deviceless_stub(unsigned long arg) | |
4714 | +{ | |
4715 | + int err; | |
4716 | + unsigned long i[3]; | |
4717 | + | |
4718 | + if (!capable(CAP_NET_ADMIN)) | |
4719 | + return -EPERM; | |
4720 | + | |
4721 | + if (copy_from_user(i, (void *)arg, 3*sizeof(unsigned long))) | |
4722 | + return -EFAULT; | |
4723 | + | |
4724 | + down(&ioctl_mutex); | |
4725 | + err = br_ioctl_deviceless(i[0], i[1], i[2]); | |
4726 | + up(&ioctl_mutex); | |
4727 | + | |
4728 | + return err; | |
4729 | +} | |
4730 | + | |
4731 | +int br_ioctl(struct net_bridge *br, unsigned int cmd, unsigned long arg0, unsigned long arg1, unsigned long arg2) | |
4732 | +{ | |
4733 | + int err; | |
4734 | + | |
4735 | + if (!capable(CAP_NET_ADMIN)) | |
4736 | + return -EPERM; | |
4737 | + | |
4738 | + down(&ioctl_mutex); | |
4739 | + err = br_ioctl_deviceless(cmd, arg0, arg1); | |
4740 | + if (err == -EOPNOTSUPP) | |
4741 | + err = br_ioctl_device(br, cmd, arg0, arg1, arg2); | |
4742 | + up(&ioctl_mutex); | |
4743 | + | |
4744 | + return err; | |
4745 | +} | |
4746 | diff -urN linux-2.2.19/net/bridge/br_notify.c linux-2.2.19br/net/bridge/br_notify.c | |
4747 | --- linux-2.2.19/net/bridge/br_notify.c Thu Jan 1 01:00:00 1970 | |
4748 | +++ linux-2.2.19br/net/bridge/br_notify.c Tue Apr 3 11:32:57 2001 | |
4749 | @@ -0,0 +1,76 @@ | |
4750 | +/* | |
4751 | + * Device event handling | |
4752 | + * Linux ethernet bridge | |
4753 | + * | |
4754 | + * Authors: | |
4755 | + * Lennert Buytenhek <buytenh@gnu.org> | |
4756 | + * | |
4757 | + * $Id$ | |
4758 | + * | |
4759 | + * This program is free software; you can redistribute it and/or | |
4760 | + * modify it under the terms of the GNU General Public License | |
4761 | + * as published by the Free Software Foundation; either version | |
4762 | + * 2 of the License, or (at your option) any later version. | |
4763 | + */ | |
4764 | + | |
4765 | +#include <linux/config.h> | |
4766 | +#include <linux/kernel.h> | |
4767 | +#include <linux/if_bridge.h> | |
4768 | +#include "br_private.h" | |
4769 | + | |
4770 | +static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr); | |
4771 | + | |
4772 | +struct notifier_block br_device_notifier = | |
4773 | +{ | |
4774 | + br_device_event, | |
4775 | + NULL, | |
4776 | + 0 | |
4777 | +}; | |
4778 | + | |
4779 | +static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr) | |
4780 | +{ | |
4781 | + struct device *dev; | |
4782 | + struct net_bridge_port *p; | |
4783 | + | |
4784 | + dev = ptr; | |
4785 | + p = dev->br_port; | |
4786 | + | |
4787 | + if (p == NULL) | |
4788 | + return NOTIFY_DONE; | |
4789 | + | |
4790 | + switch (event) | |
4791 | + { | |
4792 | + case NETDEV_CHANGEADDR: | |
4793 | + read_lock(&p->br->lock); | |
4794 | + br_fdb_changeaddr(p, dev->dev_addr); | |
4795 | + br_stp_recalculate_bridge_id(p->br); | |
4796 | + read_unlock(&p->br->lock); | |
4797 | + break; | |
4798 | + | |
4799 | + case NETDEV_GOING_DOWN: | |
4800 | + /* extend the protocol to send some kind of notification? */ | |
4801 | + break; | |
4802 | + | |
4803 | + case NETDEV_DOWN: | |
4804 | + if (p->br->dev.flags & IFF_UP) { | |
4805 | + read_lock(&p->br->lock); | |
4806 | + br_stp_disable_port(dev->br_port); | |
4807 | + read_unlock(&p->br->lock); | |
4808 | + } | |
4809 | + break; | |
4810 | + | |
4811 | + case NETDEV_UP: | |
4812 | + if (p->br->dev.flags & IFF_UP) { | |
4813 | + read_lock(&p->br->lock); | |
4814 | + br_stp_enable_port(dev->br_port); | |
4815 | + read_unlock(&p->br->lock); | |
4816 | + } | |
4817 | + break; | |
4818 | + | |
4819 | + case NETDEV_UNREGISTER: | |
4820 | + br_del_if(dev->br_port->br, dev); | |
4821 | + break; | |
4822 | + } | |
4823 | + | |
4824 | + return NOTIFY_DONE; | |
4825 | +} | |
4826 | diff -urN linux-2.2.19/net/bridge/br_private.h linux-2.2.19br/net/bridge/br_private.h | |
4827 | --- linux-2.2.19/net/bridge/br_private.h Thu Jan 1 01:00:00 1970 | |
4828 | +++ linux-2.2.19br/net/bridge/br_private.h Tue Apr 3 11:32:58 2001 | |
4829 | @@ -0,0 +1,215 @@ | |
4830 | +/* | |
4831 | + * Linux ethernet bridge | |
4832 | + * | |
4833 | + * Authors: | |
4834 | + * Lennert Buytenhek <buytenh@gnu.org> | |
4835 | + * | |
4836 | + * $Id$ | |
4837 | + * | |
4838 | + * This program is free software; you can redistribute it and/or | |
4839 | + * modify it under the terms of the GNU General Public License | |
4840 | + * as published by the Free Software Foundation; either version | |
4841 | + * 2 of the License, or (at your option) any later version. | |
4842 | + */ | |
4843 | + | |
4844 | +#ifndef _BR_PRIVATE_H | |
4845 | +#define _BR_PRIVATE_H | |
4846 | + | |
4847 | +#include <linux/netdevice.h> | |
4848 | +#include <linux/miscdevice.h> | |
4849 | +#include <linux/if_bridge.h> | |
4850 | + | |
4851 | +#define BR_HASH_BITS 8 | |
4852 | +#define BR_HASH_SIZE (1 << BR_HASH_BITS) | |
4853 | + | |
4854 | +#define BR_HOLD_TIME (1*HZ) | |
4855 | + | |
4856 | +#ifndef read_lock_bh | |
4857 | +#define read_lock_bh(x) { start_bh_atomic(); read_lock(x); } | |
4858 | +#define read_unlock_bh(x) { read_unlock(x); end_bh_atomic(); } | |
4859 | +#define write_lock_bh(x) { start_bh_atomic(); write_lock(x); } | |
4860 | +#define write_unlock_bh(x) { write_unlock(x); end_bh_atomic(); } | |
4861 | +#endif | |
4862 | + | |
4863 | +typedef struct bridge_id bridge_id; | |
4864 | +typedef struct mac_addr mac_addr; | |
4865 | +typedef __u16 port_id; | |
4866 | + | |
4867 | +#if 1 | |
4868 | +struct br_timer { int running; unsigned long expires; }; | |
4869 | +#define br_timer_clear(t) { (t)->running = 0; } | |
4870 | +#define br_timer_get_residue(t) (((t)->running)?(jiffies - (t)->expires):0) | |
4871 | +#define br_timer_set(t,x) { (t)->expires = (x); (t)->running = 1; } | |
4872 | +#define br_timer_is_running(t) ((t)->running) | |
4873 | +#define br_timer_has_expired(t,to) ((t)->running && time_after_eq(jiffies, (t)->expires + (to))) | |
4874 | +#endif | |
4875 | + | |
4876 | + | |
4877 | + | |
4878 | +struct bridge_id | |
4879 | +{ | |
4880 | + unsigned char prio[2]; | |
4881 | + unsigned char addr[6]; | |
4882 | +}; | |
4883 | + | |
4884 | +struct mac_addr | |
4885 | +{ | |
4886 | + unsigned char addr[6]; | |
4887 | + unsigned char pad[2]; | |
4888 | +}; | |
4889 | + | |
4890 | +struct net_bridge_fdb_entry | |
4891 | +{ | |
4892 | + struct net_bridge_fdb_entry *next_hash; | |
4893 | + struct net_bridge_fdb_entry **pprev_hash; | |
4894 | + atomic_t use_count; | |
4895 | + mac_addr addr; | |
4896 | + struct net_bridge_port *dst; | |
4897 | + unsigned long ageing_timer; | |
4898 | + unsigned is_local:1; | |
4899 | + unsigned is_static:1; | |
4900 | +}; | |
4901 | + | |
4902 | +struct net_bridge_port | |
4903 | +{ | |
4904 | + struct net_bridge_port *next; | |
4905 | + struct net_bridge *br; | |
4906 | + struct device *dev; | |
4907 | + int port_no; | |
4908 | + | |
4909 | + /* STP */ | |
4910 | + port_id port_id; | |
4911 | + int state; | |
4912 | + int path_cost; | |
4913 | + bridge_id designated_root; | |
4914 | + int designated_cost; | |
4915 | + bridge_id designated_bridge; | |
4916 | + port_id designated_port; | |
4917 | + unsigned topology_change_ack:1; | |
4918 | + unsigned config_pending:1; | |
4919 | + int priority; | |
4920 | + | |
4921 | + struct br_timer forward_delay_timer; | |
4922 | + struct br_timer hold_timer; | |
4923 | + struct br_timer message_age_timer; | |
4924 | +}; | |
4925 | + | |
4926 | +struct net_bridge | |
4927 | +{ | |
4928 | + struct net_bridge *next; | |
4929 | + rwlock_t lock; | |
4930 | + struct net_bridge_port *port_list; | |
4931 | + char name[IFNAMSIZ]; | |
4932 | + struct device dev; | |
4933 | + struct net_device_stats statistics; | |
4934 | + rwlock_t hash_lock; | |
4935 | + struct net_bridge_fdb_entry *hash[BR_HASH_SIZE]; | |
4936 | + struct timer_list tick; | |
4937 | + | |
4938 | + /* STP */ | |
4939 | + bridge_id designated_root; | |
4940 | + int root_path_cost; | |
4941 | + int root_port; | |
4942 | + int max_age; | |
4943 | + int hello_time; | |
4944 | + int forward_delay; | |
4945 | + bridge_id bridge_id; | |
4946 | + int bridge_max_age; | |
4947 | + int bridge_hello_time; | |
4948 | + int bridge_forward_delay; | |
4949 | + unsigned stp_enabled:1; | |
4950 | + unsigned topology_change:1; | |
4951 | + unsigned topology_change_detected:1; | |
4952 | + | |
4953 | + struct br_timer hello_timer; | |
4954 | + struct br_timer tcn_timer; | |
4955 | + struct br_timer topology_change_timer; | |
4956 | + struct br_timer gc_timer; | |
4957 | + | |
4958 | + int ageing_time; | |
4959 | + int gc_interval; | |
4960 | +}; | |
4961 | + | |
4962 | +struct notifier_block br_device_notifier; | |
4963 | +unsigned char bridge_ula[6]; | |
4964 | + | |
4965 | +/* br.c */ | |
4966 | +void br_dec_use_count(void); | |
4967 | +void br_inc_use_count(void); | |
4968 | + | |
4969 | +/* br_device.c */ | |
4970 | +void br_dev_setup(struct device *dev); | |
4971 | + | |
4972 | +/* br_fdb.c */ | |
4973 | +void br_fdb_changeaddr(struct net_bridge_port *p, | |
4974 | + unsigned char *newaddr); | |
4975 | +void br_fdb_cleanup(struct net_bridge *br); | |
4976 | +void br_fdb_delete_by_port(struct net_bridge *br, | |
4977 | + struct net_bridge_port *p); | |
4978 | +struct net_bridge_fdb_entry *br_fdb_get(struct net_bridge *br, | |
4979 | + unsigned char *addr); | |
4980 | +void br_fdb_put(struct net_bridge_fdb_entry *ent); | |
4981 | +int br_fdb_get_entries(struct net_bridge *br, | |
4982 | + unsigned char *_buf, | |
4983 | + int maxnum, | |
4984 | + int offset); | |
4985 | +void br_fdb_insert(struct net_bridge *br, | |
4986 | + struct net_bridge_port *source, | |
4987 | + unsigned char *addr, | |
4988 | + int is_local); | |
4989 | + | |
4990 | +/* br_forward.c */ | |
4991 | +void br_forward(struct net_bridge_port *to, | |
4992 | + struct sk_buff *skb); | |
4993 | +void br_flood(struct net_bridge *br, | |
4994 | + struct sk_buff *skb, | |
4995 | + int clone); | |
4996 | + | |
4997 | +/* br_if.c */ | |
4998 | +int br_add_bridge(char *name); | |
4999 | +int br_del_bridge(char *name); | |
5000 | +int br_add_if(struct net_bridge *br, | |
5001 | + struct device *dev); | |
5002 | +int br_del_if(struct net_bridge *br, | |
5003 | + struct device *dev); | |
5004 | +int br_get_bridge_ifindices(int *indices, | |
5005 | + int num); | |
5006 | +void br_get_port_ifindices(struct net_bridge *br, | |
5007 | + int *ifindices); | |
5008 | + | |
5009 | +/* br_input.c */ | |
5010 | +void br_handle_frame(struct sk_buff *skb); | |
5011 | + | |
5012 | +/* br_ioctl.c */ | |
5013 | +int br_ioctl(struct net_bridge *br, | |
5014 | + unsigned int cmd, | |
5015 | + unsigned long arg0, | |
5016 | + unsigned long arg1, | |
5017 | + unsigned long arg2); | |
5018 | +int br_ioctl_deviceless_stub(unsigned long arg); | |
5019 | + | |
5020 | +/* br_stp.c */ | |
5021 | +int br_is_root_bridge(struct net_bridge *br); | |
5022 | +struct net_bridge_port *br_get_port(struct net_bridge *br, | |
5023 | + int port_no); | |
5024 | +void br_init_port(struct net_bridge_port *p); | |
5025 | +port_id br_make_port_id(struct net_bridge_port *p); | |
5026 | +void br_become_designated_port(struct net_bridge_port *p); | |
5027 | + | |
5028 | +/* br_stp_if.c */ | |
5029 | +void br_stp_enable_bridge(struct net_bridge *br); | |
5030 | +void br_stp_disable_bridge(struct net_bridge *br); | |
5031 | +void br_stp_enable_port(struct net_bridge_port *p); | |
5032 | +void br_stp_disable_port(struct net_bridge_port *p); | |
5033 | +void br_stp_recalculate_bridge_id(struct net_bridge *br); | |
5034 | +void br_stp_set_bridge_priority(struct net_bridge *br, | |
5035 | + int newprio); | |
5036 | +void br_stp_set_port_priority(struct net_bridge_port *p, | |
5037 | + int newprio); | |
5038 | +void br_stp_set_path_cost(struct net_bridge_port *p, | |
5039 | + int path_cost); | |
5040 | + | |
5041 | +/* br_stp_bpdu.c */ | |
5042 | +void br_stp_handle_bpdu(struct sk_buff *skb); | |
5043 | + | |
5044 | +#endif | |
5045 | diff -urN linux-2.2.19/net/bridge/br_private_stp.h linux-2.2.19br/net/bridge/br_private_stp.h | |
5046 | --- linux-2.2.19/net/bridge/br_private_stp.h Thu Jan 1 01:00:00 1970 | |
5047 | +++ linux-2.2.19br/net/bridge/br_private_stp.h Tue Apr 3 11:32:58 2001 | |
5048 | @@ -0,0 +1,53 @@ | |
5049 | +/* | |
5050 | + * Linux ethernet bridge | |
5051 | + * | |
5052 | + * Authors: | |
5053 | + * Lennert Buytenhek <buytenh@gnu.org> | |
5054 | + * | |
5055 | + * $Id$ | |
5056 | + * | |
5057 | + * This program is free software; you can redistribute it and/or | |
5058 | + * modify it under the terms of the GNU General Public License | |
5059 | + * as published by the Free Software Foundation; either version | |
5060 | + * 2 of the License, or (at your option) any later version. | |
5061 | + */ | |
5062 | + | |
5063 | +#ifndef _BR_PRIVATE_STP_H | |
5064 | +#define _BR_PRIVATE_STP_H | |
5065 | + | |
5066 | +#define BPDU_TYPE_CONFIG 0 | |
5067 | +#define BPDU_TYPE_TCN 0x80 | |
5068 | + | |
5069 | +struct br_config_bpdu | |
5070 | +{ | |
5071 | + unsigned topology_change:1; | |
5072 | + unsigned topology_change_ack:1; | |
5073 | + bridge_id root; | |
5074 | + int root_path_cost; | |
5075 | + bridge_id bridge_id; | |
5076 | + port_id port_id; | |
5077 | + int message_age; | |
5078 | + int max_age; | |
5079 | + int hello_time; | |
5080 | + int forward_delay; | |
5081 | +}; | |
5082 | + | |
5083 | +/* br_stp.c */ | |
5084 | +void br_become_root_bridge(struct net_bridge *br); | |
5085 | +void br_config_bpdu_generation(struct net_bridge *); | |
5086 | +void br_configuration_update(struct net_bridge *); | |
5087 | +int br_is_designated_port(struct net_bridge_port *p); | |
5088 | +int br_is_root_bridge(struct net_bridge *br); | |
5089 | +void br_port_state_selection(struct net_bridge *); | |
5090 | +void br_received_config_bpdu(struct net_bridge_port *p, struct br_config_bpdu *bpdu); | |
5091 | +void br_received_tcn_bpdu(struct net_bridge_port *p); | |
5092 | +void br_tick(unsigned long __data); | |
5093 | +void br_transmit_config(struct net_bridge_port *p); | |
5094 | +void br_transmit_tcn(struct net_bridge *br); | |
5095 | +void br_topology_change_detection(struct net_bridge *br); | |
5096 | + | |
5097 | +/* br_stp_bpdu.c */ | |
5098 | +void br_send_config_bpdu(struct net_bridge_port *, struct br_config_bpdu *); | |
5099 | +void br_send_tcn_bpdu(struct net_bridge_port *); | |
5100 | + | |
5101 | +#endif | |
5102 | diff -urN linux-2.2.19/net/bridge/br_stp.c linux-2.2.19br/net/bridge/br_stp.c | |
5103 | --- linux-2.2.19/net/bridge/br_stp.c Thu Jan 1 01:00:00 1970 | |
5104 | +++ linux-2.2.19br/net/bridge/br_stp.c Tue Apr 3 11:32:58 2001 | |
5105 | @@ -0,0 +1,467 @@ | |
5106 | +/* | |
5107 | + * Spanning tree protocol; generic parts | |
5108 | + * Linux ethernet bridge | |
5109 | + * | |
5110 | + * Authors: | |
5111 | + * Lennert Buytenhek <buytenh@gnu.org> | |
5112 | + * | |
5113 | + * $Id$ | |
5114 | + * | |
5115 | + * This program is free software; you can redistribute it and/or | |
5116 | + * modify it under the terms of the GNU General Public License | |
5117 | + * as published by the Free Software Foundation; either version | |
5118 | + * 2 of the License, or (at your option) any later version. | |
5119 | + */ | |
5120 | + | |
5121 | +#include <linux/config.h> | |
5122 | +#include <linux/kernel.h> | |
5123 | +#include <linux/if_bridge.h> | |
5124 | +#include <linux/smp_lock.h> | |
5125 | +#include <asm/uaccess.h> | |
5126 | +#include "br_private.h" | |
5127 | +#include "br_private_stp.h" | |
5128 | + | |
5129 | + | |
5130 | + | |
5131 | +/* called under ioctl_lock or bridge lock */ | |
5132 | +int br_is_root_bridge(struct net_bridge *br) | |
5133 | +{ | |
5134 | + return !memcmp(&br->bridge_id, &br->designated_root, 8); | |
5135 | +} | |
5136 | + | |
5137 | +/* called under bridge lock */ | |
5138 | +int br_is_designated_port(struct net_bridge_port *p) | |
5139 | +{ | |
5140 | + return !memcmp(&p->designated_bridge, &p->br->bridge_id, 8) && | |
5141 | + (p->designated_port == p->port_id); | |
5142 | +} | |
5143 | + | |
5144 | +/* called under ioctl_lock or bridge lock */ | |
5145 | +struct net_bridge_port *br_get_port(struct net_bridge *br, int port_no) | |
5146 | +{ | |
5147 | + struct net_bridge_port *p; | |
5148 | + | |
5149 | + p = br->port_list; | |
5150 | + while (p != NULL) { | |
5151 | + if (p->port_no == port_no) | |
5152 | + return p; | |
5153 | + | |
5154 | + p = p->next; | |
5155 | + } | |
5156 | + | |
5157 | + return NULL; | |
5158 | +} | |
5159 | + | |
5160 | +/* called under bridge lock */ | |
5161 | +static int br_should_become_root_port(struct net_bridge_port *p, int root_port) | |
5162 | +{ | |
5163 | + struct net_bridge *br; | |
5164 | + struct net_bridge_port *rp; | |
5165 | + int t; | |
5166 | + | |
5167 | + br = p->br; | |
5168 | + if (p->state == BR_STATE_DISABLED || | |
5169 | + br_is_designated_port(p)) | |
5170 | + return 0; | |
5171 | + | |
5172 | + if (memcmp(&br->bridge_id, &p->designated_root, 8) <= 0) | |
5173 | + return 0; | |
5174 | + | |
5175 | + if (!root_port) | |
5176 | + return 1; | |
5177 | + | |
5178 | + rp = br_get_port(br, root_port); | |
5179 | + | |
5180 | + t = memcmp(&p->designated_root, &rp->designated_root, 8); | |
5181 | + if (t < 0) | |
5182 | + return 1; | |
5183 | + else if (t > 0) | |
5184 | + return 0; | |
5185 | + | |
5186 | + if (p->designated_cost + p->path_cost < | |
5187 | + rp->designated_cost + rp->path_cost) | |
5188 | + return 1; | |
5189 | + else if (p->designated_cost + p->path_cost > | |
5190 | + rp->designated_cost + rp->path_cost) | |
5191 | + return 0; | |
5192 | + | |
5193 | + t = memcmp(&p->designated_bridge, &rp->designated_bridge, 8); | |
5194 | + if (t < 0) | |
5195 | + return 1; | |
5196 | + else if (t > 0) | |
5197 | + return 0; | |
5198 | + | |
5199 | + if (p->designated_port < rp->designated_port) | |
5200 | + return 1; | |
5201 | + else if (p->designated_port > rp->designated_port) | |
5202 | + return 0; | |
5203 | + | |
5204 | + if (p->port_id < rp->port_id) | |
5205 | + return 1; | |
5206 | + | |
5207 | + return 0; | |
5208 | +} | |
5209 | + | |
5210 | +/* called under bridge lock */ | |
5211 | +static void br_root_selection(struct net_bridge *br) | |
5212 | +{ | |
5213 | + struct net_bridge_port *p; | |
5214 | + int root_port; | |
5215 | + | |
5216 | + root_port = 0; | |
5217 | + | |
5218 | + p = br->port_list; | |
5219 | + while (p != NULL) { | |
5220 | + if (br_should_become_root_port(p, root_port)) | |
5221 | + root_port = p->port_no; | |
5222 | + | |
5223 | + p = p->next; | |
5224 | + } | |
5225 | + | |
5226 | + br->root_port = root_port; | |
5227 | + | |
5228 | + if (!root_port) { | |
5229 | + br->designated_root = br->bridge_id; | |
5230 | + br->root_path_cost = 0; | |
5231 | + } else { | |
5232 | + p = br_get_port(br, root_port); | |
5233 | + br->designated_root = p->designated_root; | |
5234 | + br->root_path_cost = p->designated_cost + p->path_cost; | |
5235 | + } | |
5236 | +} | |
5237 | + | |
5238 | +/* called under bridge lock */ | |
5239 | +void br_become_root_bridge(struct net_bridge *br) | |
5240 | +{ | |
5241 | + br->max_age = br->bridge_max_age; | |
5242 | + br->hello_time = br->bridge_hello_time; | |
5243 | + br->forward_delay = br->bridge_forward_delay; | |
5244 | + br_topology_change_detection(br); | |
5245 | + br_timer_clear(&br->tcn_timer); | |
5246 | + br_config_bpdu_generation(br); | |
5247 | + br_timer_set(&br->hello_timer, jiffies); | |
5248 | +} | |
5249 | + | |
5250 | +/* called under bridge lock */ | |
5251 | +void br_transmit_config(struct net_bridge_port *p) | |
5252 | +{ | |
5253 | + struct br_config_bpdu bpdu; | |
5254 | + struct net_bridge *br; | |
5255 | + | |
5256 | + if (br_timer_is_running(&p->hold_timer)) { | |
5257 | + p->config_pending = 1; | |
5258 | + return; | |
5259 | + } | |
5260 | + | |
5261 | + br = p->br; | |
5262 | + | |
5263 | + bpdu.topology_change = br->topology_change; | |
5264 | + bpdu.topology_change_ack = p->topology_change_ack; | |
5265 | + bpdu.root = br->designated_root; | |
5266 | + bpdu.root_path_cost = br->root_path_cost; | |
5267 | + bpdu.bridge_id = br->bridge_id; | |
5268 | + bpdu.port_id = p->port_id; | |
5269 | + bpdu.message_age = 0; | |
5270 | + if (!br_is_root_bridge(br)) { | |
5271 | + struct net_bridge_port *root; | |
5272 | + unsigned long age; | |
5273 | + | |
5274 | + root = br_get_port(br, br->root_port); | |
5275 | + age = br_timer_get_residue(&root->message_age_timer) + 1; | |
5276 | + bpdu.message_age = age; | |
5277 | + } | |
5278 | + bpdu.max_age = br->max_age; | |
5279 | + bpdu.hello_time = br->hello_time; | |
5280 | + bpdu.forward_delay = br->forward_delay; | |
5281 | + | |
5282 | + br_send_config_bpdu(p, &bpdu); | |
5283 | + | |
5284 | + p->topology_change_ack = 0; | |
5285 | + p->config_pending = 0; | |
5286 | + br_timer_set(&p->hold_timer, jiffies); | |
5287 | +} | |
5288 | + | |
5289 | +/* called under bridge lock */ | |
5290 | +static void br_record_config_information(struct net_bridge_port *p, struct br_config_bpdu *bpdu) | |
5291 | +{ | |
5292 | + p->designated_root = bpdu->root; | |
5293 | + p->designated_cost = bpdu->root_path_cost; | |
5294 | + p->designated_bridge = bpdu->bridge_id; | |
5295 | + p->designated_port = bpdu->port_id; | |
5296 | + | |
5297 | + br_timer_set(&p->message_age_timer, jiffies - bpdu->message_age); | |
5298 | +} | |
5299 | + | |
5300 | +/* called under bridge lock */ | |
5301 | +static void br_record_config_timeout_values(struct net_bridge *br, struct br_config_bpdu *bpdu) | |
5302 | +{ | |
5303 | + br->max_age = bpdu->max_age; | |
5304 | + br->hello_time = bpdu->hello_time; | |
5305 | + br->forward_delay = bpdu->forward_delay; | |
5306 | + br->topology_change = bpdu->topology_change; | |
5307 | +} | |
5308 | + | |
5309 | +/* called under bridge lock */ | |
5310 | +void br_transmit_tcn(struct net_bridge *br) | |
5311 | +{ | |
5312 | + br_send_tcn_bpdu(br_get_port(br, br->root_port)); | |
5313 | +} | |
5314 | + | |
5315 | +/* called under bridge lock */ | |
5316 | +static int br_should_become_designated_port(struct net_bridge_port *p) | |
5317 | +{ | |
5318 | + struct net_bridge *br; | |
5319 | + int t; | |
5320 | + | |
5321 | + br = p->br; | |
5322 | + if (br_is_designated_port(p)) | |
5323 | + return 1; | |
5324 | + | |
5325 | + if (memcmp(&p->designated_root, &br->designated_root, 8)) | |
5326 | + return 1; | |
5327 | + | |
5328 | + if (br->root_path_cost < p->designated_cost) | |
5329 | + return 1; | |
5330 | + else if (br->root_path_cost > p->designated_cost) | |
5331 | + return 0; | |
5332 | + | |
5333 | + t = memcmp(&br->bridge_id, &p->designated_bridge, 8); | |
5334 | + if (t < 0) | |
5335 | + return 1; | |
5336 | + else if (t > 0) | |
5337 | + return 0; | |
5338 | + | |
5339 | + if (p->port_id < p->designated_port) | |
5340 | + return 1; | |
5341 | + | |
5342 | + return 0; | |
5343 | +} | |
5344 | + | |
5345 | +/* called under bridge lock */ | |
5346 | +static void br_designated_port_selection(struct net_bridge *br) | |
5347 | +{ | |
5348 | + struct net_bridge_port *p; | |
5349 | + | |
5350 | + p = br->port_list; | |
5351 | + while (p != NULL) { | |
5352 | + if (p->state != BR_STATE_DISABLED && | |
5353 | + br_should_become_designated_port(p)) | |
5354 | + br_become_designated_port(p); | |
5355 | + | |
5356 | + p = p->next; | |
5357 | + } | |
5358 | +} | |
5359 | + | |
5360 | +/* called under bridge lock */ | |
5361 | +static int br_supersedes_port_info(struct net_bridge_port *p, struct br_config_bpdu *bpdu) | |
5362 | +{ | |
5363 | + int t; | |
5364 | + | |
5365 | + t = memcmp(&bpdu->root, &p->designated_root, 8); | |
5366 | + if (t < 0) | |
5367 | + return 1; | |
5368 | + else if (t > 0) | |
5369 | + return 0; | |
5370 | + | |
5371 | + if (bpdu->root_path_cost < p->designated_cost) | |
5372 | + return 1; | |
5373 | + else if (bpdu->root_path_cost > p->designated_cost) | |
5374 | + return 0; | |
5375 | + | |
5376 | + t = memcmp(&bpdu->bridge_id, &p->designated_bridge, 8); | |
5377 | + if (t < 0) | |
5378 | + return 1; | |
5379 | + else if (t > 0) | |
5380 | + return 0; | |
5381 | + | |
5382 | + if (memcmp(&bpdu->bridge_id, &p->br->bridge_id, 8)) | |
5383 | + return 1; | |
5384 | + | |
5385 | + if (bpdu->port_id <= p->designated_port) | |
5386 | + return 1; | |
5387 | + | |
5388 | + return 0; | |
5389 | +} | |
5390 | + | |
5391 | +/* called under bridge lock */ | |
5392 | +static void br_topology_change_acknowledged(struct net_bridge *br) | |
5393 | +{ | |
5394 | + br->topology_change_detected = 0; | |
5395 | + br_timer_clear(&br->tcn_timer); | |
5396 | +} | |
5397 | + | |
5398 | +/* called under bridge lock */ | |
5399 | +void br_topology_change_detection(struct net_bridge *br) | |
5400 | +{ | |
5401 | + printk(KERN_INFO "%s: topology change detected", br->name); | |
5402 | + | |
5403 | + if (br_is_root_bridge(br)) { | |
5404 | + printk(", propagating"); | |
5405 | + br->topology_change = 1; | |
5406 | + br_timer_set(&br->topology_change_timer, jiffies); | |
5407 | + } else if (!br->topology_change_detected) { | |
5408 | + printk(", sending tcn bpdu"); | |
5409 | + br_transmit_tcn(br); | |
5410 | + br_timer_set(&br->tcn_timer, jiffies); | |
5411 | + } | |
5412 | + | |
5413 | + printk("\n"); | |
5414 | + br->topology_change_detected = 1; | |
5415 | +} | |
5416 | + | |
5417 | +/* called under bridge lock */ | |
5418 | +void br_config_bpdu_generation(struct net_bridge *br) | |
5419 | +{ | |
5420 | + struct net_bridge_port *p; | |
5421 | + | |
5422 | + p = br->port_list; | |
5423 | + while (p != NULL) { | |
5424 | + if (p->state != BR_STATE_DISABLED && | |
5425 | + br_is_designated_port(p)) | |
5426 | + br_transmit_config(p); | |
5427 | + | |
5428 | + p = p->next; | |
5429 | + } | |
5430 | +} | |
5431 | + | |
5432 | +/* called under bridge lock */ | |
5433 | +static void br_reply(struct net_bridge_port *p) | |
5434 | +{ | |
5435 | + br_transmit_config(p); | |
5436 | +} | |
5437 | + | |
5438 | +/* called under bridge lock */ | |
5439 | +void br_configuration_update(struct net_bridge *br) | |
5440 | +{ | |
5441 | + br_root_selection(br); | |
5442 | + br_designated_port_selection(br); | |
5443 | +} | |
5444 | + | |
5445 | +/* called under bridge lock */ | |
5446 | +void br_become_designated_port(struct net_bridge_port *p) | |
5447 | +{ | |
5448 | + struct net_bridge *br; | |
5449 | + | |
5450 | + br = p->br; | |
5451 | + p->designated_root = br->designated_root; | |
5452 | + p->designated_cost = br->root_path_cost; | |
5453 | + p->designated_bridge = br->bridge_id; | |
5454 | + p->designated_port = p->port_id; | |
5455 | +} | |
5456 | + | |
5457 | +/* called under bridge lock */ | |
5458 | +static void br_make_blocking(struct net_bridge_port *p) | |
5459 | +{ | |
5460 | + if (p->state != BR_STATE_DISABLED && | |
5461 | + p->state != BR_STATE_BLOCKING) { | |
5462 | + if (p->state == BR_STATE_FORWARDING || | |
5463 | + p->state == BR_STATE_LEARNING) | |
5464 | + br_topology_change_detection(p->br); | |
5465 | + | |
5466 | + printk(KERN_INFO "%s: port %i(%s) entering %s state\n", | |
5467 | + p->br->name, p->port_no, p->dev->name, "blocking"); | |
5468 | + | |
5469 | + p->state = BR_STATE_BLOCKING; | |
5470 | + br_timer_clear(&p->forward_delay_timer); | |
5471 | + } | |
5472 | +} | |
5473 | + | |
5474 | +/* called under bridge lock */ | |
5475 | +static void br_make_forwarding(struct net_bridge_port *p) | |
5476 | +{ | |
5477 | + if (p->state == BR_STATE_BLOCKING) { | |
5478 | + printk(KERN_INFO "%s: port %i(%s) entering %s state\n", | |
5479 | + p->br->name, p->port_no, p->dev->name, "listening"); | |
5480 | + | |
5481 | + p->state = BR_STATE_LISTENING; | |
5482 | + br_timer_set(&p->forward_delay_timer, jiffies); | |
5483 | + } | |
5484 | +} | |
5485 | + | |
5486 | +/* called under bridge lock */ | |
5487 | +void br_port_state_selection(struct net_bridge *br) | |
5488 | +{ | |
5489 | + struct net_bridge_port *p; | |
5490 | + | |
5491 | + p = br->port_list; | |
5492 | + while (p != NULL) { | |
5493 | + if (p->state != BR_STATE_DISABLED) { | |
5494 | + if (p->port_no == br->root_port) { | |
5495 | + p->config_pending = 0; | |
5496 | + p->topology_change_ack = 0; | |
5497 | + br_make_forwarding(p); | |
5498 | + } else if (br_is_designated_port(p)) { | |
5499 | + br_timer_clear(&p->message_age_timer); | |
5500 | + br_make_forwarding(p); | |
5501 | + } else { | |
5502 | + p->config_pending = 0; | |
5503 | + p->topology_change_ack = 0; | |
5504 | + br_make_blocking(p); | |
5505 | + } | |
5506 | + } | |
5507 | + | |
5508 | + p = p->next; | |
5509 | + } | |
5510 | +} | |
5511 | + | |
5512 | +/* called under bridge lock */ | |
5513 | +static void br_topology_change_acknowledge(struct net_bridge_port *p) | |
5514 | +{ | |
5515 | + p->topology_change_ack = 1; | |
5516 | + br_transmit_config(p); | |
5517 | +} | |
5518 | + | |
5519 | +/* lock-safe */ | |
5520 | +void br_received_config_bpdu(struct net_bridge_port *p, struct br_config_bpdu *bpdu) | |
5521 | +{ | |
5522 | + struct net_bridge *br; | |
5523 | + int was_root; | |
5524 | + | |
5525 | + if (p->state == BR_STATE_DISABLED) | |
5526 | + return; | |
5527 | + | |
5528 | + br = p->br; | |
5529 | + read_lock(&br->lock); | |
5530 | + | |
5531 | + was_root = br_is_root_bridge(br); | |
5532 | + if (br_supersedes_port_info(p, bpdu)) { | |
5533 | + br_record_config_information(p, bpdu); | |
5534 | + br_configuration_update(br); | |
5535 | + br_port_state_selection(br); | |
5536 | + | |
5537 | + if (!br_is_root_bridge(br) && was_root) { | |
5538 | + br_timer_clear(&br->hello_timer); | |
5539 | + if (br->topology_change_detected) { | |
5540 | + br_timer_clear(&br->topology_change_timer); | |
5541 | + br_transmit_tcn(br); | |
5542 | + br_timer_set(&br->tcn_timer, jiffies); | |
5543 | + } | |
5544 | + } | |
5545 | + | |
5546 | + if (p->port_no == br->root_port) { | |
5547 | + br_record_config_timeout_values(br, bpdu); | |
5548 | + br_config_bpdu_generation(br); | |
5549 | + if (bpdu->topology_change_ack) | |
5550 | + br_topology_change_acknowledged(br); | |
5551 | + } | |
5552 | + } else if (br_is_designated_port(p)) { | |
5553 | + br_reply(p); | |
5554 | + } | |
5555 | + | |
5556 | + read_unlock(&br->lock); | |
5557 | +} | |
5558 | + | |
5559 | +/* lock-safe */ | |
5560 | +void br_received_tcn_bpdu(struct net_bridge_port *p) | |
5561 | +{ | |
5562 | + read_lock(&p->br->lock); | |
5563 | + if (p->state != BR_STATE_DISABLED && | |
5564 | + br_is_designated_port(p)) { | |
5565 | + printk(KERN_INFO "%s: received tcn bpdu on port %i(%s)\n", | |
5566 | + p->br->name, p->port_no, p->dev->name); | |
5567 | + | |
5568 | + br_topology_change_detection(p->br); | |
5569 | + br_topology_change_acknowledge(p); | |
5570 | + } | |
5571 | + read_unlock(&p->br->lock); | |
5572 | +} | |
5573 | diff -urN linux-2.2.19/net/bridge/br_stp_bpdu.c linux-2.2.19br/net/bridge/br_stp_bpdu.c | |
5574 | --- linux-2.2.19/net/bridge/br_stp_bpdu.c Thu Jan 1 01:00:00 1970 | |
5575 | +++ linux-2.2.19br/net/bridge/br_stp_bpdu.c Tue Apr 3 11:32:58 2001 | |
5576 | @@ -0,0 +1,189 @@ | |
5577 | +/* | |
5578 | + * Spanning tree protocol; BPDU handling | |
5579 | + * Linux ethernet bridge | |
5580 | + * | |
5581 | + * Authors: | |
5582 | + * Lennert Buytenhek <buytenh@gnu.org> | |
5583 | + * | |
5584 | + * $Id$ | |
5585 | + * | |
5586 | + * This program is free software; you can redistribute it and/or | |
5587 | + * modify it under the terms of the GNU General Public License | |
5588 | + * as published by the Free Software Foundation; either version | |
5589 | + * 2 of the License, or (at your option) any later version. | |
5590 | + */ | |
5591 | + | |
5592 | +#include <linux/config.h> | |
5593 | +#include <linux/kernel.h> | |
5594 | +#include <linux/if_bridge.h> | |
5595 | +#include "br_private.h" | |
5596 | +#include "br_private_stp.h" | |
5597 | + | |
5598 | +#define JIFFIES_TO_TICKS(j) (((j) << 8) / HZ) | |
5599 | +#define TICKS_TO_JIFFIES(j) (((j) * HZ) >> 8) | |
5600 | + | |
5601 | +static void br_send_bpdu(struct net_bridge_port *p, unsigned char *data, int length) | |
5602 | +{ | |
5603 | + struct device *dev; | |
5604 | + struct sk_buff *skb; | |
5605 | + int size; | |
5606 | + | |
5607 | + if (!p->br->stp_enabled) | |
5608 | + return; | |
5609 | + | |
5610 | + size = length + 2*ETH_ALEN + 2; | |
5611 | + if (size < 60) | |
5612 | + size = 60; | |
5613 | + | |
5614 | + dev = p->dev; | |
5615 | + | |
5616 | + if ((skb = dev_alloc_skb(size)) == NULL) { | |
5617 | + printk(KERN_INFO "br: memory squeeze!\n"); | |
5618 | + return; | |
5619 | + } | |
5620 | + | |
5621 | + skb->dev = dev; | |
5622 | + skb->mac.raw = skb_put(skb, size); | |
5623 | + memcpy(skb->mac.raw, bridge_ula, ETH_ALEN); | |
5624 | + memcpy(skb->mac.raw+ETH_ALEN, dev->dev_addr, ETH_ALEN); | |
5625 | + skb->mac.raw[2*ETH_ALEN] = 0; | |
5626 | + skb->mac.raw[2*ETH_ALEN+1] = length; | |
5627 | + skb->nh.raw = skb->mac.raw + 2*ETH_ALEN + 2; | |
5628 | + memcpy(skb->nh.raw, data, length); | |
5629 | + memset(skb->nh.raw + length, 0xa5, size - length - 2*ETH_ALEN - 2); | |
5630 | + | |
5631 | + dev_queue_xmit(skb); | |
5632 | +} | |
5633 | + | |
5634 | +static __inline__ void br_set_ticks(unsigned char *dest, int jiff) | |
5635 | +{ | |
5636 | + __u16 ticks; | |
5637 | + | |
5638 | + ticks = JIFFIES_TO_TICKS(jiff); | |
5639 | + dest[0] = (ticks >> 8) & 0xFF; | |
5640 | + dest[1] = ticks & 0xFF; | |
5641 | +} | |
5642 | + | |
5643 | +static __inline__ int br_get_ticks(unsigned char *dest) | |
5644 | +{ | |
5645 | + return TICKS_TO_JIFFIES((dest[0] << 8) | dest[1]); | |
5646 | +} | |
5647 | + | |
5648 | +void br_send_config_bpdu(struct net_bridge_port *p, struct br_config_bpdu *bpdu) | |
5649 | +{ | |
5650 | + unsigned char buf[38]; | |
5651 | + | |
5652 | + buf[0] = 0x42; | |
5653 | + buf[1] = 0x42; | |
5654 | + buf[2] = 0x03; | |
5655 | + buf[3] = 0; | |
5656 | + buf[4] = 0; | |
5657 | + buf[5] = 0; | |
5658 | + buf[6] = BPDU_TYPE_CONFIG; | |
5659 | + buf[7] = (bpdu->topology_change ? 0x01 : 0) | | |
5660 | + (bpdu->topology_change_ack ? 0x80 : 0); | |
5661 | + buf[8] = bpdu->root.prio[0]; | |
5662 | + buf[9] = bpdu->root.prio[1]; | |
5663 | + buf[10] = bpdu->root.addr[0]; | |
5664 | + buf[11] = bpdu->root.addr[1]; | |
5665 | + buf[12] = bpdu->root.addr[2]; | |
5666 | + buf[13] = bpdu->root.addr[3]; | |
5667 | + buf[14] = bpdu->root.addr[4]; | |
5668 | + buf[15] = bpdu->root.addr[5]; | |
5669 | + buf[16] = (bpdu->root_path_cost >> 24) & 0xFF; | |
5670 | + buf[17] = (bpdu->root_path_cost >> 16) & 0xFF; | |
5671 | + buf[18] = (bpdu->root_path_cost >> 8) & 0xFF; | |
5672 | + buf[19] = bpdu->root_path_cost & 0xFF; | |
5673 | + buf[20] = bpdu->bridge_id.prio[0]; | |
5674 | + buf[21] = bpdu->bridge_id.prio[1]; | |
5675 | + buf[22] = bpdu->bridge_id.addr[0]; | |
5676 | + buf[23] = bpdu->bridge_id.addr[1]; | |
5677 | + buf[24] = bpdu->bridge_id.addr[2]; | |
5678 | + buf[25] = bpdu->bridge_id.addr[3]; | |
5679 | + buf[26] = bpdu->bridge_id.addr[4]; | |
5680 | + buf[27] = bpdu->bridge_id.addr[5]; | |
5681 | + buf[28] = (bpdu->port_id >> 8) & 0xFF; | |
5682 | + buf[29] = bpdu->port_id & 0xFF; | |
5683 | + | |
5684 | + br_set_ticks(buf+30, bpdu->message_age); | |
5685 | + br_set_ticks(buf+32, bpdu->max_age); | |
5686 | + br_set_ticks(buf+34, bpdu->hello_time); | |
5687 | + br_set_ticks(buf+36, bpdu->forward_delay); | |
5688 | + | |
5689 | + br_send_bpdu(p, buf, 38); | |
5690 | +} | |
5691 | + | |
5692 | +void br_send_tcn_bpdu(struct net_bridge_port *p) | |
5693 | +{ | |
5694 | + unsigned char buf[7]; | |
5695 | + | |
5696 | + buf[0] = 0x42; | |
5697 | + buf[1] = 0x42; | |
5698 | + buf[2] = 0x03; | |
5699 | + buf[3] = 0; | |
5700 | + buf[4] = 0; | |
5701 | + buf[5] = 0; | |
5702 | + buf[6] = BPDU_TYPE_TCN; | |
5703 | + br_send_bpdu(p, buf, 7); | |
5704 | +} | |
5705 | + | |
5706 | +static unsigned char header[6] = {0x42, 0x42, 0x03, 0x00, 0x00, 0x00}; | |
5707 | + | |
5708 | +void br_stp_handle_bpdu(struct sk_buff *skb) | |
5709 | +{ | |
5710 | + unsigned char *buf; | |
5711 | + struct net_bridge_port *p; | |
5712 | + | |
5713 | + buf = skb->mac.raw + 14; | |
5714 | + p = skb->dev->br_port; | |
5715 | + if (!p->br->stp_enabled || memcmp(buf, header, 6)) { | |
5716 | + kfree_skb(skb); | |
5717 | + return; | |
5718 | + } | |
5719 | + | |
5720 | + if (buf[6] == BPDU_TYPE_CONFIG) { | |
5721 | + struct br_config_bpdu bpdu; | |
5722 | + | |
5723 | + bpdu.topology_change = (buf[7] & 0x01) ? 1 : 0; | |
5724 | + bpdu.topology_change_ack = (buf[7] & 0x80) ? 1 : 0; | |
5725 | + bpdu.root.prio[0] = buf[8]; | |
5726 | + bpdu.root.prio[1] = buf[9]; | |
5727 | + bpdu.root.addr[0] = buf[10]; | |
5728 | + bpdu.root.addr[1] = buf[11]; | |
5729 | + bpdu.root.addr[2] = buf[12]; | |
5730 | + bpdu.root.addr[3] = buf[13]; | |
5731 | + bpdu.root.addr[4] = buf[14]; | |
5732 | + bpdu.root.addr[5] = buf[15]; | |
5733 | + bpdu.root_path_cost = | |
5734 | + (buf[16] << 24) | | |
5735 | + (buf[17] << 16) | | |
5736 | + (buf[18] << 8) | | |
5737 | + buf[19]; | |
5738 | + bpdu.bridge_id.prio[0] = buf[20]; | |
5739 | + bpdu.bridge_id.prio[1] = buf[21]; | |
5740 | + bpdu.bridge_id.addr[0] = buf[22]; | |
5741 | + bpdu.bridge_id.addr[1] = buf[23]; | |
5742 | + bpdu.bridge_id.addr[2] = buf[24]; | |
5743 | + bpdu.bridge_id.addr[3] = buf[25]; | |
5744 | + bpdu.bridge_id.addr[4] = buf[26]; | |
5745 | + bpdu.bridge_id.addr[5] = buf[27]; | |
5746 | + bpdu.port_id = (buf[28] << 8) | buf[29]; | |
5747 | + | |
5748 | + bpdu.message_age = br_get_ticks(buf+30); | |
5749 | + bpdu.max_age = br_get_ticks(buf+32); | |
5750 | + bpdu.hello_time = br_get_ticks(buf+34); | |
5751 | + bpdu.forward_delay = br_get_ticks(buf+36); | |
5752 | + | |
5753 | + kfree_skb(skb); | |
5754 | + br_received_config_bpdu(p, &bpdu); | |
5755 | + return; | |
5756 | + } | |
5757 | + | |
5758 | + if (buf[6] == BPDU_TYPE_TCN) { | |
5759 | + br_received_tcn_bpdu(p); | |
5760 | + kfree_skb(skb); | |
5761 | + return; | |
5762 | + } | |
5763 | + | |
5764 | + kfree_skb(skb); | |
5765 | +} | |
5766 | diff -urN linux-2.2.19/net/bridge/br_stp_if.c linux-2.2.19br/net/bridge/br_stp_if.c | |
5767 | --- linux-2.2.19/net/bridge/br_stp_if.c Thu Jan 1 01:00:00 1970 | |
5768 | +++ linux-2.2.19br/net/bridge/br_stp_if.c Tue Apr 3 11:32:58 2001 | |
5769 | @@ -0,0 +1,229 @@ | |
5770 | +/* | |
5771 | + * Spanning tree protocol; interface code | |
5772 | + * Linux ethernet bridge | |
5773 | + * | |
5774 | + * Authors: | |
5775 | + * Lennert Buytenhek <buytenh@gnu.org> | |
5776 | + * | |
5777 | + * $Id$ | |
5778 | + * | |
5779 | + * This program is free software; you can redistribute it and/or | |
5780 | + * modify it under the terms of the GNU General Public License | |
5781 | + * as published by the Free Software Foundation; either version | |
5782 | + * 2 of the License, or (at your option) any later version. | |
5783 | + */ | |
5784 | + | |
5785 | +#include <linux/config.h> | |
5786 | +#include <linux/kernel.h> | |
5787 | +#include <linux/types.h> | |
5788 | +#include <linux/notifier.h> | |
5789 | +#include <linux/if_bridge.h> | |
5790 | +#include <linux/smp_lock.h> | |
5791 | +#include <asm/uaccess.h> | |
5792 | +#include "br_private.h" | |
5793 | +#include "br_private_stp.h" | |
5794 | + | |
5795 | +__u16 br_make_port_id(struct net_bridge_port *p) | |
5796 | +{ | |
5797 | + return (p->priority << 8) | p->port_no; | |
5798 | +} | |
5799 | + | |
5800 | +/* called under bridge lock */ | |
5801 | +void br_init_port(struct net_bridge_port *p) | |
5802 | +{ | |
5803 | + p->port_id = br_make_port_id(p); | |
5804 | + br_become_designated_port(p); | |
5805 | + p->state = BR_STATE_BLOCKING; | |
5806 | + p->topology_change_ack = 0; | |
5807 | + p->config_pending = 0; | |
5808 | + br_timer_clear(&p->message_age_timer); | |
5809 | + br_timer_clear(&p->forward_delay_timer); | |
5810 | + br_timer_clear(&p->hold_timer); | |
5811 | +} | |
5812 | + | |
5813 | +/* called under bridge lock */ | |
5814 | +void br_stp_enable_bridge(struct net_bridge *br) | |
5815 | +{ | |
5816 | + struct net_bridge_port *p; | |
5817 | + struct timer_list *timer = &br->tick; | |
5818 | + | |
5819 | + init_timer(timer); | |
5820 | + timer->data = (unsigned long) br; | |
5821 | + timer->function = br_tick; | |
5822 | + timer->expires = jiffies + 1; | |
5823 | + add_timer(timer); | |
5824 | + | |
5825 | + br_timer_set(&br->hello_timer, jiffies); | |
5826 | + br_config_bpdu_generation(br); | |
5827 | + | |
5828 | + p = br->port_list; | |
5829 | + while (p != NULL) { | |
5830 | + if (p->dev->flags & IFF_UP) | |
5831 | + br_stp_enable_port(p); | |
5832 | + | |
5833 | + p = p->next; | |
5834 | + } | |
5835 | + | |
5836 | + br_timer_set(&br->gc_timer, jiffies); | |
5837 | +} | |
5838 | + | |
5839 | +/* called under bridge lock */ | |
5840 | +void br_stp_disable_bridge(struct net_bridge *br) | |
5841 | +{ | |
5842 | + struct net_bridge_port *p; | |
5843 | + | |
5844 | + br->topology_change = 0; | |
5845 | + br->topology_change_detected = 0; | |
5846 | + br_timer_clear(&br->hello_timer); | |
5847 | + br_timer_clear(&br->topology_change_timer); | |
5848 | + br_timer_clear(&br->tcn_timer); | |
5849 | + br_timer_clear(&br->gc_timer); | |
5850 | + br_fdb_cleanup(br); | |
5851 | + | |
5852 | + p = br->port_list; | |
5853 | + while (p != NULL) { | |
5854 | + if (p->state != BR_STATE_DISABLED) | |
5855 | + br_stp_disable_port(p); | |
5856 | + | |
5857 | + p = p->next; | |
5858 | + } | |
5859 | + | |
5860 | + del_timer(&br->tick); | |
5861 | + synchronize_bh(); | |
5862 | +} | |
5863 | + | |
5864 | +/* called under bridge lock */ | |
5865 | +void br_stp_enable_port(struct net_bridge_port *p) | |
5866 | +{ | |
5867 | + br_init_port(p); | |
5868 | + br_port_state_selection(p->br); | |
5869 | +} | |
5870 | + | |
5871 | +/* called under bridge lock */ | |
5872 | +void br_stp_disable_port(struct net_bridge_port *p) | |
5873 | +{ | |
5874 | + struct net_bridge *br; | |
5875 | + int wasroot; | |
5876 | + | |
5877 | + br = p->br; | |
5878 | + printk(KERN_INFO "%s: port %i(%s) entering %s state\n", | |
5879 | + br->name, p->port_no, p->dev->name, "disabled"); | |
5880 | + | |
5881 | + wasroot = br_is_root_bridge(br); | |
5882 | + br_become_designated_port(p); | |
5883 | + p->state = BR_STATE_DISABLED; | |
5884 | + p->topology_change_ack = 0; | |
5885 | + p->config_pending = 0; | |
5886 | + br_timer_clear(&p->message_age_timer); | |
5887 | + br_timer_clear(&p->forward_delay_timer); | |
5888 | + br_timer_clear(&p->hold_timer); | |
5889 | + br_configuration_update(br); | |
5890 | + br_port_state_selection(br); | |
5891 | + | |
5892 | + if (br_is_root_bridge(br) && !wasroot) | |
5893 | + br_become_root_bridge(br); | |
5894 | +} | |
5895 | + | |
5896 | +/* called under bridge lock */ | |
5897 | +static void br_stp_change_bridge_id(struct net_bridge *br, unsigned char *addr) | |
5898 | +{ | |
5899 | + unsigned char oldaddr[6]; | |
5900 | + struct net_bridge_port *p; | |
5901 | + int wasroot; | |
5902 | + | |
5903 | + wasroot = br_is_root_bridge(br); | |
5904 | + | |
5905 | + memcpy(oldaddr, br->bridge_id.addr, ETH_ALEN); | |
5906 | + memcpy(br->bridge_id.addr, addr, ETH_ALEN); | |
5907 | + memcpy(br->dev.dev_addr, addr, ETH_ALEN); | |
5908 | + | |
5909 | + p = br->port_list; | |
5910 | + while (p != NULL) { | |
5911 | + if (!memcmp(p->designated_bridge.addr, oldaddr, ETH_ALEN)) | |
5912 | + memcpy(p->designated_bridge.addr, addr, ETH_ALEN); | |
5913 | + | |
5914 | + if (!memcmp(p->designated_root.addr, oldaddr, ETH_ALEN)) | |
5915 | + memcpy(p->designated_root.addr, addr, ETH_ALEN); | |
5916 | + | |
5917 | + p = p->next; | |
5918 | + } | |
5919 | + | |
5920 | + br_configuration_update(br); | |
5921 | + br_port_state_selection(br); | |
5922 | + if (br_is_root_bridge(br) && !wasroot) | |
5923 | + br_become_root_bridge(br); | |
5924 | +} | |
5925 | + | |
5926 | +static unsigned char br_mac_zero[6] = {0,0,0,0,0,0}; | |
5927 | + | |
5928 | +/* called under bridge lock */ | |
5929 | +void br_stp_recalculate_bridge_id(struct net_bridge *br) | |
5930 | +{ | |
5931 | + unsigned char *addr; | |
5932 | + struct net_bridge_port *p; | |
5933 | + | |
5934 | + addr = br_mac_zero; | |
5935 | + | |
5936 | + p = br->port_list; | |
5937 | + while (p != NULL) { | |
5938 | + if (addr == br_mac_zero || | |
5939 | + memcmp(p->dev->dev_addr, addr, ETH_ALEN) < 0) | |
5940 | + addr = p->dev->dev_addr; | |
5941 | + | |
5942 | + p = p->next; | |
5943 | + } | |
5944 | + | |
5945 | + if (memcmp(br->bridge_id.addr, addr, ETH_ALEN)) | |
5946 | + br_stp_change_bridge_id(br, addr); | |
5947 | +} | |
5948 | + | |
5949 | +/* called under bridge lock */ | |
5950 | +void br_stp_set_bridge_priority(struct net_bridge *br, int newprio) | |
5951 | +{ | |
5952 | + struct net_bridge_port *p; | |
5953 | + int wasroot; | |
5954 | + | |
5955 | + wasroot = br_is_root_bridge(br); | |
5956 | + | |
5957 | + p = br->port_list; | |
5958 | + while (p != NULL) { | |
5959 | + if (p->state != BR_STATE_DISABLED && | |
5960 | + br_is_designated_port(p)) { | |
5961 | + p->designated_bridge.prio[0] = (newprio >> 8) & 0xFF; | |
5962 | + p->designated_bridge.prio[1] = newprio & 0xFF; | |
5963 | + } | |
5964 | + | |
5965 | + p = p->next; | |
5966 | + } | |
5967 | + | |
5968 | + br->bridge_id.prio[0] = (newprio >> 8) & 0xFF; | |
5969 | + br->bridge_id.prio[1] = newprio & 0xFF; | |
5970 | + br_configuration_update(br); | |
5971 | + br_port_state_selection(br); | |
5972 | + if (br_is_root_bridge(br) && !wasroot) | |
5973 | + br_become_root_bridge(br); | |
5974 | +} | |
5975 | + | |
5976 | +/* called under bridge lock */ | |
5977 | +void br_stp_set_port_priority(struct net_bridge_port *p, int newprio) | |
5978 | +{ | |
5979 | + int new_port_id = ((newprio & 0xFF) << 8) | p->port_no; | |
5980 | + | |
5981 | + if (br_is_designated_port(p)) | |
5982 | + p->designated_port = new_port_id; | |
5983 | + | |
5984 | + p->port_id = new_port_id; | |
5985 | + if (!memcmp(&p->br->bridge_id, &p->designated_bridge, 8) && | |
5986 | + p->port_id < p->designated_port) { | |
5987 | + br_become_designated_port(p); | |
5988 | + br_port_state_selection(p->br); | |
5989 | + } | |
5990 | +} | |
5991 | + | |
5992 | +/* called under bridge lock */ | |
5993 | +void br_stp_set_path_cost(struct net_bridge_port *p, int path_cost) | |
5994 | +{ | |
5995 | + p->path_cost = path_cost; | |
5996 | + br_configuration_update(p->br); | |
5997 | + br_port_state_selection(p->br); | |
5998 | +} | |
5999 | diff -urN linux-2.2.19/net/bridge/br_stp_timer.c linux-2.2.19br/net/bridge/br_stp_timer.c | |
6000 | --- linux-2.2.19/net/bridge/br_stp_timer.c Thu Jan 1 01:00:00 1970 | |
6001 | +++ linux-2.2.19br/net/bridge/br_stp_timer.c Tue Apr 3 11:32:58 2001 | |
6002 | @@ -0,0 +1,185 @@ | |
6003 | +/* | |
6004 | + * Spanning tree protocol; timer-related code | |
6005 | + * Linux ethernet bridge | |
6006 | + * | |
6007 | + * Authors: | |
6008 | + * Lennert Buytenhek <buytenh@gnu.org> | |
6009 | + * | |
6010 | + * $Id$ | |
6011 | + * | |
6012 | + * This program is free software; you can redistribute it and/or | |
6013 | + * modify it under the terms of the GNU General Public License | |
6014 | + * as published by the Free Software Foundation; either version | |
6015 | + * 2 of the License, or (at your option) any later version. | |
6016 | + */ | |
6017 | + | |
6018 | +#include <linux/config.h> | |
6019 | +#include <linux/kernel.h> | |
6020 | +#include <linux/if_bridge.h> | |
6021 | +#include <linux/smp_lock.h> | |
6022 | +#include <asm/uaccess.h> | |
6023 | +#include "br_private.h" | |
6024 | +#include "br_private_stp.h" | |
6025 | + | |
6026 | +static void dump_bridge_id(bridge_id *id) | |
6027 | +{ | |
6028 | + printk("%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", id->prio[0], | |
6029 | + id->prio[1], id->addr[0], id->addr[1], id->addr[2], id->addr[3], | |
6030 | + id->addr[4], id->addr[5]); | |
6031 | +} | |
6032 | + | |
6033 | +/* called under bridge lock */ | |
6034 | +static int br_is_designated_for_some_port(struct net_bridge *br) | |
6035 | +{ | |
6036 | + struct net_bridge_port *p; | |
6037 | + | |
6038 | + p = br->port_list; | |
6039 | + while (p != NULL) { | |
6040 | + if (p->state != BR_STATE_DISABLED && | |
6041 | + !memcmp(&p->designated_bridge, &br->bridge_id, 8)) | |
6042 | + return 1; | |
6043 | + | |
6044 | + p = p->next; | |
6045 | + } | |
6046 | + | |
6047 | + return 0; | |
6048 | +} | |
6049 | + | |
6050 | +/* called under bridge lock */ | |
6051 | +static void br_hello_timer_expired(struct net_bridge *br) | |
6052 | +{ | |
6053 | + br_config_bpdu_generation(br); | |
6054 | + br_timer_set(&br->hello_timer, jiffies); | |
6055 | +} | |
6056 | + | |
6057 | +/* called under bridge lock */ | |
6058 | +static void br_message_age_timer_expired(struct net_bridge_port *p) | |
6059 | +{ | |
6060 | + struct net_bridge *br; | |
6061 | + int was_root; | |
6062 | + | |
6063 | + br = p->br; | |
6064 | + printk(KERN_INFO "%s: ", br->name); | |
6065 | + printk("neighbour "); | |
6066 | + dump_bridge_id(&p->designated_bridge); | |
6067 | + printk(" lost on port %i(%s)\n", p->port_no, p->dev->name); | |
6068 | + | |
6069 | + /* | |
6070 | + * According to the spec, the message age timer cannot be | |
6071 | + * running when we are the root bridge. So.. this was_root | |
6072 | + * check is redundant. I'm leaving it in for now, though. | |
6073 | + */ | |
6074 | + was_root = br_is_root_bridge(br); | |
6075 | + | |
6076 | + br_become_designated_port(p); | |
6077 | + br_configuration_update(br); | |
6078 | + br_port_state_selection(br); | |
6079 | + if (br_is_root_bridge(br) && !was_root) | |
6080 | + br_become_root_bridge(br); | |
6081 | +} | |
6082 | + | |
6083 | +/* called under bridge lock */ | |
6084 | +static void br_forward_delay_timer_expired(struct net_bridge_port *p) | |
6085 | +{ | |
6086 | + if (p->state == BR_STATE_LISTENING) { | |
6087 | + printk(KERN_INFO "%s: port %i(%s) entering %s state\n", | |
6088 | + p->br->name, p->port_no, p->dev->name, "learning"); | |
6089 | + | |
6090 | + p->state = BR_STATE_LEARNING; | |
6091 | + br_timer_set(&p->forward_delay_timer, jiffies); | |
6092 | + } else if (p->state == BR_STATE_LEARNING) { | |
6093 | + printk(KERN_INFO "%s: port %i(%s) entering %s state\n", | |
6094 | + p->br->name, p->port_no, p->dev->name, "forwarding"); | |
6095 | + | |
6096 | + p->state = BR_STATE_FORWARDING; | |
6097 | + if (br_is_designated_for_some_port(p->br)) | |
6098 | + br_topology_change_detection(p->br); | |
6099 | + } | |
6100 | +} | |
6101 | + | |
6102 | +/* called under bridge lock */ | |
6103 | +static void br_tcn_timer_expired(struct net_bridge *br) | |
6104 | +{ | |
6105 | + printk(KERN_INFO "%s: retransmitting tcn bpdu\n", br->name); | |
6106 | + br_transmit_tcn(br); | |
6107 | + br_timer_set(&br->tcn_timer, jiffies); | |
6108 | +} | |
6109 | + | |
6110 | +/* called under bridge lock */ | |
6111 | +static void br_topology_change_timer_expired(struct net_bridge *br) | |
6112 | +{ | |
6113 | + br->topology_change_detected = 0; | |
6114 | + br->topology_change = 0; | |
6115 | +} | |
6116 | + | |
6117 | +/* called under bridge lock */ | |
6118 | +static void br_hold_timer_expired(struct net_bridge_port *p) | |
6119 | +{ | |
6120 | + if (p->config_pending) | |
6121 | + br_transmit_config(p); | |
6122 | +} | |
6123 | + | |
6124 | +/* called under bridge lock */ | |
6125 | +static void br_check_port_timers(struct net_bridge_port *p) | |
6126 | +{ | |
6127 | + if (br_timer_has_expired(&p->message_age_timer, p->br->max_age)) { | |
6128 | + br_timer_clear(&p->message_age_timer); | |
6129 | + br_message_age_timer_expired(p); | |
6130 | + } | |
6131 | + | |
6132 | + if (br_timer_has_expired(&p->forward_delay_timer, p->br->forward_delay)) { | |
6133 | + br_timer_clear(&p->forward_delay_timer); | |
6134 | + br_forward_delay_timer_expired(p); | |
6135 | + } | |
6136 | + | |
6137 | + if (br_timer_has_expired(&p->hold_timer, BR_HOLD_TIME)) { | |
6138 | + br_timer_clear(&p->hold_timer); | |
6139 | + br_hold_timer_expired(p); | |
6140 | + } | |
6141 | +} | |
6142 | + | |
6143 | +/* called under bridge lock */ | |
6144 | +static void br_check_timers(struct net_bridge *br) | |
6145 | +{ | |
6146 | + struct net_bridge_port *p; | |
6147 | + | |
6148 | + if (br_timer_has_expired(&br->gc_timer, br->gc_interval)) { | |
6149 | + br_timer_set(&br->gc_timer, jiffies); | |
6150 | + br_fdb_cleanup(br); | |
6151 | + } | |
6152 | + | |
6153 | + if (br_timer_has_expired(&br->hello_timer, br->hello_time)) { | |
6154 | + br_timer_clear(&br->hello_timer); | |
6155 | + br_hello_timer_expired(br); | |
6156 | + } | |
6157 | + | |
6158 | + if (br_timer_has_expired(&br->tcn_timer, br->bridge_hello_time)) { | |
6159 | + br_timer_clear(&br->tcn_timer); | |
6160 | + br_tcn_timer_expired(br); | |
6161 | + } | |
6162 | + | |
6163 | + if (br_timer_has_expired(&br->topology_change_timer, br->bridge_forward_delay + br->bridge_max_age)) { | |
6164 | + br_timer_clear(&br->topology_change_timer); | |
6165 | + br_topology_change_timer_expired(br); | |
6166 | + } | |
6167 | + | |
6168 | + p = br->port_list; | |
6169 | + while (p != NULL) { | |
6170 | + if (p->state != BR_STATE_DISABLED) | |
6171 | + br_check_port_timers(p); | |
6172 | + | |
6173 | + p = p->next; | |
6174 | + } | |
6175 | +} | |
6176 | + | |
6177 | +void br_tick(unsigned long __data) | |
6178 | +{ | |
6179 | + struct net_bridge *br = (struct net_bridge *)__data; | |
6180 | + | |
6181 | + read_lock(&br->lock); | |
6182 | + br_check_timers(br); | |
6183 | + read_unlock(&br->lock); | |
6184 | + | |
6185 | + br->tick.expires = jiffies + 1; | |
6186 | + add_timer(&br->tick); | |
6187 | +} | |
6188 | diff -urN linux-2.2.19/net/bridge/br_tree.c linux-2.2.19br/net/bridge/br_tree.c | |
6189 | --- linux-2.2.19/net/bridge/br_tree.c Sun Mar 25 18:31:13 2001 | |
6190 | +++ linux-2.2.19br/net/bridge/br_tree.c Thu Jan 1 01:00:00 1970 | |
6191 | @@ -1,501 +0,0 @@ | |
6192 | -/* | |
6193 | - * This code is derived from the avl functions in mmap.c | |
6194 | - */ | |
6195 | - | |
6196 | -#include <linux/kernel.h> | |
6197 | -#include <linux/errno.h> | |
6198 | -#include <linux/string.h> | |
6199 | -#include <linux/malloc.h> | |
6200 | -#include <linux/skbuff.h> | |
6201 | -#include <linux/netdevice.h> | |
6202 | - | |
6203 | -#include <net/br.h> | |
6204 | -#define _DEBUG_AVL | |
6205 | - | |
6206 | -/* | |
6207 | - * Use an AVL (Adelson-Velskii and Landis) tree to speed up this search | |
6208 | - * from O(n) to O(log n), where n is the number of ULAs. | |
6209 | - * Written by Bruno Haible <haible@ma2s2.mathematik.uni-karlsruhe.de>. | |
6210 | - * Taken from mmap.c, extensively modified by John Hayes | |
6211 | - * <hayes@netplumbing.com> | |
6212 | - * 98-02 Modified by Jean-Rene Peulve jr.peulve@aix.pacwan.net | |
6213 | - * update port number when topology change | |
6214 | - * return oldfdb when updating, for broadcast storm checking | |
6215 | - * call addr_cmp once per node | |
6216 | - */ | |
6217 | - | |
6218 | -static struct fdb fdb_head; | |
6219 | -static struct fdb *fhp = &fdb_head; | |
6220 | -static struct fdb **fhpp = &fhp; | |
6221 | -static int fdb_inited = 0; | |
6222 | - | |
6223 | -#ifdef DEBUG_AVL | |
6224 | -static void printk_avl (struct fdb * tree); | |
6225 | -#endif | |
6226 | - | |
6227 | -static int addr_cmp(unsigned char *a1, unsigned char *a2); | |
6228 | - | |
6229 | -/* | |
6230 | - * fdb_head is the AVL tree corresponding to fdb | |
6231 | - * or, more exactly, its root. | |
6232 | - * A fdb has the following fields: | |
6233 | - * fdb_avl_left left son of a tree node | |
6234 | - * fdb_avl_right right son of a tree node | |
6235 | - * fdb_avl_height 1+max(heightof(left),heightof(right)) | |
6236 | - * The empty tree is represented as NULL. | |
6237 | - */ | |
6238 | - | |
6239 | -#ifndef avl_br_empty | |
6240 | -#define avl_br_empty (struct fdb *) NULL | |
6241 | -#endif | |
6242 | - | |
6243 | -/* Since the trees are balanced, their height will never be large. */ | |
6244 | -#define avl_maxheight 127 | |
6245 | -#define heightof(tree) ((tree) == avl_br_empty ? 0 : (tree)->fdb_avl_height) | |
6246 | -/* | |
6247 | - * Consistency and balancing rules: | |
6248 | - * 1. tree->fdb_avl_height == 1+max(heightof(tree->fdb_avl_left),heightof(tree->fdb_avl_right)) | |
6249 | - * 2. abs( heightof(tree->fdb_avl_left) - heightof(tree->fdb_avl_right) ) <= 1 | |
6250 | - * 3. foreach node in tree->fdb_avl_left: node->fdb_avl_key <= tree->fdb_avl_key, | |
6251 | - * foreach node in tree->fdb_avl_right: node->fdb_avl_key >= tree->fdb_avl_key. | |
6252 | - */ | |
6253 | - | |
6254 | -static int fdb_init(void) | |
6255 | -{ | |
6256 | - fdb_head.fdb_avl_height = 0; | |
6257 | - fdb_head.fdb_avl_left = (struct fdb *)0; | |
6258 | - fdb_head.fdb_avl_right = (struct fdb *)0; | |
6259 | - fdb_inited = 1; | |
6260 | - return(0); | |
6261 | -} | |
6262 | - | |
6263 | -struct fdb *br_avl_find_addr(unsigned char addr[6]) | |
6264 | -{ | |
6265 | - struct fdb * result = NULL; | |
6266 | - struct fdb * tree; | |
6267 | - | |
6268 | - if (!fdb_inited) | |
6269 | - fdb_init(); | |
6270 | -#if (DEBUG_AVL) | |
6271 | - printk("searching for ula %02x:%02x:%02x:%02x:%02x:%02x\n", | |
6272 | - addr[0], | |
6273 | - addr[1], | |
6274 | - addr[2], | |
6275 | - addr[3], | |
6276 | - addr[4], | |
6277 | - addr[5]); | |
6278 | -#endif /* DEBUG_AVL */ | |
6279 | - for (tree = fhp ; ; ) { | |
6280 | - if (tree == avl_br_empty) { | |
6281 | -#if (DEBUG_AVL) | |
6282 | - printk("search failed, returning node 0x%x\n", (unsigned int)result); | |
6283 | -#endif /* DEBUG_AVL */ | |
6284 | - return result; | |
6285 | - } | |
6286 | - | |
6287 | -#if (DEBUG_AVL) | |
6288 | - printk("node 0x%x: checking ula %02x:%02x:%02x:%02x:%02x:%02x\n", | |
6289 | - (unsigned int)tree, | |
6290 | - tree->ula[0], | |
6291 | - tree->ula[1], | |
6292 | - tree->ula[2], | |
6293 | - tree->ula[3], | |
6294 | - tree->ula[4], | |
6295 | - tree->ula[5]); | |
6296 | -#endif /* DEBUG_AVL */ | |
6297 | - if (addr_cmp(addr, tree->ula) == 0) { | |
6298 | -#if (DEBUG_AVL) | |
6299 | - printk("found node 0x%x\n", (unsigned int)tree); | |
6300 | -#endif /* DEBUG_AVL */ | |
6301 | - return tree; | |
6302 | - } | |
6303 | - if (addr_cmp(addr, tree->ula) < 0) { | |
6304 | - tree = tree->fdb_avl_left; | |
6305 | - } else { | |
6306 | - tree = tree->fdb_avl_right; | |
6307 | - } | |
6308 | - } | |
6309 | -} | |
6310 | - | |
6311 | - | |
6312 | -/* | |
6313 | - * Rebalance a tree. | |
6314 | - * After inserting or deleting a node of a tree we have a sequence of subtrees | |
6315 | - * nodes[0]..nodes[k-1] such that | |
6316 | - * nodes[0] is the root and nodes[i+1] = nodes[i]->{fdb_avl_left|fdb_avl_right}. | |
6317 | - */ | |
6318 | -static void br_avl_rebalance (struct fdb *** nodeplaces_ptr, int count) | |
6319 | -{ | |
6320 | - if (!fdb_inited) | |
6321 | - fdb_init(); | |
6322 | - for ( ; count > 0 ; count--) { | |
6323 | - struct fdb ** nodeplace = *--nodeplaces_ptr; | |
6324 | - struct fdb * node = *nodeplace; | |
6325 | - struct fdb * nodeleft = node->fdb_avl_left; | |
6326 | - struct fdb * noderight = node->fdb_avl_right; | |
6327 | - int heightleft = heightof(nodeleft); | |
6328 | - int heightright = heightof(noderight); | |
6329 | - if (heightright + 1 < heightleft) { | |
6330 | - /* */ | |
6331 | - /* * */ | |
6332 | - /* / \ */ | |
6333 | - /* n+2 n */ | |
6334 | - /* */ | |
6335 | - struct fdb * nodeleftleft = nodeleft->fdb_avl_left; | |
6336 | - struct fdb * nodeleftright = nodeleft->fdb_avl_right; | |
6337 | - int heightleftright = heightof(nodeleftright); | |
6338 | - if (heightof(nodeleftleft) >= heightleftright) { | |
6339 | - /* */ | |
6340 | - /* * n+2|n+3 */ | |
6341 | - /* / \ / \ */ | |
6342 | - /* n+2 n --> / n+1|n+2 */ | |
6343 | - /* / \ | / \ */ | |
6344 | - /* n+1 n|n+1 n+1 n|n+1 n */ | |
6345 | - /* */ | |
6346 | - node->fdb_avl_left = nodeleftright; | |
6347 | - nodeleft->fdb_avl_right = node; | |
6348 | - nodeleft->fdb_avl_height = 1 + (node->fdb_avl_height = 1 + heightleftright); | |
6349 | - *nodeplace = nodeleft; | |
6350 | - } else { | |
6351 | - /* */ | |
6352 | - /* * n+2 */ | |
6353 | - /* / \ / \ */ | |
6354 | - /* n+2 n --> n+1 n+1 */ | |
6355 | - /* / \ / \ / \ */ | |
6356 | - /* n n+1 n L R n */ | |
6357 | - /* / \ */ | |
6358 | - /* L R */ | |
6359 | - /* */ | |
6360 | - nodeleft->fdb_avl_right = nodeleftright->fdb_avl_left; | |
6361 | - node->fdb_avl_left = nodeleftright->fdb_avl_right; | |
6362 | - nodeleftright->fdb_avl_left = nodeleft; | |
6363 | - nodeleftright->fdb_avl_right = node; | |
6364 | - nodeleft->fdb_avl_height = node->fdb_avl_height = heightleftright; | |
6365 | - nodeleftright->fdb_avl_height = heightleft; | |
6366 | - *nodeplace = nodeleftright; | |
6367 | - } | |
6368 | - } else if (heightleft + 1 < heightright) { | |
6369 | - /* similar to the above, just interchange 'left' <--> 'right' */ | |
6370 | - struct fdb * noderightright = noderight->fdb_avl_right; | |
6371 | - struct fdb * noderightleft = noderight->fdb_avl_left; | |
6372 | - int heightrightleft = heightof(noderightleft); | |
6373 | - if (heightof(noderightright) >= heightrightleft) { | |
6374 | - node->fdb_avl_right = noderightleft; | |
6375 | - noderight->fdb_avl_left = node; | |
6376 | - noderight->fdb_avl_height = 1 + (node->fdb_avl_height = 1 + heightrightleft); | |
6377 | - *nodeplace = noderight; | |
6378 | - } else { | |
6379 | - noderight->fdb_avl_left = noderightleft->fdb_avl_right; | |
6380 | - node->fdb_avl_right = noderightleft->fdb_avl_left; | |
6381 | - noderightleft->fdb_avl_right = noderight; | |
6382 | - noderightleft->fdb_avl_left = node; | |
6383 | - noderight->fdb_avl_height = node->fdb_avl_height = heightrightleft; | |
6384 | - noderightleft->fdb_avl_height = heightright; | |
6385 | - *nodeplace = noderightleft; | |
6386 | - } | |
6387 | - } else { | |
6388 | - int height = (heightleft<heightright ? heightright : heightleft) + 1; | |
6389 | - if (height == node->fdb_avl_height) | |
6390 | - break; | |
6391 | - node->fdb_avl_height = height; | |
6392 | - } | |
6393 | - } | |
6394 | -#ifdef DEBUG_AVL | |
6395 | - printk_avl(&fdb_head); | |
6396 | -#endif /* DEBUG_AVL */ | |
6397 | -} | |
6398 | - | |
6399 | -/* Insert a node into a tree. | |
6400 | - * Performance improvement: | |
6401 | - * call addr_cmp() only once per node and use result in a switch. | |
6402 | - * Return old node address if we knew that MAC address already | |
6403 | - * Return NULL if we insert the new node | |
6404 | - */ | |
6405 | -struct fdb *br_avl_insert (struct fdb * new_node) | |
6406 | -{ | |
6407 | - struct fdb ** nodeplace = fhpp; | |
6408 | - struct fdb ** stack[avl_maxheight]; | |
6409 | - int stack_count = 0; | |
6410 | - struct fdb *** stack_ptr = &stack[0]; /* = &stack[stackcount] */ | |
6411 | - if (!fdb_inited) | |
6412 | - fdb_init(); | |
6413 | - for (;;) { | |
6414 | - struct fdb *node; | |
6415 | - | |
6416 | - node = *nodeplace; | |
6417 | - if (node == avl_br_empty) | |
6418 | - break; | |
6419 | - *stack_ptr++ = nodeplace; stack_count++; | |
6420 | - switch(addr_cmp(new_node->ula, node->ula)) { | |
6421 | - case 0: /* update */ | |
6422 | - if (node->port == new_node->port) { | |
6423 | - node->flags = new_node->flags; | |
6424 | - node->timer = new_node->timer; | |
6425 | - } else if (!(node->flags & FDB_ENT_VALID) && | |
6426 | - node->port) { | |
6427 | - /* update fdb but never for local interfaces */ | |
6428 | -#if (DEBUG_AVL) | |
6429 | - printk("node 0x%x:port changed old=%d new=%d\n", | |
6430 | - (unsigned int)node, node->port,new_node->port); | |
6431 | -#endif | |
6432 | - /* JRP: update port as well if the topology change ! | |
6433 | - * Don't do this while entry is still valid otherwise | |
6434 | - * a broadcast that we flooded and is reentered by another | |
6435 | - * port would mess up the good port number. | |
6436 | - * The fdb list per port needs to be updated as well. | |
6437 | - */ | |
6438 | - requeue_fdb(node, new_node->port); | |
6439 | - node->flags = new_node->flags; | |
6440 | - node->timer = new_node->timer; | |
6441 | -#if (DEBUG_AVL) | |
6442 | - printk_avl(&fdb_head); | |
6443 | -#endif /* DEBUG_AVL */ | |
6444 | - } | |
6445 | - return node; /* pass old fdb to caller */ | |
6446 | - | |
6447 | - case 1: /* new_node->ula > node->ula */ | |
6448 | - nodeplace = &node->fdb_avl_right; | |
6449 | - break; | |
6450 | - default: /* -1 => new_node->ula < node->ula */ | |
6451 | - nodeplace = &node->fdb_avl_left; | |
6452 | - } | |
6453 | - } | |
6454 | -#if (DEBUG_AVL) | |
6455 | - printk("node 0x%x: adding ula %02x:%02x:%02x:%02x:%02x:%02x\n", | |
6456 | - (unsigned int)new_node, | |
6457 | - new_node->ula[0], | |
6458 | - new_node->ula[1], | |
6459 | - new_node->ula[2], | |
6460 | - new_node->ula[3], | |
6461 | - new_node->ula[4], | |
6462 | - new_node->ula[5]); | |
6463 | -#endif /* (DEBUG_AVL) */ | |
6464 | - new_node->fdb_avl_left = avl_br_empty; | |
6465 | - new_node->fdb_avl_right = avl_br_empty; | |
6466 | - new_node->fdb_avl_height = 1; | |
6467 | - *nodeplace = new_node; | |
6468 | - br_avl_rebalance(stack_ptr,stack_count); | |
6469 | -#ifdef DEBUG_AVL | |
6470 | - printk_avl(&fdb_head); | |
6471 | -#endif /* DEBUG_AVL */ | |
6472 | - return NULL; /* this is a new node */ | |
6473 | -} | |
6474 | - | |
6475 | - | |
6476 | -/* Removes a node out of a tree. */ | |
6477 | -static int br_avl_remove (struct fdb * node_to_delete) | |
6478 | -{ | |
6479 | - struct fdb ** nodeplace = fhpp; | |
6480 | - struct fdb ** stack[avl_maxheight]; | |
6481 | - int stack_count = 0; | |
6482 | - struct fdb *** stack_ptr = &stack[0]; /* = &stack[stackcount] */ | |
6483 | - struct fdb ** nodeplace_to_delete; | |
6484 | - if (!fdb_inited) | |
6485 | - fdb_init(); | |
6486 | - for (;;) { | |
6487 | - struct fdb * node = *nodeplace; | |
6488 | - if (node == avl_br_empty) { | |
6489 | - /* what? node_to_delete not found in tree? */ | |
6490 | - printk(KERN_ERR "br: avl_remove: node to delete not found in tree\n"); | |
6491 | - return(-1); | |
6492 | - } | |
6493 | - *stack_ptr++ = nodeplace; stack_count++; | |
6494 | - if (addr_cmp(node_to_delete->ula, node->ula) == 0) | |
6495 | - break; | |
6496 | - if (addr_cmp(node_to_delete->ula, node->ula) < 0) | |
6497 | - nodeplace = &node->fdb_avl_left; | |
6498 | - else | |
6499 | - nodeplace = &node->fdb_avl_right; | |
6500 | - } | |
6501 | - nodeplace_to_delete = nodeplace; | |
6502 | - /* Have to remove node_to_delete = *nodeplace_to_delete. */ | |
6503 | - if (node_to_delete->fdb_avl_left == avl_br_empty) { | |
6504 | - *nodeplace_to_delete = node_to_delete->fdb_avl_right; | |
6505 | - stack_ptr--; stack_count--; | |
6506 | - } else { | |
6507 | - struct fdb *** stack_ptr_to_delete = stack_ptr; | |
6508 | - struct fdb ** nodeplace = &node_to_delete->fdb_avl_left; | |
6509 | - struct fdb * node; | |
6510 | - for (;;) { | |
6511 | - node = *nodeplace; | |
6512 | - if (node->fdb_avl_right == avl_br_empty) | |
6513 | - break; | |
6514 | - *stack_ptr++ = nodeplace; stack_count++; | |
6515 | - nodeplace = &node->fdb_avl_right; | |
6516 | - } | |
6517 | - *nodeplace = node->fdb_avl_left; | |
6518 | - /* node replaces node_to_delete */ | |
6519 | - node->fdb_avl_left = node_to_delete->fdb_avl_left; | |
6520 | - node->fdb_avl_right = node_to_delete->fdb_avl_right; | |
6521 | - node->fdb_avl_height = node_to_delete->fdb_avl_height; | |
6522 | - *nodeplace_to_delete = node; /* replace node_to_delete */ | |
6523 | - *stack_ptr_to_delete = &node->fdb_avl_left; /* replace &node_to_delete->fdb_avl_left */ | |
6524 | - } | |
6525 | - br_avl_rebalance(stack_ptr,stack_count); | |
6526 | - return(0); | |
6527 | -} | |
6528 | - | |
6529 | -#ifdef DEBUG_AVL | |
6530 | - | |
6531 | -/* print a tree */ | |
6532 | -static void printk_avl (struct fdb * tree) | |
6533 | -{ | |
6534 | - if (tree != avl_br_empty) { | |
6535 | - printk("("); | |
6536 | - printk("%02x:%02x:%02x:%02x:%02x:%02x(%d)", | |
6537 | - tree->ula[0], | |
6538 | - tree->ula[1], | |
6539 | - tree->ula[2], | |
6540 | - tree->ula[3], | |
6541 | - tree->ula[4], | |
6542 | - tree->ula[5], | |
6543 | - tree->port); | |
6544 | - if (tree->fdb_avl_left != avl_br_empty) { | |
6545 | - printk_avl(tree->fdb_avl_left); | |
6546 | - printk("<"); | |
6547 | - } | |
6548 | - if (tree->fdb_avl_right != avl_br_empty) { | |
6549 | - printk(">"); | |
6550 | - printk_avl(tree->fdb_avl_right); | |
6551 | - } | |
6552 | - printk(")\n"); | |
6553 | - } | |
6554 | -} | |
6555 | - | |
6556 | -static char *avl_check_point = "somewhere"; | |
6557 | - | |
6558 | -/* check a tree's consistency and balancing */ | |
6559 | -static void avl_checkheights (struct fdb * tree) | |
6560 | -{ | |
6561 | - int h, hl, hr; | |
6562 | - | |
6563 | - if (tree == avl_br_empty) | |
6564 | - return; | |
6565 | - avl_checkheights(tree->fdb_avl_left); | |
6566 | - avl_checkheights(tree->fdb_avl_right); | |
6567 | - h = tree->fdb_avl_height; | |
6568 | - hl = heightof(tree->fdb_avl_left); | |
6569 | - hr = heightof(tree->fdb_avl_right); | |
6570 | - if ((h == hl+1) && (hr <= hl) && (hl <= hr+1)) | |
6571 | - return; | |
6572 | - if ((h == hr+1) && (hl <= hr) && (hr <= hl+1)) | |
6573 | - return; | |
6574 | - printk("%s: avl_checkheights: heights inconsistent\n",avl_check_point); | |
6575 | -} | |
6576 | - | |
6577 | -/* check that all values stored in a tree are < key */ | |
6578 | -static void avl_checkleft (struct fdb * tree, fdb_avl_key_t key) | |
6579 | -{ | |
6580 | - if (tree == avl_br_empty) | |
6581 | - return; | |
6582 | - avl_checkleft(tree->fdb_avl_left,key); | |
6583 | - avl_checkleft(tree->fdb_avl_right,key); | |
6584 | - if (tree->fdb_avl_key < key) | |
6585 | - return; | |
6586 | - printk("%s: avl_checkleft: left key %lu >= top key %lu\n",avl_check_point,tree->fdb_avl_key,key); | |
6587 | -} | |
6588 | - | |
6589 | -/* check that all values stored in a tree are > key */ | |
6590 | -static void avl_checkright (struct fdb * tree, fdb_avl_key_t key) | |
6591 | -{ | |
6592 | - if (tree == avl_br_empty) | |
6593 | - return; | |
6594 | - avl_checkright(tree->fdb_avl_left,key); | |
6595 | - avl_checkright(tree->fdb_avl_right,key); | |
6596 | - if (tree->fdb_avl_key > key) | |
6597 | - return; | |
6598 | - printk("%s: avl_checkright: right key %lu <= top key %lu\n",avl_check_point,tree->fdb_avl_key,key); | |
6599 | -} | |
6600 | - | |
6601 | -/* check that all values are properly increasing */ | |
6602 | -static void avl_checkorder (struct fdb * tree) | |
6603 | -{ | |
6604 | - if (tree == avl_br_empty) | |
6605 | - return; | |
6606 | - avl_checkorder(tree->fdb_avl_left); | |
6607 | - avl_checkorder(tree->fdb_avl_right); | |
6608 | - avl_checkleft(tree->fdb_avl_left,tree->fdb_avl_key); | |
6609 | - avl_checkright(tree->fdb_avl_right,tree->fdb_avl_key); | |
6610 | -} | |
6611 | - | |
6612 | -#endif /* DEBUG_AVL */ | |
6613 | - | |
6614 | -static int addr_cmp(unsigned char a1[], unsigned char a2[]) | |
6615 | -{ | |
6616 | - int i; | |
6617 | - | |
6618 | - for (i=0; i<6; i++) { | |
6619 | - if (a1[i] > a2[i]) return(1); | |
6620 | - if (a1[i] < a2[i]) return(-1); | |
6621 | - } | |
6622 | - return(0); | |
6623 | -} | |
6624 | - | |
6625 | -/* Vova Oksman: function for copy tree to the buffer */ | |
6626 | -void sprintf_avl (char **pbuffer, struct fdb * tree, off_t *pos, | |
6627 | - int* len, off_t offset, int length) | |
6628 | -{ | |
6629 | - int size; | |
6630 | - | |
6631 | - if( 0 == *pos){ | |
6632 | - if(avl_br_empty == tree) | |
6633 | - /* begin from the root */ | |
6634 | - tree = fhp; | |
6635 | - *pos = *len; | |
6636 | - } | |
6637 | - | |
6638 | - if (*pos >= offset+length) | |
6639 | - return; | |
6640 | - | |
6641 | - if (tree != avl_br_empty) { | |
6642 | - /* don't write the local device */ | |
6643 | - if(tree->port != 0){ | |
6644 | - size = sprintf(*pbuffer, | |
6645 | - "%02x:%02x:%02x:%02x:%02x:%02x %s %d %ld\n", | |
6646 | - tree->ula[0],tree->ula[1],tree->ula[2], | |
6647 | - tree->ula[3],tree->ula[4],tree->ula[5], | |
6648 | - port_info[tree->port].dev->name, tree->flags,CURRENT_TIME-tree->timer); | |
6649 | - | |
6650 | - (*pos)+=size; | |
6651 | - (*len)+=size; | |
6652 | - (*pbuffer)+=size; | |
6653 | - } | |
6654 | - if (*pos <= offset) | |
6655 | - *len=0; | |
6656 | - | |
6657 | - if (tree->fdb_avl_left != avl_br_empty) { | |
6658 | - sprintf_avl (pbuffer,tree->fdb_avl_left,pos,len,offset,length); | |
6659 | - } | |
6660 | - if (tree->fdb_avl_right != avl_br_empty) { | |
6661 | - sprintf_avl (pbuffer,tree->fdb_avl_right,pos,len,offset,length); | |
6662 | - } | |
6663 | - | |
6664 | - } | |
6665 | - | |
6666 | - return; | |
6667 | -} | |
6668 | - | |
6669 | -/* | |
6670 | - * Delete all nodes learnt by the port | |
6671 | - */ | |
6672 | -void br_avl_delete_by_port(int port) | |
6673 | -{ | |
6674 | - struct fdb *fdb, *next; | |
6675 | - | |
6676 | - if (!fdb_inited) | |
6677 | - fdb_init(); | |
6678 | - | |
6679 | - for(fdb = port_info[port].fdb; fdb != NULL; fdb = next) { | |
6680 | - next = fdb->fdb_next; | |
6681 | - br_avl_remove(fdb); | |
6682 | - } | |
6683 | - port_info[port].fdb = NULL; | |
6684 | - | |
6685 | - /* remove the local mac too */ | |
6686 | -/* next = br_avl_find_addr(port_info[port].dev->dev_addr); */ | |
6687 | - next = br_avl_find_addr(port_info[port].ifmac.BRIDGE_ID_ULA); | |
6688 | - if (next != NULL) | |
6689 | - br_avl_remove(next); | |
6690 | - | |
6691 | - return; | |
6692 | -} | |
6693 | diff -urN linux-2.2.19/net/bridge/sysctl_net_bridge.c linux-2.2.19br/net/bridge/sysctl_net_bridge.c | |
6694 | --- linux-2.2.19/net/bridge/sysctl_net_bridge.c Sun Mar 25 18:31:13 2001 | |
6695 | +++ linux-2.2.19br/net/bridge/sysctl_net_bridge.c Thu Jan 1 01:00:00 1970 | |
6696 | @@ -1,13 +0,0 @@ | |
6697 | -/* -*- linux-c -*- | |
6698 | - * sysctl_net_bridge.c: sysctl interface to net bridge subsystem. | |
6699 | - * | |
6700 | - * Begun June 1, 1996, Mike Shaver. | |
6701 | - * Added /proc/sys/net/bridge directory entry (empty =) ). [MS] | |
6702 | - */ | |
6703 | - | |
6704 | -#include <linux/mm.h> | |
6705 | -#include <linux/sysctl.h> | |
6706 | - | |
6707 | -ctl_table bridge_table[] = { | |
6708 | - {0} | |
6709 | -}; | |
6710 | diff -urN linux-2.2.19/net/core/dev.c linux-2.2.19br/net/core/dev.c | |
6711 | --- linux-2.2.19/net/core/dev.c Sun Mar 25 18:37:41 2001 | |
6712 | +++ linux-2.2.19br/net/core/dev.c Tue Apr 3 11:32:58 2001 | |
6713 | @@ -84,7 +84,7 @@ | |
6714 | #include <linux/rtnetlink.h> | |
6715 | #include <linux/proc_fs.h> | |
6716 | #include <linux/stat.h> | |
6717 | -#include <net/br.h> | |
6718 | +#include <linux/if_bridge.h> | |
6719 | #include <linux/divert.h> | |
6720 | #include <net/dst.h> | |
6721 | #include <net/pkt_sched.h> | |
6722 | @@ -810,35 +810,8 @@ | |
6723 | kfree_skb(skb); | |
6724 | } | |
6725 | ||
6726 | -#ifdef CONFIG_BRIDGE | |
6727 | -static inline void handle_bridge(struct sk_buff *skb, unsigned short type) | |
6728 | -{ | |
6729 | - /* | |
6730 | - * The br_stats.flags is checked here to save the expense of a | |
6731 | - * function call. | |
6732 | - */ | |
6733 | - if ((br_stats.flags & BR_UP) && br_call_bridge(skb, type)) | |
6734 | - { | |
6735 | - /* | |
6736 | - * We pass the bridge a complete frame. This means | |
6737 | - * recovering the MAC header first. | |
6738 | - */ | |
6739 | - | |
6740 | - int offset; | |
6741 | - | |
6742 | - skb=skb_clone(skb, GFP_ATOMIC); | |
6743 | - if(skb==NULL) | |
6744 | - return; | |
6745 | - | |
6746 | - offset=skb->data-skb->mac.raw; | |
6747 | - skb_push(skb,offset); /* Put header back on for bridge */ | |
6748 | - | |
6749 | - if(br_receive_frame(skb)) | |
6750 | - return; | |
6751 | - kfree_skb(skb); | |
6752 | - } | |
6753 | - return; | |
6754 | -} | |
6755 | +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) | |
6756 | +void (*br_handle_frame_hook)(struct sk_buff *skb) = NULL; | |
6757 | #endif | |
6758 | ||
6759 | ||
6760 | @@ -955,11 +928,6 @@ | |
6761 | continue; | |
6762 | } | |
6763 | ||
6764 | - /* | |
6765 | - * Fetch the packet protocol ID. | |
6766 | - */ | |
6767 | - | |
6768 | - type = skb->protocol; | |
6769 | ||
6770 | #ifdef CONFIG_NET_DIVERT | |
6771 | /* | |
6772 | @@ -970,15 +938,6 @@ | |
6773 | #endif /* CONFIG_NET_DIVERT */ | |
6774 | ||
6775 | ||
6776 | -#ifdef CONFIG_BRIDGE | |
6777 | - /* | |
6778 | - * If we are bridging then pass the frame up to the | |
6779 | - * bridging code (if this protocol is to be bridged). | |
6780 | - * If it is bridged then move on | |
6781 | - */ | |
6782 | - handle_bridge(skb, type); | |
6783 | -#endif | |
6784 | - | |
6785 | /* | |
6786 | * We got a packet ID. Now loop over the "known protocols" | |
6787 | * list. There are two lists. The ptype_all list of taps (normally empty) | |
6788 | @@ -986,19 +945,44 @@ | |
6789 | */ | |
6790 | ||
6791 | pt_prev = NULL; | |
6792 | - for (ptype = ptype_all; ptype!=NULL; ptype=ptype->next) | |
6793 | + for (ptype = ptype_all; ptype != NULL; ptype = ptype->next) | |
6794 | { | |
6795 | if (!ptype->dev || ptype->dev == skb->dev) { | |
6796 | - if(pt_prev) | |
6797 | + if (pt_prev) | |
6798 | { | |
6799 | - struct sk_buff *skb2=skb_clone(skb, GFP_ATOMIC); | |
6800 | - if(skb2) | |
6801 | - pt_prev->func(skb2,skb->dev, pt_prev); | |
6802 | + struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); | |
6803 | + if (skb2) | |
6804 | + pt_prev->func(skb2, skb->dev, pt_prev); | |
6805 | } | |
6806 | - pt_prev=ptype; | |
6807 | + pt_prev = ptype; | |
6808 | } | |
6809 | } | |
6810 | ||
6811 | + /* | |
6812 | + * Is there a last item to send to ? | |
6813 | + */ | |
6814 | + | |
6815 | + if (pt_prev) | |
6816 | + { | |
6817 | + struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); | |
6818 | + if (skb2) | |
6819 | + pt_prev->func(skb2, skb->dev, pt_prev); | |
6820 | + pt_prev = NULL; | |
6821 | + } | |
6822 | + | |
6823 | +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) | |
6824 | + if (skb->dev->br_port != NULL && br_handle_frame_hook != NULL) { | |
6825 | + br_handle_frame_hook(skb); | |
6826 | + continue; | |
6827 | + } | |
6828 | +#endif | |
6829 | + | |
6830 | + /* | |
6831 | + * Fetch the packet protocol ID. | |
6832 | + */ | |
6833 | + | |
6834 | + type = skb->protocol; | |
6835 | + | |
6836 | for (ptype = ptype_base[ntohs(type)&15]; ptype != NULL; ptype = ptype->next) | |
6837 | { | |
6838 | if (ptype->type == type && (!ptype->dev || ptype->dev==skb->dev)) | |
6839 | @@ -1007,7 +991,8 @@ | |
6840 | * We already have a match queued. Deliver | |
6841 | * to it and then remember the new match | |
6842 | */ | |
6843 | - if(pt_prev) | |
6844 | + | |
6845 | + if (pt_prev) | |
6846 | { | |
6847 | struct sk_buff *skb2; | |
6848 | ||
6849 | @@ -1032,13 +1017,14 @@ | |
6850 | ||
6851 | if(pt_prev) | |
6852 | pt_prev->func(skb, skb->dev, pt_prev); | |
6853 | + | |
6854 | /* | |
6855 | * Has an unknown packet has been received ? | |
6856 | */ | |
6857 | ||
6858 | - else { | |
6859 | + else | |
6860 | kfree_skb(skb); | |
6861 | - } | |
6862 | + | |
6863 | } /* End of queue loop */ | |
6864 | ||
6865 | /* | |
6866 | @@ -1963,12 +1949,11 @@ | |
6867 | skb_queue_head_init(&backlog); | |
6868 | ||
6869 | /* | |
6870 | - * The bridge has to be up before the devices | |
6871 | + * Initialize the ethernet bridge. | |
6872 | */ | |
6873 | - | |
6874 | -#ifdef CONFIG_BRIDGE | |
6875 | +#ifdef CONFIG_BRIDGE | |
6876 | br_init(); | |
6877 | -#endif | |
6878 | +#endif | |
6879 | ||
6880 | /* | |
6881 | * Frame Diverter init | |
6882 | @@ -2082,13 +2067,6 @@ | |
6883 | dev_boot_phase = 0; | |
6884 | ||
6885 | dev_mcast_init(); | |
6886 | - | |
6887 | -#ifdef CONFIG_BRIDGE | |
6888 | - /* | |
6889 | - * Register any statically linked ethernet devices with the bridge | |
6890 | - */ | |
6891 | - br_spacedevice_register(); | |
6892 | -#endif | |
6893 | ||
6894 | #ifdef CONFIG_N2 | |
6895 | n2_init(); | |
6896 | diff -urN linux-2.2.19/net/core/skbuff.c linux-2.2.19br/net/core/skbuff.c | |
6897 | --- linux-2.2.19/net/core/skbuff.c Sun Mar 25 18:31:12 2001 | |
6898 | +++ linux-2.2.19br/net/core/skbuff.c Tue Apr 3 11:32:58 2001 | |
6899 | @@ -184,7 +184,6 @@ | |
6900 | ||
6901 | skb->destructor = NULL; | |
6902 | skb->pkt_type = PACKET_HOST; /* Default type */ | |
6903 | - skb->pkt_bridged = 0; /* Not bridged */ | |
6904 | skb->prev = skb->next = NULL; | |
6905 | skb->list = NULL; | |
6906 | skb->sk = NULL; | |
6907 | diff -urN linux-2.2.19/net/ipv4/af_inet.c linux-2.2.19br/net/ipv4/af_inet.c | |
6908 | --- linux-2.2.19/net/ipv4/af_inet.c Sun Mar 25 18:31:12 2001 | |
6909 | +++ linux-2.2.19br/net/ipv4/af_inet.c Tue Apr 3 11:32:58 2001 | |
6910 | @@ -106,10 +106,8 @@ | |
6911 | #ifdef CONFIG_IP_MASQUERADE | |
6912 | #include <net/ip_masq.h> | |
6913 | #endif | |
6914 | -#ifdef CONFIG_BRIDGE | |
6915 | -#include <net/br.h> | |
6916 | -#endif | |
6917 | - | |
6918 | +#include <linux/if_bridge.h> | |
6919 | + | |
6920 | #ifdef CONFIG_NET_DIVERT | |
6921 | #include <linux/divert.h> | |
6922 | #endif /* CONFIG_NET_DIVERT */ | |
6923 | @@ -139,6 +137,7 @@ | |
6924 | int (*dlci_ioctl_hook)(unsigned int, void *) = NULL; | |
6925 | #endif | |
6926 | ||
6927 | +int (*br_ioctl_hook)(unsigned long) = NULL; | |
6928 | int (*rarp_ioctl_hook)(unsigned int,void*) = NULL; | |
6929 | ||
6930 | /* | |
6931 | @@ -912,11 +911,15 @@ | |
6932 | return(devinet_ioctl(cmd,(void *) arg)); | |
6933 | case SIOCGIFBR: | |
6934 | case SIOCSIFBR: | |
6935 | -#ifdef CONFIG_BRIDGE | |
6936 | - return(br_ioctl(cmd,(void *) arg)); | |
6937 | -#else | |
6938 | +#ifdef CONFIG_KMOD | |
6939 | + if (br_ioctl_hook == NULL) | |
6940 | + request_module("bridge"); | |
6941 | +#endif | |
6942 | + | |
6943 | + if (br_ioctl_hook != NULL) | |
6944 | + return br_ioctl_hook(arg); | |
6945 | + | |
6946 | return -ENOPKG; | |
6947 | -#endif | |
6948 | ||
6949 | case SIOCGIFDIVERT: | |
6950 | case SIOCSIFDIVERT: | |
6951 | diff -urN linux-2.2.19/net/netsyms.c linux-2.2.19br/net/netsyms.c | |
6952 | --- linux-2.2.19/net/netsyms.c Sun Mar 25 18:37:41 2001 | |
6953 | +++ linux-2.2.19br/net/netsyms.c Tue Apr 3 11:32:58 2001 | |
6954 | @@ -28,10 +28,7 @@ | |
6955 | #endif | |
6956 | #include <net/pkt_sched.h> | |
6957 | #include <net/scm.h> | |
6958 | - | |
6959 | -#ifdef CONFIG_BRIDGE | |
6960 | -#include <net/br.h> | |
6961 | -#endif | |
6962 | +#include <linux/if_bridge.h> | |
6963 | ||
6964 | #ifdef CONFIG_NET_DIVERT | |
6965 | #include <linux/divert.h> | |
6966 | @@ -225,9 +222,10 @@ | |
6967 | ||
6968 | EXPORT_SYMBOL(scm_detach_fds); | |
6969 | ||
6970 | -#ifdef CONFIG_BRIDGE | |
6971 | -EXPORT_SYMBOL(br_ioctl); | |
6972 | +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) | |
6973 | +EXPORT_SYMBOL(br_handle_frame_hook); | |
6974 | #endif | |
6975 | +EXPORT_SYMBOL(br_ioctl_hook); | |
6976 | ||
6977 | #ifdef CONFIG_NET_DIVERT | |
6978 | EXPORT_SYMBOL(alloc_divert_blk); | |
6979 | diff -urN linux-2.2.19/net/packet/af_packet.c linux-2.2.19br/net/packet/af_packet.c | |
6980 | --- linux-2.2.19/net/packet/af_packet.c Sun Mar 25 18:31:14 2001 | |
6981 | +++ linux-2.2.19br/net/packet/af_packet.c Tue Apr 3 11:32:58 2001 | |
6982 | @@ -63,14 +63,12 @@ | |
6983 | #include <asm/uaccess.h> | |
6984 | #include <linux/module.h> | |
6985 | #include <linux/init.h> | |
6986 | +#include <linux/if_bridge.h> | |
6987 | ||
6988 | #ifdef CONFIG_INET | |
6989 | #include <net/inet_common.h> | |
6990 | #endif | |
6991 | ||
6992 | -#ifdef CONFIG_BRIDGE | |
6993 | -#include <net/br.h> | |
6994 | -#endif | |
6995 | ||
6996 | #ifdef CONFIG_NET_DIVERT | |
6997 | #include <linux/divert.h> | |
6998 | @@ -1131,11 +1129,15 @@ | |
6999 | ||
7000 | case SIOCGIFBR: | |
7001 | case SIOCSIFBR: | |
7002 | -#ifdef CONFIG_BRIDGE | |
7003 | - return(br_ioctl(cmd,(void *) arg)); | |
7004 | -#else | |
7005 | +#ifdef CONFIG_KMOD | |
7006 | + if (br_ioctl_hook == NULL) | |
7007 | + request_module("bridge"); | |
7008 | +#endif | |
7009 | + | |
7010 | + if (br_ioctl_hook != NULL) | |
7011 | + return br_ioctl_hook(arg); | |
7012 | + | |
7013 | return -ENOPKG; | |
7014 | -#endif | |
7015 | ||
7016 | case SIOCGIFDIVERT: | |
7017 | case SIOCSIFDIVERT: | |
7018 | diff -urN linux-2.2.19/net/sysctl_net.c linux-2.2.19br/net/sysctl_net.c | |
7019 | --- linux-2.2.19/net/sysctl_net.c Sun Mar 25 18:31:13 2001 | |
7020 | +++ linux-2.2.19br/net/sysctl_net.c Tue Apr 3 11:32:58 2001 | |
7021 | @@ -34,10 +34,6 @@ | |
7022 | extern ctl_table ether_table[], e802_table[]; | |
7023 | #endif | |
7024 | ||
7025 | -#ifdef CONFIG_BRIDGE | |
7026 | -extern ctl_table bridge_table[]; | |
7027 | -#endif | |
7028 | - | |
7029 | #ifdef CONFIG_IPV6 | |
7030 | extern ctl_table ipv6_table[]; | |
7031 | #endif | |
7032 | @@ -60,9 +56,6 @@ | |
7033 | #endif | |
7034 | #ifdef CONFIG_IPX | |
7035 | {NET_IPX, "ipx", NULL, 0, 0555, ipx_table}, | |
7036 | -#endif | |
7037 | -#ifdef CONFIG_BRIDGE | |
7038 | - {NET_BRIDGE, "bridge", NULL, 0, 0555, bridge_table}, | |
7039 | #endif | |
7040 | #ifdef CONFIG_IPV6 | |
7041 | {NET_IPV6, "ipv6", NULL, 0, 0555, ipv6_table}, |