Skip to content

Commit c1a6589

Browse files
committed
Merge branch 'doc-netlink-add-a-yaml-spec-for-team'
Hangbin Liu says: ==================== doc/netlink: add a YAML spec for team Add a YAML spec for team. As we need to link two objects together to form the team module, rename team to team_core for linking. ==================== Link: https://lore.kernel.org/r/20240401031004.1159713-1-liuhangbin@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 9a79c65 + e57ba7e commit c1a6589

File tree

7 files changed

+346
-127
lines changed

7 files changed

+346
-127
lines changed
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
2+
3+
name: team
4+
5+
protocol: genetlink-legacy
6+
7+
doc: |
8+
Network team device driver.
9+
10+
c-family-name: team-genl-name
11+
c-version-name: team-genl-version
12+
kernel-policy: global
13+
uapi-header: linux/if_team.h
14+
15+
definitions:
16+
-
17+
name: string-max-len
18+
type: const
19+
value: 32
20+
-
21+
name: genl-change-event-mc-grp-name
22+
type: const
23+
value: change_event
24+
25+
attribute-sets:
26+
-
27+
name: team
28+
doc:
29+
The team nested layout of get/set msg looks like
30+
[TEAM_ATTR_LIST_OPTION]
31+
[TEAM_ATTR_ITEM_OPTION]
32+
[TEAM_ATTR_OPTION_*], ...
33+
[TEAM_ATTR_ITEM_OPTION]
34+
[TEAM_ATTR_OPTION_*], ...
35+
...
36+
[TEAM_ATTR_LIST_PORT]
37+
[TEAM_ATTR_ITEM_PORT]
38+
[TEAM_ATTR_PORT_*], ...
39+
[TEAM_ATTR_ITEM_PORT]
40+
[TEAM_ATTR_PORT_*], ...
41+
...
42+
name-prefix: team-attr-
43+
attributes:
44+
-
45+
name: unspec
46+
type: unused
47+
value: 0
48+
-
49+
name: team-ifindex
50+
type: u32
51+
-
52+
name: list-option
53+
type: nest
54+
nested-attributes: item-option
55+
-
56+
name: list-port
57+
type: nest
58+
nested-attributes: item-port
59+
-
60+
name: item-option
61+
name-prefix: team-attr-item-
62+
attr-cnt-name: __team-attr-item-option-max
63+
attr-max-name: team-attr-item-option-max
64+
attributes:
65+
-
66+
name: option-unspec
67+
type: unused
68+
value: 0
69+
-
70+
name: option
71+
type: nest
72+
nested-attributes: attr-option
73+
-
74+
name: attr-option
75+
name-prefix: team-attr-option-
76+
attributes:
77+
-
78+
name: unspec
79+
type: unused
80+
value: 0
81+
-
82+
name: name
83+
type: string
84+
checks:
85+
max-len: string-max-len
86+
unterminated-ok: true
87+
-
88+
name: changed
89+
type: flag
90+
-
91+
name: type
92+
type: u8
93+
-
94+
name: data
95+
type: binary
96+
-
97+
name: removed
98+
type: flag
99+
-
100+
name: port-ifindex
101+
type: u32
102+
doc: for per-port options
103+
-
104+
name: array-index
105+
type: u32
106+
doc: for array options
107+
-
108+
name: item-port
109+
name-prefix: team-attr-item-
110+
attr-cnt-name: __team-attr-item-port-max
111+
attr-max-name: team-attr-item-port-max
112+
attributes:
113+
-
114+
name: port-unspec
115+
type: unused
116+
value: 0
117+
-
118+
name: port
119+
type: nest
120+
nested-attributes: attr-port
121+
-
122+
name: attr-port
123+
name-prefix: team-attr-port-
124+
attributes:
125+
-
126+
name: unspec
127+
type: unused
128+
value: 0
129+
-
130+
name: ifindex
131+
type: u32
132+
-
133+
name: changed
134+
type: flag
135+
-
136+
name: linkup
137+
type: flag
138+
-
139+
name: speed
140+
type: u32
141+
-
142+
name: duplex
143+
type: u8
144+
-
145+
name: removed
146+
type: flag
147+
148+
operations:
149+
list:
150+
-
151+
name: noop
152+
doc: No operation
153+
value: 0
154+
attribute-set: team
155+
dont-validate: [ strict ]
156+
157+
do:
158+
# Actually it only reply the team netlink family
159+
reply:
160+
attributes:
161+
- team-ifindex
162+
163+
-
164+
name: options-set
165+
doc: Set team options
166+
attribute-set: team
167+
dont-validate: [ strict ]
168+
flags: [ admin-perm ]
169+
170+
do:
171+
request: &option_attrs
172+
attributes:
173+
- team-ifindex
174+
- list-option
175+
reply: *option_attrs
176+
177+
-
178+
name: options-get
179+
doc: Get team options info
180+
attribute-set: team
181+
dont-validate: [ strict ]
182+
flags: [ admin-perm ]
183+
184+
do:
185+
request:
186+
attributes:
187+
- team-ifindex
188+
reply: *option_attrs
189+
190+
-
191+
name: port-list-get
192+
doc: Get team ports info
193+
attribute-set: team
194+
dont-validate: [ strict ]
195+
flags: [ admin-perm ]
196+
197+
do:
198+
request:
199+
attributes:
200+
- team-ifindex
201+
reply: &port_attrs
202+
attributes:
203+
- team-ifindex
204+
- list-port

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21665,6 +21665,7 @@ TEAM DRIVER
2166521665
M: Jiri Pirko <jiri@resnulli.us>
2166621666
L: netdev@vger.kernel.org
2166721667
S: Supported
21668+
F: Documentation/netlink/specs/team.yaml
2166821669
F: drivers/net/team/
2166921670
F: include/linux/if_team.h
2167021671
F: include/uapi/linux/if_team.h

drivers/net/team/Makefile

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

6+
team-y:= team_core.o team_nl.o
67
obj-$(CONFIG_NET_TEAM) += team.o
78
obj-$(CONFIG_NET_TEAM_MODE_BROADCAST) += team_mode_broadcast.o
89
obj-$(CONFIG_NET_TEAM_MODE_ROUNDROBIN) += team_mode_roundrobin.o

drivers/net/team/team.c renamed to 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+
};

0 commit comments

Comments
 (0)