1 #include <linux/config.h>
3 * Constants and structure definitions for the bridging code
9 #endif /* !defined(One) */
14 #endif /* !defined(TRUE) */
17 #define Disabled 0 /* (4.4 5) */
18 #define Listening 1 /* (4.4.2) */
19 #define Learning 2 /* (4.4.3) */
20 #define Forwarding 3 /* (4 4 4) */
21 #define Blocking 4 /* (4.4.1) */
24 /* MAG Yich! Easiest way of giving a configurable number of ports
25 * If you want more than 32, change BR_MAX_PORTS and recompile brcfg!
27 #define BR_MAX_PORTS (32)
28 #if CONFIG_BRIDGE_NUM_PORTS > BR_MAX_PORTS
29 #undef CONFIG_BRIDGE_NUM_PORTS
30 #define CONFIG_BRIDGE_NUM_PORTS BR_MAX_PORTS
32 #define No_of_ports CONFIG_BRIDGE_NUM_PORTS
33 /* arbitrary choice, to allow the code below to compile */
35 #define All_ports (No_of_ports + 1)
38 * We time out our entries in the FDB after this many seconds.
40 #define FDB_TIMEOUT 20 /* JRP: 20s as NSC bridge code, was 300 for Linux */
43 * the following defines are the initial values used when the
44 * bridge is booted. These may be overridden when this bridge is
45 * not the root bridge. These are the recommended default values
46 * from the 802.1d specification.
48 #define BRIDGE_MAX_AGE 20
49 #define BRIDGE_HELLO_TIME 2
50 #define BRIDGE_FORWARD_DELAY 15
53 /* broacast/multicast storm limitation. This per source. */
54 #define MAX_MCAST_PER_PERIOD 4
55 #define MCAST_HOLD_TIME (10*HZ/100)
57 #define Default_path_cost 10
60 * minimum increment possible to avoid underestimating age, allows for BPDU
63 #define Message_age_increment 1
67 * reserved value for Bridge's root port parameter indicating no root port,
68 * used when Bridge is the root - also used to indicate the source when
69 * a frame is being generated by a higher layer protocol on this host
72 /** Configuration BPDU Parameters (4.5.1) **/
77 unsigned short priority
;
84 #define BRIDGE_PRIORITY bi.p_u.priority
85 #define BRIDGE_ID_ULA bi.p_u.ula
86 #define BRIDGE_ID bi.id
88 /* JRP: on the network the flags field is between "type" and "root_id"
89 * this is unfortunated! To make the code portable to a RISC machine
90 * the pdus are now massaged a little bit for processing
92 #define TOPOLOGY_CHANGE 0x01
93 #define TOPOLOGY_CHANGE_ACK 0x80
94 #define BRIDGE_BPDU_8021_CONFIG_SIZE 35 /* real size */
95 #define BRIDGE_BPDU_8021_CONFIG_FLAG_OFFSET 4
96 #define BRIDGE_BPDU_8021_PROTOCOL_ID 0
97 #define BRIDGE_BPDU_8021_PROTOCOL_VERSION_ID 0
98 #define BRIDGE_LLC1_HS 3
99 #define BRIDGE_LLC1_DSAP 0x42
100 #define BRIDGE_LLC1_SSAP 0x42
101 #define BRIDGE_LLC1_CTRL 0x03
104 unsigned short protocol_id
;
105 unsigned char protocol_version_id
;
107 bridge_id_t root_id
; /* (4.5.1.1) */
108 unsigned int root_path_cost
; /* (4.5.1.2) */
109 bridge_id_t bridge_id
; /* (4.5.1.3) */
110 unsigned short port_id
; /* (4.5.1.4) */
111 unsigned short message_age
; /* (4.5.1.5) */
112 unsigned short max_age
; /* (4.5.1.6) */
113 unsigned short hello_time
; /* (4.5.1.7) */
114 unsigned short forward_delay
; /* (4.5.1.8) */
115 unsigned char top_change_ack
;
116 unsigned char top_change
;
119 #ifdef __LITTLE_ENDIAN
120 #define config_bpdu_hton(config_bpdu) \
121 (config_bpdu)->root_path_cost = htonl((config_bpdu)->root_path_cost); \
122 (config_bpdu)->port_id = htons((config_bpdu)->port_id); \
123 (config_bpdu)->message_age = htons((config_bpdu)->message_age); \
124 (config_bpdu)->max_age = htons((config_bpdu)->max_age); \
125 (config_bpdu)->hello_time = htons((config_bpdu)->hello_time); \
126 (config_bpdu)->forward_delay = htons((config_bpdu)->forward_delay);
128 #define config_bpdu_hton(config_bpdu)
130 #define config_bpdu_ntoh config_bpdu_hton
133 /** Topology Change Notification BPDU Parameters (4.5.2) **/
136 unsigned short protocol_id
;
137 unsigned char protocol_version_id
;
141 #define BPDU_TYPE_CONFIG 0
142 #define BPDU_TYPE_TOPO_CHANGE 128
144 /** Bridge Parameters (4.5.3) **/
146 bridge_id_t designated_root
; /* (4.5.3.1) */
147 unsigned int root_path_cost
; /* (4.5.3.2) */
148 unsigned int root_port
; /* (4.5.3.3) */
149 unsigned short max_age
; /* (4.5.3.4) */
150 unsigned short hello_time
; /* (4.5.3.5) */
151 unsigned short forward_delay
; /* (4.5.3.6) */
152 bridge_id_t bridge_id
; /* (4.5.3.7) */
153 unsigned short bridge_max_age
; /* (4.5.3.8) */
154 unsigned short bridge_hello_time
; /* (4.5.3.9) */
155 unsigned short bridge_forward_delay
; /* (4.5.3.10) */
156 unsigned int top_change_detected
; /* (4.5.3.11) */
157 unsigned int top_change
; /* (4.5.3.12) */
158 unsigned short topology_change_time
; /* (4.5.3.13) */
159 unsigned short hold_time
; /* (4.5.3.14) */
160 unsigned int instance
;
163 /** Port Parameters (4.5.5) **/
165 unsigned short port_id
; /* (4.5.5.1) */
166 unsigned int state
; /* (4.5.5.2) */
167 unsigned int path_cost
; /* (4.5.5.3) */
168 bridge_id_t designated_root
; /* (4.5.5.4) */
169 unsigned int designated_cost
; /* (4.5.5.5) */
170 bridge_id_t designated_bridge
; /* (4.5.5.6) */
171 unsigned short designated_port
; /* (4.5.5.7) */
172 unsigned int top_change_ack
; /* (4.5.5.8) */
173 unsigned int config_pending
; /* (4.5.5.9) */
175 char ifname
[IFNAMSIZ
]; /* Make life easier for brcfg */
176 struct net_device
*dev
;
177 struct fdb
*fdb
; /* head of per port fdb chain */
182 /** types to support timers for this pseudo-implementation. **/
184 unsigned int active
; /* timer in use. */
185 unsigned int value
; /* current value of timer,
190 unsigned char ula
[6];
191 unsigned char pad
[2];
194 unsigned short flags
;
195 #define FDB_ENT_VALID 0x01
196 unsigned short mcast_count
;
197 unsigned int mcast_timer
; /* oldest xxxxxcast */
199 /* AVL tree of all addresses, sorted by address */
200 short fdb_avl_height
;
201 struct fdb
*fdb_avl_left
;
202 struct fdb
*fdb_avl_right
;
203 /* linked list of addresses for each port */
204 struct fdb
*fdb_next
;
207 /* data returned on BRCMD_DISPLAY_FDB */
209 unsigned char ula
[6];
214 struct fdb_info_hdr
{
215 int copied
; /* nb of entries copied to user */
216 int not_copied
; /* when user buffer is too small */
220 #define IS_BRIDGED 0x2e
223 #define BR_MAX_PROTOCOLS 32
224 #define BR_MAX_PROT_STATS BR_MAX_PROTOCOLS
226 /* policy values for policy field */
230 /* JRP: extra statistics for debug */
232 /* br_receive_frame counters */
233 int port_disable_up_stack
;
236 int forwarding_up_stack
;
239 /* br_tx_frame counters */
241 int port_not_disable
;
243 /* br_forward counters */
245 int forwarded_multicast
; /* up stack as well */
247 int aged_flood_unicast
;
248 int forwarded_unicast
;
249 int forwarded_unicast_up_stack
;
250 int forwarded_ip_up_stack
;
251 int forwarded_ip_up_stack_lie
; /* received on alternate device */
252 int arp_for_local_mac
;
254 int drop_same_port_aged
;
260 Bridge_data bridge_data
;
262 unsigned int exempt_protocols
;
263 unsigned short protocols
[BR_MAX_PROTOCOLS
];
264 unsigned short prot_id
[BR_MAX_PROT_STATS
]; /* Protocol encountered */
265 unsigned int prot_counter
[BR_MAX_PROT_STATS
]; /* How many packets ? */
266 br_stats_counter packet_cnts
;
267 unsigned int num_ports
;
268 Port_data port_data
[BR_MAX_PORTS
+ 1];
271 /* defined flags for br_stat.flags */
272 #define BR_UP 0x0001 /* bridging enabled */
273 #define BR_DEBUG 0x0002 /* debugging enabled */
274 #define BR_PROT_STATS 0x0004 /* protocol statistics enabled */
275 #define BR_STP_DISABLED 0x0008 /* Spanning tree protocol disabled */
284 #define BRCMD_BRIDGE_ENABLE 1
285 #define BRCMD_BRIDGE_DISABLE 2
286 #define BRCMD_PORT_ENABLE 3 /* arg1 = port */
287 #define BRCMD_PORT_DISABLE 4 /* arg1 = port */
288 #define BRCMD_SET_BRIDGE_PRIORITY 5 /* arg1 = priority */
289 #define BRCMD_SET_PORT_PRIORITY 6 /* arg1 = port, arg2 = priority */
290 #define BRCMD_SET_PATH_COST 7 /* arg1 = port, arg2 = cost */
291 #define BRCMD_DISPLAY_FDB 8
292 #define BRCMD_ENABLE_DEBUG 9
293 #define BRCMD_DISABLE_DEBUG 10
294 #define BRCMD_SET_POLICY 11 /* arg1 = default policy (1==bridge all) */
295 #define BRCMD_EXEMPT_PROTOCOL 12 /* arg1 = protocol (see net/if_ether.h) */
296 #define BRCMD_ENABLE_PROT_STATS 13
297 #define BRCMD_DISABLE_PROT_STATS 14
298 #define BRCMD_ZERO_PROT_STATS 15
299 #define BRCMD_TOGGLE_STP 16
300 #define BRCMD_IF_ENABLE 17 /* arg1 = if_index */
301 #define BRCMD_IF_DISABLE 18 /* arg1 = if_index */
302 #define BRCMD_SET_IF_PRIORITY 19 /* arg1 = if_index, arg2 = priority */
303 #define BRCMD_SET_IF_PATH_COST 20 /* arg1 = if_index, arg2 = cost */
305 /* prototypes of exported bridging functions... */
309 int br_receive_frame(struct sk_buff
*skb
); /* 3.5 */
310 int br_tx_frame(struct sk_buff
*skb
);
312 int br_ioctl(unsigned int cmd
, void *arg
);
313 void requeue_fdb(struct fdb
*node
, int new_port
);
315 struct fdb
*br_avl_find_addr(unsigned char addr
[6]);
316 struct fdb
*br_avl_insert (struct fdb
* new_node
);
317 void sprintf_avl (char **pbuffer
, struct fdb
* tree
, off_t
*pos
,int* len
, off_t offset
, int length
);
318 void br_avl_delete_by_port(int port
);
319 int br_call_bridge(struct sk_buff
*skb
, unsigned short type
);
320 void br_spacedevice_register(void);
324 extern struct br_stat br_stats
;
325 extern Port_data port_info
[];