[qca-nss-clients] Add Interface type support to netlink manager

netlink type support

Change-Id: I271ec04c561bab7e1c3d49d18e5fbf3b5ff756c1
Signed-off-by: ratheesh kannoth <rkannoth@codeaurora.org>
Signed-off-by: pavir <pavir@codeaurora.org>
diff --git a/netlink/include/nss_nlipv4_if.h b/netlink/include/nss_nlipv4_if.h
index 7e85879..d048de0 100644
--- a/netlink/include/nss_nlipv4_if.h
+++ b/netlink/include/nss_nlipv4_if.h
@@ -1,6 +1,6 @@
 /*
  **************************************************************************
- * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2015-2016,2018, The Linux Foundation. All rights reserved.
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
  * above copyright notice and this permission notice appear in all copies.
@@ -39,6 +39,9 @@
 	char flow_ifname[IFNAMSIZ];	/**< ingress interface name */
 	char return_ifname[IFNAMSIZ];	/**< egress interface name */
 
+	uint16_t flow_if_type;            /**< ingress interface type */
+	uint16_t return_if_type;            /**< egress interface type */
+
 	struct nss_ipv4_msg nim;	/**< rule message */
 };
 
diff --git a/netlink/include/nss_nlipv6_if.h b/netlink/include/nss_nlipv6_if.h
index d6edac0..8445064 100644
--- a/netlink/include/nss_nlipv6_if.h
+++ b/netlink/include/nss_nlipv6_if.h
@@ -1,6 +1,6 @@
 /*
  **************************************************************************
- * Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016,2018, The Linux Foundation. All rights reserved.
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
  * above copyright notice and this permission notice appear in all copies.
@@ -38,6 +38,9 @@
 	char flow_ifname[IFNAMSIZ];	/**< ingress interface name */
 	char return_ifname[IFNAMSIZ];	/**< egress interface name */
 
+	uint16_t flow_if_type;            /**< ingress interface type */
+	uint16_t return_if_type;            /**< egress interface type */
+
 	struct nss_ipv6_msg nim;	/**< rule message */
 };
 
diff --git a/netlink/nss_nlipv4.c b/netlink/nss_nlipv4.c
index 56fbfc1..c3bf37d 100644
--- a/netlink/nss_nlipv4.c
+++ b/netlink/nss_nlipv4.c
@@ -63,11 +63,9 @@
 /*
  * prototypes
  */
-
 static int nss_nlipv4_ops_create_rule(struct sk_buff *skb, struct genl_info *info);
 static int nss_nlipv4_ops_destroy_rule(struct sk_buff *skb, struct genl_info *info);
 
-
 /*
  * IPv4 family definition
  */
@@ -147,7 +145,6 @@
 	return NULL;
 }
 
-
 /*
  * nss_nlipv4_mac_addr_get()
  * 	Return the hardware (MAC) address of the given IPv4 address, if any.
@@ -182,7 +179,6 @@
 		return 0;
 	}
 
-
 	rcu_read_lock();
 
 	/*
@@ -221,7 +217,6 @@
 	return -ENODEV;
 }
 
-
 /*
  * nss_nlipv4_verify_5tuple()
  * 	verify and override 5-tuple entries
@@ -263,7 +258,7 @@
  * 	verify and override connection rule entries
  */
 static int nss_nlipv4_verify_conn_rule(struct nss_ipv4_rule_create_msg *msg, struct net_device *flow_dev,
-					struct net_device *return_dev)
+					struct net_device *return_dev, uint16_t flow_dev_type, uint16_t return_dev_type)
 {
 	struct nss_ipv4_connection_rule *conn = &msg->conn_rule;
 	struct nss_ipv4_nexthop *nexthop = &msg->nexthop_rule;
@@ -301,15 +296,27 @@
 		conn->flow_interface_num = nss_ipsec_get_ifnum(nss_ipsec_get_data_interface());
 	else if (is_vlan_dev(flow_dev))
 		conn->flow_interface_num = nss_cmn_get_interface_number_by_dev(vlan_dev_real_dev(flow_dev));
-	else
-		conn->flow_interface_num = nss_cmn_get_interface_number_by_dev(flow_dev);
+	else {
+		if (!flow_dev_type)
+			conn->flow_interface_num = nss_cmn_get_interface_number_by_dev(flow_dev);
+		else {
+			conn->flow_interface_num = nss_cmn_get_interface_number_by_dev_and_type(flow_dev, flow_dev_type);
+		}
+                        nss_nl_info("flow_interface_num: %d flow_interface_type: %d\n", conn->flow_interface_num, flow_dev_type);
+	}
 
 	if (return_dev->type == NSS_IPSEC_ARPHRD_IPSEC)
 		conn->return_interface_num = nss_ipsec_get_ifnum(nss_ipsec_get_data_interface());
 	else if (is_vlan_dev(return_dev))
 		conn->return_interface_num = nss_cmn_get_interface_number_by_dev(vlan_dev_real_dev(return_dev));
-	else
-		conn->return_interface_num = nss_cmn_get_interface_number_by_dev(return_dev);
+	else {
+		if (!return_dev_type)
+			conn->return_interface_num = nss_cmn_get_interface_number_by_dev(return_dev);
+		else {
+			conn->return_interface_num = nss_cmn_get_interface_number_by_dev_and_type(return_dev, return_dev_type);
+		}
+                        nss_nl_info("return_interface_num: %d return_interface_type: %d\n", conn->return_interface_num, return_dev_type);
+	}
 
 	nexthop->flow_nexthop = conn->flow_interface_num;
 	nexthop->return_nexthop = conn->return_interface_num;
@@ -629,7 +636,8 @@
 	/*
 	 * check connection rule
 	 */
-	error = nss_nlipv4_verify_conn_rule(&nim->msg.rule_create, flow_dev, return_dev);
+	error = nss_nlipv4_verify_conn_rule(&nim->msg.rule_create, flow_dev, return_dev,
+					nl_rule->flow_if_type, nl_rule->return_if_type);
 	if (error < 0) {
 		nss_nl_error("%d:invalid conn rule information passed\n", pid);
 		goto done;
@@ -855,4 +863,3 @@
 
 	return true;
 }
-
diff --git a/netlink/nss_nlipv6.c b/netlink/nss_nlipv6.c
index 6994832..1a0972b 100644
--- a/netlink/nss_nlipv6.c
+++ b/netlink/nss_nlipv6.c
@@ -73,7 +73,6 @@
 static int nss_nlipv6_ops_create_rule(struct sk_buff *skb, struct genl_info *info);
 static int nss_nlipv6_ops_destroy_rule(struct sk_buff *skb, struct genl_info *info);
 
-
 /*
  * IPV6 family definition
  */
@@ -224,7 +223,6 @@
 	return -ENODEV;
 }
 
-
 /*
  * nss_nlipv6_verify_5tuple()
  * 	verify and override 5-tuple entries
@@ -274,7 +272,7 @@
  * 	verify and override connection rule entries
  */
 static int nss_nlipv6_verify_conn_rule(struct nss_ipv6_rule_create_msg *msg, struct net_device *flow_dev,
-					struct net_device *return_dev)
+					struct net_device *return_dev, uint16_t flow_dev_type, uint16_t return_dev_type)
 {
 	struct nss_ipv6_connection_rule *conn = &msg->conn_rule;
 	struct nss_ipv6_nexthop *nexthop = &msg->nexthop_rule;
@@ -310,15 +308,27 @@
 		conn->flow_interface_num = nss_ipsec_get_ifnum(nss_ipsec_get_data_interface());
 	else if (is_vlan_dev(flow_dev))
 		conn->flow_interface_num = nss_cmn_get_interface_number_by_dev(vlan_dev_real_dev(flow_dev));
-	else
-		conn->flow_interface_num = nss_cmn_get_interface_number_by_dev(flow_dev);
+	else {
+		if (!flow_dev_type)
+			conn->flow_interface_num = nss_cmn_get_interface_number_by_dev(flow_dev);
+		else {
+			conn->flow_interface_num = nss_cmn_get_interface_number_by_dev_and_type(flow_dev, flow_dev_type);
+		}
+			nss_nl_info("flow_interface_num: %d flow_interface_type: %d\n", conn->flow_interface_num, flow_dev_type);
+}
 
 	if (return_dev->type == NSS_IPSEC_ARPHRD_IPSEC)
 		conn->return_interface_num = nss_ipsec_get_ifnum(nss_ipsec_get_data_interface());
 	else if (is_vlan_dev(return_dev))
 		conn->return_interface_num = nss_cmn_get_interface_number_by_dev(vlan_dev_real_dev(return_dev));
-	else
-		conn->return_interface_num = nss_cmn_get_interface_number_by_dev(return_dev);
+	else {
+		if (!return_dev_type)
+			conn->return_interface_num = nss_cmn_get_interface_number_by_dev(return_dev);
+		else {
+			conn->return_interface_num = nss_cmn_get_interface_number_by_dev_and_type(return_dev, return_dev_type);
+		}
+                        nss_nl_info("return_interface_num: %d return_interface_type: %d\n", conn->return_interface_num, return_dev_type);
+	}
 
 	nexthop->flow_nexthop = conn->flow_interface_num;
 	nexthop->return_nexthop = conn->return_interface_num;
@@ -599,7 +609,8 @@
 	/*
 	 * check connection rule
 	 */
-	error = nss_nlipv6_verify_conn_rule(&nim->msg.rule_create, flow_dev, return_dev);
+	error = nss_nlipv6_verify_conn_rule(&nim->msg.rule_create, flow_dev, return_dev,
+				nl_rule->flow_if_type, nl_rule->return_if_type);
 	if (error < 0) {
 		nss_nl_error("%d:invalid conn rule information passed\n", pid);
 		goto done;
@@ -757,7 +768,6 @@
 	nss_nlipv6_swap_addr(nim->msg.rule_destroy.tuple.flow_ip, nim->msg.rule_destroy.tuple.flow_ip);
 	nss_nlipv6_swap_addr(nim->msg.rule_destroy.tuple.return_ip, nim->msg.rule_destroy.tuple.return_ip);
 
-
 	/*
 	 * Push rule to NSS
 	 */
@@ -839,4 +849,3 @@
 
 	return true;
 }
-