shortcut-fe: include NAT information and sync reason in sync message

Some connection manager need these information to manipulate connection,
so add them in stats sync message

Change-Id: I59ea72a44d64159aba96b78f779ab7886ee55681
Signed-off-by: Xiaoping Fan <xfan@codeaurora.org>
diff --git a/shortcut-fe/sfe_ipv4.c b/shortcut-fe/sfe_ipv4.c
index 6a12317..7bcdf69 100644
--- a/shortcut-fe/sfe_ipv4.c
+++ b/shortcut-fe/sfe_ipv4.c
@@ -1057,7 +1057,8 @@
  * already held or isn't required.
  */
 static void sfe_ipv4_gen_sync_sfe_ipv4_connection(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c,
-						  struct sfe_connection_sync *sis, uint64_t now_jiffies)
+						  struct sfe_connection_sync *sis, sfe_sync_reason_t reason,
+						  uint64_t now_jiffies)
 {
 	struct sfe_ipv4_connection_match *original_cm;
 	struct sfe_ipv4_connection_match *reply_cm;
@@ -1068,9 +1069,13 @@
 	sis->is_v6 = 0;
 	sis->protocol = c->protocol;
 	sis->src_ip.ip = c->src_ip;
+	sis->src_ip_xlate.ip = c->src_ip_xlate;
 	sis->dest_ip.ip = c->dest_ip;
+	sis->dest_ip_xlate.ip = c->dest_ip_xlate;
 	sis->src_port = c->src_port;
+	sis->src_port_xlate = c->src_port_xlate;
 	sis->dest_port = c->dest_port;
+	sis->dest_port_xlate = c->dest_port_xlate;
 
 	original_cm = c->original_match;
 	reply_cm = c->reply_match;
@@ -1097,6 +1102,8 @@
 	sis->dest_packet_count = reply_cm->rx_packet_count64;
 	sis->dest_byte_count = reply_cm->rx_byte_count64;
 
+	sis->reason = reason;
+
 	/*
 	 * Get the time increment since our last sync.
 	 */
@@ -1113,7 +1120,7 @@
  * from within a BH and so we're fine, but we're also called when connections are
  * torn down.
  */
-static void sfe_ipv4_flush_sfe_ipv4_connection(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c)
+static void sfe_ipv4_flush_sfe_ipv4_connection(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c, sfe_sync_reason_t reason)
 {
 	struct sfe_connection_sync sis;
 	uint64_t now_jiffies;
@@ -1130,7 +1137,7 @@
 		 * Generate a sync message and then sync.
 		 */
 		now_jiffies = get_jiffies_64();
-		sfe_ipv4_gen_sync_sfe_ipv4_connection(si, c, &sis, now_jiffies);
+		sfe_ipv4_gen_sync_sfe_ipv4_connection(si, c, &sis, reason, now_jiffies);
 		sync_rule_callback(&sis);
 	}
 
@@ -1223,7 +1230,7 @@
 		spin_unlock_bh(&si->lock);
 
 		DEBUG_TRACE("flush on find\n");
-		sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+		sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 		return 0;
 	}
 
@@ -1251,7 +1258,7 @@
 		spin_unlock_bh(&si->lock);
 
 		DEBUG_TRACE("ttl too low\n");
-		sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+		sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 		return 0;
 	}
 
@@ -1267,7 +1274,7 @@
 		spin_unlock_bh(&si->lock);
 
 		DEBUG_TRACE("larger than mtu\n");
-		sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+		sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 		return 0;
 	}
 
@@ -1592,7 +1599,7 @@
 		spin_unlock_bh(&si->lock);
 
 		DEBUG_TRACE("flush on find\n");
-		sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+		sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 		return 0;
 	}
 
@@ -1619,7 +1626,7 @@
 		spin_unlock_bh(&si->lock);
 
 		DEBUG_TRACE("ttl too low\n");
-		sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+		sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 		return 0;
 	}
 
@@ -1635,7 +1642,7 @@
 		spin_unlock_bh(&si->lock);
 
 		DEBUG_TRACE("larger than mtu\n");
-		sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+		sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 		return 0;
 	}
 
@@ -1652,7 +1659,7 @@
 
 		DEBUG_TRACE("TCP flags: 0x%x are not fast\n",
 			    flags & (TCP_FLAG_SYN | TCP_FLAG_RST | TCP_FLAG_FIN | TCP_FLAG_ACK));
-		sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+		sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 		return 0;
 	}
 
@@ -1684,7 +1691,7 @@
 
 			DEBUG_TRACE("seq: %u exceeds right edge: %u\n",
 				    seq, cm->protocol_state.tcp.max_end + 1);
-			sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+			sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 			return 0;
 		}
 
@@ -1700,7 +1707,7 @@
 			spin_unlock_bh(&si->lock);
 
 			DEBUG_TRACE("TCP data offset: %u, too small\n", data_offs);
-			sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+			sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 			return 0;
 		}
 
@@ -1717,7 +1724,7 @@
 			spin_unlock_bh(&si->lock);
 
 			DEBUG_TRACE("TCP option SACK size is wrong\n");
-			sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+			sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 			return 0;
 		}
 
@@ -1734,7 +1741,7 @@
 
 			DEBUG_TRACE("TCP data offset: %u, past end of packet: %u\n",
 				    data_offs, len);
-			sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+			sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 			return 0;
 		}
 
@@ -1753,7 +1760,7 @@
 
 			DEBUG_TRACE("seq: %u before left edge: %u\n",
 				    end, cm->protocol_state.tcp.end - counter_cm->protocol_state.tcp.max_win - 1);
-			sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+			sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 			return 0;
 		}
 
@@ -1769,7 +1776,7 @@
 
 			DEBUG_TRACE("ack: %u exceeds right edge: %u\n",
 				    sack, counter_cm->protocol_state.tcp.end + 1);
-			sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+			sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 			return 0;
 		}
 
@@ -1788,7 +1795,7 @@
 			spin_unlock_bh(&si->lock);
 
 			DEBUG_TRACE("ack: %u before left edge: %u\n", sack, left_edge);
-			sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+			sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 			return 0;
 		}
 
@@ -2148,7 +2155,7 @@
 	si->packets_not_forwarded++;
 	spin_unlock_bh(&si->lock);
 
-	sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+	sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_FLUSH);
 	return 0;
 }
 
@@ -2653,7 +2660,7 @@
 	sfe_ipv4_remove_sfe_ipv4_connection(si, c);
 	spin_unlock_bh(&si->lock);
 
-	sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+	sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_DESTROY);
 
 	DEBUG_INFO("connection destroyed - p: %d, s: %pI4:%u, d: %pI4:%u\n",
 		   sid->protocol, &sid->src_ip.ip, ntohs(sid->src_port),
@@ -2730,7 +2737,7 @@
 	spin_unlock_bh(&si->lock);
 
 	if (c) {
-		sfe_ipv4_flush_sfe_ipv4_connection(si, c);
+		sfe_ipv4_flush_sfe_ipv4_connection(si, c, SFE_SYNC_REASON_DESTROY);
 		goto another_round;
 	}
 }
@@ -2817,7 +2824,7 @@
 		 * Sync the connection state.
 		 */
 		c = cm->connection;
-		sfe_ipv4_gen_sync_sfe_ipv4_connection(si, c, &sis, now_jiffies);
+		sfe_ipv4_gen_sync_sfe_ipv4_connection(si, c, &sis, SFE_SYNC_REASON_STATS, now_jiffies);
 
 		/*
 		 * We don't want to be holding the lock when we sync!