|
|
049c96 |
From f6e5ebe6d481c6785c7b6b8b9888620087669a1c Mon Sep 17 00:00:00 2001
|
|
|
049c96 |
From: Phil Sutter <psutter@redhat.com>
|
|
|
049c96 |
Date: Sat, 9 Jul 2016 11:32:36 +0200
|
|
|
049c96 |
Subject: [PATCH] add devlink tool
|
|
|
049c96 |
|
|
|
049c96 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1342515
|
|
|
049c96 |
Upstream Status: iproute2.git commit a3c4b484a1edd
|
|
|
049c96 |
Conflicts: Context changed due to missing tipc utility.
|
|
|
049c96 |
|
|
|
049c96 |
commit a3c4b484a1eddc87fbb66812a2453d840bc89f35
|
|
|
049c96 |
Author: Jiri Pirko <jiri@mellanox.com>
|
|
|
049c96 |
Date: Tue Mar 22 10:02:21 2016 +0100
|
|
|
049c96 |
|
|
|
049c96 |
add devlink tool
|
|
|
049c96 |
|
|
|
049c96 |
Add new tool called devlink which is userspace counterpart of devlink
|
|
|
049c96 |
Netlink socket.
|
|
|
049c96 |
|
|
|
049c96 |
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
|
|
|
049c96 |
---
|
|
|
049c96 |
Makefile | 2 +-
|
|
|
049c96 |
devlink/Makefile | 20 +
|
|
|
049c96 |
devlink/devlink.c | 986 +++++++++++++++++++++++++++++++++++++++++++++
|
|
|
049c96 |
devlink/mnlg.c | 274 +++++++++++++
|
|
|
049c96 |
devlink/mnlg.h | 27 ++
|
|
|
049c96 |
man/man8/devlink-dev.8 | 58 +++
|
|
|
049c96 |
man/man8/devlink-monitor.8 | 36 ++
|
|
|
049c96 |
man/man8/devlink-port.8 | 126 ++++++
|
|
|
049c96 |
man/man8/devlink.8 | 83 ++++
|
|
|
049c96 |
9 files changed, 1611 insertions(+), 1 deletion(-)
|
|
|
049c96 |
create mode 100644 devlink/Makefile
|
|
|
049c96 |
create mode 100644 devlink/devlink.c
|
|
|
049c96 |
create mode 100644 devlink/mnlg.c
|
|
|
049c96 |
create mode 100644 devlink/mnlg.h
|
|
|
049c96 |
create mode 100644 man/man8/devlink-dev.8
|
|
|
049c96 |
create mode 100644 man/man8/devlink-monitor.8
|
|
|
049c96 |
create mode 100644 man/man8/devlink-port.8
|
|
|
049c96 |
create mode 100644 man/man8/devlink.8
|
|
|
049c96 |
|
|
|
049c96 |
diff --git a/Makefile b/Makefile
|
|
|
049c96 |
index 18faee4..d50512f 100644
|
|
|
049c96 |
--- a/Makefile
|
|
|
049c96 |
+++ b/Makefile
|
|
|
049c96 |
@@ -36,7 +36,7 @@ WFLAGS += -Wmissing-declarations -Wold-style-definition -Wformat=2
|
|
|
049c96 |
CFLAGS := $(WFLAGS) $(CCOPTS) -I../include $(DEFINES) $(CFLAGS)
|
|
|
049c96 |
YACCFLAGS = -d -t -v
|
|
|
049c96 |
|
|
|
049c96 |
-SUBDIRS=lib ip tc bridge misc netem genl man
|
|
|
049c96 |
+SUBDIRS=lib ip tc bridge misc netem genl devlink man
|
|
|
049c96 |
|
|
|
049c96 |
LIBNETLINK=../lib/libnetlink.a ../lib/libutil.a
|
|
|
049c96 |
LDLIBS += $(LIBNETLINK)
|
|
|
049c96 |
diff --git a/devlink/Makefile b/devlink/Makefile
|
|
|
049c96 |
new file mode 100644
|
|
|
049c96 |
index 0000000..3fdaa69
|
|
|
049c96 |
--- /dev/null
|
|
|
049c96 |
+++ b/devlink/Makefile
|
|
|
049c96 |
@@ -0,0 +1,20 @@
|
|
|
049c96 |
+include ../Config
|
|
|
049c96 |
+ifeq ($(HAVE_MNL),y)
|
|
|
049c96 |
+
|
|
|
049c96 |
+DEVLINKOBJ = devlink.o mnlg.o
|
|
|
049c96 |
+TARGETS=devlink
|
|
|
049c96 |
+
|
|
|
049c96 |
+CFLAGS += $(shell $(PKG_CONFIG) libmnl --cflags)
|
|
|
049c96 |
+LDLIBS += $(shell $(PKG_CONFIG) libmnl --libs)
|
|
|
049c96 |
+
|
|
|
049c96 |
+endif
|
|
|
049c96 |
+
|
|
|
049c96 |
+all: $(TARGETS) $(LIBS)
|
|
|
049c96 |
+
|
|
|
049c96 |
+devlink: $(DEVLINKOBJ)
|
|
|
049c96 |
+
|
|
|
049c96 |
+install: all
|
|
|
049c96 |
+ install -m 0755 $(TARGETS) $(DESTDIR)$(SBINDIR)
|
|
|
049c96 |
+
|
|
|
049c96 |
+clean:
|
|
|
049c96 |
+ rm -f $(DEVLINKOBJ) $(TARGETS)
|
|
|
049c96 |
diff --git a/devlink/devlink.c b/devlink/devlink.c
|
|
|
049c96 |
new file mode 100644
|
|
|
049c96 |
index 0000000..c2da850
|
|
|
049c96 |
--- /dev/null
|
|
|
049c96 |
+++ b/devlink/devlink.c
|
|
|
049c96 |
@@ -0,0 +1,986 @@
|
|
|
049c96 |
+/*
|
|
|
049c96 |
+ * devlink.c Devlink tool
|
|
|
049c96 |
+ *
|
|
|
049c96 |
+ * This program is free software; you can redistribute it and/or
|
|
|
049c96 |
+ * modify it under the terms of the GNU General Public License
|
|
|
049c96 |
+ * as published by the Free Software Foundation; either version
|
|
|
049c96 |
+ * 2 of the License, or (at your option) any later version.
|
|
|
049c96 |
+ *
|
|
|
049c96 |
+ * Authors: Jiri Pirko <jiri@mellanox.com>
|
|
|
049c96 |
+ */
|
|
|
049c96 |
+
|
|
|
049c96 |
+#include <stdio.h>
|
|
|
049c96 |
+#include <stdlib.h>
|
|
|
049c96 |
+#include <string.h>
|
|
|
049c96 |
+#include <stdbool.h>
|
|
|
049c96 |
+#include <unistd.h>
|
|
|
049c96 |
+#include <getopt.h>
|
|
|
049c96 |
+#include <limits.h>
|
|
|
049c96 |
+#include <errno.h>
|
|
|
049c96 |
+#include <linux/genetlink.h>
|
|
|
049c96 |
+#include <linux/devlink.h>
|
|
|
049c96 |
+#include <libmnl/libmnl.h>
|
|
|
049c96 |
+
|
|
|
049c96 |
+#include "SNAPSHOT.h"
|
|
|
049c96 |
+#include "list.h"
|
|
|
049c96 |
+#include "mnlg.h"
|
|
|
049c96 |
+
|
|
|
049c96 |
+#define pr_err(args...) fprintf(stderr, ##args)
|
|
|
049c96 |
+#define pr_out(args...) fprintf(stdout, ##args)
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int _mnlg_socket_recv_run(struct mnlg_socket *nlg,
|
|
|
049c96 |
+ mnl_cb_t data_cb, void *data)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = mnlg_socket_recv_run(nlg, data_cb, data);
|
|
|
049c96 |
+ if (err < 0) {
|
|
|
049c96 |
+ pr_err("devlink answers: %s\n", strerror(errno));
|
|
|
049c96 |
+ return -errno;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int _mnlg_socket_sndrcv(struct mnlg_socket *nlg,
|
|
|
049c96 |
+ const struct nlmsghdr *nlh,
|
|
|
049c96 |
+ mnl_cb_t data_cb, void *data)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = mnlg_socket_send(nlg, nlh);
|
|
|
049c96 |
+ if (err < 0) {
|
|
|
049c96 |
+ pr_err("Failed to call mnlg_socket_send\n");
|
|
|
049c96 |
+ return -errno;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ return _mnlg_socket_recv_run(nlg, data_cb, data);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int _mnlg_socket_group_add(struct mnlg_socket *nlg,
|
|
|
049c96 |
+ const char *group_name)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = mnlg_socket_group_add(nlg, group_name);
|
|
|
049c96 |
+ if (err < 0) {
|
|
|
049c96 |
+ pr_err("Failed to call mnlg_socket_group_add\n");
|
|
|
049c96 |
+ return -errno;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+struct ifname_map {
|
|
|
049c96 |
+ struct list_head list;
|
|
|
049c96 |
+ char *bus_name;
|
|
|
049c96 |
+ char *dev_name;
|
|
|
049c96 |
+ uint32_t port_index;
|
|
|
049c96 |
+ char *ifname;
|
|
|
049c96 |
+};
|
|
|
049c96 |
+
|
|
|
049c96 |
+static struct ifname_map *ifname_map_alloc(const char *bus_name,
|
|
|
049c96 |
+ const char *dev_name,
|
|
|
049c96 |
+ uint32_t port_index,
|
|
|
049c96 |
+ const char *ifname)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct ifname_map *ifname_map;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ ifname_map = calloc(1, sizeof(*ifname_map));
|
|
|
049c96 |
+ if (!ifname_map)
|
|
|
049c96 |
+ return NULL;
|
|
|
049c96 |
+ ifname_map->bus_name = strdup(bus_name);
|
|
|
049c96 |
+ ifname_map->dev_name = strdup(dev_name);
|
|
|
049c96 |
+ ifname_map->port_index = port_index;
|
|
|
049c96 |
+ ifname_map->ifname = strdup(ifname);
|
|
|
049c96 |
+ if (!ifname_map->bus_name || !ifname_map->dev_name ||
|
|
|
049c96 |
+ !ifname_map->ifname) {
|
|
|
049c96 |
+ free(ifname_map->ifname);
|
|
|
049c96 |
+ free(ifname_map->dev_name);
|
|
|
049c96 |
+ free(ifname_map->bus_name);
|
|
|
049c96 |
+ free(ifname_map);
|
|
|
049c96 |
+ return NULL;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ return ifname_map;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void ifname_map_free(struct ifname_map *ifname_map)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ free(ifname_map->ifname);
|
|
|
049c96 |
+ free(ifname_map->dev_name);
|
|
|
049c96 |
+ free(ifname_map->bus_name);
|
|
|
049c96 |
+ free(ifname_map);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+struct dl {
|
|
|
049c96 |
+ struct mnlg_socket *nlg;
|
|
|
049c96 |
+ struct list_head ifname_map_list;
|
|
|
049c96 |
+ int argc;
|
|
|
049c96 |
+ char **argv;
|
|
|
049c96 |
+};
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int dl_argc(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ return dl->argc;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static char *dl_argv(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ if (dl_argc(dl) == 0)
|
|
|
049c96 |
+ return NULL;
|
|
|
049c96 |
+ return *dl->argv;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void dl_arg_inc(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ if (dl_argc(dl) == 0)
|
|
|
049c96 |
+ return;
|
|
|
049c96 |
+ dl->argc--;
|
|
|
049c96 |
+ dl->argv++;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static char *dl_argv_next(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ char *ret;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (dl_argc(dl) == 0)
|
|
|
049c96 |
+ return NULL;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ ret = *dl->argv;
|
|
|
049c96 |
+ dl_arg_inc(dl);
|
|
|
049c96 |
+ return ret;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static char *dl_argv_index(struct dl *dl, unsigned int index)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ if (index >= dl_argc(dl))
|
|
|
049c96 |
+ return NULL;
|
|
|
049c96 |
+ return dl->argv[index];
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int strcmpx(const char *str1, const char *str2)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ if (strlen(str1) > strlen(str2))
|
|
|
049c96 |
+ return -1;
|
|
|
049c96 |
+ return strncmp(str1, str2, strlen(str1));
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static bool dl_argv_match(struct dl *dl, const char *pattern)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ if (dl_argc(dl) == 0)
|
|
|
049c96 |
+ return false;
|
|
|
049c96 |
+ return strcmpx(dl_argv(dl), pattern) == 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static bool dl_no_arg(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ return dl_argc(dl) == 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int attr_cb(const struct nlattr *attr, void *data)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ const struct nlattr **tb = data;
|
|
|
049c96 |
+ int type;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ type = mnl_attr_get_type(attr);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (mnl_attr_type_valid(attr, DEVLINK_ATTR_MAX) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (type == DEVLINK_ATTR_BUS_NAME &&
|
|
|
049c96 |
+ mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ if (type == DEVLINK_ATTR_DEV_NAME &&
|
|
|
049c96 |
+ mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ if (type == DEVLINK_ATTR_PORT_INDEX &&
|
|
|
049c96 |
+ mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ if (type == DEVLINK_ATTR_PORT_TYPE &&
|
|
|
049c96 |
+ mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ if (type == DEVLINK_ATTR_PORT_DESIRED_TYPE &&
|
|
|
049c96 |
+ mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ if (type == DEVLINK_ATTR_PORT_NETDEV_IFINDEX &&
|
|
|
049c96 |
+ mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ if (type == DEVLINK_ATTR_PORT_NETDEV_NAME &&
|
|
|
049c96 |
+ mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ if (type == DEVLINK_ATTR_PORT_IBDEV_NAME &&
|
|
|
049c96 |
+ mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ tb[type] = attr;
|
|
|
049c96 |
+ return MNL_CB_OK;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int ifname_map_cb(const struct nlmsghdr *nlh, void *data)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
|
|
|
049c96 |
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
|
|
|
049c96 |
+ struct dl *dl = data;
|
|
|
049c96 |
+ struct ifname_map *ifname_map;
|
|
|
049c96 |
+ const char *bus_name;
|
|
|
049c96 |
+ const char *dev_name;
|
|
|
049c96 |
+ uint32_t port_ifindex;
|
|
|
049c96 |
+ const char *port_ifname;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
|
|
|
049c96 |
+ if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
|
|
|
049c96 |
+ !tb[DEVLINK_ATTR_PORT_INDEX])
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (!tb[DEVLINK_ATTR_PORT_NETDEV_NAME])
|
|
|
049c96 |
+ return MNL_CB_OK;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ bus_name = mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]);
|
|
|
049c96 |
+ dev_name = mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]);
|
|
|
049c96 |
+ port_ifindex = mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_INDEX]);
|
|
|
049c96 |
+ port_ifname = mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_NETDEV_NAME]);
|
|
|
049c96 |
+ ifname_map = ifname_map_alloc(bus_name, dev_name,
|
|
|
049c96 |
+ port_ifindex, port_ifname);
|
|
|
049c96 |
+ if (!ifname_map)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ list_add(&ifname_map->list, &dl->ifname_map_list);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ return MNL_CB_OK;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void ifname_map_fini(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct ifname_map *ifname_map, *tmp;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ list_for_each_entry_safe(ifname_map, tmp,
|
|
|
049c96 |
+ &dl->ifname_map_list, list) {
|
|
|
049c96 |
+ list_del(&ifname_map->list);
|
|
|
049c96 |
+ ifname_map_free(ifname_map);
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int ifname_map_init(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct nlmsghdr *nlh;
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ INIT_LIST_HEAD(&dl->ifname_map_list);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_GET,
|
|
|
049c96 |
+ NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = _mnlg_socket_sndrcv(dl->nlg, nlh, ifname_map_cb, dl);
|
|
|
049c96 |
+ if (err) {
|
|
|
049c96 |
+ ifname_map_fini(dl);
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int ifname_map_lookup(struct dl *dl, const char *ifname,
|
|
|
049c96 |
+ char **p_bus_name, char **p_dev_name,
|
|
|
049c96 |
+ uint32_t *p_port_index)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct ifname_map *ifname_map;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ list_for_each_entry(ifname_map, &dl->ifname_map_list, list) {
|
|
|
049c96 |
+ if (strcmp(ifname, ifname_map->ifname) == 0) {
|
|
|
049c96 |
+ *p_bus_name = ifname_map->bus_name;
|
|
|
049c96 |
+ *p_dev_name = ifname_map->dev_name;
|
|
|
049c96 |
+ *p_port_index = ifname_map->port_index;
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ return -ENOENT;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static unsigned int strslashcount(char *str)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ unsigned int count = 0;
|
|
|
049c96 |
+ char *pos = str;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ while ((pos = strchr(pos, '/'))) {
|
|
|
049c96 |
+ count++;
|
|
|
049c96 |
+ pos++;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ return count;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int strslashrsplit(char *str, char **before, char **after)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ char *slash;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ slash = strrchr(str, '/');
|
|
|
049c96 |
+ if (!slash)
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ *slash = '\0';
|
|
|
049c96 |
+ *before = str;
|
|
|
049c96 |
+ *after = slash + 1;
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int strtouint32_t(const char *str, uint32_t *p_val)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ char *endptr;
|
|
|
049c96 |
+ unsigned long int val;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ val = strtoul(str, &endptr, 10);
|
|
|
049c96 |
+ if (endptr == str || *endptr != '\0')
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ if (val > UINT_MAX)
|
|
|
049c96 |
+ return -ERANGE;
|
|
|
049c96 |
+ *p_val = val;
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int dl_argv_put_handle(struct nlmsghdr *nlh, struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ char *str = dl_argv_next(dl);
|
|
|
049c96 |
+ char *bus_name = bus_name;
|
|
|
049c96 |
+ char *dev_name = dev_name;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (!str) {
|
|
|
049c96 |
+ pr_err("Devlink identification (\"bus_name/dev_name\") expected\n");
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ if (strslashcount(str) != 1) {
|
|
|
049c96 |
+ pr_err("Wrong devlink identification string format.\n");
|
|
|
049c96 |
+ pr_err("Expected \"bus_name/dev_name\".\n");
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ strslashrsplit(str, &bus_name, &dev_name);
|
|
|
049c96 |
+ mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, bus_name);
|
|
|
049c96 |
+ mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, dev_name);
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int dl_argv_put_handle_port(struct nlmsghdr *nlh, struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ char *str = dl_argv_next(dl);
|
|
|
049c96 |
+ unsigned int slash_count;
|
|
|
049c96 |
+ char *bus_name = bus_name;
|
|
|
049c96 |
+ char *dev_name = dev_name;
|
|
|
049c96 |
+ uint32_t port_index = port_index;
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (!str) {
|
|
|
049c96 |
+ pr_err("Port identification (\"bus_name/dev_name/port_index\" or \"netdev ifname\") expected.\n");
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ slash_count = strslashcount(str);
|
|
|
049c96 |
+ if (slash_count != 2 && slash_count != 0) {
|
|
|
049c96 |
+ pr_err("Wrong port identification string format.\n");
|
|
|
049c96 |
+ pr_err("Expected \"bus_name/dev_name/port_index\" or \"netdev_ifname\".\n");
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (slash_count == 2) {
|
|
|
049c96 |
+ char *handlestr = handlestr;
|
|
|
049c96 |
+ char *portstr = portstr;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = strslashrsplit(str, &handlestr, &portstr);
|
|
|
049c96 |
+ err = strtouint32_t(portstr, &port_index);
|
|
|
049c96 |
+ if (err) {
|
|
|
049c96 |
+ pr_err("Port index \"%s\" is not a number or not within range\n",
|
|
|
049c96 |
+ portstr);
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ strslashrsplit(handlestr, &bus_name, &dev_name);
|
|
|
049c96 |
+ } else if (slash_count == 0) {
|
|
|
049c96 |
+ err = ifname_map_lookup(dl, str, &bus_name, &dev_name,
|
|
|
049c96 |
+ &port_index);
|
|
|
049c96 |
+ if (err) {
|
|
|
049c96 |
+ pr_err("Netdevice \"%s\" not found\n", str);
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, bus_name);
|
|
|
049c96 |
+ mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, dev_name);
|
|
|
049c96 |
+ mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, port_index);
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int dl_argv_uint32_t(struct dl *dl, uint32_t *p_val)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ char *str = dl_argv_next(dl);
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (!str) {
|
|
|
049c96 |
+ pr_err("Unsigned number argument expected\n");
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = strtouint32_t(str, p_val);
|
|
|
049c96 |
+ if (err) {
|
|
|
049c96 |
+ pr_err("\"%s\" is not a number or not within range\n", str);
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int dl_argv_str(struct dl *dl, const char **p_str)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ const char *str = dl_argv_next(dl);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (!str) {
|
|
|
049c96 |
+ pr_err("String parameter expected\n");
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ *p_str = str;
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int port_type_get(const char *typestr, enum devlink_port_type *p_type)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ if (strcmp(typestr, "auto") == 0) {
|
|
|
049c96 |
+ *p_type = DEVLINK_PORT_TYPE_AUTO;
|
|
|
049c96 |
+ } else if (strcmp(typestr, "eth") == 0) {
|
|
|
049c96 |
+ *p_type = DEVLINK_PORT_TYPE_ETH;
|
|
|
049c96 |
+ } else if (strcmp(typestr, "ib") == 0) {
|
|
|
049c96 |
+ *p_type = DEVLINK_PORT_TYPE_IB;
|
|
|
049c96 |
+ } else {
|
|
|
049c96 |
+ pr_err("Unknown port type \"%s\"\n", typestr);
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+#define BIT(nr) (1UL << (nr))
|
|
|
049c96 |
+#define DL_OPT_HANDLE BIT(0)
|
|
|
049c96 |
+#define DL_OPT_HANDLEP BIT(1)
|
|
|
049c96 |
+#define DL_OPT_PORT_TYPE BIT(2)
|
|
|
049c96 |
+#define DL_OPT_PORT_COUNT BIT(3)
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
|
|
|
049c96 |
+ uint32_t o_required, uint32_t o_optional)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ uint32_t o_all = o_required | o_optional;
|
|
|
049c96 |
+ uint32_t o_found = 0;
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (o_required & DL_OPT_HANDLE) {
|
|
|
049c96 |
+ err = dl_argv_put_handle(nlh, dl);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ } else if (o_required & DL_OPT_HANDLEP) {
|
|
|
049c96 |
+ err = dl_argv_put_handle_port(nlh, dl);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ while (dl_argc(dl)) {
|
|
|
049c96 |
+ if (dl_argv_match(dl, "type") &&
|
|
|
049c96 |
+ (o_all & DL_OPT_PORT_TYPE)) {
|
|
|
049c96 |
+ enum devlink_port_type port_type;
|
|
|
049c96 |
+ const char *typestr;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ dl_arg_inc(dl);
|
|
|
049c96 |
+ err = dl_argv_str(dl, &typestr);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ err = port_type_get(typestr, &port_type);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ mnl_attr_put_u16(nlh, DEVLINK_ATTR_PORT_TYPE,
|
|
|
049c96 |
+ port_type);
|
|
|
049c96 |
+ o_found |= DL_OPT_PORT_TYPE;
|
|
|
049c96 |
+ } else if (dl_argv_match(dl, "count") &&
|
|
|
049c96 |
+ (o_all & DL_OPT_PORT_COUNT)) {
|
|
|
049c96 |
+ uint32_t count;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ dl_arg_inc(dl);
|
|
|
049c96 |
+ err = dl_argv_uint32_t(dl, &count);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_SPLIT_COUNT,
|
|
|
049c96 |
+ count);
|
|
|
049c96 |
+ o_found |= DL_OPT_PORT_COUNT;
|
|
|
049c96 |
+ } else {
|
|
|
049c96 |
+ pr_err("Unknown option \"%s\"\n", dl_argv(dl));
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if ((o_required & DL_OPT_PORT_TYPE) && !(o_found & DL_OPT_PORT_TYPE)) {
|
|
|
049c96 |
+ pr_err("Port type option expected.\n");
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if ((o_required & DL_OPT_PORT_COUNT) &&
|
|
|
049c96 |
+ !(o_found & DL_OPT_PORT_COUNT)) {
|
|
|
049c96 |
+ pr_err("Port split count option expected.\n");
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void cmd_dev_help(void)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ pr_out("Usage: devlink dev show [ DEV ]\n");
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void pr_out_handle(struct nlattr **tb)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ pr_out("%s/%s", mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]),
|
|
|
049c96 |
+ mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]));
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void pr_out_dev(struct nlattr **tb)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ pr_out_handle(tb);
|
|
|
049c96 |
+ pr_out("\n");
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
|
|
|
049c96 |
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
|
|
|
049c96 |
+ if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ pr_out_dev(tb);
|
|
|
049c96 |
+ return MNL_CB_OK;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int cmd_dev_show(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct nlmsghdr *nlh;
|
|
|
049c96 |
+ uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (dl_argc(dl) == 0)
|
|
|
049c96 |
+ flags |= NLM_F_DUMP;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_GET, flags);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (dl_argc(dl) > 0) {
|
|
|
049c96 |
+ err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ return _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_show_cb, NULL);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int cmd_dev(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ if (dl_argv_match(dl, "help")) {
|
|
|
049c96 |
+ cmd_dev_help();
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+ } else if (dl_argv_match(dl, "show") ||
|
|
|
049c96 |
+ dl_argv_match(dl, "list") || dl_no_arg(dl)) {
|
|
|
049c96 |
+ dl_arg_inc(dl);
|
|
|
049c96 |
+ return cmd_dev_show(dl);
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ pr_err("Command \"%s\" not found\n", dl_argv(dl));
|
|
|
049c96 |
+ return -ENOENT;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void cmd_port_help(void)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ pr_out("Usage: devlink port show [ DEV/PORT_INDEX ]\n");
|
|
|
049c96 |
+ pr_out(" dl port set DEV/PORT_INDEX [ type { eth | ib | auto} ]\n");
|
|
|
049c96 |
+ pr_out(" dl port split DEV/PORT_INDEX count COUNT\n");
|
|
|
049c96 |
+ pr_out(" dl port unsplit DEV/PORT_INDEX\n");
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static const char *port_type_name(uint32_t type)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ switch (type) {
|
|
|
049c96 |
+ case DEVLINK_PORT_TYPE_NOTSET: return "notset";
|
|
|
049c96 |
+ case DEVLINK_PORT_TYPE_AUTO: return "auto";
|
|
|
049c96 |
+ case DEVLINK_PORT_TYPE_ETH: return "eth";
|
|
|
049c96 |
+ case DEVLINK_PORT_TYPE_IB: return "ib";
|
|
|
049c96 |
+ default: return "<unknown type>";
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void pr_out_port(struct nlattr **tb)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct nlattr *pt_attr = tb[DEVLINK_ATTR_PORT_TYPE];
|
|
|
049c96 |
+ struct nlattr *dpt_attr = tb[DEVLINK_ATTR_PORT_DESIRED_TYPE];
|
|
|
049c96 |
+
|
|
|
049c96 |
+ pr_out_handle(tb);
|
|
|
049c96 |
+ pr_out("/%d:", mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_INDEX]));
|
|
|
049c96 |
+ if (pt_attr) {
|
|
|
049c96 |
+ uint16_t port_type = mnl_attr_get_u16(pt_attr);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ pr_out(" type %s", port_type_name(port_type));
|
|
|
049c96 |
+ if (dpt_attr) {
|
|
|
049c96 |
+ uint16_t des_port_type = mnl_attr_get_u16(dpt_attr);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (port_type != des_port_type)
|
|
|
049c96 |
+ pr_out("(%s)", port_type_name(des_port_type));
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ if (tb[DEVLINK_ATTR_PORT_NETDEV_NAME])
|
|
|
049c96 |
+ pr_out(" netdev %s",
|
|
|
049c96 |
+ mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_NETDEV_NAME]));
|
|
|
049c96 |
+ if (tb[DEVLINK_ATTR_PORT_IBDEV_NAME])
|
|
|
049c96 |
+ pr_out(" ibdev %s",
|
|
|
049c96 |
+ mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_IBDEV_NAME]));
|
|
|
049c96 |
+ if (tb[DEVLINK_ATTR_PORT_SPLIT_GROUP])
|
|
|
049c96 |
+ pr_out(" split_group %u",
|
|
|
049c96 |
+ mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_SPLIT_GROUP]));
|
|
|
049c96 |
+ pr_out("\n");
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int cmd_port_show_cb(const struct nlmsghdr *nlh, void *data)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
|
|
|
049c96 |
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
|
|
|
049c96 |
+ if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
|
|
|
049c96 |
+ !tb[DEVLINK_ATTR_PORT_INDEX])
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ pr_out_port(tb);
|
|
|
049c96 |
+ return MNL_CB_OK;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int cmd_port_show(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct nlmsghdr *nlh;
|
|
|
049c96 |
+ uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (dl_argc(dl) == 0)
|
|
|
049c96 |
+ flags |= NLM_F_DUMP;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_GET, flags);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (dl_argc(dl) > 0) {
|
|
|
049c96 |
+ err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP, 0);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ return _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_port_show_cb, NULL);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int cmd_port_set(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct nlmsghdr *nlh;
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_SET,
|
|
|
049c96 |
+ NLM_F_REQUEST | NLM_F_ACK);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_PORT_TYPE, 0);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int cmd_port_split(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct nlmsghdr *nlh;
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_SPLIT,
|
|
|
049c96 |
+ NLM_F_REQUEST | NLM_F_ACK);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_PORT_COUNT, 0);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int cmd_port_unsplit(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct nlmsghdr *nlh;
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_UNSPLIT,
|
|
|
049c96 |
+ NLM_F_REQUEST | NLM_F_ACK);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP, 0);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int cmd_port(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ if (dl_argv_match(dl, "help")) {
|
|
|
049c96 |
+ cmd_port_help();
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+ } else if (dl_argv_match(dl, "show") ||
|
|
|
049c96 |
+ dl_argv_match(dl, "list") || dl_no_arg(dl)) {
|
|
|
049c96 |
+ dl_arg_inc(dl);
|
|
|
049c96 |
+ return cmd_port_show(dl);
|
|
|
049c96 |
+ } else if (dl_argv_match(dl, "set")) {
|
|
|
049c96 |
+ dl_arg_inc(dl);
|
|
|
049c96 |
+ return cmd_port_set(dl);
|
|
|
049c96 |
+ } else if (dl_argv_match(dl, "split")) {
|
|
|
049c96 |
+ dl_arg_inc(dl);
|
|
|
049c96 |
+ return cmd_port_split(dl);
|
|
|
049c96 |
+ } else if (dl_argv_match(dl, "unsplit")) {
|
|
|
049c96 |
+ dl_arg_inc(dl);
|
|
|
049c96 |
+ return cmd_port_unsplit(dl);
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ pr_err("Command \"%s\" not found\n", dl_argv(dl));
|
|
|
049c96 |
+ return -ENOENT;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static const char *cmd_name(uint8_t cmd)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ switch (cmd) {
|
|
|
049c96 |
+ case DEVLINK_CMD_UNSPEC: return "unspec";
|
|
|
049c96 |
+ case DEVLINK_CMD_GET: return "get";
|
|
|
049c96 |
+ case DEVLINK_CMD_SET: return "set";
|
|
|
049c96 |
+ case DEVLINK_CMD_NEW: return "new";
|
|
|
049c96 |
+ case DEVLINK_CMD_DEL: return "del";
|
|
|
049c96 |
+ case DEVLINK_CMD_PORT_GET: return "get";
|
|
|
049c96 |
+ case DEVLINK_CMD_PORT_SET: return "set";
|
|
|
049c96 |
+ case DEVLINK_CMD_PORT_NEW: return "net";
|
|
|
049c96 |
+ case DEVLINK_CMD_PORT_DEL: return "del";
|
|
|
049c96 |
+ default: return "<unknown cmd>";
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static const char *cmd_obj(uint8_t cmd)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ switch (cmd) {
|
|
|
049c96 |
+ case DEVLINK_CMD_UNSPEC: return "unspec";
|
|
|
049c96 |
+ case DEVLINK_CMD_GET:
|
|
|
049c96 |
+ case DEVLINK_CMD_SET:
|
|
|
049c96 |
+ case DEVLINK_CMD_NEW:
|
|
|
049c96 |
+ case DEVLINK_CMD_DEL:
|
|
|
049c96 |
+ return "dev";
|
|
|
049c96 |
+ case DEVLINK_CMD_PORT_GET:
|
|
|
049c96 |
+ case DEVLINK_CMD_PORT_SET:
|
|
|
049c96 |
+ case DEVLINK_CMD_PORT_NEW:
|
|
|
049c96 |
+ case DEVLINK_CMD_PORT_DEL:
|
|
|
049c96 |
+ return "port";
|
|
|
049c96 |
+ default: return "<unknown obj>";
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void pr_out_mon_header(uint8_t cmd)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ pr_out("[%s,%s] ", cmd_obj(cmd), cmd_name(cmd));
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static bool cmd_filter_check(struct dl *dl, uint8_t cmd)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ const char *obj = cmd_obj(cmd);
|
|
|
049c96 |
+ unsigned int index = 0;
|
|
|
049c96 |
+ const char *cur_obj;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (dl_no_arg(dl))
|
|
|
049c96 |
+ return true;
|
|
|
049c96 |
+ while ((cur_obj = dl_argv_index(dl, index++))) {
|
|
|
049c96 |
+ if (strcmp(cur_obj, obj) == 0 || strcmp(cur_obj, "all") == 0)
|
|
|
049c96 |
+ return true;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ return false;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct dl *dl = data;
|
|
|
049c96 |
+ struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
|
|
|
049c96 |
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
|
|
|
049c96 |
+ uint8_t cmd = genl->cmd;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (!cmd_filter_check(dl, cmd))
|
|
|
049c96 |
+ return MNL_CB_OK;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ switch (cmd) {
|
|
|
049c96 |
+ case DEVLINK_CMD_GET: /* fall through */
|
|
|
049c96 |
+ case DEVLINK_CMD_SET: /* fall through */
|
|
|
049c96 |
+ case DEVLINK_CMD_NEW: /* fall through */
|
|
|
049c96 |
+ case DEVLINK_CMD_DEL:
|
|
|
049c96 |
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
|
|
|
049c96 |
+ if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ pr_out_mon_header(genl->cmd);
|
|
|
049c96 |
+ pr_out_dev(tb);
|
|
|
049c96 |
+ break;
|
|
|
049c96 |
+ case DEVLINK_CMD_PORT_GET: /* fall through */
|
|
|
049c96 |
+ case DEVLINK_CMD_PORT_SET: /* fall through */
|
|
|
049c96 |
+ case DEVLINK_CMD_PORT_NEW: /* fall through */
|
|
|
049c96 |
+ case DEVLINK_CMD_PORT_DEL:
|
|
|
049c96 |
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
|
|
|
049c96 |
+ if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
|
|
|
049c96 |
+ !tb[DEVLINK_ATTR_PORT_INDEX])
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ pr_out_mon_header(genl->cmd);
|
|
|
049c96 |
+ pr_out_port(tb);
|
|
|
049c96 |
+ break;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ return MNL_CB_OK;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int cmd_mon_show(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+ unsigned int index = 0;
|
|
|
049c96 |
+ const char *cur_obj;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ while ((cur_obj = dl_argv_index(dl, index++))) {
|
|
|
049c96 |
+ if (strcmp(cur_obj, "all") != 0 &&
|
|
|
049c96 |
+ strcmp(cur_obj, "dev") != 0 &&
|
|
|
049c96 |
+ strcmp(cur_obj, "port") != 0) {
|
|
|
049c96 |
+ pr_err("Unknown object \"%s\"\n", cur_obj);
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ err = _mnlg_socket_group_add(dl->nlg, DEVLINK_GENL_MCGRP_CONFIG_NAME);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ err = _mnlg_socket_recv_run(dl->nlg, cmd_mon_show_cb, dl);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void cmd_mon_help(void)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ pr_out("Usage: devlink monitor [ all | OBJECT-LIST ]\n"
|
|
|
049c96 |
+ "where OBJECT-LIST := { dev | port }\n");
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int cmd_mon(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ if (dl_argv_match(dl, "help")) {
|
|
|
049c96 |
+ cmd_mon_help();
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+ } else if (dl_no_arg(dl)) {
|
|
|
049c96 |
+ dl_arg_inc(dl);
|
|
|
049c96 |
+ return cmd_mon_show(dl);
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ pr_err("Command \"%s\" not found\n", dl_argv(dl));
|
|
|
049c96 |
+ return -ENOENT;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void help(void)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ pr_out("Usage: devlink [ OPTIONS ] OBJECT { COMMAND | help }\n"
|
|
|
049c96 |
+ "where OBJECT := { dev | port | monitor }\n"
|
|
|
049c96 |
+ " OPTIONS := { -V[ersion] }\n");
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int dl_cmd(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
|
|
|
049c96 |
+ help();
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+ } else if (dl_argv_match(dl, "dev")) {
|
|
|
049c96 |
+ dl_arg_inc(dl);
|
|
|
049c96 |
+ return cmd_dev(dl);
|
|
|
049c96 |
+ } else if (dl_argv_match(dl, "port")) {
|
|
|
049c96 |
+ dl_arg_inc(dl);
|
|
|
049c96 |
+ return cmd_port(dl);
|
|
|
049c96 |
+ } else if (dl_argv_match(dl, "monitor")) {
|
|
|
049c96 |
+ dl_arg_inc(dl);
|
|
|
049c96 |
+ return cmd_mon(dl);
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ pr_err("Object \"%s\" not found\n", dl_argv(dl));
|
|
|
049c96 |
+ return -ENOENT;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int dl_init(struct dl *dl, int argc, char **argv)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ dl->argc = argc;
|
|
|
049c96 |
+ dl->argv = argv;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ dl->nlg = mnlg_socket_open(DEVLINK_GENL_NAME, DEVLINK_GENL_VERSION);
|
|
|
049c96 |
+ if (!dl->nlg) {
|
|
|
049c96 |
+ pr_err("Failed to connect to devlink Netlink\n");
|
|
|
049c96 |
+ return -errno;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = ifname_map_init(dl);
|
|
|
049c96 |
+ if (err) {
|
|
|
049c96 |
+ pr_err("Failed to create index map\n");
|
|
|
049c96 |
+ goto err_ifname_map_create;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+
|
|
|
049c96 |
+err_ifname_map_create:
|
|
|
049c96 |
+ mnlg_socket_close(dl->nlg);
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void dl_fini(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ ifname_map_fini(dl);
|
|
|
049c96 |
+ mnlg_socket_close(dl->nlg);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static struct dl *dl_alloc(void)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct dl *dl;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ dl = calloc(1, sizeof(*dl));
|
|
|
049c96 |
+ if (!dl)
|
|
|
049c96 |
+ return NULL;
|
|
|
049c96 |
+ return dl;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void dl_free(struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ free(dl);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+int main(int argc, char **argv)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ static const struct option long_options[] = {
|
|
|
049c96 |
+ { "Version", no_argument, NULL, 'V' },
|
|
|
049c96 |
+ { NULL, 0, NULL, 0 }
|
|
|
049c96 |
+ };
|
|
|
049c96 |
+ struct dl *dl;
|
|
|
049c96 |
+ int opt;
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+ int ret;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ while ((opt = getopt_long(argc, argv, "V",
|
|
|
049c96 |
+ long_options, NULL)) >= 0) {
|
|
|
049c96 |
+
|
|
|
049c96 |
+ switch (opt) {
|
|
|
049c96 |
+ case 'V':
|
|
|
049c96 |
+ printf("devlink utility, iproute2-ss%s\n", SNAPSHOT);
|
|
|
049c96 |
+ return EXIT_SUCCESS;
|
|
|
049c96 |
+ default:
|
|
|
049c96 |
+ pr_err("Unknown option.\n");
|
|
|
049c96 |
+ help();
|
|
|
049c96 |
+ return EXIT_FAILURE;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ argc -= optind;
|
|
|
049c96 |
+ argv += optind;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ dl = dl_alloc();
|
|
|
049c96 |
+ if (!dl) {
|
|
|
049c96 |
+ pr_err("Failed to allocate memory for devlink\n");
|
|
|
049c96 |
+ return EXIT_FAILURE;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = dl_init(dl, argc, argv);
|
|
|
049c96 |
+ if (err) {
|
|
|
049c96 |
+ ret = EXIT_FAILURE;
|
|
|
049c96 |
+ goto dl_free;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = dl_cmd(dl);
|
|
|
049c96 |
+ if (err) {
|
|
|
049c96 |
+ ret = EXIT_FAILURE;
|
|
|
049c96 |
+ goto dl_fini;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ ret = EXIT_SUCCESS;
|
|
|
049c96 |
+
|
|
|
049c96 |
+dl_fini:
|
|
|
049c96 |
+ dl_fini(dl);
|
|
|
049c96 |
+dl_free:
|
|
|
049c96 |
+ dl_free(dl);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ return ret;
|
|
|
049c96 |
+}
|
|
|
049c96 |
diff --git a/devlink/mnlg.c b/devlink/mnlg.c
|
|
|
049c96 |
new file mode 100644
|
|
|
049c96 |
index 0000000..9e27de2
|
|
|
049c96 |
--- /dev/null
|
|
|
049c96 |
+++ b/devlink/mnlg.c
|
|
|
049c96 |
@@ -0,0 +1,274 @@
|
|
|
049c96 |
+/*
|
|
|
049c96 |
+ * mnlg.c Generic Netlink helpers for libmnl
|
|
|
049c96 |
+ *
|
|
|
049c96 |
+ * This program is free software; you can redistribute it and/or
|
|
|
049c96 |
+ * modify it under the terms of the GNU General Public License
|
|
|
049c96 |
+ * as published by the Free Software Foundation; either version
|
|
|
049c96 |
+ * 2 of the License, or (at your option) any later version.
|
|
|
049c96 |
+ *
|
|
|
049c96 |
+ * Authors: Jiri Pirko <jiri@mellanox.com>
|
|
|
049c96 |
+ */
|
|
|
049c96 |
+
|
|
|
049c96 |
+#include <stdlib.h>
|
|
|
049c96 |
+#include <stdbool.h>
|
|
|
049c96 |
+#include <string.h>
|
|
|
049c96 |
+#include <errno.h>
|
|
|
049c96 |
+#include <unistd.h>
|
|
|
049c96 |
+#include <time.h>
|
|
|
049c96 |
+#include <libmnl/libmnl.h>
|
|
|
049c96 |
+#include <linux/genetlink.h>
|
|
|
049c96 |
+
|
|
|
049c96 |
+#include "mnlg.h"
|
|
|
049c96 |
+
|
|
|
049c96 |
+struct mnlg_socket {
|
|
|
049c96 |
+ struct mnl_socket *nl;
|
|
|
049c96 |
+ char *buf;
|
|
|
049c96 |
+ uint32_t id;
|
|
|
049c96 |
+ uint8_t version;
|
|
|
049c96 |
+ unsigned int seq;
|
|
|
049c96 |
+ unsigned int portid;
|
|
|
049c96 |
+};
|
|
|
049c96 |
+
|
|
|
049c96 |
+static struct nlmsghdr *__mnlg_msg_prepare(struct mnlg_socket *nlg, uint8_t cmd,
|
|
|
049c96 |
+ uint16_t flags, uint32_t id,
|
|
|
049c96 |
+ uint8_t version)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct nlmsghdr *nlh;
|
|
|
049c96 |
+ struct genlmsghdr *genl;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlh = mnl_nlmsg_put_header(nlg->buf);
|
|
|
049c96 |
+ nlh->nlmsg_type = id;
|
|
|
049c96 |
+ nlh->nlmsg_flags = flags;
|
|
|
049c96 |
+ nlg->seq = time(NULL);
|
|
|
049c96 |
+ nlh->nlmsg_seq = nlg->seq;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ genl = mnl_nlmsg_put_extra_header(nlh, sizeof(struct genlmsghdr));
|
|
|
049c96 |
+ genl->cmd = cmd;
|
|
|
049c96 |
+ genl->version = version;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ return nlh;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+struct nlmsghdr *mnlg_msg_prepare(struct mnlg_socket *nlg, uint8_t cmd,
|
|
|
049c96 |
+ uint16_t flags)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ return __mnlg_msg_prepare(nlg, cmd, flags, nlg->id, nlg->version);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+int mnlg_socket_send(struct mnlg_socket *nlg, const struct nlmsghdr *nlh)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ return mnl_socket_sendto(nlg->nl, nlh, nlh->nlmsg_len);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+int mnlg_socket_recv_run(struct mnlg_socket *nlg, mnl_cb_t data_cb, void *data)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ do {
|
|
|
049c96 |
+ err = mnl_socket_recvfrom(nlg->nl, nlg->buf,
|
|
|
049c96 |
+ MNL_SOCKET_BUFFER_SIZE);
|
|
|
049c96 |
+ if (err <= 0)
|
|
|
049c96 |
+ break;
|
|
|
049c96 |
+ err = mnl_cb_run(nlg->buf, err, nlg->seq, nlg->portid,
|
|
|
049c96 |
+ data_cb, data);
|
|
|
049c96 |
+ } while (err > 0);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+struct group_info {
|
|
|
049c96 |
+ bool found;
|
|
|
049c96 |
+ uint32_t id;
|
|
|
049c96 |
+ const char *name;
|
|
|
049c96 |
+};
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int parse_mc_grps_cb(const struct nlattr *attr, void *data)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ const struct nlattr **tb = data;
|
|
|
049c96 |
+ int type = mnl_attr_get_type(attr);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (mnl_attr_type_valid(attr, CTRL_ATTR_MCAST_GRP_MAX) < 0)
|
|
|
049c96 |
+ return MNL_CB_OK;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ switch (type) {
|
|
|
049c96 |
+ case CTRL_ATTR_MCAST_GRP_ID:
|
|
|
049c96 |
+ if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ break;
|
|
|
049c96 |
+ case CTRL_ATTR_MCAST_GRP_NAME:
|
|
|
049c96 |
+ if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ break;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ tb[type] = attr;
|
|
|
049c96 |
+ return MNL_CB_OK;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void parse_genl_mc_grps(struct nlattr *nested,
|
|
|
049c96 |
+ struct group_info *group_info)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct nlattr *pos;
|
|
|
049c96 |
+ const char *name;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ mnl_attr_for_each_nested(pos, nested) {
|
|
|
049c96 |
+ struct nlattr *tb[CTRL_ATTR_MCAST_GRP_MAX + 1] = {};
|
|
|
049c96 |
+
|
|
|
049c96 |
+ mnl_attr_parse_nested(pos, parse_mc_grps_cb, tb);
|
|
|
049c96 |
+ if (!tb[CTRL_ATTR_MCAST_GRP_NAME] ||
|
|
|
049c96 |
+ !tb[CTRL_ATTR_MCAST_GRP_ID])
|
|
|
049c96 |
+ continue;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ name = mnl_attr_get_str(tb[CTRL_ATTR_MCAST_GRP_NAME]);
|
|
|
049c96 |
+ if (strcmp(name, group_info->name) != 0)
|
|
|
049c96 |
+ continue;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ group_info->id = mnl_attr_get_u32(tb[CTRL_ATTR_MCAST_GRP_ID]);
|
|
|
049c96 |
+ group_info->found = true;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int get_group_id_attr_cb(const struct nlattr *attr, void *data)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ const struct nlattr **tb = data;
|
|
|
049c96 |
+ int type = mnl_attr_get_type(attr);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (mnl_attr_type_valid(attr, CTRL_ATTR_MAX) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (type == CTRL_ATTR_MCAST_GROUPS &&
|
|
|
049c96 |
+ mnl_attr_validate(attr, MNL_TYPE_NESTED) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ tb[type] = attr;
|
|
|
049c96 |
+ return MNL_CB_OK;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int get_group_id_cb(const struct nlmsghdr *nlh, void *data)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct group_info *group_info = data;
|
|
|
049c96 |
+ struct nlattr *tb[CTRL_ATTR_MAX + 1] = {};
|
|
|
049c96 |
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ mnl_attr_parse(nlh, sizeof(*genl), get_group_id_attr_cb, tb);
|
|
|
049c96 |
+ if (!tb[CTRL_ATTR_MCAST_GROUPS])
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ parse_genl_mc_grps(tb[CTRL_ATTR_MCAST_GROUPS], group_info);
|
|
|
049c96 |
+ return MNL_CB_OK;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+int mnlg_socket_group_add(struct mnlg_socket *nlg, const char *group_name)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct nlmsghdr *nlh;
|
|
|
049c96 |
+ struct group_info group_info;
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlh = __mnlg_msg_prepare(nlg, CTRL_CMD_GETFAMILY,
|
|
|
049c96 |
+ NLM_F_REQUEST | NLM_F_ACK, GENL_ID_CTRL, 1);
|
|
|
049c96 |
+ mnl_attr_put_u32(nlh, CTRL_ATTR_FAMILY_ID, nlg->id);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = mnlg_socket_send(nlg, nlh);
|
|
|
049c96 |
+ if (err < 0)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ group_info.found = false;
|
|
|
049c96 |
+ group_info.name = group_name;
|
|
|
049c96 |
+ err = mnlg_socket_recv_run(nlg, get_group_id_cb, &group_info);
|
|
|
049c96 |
+ if (err < 0)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (!group_info.found) {
|
|
|
049c96 |
+ errno = ENOENT;
|
|
|
049c96 |
+ return -1;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = mnl_socket_setsockopt(nlg->nl, NETLINK_ADD_MEMBERSHIP,
|
|
|
049c96 |
+ &group_info.id, sizeof(group_info.id));
|
|
|
049c96 |
+ if (err < 0)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int get_family_id_attr_cb(const struct nlattr *attr, void *data)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ const struct nlattr **tb = data;
|
|
|
049c96 |
+ int type = mnl_attr_get_type(attr);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (mnl_attr_type_valid(attr, CTRL_ATTR_MAX) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (type == CTRL_ATTR_FAMILY_ID &&
|
|
|
049c96 |
+ mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ tb[type] = attr;
|
|
|
049c96 |
+ return MNL_CB_OK;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int get_family_id_cb(const struct nlmsghdr *nlh, void *data)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ uint32_t *p_id = data;
|
|
|
049c96 |
+ struct nlattr *tb[CTRL_ATTR_MAX + 1] = {};
|
|
|
049c96 |
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ mnl_attr_parse(nlh, sizeof(*genl), get_family_id_attr_cb, tb);
|
|
|
049c96 |
+ if (!tb[CTRL_ATTR_FAMILY_ID])
|
|
|
049c96 |
+ return MNL_CB_ERROR;
|
|
|
049c96 |
+ *p_id = mnl_attr_get_u16(tb[CTRL_ATTR_FAMILY_ID]);
|
|
|
049c96 |
+ return MNL_CB_OK;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+struct mnlg_socket *mnlg_socket_open(const char *family_name, uint8_t version)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct mnlg_socket *nlg;
|
|
|
049c96 |
+ struct nlmsghdr *nlh;
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlg = malloc(sizeof(*nlg));
|
|
|
049c96 |
+ if (!nlg)
|
|
|
049c96 |
+ return NULL;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlg->buf = malloc(MNL_SOCKET_BUFFER_SIZE);
|
|
|
049c96 |
+ if (!nlg->buf)
|
|
|
049c96 |
+ goto err_buf_alloc;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlg->nl = mnl_socket_open(NETLINK_GENERIC);
|
|
|
049c96 |
+ if (!nlg->nl)
|
|
|
049c96 |
+ goto err_mnl_socket_open;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = mnl_socket_bind(nlg->nl, 0, MNL_SOCKET_AUTOPID);
|
|
|
049c96 |
+ if (err < 0)
|
|
|
049c96 |
+ goto err_mnl_socket_bind;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlg->portid = mnl_socket_get_portid(nlg->nl);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlh = __mnlg_msg_prepare(nlg, CTRL_CMD_GETFAMILY,
|
|
|
049c96 |
+ NLM_F_REQUEST | NLM_F_ACK, GENL_ID_CTRL, 1);
|
|
|
049c96 |
+ mnl_attr_put_strz(nlh, CTRL_ATTR_FAMILY_NAME, family_name);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = mnlg_socket_send(nlg, nlh);
|
|
|
049c96 |
+ if (err < 0)
|
|
|
049c96 |
+ goto err_mnlg_socket_send;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = mnlg_socket_recv_run(nlg, get_family_id_cb, &nlg->id);
|
|
|
049c96 |
+ if (err < 0)
|
|
|
049c96 |
+ goto err_mnlg_socket_recv_run;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ nlg->version = version;
|
|
|
049c96 |
+ return nlg;
|
|
|
049c96 |
+
|
|
|
049c96 |
+err_mnlg_socket_recv_run:
|
|
|
049c96 |
+err_mnlg_socket_send:
|
|
|
049c96 |
+err_mnl_socket_bind:
|
|
|
049c96 |
+ mnl_socket_close(nlg->nl);
|
|
|
049c96 |
+err_mnl_socket_open:
|
|
|
049c96 |
+ free(nlg->buf);
|
|
|
049c96 |
+err_buf_alloc:
|
|
|
049c96 |
+ free(nlg);
|
|
|
049c96 |
+ return NULL;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+void mnlg_socket_close(struct mnlg_socket *nlg)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ mnl_socket_close(nlg->nl);
|
|
|
049c96 |
+ free(nlg->buf);
|
|
|
049c96 |
+ free(nlg);
|
|
|
049c96 |
+}
|
|
|
049c96 |
diff --git a/devlink/mnlg.h b/devlink/mnlg.h
|
|
|
049c96 |
new file mode 100644
|
|
|
049c96 |
index 0000000..4d1babf
|
|
|
049c96 |
--- /dev/null
|
|
|
049c96 |
+++ b/devlink/mnlg.h
|
|
|
049c96 |
@@ -0,0 +1,27 @@
|
|
|
049c96 |
+/*
|
|
|
049c96 |
+ * mnlg.h Generic Netlink helpers for libmnl
|
|
|
049c96 |
+ *
|
|
|
049c96 |
+ * This program is free software; you can redistribute it and/or
|
|
|
049c96 |
+ * modify it under the terms of the GNU General Public License
|
|
|
049c96 |
+ * as published by the Free Software Foundation; either version
|
|
|
049c96 |
+ * 2 of the License, or (at your option) any later version.
|
|
|
049c96 |
+ *
|
|
|
049c96 |
+ * Authors: Jiri Pirko <jiri@mellanox.com>
|
|
|
049c96 |
+ */
|
|
|
049c96 |
+
|
|
|
049c96 |
+#ifndef _MNLG_H_
|
|
|
049c96 |
+#define _MNLG_H_
|
|
|
049c96 |
+
|
|
|
049c96 |
+#include <libmnl/libmnl.h>
|
|
|
049c96 |
+
|
|
|
049c96 |
+struct mnlg_socket;
|
|
|
049c96 |
+
|
|
|
049c96 |
+struct nlmsghdr *mnlg_msg_prepare(struct mnlg_socket *nlg, uint8_t cmd,
|
|
|
049c96 |
+ uint16_t flags);
|
|
|
049c96 |
+int mnlg_socket_send(struct mnlg_socket *nlg, const struct nlmsghdr *nlh);
|
|
|
049c96 |
+int mnlg_socket_recv_run(struct mnlg_socket *nlg, mnl_cb_t data_cb, void *data);
|
|
|
049c96 |
+int mnlg_socket_group_add(struct mnlg_socket *nlg, const char *group_name);
|
|
|
049c96 |
+struct mnlg_socket *mnlg_socket_open(const char *family_name, uint8_t version);
|
|
|
049c96 |
+void mnlg_socket_close(struct mnlg_socket *nlg);
|
|
|
049c96 |
+
|
|
|
049c96 |
+#endif /* _MNLG_H_ */
|
|
|
049c96 |
diff --git a/man/man8/devlink-dev.8 b/man/man8/devlink-dev.8
|
|
|
049c96 |
new file mode 100644
|
|
|
049c96 |
index 0000000..7878d89
|
|
|
049c96 |
--- /dev/null
|
|
|
049c96 |
+++ b/man/man8/devlink-dev.8
|
|
|
049c96 |
@@ -0,0 +1,58 @@
|
|
|
049c96 |
+.TH DEVLINK\-DEV 8 "14 Mar 2016" "iproute2" "Linux"
|
|
|
049c96 |
+.SH NAME
|
|
|
049c96 |
+devlink-dev \- devlink device configuration
|
|
|
049c96 |
+.SH SYNOPSIS
|
|
|
049c96 |
+.sp
|
|
|
049c96 |
+.ad l
|
|
|
049c96 |
+.in +8
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.B devlink
|
|
|
049c96 |
+.RI "[ " OPTIONS " ]"
|
|
|
049c96 |
+.B dev
|
|
|
049c96 |
+.RI " { " COMMAND " | "
|
|
|
049c96 |
+.BR help " }"
|
|
|
049c96 |
+.sp
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.IR OPTIONS " := { "
|
|
|
049c96 |
+\fB\-V\fR[\fIersion\fR] |
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.B devlink dev show
|
|
|
049c96 |
+.RI "[ " DEV " ]"
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.B devlink dev help
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH "DESCRIPTION"
|
|
|
049c96 |
+.SS devlink dev show - display devlink device attributes
|
|
|
049c96 |
+
|
|
|
049c96 |
+.PP
|
|
|
049c96 |
+.I "DEV"
|
|
|
049c96 |
+- specifies the devlink device to show.
|
|
|
049c96 |
+If this argument is omitted all devices are listed.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.in +4
|
|
|
049c96 |
+Format is:
|
|
|
049c96 |
+.in +2
|
|
|
049c96 |
+BUS_NAME/BUS_ADDRESS
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH "EXAMPLES"
|
|
|
049c96 |
+.PP
|
|
|
049c96 |
+devlink dev show
|
|
|
049c96 |
+.RS 4
|
|
|
049c96 |
+Shows the state of all devlink devices on the system.
|
|
|
049c96 |
+.RE
|
|
|
049c96 |
+.PP
|
|
|
049c96 |
+devlink dev show pci/0000:01:00.0
|
|
|
049c96 |
+.RS 4
|
|
|
049c96 |
+Shows the state of specified devlink device.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH SEE ALSO
|
|
|
049c96 |
+.BR devlink (8),
|
|
|
049c96 |
+.BR devlink-port (8),
|
|
|
049c96 |
+.BR devlink-monitor (8),
|
|
|
049c96 |
+.br
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH AUTHOR
|
|
|
049c96 |
+Jiri Pirko <jiri@mellanox.com>
|
|
|
049c96 |
diff --git a/man/man8/devlink-monitor.8 b/man/man8/devlink-monitor.8
|
|
|
049c96 |
new file mode 100644
|
|
|
049c96 |
index 0000000..98134c3
|
|
|
049c96 |
--- /dev/null
|
|
|
049c96 |
+++ b/man/man8/devlink-monitor.8
|
|
|
049c96 |
@@ -0,0 +1,36 @@
|
|
|
049c96 |
+.TH DEVLINK\-MONITOR 8 "14 Mar 2016" "iproute2" "Linux"
|
|
|
049c96 |
+.SH "NAME"
|
|
|
049c96 |
+devlink-monitor \- state monitoring
|
|
|
049c96 |
+.SH SYNOPSIS
|
|
|
049c96 |
+.sp
|
|
|
049c96 |
+.ad l
|
|
|
049c96 |
+.in +8
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.BR "devlink monitor" " [ " all " |"
|
|
|
049c96 |
+.IR OBJECT-LIST " ]"
|
|
|
049c96 |
+.sp
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH DESCRIPTION
|
|
|
049c96 |
+The
|
|
|
049c96 |
+.B devlink
|
|
|
049c96 |
+utility can monitor the state of devlink devices and ports
|
|
|
049c96 |
+continuously. This option has a slightly different format. Namely, the
|
|
|
049c96 |
+.B monitor
|
|
|
049c96 |
+command is the first in the command line and then the object list.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.I OBJECT-LIST
|
|
|
049c96 |
+is the list of object types that we want to monitor.
|
|
|
049c96 |
+It may contain
|
|
|
049c96 |
+.BR dev ", " port ".
|
|
|
049c96 |
+
|
|
|
049c96 |
+.B devlink
|
|
|
049c96 |
+opens Devlink Netlink socket, listens on it and dumps state changes.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH SEE ALSO
|
|
|
049c96 |
+.BR devlink (8),
|
|
|
049c96 |
+.BR devlink-dev (8),
|
|
|
049c96 |
+.BR devlink-port (8),
|
|
|
049c96 |
+.br
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH AUTHOR
|
|
|
049c96 |
+Jiri Pirko <jiri@mellanox.com>
|
|
|
049c96 |
diff --git a/man/man8/devlink-port.8 b/man/man8/devlink-port.8
|
|
|
049c96 |
new file mode 100644
|
|
|
049c96 |
index 0000000..e6ae686
|
|
|
049c96 |
--- /dev/null
|
|
|
049c96 |
+++ b/man/man8/devlink-port.8
|
|
|
049c96 |
@@ -0,0 +1,126 @@
|
|
|
049c96 |
+.TH DEVLINK\-PORT 8 "14 Mar 2016" "iproute2" "Linux"
|
|
|
049c96 |
+.SH NAME
|
|
|
049c96 |
+devlink-port \- devlink port configuration
|
|
|
049c96 |
+.SH SYNOPSIS
|
|
|
049c96 |
+.sp
|
|
|
049c96 |
+.ad l
|
|
|
049c96 |
+.in +8
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.B devlink
|
|
|
049c96 |
+.RI "[ " OPTIONS " ]"
|
|
|
049c96 |
+.B port
|
|
|
049c96 |
+.RI " { " COMMAND " | "
|
|
|
049c96 |
+.BR help " }"
|
|
|
049c96 |
+.sp
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.IR OPTIONS " := { "
|
|
|
049c96 |
+\fB\-V\fR[\fIersion\fR] |
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.BR "devlink port set "
|
|
|
049c96 |
+.IR DEV/PORT_INDEX
|
|
|
049c96 |
+.RI "[ "
|
|
|
049c96 |
+.BR type " { " eth " | " ib " | " auto " }"
|
|
|
049c96 |
+.RI "]"
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.BR "devlink port split "
|
|
|
049c96 |
+.IR DEV/PORT_INDEX
|
|
|
049c96 |
+.BR count
|
|
|
049c96 |
+.IR COUNT
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.BR "devlink port unsplit "
|
|
|
049c96 |
+.IR DEV/PORT_INDEX
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.B devlink port show
|
|
|
049c96 |
+.RI "[ " DEV/PORT_INDEX " ]"
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.B devlink port help
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH "DESCRIPTION"
|
|
|
049c96 |
+.SS devlink port set - change devlink port attributes
|
|
|
049c96 |
+
|
|
|
049c96 |
+.PP
|
|
|
049c96 |
+.B "DEV/PORT_INDEX"
|
|
|
049c96 |
+- specifies the devlink port to operate on.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.in +4
|
|
|
049c96 |
+Format is:
|
|
|
049c96 |
+.in +2
|
|
|
049c96 |
+BUS_NAME/BUS_ADDRESS/PORT_INDEX
|
|
|
049c96 |
+
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.BR type " { " eth " | " ib " | " auto " } "
|
|
|
049c96 |
+set port type
|
|
|
049c96 |
+
|
|
|
049c96 |
+.I eth
|
|
|
049c96 |
+- Ethernet
|
|
|
049c96 |
+
|
|
|
049c96 |
+.I ib
|
|
|
049c96 |
+- Infiniband
|
|
|
049c96 |
+
|
|
|
049c96 |
+.I auto
|
|
|
049c96 |
+- autoselect
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SS devlink port split - split devlink port into more
|
|
|
049c96 |
+
|
|
|
049c96 |
+.PP
|
|
|
049c96 |
+.B "DEV/PORT_INDEX"
|
|
|
049c96 |
+- specifies the devlink port to operate on.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.BI count " COUNT"
|
|
|
049c96 |
+number of ports to split to.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SS devlink port unsplit - unsplit previously split devlink port
|
|
|
049c96 |
+Could be performed on any split port of the same split group.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.PP
|
|
|
049c96 |
+.B "DEV/PORT_INDEX"
|
|
|
049c96 |
+- specifies the devlink port to operate on.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SS devlink port show - display devlink port attributes
|
|
|
049c96 |
+
|
|
|
049c96 |
+.PP
|
|
|
049c96 |
+.I "DEV/PORT_INDEX"
|
|
|
049c96 |
+- specifies the devlink port to show.
|
|
|
049c96 |
+If this argument is omitted all ports are listed.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH "EXAMPLES"
|
|
|
049c96 |
+.PP
|
|
|
049c96 |
+devlink port show
|
|
|
049c96 |
+.RS 4
|
|
|
049c96 |
+Shows the state of all devlink ports on the system.
|
|
|
049c96 |
+.RE
|
|
|
049c96 |
+.PP
|
|
|
049c96 |
+devlink port show pci/0000:01:00.0/1
|
|
|
049c96 |
+.RS 4
|
|
|
049c96 |
+Shows the state of specified devlink port.
|
|
|
049c96 |
+.RE
|
|
|
049c96 |
+.PP
|
|
|
049c96 |
+devlink port set pci/0000:01:00.0/1 type eth
|
|
|
049c96 |
+.RS 4
|
|
|
049c96 |
+Set type of specified devlink port to Ethernet.
|
|
|
049c96 |
+.RE
|
|
|
049c96 |
+.PP
|
|
|
049c96 |
+devlink port split pci/0000:01:00.0/1 count 4
|
|
|
049c96 |
+.RS 4
|
|
|
049c96 |
+Split the specified devlink port into four ports.
|
|
|
049c96 |
+.RE
|
|
|
049c96 |
+.PP
|
|
|
049c96 |
+devlink port unsplit pci/0000:01:00.0/1
|
|
|
049c96 |
+.RS 4
|
|
|
049c96 |
+Unplit the specified previously split devlink port.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH SEE ALSO
|
|
|
049c96 |
+.BR devlink (8),
|
|
|
049c96 |
+.BR devlink-dev (8),
|
|
|
049c96 |
+.BR devlink-monitor (8),
|
|
|
049c96 |
+.br
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH AUTHOR
|
|
|
049c96 |
+Jiri Pirko <jiri@mellanox.com>
|
|
|
049c96 |
diff --git a/man/man8/devlink.8 b/man/man8/devlink.8
|
|
|
049c96 |
new file mode 100644
|
|
|
049c96 |
index 0000000..f608ccc
|
|
|
049c96 |
--- /dev/null
|
|
|
049c96 |
+++ b/man/man8/devlink.8
|
|
|
049c96 |
@@ -0,0 +1,83 @@
|
|
|
049c96 |
+.TH DEVLINK 8 "14 Mar 2016" "iproute2" "Linux"
|
|
|
049c96 |
+.SH NAME
|
|
|
049c96 |
+devlink \- Devlink tool
|
|
|
049c96 |
+.SH SYNOPSIS
|
|
|
049c96 |
+.sp
|
|
|
049c96 |
+.ad l
|
|
|
049c96 |
+.in +8
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.B devlink
|
|
|
049c96 |
+.RI "[ " OPTIONS " ] " OBJECT " { " COMMAND " | "
|
|
|
049c96 |
+.BR help " }"
|
|
|
049c96 |
+.sp
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.IR OBJECT " := { "
|
|
|
049c96 |
+.BR dev " | " port " | " monitor " }"
|
|
|
049c96 |
+.sp
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.IR OPTIONS " := { "
|
|
|
049c96 |
+\fB\-V\fR[\fIersion\fR] |
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH OPTIONS
|
|
|
049c96 |
+
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.BR "\-V" , " -Version"
|
|
|
049c96 |
+Print the version of the
|
|
|
049c96 |
+.B devlink
|
|
|
049c96 |
+utility and exit.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SS
|
|
|
049c96 |
+.I OBJECT
|
|
|
049c96 |
+
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B dev
|
|
|
049c96 |
+- devlink device.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B port
|
|
|
049c96 |
+- devlink port.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B monitor
|
|
|
049c96 |
+- watch for netlink messages.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SS
|
|
|
049c96 |
+.I COMMAND
|
|
|
049c96 |
+
|
|
|
049c96 |
+Specifies the action to perform on the object.
|
|
|
049c96 |
+The set of possible actions depends on the object type.
|
|
|
049c96 |
+As a rule, it is possible to
|
|
|
049c96 |
+.B show
|
|
|
049c96 |
+(or
|
|
|
049c96 |
+.B list
|
|
|
049c96 |
+) objects, but some objects do not allow all of these operations
|
|
|
049c96 |
+or have some additional commands. The
|
|
|
049c96 |
+.B help
|
|
|
049c96 |
+command is available for all objects. It prints
|
|
|
049c96 |
+out a list of available commands and argument syntax conventions.
|
|
|
049c96 |
+.sp
|
|
|
049c96 |
+If no command is given, some default command is assumed.
|
|
|
049c96 |
+Usually it is
|
|
|
049c96 |
+.B list
|
|
|
049c96 |
+or, if the objects of this class cannot be listed,
|
|
|
049c96 |
+.BR "help" .
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH EXIT STATUS
|
|
|
049c96 |
+Exit status is 0 if command was successful or a positive integer upon failure.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH SEE ALSO
|
|
|
049c96 |
+.BR devlink-dev (8),
|
|
|
049c96 |
+.BR devlink-port (8),
|
|
|
049c96 |
+.BR devlink-monitor (8),
|
|
|
049c96 |
+.br
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH REPORTING BUGS
|
|
|
049c96 |
+Report any bugs to the Network Developers mailing list
|
|
|
049c96 |
+.B <netdev@vger.kernel.org>
|
|
|
049c96 |
+where the development and maintenance is primarily done.
|
|
|
049c96 |
+You do not have to be subscribed to the list to send a message there.
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH AUTHOR
|
|
|
049c96 |
+Jiri Pirko <jiri@mellanox.com>
|
|
|
049c96 |
--
|
|
|
049c96 |
1.8.3.1
|
|
|
049c96 |
|