media: cpia2_usb: drop bogus interface-release call
[linux/fpc-iii.git] / net / bridge / br_stp_timer.c
blobe7739de5f0e1092037d878d989dcc5c61c372b9d
1 /*
2 * Spanning tree protocol; timer-related code
3 * Linux ethernet bridge
5 * Authors:
6 * Lennert Buytenhek <buytenh@gnu.org>
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.
14 #include <linux/kernel.h>
15 #include <linux/times.h>
17 #include "br_private.h"
18 #include "br_private_stp.h"
20 /* called under bridge lock */
21 static int br_is_designated_for_some_port(const struct net_bridge *br)
23 struct net_bridge_port *p;
25 list_for_each_entry(p, &br->port_list, list) {
26 if (p->state != BR_STATE_DISABLED &&
27 !memcmp(&p->designated_bridge, &br->bridge_id, 8))
28 return 1;
31 return 0;
34 static void br_hello_timer_expired(struct timer_list *t)
36 struct net_bridge *br = from_timer(br, t, hello_timer);
38 br_debug(br, "hello timer expired\n");
39 spin_lock(&br->lock);
40 if (br->dev->flags & IFF_UP) {
41 br_config_bpdu_generation(br);
43 if (br->stp_enabled == BR_KERNEL_STP)
44 mod_timer(&br->hello_timer,
45 round_jiffies(jiffies + br->hello_time));
47 spin_unlock(&br->lock);
50 static void br_message_age_timer_expired(struct timer_list *t)
52 struct net_bridge_port *p = from_timer(p, t, message_age_timer);
53 struct net_bridge *br = p->br;
54 const bridge_id *id = &p->designated_bridge;
55 int was_root;
57 if (p->state == BR_STATE_DISABLED)
58 return;
60 br_info(br, "port %u(%s) neighbor %.2x%.2x.%pM lost\n",
61 (unsigned int) p->port_no, p->dev->name,
62 id->prio[0], id->prio[1], &id->addr);
65 * According to the spec, the message age timer cannot be
66 * running when we are the root bridge. So.. this was_root
67 * check is redundant. I'm leaving it in for now, though.
69 spin_lock(&br->lock);
70 if (p->state == BR_STATE_DISABLED)
71 goto unlock;
72 was_root = br_is_root_bridge(br);
74 br_become_designated_port(p);
75 br_configuration_update(br);
76 br_port_state_selection(br);
77 if (br_is_root_bridge(br) && !was_root)
78 br_become_root_bridge(br);
79 unlock:
80 spin_unlock(&br->lock);
83 static void br_forward_delay_timer_expired(struct timer_list *t)
85 struct net_bridge_port *p = from_timer(p, t, forward_delay_timer);
86 struct net_bridge *br = p->br;
88 br_debug(br, "port %u(%s) forward delay timer\n",
89 (unsigned int) p->port_no, p->dev->name);
90 spin_lock(&br->lock);
91 if (p->state == BR_STATE_LISTENING) {
92 br_set_state(p, BR_STATE_LEARNING);
93 mod_timer(&p->forward_delay_timer,
94 jiffies + br->forward_delay);
95 } else if (p->state == BR_STATE_LEARNING) {
96 br_set_state(p, BR_STATE_FORWARDING);
97 if (br_is_designated_for_some_port(br))
98 br_topology_change_detection(br);
99 netif_carrier_on(br->dev);
101 rcu_read_lock();
102 br_ifinfo_notify(RTM_NEWLINK, NULL, p);
103 rcu_read_unlock();
104 spin_unlock(&br->lock);
107 static void br_tcn_timer_expired(struct timer_list *t)
109 struct net_bridge *br = from_timer(br, t, tcn_timer);
111 br_debug(br, "tcn timer expired\n");
112 spin_lock(&br->lock);
113 if (!br_is_root_bridge(br) && (br->dev->flags & IFF_UP)) {
114 br_transmit_tcn(br);
116 mod_timer(&br->tcn_timer, jiffies + br->bridge_hello_time);
118 spin_unlock(&br->lock);
121 static void br_topology_change_timer_expired(struct timer_list *t)
123 struct net_bridge *br = from_timer(br, t, topology_change_timer);
125 br_debug(br, "topo change timer expired\n");
126 spin_lock(&br->lock);
127 br->topology_change_detected = 0;
128 __br_set_topology_change(br, 0);
129 spin_unlock(&br->lock);
132 static void br_hold_timer_expired(struct timer_list *t)
134 struct net_bridge_port *p = from_timer(p, t, hold_timer);
136 br_debug(p->br, "port %u(%s) hold timer expired\n",
137 (unsigned int) p->port_no, p->dev->name);
139 spin_lock(&p->br->lock);
140 if (p->config_pending)
141 br_transmit_config(p);
142 spin_unlock(&p->br->lock);
145 void br_stp_timer_init(struct net_bridge *br)
147 timer_setup(&br->hello_timer, br_hello_timer_expired, 0);
148 timer_setup(&br->tcn_timer, br_tcn_timer_expired, 0);
149 timer_setup(&br->topology_change_timer,
150 br_topology_change_timer_expired, 0);
153 void br_stp_port_timer_init(struct net_bridge_port *p)
155 timer_setup(&p->message_age_timer, br_message_age_timer_expired, 0);
156 timer_setup(&p->forward_delay_timer, br_forward_delay_timer_expired, 0);
157 timer_setup(&p->hold_timer, br_hold_timer_expired, 0);
160 /* Report ticks left (in USER_HZ) used for API */
161 unsigned long br_timer_value(const struct timer_list *timer)
163 return timer_pending(timer)
164 ? jiffies_delta_to_clock_t(timer->expires - jiffies) : 0;