Blame SOURCES/open-lldp-v1.0.1-1-VDP-vdp22_cmds-retrieve-vsi-paramenter-data.patch

89f6b3
From dff810b2e546eb74e8b9cebb7185ca5bcb5ecc9d Mon Sep 17 00:00:00 2001
89f6b3
From: Thomas Richter <tmricht@linux.vnet.ibm.com>
89f6b3
Date: Wed, 21 Jan 2015 03:35:59 +0000
89f6b3
Subject: [PATCH] VDP: vdp22_cmds retrieve vsi paramenter data
89f6b3
89f6b3
This patch adds support for the retrieval of the
89f6b3
vsi parameter data to a command line client.
89f6b3
89f6b3
Signed-off-by: Thomas Richter <tmricht@linux.vnet.ibm.com>
89f6b3
Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
89f6b3
---
89f6b3
 include/qbg_vdpnl.h |  1 +
89f6b3
 qbg/vdp22_cmds.c    | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
89f6b3
 2 files changed, 64 insertions(+)
89f6b3
89f6b3
diff --git a/include/qbg_vdpnl.h b/include/qbg_vdpnl.h
89f6b3
index 7b26bc7..510a20c 100644
89f6b3
--- a/include/qbg_vdpnl.h
89f6b3
+++ b/include/qbg_vdpnl.h
89f6b3
@@ -78,4 +78,5 @@ int event_trigger(struct nlmsghdr *, pid_t);
89f6b3
 int vdp_str2vdpnl(char *, struct vdpnl_vsi *, char *);
89f6b3
 int vdp_vdpnl2str(struct vdpnl_vsi *, char *, size_t);
89f6b3
 int vdp22_sendevent(struct vdpnl_vsi *);
89f6b3
+void vdp22_freemaclist(struct vdpnl_vsi *);
89f6b3
 #endif
89f6b3
diff --git a/qbg/vdp22_cmds.c b/qbg/vdp22_cmds.c
89f6b3
index a75c02d..f055441 100644
89f6b3
--- a/qbg/vdp22_cmds.c
89f6b3
+++ b/qbg/vdp22_cmds.c
89f6b3
@@ -471,10 +471,73 @@ static int test_arg_vsi(struct cmd *cmd, UNUSED char *arg, char *argvalue,
89f6b3
 	return set_arg_vsi2(cmd, argvalue, true);
89f6b3
 }
89f6b3
 
89f6b3
+/*
89f6b3
+ * Concatenate all VSI information into one string.
89f6b3
+ * Return length of string in bytes.
89f6b3
+ */
89f6b3
+static int catvsis(struct vdpnl_vsi *vsi, char *out, size_t out_len)
89f6b3
+{
89f6b3
+	int rc, i;
89f6b3
+	size_t used = 0;
89f6b3
+	unsigned char wanted_req = vsi->request;
89f6b3
+
89f6b3
+	for (i = 1; vdp22_status(i, vsi, 1) > 0; ++i) {
89f6b3
+		if (wanted_req != vsi->request) {
89f6b3
+			vdp22_freemaclist(vsi);
89f6b3
+			continue;
89f6b3
+		}
89f6b3
+		rc = vdp_vdpnl2str(vsi, out + used, out_len - used);
89f6b3
+		vdp22_freemaclist(vsi);
89f6b3
+		if (rc) {
89f6b3
+			strcat(out, ";");
89f6b3
+			used = strlen(out);
89f6b3
+		} else
89f6b3
+			return 0;
89f6b3
+	}
89f6b3
+	return used;
89f6b3
+}
89f6b3
+
89f6b3
+/*
89f6b3
+ * Return all VSIs on a particular interface into one string.
89f6b3
+ */
89f6b3
+static int get_arg_vsi(struct cmd *cmd, char *arg, UNUSED char *argvalue,
89f6b3
+		       char *obuf, int obuf_len)
89f6b3
+{
89f6b3
+	cmd_status good_cmd = vdp22_cmdok(cmd, cmd_gettlv);
89f6b3
+	struct vdpnl_vsi vsi;
89f6b3
+	char vsi_str[MAX_CLIF_MSGBUF];
89f6b3
+	int rc;
89f6b3
+
89f6b3
+	if (good_cmd != cmd_success)
89f6b3
+		return good_cmd;
89f6b3
+	if (!port_find_by_ifindex(get_ifidx(cmd->ifname)))
89f6b3
+		return cmd_device_not_found;
89f6b3
+	good_cmd = ifok(cmd);
89f6b3
+	if (good_cmd != cmd_success)
89f6b3
+		return good_cmd;
89f6b3
+
89f6b3
+	memset(obuf, 0, obuf_len);
89f6b3
+	memset(&vsi, 0, sizeof(vsi));
89f6b3
+	vsi.request = cmd->tlvid;
89f6b3
+	strncpy(vsi.ifname, cmd->ifname, sizeof(vsi.ifname) - 1);
89f6b3
+	good_cmd = cmd_failed;
89f6b3
+	if (!catvsis(&vsi, vsi_str, sizeof(vsi_str)))
89f6b3
+		goto out;
89f6b3
+	rc = snprintf(obuf, obuf_len, "%02x%s%04x%s",
89f6b3
+		 (unsigned int)strlen(arg), arg, (unsigned int)strlen(vsi_str),
89f6b3
+		 vsi_str);
89f6b3
+	if (rc > 0 || rc < obuf_len)
89f6b3
+		good_cmd = cmd_success;
89f6b3
+out:
89f6b3
+	return good_cmd;
89f6b3
+}
89f6b3
+
89f6b3
+
89f6b3
 static struct arg_handlers arg_handlers[] = {
89f6b3
 	{
89f6b3
 		.arg = ARG_VDP22_VSI,
89f6b3
 		.arg_class = TLV_ARG,
89f6b3
+		.handle_get = get_arg_vsi,
89f6b3
 		.handle_set = set_arg_vsi,
89f6b3
 		.handle_test = test_arg_vsi
89f6b3
 	},
89f6b3
-- 
89f6b3
2.1.0
89f6b3