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,
unsigned 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(
DPDKIfaceConfig *iconf,
const char *entry_str);
85 static int ConfigSetMempoolCacheSize(
DPDKIfaceConfig *iconf,
const char *entry_str);
86 static int ConfigSetRxDescriptors(
DPDKIfaceConfig *iconf,
const char *entry_str, uint16_t max_desc);
87 static int ConfigSetTxDescriptors(
88 DPDKIfaceConfig *iconf,
const char *entry_str, uint16_t max_desc,
bool iface_sends_pkts);
90 static bool ConfigSetPromiscuousMode(
DPDKIfaceConfig *iconf,
int entry_bool);
92 static int ConfigSetChecksumChecks(
DPDKIfaceConfig *iconf,
int entry_bool);
93 static int ConfigSetChecksumOffload(
DPDKIfaceConfig *iconf,
int entry_bool);
94 static int ConfigSetCopyIface(
DPDKIfaceConfig *iconf,
const char *entry_str);
95 static int ConfigSetCopyMode(
DPDKIfaceConfig *iconf,
const char *entry_str);
96 static int ConfigSetCopyIfaceSettings(
DPDKIfaceConfig *iconf,
const char *iface,
const char *mode);
102 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf);
103 static int DeviceConfigureQueues(
DPDKIfaceConfig *iconf,
const struct rte_eth_dev_info *dev_info,
104 const struct rte_eth_conf *port_conf);
108 static void *ParseDpdkConfigAndConfigureDevice(
const char *iface);
109 static void DPDKDerefConfig(
void *conf);
111 #define DPDK_CONFIG_DEFAULT_THREADS "auto"
112 #define DPDK_CONFIG_DEFAULT_INTERRUPT_MODE false
113 #define DPDK_CONFIG_DEFAULT_MEMPOOL_SIZE "auto"
114 #define DPDK_CONFIG_DEFAULT_MEMPOOL_CACHE_SIZE "auto"
115 #define DPDK_CONFIG_DEFAULT_RX_DESCRIPTORS "auto"
116 #define DPDK_CONFIG_DEFAULT_TX_DESCRIPTORS "auto"
117 #define DPDK_CONFIG_DEFAULT_RSS_HASH_FUNCTIONS RTE_ETH_RSS_IP
118 #define DPDK_CONFIG_DEFAULT_MTU 1500
119 #define DPDK_CONFIG_DEFAULT_PROMISCUOUS_MODE 1
120 #define DPDK_CONFIG_DEFAULT_MULTICAST_MODE 1
121 #define DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION 1
122 #define DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION_OFFLOAD 1
123 #define DPDK_CONFIG_DEFAULT_VLAN_STRIP 0
124 #define DPDK_CONFIG_DEFAULT_LINKUP_TIMEOUT 0
125 #define DPDK_CONFIG_DEFAULT_COPY_MODE "none"
126 #define DPDK_CONFIG_DEFAULT_COPY_INTERFACE "none"
130 .irq_mode =
"interrupt-mode",
131 .promisc =
"promisc",
132 .multicast =
"multicast",
133 .checksum_checks =
"checksum-checks",
134 .checksum_checks_offload =
"checksum-checks-offload",
136 .vlan_strip_offload =
"vlan-strip-offload",
137 .rss_hf =
"rss-hash-functions",
138 .linkup_timeout =
"linkup-timeout",
139 .mempool_size =
"mempool-size",
140 .mempool_cache_size =
"mempool-cache-size",
141 .rx_descriptors =
"rx-descriptors",
142 .tx_descriptors =
"tx-descriptors",
143 .copy_mode =
"copy-mode",
144 .copy_iface =
"copy-iface",
151 static int GreatestDivisorUpTo(uint32_t num, uint32_t max_num)
153 for (
int i = max_num; i >= 2; i--) {
165 static uint64_t GreatestPowOf2UpTo(uint64_t num)
178 num = num - (num >> 1);
183 static char *AllocArgument(
size_t arg_len)
189 ptr = (
char *)
SCCalloc(arg_len,
sizeof(
char));
191 FatalError(
"Could not allocate memory for an argument");
201 static char *AllocAndSetArgument(
const char *arg)
205 FatalError(
"Passed argument is NULL in DPDK config initialization");
208 size_t arg_len = strlen(arg);
210 ptr = AllocArgument(arg_len);
211 strlcpy(ptr, arg, arg_len + 1);
215 static char *AllocAndSetOption(
const char *arg)
219 FatalError(
"Passed option is NULL in DPDK config initialization");
222 size_t arg_len = strlen(arg);
223 uint8_t is_long_arg = arg_len > 1;
224 const char *dash_prefix = is_long_arg ?
"--" :
"-";
225 size_t full_len = arg_len + strlen(dash_prefix);
227 ptr = AllocArgument(full_len);
228 strlcpy(ptr, dash_prefix, strlen(dash_prefix) + 1);
229 strlcat(ptr, arg, full_len + 1);
233 static void ArgumentsInit(
struct Arguments *args,
unsigned capacity)
236 args->argv =
SCCalloc(capacity,
sizeof(*args->argv));
237 if (args->argv == NULL)
238 FatalError(
"Could not allocate memory for Arguments structure");
240 args->capacity = capacity;
245 static void ArgumentsCleanup(
struct Arguments *args)
248 for (
int i = 0; i < args->argc; i++) {
249 if (args->argv[i] != NULL) {
251 args->argv[i] = NULL;
261 static void ArgumentsAdd(
struct Arguments *args,
char *value)
264 if (args->argc + 1 > args->capacity)
265 FatalError(
"No capacity for more arguments (Max: %" PRIu32
")", EAL_ARGS);
267 args->argv[args->argc++] = value;
271 static void ArgumentsAddOptionAndArgument(
struct Arguments *args,
const char *opt,
const char *arg)
277 option = AllocAndSetOption(opt);
278 ArgumentsAdd(args, option);
281 if (arg == NULL || arg[0] ==
'\0')
284 argument = AllocAndSetArgument(arg);
285 ArgumentsAdd(args, argument);
289 static void InitEal(
void)
295 struct Arguments args;
298 if (eal_params == NULL) {
299 FatalError(
"DPDK EAL parameters not found in the config");
302 ArgumentsInit(&args, EAL_ARGS);
303 ArgumentsAdd(&args, AllocAndSetArgument(
"suricata"));
307 const char *key = param->
name;
310 ArgumentsAddOptionAndArgument(&args, key, (
const char *)val->
val);
314 ArgumentsAddOptionAndArgument(&args, param->
name, param->
val);
318 eal_argv =
SCCalloc(args.argc,
sizeof(*args.argv));
319 if (eal_argv == NULL) {
320 FatalError(
"Failed to allocate memory for the array of DPDK EAL arguments");
322 memcpy(eal_argv, args.argv, args.argc *
sizeof(*args.argv));
324 rte_log_set_global_level(RTE_LOG_WARNING);
325 retval = rte_eal_init(args.argc, eal_argv);
327 ArgumentsCleanup(&args);
331 FatalError(
"DPDK EAL initialization error: %s", rte_strerror(-retval));
335 static void DPDKDerefConfig(
void *conf)
341 DPDKDeviceResourcesDeinit(&iconf->pkt_mempools);
353 FatalError(
"Could not allocate memory for DPDKIfaceConfig");
355 ptr->out_port_id = -1;
358 ptr->DerefFunc = DPDKDerefConfig;
365 static void ConfigSetIface(
DPDKIfaceConfig *iconf,
const char *entry_str)
370 if (entry_str == NULL || entry_str[0] ==
'\0')
371 FatalError(
"Interface name in DPDK config is NULL or empty");
373 retval = rte_eth_dev_get_port_by_name(entry_str, &iconf->port_id);
375 FatalError(
"%s: interface not found: %s", entry_str, rte_strerror(-retval));
377 strlcpy(iconf->iface, entry_str,
sizeof(iconf->iface));
381 static int ConfigSetThreads(
DPDKIfaceConfig *iconf,
const char *entry_str)
384 static int32_t remaining_auto_cpus = -1;
386 SCLogError(
"DPDK runmode requires configured thread affinity");
392 SCLogError(
"Specify worker-cpu-set list in the threading section");
397 SCLogError(
"Specify management-cpu-set list in the threading section");
403 "\"all\" specified in worker CPU cores affinity, excluding management threads");
404 UtilAffinityCpusExclude(wtaf, mtaf);
408 if (sched_cpus == 0) {
409 SCLogError(
"No worker CPU cores with configured affinity were configured");
411 }
else if (UtilAffinityCpusOverlap(wtaf, mtaf) != 0) {
412 SCLogWarning(
"Worker threads should not overlap with management threads in the CPU core "
413 "affinity configuration");
417 if (active_runmode && !strcmp(
"single", active_runmode)) {
422 if (entry_str == NULL) {
423 SCLogError(
"Number of threads for interface \"%s\" not specified", iconf->iface);
427 if (strcmp(entry_str,
"auto") == 0) {
429 if (iconf->threads == 0) {
430 SCLogError(
"Not enough worker CPU cores with affinity were configured");
434 if (remaining_auto_cpus > 0) {
436 remaining_auto_cpus--;
437 }
else if (remaining_auto_cpus == -1) {
439 if (remaining_auto_cpus > 0) {
441 remaining_auto_cpus--;
444 SCLogConfig(
"%s: auto-assigned %u threads", iconf->iface, iconf->threads);
449 SCLogError(
"Threads entry for interface %s contain non-numerical characters - \"%s\"",
450 iconf->iface, entry_str);
454 if (iconf->threads <= 0) {
455 SCLogError(
"%s: positive number of threads required", iconf->iface);
462 static bool ConfigSetInterruptMode(
DPDKIfaceConfig *iconf,
bool enable)
471 static int ConfigSetRxQueues(
DPDKIfaceConfig *iconf, uint16_t nb_queues, uint16_t max_queues)
474 if (nb_queues == 0) {
475 SCLogInfo(
"%s: positive number of RX queues is required", iconf->iface);
479 if (nb_queues > max_queues) {
480 SCLogInfo(
"%s: number of RX queues cannot exceed %" PRIu16, iconf->iface, max_queues);
484 iconf->nb_rx_queues = nb_queues;
488 static bool ConfigIfaceSendsPkts(
const char *mode)
491 if (strcmp(mode,
"ips") == 0 || strcmp(mode,
"tap") == 0) {
497 static int ConfigSetTxQueues(
498 DPDKIfaceConfig *iconf, uint16_t nb_queues, uint16_t max_queues,
bool iface_sends_pkts)
501 if (nb_queues == 0 && iface_sends_pkts) {
502 SCLogInfo(
"%s: positive number of TX queues is required", iconf->iface);
506 if (nb_queues > max_queues) {
507 SCLogInfo(
"%s: number of TX queues cannot exceed %" PRIu16, iconf->iface, max_queues);
511 iconf->nb_tx_queues = nb_queues;
515 static uint32_t MempoolSizeCalculate(
516 uint32_t rx_queues, uint32_t rx_desc, uint32_t tx_queues, uint32_t tx_desc)
518 uint32_t sz = rx_queues * rx_desc + tx_queues * tx_desc;
519 if (!tx_queues || !tx_desc)
525 static int ConfigSetMempoolSize(
DPDKIfaceConfig *iconf,
const char *entry_str)
528 if (entry_str == NULL || entry_str[0] ==
'\0' || strcmp(entry_str,
"auto") == 0) {
533 if (iconf->nb_rx_queues == 0) {
535 SCLogError(
"%s: cannot autocalculate mempool size without RX queues", iconf->iface);
539 if (iconf->nb_rx_desc == 0) {
541 "%s: cannot autocalculate mempool size without RX descriptors", iconf->iface);
549 iconf->mempool_size = MempoolSizeCalculate(
550 iconf->nb_rx_queues, iconf->nb_rx_desc, iconf->nb_tx_queues, iconf->nb_tx_desc);
555 SCLogError(
"%s: mempool size entry contain non-numerical characters - \"%s\"", iconf->iface,
560 if (MempoolSizeCalculate(
561 iconf->nb_rx_queues, iconf->nb_rx_desc, iconf->nb_tx_queues, iconf->nb_tx_desc) >
562 iconf->mempool_size + 1) {
564 SCLogError(
"%s: mempool size is likely too small for the number of descriptors and queues, "
565 "set to \"auto\" or adjust to the value of \"%" PRIu32
"\"",
567 MempoolSizeCalculate(iconf->nb_rx_queues, iconf->nb_rx_desc, iconf->nb_tx_queues,
572 if (iconf->mempool_size == 0) {
573 SCLogError(
"%s: mempool size requires a positive integer", iconf->iface);
580 static uint32_t MempoolCacheSizeCalculate(uint32_t mp_sz)
585 uint32_t max_cache_size =
MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, mp_sz / 1.5);
586 return GreatestDivisorUpTo(mp_sz, max_cache_size);
589 static int ConfigSetMempoolCacheSize(
DPDKIfaceConfig *iconf,
const char *entry_str)
592 if (entry_str == NULL || entry_str[0] ==
'\0' || strcmp(entry_str,
"auto") == 0) {
594 if (iconf->mempool_size == 0) {
595 SCLogError(
"%s: cannot calculate mempool cache size of a mempool with size %d",
596 iconf->iface, iconf->mempool_size);
600 iconf->mempool_cache_size = MempoolCacheSizeCalculate(iconf->mempool_size);
605 SCLogError(
"%s: mempool cache size entry contain non-numerical characters - \"%s\"",
606 iconf->iface, entry_str);
610 if (iconf->mempool_cache_size <= 0 || iconf->mempool_cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE) {
611 SCLogError(
"%s: mempool cache size requires a positive number smaller than %" PRIu32,
612 iconf->iface, RTE_MEMPOOL_CACHE_MAX_SIZE);
619 static int ConfigSetRxDescriptors(
DPDKIfaceConfig *iconf,
const char *entry_str, uint16_t max_desc)
622 if (entry_str == NULL || entry_str[0] ==
'\0') {
623 SCLogInfo(
"%s: number of RX descriptors not found, going with: %s", iconf->iface,
624 DPDK_CONFIG_DEFAULT_RX_DESCRIPTORS);
625 entry_str = DPDK_CONFIG_DEFAULT_RX_DESCRIPTORS;
628 if (strcmp(entry_str,
"auto") == 0) {
629 iconf->nb_rx_desc = GreatestPowOf2UpTo(max_desc);
634 SCLogError(
"%s: RX descriptors entry contains non-numerical characters - \"%s\"",
635 iconf->iface, entry_str);
639 if (iconf->nb_rx_desc == 0) {
640 SCLogError(
"%s: positive number of RX descriptors is required", iconf->iface);
642 }
else if (iconf->nb_rx_desc > max_desc) {
643 SCLogError(
"%s: number of RX descriptors cannot exceed %" PRIu16, iconf->iface, max_desc);
650 static int ConfigSetTxDescriptors(
651 DPDKIfaceConfig *iconf,
const char *entry_str, uint16_t max_desc,
bool iface_sends_pkts)
654 if (entry_str == NULL || entry_str[0] ==
'\0') {
655 SCLogInfo(
"%s: number of TX descriptors not found, going with: %s", iconf->iface,
656 DPDK_CONFIG_DEFAULT_TX_DESCRIPTORS);
657 entry_str = DPDK_CONFIG_DEFAULT_TX_DESCRIPTORS;
660 if (strcmp(entry_str,
"auto") == 0) {
661 if (iface_sends_pkts) {
662 iconf->nb_tx_desc = GreatestPowOf2UpTo(max_desc);
664 iconf->nb_tx_desc = 0;
670 SCLogError(
"%s: TX descriptors entry contains non-numerical characters - \"%s\"",
671 iconf->iface, entry_str);
675 if (iconf->nb_tx_desc == 0 && iface_sends_pkts) {
676 SCLogError(
"%s: positive number of TX descriptors is required", iconf->iface);
678 }
else if (iconf->nb_tx_desc > max_desc) {
679 SCLogError(
"%s: number of TX descriptors cannot exceed %" PRIu16, iconf->iface, max_desc);
686 static int ConfigSetRSSHashFunctions(
DPDKIfaceConfig *iconf,
const char *entry_str)
689 if (entry_str == NULL || entry_str[0] ==
'\0' || strcmp(entry_str,
"auto") == 0) {
690 iconf->rss_hf = DPDK_CONFIG_DEFAULT_RSS_HASH_FUNCTIONS;
695 SCLogError(
"%s: RSS hash functions entry contain non-numerical characters - \"%s\"",
696 iconf->iface, entry_str);
706 if (entry_int < RTE_ETHER_MIN_MTU || entry_int > RTE_ETHER_MAX_JUMBO_FRAME_LEN) {
707 SCLogError(
"%s: MTU size can only be between %" PRIu32
" and %" PRIu32, iconf->iface,
708 RTE_ETHER_MIN_MTU, RTE_ETHER_MAX_JUMBO_FRAME_LEN);
712 iconf->mtu = entry_int;
716 static int ConfigSetLinkupTimeout(
DPDKIfaceConfig *iconf, intmax_t entry_int)
720 SCLogError(
"%s: Link-up waiting timeout needs to be a positive number or 0 to disable",
725 iconf->linkup_timeout = entry_int;
729 static bool ConfigSetPromiscuousMode(
DPDKIfaceConfig *iconf,
int entry_bool)
747 static int ConfigSetChecksumChecks(
DPDKIfaceConfig *iconf,
int entry_bool)
756 static int ConfigSetChecksumOffload(
DPDKIfaceConfig *iconf,
int entry_bool)
768 iconf->vlan_strip_enabled = entry_bool;
772 static int ConfigSetCopyIface(
DPDKIfaceConfig *iconf,
const char *entry_str)
777 if (entry_str == NULL || entry_str[0] ==
'\0' || strcmp(entry_str,
"none") == 0) {
778 iconf->out_iface = NULL;
782 retval = rte_eth_dev_get_port_by_name(entry_str, &iconf->out_port_id);
784 SCLogError(
"%s: copy interface (%s) not found: %s", iconf->iface, entry_str,
785 rte_strerror(-retval));
789 iconf->out_iface = entry_str;
793 static int ConfigSetCopyMode(
DPDKIfaceConfig *iconf,
const char *entry_str)
796 if (entry_str == NULL) {
797 SCLogWarning(
"%s: no copy mode specified, changing to %s ", iconf->iface,
798 DPDK_CONFIG_DEFAULT_COPY_MODE);
799 entry_str = DPDK_CONFIG_DEFAULT_COPY_MODE;
802 if (strcmp(entry_str,
"none") != 0 && strcmp(entry_str,
"tap") != 0 &&
803 strcmp(entry_str,
"ips") != 0) {
804 SCLogWarning(
"%s: copy mode \"%s\" is not one of the possible values (none|tap|ips). "
806 entry_str, iconf->iface, DPDK_CONFIG_DEFAULT_COPY_MODE);
807 entry_str = DPDK_CONFIG_DEFAULT_COPY_MODE;
810 if (strcmp(entry_str,
"none") == 0) {
812 }
else if (strcmp(entry_str,
"tap") == 0) {
814 }
else if (strcmp(entry_str,
"ips") == 0) {
821 static int ConfigSetCopyIfaceSettings(
DPDKIfaceConfig *iconf,
const char *iface,
const char *mode)
826 retval = ConfigSetCopyIface(iconf, iface);
830 retval = ConfigSetCopyMode(iconf, mode);
835 if (iconf->out_iface != NULL)
836 iconf->out_iface = NULL;
840 if (iconf->out_iface == NULL || strlen(iconf->out_iface) <= 0) {
841 SCLogError(
"%s: copy mode enabled but interface not set", iconf->iface);
854 const char *entry_str = NULL;
855 intmax_t entry_int = 0;
857 const char *copy_iface_str = NULL;
858 const char *copy_mode_str = NULL;
860 ConfigSetIface(iconf, iface);
861 struct rte_eth_dev_info dev_info = { 0 };
862 retval = rte_eth_dev_info_get(iconf->port_id, &dev_info);
864 SCLogError(
"%s: getting device info failed: %s", iconf->iface, rte_strerror(-retval));
870 FatalError(
"failed to find DPDK configuration for the interface %s", iconf->iface);
874 ? ConfigSetThreads(iconf, DPDK_CONFIG_DEFAULT_THREADS)
875 : ConfigSetThreads(iconf, entry_str);
881 if_root, if_default, dpdk_yaml.
irq_mode, &entry_bool);
883 irq_enable = DPDK_CONFIG_DEFAULT_INTERRUPT_MODE;
885 irq_enable = entry_bool ? true :
false;
887 retval = ConfigSetInterruptMode(iconf, irq_enable);
892 if_root, if_default, dpdk_yaml.
copy_mode, ©_mode_str);
894 copy_mode_str = DPDK_CONFIG_DEFAULT_COPY_MODE;
899 ? ConfigSetRxDescriptors(iconf, DPDK_CONFIG_DEFAULT_RX_DESCRIPTORS,
900 dev_info.rx_desc_lim.nb_max)
901 : ConfigSetRxDescriptors(iconf, entry_str, dev_info.rx_desc_lim.nb_max);
905 bool iface_sends_pkts = ConfigIfaceSendsPkts(copy_mode_str);
908 ? ConfigSetTxDescriptors(iconf, DPDK_CONFIG_DEFAULT_TX_DESCRIPTORS,
909 dev_info.tx_desc_lim.nb_max, iface_sends_pkts)
910 : ConfigSetTxDescriptors(
911 iconf, entry_str, dev_info.tx_desc_lim.nb_max, iface_sends_pkts);
916 retval = ConfigSetRxQueues(iconf, (uint16_t)iconf->threads, dev_info.max_rx_queues);
918 SCLogError(
"%s: too many threads configured - reduce thread count to: %" PRIu16,
919 iconf->iface, dev_info.max_rx_queues);
924 uint16_t tx_queues = iconf->nb_tx_desc > 0 ? (uint16_t)iconf->threads : 0;
925 retval = ConfigSetTxQueues(iconf, tx_queues, dev_info.max_tx_queues, iface_sends_pkts);
927 SCLogError(
"%s: too many threads configured - reduce thread count to: %" PRIu16,
928 iconf->iface, dev_info.max_tx_queues);
933 if_root, if_default, dpdk_yaml.
mempool_size, &entry_str) != 1
934 ? ConfigSetMempoolSize(iconf, DPDK_CONFIG_DEFAULT_MEMPOOL_SIZE)
935 : ConfigSetMempoolSize(iconf, entry_str);
941 ? ConfigSetMempoolCacheSize(iconf, DPDK_CONFIG_DEFAULT_MEMPOOL_CACHE_SIZE)
942 : ConfigSetMempoolCacheSize(iconf, entry_str);
947 ? ConfigSetMtu(iconf, DPDK_CONFIG_DEFAULT_MTU)
948 : ConfigSetMtu(iconf, entry_int);
953 ? ConfigSetRSSHashFunctions(iconf, NULL)
954 : ConfigSetRSSHashFunctions(iconf, entry_str);
959 if_root, if_default, dpdk_yaml.
promisc, &entry_bool) != 1
960 ? ConfigSetPromiscuousMode(iconf, DPDK_CONFIG_DEFAULT_PROMISCUOUS_MODE)
961 : ConfigSetPromiscuousMode(iconf, entry_bool);
966 if_root, if_default, dpdk_yaml.
multicast, &entry_bool) != 1
967 ? ConfigSetMulticast(iconf, DPDK_CONFIG_DEFAULT_MULTICAST_MODE)
968 : ConfigSetMulticast(iconf, entry_bool);
974 ? ConfigSetChecksumChecks(iconf, DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION)
975 : ConfigSetChecksumChecks(iconf, entry_bool);
981 ? ConfigSetChecksumOffload(
982 iconf, DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION_OFFLOAD)
983 : ConfigSetChecksumOffload(iconf, entry_bool);
990 ConfigSetVlanStrip(iconf, DPDK_CONFIG_DEFAULT_VLAN_STRIP);
992 ConfigSetVlanStrip(iconf, entry_bool);
997 ? ConfigSetLinkupTimeout(iconf, DPDK_CONFIG_DEFAULT_LINKUP_TIMEOUT)
998 : ConfigSetLinkupTimeout(iconf, entry_int);
1003 if_root, if_default, dpdk_yaml.
copy_iface, ©_iface_str);
1005 copy_iface_str = DPDK_CONFIG_DEFAULT_COPY_INTERFACE;
1008 retval = ConfigSetCopyIfaceSettings(iconf, copy_iface_str, copy_mode_str);
1015 static int32_t ConfigValidateThreads(uint16_t iface_threads)
1017 static uint32_t total_cpus = 0;
1018 total_cpus += iface_threads;
1021 SCLogError(
"Specify worker-cpu-set list in the threading section");
1025 SCLogError(
"Interfaces requested more cores than configured in the threading section "
1026 "(requested %d configured %d",
1043 retval = ConfigLoad(iconf, iface);
1044 if (retval < 0 || ConfigValidateThreads(iconf->threads) != 0) {
1045 iconf->DerefFunc(iconf);
1052 static void DeviceSetPMDSpecificRSS(
struct rte_eth_rss_conf *rss_conf,
const char *driver_name)
1054 if (strcmp(driver_name,
"net_i40e") == 0)
1055 i40eDeviceSetRSSConf(rss_conf);
1056 if (strcmp(driver_name,
"net_ice") == 0)
1057 iceDeviceSetRSSConf(rss_conf);
1058 if (strcmp(driver_name,
"net_ixgbe") == 0)
1059 ixgbeDeviceSetRSSHashFunction(&rss_conf->rss_hf);
1060 if (strcmp(driver_name,
"net_e1000_igb") == 0)
1061 rss_conf->rss_hf = (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_IPV6_EX);
1065 static int GetFirstSetBitPosition(uint64_t bits)
1067 for (uint64_t i = 0; i < 64; i++) {
1074 static void DumpRSSFlags(
const uint64_t requested,
const uint64_t actual)
1079 "RTE_ETH_RSS_IP %sset", ((requested & RTE_ETH_RSS_IP) == RTE_ETH_RSS_IP) ?
"" :
"NOT ");
1081 ((requested & RTE_ETH_RSS_TCP) == RTE_ETH_RSS_TCP) ?
"" :
"NOT ");
1083 ((requested & RTE_ETH_RSS_UDP) == RTE_ETH_RSS_UDP) ?
"" :
"NOT ");
1085 ((requested & RTE_ETH_RSS_SCTP) == RTE_ETH_RSS_SCTP) ?
"" :
"NOT ");
1087 ((requested & RTE_ETH_RSS_TUNNEL) == RTE_ETH_RSS_TUNNEL) ?
"" :
"NOT ");
1090 SCLogConfig(
"RTE_ETH_RSS_IPV4 (Bit position: %d) %sset",
1091 GetFirstSetBitPosition(RTE_ETH_RSS_IPV4), (requested & RTE_ETH_RSS_IPV4) ?
"" :
"NOT ");
1092 SCLogConfig(
"RTE_ETH_RSS_FRAG_IPV4 (Bit position: %d) %sset",
1093 GetFirstSetBitPosition(RTE_ETH_RSS_FRAG_IPV4),
1094 (requested & RTE_ETH_RSS_FRAG_IPV4) ?
"" :
"NOT ");
1095 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_TCP (Bit position: %d) %sset",
1096 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_TCP),
1097 (requested & RTE_ETH_RSS_NONFRAG_IPV4_TCP) ?
"" :
"NOT ");
1098 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_UDP (Bit position: %d) %sset",
1099 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_UDP),
1100 (requested & RTE_ETH_RSS_NONFRAG_IPV4_UDP) ?
"" :
"NOT ");
1101 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_SCTP (Bit position: %d) %sset",
1102 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_SCTP),
1103 (requested & RTE_ETH_RSS_NONFRAG_IPV4_SCTP) ?
"" :
"NOT ");
1104 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_OTHER (Bit position: %d) %sset",
1105 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_OTHER),
1106 (requested & RTE_ETH_RSS_NONFRAG_IPV4_OTHER) ?
"" :
"NOT ");
1107 SCLogConfig(
"RTE_ETH_RSS_IPV6 (Bit position: %d) %sset",
1108 GetFirstSetBitPosition(RTE_ETH_RSS_IPV6), (requested & RTE_ETH_RSS_IPV6) ?
"" :
"NOT ");
1109 SCLogConfig(
"RTE_ETH_RSS_FRAG_IPV6 (Bit position: %d) %sset",
1110 GetFirstSetBitPosition(RTE_ETH_RSS_FRAG_IPV6),
1111 (requested & RTE_ETH_RSS_FRAG_IPV6) ?
"" :
"NOT ");
1112 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_TCP (Bit position: %d) %sset",
1113 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_TCP),
1114 (requested & RTE_ETH_RSS_NONFRAG_IPV6_TCP) ?
"" :
"NOT ");
1115 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_UDP (Bit position: %d) %sset",
1116 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_UDP),
1117 (requested & RTE_ETH_RSS_NONFRAG_IPV6_UDP) ?
"" :
"NOT ");
1118 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_SCTP (Bit position: %d) %sset",
1119 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_SCTP),
1120 (requested & RTE_ETH_RSS_NONFRAG_IPV6_SCTP) ?
"" :
"NOT ");
1121 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_OTHER (Bit position: %d) %sset",
1122 GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_OTHER),
1123 (requested & RTE_ETH_RSS_NONFRAG_IPV6_OTHER) ?
"" :
"NOT ");
1125 SCLogConfig(
"RTE_ETH_RSS_L2_PAYLOAD (Bit position: %d) %sset",
1126 GetFirstSetBitPosition(RTE_ETH_RSS_L2_PAYLOAD),
1127 (requested & RTE_ETH_RSS_L2_PAYLOAD) ?
"" :
"NOT ");
1128 SCLogConfig(
"RTE_ETH_RSS_IPV6_EX (Bit position: %d) %sset",
1129 GetFirstSetBitPosition(RTE_ETH_RSS_IPV6_EX),
1130 (requested & RTE_ETH_RSS_IPV6_EX) ?
"" :
"NOT ");
1131 SCLogConfig(
"RTE_ETH_RSS_IPV6_TCP_EX (Bit position: %d) %sset",
1132 GetFirstSetBitPosition(RTE_ETH_RSS_IPV6_TCP_EX),
1133 (requested & RTE_ETH_RSS_IPV6_TCP_EX) ?
"" :
"NOT ");
1134 SCLogConfig(
"RTE_ETH_RSS_IPV6_UDP_EX (Bit position: %d) %sset",
1135 GetFirstSetBitPosition(RTE_ETH_RSS_IPV6_UDP_EX),
1136 (requested & RTE_ETH_RSS_IPV6_UDP_EX) ?
"" :
"NOT ");
1138 SCLogConfig(
"RTE_ETH_RSS_PORT (Bit position: %d) %sset",
1139 GetFirstSetBitPosition(RTE_ETH_RSS_PORT), (requested & RTE_ETH_RSS_PORT) ?
"" :
"NOT ");
1140 SCLogConfig(
"RTE_ETH_RSS_VXLAN (Bit position: %d) %sset",
1141 GetFirstSetBitPosition(RTE_ETH_RSS_VXLAN),
1142 (requested & RTE_ETH_RSS_VXLAN) ?
"" :
"NOT ");
1143 SCLogConfig(
"RTE_ETH_RSS_NVGRE (Bit position: %d) %sset",
1144 GetFirstSetBitPosition(RTE_ETH_RSS_NVGRE),
1145 (requested & RTE_ETH_RSS_NVGRE) ?
"" :
"NOT ");
1146 SCLogConfig(
"RTE_ETH_RSS_GTPU (Bit position: %d) %sset",
1147 GetFirstSetBitPosition(RTE_ETH_RSS_GTPU), (requested & RTE_ETH_RSS_GTPU) ?
"" :
"NOT ");
1149 SCLogConfig(
"RTE_ETH_RSS_L3_SRC_ONLY (Bit position: %d) %sset",
1150 GetFirstSetBitPosition(RTE_ETH_RSS_L3_SRC_ONLY),
1151 (requested & RTE_ETH_RSS_L3_SRC_ONLY) ?
"" :
"NOT ");
1152 SCLogConfig(
"RTE_ETH_RSS_L3_DST_ONLY (Bit position: %d) %sset",
1153 GetFirstSetBitPosition(RTE_ETH_RSS_L3_DST_ONLY),
1154 (requested & RTE_ETH_RSS_L3_DST_ONLY) ?
"" :
"NOT ");
1155 SCLogConfig(
"RTE_ETH_RSS_L4_SRC_ONLY (Bit position: %d) %sset",
1156 GetFirstSetBitPosition(RTE_ETH_RSS_L4_SRC_ONLY),
1157 (requested & RTE_ETH_RSS_L4_SRC_ONLY) ?
"" :
"NOT ");
1158 SCLogConfig(
"RTE_ETH_RSS_L4_DST_ONLY (Bit position: %d) %sset",
1159 GetFirstSetBitPosition(RTE_ETH_RSS_L4_DST_ONLY),
1160 (requested & RTE_ETH_RSS_L4_DST_ONLY) ?
"" :
"NOT ");
1163 "RTE_ETH_RSS_IP %sset", ((actual & RTE_ETH_RSS_IP) == RTE_ETH_RSS_IP) ?
"" :
"NOT ");
1165 "RTE_ETH_RSS_TCP %sset", ((actual & RTE_ETH_RSS_TCP) == RTE_ETH_RSS_TCP) ?
"" :
"NOT ");
1167 "RTE_ETH_RSS_UDP %sset", ((actual & RTE_ETH_RSS_UDP) == RTE_ETH_RSS_UDP) ?
"" :
"NOT ");
1169 ((actual & RTE_ETH_RSS_SCTP) == RTE_ETH_RSS_SCTP) ?
"" :
"NOT ");
1171 ((actual & RTE_ETH_RSS_TUNNEL) == RTE_ETH_RSS_TUNNEL) ?
"" :
"NOT ");
1174 SCLogConfig(
"RTE_ETH_RSS_IPV4 %sset", (actual & RTE_ETH_RSS_IPV4) ?
"" :
"NOT ");
1175 SCLogConfig(
"RTE_ETH_RSS_FRAG_IPV4 %sset", (actual & RTE_ETH_RSS_FRAG_IPV4) ?
"" :
"NOT ");
1177 (actual & RTE_ETH_RSS_NONFRAG_IPV4_TCP) ?
"" :
"NOT ");
1179 (actual & RTE_ETH_RSS_NONFRAG_IPV4_UDP) ?
"" :
"NOT ");
1180 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_SCTP %sset",
1181 (actual & RTE_ETH_RSS_NONFRAG_IPV4_SCTP) ?
"" :
"NOT ");
1182 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV4_OTHER %sset",
1183 (actual & RTE_ETH_RSS_NONFRAG_IPV4_OTHER) ?
"" :
"NOT ");
1184 SCLogConfig(
"RTE_ETH_RSS_IPV6 %sset", (actual & RTE_ETH_RSS_IPV6) ?
"" :
"NOT ");
1185 SCLogConfig(
"RTE_ETH_RSS_FRAG_IPV6 %sset", (actual & RTE_ETH_RSS_FRAG_IPV6) ?
"" :
"NOT ");
1187 (actual & RTE_ETH_RSS_NONFRAG_IPV6_TCP) ?
"" :
"NOT ");
1189 (actual & RTE_ETH_RSS_NONFRAG_IPV6_UDP) ?
"" :
"NOT ");
1190 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_SCTP %sset",
1191 (actual & RTE_ETH_RSS_NONFRAG_IPV6_SCTP) ?
"" :
"NOT ");
1192 SCLogConfig(
"RTE_ETH_RSS_NONFRAG_IPV6_OTHER %sset",
1193 (actual & RTE_ETH_RSS_NONFRAG_IPV6_OTHER) ?
"" :
"NOT ");
1195 SCLogConfig(
"RTE_ETH_RSS_L2_PAYLOAD %sset", (actual & RTE_ETH_RSS_L2_PAYLOAD) ?
"" :
"NOT ");
1196 SCLogConfig(
"RTE_ETH_RSS_IPV6_EX %sset", (actual & RTE_ETH_RSS_IPV6_EX) ?
"" :
"NOT ");
1197 SCLogConfig(
"RTE_ETH_RSS_IPV6_TCP_EX %sset", (actual & RTE_ETH_RSS_IPV6_TCP_EX) ?
"" :
"NOT ");
1198 SCLogConfig(
"RTE_ETH_RSS_IPV6_UDP_EX %sset", (actual & RTE_ETH_RSS_IPV6_UDP_EX) ?
"" :
"NOT ");
1200 SCLogConfig(
"RTE_ETH_RSS_PORT %sset", (actual & RTE_ETH_RSS_PORT) ?
"" :
"NOT ");
1201 SCLogConfig(
"RTE_ETH_RSS_VXLAN %sset", (actual & RTE_ETH_RSS_VXLAN) ?
"" :
"NOT ");
1202 SCLogConfig(
"RTE_ETH_RSS_NVGRE %sset", (actual & RTE_ETH_RSS_NVGRE) ?
"" :
"NOT ");
1203 SCLogConfig(
"RTE_ETH_RSS_GTPU %sset", (actual & RTE_ETH_RSS_GTPU) ?
"" :
"NOT ");
1205 SCLogConfig(
"RTE_ETH_RSS_L3_SRC_ONLY %sset", (actual & RTE_ETH_RSS_L3_SRC_ONLY) ?
"" :
"NOT ");
1206 SCLogConfig(
"RTE_ETH_RSS_L3_DST_ONLY %sset", (actual & RTE_ETH_RSS_L3_DST_ONLY) ?
"" :
"NOT ");
1207 SCLogConfig(
"RTE_ETH_RSS_L4_SRC_ONLY %sset", (actual & RTE_ETH_RSS_L4_SRC_ONLY) ?
"" :
"NOT ");
1208 SCLogConfig(
"RTE_ETH_RSS_L4_DST_ONLY %sset", (actual & RTE_ETH_RSS_L4_DST_ONLY) ?
"" :
"NOT ");
1211 static void DumpRXOffloadCapabilities(
const uint64_t rx_offld_capa)
1213 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_VLAN_STRIP - %savailable",
1214 rx_offld_capa & RTE_ETH_RX_OFFLOAD_VLAN_STRIP ?
"" :
"NOT ");
1215 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_IPV4_CKSUM - %savailable",
1216 rx_offld_capa & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM ?
"" :
"NOT ");
1217 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_UDP_CKSUM - %savailable",
1218 rx_offld_capa & RTE_ETH_RX_OFFLOAD_UDP_CKSUM ?
"" :
"NOT ");
1219 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_TCP_CKSUM - %savailable",
1220 rx_offld_capa & RTE_ETH_RX_OFFLOAD_TCP_CKSUM ?
"" :
"NOT ");
1221 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_TCP_LRO - %savailable",
1222 rx_offld_capa & RTE_ETH_RX_OFFLOAD_TCP_LRO ?
"" :
"NOT ");
1223 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_QINQ_STRIP - %savailable",
1224 rx_offld_capa & RTE_ETH_RX_OFFLOAD_QINQ_STRIP ?
"" :
"NOT ");
1225 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM - %savailable",
1226 rx_offld_capa & RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM ?
"" :
"NOT ");
1227 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_MACSEC_STRIP - %savailable",
1228 rx_offld_capa & RTE_ETH_RX_OFFLOAD_MACSEC_STRIP ?
"" :
"NOT ");
1229 #if RTE_VERSION < RTE_VERSION_NUM(22, 11, 0, 0)
1230 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_HEADER_SPLIT - %savailable",
1231 rx_offld_capa & RTE_ETH_RX_OFFLOAD_HEADER_SPLIT ?
"" :
"NOT ");
1233 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_VLAN_FILTER - %savailable",
1234 rx_offld_capa & RTE_ETH_RX_OFFLOAD_VLAN_FILTER ?
"" :
"NOT ");
1235 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_VLAN_EXTEND - %savailable",
1236 rx_offld_capa & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND ?
"" :
"NOT ");
1237 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_SCATTER - %savailable",
1238 rx_offld_capa & RTE_ETH_RX_OFFLOAD_SCATTER ?
"" :
"NOT ");
1239 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_TIMESTAMP - %savailable",
1240 rx_offld_capa & RTE_ETH_RX_OFFLOAD_TIMESTAMP ?
"" :
"NOT ");
1241 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_SECURITY - %savailable",
1242 rx_offld_capa & RTE_ETH_RX_OFFLOAD_SECURITY ?
"" :
"NOT ");
1243 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_KEEP_CRC - %savailable",
1244 rx_offld_capa & RTE_ETH_RX_OFFLOAD_KEEP_CRC ?
"" :
"NOT ");
1245 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_SCTP_CKSUM - %savailable",
1246 rx_offld_capa & RTE_ETH_RX_OFFLOAD_SCTP_CKSUM ?
"" :
"NOT ");
1247 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM - %savailable",
1248 rx_offld_capa & RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM ?
"" :
"NOT ");
1249 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_RSS_HASH - %savailable",
1250 rx_offld_capa & RTE_ETH_RX_OFFLOAD_RSS_HASH ?
"" :
"NOT ");
1251 #if RTE_VERSION >= RTE_VERSION_NUM(20, 11, 0, 0)
1252 SCLogConfig(
"RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT - %savailable",
1253 rx_offld_capa & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT ?
"" :
"NOT ");
1257 static int DeviceValidateMTU(
const DPDKIfaceConfig *iconf,
const struct rte_eth_dev_info *dev_info)
1260 if (iconf->mtu > dev_info->max_mtu || iconf->mtu < dev_info->min_mtu) {
1262 "Min MTU: %" PRIu16
" Max MTU: %" PRIu16,
1263 iconf->iface, dev_info->min_mtu, dev_info->max_mtu);
1267 #if RTE_VERSION < RTE_VERSION_NUM(21, 11, 0, 0)
1269 if (iconf->mtu > RTE_ETHER_MAX_LEN &&
1270 !(dev_info->rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME)) {
1271 SCLogError(
"%s: jumbo frames not supported, set MTU to 1500", iconf->iface);
1279 static void DeviceSetMTU(
struct rte_eth_conf *port_conf, uint16_t mtu)
1281 #if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0)
1282 port_conf->rxmode.mtu = mtu;
1284 port_conf->rxmode.max_rx_pkt_len = mtu;
1285 if (mtu > RTE_ETHER_MAX_LEN) {
1286 port_conf->rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1296 static int32_t DeviceSetSocketID(uint16_t port_id, int32_t *socket_id)
1299 int retval = rte_eth_dev_socket_id(port_id);
1300 *socket_id = retval;
1302 #if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) // DPDK API changed since 22.11
1303 retval = -rte_errno;
1305 if (retval == SOCKET_ID_ANY)
1312 static void PortConfSetInterruptMode(
const DPDKIfaceConfig *iconf,
struct rte_eth_conf *port_conf)
1314 SCLogConfig(
"%s: interrupt mode is %s", iconf->iface,
1317 port_conf->intr_conf.rxq = 1;
1321 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf)
1323 if (dev_info->rx_offload_capa & RTE_ETH_RX_OFFLOAD_RSS_HASH) {
1324 if (iconf->nb_rx_queues > 1) {
1325 SCLogConfig(
"%s: RSS enabled for %d queues", iconf->iface, iconf->nb_rx_queues);
1326 port_conf->rx_adv_conf.rss_conf = (
struct rte_eth_rss_conf){
1327 .rss_key = RSS_HKEY,
1328 .rss_key_len = RSS_HKEY_LEN,
1329 .rss_hf = iconf->rss_hf,
1332 const char *dev_driver = dev_info->driver_name;
1333 if (strcmp(dev_info->driver_name,
"net_bonding") == 0) {
1334 dev_driver = BondingDeviceDriverGet(iconf->port_id);
1337 DeviceSetPMDSpecificRSS(&port_conf->rx_adv_conf.rss_conf, dev_driver);
1339 uint64_t rss_hf_tmp =
1340 port_conf->rx_adv_conf.rss_conf.rss_hf & dev_info->flow_type_rss_offloads;
1341 if (port_conf->rx_adv_conf.rss_conf.rss_hf != rss_hf_tmp) {
1342 DumpRSSFlags(port_conf->rx_adv_conf.rss_conf.rss_hf, rss_hf_tmp);
1344 SCLogWarning(
"%s: modified RSS hash function based on hardware support: "
1345 "requested:%#" PRIx64
", configured:%#" PRIx64,
1346 iconf->iface, port_conf->rx_adv_conf.rss_conf.rss_hf, rss_hf_tmp);
1347 port_conf->rx_adv_conf.rss_conf.rss_hf = rss_hf_tmp;
1349 port_conf->rxmode.mq_mode = RTE_ETH_MQ_RX_RSS;
1352 port_conf->rx_adv_conf.rss_conf.rss_key = NULL;
1353 port_conf->rx_adv_conf.rss_conf.rss_hf = 0;
1356 SCLogConfig(
"%s: RSS not supported", iconf->iface);
1361 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf)
1364 SCLogConfig(
"%s: checksum validation disabled", iconf->iface);
1365 }
else if ((dev_info->rx_offload_capa & RTE_ETH_RX_OFFLOAD_CHECKSUM) ==
1366 RTE_ETH_RX_OFFLOAD_CHECKSUM) {
1369 SCLogConfig(
"%s: IP, TCP and UDP checksum validation offloaded", iconf->iface);
1370 port_conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_CHECKSUM;
1373 SCLogConfig(
"%s: checksum validation enabled (but can be offloaded)", iconf->iface);
1379 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf)
1381 if (iconf->vlan_strip_enabled) {
1382 if (dev_info->rx_offload_capa & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
1383 port_conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
1384 SCLogConfig(
"%s: hardware VLAN stripping enabled", iconf->iface);
1386 SCLogWarning(
"%s: hardware VLAN stripping enabled but not supported, disabling",
1393 const struct rte_eth_dev_info *dev_info,
struct rte_eth_conf *port_conf)
1395 DumpRXOffloadCapabilities(dev_info->rx_offload_capa);
1396 *port_conf = (
struct rte_eth_conf){
1398 .mq_mode = RTE_ETH_MQ_RX_NONE,
1402 .mq_mode = RTE_ETH_MQ_TX_NONE,
1407 PortConfSetInterruptMode(iconf, port_conf);
1410 PortConfSetRSSConf(iconf, dev_info, port_conf);
1411 PortConfSetChsumOffload(iconf, dev_info, port_conf);
1412 DeviceSetMTU(port_conf, iconf->mtu);
1413 PortConfSetVlanOffload(iconf, dev_info, port_conf);
1415 if (dev_info->tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) {
1416 port_conf->txmode.offloads |= RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
1420 static int DeviceConfigureQueues(
DPDKIfaceConfig *iconf,
const struct rte_eth_dev_info *dev_info,
1421 const struct rte_eth_conf *port_conf)
1425 struct rte_eth_rxconf rxq_conf;
1426 struct rte_eth_txconf txq_conf;
1428 retval = DPDKDeviceResourcesInit(&(iconf->pkt_mempools), iconf->nb_rx_queues);
1434 uint16_t mtu_size = iconf->mtu + RTE_ETHER_CRC_LEN + RTE_ETHER_HDR_LEN + 4;
1435 uint16_t mbuf_size = ROUNDUP(mtu_size, 1024) + RTE_PKTMBUF_HEADROOM;
1437 uint32_t q_mp_sz = (iconf->mempool_size + iconf->nb_rx_queues - 1) / iconf->nb_rx_queues - 1;
1438 uint32_t q_mp_cache_sz = MempoolCacheSizeCalculate(q_mp_sz);
1439 SCLogInfo(
"%s: creating %u packet mempools of size %u, cache size %u, mbuf size %u",
1440 iconf->iface, iconf->nb_rx_queues, q_mp_sz, q_mp_cache_sz, mbuf_size);
1441 for (
int i = 0; i < iconf->nb_rx_queues; i++) {
1442 char mempool_name[64];
1443 snprintf(mempool_name,
sizeof(mempool_name),
"mp_%d_%.20s", i, iconf->iface);
1444 iconf->pkt_mempools->pkt_mp[i] = rte_pktmbuf_pool_create(
1445 mempool_name, q_mp_sz, q_mp_cache_sz, 0, mbuf_size, (
int)iconf->socket_id);
1446 if (iconf->pkt_mempools->pkt_mp[i] == NULL) {
1447 retval = -rte_errno;
1448 SCLogError(
"%s: rte_pktmbuf_pool_create failed with code %d (mempool: %s) - %s",
1449 iconf->iface, rte_errno, mempool_name, rte_strerror(rte_errno));
1454 for (uint16_t queue_id = 0; queue_id < iconf->nb_rx_queues; queue_id++) {
1455 rxq_conf = dev_info->default_rxconf;
1456 rxq_conf.offloads = port_conf->rxmode.offloads;
1457 rxq_conf.rx_thresh.hthresh = 0;
1458 rxq_conf.rx_thresh.pthresh = 0;
1459 rxq_conf.rx_thresh.wthresh = 0;
1460 rxq_conf.rx_free_thresh = 0;
1461 rxq_conf.rx_drop_en = 0;
1462 SCLogConfig(
"%s: setting up RX queue %d: rx_desc: %u offloads: 0x%" PRIx64
1463 " hthresh: %" PRIu8
" pthresh: %" PRIu8
" wthresh: %" PRIu8
1464 " free_thresh: %" PRIu16
" drop_en: %" PRIu8,
1465 iconf->iface, queue_id, iconf->nb_rx_desc, rxq_conf.offloads,
1466 rxq_conf.rx_thresh.hthresh, rxq_conf.rx_thresh.pthresh, rxq_conf.rx_thresh.wthresh,
1467 rxq_conf.rx_free_thresh, rxq_conf.rx_drop_en);
1469 retval = rte_eth_rx_queue_setup(iconf->port_id, queue_id, iconf->nb_rx_desc,
1470 iconf->socket_id, &rxq_conf, iconf->pkt_mempools->pkt_mp[queue_id]);
1472 SCLogError(
"%s: failed to setup RX queue %u: %s", iconf->iface, queue_id,
1473 rte_strerror(-retval));
1478 for (uint16_t queue_id = 0; queue_id < iconf->nb_tx_queues; queue_id++) {
1479 txq_conf = dev_info->default_txconf;
1480 txq_conf.offloads = port_conf->txmode.offloads;
1481 SCLogConfig(
"%s: setting up TX queue %d: tx_desc: %" PRIu16
" tx: offloads: 0x%" PRIx64
1482 " hthresh: %" PRIu8
" pthresh: %" PRIu8
" wthresh: %" PRIu8
1483 " tx_free_thresh: %" PRIu16
" tx_rs_thresh: %" PRIu16
1484 " txq_deferred_start: %" PRIu8,
1485 iconf->iface, queue_id, iconf->nb_tx_desc, txq_conf.offloads,
1486 txq_conf.tx_thresh.hthresh, txq_conf.tx_thresh.pthresh, txq_conf.tx_thresh.wthresh,
1487 txq_conf.tx_free_thresh, txq_conf.tx_rs_thresh, txq_conf.tx_deferred_start);
1488 retval = rte_eth_tx_queue_setup(
1489 iconf->port_id, queue_id, iconf->nb_tx_desc, iconf->socket_id, &txq_conf);
1491 SCLogError(
"%s: failed to setup TX queue %u: %s", iconf->iface, queue_id,
1492 rte_strerror(-retval));
1501 DPDKDeviceResourcesDeinit(&iconf->pkt_mempools);
1510 ConfigInit(&out_iconf);
1511 if (out_iconf == NULL) {
1512 FatalError(
"Copy interface of the interface \"%s\" is NULL", iconf->iface);
1515 retval = ConfigLoad(out_iconf, iconf->out_iface);
1517 SCLogError(
"%s: fail to load config of interface", iconf->out_iface);
1518 out_iconf->DerefFunc(out_iconf);
1522 if (iconf->nb_rx_queues != out_iconf->nb_tx_queues) {
1524 SCLogError(
"%s: configured %d RX queues but copy interface %s has %d TX queues"
1525 " - number of queues must be equal",
1526 iconf->iface, iconf->nb_rx_queues, out_iconf->iface, out_iconf->nb_tx_queues);
1527 out_iconf->DerefFunc(out_iconf);
1529 }
else if (iconf->mtu != out_iconf->mtu) {
1530 SCLogError(
"%s: configured MTU of %d but copy interface %s has MTU set to %d"
1531 " - MTU must be equal",
1532 iconf->iface, iconf->mtu, out_iconf->iface, out_iconf->mtu);
1533 out_iconf->DerefFunc(out_iconf);
1535 }
else if (iconf->copy_mode != out_iconf->copy_mode) {
1536 SCLogError(
"%s: copy modes of interfaces %s and %s are not equal", iconf->iface,
1537 iconf->iface, out_iconf->iface);
1538 out_iconf->DerefFunc(out_iconf);
1540 }
else if (strcmp(iconf->iface, out_iconf->out_iface) != 0) {
1542 SCLogError(
"%s: copy interface of %s is not set to %s", iconf->iface, out_iconf->iface,
1544 out_iconf->DerefFunc(out_iconf);
1548 out_iconf->DerefFunc(out_iconf);
1555 if (iconf->out_iface != NULL) {
1556 if (!rte_eth_dev_is_valid_port(iconf->out_port_id)) {
1557 SCLogError(
"%s: retrieved copy interface port ID \"%d\" is invalid or the device is "
1559 iconf->iface, iconf->out_port_id);
1562 int32_t out_port_socket_id;
1563 int retval = DeviceSetSocketID(iconf->out_port_id, &out_port_socket_id);
1565 SCLogError(
"%s: invalid socket id: %s", iconf->out_iface, rte_strerror(-retval));
1569 if (iconf->socket_id != out_port_socket_id) {
1571 "%s: out iface %s is not on the same NUMA node (%s - NUMA %d, %s - NUMA %d)",
1572 iconf->iface, iconf->out_iface, iconf->iface, iconf->socket_id,
1573 iconf->out_iface, out_port_socket_id);
1576 retval = DeviceValidateOutIfaceConfig(iconf);
1583 SCLogInfo(
"%s: DPDK IPS mode activated: %s->%s", iconf->iface, iconf->iface,
1586 SCLogInfo(
"%s: DPDK TAP mode activated: %s->%s", iconf->iface, iconf->iface,
1600 static int32_t DeviceVerifyPostConfigure(
1601 const DPDKIfaceConfig *iconf,
const struct rte_eth_dev_info *dev_info)
1604 struct rte_eth_dev_info post_conf_dev_info = { 0 };
1605 int32_t ret = rte_eth_dev_info_get(iconf->port_id, &post_conf_dev_info);
1607 SCLogError(
"%s: getting device info failed: %s", iconf->iface, rte_strerror(-ret));
1611 if (dev_info->flow_type_rss_offloads != post_conf_dev_info.flow_type_rss_offloads ||
1612 dev_info->rx_offload_capa != post_conf_dev_info.rx_offload_capa ||
1613 dev_info->tx_offload_capa != post_conf_dev_info.tx_offload_capa ||
1614 dev_info->max_rx_queues != post_conf_dev_info.max_rx_queues ||
1615 dev_info->max_tx_queues != post_conf_dev_info.max_tx_queues ||
1616 dev_info->max_mtu != post_conf_dev_info.max_mtu) {
1617 SCLogWarning(
"%s: device information severely changed after configuration, reconfiguring",
1622 if (strcmp(dev_info->driver_name,
"net_bonding") == 0) {
1623 ret = BondingAllDevicesSameDriver(iconf->port_id);
1625 SCLogError(
"%s: bond port uses port with different DPDK drivers", iconf->iface);
1636 if (!rte_eth_dev_is_valid_port(iconf->port_id)) {
1637 SCLogError(
"%s: retrieved port ID \"%d\" is invalid or the device is not attached ",
1638 iconf->iface, iconf->port_id);
1642 int32_t retval = DeviceSetSocketID(iconf->port_id, &iconf->socket_id);
1644 SCLogError(
"%s: invalid socket id: %s", iconf->iface, rte_strerror(-retval));
1648 struct rte_eth_dev_info dev_info = { 0 };
1649 retval = rte_eth_dev_info_get(iconf->port_id, &dev_info);
1651 SCLogError(
"%s: getting device info failed: %s", iconf->iface, rte_strerror(-retval));
1655 if (iconf->nb_rx_queues > dev_info.max_rx_queues) {
1656 SCLogError(
"%s: configured RX queues %u is higher than device maximum (%" PRIu16
")",
1657 iconf->iface, iconf->nb_rx_queues, dev_info.max_rx_queues);
1661 if (iconf->nb_tx_queues > dev_info.max_tx_queues) {
1662 SCLogError(
"%s: configured TX queues %u is higher than device maximum (%" PRIu16
")",
1663 iconf->iface, iconf->nb_tx_queues, dev_info.max_tx_queues);
1667 retval = DeviceValidateMTU(iconf, &dev_info);
1671 struct rte_eth_conf port_conf = { 0 };
1672 DeviceInitPortConf(iconf, &dev_info, &port_conf);
1673 if (port_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM) {
1678 retval = rte_eth_dev_configure(
1679 iconf->port_id, iconf->nb_rx_queues, iconf->nb_tx_queues, &port_conf);
1681 SCLogError(
"%s: failed to configure the device: %s", iconf->iface, rte_strerror(-retval));
1685 retval = DeviceVerifyPostConfigure(iconf, &dev_info);
1689 uint16_t tmp_nb_rx_desc = iconf->nb_rx_desc;
1690 uint16_t tmp_nb_tx_desc = iconf->nb_tx_desc;
1691 retval = rte_eth_dev_adjust_nb_rx_tx_desc(
1692 iconf->port_id, &iconf->nb_rx_desc, &iconf->nb_tx_desc);
1694 SCLogError(
"%s: failed to adjust device queue descriptors: %s", iconf->iface,
1695 rte_strerror(-retval));
1697 }
else if (tmp_nb_rx_desc != iconf->nb_rx_desc || tmp_nb_tx_desc != iconf->nb_tx_desc) {
1698 SCLogWarning(
"%s: device queue descriptors adjusted (RX: from %u to %u, TX: from %u to %u)",
1699 iconf->iface, tmp_nb_rx_desc, iconf->nb_rx_desc, tmp_nb_tx_desc, iconf->nb_tx_desc);
1702 retval = iconf->flags &
DPDK_MULTICAST ? rte_eth_allmulticast_enable(iconf->port_id)
1703 : rte_eth_allmulticast_disable(iconf->port_id);
1704 if (retval == -ENOTSUP) {
1705 retval = rte_eth_allmulticast_get(iconf->port_id);
1709 SCLogWarning(
"%s: cannot configure allmulticast, the port is %sin allmulticast mode",
1710 iconf->iface, retval == 1 ?
"" :
"not ");
1711 }
else if (retval < 0) {
1712 SCLogError(
"%s: failed to get multicast mode: %s", iconf->iface, rte_strerror(-retval));
1715 }
else if (retval < 0) {
1716 SCLogError(
"%s: error when changing multicast setting: %s", iconf->iface,
1717 rte_strerror(-retval));
1721 retval = iconf->flags &
DPDK_PROMISC ? rte_eth_promiscuous_enable(iconf->port_id)
1722 : rte_eth_promiscuous_disable(iconf->port_id);
1723 if (retval == -ENOTSUP) {
1724 retval = rte_eth_promiscuous_get(iconf->port_id);
1727 SCLogError(
"%s: cannot configure promiscuous mode, the port is in %spromiscuous mode",
1728 iconf->iface, retval == 1 ?
"" :
"non-");
1730 }
else if (retval < 0) {
1732 "%s: failed to get promiscuous mode: %s", iconf->iface, rte_strerror(-retval));
1735 }
else if (retval < 0) {
1736 SCLogError(
"%s: error when changing promiscuous setting: %s", iconf->iface,
1737 rte_strerror(-retval));
1742 SCLogConfig(
"%s: setting MTU to %d", iconf->iface, iconf->mtu);
1743 retval = rte_eth_dev_set_mtu(iconf->port_id, iconf->mtu);
1744 if (retval == -ENOTSUP) {
1746 retval = rte_eth_dev_get_mtu(iconf->port_id, &iconf->mtu);
1748 SCLogError(
"%s: failed to retrieve MTU: %s", iconf->iface, rte_strerror(-retval));
1752 "%s: changing MTU is not supported, current MTU: %u", iconf->iface, iconf->mtu);
1753 }
else if (retval < 0) {
1755 "%s: failed to set MTU to %u: %s", iconf->iface, iconf->mtu, rte_strerror(-retval));
1759 retval = DeviceConfigureQueues(iconf, &dev_info, &port_conf);
1764 retval = DeviceConfigureIPS(iconf);
1772 static void *ParseDpdkConfigAndConfigureDevice(
const char *iface)
1776 if (iconf == NULL) {
1777 FatalError(
"DPDK configuration could not be parsed");
1780 retval = DeviceConfigure(iconf);
1781 if (retval == -EAGAIN) {
1783 retval = DeviceConfigure(iconf);
1787 iconf->DerefFunc(iconf);
1788 if (rte_eal_cleanup() != 0)
1789 FatalError(
"EAL cleanup failed: %s", rte_strerror(-retval));
1791 if (retval == -ENOMEM) {
1792 FatalError(
"%s: memory allocation failed - consider"
1793 "%s freeing up some memory.",
1795 rte_eal_has_hugepages() != 0 ?
" increasing the number of hugepages or" :
"");
1797 FatalError(
"%s: failed to configure", iface);
1806 iconf->workers_sync =
SCCalloc(1,
sizeof(*iconf->workers_sync));
1807 if (iconf->workers_sync == NULL) {
1808 FatalError(
"Failed to allocate memory for workers_sync");
1811 iconf->workers_sync->worker_cnt = iconf->threads;
1815 if (ldev_instance == NULL) {
1816 FatalError(
"Device %s is not registered as a live device", iface);
1818 for (int32_t i = 0; i < iconf->threads; i++) {
1819 ldev_instance->dpdk_vars = iconf->pkt_mempools;
1820 iconf->pkt_mempools = NULL;
1838 static int DPDKConfigGetThreadsCount(
void *conf)
1844 return dpdk_conf->threads;
1849 static int DPDKRunModeIsIPS(
void)
1852 const char dpdk_node_query[] =
"dpdk.interfaces";
1854 if (dpdk_node == NULL) {
1855 FatalError(
"Unable to get %s configuration node", dpdk_node_query);
1858 const char default_iface[] =
"default";
1861 bool has_ips =
false;
1862 bool has_ids =
false;
1863 for (
int ldev = 0; ldev < nlive; ldev++) {
1865 if (live_dev == NULL)
1866 FatalError(
"Unable to get device id %d from LiveDevice list", ldev);
1869 if (if_root == NULL) {
1870 if (if_default == NULL)
1871 FatalError(
"Unable to get %s or %s interface", live_dev, default_iface);
1873 if_root = if_default;
1876 const char *copymodestr = NULL;
1877 const char *copyifacestr = NULL;
1880 if (strcmp(copymodestr,
"ips") == 0) {
1889 if (has_ids && has_ips) {
1890 FatalError(
"Copy-mode of interface %s mixes with the previously set copy-modes "
1891 "(only IDS/TAP and IPS copy-mode combinations are allowed in DPDK",
1899 static int DPDKRunModeEnableIPS(
void)
1901 int r = DPDKRunModeIsIPS();
1917 "Workers DPDK mode, each thread does all"
1918 " tasks from acquisition to logging",
1943 SCLogDebug(
"RunModeIdsDpdkWorkers initialised");