Skip to contentSkip to conversation

tunnels: implement new --show-tunnels command

PATCH In review Jakub Kicinski 2 participants 3 messages Sep 9, 2020 – Sep 10, 2020

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 tunnels: implement new --show-tunnels command

Add support for the new show-tunnels command. Support dump.

 # ethtool --show-tunnels \*
Tunnel information for eth0:
  UDP port table 0:
    Size: 4
    Types: vxlan
    No entries
  UDP port table 1:
    Size: 4
    Types: geneve, vxlan-gpe
    Entries (2):
        port 1230, vxlan-gpe
        port 6081, geneve
---
 Makefile.am       |   2 +-
 ethtool.8.in      |   9 ++
 ethtool.c         |   5 +
 netlink/extapi.h  |   2 +
 netlink/tunnels.c | 236 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 253 insertions(+), 1 deletion(-)
 create mode 100644 netlink/tunnels.c
Makefile.am +1 -1
index aca0ad7bc773..0e237d070d4b 100644
@@ -37,7 +37,7 @@ ethtool_SOURCES += \
 		  netlink/channels.c netlink/coalesce.c netlink/pause.c \
 		  netlink/eee.c netlink/tsinfo.c \
 		  netlink/desc-ethtool.c netlink/desc-genlctrl.c \
-		  netlink/desc-rtnl.c netlink/cable_test.c \
+		  netlink/desc-rtnl.c netlink/cable_test.c netlink/tunnels.c \
 		  uapi/linux/ethtool_netlink.h \
 		  uapi/linux/netlink.h uapi/linux/genetlink.h \
 		  uapi/linux/rtnetlink.h uapi/linux/if_link.h
ethtool.8.in +9 -0
index a50a4769895c..42c4767db33e 100644
@@ -459,6 +459,9 @@ ethtool \- query or control network driver and hardware settings
 .BN last N
 .BN step N
 .BN pair N
+.HP
+.B ethtool \-\-show\-tunnels
+.I devname
 .
 .\" Adjust lines (i.e. full justification) and hyphenate.
 .ad
@@ -1383,6 +1386,12 @@ shown.
 If a device name is used as argument, only notification for this device are
 shown. Default is to show notifications for all devices.
 .RE
+.TP
+.B \-\-show\-tunnels
+Show tunnel-related device capabilities and state.
+List UDP ports kernel has programmed the device to parse as VxLAN,
+or GENEVE tunnels.
+.RE
 .SH BUGS
 Not supported (in part or whole) on all network drivers.
 .SH AUTHOR
ethtool.c +5 -0
index 606af3e6b48f..23ecfcfd069c 100644
@@ -5919,6 +5919,11 @@ static const struct option args[] = {
 			  "		[ step N ]\n"
 			  "		[ pair N ]\n"
 	},
+	{
+		.opts	= "--show-tunnels",
+		.nlfunc	= nl_gtunnels,
+		.help	= "Show NIC tunnel offload information",
+	},
 	{
 		.opts	= "-h|--help",
 		.no_dev	= true,
netlink/extapi.h +2 -0
index a35d5f2c0b26..9285e2325dfd 100644
@@ -37,6 +37,7 @@ int nl_seee(struct cmd_context *ctx);
 int nl_tsinfo(struct cmd_context *ctx);
 int nl_cable_test(struct cmd_context *ctx);
 int nl_cable_test_tdr(struct cmd_context *ctx);
+int nl_gtunnels(struct cmd_context *ctx);
 int nl_monitor(struct cmd_context *ctx);
 
 void nl_monitor_usage(void);
@@ -84,6 +85,7 @@ static inline void nl_monitor_usage(void)
 #define nl_tsinfo		NULL
 #define nl_cable_test		NULL
 #define nl_cable_test_tdr	NULL
+#define nl_gtunnels		NULL
 
 #endif /* ETHTOOL_ENABLE_NETLINK */
 
netlink/tunnels.c new file +236 -0

236 lines not on this page · raw message

Signature · 1 line
2.26.2
#1 lore raw
Quoted 15 lines · Jakub Kicinski

Add support for the new show-tunnels command. Support dump.

 # ethtool --show-tunnels \*
Tunnel information for eth0:
  UDP port table 0:
    Size: 4
    Types: vxlan
    No entries
  UDP port table 1:
    Size: 4
    Types: geneve, vxlan-gpe
    Entries (2):
        port 1230, vxlan-gpe
        port 6081, geneve
Quoted 1 line

The patch looks good except for one cosmetic issue below. But you will need to update the uapi header copies first to get the new constants. You can use the script at the end of this mail.

[...]

Quoted 15 lines
netlink/tunnels.c new file +15 -0
+static int
+tunnel_info_dump_udp_entry(struct nl_context *nlctx, const struct nlattr *entry,
+			   const struct stringset **strings)
+{
+	const struct nlattr *entry_tb[ETHTOOL_A_TUNNEL_UDP_ENTRY_MAX + 1] = {};
+	DECLARE_ATTR_TB_INFO(entry_tb);
+	const struct nlattr *attr;
+	unsigned int port, type;
+	int ret;
+
+	if (tunnel_info_strings_load(nlctx, strings))
+		return 1;
+
+	ret = mnl_attr_parse_nested(entry, attr_cb, &entry_tb_info);
+	if (ret < 0) {

netlink/tunnels.c line 61

Quoted 10 lines
netlink/tunnels.c new file +10 -0
+		fprintf(stderr, "malformed netlink message (udp entry)\n");
+		return 1;
+	}
+
+	attr = entry_tb[ETHTOOL_A_TUNNEL_UDP_ENTRY_PORT];
+	if (!attr || mnl_attr_validate(attr, MNL_TYPE_U16) < 0) {
+		fprintf(stderr, "malformed netlink message (port)\n");
+		return 1;
+	}
+	port = htons(mnl_attr_get_u16(attr));

This should be ntohs() as the attribute is in network byte order and we convert it to host byte order (the result is the same, of course).

netlink/tunnels.c line 73

Quoted 12 lines
netlink/tunnels.c new file +12 -0
+
+	attr = entry_tb[ETHTOOL_A_TUNNEL_UDP_ENTRY_TYPE];
+	if (!attr || mnl_attr_validate(attr, MNL_TYPE_U32) < 0) {
+		fprintf(stderr, "malformed netlink message (tunnel type)\n");
+		return 1;
+	}
+	type = mnl_attr_get_u32(attr);
+
+	printf("        port %d, %s\n", port, get_string(*strings, type));
+
+	return 0;
+}

The script below expects LINUX_GIT to be set to the directory with kernel git repository. It takes an optional argument which is a tag or commit id to import uapi headers from; without an argument it updates from what is currently checked out in $LINUX_GIT. So you can run e.g.

LINUX_GIT=~/git/kernel ethtool-import-uapi v5.9-rc1

Michal

------------------------------------------------------------------------------
#!/bin/bash -e

sn="${0##*/}"
export ARCH="x86_64"

if [ ! -d "$LINUX_GIT" ]; then

    echo "${sn}: LINUX_GIT not set" >&2
    exit 1

fi

pushd "$LINUX_GIT"
if [ -n "$1" ]; then
git checkout "$1"
fi

desc=$(git describe --exact-match 2>/dev/null \
       || git show -s --abbrev=12 --pretty='commit %h')

kobj=$(mktemp -d)
make -j16 O="$kobj" allmodconfig
make -j16 O="$kobj" prepare
make -j16 O="$kobj" INSTALL_HDR_PATH="${kobj}/hdr" headers_install popd

pushd uapi
find . -type f -name '*.h' -exec cp -v "${kobj}/hdr/include/{}" {} \; popd
rm -rf "$kobj"

git add uapi
git commit -s -F - <<EOT
update UAPI header copies

Update to kernel ${desc}.

EOT
------------------------------------------------------------------------------

author maintainer
#2 lore raw
Quoted 16 lines · On Thu, 10 Sep 2020 12:16:05 +0200 Michal Kubecek wrote:
Quoted 15 lines · Jakub Kicinski

Add support for the new show-tunnels command. Support dump.

 # ethtool --show-tunnels \*
Tunnel information for eth0:
  UDP port table 0:
    Size: 4
    Types: vxlan
    No entries
  UDP port table 1:
    Size: 4
    Types: geneve, vxlan-gpe
    Entries (2):
        port 1230, vxlan-gpe
        port 6081, geneve
Quoted 5 lines
Quoted 1 line

The patch looks good except for one cosmetic issue below. But you will need to update the uapi header copies first to get the new constants. You can use the script at the end of this mail.

Thanks! I wasn't sure if you sync yourself, like iproute2 folks do. Now I know :)