IPA HAL: Remove Downstream Iface

Empty iface and garbage iface names should return an error
when passed to removeDownstream.

Bug: 65612332
Crs-fixed: 2105305

Change-Id: Ib4a99bd6cefe372ac4292b53842bd76e767449a1
diff --git a/ipacm/inc/IPACM_OffloadManager.h b/ipacm/inc/IPACM_OffloadManager.h
index 9d94253..72070dd 100644
--- a/ipacm/inc/IPACM_OffloadManager.h
+++ b/ipacm/inc/IPACM_OffloadManager.h
@@ -29,7 +29,7 @@
 #ifndef _IPACM_OFFLOAD_MANAGER_H_
 #define _IPACM_OFFLOAD_MANAGER_H_
 
-
+#include <list>
 #include <stdint.h>
 #include <IOffloadManager.h>
 #include "IPACM_Defs.h"
@@ -96,6 +96,8 @@
 
 private:
 
+	std::list<const char *> valid_ifaces;
+
 	bool upstream_v4_up;
 
 	bool upstream_v6_up;
diff --git a/ipacm/src/IPACM_OffloadManager.cpp b/ipacm/src/IPACM_OffloadManager.cpp
index 762b56d..3f16d7c 100644
--- a/ipacm/src/IPACM_OffloadManager.cpp
+++ b/ipacm/src/IPACM_OffloadManager.cpp
@@ -263,6 +263,13 @@
 		return SUCCESS;
 	}
 
+	/* Iface is valid, add to list if not present */
+	if (std::find(valid_ifaces.begin(), valid_ifaces.end(), downstream_name) == valid_ifaces.end())
+	{
+		/* Iface is new, add it to the list */
+		valid_ifaces.push_back(downstream_name);
+	}
+
 	evt_data = (ipacm_event_ipahal_stream*)malloc(sizeof(ipacm_event_ipahal_stream));
 	if(evt_data == NULL)
 	{
@@ -291,6 +298,17 @@
 	ipacm_event_ipahal_stream *evt_data;
 
 	IPACMDBG_H("removeDownstream name(%s), ip-family(%d) \n", downstream_name, prefix.fam);
+	if(strnlen(downstream_name, sizeof(downstream_name)) == 0)
+	{
+		IPACMERR("iface length is 0.\n");
+		return FAIL_HARDWARE;
+	}
+	if (std::find(valid_ifaces.begin(), valid_ifaces.end(), downstream_name) == valid_ifaces.end())
+	{
+		IPACMERR("iface is not present in list.\n");
+		return FAIL_HARDWARE;
+	}
+
 	if(ipa_get_if_index(downstream_name, &index))
 	{
 		IPACMERR("fail to get iface index.\n");