Return-Path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cumulusnetworks.com; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=sGIJHh/puT6NxbufoFpsfxcnGoUe2JqTWxhpfJYWZlA=; b=VdSpN6leoifwtGtjB3IGgSy/AZ+Mo5F4Bd+mqGoCnHE/dKoMc6b+xU6PV3Mrcfm1Xl 7RX2TybRi+nrKN4IaMdvg6eux8iYv58gDxh6PjJ8L9yTfvtu2Y72us1ZJsnnbO8pSgQW v5OjFrZkaBe1/6g/wDNDdhIKnertxEyMqs2ss= References: <20200420150947.30974-1-horatiu.vultur@microchip.com> <20200420150947.30974-11-horatiu.vultur@microchip.com> From: Nikolay Aleksandrov Message-ID: <4d989958-0c2b-69de-2015-1808e2ce94db@cumulusnetworks.com> Date: Tue, 21 Apr 2020 11:47:15 +0300 MIME-Version: 1.0 In-Reply-To: <20200420150947.30974-11-horatiu.vultur@microchip.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Bridge] [PATCH net-next 10/13] bridge: mrp: Implement netlink interface to configure MRP List-Id: Linux Ethernet Bridging List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Horatiu Vultur , davem@davemloft.net, jiri@resnulli.us, ivecera@redhat.com, kuba@kernel.org, roopa@cumulusnetworks.com, olteanv@gmail.com, andrew@lunn.ch, UNGLinuxDriver@microchip.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bridge@lists.linux-foundation.org On 20/04/2020 18:09, Horatiu Vultur wrote: > Implement netlink interface to configure MRP. The implementation > will do sanity checks over the attributes and then eventually call the MRP > interface. > > Signed-off-by: Horatiu Vultur > --- > net/bridge/br_mrp_netlink.c | 117 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 117 insertions(+) > create mode 100644 net/bridge/br_mrp_netlink.c > > diff --git a/net/bridge/br_mrp_netlink.c b/net/bridge/br_mrp_netlink.c > new file mode 100644 > index 000000000000..0ff42e7c7f57 > --- /dev/null > +++ b/net/bridge/br_mrp_netlink.c > @@ -0,0 +1,117 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > + > +#include > + > +#include > +#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) > +{ Note that "p" can be NULL here if br_afspec() was called for the bridge device. Some of the functions below dereference it without any checks and will deref a null ptr. > + 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, > + NULL, 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; > + } > + > + p->loc = loc; > + br_ifinfo_notify(RTM_NEWLINK, NULL, p); > + > +out: > + return err; > +} > +EXPORT_SYMBOL(br_mrp_port_open); >