Commit 45c9cbec authored by David S. Miller's avatar David S. Miller

Merge branch 'net-bridge-mrp'

Horatiu Vultur says:

====================
net: bridge: mrp: Add support for Media Redundancy Protocol(MRP)

Media Redundancy Protocol is a data network protocol standardized by
International Electrotechnical Commission as IEC 62439-2. It allows rings of
Ethernet switches to overcome any single failure with recovery time faster than
STP. It is primarily used in Industrial Ethernet applications.

Based on the previous RFC[1][2][3][4][5], and patches[6][7][8], the MRP state
machine and all the timers were moved to userspace, except for the timers used
to generate MRP Test frames.  In this way the userspace doesn't know and should
not know if the HW or the kernel will generate the MRP Test frames. The
following changes were added to the bridge to support the MRP:
- the existing netlink interface was extended with MRP support,
- allow to detect when a MRP frame was received on a MRP ring port
- allow MRP instance to forward/terminate MRP frames
- generate MRP Test frames in case the HW doesn't have support for this

To be able to offload MRP support to HW, the switchdev API  was extend.

With these changes the userspace doesn't do the following because already the
kernel/HW will do:
- doesn't need to forward/terminate MRP frames
- doesn't need to generate MRP Test frames
- doesn't need to detect when the ring is open/closed.

The userspace application that is using the new netlink can be found here[9].

The current implementation both in kernel and userspace supports only 2 roles:
  MRM - this one is responsible to send MRP_Test and MRP_Topo frames on both
  ring ports. It needs to process MRP_Test to know if the ring is open or
  closed. This operation is desired to be offloaded to the HW because it
  requires to generate and process up to 4000 frames per second. Whenever it
  detects that the ring is open it sends MRP_Topo frames to notify all MRC about
  changes in the topology. MRM needs also to process MRP_LinkChange frames,
  these frames are generated by the MRC. When the ring is open then the state
  of both ports is to forward frames and when the ring is closed then the
  secondary port is blocked.

  MRC - this one is responsible to forward MRP frames between the ring ports.
  In case one of the ring ports gets a link down or up, then MRC will generate
  a MRP_LinkChange frames. This node should also process MRP_Topo frames and to
  clear its FDB when it receives this frame.

 Userspace
               Deamon +----------+ Client
                +
                |
 +--------------|-----------------------------------------+
  Kernel        |
                + Netlink

                |                              + Interrupt
                |                              |
 +--------------|------------------------------|----------+
  HW            | Switchdev                    |
                +                              |

The user interacts using the client (called 'mrp'), the client talks to the
deamon (called 'mrp_server'), which talks with the kernel using netlink. The
kernel will try to offload the requests to the HW via switchdev API.

If this will be accepted then in the future the netlink interface can be
expended with multiple attributes which are required by different roles of the
MRP. Like Media Redundancy Automanager(MRA), Media Interconnect Manager(MIM) and
Media Interconnect Client(MIC).

[1] https://www.spinics.net/lists/netdev/msg623647.html
[2] https://www.spinics.net/lists/netdev/msg624378.html
[3] https://www.spinics.net/lists/netdev/msg627500.html
[4] https://www.spinics.net/lists/netdev/msg641005.html
[5] https://www.spinics.net/lists/netdev/msg643991.html
[6] https://www.spinics.net/lists/netdev/msg645378.html
[7] https://www.spinics.net/lists/kernel/msg3484685.html
[8] https://www.spinics.net/lists/netdev/msg646202.html
[9] https://github.com/microchip-ung/mrp/tree/patch-v9

-v4:
  - fix comments in br_mrp.c
  - use skb_header_pointer to get br_mrp_tlv_hdr
  - fix line over 80 characters

-v3:
  - fix unused variables

-v2:
  - drop patch 4
  - add port flag BR_MRP_LOST_CONT;
  - another fix for bisectability

-v1:
  - fix bisectability issues
  - in case of errors use extack

-RFC v5:
  - use nla_parse_nested
  - rework the usage of the rcu in br_mrp
  - reorder patches
  - few other small issues raised by Nikolay

-RFC v4:
  - extend existing netlink interface to add mrp support
  - use rcu locks

-RFC v3:
  - move MRP state machine in userspace
  - create generic netlink interface for configuring the HW using switchdev API

-RFC v2:
  - extend switchdev API to offload to HW
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 7d311801 419dba8a
......@@ -47,6 +47,8 @@ struct br_ip_list {
#define BR_BCAST_FLOOD BIT(14)
#define BR_NEIGH_SUPPRESS BIT(15)
#define BR_ISOLATED BIT(16)
#define BR_MRP_AWARE BIT(17)
#define BR_MRP_LOST_CONT BIT(18)
#define BR_DEFAULT_AGEING_TIME (300 * HZ)
......
......@@ -40,6 +40,10 @@ enum switchdev_attr_id {
SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING,
SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED,
SWITCHDEV_ATTR_ID_BRIDGE_MROUTER,
#if IS_ENABLED(CONFIG_BRIDGE_MRP)
SWITCHDEV_ATTR_ID_MRP_PORT_STATE,
SWITCHDEV_ATTR_ID_MRP_PORT_ROLE,
#endif
};
struct switchdev_attr {
......@@ -55,6 +59,11 @@ struct switchdev_attr {
clock_t ageing_time; /* BRIDGE_AGEING_TIME */
bool vlan_filtering; /* BRIDGE_VLAN_FILTERING */
bool mc_disabled; /* MC_DISABLED */
#if IS_ENABLED(CONFIG_BRIDGE_MRP)
u8 mrp_port_state; /* MRP_PORT_STATE */
u8 mrp_port_role; /* MRP_PORT_ROLE */
u8 mrp_ring_state; /* MRP_RING_STATE */
#endif
} u;
};
......@@ -63,6 +72,12 @@ enum switchdev_obj_id {
SWITCHDEV_OBJ_ID_PORT_VLAN,
SWITCHDEV_OBJ_ID_PORT_MDB,
SWITCHDEV_OBJ_ID_HOST_MDB,
#if IS_ENABLED(CONFIG_BRIDGE_MRP)
SWITCHDEV_OBJ_ID_MRP,
SWITCHDEV_OBJ_ID_RING_TEST_MRP,
SWITCHDEV_OBJ_ID_RING_ROLE_MRP,
SWITCHDEV_OBJ_ID_RING_STATE_MRP,
#endif
};
struct switchdev_obj {
......@@ -94,6 +109,53 @@ struct switchdev_obj_port_mdb {
#define SWITCHDEV_OBJ_PORT_MDB(OBJ) \
container_of((OBJ), struct switchdev_obj_port_mdb, obj)
#if IS_ENABLED(CONFIG_BRIDGE_MRP)
/* SWITCHDEV_OBJ_ID_MRP */
struct switchdev_obj_mrp {
struct switchdev_obj obj;
struct net_device *p_port;
struct net_device *s_port;
u32 ring_id;
};
#define SWITCHDEV_OBJ_MRP(OBJ) \
container_of((OBJ), struct switchdev_obj_mrp, obj)
/* SWITCHDEV_OBJ_ID_RING_TEST_MRP */
struct switchdev_obj_ring_test_mrp {
struct switchdev_obj obj;
/* The value is in us and a value of 0 represents to stop */
u32 interval;
u8 max_miss;
u32 ring_id;
u32 period;
};
#define SWITCHDEV_OBJ_RING_TEST_MRP(OBJ) \
container_of((OBJ), struct switchdev_obj_ring_test_mrp, obj)
/* SWICHDEV_OBJ_ID_RING_ROLE_MRP */
struct switchdev_obj_ring_role_mrp {
struct switchdev_obj obj;
u8 ring_role;
u32 ring_id;
};
#define SWITCHDEV_OBJ_RING_ROLE_MRP(OBJ) \
container_of((OBJ), struct switchdev_obj_ring_role_mrp, obj)
struct switchdev_obj_ring_state_mrp {
struct switchdev_obj obj;
u8 ring_state;
u32 ring_id;
};
#define SWITCHDEV_OBJ_RING_STATE_MRP(OBJ) \
container_of((OBJ), struct switchdev_obj_ring_state_mrp, obj)
#endif
typedef int switchdev_obj_dump_cb_t(struct switchdev_obj *obj);
enum switchdev_notifier_type {
......
......@@ -120,6 +120,7 @@ enum {
IFLA_BRIDGE_MODE,
IFLA_BRIDGE_VLAN_INFO,
IFLA_BRIDGE_VLAN_TUNNEL_INFO,
IFLA_BRIDGE_MRP,
__IFLA_BRIDGE_MAX,
};
#define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
......@@ -157,6 +158,47 @@ struct bridge_vlan_xstats {
__u32 pad2;
};
enum {
IFLA_BRIDGE_MRP_UNSPEC,
IFLA_BRIDGE_MRP_INSTANCE,
IFLA_BRIDGE_MRP_PORT_STATE,
IFLA_BRIDGE_MRP_PORT_ROLE,
IFLA_BRIDGE_MRP_RING_STATE,
IFLA_BRIDGE_MRP_RING_ROLE,
IFLA_BRIDGE_MRP_START_TEST,
__IFLA_BRIDGE_MRP_MAX,
};
struct br_mrp_instance {
__u32 ring_id;
__u32 p_ifindex;
__u32 s_ifindex;
};
struct br_mrp_port_role {
__u32 ring_id;
__u32 role;
};
struct br_mrp_ring_state {
__u32 ring_id;
__u32 ring_state;
};
struct br_mrp_ring_role {
__u32 ring_id;
__u32 ring_role;
};
struct br_mrp_start_test {
__u32 ring_id;
__u32 interval;
__u32 max_miss;
__u32 period;
};
#define IFLA_BRIDGE_MRP_MAX (__IFLA_BRIDGE_MRP_MAX - 1)
struct bridge_stp_xstats {
__u64 transition_blk;
__u64 transition_fwd;
......
......@@ -92,6 +92,7 @@
#define ETH_P_PREAUTH 0x88C7 /* 802.11 Preauthentication */
#define ETH_P_TIPC 0x88CA /* TIPC */
#define ETH_P_LLDP 0x88CC /* Link Layer Discovery Protocol */
#define ETH_P_MRP 0x88E3 /* Media Redundancy Protocol */
#define ETH_P_MACSEC 0x88E5 /* 802.1ae MACsec */
#define ETH_P_8021AH 0x88E7 /* 802.1ah Backbone Service Tag */
#define ETH_P_MVRP 0x88F5 /* 802.1Q MVRP */
......
......@@ -343,6 +343,7 @@ enum {
IFLA_BRPORT_NEIGH_SUPPRESS,
IFLA_BRPORT_ISOLATED,
IFLA_BRPORT_BACKUP_PORT,
IFLA_BRPORT_MRP_RING_OPEN,
__IFLA_BRPORT_MAX
};
#define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
......
/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
#ifndef _UAPI_LINUX_MRP_BRIDGE_H_
#define _UAPI_LINUX_MRP_BRIDGE_H_
#include <linux/types.h>
#include <linux/if_ether.h>
#define MRP_MAX_FRAME_LENGTH 200
#define MRP_DEFAULT_PRIO 0x8000
#define MRP_DOMAIN_UUID_LENGTH 16
#define MRP_VERSION 1
#define MRP_FRAME_PRIO 7
enum br_mrp_ring_role_type {
BR_MRP_RING_ROLE_DISABLED,
BR_MRP_RING_ROLE_MRC,
BR_MRP_RING_ROLE_MRM,
};
enum br_mrp_ring_state_type {
BR_MRP_RING_STATE_OPEN,
BR_MRP_RING_STATE_CLOSED,
};
enum br_mrp_port_state_type {
BR_MRP_PORT_STATE_DISABLED,
BR_MRP_PORT_STATE_BLOCKED,
BR_MRP_PORT_STATE_FORWARDING,
BR_MRP_PORT_STATE_NOT_CONNECTED,
};
enum br_mrp_port_role_type {
BR_MRP_PORT_ROLE_PRIMARY,
BR_MRP_PORT_ROLE_SECONDARY,
BR_MRP_PORT_ROLE_NONE,
};
enum br_mrp_tlv_header_type {
BR_MRP_TLV_HEADER_END = 0x0,
BR_MRP_TLV_HEADER_COMMON = 0x1,
BR_MRP_TLV_HEADER_RING_TEST = 0x2,
BR_MRP_TLV_HEADER_RING_TOPO = 0x3,
BR_MRP_TLV_HEADER_RING_LINK_DOWN = 0x4,
BR_MRP_TLV_HEADER_RING_LINK_UP = 0x5,
};
struct br_mrp_tlv_hdr {
__u8 type;
__u8 length;
};
struct br_mrp_end_hdr {
struct br_mrp_tlv_hdr hdr;
};
struct br_mrp_common_hdr {
__u16 seq_id;
__u8 domain[MRP_DOMAIN_UUID_LENGTH];
};
struct br_mrp_ring_test_hdr {
__u16 prio;
__u8 sa[ETH_ALEN];
__u16 port_role;
__u16 state;
__u16 transitions;
__u32 timestamp;
};
struct br_mrp_ring_topo_hdr {
__u16 prio;
__u8 sa[ETH_ALEN];
__u16 interval;
};
struct br_mrp_ring_link_hdr {
__u8 sa[ETH_ALEN];
__u16 port_role;
__u16 interval;
__u16 blocked;
};
#endif
......@@ -61,3 +61,15 @@ config BRIDGE_VLAN_FILTERING
Say N to exclude this support and reduce the binary size.
If unsure, say Y.
config BRIDGE_MRP
bool "MRP protocol"
depends on BRIDGE
default n
help
If you say Y here, then the Ethernet bridge will be able to run MRP
protocol to detect loops
Say N to exclude this support and reduce the binary size.
If unsure, say N.
......@@ -25,3 +25,5 @@ bridge-$(CONFIG_BRIDGE_VLAN_FILTERING) += br_vlan.o br_vlan_tunnel.o br_vlan_opt
bridge-$(CONFIG_NET_SWITCHDEV) += br_switchdev.o
obj-$(CONFIG_NETFILTER) += netfilter/
bridge-$(CONFIG_BRIDGE_MRP) += br_mrp_switchdev.o br_mrp.o br_mrp_netlink.o
......@@ -463,6 +463,9 @@ void br_dev_setup(struct net_device *dev)
spin_lock_init(&br->lock);
INIT_LIST_HEAD(&br->port_list);
INIT_HLIST_HEAD(&br->fdb_list);
#if IS_ENABLED(CONFIG_BRIDGE_MRP)
INIT_LIST_HEAD(&br->mrp_list);
#endif
spin_lock_init(&br->hash_lock);
br->bridge_id.prio[0] = 0x80;
......
......@@ -333,6 +333,8 @@ static void del_nbp(struct net_bridge_port *p)
br_stp_disable_port(p);
spin_unlock_bh(&br->lock);
br_mrp_port_del(br, p);
br_ifinfo_notify(RTM_DELLINK, NULL, p);
list_del_rcu(&p->list);
......
......@@ -342,6 +342,9 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb)
}
}
if (unlikely(br_mrp_process(p, skb)))
return RX_HANDLER_PASS;
forward:
switch (p->state) {
case BR_STATE_FORWARDING:
......
......@@ -242,8 +242,7 @@ static int old_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
if (!ns_capable(dev_net(dev)->user_ns, CAP_NET_ADMIN))
return -EPERM;
br_stp_set_enabled(br, args[1]);
ret = 0;
ret = br_stp_set_enabled(br, args[1], NULL);
break;
case BRCTL_SET_BRIDGE_PRIORITY:
......
This diff is collapsed.
// SPDX-License-Identifier: GPL-2.0-or-later
#include <net/genetlink.h>
#include <uapi/linux/mrp_bridge.h>
#include "br_private.h"
#include "br_private_mrp.h"
static const struct nla_policy br_mrp_policy[IFLA_BRIDGE_MRP_MAX + 1] = {
[IFLA_BRIDGE_MRP_UNSPEC] = { .type = NLA_REJECT },
[IFLA_BRIDGE_MRP_INSTANCE] = { .type = NLA_EXACT_LEN,
.len = sizeof(struct br_mrp_instance)},
[IFLA_BRIDGE_MRP_PORT_STATE] = { .type = NLA_U32 },
[IFLA_BRIDGE_MRP_PORT_ROLE] = { .type = NLA_EXACT_LEN,
.len = sizeof(struct br_mrp_port_role)},
[IFLA_BRIDGE_MRP_RING_STATE] = { .type = NLA_EXACT_LEN,
.len = sizeof(struct br_mrp_ring_state)},
[IFLA_BRIDGE_MRP_RING_ROLE] = { .type = NLA_EXACT_LEN,
.len = sizeof(struct br_mrp_ring_role)},
[IFLA_BRIDGE_MRP_START_TEST] = { .type = NLA_EXACT_LEN,
.len = sizeof(struct br_mrp_start_test)},
};
int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
struct nlattr *attr, int cmd, struct netlink_ext_ack *extack)
{
struct nlattr *tb[IFLA_BRIDGE_MRP_MAX + 1];
int err;
if (br->stp_enabled != BR_NO_STP) {
NL_SET_ERR_MSG_MOD(extack, "MRP can't be enabled if STP is already enabled\n");
return -EINVAL;
}
err = nla_parse_nested(tb, IFLA_BRIDGE_MRP_MAX, attr,
br_mrp_policy, extack);
if (err)
return err;
if (tb[IFLA_BRIDGE_MRP_INSTANCE]) {
struct br_mrp_instance *instance =
nla_data(tb[IFLA_BRIDGE_MRP_INSTANCE]);
if (cmd == RTM_SETLINK)
err = br_mrp_add(br, instance);
else
err = br_mrp_del(br, instance);
if (err)
return err;
}
if (tb[IFLA_BRIDGE_MRP_PORT_STATE]) {
enum br_mrp_port_state_type state =
nla_get_u32(tb[IFLA_BRIDGE_MRP_PORT_STATE]);
err = br_mrp_set_port_state(p, state);
if (err)
return err;
}
if (tb[IFLA_BRIDGE_MRP_PORT_ROLE]) {
struct br_mrp_port_role *role =
nla_data(tb[IFLA_BRIDGE_MRP_PORT_ROLE]);
err = br_mrp_set_port_role(p, role);
if (err)
return err;
}
if (tb[IFLA_BRIDGE_MRP_RING_STATE]) {
struct br_mrp_ring_state *state =
nla_data(tb[IFLA_BRIDGE_MRP_RING_STATE]);
err = br_mrp_set_ring_state(br, state);
if (err)
return err;
}
if (tb[IFLA_BRIDGE_MRP_RING_ROLE]) {
struct br_mrp_ring_role *role =
nla_data(tb[IFLA_BRIDGE_MRP_RING_ROLE]);
err = br_mrp_set_ring_role(br, role);
if (err)
return err;
}
if (tb[IFLA_BRIDGE_MRP_START_TEST]) {
struct br_mrp_start_test *test =
nla_data(tb[IFLA_BRIDGE_MRP_START_TEST]);
err = br_mrp_start_test(br, test);
if (err)
return err;
}
return 0;
}
int br_mrp_port_open(struct net_device *dev, u8 loc)
{
struct net_bridge_port *p;
int err = 0;
p = br_port_get_rcu(dev);
if (!p) {
err = -EINVAL;
goto out;
}
if (loc)
p->flags |= BR_MRP_LOST_CONT;
else
p->flags &= ~BR_MRP_LOST_CONT;
br_ifinfo_notify(RTM_NEWLINK, NULL, p);
out:
return err;
}
// SPDX-License-Identifier: GPL-2.0-or-later
#include <net/switchdev.h>
#include "br_private_mrp.h"
int br_mrp_switchdev_add(struct net_bridge *br, struct br_mrp *mrp)
{
struct switchdev_obj_mrp mrp_obj = {
.obj.orig_dev = br->dev,
.obj.id = SWITCHDEV_OBJ_ID_MRP,
.p_port = rtnl_dereference(mrp->p_port)->dev,
.s_port = rtnl_dereference(mrp->s_port)->dev,
.ring_id = mrp->ring_id,
};
int err;
err = switchdev_port_obj_add(br->dev, &mrp_obj.obj, NULL);
if (err && err != -EOPNOTSUPP)
return err;
return 0;
}
int br_mrp_switchdev_del(struct net_bridge *br, struct br_mrp *mrp)
{
struct switchdev_obj_mrp mrp_obj = {
.obj.orig_dev = br->dev,
.obj.id = SWITCHDEV_OBJ_ID_MRP,
.p_port = NULL,
.s_port = NULL,
.ring_id = mrp->ring_id,
};
int err;
err = switchdev_port_obj_del(br->dev, &mrp_obj.obj);
if (err && err != -EOPNOTSUPP)
return err;
return 0;
}
int br_mrp_switchdev_set_ring_role(struct net_bridge *br,
struct br_mrp *mrp,
enum br_mrp_ring_role_type role)
{
struct switchdev_obj_ring_role_mrp mrp_role = {
.obj.orig_dev = br->dev,
.obj.id = SWITCHDEV_OBJ_ID_RING_ROLE_MRP,
.ring_role = role,
.ring_id = mrp->ring_id,
};
int err;
if (role == BR_MRP_RING_ROLE_DISABLED)
err = switchdev_port_obj_del(br->dev, &mrp_role.obj);
else
err = switchdev_port_obj_add(br->dev, &mrp_role.obj, NULL);
return err;
}
int br_mrp_switchdev_send_ring_test(struct net_bridge *br,
struct br_mrp *mrp, u32 interval,
u8 max_miss, u32 period)
{
struct switchdev_obj_ring_test_mrp test = {
.obj.orig_dev = br->dev,
.obj.id = SWITCHDEV_OBJ_ID_RING_TEST_MRP,
.interval = interval,
.max_miss = max_miss,
.ring_id = mrp->ring_id,
.period = period,
};
int err;
if (interval == 0)
err = switchdev_port_obj_del(br->dev, &test.obj);
else
err = switchdev_port_obj_add(br->dev, &test.obj, NULL);
return err;
}
int br_mrp_switchdev_set_ring_state(struct net_bridge *br,
struct br_mrp *mrp,
enum br_mrp_ring_state_type state)
{
struct switchdev_obj_ring_state_mrp mrp_state = {
.obj.orig_dev = br->dev,
.obj.id = SWITCHDEV_OBJ_ID_RING_STATE_MRP,
.ring_state = state,
.ring_id = mrp->ring_id,
};
int err;
err = switchdev_port_obj_add(br->dev, &mrp_state.obj, NULL);
if (err && err != -EOPNOTSUPP)
return err;
return 0;
}
int br_mrp_port_switchdev_set_state(struct net_bridge_port *p,
enum br_mrp_port_state_type state)
{
struct switchdev_attr attr = {
.orig_dev = p->dev,
.id = SWITCHDEV_ATTR_ID_MRP_PORT_STATE,
.u.mrp_port_state = state,
};
int err;
err = switchdev_port_attr_set(p->dev, &attr);
if (err && err != -EOPNOTSUPP)
br_warn(p->br, "error setting offload MRP state on port %u(%s)\n",
(unsigned int)p->port_no, p->dev->name);
return err;
}
int br_mrp_port_switchdev_set_role(struct net_bridge_port *p,
enum br_mrp_port_role_type role)
{
struct switchdev_attr attr = {
.orig_dev = p->dev,
.id = SWITCHDEV_ATTR_ID_MRP_PORT_ROLE,
.u.mrp_port_role = role,
};
int err;
err = switchdev_port_attr_set(p->dev, &attr);
if (err && err != -EOPNOTSUPP)
return err;
return 0;
}
......@@ -151,6 +151,7 @@ static inline size_t br_port_info_size(void)
+ nla_total_size(sizeof(u8)) /* IFLA_BRPORT_MULTICAST_ROUTER */
#endif
+ nla_total_size(sizeof(u16)) /* IFLA_BRPORT_GROUP_FWD_MASK */
+ nla_total_size(sizeof(u8)) /* IFLA_BRPORT_MRP_RING_OPEN */
+ 0;
}
......@@ -213,6 +214,8 @@ static int br_port_fill_attrs(struct sk_buff *skb,
nla_put_u16(skb, IFLA_BRPORT_GROUP_FWD_MASK, p->group_fwd_mask) ||
nla_put_u8(skb, IFLA_BRPORT_NEIGH_SUPPRESS,
!!(p->flags & BR_NEIGH_SUPPRESS)) ||
nla_put_u8(skb, IFLA_BRPORT_MRP_RING_OPEN, !!(p->flags &
BR_MRP_LOST_CONT)) ||
nla_put_u8(skb, IFLA_BRPORT_ISOLATED, !!(p->flags & BR_ISOLATED)))
return -EMSGSIZE;
......@@ -669,6 +672,11 @@ static int br_afspec(struct net_bridge *br,
if (err)
return err;
break;
case IFLA_BRIDGE_MRP:
err = br_mrp_parse(br, p, attr, cmd, extack);
if (err)
return err;
break;
}
}
......@@ -1101,7 +1109,9 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
if (data[IFLA_BR_STP_STATE]) {
u32 stp_enabled = nla_get_u32(data[IFLA_BR_STP_STATE]);
br_stp_set_enabled(br, stp_enabled);
err = br_stp_set_enabled(br, stp_enabled, extack);
if (err)
return err;
}
if (data[IFLA_BR_PRIORITY]) {
......
......@@ -428,6 +428,10 @@ struct net_bridge {
int offload_fwd_mark;
#endif
struct hlist_head fdb_list;
#if IS_ENABLED(CONFIG_BRIDGE_MRP)
struct list_head __rcu mrp_list;
#endif
};
struct br_input_skb_cb {
......@@ -1279,7 +1283,8 @@ int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time);
/* br_stp_if.c */
void br_stp_enable_bridge(struct net_bridge *br);
void br_stp_disable_bridge(struct net_bridge *br);
void br_stp_set_enabled(struct net_bridge *br, unsigned long val);
int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
struct netlink_ext_ack *extack);
void br_stp_enable_port(struct net_bridge_port *p);
void br_stp_disable_port(struct net_bridge_port *p);
bool br_stp_recalculate_bridge_id(struct net_bridge *br);
......@@ -1304,6 +1309,37 @@ unsigned long br_timer_value(const struct timer_list *timer);
extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr);
#endif
/* br_mrp.c */
#if IS_ENABLED(CONFIG_BRIDGE_MRP)
int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
struct nlattr *attr, int cmd, struct netlink_ext_ack *extack);
int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb);
bool br_mrp_enabled(struct net_bridge *br);
void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p);
#else
static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
struct nlattr *attr, int cmd,
struct netlink_ext_ack *extack)
{
return -EOPNOTSUPP;
}
static inline int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb)
{
return 0;
}
static inline bool br_mrp_enabled(struct net_bridge *br)
{
return 0;
}
static inline void br_mrp_port_del(struct net_bridge *br,
struct net_bridge_port *p)
{
}
#endif
/* br_netlink.c */
extern struct rtnl_link_ops br_link_ops;
int br_netlink_init(void);
......
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef _BR_PRIVATE_MRP_H_
#define _BR_PRIVATE_MRP_H_
#include "br_private.h"
#include <uapi/linux/mrp_bridge.h>
struct br_mrp {
/* list of mrp instances */
struct list_head __rcu list;
struct net_bridge_port __rcu *p_port;
struct net_bridge_port __rcu *s_port;
u32 ring_id;
enum br_mrp_ring_role_type ring_role;
u8 ring_role_offloaded;
enum br_mrp_ring_state_type ring_state;
u32 ring_transitions;
struct delayed_work test_work;
u32 test_interval;
unsigned long test_end;
u32 test_count_miss;
u32 test_max_miss;
u32 seq_id;
struct rcu_head rcu;
};
/* br_mrp.c */
int br_mrp_add(struct net_bridge *br, struct br_mrp_instance *instance);
int br_mrp_del(struct net_bridge *br, struct br_mrp_instance *instance);
int br_mrp_set_port_state(struct net_bridge_port *p,
enum br_mrp_port_state_type state);
int br_mrp_set_port_role(struct net_bridge_port *p,
struct br_mrp_port_role *role);
int br_mrp_set_ring_state(struct net_bridge *br,
struct br_mrp_ring_state *state);
int br_mrp_set_ring_role(struct net_bridge *br, struct br_mrp_ring_role *role);
int br_mrp_start_test(struct net_bridge *br, struct br_mrp_start_test *test);
/* br_mrp_switchdev.c */
int br_mrp_switchdev_add(struct net_bridge *br, struct br_mrp *mrp);
int br_mrp_switchdev_del(struct net_bridge *br, struct br_mrp *mrp);
int br_mrp_switchdev_set_ring_role(struct net_bridge *br, struct br_mrp *mrp,
enum br_mrp_ring_role_type role);
int br_mrp_switchdev_set_ring_state(struct net_bridge *br, struct br_mrp *mrp,
enum br_mrp_ring_state_type state);
int br_mrp_switchdev_send_ring_test(struct net_bridge *br, struct br_mrp *mrp,
u32 interval, u8 max_miss, u32 period);
int br_mrp_port_switchdev_set_state(struct net_bridge_port *p,
enum br_mrp_port_state_type state);
int br_mrp_port_switchdev_set_role(struct net_bridge_port *p,
enum br_mrp_port_role_type role);
/* br_mrp_netlink.c */
int br_mrp_port_open(struct net_device *dev, u8 loc);
#endif /* _BR_PRIVATE_MRP_H */
......@@ -36,6 +36,12 @@ void br_set_state(struct net_bridge_port *p, unsigned int state)
};
int err;
/* Don't change the state of the ports if they are driven by a different
* protocol.
*/
if (p->flags & BR_MRP_AWARE)
return;
p->state = state;
err = switchdev_port_attr_set(p->dev, &attr);
if (err && err != -EOPNOTSUPP)
......
......@@ -196,10 +196,17 @@ static void br_stp_stop(struct net_bridge *br)
br->stp_enabled = BR_NO_STP;
}
void br_stp_set_enabled(struct net_bridge *br, unsigned long val)
int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
struct netlink_ext_ack *extack)
{
ASSERT_RTNL();
if (br_mrp_enabled(br)) {
NL_SET_ERR_MSG_MOD(extack,
"STP can't be enabled if MRP is already enabled\n");
return -EINVAL;
}
if (val) {
if (br->stp_enabled == BR_NO_STP)
br_stp_start(br);
......@@ -207,6 +214,8 @@ void br_stp_set_enabled(struct net_bridge *br, unsigned long val)
if (br->stp_enabled != BR_NO_STP)
br_stp_stop(br);
}
return 0;
}
/* called under bridge lock */
......
......@@ -126,9 +126,7 @@ static ssize_t stp_state_show(struct device *d,
static int set_stp_state(struct net_bridge *br, unsigned long val)
{
br_stp_set_enabled(br, val);
return 0;
return br_stp_set_enabled(br, val, NULL);
}
static ssize_t stp_state_store(struct device *d,
......
......@@ -343,6 +343,7 @@ enum {
IFLA_BRPORT_NEIGH_SUPPRESS,
IFLA_BRPORT_ISOLATED,
IFLA_BRPORT_BACKUP_PORT,
IFLA_BRPORT_MRP_RING_OPEN,
__IFLA_BRPORT_MAX
};
#define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment