]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Spanning tree protocol; timer-related code | |
3 | * Linux ethernet bridge | |
4 | * | |
5 | * Authors: | |
6 | * Lennert Buytenhek <buytenh@gnu.org> | |
7 | * | |
1da177e4 LT |
8 | * 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 | ||
14 | #include <linux/kernel.h> | |
15 | #include <linux/times.h> | |
1da177e4 LT |
16 | |
17 | #include "br_private.h" | |
18 | #include "br_private_stp.h" | |
19 | ||
20 | /* called under bridge lock */ | |
21 | static int br_is_designated_for_some_port(const struct net_bridge *br) | |
22 | { | |
23 | struct net_bridge_port *p; | |
24 | ||
25 | list_for_each_entry(p, &br->port_list, list) { | |
26 | if (p->state != BR_STATE_DISABLED && | |
9d6f229f | 27 | !memcmp(&p->designated_bridge, &br->bridge_id, 8)) |
1da177e4 LT |
28 | return 1; |
29 | } | |
30 | ||
31 | return 0; | |
32 | } | |
33 | ||
34 | static void br_hello_timer_expired(unsigned long arg) | |
35 | { | |
36 | struct net_bridge *br = (struct net_bridge *)arg; | |
9d6f229f | 37 | |
28a16c97 | 38 | br_debug(br, "hello timer expired\n"); |
e3efe08e | 39 | spin_lock(&br->lock); |
1da177e4 LT |
40 | if (br->dev->flags & IFF_UP) { |
41 | br_config_bpdu_generation(br); | |
42 | ||
9a834b87 | 43 | mod_timer(&br->hello_timer, round_jiffies(jiffies + br->hello_time)); |
1da177e4 | 44 | } |
e3efe08e | 45 | spin_unlock(&br->lock); |
1da177e4 LT |
46 | } |
47 | ||
48 | static void br_message_age_timer_expired(unsigned long arg) | |
49 | { | |
50 | struct net_bridge_port *p = (struct net_bridge_port *) arg; | |
51 | struct net_bridge *br = p->br; | |
52 | const bridge_id *id = &p->designated_bridge; | |
53 | int was_root; | |
54 | ||
55 | if (p->state == BR_STATE_DISABLED) | |
56 | return; | |
57 | ||
28a16c97 | 58 | br_info(br, "port %u(%s) neighbor %.2x%.2x.%pM lost\n", |
95c96174 | 59 | (unsigned int) p->port_no, p->dev->name, |
28a16c97 | 60 | id->prio[0], id->prio[1], &id->addr); |
1da177e4 LT |
61 | |
62 | /* | |
63 | * According to the spec, the message age timer cannot be | |
64 | * running when we are the root bridge. So.. this was_root | |
65 | * check is redundant. I'm leaving it in for now, though. | |
66 | */ | |
e3efe08e | 67 | spin_lock(&br->lock); |
1da177e4 LT |
68 | if (p->state == BR_STATE_DISABLED) |
69 | goto unlock; | |
70 | was_root = br_is_root_bridge(br); | |
71 | ||
72 | br_become_designated_port(p); | |
73 | br_configuration_update(br); | |
74 | br_port_state_selection(br); | |
75 | if (br_is_root_bridge(br) && !was_root) | |
76 | br_become_root_bridge(br); | |
77 | unlock: | |
e3efe08e | 78 | spin_unlock(&br->lock); |
1da177e4 LT |
79 | } |
80 | ||
81 | static void br_forward_delay_timer_expired(unsigned long arg) | |
82 | { | |
83 | struct net_bridge_port *p = (struct net_bridge_port *) arg; | |
84 | struct net_bridge *br = p->br; | |
85 | ||
28a16c97 | 86 | br_debug(br, "port %u(%s) forward delay timer\n", |
95c96174 | 87 | (unsigned int) p->port_no, p->dev->name); |
e3efe08e | 88 | spin_lock(&br->lock); |
1da177e4 | 89 | if (p->state == BR_STATE_LISTENING) { |
775dd692 | 90 | br_set_state(p, BR_STATE_LEARNING); |
1da177e4 LT |
91 | mod_timer(&p->forward_delay_timer, |
92 | jiffies + br->forward_delay); | |
93 | } else if (p->state == BR_STATE_LEARNING) { | |
775dd692 | 94 | br_set_state(p, BR_STATE_FORWARDING); |
1da177e4 LT |
95 | if (br_is_designated_for_some_port(br)) |
96 | br_topology_change_detection(br); | |
1faa4356 | 97 | netif_carrier_on(br->dev); |
1da177e4 LT |
98 | } |
99 | br_log_state(p); | |
93a33a58 | 100 | rcu_read_lock(); |
4ecb961c | 101 | br_ifinfo_notify(RTM_NEWLINK, p); |
93a33a58 | 102 | rcu_read_unlock(); |
e3efe08e | 103 | spin_unlock(&br->lock); |
1da177e4 LT |
104 | } |
105 | ||
106 | static void br_tcn_timer_expired(unsigned long arg) | |
107 | { | |
108 | struct net_bridge *br = (struct net_bridge *) arg; | |
109 | ||
28a16c97 | 110 | br_debug(br, "tcn timer expired\n"); |
e3efe08e | 111 | spin_lock(&br->lock); |
83401eb4 | 112 | if (!br_is_root_bridge(br) && (br->dev->flags & IFF_UP)) { |
1da177e4 | 113 | br_transmit_tcn(br); |
9d6f229f | 114 | |
31a5b837 | 115 | mod_timer(&br->tcn_timer, jiffies + br->bridge_hello_time); |
1da177e4 | 116 | } |
e3efe08e | 117 | spin_unlock(&br->lock); |
1da177e4 LT |
118 | } |
119 | ||
120 | static void br_topology_change_timer_expired(unsigned long arg) | |
121 | { | |
122 | struct net_bridge *br = (struct net_bridge *) arg; | |
123 | ||
28a16c97 | 124 | br_debug(br, "topo change timer expired\n"); |
e3efe08e | 125 | spin_lock(&br->lock); |
1da177e4 LT |
126 | br->topology_change_detected = 0; |
127 | br->topology_change = 0; | |
e3efe08e | 128 | spin_unlock(&br->lock); |
1da177e4 LT |
129 | } |
130 | ||
131 | static void br_hold_timer_expired(unsigned long arg) | |
132 | { | |
133 | struct net_bridge_port *p = (struct net_bridge_port *) arg; | |
134 | ||
28a16c97 | 135 | br_debug(p->br, "port %u(%s) hold timer expired\n", |
95c96174 | 136 | (unsigned int) p->port_no, p->dev->name); |
1da177e4 | 137 | |
e3efe08e | 138 | spin_lock(&p->br->lock); |
1da177e4 LT |
139 | if (p->config_pending) |
140 | br_transmit_config(p); | |
e3efe08e | 141 | spin_unlock(&p->br->lock); |
1da177e4 LT |
142 | } |
143 | ||
1da177e4 LT |
144 | void br_stp_timer_init(struct net_bridge *br) |
145 | { | |
a95fcacd | 146 | setup_timer(&br->hello_timer, br_hello_timer_expired, |
1da177e4 LT |
147 | (unsigned long) br); |
148 | ||
a95fcacd | 149 | setup_timer(&br->tcn_timer, br_tcn_timer_expired, |
1da177e4 LT |
150 | (unsigned long) br); |
151 | ||
a95fcacd | 152 | setup_timer(&br->topology_change_timer, |
1da177e4 LT |
153 | br_topology_change_timer_expired, |
154 | (unsigned long) br); | |
155 | ||
a95fcacd | 156 | setup_timer(&br->gc_timer, br_fdb_cleanup, (unsigned long) br); |
1da177e4 LT |
157 | } |
158 | ||
159 | void br_stp_port_timer_init(struct net_bridge_port *p) | |
160 | { | |
a95fcacd | 161 | setup_timer(&p->message_age_timer, br_message_age_timer_expired, |
1da177e4 LT |
162 | (unsigned long) p); |
163 | ||
a95fcacd | 164 | setup_timer(&p->forward_delay_timer, br_forward_delay_timer_expired, |
1da177e4 | 165 | (unsigned long) p); |
9d6f229f | 166 | |
a95fcacd | 167 | setup_timer(&p->hold_timer, br_hold_timer_expired, |
1da177e4 | 168 | (unsigned long) p); |
9d6f229f | 169 | } |
1da177e4 LT |
170 | |
171 | /* Report ticks left (in USER_HZ) used for API */ | |
172 | unsigned long br_timer_value(const struct timer_list *timer) | |
173 | { | |
174 | return timer_pending(timer) | |
a399a805 | 175 | ? jiffies_delta_to_clock_t(timer->expires - jiffies) : 0; |
1da177e4 | 176 | } |