blob: 45f1ff113af9591bb5d7d3f05c0792b99fc4103d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Spanning tree protocol; generic parts
3 * Linux ethernet bridge
4 *
5 * Authors:
6 * Lennert Buytenhek <buytenh@gnu.org>
7 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 */
13#include <linux/kernel.h>
Franck Bui-Huu82524742008-05-12 21:21:05 +020014#include <linux/rculist.h>
Scott Feldman38dcf352014-11-28 14:34:20 +010015#include <net/switchdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#include "br_private.h"
18#include "br_private_stp.h"
19
20/* since time values in bpdu are in jiffies and then scaled (1/256)
Joakim Tjernlundaaca7352012-03-01 08:12:18 +000021 * before sending, make sure that is at least one STP tick.
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 */
Joakim Tjernlundaaca7352012-03-01 08:12:18 +000023#define MESSAGE_AGE_INCR ((HZ / 256) + 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -070025static const char *const br_port_state_names[] = {
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +090026 [BR_STATE_DISABLED] = "disabled",
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 [BR_STATE_LISTENING] = "listening",
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +090028 [BR_STATE_LEARNING] = "learning",
29 [BR_STATE_FORWARDING] = "forwarding",
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 [BR_STATE_BLOCKING] = "blocking",
31};
32
33void br_log_state(const struct net_bridge_port *p)
34{
Paulius Zaleckasd9e179e2012-03-06 22:25:14 +000035 br_info(p->br, "port %u(%s) entered %s state\n",
Eric Dumazet95c96172012-04-15 05:58:06 +000036 (unsigned int) p->port_no, p->dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 br_port_state_names[p->state]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
Florian Fainelli775dd692014-09-30 16:13:19 -070040void br_set_state(struct net_bridge_port *p, unsigned int state)
41{
Scott Feldman35636062015-05-10 09:47:51 -070042 struct switchdev_attr attr = {
43 .id = SWITCHDEV_ATTR_PORT_STP_STATE,
Scott Feldman42275bd2015-05-13 11:16:50 -070044 .u.stp_state = state,
Scott Feldman35636062015-05-10 09:47:51 -070045 };
Scott Feldman38dcf352014-11-28 14:34:20 +010046 int err;
47
Florian Fainelli775dd692014-09-30 16:13:19 -070048 p->state = state;
Scott Feldman35636062015-05-10 09:47:51 -070049 err = switchdev_port_attr_set(p->dev, &attr);
Scott Feldman38dcf352014-11-28 14:34:20 +010050 if (err && err != -EOPNOTSUPP)
51 br_warn(p->br, "error setting offload STP state on port %u(%s)\n",
52 (unsigned int) p->port_no, p->dev->name);
Florian Fainelli775dd692014-09-30 16:13:19 -070053}
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055/* called under bridge lock */
56struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no)
57{
58 struct net_bridge_port *p;
59
60 list_for_each_entry_rcu(p, &br->port_list, list) {
61 if (p->port_no == port_no)
62 return p;
63 }
64
65 return NULL;
66}
67
68/* called under bridge lock */
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +090069static int br_should_become_root_port(const struct net_bridge_port *p,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 u16 root_port)
71{
72 struct net_bridge *br;
73 struct net_bridge_port *rp;
74 int t;
75
76 br = p->br;
77 if (p->state == BR_STATE_DISABLED ||
78 br_is_designated_port(p))
79 return 0;
80
81 if (memcmp(&br->bridge_id, &p->designated_root, 8) <= 0)
82 return 0;
83
84 if (!root_port)
85 return 1;
86
87 rp = br_get_port(br, root_port);
88
89 t = memcmp(&p->designated_root, &rp->designated_root, 8);
90 if (t < 0)
91 return 1;
92 else if (t > 0)
93 return 0;
94
95 if (p->designated_cost + p->path_cost <
96 rp->designated_cost + rp->path_cost)
97 return 1;
98 else if (p->designated_cost + p->path_cost >
99 rp->designated_cost + rp->path_cost)
100 return 0;
101
102 t = memcmp(&p->designated_bridge, &rp->designated_bridge, 8);
103 if (t < 0)
104 return 1;
105 else if (t > 0)
106 return 0;
107
108 if (p->designated_port < rp->designated_port)
109 return 1;
110 else if (p->designated_port > rp->designated_port)
111 return 0;
112
113 if (p->port_id < rp->port_id)
114 return 1;
115
116 return 0;
117}
118
stephen hemminger1007dd12012-11-13 07:53:08 +0000119static void br_root_port_block(const struct net_bridge *br,
120 struct net_bridge_port *p)
121{
122
123 br_notice(br, "port %u(%s) tried to become root port (blocked)",
124 (unsigned int) p->port_no, p->dev->name);
125
Florian Fainelli775dd692014-09-30 16:13:19 -0700126 br_set_state(p, BR_STATE_LISTENING);
stephen hemminger1007dd12012-11-13 07:53:08 +0000127 br_log_state(p);
128 br_ifinfo_notify(RTM_NEWLINK, p);
129
130 if (br->forward_delay > 0)
131 mod_timer(&p->forward_delay_timer, jiffies + br->forward_delay);
132}
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134/* called under bridge lock */
135static void br_root_selection(struct net_bridge *br)
136{
137 struct net_bridge_port *p;
138 u16 root_port = 0;
139
140 list_for_each_entry(p, &br->port_list, list) {
stephen hemminger1007dd12012-11-13 07:53:08 +0000141 if (!br_should_become_root_port(p, root_port))
142 continue;
143
144 if (p->flags & BR_ROOT_BLOCK)
145 br_root_port_block(br, p);
146 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 root_port = p->port_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 }
149
150 br->root_port = root_port;
151
152 if (!root_port) {
153 br->designated_root = br->bridge_id;
154 br->root_path_cost = 0;
155 } else {
156 p = br_get_port(br, root_port);
157 br->designated_root = p->designated_root;
158 br->root_path_cost = p->designated_cost + p->path_cost;
159 }
160}
161
162/* called under bridge lock */
163void br_become_root_bridge(struct net_bridge *br)
164{
165 br->max_age = br->bridge_max_age;
166 br->hello_time = br->bridge_hello_time;
167 br->forward_delay = br->bridge_forward_delay;
168 br_topology_change_detection(br);
169 del_timer(&br->tcn_timer);
170
171 if (br->dev->flags & IFF_UP) {
172 br_config_bpdu_generation(br);
173 mod_timer(&br->hello_timer, jiffies + br->hello_time);
174 }
175}
176
177/* called under bridge lock */
178void br_transmit_config(struct net_bridge_port *p)
179{
180 struct br_config_bpdu bpdu;
181 struct net_bridge *br;
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 if (timer_pending(&p->hold_timer)) {
184 p->config_pending = 1;
185 return;
186 }
187
188 br = p->br;
189
190 bpdu.topology_change = br->topology_change;
191 bpdu.topology_change_ack = p->topology_change_ack;
192 bpdu.root = br->designated_root;
193 bpdu.root_path_cost = br->root_path_cost;
194 bpdu.bridge_id = br->bridge_id;
195 bpdu.port_id = p->port_id;
196 if (br_is_root_bridge(br))
197 bpdu.message_age = 0;
198 else {
199 struct net_bridge_port *root
200 = br_get_port(br, br->root_port);
stephen hemminger0c031502011-07-22 07:47:06 +0000201 bpdu.message_age = (jiffies - root->designated_age)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 + MESSAGE_AGE_INCR;
203 }
204 bpdu.max_age = br->max_age;
205 bpdu.hello_time = br->hello_time;
206 bpdu.forward_delay = br->forward_delay;
207
208 if (bpdu.message_age < br->max_age) {
209 br_send_config_bpdu(p, &bpdu);
210 p->topology_change_ack = 0;
211 p->config_pending = 0;
Stephen Hemminger9a834b82007-05-31 01:21:39 -0700212 mod_timer(&p->hold_timer,
213 round_jiffies(jiffies + BR_HOLD_TIME));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 }
215}
216
217/* called under bridge lock */
stephen hemminger160d73b2011-07-22 07:47:10 +0000218static void br_record_config_information(struct net_bridge_port *p,
219 const struct br_config_bpdu *bpdu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
221 p->designated_root = bpdu->root;
222 p->designated_cost = bpdu->root_path_cost;
223 p->designated_bridge = bpdu->bridge_id;
224 p->designated_port = bpdu->port_id;
Joakim Tjernlund709e1b52012-03-01 08:12:19 +0000225 p->designated_age = jiffies - bpdu->message_age;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900227 mod_timer(&p->message_age_timer, jiffies
Chris Healy9a062012013-09-11 21:37:47 -0700228 + (bpdu->max_age - bpdu->message_age));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229}
230
231/* called under bridge lock */
stephen hemminger160d73b2011-07-22 07:47:10 +0000232static void br_record_config_timeout_values(struct net_bridge *br,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 const struct br_config_bpdu *bpdu)
234{
235 br->max_age = bpdu->max_age;
236 br->hello_time = bpdu->hello_time;
237 br->forward_delay = bpdu->forward_delay;
238 br->topology_change = bpdu->topology_change;
239}
240
241/* called under bridge lock */
242void br_transmit_tcn(struct net_bridge *br)
243{
stephen hemminger91bc0332013-04-30 05:29:27 +0000244 struct net_bridge_port *p;
245
246 p = br_get_port(br, br->root_port);
247 if (p)
248 br_send_tcn_bpdu(p);
249 else
250 br_notice(br, "root port %u not found for topology notice\n",
251 br->root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252}
253
254/* called under bridge lock */
255static int br_should_become_designated_port(const struct net_bridge_port *p)
256{
257 struct net_bridge *br;
258 int t;
259
260 br = p->br;
261 if (br_is_designated_port(p))
262 return 1;
263
264 if (memcmp(&p->designated_root, &br->designated_root, 8))
265 return 1;
266
267 if (br->root_path_cost < p->designated_cost)
268 return 1;
269 else if (br->root_path_cost > p->designated_cost)
270 return 0;
271
272 t = memcmp(&br->bridge_id, &p->designated_bridge, 8);
273 if (t < 0)
274 return 1;
275 else if (t > 0)
276 return 0;
277
278 if (p->port_id < p->designated_port)
279 return 1;
280
281 return 0;
282}
283
284/* called under bridge lock */
285static void br_designated_port_selection(struct net_bridge *br)
286{
287 struct net_bridge_port *p;
288
289 list_for_each_entry(p, &br->port_list, list) {
290 if (p->state != BR_STATE_DISABLED &&
291 br_should_become_designated_port(p))
292 br_become_designated_port(p);
293
294 }
295}
296
297/* called under bridge lock */
stephen hemminger160d73b2011-07-22 07:47:10 +0000298static int br_supersedes_port_info(const struct net_bridge_port *p,
299 const struct br_config_bpdu *bpdu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
301 int t;
302
303 t = memcmp(&bpdu->root, &p->designated_root, 8);
304 if (t < 0)
305 return 1;
306 else if (t > 0)
307 return 0;
308
309 if (bpdu->root_path_cost < p->designated_cost)
310 return 1;
311 else if (bpdu->root_path_cost > p->designated_cost)
312 return 0;
313
314 t = memcmp(&bpdu->bridge_id, &p->designated_bridge, 8);
315 if (t < 0)
316 return 1;
317 else if (t > 0)
318 return 0;
319
320 if (memcmp(&bpdu->bridge_id, &p->br->bridge_id, 8))
321 return 1;
322
323 if (bpdu->port_id <= p->designated_port)
324 return 1;
325
326 return 0;
327}
328
329/* called under bridge lock */
stephen hemminger160d73b2011-07-22 07:47:10 +0000330static void br_topology_change_acknowledged(struct net_bridge *br)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
332 br->topology_change_detected = 0;
333 del_timer(&br->tcn_timer);
334}
335
336/* called under bridge lock */
337void br_topology_change_detection(struct net_bridge *br)
338{
339 int isroot = br_is_root_bridge(br);
340
Stephen Hemminger4f0611a2009-05-15 06:11:58 +0000341 if (br->stp_enabled != BR_KERNEL_STP)
342 return;
343
stephen hemminger28a16c92010-05-10 09:31:09 +0000344 br_info(br, "topology change detected, %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 isroot ? "propagating" : "sending tcn bpdu");
346
347 if (isroot) {
348 br->topology_change = 1;
349 mod_timer(&br->topology_change_timer, jiffies
350 + br->bridge_forward_delay + br->bridge_max_age);
351 } else if (!br->topology_change_detected) {
352 br_transmit_tcn(br);
353 mod_timer(&br->tcn_timer, jiffies + br->bridge_hello_time);
354 }
355
356 br->topology_change_detected = 1;
357}
358
359/* called under bridge lock */
360void br_config_bpdu_generation(struct net_bridge *br)
361{
362 struct net_bridge_port *p;
363
364 list_for_each_entry(p, &br->port_list, list) {
365 if (p->state != BR_STATE_DISABLED &&
366 br_is_designated_port(p))
367 br_transmit_config(p);
368 }
369}
370
371/* called under bridge lock */
stephen hemminger160d73b2011-07-22 07:47:10 +0000372static void br_reply(struct net_bridge_port *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
374 br_transmit_config(p);
375}
376
377/* called under bridge lock */
378void br_configuration_update(struct net_bridge *br)
379{
380 br_root_selection(br);
381 br_designated_port_selection(br);
382}
383
384/* called under bridge lock */
385void br_become_designated_port(struct net_bridge_port *p)
386{
387 struct net_bridge *br;
388
389 br = p->br;
390 p->designated_root = br->designated_root;
391 p->designated_cost = br->root_path_cost;
392 p->designated_bridge = br->bridge_id;
393 p->designated_port = p->port_id;
394}
395
396
397/* called under bridge lock */
398static void br_make_blocking(struct net_bridge_port *p)
399{
400 if (p->state != BR_STATE_DISABLED &&
401 p->state != BR_STATE_BLOCKING) {
402 if (p->state == BR_STATE_FORWARDING ||
403 p->state == BR_STATE_LEARNING)
404 br_topology_change_detection(p->br);
405
Florian Fainelli775dd692014-09-30 16:13:19 -0700406 br_set_state(p, BR_STATE_BLOCKING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 br_log_state(p);
stephen hemminger4ecb9612011-07-22 07:47:09 +0000408 br_ifinfo_notify(RTM_NEWLINK, p);
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 del_timer(&p->forward_delay_timer);
411 }
412}
413
414/* called under bridge lock */
415static void br_make_forwarding(struct net_bridge_port *p)
416{
Stephen Hemmingeref647f12008-08-05 18:42:51 -0700417 struct net_bridge *br = p->br;
Stephen Hemminger9cde0702007-03-21 14:22:44 -0700418
Stephen Hemmingeref647f12008-08-05 18:42:51 -0700419 if (p->state != BR_STATE_BLOCKING)
420 return;
421
stephen hemmingera461c022011-03-10 05:57:04 +0000422 if (br->stp_enabled == BR_NO_STP || br->forward_delay == 0) {
Florian Fainelli775dd692014-09-30 16:13:19 -0700423 br_set_state(p, BR_STATE_FORWARDING);
Stephen Hemmingeref647f12008-08-05 18:42:51 -0700424 br_topology_change_detection(br);
425 del_timer(&p->forward_delay_timer);
stephen hemminger160d73b2011-07-22 07:47:10 +0000426 } else if (br->stp_enabled == BR_KERNEL_STP)
Florian Fainelli775dd692014-09-30 16:13:19 -0700427 br_set_state(p, BR_STATE_LISTENING);
Stephen Hemmingeref647f12008-08-05 18:42:51 -0700428 else
Florian Fainelli775dd692014-09-30 16:13:19 -0700429 br_set_state(p, BR_STATE_LEARNING);
Stephen Hemmingeref647f12008-08-05 18:42:51 -0700430
Herbert Xu3fe2d7c2010-02-28 00:49:38 -0800431 br_multicast_enable_port(p);
Stephen Hemmingeref647f12008-08-05 18:42:51 -0700432 br_log_state(p);
stephen hemminger4ecb9612011-07-22 07:47:09 +0000433 br_ifinfo_notify(RTM_NEWLINK, p);
Stephen Hemmingeref647f12008-08-05 18:42:51 -0700434
435 if (br->forward_delay != 0)
436 mod_timer(&p->forward_delay_timer, jiffies + br->forward_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
439/* called under bridge lock */
440void br_port_state_selection(struct net_bridge *br)
441{
442 struct net_bridge_port *p;
stephen hemminger1faa4352011-03-07 08:34:06 +0000443 unsigned int liveports = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445 list_for_each_entry(p, &br->port_list, list) {
stephen hemminger1faa4352011-03-07 08:34:06 +0000446 if (p->state == BR_STATE_DISABLED)
447 continue;
448
Vitalii Demianetsb03b6dd2011-11-25 00:16:37 +0000449 /* Don't change port states if userspace is handling STP */
450 if (br->stp_enabled != BR_USER_STP) {
451 if (p->port_no == br->root_port) {
452 p->config_pending = 0;
453 p->topology_change_ack = 0;
454 br_make_forwarding(p);
455 } else if (br_is_designated_port(p)) {
456 del_timer(&p->message_age_timer);
457 br_make_forwarding(p);
458 } else {
459 p->config_pending = 0;
460 p->topology_change_ack = 0;
461 br_make_blocking(p);
462 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 }
464
stephen hemminger1faa4352011-03-07 08:34:06 +0000465 if (p->state == BR_STATE_FORWARDING)
466 ++liveports;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 }
stephen hemminger1faa4352011-03-07 08:34:06 +0000468
469 if (liveports == 0)
470 netif_carrier_off(br->dev);
471 else
472 netif_carrier_on(br->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473}
474
475/* called under bridge lock */
stephen hemminger160d73b2011-07-22 07:47:10 +0000476static void br_topology_change_acknowledge(struct net_bridge_port *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
478 p->topology_change_ack = 1;
479 br_transmit_config(p);
480}
481
482/* called under bridge lock */
stephen hemminger160d73b2011-07-22 07:47:10 +0000483void br_received_config_bpdu(struct net_bridge_port *p,
484 const struct br_config_bpdu *bpdu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
486 struct net_bridge *br;
487 int was_root;
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 br = p->br;
490 was_root = br_is_root_bridge(br);
491
492 if (br_supersedes_port_info(p, bpdu)) {
493 br_record_config_information(p, bpdu);
494 br_configuration_update(br);
495 br_port_state_selection(br);
496
497 if (!br_is_root_bridge(br) && was_root) {
498 del_timer(&br->hello_timer);
499 if (br->topology_change_detected) {
500 del_timer(&br->topology_change_timer);
501 br_transmit_tcn(br);
502
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900503 mod_timer(&br->tcn_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 jiffies + br->bridge_hello_time);
505 }
506 }
507
508 if (p->port_no == br->root_port) {
509 br_record_config_timeout_values(br, bpdu);
510 br_config_bpdu_generation(br);
511 if (bpdu->topology_change_ack)
512 br_topology_change_acknowledged(br);
513 }
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900514 } else if (br_is_designated_port(p)) {
515 br_reply(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
517}
518
519/* called under bridge lock */
520void br_received_tcn_bpdu(struct net_bridge_port *p)
521{
522 if (br_is_designated_port(p)) {
stephen hemminger28a16c92010-05-10 09:31:09 +0000523 br_info(p->br, "port %u(%s) received tcn bpdu\n",
Eric Dumazet95c96172012-04-15 05:58:06 +0000524 (unsigned int) p->port_no, p->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 br_topology_change_detection(p->br);
527 br_topology_change_acknowledge(p);
528 }
529}
stephen hemminger14f98f22011-04-04 14:03:33 +0000530
531/* Change bridge STP parameter */
532int br_set_hello_time(struct net_bridge *br, unsigned long val)
533{
534 unsigned long t = clock_t_to_jiffies(val);
535
536 if (t < BR_MIN_HELLO_TIME || t > BR_MAX_HELLO_TIME)
537 return -ERANGE;
538
539 spin_lock_bh(&br->lock);
540 br->bridge_hello_time = t;
541 if (br_is_root_bridge(br))
542 br->hello_time = br->bridge_hello_time;
543 spin_unlock_bh(&br->lock);
544 return 0;
545}
546
547int br_set_max_age(struct net_bridge *br, unsigned long val)
548{
549 unsigned long t = clock_t_to_jiffies(val);
550
551 if (t < BR_MIN_MAX_AGE || t > BR_MAX_MAX_AGE)
552 return -ERANGE;
553
554 spin_lock_bh(&br->lock);
555 br->bridge_max_age = t;
556 if (br_is_root_bridge(br))
557 br->max_age = br->bridge_max_age;
558 spin_unlock_bh(&br->lock);
559 return 0;
560
561}
562
Herbert Xube4f1542013-09-12 17:12:05 +1000563void __br_set_forward_delay(struct net_bridge *br, unsigned long t)
stephen hemminger14f98f22011-04-04 14:03:33 +0000564{
stephen hemminger14f98f22011-04-04 14:03:33 +0000565 br->bridge_forward_delay = t;
566 if (br_is_root_bridge(br))
567 br->forward_delay = br->bridge_forward_delay;
Herbert Xube4f1542013-09-12 17:12:05 +1000568}
569
570int br_set_forward_delay(struct net_bridge *br, unsigned long val)
571{
572 unsigned long t = clock_t_to_jiffies(val);
573 int err = -ERANGE;
574
575 spin_lock_bh(&br->lock);
576 if (br->stp_enabled != BR_NO_STP &&
577 (t < BR_MIN_FORWARD_DELAY || t > BR_MAX_FORWARD_DELAY))
578 goto unlock;
579
580 __br_set_forward_delay(br, t);
581 err = 0;
582
583unlock:
stephen hemminger14f98f22011-04-04 14:03:33 +0000584 spin_unlock_bh(&br->lock);
Herbert Xube4f1542013-09-12 17:12:05 +1000585 return err;
stephen hemminger14f98f22011-04-04 14:03:33 +0000586}