[lldp-devel] [PATCH] evb lower case comparision for EVB protocol parameters

Thomas Richter tmricht at linux.vnet.ibm.com
Mon Mar 4 14:55:10 UTC 2013


The lldpad configuration file may store IEEE 802.1 Qbg parameters
(such as fmode and capabilities) in upper case letters.
When reading the confuration file the values a compared
against lower case strings and do not match.
The patch reads the configuration file values and converts
them to lowercase before the comparison.

Signed-off-by: Thomas Richter <tmricht at linux.vnet.ibm.com>
---
 lldp_evb_cmds.c |   44 ++++++++++++++++++++++++++++++--------------
 1 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/lldp_evb_cmds.c b/lldp_evb_cmds.c
index 6d40aae..11f1820 100644
--- a/lldp_evb_cmds.c
+++ b/lldp_evb_cmds.c
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <ctype.h>
 
 #include "lldp.h"
 #include "lldp_evb.h"
@@ -51,11 +52,20 @@
 #define ARG_EVB_VSIS			"vsis"
 #define ARG_EVB_RTE			"rte"
 
+static void lowercase(char *cp)
+{
+	for (; *cp; ++cp)
+		if (isupper(*cp))
+			*cp = tolower(*cp);
+}
+
 /*
  * Read EVB specific data from the configuration file.
+ * If last parameter is a valid pointer (non-zero) return string converted to
+ * lower case characters in that parameter.
  */
 static const char *evb_conf_string(char *ifname, enum agent_type type,
-				   char *ext, int def)
+				   char *ext, int def, char *lc)
 {
 	char arg_path[EVB_BUF_SIZE];
 	const char *param = NULL;
@@ -69,6 +79,10 @@ static const char *evb_conf_string(char *ifname, enum agent_type type,
 			    ifname, type, ext, def);
 		return 0;
 	}
+	if (lc) {
+		strcpy(lc, param);
+		lowercase(lc);
+	}
 	return param;
 }
 
@@ -79,12 +93,14 @@ u8 evb_conf_fmode(char *ifname, enum agent_type type)
 {
 	u8 smode = LLDP_EVB_CAPABILITY_FORWARD_STANDARD;
 	const char *value;
+	char value_lc[EVB_BUF_SIZE];
 
-	value = evb_conf_string(ifname, type, ARG_EVB_FORWARDING_MODE, smode);
+	value = evb_conf_string(ifname, type, ARG_EVB_FORWARDING_MODE, smode,
+				value_lc);
 	if (value) {
-		if (strstr(value, VAL_EVB_FMODE_BRIDGE))
+		if (strstr(value_lc, VAL_EVB_FMODE_BRIDGE))
 			smode = LLDP_EVB_CAPABILITY_FORWARD_STANDARD;
-		if (strstr(value, VAL_EVB_FMODE_REFLECTIVE_RELAY))
+		if (strstr(value_lc, VAL_EVB_FMODE_REFLECTIVE_RELAY))
 			smode = LLDP_EVB_CAPABILITY_FORWARD_REFLECTIVE_RELAY;
 		LLDPAD_DBG("%s:%s agent %d policy %s %s(%#x)\n", __func__,
 			   ifname, type, ARG_EVB_FORWARDING_MODE, value, smode);
@@ -100,7 +116,7 @@ u16 evb_conf_vsis(char *ifname, enum agent_type type)
 	u16 svsi = LLDP_EVB_DEFAULT_SVSI;
 	const char *value;
 
-	value = evb_conf_string(ifname, type, ARG_EVB_VSIS, svsi);
+	value = evb_conf_string(ifname, type, ARG_EVB_VSIS, svsi, NULL);
 	if (value) {
 		svsi = atoi(value);
 		LLDPAD_DBG("%s:%s agent %d policy %s %s(%#x)\n", __func__,
@@ -114,23 +130,23 @@ u16 evb_conf_vsis(char *ifname, enum agent_type type)
  */
 u8 evb_conf_capa(char *ifname, enum agent_type type)
 {
-	u8 scap = LLDP_EVB_CAPABILITY_PROTOCOL_RTE |
-			   LLDP_EVB_CAPABILITY_PROTOCOL_ECP |
-			   LLDP_EVB_CAPABILITY_PROTOCOL_VDP;
+	u8 scap = 0;
 	const char *value;
+	char value_lc[EVB_BUF_SIZE];
 
-	value = evb_conf_string(ifname, type, ARG_EVB_CAPABILITIES, scap);
+	value = evb_conf_string(ifname, type, ARG_EVB_CAPABILITIES, scap,
+				value_lc);
 	if (value) {
-		if (strstr(value, VAL_EVB_CAPA_RTE))
+		if (strstr(value_lc, VAL_EVB_CAPA_RTE))
 			scap = LLDP_EVB_CAPABILITY_PROTOCOL_RTE;
 
-		if (strstr(value, VAL_EVB_CAPA_ECP))
+		if (strstr(value_lc, VAL_EVB_CAPA_ECP))
 			scap |= LLDP_EVB_CAPABILITY_PROTOCOL_ECP;
 
-		if (strstr(value, VAL_EVB_CAPA_VDP))
+		if (strstr(value_lc, VAL_EVB_CAPA_VDP))
 			scap |= LLDP_EVB_CAPABILITY_PROTOCOL_VDP;
 
-		if (strstr(value, VAL_EVB_CAPA_NONE))
+		if (strstr(value_lc, VAL_EVB_CAPA_NONE))
 			scap = 0;
 
 		LLDPAD_DBG("%s:%s agent %d policy %s %s(%#x)\n",
@@ -148,7 +164,7 @@ u8 evb_conf_rte(char *ifname, enum agent_type type)
 	u8 rte = LLDP_EVB_DEFAULT_RTE;
 	const char *value;
 
-	value = evb_conf_string(ifname, type, ARG_EVB_RTE, rte);
+	value = evb_conf_string(ifname, type, ARG_EVB_RTE, rte, NULL);
 	if (value) {
 		rte = atoi(value);
 		LLDPAD_DBG("%s:%s agent %d policy %s %s(%#x)\n", __func__,
-- 
1.7.1



More information about the lldp-devel mailing list