1
2
3
4
5 #if !defined(One)
6 #define Zero 0
7 #define One 1
8 #endif
9
10 #if !defined(TRUE)
11 #define FALSE 0
12 #define TRUE 1
13 #endif
14
15
16 #define Disabled 0
17 #define Listening 1
18 #define Learning 2
19 #define Forwarding 3
20 #define Blocking 4
21
22 #define No_of_ports 8
23
24
25 #define All_ports (No_of_ports + 1)
26
27
28
29
30 #define FDB_TIMEOUT 300
31
32
33
34
35
36
37
38 #define BRIDGE_MAX_AGE 20
39 #define BRIDGE_HELLO_TIME 2
40 #define BRIDGE_FORWARD_DELAY 15
41 #define HOLD_TIME 1
42
43 #define Default_path_cost 10
44
45
46
47
48
49 #define Message_age_increment 1
50
51 #define No_port 0
52
53
54
55
56
57
58
59
60 typedef struct {
61 union {
62 struct {
63 unsigned short priority;
64 unsigned char ula[6];
65 } p_u;
66 unsigned int id[2];
67 } bi;
68 } bridge_id_t;
69
70 #define BRIDGE_PRIORITY bi.p_u.priority
71 #define BRIDGE_ID_ULA bi.p_u.ula
72 #define BRIDGE_ID bi.id
73
74 typedef struct {
75 unsigned short protocol_id;
76 unsigned char protocol_version_id;
77 unsigned char type;
78 unsigned char flags;
79 #define TOPOLOGY_CHANGE 0x01
80 #define TOPOLOGY_CHANGE_ACK 0x80
81 bridge_id_t root_id;
82 unsigned int root_path_cost;
83 bridge_id_t bridge_id;
84 unsigned short port_id;
85 unsigned short message_age;
86 unsigned short max_age;
87 unsigned short hello_time;
88 unsigned short forward_delay;
89 } Config_bpdu;
90
91
92
93
94 typedef struct {
95 unsigned short protocol_id;
96 unsigned char protocol_version_id;
97 unsigned char type;
98 } Tcn_bpdu;
99
100 #define BPDU_TYPE_CONFIG 0
101 #define BPDU_TYPE_TOPO_CHANGE 128
102
103
104 typedef struct {
105 bridge_id_t designated_root;
106 unsigned int root_path_cost;
107 unsigned int root_port;
108 unsigned short max_age;
109 unsigned short hello_time;
110 unsigned short forward_delay;
111 bridge_id_t bridge_id;
112 unsigned short bridge_max_age;
113 unsigned short bridge_hello_time;
114 unsigned short bridge_forward_delay;
115 unsigned int topology_change_detected;
116 unsigned int topology_change;
117 unsigned short topology_change_time;
118 unsigned short hold_time;
119 unsigned int top_change;
120 unsigned int top_change_detected;
121 } Bridge_data;
122
123
124 typedef struct {
125 unsigned short port_id;
126 unsigned int state;
127 unsigned int path_cost;
128 bridge_id_t designated_root;
129 unsigned int designated_cost;
130 bridge_id_t designated_bridge;
131 unsigned short designated_port;
132 unsigned int top_change_ack;
133 unsigned int config_pending;
134 struct device *dev;
135 struct fdb *fdb;
136 } Port_data;
137
138
139
140
141 typedef struct {
142 unsigned int active;
143 unsigned int value;
144
145 } Timer;
146
147 struct fdb {
148 unsigned char ula[6];
149 unsigned char pad[2];
150 unsigned short port;
151 unsigned int timer;
152 unsigned int flags;
153 #define FDB_ENT_VALID 0x01
154
155 short fdb_avl_height;
156 struct fdb *fdb_avl_left;
157 struct fdb *fdb_avl_right;
158
159 struct fdb *fdb_next;
160 };
161
162 #define IS_BRIDGED 0x2e
163
164 struct br_stat {
165 unsigned int flags;
166 Bridge_data bridge_data;
167 Port_data port_data[No_of_ports];
168 };
169
170
171 #define BR_UP 0x0001
172 #define BR_DEBUG 0x0002
173
174 struct br_cf {
175 unsigned int cmd;
176 unsigned int arg1;
177 unsigned int arg2;
178 };
179
180
181 #define BRCMD_BRIDGE_ENABLE 1
182 #define BRCMD_BRIDGE_DISABLE 2
183 #define BRCMD_PORT_ENABLE 3
184 #define BRCMD_PORT_DISABLE 4
185 #define BRCMD_SET_BRIDGE_PRIORITY 5
186 #define BRCMD_SET_PORT_PRIORITY 6
187 #define BRCMD_SET_PATH_COST 7
188 #define BRCMD_DISPLAY_FDB 8
189 #define BRCMD_ENABLE_DEBUG 9
190 #define BRCMD_DISABLE_DEBUG 10
191
192
193
194 void transmit_config(int port_no);
195 int root_bridge(void);
196 int supersedes_port_info(int port_no, Config_bpdu *config);
197 void record_config_information(int port_no, Config_bpdu *config);
198 void record_config_timeout_values(Config_bpdu *config);
199 void config_bpdu_generation(void);
200 int designated_port(int port_no);
201 void reply(int port_no);
202 void transmit_tcn(void);
203 void configuration_update(void);
204 void root_selection(void);
205 void designated_port_selection(void);
206 void become_designated_port(int port_no);
207 void port_state_selection(void);
208 void make_forwarding(int port_no);
209 void topology_change_detection(void);
210 void topology_change_acknowledged(void);
211 void acknowledge_topology_change(int port_no);
212 void make_blocking(int port_no);
213 void set_port_state(int port_no, int state);
214 void received_config_bpdu(int port_no, Config_bpdu *config);
215 void received_tcn_bpdu(int port_no, Tcn_bpdu *tcn);
216 void hello_timer_expiry(void);
217 void message_age_timer_expiry(int port_no);
218 void forward_delay_timer_expiry(int port_no);
219 int designated_for_some_port(void);
220 void tcn_timer_expiry(void);
221 void topology_change_timer_expiry(void);
222 void hold_timer_expiry(int port_no);
223 void br_init(void);
224 void br_init_port(int port_no);
225 void enable_port(int port_no);
226 void disable_port(int port_no);
227 void set_bridge_priority(bridge_id_t *new_bridge_id);
228 void set_port_priority(int port_no, unsigned short new_port_id);
229 void set_path_cost(int port_no, unsigned short path_cost);
230 void start_hello_timer(void);
231 void stop_hello_timer(void);
232 int hello_timer_expired(void);
233 void start_tcn_timer(void);
234 void stop_tcn_timer(void);
235 int tcn_timer_expired(void);
236 void start_topology_change_timer(void);
237 void stop_topology_change_timer(void);
238 int topology_change_timer_expired(void);
239 void start_message_age_timer(int port_no, unsigned short message_age);
240 void stop_message_age_timer(int port_no);
241 int message_age_timer_expired(int port_no);
242 void start_forward_delay_timer(int port_no);
243 void stop_forward_delay_timer(int port_no);
244 int forward_delay_timer_expired(int port_no);
245 void start_hold_timer(int port_no);
246 void stop_hold_timer(int port_no);
247 int hold_timer_expired(int port_no);
248
249 struct fdb *br_avl_find_addr(unsigned char addr[6]);
250 int br_avl_insert (struct fdb * new_node);
251 int br_avl_remove (struct fdb * node_to_delete);
252
253 int send_tcn_bpdu(int port_no, Tcn_bpdu *bpdu);
254 int send_config_bpdu(int port_no, Config_bpdu *config_bpdu);
255 int find_port(struct device *dev);
256 int br_flood(struct sk_buff *skb, int port);
257 int br_drop(struct sk_buff *skb);
258 int br_learn(struct sk_buff *skb, int port);
259
260 int br_receive_frame(struct sk_buff *skb);
261 int br_tx_frame(struct sk_buff *skb);
262 int br_ioctl(unsigned int cmd, void *arg);
263
264 void free_fdb(struct fdb *);
265 struct fdb *get_fdb(void);
266
267
268
269 extern struct br_stat br_stats;
270