Skip to content

Commit d3d854f

Browse files
kuba-mooAlexei Starovoitov
authored andcommitted
netdev-genl: create a simple family for netdev stuff
Add a Netlink spec-compatible family for netdevs. This is a very simple implementation without much thought going into it. It allows us to reap all the benefits of Netlink specs, one can use the generic client to issue the commands: $ ./cli.py --spec netdev.yaml --dump dev_get [{'ifindex': 1, 'xdp-features': set()}, {'ifindex': 2, 'xdp-features': {'basic', 'ndo-xmit', 'redirect'}}, {'ifindex': 3, 'xdp-features': {'rx-sg'}}] the generic python library does not have flags-by-name support, yet, but we also don't have to carry strings in the messages, as user space can get the names from the spec. Acked-by: Jesper Dangaard Brouer <[email protected]> Co-developed-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Lorenzo Bianconi <[email protected]> Co-developed-by: Kumar Kartikeya Dwivedi <[email protected]> Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Co-developed-by: Marek Majtyka <[email protected]> Signed-off-by: Marek Majtyka <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Link: https://lore.kernel.org/r/327ad9c9868becbe1e601b580c962549c8cd81f2.1675245258.git.lorenzo@kernel.org Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 1508090 commit d3d854f

File tree

10 files changed

+477
-1
lines changed

10 files changed

+477
-1
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: netdev
2+
3+
doc:
4+
netdev configuration over generic netlink.
5+
6+
definitions:
7+
-
8+
type: flags
9+
name: xdp-act
10+
entries:
11+
-
12+
name: basic
13+
doc:
14+
XDP feautues set supported by all drivers
15+
(XDP_ABORTED, XDP_DROP, XDP_PASS, XDP_TX)
16+
-
17+
name: redirect
18+
doc:
19+
The netdev supports XDP_REDIRECT
20+
-
21+
name: ndo-xmit
22+
doc:
23+
This feature informs if netdev implements ndo_xdp_xmit callback.
24+
-
25+
name: xsk-zerocopy
26+
doc:
27+
This feature informs if netdev supports AF_XDP in zero copy mode.
28+
-
29+
name: hw-offload
30+
doc:
31+
This feature informs if netdev supports XDP hw oflloading.
32+
-
33+
name: rx-sg
34+
doc:
35+
This feature informs if netdev implements non-linear XDP buffer
36+
support in the driver napi callback.
37+
-
38+
name: ndo-xmit-sg
39+
doc:
40+
This feature informs if netdev implements non-linear XDP buffer
41+
support in ndo_xdp_xmit callback.
42+
43+
attribute-sets:
44+
-
45+
name: dev
46+
attributes:
47+
-
48+
name: ifindex
49+
doc: netdev ifindex
50+
type: u32
51+
value: 1
52+
checks:
53+
min: 1
54+
-
55+
name: pad
56+
type: pad
57+
-
58+
name: xdp-features
59+
doc: Bitmask of enabled xdp-features.
60+
type: u64
61+
enum: xdp-act
62+
enum-as-flags: true
63+
64+
operations:
65+
list:
66+
-
67+
name: dev-get
68+
doc: Get / dump information about a netdev.
69+
value: 1
70+
attribute-set: dev
71+
do:
72+
request:
73+
attributes:
74+
- ifindex
75+
reply: &dev-all
76+
attributes:
77+
- ifindex
78+
- xdp-features
79+
dump:
80+
reply: *dev-all
81+
-
82+
name: dev-add-ntf
83+
doc: Notification about device appearing.
84+
notify: dev-get
85+
mcgrp: mgmt
86+
-
87+
name: dev-del-ntf
88+
doc: Notification about device disappearing.
89+
notify: dev-get
90+
mcgrp: mgmt
91+
-
92+
name: dev-change-ntf
93+
doc: Notification about device configuration being changed.
94+
notify: dev-get
95+
mcgrp: mgmt
96+
97+
mcast-groups:
98+
list:
99+
-
100+
name: mgmt

include/linux/netdevice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <uapi/linux/netdevice.h>
4848
#include <uapi/linux/if_bonding.h>
4949
#include <uapi/linux/pkt_cls.h>
50+
#include <uapi/linux/netdev.h>
5051
#include <linux/hashtable.h>
5152
#include <linux/rbtree.h>
5253
#include <net/net_trackers.h>
@@ -2055,6 +2056,7 @@ struct net_device {
20552056

20562057
/* Read-mostly cache-line for fast-path access */
20572058
unsigned int flags;
2059+
xdp_features_t xdp_features;
20582060
unsigned long long priv_flags;
20592061
const struct net_device_ops *netdev_ops;
20602062
const struct xdp_metadata_ops *xdp_metadata_ops;
@@ -2839,6 +2841,7 @@ enum netdev_cmd {
28392841
NETDEV_OFFLOAD_XSTATS_DISABLE,
28402842
NETDEV_OFFLOAD_XSTATS_REPORT_USED,
28412843
NETDEV_OFFLOAD_XSTATS_REPORT_DELTA,
2844+
NETDEV_XDP_FEAT_CHANGE,
28422845
};
28432846
const char *netdev_cmd_to_name(enum netdev_cmd cmd);
28442847

include/net/xdp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define __LINUX_NET_XDP_H__
88

99
#include <linux/skbuff.h> /* skb_shared_info */
10+
#include <uapi/linux/netdev.h>
1011

1112
/**
1213
* DOC: XDP RX-queue information
@@ -43,6 +44,8 @@ enum xdp_mem_type {
4344
MEM_TYPE_MAX,
4445
};
4546

47+
typedef u32 xdp_features_t;
48+
4649
/* XDP flags for ndo_xdp_xmit */
4750
#define XDP_XMIT_FLUSH (1U << 0) /* doorbell signal consumer */
4851
#define XDP_XMIT_FLAGS_MASK XDP_XMIT_FLUSH

include/uapi/linux/netdev.h

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 */
2+
/* Do not edit directly, auto-generated from: */
3+
/* Documentation/netlink/specs/netdev.yaml */
4+
/* YNL-GEN uapi header */
5+
6+
#ifndef _UAPI_LINUX_NETDEV_H
7+
#define _UAPI_LINUX_NETDEV_H
8+
9+
#define NETDEV_FAMILY_NAME "netdev"
10+
#define NETDEV_FAMILY_VERSION 1
11+
12+
/**
13+
* enum netdev_xdp_act
14+
* @NETDEV_XDP_ACT_BASIC: XDP feautues set supported by all drivers
15+
* (XDP_ABORTED, XDP_DROP, XDP_PASS, XDP_TX)
16+
* @NETDEV_XDP_ACT_REDIRECT: The netdev supports XDP_REDIRECT
17+
* @NETDEV_XDP_ACT_NDO_XMIT: This feature informs if netdev implements
18+
* ndo_xdp_xmit callback.
19+
* @NETDEV_XDP_ACT_XSK_ZEROCOPY: This feature informs if netdev supports AF_XDP
20+
* in zero copy mode.
21+
* @NETDEV_XDP_ACT_HW_OFFLOAD: This feature informs if netdev supports XDP hw
22+
* oflloading.
23+
* @NETDEV_XDP_ACT_RX_SG: This feature informs if netdev implements non-linear
24+
* XDP buffer support in the driver napi callback.
25+
* @NETDEV_XDP_ACT_NDO_XMIT_SG: This feature informs if netdev implements
26+
* non-linear XDP buffer support in ndo_xdp_xmit callback.
27+
*/
28+
enum netdev_xdp_act {
29+
NETDEV_XDP_ACT_BASIC = 1,
30+
NETDEV_XDP_ACT_REDIRECT = 2,
31+
NETDEV_XDP_ACT_NDO_XMIT = 4,
32+
NETDEV_XDP_ACT_XSK_ZEROCOPY = 8,
33+
NETDEV_XDP_ACT_HW_OFFLOAD = 16,
34+
NETDEV_XDP_ACT_RX_SG = 32,
35+
NETDEV_XDP_ACT_NDO_XMIT_SG = 64,
36+
};
37+
38+
enum {
39+
NETDEV_A_DEV_IFINDEX = 1,
40+
NETDEV_A_DEV_PAD,
41+
NETDEV_A_DEV_XDP_FEATURES,
42+
43+
__NETDEV_A_DEV_MAX,
44+
NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1)
45+
};
46+
47+
enum {
48+
NETDEV_CMD_DEV_GET = 1,
49+
NETDEV_CMD_DEV_ADD_NTF,
50+
NETDEV_CMD_DEV_DEL_NTF,
51+
NETDEV_CMD_DEV_CHANGE_NTF,
52+
53+
__NETDEV_CMD_MAX,
54+
NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1)
55+
};
56+
57+
#define NETDEV_MCGRP_MGMT "mgmt"
58+
59+
#endif /* _UAPI_LINUX_NETDEV_H */

net/core/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.o
1212
obj-y += dev.o dev_addr_lists.o dst.o netevent.o \
1313
neighbour.o rtnetlink.o utils.o link_watch.o filter.o \
1414
sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \
15-
fib_notifier.o xdp.o flow_offload.o gro.o
15+
fib_notifier.o xdp.o flow_offload.o gro.o \
16+
netdev-genl.o netdev-genl-gen.o
1617

1718
obj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o
1819

net/core/dev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,7 @@ const char *netdev_cmd_to_name(enum netdev_cmd cmd)
16141614
N(SVLAN_FILTER_PUSH_INFO) N(SVLAN_FILTER_DROP_INFO)
16151615
N(PRE_CHANGEADDR) N(OFFLOAD_XSTATS_ENABLE) N(OFFLOAD_XSTATS_DISABLE)
16161616
N(OFFLOAD_XSTATS_REPORT_USED) N(OFFLOAD_XSTATS_REPORT_DELTA)
1617+
N(XDP_FEAT_CHANGE)
16171618
}
16181619
#undef N
16191620
return "UNKNOWN_NETDEV_EVENT";

net/core/netdev-genl-gen.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
/* Do not edit directly, auto-generated from: */
3+
/* Documentation/netlink/specs/netdev.yaml */
4+
/* YNL-GEN kernel source */
5+
6+
#include <net/netlink.h>
7+
#include <net/genetlink.h>
8+
9+
#include "netdev-genl-gen.h"
10+
11+
#include <linux/netdev.h>
12+
13+
/* NETDEV_CMD_DEV_GET - do */
14+
static const struct nla_policy netdev_dev_get_nl_policy[NETDEV_A_DEV_IFINDEX + 1] = {
15+
[NETDEV_A_DEV_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1),
16+
};
17+
18+
/* Ops table for netdev */
19+
static const struct genl_split_ops netdev_nl_ops[2] = {
20+
{
21+
.cmd = NETDEV_CMD_DEV_GET,
22+
.doit = netdev_nl_dev_get_doit,
23+
.policy = netdev_dev_get_nl_policy,
24+
.maxattr = NETDEV_A_DEV_IFINDEX,
25+
.flags = GENL_CMD_CAP_DO,
26+
},
27+
{
28+
.cmd = NETDEV_CMD_DEV_GET,
29+
.dumpit = netdev_nl_dev_get_dumpit,
30+
.flags = GENL_CMD_CAP_DUMP,
31+
},
32+
};
33+
34+
static const struct genl_multicast_group netdev_nl_mcgrps[] = {
35+
[NETDEV_NLGRP_MGMT] = { "mgmt", },
36+
};
37+
38+
struct genl_family netdev_nl_family __ro_after_init = {
39+
.name = NETDEV_FAMILY_NAME,
40+
.version = NETDEV_FAMILY_VERSION,
41+
.netnsok = true,
42+
.parallel_ops = true,
43+
.module = THIS_MODULE,
44+
.split_ops = netdev_nl_ops,
45+
.n_split_ops = ARRAY_SIZE(netdev_nl_ops),
46+
.mcgrps = netdev_nl_mcgrps,
47+
.n_mcgrps = ARRAY_SIZE(netdev_nl_mcgrps),
48+
};

net/core/netdev-genl-gen.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* SPDX-License-Identifier: BSD-3-Clause */
2+
/* Do not edit directly, auto-generated from: */
3+
/* Documentation/netlink/specs/netdev.yaml */
4+
/* YNL-GEN kernel header */
5+
6+
#ifndef _LINUX_NETDEV_GEN_H
7+
#define _LINUX_NETDEV_GEN_H
8+
9+
#include <net/netlink.h>
10+
#include <net/genetlink.h>
11+
12+
#include <linux/netdev.h>
13+
14+
int netdev_nl_dev_get_doit(struct sk_buff *skb, struct genl_info *info);
15+
int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
16+
17+
enum {
18+
NETDEV_NLGRP_MGMT,
19+
};
20+
21+
extern struct genl_family netdev_nl_family;
22+
23+
#endif /* _LINUX_NETDEV_GEN_H */

0 commit comments

Comments
 (0)