Re: [PATCH net-next v6 05/15] ethtool: helper functions for netlink interface

From: Jakub Kicinski
Date: Tue Jul 02 2019 - 21:37:33 EST


On Tue, 2 Jul 2019 13:50:04 +0200 (CEST), Michal Kubecek wrote:
> Add common request/reply header definition and helpers to parse request
> header and fill reply header. Provide ethnl_update_* helpers to update
> structure members from request attributes (to be used for *_SET requests).
>
> Signed-off-by: Michal Kubecek <mkubecek@xxxxxxx>

> diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c
> index 3c98b41f04e5..e13f29bbd625 100644
> --- a/net/ethtool/netlink.c
> +++ b/net/ethtool/netlink.c
> @@ -1,8 +1,181 @@
> // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
>
> +#include <net/sock.h>
> #include <linux/ethtool_netlink.h>
> #include "netlink.h"
>
> +static struct genl_family ethtool_genl_family;
> +
> +static const struct nla_policy dflt_header_policy[ETHTOOL_A_HEADER_MAX + 1] = {
> + [ETHTOOL_A_HEADER_UNSPEC] = { .type = NLA_REJECT },

I think we want strict checking on all new netlink interfaces, and
unfortunately that feature is opt-in.. so you need to add:

.strict_start_type = ETHTOOL_A_HEADER_UNSPEC + 1

To the first attr.

> + [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 },
> + [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING,
> + .len = IFNAMSIZ - 1 },
> + [ETHTOOL_A_HEADER_INFOMASK] = { .type = NLA_U32 },
> + [ETHTOOL_A_HEADER_GFLAGS] = { .type = NLA_U32 },
> + [ETHTOOL_A_HEADER_RFLAGS] = { .type = NLA_U32 },
> +};