27 #include <odp/helper/odph_api.h>
30 #include <sys/socket.h>
32 #include <sys/ioctl.h>
34 #include <sys/socket.h>
35 #include <netpacket/packet.h>
36 #include <net/ethernet.h>
37 #include <arpa/inet.h>
39 #include <odp_ipsec_misc.h>
40 #include <odp_ipsec_sa_db.h>
41 #include <odp_ipsec_sp_db.h>
42 #include <odp_ipsec_fwd_db.h>
43 #include <odp_ipsec_cache.h>
46 #include <odp_ipsec_stream.h>
48 static void init_stream_db(
void) {}
49 static void deinit_stream_db(
void) {}
50 static void resolve_stream_db(
void) {}
51 static int create_stream_db_inputs(
void)
56 static odp_bool_t verify_stream_db_outputs(
void)
61 static int create_stream_db_entry(
char *input
ODP_UNUSED)
68 #define MAX_WORKERS (ODP_THREAD_COUNT_MAX - 1)
70 #define MAX_POLL_QUEUES 256
76 unsigned int cpu_count;
79 crypto_api_mode_e mode;
101 int num_polled_queues;
108 static void parse_args(
int argc,
char *argv[], appl_args_t *appl_args);
109 static void print_info(
char *progname, appl_args_t *appl_args);
110 static void usage(
char *progname);
115 #define SHM_PKT_POOL_BUF_COUNT 1024
116 #define SHM_PKT_POOL_BUF_SIZE 4096
117 #define SHM_PKT_POOL_SIZE (SHM_PKT_POOL_BUF_COUNT * SHM_PKT_POOL_BUF_SIZE)
122 #define SHM_OUT_POOL_BUF_COUNT 1024
123 #define SHM_OUT_POOL_BUF_SIZE 4096
124 #define SHM_OUT_POOL_SIZE (SHM_OUT_POOL_BUF_COUNT * SHM_OUT_POOL_BUF_SIZE)
130 PKT_STATE_INPUT_VERIFY,
131 PKT_STATE_IPSEC_IN_CLASSIFY,
132 PKT_STATE_IPSEC_IN_FINISH,
133 PKT_STATE_ROUTE_LOOKUP,
134 PKT_STATE_IPSEC_OUT_CLASSIFY,
135 PKT_STATE_IPSEC_OUT_SEQ,
136 PKT_STATE_IPSEC_OUT_FINISH,
155 uint16_t ip_frag_offset;
159 uint16_t tun_hdr_offset;
172 uint16_t *tun_hdr_id;
185 #define SHM_CTX_POOL_BUF_SIZE (sizeof(pkt_ctx_t))
186 #define SHM_CTX_POOL_BUF_COUNT (SHM_PKT_POOL_BUF_COUNT + SHM_OUT_POOL_BUF_COUNT)
187 #define SHM_CTX_POOL_SIZE (SHM_CTX_POOL_BUF_COUNT * SHM_CTX_POOL_BUF_SIZE)
189 static global_data_t *global;
229 memset(ctx, 0,
sizeof(*ctx));
230 ctx->buffer = ctx_buf;
242 void free_pkt_ctx(pkt_ctx_t *ctx)
254 static queue_create_func_t queue_create;
255 static schedule_func_t schedule_fn;
261 odp_queue_t polled_odp_queue_create(
const char *name,
275 printf(
"%s: change %s to PLAIN\n", __func__, name);
282 global->poll_queues[global->num_polled_queues++] = my_queue;
283 printf(
"%s: adding %"PRIu64
"\n", __func__,
304 while (idx < global->num_polled_queues) {
324 void ipsec_init_pre(
void)
341 global->completionq = queue_create(
"completion", &qparam);
343 ODPH_ERR(
"Error: completion queue creation failed\n");
352 global->seqnumq = queue_create(
"seqnum", &qparam);
354 ODPH_ERR(
"Error: sequence number queue creation failed\n");
361 params.
pkt.
len = SHM_OUT_POOL_BUF_SIZE;
362 params.
pkt.
num = SHM_PKT_POOL_BUF_COUNT;
368 ODPH_ERR(
"Error: message pool create failed.\n");
387 void ipsec_init_post(crypto_api_mode_e api_mode)
389 sp_db_entry_t *entry;
392 for (entry = sp_db->list; NULL != entry; entry = entry->next) {
393 sa_db_entry_t *cipher_sa = NULL;
394 sa_db_entry_t *auth_sa = NULL;
395 tun_db_entry_t *tun = NULL;
398 cipher_sa = find_sa_db_entry(&entry->src_subnet,
401 tun = find_tun_db_entry(cipher_sa->src_ip,
405 auth_sa = find_sa_db_entry(&entry->src_subnet,
408 tun = find_tun_db_entry(auth_sa->src_ip,
412 if (cipher_sa || auth_sa) {
413 if (create_ipsec_cache_entry(cipher_sa,
420 ODPH_ERR(
"Error: IPSec cache entry failed.\n"
425 printf(
" WARNING: SA not found for SP\n");
426 dump_sp_db_entry(entry);
433 int check_stream_db_out(
const char *intf)
435 stream_db_entry_t *stream = NULL;
438 for (stream = stream_db->list; NULL != stream; stream = stream->next) {
439 if (!strcmp(stream->output.intf, intf))
447 int check_stream_db_out(
const char *intf
ODP_UNUSED)
462 void initialize_intf(
char *intf)
468 uint8_t src_mac[ODPH_ETHADDR_LEN];
469 char src_mac_str[MAX_STRING];
475 if (getenv(
"ODP_IPSEC_USE_POLL_QUEUES") ||
476 check_stream_db_out(intf))
486 ODPH_ERR(
"Error: pktio create failed for %s\n", intf);
494 ODPH_ERR(
"Error: pktin config failed for %s\n", intf);
499 ODPH_ERR(
"Error: pktout config failed for %s\n", intf);
504 ODPH_ERR(
"Error: failed to get input queue for %s\n", intf);
509 ODPH_ERR(
"Error: failed to get pktout queue for %s\n", intf);
515 ODPH_ERR(
"Error: unable to start %s\n", intf);
522 ODPH_ERR(
"Error: failed during MAC address get for %s\n", intf);
526 printf(
"Created pktio:%02" PRIu64
", queue mode (ATOMIC queues)\n"
527 " default pktio%02" PRIu64
"-INPUT queue:%" PRIu64
"\n"
528 " source mac address %s\n",
531 mac_addr_str(src_mac_str, src_mac));
534 resolve_fwd_db(intf, pktio, pktout, src_mac);
570 pkt_disposition_e do_route_fwd_db(
odp_packet_t pkt, pkt_ctx_t *ctx)
573 fwd_db_entry_t *entry;
581 memcpy(ð->dst, entry->dst_mac, ODPH_ETHADDR_LEN);
582 memcpy(ð->src, entry->src_mac, ODPH_ETHADDR_LEN);
583 ctx->pktout = entry->pktout;
605 pkt_disposition_e do_ipsec_in_classify(
odp_packet_t *pkt,
612 odph_ahhdr_t *ah = NULL;
613 odph_esphdr_t *esp = NULL;
614 ipsec_cache_entry_t *entry;
622 hdr_len = locate_ipsec_headers(ip, &ah, &esp);
633 hdr_len += entry->esp.iv_len;
636 memset(¶ms, 0,
sizeof(params));
637 params.
session = entry->state.session;
640 ctx->ipsec.ip_tos = ip->tos;
642 ctx->ipsec.ip_ttl = ip->ttl;
643 ctx->ipsec.ah_offset = ah ? ((uint8_t *)ah) - buf : 0;
644 ctx->ipsec.esp_offset = esp ? ((uint8_t *)esp) - buf : 0;
645 ctx->ipsec.hdr_len = hdr_len;
646 ctx->ipsec.trl_len = 0;
647 ctx->ipsec.src_ip = entry->src_ip;
648 ctx->ipsec.dst_ip = entry->dst_ip;
669 if (entry->sa_flags & BIT_MODE_CIPHER) {
673 if (entry->sa_flags & BIT_MODE_AUTH) {
680 ctx->state = PKT_STATE_IPSEC_IN_FINISH;
683 ODPH_ERR(
"Error: odp_crypto_op_enq() failed\n");
690 ODPH_ERR(
"Error: odp_crypto_op() failed\n");
711 int hdr_len = ctx->ipsec.hdr_len;
722 if (ctx->ipsec.ah_offset) {
726 ah = (odph_ahhdr_t *)(ctx->ipsec.ah_offset + buf);
727 ip->proto = ah->next_header;
735 if (ctx->ipsec.esp_offset) {
737 odph_esptrl_t *esp_t = (odph_esptrl_t *)(eop) - 1;
739 ip->proto = esp_t->next_header;
740 trl_len += esp_t->pad_len +
sizeof(*esp_t);
744 if (ip->proto == ODPH_IPV4) {
750 eth->type = ODPH_ETHTYPE_IPV4;
754 if ((ip->src_addr != ctx->ipsec.src_ip ||
755 ip->dst_addr != ctx->ipsec.dst_ip))
762 ipv4_adjust_len(ip, -(hdr_len + trl_len));
763 ip->ttl = ctx->ipsec.ip_ttl;
764 ip->tos = ctx->ipsec.ip_tos;
767 odph_ipv4_csum_update(pkt);
770 memmove(ipv4_data_p(ip),
771 ipv4_data_p(ip) + hdr_len,
779 static int generate_iv(uint8_t *buf, uint32_t size)
809 pkt_disposition_e do_ipsec_out_classify(
odp_packet_t pkt,
815 uint16_t ip_data_len = ipv4_data_len(ip);
816 uint8_t *ip_data = ipv4_data_p(ip);
817 ipsec_cache_entry_t *entry;
821 odph_ahhdr_t *ah = NULL;
822 odph_esphdr_t *esp = NULL;
835 ctx->ipsec.ip_tos = ip->tos;
837 ctx->ipsec.ip_ttl = ip->ttl;
840 memset(¶ms, 0,
sizeof(params));
841 params.
session = entry->state.session;
843 if (entry->mode == IPSEC_SA_MODE_TUNNEL) {
844 hdr_len +=
sizeof(odph_ipv4hdr_t);
845 ip_data = (uint8_t *)ip;
846 ip_data_len +=
sizeof(odph_ipv4hdr_t);
850 ah = (odph_ahhdr_t *)(ip_data + hdr_len);
851 hdr_len +=
sizeof(odph_ahhdr_t);
852 hdr_len += entry->ah.icv_len;
854 if (entry->esp.alg) {
855 esp = (odph_esphdr_t *)(ip_data + hdr_len);
856 hdr_len +=
sizeof(odph_esphdr_t);
857 hdr_len += entry->esp.iv_len;
859 memmove(ip_data + hdr_len, ip_data, ip_data_len);
863 if (entry->mode == IPSEC_SA_MODE_TUNNEL) {
871 uint32_t encrypt_len;
872 odph_esptrl_t *esp_t;
874 encrypt_len = ESP_ENCODE_LEN(ip_data_len +
876 entry->esp.block_len);
877 trl_len = encrypt_len - ip_data_len;
880 if (generate_iv(esp->iv, entry->esp.iv_len))
884 esp_t = (odph_esptrl_t *)(ip_data + encrypt_len) - 1;
885 esp_t->pad_len = trl_len -
sizeof(*esp_t);
886 if (entry->mode == IPSEC_SA_MODE_TUNNEL)
887 esp_t->next_header = ODPH_IPV4;
889 esp_t->next_header = ip->proto;
890 ip->proto = ODPH_IPPROTO_ESP;
898 memset(ah, 0,
sizeof(*ah) + entry->ah.icv_len);
900 ah->ah_len = 1 + (entry->ah.icv_len / 4);
901 if (entry->mode == IPSEC_SA_MODE_TUNNEL && !esp)
902 ah->next_header = ODPH_IPV4;
904 ah->next_header = ip->proto;
905 ip->proto = ODPH_IPPROTO_AH;
919 ipv4_adjust_len(ip, hdr_len + trl_len);
924 ctx->ipsec.hdr_len = hdr_len;
925 ctx->ipsec.trl_len = trl_len;
926 ctx->ipsec.ah_offset = ah ? ((uint8_t *)ah) - buf : 0;
927 ctx->ipsec.esp_offset = esp ? ((uint8_t *)esp) - buf : 0;
928 ctx->ipsec.tun_hdr_offset = (entry->mode == IPSEC_SA_MODE_TUNNEL) ?
929 ((uint8_t *)ip - buf) : 0;
930 ctx->ipsec.ah_seq = &entry->state.ah_seq;
931 ctx->ipsec.esp_seq = &entry->state.esp_seq;
932 ctx->ipsec.tun_hdr_id = &entry->state.tun_hdr_id;
933 memcpy(&ctx->ipsec.params, ¶ms,
sizeof(params));
957 ipsec_cache_entry_t *entry;
966 if (ctx->ipsec.ah_offset) {
969 ah = (odph_ahhdr_t *)(ctx->ipsec.ah_offset + buf);
972 if (ctx->ipsec.esp_offset) {
975 esp = (odph_esphdr_t *)(ctx->ipsec.esp_offset + buf);
978 if (ctx->ipsec.tun_hdr_offset) {
979 odph_ipv4hdr_t *ip_tun;
981 ip_tun = (odph_ipv4hdr_t *)(ctx->ipsec.tun_hdr_offset + buf);
988 &ctx->ipsec.params, 1) != 1) {
989 ODPH_ERR(
"Error: odp_crypto_op_enq() failed\n");
995 if (
odp_crypto_op(pkt, &out_pkt, &ctx->ipsec.params, 1) != 1) {
996 ODPH_ERR(
"Error: odp_crypto_op() failed\n");
1001 return PKT_CONTINUE;
1013 pkt_disposition_e do_ipsec_out_finish(
odp_packet_t pkt,
1024 ip->ttl = ctx->ipsec.ip_ttl;
1025 ip->tos = ctx->ipsec.ip_tos;
1028 odph_ipv4_csum_update(pkt);
1031 return PKT_CONTINUE;
1055 unsigned long pkt_cnt = 0;
1059 printf(
"Pktio thread [%02i] starts\n", thr);
1065 pkt_disposition_e rc;
1071 ev = schedule_fn(&dispatchq);
1079 if (global->seqnumq == dispatchq ||
1080 global->completionq == dispatchq) {
1081 ctx = get_pkt_ctx_from_pkt(pkt);
1083 ctx = alloc_pkt_ctx(pkt);
1088 ctx->state = PKT_STATE_INPUT_VERIFY;
1091 ODPH_ERR(
"Error: Bad event type\n");
1110 switch (ctx->state) {
1111 case PKT_STATE_INPUT_VERIFY:
1113 rc = do_input_verify(pkt, ctx);
1114 ctx->state = PKT_STATE_IPSEC_IN_CLASSIFY;
1117 case PKT_STATE_IPSEC_IN_CLASSIFY:
1119 ctx->state = PKT_STATE_ROUTE_LOOKUP;
1120 rc = do_ipsec_in_classify(&pkt,
1125 case PKT_STATE_IPSEC_IN_FINISH:
1127 rc = do_ipsec_in_finish(pkt, ctx);
1128 ctx->state = PKT_STATE_ROUTE_LOOKUP;
1131 case PKT_STATE_ROUTE_LOOKUP:
1133 rc = do_route_fwd_db(pkt, ctx);
1134 ctx->state = PKT_STATE_IPSEC_OUT_CLASSIFY;
1137 case PKT_STATE_IPSEC_OUT_CLASSIFY:
1139 rc = do_ipsec_out_classify(pkt,
1143 ctx->state = PKT_STATE_TRANSMIT;
1145 ctx->state = PKT_STATE_IPSEC_OUT_SEQ;
1151 case PKT_STATE_IPSEC_OUT_SEQ:
1153 ctx->state = PKT_STATE_IPSEC_OUT_FINISH;
1154 rc = do_ipsec_out_seq(&pkt, ctx);
1157 case PKT_STATE_IPSEC_OUT_FINISH:
1159 rc = do_ipsec_out_finish(pkt, ctx);
1160 ctx->state = PKT_STATE_TRANSMIT;
1163 case PKT_STATE_TRANSMIT:
1176 }
while (PKT_CONTINUE == rc);
1179 if ((PKT_DROP == rc) || (PKT_DONE == rc))
1188 if (PKT_DONE == rc) {
1190 printf(
" [%02i] pkt_cnt:%lu\n", thr, pkt_cnt);
1203 main(
int argc,
char *argv[])
1205 odph_helper_options_t helper_options;
1206 odph_thread_t thread_tbl[MAX_WORKERS];
1207 odph_thread_common_param_t thr_common;
1208 odph_thread_param_t thr_param;
1222 schedule_fn = odp_schedule_cb;
1225 if (getenv(
"ODP_IPSEC_USE_POLL_QUEUES")) {
1226 queue_create = polled_odp_queue_create;
1227 schedule_fn = polled_odp_schedule_cb;
1231 argc = odph_parse_options(argc, argv);
1232 if (odph_options(&helper_options)) {
1233 ODPH_ERR(
"Error: reading ODP helper options failed.\n");
1239 signal(SIGINT, sig_handler);
1242 init_param.
mem_model = helper_options.mem_model;
1246 ODPH_ERR(
"Error: ODP global init failed.\n");
1252 ODPH_ERR(
"Error: ODP local init failed.\n");
1257 ODPH_ERR(
"Error: Crypto capability request failed.\n");
1261 if ((NULL == getenv(
"ODP_IPSEC_USE_POLL_QUEUES")) &&
1263 ODPH_ERR(
"Error: scheduled type compl queue not supported.\n");
1265 }
else if ((NULL != getenv(
"ODP_IPSEC_USE_POLL_QUEUES")) &&
1267 ODPH_ERR(
"Error: Plain type compl queue not supported.\n");
1273 ODP_CACHE_LINE_SIZE, 0);
1276 ODPH_ERR(
"Error: shared mem reserve failed.\n");
1282 if (NULL == global) {
1283 ODPH_ERR(
"Error: shared mem alloc failed.\n");
1286 memset(global, 0,
sizeof(global_data_t));
1289 global->crypto_capa = crypto_capa;
1300 parse_args(argc, argv, &global->appl);
1303 print_info(NO_PATH(argv[0]), &global->appl);
1305 num_workers = MAX_WORKERS;
1306 if (global->appl.cpu_count && global->appl.cpu_count < MAX_WORKERS)
1307 num_workers = global->appl.cpu_count;
1313 printf(
"num worker threads: %i\n", num_workers);
1315 printf(
"cpu mask: %s\n", cpumaskstr);
1323 params.
pkt.
len = SHM_PKT_POOL_BUF_SIZE;
1324 params.
pkt.
num = SHM_PKT_POOL_BUF_COUNT;
1330 ODPH_ERR(
"Error: packet pool create failed.\n");
1335 params.
buf.
size = SHM_CTX_POOL_BUF_SIZE;
1337 params.
buf.
num = SHM_CTX_POOL_BUF_COUNT;
1343 ODPH_ERR(
"Error: context pool create failed.\n");
1348 printf(
"Using %s mode for crypto API\n\n",
1349 (CRYPTO_API_SYNC == global->appl.mode) ?
"SYNC" :
"ASYNC");
1350 ipsec_init_post(global->appl.mode);
1353 for (i = 0; i < global->appl.if_count; i++)
1354 initialize_intf(global->appl.if_names[i]);
1357 resolve_stream_db();
1358 stream_count = create_stream_db_inputs();
1359 if (stream_count < 0) {
1360 ODPH_ERR(
"Error: creating input packets failed\n");
1367 odph_thread_common_param_init(&thr_common);
1368 thr_common.instance = instance;
1369 thr_common.cpumask = &cpumask;
1370 thr_common.share_param = 1;
1372 odph_thread_param_init(&thr_param);
1373 thr_param.start = pktio_thread;
1374 thr_param.arg = NULL;
1377 memset(thread_tbl, 0,
sizeof(thread_tbl));
1378 odph_thread_create(thread_tbl, &thr_common, &thr_param, num_workers);
1386 done = verify_stream_db_outputs();
1389 printf(
"All received\n");
1392 odph_thread_join(thread_tbl, num_workers);
1395 for (i = 0; i < global->appl.if_count; i++) {
1402 ODPH_ERR(
"Error: failed to close pktio %s\n",
1403 global->appl.if_names[i]);
1408 free(global->appl.if_names);
1409 free(global->appl.if_str);
1411 if (destroy_ipsec_cache())
1412 ODPH_ERR(
"Error: crypto session destroy failed\n");
1415 ODPH_ERR(
"Error: queue destroy failed\n");
1417 ODPH_ERR(
"Error: queue destroy failed\n");
1420 ODPH_ERR(
"Error: pool destroy failed\n");
1422 ODPH_ERR(
"Error: pool destroy failed\n");
1424 ODPH_ERR(
"Error: pool destroy failed\n");
1428 ODPH_ERR(
"Error: shm free shm_ipsec_cache failed\n");
1431 ODPH_ERR(
"Error: shm free shm_fwd_db failed\n");
1434 ODPH_ERR(
"Error: shm free shm_sa_db failed\n");
1437 ODPH_ERR(
"Error: shm free shm_tun_db failed\n");
1440 ODPH_ERR(
"Error: shm free shm_sp_db failed\n");
1445 ODPH_ERR(
"Error: shm free global data failed\n");
1450 ODPH_ERR(
"Error: term local failed\n");
1455 ODPH_ERR(
"Error: term global failed\n");
1471 static void parse_args(
int argc,
char *argv[], appl_args_t *appl_args)
1479 static const struct option longopts[] = {
1480 {
"count", required_argument, NULL,
'c'},
1481 {
"interface", required_argument, NULL,
'i'},
1482 {
"mode", required_argument, NULL,
'm'},
1483 {
"route", required_argument, NULL,
'r'},
1484 {
"policy", required_argument, NULL,
'p'},
1485 {
"ah", required_argument, NULL,
'a'},
1486 {
"esp", required_argument, NULL,
'e'},
1487 {
"tunnel", required_argument, NULL,
't'},
1488 {
"stream", required_argument, NULL,
's'},
1489 {
"help", no_argument, NULL,
'h'},
1493 static const char *shortopts =
"+c:i:m:r:p:a:e:t:s:h";
1495 printf(
"\nParsing command line options\n");
1497 appl_args->cpu_count = 1;
1498 appl_args->mode = 0;
1501 opt = getopt_long(argc, argv, shortopts, longopts, NULL);
1508 appl_args->cpu_count = atoi(optarg);
1512 len = strlen(optarg);
1519 appl_args->if_str = malloc(len);
1520 if (appl_args->if_str == NULL) {
1526 strcpy(appl_args->if_str, optarg);
1527 for (token = strtok(appl_args->if_str,
","), i = 0;
1529 token = strtok(NULL,
","), i++)
1532 appl_args->if_count = i;
1534 if (0 == appl_args->if_count) {
1540 appl_args->if_names =
1541 calloc(appl_args->if_count,
sizeof(
char *));
1544 strcpy(appl_args->if_str, optarg);
1545 for (token = strtok(appl_args->if_str,
","), i = 0;
1546 token != NULL; token = strtok(NULL,
","), i++) {
1547 appl_args->if_names[i] = token;
1552 appl_args->mode = atoi(optarg);
1556 rc = create_fwd_db_entry(optarg, appl_args->if_names,
1557 appl_args->if_count);
1561 rc = create_sp_db_entry(optarg, TRUE);
1565 rc = create_sa_db_entry(optarg, FALSE);
1569 rc = create_sa_db_entry(optarg, TRUE);
1573 rc = create_tun_db_entry(optarg);
1577 rc = create_stream_db_entry(optarg);
1591 printf(
"ERROR: failed parsing -%c option\n", opt);
1596 if (0 == appl_args->if_count) {
1607 static void print_info(
char *progname, appl_args_t *appl_args)
1613 printf(
"Running ODP appl: \"%s\"\n"
1614 "-----------------\n"
1617 progname, appl_args->if_count);
1618 for (i = 0; i < appl_args->if_count; ++i)
1619 printf(
" %s", appl_args->if_names[i]);
1634 static void usage(
char *progname)
1637 "Usage: %s OPTIONS\n"
1638 " E.g. %s -i eth1,eth2,eth3 -m 0\n"
1640 "OpenDataPlane example application.\n"
1642 "Mandatory OPTIONS:\n"
1643 " -i, --interface Eth interfaces (comma-separated, no spaces)\n"
1644 " -m, --mode 0: SYNC\n"
1646 " Default: 0: SYNC api mode\n"
1648 "Routing / IPSec OPTIONS:\n"
1649 " -r, --route SubNet,Intf,NextHopMAC\n"
1650 " -p, --policy SrcSubNet,DstSubNet,(in|out),(ah|esp|both)\n"
1651 " -e, --esp SrcIP,DstIP,(3des|null),SPI,Key192\n"
1652 " -a, --ah SrcIP,DstIP,(sha256|sha1|md5|null),SPI,Key(256|160|128)\n"
1654 " Where: NextHopMAC is raw hex/colon notation, i.e. 03:BA;44:9A:CE:02\n"
1655 " IP is decimal/dot notation, i.e. 192.168.1.1\n"
1656 " SubNet is decimal/dot/slash notation, i.e 192.168.0.0/16\n"
1657 " SPI is raw hex, 32 bits\n"
1658 " KeyXXX is raw hex, XXX bits long\n"
1661 " -r 192.168.222.0/24,p8p1,08:00:27:F5:8B:DB\n"
1662 " -p 192.168.111.0/24,192.168.222.0/24,out,esp\n"
1663 " -e 192.168.111.2,192.168.222.2,3des,201,656c8523255ccc23a66c1917aa0cf30991fce83532a4b224\n"
1664 " -a 192.168.111.2,192.168.222.2,md5,201,a731649644c5dee92cbd9c2e7e188ee6\n"
1666 "Optional OPTIONS\n"
1667 " -c, --count <number> CPU count, 0=all available, default=1\n"
1668 " -s, --stream SrcIP,DstIP,InIntf,OutIntf,Count,Length\n"
1669 " -h, --help Display help and exit.\n"
1670 " environment variables: ODP_IPSEC_USE_POLL_QUEUES\n"
1671 " to enable use of poll queues instead of scheduled (default)\n"
1672 " ODP_IPSEC_STREAM_VERIFY_MDEQ\n"
1673 " to enable use of multiple dequeue for queue draining during\n"
1674 " stream verification instead of single dequeue (default)\n"
1675 "\n", NO_PATH(progname), NO_PATH(progname)
1699 printf(
"ERROR: cipher algorithm not supported\n");
1705 printf(
"ERROR: odp_crypto_cipher_capability() failed\n");
1711 for (
int n = 0; n < num; n++) {
1714 if (capa->
key_len == sa->key.length &&
1715 capa->
iv_len == sa->iv_len) {
1717 *sa_flags |= BIT_MODE_CIPHER;
1721 printf(
"ERROR: cipher key length or IV length not supported\n");
1753 printf(
"ERROR: auth algorithm not supported\n");
1759 printf(
"ERROR: odp_crypto_auth_capability() failed\n");
1765 for (
int n = 0; n < num; n++) {
1769 capa->
key_len == sa->key.length &&
1772 *sa_flags |= BIT_MODE_AUTH;
1776 printf(
"ERROR: auth ICV length or key length not supported\n");
1780 odp_bool_t sa_config_supported(
const sa_db_entry_t *sa,
int *sa_flags);
1782 odp_bool_t sa_config_supported(
const sa_db_entry_t *sa,
int *sa_flags)
1784 return sa->alg.cipher ? cipher_supported(sa->alg.u.cipher, sa, sa_flags)
1785 : auth_supported(sa->alg.u.auth, sa, sa_flags);
void odp_atomic_init_u32(odp_atomic_u32_t *atom, uint32_t val)
Initialize atomic uint32 variable.
uint32_t odp_atomic_load_u32(odp_atomic_u32_t *atom)
Load value of atomic uint32 variable.
void odp_atomic_store_u32(odp_atomic_u32_t *atom, uint32_t val)
Store value to atomic uint32 variable.
void odp_barrier_init(odp_barrier_t *barr, int count)
Initialize barrier with thread count.
void odp_barrier_wait(odp_barrier_t *barr)
Synchronize thread execution on barrier.
odp_buffer_t odp_buffer_alloc(odp_pool_t pool)
Buffer alloc.
void odp_buffer_free(odp_buffer_t buf)
Buffer free.
void * odp_buffer_addr(odp_buffer_t buf)
Buffer start address.
#define ODP_BUFFER_INVALID
Invalid buffer.
#define odp_unlikely(x)
Branch unlikely taken.
odp_u16be_t odp_cpu_to_be_16(uint16_t cpu16)
Convert cpu native uint16_t to 16bit big endian.
#define ODP_UNUSED
Intentionally unused variables of functions.
uint16_t odp_be_to_cpu_16(odp_u16be_t be16)
Convert 16bit big endian to cpu native uint16_t.
odp_u32be_t odp_cpu_to_be_32(uint32_t cpu32)
Convert cpu native uint32_t to 32bit big endian.
uint32_t odp_be_to_cpu_32(odp_u32be_t be32)
Convert 32bit big endian to cpu native uint32_t.
int odp_cpumask_default_worker(odp_cpumask_t *mask, int num)
Default CPU mask for worker threads.
int odp_cpumask_first(const odp_cpumask_t *mask)
Find first set CPU in mask.
int32_t odp_cpumask_to_str(const odp_cpumask_t *mask, char *str, int32_t size)
Format a string from CPU mask.
#define ODP_CPUMASK_STR_SIZE
The maximum number of characters needed to record any CPU mask as a string (output of odp_cpumask_to_...
int odp_crypto_cipher_capability(odp_cipher_alg_t cipher, odp_crypto_cipher_capability_t capa[], int num)
Query supported cipher algorithm capabilities.
odp_cipher_alg_t
Crypto API cipher algorithm.
int odp_crypto_capability(odp_crypto_capability_t *capa)
Query crypto capabilities.
int odp_crypto_result(odp_crypto_packet_result_t *result, odp_packet_t packet)
Get crypto operation results from a crypto processed packet.
int odp_crypto_op(const odp_packet_t pkt_in[], odp_packet_t pkt_out[], const odp_crypto_packet_op_param_t param[], int num_pkt)
Crypto packet operation.
odp_auth_alg_t
Crypto API authentication algorithm.
int odp_crypto_op_enq(const odp_packet_t pkt_in[], const odp_packet_t pkt_out[], const odp_crypto_packet_op_param_t param[], int num_pkt)
Crypto packet operation.
int odp_crypto_auth_capability(odp_auth_alg_t auth, odp_crypto_auth_capability_t capa[], int num)
Query supported authentication algorithm capabilities.
@ ODP_CIPHER_ALG_3DES_CBC
Triple DES with cipher block chaining.
@ ODP_CIPHER_ALG_NULL
No cipher algorithm specified.
@ ODP_AUTH_ALG_NULL
No authentication algorithm specified.
@ ODP_AUTH_ALG_MD5_HMAC
HMAC-MD5.
@ ODP_AUTH_ALG_SHA1_HMAC
HMAC-SHA-1.
@ ODP_AUTH_ALG_SHA256_HMAC
HMAC-SHA-256.
_odp_abi_event_t * odp_event_t
ODP event.
odp_event_subtype_t
Event subtype.
odp_event_type_t odp_event_types(odp_event_t event, odp_event_subtype_t *subtype)
Event type and subtype of an event.
#define ODP_EVENT_INVALID
Invalid event.
void odp_init_param_init(odp_init_t *param)
Initialize the odp_init_t to default values for all fields.
int odp_init_local(odp_instance_t instance, odp_thread_type_t thr_type)
Thread local ODP initialization.
int odp_init_global(odp_instance_t *instance, const odp_init_t *params, const odp_platform_init_t *platform_params)
Global ODP initialization.
int odp_term_local(void)
Thread local ODP termination.
int odp_term_global(odp_instance_t instance)
Global ODP termination.
uint64_t odp_instance_t
ODP instance ID.
int odp_pktio_mac_addr(odp_pktio_t pktio, void *mac_addr, int size)
Get the default MAC address of a packet IO interface.
void odp_pktin_queue_param_init(odp_pktin_queue_param_t *param)
Initialize packet input queue parameters.
void odp_pktio_param_init(odp_pktio_param_t *param)
Initialize pktio params.
int odp_pktio_close(odp_pktio_t pktio)
Close a packet IO interface.
odp_pktio_t odp_pktio_lookup(const char *name)
Return a packet IO handle for an already open device.
int odp_pktout_queue(odp_pktio_t pktio, odp_pktout_queue_t queues[], int num)
Direct packet output queues.
int odp_pktin_event_queue(odp_pktio_t pktio, odp_queue_t queues[], int num)
Event queues for packet input.
odp_pktio_t odp_pktio_open(const char *name, odp_pool_t pool, const odp_pktio_param_t *param)
Open a packet IO interface.
int odp_pktio_start(odp_pktio_t pktio)
Start packet receive and transmit.
#define ODP_PKTIO_INVALID
Invalid packet IO handle.
int odp_pktio_stop(odp_pktio_t pktio)
Stop packet receive and transmit.
int odp_pktout_send(odp_pktout_queue_t queue, const odp_packet_t packets[], int num)
Send packets directly to an interface output queue.
uint64_t odp_pktio_to_u64(odp_pktio_t pktio)
Get printable value for an odp_pktio_t.
int odp_pktin_queue_config(odp_pktio_t pktio, const odp_pktin_queue_param_t *param)
Configure packet input queues.
int odp_pktout_queue_config(odp_pktio_t pktio, const odp_pktout_queue_param_t *param)
Configure packet output queues.
@ ODP_PKTIN_MODE_QUEUE
Packet input through plain event queues.
@ ODP_PKTIN_MODE_SCHED
Packet input through scheduler and scheduled event queues.
void * odp_packet_pull_head(odp_packet_t pkt, uint32_t len)
Pull in packet head.
void * odp_packet_user_ptr(odp_packet_t pkt)
User context pointer.
int odp_packet_has_ipv4(odp_packet_t pkt)
Check for IPv4.
void * odp_packet_data(odp_packet_t pkt)
Packet data pointer.
int odp_packet_has_eth(odp_packet_t pkt)
Check for Ethernet header.
void * odp_packet_push_tail(odp_packet_t pkt, uint32_t len)
Push out packet tail.
int odp_packet_has_error(odp_packet_t pkt)
Check for all parse errors in packet.
odp_packet_t odp_packet_from_event(odp_event_t ev)
Get packet handle from event.
void odp_packet_free(odp_packet_t pkt)
Free packet.
void * odp_packet_l2_ptr(odp_packet_t pkt, uint32_t *len)
Layer 2 start pointer.
void odp_packet_user_ptr_set(odp_packet_t pkt, const void *user_ptr)
Set user context pointer.
void * odp_packet_l3_ptr(odp_packet_t pkt, uint32_t *len)
Layer 3 start pointer.
void * odp_packet_pull_tail(odp_packet_t pkt, uint32_t len)
Pull in packet tail.
odp_pool_t odp_pool_create(const char *name, const odp_pool_param_t *param)
Create a pool.
void odp_pool_param_init(odp_pool_param_t *param)
Initialize pool params.
int odp_pool_destroy(odp_pool_t pool)
Destroy a pool previously created by odp_pool_create()
#define ODP_POOL_INVALID
Invalid pool.
@ ODP_POOL_BUFFER
Buffer pool.
@ ODP_POOL_PACKET
Packet pool.
_odp_abi_queue_t * odp_queue_t
ODP queue.
void odp_queue_param_init(odp_queue_param_t *param)
Initialize queue params.
#define ODP_QUEUE_INVALID
Invalid queue.
odp_event_t odp_queue_deq(odp_queue_t queue)
Dequeue an event from a queue.
odp_queue_type_t
Queue type.
int odp_queue_enq(odp_queue_t queue, odp_event_t ev)
Enqueue an event to a queue.
odp_queue_t odp_queue_create(const char *name, const odp_queue_param_t *param)
Queue create.
int odp_queue_destroy(odp_queue_t queue)
Destroy ODP queue.
uint64_t odp_queue_to_u64(odp_queue_t hdl)
Get printable value for an odp_queue_t.
@ ODP_QUEUE_TYPE_SCHED
Scheduled queue.
@ ODP_QUEUE_TYPE_PLAIN
Plain queue.
int32_t odp_random_data(uint8_t *buf, uint32_t len, odp_random_kind_t kind)
Generate random byte data.
@ ODP_RANDOM_CRYPTO
Cryptographic quality random.
#define ODP_SCHED_SYNC_ATOMIC
Atomic queue synchronization.
#define ODP_SCHED_NO_WAIT
Do not wait.
int odp_schedule_max_prio(void)
Maximum scheduling priority level.
int odp_schedule_config(const odp_schedule_config_t *config)
Global schedule configuration.
odp_event_t odp_schedule(odp_queue_t *from, uint64_t wait)
Schedule an event.
#define ODP_SCHED_GROUP_ALL
Group of all threads.
odp_shm_t odp_shm_lookup(const char *name)
Lookup for a block of shared memory.
int odp_shm_free(odp_shm_t shm)
Free a contiguous block of shared memory.
#define ODP_SHM_INVALID
Invalid shared memory block.
void * odp_shm_addr(odp_shm_t shm)
Shared memory block address.
odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, uint32_t flags)
Reserve a contiguous block of shared memory.
bool odp_bool_t
Boolean type.
void odp_sys_info_print(void)
Print system info.
int odp_thread_id(void)
Get thread identifier.
@ ODP_THREAD_WORKER
Worker thread.
@ ODP_THREAD_CONTROL
Control thread.
Authentication algorithm capabilities.
odp_bool_t bit_mode
Auth algorithm supports bit mode.
uint32_t digest_len
Digest length in bytes.
uint32_t key_len
Key length in bytes.
uint32_t iv_len
IV length in bytes.
odp_bool_t queue_type_sched
Scheduled crypto completion queue support.
odp_bool_t queue_type_plain
Plain crypto completion queue support.
Cipher algorithm capabilities.
odp_bool_t bit_mode
Cipher supports bit mode.
uint32_t key_len
Key length in bytes.
uint32_t iv_len
IV length in bytes.
Crypto packet API per packet operation parameters.
uint32_t hash_result_offset
Offset from start of packet for hash result.
const uint8_t * cipher_iv_ptr
IV pointer for cipher.
odp_packet_data_range_t cipher_range
Data range to be ciphered.
odp_crypto_session_t session
Session handle from creation.
odp_packet_data_range_t auth_range
Data range to be authenticated.
Global initialization parameters.
odp_mem_model_t mem_model
Application memory model.
uint32_t offset
Offset from beginning of packet.
uint32_t length
Length of data to operate on.
Packet input queue parameters.
odp_queue_param_t queue_param
Queue parameters.
odp_pktin_mode_t in_mode
Packet input mode.
uint32_t num
Number of buffers in the pool.
uint32_t align
Minimum buffer alignment in bytes.
uint32_t size
Minimum buffer size in bytes.
odp_pool_type_t type
Pool type.
uint32_t len
Minimum length of 'num' packets.
uint32_t seg_len
Minimum number of packet data bytes that can be stored in the first segment of a newly allocated pack...
struct odp_pool_param_t::@126 pkt
Parameters for packet pools.
struct odp_pool_param_t::@125 buf
Parameters for buffer pools.
odp_schedule_param_t sched
Scheduler parameters.
odp_queue_type_t type
Queue type.
odp_schedule_group_t group
Thread group.
odp_schedule_prio_t prio
Priority level.
odp_schedule_sync_t sync
Synchronization method.
Authentication algorithms in a bit field structure.
uint32_t null
ODP_AUTH_ALG_NULL.
uint32_t sha1_hmac
ODP_AUTH_ALG_SHA1_HMAC.
uint32_t md5_hmac
ODP_AUTH_ALG_MD5_HMAC.
struct odp_crypto_auth_algos_t::@28 bit
Authentication algorithms.
uint32_t sha256_hmac
ODP_AUTH_ALG_SHA256_HMAC.
Cipher algorithms in a bit field structure.
uint32_t trides_cbc
ODP_CIPHER_ALG_3DES_CBC.
struct odp_crypto_cipher_algos_t::@27 bit
Cipher algorithms.
uint32_t null
ODP_CIPHER_ALG_NULL.