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

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