Skip to content

Commit

Permalink
app/testpmd: fix IP checksum calculation
Browse files Browse the repository at this point in the history
[ upstream commit d841ef8 ]

Strict-aliasing rules are violated by cast to uint16_t* in flowgen.c and
the calculated IP checksum is wrong. Use attribute __may_alias__ to fix
the problem.

Fixes: e9e23a6 ("app/testpmd: add flowgen forwarding engine")

Signed-off-by: George Prekas <prekageo@amazon.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
  • Loading branch information
prekageo authored and bluca committed Feb 4, 2021
1 parent 7cef997 commit a098beb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/test-pmd/flowgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ static struct rte_ether_addr cfg_ether_dst =

#define IP_DEFTTL 64 /* from RFC 1340. */

/* Use this type to inform GCC that ip_sum violates aliasing rules. */
typedef unaligned_uint16_t alias_int16_t __attribute__((__may_alias__));

static inline uint16_t
ip_sum(const unaligned_uint16_t *hdr, int hdr_len)
ip_sum(const alias_int16_t *hdr, int hdr_len)
{
uint32_t sum = 0;

Expand Down Expand Up @@ -150,7 +153,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
next_flow);
ip_hdr->total_length = RTE_CPU_TO_BE_16(pkt_size -
sizeof(*eth_hdr));
ip_hdr->hdr_checksum = ip_sum((unaligned_uint16_t *)ip_hdr,
ip_hdr->hdr_checksum = ip_sum((const alias_int16_t *)ip_hdr,
sizeof(*ip_hdr));

/* Initialize UDP header. */
Expand Down

0 comments on commit a098beb

Please sign in to comment.