From ad4825bc6349d1cd68680aaaa6c5b217227c90fe Mon Sep 17 00:00:00 2001
From: Vivek Kumar Dutta <vivek.dutta@iopsys.eu>
Date: Fri, 20 Sep 2024 14:26:18 +0530
Subject: [PATCH] Fix usages of BBF_VENDOR_PREFIX macro

---
 .gitlab-ci.yml       | 2 +-
 src/Makefile         | 2 +-
 src/common.h         | 1 +
 src/interfacestack.c | 5 +++--
 src/ip.c             | 8 ++++++--
 src/ppp.c            | 5 +++--
 src/routing.c        | 1 +
 7 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1515e60..b81ec81 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,6 +1,6 @@
 variables:
   SOURCE_FOLDER: "src"
-  CPPCHECK_OPTIONS: "--suppress=cert-MSC24-C -DBBF_VENDOR_PREFIX=X_IOPSYS_EU_"
+  CFLAGS: "-DBBF_VENDOR_PREFIX=X_IOPSYS_EU"
 
 include:
   - project: 'iopsys/gitlab-ci-pipeline'
diff --git a/src/Makefile b/src/Makefile
index a60218d..7330df0 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -11,7 +11,7 @@ LIBNETMNGROBJS := net_plugin.o \
 		   
 LIBIFACESTACKOBJS := interfacestack.o
 
-LIB_CFLAGS = $(CFLAGS) -Wall -Werror -fstrict-aliasing -g -DBBF_VENDOR_PREFIX=\"X_IOPSYS_EU_\"
+LIB_CFLAGS = $(CFLAGS) -Wall -Werror -fstrict-aliasing -g
 LIB_LDFLAGS = $(LDFLAGS)
 FPIC := -fPIC
 
diff --git a/src/common.h b/src/common.h
index 7661902..49bb75c 100644
--- a/src/common.h
+++ b/src/common.h
@@ -13,6 +13,7 @@
 #define __DMLAYER_H__
 
 #include "libbbfdm-api/dmcommon.h"
+#define STR(s) #s
 
 void gre___get_tunnel_system_name(struct uci_section *iface_section, char *device_str, size_t device_str_size);
 
diff --git a/src/interfacestack.c b/src/interfacestack.c
index d0d238c..4a625d1 100644
--- a/src/interfacestack.c
+++ b/src/interfacestack.c
@@ -8,6 +8,7 @@
  *	Author: Amin Ben Romdhane <amin.benromdhane@iopsys.eu>
  */
 
+#include "common.h"
 #include "interfacestack.h"
 
 struct interfacestack_data
@@ -100,7 +101,7 @@ static char *get_lower_alias_value(const char *path)
 	} else if (DM_STRNCMP(path, "Device.PPP.Interface.", strlen("Device.PPP.Interface.")) == 0) {
 		get_dmmap_section_of_config_section_eq("dmmap_ppp", "interface", "ppp_int_instance", instance + 1, &s);
 		dmuci_get_value_by_section_string(s, "ppp_int_alias", &alias_value);
-	} else if (DM_STRNCMP(path, "Device.Ethernet."BBF_VENDOR_PREFIX"MACVLAN.", strlen("Device.Ethernet."BBF_VENDOR_PREFIX"MACVLAN.")) == 0) {
+	} else if (DM_STRNCMP(path, "Device.Ethernet."STR(BBF_VENDOR_PREFIX)"MACVLAN.", strlen("Device.Ethernet."STR(BBF_VENDOR_PREFIX)"MACVLAN.")) == 0) {
 		get_dmmap_section_of_config_section_eq("dmmap_network", "device", "mac_vlan_instance", instance + 1, &s);
 		dmuci_get_value_by_section_string(s, "mac_vlan_alias", &alias_value);
 	}
@@ -184,7 +185,7 @@ static int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, vo
 	uci_path_foreach_sections(bbfdm, "dmmap_network", "device", s) {
 
 		if (create_interface_stack_instance(dmctx, parent_node, &curr_interfacestack_data, s,
-				"Device.Ethernet."BBF_VENDOR_PREFIX"MACVLAN.", "mac_vlan_instance", "mac_vlan_alias", &idx))
+				"Device.Ethernet."STR(BBF_VENDOR_PREFIX)"MACVLAN.", "mac_vlan_instance", "mac_vlan_alias", &idx))
 			goto end;
 	}
 
diff --git a/src/ip.c b/src/ip.c
index 060b7e8..8a3cf32 100644
--- a/src/ip.c
+++ b/src/ip.c
@@ -75,6 +75,7 @@ static bool browse_ip_port(struct dmctx *dmctx, DMNODE *parent_node, bool is_ipv
 	if (proc_path == NULL || DM_STRLEN(proc_path) == 0)
 		return is_instance;
 
+	// cppcheck-suppress cert-MSC24-C
 	FILE* fp = fopen(proc_path, "r");
 	if (fp == NULL) {
 		return is_instance;
@@ -142,6 +143,7 @@ static int set_sysctl_disable_ipv6_per_device(const char *device, bool value)
 	char cmd[128] = {0};
 	char path[64] = {0};
 
+	// cppcheck-suppress cert-MSC24-C
 	fp = fopen("/etc/bbfdm/sysctl.conf", "r+");
 	if (!fp)
 		return -1;
@@ -254,6 +256,7 @@ static void dmmap_synchronize_ipv6_address_link_local(const char *parent_section
 
 		dmuci_get_value_by_section_string(s, "address", &address);
 
+		// cppcheck-suppress cert-MSC24-C
 		fp = fopen(PROC_INTF6, "r");
 		if (fp == NULL)
 			return;
@@ -275,6 +278,7 @@ static void dmmap_synchronize_ipv6_address_link_local(const char *parent_section
 			dmuci_delete_by_section(s, NULL, NULL);
 	}
 
+	// cppcheck-suppress cert-MSC24-C
 	fp = fopen(PROC_INTF6, "r");
 	if (fp == NULL)
 		return;
@@ -1303,7 +1307,7 @@ static int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *
 		}
 
 		bbfdm_get_references(ctx, MATCH_FIRST, "Device.PPP.Interface.", "Name", device, buf, sizeof(buf));
-		bbfdm_get_references(ctx, MATCH_FIRST, "Device.Ethernet."BBF_VENDOR_PREFIX"MACVLAN.", "Name", device, buf, sizeof(buf));
+		bbfdm_get_references(ctx, MATCH_FIRST, "Device.Ethernet."STR(BBF_VENDOR_PREFIX)"MACVLAN.", "Name", device, buf, sizeof(buf));
 		bbfdm_get_references(ctx, MATCH_FIRST, "Device.Ethernet.VLANTermination.", "Name", device, buf, sizeof(buf));
 		bbfdm_get_references(ctx, MATCH_FIRST, "Device.Ethernet.Link.", "Name", device, buf, sizeof(buf));
 
@@ -1325,7 +1329,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *
 {
 	char *allowed_objects[] = {
 			"Device.PPP.Interface.",
-			"Device.Ethernet."BBF_VENDOR_PREFIX"MACVLAN",
+			"Device.Ethernet."STR(BBF_VENDOR_PREFIX)"MACVLAN",
 			"Device.Ethernet.VLANTermination.",
 			"Device.Ethernet.Link.",
 			"Device.GRE.Tunnel.*.Interface.",
diff --git a/src/ppp.c b/src/ppp.c
index 3293b71..5af533f 100644
--- a/src/ppp.c
+++ b/src/ppp.c
@@ -682,6 +682,7 @@ static int set_PPPInterface_IPv6CPEnable(char *refparam, struct dmctx *ctx, void
 
 static int get_PPPInterfacePPPoE_SessionID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
 {
+	// cppcheck-suppress cert-MSC24-C
 	FILE *fp = fopen("/proc/net/pppoe" ,"r");
 	if (NULL == fp) {
 		*value = dmstrdup("1");
@@ -956,7 +957,7 @@ static int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch
 		if (DM_STRLEN(device) == 0)
 			return 0;
 
-		bbfdm_get_references(ctx, MATCH_FIRST, "Device.Ethernet."BBF_VENDOR_PREFIX"MACVLAN.", "Name", device, buf, sizeof(buf));
+		bbfdm_get_references(ctx, MATCH_FIRST, "Device.Ethernet."STR(BBF_VENDOR_PREFIX)"MACVLAN.", "Name", device, buf, sizeof(buf));
 		bbfdm_get_references(ctx, MATCH_FIRST, "Device.Ethernet.VLANTermination.", "Name", device, buf, sizeof(buf));
 		bbfdm_get_references(ctx, MATCH_FIRST, "Device.Ethernet.Link.", "Name", device, buf, sizeof(buf));
 
@@ -973,7 +974,7 @@ static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch
 {
 	struct dm_data *ppp = (struct dm_data *)data;
 	char *allowed_objects[] = {
-			"Device.Ethernet."BBF_VENDOR_PREFIX"MACVLAN",
+			"Device.Ethernet."STR(BBF_VENDOR_PREFIX)"MACVLAN",
 			"Device.Ethernet.VLANTermination.",
 			"Device.Ethernet.Link.",
 			NULL};
diff --git a/src/routing.c b/src/routing.c
index 7757ed6..c3c44a9 100644
--- a/src/routing.c
+++ b/src/routing.c
@@ -1010,6 +1010,7 @@ static int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam,
 
 	snprintf(cmd, sizeof(cmd), "ip -6 route show");
 
+	// cppcheck-suppress cert-MSC24-C
 	FILE *fp = fopen(PROC_ROUTE6, "r");
 	if (fp != NULL) {
 		char line[MAX_ROUTE_LEN] = {0};
-- 
GitLab