[lldp-devel] [PATCH] vdp add protocol switch

Thomas Richter tmricht at linux.vnet.ibm.com
Tue Mar 19 07:17:17 UTC 2013


Add a protocol switch for the vdp protocol version being used
on an interface. The netlink message received from a EVB user
such as libvirtd will be directed to the vdp module handling
the protocol version running on a particular interface.

The vdp protocol versions supported are draft 0.2 and draft
2.2 (ratified standard). The switch facing the interface
determines the protocol version being, lldpad simple reacts
using the proper protocol version.

Signed-off-by: Thomas Richter <tmricht at linux.vnet.ibm.com>
---
 include/lldp_vdp22.h |    4 ++--
 include/lldp_vdpnl.h |    1 +
 qbg/lldp_vdp22.c     |   47 ++++++++++++++++++++++++++++++++++++++++++++---
 qbg/lldp_vdpnl.c     |    4 +++-
 4 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/include/lldp_vdp22.h b/include/lldp_vdp22.h
index e4ea1ff..c29b7fe 100644
--- a/include/lldp_vdp22.h
+++ b/include/lldp_vdp22.h
@@ -30,7 +30,6 @@
 #define LLDP_VDP22_H
 
 #include	<sys/queue.h>
-#include	<net/if.h>
 #include	<linux/if_ether.h>
 
 #include	"lldp_mod.h"
@@ -56,7 +55,8 @@ struct vdp22_user_data {		/* Head for all VDP data */
 
 struct lldp_module *vdp22_register(void);
 void vdp22_unregister(struct lldp_module *);
-void vdp22_start(char *);
+void vdp22_start(const char *);
 void vdp22_stop(char *);
+int vdp22_query(const char *);
 
 #endif
diff --git a/include/lldp_vdpnl.h b/include/lldp_vdpnl.h
index 4cc3642..d6fdca6 100644
--- a/include/lldp_vdpnl.h
+++ b/include/lldp_vdpnl.h
@@ -58,6 +58,7 @@ struct vdpnl_vsi {		/* Data structure for VSI data via netlink */
 int vdpnl_recv(unsigned char *, size_t);
 int vdpnl_send(struct vdpnl_vsi *);
 int vdp_request(struct vdpnl_vsi *);
+int vdp22_request(struct vdpnl_vsi *);
 int vdp_status(int, struct vdpnl_vsi *);
 int event_trigger(struct nlmsghdr *, pid_t);
 #endif
diff --git a/qbg/lldp_vdp22.c b/qbg/lldp_vdp22.c
index b9390f6..1d151ea 100644
--- a/qbg/lldp_vdp22.c
+++ b/qbg/lldp_vdp22.c
@@ -28,9 +28,12 @@
 #include <stdlib.h>
 #include <errno.h>
 
+#include <net/if.h>
+
 #include "messages.h"
 #include "config.h"
 
+#include "lldp_vdpnl.h"
 #include "lldp_qbg22.h"
 #include "lldp_vdp22.h"
 
@@ -41,7 +44,8 @@
  * Find the vdp data associated with an interface.
  * Return pointer or NULL if not found.
  */
-static struct vdp22 *vdp22_findif(char *ifname, struct vdp22_user_data *ud)
+static struct vdp22 *vdp22_findif(const char *ifname,
+				  struct vdp22_user_data *ud)
 {
 	struct vdp22 *vdp = 0;
 
@@ -156,7 +160,8 @@ void vdp22_stop(char *ifname)
  * To be called when a successful exchange of EVB TLVs has been
  * made and ECP protocols are supported by both sides.
  */
-static struct vdp22 *vdp22_create(char *ifname, struct vdp22_user_data *eud)
+static struct vdp22 *vdp22_create(const char *ifname,
+				  struct vdp22_user_data *eud)
 {
 	struct vdp22 *vdp;
 
@@ -172,10 +177,36 @@ static struct vdp22 *vdp22_create(char *ifname, struct vdp22_user_data *eud)
 	LLDPAD_DBG("%s:%s create vdp data\n", __func__, ifname);
 	return vdp;
 }
+
+/*
+ * Query the supported VDP protocol on an interface.
+ */
+static struct vdp22 *vdp22_getvdp(const char *ifname)
+{
+	struct vdp22_user_data *vud;
+	struct vdp22 *vdp = NULL;
+
+	vud = find_module_user_data_by_id(&lldp_head, LLDP_MOD_VDP22);
+	if (vud)
+		vdp = vdp22_findif(ifname, vud);
+	LLDPAD_DBG("%s:%s vdp %p\n", __func__, ifname, vdp);
+	return vdp;
+}
+
+int vdp22_query(const char *ifname)
+{
+	int rc = 0;
+
+	if (vdp22_getvdp(ifname))
+		rc = 1;
+	LLDPAD_DBG("%s:%s rc:%d\n", __func__, ifname, rc);
+	return rc;
+}
+
 /*
  * Enable the interface for VDP protocol support.
  */
-void vdp22_start(char *ifname)
+void vdp22_start(const char *ifname)
 {
 	struct vdp22_user_data *vud;
 	struct vdp22 *vdp;
@@ -192,6 +223,16 @@ void vdp22_start(char *ifname)
 }
 
 /*
+ * Handle a VSI request from buddy.
+ */
+int vdp22_request(struct vdpnl_vsi *vsi)
+{
+	int rc = -ENODEV;
+	LLDPAD_DBG("%s:%s rc:%d\n", __func__, vsi->ifname, rc);
+	return rc;
+}
+
+/*
  * Remove all interface/agent specific vdp data.
  */
 static void vdp22_free_data(struct vdp22_user_data *ud)
diff --git a/qbg/lldp_vdpnl.c b/qbg/lldp_vdpnl.c
index cd3f32a..4a117d6 100644
--- a/qbg/lldp_vdpnl.c
+++ b/qbg/lldp_vdpnl.c
@@ -40,6 +40,7 @@
 
 #include "messages.h"
 #include "lldp_vdp.h"
+#include "lldp_vdp22.h"
 #include "lldp_vdpnl.h"
 #include "lldp_qbg_utils.h"
 #include "lldp_rtnl.h"
@@ -381,7 +382,8 @@ static int vdpnl_setlink(struct nlmsghdr *nlh, size_t len)
 	p.maclist = &mac;
 	rc = vdpnl_set(nlh, &p);
 	if (!rc)
-		rc = vdp_request(&p);
+		rc = vdp22_query(p.ifname) ? vdp22_request(&p)
+					   : vdp_request(&p);
 	return vdpnl_error(rc, nlh, len);
 }
 
-- 
1.7.1



More information about the lldp-devel mailing list