Merge "[qca-nss-ecm] Fixed the VLAN over LAG acceleration issue"
diff --git a/ecm_db.c b/ecm_db.c
index 3d58ff5..55a2006 100644
--- a/ecm_db.c
+++ b/ecm_db.c
@@ -952,6 +952,17 @@
 EXPORT_SYMBOL(ecm_db_iface_ae_interface_identifier_get);
 
 /*
+ * ecm_db_iface_ae_interface_identifier_set()
+ *	Sets accel engine  interface number of this ecm interface
+ */
+void ecm_db_iface_ae_interface_identifier_set(struct ecm_db_iface_instance *ii, uint32_t num)
+{
+	DEBUG_CHECK_MAGIC(ii, ECM_DB_IFACE_INSTANCE_MAGIC, "%p: magic failed", ii);
+	ii->ae_interface_identifier = num;
+}
+EXPORT_SYMBOL(ecm_db_iface_ae_interface_identifier_set);
+
+/*
  * ecm_db_iface_interface_identifier_get()
  *	Return the interface number of this ecm interface
  */
@@ -6930,6 +6941,19 @@
 EXPORT_SYMBOL(ecm_db_connection_to_nat_interfaces_clear);
 
 /*
+ * ecm_db_front_end_instance_ref_and_set()
+ *	Refs and sets the front end instance of connection.
+ */
+void ecm_db_front_end_instance_ref_and_set(struct ecm_db_connection_instance *ci, struct ecm_front_end_connection_instance *feci)
+{
+	DEBUG_CHECK_MAGIC(ci, ECM_DB_CONNECTION_INSTANCE_MAGIC, "%p: magic failed\n", ci);
+
+	feci->ref(feci);
+	ci->feci = feci;
+}
+EXPORT_SYMBOL(ecm_db_front_end_instance_ref_and_set);
+
+/*
  * ecm_db_connection_add()
  *	Add the connection into the database.
  *
@@ -6937,7 +6961,6 @@
  * NOTE: Dir confirms if this is an egressing or ingressing connection.  This applies to firewalling front ends mostly. If INGRESS then mapping_from is the WAN side.  If EGRESS then mapping_to is the WAN side.
  */
 void ecm_db_connection_add(struct ecm_db_connection_instance *ci,
-							struct ecm_front_end_connection_instance *feci,
 							struct ecm_db_mapping_instance *mapping_from, struct ecm_db_mapping_instance *mapping_to,
 							struct ecm_db_mapping_instance *mapping_nat_from, struct ecm_db_mapping_instance *mapping_nat_to,
 							struct ecm_db_node_instance *from_node, struct ecm_db_node_instance *to_node,
@@ -6986,12 +7009,6 @@
 #endif
 
 	/*
-	 * Take reference to the front end
-	 */
-	feci->ref(feci);
-	ci->feci = feci;
-
-	/*
 	 * Ensure default classifier has been assigned this is a must to ensure minimum level of classification
 	 */
 	DEBUG_ASSERT(ci->assignments_by_type[ECM_CLASSIFIER_TYPE_DEFAULT], "%p: No default classifier assigned\n", ci);
diff --git a/ecm_db.h b/ecm_db.h
index 80922f8..2a815fc 100644
--- a/ecm_db.h
+++ b/ecm_db.h
@@ -22,6 +22,7 @@
 
 #include <net/netfilter/nf_conntrack.h>
 
+void ecm_db_front_end_instance_ref_and_set(struct ecm_db_connection_instance *ci, struct ecm_front_end_connection_instance *feci);
 struct ecm_db_connection_instance *ecm_db_connection_ipv4_from_ct_get_and_ref(struct nf_conn *ct);
 struct ecm_db_connection_instance *ecm_db_connection_ipv6_from_ct_get_and_ref(struct nf_conn *ct);
 uint32_t ecm_db_time_get(void);
@@ -68,6 +69,7 @@
 ecm_db_iface_type_t ecm_db_connection_iface_type_get(struct ecm_db_iface_instance *ii);
 int32_t ecm_db_iface_mtu_reset(struct ecm_db_iface_instance *ii, int32_t mtu);
 int32_t ecm_db_iface_ae_interface_identifier_get(struct ecm_db_iface_instance *ii);
+void ecm_db_iface_ae_interface_identifier_set(struct ecm_db_iface_instance *ii, uint32_t num);
 int32_t ecm_db_iface_interface_identifier_get(struct ecm_db_iface_instance *ii);
 void ecm_db_iface_interface_name_get(struct ecm_db_iface_instance *ii, char *name_buffer);
 void ecm_db_iface_identifier_hash_table_entry_check_and_update(struct ecm_db_iface_instance *ii, int32_t new_interface_identifier);
@@ -312,7 +314,7 @@
 void ecm_db_node_add(struct ecm_db_node_instance *ni, struct ecm_db_iface_instance *ii, uint8_t *address, ecm_db_node_final_callback_t final, void *arg);
 void ecm_db_host_add(struct ecm_db_host_instance *hi, ip_addr_t address, bool on_link, ecm_db_host_final_callback_t final, void *arg);
 void ecm_db_mapping_add(struct ecm_db_mapping_instance *mi, struct ecm_db_host_instance *hi, int port, ecm_db_mapping_final_callback_t final, void *arg);
-void ecm_db_connection_add(struct ecm_db_connection_instance *ci, struct ecm_front_end_connection_instance *feci, struct ecm_db_mapping_instance *mapping_from, struct ecm_db_mapping_instance *mapping_to, struct ecm_db_mapping_instance *mapping_nat_from, struct ecm_db_mapping_instance *mapping_nat_to, struct ecm_db_node_instance *from_node, struct ecm_db_node_instance *to_node, struct ecm_db_node_instance *from_nat_node, struct ecm_db_node_instance *to_nat_node, int ip_version, int protocol, ecm_db_direction_t dir, ecm_db_connection_final_callback_t final, ecm_db_connection_defunct_callback_t defunct, ecm_db_timer_group_t tg, bool is_routed, void *arg);
+void ecm_db_connection_add(struct ecm_db_connection_instance *ci, struct ecm_db_mapping_instance *mapping_from, struct ecm_db_mapping_instance *mapping_to, struct ecm_db_mapping_instance *mapping_nat_from, struct ecm_db_mapping_instance *mapping_nat_to, struct ecm_db_node_instance *from_node, struct ecm_db_node_instance *to_node, struct ecm_db_node_instance *from_nat_node, struct ecm_db_node_instance *to_nat_node, int ip_version, int protocol, ecm_db_direction_t dir, ecm_db_connection_final_callback_t final, ecm_db_connection_defunct_callback_t defunct, ecm_db_timer_group_t tg, bool is_routed, void *arg);
 
 void ecm_db_listener_ref(struct ecm_db_listener_instance *li);
 void ecm_db_connection_ref(struct ecm_db_connection_instance *ci);
diff --git a/ecm_interface.c b/ecm_interface.c
index 5cce32a..54cbd96 100644
--- a/ecm_interface.c
+++ b/ecm_interface.c
@@ -1373,6 +1373,10 @@
 
 	if (ii) {
 		DEBUG_TRACE("%p: iface established\n", ii);
+		/*
+		 * Update the accel engine interface identifier, just in case it was changed.
+		 */
+		ecm_db_iface_ae_interface_identifier_set(ii, ae_interface_num);
 		return ii;
 	}
 
diff --git a/frontends/nss/ecm_nss_multicast_ipv4.c b/frontends/nss/ecm_nss_multicast_ipv4.c
index 634a103..fe465cd 100644
--- a/frontends/nss/ecm_nss_multicast_ipv4.c
+++ b/frontends/nss/ecm_nss_multicast_ipv4.c
@@ -2933,6 +2933,8 @@
 			}
 		}
 
+		ecm_db_front_end_instance_ref_and_set(nci, feci);
+
 		/*
 		 * Now add the connection into the database.
 		 * NOTE: In an SMP situation such as ours there is a possibility that more than one packet for the same
@@ -2967,13 +2969,13 @@
 			 * Add the new connection we created into the database
 			 * NOTE: assign to a short timer group for now - it is the assigned classifiers responsibility to do this
 			 */
-			ecm_db_connection_add(nci, feci,
-					src_mi, dest_mi, src_nat_mi, dest_mi,
+			ecm_db_connection_add(nci, src_mi, dest_mi, src_nat_mi, dest_mi,
 					src_ni, dest_ni, src_nat_ni, dest_ni,
 					4, protocol, ecm_dir,
 					NULL /* final callback */,
 					ecm_nss_multicast_ipv4_connection_defunct_callback,
 					tg, is_routed, nci);
+
 			/*
 			 * Add the tuple instance and attach it with connection instance
 			 */
@@ -2983,6 +2985,7 @@
 			}
 
 			spin_unlock_bh(&ecm_nss_ipv4_lock);
+
 			ecm_db_multicast_tuple_instance_deref(tuple_instance);
 			ci = nci;
 			DEBUG_INFO("%p: New UDP multicast connection created\n", ci);
diff --git a/frontends/nss/ecm_nss_multicast_ipv6.c b/frontends/nss/ecm_nss_multicast_ipv6.c
index e216680..1b429c4 100644
--- a/frontends/nss/ecm_nss_multicast_ipv6.c
+++ b/frontends/nss/ecm_nss_multicast_ipv6.c
@@ -2722,6 +2722,8 @@
 			}
 		}
 
+		ecm_db_front_end_instance_ref_and_set(nci, feci);
+
 		/*
 		 * Now add the connection into the database.
 		 * NOTE: In an SMP situation such as ours there is a possibility that more than one packet for the same
@@ -2763,7 +2765,7 @@
 			 * Add the new connection we created into the database
 			 * NOTE: assign to a short timer group for now - it is the assigned classifiers responsibility to do this
 			 */
-			ecm_db_connection_add(nci, feci, src_mi, dest_mi, src_mi, dest_mi,
+			ecm_db_connection_add(nci, src_mi, dest_mi, src_mi, dest_mi,
 					src_ni, dest_ni, src_ni, dest_ni,
 					6, IPPROTO_UDP, ecm_dir,
 					NULL /* final callback */,
@@ -2779,6 +2781,7 @@
 			}
 
 			spin_unlock_bh(&ecm_nss_ipv6_lock);
+
 			ecm_db_multicast_tuple_instance_deref(tuple_instance);
 			ci = nci;
 			DEBUG_INFO("%p: New UDP connection created\n", ci);
diff --git a/frontends/nss/ecm_nss_non_ported_ipv4.c b/frontends/nss/ecm_nss_non_ported_ipv4.c
index 4d69631..6750917 100644
--- a/frontends/nss/ecm_nss_non_ported_ipv4.c
+++ b/frontends/nss/ecm_nss_non_ported_ipv4.c
@@ -2182,6 +2182,8 @@
 			}
 		}
 
+		ecm_db_front_end_instance_ref_and_set(nci, feci);
+
 		/*
 		 * Now add the connection into the database.
 		 * NOTE: In an SMP situation such as ours there is a possibility that more than one packet for the same
@@ -2215,7 +2217,7 @@
 			 * Add the new connection we created into the database
 			 * NOTE: assign to a short timer group for now - it is the assigned classifiers responsibility to do this
 			 */
-			ecm_db_connection_add(nci, feci, src_mi, dest_mi, src_nat_mi, dest_nat_mi,
+			ecm_db_connection_add(nci, src_mi, dest_mi, src_nat_mi, dest_nat_mi,
 					src_ni, dest_ni, src_nat_ni, dest_nat_ni,
 					4, protocol, ecm_dir,
 					NULL /* final callback */,
diff --git a/frontends/nss/ecm_nss_non_ported_ipv6.c b/frontends/nss/ecm_nss_non_ported_ipv6.c
index 5bc6985..7df258f 100644
--- a/frontends/nss/ecm_nss_non_ported_ipv6.c
+++ b/frontends/nss/ecm_nss_non_ported_ipv6.c
@@ -1852,6 +1852,8 @@
 			}
 		}
 
+		ecm_db_front_end_instance_ref_and_set(nci, feci);
+
 		/*
 		 * Now add the connection into the database.
 		 * NOTE: In an SMP situation such as ours there is a possibility that more than one packet for the same
@@ -1885,7 +1887,7 @@
 			 * Add the new connection we created into the database
 			 * NOTE: assign to a short timer group for now - it is the assigned classifiers responsibility to do this
 			 */
-			ecm_db_connection_add(nci, feci, src_mi, dest_mi, src_mi, dest_mi,
+			ecm_db_connection_add(nci, src_mi, dest_mi, src_mi, dest_mi,
 					src_ni, dest_ni, src_ni, dest_ni,
 					6, protocol, ecm_dir,
 					NULL /* final callback */,
diff --git a/frontends/nss/ecm_nss_ported_ipv4.c b/frontends/nss/ecm_nss_ported_ipv4.c
index 084c5bc..9fe2e7e 100644
--- a/frontends/nss/ecm_nss_ported_ipv4.c
+++ b/frontends/nss/ecm_nss_ported_ipv4.c
@@ -2315,6 +2315,8 @@
 			}
 		}
 
+		ecm_db_front_end_instance_ref_and_set(nci, feci);
+
 		/*
 		 * Now add the connection into the database.
 		 * NOTE: In an SMP situation such as ours there is a possibility that more than one packet for the same
@@ -2348,7 +2350,7 @@
 			 * Add the new connection we created into the database
 			 * NOTE: assign to a short timer group for now - it is the assigned classifiers responsibility to do this
 			 */
-			ecm_db_connection_add(nci, feci, src_mi, dest_mi, src_nat_mi, dest_nat_mi,
+			ecm_db_connection_add(nci, src_mi, dest_mi, src_nat_mi, dest_nat_mi,
 					src_ni, dest_ni, src_nat_ni, dest_nat_ni,
 					4, protocol, ecm_dir,
 					NULL /* final callback */,
diff --git a/frontends/nss/ecm_nss_ported_ipv6.c b/frontends/nss/ecm_nss_ported_ipv6.c
index ce10249..e776db2 100644
--- a/frontends/nss/ecm_nss_ported_ipv6.c
+++ b/frontends/nss/ecm_nss_ported_ipv6.c
@@ -2048,6 +2048,8 @@
 			}
 		}
 
+		ecm_db_front_end_instance_ref_and_set(nci, feci);
+
 		/*
 		 * Now add the connection into the database.
 		 * NOTE: In an SMP situation such as ours there is a possibility that more than one packet for the same
@@ -2081,7 +2083,7 @@
 			 * Add the new connection we created into the database
 			 * NOTE: assign to a short timer group for now - it is the assigned classifiers responsibility to do this
 			 */
-			ecm_db_connection_add(nci, feci, src_mi, dest_mi, src_mi, dest_mi,
+			ecm_db_connection_add(nci, src_mi, dest_mi, src_mi, dest_mi,
 					src_ni, dest_ni, src_ni, dest_ni,
 					6, protocol, ecm_dir,
 					NULL /* final callback */,
diff --git a/frontends/sfe/ecm_sfe_non_ported_ipv4.c b/frontends/sfe/ecm_sfe_non_ported_ipv4.c
index 7ec68a8..08d4ef6 100644
--- a/frontends/sfe/ecm_sfe_non_ported_ipv4.c
+++ b/frontends/sfe/ecm_sfe_non_ported_ipv4.c
@@ -2126,6 +2126,8 @@
 			}
 		}
 
+		ecm_db_front_end_instance_ref_and_set(nci, feci);
+
 		/*
 		 * Now add the connection into the database.
 		 * NOTE: In an SMP situation such as ours there is a possibility that more than one packet for the same
@@ -2159,7 +2161,7 @@
 			 * Add the new connection we created into the database
 			 * NOTE: assign to a short timer group for now - it is the assigned classifiers responsibility to do this
 			 */
-			ecm_db_connection_add(nci, feci, src_mi, dest_mi, src_nat_mi, dest_nat_mi,
+			ecm_db_connection_add(nci, src_mi, dest_mi, src_nat_mi, dest_nat_mi,
 					src_ni, dest_ni, src_nat_ni, dest_nat_ni,
 					4, protocol, ecm_dir,
 					NULL /* final callback */,
diff --git a/frontends/sfe/ecm_sfe_non_ported_ipv6.c b/frontends/sfe/ecm_sfe_non_ported_ipv6.c
index ed6e984..c82d79e 100644
--- a/frontends/sfe/ecm_sfe_non_ported_ipv6.c
+++ b/frontends/sfe/ecm_sfe_non_ported_ipv6.c
@@ -1881,6 +1881,8 @@
 			}
 		}
 
+		ecm_db_front_end_instance_ref_and_set(nci, feci);
+
 		/*
 		 * Now add the connection into the database.
 		 * NOTE: In an SMP situation such as ours there is a possibility that more than one packet for the same
@@ -1914,7 +1916,7 @@
 			 * Add the new connection we created into the database
 			 * NOTE: assign to a short timer group for now - it is the assigned classifiers responsibility to do this
 			 */
-			ecm_db_connection_add(nci, feci, src_mi, dest_mi, src_mi, dest_mi,
+			ecm_db_connection_add(nci, src_mi, dest_mi, src_mi, dest_mi,
 					src_ni, dest_ni, src_ni, dest_ni,
 					6, protocol, ecm_dir,
 					NULL /* final callback */,
diff --git a/frontends/sfe/ecm_sfe_ported_ipv4.c b/frontends/sfe/ecm_sfe_ported_ipv4.c
index f12237b..12473fd 100644
--- a/frontends/sfe/ecm_sfe_ported_ipv4.c
+++ b/frontends/sfe/ecm_sfe_ported_ipv4.c
@@ -2280,6 +2280,8 @@
 			}
 		}
 
+		ecm_db_front_end_instance_ref_and_set(nci, feci);
+
 		/*
 		 * Now add the connection into the database.
 		 * NOTE: In an SMP situation such as ours there is a possibility that more than one packet for the same
@@ -2313,7 +2315,7 @@
 			 * Add the new connection we created into the database
 			 * NOTE: assign to a short timer group for now - it is the assigned classifiers responsibility to do this
 			 */
-			ecm_db_connection_add(nci, feci, src_mi, dest_mi, src_nat_mi, dest_nat_mi,
+			ecm_db_connection_add(nci, src_mi, dest_mi, src_nat_mi, dest_nat_mi,
 					src_ni, dest_ni, src_nat_ni, dest_nat_ni,
 					4, protocol, ecm_dir,
 					NULL /* final callback */,
diff --git a/frontends/sfe/ecm_sfe_ported_ipv6.c b/frontends/sfe/ecm_sfe_ported_ipv6.c
index 2327c36..fe5ba00 100644
--- a/frontends/sfe/ecm_sfe_ported_ipv6.c
+++ b/frontends/sfe/ecm_sfe_ported_ipv6.c
@@ -2078,6 +2078,8 @@
 			}
 		}
 
+		ecm_db_front_end_instance_ref_and_set(nci, feci);
+
 		/*
 		 * Now add the connection into the database.
 		 * NOTE: In an SMP situation such as ours there is a possibility that more than one packet for the same
@@ -2111,7 +2113,7 @@
 			 * Add the new connection we created into the database
 			 * NOTE: assign to a short timer group for now - it is the assigned classifiers responsibility to do this
 			 */
-			ecm_db_connection_add(nci, feci, src_mi, dest_mi, src_mi, dest_mi,
+			ecm_db_connection_add(nci, src_mi, dest_mi, src_mi, dest_mi,
 					src_ni, dest_ni, src_ni, dest_ni,
 					6, protocol, ecm_dir,
 					NULL /* final callback */,