Blame view
net/bridge/br_stp_timer.c
4.46 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 |
/* * Spanning tree protocol; timer-related code * Linux ethernet bridge * * Authors: * Lennert Buytenhek <buytenh@gnu.org> * |
1da177e4c Linux-2.6.12-rc2 |
8 9 10 11 12 13 14 15 |
* This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/kernel.h> #include <linux/times.h> |
1da177e4c Linux-2.6.12-rc2 |
16 17 18 19 20 21 22 23 24 25 26 |
#include "br_private.h" #include "br_private_stp.h" /* called under bridge lock */ static int br_is_designated_for_some_port(const struct net_bridge *br) { struct net_bridge_port *p; list_for_each_entry(p, &br->port_list, list) { if (p->state != BR_STATE_DISABLED && |
9d6f229fc [NET] BRIDGE: Fix... |
27 |
!memcmp(&p->designated_bridge, &br->bridge_id, 8)) |
1da177e4c Linux-2.6.12-rc2 |
28 29 30 31 32 33 34 35 36 |
return 1; } return 0; } static void br_hello_timer_expired(unsigned long arg) { struct net_bridge *br = (struct net_bridge *)arg; |
9d6f229fc [NET] BRIDGE: Fix... |
37 |
|
28a16c979 bridge: change co... |
38 39 |
br_debug(br, "hello timer expired "); |
e3efe08e9 [BRIDGE]: remove ... |
40 |
spin_lock(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
41 42 |
if (br->dev->flags & IFF_UP) { br_config_bpdu_generation(br); |
9a834b87c [BRIDGE]: Round o... |
43 |
mod_timer(&br->hello_timer, round_jiffies(jiffies + br->hello_time)); |
1da177e4c Linux-2.6.12-rc2 |
44 |
} |
e3efe08e9 [BRIDGE]: remove ... |
45 |
spin_unlock(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
46 47 48 49 50 51 52 53 54 55 56 |
} static void br_message_age_timer_expired(unsigned long arg) { struct net_bridge_port *p = (struct net_bridge_port *) arg; struct net_bridge *br = p->br; const bridge_id *id = &p->designated_bridge; int was_root; if (p->state == BR_STATE_DISABLED) return; |
28a16c979 bridge: change co... |
57 58 59 60 |
br_info(br, "port %u(%s) neighbor %.2x%.2x.%pM lost ", (unsigned) p->port_no, p->dev->name, id->prio[0], id->prio[1], &id->addr); |
1da177e4c Linux-2.6.12-rc2 |
61 62 63 64 65 66 |
/* * According to the spec, the message age timer cannot be * running when we are the root bridge. So.. this was_root * check is redundant. I'm leaving it in for now, though. */ |
e3efe08e9 [BRIDGE]: remove ... |
67 |
spin_lock(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
68 69 70 71 72 73 74 75 76 77 |
if (p->state == BR_STATE_DISABLED) goto unlock; was_root = br_is_root_bridge(br); br_become_designated_port(p); br_configuration_update(br); br_port_state_selection(br); if (br_is_root_bridge(br) && !was_root) br_become_root_bridge(br); unlock: |
e3efe08e9 [BRIDGE]: remove ... |
78 |
spin_unlock(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
79 80 81 82 83 84 |
} static void br_forward_delay_timer_expired(unsigned long arg) { struct net_bridge_port *p = (struct net_bridge_port *) arg; struct net_bridge *br = p->br; |
28a16c979 bridge: change co... |
85 86 87 |
br_debug(br, "port %u(%s) forward delay timer ", (unsigned) p->port_no, p->dev->name); |
e3efe08e9 [BRIDGE]: remove ... |
88 |
spin_lock(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
89 90 91 92 93 94 95 96 |
if (p->state == BR_STATE_LISTENING) { p->state = BR_STATE_LEARNING; mod_timer(&p->forward_delay_timer, jiffies + br->forward_delay); } else if (p->state == BR_STATE_LEARNING) { p->state = BR_STATE_FORWARDING; if (br_is_designated_for_some_port(br)) br_topology_change_detection(br); |
1faa4356a bridge: control c... |
97 |
netif_carrier_on(br->dev); |
1da177e4c Linux-2.6.12-rc2 |
98 99 |
} br_log_state(p); |
4ecb961c8 bridge: add notif... |
100 |
br_ifinfo_notify(RTM_NEWLINK, p); |
e3efe08e9 [BRIDGE]: remove ... |
101 |
spin_unlock(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
102 103 104 105 106 |
} static void br_tcn_timer_expired(unsigned long arg) { struct net_bridge *br = (struct net_bridge *) arg; |
28a16c979 bridge: change co... |
107 108 |
br_debug(br, "tcn timer expired "); |
e3efe08e9 [BRIDGE]: remove ... |
109 |
spin_lock(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
110 111 |
if (br->dev->flags & IFF_UP) { br_transmit_tcn(br); |
9d6f229fc [NET] BRIDGE: Fix... |
112 |
|
1da177e4c Linux-2.6.12-rc2 |
113 114 |
mod_timer(&br->tcn_timer,jiffies + br->bridge_hello_time); } |
e3efe08e9 [BRIDGE]: remove ... |
115 |
spin_unlock(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
116 117 118 119 120 |
} static void br_topology_change_timer_expired(unsigned long arg) { struct net_bridge *br = (struct net_bridge *) arg; |
28a16c979 bridge: change co... |
121 122 |
br_debug(br, "topo change timer expired "); |
e3efe08e9 [BRIDGE]: remove ... |
123 |
spin_lock(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
124 125 |
br->topology_change_detected = 0; br->topology_change = 0; |
e3efe08e9 [BRIDGE]: remove ... |
126 |
spin_unlock(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
127 128 129 130 131 |
} static void br_hold_timer_expired(unsigned long arg) { struct net_bridge_port *p = (struct net_bridge_port *) arg; |
28a16c979 bridge: change co... |
132 133 134 |
br_debug(p->br, "port %u(%s) hold timer expired ", (unsigned) p->port_no, p->dev->name); |
1da177e4c Linux-2.6.12-rc2 |
135 |
|
e3efe08e9 [BRIDGE]: remove ... |
136 |
spin_lock(&p->br->lock); |
1da177e4c Linux-2.6.12-rc2 |
137 138 |
if (p->config_pending) br_transmit_config(p); |
e3efe08e9 [BRIDGE]: remove ... |
139 |
spin_unlock(&p->br->lock); |
1da177e4c Linux-2.6.12-rc2 |
140 |
} |
1da177e4c Linux-2.6.12-rc2 |
141 142 |
void br_stp_timer_init(struct net_bridge *br) { |
a95fcacdc [BRIDGE]: use set... |
143 |
setup_timer(&br->hello_timer, br_hello_timer_expired, |
1da177e4c Linux-2.6.12-rc2 |
144 |
(unsigned long) br); |
a95fcacdc [BRIDGE]: use set... |
145 |
setup_timer(&br->tcn_timer, br_tcn_timer_expired, |
1da177e4c Linux-2.6.12-rc2 |
146 |
(unsigned long) br); |
a95fcacdc [BRIDGE]: use set... |
147 |
setup_timer(&br->topology_change_timer, |
1da177e4c Linux-2.6.12-rc2 |
148 149 |
br_topology_change_timer_expired, (unsigned long) br); |
a95fcacdc [BRIDGE]: use set... |
150 |
setup_timer(&br->gc_timer, br_fdb_cleanup, (unsigned long) br); |
1da177e4c Linux-2.6.12-rc2 |
151 152 153 154 |
} void br_stp_port_timer_init(struct net_bridge_port *p) { |
a95fcacdc [BRIDGE]: use set... |
155 |
setup_timer(&p->message_age_timer, br_message_age_timer_expired, |
1da177e4c Linux-2.6.12-rc2 |
156 |
(unsigned long) p); |
a95fcacdc [BRIDGE]: use set... |
157 |
setup_timer(&p->forward_delay_timer, br_forward_delay_timer_expired, |
1da177e4c Linux-2.6.12-rc2 |
158 |
(unsigned long) p); |
9d6f229fc [NET] BRIDGE: Fix... |
159 |
|
a95fcacdc [BRIDGE]: use set... |
160 |
setup_timer(&p->hold_timer, br_hold_timer_expired, |
1da177e4c Linux-2.6.12-rc2 |
161 |
(unsigned long) p); |
9d6f229fc [NET] BRIDGE: Fix... |
162 |
} |
1da177e4c Linux-2.6.12-rc2 |
163 164 165 166 167 168 169 |
/* Report ticks left (in USER_HZ) used for API */ unsigned long br_timer_value(const struct timer_list *timer) { return timer_pending(timer) ? jiffies_to_clock_t(timer->expires - jiffies) : 0; } |