]> git.ipfire.org Git - people/ms/rstp.git/blob - rstp.h
Merge remote-tracking branch 'upstream/master'
[people/ms/rstp.git] / rstp.h
1 #ifndef _RSTP_H
2 #define _RSTP_H
3
4 /*********************************************************************
5 This is an implementation of the Rapid Spanning Tree Protocol
6 based on the 802.1D-2004 standard.
7 *********************************************************************/
8
9 struct STP_Bridge_;
10 typedef struct STP_Bridge_ STP_Bridge;
11 struct STP_Port_;
12 typedef struct STP_Port_ STP_Port;
13
14 typedef struct STP_macaddr
15 {
16 unsigned char addr[6];
17 } STP_MacAddress;
18
19
20 /****** Creating and deleting ******/
21
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.
24 */
25 STP_Bridge *STP_IN_bridge_create(void *user_ref);
26
27 /* All ports will be deleted, don't reference them */
28 void STP_IN_bridge_delete(STP_Bridge *);
29
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.
32 */
33 STP_Port *STP_IN_port_create(STP_Bridge *,
34 unsigned int port_number, void *user_ref);
35
36 void STP_IN_port_delete(STP_Port *);
37
38 /****** enable/disable ******/
39
40 /* When disabled, we can set config without any immediate effect.
41 State machine is reinitialized when we enable.
42 */
43 void STP_IN_set_bridge_enable(STP_Bridge *, unsigned int enabled);
44
45 /****** Configuration ******/
46
47 typedef struct STP_BridgeConfig_
48 {
49 int set_bridge_protocol_version;
50 unsigned int bridge_protocol_version;
51
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.
55 */
56 unsigned int set_bridge_address;
57 STP_MacAddress bridge_address;
58
59 unsigned int set_bridge_priority;
60 unsigned int bridge_priority;
61
62 unsigned int set_bridge_hello_time;
63 unsigned int bridge_hello_time;
64
65 unsigned int set_bridge_max_age;
66 unsigned int bridge_max_age;
67
68 unsigned int set_bridge_forward_delay;
69 unsigned int bridge_forward_delay;
70
71 unsigned int set_bridge_tx_hold_count;
72 unsigned int bridge_tx_hold_count;
73 } STP_BridgeConfig;
74
75 int STP_IN_set_bridge_config(STP_Bridge *, const STP_BridgeConfig *);
76
77 /* Alternate forms to set single fields */
78
79 /* 0 for STP, 2 for RSTP */
80 int STP_IN_set_protocol_version(STP_Bridge *, unsigned int version);
81
82 /* This reinitializes the bridge if bridge is enabled */
83 int STP_IN_set_bridge_address(STP_Bridge *, const STP_MacAddress *);
84
85 int STP_IN_set_bridge_priority(STP_Bridge *, unsigned int priority);
86
87 /* Just for compatibility interfacing. Always fails */
88 int STP_IN_set_bridge_hello_time(STP_Bridge *, unsigned int hello_time);
89
90 int STP_IN_set_bridge_max_age(STP_Bridge *, unsigned int max_age);
91
92 int STP_IN_set_bridge_forward_delay(STP_Bridge *, unsigned int fwd_delay);
93
94 int STP_IN_set_tx_hold_count(STP_Bridge *, unsigned int count);
95
96
97 typedef struct STP_PortConfig_
98 {
99 unsigned int set_port_priority;
100 unsigned int port_priority;
101
102 unsigned int set_port_pathcost;
103 unsigned int port_pathcost;
104
105 unsigned int set_port_admin_edge;
106 unsigned int port_admin_edge;
107
108 unsigned int set_port_auto_edge;
109 unsigned int port_auto_edge;
110
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
116 } STP_PortConfig;
117
118 int STP_IN_set_port_config(STP_Port *, const STP_PortConfig *);
119
120 /* Alternate forms to set single fields */
121
122 int STP_IN_set_port_priority(STP_Port *, unsigned int priority);
123
124 int STP_IN_set_port_pathcost(STP_Port *, unsigned int pcost);
125
126 /* edge is 0 or 1 - boolean */
127 int STP_IN_set_port_admin_edge(STP_Port *, unsigned int edge);
128
129 int STP_IN_set_port_auto_edge(STP_Port *, unsigned int edge);
130
131 /* See STP_PortConfig struct for allowed values of p2p */
132 int STP_IN_set_port_admin_p2p(STP_Port *, unsigned int p2p);
133
134
135 /* Force migration check */
136 int STP_IN_port_mcheck(STP_Port *);
137
138 /****** Notifications ******/
139
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);
143
144 /* No MAC or LLC header included */
145 void STP_IN_rx_bpdu(STP_Port *, const void *base, unsigned int len);
146
147 /* Should be called every second, triggers timer operation. */
148 void STP_IN_one_second(STP_Bridge *);
149
150 /****** Status ******/
151
152 typedef struct STP_BridgeStatus_
153 {
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 */
172 } STP_BridgeStatus;
173
174 void STP_IN_get_bridge_status(STP_Bridge *, STP_BridgeStatus *);
175
176 typedef struct STP_PortStatus_
177 {
178 unsigned int uptime;
179 unsigned int state;
180 #define STP_PORT_STATE_DISCARDING 0
181 #define STP_PORT_STATE_LEARNING 1
182 #define STP_PORT_STATE_FORWARDING 2
183 unsigned int id;
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.
197 */
198 unsigned int admin_p2p;
199 unsigned int oper_p2p;
200 } STP_PortStatus;
201
202 void STP_IN_get_port_status(STP_Port *, STP_PortStatus *);
203
204 /****** Procedures to be provided by user ******/
205
206 /* No MAC or LLC header included */
207 void STP_OUT_tx_bpdu(void *port_user_ref, void *base, unsigned int len);
208
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);
212
213 void STP_OUT_port_fdb_flush(void *user_ref);
214
215 #define STP_LOG_LEVEL_ERROR 1
216 #define STP_LOG_LEVEL_DEBUG 10
217
218 void STP_OUT_logmsg(void *br_user_ref, void *port_user_ref,
219 int level, char *fmt, ...);
220
221
222 void *STP_OUT_mem_zalloc(unsigned int size);
223
224 void STP_OUT_mem_free(void *);
225
226 #endif