Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Hangbin Liu and committed by
Jakub Kicinski
948dbafc a0393e3e

+98 -55
+1 -1
drivers/net/team/Makefile
··· 3 3 # Makefile for the network team driver 4 4 # 5 5 6 - team-y:= team_core.o 6 + team-y:= team_core.o team_nl.o 7 7 obj-$(CONFIG_NET_TEAM) += team.o 8 8 obj-$(CONFIG_NET_TEAM_MODE_BROADCAST) += team_mode_broadcast.o 9 9 obj-$(CONFIG_NET_TEAM_MODE_ROUNDROBIN) += team_mode_roundrobin.o
+9 -54
drivers/net/team/team_core.c
··· 27 27 #include <net/sch_generic.h> 28 28 #include <linux/if_team.h> 29 29 30 + #include "team_nl.h" 31 + 30 32 #define DRV_NAME "team" 31 33 32 34 ··· 2256 2254 2257 2255 static struct genl_family team_nl_family; 2258 2256 2259 - static const struct nla_policy team_nl_policy[TEAM_ATTR_MAX + 1] = { 2260 - [TEAM_ATTR_UNSPEC] = { .type = NLA_UNSPEC, }, 2261 - [TEAM_ATTR_TEAM_IFINDEX] = { .type = NLA_U32 }, 2262 - [TEAM_ATTR_LIST_OPTION] = { .type = NLA_NESTED }, 2263 - [TEAM_ATTR_LIST_PORT] = { .type = NLA_NESTED }, 2264 - }; 2265 - 2266 - static const struct nla_policy 2267 - team_nl_option_policy[TEAM_ATTR_OPTION_MAX + 1] = { 2268 - [TEAM_ATTR_OPTION_UNSPEC] = { .type = NLA_UNSPEC, }, 2269 - [TEAM_ATTR_OPTION_NAME] = { 2270 - .type = NLA_STRING, 2271 - .len = TEAM_STRING_MAX_LEN, 2272 - }, 2273 - [TEAM_ATTR_OPTION_CHANGED] = { .type = NLA_FLAG }, 2274 - [TEAM_ATTR_OPTION_TYPE] = { .type = NLA_U8 }, 2275 - [TEAM_ATTR_OPTION_DATA] = { .type = NLA_BINARY }, 2276 - [TEAM_ATTR_OPTION_PORT_IFINDEX] = { .type = NLA_U32 }, 2277 - [TEAM_ATTR_OPTION_ARRAY_INDEX] = { .type = NLA_U32 }, 2278 - }; 2279 - 2280 - static int team_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info) 2257 + int team_nl_noop_doit(struct sk_buff *skb, struct genl_info *info) 2281 2258 { 2282 2259 struct sk_buff *msg; 2283 2260 void *hdr; ··· 2494 2513 return err; 2495 2514 } 2496 2515 2497 - static int team_nl_cmd_options_get(struct sk_buff *skb, struct genl_info *info) 2516 + int team_nl_options_get_doit(struct sk_buff *skb, struct genl_info *info) 2498 2517 { 2499 2518 struct team *team; 2500 2519 struct team_option_inst *opt_inst; ··· 2519 2538 static int team_nl_send_event_options_get(struct team *team, 2520 2539 struct list_head *sel_opt_inst_list); 2521 2540 2522 - static int team_nl_cmd_options_set(struct sk_buff *skb, struct genl_info *info) 2541 + int team_nl_options_set_doit(struct sk_buff *skb, struct genl_info *info) 2523 2542 { 2524 2543 struct team *team; 2525 2544 int err = 0; ··· 2560 2579 err = nla_parse_nested_deprecated(opt_attrs, 2561 2580 TEAM_ATTR_OPTION_MAX, 2562 2581 nl_option, 2563 - team_nl_option_policy, 2582 + team_attr_option_nl_policy, 2564 2583 info->extack); 2565 2584 if (err) 2566 2585 goto team_put; ··· 2783 2802 return err; 2784 2803 } 2785 2804 2786 - static int team_nl_cmd_port_list_get(struct sk_buff *skb, 2787 - struct genl_info *info) 2805 + int team_nl_port_list_get_doit(struct sk_buff *skb, 2806 + struct genl_info *info) 2788 2807 { 2789 2808 struct team *team; 2790 2809 int err; ··· 2801 2820 return err; 2802 2821 } 2803 2822 2804 - static const struct genl_small_ops team_nl_ops[] = { 2805 - { 2806 - .cmd = TEAM_CMD_NOOP, 2807 - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 2808 - .doit = team_nl_cmd_noop, 2809 - }, 2810 - { 2811 - .cmd = TEAM_CMD_OPTIONS_SET, 2812 - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 2813 - .doit = team_nl_cmd_options_set, 2814 - .flags = GENL_ADMIN_PERM, 2815 - }, 2816 - { 2817 - .cmd = TEAM_CMD_OPTIONS_GET, 2818 - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 2819 - .doit = team_nl_cmd_options_get, 2820 - .flags = GENL_ADMIN_PERM, 2821 - }, 2822 - { 2823 - .cmd = TEAM_CMD_PORT_LIST_GET, 2824 - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 2825 - .doit = team_nl_cmd_port_list_get, 2826 - .flags = GENL_ADMIN_PERM, 2827 - }, 2828 - }; 2829 - 2830 2823 static const struct genl_multicast_group team_nl_mcgrps[] = { 2831 2824 { .name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME, }, 2832 2825 }; ··· 2808 2853 static struct genl_family team_nl_family __ro_after_init = { 2809 2854 .name = TEAM_GENL_NAME, 2810 2855 .version = TEAM_GENL_VERSION, 2811 - .maxattr = TEAM_ATTR_MAX, 2856 + .maxattr = ARRAY_SIZE(team_nl_policy), 2812 2857 .policy = team_nl_policy, 2813 2858 .netnsok = true, 2814 2859 .module = THIS_MODULE,
+59
drivers/net/team/team_nl.c
··· 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 + };
+29
drivers/net/team/team_nl.h
··· 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 */