[lldp-devel] [PATCH 2/2] vdp22 support variable number of VLAN/QoS returns

Thomas Richter tmricht at linux.vnet.ibm.com
Tue Nov 19 11:59:10 UTC 2013


Protocol vdp22 allows the switch to return vlan identifier and
quality of service (QoS) identiers to lldpad. Lldpad will receive
these values (if specified in the filter inforation section) and
return them to the originator.
Right now only one VLAN/QoS pair is supported. This patch allows
for a variable number of VLAN/QoS reception. Allocate enough
memory when the filter information is receved from the swich,
copy the information and forward it to the originater and finally
delete the memeory. This is done once at VSI association.

Signed-off-by: Thomas Richter <tmricht at linux.vnet.ibm.com>
---
 qbg/vdp22.c |  9 +++++----
 qbg/vdpnl.c | 12 ++++++------
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/qbg/vdp22.c b/qbg/vdp22.c
index 72ffbba..3d37444 100644
--- a/qbg/vdp22.c
+++ b/qbg/vdp22.c
@@ -870,16 +870,17 @@ static void copy_fid(struct vdpnl_vsi *vsi, struct vsi22 *p)
 {
 	int i;
 
+	vsi->maclist = calloc(p->no_fdata, sizeof(*vsi->maclist));
+	if (!vsi->maclist)
+		return;
+	vsi->macsz = p->no_fdata;
 	vsi->filter_fmt = p->fif;
-	for (i = 0; i < vsi->macsz; ++i) {
-		if( i == p->no_fdata)
-			break;
+	for (i = 0; i < p->no_fdata; ++i) {
 		vsi->maclist[i].gpid = p->fdata[i].grpid;
 		vsi->maclist[i].vlan = vdp22_get_vlanid(p->fdata[i].vlan);
 		vsi->maclist[i].qos = vdp22_get_qos(p->fdata[i].vlan);
 		vsi->maclist[i].changed = 1;
 	}
-	vsi->macsz = i;
 }
 
 /*
diff --git a/qbg/vdpnl.c b/qbg/vdpnl.c
index 61b6a2b..955447f 100644
--- a/qbg/vdpnl.c
+++ b/qbg/vdpnl.c
@@ -360,14 +360,10 @@ static void vdpnl_reply2(struct vdpnl_vsi *p, struct nlmsghdr *nlh)
 static int vdpnl_getlink(struct nlmsghdr *nlh, size_t len)
 {
 	struct vdpnl_vsi p;
-	struct vdpnl_mac mac;
 	int i = 0, rc;
 	struct nlattr *vf_ports, *vf_port;
 
 	memset(&p, 0, sizeof p);
-	memset(&mac, 0, sizeof mac);
-	p.macsz = 1;
-	p.maclist = &mac;
 	rc = vdpnl_get(nlh, &p);
 	if (rc)
 		return vdpnl_error(rc, nlh, len);
@@ -382,9 +378,13 @@ static int vdpnl_getlink(struct nlmsghdr *nlh, size_t len)
 			vdpnl_reply2(&p, nlh);
 			mynla_nest_end(nlh, vf_port);
 		}
-		if (rc == 0)
-			mynla_nest_end(nlh, vf_ports);
+		if (p.maclist) {
+			free(p.maclist);
+			p.maclist = NULL;
+			p.macsz = 0;
+		}
 	} while (rc == 1);
+	mynla_nest_end(nlh, vf_ports);
 	if (rc < 0)
 		return vdpnl_error(rc, nlh, len);
 	LLDPAD_DBG("%s:message-size:%d\n", __func__, nlh->nlmsg_len);
-- 
1.8.3.1



More information about the lldp-devel mailing list