Import 2.3.36
[davej-history.git] / include / net / br.h
blobbfa25b645476ff9d54bec5a2885fa810b159555e
1 #include <linux/config.h>
2 /*
3 * Constants and structure definitions for the bridging code
4 */
6 #if !defined(One)
7 #define Zero 0
8 #define One 1
9 #endif /* !defined(One) */
11 #if !defined(TRUE)
12 #define FALSE 0
13 #define TRUE 1
14 #endif /* !defined(TRUE) */
16 /** port states. **/
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
31 #endif
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
51 #define HOLD_TIME 1
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
61 * transmission time
63 #define Message_age_increment 1
65 #define No_port 0
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) **/
74 typedef struct {
75 union {
76 struct {
77 unsigned short priority;
78 unsigned char ula[6];
79 } p_u;
80 unsigned int id[2];
81 } bi;
82 } bridge_id_t;
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
91 */
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
103 typedef struct {
104 unsigned short protocol_id;
105 unsigned char protocol_version_id;
106 unsigned char type;
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;
117 } Config_bpdu;
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);
127 #else
128 #define config_bpdu_hton(config_bpdu)
129 #endif
130 #define config_bpdu_ntoh config_bpdu_hton
133 /** Topology Change Notification BPDU Parameters (4.5.2) **/
135 typedef struct {
136 unsigned short protocol_id;
137 unsigned char protocol_version_id;
138 unsigned char type;
139 } Tcn_bpdu;
141 #define BPDU_TYPE_CONFIG 0
142 #define BPDU_TYPE_TOPO_CHANGE 128
144 /** Bridge Parameters (4.5.3) **/
145 typedef struct {
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;
161 } Bridge_data;
163 /** Port Parameters (4.5.5) **/
164 typedef struct {
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) */
174 bridge_id_t ifmac;
175 char ifname[IFNAMSIZ]; /* Make life easier for brcfg */
176 struct net_device *dev;
177 struct fdb *fdb; /* head of per port fdb chain */
178 } Port_data;
182 /** types to support timers for this pseudo-implementation. **/
183 typedef struct {
184 unsigned int active; /* timer in use. */
185 unsigned int value; /* current value of timer,
186 * counting up. */
187 } Timer;
189 struct fdb {
190 unsigned char ula[6];
191 unsigned char pad[2];
192 unsigned short port;
193 unsigned int timer;
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 */
208 struct fdb_info {
209 unsigned char ula[6];
210 unsigned char port;
211 unsigned char flags;
212 unsigned int timer;
214 struct fdb_info_hdr {
215 int copied; /* nb of entries copied to user */
216 int not_copied; /* when user buffer is too small */
217 int cmd_time;
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 */
227 #define BR_ACCEPT 1
228 #define BR_REJECT 0
230 /* JRP: extra statistics for debug */
231 typedef struct {
232 /* br_receive_frame counters */
233 int port_disable_up_stack;
234 int rcv_bpdu;
235 int notForwarding;
236 int forwarding_up_stack;
237 int unknown_state;
239 /* br_tx_frame counters */
240 int port_disable;
241 int port_not_disable;
243 /* br_forward counters */
244 int local_multicast;
245 int forwarded_multicast; /* up stack as well */
246 int flood_unicast;
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;
253 int drop_same_port;
254 int drop_same_port_aged;
255 int drop_multicast;
256 } br_stats_counter;
258 struct br_stat {
259 unsigned int flags;
260 Bridge_data bridge_data;
261 unsigned int policy;
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 */
277 struct br_cf {
278 unsigned int cmd;
279 unsigned int arg1;
280 unsigned int arg2;
283 /* defined cmds */
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... */
307 #ifdef __KERNEL__
308 void br_init(void);
309 int br_receive_frame(struct sk_buff *skb); /* 3.5 */
310 int br_tx_frame(struct sk_buff *skb);
311 int brg_init(void);
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);
322 /* externs */
324 extern struct br_stat br_stats;
325 extern Port_data port_info[];
327 #endif