From: Petr Machata <petrm@nvidia.com>
To: Daniel Machon <daniel.machon@microchip.com>
Cc: <netdev@vger.kernel.org>, <Allan.Nielsen@microchip.com>,
<UNGLinuxDriver@microchip.com>, <maxime.chevallier@bootlin.com>,
<vladimir.oltean@nxp.com>, <petrm@nvidia.com>, <kuba@kernel.org>,
<vinicius.gomes@intel.com>, <thomas.petazzoni@bootlin.com>
Subject: Re: [RFC PATCH v2 net-next 2/2] net: dcb: add new apptrust attribute
Date: Mon, 19 Sep 2022 09:30:21 +0200 [thread overview]
Message-ID: <87mtavyf3b.fsf@nvidia.com> (raw)
In-Reply-To: <20220915095757.2861822-3-daniel.machon@microchip.com>
Daniel Machon <daniel.machon@microchip.com> writes:
> Add new apptrust extension attributes to the 8021Qaz APP managed
> object.
>
> Two new attributes, DCB_ATTR_DCB_APP_TRUST_TABLE and
> DCB_ATTR_DCB_APP_TRUST, has been added. Trusted selectors are passed in
> the nested attribute (TRUST_TABLE), in order of precedence.
>
> The new attributes are meant to allow drivers, whose hw supports the
> notion of trust, to be able to set whether a particular app selector is
> to be trusted - and also the order of precedence of selectors.
>
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
> ---
> include/net/dcbnl.h | 4 +++
> include/uapi/linux/dcbnl.h | 4 +++
> net/dcb/dcbnl.c | 64 ++++++++++++++++++++++++++++++++++++--
> 3 files changed, 69 insertions(+), 3 deletions(-)
>
> diff --git a/include/net/dcbnl.h b/include/net/dcbnl.h
> index 2b2d86fb3131..8841ab6c2de7 100644
> --- a/include/net/dcbnl.h
> +++ b/include/net/dcbnl.h
> @@ -109,6 +109,10 @@ struct dcbnl_rtnl_ops {
> /* buffer settings */
> int (*dcbnl_getbuffer)(struct net_device *, struct dcbnl_buffer *);
> int (*dcbnl_setbuffer)(struct net_device *, struct dcbnl_buffer *);
> +
> + /* apptrust */
> + int (*dcbnl_setapptrust)(struct net_device *, u8 *, int);
> + int (*dcbnl_getapptrust)(struct net_device *, u8 *, int *);
> };
>
> #endif /* __NET_DCBNL_H__ */
> diff --git a/include/uapi/linux/dcbnl.h b/include/uapi/linux/dcbnl.h
> index 8eab16e5bc13..ede72aefd88f 100644
> --- a/include/uapi/linux/dcbnl.h
> +++ b/include/uapi/linux/dcbnl.h
> @@ -248,6 +248,8 @@ struct dcb_app {
> __u16 protocol;
> };
>
> +#define IEEE_8021QAZ_APP_SEL_MAX 255
> +
> /**
> * struct dcb_peer_app_info - APP feature information sent by the peer
> *
> @@ -419,6 +421,8 @@ enum ieee_attrs {
> DCB_ATTR_IEEE_QCN,
> DCB_ATTR_IEEE_QCN_STATS,
> DCB_ATTR_DCB_BUFFER,
> + DCB_ATTR_DCB_APP_TRUST_TABLE,
> + DCB_ATTR_DCB_APP_TRUST,
> __DCB_ATTR_IEEE_MAX
> };
I find it odd that APP_TRUST is at the same level as APP_TRUST_TABLE. I
think it would be better to have a separate enum ala what APP_TABLE has
with enum ieee_attr_app.
> #define DCB_ATTR_IEEE_MAX (__DCB_ATTR_IEEE_MAX - 1)
> diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
> index dc4fb699b56c..6f5d2b295d09 100644
> --- a/net/dcb/dcbnl.c
> +++ b/net/dcb/dcbnl.c
> @@ -166,6 +166,7 @@ static const struct nla_policy dcbnl_ieee_policy[DCB_ATTR_IEEE_MAX + 1] = {
> [DCB_ATTR_IEEE_QCN] = {.len = sizeof(struct ieee_qcn)},
> [DCB_ATTR_IEEE_QCN_STATS] = {.len = sizeof(struct ieee_qcn_stats)},
> [DCB_ATTR_DCB_BUFFER] = {.len = sizeof(struct dcbnl_buffer)},
> + [DCB_ATTR_DCB_APP_TRUST_TABLE] = {.type = NLA_NESTED},
> };
>
> /* DCB number of traffic classes nested attributes. */
> @@ -1030,11 +1031,11 @@ static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
> /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb GET commands. */
> static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
> {
> - struct nlattr *ieee, *app;
> + struct nlattr *ieee, *app, *apptrust;
> struct dcb_app_type *itr;
> const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
> int dcbx;
> - int err;
> + int err, i;
Move "err, i" up before dcbx so that it observes the reverse xmass tree
principle, please.
>
> if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
> return -EMSGSIZE;
> @@ -1133,6 +1134,24 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
> spin_unlock_bh(&dcb_lock);
> nla_nest_end(skb, app);
>
> + if (ops->dcbnl_getapptrust) {
> + u8 selectors[IEEE_8021QAZ_APP_SEL_MAX + 1] = {0};
> + int nselectors;
> +
> + apptrust = nla_nest_start_noflag(skb,
> + DCB_ATTR_DCB_APP_TRUST_TABLE);
> + if (!app)
> + return -EMSGSIZE;
I agree with Vladimir that this should not be _noflag.
> +
> + err = ops->dcbnl_getapptrust(netdev, selectors, &nselectors);
> + if (err)
> + return -EMSGSIZE;
> +
> + for (i = 0; i < nselectors; i++)
> + nla_put_u8(skb, DCB_ATTR_DCB_APP_TRUST, selectors[i]);
> + nla_nest_end(skb, apptrust);
> + }
> +
> /* get peer info if available */
> if (ops->ieee_peer_getets) {
> struct ieee_ets ets;
> @@ -1427,7 +1446,7 @@ static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh,
> const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
> struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
> int prio;
> - int err;
> + int err, i;
RXT this as well, please.
>
> if (!ops)
> return -EOPNOTSUPP;
> @@ -1513,6 +1532,45 @@ static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh,
> }
> }
>
> + if (ieee[DCB_ATTR_DCB_APP_TRUST_TABLE]) {
> + u8 selectors[IEEE_8021QAZ_APP_SEL_MAX + 1] = {0};
> + struct nlattr *attr;
> + int nselectors = 0;
> + u8 selector;
> +
> + int rem;
> +
> + if (!ops->dcbnl_setapptrust) {
> + err = -EOPNOTSUPP;
> + goto err;
> + }
> +
> + nla_for_each_nested(attr, ieee[DCB_ATTR_DCB_APP_TRUST_TABLE],
> + rem) {
> + if (nla_type(attr) != DCB_ATTR_DCB_APP_TRUST ||
> + nla_len(attr) != 1 ||
> + nselectors >= sizeof(selectors)) {
> + err = -EINVAL;
> + goto err;
> + }
I'm assuming you tested this code, I just wrote it into the email
client, so all guarantees are off :)
> +
> + selector = nla_get_u8(attr);
> + /* Duplicate selector ? */
> + for (i = 0; i < nselectors; i++) {
> + if (selectors[i] == selector) {
> + err = -EINVAL;
> + goto err;
> + }
> + }
This should validate the selector values as well IMHO. Maybe something
like this?
switch (selector) {
...
case IEEE_8021QAZ_APP_SEL_DGRAM:
case IEEE_8021QAZ_APP_SEL_ANY:
case IEEE_8021QAZ_APP_SEL_DSCP:
case IEEE_8021QAZ_APP_SEL_PCP:
break;
default:
err = -EINVAL;
goto err;
}
> +
> + selectors[nselectors++] = selector;
> + }
> +
> + err = ops->dcbnl_setapptrust(netdev, selectors, nselectors);
> + if (err)
> + goto err;
> + }
> +
> err:
> err = nla_put_u8(skb, DCB_ATTR_IEEE, err);
> dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, seq, 0);
next prev parent reply other threads:[~2022-09-19 7:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-15 9:57 [RFC PATCH v2 net-next 0/2] Add PCP selector and new APPTRUST attribute Daniel Machon
2022-09-15 9:57 ` [RFC PATCH v2 net-next 1/2] net: dcb: add new pcp selector to app object Daniel Machon
2022-09-19 9:45 ` Petr Machata
2022-09-28 13:52 ` Daniel.Machon
2022-09-28 15:50 ` Petr Machata
2022-09-15 9:57 ` [RFC PATCH v2 net-next 2/2] net: dcb: add new apptrust attribute Daniel Machon
2022-09-15 9:51 ` Vladimir Oltean
2022-09-19 7:30 ` Petr Machata [this message]
2022-09-19 7:54 ` [RFC PATCH v2 net-next 0/2] Add PCP selector and new APPTRUST attribute Petr Machata
2022-09-19 8:13 ` Daniel.Machon
2022-09-19 15:11 ` Petr Machata
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mtavyf3b.fsf@nvidia.com \
--to=petrm@nvidia.com \
--cc=Allan.Nielsen@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=daniel.machon@microchip.com \
--cc=kuba@kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=vinicius.gomes@intel.com \
--cc=vladimir.oltean@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.