[1/2] example: ipsec: fix endianness of IP address checks

Message ID 1452080019-25124-1-git-send-email-stuart.haslam@linaro.org
State New
Headers show

Commit Message

Stuart Haslam Jan. 6, 2016, 11:33 a.m.
Convert IP addresses in packet header from network to CPU byte order
before comparing with policy cache.

Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>
---
 example/ipsec/odp_ipsec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Bill Fischofer Jan. 7, 2016, 12:08 a.m. | #1
On Wed, Jan 6, 2016 at 5:33 AM, Stuart Haslam <stuart.haslam@linaro.org>
wrote:

> Convert IP addresses in packet header from network to CPU byte order

> before comparing with policy cache.

>

> Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>

>


Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>



> ---

>  example/ipsec/odp_ipsec.c | 4 ++--

>  1 file changed, 2 insertions(+), 2 deletions(-)

>

> diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c

> index fab1035..45892f9 100644

> --- a/example/ipsec/odp_ipsec.c

> +++ b/example/ipsec/odp_ipsec.c

> @@ -771,8 +771,8 @@ pkt_disposition_e do_ipsec_in_finish(odp_packet_t pkt,

>                 ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);

>

>                 /* Check inbound policy */

> -               if ((ip->src_addr != ctx->ipsec.src_ip ||

> -                    ip->dst_addr != ctx->ipsec.dst_ip))

> +               if ((odp_be_to_cpu_32(ip->src_addr) != ctx->ipsec.src_ip ||

> +                    odp_be_to_cpu_32(ip->dst_addr) != ctx->ipsec.dst_ip))

>                         return PKT_DROP;

>

>                 return PKT_CONTINUE;

> --

> 2.1.1

>

> _______________________________________________

> lng-odp mailing list

> lng-odp@lists.linaro.org

> https://lists.linaro.org/mailman/listinfo/lng-odp

>

Patch

diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index fab1035..45892f9 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -771,8 +771,8 @@  pkt_disposition_e do_ipsec_in_finish(odp_packet_t pkt,
 		ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
 
 		/* Check inbound policy */
-		if ((ip->src_addr != ctx->ipsec.src_ip ||
-		     ip->dst_addr != ctx->ipsec.dst_ip))
+		if ((odp_be_to_cpu_32(ip->src_addr) != ctx->ipsec.src_ip ||
+		     odp_be_to_cpu_32(ip->dst_addr) != ctx->ipsec.dst_ip))
 			return PKT_DROP;
 
 		return PKT_CONTINUE;