From: Petr Machata <petrm@nvidia.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: Ido Schimmel <idosch@nvidia.com>, <netdev@vger.kernel.org>,
<davem@davemloft.net>, <petrm@nvidia.com>, <jiri@nvidia.com>,
<razor@blackwall.org>, <roopa@nvidia.com>, <dsahern@gmail.com>,
<andrew@lunn.ch>, <mlxsw@nvidia.com>
Subject: Re: [PATCH net-next 03/14] net: rtnetlink: RTM_GETSTATS: Allow filtering inside nests
Date: Fri, 25 Feb 2022 09:22:19 +0100 [thread overview]
Message-ID: <87a6effiup.fsf@nvidia.com> (raw)
In-Reply-To: <20220224221447.6c7fa95d@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>
Jakub Kicinski <kuba@kernel.org> writes:
> On Thu, 24 Feb 2022 15:33:24 +0200 Ido Schimmel wrote:
>
>> @@ -5344,6 +5368,75 @@ static size_t if_nlmsg_stats_size(const struct net_device *dev,
>> return size;
>> }
>>
>> +static const struct nla_policy
>> +rtnl_stats_get_policy[IFLA_STATS_GETSET_MAX + 1] = {
>> + [IFLA_STATS_GETSET_UNSPEC] = { .strict_start_type = 1 },
>
> I don't think we need the .strict_start_type if the policy is not used
> in parse calls with a _deprecated() suffix, no?
You are right:
if (strict_start_type && type >= strict_start_type)
validate |= NL_VALIDATE_STRICT;
This flag is there to begin with in non-_depreceted calls.
I'll drop the strict_start_type.
>> + [IFLA_STATS_GET_FILTERS] = { .type = NLA_NESTED },
>
> NLA_POLICY_NESTED()? Maybe one day we'll have policy dumping
> for rtnetlink and it'll be useful to have policies linked up.
Nice, I'll add it.
>> +};
>> +
>> +#define RTNL_STATS_OFFLOAD_XSTATS_VALID ((1 << __IFLA_OFFLOAD_XSTATS_MAX) - 1)
>> +
>> +static const struct nla_policy
>> +rtnl_stats_get_policy_filters[IFLA_STATS_MAX + 1] = {
>> + [IFLA_STATS_UNSPEC] = { .strict_start_type = 1 },
>> + [IFLA_STATS_LINK_OFFLOAD_XSTATS] =
>> + NLA_POLICY_BITFIELD32(RTNL_STATS_OFFLOAD_XSTATS_VALID),
>> +};
>> +
>> +static int rtnl_stats_get_parse_filters(struct nlattr *ifla_filters,
>> + struct rtnl_stats_dump_filters *filters,
>> + struct netlink_ext_ack *extack)
>> +{
>> + struct nlattr *tb[IFLA_STATS_MAX + 1];
>> + int err;
>> + int at;
>> +
>> + err = nla_parse_nested(tb, IFLA_STATS_MAX, ifla_filters,
>> + rtnl_stats_get_policy_filters, extack);
>> + if (err < 0)
>> + return err;
>> +
>> + for (at = 1; at <= IFLA_STATS_MAX; at++) {
>> + if (tb[at]) {
>> + if (!(filters->mask[0] & IFLA_STATS_FILTER_BIT(at))) {
>> + NL_SET_ERR_MSG(extack, "Filtered attribute not enabled in filter_mask");
>> + return -EINVAL;
>> + }
>> + filters->mask[at] = nla_get_bitfield32(tb[at]).value;
>
> Why use bitfield if we only use the .value, a u32 would do?
The bitfield validates the mask as well, thereby making sure that
userspace and the kernel are in sync WRT which bits are meaningful.
Specifically in case of filtering, all meaningful bits are always going
to be the set ones. So it should be OK to just handroll the check that
value doesn't include any bits that we don't know about, and we don't
really need the mask.
So I can redo this as u32 if you prefer.
next prev parent reply other threads:[~2022-02-25 8:31 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-24 13:33 [PATCH net-next 00/14] HW counters for soft devices Ido Schimmel
2022-02-24 13:33 ` [PATCH net-next 01/14] net: rtnetlink: Namespace functions related to IFLA_OFFLOAD_XSTATS_* Ido Schimmel
2022-02-24 13:33 ` [PATCH net-next 02/14] net: rtnetlink: Stop assuming that IFLA_OFFLOAD_XSTATS_* are dev-backed Ido Schimmel
2022-02-24 13:33 ` [PATCH net-next 03/14] net: rtnetlink: RTM_GETSTATS: Allow filtering inside nests Ido Schimmel
2022-02-25 6:14 ` Jakub Kicinski
2022-02-25 8:22 ` Petr Machata [this message]
2022-02-25 16:04 ` Jakub Kicinski
2022-02-25 16:57 ` Petr Machata
2022-02-24 13:33 ` [PATCH net-next 04/14] net: rtnetlink: Propagate extack to rtnl_offload_xstats_fill() Ido Schimmel
2022-02-24 13:33 ` [PATCH net-next 05/14] net: rtnetlink: rtnl_fill_statsinfo(): Permit non-EMSGSIZE error returns Ido Schimmel
2022-02-24 13:33 ` [PATCH net-next 06/14] net: dev: Add hardware stats support Ido Schimmel
2022-02-25 6:22 ` Jakub Kicinski
2022-02-25 8:31 ` Petr Machata
2022-02-25 16:12 ` Jakub Kicinski
2022-02-25 17:00 ` Petr Machata
2022-02-25 17:56 ` Jakub Kicinski
2022-02-25 20:01 ` Petr Machata
2022-02-25 22:37 ` Jakub Kicinski
2022-02-24 13:33 ` [PATCH net-next 07/14] net: rtnetlink: Add UAPI for obtaining L3 offload xstats Ido Schimmel
2022-02-24 13:33 ` [PATCH net-next 08/14] net: rtnetlink: Add RTM_SETSTATS Ido Schimmel
2022-02-24 13:33 ` [PATCH net-next 09/14] net: rtnetlink: Add UAPI toggle for IFLA_OFFLOAD_XSTATS_L3_STATS Ido Schimmel
2022-02-24 13:33 ` [PATCH net-next 10/14] mlxsw: reg: Fix packing of router interface counters Ido Schimmel
2022-02-24 13:33 ` [PATCH net-next 11/14] mlxsw: spectrum_router: Drop mlxsw_sp arg from counter alloc/free functions Ido Schimmel
2022-02-24 13:33 ` [PATCH net-next 12/14] mlxsw: Extract classification of router-related events to a helper Ido Schimmel
2022-02-24 13:33 ` [PATCH net-next 13/14] mlxsw: Add support for IFLA_OFFLOAD_XSTATS_L3_STATS Ido Schimmel
2022-02-24 13:33 ` [PATCH net-next 14/14] selftests: forwarding: hw_stats_l3: Add a new test Ido Schimmel
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=87a6effiup.fsf@nvidia.com \
--to=petrm@nvidia.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=idosch@nvidia.com \
--cc=jiri@nvidia.com \
--cc=kuba@kernel.org \
--cc=mlxsw@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=razor@blackwall.org \
--cc=roopa@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).