Skip to content

Commit 948dbaf

Browse files
liuhangbinkuba-moo
authored andcommitted
net: team: use policy generated by YAML spec
generated with: $ ./tools/net/ynl/ynl-gen-c.py --mode kernel \ > --spec Documentation/netlink/specs/team.yaml --source \ > -o drivers/net/team/team_nl.c $ ./tools/net/ynl/ynl-gen-c.py --mode kernel \ > --spec Documentation/netlink/specs/team.yaml --header \ > -o drivers/net/team/team_nl.h The TEAM_ATTR_LIST_PORT in team_nl_policy is removed as it is only in the port list reply attributes. Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Link: https://lore.kernel.org/r/20240401031004.1159713-4-liuhangbin@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent a0393e3 commit 948dbaf

File tree

4 files changed

+98
-55
lines changed

4 files changed

+98
-55
lines changed

drivers/net/team/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Makefile for the network team driver
44
#
55

6-
team-y:= team_core.o
6+
team-y:= team_core.o team_nl.o
77
obj-$(CONFIG_NET_TEAM) += team.o
88
obj-$(CONFIG_NET_TEAM_MODE_BROADCAST) += team_mode_broadcast.o
99
obj-$(CONFIG_NET_TEAM_MODE_ROUNDROBIN) += team_mode_roundrobin.o

drivers/net/team/team_core.c

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <net/sch_generic.h>
2828
#include <linux/if_team.h>
2929

30+
#include "team_nl.h"
31+
3032
#define DRV_NAME "team"
3133

3234

@@ -2254,28 +2256,7 @@ static struct rtnl_link_ops team_link_ops __read_mostly = {
22542256

22552257
static struct genl_family team_nl_family;
22562258

2257-
static const struct nla_policy team_nl_policy[TEAM_ATTR_MAX + 1] = {
2258-
[TEAM_ATTR_UNSPEC] = { .type = NLA_UNSPEC, },
2259-
[TEAM_ATTR_TEAM_IFINDEX] = { .type = NLA_U32 },
2260-
[TEAM_ATTR_LIST_OPTION] = { .type = NLA_NESTED },
2261-
[TEAM_ATTR_LIST_PORT] = { .type = NLA_NESTED },
2262-
};
2263-
2264-
static const struct nla_policy
2265-
team_nl_option_policy[TEAM_ATTR_OPTION_MAX + 1] = {
2266-
[TEAM_ATTR_OPTION_UNSPEC] = { .type = NLA_UNSPEC, },
2267-
[TEAM_ATTR_OPTION_NAME] = {
2268-
.type = NLA_STRING,
2269-
.len = TEAM_STRING_MAX_LEN,
2270-
},
2271-
[TEAM_ATTR_OPTION_CHANGED] = { .type = NLA_FLAG },
2272-
[TEAM_ATTR_OPTION_TYPE] = { .type = NLA_U8 },
2273-
[TEAM_ATTR_OPTION_DATA] = { .type = NLA_BINARY },
2274-
[TEAM_ATTR_OPTION_PORT_IFINDEX] = { .type = NLA_U32 },
2275-
[TEAM_ATTR_OPTION_ARRAY_INDEX] = { .type = NLA_U32 },
2276-
};
2277-
2278-
static int team_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info)
2259+
int team_nl_noop_doit(struct sk_buff *skb, struct genl_info *info)
22792260
{
22802261
struct sk_buff *msg;
22812262
void *hdr;
@@ -2513,7 +2494,7 @@ static int team_nl_send_options_get(struct team *team, u32 portid, u32 seq,
25132494
return err;
25142495
}
25152496

2516-
static int team_nl_cmd_options_get(struct sk_buff *skb, struct genl_info *info)
2497+
int team_nl_options_get_doit(struct sk_buff *skb, struct genl_info *info)
25172498
{
25182499
struct team *team;
25192500
struct team_option_inst *opt_inst;
@@ -2538,7 +2519,7 @@ static int team_nl_cmd_options_get(struct sk_buff *skb, struct genl_info *info)
25382519
static int team_nl_send_event_options_get(struct team *team,
25392520
struct list_head *sel_opt_inst_list);
25402521

2541-
static int team_nl_cmd_options_set(struct sk_buff *skb, struct genl_info *info)
2522+
int team_nl_options_set_doit(struct sk_buff *skb, struct genl_info *info)
25422523
{
25432524
struct team *team;
25442525
int err = 0;
@@ -2579,7 +2560,7 @@ static int team_nl_cmd_options_set(struct sk_buff *skb, struct genl_info *info)
25792560
err = nla_parse_nested_deprecated(opt_attrs,
25802561
TEAM_ATTR_OPTION_MAX,
25812562
nl_option,
2582-
team_nl_option_policy,
2563+
team_attr_option_nl_policy,
25832564
info->extack);
25842565
if (err)
25852566
goto team_put;
@@ -2802,8 +2783,8 @@ static int team_nl_send_port_list_get(struct team *team, u32 portid, u32 seq,
28022783
return err;
28032784
}
28042785

2805-
static int team_nl_cmd_port_list_get(struct sk_buff *skb,
2806-
struct genl_info *info)
2786+
int team_nl_port_list_get_doit(struct sk_buff *skb,
2787+
struct genl_info *info)
28072788
{
28082789
struct team *team;
28092790
int err;
@@ -2820,40 +2801,14 @@ static int team_nl_cmd_port_list_get(struct sk_buff *skb,
28202801
return err;
28212802
}
28222803

2823-
static const struct genl_small_ops team_nl_ops[] = {
2824-
{
2825-
.cmd = TEAM_CMD_NOOP,
2826-
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2827-
.doit = team_nl_cmd_noop,
2828-
},
2829-
{
2830-
.cmd = TEAM_CMD_OPTIONS_SET,
2831-
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2832-
.doit = team_nl_cmd_options_set,
2833-
.flags = GENL_ADMIN_PERM,
2834-
},
2835-
{
2836-
.cmd = TEAM_CMD_OPTIONS_GET,
2837-
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2838-
.doit = team_nl_cmd_options_get,
2839-
.flags = GENL_ADMIN_PERM,
2840-
},
2841-
{
2842-
.cmd = TEAM_CMD_PORT_LIST_GET,
2843-
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2844-
.doit = team_nl_cmd_port_list_get,
2845-
.flags = GENL_ADMIN_PERM,
2846-
},
2847-
};
2848-
28492804
static const struct genl_multicast_group team_nl_mcgrps[] = {
28502805
{ .name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME, },
28512806
};
28522807

28532808
static struct genl_family team_nl_family __ro_after_init = {
28542809
.name = TEAM_GENL_NAME,
28552810
.version = TEAM_GENL_VERSION,
2856-
.maxattr = TEAM_ATTR_MAX,
2811+
.maxattr = ARRAY_SIZE(team_nl_policy),
28572812
.policy = team_nl_policy,
28582813
.netnsok = true,
28592814
.module = THIS_MODULE,

drivers/net/team/team_nl.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
2+
/* Do not edit directly, auto-generated from: */
3+
/* Documentation/netlink/specs/team.yaml */
4+
/* YNL-GEN kernel source */
5+
6+
#include <net/netlink.h>
7+
#include <net/genetlink.h>
8+
9+
#include "team_nl.h"
10+
11+
#include <uapi/linux/if_team.h>
12+
13+
/* Common nested types */
14+
const struct nla_policy team_attr_option_nl_policy[TEAM_ATTR_OPTION_ARRAY_INDEX + 1] = {
15+
[TEAM_ATTR_OPTION_NAME] = { .type = NLA_STRING, .len = TEAM_STRING_MAX_LEN, },
16+
[TEAM_ATTR_OPTION_CHANGED] = { .type = NLA_FLAG, },
17+
[TEAM_ATTR_OPTION_TYPE] = { .type = NLA_U8, },
18+
[TEAM_ATTR_OPTION_DATA] = { .type = NLA_BINARY, },
19+
[TEAM_ATTR_OPTION_REMOVED] = { .type = NLA_FLAG, },
20+
[TEAM_ATTR_OPTION_PORT_IFINDEX] = { .type = NLA_U32, },
21+
[TEAM_ATTR_OPTION_ARRAY_INDEX] = { .type = NLA_U32, },
22+
};
23+
24+
const struct nla_policy team_item_option_nl_policy[TEAM_ATTR_ITEM_OPTION + 1] = {
25+
[TEAM_ATTR_ITEM_OPTION] = NLA_POLICY_NESTED(team_attr_option_nl_policy),
26+
};
27+
28+
/* Global operation policy for team */
29+
const struct nla_policy team_nl_policy[TEAM_ATTR_LIST_OPTION + 1] = {
30+
[TEAM_ATTR_TEAM_IFINDEX] = { .type = NLA_U32, },
31+
[TEAM_ATTR_LIST_OPTION] = NLA_POLICY_NESTED(team_item_option_nl_policy),
32+
};
33+
34+
/* Ops table for team */
35+
const struct genl_small_ops team_nl_ops[4] = {
36+
{
37+
.cmd = TEAM_CMD_NOOP,
38+
.validate = GENL_DONT_VALIDATE_STRICT,
39+
.doit = team_nl_noop_doit,
40+
},
41+
{
42+
.cmd = TEAM_CMD_OPTIONS_SET,
43+
.validate = GENL_DONT_VALIDATE_STRICT,
44+
.doit = team_nl_options_set_doit,
45+
.flags = GENL_ADMIN_PERM,
46+
},
47+
{
48+
.cmd = TEAM_CMD_OPTIONS_GET,
49+
.validate = GENL_DONT_VALIDATE_STRICT,
50+
.doit = team_nl_options_get_doit,
51+
.flags = GENL_ADMIN_PERM,
52+
},
53+
{
54+
.cmd = TEAM_CMD_PORT_LIST_GET,
55+
.validate = GENL_DONT_VALIDATE_STRICT,
56+
.doit = team_nl_port_list_get_doit,
57+
.flags = GENL_ADMIN_PERM,
58+
},
59+
};

drivers/net/team/team_nl.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
2+
/* Do not edit directly, auto-generated from: */
3+
/* Documentation/netlink/specs/team.yaml */
4+
/* YNL-GEN kernel header */
5+
6+
#ifndef _LINUX_TEAM_GEN_H
7+
#define _LINUX_TEAM_GEN_H
8+
9+
#include <net/netlink.h>
10+
#include <net/genetlink.h>
11+
12+
#include <uapi/linux/if_team.h>
13+
14+
/* Common nested types */
15+
extern const struct nla_policy team_attr_option_nl_policy[TEAM_ATTR_OPTION_ARRAY_INDEX + 1];
16+
extern const struct nla_policy team_item_option_nl_policy[TEAM_ATTR_ITEM_OPTION + 1];
17+
18+
/* Global operation policy for team */
19+
extern const struct nla_policy team_nl_policy[TEAM_ATTR_LIST_OPTION + 1];
20+
21+
/* Ops table for team */
22+
extern const struct genl_small_ops team_nl_ops[4];
23+
24+
int team_nl_noop_doit(struct sk_buff *skb, struct genl_info *info);
25+
int team_nl_options_set_doit(struct sk_buff *skb, struct genl_info *info);
26+
int team_nl_options_get_doit(struct sk_buff *skb, struct genl_info *info);
27+
int team_nl_port_list_get_doit(struct sk_buff *skb, struct genl_info *info);
28+
29+
#endif /* _LINUX_TEAM_GEN_H */

0 commit comments

Comments
 (0)