diff mbox

[PATCHv1,1/1] validation: pktio: fix invalid mac addr

Message ID 1478179275-26374-1-git-send-email-bala.manoharan@linaro.org
State New
Headers show

Commit Message

Balasubramanian Manoharan Nov. 3, 2016, 1:21 p.m. UTC
Fixes https://bugs.linaro.org/show_bug.cgi?id=2496

Signed-off-by: Balasubramanian Manoharan <bala.manoharan@linaro.org>

---
 test/common_plat/validation/api/pktio/pktio.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

-- 
1.9.1

Comments

Josep Puigdemont Nov. 3, 2016, 1:29 p.m. UTC | #1
On Thu, Nov 03, 2016 at 06:51:15PM +0530, Balasubramanian Manoharan wrote:
> Fixes https://bugs.linaro.org/show_bug.cgi?id=2496

> 

> Signed-off-by: Balasubramanian Manoharan <bala.manoharan@linaro.org>

> ---

>  test/common_plat/validation/api/pktio/pktio.c | 17 ++++++++++++++---

>  1 file changed, 14 insertions(+), 3 deletions(-)

> 

> diff --git a/test/common_plat/validation/api/pktio/pktio.c b/test/common_plat/validation/api/pktio/pktio.c

> index a6a18c3..4bc7e0a 100644

> --- a/test/common_plat/validation/api/pktio/pktio.c

> +++ b/test/common_plat/validation/api/pktio/pktio.c

> @@ -241,16 +241,27 @@ static uint32_t pktio_init_packet(odp_packet_t pkt)

>  	odph_udphdr_t *udp;

>  	char *buf;

>  	uint16_t seq;

> -	uint8_t mac[ODP_PKTIO_MACADDR_MAXSIZE] = {0};

> +	uint64_t src_mac = 0x010203040506;

> +	uint64_t dst_mac = 0x070809101112;

> +	uint64_t src_mac_be;

> +	uint64_t dst_mac_be;


it might be easyer and more portable to save the mac addresses as:
uint8_t src_mac[ODP_PKTIO_MACADDR_MAXSIZE] = {1, 2, 3, 4, 5, 6};

>  	int pkt_len = odp_packet_len(pkt);

>  

> +	dst_mac_be = odp_cpu_to_be_64(dst_mac);

> +	if (dst_mac != dst_mac_be)

> +		dst_mac_be = dst_mac_be >> (64 - 8 * ODPH_ETHADDR_LEN);

> +

> +	src_mac_be = odp_cpu_to_be_64(src_mac);

> +	if (src_mac != src_mac_be)

> +		src_mac_be = src_mac_be >> (64 - 8 * ODPH_ETHADDR_LEN);

> +

>  	buf = odp_packet_data(pkt);

>  

>  	/* Ethernet */

>  	odp_packet_l2_offset_set(pkt, 0);

>  	eth = (odph_ethhdr_t *)buf;

> -	memcpy(eth->src.addr, mac, ODPH_ETHADDR_LEN);

> -	memcpy(eth->dst.addr, mac, ODPH_ETHADDR_LEN);

> +	memcpy(eth->src.addr, &src_mac_be, ODPH_ETHADDR_LEN);

> +	memcpy(eth->dst.addr, &dst_mac_be, ODPH_ETHADDR_LEN);

>  	eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4);

>  

>  	/* IP */

> -- 

> 1.9.1

>
diff mbox

Patch

diff --git a/test/common_plat/validation/api/pktio/pktio.c b/test/common_plat/validation/api/pktio/pktio.c
index a6a18c3..4bc7e0a 100644
--- a/test/common_plat/validation/api/pktio/pktio.c
+++ b/test/common_plat/validation/api/pktio/pktio.c
@@ -241,16 +241,27 @@  static uint32_t pktio_init_packet(odp_packet_t pkt)
 	odph_udphdr_t *udp;
 	char *buf;
 	uint16_t seq;
-	uint8_t mac[ODP_PKTIO_MACADDR_MAXSIZE] = {0};
+	uint64_t src_mac = 0x010203040506;
+	uint64_t dst_mac = 0x070809101112;
+	uint64_t src_mac_be;
+	uint64_t dst_mac_be;
 	int pkt_len = odp_packet_len(pkt);
 
+	dst_mac_be = odp_cpu_to_be_64(dst_mac);
+	if (dst_mac != dst_mac_be)
+		dst_mac_be = dst_mac_be >> (64 - 8 * ODPH_ETHADDR_LEN);
+
+	src_mac_be = odp_cpu_to_be_64(src_mac);
+	if (src_mac != src_mac_be)
+		src_mac_be = src_mac_be >> (64 - 8 * ODPH_ETHADDR_LEN);
+
 	buf = odp_packet_data(pkt);
 
 	/* Ethernet */
 	odp_packet_l2_offset_set(pkt, 0);
 	eth = (odph_ethhdr_t *)buf;
-	memcpy(eth->src.addr, mac, ODPH_ETHADDR_LEN);
-	memcpy(eth->dst.addr, mac, ODPH_ETHADDR_LEN);
+	memcpy(eth->src.addr, &src_mac_be, ODPH_ETHADDR_LEN);
+	memcpy(eth->dst.addr, &dst_mac_be, ODPH_ETHADDR_LEN);
 	eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4);
 
 	/* IP */