example/ipsec_crypto/odp_ipsec.c
static
pkt_disposition_e do_ipsec_out_seq(odp_packet_t *pkt,
				   pkt_ctx_t *ctx)
{
	uint8_t *buf = odp_packet_data(*pkt);
	odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(*pkt, NULL);
	odp_packet_t out_pkt;
	ipsec_cache_entry_t *entry;

	entry = find_ipsec_cache_entry_out(odp_be_to_cpu_32(ip->src_addr),
					   odp_be_to_cpu_32(ip->dst_addr),
					   ip->proto);
	if (!entry)
		return PKT_DROP;

	/* We were dispatched from atomic queue, assign sequence numbers */
	if (ctx->ipsec.ah_offset) {
		odph_ahhdr_t *ah;

		ah = (odph_ahhdr_t *)(ctx->ipsec.ah_offset + buf);
		ah->seq_no = odp_cpu_to_be_32((*ctx->ipsec.ah_seq)++);
	}
	if (ctx->ipsec.esp_offset) {
		odph_esphdr_t *esp;

		esp = (odph_esphdr_t *)(ctx->ipsec.esp_offset + buf);
		esp->seq_no = odp_cpu_to_be_32((*ctx->ipsec.esp_seq)++);
	}
	if (ctx->ipsec.tun_hdr_offset) {
		odph_ipv4hdr_t *ip;
		int ret;

		ip = (odph_ipv4hdr_t *)(ctx->ipsec.tun_hdr_offset + buf);
		ip->id = odp_cpu_to_be_16((*ctx->ipsec.tun_hdr_id)++);
		if (!ip->id) {
			/* re-init tunnel hdr id */
			ret = odp_random_data((uint8_t *)ctx->ipsec.tun_hdr_id,
					      sizeof(*ctx->ipsec.tun_hdr_id),
					      1);
			if (ret != sizeof(*ctx->ipsec.tun_hdr_id)) {
				ODPH_ERR("Error: Not enough random data\n");
				exit(EXIT_FAILURE);
			}
		}
	}

	out_pkt = entry->in_place ? *pkt : ODP_PACKET_INVALID;

	/* Issue crypto request */
	if (entry->async) {
		if (odp_crypto_op_enq(pkt, &out_pkt,
				      &ctx->ipsec.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, &ctx->ipsec.params, 1) != 1) {
		ODPH_ERR("Error: odp_crypto_op() failed\n");
		exit(EXIT_FAILURE);
	}
	*pkt = out_pkt;

	return PKT_CONTINUE;
}
/**
 * Packet Processing - Output IPsec packet sequence number assignment
 *
 * Assign the necessary sequence numbers and then issue the crypto API call
 *
 * @param pkt  Packet to handle
 * @param ctx  Packet process context
 *
 * @return PKT_CONTINUE if done else PKT_POSTED
 */
Packet Processing - Output IPsec packet sequence number assignment
Assign the necessary sequence numbers and then issue the crypto API call

@param pkt  Packet to handle
@param ctx  Packet process context


Packet Processing - Output IPsec packet sequence number assignment Assign the necessary sequence numbers and then issue the crypto API call @param pkt Packet to handle @param ctx Packet process context
static
pkt_disposition_e do_ipsec_out_seq(odp_packet_t *pkt,
				   pkt_ctx_t *ctx)
{
	uint8_t *buf = odp_packet_data(*pkt);
	odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(*pkt, NULL);
	odp_packet_t out_pkt;
	ipsec_cache_entry_t *entry;
	entry = find_ipsec_cache_entry_out(odp_be_to_cpu_32(ip->src_addr),
					   odp_be_to_cpu_32(ip->dst_addr),
					   ip->proto);
	if (!entry)
		return PKT_DROP;
	if (ctx->ipsec.ah_offset) {
		odph_ahhdr_t *ah;
		ah = (odph_ahhdr_t *)(ctx->ipsec.ah_offset + buf);
		ah->seq_no = odp_cpu_to_be_32((*ctx->ipsec.ah_seq)++);
	}
	if (ctx->ipsec.esp_offset) {
		odph_esphdr_t *esp;
		esp = (odph_esphdr_t *)(ctx->ipsec.esp_offset + buf);
		esp->seq_no = odp_cpu_to_be_32((*ctx->ipsec.esp_seq)++);
	}
	if (ctx->ipsec.tun_hdr_offset) {
		odph_ipv4hdr_t *ip;
		int ret;
		ip = (odph_ipv4hdr_t *)(ctx->ipsec.tun_hdr_offset + buf);
		ip->id = odp_cpu_to_be_16((*ctx->ipsec.tun_hdr_id)++);
		if (!ip->id) {
			ret = odp_random_data((uint8_t *)ctx->ipsec.tun_hdr_id,
					      sizeof(*ctx->ipsec.tun_hdr_id),
					      1);
			if (ret != sizeof(*ctx->ipsec.tun_hdr_id)) {
				ODPH_ERR("Error: Not enough random data\n");
				exit(EXIT_FAILURE);
			}
		}
	}
	out_pkt = entry->in_place ? *pkt : ODP_PACKET_INVALID;
	if (entry->async) {
		if (odp_crypto_op_enq(pkt, &out_pkt,
				      &ctx->ipsec.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, &ctx->ipsec.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_out_seq ( odp_packet_t * pkt , pkt_ctx_t * ctx ) { uint8_t * buf = odp_packet_data ( * pkt ) ; odph_ipv4hdr_t * ip = ( odph_ipv4hdr_t * ) odp_packet_l3_ptr ( * pkt , NULL ) ; odp_packet_t out_pkt ; ipsec_cache_entry_t * entry ; entry = find_ipsec_cache_entry_out ( odp_be_to_cpu_32 ( ip -> src_addr ) , odp_be_to_cpu_32 ( ip -> dst_addr ) , ip -> proto ) ; if ( ! entry ) return PKT_DROP ; if ( ctx -> ipsec . ah_offset ) { odph_ahhdr_t * ah ; ah = ( odph_ahhdr_t * ) ( ctx -> ipsec . ah_offset + buf ) ; ah -> seq_no = odp_cpu_to_be_32 ( ( * ctx -> ipsec . ah_seq ) ++ ) ; } if ( ctx -> ipsec . esp_offset ) { odph_esphdr_t * esp ; esp = ( odph_esphdr_t * ) ( ctx -> ipsec . esp_offset + buf ) ; esp -> seq_no = odp_cpu_to_be_32 ( ( * ctx -> ipsec . esp_seq ) ++ ) ; } if ( ctx -> ipsec . tun_hdr_offset ) { odph_ipv4hdr_t * ip ; int ret ; ip = ( odph_ipv4hdr_t * ) ( ctx -> ipsec . tun_hdr_offset + buf ) ; ip -> id = odp_cpu_to_be_16 ( ( * ctx -> ipsec . tun_hdr_id ) ++ ) ; if ( ! ip -> id ) { ret = odp_random_data ( ( uint8_t * ) ctx -> ipsec . tun_hdr_id , sizeof ( * ctx -> ipsec . tun_hdr_id ) , 1 ) ; if ( ret != sizeof ( * ctx -> ipsec . tun_hdr_id ) ) { ODPH_ERR ( " \n " ) ; exit ( EXIT_FAILURE ) ; } } } out_pkt = entry -> in_place ? * pkt : ODP_PACKET_INVALID ; if ( entry -> async ) { if ( odp_crypto_op_enq ( pkt , & out_pkt , & ctx -> ipsec . params , 1 ) != 1 ) { ODPH_ERR ( " \n " ) ; exit ( EXIT_FAILURE ) ; } return PKT_POSTED ; } if ( odp_crypto_op ( pkt , & out_pkt , & ctx -> ipsec . params , 1 ) != 1 ) { ODPH_ERR ( " \n " ) ; exit ( EXIT_FAILURE ) ; } * pkt = out_pkt ; return PKT_CONTINUE ; }
Packet Processing - Output IPsec packet sequence number assignment
 Assign the necessary sequence numbers and then issue the crypto API call
Packet Processing - Output IPsec packet sequence number assignment Assign the necessary sequence numbers and then issue the crypto API call
/* We were dispatched from atomic queue, assign sequence numbers */ /* re-init tunnel hdr id */ /* Issue crypto request */