58 #define ROUNDUP(x, y) ((((x) + ((y)-1)) / (y)) * (y))
69 static char *AllocArgument(
size_t arg_len);
70 static char *AllocAndSetArgument(
const char *arg);
71 static char *AllocAndSetOption(
const char *arg);
73 static void ArgumentsInit(
struct Arguments *args, uint16_t capacity);
74 static void ArgumentsCleanup(
struct Arguments *args);
75 static void ArgumentsAdd(
struct Arguments *args,
char *value);
76 static void ArgumentsAddOptionAndArgument(
struct Arguments *args,
const char *opt,
const char *arg);
77 static void InitEal(
void);
79 static void ConfigSetIface(
DPDKIfaceConfig *iconf,
const char *entry_str);
80 static int ConfigSetThreads(
DPDKIfaceConfig *iconf,
const char *entry_str);
81 static int ConfigSetRxQueues(
DPDKIfaceConfig *iconf, uint16_t nb_queues, uint16_t max_queues);
82 static int ConfigSetTxQueues(
83 DPDKIfaceConfig *iconf, uint16_t nb_queues, uint16_t max_queues,
bool iface_sends_pkts);
84 static int ConfigSetMempoolSize(
85 DPDKIfaceConfig *iconf,
const char *entry_str,
const struct rte_eth_dev_info *dev_info);
86 static int ConfigSetMempoolCacheSize(
DPDKIfaceConfig *iconf,
const char *entry_str);
87 static int ConfigSetRxDescriptors(
DPDKIfaceConfig *iconf,
const char *entry_str, uint16_t max_desc);
88 static int ConfigSetTxDescriptors(
89 DPDKIfaceConfig *iconf,
const char *entry_str, uint16_t max_desc,
bool iface_sends_pkts);
91 static bool ConfigSetPromiscuousMode(
DPDKIfaceConfig *iconf,
int entry_bool);
93 static int ConfigSetChecksumChecks(
DPDKIfaceConfig *iconf,
int entry_bool);
94 static int ConfigSetChecksumOffload(
DPDKIfaceConfig *iconf,
int entry_bool);
95 static int ConfigSetCopyIface(
DPDKIfaceConfig *iconf,
const char *entry_str);
96 static int ConfigSetCopyMode(
DPDKIfaceConfig *iconf,
const char *entry_str);
97 static int ConfigSetCopyIfaceSettings(
DPDKIfaceConfig *iconf,
const char *iface,
const char *mode);
103 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf);
104 static int DeviceConfigureQueues(
DPDKIfaceConfig *iconf,
const struct rte_eth_dev_info *dev_info,
105 const struct rte_eth_conf *port_conf);
109 static void *ParseDpdkConfigAndConfigureDevice(
const char *iface);
110 static void DPDKDerefConfig(
void *conf);
112 #define DPDK_CONFIG_DEFAULT_THREADS "auto"
113 #define DPDK_CONFIG_DEFAULT_INTERRUPT_MODE false
114 #define DPDK_CONFIG_DEFAULT_MEMPOOL_SIZE "auto"
115 #define DPDK_CONFIG_DEFAULT_MEMPOOL_CACHE_SIZE "auto"
116 #define DPDK_CONFIG_DEFAULT_RX_DESCRIPTORS "auto"
117 #define DPDK_CONFIG_DEFAULT_TX_DESCRIPTORS "auto"
118 #define DPDK_CONFIG_DEFAULT_RSS_HASH_FUNCTIONS RTE_ETH_RSS_IP
119 #define DPDK_CONFIG_DEFAULT_MTU 1500
120 #define DPDK_CONFIG_DEFAULT_PROMISCUOUS_MODE 1
121 #define DPDK_CONFIG_DEFAULT_MULTICAST_MODE 1
122 #define DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION 1
123 #define DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION_OFFLOAD 1
124 #define DPDK_CONFIG_DEFAULT_VLAN_STRIP 0
125 #define DPDK_CONFIG_DEFAULT_LINKUP_TIMEOUT 0
126 #define DPDK_CONFIG_DEFAULT_COPY_MODE "none"
127 #define DPDK_CONFIG_DEFAULT_COPY_INTERFACE "none"
131 .irq_mode =
"interrupt-mode",
132 .promisc =
"promisc",
133 .multicast =
"multicast",
134 .checksum_checks =
"checksum-checks",
135 .checksum_checks_offload =
"checksum-checks-offload",
137 .vlan_strip_offload =
"vlan-strip-offload",
138 .rss_hf =
"rss-hash-functions",
139 .linkup_timeout =
"linkup-timeout",
140 .mempool_size =
"mempool-size",
141 .mempool_cache_size =
"mempool-cache-size",
142 .rx_descriptors =
"rx-descriptors",
143 .tx_descriptors =
"tx-descriptors",
144 .copy_mode =
"copy-mode",
145 .copy_iface =
"copy-iface",
152 static uint32_t GreatestDivisorUpTo(uint32_t num, uint32_t max_num)
154 for (uint32_t i = max_num; i >= 2; i--) {
166 static uint64_t GreatestPowOf2UpTo(uint64_t num)
179 num = num - (num >> 1);
184 static char *AllocArgument(
size_t arg_len)
190 ptr = (
char *)
SCCalloc(arg_len,
sizeof(
char));
192 FatalError(
"Could not allocate memory for an argument");
202 static char *AllocAndSetArgument(
const char *arg)
206 FatalError(
"Passed argument is NULL in DPDK config initialization");
209 size_t arg_len = strlen(arg);
211 ptr = AllocArgument(arg_len);
212 strlcpy(ptr, arg, arg_len + 1);
216 static char *AllocAndSetOption(
const char *arg)
220 FatalError(
"Passed option is NULL in DPDK config initialization");
223 size_t arg_len = strlen(arg);
224 uint8_t is_long_arg = arg_len > 1;
225 const char *dash_prefix = is_long_arg ?
"--" :
"-";
226 size_t full_len = arg_len + strlen(dash_prefix);
228 ptr = AllocArgument(full_len);
229 strlcpy(ptr, dash_prefix, full_len);
230 strlcat(ptr, arg, full_len + 1);
234 static void ArgumentsInit(
struct Arguments *args, uint16_t capacity)
237 args->argv =
SCCalloc(capacity,
sizeof(*args->argv));
238 if (args->argv == NULL)
239 FatalError(
"Could not allocate memory for Arguments structure");
241 args->capacity = capacity;
246 static void ArgumentsCleanup(
struct Arguments *args)
249 for (
int i = 0; i < args->argc; i++) {
250 if (args->argv[i] != NULL) {
252 args->argv[i] = NULL;
262 static void ArgumentsAdd(
struct Arguments *args,
char *value)
265 if (args->argc + 1 > args->capacity)
266 FatalError(
"No capacity for more arguments (Max: %" PRIu32
")", EAL_ARGS);
268 args->argv[args->argc++] = value;
272 static void ArgumentsAddOptionAndArgument(
struct Arguments *args,
const char *opt,
const char *arg)
278 option = AllocAndSetOption(opt);
279 ArgumentsAdd(args, option);
282 if (arg == NULL || arg[0] ==
'\0')
285 argument = AllocAndSetArgument(arg);
286 ArgumentsAdd(args, argument);
290 static void InitEal(
void)
296 struct Arguments args;
299 if (eal_params == NULL) {
300 FatalError(
"DPDK EAL parameters not found in the config");
303 ArgumentsInit(&args, EAL_ARGS);
304 ArgumentsAdd(&args, AllocAndSetArgument(
"suricata"));
308 const char *key = param->
name;
311 ArgumentsAddOptionAndArgument(&args, key, (
const char *)val->
val);
315 ArgumentsAddOptionAndArgument(&args, param->
name, param->
val);
319 eal_argv =
SCCalloc(args.argc,
sizeof(*args.argv));
320 if (eal_argv == NULL) {
321 FatalError(
"Failed to allocate memory for the array of DPDK EAL arguments");
323 memcpy(eal_argv, args.argv, args.argc *
sizeof(*args.argv));
325 rte_log_set_global_level(RTE_LOG_WARNING);
326 retval = rte_eal_init(args.argc, eal_argv);
328 ArgumentsCleanup(&args);
332 FatalError(
"DPDK EAL initialization error: %s", rte_strerror(-retval));
336 static void DPDKDerefConfig(
void *conf)
342 DPDKDeviceResourcesDeinit(&iconf->pkt_mempools);
354 FatalError(
"Could not allocate memory for DPDKIfaceConfig");
356 ptr->out_port_id = UINT16_MAX;
359 ptr->DerefFunc = DPDKDerefConfig;
366 static void ConfigSetIface(
DPDKIfaceConfig *iconf,
const char *entry_str)
371 if (entry_str == NULL || entry_str[0] ==
'\0')
372 FatalError(
"Interface name in DPDK config is NULL or empty");
374 retval = rte_eth_dev_get_port_by_name(entry_str, &iconf->port_id);
376 FatalError(
"%s: interface not found: %s", entry_str, rte_strerror(-retval));
378 strlcpy(iconf->iface, entry_str,
sizeof(iconf->iface));
382 static int ConfigSetThreads(
DPDKIfaceConfig *iconf,
const char *entry_str)
385 static uint16_t remaining_auto_cpus = UINT16_MAX;
387 SCLogError(
"DPDK runmode requires configured thread affinity");
391 bool wtaf_periface =
true;
394 wtaf_periface =
false;
397 SCLogError(
"Specify worker-cpu-set list in the threading section");
403 SCLogError(
"Specify management-cpu-set list in the threading section");
409 "\"all\" specified in worker CPU cores affinity, excluding management threads");
410 UtilAffinityCpusExclude(wtaf, mtaf);
414 if (sched_cpus == 0) {
415 SCLogError(
"No worker CPU cores with configured affinity were configured");
417 }
else if (UtilAffinityCpusOverlap(wtaf, mtaf) != 0) {
418 SCLogWarning(
"Worker threads should not overlap with management threads in the CPU core "
419 "affinity configuration");
423 if (active_runmode && !strcmp(
"single", active_runmode)) {
428 if (entry_str == NULL) {
429 SCLogError(
"Number of threads for interface \"%s\" not specified", iconf->iface);
433 if (strcmp(entry_str,
"auto") == 0) {
435 iconf->threads = (uint16_t)sched_cpus;
436 SCLogConfig(
"%s: auto-assigned %u threads", iconf->iface, iconf->threads);
441 if (live_dev_count == 0) {
442 SCLogError(
"No live devices found, cannot auto-assign threads");
445 iconf->threads = sched_cpus / live_dev_count;
446 if (iconf->threads == 0) {
447 SCLogError(
"Not enough worker CPU cores with affinity were configured");
451 if (remaining_auto_cpus == UINT16_MAX) {
453 remaining_auto_cpus = sched_cpus % live_dev_count;
454 if (remaining_auto_cpus > 0) {
456 remaining_auto_cpus--;
458 }
else if (remaining_auto_cpus > 0) {
460 remaining_auto_cpus--;
462 SCLogConfig(
"%s: auto-assigned %u threads", iconf->iface, iconf->threads);
467 SCLogError(
"Threads entry for interface %s contain non-numerical characters - \"%s\"",
468 iconf->iface, entry_str);
472 if (iconf->threads <= 0) {
473 SCLogError(
"%s: positive number of threads required", iconf->iface);
480 static bool ConfigSetInterruptMode(
DPDKIfaceConfig *iconf,
bool enable)
489 static int ConfigSetRxQueues(
DPDKIfaceConfig *iconf, uint16_t nb_queues, uint16_t max_queues)
492 if (nb_queues == 0) {
493 SCLogInfo(
"%s: positive number of RX queues is required", iconf->iface);
497 if (nb_queues > max_queues) {
498 SCLogInfo(
"%s: number of RX queues cannot exceed %" PRIu16, iconf->iface, max_queues);
502 iconf->nb_rx_queues = nb_queues;
506 static bool ConfigIfaceSendsPkts(
const char *mode)
509 if (strcmp(mode,
"ips") == 0 || strcmp(mode,
"tap") == 0) {
515 static int ConfigSetTxQueues(
516 DPDKIfaceConfig *iconf, uint16_t nb_queues, uint16_t max_queues,
bool iface_sends_pkts)
519 if (nb_queues == 0 && iface_sends_pkts) {
520 SCLogInfo(
"%s: positive number of TX queues is required", iconf->iface);
524 if (nb_queues > max_queues) {
525 SCLogInfo(
"%s: number of TX queues cannot exceed %" PRIu16, iconf->iface, max_queues);
529 iconf->nb_tx_queues = nb_queues;
533 static uint32_t MempoolSizeCalculateAutosize(
537 rte_align32pow2(iconf->nb_rx_desc + iconf->nb_tx_desc +
540 uint32_t mp_size = next_p2;
541 if (dev_info != NULL) {
542 if (strcmp(dev_info->driver_name,
"net_bonding") == 0) {
543 mp_size = BondingMempoolSizeCalculate(iconf->port_id, dev_info, mp_size);
551 static uint32_t MempoolSizeDistributeToQueues(uint32_t global_mp_size, uint16_t nic_queues)
553 if (nic_queues == 0) {
557 uint32_t mp_size_per_queue = global_mp_size / nic_queues;
558 if (mp_size_per_queue == 0) {
562 uint32_t next_p2 = rte_align32pow2(mp_size_per_queue);
563 return (mp_size_per_queue == next_p2 || mp_size_per_queue == next_p2 - 1)
565 : (next_p2 >> 1) - 1;
568 static uint32_t MempoolSizeCalculateMinimal(
572 rte_align32pow2(iconf->nb_rx_desc + iconf->nb_tx_desc +
574 if (dev_info != NULL) {
575 if (strcmp(dev_info->driver_name,
"net_bonding") == 0) {
576 mp_size = BondingMempoolSizeCalculate(iconf->port_id, dev_info, mp_size);
582 static int ConfigSetMempoolSize(
583 DPDKIfaceConfig *iconf,
const char *entry_str,
const struct rte_eth_dev_info *dev_info)
586 if (entry_str == NULL || entry_str[0] ==
'\0' || strcmp(entry_str,
"auto") == 0) {
591 if (iconf->nb_rx_queues == 0) {
593 SCLogError(
"%s: cannot autocalculate mempool size without RX queues", iconf->iface);
597 if (iconf->nb_rx_desc == 0) {
599 "%s: cannot autocalculate mempool size without RX descriptors", iconf->iface);
607 iconf->queue_mempool_size = MempoolSizeCalculateAutosize(iconf, dev_info);
611 uint32_t global_mempool_size;
613 SCLogError(
"%s: mempool size entry contain non-numerical characters - \"%s\"", iconf->iface,
618 iconf->queue_mempool_size =
619 MempoolSizeDistributeToQueues(global_mempool_size, iconf->nb_rx_queues);
620 uint32_t required_mp_size = MempoolSizeCalculateMinimal(iconf, dev_info);
621 if (required_mp_size > iconf->queue_mempool_size) {
622 uint32_t required_global_mp_size =
623 required_mp_size * iconf->nb_rx_queues + iconf->nb_rx_queues - 1;
624 SCLogError(
"%s: mempool size is likely too small for the number of descriptors and queues, "
625 "set to \"auto\" or adjust to the value of \"%" PRIu32
"\"",
626 iconf->iface, required_global_mp_size);
630 if (iconf->queue_mempool_size == 0) {
631 SCLogError(
"%s: mempool size requires a positive integer", iconf->iface);
638 static uint32_t MempoolCacheSizeCalculate(uint32_t mp_sz)
643 uint32_t max_cache_size =
MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, (uint32_t)(mp_sz / 1.5));
644 return GreatestDivisorUpTo(mp_sz, max_cache_size);
647 static int ConfigSetMempoolCacheSize(
DPDKIfaceConfig *iconf,
const char *entry_str)
650 if (entry_str == NULL || entry_str[0] ==
'\0' || strcmp(entry_str,
"auto") == 0) {
652 if (iconf->queue_mempool_size == 0) {
653 SCLogError(
"%s: cannot calculate mempool cache size of a mempool with size %" PRIu32,
654 iconf->iface, iconf->queue_mempool_size);
658 iconf->mempool_cache_size_auto =
true;
662 iconf->mempool_cache_size_auto =
false;
664 SCLogError(
"%s: mempool cache size entry contain non-numerical characters - \"%s\"",
665 iconf->iface, entry_str);
669 if (iconf->mempool_cache_size <= 0 || iconf->mempool_cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE) {
670 SCLogError(
"%s: mempool cache size requires a positive number smaller than %" PRIu32,
671 iconf->iface, RTE_MEMPOOL_CACHE_MAX_SIZE);
678 static int ConfigSetRxDescriptors(
DPDKIfaceConfig *iconf,
const char *entry_str, uint16_t max_desc)
681 if (entry_str == NULL || entry_str[0] ==
'\0') {
682 SCLogInfo(
"%s: number of RX descriptors not found, going with: %s", iconf->iface,
683 DPDK_CONFIG_DEFAULT_RX_DESCRIPTORS);
684 entry_str = DPDK_CONFIG_DEFAULT_RX_DESCRIPTORS;
687 if (strcmp(entry_str,
"auto") == 0) {
688 iconf->nb_rx_desc = (uint16_t)GreatestPowOf2UpTo(max_desc);
693 SCLogError(
"%s: RX descriptors entry contains non-numerical characters - \"%s\"",
694 iconf->iface, entry_str);
698 if (iconf->nb_rx_desc == 0) {
699 SCLogError(
"%s: positive number of RX descriptors is required", iconf->iface);
701 }
else if (iconf->nb_rx_desc > max_desc) {
702 SCLogError(
"%s: number of RX descriptors cannot exceed %" PRIu16, iconf->iface, max_desc);
709 static int ConfigSetTxDescriptors(
710 DPDKIfaceConfig *iconf,
const char *entry_str, uint16_t max_desc,
bool iface_sends_pkts)
713 if (entry_str == NULL || entry_str[0] ==
'\0') {
714 SCLogInfo(
"%s: number of TX descriptors not found, going with: %s", iconf->iface,
715 DPDK_CONFIG_DEFAULT_TX_DESCRIPTORS);
716 entry_str = DPDK_CONFIG_DEFAULT_TX_DESCRIPTORS;
719 if (strcmp(entry_str,
"auto") == 0) {
720 if (iface_sends_pkts) {
721 iconf->nb_tx_desc = (uint16_t)GreatestPowOf2UpTo(max_desc);
723 iconf->nb_tx_desc = 0;
729 SCLogError(
"%s: TX descriptors entry contains non-numerical characters - \"%s\"",
730 iconf->iface, entry_str);
734 if (iconf->nb_tx_desc == 0 && iface_sends_pkts) {
735 SCLogError(
"%s: positive number of TX descriptors is required", iconf->iface);
737 }
else if (iconf->nb_tx_desc > max_desc) {
738 SCLogError(
"%s: number of TX descriptors cannot exceed %" PRIu16, iconf->iface, max_desc);
745 static int ConfigSetRSSHashFunctions(
DPDKIfaceConfig *iconf,
const char *entry_str)
748 if (entry_str == NULL || entry_str[0] ==
'\0' || strcmp(entry_str,
"auto") == 0) {
749 iconf->rss_hf = DPDK_CONFIG_DEFAULT_RSS_HASH_FUNCTIONS;
754 SCLogError(
"%s: RSS hash functions entry contain non-numerical characters - \"%s\"",
755 iconf->iface, entry_str);
765 if (entry_int < RTE_ETHER_MIN_MTU || entry_int > RTE_ETHER_MAX_JUMBO_FRAME_LEN) {
766 SCLogError(
"%s: MTU size can only be between %" PRIu32
" and %" PRIu32, iconf->iface,
767 RTE_ETHER_MIN_MTU, RTE_ETHER_MAX_JUMBO_FRAME_LEN);
771 iconf->mtu = (uint16_t)entry_int;
775 static int ConfigSetLinkupTimeout(
DPDKIfaceConfig *iconf, intmax_t entry_int)
778 if (entry_int < 0 || entry_int > UINT16_MAX) {
779 SCLogError(
"%s: Link-up waiting timeout needs to be a positive number (up to %u) or 0 to "
781 iconf->iface, UINT16_MAX);
785 iconf->linkup_timeout = (uint16_t)entry_int;
789 static bool ConfigSetPromiscuousMode(
DPDKIfaceConfig *iconf,
int entry_bool)
807 static int ConfigSetChecksumChecks(
DPDKIfaceConfig *iconf,
int entry_bool)
816 static int ConfigSetChecksumOffload(
DPDKIfaceConfig *iconf,
int entry_bool)
828 iconf->vlan_strip_enabled = entry_bool;
832 static int ConfigSetCopyIface(
DPDKIfaceConfig *iconf,
const char *entry_str)
837 if (entry_str == NULL || entry_str[0] ==
'\0' || strcmp(entry_str,
"none") == 0) {
838 iconf->out_iface = NULL;
842 retval = rte_eth_dev_get_port_by_name(entry_str, &iconf->out_port_id);
844 SCLogError(
"%s: copy interface (%s) not found: %s", iconf->iface, entry_str,
845 rte_strerror(-retval));
849 iconf->out_iface = entry_str;
853 static int ConfigSetCopyMode(
DPDKIfaceConfig *iconf,
const char *entry_str)
856 if (entry_str == NULL) {
857 SCLogWarning(
"%s: no copy mode specified, changing to %s ", iconf->iface,
858 DPDK_CONFIG_DEFAULT_COPY_MODE);
859 entry_str = DPDK_CONFIG_DEFAULT_COPY_MODE;
862 if (strcmp(entry_str,
"none") != 0 && strcmp(entry_str,
"tap") != 0 &&
863 strcmp(entry_str,
"ips") != 0) {
864 SCLogWarning(
"%s: copy mode \"%s\" is not one of the possible values (none|tap|ips). "
866 entry_str, iconf->iface, DPDK_CONFIG_DEFAULT_COPY_MODE);
867 entry_str = DPDK_CONFIG_DEFAULT_COPY_MODE;
870 if (strcmp(entry_str,
"none") == 0) {
872 }
else if (strcmp(entry_str,
"tap") == 0) {
874 }
else if (strcmp(entry_str,
"ips") == 0) {
881 static int ConfigSetCopyIfaceSettings(
DPDKIfaceConfig *iconf,
const char *iface,
const char *mode)
886 retval = ConfigSetCopyIface(iconf, iface);
890 retval = ConfigSetCopyMode(iconf, mode);
895 if (iconf->out_iface != NULL)
896 iconf->out_iface = NULL;
900 if (iconf->out_iface == NULL || strlen(iconf->out_iface) <= 0) {
901 SCLogError(
"%s: copy mode enabled but interface not set", iconf->iface);
914 const char *entry_str = NULL;
915 intmax_t entry_int = 0;
917 const char *copy_iface_str = NULL;
918 const char *copy_mode_str = NULL;
920 ConfigSetIface(iconf, iface);
921 struct rte_eth_dev_info dev_info = { 0 };
922 retval = rte_eth_dev_info_get(iconf->port_id, &dev_info);
924 SCLogError(
"%s: getting device info failed: %s", iconf->iface, rte_strerror(-retval));
930 FatalError(
"failed to find DPDK configuration for the interface %s", iconf->iface);
934 ? ConfigSetThreads(iconf, DPDK_CONFIG_DEFAULT_THREADS)
935 : ConfigSetThreads(iconf, entry_str);
941 if_root, if_default, dpdk_yaml.
irq_mode, &entry_bool);
943 irq_enable = DPDK_CONFIG_DEFAULT_INTERRUPT_MODE;
945 irq_enable = entry_bool;
947 retval = ConfigSetInterruptMode(iconf, irq_enable);
952 if_root, if_default, dpdk_yaml.
copy_mode, ©_mode_str);
954 copy_mode_str = DPDK_CONFIG_DEFAULT_COPY_MODE;
959 ? ConfigSetRxDescriptors(iconf, DPDK_CONFIG_DEFAULT_RX_DESCRIPTORS,
960 dev_info.rx_desc_lim.nb_max)
961 : ConfigSetRxDescriptors(iconf, entry_str, dev_info.rx_desc_lim.nb_max);
965 bool iface_sends_pkts = ConfigIfaceSendsPkts(copy_mode_str);
968 ? ConfigSetTxDescriptors(iconf, DPDK_CONFIG_DEFAULT_TX_DESCRIPTORS,
969 dev_info.tx_desc_lim.nb_max, iface_sends_pkts)
970 : ConfigSetTxDescriptors(
971 iconf, entry_str, dev_info.tx_desc_lim.nb_max, iface_sends_pkts);
976 retval = ConfigSetRxQueues(iconf, iconf->threads, dev_info.max_rx_queues);
978 SCLogError(
"%s: too many threads configured - reduce thread count to: %" PRIu16,
979 iconf->iface, dev_info.max_rx_queues);
984 uint16_t tx_queues = iconf->nb_tx_desc > 0 ? iconf->threads : 0;
985 retval = ConfigSetTxQueues(iconf, tx_queues, dev_info.max_tx_queues, iface_sends_pkts);
987 SCLogError(
"%s: too many threads configured - reduce thread count to: %" PRIu16,
988 iconf->iface, dev_info.max_tx_queues);
993 if_root, if_default, dpdk_yaml.
mempool_size, &entry_str) != 1
994 ? ConfigSetMempoolSize(iconf, DPDK_CONFIG_DEFAULT_MEMPOOL_SIZE, &dev_info)
995 : ConfigSetMempoolSize(iconf, entry_str, &dev_info);
1001 ? ConfigSetMempoolCacheSize(iconf, DPDK_CONFIG_DEFAULT_MEMPOOL_CACHE_SIZE)
1002 : ConfigSetMempoolCacheSize(iconf, entry_str);
1007 ? ConfigSetMtu(iconf, DPDK_CONFIG_DEFAULT_MTU)
1008 : ConfigSetMtu(iconf, entry_int);
1013 ? ConfigSetRSSHashFunctions(iconf, NULL)
1014 : ConfigSetRSSHashFunctions(iconf, entry_str);
1019 if_root, if_default, dpdk_yaml.
promisc, &entry_bool) != 1
1020 ? ConfigSetPromiscuousMode(iconf, DPDK_CONFIG_DEFAULT_PROMISCUOUS_MODE)
1021 : ConfigSetPromiscuousMode(iconf, entry_bool);
1026 if_root, if_default, dpdk_yaml.
multicast, &entry_bool) != 1
1027 ? ConfigSetMulticast(iconf, DPDK_CONFIG_DEFAULT_MULTICAST_MODE)
1028 : ConfigSetMulticast(iconf, entry_bool);
1034 ? ConfigSetChecksumChecks(iconf, DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION)
1035 : ConfigSetChecksumChecks(iconf, entry_bool);
1041 ? ConfigSetChecksumOffload(
1042 iconf, DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION_OFFLOAD)
1043 : ConfigSetChecksumOffload(iconf, entry_bool);
1050 ConfigSetVlanStrip(iconf, DPDK_CONFIG_DEFAULT_VLAN_STRIP);
1052 ConfigSetVlanStrip(iconf, entry_bool);
1057 ? ConfigSetLinkupTimeout(iconf, DPDK_CONFIG_DEFAULT_LINKUP_TIMEOUT)
1058 : ConfigSetLinkupTimeout(iconf, entry_int);
1063 if_root, if_default, dpdk_yaml.
copy_iface, ©_iface_str);
1065 copy_iface_str = DPDK_CONFIG_DEFAULT_COPY_INTERFACE;
1068 retval = ConfigSetCopyIfaceSettings(iconf, copy_iface_str, copy_mode_str);
1075 static bool ConfigThreadsGenericIsValid(uint16_t iface_threads,
ThreadsAffinityType *wtaf)
1077 static uint32_t total_cpus = 0;
1078 total_cpus += iface_threads;
1080 SCLogError(
"Specify worker-cpu-set list in the threading section");
1084 SCLogError(
"Interfaces requested more cores than configured in the worker-cpu-set "
1085 "threading section (requested %d configured %d",
1093 static bool ConfigThreadsInterfaceIsValid(uint16_t iface_threads,
ThreadsAffinityType *itaf)
1096 SCLogError(
"Interface requested more cores than configured in the interface-specific "
1097 "threading section (requested %d configured %d",
1105 static bool ConfigIsThreadingValid(uint16_t iface_threads,
const char *iface)
1109 if (itaf && !ConfigThreadsInterfaceIsValid(iface_threads, itaf)) {
1111 }
else if (itaf == NULL && !ConfigThreadsGenericIsValid(iface_threads, wtaf)) {
1126 retval = ConfigLoad(iconf, iface);
1127 if (retval < 0 || !ConfigIsThreadingValid(iconf->threads, iface)) {
1128 iconf->DerefFunc(iconf);
1135 static void DeviceSetPMDSpecificRSS(
struct rte_eth_rss_conf *rss_conf,
const char *driver_name)
1137 if (strcmp(driver_name,
"net_i40e") == 0)
1138 i40eDeviceSetRSSConf(rss_conf);
1139 if (strcmp(driver_name,
"net_ice") == 0)
1140 iceDeviceSetRSSConf(rss_conf);
1141 if (strcmp(driver_name,
"net_ixgbe") == 0)
1142 ixgbeDeviceSetRSSHashFunction(&rss_conf->rss_hf);
1143 if (strcmp(driver_name,
"net_e1000_igb") == 0)
1144 rss_conf->rss_hf = (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_IPV6_EX);
1148 static int32_t GetFirstSetBitPosition(uint64_t bits)
1150 for (int32_t i = 0; i < 64; i++) {
1157 static void DumpRSSFlags(
const uint64_t requested,
const uint64_t actual)
1162 "RTE_ETH_RSS_IP %sset", ((requested & RTE_ETH_RSS_IP) == RTE_ETH_RSS_IP) ?
"" :
"NOT ");
1164 ((requested & RTE_ETH_RSS_TCP) == RTE_ETH_RSS_TCP) ?
"" :
"NOT ");
1166 ((requested & RTE_ETH_RSS_UDP) == RTE_ETH_RSS_UDP) ?
"" :
"NOT ");
1168 ((requested & RTE_ETH_RSS_SCTP) == RTE_ETH_RSS_SCTP) ?
"" :
"NOT ");
1170 ((requested & RTE_ETH_RSS_TUNNEL) == RTE_ETH_RSS_TUNNEL) ?
"" :
"NOT ");
1173 SCLogConfig(
"RTE_ETH_RSS_IPV4 (Bit position: %d) %sset",
1174 GetFirstSetBitPosition(RTE_ETH_RSS_IPV4), (requested & RTE_ETH_RSS_IPV4) ?
"" :
"NOT ");
1175 SCLogConfig(
"RTE_ETH_RSS_FRAG_IPV4 (Bit position: %d) %sset",
1176 GetFirstSetBitPosition(RTE_ETH_RSS_FRAG_IPV4),
1177 (requested & RTE_ETH_RSS_FRAG_IPV4) ?
"" :
"NOT ");
1178 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_TCP (Bit position: %d) %sset",
1179 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_TCP),
1180 (requested & RTE_ETH_RSS_NONFRAG_IPV4_TCP) ?
"" :
"NOT ");
1181 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_UDP (Bit position: %d) %sset",
1182 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_UDP),
1183 (requested & RTE_ETH_RSS_NONFRAG_IPV4_UDP) ?
"" :
"NOT ");
1184 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_SCTP (Bit position: %d) %sset",
1185 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_SCTP),
1186 (requested & RTE_ETH_RSS_NONFRAG_IPV4_SCTP) ?
"" :
"NOT ");
1187 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_OTHER (Bit position: %d) %sset",
1188 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_OTHER),
1189 (requested & RTE_ETH_RSS_NONFRAG_IPV4_OTHER) ?
"" :
"NOT ");
1190 SCLogConfig(
"RTE_ETH_RSS_IPV6 (Bit position: %d) %sset",
1191 GetFirstSetBitPosition(RTE_ETH_RSS_IPV6), (requested & RTE_ETH_RSS_IPV6) ?
"" :
"NOT ");
1192 SCLogConfig(
"RTE_ETH_RSS_FRAG_IPV6 (Bit position: %d) %sset",
1193 GetFirstSetBitPosition(RTE_ETH_RSS_FRAG_IPV6),
1194 (requested & RTE_ETH_RSS_FRAG_IPV6) ?
"" :
"NOT ");
1195 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_TCP (Bit position: %d) %sset",
1196 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_TCP),
1197 (requested & RTE_ETH_RSS_NONFRAG_IPV6_TCP) ?
"" :
"NOT ");
1198 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_UDP (Bit position: %d) %sset",
1199 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_UDP),
1200 (requested & RTE_ETH_RSS_NONFRAG_IPV6_UDP) ?
"" :
"NOT ");
1201 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_SCTP (Bit position: %d) %sset",
1202 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_SCTP),
1203 (requested & RTE_ETH_RSS_NONFRAG_IPV6_SCTP) ?
"" :
"NOT ");
1204 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_OTHER (Bit position: %d) %sset",
1205 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_OTHER),
1206 (requested & RTE_ETH_RSS_NONFRAG_IPV6_OTHER) ?
"" :
"NOT ");
1208 SCLogConfig(
"RTE_ETH_RSS_L2_PAYLOAD (Bit position: %d) %sset",
1209 GetFirstSetBitPosition(RTE_ETH_RSS_L2_PAYLOAD),
1210 (requested & RTE_ETH_RSS_L2_PAYLOAD) ?
"" :
"NOT ");
1211 SCLogConfig(
"RTE_ETH_RSS_IPV6_EX (Bit position: %d) %sset",
1212 GetFirstSetBitPosition(RTE_ETH_RSS_IPV6_EX),
1213 (requested & RTE_ETH_RSS_IPV6_EX) ?
"" :
"NOT ");
1214 SCLogConfig(
"RTE_ETH_RSS_IPV6_TCP_EX (Bit position: %d) %sset",
1215 GetFirstSetBitPosition(RTE_ETH_RSS_IPV6_TCP_EX),
1216 (requested & RTE_ETH_RSS_IPV6_TCP_EX) ?
"" :
"NOT ");
1217 SCLogConfig(
"RTE_ETH_RSS_IPV6_UDP_EX (Bit position: %d) %sset",
1218 GetFirstSetBitPosition(RTE_ETH_RSS_IPV6_UDP_EX),
1219 (requested & RTE_ETH_RSS_IPV6_UDP_EX) ?
"" :
"NOT ");
1221 SCLogConfig(
"RTE_ETH_RSS_PORT (Bit position: %d) %sset",
1222 GetFirstSetBitPosition(RTE_ETH_RSS_PORT), (requested & RTE_ETH_RSS_PORT) ?
"" :
"NOT ");
1223 SCLogConfig(
"RTE_ETH_RSS_VXLAN (Bit position: %d) %sset",
1224 GetFirstSetBitPosition(RTE_ETH_RSS_VXLAN),
1225 (requested & RTE_ETH_RSS_VXLAN) ?
"" :
"NOT ");
1226 SCLogConfig(
"RTE_ETH_RSS_NVGRE (Bit position: %d) %sset",
1227 GetFirstSetBitPosition(RTE_ETH_RSS_NVGRE),
1228 (requested & RTE_ETH_RSS_NVGRE) ?
"" :
"NOT ");
1229 SCLogConfig(
"RTE_ETH_RSS_GTPU (Bit position: %d) %sset",
1230 GetFirstSetBitPosition(RTE_ETH_RSS_GTPU), (requested & RTE_ETH_RSS_GTPU) ?
"" :
"NOT ");
1232 SCLogConfig(
"RTE_ETH_RSS_L3_SRC_ONLY (Bit position: %d) %sset",
1233 GetFirstSetBitPosition(RTE_ETH_RSS_L3_SRC_ONLY),
1234 (requested & RTE_ETH_RSS_L3_SRC_ONLY) ?
"" :
"NOT ");
1235 SCLogConfig(
"RTE_ETH_RSS_L3_DST_ONLY (Bit position: %d) %sset",
1236 GetFirstSetBitPosition(RTE_ETH_RSS_L3_DST_ONLY),
1237 (requested & RTE_ETH_RSS_L3_DST_ONLY) ?
"" :
"NOT ");
1238 SCLogConfig(
"RTE_ETH_RSS_L4_SRC_ONLY (Bit position: %d) %sset",
1239 GetFirstSetBitPosition(RTE_ETH_RSS_L4_SRC_ONLY),
1240 (requested & RTE_ETH_RSS_L4_SRC_ONLY) ?
"" :
"NOT ");
1241 SCLogConfig(
"RTE_ETH_RSS_L4_DST_ONLY (Bit position: %d) %sset",
1242 GetFirstSetBitPosition(RTE_ETH_RSS_L4_DST_ONLY),
1243 (requested & RTE_ETH_RSS_L4_DST_ONLY) ?
"" :
"NOT ");
1246 "RTE_ETH_RSS_IP %sset", ((actual & RTE_ETH_RSS_IP) == RTE_ETH_RSS_IP) ?
"" :
"NOT ");
1248 "RTE_ETH_RSS_TCP %sset", ((actual & RTE_ETH_RSS_TCP) == RTE_ETH_RSS_TCP) ?
"" :
"NOT ");
1250 "RTE_ETH_RSS_UDP %sset", ((actual & RTE_ETH_RSS_UDP) == RTE_ETH_RSS_UDP) ?
"" :
"NOT ");
1252 ((actual & RTE_ETH_RSS_SCTP) == RTE_ETH_RSS_SCTP) ?
"" :
"NOT ");
1254 ((actual & RTE_ETH_RSS_TUNNEL) == RTE_ETH_RSS_TUNNEL) ?
"" :
"NOT ");
1257 SCLogConfig(
"RTE_ETH_RSS_IPV4 %sset", (actual & RTE_ETH_RSS_IPV4) ?
"" :
"NOT ");
1258 SCLogConfig(
"RTE_ETH_RSS_FRAG_IPV4 %sset", (actual & RTE_ETH_RSS_FRAG_IPV4) ?
"" :
"NOT ");
1260 (actual & RTE_ETH_RSS_NONFRAG_IPV4_TCP) ?
"" :
"NOT ");
1262 (actual & RTE_ETH_RSS_NONFRAG_IPV4_UDP) ?
"" :
"NOT ");
1263 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_SCTP %sset",
1264 (actual & RTE_ETH_RSS_NONFRAG_IPV4_SCTP) ?
"" :
"NOT ");
1265 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_OTHER %sset",
1266 (actual & RTE_ETH_RSS_NONFRAG_IPV4_OTHER) ?
"" :
"NOT ");
1267 SCLogConfig(
"RTE_ETH_RSS_IPV6 %sset", (actual & RTE_ETH_RSS_IPV6) ?
"" :
"NOT ");
1268 SCLogConfig(
"RTE_ETH_RSS_FRAG_IPV6 %sset", (actual & RTE_ETH_RSS_FRAG_IPV6) ?
"" :
"NOT ");
1270 (actual & RTE_ETH_RSS_NONFRAG_IPV6_TCP) ?
"" :
"NOT ");
1272 (actual & RTE_ETH_RSS_NONFRAG_IPV6_UDP) ?
"" :
"NOT ");
1273 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_SCTP %sset",
1274 (actual & RTE_ETH_RSS_NONFRAG_IPV6_SCTP) ?
"" :
"NOT ");
1275 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_OTHER %sset",
1276 (actual & RTE_ETH_RSS_NONFRAG_IPV6_OTHER) ?
"" :
"NOT ");
1278 SCLogConfig(
"RTE_ETH_RSS_L2_PAYLOAD %sset", (actual & RTE_ETH_RSS_L2_PAYLOAD) ?
"" :
"NOT ");
1279 SCLogConfig(
"RTE_ETH_RSS_IPV6_EX %sset", (actual & RTE_ETH_RSS_IPV6_EX) ?
"" :
"NOT ");
1280 SCLogConfig(
"RTE_ETH_RSS_IPV6_TCP_EX %sset", (actual & RTE_ETH_RSS_IPV6_TCP_EX) ?
"" :
"NOT ");
1281 SCLogConfig(
"RTE_ETH_RSS_IPV6_UDP_EX %sset", (actual & RTE_ETH_RSS_IPV6_UDP_EX) ?
"" :
"NOT ");
1283 SCLogConfig(
"RTE_ETH_RSS_PORT %sset", (actual & RTE_ETH_RSS_PORT) ?
"" :
"NOT ");
1284 SCLogConfig(
"RTE_ETH_RSS_VXLAN %sset", (actual & RTE_ETH_RSS_VXLAN) ?
"" :
"NOT ");
1285 SCLogConfig(
"RTE_ETH_RSS_NVGRE %sset", (actual & RTE_ETH_RSS_NVGRE) ?
"" :
"NOT ");
1286 SCLogConfig(
"RTE_ETH_RSS_GTPU %sset", (actual & RTE_ETH_RSS_GTPU) ?
"" :
"NOT ");
1288 SCLogConfig(
"RTE_ETH_RSS_L3_SRC_ONLY %sset", (actual & RTE_ETH_RSS_L3_SRC_ONLY) ?
"" :
"NOT ");
1289 SCLogConfig(
"RTE_ETH_RSS_L3_DST_ONLY %sset", (actual & RTE_ETH_RSS_L3_DST_ONLY) ?
"" :
"NOT ");
1290 SCLogConfig(
"RTE_ETH_RSS_L4_SRC_ONLY %sset", (actual & RTE_ETH_RSS_L4_SRC_ONLY) ?
"" :
"NOT ");
1291 SCLogConfig(
"RTE_ETH_RSS_L4_DST_ONLY %sset", (actual & RTE_ETH_RSS_L4_DST_ONLY) ?
"" :
"NOT ");
1294 static void DumpRXOffloadCapabilities(
const uint64_t rx_offld_capa)
1296 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_VLAN_STRIP - %savailable",
1297 rx_offld_capa & RTE_ETH_RX_OFFLOAD_VLAN_STRIP ?
"" :
"NOT ");
1298 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_IPV4_CKSUM - %savailable",
1299 rx_offld_capa & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM ?
"" :
"NOT ");
1300 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_UDP_CKSUM - %savailable",
1301 rx_offld_capa & RTE_ETH_RX_OFFLOAD_UDP_CKSUM ?
"" :
"NOT ");
1302 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_TCP_CKSUM - %savailable",
1303 rx_offld_capa & RTE_ETH_RX_OFFLOAD_TCP_CKSUM ?
"" :
"NOT ");
1304 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_TCP_LRO - %savailable",
1305 rx_offld_capa & RTE_ETH_RX_OFFLOAD_TCP_LRO ?
"" :
"NOT ");
1306 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_QINQ_STRIP - %savailable",
1307 rx_offld_capa & RTE_ETH_RX_OFFLOAD_QINQ_STRIP ?
"" :
"NOT ");
1308 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM - %savailable",
1309 rx_offld_capa & RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM ?
"" :
"NOT ");
1310 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_MACSEC_STRIP - %savailable",
1311 rx_offld_capa & RTE_ETH_RX_OFFLOAD_MACSEC_STRIP ?
"" :
"NOT ");
1312 #if RTE_VERSION < RTE_VERSION_NUM(22, 11, 0, 0)
1313 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_HEADER_SPLIT - %savailable",
1314 rx_offld_capa & RTE_ETH_RX_OFFLOAD_HEADER_SPLIT ?
"" :
"NOT ");
1316 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_VLAN_FILTER - %savailable",
1317 rx_offld_capa & RTE_ETH_RX_OFFLOAD_VLAN_FILTER ?
"" :
"NOT ");
1318 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_VLAN_EXTEND - %savailable",
1319 rx_offld_capa & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND ?
"" :
"NOT ");
1320 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_SCATTER - %savailable",
1321 rx_offld_capa & RTE_ETH_RX_OFFLOAD_SCATTER ?
"" :
"NOT ");
1322 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_TIMESTAMP - %savailable",
1323 rx_offld_capa & RTE_ETH_RX_OFFLOAD_TIMESTAMP ?
"" :
"NOT ");
1324 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_SECURITY - %savailable",
1325 rx_offld_capa & RTE_ETH_RX_OFFLOAD_SECURITY ?
"" :
"NOT ");
1326 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_KEEP_CRC - %savailable",
1327 rx_offld_capa & RTE_ETH_RX_OFFLOAD_KEEP_CRC ?
"" :
"NOT ");
1328 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_SCTP_CKSUM - %savailable",
1329 rx_offld_capa & RTE_ETH_RX_OFFLOAD_SCTP_CKSUM ?
"" :
"NOT ");
1330 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM - %savailable",
1331 rx_offld_capa & RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM ?
"" :
"NOT ");
1332 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_RSS_HASH - %savailable",
1333 rx_offld_capa & RTE_ETH_RX_OFFLOAD_RSS_HASH ?
"" :
"NOT ");
1334 #if RTE_VERSION >= RTE_VERSION_NUM(20, 11, 0, 0)
1335 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT - %savailable",
1336 rx_offld_capa & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT ?
"" :
"NOT ");
1340 static int DeviceValidateMTU(
const DPDKIfaceConfig *iconf,
const struct rte_eth_dev_info *dev_info)
1343 if (iconf->mtu > dev_info->max_mtu || iconf->mtu < dev_info->min_mtu) {
1345 "Min MTU: %" PRIu16
" Max MTU: %" PRIu16,
1346 iconf->iface, dev_info->min_mtu, dev_info->max_mtu);
1350 #if RTE_VERSION < RTE_VERSION_NUM(21, 11, 0, 0)
1352 if (iconf->mtu > RTE_ETHER_MAX_LEN &&
1353 !(dev_info->rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME)) {
1354 SCLogError(
"%s: jumbo frames not supported, set MTU to 1500", iconf->iface);
1362 static void DeviceSetMTU(
struct rte_eth_conf *port_conf, uint16_t mtu)
1364 #if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0)
1365 port_conf->rxmode.mtu = mtu;
1367 port_conf->rxmode.max_rx_pkt_len = mtu;
1368 if (mtu > RTE_ETHER_MAX_LEN) {
1369 port_conf->rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1374 static void PortConfSetInterruptMode(
const DPDKIfaceConfig *iconf,
struct rte_eth_conf *port_conf)
1376 SCLogConfig(
"%s: interrupt mode is %s", iconf->iface,
1379 port_conf->intr_conf.rxq = 1;
1383 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf)
1385 if (dev_info->rx_offload_capa & RTE_ETH_RX_OFFLOAD_RSS_HASH) {
1386 if (iconf->nb_rx_queues > 1) {
1387 SCLogConfig(
"%s: RSS enabled for %d queues", iconf->iface, iconf->nb_rx_queues);
1388 port_conf->rx_adv_conf.rss_conf = (
struct rte_eth_rss_conf){
1389 .rss_key = RSS_HKEY,
1390 .rss_key_len = RSS_HKEY_LEN,
1391 .rss_hf = iconf->rss_hf,
1394 const char *dev_driver = dev_info->driver_name;
1395 if (strcmp(dev_info->driver_name,
"net_bonding") == 0) {
1396 dev_driver = BondingDeviceDriverGet(iconf->port_id);
1399 DeviceSetPMDSpecificRSS(&port_conf->rx_adv_conf.rss_conf, dev_driver);
1401 uint64_t rss_hf_tmp =
1402 port_conf->rx_adv_conf.rss_conf.rss_hf & dev_info->flow_type_rss_offloads;
1403 if (port_conf->rx_adv_conf.rss_conf.rss_hf != rss_hf_tmp) {
1404 DumpRSSFlags(port_conf->rx_adv_conf.rss_conf.rss_hf, rss_hf_tmp);
1406 SCLogWarning(
"%s: modified RSS hash function based on hardware support: "
1407 "requested:%#" PRIx64
", configured:%#" PRIx64,
1408 iconf->iface, port_conf->rx_adv_conf.rss_conf.rss_hf, rss_hf_tmp);
1409 port_conf->rx_adv_conf.rss_conf.rss_hf = rss_hf_tmp;
1411 port_conf->rxmode.mq_mode = RTE_ETH_MQ_RX_RSS;
1414 port_conf->rx_adv_conf.rss_conf.rss_key = NULL;
1415 port_conf->rx_adv_conf.rss_conf.rss_hf = 0;
1418 SCLogConfig(
"%s: RSS not supported", iconf->iface);
1423 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf)
1426 SCLogConfig(
"%s: checksum validation disabled", iconf->iface);
1427 }
else if ((dev_info->rx_offload_capa & RTE_ETH_RX_OFFLOAD_CHECKSUM) ==
1428 RTE_ETH_RX_OFFLOAD_CHECKSUM) {
1431 SCLogConfig(
"%s: IP, TCP and UDP checksum validation offloaded", iconf->iface);
1432 port_conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_CHECKSUM;
1435 SCLogConfig(
"%s: checksum validation enabled (but can be offloaded)", iconf->iface);
1441 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf)
1443 if (iconf->vlan_strip_enabled) {
1444 if (dev_info->rx_offload_capa & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
1445 port_conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
1446 SCLogConfig(
"%s: hardware VLAN stripping enabled", iconf->iface);
1448 SCLogWarning(
"%s: hardware VLAN stripping enabled but not supported, disabling",
1455 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf)
1457 DumpRXOffloadCapabilities(dev_info->rx_offload_capa);
1458 *port_conf = (
struct rte_eth_conf){
1460 .mq_mode = RTE_ETH_MQ_RX_NONE,
1464 .mq_mode = RTE_ETH_MQ_TX_NONE,
1469 PortConfSetInterruptMode(iconf, port_conf);
1472 PortConfSetRSSConf(iconf, dev_info, port_conf);
1473 PortConfSetChsumOffload(iconf, dev_info, port_conf);
1474 DeviceSetMTU(port_conf, iconf->mtu);
1475 PortConfSetVlanOffload(iconf, dev_info, port_conf);
1477 if (dev_info->tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) {
1478 port_conf->txmode.offloads |= RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
1482 static int DeviceConfigureQueues(
DPDKIfaceConfig *iconf,
const struct rte_eth_dev_info *dev_info,
1483 const struct rte_eth_conf *port_conf)
1487 struct rte_eth_rxconf rxq_conf;
1488 struct rte_eth_txconf txq_conf;
1490 retval = DPDKDeviceResourcesInit(&(iconf->pkt_mempools), iconf->nb_rx_queues);
1496 uint16_t mtu_size = iconf->mtu + RTE_ETHER_CRC_LEN + RTE_ETHER_HDR_LEN + 4;
1497 uint16_t mbuf_size = ROUNDUP(mtu_size, 1024) + RTE_PKTMBUF_HEADROOM;
1498 uint32_t q_mp_cache_sz = iconf->mempool_cache_size_auto
1499 ? MempoolCacheSizeCalculate(iconf->queue_mempool_size)
1500 : iconf->mempool_cache_size;
1501 SCLogInfo(
"%s: creating %u packet mempools of size %u, cache size %u, mbuf size %u",
1502 iconf->iface, iconf->nb_rx_queues, iconf->queue_mempool_size, q_mp_cache_sz, mbuf_size);
1503 for (
int i = 0; i < iconf->nb_rx_queues; i++) {
1504 char mempool_name[64];
1505 snprintf(mempool_name,
sizeof(mempool_name),
"mp_%d_%.20s", i, iconf->iface);
1506 iconf->pkt_mempools->pkt_mp[i] = rte_pktmbuf_pool_create(mempool_name,
1507 iconf->queue_mempool_size, q_mp_cache_sz, 0, mbuf_size, (
int)iconf->socket_id);
1508 if (iconf->pkt_mempools->pkt_mp[i] == NULL) {
1509 retval = -rte_errno;
1510 SCLogError(
"%s: rte_pktmbuf_pool_create failed with code %d (mempool: %s) - %s",
1511 iconf->iface, rte_errno, mempool_name, rte_strerror(rte_errno));
1516 for (uint16_t queue_id = 0; queue_id < iconf->nb_rx_queues; queue_id++) {
1517 rxq_conf = dev_info->default_rxconf;
1518 rxq_conf.offloads = port_conf->rxmode.offloads;
1519 rxq_conf.rx_thresh.hthresh = 0;
1520 rxq_conf.rx_thresh.pthresh = 0;
1521 rxq_conf.rx_thresh.wthresh = 0;
1522 rxq_conf.rx_free_thresh = 0;
1523 rxq_conf.rx_drop_en = 0;
1524 SCLogConfig(
"%s: setting up RX queue %d: rx_desc: %u offloads: 0x%" PRIx64
1525 " hthresh: %" PRIu8
" pthresh: %" PRIu8
" wthresh: %" PRIu8
1526 " free_thresh: %" PRIu16
" drop_en: %" PRIu8,
1527 iconf->iface, queue_id, iconf->nb_rx_desc, rxq_conf.offloads,
1528 rxq_conf.rx_thresh.hthresh, rxq_conf.rx_thresh.pthresh, rxq_conf.rx_thresh.wthresh,
1529 rxq_conf.rx_free_thresh, rxq_conf.rx_drop_en);
1531 retval = rte_eth_rx_queue_setup(iconf->port_id, queue_id, iconf->nb_rx_desc,
1532 (
unsigned int)iconf->socket_id, &rxq_conf, iconf->pkt_mempools->pkt_mp[queue_id]);
1534 SCLogError(
"%s: failed to setup RX queue %u: %s", iconf->iface, queue_id,
1535 rte_strerror(-retval));
1540 for (uint16_t queue_id = 0; queue_id < iconf->nb_tx_queues; queue_id++) {
1541 txq_conf = dev_info->default_txconf;
1542 txq_conf.offloads = port_conf->txmode.offloads;
1543 SCLogConfig(
"%s: setting up TX queue %d: tx_desc: %" PRIu16
" tx: offloads: 0x%" PRIx64
1544 " hthresh: %" PRIu8
" pthresh: %" PRIu8
" wthresh: %" PRIu8
1545 " tx_free_thresh: %" PRIu16
" tx_rs_thresh: %" PRIu16
1546 " txq_deferred_start: %" PRIu8,
1547 iconf->iface, queue_id, iconf->nb_tx_desc, txq_conf.offloads,
1548 txq_conf.tx_thresh.hthresh, txq_conf.tx_thresh.pthresh, txq_conf.tx_thresh.wthresh,
1549 txq_conf.tx_free_thresh, txq_conf.tx_rs_thresh, txq_conf.tx_deferred_start);
1550 retval = rte_eth_tx_queue_setup(iconf->port_id, queue_id, iconf->nb_tx_desc,
1551 (
unsigned int)iconf->socket_id, &txq_conf);
1553 SCLogError(
"%s: failed to setup TX queue %u: %s", iconf->iface, queue_id,
1554 rte_strerror(-retval));
1563 DPDKDeviceResourcesDeinit(&iconf->pkt_mempools);
1572 ConfigInit(&out_iconf);
1573 if (out_iconf == NULL) {
1574 FatalError(
"Copy interface of the interface \"%s\" is NULL", iconf->iface);
1577 retval = ConfigLoad(out_iconf, iconf->out_iface);
1579 SCLogError(
"%s: fail to load config of interface", iconf->out_iface);
1580 out_iconf->DerefFunc(out_iconf);
1584 if (iconf->nb_rx_queues != out_iconf->nb_tx_queues) {
1586 SCLogError(
"%s: configured %d RX queues but copy interface %s has %d TX queues"
1587 " - number of queues must be equal",
1588 iconf->iface, iconf->nb_rx_queues, out_iconf->iface, out_iconf->nb_tx_queues);
1589 out_iconf->DerefFunc(out_iconf);
1591 }
else if (iconf->mtu != out_iconf->mtu) {
1592 SCLogError(
"%s: configured MTU of %d but copy interface %s has MTU set to %d"
1593 " - MTU must be equal",
1594 iconf->iface, iconf->mtu, out_iconf->iface, out_iconf->mtu);
1595 out_iconf->DerefFunc(out_iconf);
1597 }
else if (iconf->copy_mode != out_iconf->copy_mode) {
1598 SCLogError(
"%s: copy modes of interfaces %s and %s are not equal", iconf->iface,
1599 iconf->iface, out_iconf->iface);
1600 out_iconf->DerefFunc(out_iconf);
1602 }
else if (strcmp(iconf->iface, out_iconf->out_iface) != 0) {
1604 SCLogError(
"%s: copy interface of %s is not set to %s", iconf->iface, out_iconf->iface,
1606 out_iconf->DerefFunc(out_iconf);
1610 out_iconf->DerefFunc(out_iconf);
1617 if (iconf->out_iface != NULL) {
1618 if (!rte_eth_dev_is_valid_port(iconf->out_port_id)) {
1619 SCLogError(
"%s: retrieved copy interface port ID \"%d\" is invalid or the device is "
1621 iconf->iface, iconf->out_port_id);
1624 int32_t out_port_socket_id;
1627 SCLogError(
"%s: invalid socket id: %s", iconf->out_iface, rte_strerror(-retval));
1631 if (iconf->socket_id != out_port_socket_id) {
1633 "%s: out iface %s is not on the same NUMA node (%s - NUMA %d, %s - NUMA %d)",
1634 iconf->iface, iconf->out_iface, iconf->iface, iconf->socket_id,
1635 iconf->out_iface, out_port_socket_id);
1638 retval = DeviceValidateOutIfaceConfig(iconf);
1645 SCLogInfo(
"%s: DPDK IPS mode activated: %s->%s", iconf->iface, iconf->iface,
1648 SCLogInfo(
"%s: DPDK TAP mode activated: %s->%s", iconf->iface, iconf->iface,
1662 static int32_t DeviceVerifyPostConfigure(
1663 const DPDKIfaceConfig *iconf,
const struct rte_eth_dev_info *dev_info)
1666 struct rte_eth_dev_info post_conf_dev_info = { 0 };
1667 int32_t ret = rte_eth_dev_info_get(iconf->port_id, &post_conf_dev_info);
1669 SCLogError(
"%s: getting device info failed: %s", iconf->iface, rte_strerror(-ret));
1673 if (dev_info->flow_type_rss_offloads != post_conf_dev_info.flow_type_rss_offloads ||
1674 dev_info->rx_offload_capa != post_conf_dev_info.rx_offload_capa ||
1675 dev_info->tx_offload_capa != post_conf_dev_info.tx_offload_capa ||
1676 dev_info->max_rx_queues != post_conf_dev_info.max_rx_queues ||
1677 dev_info->max_tx_queues != post_conf_dev_info.max_tx_queues ||
1678 dev_info->max_mtu != post_conf_dev_info.max_mtu) {
1679 SCLogWarning(
"%s: device information severely changed after configuration, reconfiguring",
1684 if (strcmp(dev_info->driver_name,
"net_bonding") == 0) {
1685 ret = BondingAllDevicesSameDriver(iconf->port_id);
1687 SCLogError(
"%s: bond port uses port with different DPDK drivers", iconf->iface);
1698 if (!rte_eth_dev_is_valid_port(iconf->port_id)) {
1699 SCLogError(
"%s: retrieved port ID \"%d\" is invalid or the device is not attached ",
1700 iconf->iface, iconf->port_id);
1706 SCLogError(
"%s: invalid socket id: %s", iconf->iface, rte_strerror(-retval));
1710 struct rte_eth_dev_info dev_info = { 0 };
1711 retval = rte_eth_dev_info_get(iconf->port_id, &dev_info);
1713 SCLogError(
"%s: getting device info failed: %s", iconf->iface, rte_strerror(-retval));
1717 if (iconf->nb_rx_queues > dev_info.max_rx_queues) {
1718 SCLogError(
"%s: configured RX queues %u is higher than device maximum (%" PRIu16
")",
1719 iconf->iface, iconf->nb_rx_queues, dev_info.max_rx_queues);
1723 if (iconf->nb_tx_queues > dev_info.max_tx_queues) {
1724 SCLogError(
"%s: configured TX queues %u is higher than device maximum (%" PRIu16
")",
1725 iconf->iface, iconf->nb_tx_queues, dev_info.max_tx_queues);
1729 retval = DeviceValidateMTU(iconf, &dev_info);
1733 struct rte_eth_conf port_conf = { 0 };
1734 DeviceInitPortConf(iconf, &dev_info, &port_conf);
1735 if (port_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM) {
1740 retval = rte_eth_dev_configure(
1741 iconf->port_id, iconf->nb_rx_queues, iconf->nb_tx_queues, &port_conf);
1743 SCLogError(
"%s: failed to configure the device: %s", iconf->iface, rte_strerror(-retval));
1747 retval = DeviceVerifyPostConfigure(iconf, &dev_info);
1751 uint16_t tmp_nb_rx_desc = iconf->nb_rx_desc;
1752 uint16_t tmp_nb_tx_desc = iconf->nb_tx_desc;
1753 retval = rte_eth_dev_adjust_nb_rx_tx_desc(
1754 iconf->port_id, &iconf->nb_rx_desc, &iconf->nb_tx_desc);
1756 SCLogError(
"%s: failed to adjust device queue descriptors: %s", iconf->iface,
1757 rte_strerror(-retval));
1759 }
else if (tmp_nb_rx_desc != iconf->nb_rx_desc || tmp_nb_tx_desc != iconf->nb_tx_desc) {
1760 SCLogWarning(
"%s: device queue descriptors adjusted (RX: from %u to %u, TX: from %u to %u)",
1761 iconf->iface, tmp_nb_rx_desc, iconf->nb_rx_desc, tmp_nb_tx_desc, iconf->nb_tx_desc);
1764 retval = iconf->flags &
DPDK_MULTICAST ? rte_eth_allmulticast_enable(iconf->port_id)
1765 : rte_eth_allmulticast_disable(iconf->port_id);
1766 if (retval == -ENOTSUP) {
1767 retval = rte_eth_allmulticast_get(iconf->port_id);
1771 SCLogWarning(
"%s: cannot configure allmulticast, the port is %sin allmulticast mode",
1772 iconf->iface, retval == 1 ?
"" :
"not ");
1773 }
else if (retval < 0) {
1774 SCLogError(
"%s: failed to get multicast mode: %s", iconf->iface, rte_strerror(-retval));
1777 }
else if (retval < 0) {
1778 SCLogError(
"%s: error when changing multicast setting: %s", iconf->iface,
1779 rte_strerror(-retval));
1783 retval = iconf->flags &
DPDK_PROMISC ? rte_eth_promiscuous_enable(iconf->port_id)
1784 : rte_eth_promiscuous_disable(iconf->port_id);
1785 if (retval == -ENOTSUP) {
1786 retval = rte_eth_promiscuous_get(iconf->port_id);
1789 SCLogError(
"%s: cannot configure promiscuous mode, the port is in %spromiscuous mode",
1790 iconf->iface, retval == 1 ?
"" :
"non-");
1792 }
else if (retval < 0) {
1794 "%s: failed to get promiscuous mode: %s", iconf->iface, rte_strerror(-retval));
1797 }
else if (retval < 0) {
1798 SCLogError(
"%s: error when changing promiscuous setting: %s", iconf->iface,
1799 rte_strerror(-retval));
1804 SCLogConfig(
"%s: setting MTU to %d", iconf->iface, iconf->mtu);
1805 retval = rte_eth_dev_set_mtu(iconf->port_id, iconf->mtu);
1806 if (retval == -ENOTSUP) {
1808 retval = rte_eth_dev_get_mtu(iconf->port_id, &iconf->mtu);
1810 SCLogError(
"%s: failed to retrieve MTU: %s", iconf->iface, rte_strerror(-retval));
1814 "%s: changing MTU is not supported, current MTU: %u", iconf->iface, iconf->mtu);
1815 }
else if (retval < 0) {
1817 "%s: failed to set MTU to %u: %s", iconf->iface, iconf->mtu, rte_strerror(-retval));
1821 retval = DeviceConfigureQueues(iconf, &dev_info, &port_conf);
1826 retval = DeviceConfigureIPS(iconf);
1834 static void *ParseDpdkConfigAndConfigureDevice(
const char *iface)
1838 if (iconf == NULL) {
1839 FatalError(
"DPDK configuration could not be parsed");
1842 retval = DeviceConfigure(iconf);
1843 if (retval == -EAGAIN) {
1845 retval = DeviceConfigure(iconf);
1849 iconf->DerefFunc(iconf);
1850 if (rte_eal_cleanup() != 0)
1851 FatalError(
"EAL cleanup failed: %s", rte_strerror(-retval));
1853 if (retval == -ENOMEM) {
1854 FatalError(
"%s: memory allocation failed - consider"
1855 "%s freeing up some memory.",
1857 rte_eal_has_hugepages() != 0 ?
" increasing the number of hugepages or" :
"");
1859 FatalError(
"%s: failed to configure", iface);
1868 iconf->workers_sync =
SCCalloc(1,
sizeof(*iconf->workers_sync));
1869 if (iconf->workers_sync == NULL) {
1870 FatalError(
"Failed to allocate memory for workers_sync");
1873 iconf->workers_sync->worker_cnt = iconf->threads;
1877 if (ldev_instance == NULL) {
1878 FatalError(
"Device %s is not registered as a live device", iface);
1880 ldev_instance->dpdk_vars = iconf->pkt_mempools;
1881 iconf->pkt_mempools = NULL;
1898 static uint16_t DPDKConfigGetThreadsCount(
void *conf)
1904 return dpdk_conf->threads;
1909 static int DPDKRunModeIsIPS(
void)
1912 const char dpdk_node_query[] =
"dpdk.interfaces";
1914 if (dpdk_node == NULL) {
1915 FatalError(
"Unable to get %s configuration node", dpdk_node_query);
1918 const char default_iface[] =
"default";
1921 bool has_ips =
false;
1922 bool has_ids =
false;
1923 for (
int ldev = 0; ldev < nlive; ldev++) {
1925 if (live_dev == NULL)
1926 FatalError(
"Unable to get device id %d from LiveDevice list", ldev);
1929 if (if_root == NULL) {
1930 if (if_default == NULL)
1931 FatalError(
"Unable to get %s or %s interface", live_dev, default_iface);
1933 if_root = if_default;
1936 const char *copymodestr = NULL;
1937 const char *copyifacestr = NULL;
1940 if (strcmp(copymodestr,
"ips") == 0) {
1949 if (has_ids && has_ips) {
1950 FatalError(
"Copy-mode of interface %s mixes with the previously set copy-modes "
1951 "(only IDS/TAP and IPS copy-mode combinations are allowed in DPDK",
1959 static int DPDKRunModeEnableIPS(
void)
1961 int r = DPDKRunModeIsIPS();
1977 "Workers DPDK mode, each thread does all"
1978 " tasks from acquisition to logging",
2003 SCLogDebug(
"RunModeIdsDpdkWorkers initialised");