test/validation/api/ipsec/ipsec.c
static void ipsec_check_packet(const ipsec_test_packet *itp, odp_packet_t pkt,
			       odp_bool_t is_outbound)
{
	uint32_t len = (ODP_PACKET_INVALID == pkt) ? 1 : odp_packet_len(pkt);
	uint32_t l3, l4;
	uint8_t data[len];
	const odph_ipv4hdr_t *itp_ip;
	odph_ipv4hdr_t *ip;

	if (NULL == itp)
		return;

	l3 = odp_packet_l3_offset(pkt);
	l4 = odp_packet_l4_offset(pkt);
	odp_packet_copy_to_mem(pkt, 0, len, data);

	if (l3 == ODP_PACKET_OFFSET_INVALID) {
		CU_ASSERT_EQUAL(itp->l3_offset, ODP_PACKET_OFFSET_INVALID);
		CU_ASSERT_EQUAL(l4, ODP_PACKET_OFFSET_INVALID);

		return;
	}

	CU_ASSERT_EQUAL(len - l3, itp->len - itp->l3_offset);
	if (len - l3 != itp->len - itp->l3_offset)
		return;

	CU_ASSERT_EQUAL(l4 - l3, itp->l4_offset - itp->l3_offset);
	if (l4 - l3 != itp->l4_offset - itp->l3_offset)
		return;

	ip = (odph_ipv4hdr_t *) &data[l3];
	itp_ip = (const odph_ipv4hdr_t *) &itp->data[itp->l3_offset];
	if (ODPH_IPV4HDR_VER(ip->ver_ihl) == ODPH_IPV4 &&
	    is_outbound &&
	    ip->id != itp_ip->id) {
		/*
		 * IP ID value chosen by the implementation differs
		 * from the IP value in our test vector. This requires
		 * special handling in outbound checks.
		 */
		/*
		 * Let's change IP ID and header checksum to same values
		 * as in the test vector to facilitate packet comparison.
		 */
		CU_ASSERT(odph_ipv4_csum_valid(pkt));
		ip->id = itp_ip->id;
		ip->chksum = itp_ip->chksum;

		if (ip->proto == ODPH_IPPROTO_AH) {
			/*
			 * ID field is included in the authentication so
			 * we cannot check ICV against our test vector.
			 * Check packet data before the first possible
			 * location of the AH ICV field.
			 */
			CU_ASSERT_EQUAL(0, memcmp(data + l3,
						  itp->data + itp->l3_offset,
						  ODPH_IPV4HDR_LEN + 12));
			return;
		}
	}

	CU_ASSERT_EQUAL(0, memcmp(data + l3,
				  itp->data + itp->l3_offset,
				  len - l3));
}
/*
 * Compare packages ignoring everything before L3 header
 */
Compare packages ignoring everything before L3 header
Compare packages ignoring everything before L3 header
static void ipsec_check_packet(const ipsec_test_packet *itp, odp_packet_t pkt,
			       odp_bool_t is_outbound)
{
	uint32_t len = (ODP_PACKET_INVALID == pkt) ? 1 : odp_packet_len(pkt);
	uint32_t l3, l4;
	uint8_t data[len];
	const odph_ipv4hdr_t *itp_ip;
	odph_ipv4hdr_t *ip;
	if (NULL == itp)
		return;
	l3 = odp_packet_l3_offset(pkt);
	l4 = odp_packet_l4_offset(pkt);
	odp_packet_copy_to_mem(pkt, 0, len, data);
	if (l3 == ODP_PACKET_OFFSET_INVALID) {
		CU_ASSERT_EQUAL(itp->l3_offset, ODP_PACKET_OFFSET_INVALID);
		CU_ASSERT_EQUAL(l4, ODP_PACKET_OFFSET_INVALID);
		return;
	}
	CU_ASSERT_EQUAL(len - l3, itp->len - itp->l3_offset);
	if (len - l3 != itp->len - itp->l3_offset)
		return;
	CU_ASSERT_EQUAL(l4 - l3, itp->l4_offset - itp->l3_offset);
	if (l4 - l3 != itp->l4_offset - itp->l3_offset)
		return;
	ip = (odph_ipv4hdr_t *) &data[l3];
	itp_ip = (const odph_ipv4hdr_t *) &itp->data[itp->l3_offset];
	if (ODPH_IPV4HDR_VER(ip->ver_ihl) == ODPH_IPV4 &&
	    is_outbound &&
	    ip->id != itp_ip->id) {
		CU_ASSERT(odph_ipv4_csum_valid(pkt));
		ip->id = itp_ip->id;
		ip->chksum = itp_ip->chksum;
		if (ip->proto == ODPH_IPPROTO_AH) {
			CU_ASSERT_EQUAL(0, memcmp(data + l3,
						  itp->data + itp->l3_offset,
						  ODPH_IPV4HDR_LEN + 12));
			return;
		}
	}
	CU_ASSERT_EQUAL(0, memcmp(data + l3,
				  itp->data + itp->l3_offset,
				  len - l3));
}
static void ipsec_check_packet ( const ipsec_test_packet * itp , odp_packet_t pkt , odp_bool_t is_outbound ) { uint32_t len = ( ODP_PACKET_INVALID == pkt ) ? 1 : odp_packet_len ( pkt ) ; uint32_t l3 , l4 ; uint8_t data [ len ] ; const odph_ipv4hdr_t * itp_ip ; odph_ipv4hdr_t * ip ; if ( NULL == itp ) return ; l3 = odp_packet_l3_offset ( pkt ) ; l4 = odp_packet_l4_offset ( pkt ) ; odp_packet_copy_to_mem ( pkt , 0 , len , data ) ; if ( l3 == ODP_PACKET_OFFSET_INVALID ) { CU_ASSERT_EQUAL ( itp -> l3_offset , ODP_PACKET_OFFSET_INVALID ) ; CU_ASSERT_EQUAL ( l4 , ODP_PACKET_OFFSET_INVALID ) ; return ; } CU_ASSERT_EQUAL ( len - l3 , itp -> len - itp -> l3_offset ) ; if ( len - l3 != itp -> len - itp -> l3_offset ) return ; CU_ASSERT_EQUAL ( l4 - l3 , itp -> l4_offset - itp -> l3_offset ) ; if ( l4 - l3 != itp -> l4_offset - itp -> l3_offset ) return ; ip = ( odph_ipv4hdr_t * ) & data [ l3 ] ; itp_ip = ( const odph_ipv4hdr_t * ) & itp -> data [ itp -> l3_offset ] ; if ( ODPH_IPV4HDR_VER ( ip -> ver_ihl ) == ODPH_IPV4 && is_outbound && ip -> id != itp_ip -> id ) { CU_ASSERT ( odph_ipv4_csum_valid ( pkt ) ) ; ip -> id = itp_ip -> id ; ip -> chksum = itp_ip -> chksum ; if ( ip -> proto == ODPH_IPPROTO_AH ) { CU_ASSERT_EQUAL ( 0 , memcmp ( data + l3 , itp -> data + itp -> l3_offset , ODPH_IPV4HDR_LEN + 12 ) ) ; return ; } } CU_ASSERT_EQUAL ( 0 , memcmp ( data + l3 , itp -> data + itp -> l3_offset , len - l3 ) ) ; }
Compare packages ignoring everything before L3 header
Compare packages ignoring everything before L3 header
/*
		 * IP ID value chosen by the implementation differs
		 * from the IP value in our test vector. This requires
		 * special handling in outbound checks.
		 */ /*
		 * Let's change IP ID and header checksum to same values
		 * as in the test vector to facilitate packet comparison.
		 */ /*
			 * ID field is included in the authentication so
			 * we cannot check ICV against our test vector.
			 * Check packet data before the first possible
			 * location of the AH ICV field.
			 */