example/ipsec_crypto/odp_ipsec.c
static
pkt_disposition_e do_ipsec_in_classify(odp_packet_t *pkt,
				       pkt_ctx_t *ctx,
				       odp_bool_t *skip)
{
	uint8_t *buf = odp_packet_data(*pkt);
	odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(*pkt, NULL);
	int hdr_len;
	odph_ahhdr_t *ah = NULL;
	odph_esphdr_t *esp = NULL;
	ipsec_cache_entry_t *entry;
	odp_crypto_packet_op_param_t params;
	odp_packet_t out_pkt;

	/* Default to skip IPsec */
	*skip = TRUE;

	/* Check IP header for IPSec protocols and look it up */
	hdr_len = locate_ipsec_headers(ip, &ah, &esp);
	if (!ah && !esp)
		return PKT_CONTINUE;
	entry = find_ipsec_cache_entry_in(odp_be_to_cpu_32(ip->src_addr),
					  odp_be_to_cpu_32(ip->dst_addr),
					  ah,
					  esp);
	if (!entry)
		return PKT_CONTINUE;

	/* Account for configured ESP IV length in packet */
	hdr_len += entry->esp.iv_len;

	/* Initialize parameters block */
	memset(&params, 0, sizeof(params));
	params.session = entry->state.session;
	out_pkt = entry->in_place ? *pkt : ODP_PACKET_INVALID;

	/*Save everything to context */
	ctx->ipsec.ip_tos = ip->tos;
	ctx->ipsec.ip_frag_offset = odp_be_to_cpu_16(ip->frag_offset);
	ctx->ipsec.ip_ttl = ip->ttl;
	ctx->ipsec.ah_offset = ah ? ((uint8_t *)ah) - buf : 0;
	ctx->ipsec.esp_offset = esp ? ((uint8_t *)esp) - buf : 0;
	ctx->ipsec.hdr_len = hdr_len;
	ctx->ipsec.trl_len = 0;
	ctx->ipsec.src_ip = entry->src_ip;
	ctx->ipsec.dst_ip = entry->dst_ip;

	/*If authenticating, zero the mutable fields build the request */
	if (ah) {
		ip->chksum = 0;
		ip->tos = 0;
		ip->frag_offset = 0;
		ip->ttl = 0;

		params.auth_range.offset = ((uint8_t *)ip) - buf;
		params.auth_range.length = odp_be_to_cpu_16(ip->tot_len);
		params.hash_result_offset = ah->icv - buf;
	}

	/* If deciphering build request */
	if (esp) {
		params.cipher_range.offset = ipv4_data_p(ip) + hdr_len - buf;
		params.cipher_range.length = ipv4_data_len(ip) - hdr_len;
		params.cipher_iv_ptr = esp->iv;
	}

	/* Issue crypto request */
	*skip = FALSE;
	ctx->state = PKT_STATE_IPSEC_IN_FINISH;
	if (entry->async) {
		if (odp_crypto_op_enq(pkt, &out_pkt, &params, 1) != 1) {
			ODPH_ERR("Error: odp_crypto_op_enq() failed\n");
			exit(EXIT_FAILURE);
		}
		return PKT_POSTED;
	}

	if (odp_crypto_op(pkt, &out_pkt, &params, 1) != 1) {
		ODPH_ERR("Error: odp_crypto_op() failed\n");
		exit(EXIT_FAILURE);
	}
	*pkt = out_pkt;

	return PKT_CONTINUE;
}
/**
 * Packet Processing - Input IPsec packet classification
 *
 * Verify the received packet has IPsec headers and a match
 * in the IPsec cache, if so issue crypto request else skip
 * input crypto.
 *
 * @param pkt   Packet to classify
 * @param ctx   Packet process context
 * @param skip  Pointer to return "skip" indication
 *
 * @return PKT_CONTINUE if done else PKT_POSTED
 */
Packet Processing - Input IPsec packet classification
Verify the received packet has IPsec headers and a match
in the IPsec cache, if so issue crypto request else skip
input crypto.

@param pkt   Packet to classify
@param ctx   Packet process context
@param skip  Pointer to return "skip" indication


Packet Processing - Input IPsec packet classification Verify the received packet has IPsec headers and a match in the IPsec cache if so issue crypto request else skip input crypto . @param pkt Packet to classify @param ctx Packet process context @param skip Pointer to return " skip " indication
static
pkt_disposition_e do_ipsec_in_classify(odp_packet_t *pkt,
				       pkt_ctx_t *ctx,
				       odp_bool_t *skip)
{
	uint8_t *buf = odp_packet_data(*pkt);
	odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(*pkt, NULL);
	int hdr_len;
	odph_ahhdr_t *ah = NULL;
	odph_esphdr_t *esp = NULL;
	ipsec_cache_entry_t *entry;
	odp_crypto_packet_op_param_t params;
	odp_packet_t out_pkt;
	*skip = TRUE;
	hdr_len = locate_ipsec_headers(ip, &ah, &esp);
	if (!ah && !esp)
		return PKT_CONTINUE;
	entry = find_ipsec_cache_entry_in(odp_be_to_cpu_32(ip->src_addr),
					  odp_be_to_cpu_32(ip->dst_addr),
					  ah,
					  esp);
	if (!entry)
		return PKT_CONTINUE;
	hdr_len += entry->esp.iv_len;
	memset(&params, 0, sizeof(params));
	params.session = entry->state.session;
	out_pkt = entry->in_place ? *pkt : ODP_PACKET_INVALID;
	ctx->ipsec.ip_tos = ip->tos;
	ctx->ipsec.ip_frag_offset = odp_be_to_cpu_16(ip->frag_offset);
	ctx->ipsec.ip_ttl = ip->ttl;
	ctx->ipsec.ah_offset = ah ? ((uint8_t *)ah) - buf : 0;
	ctx->ipsec.esp_offset = esp ? ((uint8_t *)esp) - buf : 0;
	ctx->ipsec.hdr_len = hdr_len;
	ctx->ipsec.trl_len = 0;
	ctx->ipsec.src_ip = entry->src_ip;
	ctx->ipsec.dst_ip = entry->dst_ip;
	if (ah) {
		ip->chksum = 0;
		ip->tos = 0;
		ip->frag_offset = 0;
		ip->ttl = 0;
		params.auth_range.offset = ((uint8_t *)ip) - buf;
		params.auth_range.length = odp_be_to_cpu_16(ip->tot_len);
		params.hash_result_offset = ah->icv - buf;
	}
	if (esp) {
		params.cipher_range.offset = ipv4_data_p(ip) + hdr_len - buf;
		params.cipher_range.length = ipv4_data_len(ip) - hdr_len;
		params.cipher_iv_ptr = esp->iv;
	}
	*skip = FALSE;
	ctx->state = PKT_STATE_IPSEC_IN_FINISH;
	if (entry->async) {
		if (odp_crypto_op_enq(pkt, &out_pkt, &params, 1) != 1) {
			ODPH_ERR("Error: odp_crypto_op_enq() failed\n");
			exit(EXIT_FAILURE);
		}
		return PKT_POSTED;
	}
	if (odp_crypto_op(pkt, &out_pkt, &params, 1) != 1) {
		ODPH_ERR("Error: odp_crypto_op() failed\n");
		exit(EXIT_FAILURE);
	}
	*pkt = out_pkt;
	return PKT_CONTINUE;
}
static pkt_disposition_e do_ipsec_in_classify ( odp_packet_t * pkt , pkt_ctx_t * ctx , odp_bool_t * skip ) { uint8_t * buf = odp_packet_data ( * pkt ) ; odph_ipv4hdr_t * ip = ( odph_ipv4hdr_t * ) odp_packet_l3_ptr ( * pkt , NULL ) ; int hdr_len ; odph_ahhdr_t * ah = NULL ; odph_esphdr_t * esp = NULL ; ipsec_cache_entry_t * entry ; odp_crypto_packet_op_param_t params ; odp_packet_t out_pkt ; * skip = TRUE ; hdr_len = locate_ipsec_headers ( ip , & ah , & esp ) ; if ( ! ah && ! esp ) return PKT_CONTINUE ; entry = find_ipsec_cache_entry_in ( odp_be_to_cpu_32 ( ip -> src_addr ) , odp_be_to_cpu_32 ( ip -> dst_addr ) , ah , esp ) ; if ( ! entry ) return PKT_CONTINUE ; hdr_len += entry -> esp . iv_len ; memset ( & params , 0 , sizeof ( params ) ) ; params . session = entry -> state . session ; out_pkt = entry -> in_place ? * pkt : ODP_PACKET_INVALID ; ctx -> ipsec . ip_tos = ip -> tos ; ctx -> ipsec . ip_frag_offset = odp_be_to_cpu_16 ( ip -> frag_offset ) ; ctx -> ipsec . ip_ttl = ip -> ttl ; ctx -> ipsec . ah_offset = ah ? ( ( uint8_t * ) ah ) - buf : 0 ; ctx -> ipsec . esp_offset = esp ? ( ( uint8_t * ) esp ) - buf : 0 ; ctx -> ipsec . hdr_len = hdr_len ; ctx -> ipsec . trl_len = 0 ; ctx -> ipsec . src_ip = entry -> src_ip ; ctx -> ipsec . dst_ip = entry -> dst_ip ; if ( ah ) { ip -> chksum = 0 ; ip -> tos = 0 ; ip -> frag_offset = 0 ; ip -> ttl = 0 ; params . auth_range . offset = ( ( uint8_t * ) ip ) - buf ; params . auth_range . length = odp_be_to_cpu_16 ( ip -> tot_len ) ; params . hash_result_offset = ah -> icv - buf ; } if ( esp ) { params . cipher_range . offset = ipv4_data_p ( ip ) + hdr_len - buf ; params . cipher_range . length = ipv4_data_len ( ip ) - hdr_len ; params . cipher_iv_ptr = esp -> iv ; } * skip = FALSE ; ctx -> state = PKT_STATE_IPSEC_IN_FINISH ; if ( entry -> async ) { if ( odp_crypto_op_enq ( pkt , & out_pkt , & params , 1 ) != 1 ) { ODPH_ERR ( " \n " ) ; exit ( EXIT_FAILURE ) ; } return PKT_POSTED ; } if ( odp_crypto_op ( pkt , & out_pkt , & params , 1 ) != 1 ) { ODPH_ERR ( " \n " ) ; exit ( EXIT_FAILURE ) ; } * pkt = out_pkt ; return PKT_CONTINUE ; }
Packet Processing - Input IPsec packet classification
 Verify the received packet has IPsec headers and a match
 in the IPsec cache, if so issue crypto request else skip
 input crypto.
Packet Processing - Input IPsec packet classification Verify the received packet has IPsec headers and a match in the IPsec cache if so issue crypto request else skip input crypto .
/* Default to skip IPsec */ /* Check IP header for IPSec protocols and look it up */ /* Account for configured ESP IV length in packet */ /* Initialize parameters block */ /*Save everything to context */ /*If authenticating, zero the mutable fields build the request */ /* If deciphering build request */ /* Issue crypto request */