blob: d1336a7ad7ff2da8386e00f3ec9c49b27373b723 [file] [log] [blame]
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
2
3#include <linux/mrp_bridge.h>
4#include "br_private_mrp.h"
5
6static const u8 mrp_test_dmac[ETH_ALEN] = { 0x1, 0x15, 0x4e, 0x0, 0x0, 0x1 };
Horatiu Vultur537ed562020-07-14 09:34:54 +02007static const u8 mrp_in_test_dmac[ETH_ALEN] = { 0x1, 0x15, 0x4e, 0x0, 0x0, 0x3 };
8
9static bool br_mrp_is_ring_port(struct net_bridge_port *p_port,
10 struct net_bridge_port *s_port,
11 struct net_bridge_port *port)
12{
13 if (port == p_port ||
14 port == s_port)
15 return true;
16
17 return false;
18}
19
20static bool br_mrp_is_in_port(struct net_bridge_port *i_port,
21 struct net_bridge_port *port)
22{
23 if (port == i_port)
24 return true;
25
26 return false;
27}
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +020028
29static struct net_bridge_port *br_mrp_get_port(struct net_bridge *br,
30 u32 ifindex)
31{
32 struct net_bridge_port *res = NULL;
33 struct net_bridge_port *port;
34
35 list_for_each_entry(port, &br->port_list, list) {
36 if (port->dev->ifindex == ifindex) {
37 res = port;
38 break;
39 }
40 }
41
42 return res;
43}
44
45static struct br_mrp *br_mrp_find_id(struct net_bridge *br, u32 ring_id)
46{
47 struct br_mrp *res = NULL;
48 struct br_mrp *mrp;
49
50 list_for_each_entry_rcu(mrp, &br->mrp_list, list,
51 lockdep_rtnl_is_held()) {
52 if (mrp->ring_id == ring_id) {
53 res = mrp;
54 break;
55 }
56 }
57
58 return res;
59}
60
Horatiu Vultur537ed562020-07-14 09:34:54 +020061static struct br_mrp *br_mrp_find_in_id(struct net_bridge *br, u32 in_id)
62{
63 struct br_mrp *res = NULL;
64 struct br_mrp *mrp;
65
66 list_for_each_entry_rcu(mrp, &br->mrp_list, list,
67 lockdep_rtnl_is_held()) {
68 if (mrp->in_id == in_id) {
69 res = mrp;
70 break;
71 }
72 }
73
74 return res;
75}
76
Horatiu Vultur7aa38012020-05-21 23:19:05 +000077static bool br_mrp_unique_ifindex(struct net_bridge *br, u32 ifindex)
78{
79 struct br_mrp *mrp;
80
81 list_for_each_entry_rcu(mrp, &br->mrp_list, list,
82 lockdep_rtnl_is_held()) {
83 struct net_bridge_port *p;
84
85 p = rtnl_dereference(mrp->p_port);
86 if (p && p->dev->ifindex == ifindex)
87 return false;
88
89 p = rtnl_dereference(mrp->s_port);
90 if (p && p->dev->ifindex == ifindex)
91 return false;
Horatiu Vultur537ed562020-07-14 09:34:54 +020092
93 p = rtnl_dereference(mrp->i_port);
94 if (p && p->dev->ifindex == ifindex)
95 return false;
Horatiu Vultur7aa38012020-05-21 23:19:05 +000096 }
97
98 return true;
99}
100
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200101static struct br_mrp *br_mrp_find_port(struct net_bridge *br,
102 struct net_bridge_port *p)
103{
104 struct br_mrp *res = NULL;
105 struct br_mrp *mrp;
106
107 list_for_each_entry_rcu(mrp, &br->mrp_list, list,
108 lockdep_rtnl_is_held()) {
109 if (rcu_access_pointer(mrp->p_port) == p ||
Horatiu Vultur537ed562020-07-14 09:34:54 +0200110 rcu_access_pointer(mrp->s_port) == p ||
111 rcu_access_pointer(mrp->i_port) == p) {
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200112 res = mrp;
113 break;
114 }
115 }
116
117 return res;
118}
119
120static int br_mrp_next_seq(struct br_mrp *mrp)
121{
122 mrp->seq_id++;
123 return mrp->seq_id;
124}
125
126static struct sk_buff *br_mrp_skb_alloc(struct net_bridge_port *p,
127 const u8 *src, const u8 *dst)
128{
129 struct ethhdr *eth_hdr;
130 struct sk_buff *skb;
Horatiu Vultur9b14d1f2020-06-28 15:45:16 +0200131 __be16 *version;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200132
133 skb = dev_alloc_skb(MRP_MAX_FRAME_LENGTH);
134 if (!skb)
135 return NULL;
136
137 skb->dev = p->dev;
138 skb->protocol = htons(ETH_P_MRP);
139 skb->priority = MRP_FRAME_PRIO;
140 skb_reserve(skb, sizeof(*eth_hdr));
141
142 eth_hdr = skb_push(skb, sizeof(*eth_hdr));
143 ether_addr_copy(eth_hdr->h_dest, dst);
144 ether_addr_copy(eth_hdr->h_source, src);
145 eth_hdr->h_proto = htons(ETH_P_MRP);
146
147 version = skb_put(skb, sizeof(*version));
148 *version = cpu_to_be16(MRP_VERSION);
149
150 return skb;
151}
152
153static void br_mrp_skb_tlv(struct sk_buff *skb,
154 enum br_mrp_tlv_header_type type,
155 u8 length)
156{
157 struct br_mrp_tlv_hdr *hdr;
158
159 hdr = skb_put(skb, sizeof(*hdr));
160 hdr->type = type;
161 hdr->length = length;
162}
163
164static void br_mrp_skb_common(struct sk_buff *skb, struct br_mrp *mrp)
165{
166 struct br_mrp_common_hdr *hdr;
167
168 br_mrp_skb_tlv(skb, BR_MRP_TLV_HEADER_COMMON, sizeof(*hdr));
169
170 hdr = skb_put(skb, sizeof(*hdr));
171 hdr->seq_id = cpu_to_be16(br_mrp_next_seq(mrp));
172 memset(hdr->domain, 0xff, MRP_DOMAIN_UUID_LENGTH);
173}
174
175static struct sk_buff *br_mrp_alloc_test_skb(struct br_mrp *mrp,
176 struct net_bridge_port *p,
177 enum br_mrp_port_role_type port_role)
178{
179 struct br_mrp_ring_test_hdr *hdr = NULL;
180 struct sk_buff *skb = NULL;
181
182 if (!p)
183 return NULL;
184
185 skb = br_mrp_skb_alloc(p, p->dev->dev_addr, mrp_test_dmac);
186 if (!skb)
187 return NULL;
188
189 br_mrp_skb_tlv(skb, BR_MRP_TLV_HEADER_RING_TEST, sizeof(*hdr));
190 hdr = skb_put(skb, sizeof(*hdr));
191
Horatiu Vultur4b3a61b2020-05-30 18:09:47 +0000192 hdr->prio = cpu_to_be16(mrp->prio);
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200193 ether_addr_copy(hdr->sa, p->br->dev->dev_addr);
194 hdr->port_role = cpu_to_be16(port_role);
195 hdr->state = cpu_to_be16(mrp->ring_state);
196 hdr->transitions = cpu_to_be16(mrp->ring_transitions);
197 hdr->timestamp = cpu_to_be32(jiffies_to_msecs(jiffies));
198
199 br_mrp_skb_common(skb, mrp);
200 br_mrp_skb_tlv(skb, BR_MRP_TLV_HEADER_END, 0x0);
201
202 return skb;
203}
204
Horatiu Vultur537ed562020-07-14 09:34:54 +0200205static struct sk_buff *br_mrp_alloc_in_test_skb(struct br_mrp *mrp,
206 struct net_bridge_port *p,
207 enum br_mrp_port_role_type port_role)
208{
209 struct br_mrp_in_test_hdr *hdr = NULL;
210 struct sk_buff *skb = NULL;
211
212 if (!p)
213 return NULL;
214
215 skb = br_mrp_skb_alloc(p, p->dev->dev_addr, mrp_in_test_dmac);
216 if (!skb)
217 return NULL;
218
219 br_mrp_skb_tlv(skb, BR_MRP_TLV_HEADER_IN_TEST, sizeof(*hdr));
220 hdr = skb_put(skb, sizeof(*hdr));
221
222 hdr->id = cpu_to_be16(mrp->in_id);
223 ether_addr_copy(hdr->sa, p->br->dev->dev_addr);
224 hdr->port_role = cpu_to_be16(port_role);
225 hdr->state = cpu_to_be16(mrp->in_state);
226 hdr->transitions = cpu_to_be16(mrp->in_transitions);
227 hdr->timestamp = cpu_to_be32(jiffies_to_msecs(jiffies));
228
229 br_mrp_skb_common(skb, mrp);
230 br_mrp_skb_tlv(skb, BR_MRP_TLV_HEADER_END, 0x0);
231
232 return skb;
233}
234
Horatiu Vulturc6676e72020-05-30 18:09:48 +0000235/* This function is continuously called in the following cases:
236 * - when node role is MRM, in this case test_monitor is always set to false
237 * because it needs to notify the userspace that the ring is open and needs to
238 * send MRP_Test frames
239 * - when node role is MRA, there are 2 subcases:
240 * - when MRA behaves as MRM, in this case is similar with MRM role
241 * - when MRA behaves as MRC, in this case test_monitor is set to true,
242 * because it needs to detect when it stops seeing MRP_Test frames
243 * from MRM node but it doesn't need to send MRP_Test frames.
244 */
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200245static void br_mrp_test_work_expired(struct work_struct *work)
246{
247 struct delayed_work *del_work = to_delayed_work(work);
248 struct br_mrp *mrp = container_of(del_work, struct br_mrp, test_work);
249 struct net_bridge_port *p;
250 bool notify_open = false;
251 struct sk_buff *skb;
252
253 if (time_before_eq(mrp->test_end, jiffies))
254 return;
255
256 if (mrp->test_count_miss < mrp->test_max_miss) {
257 mrp->test_count_miss++;
258 } else {
259 /* Notify that the ring is open only if the ring state is
260 * closed, otherwise it would continue to notify at every
261 * interval.
Horatiu Vulturc6676e72020-05-30 18:09:48 +0000262 * Also notify that the ring is open when the node has the
263 * role MRA and behaves as MRC. The reason is that the
264 * userspace needs to know when the MRM stopped sending
265 * MRP_Test frames so that the current node to try to take
266 * the role of a MRM.
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200267 */
Horatiu Vulturc6676e72020-05-30 18:09:48 +0000268 if (mrp->ring_state == BR_MRP_RING_STATE_CLOSED ||
269 mrp->test_monitor)
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200270 notify_open = true;
271 }
272
273 rcu_read_lock();
274
275 p = rcu_dereference(mrp->p_port);
276 if (p) {
Horatiu Vulturc6676e72020-05-30 18:09:48 +0000277 if (!mrp->test_monitor) {
278 skb = br_mrp_alloc_test_skb(mrp, p,
279 BR_MRP_PORT_ROLE_PRIMARY);
280 if (!skb)
281 goto out;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200282
Horatiu Vulturc6676e72020-05-30 18:09:48 +0000283 skb_reset_network_header(skb);
284 dev_queue_xmit(skb);
285 }
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200286
287 if (notify_open && !mrp->ring_role_offloaded)
Horatiu Vultur4cc625c2020-07-14 09:34:51 +0200288 br_mrp_ring_port_open(p->dev, true);
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200289 }
290
291 p = rcu_dereference(mrp->s_port);
292 if (p) {
Horatiu Vulturc6676e72020-05-30 18:09:48 +0000293 if (!mrp->test_monitor) {
294 skb = br_mrp_alloc_test_skb(mrp, p,
295 BR_MRP_PORT_ROLE_SECONDARY);
296 if (!skb)
297 goto out;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200298
Horatiu Vulturc6676e72020-05-30 18:09:48 +0000299 skb_reset_network_header(skb);
300 dev_queue_xmit(skb);
301 }
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200302
303 if (notify_open && !mrp->ring_role_offloaded)
Horatiu Vultur4cc625c2020-07-14 09:34:51 +0200304 br_mrp_ring_port_open(p->dev, true);
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200305 }
306
307out:
308 rcu_read_unlock();
309
310 queue_delayed_work(system_wq, &mrp->test_work,
311 usecs_to_jiffies(mrp->test_interval));
312}
313
Horatiu Vultur537ed562020-07-14 09:34:54 +0200314/* This function is continuously called when the node has the interconnect role
315 * MIM. It would generate interconnect test frames and will send them on all 3
316 * ports. But will also check if it stop receiving interconnect test frames.
317 */
318static void br_mrp_in_test_work_expired(struct work_struct *work)
319{
320 struct delayed_work *del_work = to_delayed_work(work);
321 struct br_mrp *mrp = container_of(del_work, struct br_mrp, in_test_work);
322 struct net_bridge_port *p;
323 bool notify_open = false;
324 struct sk_buff *skb;
325
326 if (time_before_eq(mrp->in_test_end, jiffies))
327 return;
328
329 if (mrp->in_test_count_miss < mrp->in_test_max_miss) {
330 mrp->in_test_count_miss++;
331 } else {
332 /* Notify that the interconnect ring is open only if the
333 * interconnect ring state is closed, otherwise it would
334 * continue to notify at every interval.
335 */
336 if (mrp->in_state == BR_MRP_IN_STATE_CLOSED)
337 notify_open = true;
338 }
339
340 rcu_read_lock();
341
342 p = rcu_dereference(mrp->p_port);
343 if (p) {
344 skb = br_mrp_alloc_in_test_skb(mrp, p,
345 BR_MRP_PORT_ROLE_PRIMARY);
346 if (!skb)
347 goto out;
348
349 skb_reset_network_header(skb);
350 dev_queue_xmit(skb);
351
352 if (notify_open && !mrp->in_role_offloaded)
353 br_mrp_in_port_open(p->dev, true);
354 }
355
356 p = rcu_dereference(mrp->s_port);
357 if (p) {
358 skb = br_mrp_alloc_in_test_skb(mrp, p,
359 BR_MRP_PORT_ROLE_SECONDARY);
360 if (!skb)
361 goto out;
362
363 skb_reset_network_header(skb);
364 dev_queue_xmit(skb);
365
366 if (notify_open && !mrp->in_role_offloaded)
367 br_mrp_in_port_open(p->dev, true);
368 }
369
370 p = rcu_dereference(mrp->i_port);
371 if (p) {
372 skb = br_mrp_alloc_in_test_skb(mrp, p,
373 BR_MRP_PORT_ROLE_INTER);
374 if (!skb)
375 goto out;
376
377 skb_reset_network_header(skb);
378 dev_queue_xmit(skb);
379
380 if (notify_open && !mrp->in_role_offloaded)
381 br_mrp_in_port_open(p->dev, true);
382 }
383
384out:
385 rcu_read_unlock();
386
387 queue_delayed_work(system_wq, &mrp->in_test_work,
388 usecs_to_jiffies(mrp->in_test_interval));
389}
390
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200391/* Deletes the MRP instance.
392 * note: called under rtnl_lock
393 */
394static void br_mrp_del_impl(struct net_bridge *br, struct br_mrp *mrp)
395{
396 struct net_bridge_port *p;
Horatiu Vultur4fb13492020-05-21 23:19:07 +0000397 u8 state;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200398
399 /* Stop sending MRP_Test frames */
400 cancel_delayed_work_sync(&mrp->test_work);
Horatiu Vulturc6676e72020-05-30 18:09:48 +0000401 br_mrp_switchdev_send_ring_test(br, mrp, 0, 0, 0, 0);
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200402
Horatiu Vultur537ed562020-07-14 09:34:54 +0200403 /* Stop sending MRP_InTest frames if has an interconnect role */
404 cancel_delayed_work_sync(&mrp->in_test_work);
405 br_mrp_switchdev_send_in_test(br, mrp, 0, 0, 0);
406
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200407 br_mrp_switchdev_del(br, mrp);
408
409 /* Reset the ports */
410 p = rtnl_dereference(mrp->p_port);
411 if (p) {
412 spin_lock_bh(&br->lock);
Horatiu Vultur4fb13492020-05-21 23:19:07 +0000413 state = netif_running(br->dev) ?
414 BR_STATE_FORWARDING : BR_STATE_DISABLED;
415 p->state = state;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200416 p->flags &= ~BR_MRP_AWARE;
417 spin_unlock_bh(&br->lock);
Horatiu Vultur4fb13492020-05-21 23:19:07 +0000418 br_mrp_port_switchdev_set_state(p, state);
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200419 rcu_assign_pointer(mrp->p_port, NULL);
420 }
421
422 p = rtnl_dereference(mrp->s_port);
423 if (p) {
424 spin_lock_bh(&br->lock);
Horatiu Vultur4fb13492020-05-21 23:19:07 +0000425 state = netif_running(br->dev) ?
426 BR_STATE_FORWARDING : BR_STATE_DISABLED;
427 p->state = state;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200428 p->flags &= ~BR_MRP_AWARE;
429 spin_unlock_bh(&br->lock);
Horatiu Vultur4fb13492020-05-21 23:19:07 +0000430 br_mrp_port_switchdev_set_state(p, state);
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200431 rcu_assign_pointer(mrp->s_port, NULL);
432 }
433
Horatiu Vultur537ed562020-07-14 09:34:54 +0200434 p = rtnl_dereference(mrp->i_port);
435 if (p) {
436 spin_lock_bh(&br->lock);
437 state = netif_running(br->dev) ?
438 BR_STATE_FORWARDING : BR_STATE_DISABLED;
439 p->state = state;
440 p->flags &= ~BR_MRP_AWARE;
441 spin_unlock_bh(&br->lock);
442 br_mrp_port_switchdev_set_state(p, state);
443 rcu_assign_pointer(mrp->i_port, NULL);
444 }
445
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200446 list_del_rcu(&mrp->list);
447 kfree_rcu(mrp, rcu);
448}
449
450/* Adds a new MRP instance.
451 * note: called under rtnl_lock
452 */
453int br_mrp_add(struct net_bridge *br, struct br_mrp_instance *instance)
454{
455 struct net_bridge_port *p;
456 struct br_mrp *mrp;
457 int err;
458
459 /* If the ring exists, it is not possible to create another one with the
460 * same ring_id
461 */
462 mrp = br_mrp_find_id(br, instance->ring_id);
463 if (mrp)
464 return -EINVAL;
465
466 if (!br_mrp_get_port(br, instance->p_ifindex) ||
467 !br_mrp_get_port(br, instance->s_ifindex))
468 return -EINVAL;
469
Horatiu Vultur7aa38012020-05-21 23:19:05 +0000470 /* It is not possible to have the same port part of multiple rings */
471 if (!br_mrp_unique_ifindex(br, instance->p_ifindex) ||
472 !br_mrp_unique_ifindex(br, instance->s_ifindex))
473 return -EINVAL;
474
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200475 mrp = kzalloc(sizeof(*mrp), GFP_KERNEL);
476 if (!mrp)
477 return -ENOMEM;
478
479 mrp->ring_id = instance->ring_id;
Horatiu Vultur4b3a61b2020-05-30 18:09:47 +0000480 mrp->prio = instance->prio;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200481
482 p = br_mrp_get_port(br, instance->p_ifindex);
483 spin_lock_bh(&br->lock);
484 p->state = BR_STATE_FORWARDING;
485 p->flags |= BR_MRP_AWARE;
486 spin_unlock_bh(&br->lock);
487 rcu_assign_pointer(mrp->p_port, p);
488
489 p = br_mrp_get_port(br, instance->s_ifindex);
490 spin_lock_bh(&br->lock);
491 p->state = BR_STATE_FORWARDING;
492 p->flags |= BR_MRP_AWARE;
493 spin_unlock_bh(&br->lock);
494 rcu_assign_pointer(mrp->s_port, p);
495
496 INIT_DELAYED_WORK(&mrp->test_work, br_mrp_test_work_expired);
Horatiu Vultur537ed562020-07-14 09:34:54 +0200497 INIT_DELAYED_WORK(&mrp->in_test_work, br_mrp_in_test_work_expired);
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200498 list_add_tail_rcu(&mrp->list, &br->mrp_list);
499
500 err = br_mrp_switchdev_add(br, mrp);
501 if (err)
502 goto delete_mrp;
503
504 return 0;
505
506delete_mrp:
507 br_mrp_del_impl(br, mrp);
508
509 return err;
510}
511
512/* Deletes the MRP instance from which the port is part of
513 * note: called under rtnl_lock
514 */
515void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p)
516{
517 struct br_mrp *mrp = br_mrp_find_port(br, p);
518
519 /* If the port is not part of a MRP instance just bail out */
520 if (!mrp)
521 return;
522
523 br_mrp_del_impl(br, mrp);
524}
525
526/* Deletes existing MRP instance based on ring_id
527 * note: called under rtnl_lock
528 */
529int br_mrp_del(struct net_bridge *br, struct br_mrp_instance *instance)
530{
531 struct br_mrp *mrp = br_mrp_find_id(br, instance->ring_id);
532
533 if (!mrp)
534 return -EINVAL;
535
536 br_mrp_del_impl(br, mrp);
537
538 return 0;
539}
540
541/* Set port state, port state can be forwarding, blocked or disabled
542 * note: already called with rtnl_lock
543 */
544int br_mrp_set_port_state(struct net_bridge_port *p,
545 enum br_mrp_port_state_type state)
546{
Horatiu Vultur55ad30c2021-02-06 22:47:33 +0100547 u32 port_state;
548
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200549 if (!p || !(p->flags & BR_MRP_AWARE))
550 return -EINVAL;
551
552 spin_lock_bh(&p->br->lock);
553
554 if (state == BR_MRP_PORT_STATE_FORWARDING)
Horatiu Vultur55ad30c2021-02-06 22:47:33 +0100555 port_state = BR_STATE_FORWARDING;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200556 else
Horatiu Vultur55ad30c2021-02-06 22:47:33 +0100557 port_state = BR_STATE_BLOCKING;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200558
Horatiu Vultur55ad30c2021-02-06 22:47:33 +0100559 p->state = port_state;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200560 spin_unlock_bh(&p->br->lock);
561
Horatiu Vultur55ad30c2021-02-06 22:47:33 +0100562 br_mrp_port_switchdev_set_state(p, port_state);
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200563
564 return 0;
565}
566
567/* Set port role, port role can be primary or secondary
568 * note: already called with rtnl_lock
569 */
570int br_mrp_set_port_role(struct net_bridge_port *p,
Horatiu Vultur20f6a052020-05-27 12:34:30 +0000571 enum br_mrp_port_role_type role)
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200572{
573 struct br_mrp *mrp;
574
575 if (!p || !(p->flags & BR_MRP_AWARE))
576 return -EINVAL;
577
Horatiu Vultur20f6a052020-05-27 12:34:30 +0000578 mrp = br_mrp_find_port(p->br, p);
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200579
580 if (!mrp)
581 return -EINVAL;
582
Horatiu Vultur7882c892020-06-23 11:05:41 +0200583 switch (role) {
584 case BR_MRP_PORT_ROLE_PRIMARY:
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200585 rcu_assign_pointer(mrp->p_port, p);
Horatiu Vultur7882c892020-06-23 11:05:41 +0200586 break;
587 case BR_MRP_PORT_ROLE_SECONDARY:
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200588 rcu_assign_pointer(mrp->s_port, p);
Horatiu Vultur7882c892020-06-23 11:05:41 +0200589 break;
590 default:
591 return -EINVAL;
592 }
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200593
Horatiu Vultur20f6a052020-05-27 12:34:30 +0000594 br_mrp_port_switchdev_set_role(p, role);
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200595
596 return 0;
597}
598
599/* Set ring state, ring state can be only Open or Closed
600 * note: already called with rtnl_lock
601 */
602int br_mrp_set_ring_state(struct net_bridge *br,
603 struct br_mrp_ring_state *state)
604{
605 struct br_mrp *mrp = br_mrp_find_id(br, state->ring_id);
606
607 if (!mrp)
608 return -EINVAL;
609
610 if (mrp->ring_state == BR_MRP_RING_STATE_CLOSED &&
611 state->ring_state != BR_MRP_RING_STATE_CLOSED)
612 mrp->ring_transitions++;
613
614 mrp->ring_state = state->ring_state;
615
616 br_mrp_switchdev_set_ring_state(br, mrp, state->ring_state);
617
618 return 0;
619}
620
621/* Set ring role, ring role can be only MRM(Media Redundancy Manager) or
622 * MRC(Media Redundancy Client).
623 * note: already called with rtnl_lock
624 */
625int br_mrp_set_ring_role(struct net_bridge *br,
626 struct br_mrp_ring_role *role)
627{
628 struct br_mrp *mrp = br_mrp_find_id(br, role->ring_id);
629 int err;
630
631 if (!mrp)
632 return -EINVAL;
633
634 mrp->ring_role = role->ring_role;
635
636 /* If there is an error just bailed out */
637 err = br_mrp_switchdev_set_ring_role(br, mrp, role->ring_role);
638 if (err && err != -EOPNOTSUPP)
639 return err;
640
641 /* Now detect if the HW actually applied the role or not. If the HW
642 * applied the role it means that the SW will not to do those operations
643 * anymore. For example if the role ir MRM then the HW will notify the
644 * SW when ring is open, but if the is not pushed to the HW the SW will
645 * need to detect when the ring is open
646 */
647 mrp->ring_role_offloaded = err == -EOPNOTSUPP ? 0 : 1;
648
649 return 0;
650}
651
Horatiu Vulturc6676e72020-05-30 18:09:48 +0000652/* Start to generate or monitor MRP test frames, the frames are generated by
653 * HW and if it fails, they are generated by the SW.
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200654 * note: already called with rtnl_lock
655 */
656int br_mrp_start_test(struct net_bridge *br,
657 struct br_mrp_start_test *test)
658{
659 struct br_mrp *mrp = br_mrp_find_id(br, test->ring_id);
660
661 if (!mrp)
662 return -EINVAL;
663
Horatiu Vulturc6676e72020-05-30 18:09:48 +0000664 /* Try to push it to the HW and if it fails then continue with SW
665 * implementation and if that also fails then return error.
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200666 */
667 if (!br_mrp_switchdev_send_ring_test(br, mrp, test->interval,
Horatiu Vulturc6676e72020-05-30 18:09:48 +0000668 test->max_miss, test->period,
669 test->monitor))
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200670 return 0;
671
672 mrp->test_interval = test->interval;
673 mrp->test_end = jiffies + usecs_to_jiffies(test->period);
674 mrp->test_max_miss = test->max_miss;
Horatiu Vulturc6676e72020-05-30 18:09:48 +0000675 mrp->test_monitor = test->monitor;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200676 mrp->test_count_miss = 0;
677 queue_delayed_work(system_wq, &mrp->test_work,
678 usecs_to_jiffies(test->interval));
679
680 return 0;
681}
682
Horatiu Vultur537ed562020-07-14 09:34:54 +0200683/* Set in state, int state can be only Open or Closed
684 * note: already called with rtnl_lock
685 */
686int br_mrp_set_in_state(struct net_bridge *br, struct br_mrp_in_state *state)
687{
688 struct br_mrp *mrp = br_mrp_find_in_id(br, state->in_id);
689
690 if (!mrp)
691 return -EINVAL;
692
693 if (mrp->in_state == BR_MRP_IN_STATE_CLOSED &&
694 state->in_state != BR_MRP_IN_STATE_CLOSED)
695 mrp->in_transitions++;
696
697 mrp->in_state = state->in_state;
698
699 br_mrp_switchdev_set_in_state(br, mrp, state->in_state);
700
701 return 0;
702}
703
704/* Set in role, in role can be only MIM(Media Interconnection Manager) or
705 * MIC(Media Interconnection Client).
706 * note: already called with rtnl_lock
707 */
708int br_mrp_set_in_role(struct net_bridge *br, struct br_mrp_in_role *role)
709{
710 struct br_mrp *mrp = br_mrp_find_id(br, role->ring_id);
711 struct net_bridge_port *p;
712 int err;
713
714 if (!mrp)
715 return -EINVAL;
716
717 if (!br_mrp_get_port(br, role->i_ifindex))
718 return -EINVAL;
719
720 if (role->in_role == BR_MRP_IN_ROLE_DISABLED) {
721 u8 state;
722
723 /* It is not allowed to disable a port that doesn't exist */
724 p = rtnl_dereference(mrp->i_port);
725 if (!p)
726 return -EINVAL;
727
728 /* Stop the generating MRP_InTest frames */
729 cancel_delayed_work_sync(&mrp->in_test_work);
730 br_mrp_switchdev_send_in_test(br, mrp, 0, 0, 0);
731
732 /* Remove the port */
733 spin_lock_bh(&br->lock);
734 state = netif_running(br->dev) ?
735 BR_STATE_FORWARDING : BR_STATE_DISABLED;
736 p->state = state;
737 p->flags &= ~BR_MRP_AWARE;
738 spin_unlock_bh(&br->lock);
739 br_mrp_port_switchdev_set_state(p, state);
740 rcu_assign_pointer(mrp->i_port, NULL);
741
742 mrp->in_role = role->in_role;
743 mrp->in_id = 0;
744
745 return 0;
746 }
747
748 /* It is not possible to have the same port part of multiple rings */
749 if (!br_mrp_unique_ifindex(br, role->i_ifindex))
750 return -EINVAL;
751
752 /* It is not allowed to set a different interconnect port if the mrp
753 * instance has already one. First it needs to be disabled and after
754 * that set the new port
755 */
756 if (rcu_access_pointer(mrp->i_port))
757 return -EINVAL;
758
759 p = br_mrp_get_port(br, role->i_ifindex);
760 spin_lock_bh(&br->lock);
761 p->state = BR_STATE_FORWARDING;
762 p->flags |= BR_MRP_AWARE;
763 spin_unlock_bh(&br->lock);
764 rcu_assign_pointer(mrp->i_port, p);
765
766 mrp->in_role = role->in_role;
767 mrp->in_id = role->in_id;
768
769 /* If there is an error just bailed out */
770 err = br_mrp_switchdev_set_in_role(br, mrp, role->in_id,
771 role->ring_id, role->in_role);
772 if (err && err != -EOPNOTSUPP)
773 return err;
774
775 /* Now detect if the HW actually applied the role or not. If the HW
776 * applied the role it means that the SW will not to do those operations
777 * anymore. For example if the role is MIM then the HW will notify the
778 * SW when interconnect ring is open, but if the is not pushed to the HW
779 * the SW will need to detect when the interconnect ring is open.
780 */
781 mrp->in_role_offloaded = err == -EOPNOTSUPP ? 0 : 1;
782
783 return 0;
784}
785
786/* Start to generate MRP_InTest frames, the frames are generated by
787 * HW and if it fails, they are generated by the SW.
788 * note: already called with rtnl_lock
789 */
790int br_mrp_start_in_test(struct net_bridge *br,
791 struct br_mrp_start_in_test *in_test)
792{
793 struct br_mrp *mrp = br_mrp_find_in_id(br, in_test->in_id);
794
795 if (!mrp)
796 return -EINVAL;
797
798 if (mrp->in_role != BR_MRP_IN_ROLE_MIM)
799 return -EINVAL;
800
801 /* Try to push it to the HW and if it fails then continue with SW
802 * implementation and if that also fails then return error.
803 */
804 if (!br_mrp_switchdev_send_in_test(br, mrp, in_test->interval,
805 in_test->max_miss, in_test->period))
806 return 0;
807
808 mrp->in_test_interval = in_test->interval;
809 mrp->in_test_end = jiffies + usecs_to_jiffies(in_test->period);
810 mrp->in_test_max_miss = in_test->max_miss;
811 mrp->in_test_count_miss = 0;
812 queue_delayed_work(system_wq, &mrp->in_test_work,
813 usecs_to_jiffies(in_test->interval));
814
815 return 0;
816}
817
818/* Determin if the frame type is a ring frame */
819static bool br_mrp_ring_frame(struct sk_buff *skb)
820{
821 const struct br_mrp_tlv_hdr *hdr;
822 struct br_mrp_tlv_hdr _hdr;
823
824 hdr = skb_header_pointer(skb, sizeof(uint16_t), sizeof(_hdr), &_hdr);
825 if (!hdr)
826 return false;
827
828 if (hdr->type == BR_MRP_TLV_HEADER_RING_TEST ||
829 hdr->type == BR_MRP_TLV_HEADER_RING_TOPO ||
830 hdr->type == BR_MRP_TLV_HEADER_RING_LINK_DOWN ||
831 hdr->type == BR_MRP_TLV_HEADER_RING_LINK_UP ||
832 hdr->type == BR_MRP_TLV_HEADER_OPTION)
833 return true;
834
835 return false;
836}
837
838/* Determin if the frame type is an interconnect frame */
839static bool br_mrp_in_frame(struct sk_buff *skb)
840{
841 const struct br_mrp_tlv_hdr *hdr;
842 struct br_mrp_tlv_hdr _hdr;
843
844 hdr = skb_header_pointer(skb, sizeof(uint16_t), sizeof(_hdr), &_hdr);
845 if (!hdr)
846 return false;
847
848 if (hdr->type == BR_MRP_TLV_HEADER_IN_TEST ||
849 hdr->type == BR_MRP_TLV_HEADER_IN_TOPO ||
850 hdr->type == BR_MRP_TLV_HEADER_IN_LINK_DOWN ||
851 hdr->type == BR_MRP_TLV_HEADER_IN_LINK_UP)
852 return true;
853
854 return false;
855}
856
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200857/* Process only MRP Test frame. All the other MRP frames are processed by
858 * userspace application
859 * note: already called with rcu_read_lock
860 */
861static void br_mrp_mrm_process(struct br_mrp *mrp, struct net_bridge_port *port,
862 struct sk_buff *skb)
863{
864 const struct br_mrp_tlv_hdr *hdr;
865 struct br_mrp_tlv_hdr _hdr;
866
867 /* Each MRP header starts with a version field which is 16 bits.
868 * Therefore skip the version and get directly the TLV header.
869 */
870 hdr = skb_header_pointer(skb, sizeof(uint16_t), sizeof(_hdr), &_hdr);
871 if (!hdr)
872 return;
873
874 if (hdr->type != BR_MRP_TLV_HEADER_RING_TEST)
875 return;
876
877 mrp->test_count_miss = 0;
878
879 /* Notify the userspace that the ring is closed only when the ring is
880 * not closed
881 */
882 if (mrp->ring_state != BR_MRP_RING_STATE_CLOSED)
Horatiu Vultur4cc625c2020-07-14 09:34:51 +0200883 br_mrp_ring_port_open(port->dev, false);
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +0200884}
885
Horatiu Vulturc6676e72020-05-30 18:09:48 +0000886/* Determin if the test hdr has a better priority than the node */
887static bool br_mrp_test_better_than_own(struct br_mrp *mrp,
888 struct net_bridge *br,
889 const struct br_mrp_ring_test_hdr *hdr)
890{
891 u16 prio = be16_to_cpu(hdr->prio);
892
893 if (prio < mrp->prio ||
894 (prio == mrp->prio &&
895 ether_addr_to_u64(hdr->sa) < ether_addr_to_u64(br->dev->dev_addr)))
896 return true;
897
898 return false;
899}
900
901/* Process only MRP Test frame. All the other MRP frames are processed by
902 * userspace application
903 * note: already called with rcu_read_lock
904 */
905static void br_mrp_mra_process(struct br_mrp *mrp, struct net_bridge *br,
906 struct net_bridge_port *port,
907 struct sk_buff *skb)
908{
909 const struct br_mrp_ring_test_hdr *test_hdr;
910 struct br_mrp_ring_test_hdr _test_hdr;
911 const struct br_mrp_tlv_hdr *hdr;
912 struct br_mrp_tlv_hdr _hdr;
913
914 /* Each MRP header starts with a version field which is 16 bits.
915 * Therefore skip the version and get directly the TLV header.
916 */
917 hdr = skb_header_pointer(skb, sizeof(uint16_t), sizeof(_hdr), &_hdr);
918 if (!hdr)
919 return;
920
921 if (hdr->type != BR_MRP_TLV_HEADER_RING_TEST)
922 return;
923
924 test_hdr = skb_header_pointer(skb, sizeof(uint16_t) + sizeof(_hdr),
925 sizeof(_test_hdr), &_test_hdr);
926 if (!test_hdr)
927 return;
928
929 /* Only frames that have a better priority than the node will
930 * clear the miss counter because otherwise the node will need to behave
931 * as MRM.
932 */
933 if (br_mrp_test_better_than_own(mrp, br, test_hdr))
934 mrp->test_count_miss = 0;
935}
936
Horatiu Vultur537ed562020-07-14 09:34:54 +0200937/* Process only MRP InTest frame. All the other MRP frames are processed by
938 * userspace application
939 * note: already called with rcu_read_lock
940 */
941static bool br_mrp_mim_process(struct br_mrp *mrp, struct net_bridge_port *port,
942 struct sk_buff *skb)
943{
944 const struct br_mrp_in_test_hdr *in_hdr;
945 struct br_mrp_in_test_hdr _in_hdr;
946 const struct br_mrp_tlv_hdr *hdr;
947 struct br_mrp_tlv_hdr _hdr;
948
949 /* Each MRP header starts with a version field which is 16 bits.
950 * Therefore skip the version and get directly the TLV header.
951 */
952 hdr = skb_header_pointer(skb, sizeof(uint16_t), sizeof(_hdr), &_hdr);
953 if (!hdr)
954 return false;
955
956 /* The check for InTest frame type was already done */
957 in_hdr = skb_header_pointer(skb, sizeof(uint16_t) + sizeof(_hdr),
958 sizeof(_in_hdr), &_in_hdr);
959 if (!in_hdr)
960 return false;
961
962 /* It needs to process only it's own InTest frames. */
963 if (mrp->in_id != ntohs(in_hdr->id))
964 return false;
965
966 mrp->in_test_count_miss = 0;
967
968 /* Notify the userspace that the ring is closed only when the ring is
969 * not closed
970 */
971 if (mrp->in_state != BR_MRP_IN_STATE_CLOSED)
972 br_mrp_in_port_open(port->dev, false);
973
974 return true;
975}
976
977/* Get the MRP frame type
978 * note: already called with rcu_read_lock
979 */
980static u8 br_mrp_get_frame_type(struct sk_buff *skb)
981{
982 const struct br_mrp_tlv_hdr *hdr;
983 struct br_mrp_tlv_hdr _hdr;
984
985 /* Each MRP header starts with a version field which is 16 bits.
986 * Therefore skip the version and get directly the TLV header.
987 */
988 hdr = skb_header_pointer(skb, sizeof(uint16_t), sizeof(_hdr), &_hdr);
989 if (!hdr)
990 return 0xff;
991
992 return hdr->type;
993}
994
995static bool br_mrp_mrm_behaviour(struct br_mrp *mrp)
996{
997 if (mrp->ring_role == BR_MRP_RING_ROLE_MRM ||
998 (mrp->ring_role == BR_MRP_RING_ROLE_MRA && !mrp->test_monitor))
999 return true;
1000
1001 return false;
1002}
1003
1004static bool br_mrp_mrc_behaviour(struct br_mrp *mrp)
1005{
1006 if (mrp->ring_role == BR_MRP_RING_ROLE_MRC ||
1007 (mrp->ring_role == BR_MRP_RING_ROLE_MRA && mrp->test_monitor))
1008 return true;
1009
1010 return false;
1011}
1012
1013/* This will just forward the frame to the other mrp ring ports, depending on
1014 * the frame type, ring role and interconnect role
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +02001015 * note: already called with rcu_read_lock
1016 */
1017static int br_mrp_rcv(struct net_bridge_port *p,
1018 struct sk_buff *skb, struct net_device *dev)
1019{
Horatiu Vultur537ed562020-07-14 09:34:54 +02001020 struct net_bridge_port *p_port, *s_port, *i_port = NULL;
1021 struct net_bridge_port *p_dst, *s_dst, *i_dst = NULL;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +02001022 struct net_bridge *br;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +02001023 struct br_mrp *mrp;
1024
1025 /* If port is disabled don't accept any frames */
1026 if (p->state == BR_STATE_DISABLED)
1027 return 0;
1028
1029 br = p->br;
1030 mrp = br_mrp_find_port(br, p);
1031 if (unlikely(!mrp))
1032 return 0;
1033
1034 p_port = rcu_dereference(mrp->p_port);
1035 if (!p_port)
1036 return 0;
Horatiu Vultur537ed562020-07-14 09:34:54 +02001037 p_dst = p_port;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +02001038
1039 s_port = rcu_dereference(mrp->s_port);
1040 if (!s_port)
1041 return 0;
Horatiu Vultur537ed562020-07-14 09:34:54 +02001042 s_dst = s_port;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +02001043
Horatiu Vultur537ed562020-07-14 09:34:54 +02001044 /* If the frame is a ring frame then it is not required to check the
1045 * interconnect role and ports to process or forward the frame
Horatiu Vulturc6676e72020-05-30 18:09:48 +00001046 */
Horatiu Vultur537ed562020-07-14 09:34:54 +02001047 if (br_mrp_ring_frame(skb)) {
1048 /* If the role is MRM then don't forward the frames */
1049 if (mrp->ring_role == BR_MRP_RING_ROLE_MRM) {
Horatiu Vulturc6676e72020-05-30 18:09:48 +00001050 br_mrp_mrm_process(mrp, p, skb);
Horatiu Vultur537ed562020-07-14 09:34:54 +02001051 goto no_forward;
Horatiu Vulturc6676e72020-05-30 18:09:48 +00001052 }
1053
Horatiu Vultur537ed562020-07-14 09:34:54 +02001054 /* If the role is MRA then don't forward the frames if it
1055 * behaves as MRM node
1056 */
1057 if (mrp->ring_role == BR_MRP_RING_ROLE_MRA) {
1058 if (!mrp->test_monitor) {
1059 br_mrp_mrm_process(mrp, p, skb);
1060 goto no_forward;
1061 }
1062
1063 br_mrp_mra_process(mrp, br, p, skb);
1064 }
1065
1066 goto forward;
Horatiu Vulturc6676e72020-05-30 18:09:48 +00001067 }
1068
Horatiu Vultur537ed562020-07-14 09:34:54 +02001069 if (br_mrp_in_frame(skb)) {
1070 u8 in_type = br_mrp_get_frame_type(skb);
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +02001071
Horatiu Vultur537ed562020-07-14 09:34:54 +02001072 i_port = rcu_dereference(mrp->i_port);
1073 i_dst = i_port;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +02001074
Horatiu Vultur537ed562020-07-14 09:34:54 +02001075 /* If the ring port is in block state it should not forward
1076 * In_Test frames
1077 */
1078 if (br_mrp_is_ring_port(p_port, s_port, p) &&
1079 p->state == BR_STATE_BLOCKING &&
1080 in_type == BR_MRP_TLV_HEADER_IN_TEST)
1081 goto no_forward;
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +02001082
Horatiu Vultur537ed562020-07-14 09:34:54 +02001083 /* Nodes that behaves as MRM needs to stop forwarding the
1084 * frames in case the ring is closed, otherwise will be a loop.
1085 * In this case the frame is no forward between the ring ports.
1086 */
1087 if (br_mrp_mrm_behaviour(mrp) &&
1088 br_mrp_is_ring_port(p_port, s_port, p) &&
1089 (s_port->state != BR_STATE_FORWARDING ||
1090 p_port->state != BR_STATE_FORWARDING)) {
1091 p_dst = NULL;
1092 s_dst = NULL;
1093 }
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +02001094
Horatiu Vultur537ed562020-07-14 09:34:54 +02001095 /* A node that behaves as MRC and doesn't have a interconnect
1096 * role then it should forward all frames between the ring ports
1097 * because it doesn't have an interconnect port
1098 */
1099 if (br_mrp_mrc_behaviour(mrp) &&
1100 mrp->in_role == BR_MRP_IN_ROLE_DISABLED)
1101 goto forward;
1102
1103 if (mrp->in_role == BR_MRP_IN_ROLE_MIM) {
1104 if (in_type == BR_MRP_TLV_HEADER_IN_TEST) {
1105 /* MIM should not forward it's own InTest
1106 * frames
1107 */
1108 if (br_mrp_mim_process(mrp, p, skb)) {
1109 goto no_forward;
1110 } else {
1111 if (br_mrp_is_ring_port(p_port, s_port,
1112 p))
1113 i_dst = NULL;
1114
1115 if (br_mrp_is_in_port(i_port, p))
1116 goto no_forward;
1117 }
1118 } else {
1119 /* MIM should forward IntLinkChange and
1120 * IntTopoChange between ring ports but MIM
1121 * should not forward IntLinkChange and
1122 * IntTopoChange if the frame was received at
1123 * the interconnect port
1124 */
1125 if (br_mrp_is_ring_port(p_port, s_port, p))
1126 i_dst = NULL;
1127
1128 if (br_mrp_is_in_port(i_port, p))
1129 goto no_forward;
1130 }
1131 }
1132
1133 if (mrp->in_role == BR_MRP_IN_ROLE_MIC) {
1134 /* MIC should forward InTest frames on all ports
1135 * regardless of the received port
1136 */
1137 if (in_type == BR_MRP_TLV_HEADER_IN_TEST)
1138 goto forward;
1139
1140 /* MIC should forward IntLinkChange frames only if they
1141 * are received on ring ports to all the ports
1142 */
1143 if (br_mrp_is_ring_port(p_port, s_port, p) &&
1144 (in_type == BR_MRP_TLV_HEADER_IN_LINK_UP ||
1145 in_type == BR_MRP_TLV_HEADER_IN_LINK_DOWN))
1146 goto forward;
1147
1148 /* Should forward the InTopo frames only between the
1149 * ring ports
1150 */
1151 if (in_type == BR_MRP_TLV_HEADER_IN_TOPO) {
1152 i_dst = NULL;
1153 goto forward;
1154 }
1155
1156 /* In all the other cases don't forward the frames */
1157 goto no_forward;
1158 }
1159 }
1160
1161forward:
1162 if (p_dst)
1163 br_forward(p_dst, skb, true, false);
1164 if (s_dst)
1165 br_forward(s_dst, skb, true, false);
1166 if (i_dst)
1167 br_forward(i_dst, skb, true, false);
1168
1169no_forward:
Horatiu Vultur9a9f26e2020-04-26 15:22:05 +02001170 return 1;
1171}
1172
1173/* Check if the frame was received on a port that is part of MRP ring
1174 * and if the frame has MRP eth. In that case process the frame otherwise do
1175 * normal forwarding.
1176 * note: already called with rcu_read_lock
1177 */
1178int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb)
1179{
1180 /* If there is no MRP instance do normal forwarding */
1181 if (likely(!(p->flags & BR_MRP_AWARE)))
1182 goto out;
1183
1184 if (unlikely(skb->protocol == htons(ETH_P_MRP)))
1185 return br_mrp_rcv(p, skb, p->dev);
1186
1187out:
1188 return 0;
1189}
1190
1191bool br_mrp_enabled(struct net_bridge *br)
1192{
1193 return !list_empty(&br->mrp_list);
1194}