4 /*********************************************************************
5 This is an implementation of the Rapid Spanning Tree Protocol
6 based on the 802.1D-2004 standard.
7 *********************************************************************/
10 typedef struct STP_Bridge_ STP_Bridge
;
12 typedef struct STP_Port_ STP_Port
;
14 typedef struct STP_macaddr
16 unsigned char addr
[6];
20 /****** Creating and deleting ******/
22 /* user_ref is a pointer that the STP part uses to call the system part
23 Bridge is created as disabled. You need to enable it.
25 STP_Bridge
*STP_IN_bridge_create(void *user_ref
);
27 /* All ports will be deleted, don't reference them */
28 void STP_IN_bridge_delete(STP_Bridge
*);
30 /* user_ref is a pointer that the STP part uses to call the system part
31 Port is created as disabled. You need to enable it.
33 STP_Port
*STP_IN_port_create(STP_Bridge
*,
34 unsigned int port_number
, void *user_ref
);
36 void STP_IN_port_delete(STP_Port
*);
38 /****** enable/disable ******/
40 /* When disabled, we can set config without any immediate effect.
41 State machine is reinitialized when we enable.
43 void STP_IN_set_bridge_enable(STP_Bridge
*, unsigned int enabled
);
45 /****** Configuration ******/
47 typedef struct STP_BridgeConfig_
49 int set_bridge_protocol_version
;
50 unsigned int bridge_protocol_version
;
52 /* Setting bridge address dynamically is not part of the standard
53 It is convenient for us to interface with Linux bridges where this
54 may happen. We reinit the state machine when this is changed.
56 unsigned int set_bridge_address
;
57 STP_MacAddress bridge_address
;
59 unsigned int set_bridge_priority
;
60 unsigned int bridge_priority
;
62 unsigned int set_bridge_hello_time
;
63 unsigned int bridge_hello_time
;
65 unsigned int set_bridge_max_age
;
66 unsigned int bridge_max_age
;
68 unsigned int set_bridge_forward_delay
;
69 unsigned int bridge_forward_delay
;
71 unsigned int set_bridge_tx_hold_count
;
72 unsigned int bridge_tx_hold_count
;
75 int STP_IN_set_bridge_config(STP_Bridge
*, const STP_BridgeConfig
*);
77 /* Alternate forms to set single fields */
79 /* 0 for STP, 2 for RSTP */
80 int STP_IN_set_protocol_version(STP_Bridge
*, unsigned int version
);
82 /* This reinitializes the bridge if bridge is enabled */
83 int STP_IN_set_bridge_address(STP_Bridge
*, const STP_MacAddress
*);
85 int STP_IN_set_bridge_priority(STP_Bridge
*, unsigned int priority
);
87 /* Just for compatibility interfacing. Always fails */
88 int STP_IN_set_bridge_hello_time(STP_Bridge
*, unsigned int hello_time
);
90 int STP_IN_set_bridge_max_age(STP_Bridge
*, unsigned int max_age
);
92 int STP_IN_set_bridge_forward_delay(STP_Bridge
*, unsigned int fwd_delay
);
94 int STP_IN_set_tx_hold_count(STP_Bridge
*, unsigned int count
);
97 typedef struct STP_PortConfig_
99 unsigned int set_port_priority
;
100 unsigned int port_priority
;
102 unsigned int set_port_pathcost
;
103 unsigned int port_pathcost
;
105 unsigned int set_port_admin_edge
;
106 unsigned int port_admin_edge
;
108 unsigned int set_port_auto_edge
;
109 unsigned int port_auto_edge
;
111 unsigned int set_port_admin_p2p
;
112 unsigned int port_admin_p2p
;
113 #define STP_ADMIN_P2P_FORCE_FALSE 0
114 #define STP_ADMIN_P2P_FORCE_TRUE 1
115 #define STP_ADMIN_P2P_AUTO 2
118 int STP_IN_set_port_config(STP_Port
*, const STP_PortConfig
*);
120 /* Alternate forms to set single fields */
122 int STP_IN_set_port_priority(STP_Port
*, unsigned int priority
);
124 int STP_IN_set_port_pathcost(STP_Port
*, unsigned int pcost
);
126 /* edge is 0 or 1 - boolean */
127 int STP_IN_set_port_admin_edge(STP_Port
*, unsigned int edge
);
129 int STP_IN_set_port_auto_edge(STP_Port
*, unsigned int edge
);
131 /* See STP_PortConfig struct for allowed values of p2p */
132 int STP_IN_set_port_admin_p2p(STP_Port
*, unsigned int p2p
);
135 /* Force migration check */
136 int STP_IN_port_mcheck(STP_Port
*);
138 /****** Notifications ******/
140 /* speed and duplex matter only if enabled */
141 void STP_IN_set_port_enable(STP_Port
*, unsigned int enabled
,
142 unsigned int speed
, unsigned int duplex
);
144 /* No MAC or LLC header included */
145 void STP_IN_rx_bpdu(STP_Port
*, const void *base
, unsigned int len
);
147 /* Should be called every second, triggers timer operation. */
148 void STP_IN_one_second(STP_Bridge
*);
150 /****** Status ******/
152 typedef struct STP_BridgeStatus_
154 unsigned char bridge_id
[8];
155 unsigned int time_since_topology_change
;
156 unsigned int topology_change_count
;
157 unsigned int topology_change
; /* boolean */
158 unsigned char designated_root
[8];
159 unsigned int root_path_cost
;
160 /* Not in standard, but part of rootPriority */
161 unsigned char designated_bridge
[8];
162 unsigned int root_port
;
163 unsigned int max_age
;
164 unsigned int hello_time
;
165 unsigned int forward_delay
;
166 unsigned int bridge_max_age
;
167 unsigned int bridge_hello_time
;
168 unsigned int bridge_forward_delay
;
169 unsigned int tx_hold_count
;
170 unsigned int protocol_version
;
171 unsigned int enabled
; /* Whether we are running state machines */
174 void STP_IN_get_bridge_status(STP_Bridge
*, STP_BridgeStatus
*);
176 typedef struct STP_PortStatus_
180 #define STP_PORT_STATE_DISCARDING 0
181 #define STP_PORT_STATE_LEARNING 1
182 #define STP_PORT_STATE_FORWARDING 2
184 unsigned int admin_path_cost
;
185 unsigned int path_cost
;
186 unsigned char designated_root
[8];
187 unsigned int designated_cost
;
188 unsigned char designated_bridge
[8];
189 unsigned int designated_port
;
190 unsigned int tc_ack
; /* booleans */
191 unsigned int admin_edge_port
;
192 unsigned int oper_edge_port
;
193 unsigned int auto_edge_port
;
194 unsigned int enabled
; /* Is this MAC Enabled or MAC operational?
195 It is false both if ifconfig <port> down
196 and if the link status is down.
198 unsigned int admin_p2p
;
199 unsigned int oper_p2p
;
202 void STP_IN_get_port_status(STP_Port
*, STP_PortStatus
*);
204 /****** Procedures to be provided by user ******/
206 /* No MAC or LLC header included */
207 void STP_OUT_tx_bpdu(void *port_user_ref
, void *base
, unsigned int len
);
209 #define STP_PORT_STATE_FLAG_LEARNING 1
210 #define STP_PORT_STATE_FLAG_FORWARDING 2
211 void STP_OUT_port_set_state(void *user_ref
, unsigned int flags
);
213 void STP_OUT_port_fdb_flush(void *user_ref
);
215 #define STP_LOG_LEVEL_ERROR 1
216 #define STP_LOG_LEVEL_DEBUG 10
218 void STP_OUT_logmsg(void *br_user_ref
, void *port_user_ref
,
219 int level
, char *fmt
, ...);
222 void *STP_OUT_mem_zalloc(unsigned int size
);
224 void STP_OUT_mem_free(void *);