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 MempoolSizeCalculate(
536 uint32_t sz = iconf->nb_rx_queues * iconf->nb_rx_desc + iconf->nb_tx_queues * iconf->nb_tx_desc;
537 if (!iconf->nb_tx_queues || !iconf->nb_tx_desc)
540 if (dev_info != NULL) {
541 if (strcmp(dev_info->driver_name,
"net_bonding") == 0) {
542 sz = BondingMempoolSizeCalculate(iconf->port_id, dev_info, sz);
549 static int ConfigSetMempoolSize(
550 DPDKIfaceConfig *iconf,
const char *entry_str,
const struct rte_eth_dev_info *dev_info)
553 if (entry_str == NULL || entry_str[0] ==
'\0' || strcmp(entry_str,
"auto") == 0) {
558 if (iconf->nb_rx_queues == 0) {
560 SCLogError(
"%s: cannot autocalculate mempool size without RX queues", iconf->iface);
564 if (iconf->nb_rx_desc == 0) {
566 "%s: cannot autocalculate mempool size without RX descriptors", iconf->iface);
574 iconf->mempool_size = MempoolSizeCalculate(iconf, dev_info);
579 SCLogError(
"%s: mempool size entry contain non-numerical characters - \"%s\"", iconf->iface,
584 uint32_t required_mp_size = MempoolSizeCalculate(iconf, dev_info);
585 if (required_mp_size >
586 iconf->mempool_size + 1) {
588 SCLogError(
"%s: mempool size is likely too small for the number of descriptors and queues, "
589 "set to \"auto\" or adjust to the value of \"%" PRIu32
"\"",
590 iconf->iface, required_mp_size);
594 if (iconf->mempool_size == 0) {
595 SCLogError(
"%s: mempool size requires a positive integer", iconf->iface);
602 static uint32_t MempoolCacheSizeCalculate(uint32_t mp_sz)
607 uint32_t max_cache_size =
MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, (uint32_t)(mp_sz / 1.5));
608 return GreatestDivisorUpTo(mp_sz, max_cache_size);
611 static int ConfigSetMempoolCacheSize(
DPDKIfaceConfig *iconf,
const char *entry_str)
614 if (entry_str == NULL || entry_str[0] ==
'\0' || strcmp(entry_str,
"auto") == 0) {
616 if (iconf->mempool_size == 0) {
617 SCLogError(
"%s: cannot calculate mempool cache size of a mempool with size %d",
618 iconf->iface, iconf->mempool_size);
622 iconf->mempool_cache_size_auto =
true;
626 iconf->mempool_cache_size_auto =
false;
628 SCLogError(
"%s: mempool cache size entry contain non-numerical characters - \"%s\"",
629 iconf->iface, entry_str);
633 if (iconf->mempool_cache_size <= 0 || iconf->mempool_cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE) {
634 SCLogError(
"%s: mempool cache size requires a positive number smaller than %" PRIu32,
635 iconf->iface, RTE_MEMPOOL_CACHE_MAX_SIZE);
642 static int ConfigSetRxDescriptors(
DPDKIfaceConfig *iconf,
const char *entry_str, uint16_t max_desc)
645 if (entry_str == NULL || entry_str[0] ==
'\0') {
646 SCLogInfo(
"%s: number of RX descriptors not found, going with: %s", iconf->iface,
647 DPDK_CONFIG_DEFAULT_RX_DESCRIPTORS);
648 entry_str = DPDK_CONFIG_DEFAULT_RX_DESCRIPTORS;
651 if (strcmp(entry_str,
"auto") == 0) {
652 iconf->nb_rx_desc = (uint16_t)GreatestPowOf2UpTo(max_desc);
657 SCLogError(
"%s: RX descriptors entry contains non-numerical characters - \"%s\"",
658 iconf->iface, entry_str);
662 if (iconf->nb_rx_desc == 0) {
663 SCLogError(
"%s: positive number of RX descriptors is required", iconf->iface);
665 }
else if (iconf->nb_rx_desc > max_desc) {
666 SCLogError(
"%s: number of RX descriptors cannot exceed %" PRIu16, iconf->iface, max_desc);
673 static int ConfigSetTxDescriptors(
674 DPDKIfaceConfig *iconf,
const char *entry_str, uint16_t max_desc,
bool iface_sends_pkts)
677 if (entry_str == NULL || entry_str[0] ==
'\0') {
678 SCLogInfo(
"%s: number of TX descriptors not found, going with: %s", iconf->iface,
679 DPDK_CONFIG_DEFAULT_TX_DESCRIPTORS);
680 entry_str = DPDK_CONFIG_DEFAULT_TX_DESCRIPTORS;
683 if (strcmp(entry_str,
"auto") == 0) {
684 if (iface_sends_pkts) {
685 iconf->nb_tx_desc = (uint16_t)GreatestPowOf2UpTo(max_desc);
687 iconf->nb_tx_desc = 0;
693 SCLogError(
"%s: TX descriptors entry contains non-numerical characters - \"%s\"",
694 iconf->iface, entry_str);
698 if (iconf->nb_tx_desc == 0 && iface_sends_pkts) {
699 SCLogError(
"%s: positive number of TX descriptors is required", iconf->iface);
701 }
else if (iconf->nb_tx_desc > max_desc) {
702 SCLogError(
"%s: number of TX descriptors cannot exceed %" PRIu16, iconf->iface, max_desc);
709 static int ConfigSetRSSHashFunctions(
DPDKIfaceConfig *iconf,
const char *entry_str)
712 if (entry_str == NULL || entry_str[0] ==
'\0' || strcmp(entry_str,
"auto") == 0) {
713 iconf->rss_hf = DPDK_CONFIG_DEFAULT_RSS_HASH_FUNCTIONS;
718 SCLogError(
"%s: RSS hash functions entry contain non-numerical characters - \"%s\"",
719 iconf->iface, entry_str);
729 if (entry_int < RTE_ETHER_MIN_MTU || entry_int > RTE_ETHER_MAX_JUMBO_FRAME_LEN) {
730 SCLogError(
"%s: MTU size can only be between %" PRIu32
" and %" PRIu32, iconf->iface,
731 RTE_ETHER_MIN_MTU, RTE_ETHER_MAX_JUMBO_FRAME_LEN);
735 iconf->mtu = (uint16_t)entry_int;
739 static int ConfigSetLinkupTimeout(
DPDKIfaceConfig *iconf, intmax_t entry_int)
742 if (entry_int < 0 || entry_int > UINT16_MAX) {
743 SCLogError(
"%s: Link-up waiting timeout needs to be a positive number (up to %u) or 0 to "
745 iconf->iface, UINT16_MAX);
749 iconf->linkup_timeout = (uint16_t)entry_int;
753 static bool ConfigSetPromiscuousMode(
DPDKIfaceConfig *iconf,
int entry_bool)
771 static int ConfigSetChecksumChecks(
DPDKIfaceConfig *iconf,
int entry_bool)
780 static int ConfigSetChecksumOffload(
DPDKIfaceConfig *iconf,
int entry_bool)
792 iconf->vlan_strip_enabled = entry_bool;
796 static int ConfigSetCopyIface(
DPDKIfaceConfig *iconf,
const char *entry_str)
801 if (entry_str == NULL || entry_str[0] ==
'\0' || strcmp(entry_str,
"none") == 0) {
802 iconf->out_iface = NULL;
806 retval = rte_eth_dev_get_port_by_name(entry_str, &iconf->out_port_id);
808 SCLogError(
"%s: copy interface (%s) not found: %s", iconf->iface, entry_str,
809 rte_strerror(-retval));
813 iconf->out_iface = entry_str;
817 static int ConfigSetCopyMode(
DPDKIfaceConfig *iconf,
const char *entry_str)
820 if (entry_str == NULL) {
821 SCLogWarning(
"%s: no copy mode specified, changing to %s ", iconf->iface,
822 DPDK_CONFIG_DEFAULT_COPY_MODE);
823 entry_str = DPDK_CONFIG_DEFAULT_COPY_MODE;
826 if (strcmp(entry_str,
"none") != 0 && strcmp(entry_str,
"tap") != 0 &&
827 strcmp(entry_str,
"ips") != 0) {
828 SCLogWarning(
"%s: copy mode \"%s\" is not one of the possible values (none|tap|ips). "
830 entry_str, iconf->iface, DPDK_CONFIG_DEFAULT_COPY_MODE);
831 entry_str = DPDK_CONFIG_DEFAULT_COPY_MODE;
834 if (strcmp(entry_str,
"none") == 0) {
836 }
else if (strcmp(entry_str,
"tap") == 0) {
838 }
else if (strcmp(entry_str,
"ips") == 0) {
845 static int ConfigSetCopyIfaceSettings(
DPDKIfaceConfig *iconf,
const char *iface,
const char *mode)
850 retval = ConfigSetCopyIface(iconf, iface);
854 retval = ConfigSetCopyMode(iconf, mode);
859 if (iconf->out_iface != NULL)
860 iconf->out_iface = NULL;
864 if (iconf->out_iface == NULL || strlen(iconf->out_iface) <= 0) {
865 SCLogError(
"%s: copy mode enabled but interface not set", iconf->iface);
878 const char *entry_str = NULL;
879 intmax_t entry_int = 0;
881 const char *copy_iface_str = NULL;
882 const char *copy_mode_str = NULL;
884 ConfigSetIface(iconf, iface);
885 struct rte_eth_dev_info dev_info = { 0 };
886 retval = rte_eth_dev_info_get(iconf->port_id, &dev_info);
888 SCLogError(
"%s: getting device info failed: %s", iconf->iface, rte_strerror(-retval));
894 FatalError(
"failed to find DPDK configuration for the interface %s", iconf->iface);
898 ? ConfigSetThreads(iconf, DPDK_CONFIG_DEFAULT_THREADS)
899 : ConfigSetThreads(iconf, entry_str);
905 if_root, if_default, dpdk_yaml.
irq_mode, &entry_bool);
907 irq_enable = DPDK_CONFIG_DEFAULT_INTERRUPT_MODE;
909 irq_enable = entry_bool ? true :
false;
911 retval = ConfigSetInterruptMode(iconf, irq_enable);
916 if_root, if_default, dpdk_yaml.
copy_mode, ©_mode_str);
918 copy_mode_str = DPDK_CONFIG_DEFAULT_COPY_MODE;
923 ? ConfigSetRxDescriptors(iconf, DPDK_CONFIG_DEFAULT_RX_DESCRIPTORS,
924 dev_info.rx_desc_lim.nb_max)
925 : ConfigSetRxDescriptors(iconf, entry_str, dev_info.rx_desc_lim.nb_max);
929 bool iface_sends_pkts = ConfigIfaceSendsPkts(copy_mode_str);
932 ? ConfigSetTxDescriptors(iconf, DPDK_CONFIG_DEFAULT_TX_DESCRIPTORS,
933 dev_info.tx_desc_lim.nb_max, iface_sends_pkts)
934 : ConfigSetTxDescriptors(
935 iconf, entry_str, dev_info.tx_desc_lim.nb_max, iface_sends_pkts);
940 retval = ConfigSetRxQueues(iconf, iconf->threads, dev_info.max_rx_queues);
942 SCLogError(
"%s: too many threads configured - reduce thread count to: %" PRIu16,
943 iconf->iface, dev_info.max_rx_queues);
948 uint16_t tx_queues = iconf->nb_tx_desc > 0 ? iconf->threads : 0;
949 retval = ConfigSetTxQueues(iconf, tx_queues, dev_info.max_tx_queues, iface_sends_pkts);
951 SCLogError(
"%s: too many threads configured - reduce thread count to: %" PRIu16,
952 iconf->iface, dev_info.max_tx_queues);
957 if_root, if_default, dpdk_yaml.
mempool_size, &entry_str) != 1
958 ? ConfigSetMempoolSize(iconf, DPDK_CONFIG_DEFAULT_MEMPOOL_SIZE, &dev_info)
959 : ConfigSetMempoolSize(iconf, entry_str, &dev_info);
965 ? ConfigSetMempoolCacheSize(iconf, DPDK_CONFIG_DEFAULT_MEMPOOL_CACHE_SIZE)
966 : ConfigSetMempoolCacheSize(iconf, entry_str);
971 ? ConfigSetMtu(iconf, DPDK_CONFIG_DEFAULT_MTU)
972 : ConfigSetMtu(iconf, entry_int);
977 ? ConfigSetRSSHashFunctions(iconf, NULL)
978 : ConfigSetRSSHashFunctions(iconf, entry_str);
983 if_root, if_default, dpdk_yaml.
promisc, &entry_bool) != 1
984 ? ConfigSetPromiscuousMode(iconf, DPDK_CONFIG_DEFAULT_PROMISCUOUS_MODE)
985 : ConfigSetPromiscuousMode(iconf, entry_bool);
990 if_root, if_default, dpdk_yaml.
multicast, &entry_bool) != 1
991 ? ConfigSetMulticast(iconf, DPDK_CONFIG_DEFAULT_MULTICAST_MODE)
992 : ConfigSetMulticast(iconf, entry_bool);
998 ? ConfigSetChecksumChecks(iconf, DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION)
999 : ConfigSetChecksumChecks(iconf, entry_bool);
1005 ? ConfigSetChecksumOffload(
1006 iconf, DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION_OFFLOAD)
1007 : ConfigSetChecksumOffload(iconf, entry_bool);
1014 ConfigSetVlanStrip(iconf, DPDK_CONFIG_DEFAULT_VLAN_STRIP);
1016 ConfigSetVlanStrip(iconf, entry_bool);
1021 ? ConfigSetLinkupTimeout(iconf, DPDK_CONFIG_DEFAULT_LINKUP_TIMEOUT)
1022 : ConfigSetLinkupTimeout(iconf, entry_int);
1027 if_root, if_default, dpdk_yaml.
copy_iface, ©_iface_str);
1029 copy_iface_str = DPDK_CONFIG_DEFAULT_COPY_INTERFACE;
1032 retval = ConfigSetCopyIfaceSettings(iconf, copy_iface_str, copy_mode_str);
1039 static bool ConfigThreadsGenericIsValid(uint16_t iface_threads,
ThreadsAffinityType *wtaf)
1041 static uint32_t total_cpus = 0;
1042 total_cpus += iface_threads;
1044 SCLogError(
"Specify worker-cpu-set list in the threading section");
1048 SCLogError(
"Interfaces requested more cores than configured in the worker-cpu-set "
1049 "threading section (requested %d configured %d",
1057 static bool ConfigThreadsInterfaceIsValid(uint16_t iface_threads,
ThreadsAffinityType *itaf)
1060 SCLogError(
"Interface requested more cores than configured in the interface-specific "
1061 "threading section (requested %d configured %d",
1069 static bool ConfigIsThreadingValid(uint16_t iface_threads,
const char *iface)
1073 if (itaf && !ConfigThreadsInterfaceIsValid(iface_threads, itaf)) {
1075 }
else if (itaf == NULL && !ConfigThreadsGenericIsValid(iface_threads, wtaf)) {
1090 retval = ConfigLoad(iconf, iface);
1091 if (retval < 0 || !ConfigIsThreadingValid(iconf->threads, iface)) {
1092 iconf->DerefFunc(iconf);
1099 static void DeviceSetPMDSpecificRSS(
struct rte_eth_rss_conf *rss_conf,
const char *driver_name)
1101 if (strcmp(driver_name,
"net_i40e") == 0)
1102 i40eDeviceSetRSSConf(rss_conf);
1103 if (strcmp(driver_name,
"net_ice") == 0)
1104 iceDeviceSetRSSConf(rss_conf);
1105 if (strcmp(driver_name,
"net_ixgbe") == 0)
1106 ixgbeDeviceSetRSSHashFunction(&rss_conf->rss_hf);
1107 if (strcmp(driver_name,
"net_e1000_igb") == 0)
1108 rss_conf->rss_hf = (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_IPV6_EX);
1112 static int32_t GetFirstSetBitPosition(uint64_t bits)
1114 for (int32_t i = 0; i < 64; i++) {
1121 static void DumpRSSFlags(
const uint64_t requested,
const uint64_t actual)
1126 "RTE_ETH_RSS_IP %sset", ((requested & RTE_ETH_RSS_IP) == RTE_ETH_RSS_IP) ?
"" :
"NOT ");
1128 ((requested & RTE_ETH_RSS_TCP) == RTE_ETH_RSS_TCP) ?
"" :
"NOT ");
1130 ((requested & RTE_ETH_RSS_UDP) == RTE_ETH_RSS_UDP) ?
"" :
"NOT ");
1132 ((requested & RTE_ETH_RSS_SCTP) == RTE_ETH_RSS_SCTP) ?
"" :
"NOT ");
1134 ((requested & RTE_ETH_RSS_TUNNEL) == RTE_ETH_RSS_TUNNEL) ?
"" :
"NOT ");
1137 SCLogConfig(
"RTE_ETH_RSS_IPV4 (Bit position: %d) %sset",
1138 GetFirstSetBitPosition(RTE_ETH_RSS_IPV4), (requested & RTE_ETH_RSS_IPV4) ?
"" :
"NOT ");
1139 SCLogConfig(
"RTE_ETH_RSS_FRAG_IPV4 (Bit position: %d) %sset",
1140 GetFirstSetBitPosition(RTE_ETH_RSS_FRAG_IPV4),
1141 (requested & RTE_ETH_RSS_FRAG_IPV4) ?
"" :
"NOT ");
1142 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_TCP (Bit position: %d) %sset",
1143 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_TCP),
1144 (requested & RTE_ETH_RSS_NONFRAG_IPV4_TCP) ?
"" :
"NOT ");
1145 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_UDP (Bit position: %d) %sset",
1146 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_UDP),
1147 (requested & RTE_ETH_RSS_NONFRAG_IPV4_UDP) ?
"" :
"NOT ");
1148 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_SCTP (Bit position: %d) %sset",
1149 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_SCTP),
1150 (requested & RTE_ETH_RSS_NONFRAG_IPV4_SCTP) ?
"" :
"NOT ");
1151 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_OTHER (Bit position: %d) %sset",
1152 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_OTHER),
1153 (requested & RTE_ETH_RSS_NONFRAG_IPV4_OTHER) ?
"" :
"NOT ");
1154 SCLogConfig(
"RTE_ETH_RSS_IPV6 (Bit position: %d) %sset",
1155 GetFirstSetBitPosition(RTE_ETH_RSS_IPV6), (requested & RTE_ETH_RSS_IPV6) ?
"" :
"NOT ");
1156 SCLogConfig(
"RTE_ETH_RSS_FRAG_IPV6 (Bit position: %d) %sset",
1157 GetFirstSetBitPosition(RTE_ETH_RSS_FRAG_IPV6),
1158 (requested & RTE_ETH_RSS_FRAG_IPV6) ?
"" :
"NOT ");
1159 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_TCP (Bit position: %d) %sset",
1160 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_TCP),
1161 (requested & RTE_ETH_RSS_NONFRAG_IPV6_TCP) ?
"" :
"NOT ");
1162 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_UDP (Bit position: %d) %sset",
1163 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_UDP),
1164 (requested & RTE_ETH_RSS_NONFRAG_IPV6_UDP) ?
"" :
"NOT ");
1165 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_SCTP (Bit position: %d) %sset",
1166 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_SCTP),
1167 (requested & RTE_ETH_RSS_NONFRAG_IPV6_SCTP) ?
"" :
"NOT ");
1168 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_OTHER (Bit position: %d) %sset",
1169 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_OTHER),
1170 (requested & RTE_ETH_RSS_NONFRAG_IPV6_OTHER) ?
"" :
"NOT ");
1172 SCLogConfig(
"RTE_ETH_RSS_L2_PAYLOAD (Bit position: %d) %sset",
1173 GetFirstSetBitPosition(RTE_ETH_RSS_L2_PAYLOAD),
1174 (requested & RTE_ETH_RSS_L2_PAYLOAD) ?
"" :
"NOT ");
1175 SCLogConfig(
"RTE_ETH_RSS_IPV6_EX (Bit position: %d) %sset",
1176 GetFirstSetBitPosition(RTE_ETH_RSS_IPV6_EX),
1177 (requested & RTE_ETH_RSS_IPV6_EX) ?
"" :
"NOT ");
1178 SCLogConfig(
"RTE_ETH_RSS_IPV6_TCP_EX (Bit position: %d) %sset",
1179 GetFirstSetBitPosition(RTE_ETH_RSS_IPV6_TCP_EX),
1180 (requested & RTE_ETH_RSS_IPV6_TCP_EX) ?
"" :
"NOT ");
1181 SCLogConfig(
"RTE_ETH_RSS_IPV6_UDP_EX (Bit position: %d) %sset",
1182 GetFirstSetBitPosition(RTE_ETH_RSS_IPV6_UDP_EX),
1183 (requested & RTE_ETH_RSS_IPV6_UDP_EX) ?
"" :
"NOT ");
1185 SCLogConfig(
"RTE_ETH_RSS_PORT (Bit position: %d) %sset",
1186 GetFirstSetBitPosition(RTE_ETH_RSS_PORT), (requested & RTE_ETH_RSS_PORT) ?
"" :
"NOT ");
1187 SCLogConfig(
"RTE_ETH_RSS_VXLAN (Bit position: %d) %sset",
1188 GetFirstSetBitPosition(RTE_ETH_RSS_VXLAN),
1189 (requested & RTE_ETH_RSS_VXLAN) ?
"" :
"NOT ");
1190 SCLogConfig(
"RTE_ETH_RSS_NVGRE (Bit position: %d) %sset",
1191 GetFirstSetBitPosition(RTE_ETH_RSS_NVGRE),
1192 (requested & RTE_ETH_RSS_NVGRE) ?
"" :
"NOT ");
1193 SCLogConfig(
"RTE_ETH_RSS_GTPU (Bit position: %d) %sset",
1194 GetFirstSetBitPosition(RTE_ETH_RSS_GTPU), (requested & RTE_ETH_RSS_GTPU) ?
"" :
"NOT ");
1196 SCLogConfig(
"RTE_ETH_RSS_L3_SRC_ONLY (Bit position: %d) %sset",
1197 GetFirstSetBitPosition(RTE_ETH_RSS_L3_SRC_ONLY),
1198 (requested & RTE_ETH_RSS_L3_SRC_ONLY) ?
"" :
"NOT ");
1199 SCLogConfig(
"RTE_ETH_RSS_L3_DST_ONLY (Bit position: %d) %sset",
1200 GetFirstSetBitPosition(RTE_ETH_RSS_L3_DST_ONLY),
1201 (requested & RTE_ETH_RSS_L3_DST_ONLY) ?
"" :
"NOT ");
1202 SCLogConfig(
"RTE_ETH_RSS_L4_SRC_ONLY (Bit position: %d) %sset",
1203 GetFirstSetBitPosition(RTE_ETH_RSS_L4_SRC_ONLY),
1204 (requested & RTE_ETH_RSS_L4_SRC_ONLY) ?
"" :
"NOT ");
1205 SCLogConfig(
"RTE_ETH_RSS_L4_DST_ONLY (Bit position: %d) %sset",
1206 GetFirstSetBitPosition(RTE_ETH_RSS_L4_DST_ONLY),
1207 (requested & RTE_ETH_RSS_L4_DST_ONLY) ?
"" :
"NOT ");
1210 "RTE_ETH_RSS_IP %sset", ((actual & RTE_ETH_RSS_IP) == RTE_ETH_RSS_IP) ?
"" :
"NOT ");
1212 "RTE_ETH_RSS_TCP %sset", ((actual & RTE_ETH_RSS_TCP) == RTE_ETH_RSS_TCP) ?
"" :
"NOT ");
1214 "RTE_ETH_RSS_UDP %sset", ((actual & RTE_ETH_RSS_UDP) == RTE_ETH_RSS_UDP) ?
"" :
"NOT ");
1216 ((actual & RTE_ETH_RSS_SCTP) == RTE_ETH_RSS_SCTP) ?
"" :
"NOT ");
1218 ((actual & RTE_ETH_RSS_TUNNEL) == RTE_ETH_RSS_TUNNEL) ?
"" :
"NOT ");
1221 SCLogConfig(
"RTE_ETH_RSS_IPV4 %sset", (actual & RTE_ETH_RSS_IPV4) ?
"" :
"NOT ");
1222 SCLogConfig(
"RTE_ETH_RSS_FRAG_IPV4 %sset", (actual & RTE_ETH_RSS_FRAG_IPV4) ?
"" :
"NOT ");
1224 (actual & RTE_ETH_RSS_NONFRAG_IPV4_TCP) ?
"" :
"NOT ");
1226 (actual & RTE_ETH_RSS_NONFRAG_IPV4_UDP) ?
"" :
"NOT ");
1227 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_SCTP %sset",
1228 (actual & RTE_ETH_RSS_NONFRAG_IPV4_SCTP) ?
"" :
"NOT ");
1229 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_OTHER %sset",
1230 (actual & RTE_ETH_RSS_NONFRAG_IPV4_OTHER) ?
"" :
"NOT ");
1231 SCLogConfig(
"RTE_ETH_RSS_IPV6 %sset", (actual & RTE_ETH_RSS_IPV6) ?
"" :
"NOT ");
1232 SCLogConfig(
"RTE_ETH_RSS_FRAG_IPV6 %sset", (actual & RTE_ETH_RSS_FRAG_IPV6) ?
"" :
"NOT ");
1234 (actual & RTE_ETH_RSS_NONFRAG_IPV6_TCP) ?
"" :
"NOT ");
1236 (actual & RTE_ETH_RSS_NONFRAG_IPV6_UDP) ?
"" :
"NOT ");
1237 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_SCTP %sset",
1238 (actual & RTE_ETH_RSS_NONFRAG_IPV6_SCTP) ?
"" :
"NOT ");
1239 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_OTHER %sset",
1240 (actual & RTE_ETH_RSS_NONFRAG_IPV6_OTHER) ?
"" :
"NOT ");
1242 SCLogConfig(
"RTE_ETH_RSS_L2_PAYLOAD %sset", (actual & RTE_ETH_RSS_L2_PAYLOAD) ?
"" :
"NOT ");
1243 SCLogConfig(
"RTE_ETH_RSS_IPV6_EX %sset", (actual & RTE_ETH_RSS_IPV6_EX) ?
"" :
"NOT ");
1244 SCLogConfig(
"RTE_ETH_RSS_IPV6_TCP_EX %sset", (actual & RTE_ETH_RSS_IPV6_TCP_EX) ?
"" :
"NOT ");
1245 SCLogConfig(
"RTE_ETH_RSS_IPV6_UDP_EX %sset", (actual & RTE_ETH_RSS_IPV6_UDP_EX) ?
"" :
"NOT ");
1247 SCLogConfig(
"RTE_ETH_RSS_PORT %sset", (actual & RTE_ETH_RSS_PORT) ?
"" :
"NOT ");
1248 SCLogConfig(
"RTE_ETH_RSS_VXLAN %sset", (actual & RTE_ETH_RSS_VXLAN) ?
"" :
"NOT ");
1249 SCLogConfig(
"RTE_ETH_RSS_NVGRE %sset", (actual & RTE_ETH_RSS_NVGRE) ?
"" :
"NOT ");
1250 SCLogConfig(
"RTE_ETH_RSS_GTPU %sset", (actual & RTE_ETH_RSS_GTPU) ?
"" :
"NOT ");
1252 SCLogConfig(
"RTE_ETH_RSS_L3_SRC_ONLY %sset", (actual & RTE_ETH_RSS_L3_SRC_ONLY) ?
"" :
"NOT ");
1253 SCLogConfig(
"RTE_ETH_RSS_L3_DST_ONLY %sset", (actual & RTE_ETH_RSS_L3_DST_ONLY) ?
"" :
"NOT ");
1254 SCLogConfig(
"RTE_ETH_RSS_L4_SRC_ONLY %sset", (actual & RTE_ETH_RSS_L4_SRC_ONLY) ?
"" :
"NOT ");
1255 SCLogConfig(
"RTE_ETH_RSS_L4_DST_ONLY %sset", (actual & RTE_ETH_RSS_L4_DST_ONLY) ?
"" :
"NOT ");
1258 static void DumpRXOffloadCapabilities(
const uint64_t rx_offld_capa)
1260 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_VLAN_STRIP - %savailable",
1261 rx_offld_capa & RTE_ETH_RX_OFFLOAD_VLAN_STRIP ?
"" :
"NOT ");
1262 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_IPV4_CKSUM - %savailable",
1263 rx_offld_capa & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM ?
"" :
"NOT ");
1264 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_UDP_CKSUM - %savailable",
1265 rx_offld_capa & RTE_ETH_RX_OFFLOAD_UDP_CKSUM ?
"" :
"NOT ");
1266 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_TCP_CKSUM - %savailable",
1267 rx_offld_capa & RTE_ETH_RX_OFFLOAD_TCP_CKSUM ?
"" :
"NOT ");
1268 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_TCP_LRO - %savailable",
1269 rx_offld_capa & RTE_ETH_RX_OFFLOAD_TCP_LRO ?
"" :
"NOT ");
1270 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_QINQ_STRIP - %savailable",
1271 rx_offld_capa & RTE_ETH_RX_OFFLOAD_QINQ_STRIP ?
"" :
"NOT ");
1272 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM - %savailable",
1273 rx_offld_capa & RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM ?
"" :
"NOT ");
1274 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_MACSEC_STRIP - %savailable",
1275 rx_offld_capa & RTE_ETH_RX_OFFLOAD_MACSEC_STRIP ?
"" :
"NOT ");
1276 #if RTE_VERSION < RTE_VERSION_NUM(22, 11, 0, 0)
1277 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_HEADER_SPLIT - %savailable",
1278 rx_offld_capa & RTE_ETH_RX_OFFLOAD_HEADER_SPLIT ?
"" :
"NOT ");
1280 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_VLAN_FILTER - %savailable",
1281 rx_offld_capa & RTE_ETH_RX_OFFLOAD_VLAN_FILTER ?
"" :
"NOT ");
1282 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_VLAN_EXTEND - %savailable",
1283 rx_offld_capa & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND ?
"" :
"NOT ");
1284 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_SCATTER - %savailable",
1285 rx_offld_capa & RTE_ETH_RX_OFFLOAD_SCATTER ?
"" :
"NOT ");
1286 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_TIMESTAMP - %savailable",
1287 rx_offld_capa & RTE_ETH_RX_OFFLOAD_TIMESTAMP ?
"" :
"NOT ");
1288 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_SECURITY - %savailable",
1289 rx_offld_capa & RTE_ETH_RX_OFFLOAD_SECURITY ?
"" :
"NOT ");
1290 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_KEEP_CRC - %savailable",
1291 rx_offld_capa & RTE_ETH_RX_OFFLOAD_KEEP_CRC ?
"" :
"NOT ");
1292 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_SCTP_CKSUM - %savailable",
1293 rx_offld_capa & RTE_ETH_RX_OFFLOAD_SCTP_CKSUM ?
"" :
"NOT ");
1294 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM - %savailable",
1295 rx_offld_capa & RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM ?
"" :
"NOT ");
1296 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_RSS_HASH - %savailable",
1297 rx_offld_capa & RTE_ETH_RX_OFFLOAD_RSS_HASH ?
"" :
"NOT ");
1298 #if RTE_VERSION >= RTE_VERSION_NUM(20, 11, 0, 0)
1299 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT - %savailable",
1300 rx_offld_capa & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT ?
"" :
"NOT ");
1304 static int DeviceValidateMTU(
const DPDKIfaceConfig *iconf,
const struct rte_eth_dev_info *dev_info)
1307 if (iconf->mtu > dev_info->max_mtu || iconf->mtu < dev_info->min_mtu) {
1309 "Min MTU: %" PRIu16
" Max MTU: %" PRIu16,
1310 iconf->iface, dev_info->min_mtu, dev_info->max_mtu);
1314 #if RTE_VERSION < RTE_VERSION_NUM(21, 11, 0, 0)
1316 if (iconf->mtu > RTE_ETHER_MAX_LEN &&
1317 !(dev_info->rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME)) {
1318 SCLogError(
"%s: jumbo frames not supported, set MTU to 1500", iconf->iface);
1326 static void DeviceSetMTU(
struct rte_eth_conf *port_conf, uint16_t mtu)
1328 #if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0)
1329 port_conf->rxmode.mtu = mtu;
1331 port_conf->rxmode.max_rx_pkt_len = mtu;
1332 if (mtu > RTE_ETHER_MAX_LEN) {
1333 port_conf->rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1338 static void PortConfSetInterruptMode(
const DPDKIfaceConfig *iconf,
struct rte_eth_conf *port_conf)
1340 SCLogConfig(
"%s: interrupt mode is %s", iconf->iface,
1343 port_conf->intr_conf.rxq = 1;
1347 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf)
1349 if (dev_info->rx_offload_capa & RTE_ETH_RX_OFFLOAD_RSS_HASH) {
1350 if (iconf->nb_rx_queues > 1) {
1351 SCLogConfig(
"%s: RSS enabled for %d queues", iconf->iface, iconf->nb_rx_queues);
1352 port_conf->rx_adv_conf.rss_conf = (
struct rte_eth_rss_conf){
1353 .rss_key = RSS_HKEY,
1354 .rss_key_len = RSS_HKEY_LEN,
1355 .rss_hf = iconf->rss_hf,
1358 const char *dev_driver = dev_info->driver_name;
1359 if (strcmp(dev_info->driver_name,
"net_bonding") == 0) {
1360 dev_driver = BondingDeviceDriverGet(iconf->port_id);
1363 DeviceSetPMDSpecificRSS(&port_conf->rx_adv_conf.rss_conf, dev_driver);
1365 uint64_t rss_hf_tmp =
1366 port_conf->rx_adv_conf.rss_conf.rss_hf & dev_info->flow_type_rss_offloads;
1367 if (port_conf->rx_adv_conf.rss_conf.rss_hf != rss_hf_tmp) {
1368 DumpRSSFlags(port_conf->rx_adv_conf.rss_conf.rss_hf, rss_hf_tmp);
1370 SCLogWarning(
"%s: modified RSS hash function based on hardware support: "
1371 "requested:%#" PRIx64
", configured:%#" PRIx64,
1372 iconf->iface, port_conf->rx_adv_conf.rss_conf.rss_hf, rss_hf_tmp);
1373 port_conf->rx_adv_conf.rss_conf.rss_hf = rss_hf_tmp;
1375 port_conf->rxmode.mq_mode = RTE_ETH_MQ_RX_RSS;
1378 port_conf->rx_adv_conf.rss_conf.rss_key = NULL;
1379 port_conf->rx_adv_conf.rss_conf.rss_hf = 0;
1382 SCLogConfig(
"%s: RSS not supported", iconf->iface);
1387 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf)
1390 SCLogConfig(
"%s: checksum validation disabled", iconf->iface);
1391 }
else if ((dev_info->rx_offload_capa & RTE_ETH_RX_OFFLOAD_CHECKSUM) ==
1392 RTE_ETH_RX_OFFLOAD_CHECKSUM) {
1395 SCLogConfig(
"%s: IP, TCP and UDP checksum validation offloaded", iconf->iface);
1396 port_conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_CHECKSUM;
1399 SCLogConfig(
"%s: checksum validation enabled (but can be offloaded)", iconf->iface);
1405 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf)
1407 if (iconf->vlan_strip_enabled) {
1408 if (dev_info->rx_offload_capa & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
1409 port_conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
1410 SCLogConfig(
"%s: hardware VLAN stripping enabled", iconf->iface);
1412 SCLogWarning(
"%s: hardware VLAN stripping enabled but not supported, disabling",
1419 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf)
1421 DumpRXOffloadCapabilities(dev_info->rx_offload_capa);
1422 *port_conf = (
struct rte_eth_conf){
1424 .mq_mode = RTE_ETH_MQ_RX_NONE,
1428 .mq_mode = RTE_ETH_MQ_TX_NONE,
1433 PortConfSetInterruptMode(iconf, port_conf);
1436 PortConfSetRSSConf(iconf, dev_info, port_conf);
1437 PortConfSetChsumOffload(iconf, dev_info, port_conf);
1438 DeviceSetMTU(port_conf, iconf->mtu);
1439 PortConfSetVlanOffload(iconf, dev_info, port_conf);
1441 if (dev_info->tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) {
1442 port_conf->txmode.offloads |= RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
1446 static int DeviceConfigureQueues(
DPDKIfaceConfig *iconf,
const struct rte_eth_dev_info *dev_info,
1447 const struct rte_eth_conf *port_conf)
1451 struct rte_eth_rxconf rxq_conf;
1452 struct rte_eth_txconf txq_conf;
1454 retval = DPDKDeviceResourcesInit(&(iconf->pkt_mempools), iconf->nb_rx_queues);
1460 uint16_t mtu_size = iconf->mtu + RTE_ETHER_CRC_LEN + RTE_ETHER_HDR_LEN + 4;
1461 uint16_t mbuf_size = ROUNDUP(mtu_size, 1024) + RTE_PKTMBUF_HEADROOM;
1464 uint32_t raw = iconf->mempool_size / iconf->nb_rx_queues;
1465 uint32_t next_p2 = rte_align32pow2(raw + 1);
1466 uint32_t q_mp_sz = (next_p2 == raw + 1) ? raw : (next_p2 >> 1) - 1;
1467 uint32_t q_mp_cache_sz = iconf->mempool_cache_size_auto ? MempoolCacheSizeCalculate(q_mp_sz)
1468 : iconf->mempool_cache_size;
1469 SCLogInfo(
"%s: creating %u packet mempools of size %u, cache size %u, mbuf size %u",
1470 iconf->iface, iconf->nb_rx_queues, q_mp_sz, q_mp_cache_sz, mbuf_size);
1471 for (
int i = 0; i < iconf->nb_rx_queues; i++) {
1472 char mempool_name[64];
1473 snprintf(mempool_name,
sizeof(mempool_name),
"mp_%d_%.20s", i, iconf->iface);
1474 iconf->pkt_mempools->pkt_mp[i] = rte_pktmbuf_pool_create(
1475 mempool_name, q_mp_sz, q_mp_cache_sz, 0, mbuf_size, (
int)iconf->socket_id);
1476 if (iconf->pkt_mempools->pkt_mp[i] == NULL) {
1477 retval = -rte_errno;
1478 SCLogError(
"%s: rte_pktmbuf_pool_create failed with code %d (mempool: %s) - %s",
1479 iconf->iface, rte_errno, mempool_name, rte_strerror(rte_errno));
1484 for (uint16_t queue_id = 0; queue_id < iconf->nb_rx_queues; queue_id++) {
1485 rxq_conf = dev_info->default_rxconf;
1486 rxq_conf.offloads = port_conf->rxmode.offloads;
1487 rxq_conf.rx_thresh.hthresh = 0;
1488 rxq_conf.rx_thresh.pthresh = 0;
1489 rxq_conf.rx_thresh.wthresh = 0;
1490 rxq_conf.rx_free_thresh = 0;
1491 rxq_conf.rx_drop_en = 0;
1492 SCLogConfig(
"%s: setting up RX queue %d: rx_desc: %u offloads: 0x%" PRIx64
1493 " hthresh: %" PRIu8
" pthresh: %" PRIu8
" wthresh: %" PRIu8
1494 " free_thresh: %" PRIu16
" drop_en: %" PRIu8,
1495 iconf->iface, queue_id, iconf->nb_rx_desc, rxq_conf.offloads,
1496 rxq_conf.rx_thresh.hthresh, rxq_conf.rx_thresh.pthresh, rxq_conf.rx_thresh.wthresh,
1497 rxq_conf.rx_free_thresh, rxq_conf.rx_drop_en);
1499 retval = rte_eth_rx_queue_setup(iconf->port_id, queue_id, iconf->nb_rx_desc,
1500 (
unsigned int)iconf->socket_id, &rxq_conf, iconf->pkt_mempools->pkt_mp[queue_id]);
1502 SCLogError(
"%s: failed to setup RX queue %u: %s", iconf->iface, queue_id,
1503 rte_strerror(-retval));
1508 for (uint16_t queue_id = 0; queue_id < iconf->nb_tx_queues; queue_id++) {
1509 txq_conf = dev_info->default_txconf;
1510 txq_conf.offloads = port_conf->txmode.offloads;
1511 SCLogConfig(
"%s: setting up TX queue %d: tx_desc: %" PRIu16
" tx: offloads: 0x%" PRIx64
1512 " hthresh: %" PRIu8
" pthresh: %" PRIu8
" wthresh: %" PRIu8
1513 " tx_free_thresh: %" PRIu16
" tx_rs_thresh: %" PRIu16
1514 " txq_deferred_start: %" PRIu8,
1515 iconf->iface, queue_id, iconf->nb_tx_desc, txq_conf.offloads,
1516 txq_conf.tx_thresh.hthresh, txq_conf.tx_thresh.pthresh, txq_conf.tx_thresh.wthresh,
1517 txq_conf.tx_free_thresh, txq_conf.tx_rs_thresh, txq_conf.tx_deferred_start);
1518 retval = rte_eth_tx_queue_setup(iconf->port_id, queue_id, iconf->nb_tx_desc,
1519 (
unsigned int)iconf->socket_id, &txq_conf);
1521 SCLogError(
"%s: failed to setup TX queue %u: %s", iconf->iface, queue_id,
1522 rte_strerror(-retval));
1531 DPDKDeviceResourcesDeinit(&iconf->pkt_mempools);
1540 ConfigInit(&out_iconf);
1541 if (out_iconf == NULL) {
1542 FatalError(
"Copy interface of the interface \"%s\" is NULL", iconf->iface);
1545 retval = ConfigLoad(out_iconf, iconf->out_iface);
1547 SCLogError(
"%s: fail to load config of interface", iconf->out_iface);
1548 out_iconf->DerefFunc(out_iconf);
1552 if (iconf->nb_rx_queues != out_iconf->nb_tx_queues) {
1554 SCLogError(
"%s: configured %d RX queues but copy interface %s has %d TX queues"
1555 " - number of queues must be equal",
1556 iconf->iface, iconf->nb_rx_queues, out_iconf->iface, out_iconf->nb_tx_queues);
1557 out_iconf->DerefFunc(out_iconf);
1559 }
else if (iconf->mtu != out_iconf->mtu) {
1560 SCLogError(
"%s: configured MTU of %d but copy interface %s has MTU set to %d"
1561 " - MTU must be equal",
1562 iconf->iface, iconf->mtu, out_iconf->iface, out_iconf->mtu);
1563 out_iconf->DerefFunc(out_iconf);
1565 }
else if (iconf->copy_mode != out_iconf->copy_mode) {
1566 SCLogError(
"%s: copy modes of interfaces %s and %s are not equal", iconf->iface,
1567 iconf->iface, out_iconf->iface);
1568 out_iconf->DerefFunc(out_iconf);
1570 }
else if (strcmp(iconf->iface, out_iconf->out_iface) != 0) {
1572 SCLogError(
"%s: copy interface of %s is not set to %s", iconf->iface, out_iconf->iface,
1574 out_iconf->DerefFunc(out_iconf);
1578 out_iconf->DerefFunc(out_iconf);
1585 if (iconf->out_iface != NULL) {
1586 if (!rte_eth_dev_is_valid_port(iconf->out_port_id)) {
1587 SCLogError(
"%s: retrieved copy interface port ID \"%d\" is invalid or the device is "
1589 iconf->iface, iconf->out_port_id);
1592 int32_t out_port_socket_id;
1595 SCLogError(
"%s: invalid socket id: %s", iconf->out_iface, rte_strerror(-retval));
1599 if (iconf->socket_id != out_port_socket_id) {
1601 "%s: out iface %s is not on the same NUMA node (%s - NUMA %d, %s - NUMA %d)",
1602 iconf->iface, iconf->out_iface, iconf->iface, iconf->socket_id,
1603 iconf->out_iface, out_port_socket_id);
1606 retval = DeviceValidateOutIfaceConfig(iconf);
1613 SCLogInfo(
"%s: DPDK IPS mode activated: %s->%s", iconf->iface, iconf->iface,
1616 SCLogInfo(
"%s: DPDK TAP mode activated: %s->%s", iconf->iface, iconf->iface,
1630 static int32_t DeviceVerifyPostConfigure(
1631 const DPDKIfaceConfig *iconf,
const struct rte_eth_dev_info *dev_info)
1634 struct rte_eth_dev_info post_conf_dev_info = { 0 };
1635 int32_t ret = rte_eth_dev_info_get(iconf->port_id, &post_conf_dev_info);
1637 SCLogError(
"%s: getting device info failed: %s", iconf->iface, rte_strerror(-ret));
1641 if (dev_info->flow_type_rss_offloads != post_conf_dev_info.flow_type_rss_offloads ||
1642 dev_info->rx_offload_capa != post_conf_dev_info.rx_offload_capa ||
1643 dev_info->tx_offload_capa != post_conf_dev_info.tx_offload_capa ||
1644 dev_info->max_rx_queues != post_conf_dev_info.max_rx_queues ||
1645 dev_info->max_tx_queues != post_conf_dev_info.max_tx_queues ||
1646 dev_info->max_mtu != post_conf_dev_info.max_mtu) {
1647 SCLogWarning(
"%s: device information severely changed after configuration, reconfiguring",
1652 if (strcmp(dev_info->driver_name,
"net_bonding") == 0) {
1653 ret = BondingAllDevicesSameDriver(iconf->port_id);
1655 SCLogError(
"%s: bond port uses port with different DPDK drivers", iconf->iface);
1666 if (!rte_eth_dev_is_valid_port(iconf->port_id)) {
1667 SCLogError(
"%s: retrieved port ID \"%d\" is invalid or the device is not attached ",
1668 iconf->iface, iconf->port_id);
1674 SCLogError(
"%s: invalid socket id: %s", iconf->iface, rte_strerror(-retval));
1678 struct rte_eth_dev_info dev_info = { 0 };
1679 retval = rte_eth_dev_info_get(iconf->port_id, &dev_info);
1681 SCLogError(
"%s: getting device info failed: %s", iconf->iface, rte_strerror(-retval));
1685 if (iconf->nb_rx_queues > dev_info.max_rx_queues) {
1686 SCLogError(
"%s: configured RX queues %u is higher than device maximum (%" PRIu16
")",
1687 iconf->iface, iconf->nb_rx_queues, dev_info.max_rx_queues);
1691 if (iconf->nb_tx_queues > dev_info.max_tx_queues) {
1692 SCLogError(
"%s: configured TX queues %u is higher than device maximum (%" PRIu16
")",
1693 iconf->iface, iconf->nb_tx_queues, dev_info.max_tx_queues);
1697 retval = DeviceValidateMTU(iconf, &dev_info);
1701 struct rte_eth_conf port_conf = { 0 };
1702 DeviceInitPortConf(iconf, &dev_info, &port_conf);
1703 if (port_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM) {
1708 retval = rte_eth_dev_configure(
1709 iconf->port_id, iconf->nb_rx_queues, iconf->nb_tx_queues, &port_conf);
1711 SCLogError(
"%s: failed to configure the device: %s", iconf->iface, rte_strerror(-retval));
1715 retval = DeviceVerifyPostConfigure(iconf, &dev_info);
1719 uint16_t tmp_nb_rx_desc = iconf->nb_rx_desc;
1720 uint16_t tmp_nb_tx_desc = iconf->nb_tx_desc;
1721 retval = rte_eth_dev_adjust_nb_rx_tx_desc(
1722 iconf->port_id, &iconf->nb_rx_desc, &iconf->nb_tx_desc);
1724 SCLogError(
"%s: failed to adjust device queue descriptors: %s", iconf->iface,
1725 rte_strerror(-retval));
1727 }
else if (tmp_nb_rx_desc != iconf->nb_rx_desc || tmp_nb_tx_desc != iconf->nb_tx_desc) {
1728 SCLogWarning(
"%s: device queue descriptors adjusted (RX: from %u to %u, TX: from %u to %u)",
1729 iconf->iface, tmp_nb_rx_desc, iconf->nb_rx_desc, tmp_nb_tx_desc, iconf->nb_tx_desc);
1732 retval = iconf->flags &
DPDK_MULTICAST ? rte_eth_allmulticast_enable(iconf->port_id)
1733 : rte_eth_allmulticast_disable(iconf->port_id);
1734 if (retval == -ENOTSUP) {
1735 retval = rte_eth_allmulticast_get(iconf->port_id);
1739 SCLogWarning(
"%s: cannot configure allmulticast, the port is %sin allmulticast mode",
1740 iconf->iface, retval == 1 ?
"" :
"not ");
1741 }
else if (retval < 0) {
1742 SCLogError(
"%s: failed to get multicast mode: %s", iconf->iface, rte_strerror(-retval));
1745 }
else if (retval < 0) {
1746 SCLogError(
"%s: error when changing multicast setting: %s", iconf->iface,
1747 rte_strerror(-retval));
1751 retval = iconf->flags &
DPDK_PROMISC ? rte_eth_promiscuous_enable(iconf->port_id)
1752 : rte_eth_promiscuous_disable(iconf->port_id);
1753 if (retval == -ENOTSUP) {
1754 retval = rte_eth_promiscuous_get(iconf->port_id);
1757 SCLogError(
"%s: cannot configure promiscuous mode, the port is in %spromiscuous mode",
1758 iconf->iface, retval == 1 ?
"" :
"non-");
1760 }
else if (retval < 0) {
1762 "%s: failed to get promiscuous mode: %s", iconf->iface, rte_strerror(-retval));
1765 }
else if (retval < 0) {
1766 SCLogError(
"%s: error when changing promiscuous setting: %s", iconf->iface,
1767 rte_strerror(-retval));
1772 SCLogConfig(
"%s: setting MTU to %d", iconf->iface, iconf->mtu);
1773 retval = rte_eth_dev_set_mtu(iconf->port_id, iconf->mtu);
1774 if (retval == -ENOTSUP) {
1776 retval = rte_eth_dev_get_mtu(iconf->port_id, &iconf->mtu);
1778 SCLogError(
"%s: failed to retrieve MTU: %s", iconf->iface, rte_strerror(-retval));
1782 "%s: changing MTU is not supported, current MTU: %u", iconf->iface, iconf->mtu);
1783 }
else if (retval < 0) {
1785 "%s: failed to set MTU to %u: %s", iconf->iface, iconf->mtu, rte_strerror(-retval));
1789 retval = DeviceConfigureQueues(iconf, &dev_info, &port_conf);
1794 retval = DeviceConfigureIPS(iconf);
1802 static void *ParseDpdkConfigAndConfigureDevice(
const char *iface)
1806 if (iconf == NULL) {
1807 FatalError(
"DPDK configuration could not be parsed");
1810 retval = DeviceConfigure(iconf);
1811 if (retval == -EAGAIN) {
1813 retval = DeviceConfigure(iconf);
1817 iconf->DerefFunc(iconf);
1818 if (rte_eal_cleanup() != 0)
1819 FatalError(
"EAL cleanup failed: %s", rte_strerror(-retval));
1821 if (retval == -ENOMEM) {
1822 FatalError(
"%s: memory allocation failed - consider"
1823 "%s freeing up some memory.",
1825 rte_eal_has_hugepages() != 0 ?
" increasing the number of hugepages or" :
"");
1827 FatalError(
"%s: failed to configure", iface);
1836 iconf->workers_sync =
SCCalloc(1,
sizeof(*iconf->workers_sync));
1837 if (iconf->workers_sync == NULL) {
1838 FatalError(
"Failed to allocate memory for workers_sync");
1841 iconf->workers_sync->worker_cnt = iconf->threads;
1845 if (ldev_instance == NULL) {
1846 FatalError(
"Device %s is not registered as a live device", iface);
1848 ldev_instance->dpdk_vars = iconf->pkt_mempools;
1849 iconf->pkt_mempools = NULL;
1866 static uint16_t DPDKConfigGetThreadsCount(
void *conf)
1872 return dpdk_conf->threads;
1877 static int DPDKRunModeIsIPS(
void)
1880 const char dpdk_node_query[] =
"dpdk.interfaces";
1882 if (dpdk_node == NULL) {
1883 FatalError(
"Unable to get %s configuration node", dpdk_node_query);
1886 const char default_iface[] =
"default";
1889 bool has_ips =
false;
1890 bool has_ids =
false;
1891 for (
int ldev = 0; ldev < nlive; ldev++) {
1893 if (live_dev == NULL)
1894 FatalError(
"Unable to get device id %d from LiveDevice list", ldev);
1897 if (if_root == NULL) {
1898 if (if_default == NULL)
1899 FatalError(
"Unable to get %s or %s interface", live_dev, default_iface);
1901 if_root = if_default;
1904 const char *copymodestr = NULL;
1905 const char *copyifacestr = NULL;
1908 if (strcmp(copymodestr,
"ips") == 0) {
1917 if (has_ids && has_ips) {
1918 FatalError(
"Copy-mode of interface %s mixes with the previously set copy-modes "
1919 "(only IDS/TAP and IPS copy-mode combinations are allowed in DPDK",
1927 static int DPDKRunModeEnableIPS(
void)
1929 int r = DPDKRunModeIsIPS();
1945 "Workers DPDK mode, each thread does all"
1946 " tasks from acquisition to logging",
1971 SCLogDebug(
"RunModeIdsDpdkWorkers initialised");