.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* Copyright 2011-2014 Autronica Fire and Security AS |
---|
2 | | - * |
---|
3 | | - * This program is free software; you can redistribute it and/or modify it |
---|
4 | | - * under the terms of the GNU General Public License as published by the Free |
---|
5 | | - * Software Foundation; either version 2 of the License, or (at your option) |
---|
6 | | - * any later version. |
---|
7 | 3 | * |
---|
8 | 4 | * Author(s): |
---|
9 | 5 | * 2011-2014 Arvid Brodin, arvid.brodin@alten.se |
---|
.. | .. |
---|
12 | 8 | * interface. A frame is identified by its source MAC address and its HSR |
---|
13 | 9 | * sequence number. This code keeps track of senders and their sequence numbers |
---|
14 | 10 | * to allow filtering of duplicate frames, and to detect HSR ring errors. |
---|
| 11 | + * Same code handles filtering of duplicates for PRP as well. |
---|
15 | 12 | */ |
---|
16 | 13 | |
---|
17 | 14 | #include <linux/if_ether.h> |
---|
.. | .. |
---|
22 | 19 | #include "hsr_framereg.h" |
---|
23 | 20 | #include "hsr_netlink.h" |
---|
24 | 21 | |
---|
25 | | - |
---|
26 | | -struct hsr_node { |
---|
27 | | - struct list_head mac_list; |
---|
28 | | - unsigned char MacAddressA[ETH_ALEN]; |
---|
29 | | - unsigned char MacAddressB[ETH_ALEN]; |
---|
30 | | - /* Local slave through which AddrB frames are received from this node */ |
---|
31 | | - enum hsr_port_type AddrB_port; |
---|
32 | | - unsigned long time_in[HSR_PT_PORTS]; |
---|
33 | | - bool time_in_stale[HSR_PT_PORTS]; |
---|
34 | | - u16 seq_out[HSR_PT_PORTS]; |
---|
35 | | - struct rcu_head rcu_head; |
---|
36 | | -}; |
---|
37 | | - |
---|
38 | | - |
---|
39 | 22 | /* TODO: use hash lists for mac addresses (linux/jhash.h)? */ |
---|
40 | | - |
---|
41 | 23 | |
---|
42 | 24 | /* seq_nr_after(a, b) - return true if a is after (higher in sequence than) b, |
---|
43 | 25 | * false otherwise. |
---|
.. | .. |
---|
47 | 29 | /* Remove inconsistency where |
---|
48 | 30 | * seq_nr_after(a, b) == seq_nr_before(a, b) |
---|
49 | 31 | */ |
---|
50 | | - if ((int) b - a == 32768) |
---|
| 32 | + if ((int)b - a == 32768) |
---|
51 | 33 | return false; |
---|
52 | 34 | |
---|
53 | | - return (((s16) (b - a)) < 0); |
---|
| 35 | + return (((s16)(b - a)) < 0); |
---|
54 | 36 | } |
---|
55 | | -#define seq_nr_before(a, b) seq_nr_after((b), (a)) |
---|
56 | | -#define seq_nr_after_or_eq(a, b) (!seq_nr_before((a), (b))) |
---|
57 | | -#define seq_nr_before_or_eq(a, b) (!seq_nr_after((a), (b))) |
---|
58 | 37 | |
---|
| 38 | +#define seq_nr_before(a, b) seq_nr_after((b), (a)) |
---|
| 39 | +#define seq_nr_before_or_eq(a, b) (!seq_nr_after((a), (b))) |
---|
59 | 40 | |
---|
60 | 41 | bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr) |
---|
61 | 42 | { |
---|
.. | .. |
---|
68 | 49 | return false; |
---|
69 | 50 | } |
---|
70 | 51 | |
---|
71 | | - if (ether_addr_equal(addr, node->MacAddressA)) |
---|
| 52 | + if (ether_addr_equal(addr, node->macaddress_A)) |
---|
72 | 53 | return true; |
---|
73 | | - if (ether_addr_equal(addr, node->MacAddressB)) |
---|
| 54 | + if (ether_addr_equal(addr, node->macaddress_B)) |
---|
74 | 55 | return true; |
---|
75 | 56 | |
---|
76 | 57 | return false; |
---|
.. | .. |
---|
78 | 59 | |
---|
79 | 60 | /* Search for mac entry. Caller must hold rcu read lock. |
---|
80 | 61 | */ |
---|
81 | | -static struct hsr_node *find_node_by_AddrA(struct list_head *node_db, |
---|
82 | | - const unsigned char addr[ETH_ALEN]) |
---|
| 62 | +static struct hsr_node *find_node_by_addr_A(struct list_head *node_db, |
---|
| 63 | + const unsigned char addr[ETH_ALEN]) |
---|
83 | 64 | { |
---|
84 | 65 | struct hsr_node *node; |
---|
85 | 66 | |
---|
86 | 67 | list_for_each_entry_rcu(node, node_db, mac_list) { |
---|
87 | | - if (ether_addr_equal(node->MacAddressA, addr)) |
---|
| 68 | + if (ether_addr_equal(node->macaddress_A, addr)) |
---|
88 | 69 | return node; |
---|
89 | 70 | } |
---|
90 | 71 | |
---|
91 | 72 | return NULL; |
---|
92 | 73 | } |
---|
93 | 74 | |
---|
94 | | - |
---|
95 | 75 | /* Helper for device init; the self_node_db is used in hsr_rcv() to recognize |
---|
96 | 76 | * frames from self that's been looped over the HSR ring. |
---|
97 | 77 | */ |
---|
98 | | -int hsr_create_self_node(struct list_head *self_node_db, |
---|
| 78 | +int hsr_create_self_node(struct hsr_priv *hsr, |
---|
99 | 79 | unsigned char addr_a[ETH_ALEN], |
---|
100 | 80 | unsigned char addr_b[ETH_ALEN]) |
---|
101 | 81 | { |
---|
| 82 | + struct list_head *self_node_db = &hsr->self_node_db; |
---|
102 | 83 | struct hsr_node *node, *oldnode; |
---|
103 | 84 | |
---|
104 | 85 | node = kmalloc(sizeof(*node), GFP_KERNEL); |
---|
105 | 86 | if (!node) |
---|
106 | 87 | return -ENOMEM; |
---|
107 | 88 | |
---|
108 | | - ether_addr_copy(node->MacAddressA, addr_a); |
---|
109 | | - ether_addr_copy(node->MacAddressB, addr_b); |
---|
| 89 | + ether_addr_copy(node->macaddress_A, addr_a); |
---|
| 90 | + ether_addr_copy(node->macaddress_B, addr_b); |
---|
110 | 91 | |
---|
111 | | - rcu_read_lock(); |
---|
| 92 | + spin_lock_bh(&hsr->list_lock); |
---|
112 | 93 | oldnode = list_first_or_null_rcu(self_node_db, |
---|
113 | | - struct hsr_node, mac_list); |
---|
| 94 | + struct hsr_node, mac_list); |
---|
114 | 95 | if (oldnode) { |
---|
115 | 96 | list_replace_rcu(&oldnode->mac_list, &node->mac_list); |
---|
116 | | - rcu_read_unlock(); |
---|
117 | | - synchronize_rcu(); |
---|
118 | | - kfree(oldnode); |
---|
| 97 | + spin_unlock_bh(&hsr->list_lock); |
---|
| 98 | + kfree_rcu(oldnode, rcu_head); |
---|
119 | 99 | } else { |
---|
120 | | - rcu_read_unlock(); |
---|
121 | 100 | list_add_tail_rcu(&node->mac_list, self_node_db); |
---|
| 101 | + spin_unlock_bh(&hsr->list_lock); |
---|
122 | 102 | } |
---|
123 | 103 | |
---|
124 | 104 | return 0; |
---|
125 | 105 | } |
---|
126 | 106 | |
---|
127 | | -void hsr_del_node(struct list_head *self_node_db) |
---|
| 107 | +void hsr_del_self_node(struct hsr_priv *hsr) |
---|
128 | 108 | { |
---|
| 109 | + struct list_head *self_node_db = &hsr->self_node_db; |
---|
129 | 110 | struct hsr_node *node; |
---|
130 | 111 | |
---|
131 | | - rcu_read_lock(); |
---|
| 112 | + spin_lock_bh(&hsr->list_lock); |
---|
132 | 113 | node = list_first_or_null_rcu(self_node_db, struct hsr_node, mac_list); |
---|
133 | | - rcu_read_unlock(); |
---|
134 | 114 | if (node) { |
---|
135 | 115 | list_del_rcu(&node->mac_list); |
---|
136 | | - kfree(node); |
---|
| 116 | + kfree_rcu(node, rcu_head); |
---|
137 | 117 | } |
---|
| 118 | + spin_unlock_bh(&hsr->list_lock); |
---|
138 | 119 | } |
---|
139 | 120 | |
---|
140 | | -/* Allocate an hsr_node and add it to node_db. 'addr' is the node's AddressA; |
---|
| 121 | +void hsr_del_nodes(struct list_head *node_db) |
---|
| 122 | +{ |
---|
| 123 | + struct hsr_node *node; |
---|
| 124 | + struct hsr_node *tmp; |
---|
| 125 | + |
---|
| 126 | + list_for_each_entry_safe(node, tmp, node_db, mac_list) |
---|
| 127 | + kfree(node); |
---|
| 128 | +} |
---|
| 129 | + |
---|
| 130 | +void prp_handle_san_frame(bool san, enum hsr_port_type port, |
---|
| 131 | + struct hsr_node *node) |
---|
| 132 | +{ |
---|
| 133 | + /* Mark if the SAN node is over LAN_A or LAN_B */ |
---|
| 134 | + if (port == HSR_PT_SLAVE_A) { |
---|
| 135 | + node->san_a = true; |
---|
| 136 | + return; |
---|
| 137 | + } |
---|
| 138 | + |
---|
| 139 | + if (port == HSR_PT_SLAVE_B) |
---|
| 140 | + node->san_b = true; |
---|
| 141 | +} |
---|
| 142 | + |
---|
| 143 | +/* Allocate an hsr_node and add it to node_db. 'addr' is the node's address_A; |
---|
141 | 144 | * seq_out is used to initialize filtering of outgoing duplicate frames |
---|
142 | 145 | * originating from the newly added node. |
---|
143 | 146 | */ |
---|
144 | | -struct hsr_node *hsr_add_node(struct list_head *node_db, unsigned char addr[], |
---|
145 | | - u16 seq_out) |
---|
| 147 | +static struct hsr_node *hsr_add_node(struct hsr_priv *hsr, |
---|
| 148 | + struct list_head *node_db, |
---|
| 149 | + unsigned char addr[], |
---|
| 150 | + u16 seq_out, bool san, |
---|
| 151 | + enum hsr_port_type rx_port) |
---|
146 | 152 | { |
---|
147 | | - struct hsr_node *node; |
---|
| 153 | + struct hsr_node *new_node, *node; |
---|
148 | 154 | unsigned long now; |
---|
149 | 155 | int i; |
---|
150 | 156 | |
---|
151 | | - node = kzalloc(sizeof(*node), GFP_ATOMIC); |
---|
152 | | - if (!node) |
---|
| 157 | + new_node = kzalloc(sizeof(*new_node), GFP_ATOMIC); |
---|
| 158 | + if (!new_node) |
---|
153 | 159 | return NULL; |
---|
154 | 160 | |
---|
155 | | - ether_addr_copy(node->MacAddressA, addr); |
---|
| 161 | + ether_addr_copy(new_node->macaddress_A, addr); |
---|
| 162 | + spin_lock_init(&new_node->seq_out_lock); |
---|
156 | 163 | |
---|
157 | 164 | /* We are only interested in time diffs here, so use current jiffies |
---|
158 | 165 | * as initialization. (0 could trigger an spurious ring error warning). |
---|
159 | 166 | */ |
---|
160 | 167 | now = jiffies; |
---|
| 168 | + for (i = 0; i < HSR_PT_PORTS; i++) { |
---|
| 169 | + new_node->time_in[i] = now; |
---|
| 170 | + new_node->time_out[i] = now; |
---|
| 171 | + } |
---|
161 | 172 | for (i = 0; i < HSR_PT_PORTS; i++) |
---|
162 | | - node->time_in[i] = now; |
---|
163 | | - for (i = 0; i < HSR_PT_PORTS; i++) |
---|
164 | | - node->seq_out[i] = seq_out; |
---|
| 173 | + new_node->seq_out[i] = seq_out; |
---|
165 | 174 | |
---|
166 | | - list_add_tail_rcu(&node->mac_list, node_db); |
---|
| 175 | + if (san && hsr->proto_ops->handle_san_frame) |
---|
| 176 | + hsr->proto_ops->handle_san_frame(san, rx_port, new_node); |
---|
167 | 177 | |
---|
| 178 | + spin_lock_bh(&hsr->list_lock); |
---|
| 179 | + list_for_each_entry_rcu(node, node_db, mac_list, |
---|
| 180 | + lockdep_is_held(&hsr->list_lock)) { |
---|
| 181 | + if (ether_addr_equal(node->macaddress_A, addr)) |
---|
| 182 | + goto out; |
---|
| 183 | + if (ether_addr_equal(node->macaddress_B, addr)) |
---|
| 184 | + goto out; |
---|
| 185 | + } |
---|
| 186 | + list_add_tail_rcu(&new_node->mac_list, node_db); |
---|
| 187 | + spin_unlock_bh(&hsr->list_lock); |
---|
| 188 | + return new_node; |
---|
| 189 | +out: |
---|
| 190 | + spin_unlock_bh(&hsr->list_lock); |
---|
| 191 | + kfree(new_node); |
---|
168 | 192 | return node; |
---|
| 193 | +} |
---|
| 194 | + |
---|
| 195 | +void prp_update_san_info(struct hsr_node *node, bool is_sup) |
---|
| 196 | +{ |
---|
| 197 | + if (!is_sup) |
---|
| 198 | + return; |
---|
| 199 | + |
---|
| 200 | + node->san_a = false; |
---|
| 201 | + node->san_b = false; |
---|
169 | 202 | } |
---|
170 | 203 | |
---|
171 | 204 | /* Get the hsr_node from which 'skb' was sent. |
---|
172 | 205 | */ |
---|
173 | | -struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, |
---|
174 | | - bool is_sup) |
---|
| 206 | +struct hsr_node *hsr_get_node(struct hsr_port *port, struct list_head *node_db, |
---|
| 207 | + struct sk_buff *skb, bool is_sup, |
---|
| 208 | + enum hsr_port_type rx_port) |
---|
175 | 209 | { |
---|
176 | | - struct list_head *node_db = &port->hsr->node_db; |
---|
| 210 | + struct hsr_priv *hsr = port->hsr; |
---|
177 | 211 | struct hsr_node *node; |
---|
178 | 212 | struct ethhdr *ethhdr; |
---|
| 213 | + struct prp_rct *rct; |
---|
| 214 | + bool san = false; |
---|
179 | 215 | u16 seq_out; |
---|
180 | 216 | |
---|
181 | 217 | if (!skb_mac_header_was_set(skb)) |
---|
182 | 218 | return NULL; |
---|
183 | 219 | |
---|
184 | | - ethhdr = (struct ethhdr *) skb_mac_header(skb); |
---|
| 220 | + ethhdr = (struct ethhdr *)skb_mac_header(skb); |
---|
185 | 221 | |
---|
186 | 222 | list_for_each_entry_rcu(node, node_db, mac_list) { |
---|
187 | | - if (ether_addr_equal(node->MacAddressA, ethhdr->h_source)) |
---|
| 223 | + if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) { |
---|
| 224 | + if (hsr->proto_ops->update_san_info) |
---|
| 225 | + hsr->proto_ops->update_san_info(node, is_sup); |
---|
188 | 226 | return node; |
---|
189 | | - if (ether_addr_equal(node->MacAddressB, ethhdr->h_source)) |
---|
| 227 | + } |
---|
| 228 | + if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) { |
---|
| 229 | + if (hsr->proto_ops->update_san_info) |
---|
| 230 | + hsr->proto_ops->update_san_info(node, is_sup); |
---|
190 | 231 | return node; |
---|
| 232 | + } |
---|
191 | 233 | } |
---|
192 | 234 | |
---|
193 | | - /* Everyone may create a node entry, connected node to a HSR device. */ |
---|
194 | | - |
---|
195 | | - if (ethhdr->h_proto == htons(ETH_P_PRP) |
---|
196 | | - || ethhdr->h_proto == htons(ETH_P_HSR)) { |
---|
| 235 | + /* Everyone may create a node entry, connected node to a HSR/PRP |
---|
| 236 | + * device. |
---|
| 237 | + */ |
---|
| 238 | + if (ethhdr->h_proto == htons(ETH_P_PRP) || |
---|
| 239 | + ethhdr->h_proto == htons(ETH_P_HSR)) { |
---|
197 | 240 | /* Use the existing sequence_nr from the tag as starting point |
---|
198 | 241 | * for filtering duplicate frames. |
---|
199 | 242 | */ |
---|
200 | 243 | seq_out = hsr_get_skb_sequence_nr(skb) - 1; |
---|
201 | 244 | } else { |
---|
202 | | - /* this is called also for frames from master port and |
---|
203 | | - * so warn only for non master ports |
---|
204 | | - */ |
---|
205 | | - if (port->type != HSR_PT_MASTER) |
---|
206 | | - WARN_ONCE(1, "%s: Non-HSR frame\n", __func__); |
---|
207 | | - seq_out = HSR_SEQNR_START; |
---|
| 245 | + rct = skb_get_PRP_rct(skb); |
---|
| 246 | + if (rct && prp_check_lsdu_size(skb, rct, is_sup)) { |
---|
| 247 | + seq_out = prp_get_skb_sequence_nr(rct); |
---|
| 248 | + } else { |
---|
| 249 | + if (rx_port != HSR_PT_MASTER) |
---|
| 250 | + san = true; |
---|
| 251 | + seq_out = HSR_SEQNR_START; |
---|
| 252 | + } |
---|
208 | 253 | } |
---|
209 | 254 | |
---|
210 | | - return hsr_add_node(node_db, ethhdr->h_source, seq_out); |
---|
| 255 | + return hsr_add_node(hsr, node_db, ethhdr->h_source, seq_out, |
---|
| 256 | + san, rx_port); |
---|
211 | 257 | } |
---|
212 | 258 | |
---|
213 | | -/* Use the Supervision frame's info about an eventual MacAddressB for merging |
---|
214 | | - * nodes that has previously had their MacAddressB registered as a separate |
---|
| 259 | +/* Use the Supervision frame's info about an eventual macaddress_B for merging |
---|
| 260 | + * nodes that has previously had their macaddress_B registered as a separate |
---|
215 | 261 | * node. |
---|
216 | 262 | */ |
---|
217 | | -void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, |
---|
218 | | - struct hsr_port *port_rcv) |
---|
| 263 | +void hsr_handle_sup_frame(struct hsr_frame_info *frame) |
---|
219 | 264 | { |
---|
220 | | - struct ethhdr *ethhdr; |
---|
221 | | - struct hsr_node *node_real; |
---|
| 265 | + struct hsr_node *node_curr = frame->node_src; |
---|
| 266 | + struct hsr_port *port_rcv = frame->port_rcv; |
---|
| 267 | + struct hsr_priv *hsr = port_rcv->hsr; |
---|
222 | 268 | struct hsr_sup_payload *hsr_sp; |
---|
| 269 | + struct hsr_node *node_real; |
---|
| 270 | + struct sk_buff *skb = NULL; |
---|
223 | 271 | struct list_head *node_db; |
---|
| 272 | + struct ethhdr *ethhdr; |
---|
224 | 273 | int i; |
---|
225 | 274 | |
---|
226 | | - ethhdr = (struct ethhdr *) skb_mac_header(skb); |
---|
| 275 | + /* Here either frame->skb_hsr or frame->skb_prp should be |
---|
| 276 | + * valid as supervision frame always will have protocol |
---|
| 277 | + * header info. |
---|
| 278 | + */ |
---|
| 279 | + if (frame->skb_hsr) |
---|
| 280 | + skb = frame->skb_hsr; |
---|
| 281 | + else if (frame->skb_prp) |
---|
| 282 | + skb = frame->skb_prp; |
---|
| 283 | + if (!skb) |
---|
| 284 | + return; |
---|
| 285 | + |
---|
| 286 | + ethhdr = (struct ethhdr *)skb_mac_header(skb); |
---|
227 | 287 | |
---|
228 | 288 | /* Leave the ethernet header. */ |
---|
229 | 289 | skb_pull(skb, sizeof(struct ethhdr)); |
---|
.. | .. |
---|
235 | 295 | /* And leave the HSR sup tag. */ |
---|
236 | 296 | skb_pull(skb, sizeof(struct hsr_sup_tag)); |
---|
237 | 297 | |
---|
238 | | - hsr_sp = (struct hsr_sup_payload *) skb->data; |
---|
| 298 | + hsr_sp = (struct hsr_sup_payload *)skb->data; |
---|
239 | 299 | |
---|
240 | | - /* Merge node_curr (registered on MacAddressB) into node_real */ |
---|
| 300 | + /* Merge node_curr (registered on macaddress_B) into node_real */ |
---|
241 | 301 | node_db = &port_rcv->hsr->node_db; |
---|
242 | | - node_real = find_node_by_AddrA(node_db, hsr_sp->MacAddressA); |
---|
| 302 | + node_real = find_node_by_addr_A(node_db, hsr_sp->macaddress_A); |
---|
243 | 303 | if (!node_real) |
---|
244 | 304 | /* No frame received from AddrA of this node yet */ |
---|
245 | | - node_real = hsr_add_node(node_db, hsr_sp->MacAddressA, |
---|
246 | | - HSR_SEQNR_START - 1); |
---|
| 305 | + node_real = hsr_add_node(hsr, node_db, hsr_sp->macaddress_A, |
---|
| 306 | + HSR_SEQNR_START - 1, true, |
---|
| 307 | + port_rcv->type); |
---|
247 | 308 | if (!node_real) |
---|
248 | 309 | goto done; /* No mem */ |
---|
249 | 310 | if (node_real == node_curr) |
---|
250 | 311 | /* Node has already been merged */ |
---|
251 | 312 | goto done; |
---|
252 | 313 | |
---|
253 | | - ether_addr_copy(node_real->MacAddressB, ethhdr->h_source); |
---|
| 314 | + ether_addr_copy(node_real->macaddress_B, ethhdr->h_source); |
---|
| 315 | + spin_lock_bh(&node_real->seq_out_lock); |
---|
254 | 316 | for (i = 0; i < HSR_PT_PORTS; i++) { |
---|
255 | 317 | if (!node_curr->time_in_stale[i] && |
---|
256 | 318 | time_after(node_curr->time_in[i], node_real->time_in[i])) { |
---|
257 | 319 | node_real->time_in[i] = node_curr->time_in[i]; |
---|
258 | | - node_real->time_in_stale[i] = node_curr->time_in_stale[i]; |
---|
| 320 | + node_real->time_in_stale[i] = |
---|
| 321 | + node_curr->time_in_stale[i]; |
---|
259 | 322 | } |
---|
260 | 323 | if (seq_nr_after(node_curr->seq_out[i], node_real->seq_out[i])) |
---|
261 | 324 | node_real->seq_out[i] = node_curr->seq_out[i]; |
---|
262 | 325 | } |
---|
263 | | - node_real->AddrB_port = port_rcv->type; |
---|
| 326 | + spin_unlock_bh(&node_real->seq_out_lock); |
---|
| 327 | + node_real->addr_B_port = port_rcv->type; |
---|
264 | 328 | |
---|
| 329 | + spin_lock_bh(&hsr->list_lock); |
---|
265 | 330 | list_del_rcu(&node_curr->mac_list); |
---|
| 331 | + spin_unlock_bh(&hsr->list_lock); |
---|
266 | 332 | kfree_rcu(node_curr, rcu_head); |
---|
267 | 333 | |
---|
268 | 334 | done: |
---|
269 | | - skb_push(skb, sizeof(struct hsrv1_ethhdr_sp)); |
---|
| 335 | + /* PRP uses v0 header */ |
---|
| 336 | + if (ethhdr->h_proto == htons(ETH_P_HSR)) |
---|
| 337 | + skb_push(skb, sizeof(struct hsrv1_ethhdr_sp)); |
---|
| 338 | + else |
---|
| 339 | + skb_push(skb, sizeof(struct hsrv0_ethhdr_sp)); |
---|
270 | 340 | } |
---|
271 | | - |
---|
272 | 341 | |
---|
273 | 342 | /* 'skb' is a frame meant for this host, that is to be passed to upper layers. |
---|
274 | 343 | * |
---|
275 | 344 | * If the frame was sent by a node's B interface, replace the source |
---|
276 | | - * address with that node's "official" address (MacAddressA) so that upper |
---|
| 345 | + * address with that node's "official" address (macaddress_A) so that upper |
---|
277 | 346 | * layers recognize where it came from. |
---|
278 | 347 | */ |
---|
279 | 348 | void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb) |
---|
.. | .. |
---|
283 | 352 | return; |
---|
284 | 353 | } |
---|
285 | 354 | |
---|
286 | | - memcpy(ð_hdr(skb)->h_source, node->MacAddressA, ETH_ALEN); |
---|
| 355 | + memcpy(ð_hdr(skb)->h_source, node->macaddress_A, ETH_ALEN); |
---|
287 | 356 | } |
---|
288 | 357 | |
---|
289 | 358 | /* 'skb' is a frame meant for another host. |
---|
.. | .. |
---|
308 | 377 | if (!is_unicast_ether_addr(eth_hdr(skb)->h_dest)) |
---|
309 | 378 | return; |
---|
310 | 379 | |
---|
311 | | - node_dst = find_node_by_AddrA(&port->hsr->node_db, eth_hdr(skb)->h_dest); |
---|
| 380 | + node_dst = find_node_by_addr_A(&port->hsr->node_db, |
---|
| 381 | + eth_hdr(skb)->h_dest); |
---|
312 | 382 | if (!node_dst) { |
---|
313 | | - if (net_ratelimit()) |
---|
| 383 | + if (port->hsr->prot_version != PRP_V1 && net_ratelimit()) |
---|
314 | 384 | netdev_err(skb->dev, "%s: Unknown node\n", __func__); |
---|
315 | 385 | return; |
---|
316 | 386 | } |
---|
317 | | - if (port->type != node_dst->AddrB_port) |
---|
| 387 | + if (port->type != node_dst->addr_B_port) |
---|
318 | 388 | return; |
---|
319 | 389 | |
---|
320 | | - ether_addr_copy(eth_hdr(skb)->h_dest, node_dst->MacAddressB); |
---|
| 390 | + if (is_valid_ether_addr(node_dst->macaddress_B)) |
---|
| 391 | + ether_addr_copy(eth_hdr(skb)->h_dest, node_dst->macaddress_B); |
---|
321 | 392 | } |
---|
322 | | - |
---|
323 | 393 | |
---|
324 | 394 | void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port, |
---|
325 | 395 | u16 sequence_nr) |
---|
.. | .. |
---|
346 | 416 | int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node, |
---|
347 | 417 | u16 sequence_nr) |
---|
348 | 418 | { |
---|
349 | | - if (seq_nr_before_or_eq(sequence_nr, node->seq_out[port->type])) |
---|
| 419 | + spin_lock_bh(&node->seq_out_lock); |
---|
| 420 | + if (seq_nr_before_or_eq(sequence_nr, node->seq_out[port->type]) && |
---|
| 421 | + time_is_after_jiffies(node->time_out[port->type] + |
---|
| 422 | + msecs_to_jiffies(HSR_ENTRY_FORGET_TIME))) { |
---|
| 423 | + spin_unlock_bh(&node->seq_out_lock); |
---|
350 | 424 | return 1; |
---|
| 425 | + } |
---|
351 | 426 | |
---|
| 427 | + node->time_out[port->type] = jiffies; |
---|
352 | 428 | node->seq_out[port->type] = sequence_nr; |
---|
| 429 | + spin_unlock_bh(&node->seq_out_lock); |
---|
353 | 430 | return 0; |
---|
354 | 431 | } |
---|
355 | | - |
---|
356 | 432 | |
---|
357 | 433 | static struct hsr_port *get_late_port(struct hsr_priv *hsr, |
---|
358 | 434 | struct hsr_node *node) |
---|
.. | .. |
---|
374 | 450 | return NULL; |
---|
375 | 451 | } |
---|
376 | 452 | |
---|
377 | | - |
---|
378 | 453 | /* Remove stale sequence_nr records. Called by timer every |
---|
379 | 454 | * HSR_LIFE_CHECK_INTERVAL (two seconds or so). |
---|
380 | 455 | */ |
---|
.. | .. |
---|
382 | 457 | { |
---|
383 | 458 | struct hsr_priv *hsr = from_timer(hsr, t, prune_timer); |
---|
384 | 459 | struct hsr_node *node; |
---|
| 460 | + struct hsr_node *tmp; |
---|
385 | 461 | struct hsr_port *port; |
---|
386 | 462 | unsigned long timestamp; |
---|
387 | 463 | unsigned long time_a, time_b; |
---|
388 | 464 | |
---|
389 | | - rcu_read_lock(); |
---|
390 | | - list_for_each_entry_rcu(node, &hsr->node_db, mac_list) { |
---|
| 465 | + spin_lock_bh(&hsr->list_lock); |
---|
| 466 | + list_for_each_entry_safe(node, tmp, &hsr->node_db, mac_list) { |
---|
| 467 | + /* Don't prune own node. Neither time_in[HSR_PT_SLAVE_A] |
---|
| 468 | + * nor time_in[HSR_PT_SLAVE_B], will ever be updated for |
---|
| 469 | + * the master port. Thus the master node will be repeatedly |
---|
| 470 | + * pruned leading to packet loss. |
---|
| 471 | + */ |
---|
| 472 | + if (hsr_addr_is_self(hsr, node->macaddress_A)) |
---|
| 473 | + continue; |
---|
| 474 | + |
---|
391 | 475 | /* Shorthand */ |
---|
392 | 476 | time_a = node->time_in[HSR_PT_SLAVE_A]; |
---|
393 | 477 | time_b = node->time_in[HSR_PT_SLAVE_B]; |
---|
394 | 478 | |
---|
395 | 479 | /* Check for timestamps old enough to risk wrap-around */ |
---|
396 | | - if (time_after(jiffies, time_a + MAX_JIFFY_OFFSET/2)) |
---|
| 480 | + if (time_after(jiffies, time_a + MAX_JIFFY_OFFSET / 2)) |
---|
397 | 481 | node->time_in_stale[HSR_PT_SLAVE_A] = true; |
---|
398 | | - if (time_after(jiffies, time_b + MAX_JIFFY_OFFSET/2)) |
---|
| 482 | + if (time_after(jiffies, time_b + MAX_JIFFY_OFFSET / 2)) |
---|
399 | 483 | node->time_in_stale[HSR_PT_SLAVE_B] = true; |
---|
400 | 484 | |
---|
401 | 485 | /* Get age of newest frame from node. |
---|
.. | .. |
---|
410 | 494 | |
---|
411 | 495 | /* Warn of ring error only as long as we get frames at all */ |
---|
412 | 496 | if (time_is_after_jiffies(timestamp + |
---|
413 | | - msecs_to_jiffies(1.5*MAX_SLAVE_DIFF))) { |
---|
| 497 | + msecs_to_jiffies(1.5 * MAX_SLAVE_DIFF))) { |
---|
414 | 498 | rcu_read_lock(); |
---|
415 | 499 | port = get_late_port(hsr, node); |
---|
416 | | - if (port != NULL) |
---|
417 | | - hsr_nl_ringerror(hsr, node->MacAddressA, port); |
---|
| 500 | + if (port) |
---|
| 501 | + hsr_nl_ringerror(hsr, node->macaddress_A, port); |
---|
418 | 502 | rcu_read_unlock(); |
---|
419 | 503 | } |
---|
420 | 504 | |
---|
421 | 505 | /* Prune old entries */ |
---|
422 | 506 | if (time_is_before_jiffies(timestamp + |
---|
423 | | - msecs_to_jiffies(HSR_NODE_FORGET_TIME))) { |
---|
424 | | - hsr_nl_nodedown(hsr, node->MacAddressA); |
---|
| 507 | + msecs_to_jiffies(HSR_NODE_FORGET_TIME))) { |
---|
| 508 | + hsr_nl_nodedown(hsr, node->macaddress_A); |
---|
425 | 509 | list_del_rcu(&node->mac_list); |
---|
426 | 510 | /* Note that we need to free this entry later: */ |
---|
427 | 511 | kfree_rcu(node, rcu_head); |
---|
428 | 512 | } |
---|
429 | 513 | } |
---|
430 | | - rcu_read_unlock(); |
---|
431 | | -} |
---|
| 514 | + spin_unlock_bh(&hsr->list_lock); |
---|
432 | 515 | |
---|
| 516 | + /* Restart timer */ |
---|
| 517 | + mod_timer(&hsr->prune_timer, |
---|
| 518 | + jiffies + msecs_to_jiffies(PRUNE_PERIOD)); |
---|
| 519 | +} |
---|
433 | 520 | |
---|
434 | 521 | void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos, |
---|
435 | 522 | unsigned char addr[ETH_ALEN]) |
---|
.. | .. |
---|
440 | 527 | node = list_first_or_null_rcu(&hsr->node_db, |
---|
441 | 528 | struct hsr_node, mac_list); |
---|
442 | 529 | if (node) |
---|
443 | | - ether_addr_copy(addr, node->MacAddressA); |
---|
| 530 | + ether_addr_copy(addr, node->macaddress_A); |
---|
444 | 531 | return node; |
---|
445 | 532 | } |
---|
446 | 533 | |
---|
447 | 534 | node = _pos; |
---|
448 | 535 | list_for_each_entry_continue_rcu(node, &hsr->node_db, mac_list) { |
---|
449 | | - ether_addr_copy(addr, node->MacAddressA); |
---|
| 536 | + ether_addr_copy(addr, node->macaddress_A); |
---|
450 | 537 | return node; |
---|
451 | 538 | } |
---|
452 | 539 | |
---|
453 | 540 | return NULL; |
---|
454 | 541 | } |
---|
455 | | - |
---|
456 | 542 | |
---|
457 | 543 | int hsr_get_node_data(struct hsr_priv *hsr, |
---|
458 | 544 | const unsigned char *addr, |
---|
.. | .. |
---|
467 | 553 | struct hsr_port *port; |
---|
468 | 554 | unsigned long tdiff; |
---|
469 | 555 | |
---|
470 | | - node = find_node_by_AddrA(&hsr->node_db, addr); |
---|
| 556 | + node = find_node_by_addr_A(&hsr->node_db, addr); |
---|
471 | 557 | if (!node) |
---|
472 | 558 | return -ENOENT; |
---|
473 | 559 | |
---|
474 | | - ether_addr_copy(addr_b, node->MacAddressB); |
---|
| 560 | + ether_addr_copy(addr_b, node->macaddress_B); |
---|
475 | 561 | |
---|
476 | 562 | tdiff = jiffies - node->time_in[HSR_PT_SLAVE_A]; |
---|
477 | 563 | if (node->time_in_stale[HSR_PT_SLAVE_A]) |
---|
.. | .. |
---|
497 | 583 | *if1_seq = node->seq_out[HSR_PT_SLAVE_B]; |
---|
498 | 584 | *if2_seq = node->seq_out[HSR_PT_SLAVE_A]; |
---|
499 | 585 | |
---|
500 | | - if (node->AddrB_port != HSR_PT_NONE) { |
---|
501 | | - port = hsr_port_get_hsr(hsr, node->AddrB_port); |
---|
| 586 | + if (node->addr_B_port != HSR_PT_NONE) { |
---|
| 587 | + port = hsr_port_get_hsr(hsr, node->addr_B_port); |
---|
502 | 588 | *addr_b_ifindex = port->dev->ifindex; |
---|
503 | 589 | } else { |
---|
504 | 590 | *addr_b_ifindex = -1; |
---|