1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016 Intel Corporation
10 #include <netinet/in.h>
11 #include <netinet/ip.h>
12 #include <netinet/ip6.h>
14 #include <sys/queue.h>
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
23 #include <rte_launch.h>
24 #include <rte_atomic.h>
25 #include <rte_cycles.h>
26 #include <rte_prefetch.h>
27 #include <rte_lcore.h>
28 #include <rte_per_lcore.h>
29 #include <rte_branch_prediction.h>
30 #include <rte_interrupts.h>
31 #include <rte_random.h>
32 #include <rte_debug.h>
33 #include <rte_ether.h>
34 #include <rte_ethdev.h>
35 #include <rte_mempool.h>
41 #include <rte_jhash.h>
42 #include <rte_cryptodev.h>
47 #define RTE_LOGTYPE_IPSEC RTE_LOGTYPE_USER1
49 #define MAX_JUMBO_PKT_LEN 9600
51 #define MEMPOOL_CACHE_SIZE 256
53 #define NB_MBUF (32000)
55 #define CDEV_QUEUE_DESC 2048
56 #define CDEV_MAP_ENTRIES 1024
57 #define CDEV_MP_NB_OBJS 2048
58 #define CDEV_MP_CACHE_SZ 64
59 #define MAX_QUEUE_PAIRS 1
61 #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */
65 /* Configure how many packets ahead to prefetch, when reading packets */
66 #define PREFETCH_OFFSET 3
68 #define MAX_RX_QUEUE_PER_LCORE 16
70 #define MAX_LCORE_PARAMS 1024
72 #define UNPROTECTED_PORT(port) (unprotected_port_mask & (1 << portid))
75 * Configurable number of RX/TX ring descriptors
77 #define IPSEC_SECGW_RX_DESC_DEFAULT 1024
78 #define IPSEC_SECGW_TX_DESC_DEFAULT 1024
79 static uint16_t nb_rxd = IPSEC_SECGW_RX_DESC_DEFAULT;
80 static uint16_t nb_txd = IPSEC_SECGW_TX_DESC_DEFAULT;
82 #if RTE_BYTE_ORDER != RTE_LITTLE_ENDIAN
83 #define __BYTES_TO_UINT64(a, b, c, d, e, f, g, h) \
84 (((uint64_t)((a) & 0xff) << 56) | \
85 ((uint64_t)((b) & 0xff) << 48) | \
86 ((uint64_t)((c) & 0xff) << 40) | \
87 ((uint64_t)((d) & 0xff) << 32) | \
88 ((uint64_t)((e) & 0xff) << 24) | \
89 ((uint64_t)((f) & 0xff) << 16) | \
90 ((uint64_t)((g) & 0xff) << 8) | \
91 ((uint64_t)(h) & 0xff))
93 #define __BYTES_TO_UINT64(a, b, c, d, e, f, g, h) \
94 (((uint64_t)((h) & 0xff) << 56) | \
95 ((uint64_t)((g) & 0xff) << 48) | \
96 ((uint64_t)((f) & 0xff) << 40) | \
97 ((uint64_t)((e) & 0xff) << 32) | \
98 ((uint64_t)((d) & 0xff) << 24) | \
99 ((uint64_t)((c) & 0xff) << 16) | \
100 ((uint64_t)((b) & 0xff) << 8) | \
101 ((uint64_t)(a) & 0xff))
103 #define ETHADDR(a, b, c, d, e, f) (__BYTES_TO_UINT64(a, b, c, d, e, f, 0, 0))
105 #define ETHADDR_TO_UINT64(addr) __BYTES_TO_UINT64( \
106 addr.addr_bytes[0], addr.addr_bytes[1], \
107 addr.addr_bytes[2], addr.addr_bytes[3], \
108 addr.addr_bytes[4], addr.addr_bytes[5], \
111 /* port/source ethernet addr and destination ethernet addr */
112 struct ethaddr_info {
116 struct ethaddr_info ethaddr_tbl[RTE_MAX_ETHPORTS] = {
117 { 0, ETHADDR(0x00, 0x16, 0x3e, 0x7e, 0x94, 0x9a) },
118 { 0, ETHADDR(0x00, 0x16, 0x3e, 0x22, 0xa1, 0xd9) },
119 { 0, ETHADDR(0x00, 0x16, 0x3e, 0x08, 0x69, 0x26) },
120 { 0, ETHADDR(0x00, 0x16, 0x3e, 0x49, 0x9e, 0xdd) }
123 #define CMD_LINE_OPT_CONFIG "config"
124 #define CMD_LINE_OPT_SINGLE_SA "single-sa"
125 #define CMD_LINE_OPT_CRYPTODEV_MASK "cryptodev_mask"
128 /* long options mapped to a short option */
130 /* first long only option value must be >= 256, so that we won't
131 * conflict with short options
133 CMD_LINE_OPT_MIN_NUM = 256,
134 CMD_LINE_OPT_CONFIG_NUM,
135 CMD_LINE_OPT_SINGLE_SA_NUM,
136 CMD_LINE_OPT_CRYPTODEV_MASK_NUM,
139 static const struct option lgopts[] = {
140 {CMD_LINE_OPT_CONFIG, 1, 0, CMD_LINE_OPT_CONFIG_NUM},
141 {CMD_LINE_OPT_SINGLE_SA, 1, 0, CMD_LINE_OPT_SINGLE_SA_NUM},
142 {CMD_LINE_OPT_CRYPTODEV_MASK, 1, 0, CMD_LINE_OPT_CRYPTODEV_MASK_NUM},
146 /* mask of enabled ports */
147 static uint32_t enabled_port_mask;
148 static uint64_t enabled_cryptodev_mask = UINT64_MAX;
149 static uint32_t unprotected_port_mask;
150 static int32_t promiscuous_on = 1;
151 static int32_t numa_on = 1; /**< NUMA is enabled by default. */
152 static uint32_t nb_lcores;
153 static uint32_t single_sa;
154 static uint32_t single_sa_idx;
155 static uint32_t frame_size;
157 struct lcore_rx_queue {
160 } __rte_cache_aligned;
162 struct lcore_params {
166 } __rte_cache_aligned;
168 static struct lcore_params lcore_params_array[MAX_LCORE_PARAMS];
170 static struct lcore_params *lcore_params;
171 static uint16_t nb_lcore_params;
173 static struct rte_hash *cdev_map_in;
174 static struct rte_hash *cdev_map_out;
178 struct rte_mbuf *m_table[MAX_PKT_BURST] __rte_aligned(sizeof(void *));
182 uint16_t nb_rx_queue;
183 struct lcore_rx_queue rx_queue_list[MAX_RX_QUEUE_PER_LCORE];
184 uint16_t tx_queue_id[RTE_MAX_ETHPORTS];
185 struct buffer tx_mbufs[RTE_MAX_ETHPORTS];
186 struct ipsec_ctx inbound;
187 struct ipsec_ctx outbound;
188 struct rt_ctx *rt4_ctx;
189 struct rt_ctx *rt6_ctx;
190 } __rte_cache_aligned;
192 static struct lcore_conf lcore_conf[RTE_MAX_LCORE];
194 static struct rte_eth_conf port_conf = {
196 .mq_mode = ETH_MQ_RX_RSS,
197 .max_rx_pkt_len = ETHER_MAX_LEN,
199 .offloads = DEV_RX_OFFLOAD_CHECKSUM |
200 DEV_RX_OFFLOAD_CRC_STRIP,
201 .ignore_offload_bitfield = 1,
206 .rss_hf = ETH_RSS_IP | ETH_RSS_UDP |
207 ETH_RSS_TCP | ETH_RSS_SCTP,
211 .mq_mode = ETH_MQ_TX_NONE,
212 .offloads = (DEV_TX_OFFLOAD_IPV4_CKSUM |
213 DEV_TX_OFFLOAD_MULTI_SEGS),
217 static struct socket_ctx socket_ctx[NB_SOCKETS];
219 struct traffic_type {
220 const uint8_t *data[MAX_PKT_BURST * 2];
221 struct rte_mbuf *pkts[MAX_PKT_BURST * 2];
222 uint32_t res[MAX_PKT_BURST * 2];
226 struct ipsec_traffic {
227 struct traffic_type ipsec;
228 struct traffic_type ip4;
229 struct traffic_type ip6;
233 prepare_one_packet(struct rte_mbuf *pkt, struct ipsec_traffic *t)
236 struct ether_hdr *eth;
238 eth = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
239 if (eth->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
240 nlp = (uint8_t *)rte_pktmbuf_adj(pkt, ETHER_HDR_LEN);
241 nlp = RTE_PTR_ADD(nlp, offsetof(struct ip, ip_p));
242 if (*nlp == IPPROTO_ESP)
243 t->ipsec.pkts[(t->ipsec.num)++] = pkt;
245 t->ip4.data[t->ip4.num] = nlp;
246 t->ip4.pkts[(t->ip4.num)++] = pkt;
248 } else if (eth->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6)) {
249 nlp = (uint8_t *)rte_pktmbuf_adj(pkt, ETHER_HDR_LEN);
250 nlp = RTE_PTR_ADD(nlp, offsetof(struct ip6_hdr, ip6_nxt));
251 if (*nlp == IPPROTO_ESP)
252 t->ipsec.pkts[(t->ipsec.num)++] = pkt;
254 t->ip6.data[t->ip6.num] = nlp;
255 t->ip6.pkts[(t->ip6.num)++] = pkt;
258 /* Unknown/Unsupported type, drop the packet */
259 RTE_LOG(ERR, IPSEC, "Unsupported packet type\n");
260 rte_pktmbuf_free(pkt);
263 /* Check if the packet has been processed inline. For inline protocol
264 * processed packets, the metadata in the mbuf can be used to identify
265 * the security processing done on the packet. The metadata will be
266 * used to retrieve the application registered userdata associated
267 * with the security session.
270 if (pkt->ol_flags & PKT_RX_SEC_OFFLOAD) {
272 struct ipsec_mbuf_metadata *priv;
273 struct rte_security_ctx *ctx = (struct rte_security_ctx *)
274 rte_eth_dev_get_sec_ctx(
277 /* Retrieve the userdata registered. Here, the userdata
278 * registered is the SA pointer.
281 sa = (struct ipsec_sa *)
282 rte_security_get_userdata(ctx, pkt->udata64);
285 /* userdata could not be retrieved */
289 /* Save SA as priv member in mbuf. This will be used in the
290 * IPsec selector(SP-SA) check.
293 priv = get_priv(pkt);
299 prepare_traffic(struct rte_mbuf **pkts, struct ipsec_traffic *t,
308 for (i = 0; i < (nb_pkts - PREFETCH_OFFSET); i++) {
309 rte_prefetch0(rte_pktmbuf_mtod(pkts[i + PREFETCH_OFFSET],
311 prepare_one_packet(pkts[i], t);
313 /* Process left packets */
314 for (; i < nb_pkts; i++)
315 prepare_one_packet(pkts[i], t);
319 prepare_tx_pkt(struct rte_mbuf *pkt, uint16_t port)
322 struct ether_hdr *ethhdr;
324 ip = rte_pktmbuf_mtod(pkt, struct ip *);
326 ethhdr = (struct ether_hdr *)rte_pktmbuf_prepend(pkt, ETHER_HDR_LEN);
328 if (ip->ip_v == IPVERSION) {
329 pkt->ol_flags |= PKT_TX_IP_CKSUM | PKT_TX_IPV4;
330 pkt->l3_len = sizeof(struct ip);
331 pkt->l2_len = ETHER_HDR_LEN;
333 ethhdr->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
335 pkt->ol_flags |= PKT_TX_IPV6;
336 pkt->l3_len = sizeof(struct ip6_hdr);
337 pkt->l2_len = ETHER_HDR_LEN;
339 ethhdr->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv6);
342 memcpy(ðhdr->s_addr, ðaddr_tbl[port].src,
343 sizeof(struct ether_addr));
344 memcpy(ðhdr->d_addr, ðaddr_tbl[port].dst,
345 sizeof(struct ether_addr));
349 prepare_tx_burst(struct rte_mbuf *pkts[], uint16_t nb_pkts, uint16_t port)
352 const int32_t prefetch_offset = 2;
354 for (i = 0; i < (nb_pkts - prefetch_offset); i++) {
355 rte_mbuf_prefetch_part2(pkts[i + prefetch_offset]);
356 prepare_tx_pkt(pkts[i], port);
358 /* Process left packets */
359 for (; i < nb_pkts; i++)
360 prepare_tx_pkt(pkts[i], port);
363 /* Send burst of packets on an output interface */
364 static inline int32_t
365 send_burst(struct lcore_conf *qconf, uint16_t n, uint16_t port)
367 struct rte_mbuf **m_table;
371 queueid = qconf->tx_queue_id[port];
372 m_table = (struct rte_mbuf **)qconf->tx_mbufs[port].m_table;
374 prepare_tx_burst(m_table, n, port);
376 ret = rte_eth_tx_burst(port, queueid, m_table, n);
377 if (unlikely(ret < n)) {
379 rte_pktmbuf_free(m_table[ret]);
386 /* Enqueue a single packet, and send burst if queue is filled */
387 static inline int32_t
388 send_single_packet(struct rte_mbuf *m, uint16_t port)
392 struct lcore_conf *qconf;
394 lcore_id = rte_lcore_id();
396 qconf = &lcore_conf[lcore_id];
397 len = qconf->tx_mbufs[port].len;
398 qconf->tx_mbufs[port].m_table[len] = m;
401 /* enough pkts to be sent */
402 if (unlikely(len == MAX_PKT_BURST)) {
403 send_burst(qconf, MAX_PKT_BURST, port);
407 qconf->tx_mbufs[port].len = len;
412 inbound_sp_sa(struct sp_ctx *sp, struct sa_ctx *sa, struct traffic_type *ip,
416 uint32_t i, j, res, sa_idx;
418 if (ip->num == 0 || sp == NULL)
421 rte_acl_classify((struct rte_acl_ctx *)sp, ip->data, ip->res,
422 ip->num, DEFAULT_MAX_CATEGORIES);
425 for (i = 0; i < ip->num; i++) {
437 /* Only check SPI match for processed IPSec packets */
438 if (i < lim && ((m->ol_flags & PKT_RX_SEC_OFFLOAD) == 0)) {
443 sa_idx = ip->res[i] & PROTECT_MASK;
444 if (sa_idx >= IPSEC_SA_MAX_ENTRIES ||
445 !inbound_sa_check(sa, m, sa_idx)) {
455 process_pkts_inbound(struct ipsec_ctx *ipsec_ctx,
456 struct ipsec_traffic *traffic)
459 uint16_t idx, nb_pkts_in, i, n_ip4, n_ip6;
461 nb_pkts_in = ipsec_inbound(ipsec_ctx, traffic->ipsec.pkts,
462 traffic->ipsec.num, MAX_PKT_BURST);
464 n_ip4 = traffic->ip4.num;
465 n_ip6 = traffic->ip6.num;
467 /* SP/ACL Inbound check ipsec and ip4 */
468 for (i = 0; i < nb_pkts_in; i++) {
469 m = traffic->ipsec.pkts[i];
470 struct ip *ip = rte_pktmbuf_mtod(m, struct ip *);
471 if (ip->ip_v == IPVERSION) {
472 idx = traffic->ip4.num++;
473 traffic->ip4.pkts[idx] = m;
474 traffic->ip4.data[idx] = rte_pktmbuf_mtod_offset(m,
475 uint8_t *, offsetof(struct ip, ip_p));
476 } else if (ip->ip_v == IP6_VERSION) {
477 idx = traffic->ip6.num++;
478 traffic->ip6.pkts[idx] = m;
479 traffic->ip6.data[idx] = rte_pktmbuf_mtod_offset(m,
481 offsetof(struct ip6_hdr, ip6_nxt));
486 inbound_sp_sa(ipsec_ctx->sp4_ctx, ipsec_ctx->sa_ctx, &traffic->ip4,
489 inbound_sp_sa(ipsec_ctx->sp6_ctx, ipsec_ctx->sa_ctx, &traffic->ip6,
494 outbound_sp(struct sp_ctx *sp, struct traffic_type *ip,
495 struct traffic_type *ipsec)
498 uint32_t i, j, sa_idx;
500 if (ip->num == 0 || sp == NULL)
503 rte_acl_classify((struct rte_acl_ctx *)sp, ip->data, ip->res,
504 ip->num, DEFAULT_MAX_CATEGORIES);
507 for (i = 0; i < ip->num; i++) {
509 sa_idx = ip->res[i] & PROTECT_MASK;
510 if (ip->res[i] & DISCARD)
512 else if (sa_idx < IPSEC_SA_MAX_ENTRIES) {
513 ipsec->res[ipsec->num] = sa_idx;
514 ipsec->pkts[ipsec->num++] = m;
522 process_pkts_outbound(struct ipsec_ctx *ipsec_ctx,
523 struct ipsec_traffic *traffic)
526 uint16_t idx, nb_pkts_out, i;
528 /* Drop any IPsec traffic from protected ports */
529 for (i = 0; i < traffic->ipsec.num; i++)
530 rte_pktmbuf_free(traffic->ipsec.pkts[i]);
532 traffic->ipsec.num = 0;
534 outbound_sp(ipsec_ctx->sp4_ctx, &traffic->ip4, &traffic->ipsec);
536 outbound_sp(ipsec_ctx->sp6_ctx, &traffic->ip6, &traffic->ipsec);
538 nb_pkts_out = ipsec_outbound(ipsec_ctx, traffic->ipsec.pkts,
539 traffic->ipsec.res, traffic->ipsec.num,
542 for (i = 0; i < nb_pkts_out; i++) {
543 m = traffic->ipsec.pkts[i];
544 struct ip *ip = rte_pktmbuf_mtod(m, struct ip *);
545 if (ip->ip_v == IPVERSION) {
546 idx = traffic->ip4.num++;
547 traffic->ip4.pkts[idx] = m;
549 idx = traffic->ip6.num++;
550 traffic->ip6.pkts[idx] = m;
556 process_pkts_inbound_nosp(struct ipsec_ctx *ipsec_ctx,
557 struct ipsec_traffic *traffic)
560 uint32_t nb_pkts_in, i, idx;
562 /* Drop any IPv4 traffic from unprotected ports */
563 for (i = 0; i < traffic->ip4.num; i++)
564 rte_pktmbuf_free(traffic->ip4.pkts[i]);
566 traffic->ip4.num = 0;
568 /* Drop any IPv6 traffic from unprotected ports */
569 for (i = 0; i < traffic->ip6.num; i++)
570 rte_pktmbuf_free(traffic->ip6.pkts[i]);
572 traffic->ip6.num = 0;
574 nb_pkts_in = ipsec_inbound(ipsec_ctx, traffic->ipsec.pkts,
575 traffic->ipsec.num, MAX_PKT_BURST);
577 for (i = 0; i < nb_pkts_in; i++) {
578 m = traffic->ipsec.pkts[i];
579 struct ip *ip = rte_pktmbuf_mtod(m, struct ip *);
580 if (ip->ip_v == IPVERSION) {
581 idx = traffic->ip4.num++;
582 traffic->ip4.pkts[idx] = m;
584 idx = traffic->ip6.num++;
585 traffic->ip6.pkts[idx] = m;
591 process_pkts_outbound_nosp(struct ipsec_ctx *ipsec_ctx,
592 struct ipsec_traffic *traffic)
595 uint32_t nb_pkts_out, i;
598 /* Drop any IPsec traffic from protected ports */
599 for (i = 0; i < traffic->ipsec.num; i++)
600 rte_pktmbuf_free(traffic->ipsec.pkts[i]);
602 traffic->ipsec.num = 0;
604 for (i = 0; i < traffic->ip4.num; i++)
605 traffic->ip4.res[i] = single_sa_idx;
607 for (i = 0; i < traffic->ip6.num; i++)
608 traffic->ip6.res[i] = single_sa_idx;
610 nb_pkts_out = ipsec_outbound(ipsec_ctx, traffic->ip4.pkts,
611 traffic->ip4.res, traffic->ip4.num,
614 /* They all sue the same SA (ip4 or ip6 tunnel) */
615 m = traffic->ipsec.pkts[i];
616 ip = rte_pktmbuf_mtod(m, struct ip *);
617 if (ip->ip_v == IPVERSION)
618 traffic->ip4.num = nb_pkts_out;
620 traffic->ip6.num = nb_pkts_out;
623 static inline int32_t
624 get_hop_for_offload_pkt(struct rte_mbuf *pkt, int is_ipv6)
626 struct ipsec_mbuf_metadata *priv;
629 priv = get_priv(pkt);
632 if (unlikely(sa == NULL)) {
633 RTE_LOG(ERR, IPSEC, "SA not saved in private data\n");
641 return (sa->portid | RTE_LPM_LOOKUP_SUCCESS);
652 route4_pkts(struct rt_ctx *rt_ctx, struct rte_mbuf *pkts[], uint8_t nb_pkts)
654 uint32_t hop[MAX_PKT_BURST * 2];
655 uint32_t dst_ip[MAX_PKT_BURST * 2];
658 uint16_t lpm_pkts = 0;
663 /* Need to do an LPM lookup for non-inline packets. Inline packets will
664 * have port ID in the SA
667 for (i = 0; i < nb_pkts; i++) {
668 if (!(pkts[i]->ol_flags & PKT_TX_SEC_OFFLOAD)) {
669 /* Security offload not enabled. So an LPM lookup is
670 * required to get the hop
672 offset = offsetof(struct ip, ip_dst);
673 dst_ip[lpm_pkts] = *rte_pktmbuf_mtod_offset(pkts[i],
675 dst_ip[lpm_pkts] = rte_be_to_cpu_32(dst_ip[lpm_pkts]);
680 rte_lpm_lookup_bulk((struct rte_lpm *)rt_ctx, dst_ip, hop, lpm_pkts);
684 for (i = 0; i < nb_pkts; i++) {
685 if (pkts[i]->ol_flags & PKT_TX_SEC_OFFLOAD) {
686 /* Read hop from the SA */
687 pkt_hop = get_hop_for_offload_pkt(pkts[i], 0);
689 /* Need to use hop returned by lookup */
690 pkt_hop = hop[lpm_pkts++];
693 if ((pkt_hop & RTE_LPM_LOOKUP_SUCCESS) == 0) {
694 rte_pktmbuf_free(pkts[i]);
697 send_single_packet(pkts[i], pkt_hop & 0xff);
702 route6_pkts(struct rt_ctx *rt_ctx, struct rte_mbuf *pkts[], uint8_t nb_pkts)
704 int32_t hop[MAX_PKT_BURST * 2];
705 uint8_t dst_ip[MAX_PKT_BURST * 2][16];
709 uint16_t lpm_pkts = 0;
714 /* Need to do an LPM lookup for non-inline packets. Inline packets will
715 * have port ID in the SA
718 for (i = 0; i < nb_pkts; i++) {
719 if (!(pkts[i]->ol_flags & PKT_TX_SEC_OFFLOAD)) {
720 /* Security offload not enabled. So an LPM lookup is
721 * required to get the hop
723 offset = offsetof(struct ip6_hdr, ip6_dst);
724 ip6_dst = rte_pktmbuf_mtod_offset(pkts[i], uint8_t *,
726 memcpy(&dst_ip[lpm_pkts][0], ip6_dst, 16);
731 rte_lpm6_lookup_bulk_func((struct rte_lpm6 *)rt_ctx, dst_ip, hop,
736 for (i = 0; i < nb_pkts; i++) {
737 if (pkts[i]->ol_flags & PKT_TX_SEC_OFFLOAD) {
738 /* Read hop from the SA */
739 pkt_hop = get_hop_for_offload_pkt(pkts[i], 1);
741 /* Need to use hop returned by lookup */
742 pkt_hop = hop[lpm_pkts++];
746 rte_pktmbuf_free(pkts[i]);
749 send_single_packet(pkts[i], pkt_hop & 0xff);
754 process_pkts(struct lcore_conf *qconf, struct rte_mbuf **pkts,
755 uint8_t nb_pkts, uint16_t portid)
757 struct ipsec_traffic traffic;
759 prepare_traffic(pkts, &traffic, nb_pkts);
761 if (unlikely(single_sa)) {
762 if (UNPROTECTED_PORT(portid))
763 process_pkts_inbound_nosp(&qconf->inbound, &traffic);
765 process_pkts_outbound_nosp(&qconf->outbound, &traffic);
767 if (UNPROTECTED_PORT(portid))
768 process_pkts_inbound(&qconf->inbound, &traffic);
770 process_pkts_outbound(&qconf->outbound, &traffic);
773 route4_pkts(qconf->rt4_ctx, traffic.ip4.pkts, traffic.ip4.num);
774 route6_pkts(qconf->rt6_ctx, traffic.ip6.pkts, traffic.ip6.num);
778 drain_buffers(struct lcore_conf *qconf)
783 for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {
784 buf = &qconf->tx_mbufs[portid];
787 send_burst(qconf, buf->len, portid);
792 /* main processing loop */
794 main_loop(__attribute__((unused)) void *dummy)
796 struct rte_mbuf *pkts[MAX_PKT_BURST];
798 uint64_t prev_tsc, diff_tsc, cur_tsc;
802 struct lcore_conf *qconf;
804 const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1)
805 / US_PER_S * BURST_TX_DRAIN_US;
806 struct lcore_rx_queue *rxql;
809 lcore_id = rte_lcore_id();
810 qconf = &lcore_conf[lcore_id];
811 rxql = qconf->rx_queue_list;
812 socket_id = rte_lcore_to_socket_id(lcore_id);
814 qconf->rt4_ctx = socket_ctx[socket_id].rt_ip4;
815 qconf->rt6_ctx = socket_ctx[socket_id].rt_ip6;
816 qconf->inbound.sp4_ctx = socket_ctx[socket_id].sp_ip4_in;
817 qconf->inbound.sp6_ctx = socket_ctx[socket_id].sp_ip6_in;
818 qconf->inbound.sa_ctx = socket_ctx[socket_id].sa_in;
819 qconf->inbound.cdev_map = cdev_map_in;
820 qconf->inbound.session_pool = socket_ctx[socket_id].session_pool;
821 qconf->outbound.sp4_ctx = socket_ctx[socket_id].sp_ip4_out;
822 qconf->outbound.sp6_ctx = socket_ctx[socket_id].sp_ip6_out;
823 qconf->outbound.sa_ctx = socket_ctx[socket_id].sa_out;
824 qconf->outbound.cdev_map = cdev_map_out;
825 qconf->outbound.session_pool = socket_ctx[socket_id].session_pool;
827 if (qconf->nb_rx_queue == 0) {
828 RTE_LOG(INFO, IPSEC, "lcore %u has nothing to do\n", lcore_id);
832 RTE_LOG(INFO, IPSEC, "entering main loop on lcore %u\n", lcore_id);
834 for (i = 0; i < qconf->nb_rx_queue; i++) {
835 portid = rxql[i].port_id;
836 queueid = rxql[i].queue_id;
838 " -- lcoreid=%u portid=%u rxqueueid=%hhu\n",
839 lcore_id, portid, queueid);
843 cur_tsc = rte_rdtsc();
845 /* TX queue buffer drain */
846 diff_tsc = cur_tsc - prev_tsc;
848 if (unlikely(diff_tsc > drain_tsc)) {
849 drain_buffers(qconf);
853 /* Read packet from RX queues */
854 for (i = 0; i < qconf->nb_rx_queue; ++i) {
855 portid = rxql[i].port_id;
856 queueid = rxql[i].queue_id;
857 nb_rx = rte_eth_rx_burst(portid, queueid,
858 pkts, MAX_PKT_BURST);
861 process_pkts(qconf, pkts, nb_rx, portid);
874 if (lcore_params == NULL) {
875 printf("Error: No port/queue/core mappings\n");
879 for (i = 0; i < nb_lcore_params; ++i) {
880 lcore = lcore_params[i].lcore_id;
881 if (!rte_lcore_is_enabled(lcore)) {
882 printf("error: lcore %hhu is not enabled in "
883 "lcore mask\n", lcore);
886 socket_id = rte_lcore_to_socket_id(lcore);
887 if (socket_id != 0 && numa_on == 0) {
888 printf("warning: lcore %hhu is on socket %d "
892 portid = lcore_params[i].port_id;
893 if ((enabled_port_mask & (1 << portid)) == 0) {
894 printf("port %u is not enabled in port mask\n", portid);
897 if (!rte_eth_dev_is_valid_port(portid)) {
898 printf("port %u is not present on the board\n", portid);
906 get_port_nb_rx_queues(const uint16_t port)
911 for (i = 0; i < nb_lcore_params; ++i) {
912 if (lcore_params[i].port_id == port &&
913 lcore_params[i].queue_id > queue)
914 queue = lcore_params[i].queue_id;
916 return (uint8_t)(++queue);
920 init_lcore_rx_queues(void)
922 uint16_t i, nb_rx_queue;
925 for (i = 0; i < nb_lcore_params; ++i) {
926 lcore = lcore_params[i].lcore_id;
927 nb_rx_queue = lcore_conf[lcore].nb_rx_queue;
928 if (nb_rx_queue >= MAX_RX_QUEUE_PER_LCORE) {
929 printf("error: too many queues (%u) for lcore: %u\n",
930 nb_rx_queue + 1, lcore);
933 lcore_conf[lcore].rx_queue_list[nb_rx_queue].port_id =
934 lcore_params[i].port_id;
935 lcore_conf[lcore].rx_queue_list[nb_rx_queue].queue_id =
936 lcore_params[i].queue_id;
937 lcore_conf[lcore].nb_rx_queue++;
944 print_usage(const char *prgname)
946 printf("%s [EAL options] -- -p PORTMASK -P -u PORTMASK"
947 " --"CMD_LINE_OPT_CONFIG" (port,queue,lcore)[,(port,queue,lcore]"
948 " --single-sa SAIDX -f CONFIG_FILE\n"
949 " -p PORTMASK: hexadecimal bitmask of ports to configure\n"
950 " -P : enable promiscuous mode\n"
951 " -u PORTMASK: hexadecimal bitmask of unprotected ports\n"
952 " -j FRAMESIZE: jumbo frame maximum size\n"
953 " --"CMD_LINE_OPT_CONFIG": (port,queue,lcore): "
954 "rx queues configuration\n"
955 " --single-sa SAIDX: use single SA index for outbound, "
957 " --cryptodev_mask MASK: hexadecimal bitmask of the "
958 "crypto devices to configure\n"
959 " -f CONFIG_FILE: Configuration file path\n",
964 parse_portmask(const char *portmask)
969 /* parse hexadecimal string */
970 pm = strtoul(portmask, &end, 16);
971 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
974 if ((pm == 0) && errno)
981 parse_decimal(const char *str)
986 num = strtoul(str, &end, 10);
987 if ((str[0] == '\0') || (end == NULL) || (*end != '\0'))
994 parse_config(const char *q_arg)
997 const char *p, *p0 = q_arg;
1005 unsigned long int_fld[_NUM_FLD];
1006 char *str_fld[_NUM_FLD];
1010 nb_lcore_params = 0;
1012 while ((p = strchr(p0, '(')) != NULL) {
1014 p0 = strchr(p, ')');
1019 if (size >= sizeof(s))
1022 snprintf(s, sizeof(s), "%.*s", size, p);
1023 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') !=
1026 for (i = 0; i < _NUM_FLD; i++) {
1028 int_fld[i] = strtoul(str_fld[i], &end, 0);
1029 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
1032 if (nb_lcore_params >= MAX_LCORE_PARAMS) {
1033 printf("exceeded max number of lcore params: %hu\n",
1037 lcore_params_array[nb_lcore_params].port_id =
1038 (uint8_t)int_fld[FLD_PORT];
1039 lcore_params_array[nb_lcore_params].queue_id =
1040 (uint8_t)int_fld[FLD_QUEUE];
1041 lcore_params_array[nb_lcore_params].lcore_id =
1042 (uint8_t)int_fld[FLD_LCORE];
1045 lcore_params = lcore_params_array;
1050 parse_args(int32_t argc, char **argv)
1054 int32_t option_index;
1055 char *prgname = argv[0];
1056 int32_t f_present = 0;
1060 while ((opt = getopt_long(argc, argvopt, "p:Pu:f:j:",
1061 lgopts, &option_index)) != EOF) {
1065 enabled_port_mask = parse_portmask(optarg);
1066 if (enabled_port_mask == 0) {
1067 printf("invalid portmask\n");
1068 print_usage(prgname);
1073 printf("Promiscuous mode selected\n");
1077 unprotected_port_mask = parse_portmask(optarg);
1078 if (unprotected_port_mask == 0) {
1079 printf("invalid unprotected portmask\n");
1080 print_usage(prgname);
1085 if (f_present == 1) {
1086 printf("\"-f\" option present more than "
1088 print_usage(prgname);
1091 if (parse_cfg_file(optarg) < 0) {
1092 printf("parsing file \"%s\" failed\n",
1094 print_usage(prgname);
1101 int32_t size = parse_decimal(optarg);
1103 printf("Invalid jumbo frame size\n");
1105 print_usage(prgname);
1108 printf("Using default value 9000\n");
1114 printf("Enabled jumbo frames size %u\n", frame_size);
1116 case CMD_LINE_OPT_CONFIG_NUM:
1117 ret = parse_config(optarg);
1119 printf("Invalid config\n");
1120 print_usage(prgname);
1124 case CMD_LINE_OPT_SINGLE_SA_NUM:
1125 ret = parse_decimal(optarg);
1127 printf("Invalid argument[sa_idx]\n");
1128 print_usage(prgname);
1134 single_sa_idx = ret;
1135 printf("Configured with single SA index %u\n",
1138 case CMD_LINE_OPT_CRYPTODEV_MASK_NUM:
1139 ret = parse_portmask(optarg);
1141 printf("Invalid argument[portmask]\n");
1142 print_usage(prgname);
1147 enabled_cryptodev_mask = ret;
1150 print_usage(prgname);
1155 if (f_present == 0) {
1156 printf("Mandatory option \"-f\" not present\n");
1161 argv[optind-1] = prgname;
1164 optind = 1; /* reset getopt lib */
1169 print_ethaddr(const char *name, const struct ether_addr *eth_addr)
1171 char buf[ETHER_ADDR_FMT_SIZE];
1172 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
1173 printf("%s%s", name, buf);
1176 /* Check the link status of all ports in up to 9s, and print them finally */
1178 check_all_ports_link_status(uint32_t port_mask)
1180 #define CHECK_INTERVAL 100 /* 100ms */
1181 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
1183 uint8_t count, all_ports_up, print_flag = 0;
1184 struct rte_eth_link link;
1186 printf("\nChecking link status");
1188 for (count = 0; count <= MAX_CHECK_TIME; count++) {
1190 RTE_ETH_FOREACH_DEV(portid) {
1191 if ((port_mask & (1 << portid)) == 0)
1193 memset(&link, 0, sizeof(link));
1194 rte_eth_link_get_nowait(portid, &link);
1195 /* print link status if flag set */
1196 if (print_flag == 1) {
1197 if (link.link_status)
1199 "Port%d Link Up - speed %u Mbps -%s\n",
1200 portid, link.link_speed,
1201 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
1202 ("full-duplex") : ("half-duplex\n"));
1204 printf("Port %d Link Down\n", portid);
1207 /* clear all_ports_up flag if any link down */
1208 if (link.link_status == ETH_LINK_DOWN) {
1213 /* after finally printing all link status, get out */
1214 if (print_flag == 1)
1217 if (all_ports_up == 0) {
1220 rte_delay_ms(CHECK_INTERVAL);
1223 /* set the print_flag if all ports up or timeout */
1224 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
1232 add_mapping(struct rte_hash *map, const char *str, uint16_t cdev_id,
1233 uint16_t qp, struct lcore_params *params,
1234 struct ipsec_ctx *ipsec_ctx,
1235 const struct rte_cryptodev_capabilities *cipher,
1236 const struct rte_cryptodev_capabilities *auth,
1237 const struct rte_cryptodev_capabilities *aead)
1241 struct cdev_key key = { 0 };
1243 key.lcore_id = params->lcore_id;
1245 key.cipher_algo = cipher->sym.cipher.algo;
1247 key.auth_algo = auth->sym.auth.algo;
1249 key.aead_algo = aead->sym.aead.algo;
1251 ret = rte_hash_lookup(map, &key);
1255 for (i = 0; i < ipsec_ctx->nb_qps; i++)
1256 if (ipsec_ctx->tbl[i].id == cdev_id)
1259 if (i == ipsec_ctx->nb_qps) {
1260 if (ipsec_ctx->nb_qps == MAX_QP_PER_LCORE) {
1261 printf("Maximum number of crypto devices assigned to "
1262 "a core, increase MAX_QP_PER_LCORE value\n");
1265 ipsec_ctx->tbl[i].id = cdev_id;
1266 ipsec_ctx->tbl[i].qp = qp;
1267 ipsec_ctx->nb_qps++;
1268 printf("%s cdev mapping: lcore %u using cdev %u qp %u "
1269 "(cdev_id_qp %lu)\n", str, key.lcore_id,
1273 ret = rte_hash_add_key_data(map, &key, (void *)i);
1275 printf("Faled to insert cdev mapping for (lcore %u, "
1276 "cdev %u, qp %u), errno %d\n",
1277 key.lcore_id, ipsec_ctx->tbl[i].id,
1278 ipsec_ctx->tbl[i].qp, ret);
1286 add_cdev_mapping(struct rte_cryptodev_info *dev_info, uint16_t cdev_id,
1287 uint16_t qp, struct lcore_params *params)
1290 const struct rte_cryptodev_capabilities *i, *j;
1291 struct rte_hash *map;
1292 struct lcore_conf *qconf;
1293 struct ipsec_ctx *ipsec_ctx;
1296 qconf = &lcore_conf[params->lcore_id];
1298 if ((unprotected_port_mask & (1 << params->port_id)) == 0) {
1300 ipsec_ctx = &qconf->outbound;
1304 ipsec_ctx = &qconf->inbound;
1308 /* Required cryptodevs with operation chainning */
1309 if (!(dev_info->feature_flags &
1310 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING))
1313 for (i = dev_info->capabilities;
1314 i->op != RTE_CRYPTO_OP_TYPE_UNDEFINED; i++) {
1315 if (i->op != RTE_CRYPTO_OP_TYPE_SYMMETRIC)
1318 if (i->sym.xform_type == RTE_CRYPTO_SYM_XFORM_AEAD) {
1319 ret |= add_mapping(map, str, cdev_id, qp, params,
1320 ipsec_ctx, NULL, NULL, i);
1324 if (i->sym.xform_type != RTE_CRYPTO_SYM_XFORM_CIPHER)
1327 for (j = dev_info->capabilities;
1328 j->op != RTE_CRYPTO_OP_TYPE_UNDEFINED; j++) {
1329 if (j->op != RTE_CRYPTO_OP_TYPE_SYMMETRIC)
1332 if (j->sym.xform_type != RTE_CRYPTO_SYM_XFORM_AUTH)
1335 ret |= add_mapping(map, str, cdev_id, qp, params,
1336 ipsec_ctx, i, j, NULL);
1343 /* Check if the device is enabled by cryptodev_mask */
1345 check_cryptodev_mask(uint8_t cdev_id)
1347 if (enabled_cryptodev_mask & (1 << cdev_id))
1354 cryptodevs_init(void)
1356 struct rte_cryptodev_config dev_conf;
1357 struct rte_cryptodev_qp_conf qp_conf;
1358 uint16_t idx, max_nb_qps, qp, i;
1359 int16_t cdev_id, port_id;
1360 struct rte_hash_parameters params = { 0 };
1362 params.entries = CDEV_MAP_ENTRIES;
1363 params.key_len = sizeof(struct cdev_key);
1364 params.hash_func = rte_jhash;
1365 params.hash_func_init_val = 0;
1366 params.socket_id = rte_socket_id();
1368 params.name = "cdev_map_in";
1369 cdev_map_in = rte_hash_create(¶ms);
1370 if (cdev_map_in == NULL)
1371 rte_panic("Failed to create cdev_map hash table, errno = %d\n",
1374 params.name = "cdev_map_out";
1375 cdev_map_out = rte_hash_create(¶ms);
1376 if (cdev_map_out == NULL)
1377 rte_panic("Failed to create cdev_map hash table, errno = %d\n",
1380 printf("lcore/cryptodev/qp mappings:\n");
1382 uint32_t max_sess_sz = 0, sess_sz;
1383 for (cdev_id = 0; cdev_id < rte_cryptodev_count(); cdev_id++) {
1384 sess_sz = rte_cryptodev_get_private_session_size(cdev_id);
1385 if (sess_sz > max_sess_sz)
1386 max_sess_sz = sess_sz;
1388 RTE_ETH_FOREACH_DEV(port_id) {
1391 if ((enabled_port_mask & (1 << port_id)) == 0)
1394 sec_ctx = rte_eth_dev_get_sec_ctx(port_id);
1395 if (sec_ctx == NULL)
1398 sess_sz = rte_security_session_get_size(sec_ctx);
1399 if (sess_sz > max_sess_sz)
1400 max_sess_sz = sess_sz;
1404 for (cdev_id = 0; cdev_id < rte_cryptodev_count(); cdev_id++) {
1405 struct rte_cryptodev_info cdev_info;
1407 if (check_cryptodev_mask((uint8_t)cdev_id))
1410 rte_cryptodev_info_get(cdev_id, &cdev_info);
1412 if (nb_lcore_params > cdev_info.max_nb_queue_pairs)
1413 max_nb_qps = cdev_info.max_nb_queue_pairs;
1415 max_nb_qps = nb_lcore_params;
1419 while (qp < max_nb_qps && i < nb_lcore_params) {
1420 if (add_cdev_mapping(&cdev_info, cdev_id, qp,
1421 &lcore_params[idx]))
1424 idx = idx % nb_lcore_params;
1431 dev_conf.socket_id = rte_cryptodev_socket_id(cdev_id);
1432 dev_conf.nb_queue_pairs = qp;
1434 if (!socket_ctx[dev_conf.socket_id].session_pool) {
1435 char mp_name[RTE_MEMPOOL_NAMESIZE];
1436 struct rte_mempool *sess_mp;
1438 snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
1439 "sess_mp_%u", dev_conf.socket_id);
1440 sess_mp = rte_mempool_create(mp_name,
1444 0, NULL, NULL, NULL,
1445 NULL, dev_conf.socket_id,
1447 if (sess_mp == NULL)
1448 rte_exit(EXIT_FAILURE,
1449 "Cannot create session pool on socket %d\n",
1450 dev_conf.socket_id);
1452 printf("Allocated session pool on socket %d\n",
1453 dev_conf.socket_id);
1454 socket_ctx[dev_conf.socket_id].session_pool = sess_mp;
1457 if (rte_cryptodev_configure(cdev_id, &dev_conf))
1458 rte_panic("Failed to initialize cryptodev %u\n",
1461 qp_conf.nb_descriptors = CDEV_QUEUE_DESC;
1462 for (qp = 0; qp < dev_conf.nb_queue_pairs; qp++)
1463 if (rte_cryptodev_queue_pair_setup(cdev_id, qp,
1464 &qp_conf, dev_conf.socket_id,
1465 socket_ctx[dev_conf.socket_id].session_pool))
1466 rte_panic("Failed to setup queue %u for "
1467 "cdev_id %u\n", 0, cdev_id);
1469 if (rte_cryptodev_start(cdev_id))
1470 rte_panic("Failed to start cryptodev %u\n",
1474 /* create session pools for eth devices that implement security */
1475 RTE_ETH_FOREACH_DEV(port_id) {
1476 if ((enabled_port_mask & (1 << port_id)) &&
1477 rte_eth_dev_get_sec_ctx(port_id)) {
1478 int socket_id = rte_eth_dev_socket_id(port_id);
1480 if (!socket_ctx[socket_id].session_pool) {
1481 char mp_name[RTE_MEMPOOL_NAMESIZE];
1482 struct rte_mempool *sess_mp;
1484 snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
1485 "sess_mp_%u", socket_id);
1486 sess_mp = rte_mempool_create(mp_name,
1490 0, NULL, NULL, NULL,
1493 if (sess_mp == NULL)
1494 rte_exit(EXIT_FAILURE,
1495 "Cannot create session pool "
1496 "on socket %d\n", socket_id);
1498 printf("Allocated session pool "
1499 "on socket %d\n", socket_id);
1500 socket_ctx[socket_id].session_pool = sess_mp;
1512 port_init(uint16_t portid)
1514 struct rte_eth_dev_info dev_info;
1515 struct rte_eth_txconf *txconf;
1516 uint16_t nb_tx_queue, nb_rx_queue;
1517 uint16_t tx_queueid, rx_queueid, queue, lcore_id;
1518 int32_t ret, socket_id;
1519 struct lcore_conf *qconf;
1520 struct ether_addr ethaddr;
1521 struct rte_eth_conf local_port_conf = port_conf;
1523 rte_eth_dev_info_get(portid, &dev_info);
1525 printf("Configuring device port %u:\n", portid);
1527 rte_eth_macaddr_get(portid, ðaddr);
1528 ethaddr_tbl[portid].src = ETHADDR_TO_UINT64(ethaddr);
1529 print_ethaddr("Address: ", ðaddr);
1532 nb_rx_queue = get_port_nb_rx_queues(portid);
1533 nb_tx_queue = nb_lcores;
1535 if (nb_rx_queue > dev_info.max_rx_queues)
1536 rte_exit(EXIT_FAILURE, "Error: queue %u not available "
1537 "(max rx queue is %u)\n",
1538 nb_rx_queue, dev_info.max_rx_queues);
1540 if (nb_tx_queue > dev_info.max_tx_queues)
1541 rte_exit(EXIT_FAILURE, "Error: queue %u not available "
1542 "(max tx queue is %u)\n",
1543 nb_tx_queue, dev_info.max_tx_queues);
1545 printf("Creating queues: nb_rx_queue=%d nb_tx_queue=%u...\n",
1546 nb_rx_queue, nb_tx_queue);
1549 local_port_conf.rxmode.max_rx_pkt_len = frame_size;
1550 local_port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1553 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SECURITY)
1554 local_port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_SECURITY;
1555 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SECURITY)
1556 local_port_conf.txmode.offloads |= DEV_TX_OFFLOAD_SECURITY;
1557 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
1558 local_port_conf.txmode.offloads |=
1559 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
1560 ret = rte_eth_dev_configure(portid, nb_rx_queue, nb_tx_queue,
1563 rte_exit(EXIT_FAILURE, "Cannot configure device: "
1564 "err=%d, port=%d\n", ret, portid);
1566 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd, &nb_txd);
1568 rte_exit(EXIT_FAILURE, "Cannot adjust number of descriptors: "
1569 "err=%d, port=%d\n", ret, portid);
1571 /* init one TX queue per lcore */
1573 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1574 if (rte_lcore_is_enabled(lcore_id) == 0)
1578 socket_id = (uint8_t)rte_lcore_to_socket_id(lcore_id);
1583 printf("Setup txq=%u,%d,%d\n", lcore_id, tx_queueid, socket_id);
1585 txconf = &dev_info.default_txconf;
1586 txconf->txq_flags = ETH_TXQ_FLAGS_IGNORE;
1587 txconf->offloads = local_port_conf.txmode.offloads;
1589 ret = rte_eth_tx_queue_setup(portid, tx_queueid, nb_txd,
1592 rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: "
1593 "err=%d, port=%d\n", ret, portid);
1595 qconf = &lcore_conf[lcore_id];
1596 qconf->tx_queue_id[portid] = tx_queueid;
1599 /* init RX queues */
1600 for (queue = 0; queue < qconf->nb_rx_queue; ++queue) {
1601 struct rte_eth_rxconf rxq_conf;
1603 if (portid != qconf->rx_queue_list[queue].port_id)
1606 rx_queueid = qconf->rx_queue_list[queue].queue_id;
1608 printf("Setup rxq=%d,%d,%d\n", portid, rx_queueid,
1611 rxq_conf = dev_info.default_rxconf;
1612 rxq_conf.offloads = local_port_conf.rxmode.offloads;
1613 ret = rte_eth_rx_queue_setup(portid, rx_queueid,
1614 nb_rxd, socket_id, &rxq_conf,
1615 socket_ctx[socket_id].mbuf_pool);
1617 rte_exit(EXIT_FAILURE,
1618 "rte_eth_rx_queue_setup: err=%d, "
1619 "port=%d\n", ret, portid);
1626 pool_init(struct socket_ctx *ctx, int32_t socket_id, uint32_t nb_mbuf)
1629 uint32_t buff_size = frame_size ? (frame_size + RTE_PKTMBUF_HEADROOM) :
1630 RTE_MBUF_DEFAULT_BUF_SIZE;
1633 snprintf(s, sizeof(s), "mbuf_pool_%d", socket_id);
1634 ctx->mbuf_pool = rte_pktmbuf_pool_create(s, nb_mbuf,
1635 MEMPOOL_CACHE_SIZE, ipsec_metadata_size(),
1638 if (ctx->mbuf_pool == NULL)
1639 rte_exit(EXIT_FAILURE, "Cannot init mbuf pool on socket %d\n",
1642 printf("Allocated mbuf pool on socket %d\n", socket_id);
1646 main(int32_t argc, char **argv)
1654 ret = rte_eal_init(argc, argv);
1656 rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
1660 /* parse application arguments (after the EAL ones) */
1661 ret = parse_args(argc, argv);
1663 rte_exit(EXIT_FAILURE, "Invalid parameters\n");
1665 if ((unprotected_port_mask & enabled_port_mask) !=
1666 unprotected_port_mask)
1667 rte_exit(EXIT_FAILURE, "Invalid unprotected portmask 0x%x\n",
1668 unprotected_port_mask);
1670 if (check_params() < 0)
1671 rte_exit(EXIT_FAILURE, "check_params failed\n");
1673 ret = init_lcore_rx_queues();
1675 rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
1677 nb_lcores = rte_lcore_count();
1679 /* Replicate each context per socket */
1680 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1681 if (rte_lcore_is_enabled(lcore_id) == 0)
1685 socket_id = (uint8_t)rte_lcore_to_socket_id(lcore_id);
1689 if (socket_ctx[socket_id].mbuf_pool)
1692 sa_init(&socket_ctx[socket_id], socket_id);
1694 sp4_init(&socket_ctx[socket_id], socket_id);
1696 sp6_init(&socket_ctx[socket_id], socket_id);
1698 rt_init(&socket_ctx[socket_id], socket_id);
1700 pool_init(&socket_ctx[socket_id], socket_id, NB_MBUF);
1703 RTE_ETH_FOREACH_DEV(portid) {
1704 if ((enabled_port_mask & (1 << portid)) == 0)
1713 RTE_ETH_FOREACH_DEV(portid) {
1714 if ((enabled_port_mask & (1 << portid)) == 0)
1718 ret = rte_eth_dev_start(portid);
1720 rte_exit(EXIT_FAILURE, "rte_eth_dev_start: "
1721 "err=%d, port=%d\n", ret, portid);
1723 * If enabled, put device in promiscuous mode.
1724 * This allows IO forwarding mode to forward packets
1725 * to itself through 2 cross-connected ports of the
1729 rte_eth_promiscuous_enable(portid);
1732 check_all_ports_link_status(enabled_port_mask);
1734 /* launch per-lcore init on every lcore */
1735 rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER);
1736 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
1737 if (rte_eal_wait_lcore(lcore_id) < 0)