example/ipsec_crypto/odp_ipsec.c
static
pkt_disposition_e do_ipsec_in_finish(odp_packet_t pkt,
				     pkt_ctx_t *ctx)
{
	odph_ipv4hdr_t *ip;
	odp_crypto_packet_result_t result;
	int hdr_len = ctx->ipsec.hdr_len;
	int trl_len = 0;

	odp_crypto_result(&result, pkt);

	/* Check crypto result */
	if (!result.ok) {
		if (!is_crypto_op_status_ok(&result.cipher_status))
			return PKT_DROP;
		if (!is_crypto_op_status_ok(&result.auth_status))
			return PKT_DROP;
	}
	ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);

	/*
	 * Finish auth
	 */
	if (ctx->ipsec.ah_offset) {
		uint8_t *buf = odp_packet_data(pkt);
		odph_ahhdr_t *ah;

		ah = (odph_ahhdr_t *)(ctx->ipsec.ah_offset + buf);
		ip->proto = ah->next_header;
	}

	/*
	 * Finish cipher by finding ESP trailer and processing
	 *
	 * NOTE: ESP authentication ICV not supported
	 */
	if (ctx->ipsec.esp_offset) {
		uint8_t *eop = (uint8_t *)(ip) + odp_be_to_cpu_16(ip->tot_len);
		odph_esptrl_t *esp_t = (odph_esptrl_t *)(eop) - 1;

		ip->proto = esp_t->next_header;
		trl_len += esp_t->pad_len + sizeof(*esp_t);
	}

	/* We have a tunneled IPv4 packet */
	if (ip->proto == ODPH_IPV4) {
		odp_packet_pull_head(pkt, sizeof(*ip) + hdr_len);
		odp_packet_pull_tail(pkt, trl_len);
		odph_ethhdr_t *eth;

		eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);
		eth->type = ODPH_ETHTYPE_IPV4;
		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))
			return PKT_DROP;

		return PKT_CONTINUE;
	}

	/* Finalize the IPv4 header */
	ipv4_adjust_len(ip, -(hdr_len + trl_len));
	ip->ttl = ctx->ipsec.ip_ttl;
	ip->tos = ctx->ipsec.ip_tos;
	ip->frag_offset = odp_cpu_to_be_16(ctx->ipsec.ip_frag_offset);
	ip->chksum = 0;
	odph_ipv4_csum_update(pkt);

	/* Correct the packet length and move payload into position */
	memmove(ipv4_data_p(ip),
		ipv4_data_p(ip) + hdr_len,
		odp_be_to_cpu_16(ip->tot_len));
	odp_packet_pull_tail(pkt, hdr_len + trl_len);

	/* Fall through to next state */
	return PKT_CONTINUE;
}
/**
 * Packet Processing - Input IPsec packet processing cleanup
 *
 * @param pkt  Packet to handle
 * @param ctx  Packet process context
 *
 * @return PKT_CONTINUE if successful else PKT_DROP
 */
Packet Processing - Input IPsec packet processing cleanup
@param pkt  Packet to handle
@param ctx  Packet process context


Packet Processing - Input IPsec packet processing cleanup @param pkt Packet to handle @param ctx Packet process context
static
pkt_disposition_e do_ipsec_in_finish(odp_packet_t pkt,
				     pkt_ctx_t *ctx)
{
	odph_ipv4hdr_t *ip;
	odp_crypto_packet_result_t result;
	int hdr_len = ctx->ipsec.hdr_len;
	int trl_len = 0;
	odp_crypto_result(&result, pkt);
	if (!result.ok) {
		if (!is_crypto_op_status_ok(&result.cipher_status))
			return PKT_DROP;
		if (!is_crypto_op_status_ok(&result.auth_status))
			return PKT_DROP;
	}
	ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
	if (ctx->ipsec.ah_offset) {
		uint8_t *buf = odp_packet_data(pkt);
		odph_ahhdr_t *ah;
		ah = (odph_ahhdr_t *)(ctx->ipsec.ah_offset + buf);
		ip->proto = ah->next_header;
	}
	if (ctx->ipsec.esp_offset) {
		uint8_t *eop = (uint8_t *)(ip) + odp_be_to_cpu_16(ip->tot_len);
		odph_esptrl_t *esp_t = (odph_esptrl_t *)(eop) - 1;
		ip->proto = esp_t->next_header;
		trl_len += esp_t->pad_len + sizeof(*esp_t);
	}
	if (ip->proto == ODPH_IPV4) {
		odp_packet_pull_head(pkt, sizeof(*ip) + hdr_len);
		odp_packet_pull_tail(pkt, trl_len);
		odph_ethhdr_t *eth;
		eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);
		eth->type = ODPH_ETHTYPE_IPV4;
		ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
		if ((ip->src_addr != ctx->ipsec.src_ip ||
		     ip->dst_addr != ctx->ipsec.dst_ip))
			return PKT_DROP;
		return PKT_CONTINUE;
	}
	ipv4_adjust_len(ip, -(hdr_len + trl_len));
	ip->ttl = ctx->ipsec.ip_ttl;
	ip->tos = ctx->ipsec.ip_tos;
	ip->frag_offset = odp_cpu_to_be_16(ctx->ipsec.ip_frag_offset);
	ip->chksum = 0;
	odph_ipv4_csum_update(pkt);
	memmove(ipv4_data_p(ip),
		ipv4_data_p(ip) + hdr_len,
		odp_be_to_cpu_16(ip->tot_len));
	odp_packet_pull_tail(pkt, hdr_len + trl_len);
	return PKT_CONTINUE;
}
static pkt_disposition_e do_ipsec_in_finish ( odp_packet_t pkt , pkt_ctx_t * ctx ) { odph_ipv4hdr_t * ip ; odp_crypto_packet_result_t result ; int hdr_len = ctx -> ipsec . hdr_len ; int trl_len = 0 ; odp_crypto_result ( & result , pkt ) ; if ( ! result . ok ) { if ( ! is_crypto_op_status_ok ( & result . cipher_status ) ) return PKT_DROP ; if ( ! is_crypto_op_status_ok ( & result . auth_status ) ) return PKT_DROP ; } ip = ( odph_ipv4hdr_t * ) odp_packet_l3_ptr ( pkt , NULL ) ; if ( ctx -> ipsec . ah_offset ) { uint8_t * buf = odp_packet_data ( pkt ) ; odph_ahhdr_t * ah ; ah = ( odph_ahhdr_t * ) ( ctx -> ipsec . ah_offset + buf ) ; ip -> proto = ah -> next_header ; } if ( ctx -> ipsec . esp_offset ) { uint8_t * eop = ( uint8_t * ) ( ip ) + odp_be_to_cpu_16 ( ip -> tot_len ) ; odph_esptrl_t * esp_t = ( odph_esptrl_t * ) ( eop ) - 1 ; ip -> proto = esp_t -> next_header ; trl_len += esp_t -> pad_len + sizeof ( * esp_t ) ; } if ( ip -> proto == ODPH_IPV4 ) { odp_packet_pull_head ( pkt , sizeof ( * ip ) + hdr_len ) ; odp_packet_pull_tail ( pkt , trl_len ) ; odph_ethhdr_t * eth ; eth = ( odph_ethhdr_t * ) odp_packet_l2_ptr ( pkt , NULL ) ; eth -> type = ODPH_ETHTYPE_IPV4 ; ip = ( odph_ipv4hdr_t * ) odp_packet_l3_ptr ( pkt , NULL ) ; if ( ( ip -> src_addr != ctx -> ipsec . src_ip || ip -> dst_addr != ctx -> ipsec . dst_ip ) ) return PKT_DROP ; return PKT_CONTINUE ; } ipv4_adjust_len ( ip , - ( hdr_len + trl_len ) ) ; ip -> ttl = ctx -> ipsec . ip_ttl ; ip -> tos = ctx -> ipsec . ip_tos ; ip -> frag_offset = odp_cpu_to_be_16 ( ctx -> ipsec . ip_frag_offset ) ; ip -> chksum = 0 ; odph_ipv4_csum_update ( pkt ) ; memmove ( ipv4_data_p ( ip ) , ipv4_data_p ( ip ) + hdr_len , odp_be_to_cpu_16 ( ip -> tot_len ) ) ; odp_packet_pull_tail ( pkt , hdr_len + trl_len ) ; return PKT_CONTINUE ; }
Packet Processing - Input IPsec packet processing cleanup
 @param pkt  Packet to handle
 @param ctx  Packet process context
Packet Processing - Input IPsec packet processing cleanup @param pkt Packet to handle @param ctx Packet process context
/* Check crypto result */ /*
	 * Finish auth
	 */ /*
	 * Finish cipher by finding ESP trailer and processing
	 *
	 * NOTE: ESP authentication ICV not supported
	 */ /* We have a tunneled IPv4 packet */ /* Check inbound policy */ /* Finalize the IPv4 header */ /* Correct the packet length and move payload into position */ /* Fall through to next state */