From 5985b914d63c3f4607f1436cdd1af4f67e864ec9 Mon Sep 17 00:00:00 2001
From: Mohd Husaam Mehdi <husaam.mehdi@iopsys.eu>
Date: Wed, 17 Apr 2024 13:47:11 +0530
Subject: [PATCH] qosmngr: update use of bbf_get_reference_param

In micro service mode, if we don't know which data model object
will map to the linker (for example, linker might be eth0 or wan),
then we just have to append all possible objects in a csv string
and pass to bbfdm. Update the code to use this approach.
---
 bbf_plugin/qos_bbf.c | 45 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 10 deletions(-)

diff --git a/bbf_plugin/qos_bbf.c b/bbf_plugin/qos_bbf.c
index cd4a6a9..97d07f8 100644
--- a/bbf_plugin/qos_bbf.c
+++ b/bbf_plugin/qos_bbf.c
@@ -380,20 +380,33 @@ static int delObjQoSShaper(char *refparam, struct dmctx *ctx, void *data, char *
 static int get_QInterface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
 {
 	char *linker = NULL;
+	char buf[4096] = {0};
+	int pos = 0;
 
 	dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "ifname", &linker);
+	if (DM_STRLEN(linker) == 0)
+		return 0;
 
 	bbf_get_reference_param("Device.IP.Interface.", "Name", linker, value);
+	if (DM_STRLEN(*value))
+		pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", *value);
 
-	if (!DM_STRLEN(*value))
-		bbf_get_reference_param("Device.PPP.Interface.", "Name", linker, value);
+	bbf_get_reference_param("Device.PPP.Interface.", "Name", linker, value);
+	if (DM_STRLEN(*value))
+		pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", *value);
 
-	if (!DM_STRLEN(*value))
-		bbf_get_reference_param("Device.Ethernet.Interface.", "Name", linker, value);
+	bbf_get_reference_param("Device.Ethernet.Interface.", "Name", linker, value);
+	if (DM_STRLEN(*value))
+		pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", *value);
+
+	bbf_get_reference_param("Device.WiFi.Radio.", "Name", linker, value);
+	if (DM_STRLEN(*value))
+		pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", *value);
 
-	if (!DM_STRLEN(*value))
-		bbf_get_reference_param("Device.WiFi.Radio.", "Name", linker, value);
+	if (pos)
+		buf[pos - 1] = 0;
 
+	*value = dmstrdup(buf);
 	return 0;
 }
 
@@ -1751,17 +1764,29 @@ static int set_QoSQueueStats_Queue(char *refparam, struct dmctx *ctx, void *data
 static int get_QoSQueueStats_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
 {
 	char *linker = NULL;
+	char buf[4096] = {0};
+	int pos = 0;
 
 	dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &linker);
+	if (DM_STRLEN(linker) == 0)
+		return 0;
 
 	bbf_get_reference_param("Device.Ethernet.Interface.", "Name", linker, value);
+	if (DM_STRLEN(*value))
+		pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", *value);
+
+	bbf_get_reference_param("Device.IP.Interface.", "Name", linker, value);
+	if (DM_STRLEN(*value))
+		pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", *value);
 
-	if (!DM_STRLEN(*value))
-		bbf_get_reference_param("Device.IP.Interface.", "Name", linker, value);
+	bbf_get_reference_param("Device.PPP.Interface.", "Name", linker, value);
+	if (DM_STRLEN(*value))
+		pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", *value);
 
-	if (!DM_STRLEN(*value))
-		bbf_get_reference_param("Device.PPP.Interface.", "Name", linker, value);
+	if (pos)
+		buf[pos - 1] = 0;
 
+	*value = dmstrdup(buf);
 	return 0;
 }
 
-- 
GitLab