ipsec: Revert "IPSEC: remove byte swap operations in DP during SPD classify"

Type: fix
Fixes: 231c4696872cb344f28648949603840136c0795d

This reverts commit 231c4696872cb344f28648949603840136c0795d.

Change-Id: I136344555983dd10a31dbc000ee40e2de2c91291
Signed-off-by: Neale Ranns <nranns@cisco.com>
diff --git a/src/vnet/ipsec/ipsec_api.c b/src/vnet/ipsec/ipsec_api.c
index 99e25f1..6de0203 100644
--- a/src/vnet/ipsec/ipsec_api.c
+++ b/src/vnet/ipsec/ipsec_api.c
@@ -278,11 +278,10 @@
   p.is_ipv6 = (itype == IP46_TYPE_IP6);
 
   p.protocol = mp->entry.protocol;
-  /* leave the ports in network order */
-  p.rport.start = mp->entry.remote_port_start;
-  p.rport.stop = mp->entry.remote_port_stop;
-  p.lport.start = mp->entry.local_port_start;
-  p.lport.stop = mp->entry.local_port_stop;
+  p.rport.start = ntohs (mp->entry.remote_port_start);
+  p.rport.stop = ntohs (mp->entry.remote_port_stop);
+  p.lport.start = ntohs (mp->entry.local_port_start);
+  p.lport.stop = ntohs (mp->entry.local_port_stop);
 
   rv = ipsec_spd_action_decode (mp->entry.policy, &p.policy);
 
@@ -616,10 +615,10 @@
 		     &mp->entry.remote_address_start);
   ip_address_encode (&p->raddr.stop, IP46_TYPE_ANY,
 		     &mp->entry.remote_address_stop);
-  mp->entry.local_port_start = p->lport.start;
-  mp->entry.local_port_stop = p->lport.stop;
-  mp->entry.remote_port_start = p->rport.start;
-  mp->entry.remote_port_stop = p->rport.stop;
+  mp->entry.local_port_start = htons (p->lport.start);
+  mp->entry.local_port_stop = htons (p->lport.stop);
+  mp->entry.remote_port_start = htons (p->rport.start);
+  mp->entry.remote_port_stop = htons (p->rport.stop);
   mp->entry.protocol = p->protocol;
   mp->entry.policy = ipsec_spd_action_encode (p->policy);
   mp->entry.sa_id = htonl (p->sa_id);
diff --git a/src/vnet/ipsec/ipsec_cli.c b/src/vnet/ipsec/ipsec_cli.c
index 1648179..60b9244 100644
--- a/src/vnet/ipsec/ipsec_cli.c
+++ b/src/vnet/ipsec/ipsec_cli.c
@@ -294,16 +294,12 @@
 	{
 	  p.lport.start = tmp;
 	  p.lport.stop = tmp2;
-	  p.lport.start = clib_host_to_net_u16 (p.lport.start);
-	  p.lport.stop = clib_host_to_net_u16 (p.lport.stop);
 	}
       else
 	if (unformat (line_input, "remote-port-range %u - %u", &tmp, &tmp2))
 	{
 	  p.rport.start = tmp;
 	  p.rport.stop = tmp2;
-	  p.rport.start = clib_host_to_net_u16 (p.rport.start);
-	  p.rport.stop = clib_host_to_net_u16 (p.rport.stop);
 	}
       else
 	{
diff --git a/src/vnet/ipsec/ipsec_format.c b/src/vnet/ipsec/ipsec_format.c
index 1c3c5f9..a0cd5ad 100644
--- a/src/vnet/ipsec/ipsec_format.c
+++ b/src/vnet/ipsec/ipsec_format.c
@@ -187,13 +187,11 @@
   s = format (s, "\n     local addr range %U - %U port range %u - %u",
 	      format_ip46_address, &p->laddr.start, ip_type,
 	      format_ip46_address, &p->laddr.stop, ip_type,
-	      clib_net_to_host_u16 (p->lport.start),
-	      clib_net_to_host_u16 (p->lport.stop));
+	      p->lport.start, p->lport.stop);
   s = format (s, "\n     remote addr range %U - %U port range %u - %u",
 	      format_ip46_address, &p->raddr.start, ip_type,
 	      format_ip46_address, &p->raddr.stop, ip_type,
-	      clib_net_to_host_u16 (p->rport.start),
-	      clib_net_to_host_u16 (p->rport.stop));
+	      p->rport.start, p->rport.stop);
 
   vlib_get_combined_counter (&ipsec_spd_policy_counters, pi, &counts);
   s = format (s, "\n     packets %u bytes %u", counts.packets, counts.bytes);
diff --git a/src/vnet/ipsec/ipsec_output.c b/src/vnet/ipsec/ipsec_output.c
index 25a427f..2ba965a 100644
--- a/src/vnet/ipsec/ipsec_output.c
+++ b/src/vnet/ipsec/ipsec_output.c
@@ -82,16 +82,16 @@
     if (PREDICT_FALSE (p->protocol && (p->protocol != pr)))
       continue;
 
-    if (ra < p->raddr.start.ip4.as_u32)
+    if (ra < clib_net_to_host_u32 (p->raddr.start.ip4.as_u32))
       continue;
 
-    if (ra > p->raddr.stop.ip4.as_u32)
+    if (ra > clib_net_to_host_u32 (p->raddr.stop.ip4.as_u32))
       continue;
 
-    if (la < p->laddr.start.ip4.as_u32)
+    if (la < clib_net_to_host_u32 (p->laddr.start.ip4.as_u32))
       continue;
 
-    if (la > p->laddr.stop.ip4.as_u32)
+    if (la > clib_net_to_host_u32 (p->laddr.stop.ip4.as_u32))
       continue;
 
     if (PREDICT_FALSE
@@ -246,8 +246,10 @@
 	  p0 = ipsec6_output_policy_match (spd0,
 					   &ip6_0->src_address,
 					   &ip6_0->dst_address,
-					   udp0->src_port,
-					   udp0->dst_port, ip6_0->protocol);
+					   clib_net_to_host_u16
+					   (udp0->src_port),
+					   clib_net_to_host_u16
+					   (udp0->dst_port), ip6_0->protocol);
 	}
       else
 	{
@@ -263,9 +265,14 @@
 #endif
 
 	  p0 = ipsec_output_policy_match (spd0, ip0->protocol,
-					  ip0->src_address.as_u32,
-					  ip0->dst_address.as_u32,
-					  udp0->src_port, udp0->dst_port);
+					  clib_net_to_host_u32
+					  (ip0->src_address.as_u32),
+					  clib_net_to_host_u32
+					  (ip0->dst_address.as_u32),
+					  clib_net_to_host_u16
+					  (udp0->src_port),
+					  clib_net_to_host_u16
+					  (udp0->dst_port));
 	}
       tcp0 = (void *) udp0;
 
diff --git a/src/vnet/ipsec/ipsec_spd_policy.h b/src/vnet/ipsec/ipsec_spd_policy.h
index d4472e6..6d6b695 100644
--- a/src/vnet/ipsec/ipsec_spd_policy.h
+++ b/src/vnet/ipsec/ipsec_spd_policy.h
@@ -39,7 +39,6 @@
 
 typedef struct
 {
-  /* Ports stored in network byte order */
   u16 start, stop;
 } port_range_t;