suricata
runmode-dpdk.c
Go to the documentation of this file.
1 /* Copyright (C) 2021 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \ingroup dpdk
20  *
21  * @{
22  */
23 
24 /**
25  * \file
26  *
27  * \author Lukas Sismis <lukas.sismis@gmail.com>
28  *
29  * DPDK runmode
30  *
31  */
32 
33 #include "suricata-common.h"
34 #include "runmodes.h"
35 #include "runmode-dpdk.h"
36 #include "decode.h"
37 #include "source-dpdk.h"
38 #include "util-runmodes.h"
39 #include "util-byte.h"
40 #include "util-cpu.h"
41 #include "util-debug.h"
42 #include "util-device.h"
43 #include "util-dpdk.h"
44 #include "util-dpdk-i40e.h"
45 #include "util-dpdk-ice.h"
46 #include "util-dpdk-ixgbe.h"
47 #include "util-dpdk-bonding.h"
48 #include "util-time.h"
49 #include "util-conf.h"
50 #include "suricata.h"
51 #include "util-affinity.h"
52 
53 #ifdef HAVE_DPDK
54 
55 #define RSS_HKEY_LEN 40
56 // General purpose RSS key for symmetric bidirectional flow distribution
57 uint8_t rss_hkey[] = {
58  0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
59  0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
60  0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, // 40
61  0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, // 52
62 };
63 
64 // Calculates the closest multiple of y from x
65 #define ROUNDUP(x, y) ((((x) + ((y)-1)) / (y)) * (y))
66 
67 /* Maximum DPDK EAL parameters count. */
68 #define EAL_ARGS 48
69 
70 struct Arguments {
71  uint16_t capacity;
72  char **argv;
73  uint16_t argc;
74 };
75 
76 static char *AllocArgument(size_t arg_len);
77 static char *AllocAndSetArgument(const char *arg);
78 static char *AllocAndSetOption(const char *arg);
79 
80 static void ArgumentsInit(struct Arguments *args, unsigned capacity);
81 static void ArgumentsCleanup(struct Arguments *args);
82 static void ArgumentsAdd(struct Arguments *args, char *value);
83 static void ArgumentsAddOptionAndArgument(struct Arguments *args, const char *opt, const char *arg);
84 static void InitEal(void);
85 
86 static void ConfigSetIface(DPDKIfaceConfig *iconf, const char *entry_str);
87 static int ConfigSetThreads(DPDKIfaceConfig *iconf, const char *entry_str);
88 static int ConfigSetRxQueues(DPDKIfaceConfig *iconf, uint16_t nb_queues);
89 static int ConfigSetTxQueues(DPDKIfaceConfig *iconf, uint16_t nb_queues);
90 static int ConfigSetMempoolSize(DPDKIfaceConfig *iconf, intmax_t entry_int);
91 static int ConfigSetMempoolCacheSize(DPDKIfaceConfig *iconf, const char *entry_str);
92 static int ConfigSetRxDescriptors(DPDKIfaceConfig *iconf, intmax_t entry_int);
93 static int ConfigSetTxDescriptors(DPDKIfaceConfig *iconf, intmax_t entry_int);
94 static int ConfigSetMtu(DPDKIfaceConfig *iconf, intmax_t entry_int);
95 static bool ConfigSetPromiscuousMode(DPDKIfaceConfig *iconf, int entry_bool);
96 static bool ConfigSetMulticast(DPDKIfaceConfig *iconf, int entry_bool);
97 static int ConfigSetChecksumChecks(DPDKIfaceConfig *iconf, int entry_bool);
98 static int ConfigSetChecksumOffload(DPDKIfaceConfig *iconf, int entry_bool);
99 static int ConfigSetCopyIface(DPDKIfaceConfig *iconf, const char *entry_str);
100 static int ConfigSetCopyMode(DPDKIfaceConfig *iconf, const char *entry_str);
101 static int ConfigSetCopyIfaceSettings(DPDKIfaceConfig *iconf, const char *iface, const char *mode);
102 static void ConfigInit(DPDKIfaceConfig **iconf);
103 static int ConfigLoad(DPDKIfaceConfig *iconf, const char *iface);
104 static DPDKIfaceConfig *ConfigParse(const char *iface);
105 
106 static void DeviceInitPortConf(const DPDKIfaceConfig *iconf,
107  const struct rte_eth_dev_info *dev_info, struct rte_eth_conf *port_conf);
108 static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_dev_info *dev_info,
109  const struct rte_eth_conf *port_conf);
110 static int DeviceValidateOutIfaceConfig(DPDKIfaceConfig *iconf);
111 static int DeviceConfigureIPS(DPDKIfaceConfig *iconf);
112 static int DeviceConfigure(DPDKIfaceConfig *iconf);
113 static void *ParseDpdkConfigAndConfigureDevice(const char *iface);
114 static void DPDKDerefConfig(void *conf);
115 
116 #define DPDK_CONFIG_DEFAULT_THREADS "auto"
117 #define DPDK_CONFIG_DEFAULT_INTERRUPT_MODE false
118 #define DPDK_CONFIG_DEFAULT_MEMPOOL_SIZE 65535
119 #define DPDK_CONFIG_DEFAULT_MEMPOOL_CACHE_SIZE "auto"
120 #define DPDK_CONFIG_DEFAULT_RX_DESCRIPTORS 1024
121 #define DPDK_CONFIG_DEFAULT_TX_DESCRIPTORS 1024
122 #define DPDK_CONFIG_DEFAULT_RSS_HASH_FUNCTIONS RTE_ETH_RSS_IP
123 #define DPDK_CONFIG_DEFAULT_MTU 1500
124 #define DPDK_CONFIG_DEFAULT_PROMISCUOUS_MODE 1
125 #define DPDK_CONFIG_DEFAULT_MULTICAST_MODE 1
126 #define DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION 1
127 #define DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION_OFFLOAD 1
128 #define DPDK_CONFIG_DEFAULT_COPY_MODE "none"
129 #define DPDK_CONFIG_DEFAULT_COPY_INTERFACE "none"
130 
131 DPDKIfaceConfigAttributes dpdk_yaml = {
132  .threads = "threads",
133  .irq_mode = "interrupt-mode",
134  .promisc = "promisc",
135  .multicast = "multicast",
136  .checksum_checks = "checksum-checks",
137  .checksum_checks_offload = "checksum-checks-offload",
138  .mtu = "mtu",
139  .rss_hf = "rss-hash-functions",
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",
146 };
147 
148 static int GreatestDivisorUpTo(uint32_t num, uint32_t max_num)
149 {
150  for (int i = max_num; i >= 2; i--) {
151  if (num % i == 0) {
152  return i;
153  }
154  }
155  return 1;
156 }
157 
158 static char *AllocArgument(size_t arg_len)
159 {
160  SCEnter();
161  char *ptr;
162 
163  arg_len += 1; // null character
164  ptr = (char *)SCCalloc(arg_len, sizeof(char));
165  if (ptr == NULL)
166  FatalError("Could not allocate memory for an argument");
167 
168  SCReturnPtr(ptr, "char *");
169 }
170 
171 /**
172  * Allocates space for length of the given string and then copies contents
173  * @param arg String to set to the newly allocated space
174  * @return memory address if no error otherwise NULL (with errno set)
175  */
176 static char *AllocAndSetArgument(const char *arg)
177 {
178  SCEnter();
179  if (arg == NULL)
180  FatalError("Passed argument is NULL in DPDK config initialization");
181 
182  char *ptr;
183  size_t arg_len = strlen(arg);
184 
185  ptr = AllocArgument(arg_len);
186  strlcpy(ptr, arg, arg_len + 1);
187  SCReturnPtr(ptr, "char *");
188 }
189 
190 static char *AllocAndSetOption(const char *arg)
191 {
192  SCEnter();
193  if (arg == NULL)
194  FatalError("Passed option is NULL in DPDK config initialization");
195 
196  char *ptr = NULL;
197  size_t arg_len = strlen(arg);
198  uint8_t is_long_arg = arg_len > 1;
199  const char *dash_prefix = is_long_arg ? "--" : "-";
200  size_t full_len = arg_len + strlen(dash_prefix);
201 
202  ptr = AllocArgument(full_len);
203  strlcpy(ptr, dash_prefix, strlen(dash_prefix) + 1);
204  strlcat(ptr, arg, full_len + 1);
205  SCReturnPtr(ptr, "char *");
206 }
207 
208 static void ArgumentsInit(struct Arguments *args, unsigned capacity)
209 {
210  SCEnter();
211  args->argv = SCCalloc(capacity, sizeof(*args->argv)); // alloc array of pointers
212  if (args->argv == NULL)
213  FatalError("Could not allocate memory for Arguments structure");
214 
215  args->capacity = capacity;
216  args->argc = 0;
217  SCReturn;
218 }
219 
220 static void ArgumentsCleanup(struct Arguments *args)
221 {
222  SCEnter();
223  for (int i = 0; i < args->argc; i++) {
224  if (args->argv[i] != NULL) {
225  SCFree(args->argv[i]);
226  args->argv[i] = NULL;
227  }
228  }
229 
230  SCFree(args->argv);
231  args->argv = NULL;
232  args->argc = 0;
233  args->capacity = 0;
234 }
235 
236 static void ArgumentsAdd(struct Arguments *args, char *value)
237 {
238  SCEnter();
239  if (args->argc + 1 > args->capacity)
240  FatalError("No capacity for more arguments (Max: %" PRIu32 ")", EAL_ARGS);
241 
242  args->argv[args->argc++] = value;
243  SCReturn;
244 }
245 
246 static void ArgumentsAddOptionAndArgument(struct Arguments *args, const char *opt, const char *arg)
247 {
248  SCEnter();
249  char *option;
250  char *argument;
251 
252  option = AllocAndSetOption(opt);
253  ArgumentsAdd(args, option);
254 
255  // Empty argument could mean option only (e.g. --no-huge)
256  if (arg == NULL || arg[0] == '\0')
257  SCReturn;
258 
259  argument = AllocAndSetArgument(arg);
260  ArgumentsAdd(args, argument);
261  SCReturn;
262 }
263 
264 static void InitEal(void)
265 {
266  SCEnter();
267  int retval;
268  ConfNode *param;
269  const ConfNode *eal_params = ConfGetNode("dpdk.eal-params");
270  struct Arguments args;
271  char **eal_argv;
272 
273  if (eal_params == NULL) {
274  FatalError("DPDK EAL parameters not found in the config");
275  }
276 
277  ArgumentsInit(&args, EAL_ARGS);
278  ArgumentsAdd(&args, AllocAndSetArgument("suricata"));
279 
280  TAILQ_FOREACH (param, &eal_params->head, next) {
281  if (ConfNodeIsSequence(param)) {
282  const char *key = param->name;
283  ConfNode *val;
284  TAILQ_FOREACH (val, &param->head, next) {
285  ArgumentsAddOptionAndArgument(&args, key, (const char *)val->val);
286  }
287  continue;
288  }
289  ArgumentsAddOptionAndArgument(&args, param->name, param->val);
290  }
291 
292  // creating a shallow copy for cleanup because rte_eal_init changes array contents
293  eal_argv = SCCalloc(args.argc, sizeof(*args.argv));
294  if (eal_argv == NULL) {
295  FatalError("Failed to allocate memory for the array of DPDK EAL arguments");
296  }
297  memcpy(eal_argv, args.argv, args.argc * sizeof(*args.argv));
298 
299  rte_log_set_global_level(RTE_LOG_WARNING);
300  retval = rte_eal_init(args.argc, eal_argv);
301 
302  ArgumentsCleanup(&args);
303  SCFree(eal_argv);
304 
305  if (retval < 0) { // retval bound to the result of rte_eal_init
306  FatalError("DPDK EAL initialization error: %s", rte_strerror(-retval));
307  }
309 }
310 
311 static void DPDKDerefConfig(void *conf)
312 {
313  SCEnter();
314  DPDKIfaceConfig *iconf = (DPDKIfaceConfig *)conf;
315 
316  if (SC_ATOMIC_SUB(iconf->ref, 1) == 1) {
317  if (iconf->pkt_mempool != NULL) {
318  rte_mempool_free(iconf->pkt_mempool);
319  }
320 
321  SCFree(iconf);
322  }
323  SCReturn;
324 }
325 
326 static void ConfigInit(DPDKIfaceConfig **iconf)
327 {
328  SCEnter();
329  DPDKIfaceConfig *ptr = NULL;
330  ptr = SCCalloc(1, sizeof(DPDKIfaceConfig));
331  if (ptr == NULL)
332  FatalError("Could not allocate memory for DPDKIfaceConfig");
333 
334  ptr->pkt_mempool = NULL;
335  ptr->out_port_id = -1; // make sure no port is set
336  SC_ATOMIC_INIT(ptr->ref);
337  (void)SC_ATOMIC_ADD(ptr->ref, 1);
338  ptr->DerefFunc = DPDKDerefConfig;
339  ptr->flags = 0;
340 
341  *iconf = ptr;
342  SCReturn;
343 }
344 
345 static void ConfigSetIface(DPDKIfaceConfig *iconf, const char *entry_str)
346 {
347  SCEnter();
348  int retval;
349 
350  if (entry_str == NULL || entry_str[0] == '\0')
351  FatalError("Interface name in DPDK config is NULL or empty");
352 
353  retval = rte_eth_dev_get_port_by_name(entry_str, &iconf->port_id);
354  if (retval < 0)
355  FatalError("%s: interface not found: %s", entry_str, rte_strerror(-retval));
356 
357  strlcpy(iconf->iface, entry_str, sizeof(iconf->iface));
358  SCReturn;
359 }
360 
361 static int ConfigSetThreads(DPDKIfaceConfig *iconf, const char *entry_str)
362 {
363  SCEnter();
364  static int32_t remaining_auto_cpus = -1;
366  SCLogError("DPDK runmode requires configured thread affinity");
367  SCReturnInt(-EINVAL);
368  }
369 
370  ThreadsAffinityType *wtaf = GetAffinityTypeFromName("worker-cpu-set");
371  if (wtaf == NULL) {
372  SCLogError("Specify worker-cpu-set list in the threading section");
373  SCReturnInt(-EINVAL);
374  }
375  ThreadsAffinityType *mtaf = GetAffinityTypeFromName("management-cpu-set");
376  if (mtaf == NULL) {
377  SCLogError("Specify management-cpu-set list in the threading section");
378  SCReturnInt(-EINVAL);
379  }
380  uint32_t sched_cpus = UtilAffinityGetAffinedCPUNum(wtaf);
381  if (sched_cpus == UtilCpuGetNumProcessorsOnline()) {
382  SCLogWarning(
383  "\"all\" specified in worker CPU cores affinity, excluding management threads");
384  UtilAffinityCpusExclude(wtaf, mtaf);
385  sched_cpus = UtilAffinityGetAffinedCPUNum(wtaf);
386  }
387 
388  if (sched_cpus == 0) {
389  SCLogError("No worker CPU cores with configured affinity were configured");
390  SCReturnInt(-EINVAL);
391  } else if (UtilAffinityCpusOverlap(wtaf, mtaf) != 0) {
392  SCLogWarning("Worker threads should not overlap with management threads in the CPU core "
393  "affinity configuration");
394  }
395 
396  const char *active_runmode = RunmodeGetActive();
397  if (active_runmode && !strcmp("single", active_runmode)) {
398  iconf->threads = 1;
399  SCReturnInt(0);
400  }
401 
402  if (entry_str == NULL) {
403  SCLogError("Number of threads for interface \"%s\" not specified", iconf->iface);
404  SCReturnInt(-EINVAL);
405  }
406 
407  if (strcmp(entry_str, "auto") == 0) {
408  iconf->threads = (uint16_t)sched_cpus / LiveGetDeviceCount();
409  if (iconf->threads == 0) {
410  SCLogError("Not enough worker CPU cores with affinity were configured");
411  SCReturnInt(-ERANGE);
412  }
413 
414  if (remaining_auto_cpus > 0) {
415  iconf->threads++;
416  remaining_auto_cpus--;
417  } else if (remaining_auto_cpus == -1) {
418  remaining_auto_cpus = (int32_t)sched_cpus % LiveGetDeviceCount();
419  if (remaining_auto_cpus > 0) {
420  iconf->threads++;
421  remaining_auto_cpus--;
422  }
423  }
424  SCLogConfig("%s: auto-assigned %u threads", iconf->iface, iconf->threads);
425  SCReturnInt(0);
426  }
427 
428  if (StringParseInt32(&iconf->threads, 10, 0, entry_str) < 0) {
429  SCLogError("Threads entry for interface %s contain non-numerical characters - \"%s\"",
430  iconf->iface, entry_str);
431  SCReturnInt(-EINVAL);
432  }
433 
434  if (iconf->threads <= 0) {
435  SCLogError("%s: positive number of threads required", iconf->iface);
436  SCReturnInt(-ERANGE);
437  }
438 
439  SCReturnInt(0);
440 }
441 
442 static bool ConfigSetInterruptMode(DPDKIfaceConfig *iconf, bool enable)
443 {
444  SCEnter();
445  if (enable)
446  iconf->flags |= DPDK_IRQ_MODE;
447 
448  SCReturnBool(true);
449 }
450 
451 static int ConfigSetRxQueues(DPDKIfaceConfig *iconf, uint16_t nb_queues)
452 {
453  SCEnter();
454  iconf->nb_rx_queues = nb_queues;
455  if (iconf->nb_rx_queues < 1) {
456  SCLogError("%s: positive number of RX queues is required", iconf->iface);
457  SCReturnInt(-ERANGE);
458  }
459 
460  SCReturnInt(0);
461 }
462 
463 static int ConfigSetTxQueues(DPDKIfaceConfig *iconf, uint16_t nb_queues)
464 {
465  SCEnter();
466  iconf->nb_tx_queues = nb_queues;
467  if (iconf->nb_tx_queues < 1) {
468  SCLogError("%s: positive number of TX queues is required", iconf->iface);
469  SCReturnInt(-ERANGE);
470  }
471 
472  SCReturnInt(0);
473 }
474 
475 static int ConfigSetMempoolSize(DPDKIfaceConfig *iconf, intmax_t entry_int)
476 {
477  SCEnter();
478  if (entry_int <= 0) {
479  SCLogError("%s: positive memory pool size is required", iconf->iface);
480  SCReturnInt(-ERANGE);
481  } else if (entry_int > UINT32_MAX) {
482  SCLogError("%s: memory pool size cannot exceed %" PRIu32, iconf->iface, UINT32_MAX);
483  SCReturnInt(-ERANGE);
484  }
485 
486  iconf->mempool_size = entry_int;
487  SCReturnInt(0);
488 }
489 
490 static int ConfigSetMempoolCacheSize(DPDKIfaceConfig *iconf, const char *entry_str)
491 {
492  SCEnter();
493  if (entry_str == NULL || entry_str[0] == '\0' || strcmp(entry_str, "auto") == 0) {
494  // calculate the mempool size based on the mempool size (it needs to be already filled in)
495  // It is advised to have mempool cache size lower or equal to:
496  // RTE_MEMPOOL_CACHE_MAX_SIZE (by default 512) and "mempool-size / 1.5"
497  // and at the same time "mempool-size modulo cache_size == 0".
498  if (iconf->mempool_size == 0) {
499  SCLogError("%s: cannot calculate mempool cache size of a mempool with size %d",
500  iconf->iface, iconf->mempool_size);
501  SCReturnInt(-EINVAL);
502  }
503 
504  uint32_t max_cache_size = MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, iconf->mempool_size / 1.5);
505  iconf->mempool_cache_size = GreatestDivisorUpTo(iconf->mempool_size, max_cache_size);
506  SCReturnInt(0);
507  }
508 
509  if (StringParseUint32(&iconf->mempool_cache_size, 10, 0, entry_str) < 0) {
510  SCLogError("%s: mempool cache size entry contain non-numerical characters - \"%s\"",
511  iconf->iface, entry_str);
512  SCReturnInt(-EINVAL);
513  }
514 
515  if (iconf->mempool_cache_size <= 0 || iconf->mempool_cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE) {
516  SCLogError("%s: mempool cache size requires a positive number smaller than %" PRIu32,
517  iconf->iface, RTE_MEMPOOL_CACHE_MAX_SIZE);
518  SCReturnInt(-ERANGE);
519  }
520 
521  SCReturnInt(0);
522 }
523 
524 static int ConfigSetRxDescriptors(DPDKIfaceConfig *iconf, intmax_t entry_int)
525 {
526  SCEnter();
527  if (entry_int <= 0) {
528  SCLogError("%s: positive number of RX descriptors is required", iconf->iface);
529  SCReturnInt(-ERANGE);
530  } else if (entry_int > UINT16_MAX) {
531  SCLogError("%s: number of RX descriptors cannot exceed %" PRIu16, iconf->iface, UINT16_MAX);
532  SCReturnInt(-ERANGE);
533  }
534 
535  iconf->nb_rx_desc = entry_int;
536  SCReturnInt(0);
537 }
538 
539 static int ConfigSetTxDescriptors(DPDKIfaceConfig *iconf, intmax_t entry_int)
540 {
541  SCEnter();
542  if (entry_int <= 0) {
543  SCLogError("%s: positive number of TX descriptors is required", iconf->iface);
544  SCReturnInt(-ERANGE);
545  } else if (entry_int > UINT16_MAX) {
546  SCLogError("%s: number of TX descriptors cannot exceed %" PRIu16, iconf->iface, UINT16_MAX);
547  SCReturnInt(-ERANGE);
548  }
549 
550  iconf->nb_tx_desc = entry_int;
551  SCReturnInt(0);
552 }
553 
554 static int ConfigSetRSSHashFunctions(DPDKIfaceConfig *iconf, const char *entry_str)
555 {
556  SCEnter();
557  if (entry_str == NULL || entry_str[0] == '\0' || strcmp(entry_str, "auto") == 0) {
558  iconf->rss_hf = DPDK_CONFIG_DEFAULT_RSS_HASH_FUNCTIONS;
559  SCReturnInt(0);
560  }
561 
562  if (StringParseUint64(&iconf->rss_hf, 0, 0, entry_str) < 0) {
563  SCLogError("%s: RSS hash functions entry contain non-numerical characters - \"%s\"",
564  iconf->iface, entry_str);
565  SCReturnInt(-EINVAL);
566  }
567 
568  SCReturnInt(0);
569 }
570 
571 static int ConfigSetMtu(DPDKIfaceConfig *iconf, intmax_t entry_int)
572 {
573  SCEnter();
574  if (entry_int < RTE_ETHER_MIN_MTU || entry_int > RTE_ETHER_MAX_JUMBO_FRAME_LEN) {
575  SCLogError("%s: MTU size can only be between %" PRIu32 " and %" PRIu32, iconf->iface,
576  RTE_ETHER_MIN_MTU, RTE_ETHER_MAX_JUMBO_FRAME_LEN);
577  SCReturnInt(-ERANGE);
578  }
579 
580  iconf->mtu = entry_int;
581  SCReturnInt(0);
582 }
583 
584 static bool ConfigSetPromiscuousMode(DPDKIfaceConfig *iconf, int entry_bool)
585 {
586  SCEnter();
587  if (entry_bool)
588  iconf->flags |= DPDK_PROMISC;
589 
590  SCReturnBool(true);
591 }
592 
593 static bool ConfigSetMulticast(DPDKIfaceConfig *iconf, int entry_bool)
594 {
595  SCEnter();
596  if (entry_bool)
597  iconf->flags |= DPDK_MULTICAST; // enable
598 
599  SCReturnBool(true);
600 }
601 
602 static int ConfigSetChecksumChecks(DPDKIfaceConfig *iconf, int entry_bool)
603 {
604  SCEnter();
605  if (entry_bool)
606  iconf->checksum_mode = CHECKSUM_VALIDATION_ENABLE;
607 
608  SCReturnInt(0);
609 }
610 
611 static int ConfigSetChecksumOffload(DPDKIfaceConfig *iconf, int entry_bool)
612 {
613  SCEnter();
614  if (entry_bool)
615  iconf->flags |= DPDK_RX_CHECKSUM_OFFLOAD;
616 
617  SCReturnInt(0);
618 }
619 
620 static int ConfigSetCopyIface(DPDKIfaceConfig *iconf, const char *entry_str)
621 {
622  SCEnter();
623  int retval;
624 
625  if (entry_str == NULL || entry_str[0] == '\0' || strcmp(entry_str, "none") == 0) {
626  iconf->out_iface = NULL;
627  SCReturnInt(0);
628  }
629 
630  retval = rte_eth_dev_get_port_by_name(entry_str, &iconf->out_port_id);
631  if (retval < 0) {
632  SCLogError("%s: copy interface (%s) not found: %s", iconf->iface, entry_str,
633  rte_strerror(-retval));
634  SCReturnInt(retval);
635  }
636 
637  iconf->out_iface = entry_str;
638  SCReturnInt(0);
639 }
640 
641 static int ConfigSetCopyMode(DPDKIfaceConfig *iconf, const char *entry_str)
642 {
643  SCEnter();
644  if (entry_str == NULL) {
645  SCLogWarning("%s: no copy mode specified, changing to %s ", iconf->iface,
646  DPDK_CONFIG_DEFAULT_COPY_MODE);
647  entry_str = DPDK_CONFIG_DEFAULT_COPY_MODE;
648  }
649 
650  if (strcmp(entry_str, "none") != 0 && strcmp(entry_str, "tap") != 0 &&
651  strcmp(entry_str, "ips") != 0) {
652  SCLogWarning("%s: copy mode \"%s\" is not one of the possible values (none|tap|ips). "
653  "Changing to %s",
654  entry_str, iconf->iface, DPDK_CONFIG_DEFAULT_COPY_MODE);
655  entry_str = DPDK_CONFIG_DEFAULT_COPY_MODE;
656  }
657 
658  if (strcmp(entry_str, "none") == 0) {
659  iconf->copy_mode = DPDK_COPY_MODE_NONE;
660  } else if (strcmp(entry_str, "tap") == 0) {
661  iconf->copy_mode = DPDK_COPY_MODE_TAP;
662  } else if (strcmp(entry_str, "ips") == 0) {
663  iconf->copy_mode = DPDK_COPY_MODE_IPS;
664  }
665 
666  SCReturnInt(0);
667 }
668 
669 static int ConfigSetCopyIfaceSettings(DPDKIfaceConfig *iconf, const char *iface, const char *mode)
670 {
671  SCEnter();
672  int retval;
673 
674  retval = ConfigSetCopyIface(iconf, iface);
675  if (retval < 0)
676  SCReturnInt(retval);
677 
678  retval = ConfigSetCopyMode(iconf, mode);
679  if (retval < 0)
680  SCReturnInt(retval);
681 
682  if (iconf->copy_mode == DPDK_COPY_MODE_NONE) {
683  if (iconf->out_iface != NULL)
684  iconf->out_iface = NULL;
685  SCReturnInt(0);
686  }
687 
688  if (iconf->out_iface == NULL || strlen(iconf->out_iface) <= 0) {
689  SCLogError("%s: copy mode enabled but interface not set", iconf->iface);
690  SCReturnInt(-EINVAL);
691  }
692 
693  SCReturnInt(0);
694 }
695 
696 static int ConfigLoad(DPDKIfaceConfig *iconf, const char *iface)
697 {
698  SCEnter();
699  int retval;
700  ConfNode *if_root;
701  ConfNode *if_default;
702  const char *entry_str = NULL;
703  intmax_t entry_int = 0;
704  int entry_bool = 0;
705  const char *copy_iface_str = NULL;
706  const char *copy_mode_str = NULL;
707 
708  ConfigSetIface(iconf, iface);
709 
710  retval = ConfSetRootAndDefaultNodes("dpdk.interfaces", iconf->iface, &if_root, &if_default);
711  if (retval < 0) {
712  FatalError("failed to find DPDK configuration for the interface %s", iconf->iface);
713  }
714 
715  retval = ConfGetChildValueWithDefault(if_root, if_default, dpdk_yaml.threads, &entry_str) != 1
716  ? ConfigSetThreads(iconf, DPDK_CONFIG_DEFAULT_THREADS)
717  : ConfigSetThreads(iconf, entry_str);
718  if (retval < 0)
719  SCReturnInt(retval);
720 
721  bool irq_enable;
722  retval = ConfGetChildValueBoolWithDefault(if_root, if_default, dpdk_yaml.irq_mode, &entry_bool);
723  if (retval != 1) {
724  irq_enable = DPDK_CONFIG_DEFAULT_INTERRUPT_MODE;
725  } else {
726  irq_enable = entry_bool ? true : false;
727  }
728  retval = ConfigSetInterruptMode(iconf, irq_enable);
729  if (retval != true)
730  SCReturnInt(-EINVAL);
731 
732  // currently only mapping "1 thread == 1 RX (and 1 TX queue in IPS mode)" is supported
733  retval = ConfigSetRxQueues(iconf, (uint16_t)iconf->threads);
734  if (retval < 0)
735  SCReturnInt(retval);
736 
737  // currently only mapping "1 thread == 1 RX (and 1 TX queue in IPS mode)" is supported
738  retval = ConfigSetTxQueues(iconf, (uint16_t)iconf->threads);
739  if (retval < 0)
740  SCReturnInt(retval);
741 
743  if_root, if_default, dpdk_yaml.mempool_size, &entry_int) != 1
744  ? ConfigSetMempoolSize(iconf, DPDK_CONFIG_DEFAULT_MEMPOOL_SIZE)
745  : ConfigSetMempoolSize(iconf, entry_int);
746  if (retval < 0)
747  SCReturnInt(retval);
748 
750  if_root, if_default, dpdk_yaml.mempool_cache_size, &entry_str) != 1
751  ? ConfigSetMempoolCacheSize(iconf, DPDK_CONFIG_DEFAULT_MEMPOOL_CACHE_SIZE)
752  : ConfigSetMempoolCacheSize(iconf, entry_str);
753  if (retval < 0)
754  SCReturnInt(retval);
755 
757  if_root, if_default, dpdk_yaml.rx_descriptors, &entry_int) != 1
758  ? ConfigSetRxDescriptors(iconf, DPDK_CONFIG_DEFAULT_RX_DESCRIPTORS)
759  : ConfigSetRxDescriptors(iconf, entry_int);
760  if (retval < 0)
761  SCReturnInt(retval);
762 
764  if_root, if_default, dpdk_yaml.tx_descriptors, &entry_int) != 1
765  ? ConfigSetTxDescriptors(iconf, DPDK_CONFIG_DEFAULT_TX_DESCRIPTORS)
766  : ConfigSetTxDescriptors(iconf, entry_int);
767  if (retval < 0)
768  SCReturnInt(retval);
769 
770  retval = ConfGetChildValueIntWithDefault(if_root, if_default, dpdk_yaml.mtu, &entry_int) != 1
771  ? ConfigSetMtu(iconf, DPDK_CONFIG_DEFAULT_MTU)
772  : ConfigSetMtu(iconf, entry_int);
773  if (retval < 0)
774  SCReturnInt(retval);
775 
776  retval = ConfGetChildValueWithDefault(if_root, if_default, dpdk_yaml.rss_hf, &entry_str) != 1
777  ? ConfigSetRSSHashFunctions(iconf, NULL)
778  : ConfigSetRSSHashFunctions(iconf, entry_str);
779  if (retval < 0)
780  SCReturnInt(retval);
781 
783  if_root, if_default, dpdk_yaml.promisc, &entry_bool) != 1
784  ? ConfigSetPromiscuousMode(iconf, DPDK_CONFIG_DEFAULT_PROMISCUOUS_MODE)
785  : ConfigSetPromiscuousMode(iconf, entry_bool);
786  if (retval != true)
787  SCReturnInt(-EINVAL);
788 
790  if_root, if_default, dpdk_yaml.multicast, &entry_bool) != 1
791  ? ConfigSetMulticast(iconf, DPDK_CONFIG_DEFAULT_MULTICAST_MODE)
792  : ConfigSetMulticast(iconf, entry_bool);
793  if (retval != true)
794  SCReturnInt(-EINVAL);
795 
797  if_root, if_default, dpdk_yaml.checksum_checks, &entry_bool) != 1
798  ? ConfigSetChecksumChecks(iconf, DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION)
799  : ConfigSetChecksumChecks(iconf, entry_bool);
800  if (retval < 0)
801  SCReturnInt(retval);
802 
804  if_root, if_default, dpdk_yaml.checksum_checks_offload, &entry_bool) != 1
805  ? ConfigSetChecksumOffload(
806  iconf, DPDK_CONFIG_DEFAULT_CHECKSUM_VALIDATION_OFFLOAD)
807  : ConfigSetChecksumOffload(iconf, entry_bool);
808  if (retval < 0)
809  SCReturnInt(retval);
810 
811  retval = ConfGetChildValueWithDefault(if_root, if_default, dpdk_yaml.copy_mode, &copy_mode_str);
812  if (retval != 1)
813  SCReturnInt(-ENOENT);
814  if (retval < 0)
815  SCReturnInt(retval);
816 
818  if_root, if_default, dpdk_yaml.copy_iface, &copy_iface_str);
819  if (retval != 1)
820  SCReturnInt(-ENOENT);
821  if (retval < 0)
822  SCReturnInt(retval);
823 
824  retval = ConfigSetCopyIfaceSettings(iconf, copy_iface_str, copy_mode_str);
825  if (retval < 0)
826  SCReturnInt(retval);
827 
828  SCReturnInt(0);
829 }
830 
831 static int32_t ConfigValidateThreads(uint16_t iface_threads)
832 {
833  static uint32_t total_cpus = 0;
834  total_cpus += iface_threads;
835  ThreadsAffinityType *wtaf = GetAffinityTypeFromName("worker-cpu-set");
836  if (wtaf == NULL) {
837  SCLogError("Specify worker-cpu-set list in the threading section");
838  return -1;
839  }
840  if (total_cpus > UtilAffinityGetAffinedCPUNum(wtaf)) {
841  SCLogError("Interfaces requested more cores than configured in the threading section "
842  "(requested %d configured %d",
843  total_cpus, UtilAffinityGetAffinedCPUNum(wtaf));
844  return -1;
845  }
846 
847  return 0;
848 }
849 
850 static DPDKIfaceConfig *ConfigParse(const char *iface)
851 {
852  SCEnter();
853  int retval;
854  DPDKIfaceConfig *iconf = NULL;
855  if (iface == NULL)
856  FatalError("DPDK interface is NULL");
857 
858  ConfigInit(&iconf);
859  retval = ConfigLoad(iconf, iface);
860  if (retval < 0 || ConfigValidateThreads(iconf->threads) != 0) {
861  iconf->DerefFunc(iconf);
862  SCReturnPtr(NULL, "void *");
863  }
864 
865  SCReturnPtr(iconf, "DPDKIfaceConfig *");
866 }
867 
868 static void DeviceSetPMDSpecificRSS(struct rte_eth_rss_conf *rss_conf, const char *driver_name)
869 {
870  // RSS is configured in a specific way for a driver i40e and DPDK version <= 19.xx
871  if (strcmp(driver_name, "net_i40e") == 0)
872  i40eDeviceSetRSSConf(rss_conf);
873  if (strcmp(driver_name, "net_ice") == 0)
874  iceDeviceSetRSSConf(rss_conf);
875  if (strcmp(driver_name, "net_ixgbe") == 0)
876  ixgbeDeviceSetRSSHashFunction(&rss_conf->rss_hf);
877  if (strcmp(driver_name, "net_e1000_igb") == 0)
878  rss_conf->rss_hf = (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_IPV6_EX);
879 }
880 
881 // Returns -1 if no bit is set
882 static int GetFirstSetBitPosition(uint64_t bits)
883 {
884  for (uint64_t i = 0; i < 64; i++) {
885  if (bits & BIT_U64(i))
886  return i;
887  }
888  return -1;
889 }
890 
891 static void DumpRSSFlags(const uint64_t requested, const uint64_t actual)
892 {
893  SCLogConfig("REQUESTED (groups):");
894 
895  SCLogConfig(
896  "RTE_ETH_RSS_IP %sset", ((requested & RTE_ETH_RSS_IP) == RTE_ETH_RSS_IP) ? "" : "NOT ");
897  SCLogConfig("RTE_ETH_RSS_TCP %sset",
898  ((requested & RTE_ETH_RSS_TCP) == RTE_ETH_RSS_TCP) ? "" : "NOT ");
899  SCLogConfig("RTE_ETH_RSS_UDP %sset",
900  ((requested & RTE_ETH_RSS_UDP) == RTE_ETH_RSS_UDP) ? "" : "NOT ");
901  SCLogConfig("RTE_ETH_RSS_SCTP %sset",
902  ((requested & RTE_ETH_RSS_SCTP) == RTE_ETH_RSS_SCTP) ? "" : "NOT ");
903  SCLogConfig("RTE_ETH_RSS_TUNNEL %sset",
904  ((requested & RTE_ETH_RSS_TUNNEL) == RTE_ETH_RSS_TUNNEL) ? "" : "NOT ");
905 
906  SCLogConfig("REQUESTED (individual):");
907  SCLogConfig("RTE_ETH_RSS_IPV4 (Bit position: %d) %sset",
908  GetFirstSetBitPosition(RTE_ETH_RSS_IPV4), (requested & RTE_ETH_RSS_IPV4) ? "" : "NOT ");
909  SCLogConfig("RTE_ETH_RSS_FRAG_IPV4 (Bit position: %d) %sset",
910  GetFirstSetBitPosition(RTE_ETH_RSS_FRAG_IPV4),
911  (requested & RTE_ETH_RSS_FRAG_IPV4) ? "" : "NOT ");
912  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV4_TCP (Bit position: %d) %sset",
913  GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_TCP),
914  (requested & RTE_ETH_RSS_NONFRAG_IPV4_TCP) ? "" : "NOT ");
915  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV4_UDP (Bit position: %d) %sset",
916  GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_UDP),
917  (requested & RTE_ETH_RSS_NONFRAG_IPV4_UDP) ? "" : "NOT ");
918  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV4_SCTP (Bit position: %d) %sset",
919  GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_SCTP),
920  (requested & RTE_ETH_RSS_NONFRAG_IPV4_SCTP) ? "" : "NOT ");
921  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV4_OTHER (Bit position: %d) %sset",
922  GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV4_OTHER),
923  (requested & RTE_ETH_RSS_NONFRAG_IPV4_OTHER) ? "" : "NOT ");
924  SCLogConfig("RTE_ETH_RSS_IPV6 (Bit position: %d) %sset",
925  GetFirstSetBitPosition(RTE_ETH_RSS_IPV6), (requested & RTE_ETH_RSS_IPV6) ? "" : "NOT ");
926  SCLogConfig("RTE_ETH_RSS_FRAG_IPV6 (Bit position: %d) %sset",
927  GetFirstSetBitPosition(RTE_ETH_RSS_FRAG_IPV6),
928  (requested & RTE_ETH_RSS_FRAG_IPV6) ? "" : "NOT ");
929  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV6_TCP (Bit position: %d) %sset",
930  GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_TCP),
931  (requested & RTE_ETH_RSS_NONFRAG_IPV6_TCP) ? "" : "NOT ");
932  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV6_UDP (Bit position: %d) %sset",
933  GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_UDP),
934  (requested & RTE_ETH_RSS_NONFRAG_IPV6_UDP) ? "" : "NOT ");
935  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV6_SCTP (Bit position: %d) %sset",
936  GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_SCTP),
937  (requested & RTE_ETH_RSS_NONFRAG_IPV6_SCTP) ? "" : "NOT ");
938  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV6_OTHER (Bit position: %d) %sset",
939  GetFirstSetBitPosition(RTE_ETH_RSS_NONFRAG_IPV6_OTHER),
940  (requested & RTE_ETH_RSS_NONFRAG_IPV6_OTHER) ? "" : "NOT ");
941 
942  SCLogConfig("RTE_ETH_RSS_L2_PAYLOAD (Bit position: %d) %sset",
943  GetFirstSetBitPosition(RTE_ETH_RSS_L2_PAYLOAD),
944  (requested & RTE_ETH_RSS_L2_PAYLOAD) ? "" : "NOT ");
945  SCLogConfig("RTE_ETH_RSS_IPV6_EX (Bit position: %d) %sset",
946  GetFirstSetBitPosition(RTE_ETH_RSS_IPV6_EX),
947  (requested & RTE_ETH_RSS_IPV6_EX) ? "" : "NOT ");
948  SCLogConfig("RTE_ETH_RSS_IPV6_TCP_EX (Bit position: %d) %sset",
949  GetFirstSetBitPosition(RTE_ETH_RSS_IPV6_TCP_EX),
950  (requested & RTE_ETH_RSS_IPV6_TCP_EX) ? "" : "NOT ");
951  SCLogConfig("RTE_ETH_RSS_IPV6_UDP_EX (Bit position: %d) %sset",
952  GetFirstSetBitPosition(RTE_ETH_RSS_IPV6_UDP_EX),
953  (requested & RTE_ETH_RSS_IPV6_UDP_EX) ? "" : "NOT ");
954 
955  SCLogConfig("RTE_ETH_RSS_PORT (Bit position: %d) %sset",
956  GetFirstSetBitPosition(RTE_ETH_RSS_PORT), (requested & RTE_ETH_RSS_PORT) ? "" : "NOT ");
957  SCLogConfig("RTE_ETH_RSS_VXLAN (Bit position: %d) %sset",
958  GetFirstSetBitPosition(RTE_ETH_RSS_VXLAN),
959  (requested & RTE_ETH_RSS_VXLAN) ? "" : "NOT ");
960  SCLogConfig("RTE_ETH_RSS_NVGRE (Bit position: %d) %sset",
961  GetFirstSetBitPosition(RTE_ETH_RSS_NVGRE),
962  (requested & RTE_ETH_RSS_NVGRE) ? "" : "NOT ");
963  SCLogConfig("RTE_ETH_RSS_GTPU (Bit position: %d) %sset",
964  GetFirstSetBitPosition(RTE_ETH_RSS_GTPU), (requested & RTE_ETH_RSS_GTPU) ? "" : "NOT ");
965 
966  SCLogConfig("RTE_ETH_RSS_L3_SRC_ONLY (Bit position: %d) %sset",
967  GetFirstSetBitPosition(RTE_ETH_RSS_L3_SRC_ONLY),
968  (requested & RTE_ETH_RSS_L3_SRC_ONLY) ? "" : "NOT ");
969  SCLogConfig("RTE_ETH_RSS_L3_DST_ONLY (Bit position: %d) %sset",
970  GetFirstSetBitPosition(RTE_ETH_RSS_L3_DST_ONLY),
971  (requested & RTE_ETH_RSS_L3_DST_ONLY) ? "" : "NOT ");
972  SCLogConfig("RTE_ETH_RSS_L4_SRC_ONLY (Bit position: %d) %sset",
973  GetFirstSetBitPosition(RTE_ETH_RSS_L4_SRC_ONLY),
974  (requested & RTE_ETH_RSS_L4_SRC_ONLY) ? "" : "NOT ");
975  SCLogConfig("RTE_ETH_RSS_L4_DST_ONLY (Bit position: %d) %sset",
976  GetFirstSetBitPosition(RTE_ETH_RSS_L4_DST_ONLY),
977  (requested & RTE_ETH_RSS_L4_DST_ONLY) ? "" : "NOT ");
978  SCLogConfig("ACTUAL (group):");
979  SCLogConfig(
980  "RTE_ETH_RSS_IP %sset", ((actual & RTE_ETH_RSS_IP) == RTE_ETH_RSS_IP) ? "" : "NOT ");
981  SCLogConfig(
982  "RTE_ETH_RSS_TCP %sset", ((actual & RTE_ETH_RSS_TCP) == RTE_ETH_RSS_TCP) ? "" : "NOT ");
983  SCLogConfig(
984  "RTE_ETH_RSS_UDP %sset", ((actual & RTE_ETH_RSS_UDP) == RTE_ETH_RSS_UDP) ? "" : "NOT ");
985  SCLogConfig("RTE_ETH_RSS_SCTP %sset",
986  ((actual & RTE_ETH_RSS_SCTP) == RTE_ETH_RSS_SCTP) ? "" : "NOT ");
987  SCLogConfig("RTE_ETH_RSS_TUNNEL %sset",
988  ((actual & RTE_ETH_RSS_TUNNEL) == RTE_ETH_RSS_TUNNEL) ? "" : "NOT ");
989 
990  SCLogConfig("ACTUAL (individual flags):");
991  SCLogConfig("RTE_ETH_RSS_IPV4 %sset", (actual & RTE_ETH_RSS_IPV4) ? "" : "NOT ");
992  SCLogConfig("RTE_ETH_RSS_FRAG_IPV4 %sset", (actual & RTE_ETH_RSS_FRAG_IPV4) ? "" : "NOT ");
993  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV4_TCP %sset",
994  (actual & RTE_ETH_RSS_NONFRAG_IPV4_TCP) ? "" : "NOT ");
995  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV4_UDP %sset",
996  (actual & RTE_ETH_RSS_NONFRAG_IPV4_UDP) ? "" : "NOT ");
997  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV4_SCTP %sset",
998  (actual & RTE_ETH_RSS_NONFRAG_IPV4_SCTP) ? "" : "NOT ");
999  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV4_OTHER %sset",
1000  (actual & RTE_ETH_RSS_NONFRAG_IPV4_OTHER) ? "" : "NOT ");
1001  SCLogConfig("RTE_ETH_RSS_IPV6 %sset", (actual & RTE_ETH_RSS_IPV6) ? "" : "NOT ");
1002  SCLogConfig("RTE_ETH_RSS_FRAG_IPV6 %sset", (actual & RTE_ETH_RSS_FRAG_IPV6) ? "" : "NOT ");
1003  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV6_TCP %sset",
1004  (actual & RTE_ETH_RSS_NONFRAG_IPV6_TCP) ? "" : "NOT ");
1005  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV6_UDP %sset",
1006  (actual & RTE_ETH_RSS_NONFRAG_IPV6_UDP) ? "" : "NOT ");
1007  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV6_SCTP %sset",
1008  (actual & RTE_ETH_RSS_NONFRAG_IPV6_SCTP) ? "" : "NOT ");
1009  SCLogConfig("RTE_ETH_RSS_NONFRAG_IPV6_OTHER %sset",
1010  (actual & RTE_ETH_RSS_NONFRAG_IPV6_OTHER) ? "" : "NOT ");
1011 
1012  SCLogConfig("RTE_ETH_RSS_L2_PAYLOAD %sset", (actual & RTE_ETH_RSS_L2_PAYLOAD) ? "" : "NOT ");
1013  SCLogConfig("RTE_ETH_RSS_IPV6_EX %sset", (actual & RTE_ETH_RSS_IPV6_EX) ? "" : "NOT ");
1014  SCLogConfig("RTE_ETH_RSS_IPV6_TCP_EX %sset", (actual & RTE_ETH_RSS_IPV6_TCP_EX) ? "" : "NOT ");
1015  SCLogConfig("RTE_ETH_RSS_IPV6_UDP_EX %sset", (actual & RTE_ETH_RSS_IPV6_UDP_EX) ? "" : "NOT ");
1016 
1017  SCLogConfig("RTE_ETH_RSS_PORT %sset", (actual & RTE_ETH_RSS_PORT) ? "" : "NOT ");
1018  SCLogConfig("RTE_ETH_RSS_VXLAN %sset", (actual & RTE_ETH_RSS_VXLAN) ? "" : "NOT ");
1019  SCLogConfig("RTE_ETH_RSS_NVGRE %sset", (actual & RTE_ETH_RSS_NVGRE) ? "" : "NOT ");
1020  SCLogConfig("RTE_ETH_RSS_GTPU %sset", (actual & RTE_ETH_RSS_GTPU) ? "" : "NOT ");
1021 
1022  SCLogConfig("RTE_ETH_RSS_L3_SRC_ONLY %sset", (actual & RTE_ETH_RSS_L3_SRC_ONLY) ? "" : "NOT ");
1023  SCLogConfig("RTE_ETH_RSS_L3_DST_ONLY %sset", (actual & RTE_ETH_RSS_L3_DST_ONLY) ? "" : "NOT ");
1024  SCLogConfig("RTE_ETH_RSS_L4_SRC_ONLY %sset", (actual & RTE_ETH_RSS_L4_SRC_ONLY) ? "" : "NOT ");
1025  SCLogConfig("RTE_ETH_RSS_L4_DST_ONLY %sset", (actual & RTE_ETH_RSS_L4_DST_ONLY) ? "" : "NOT ");
1026 }
1027 
1028 static void DumpRXOffloadCapabilities(const uint64_t rx_offld_capa)
1029 {
1030  SCLogConfig("RTE_ETH_RX_OFFLOAD_VLAN_STRIP - %savailable",
1031  rx_offld_capa & RTE_ETH_RX_OFFLOAD_VLAN_STRIP ? "" : "NOT ");
1032  SCLogConfig("RTE_ETH_RX_OFFLOAD_IPV4_CKSUM - %savailable",
1033  rx_offld_capa & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM ? "" : "NOT ");
1034  SCLogConfig("RTE_ETH_RX_OFFLOAD_UDP_CKSUM - %savailable",
1035  rx_offld_capa & RTE_ETH_RX_OFFLOAD_UDP_CKSUM ? "" : "NOT ");
1036  SCLogConfig("RTE_ETH_RX_OFFLOAD_TCP_CKSUM - %savailable",
1037  rx_offld_capa & RTE_ETH_RX_OFFLOAD_TCP_CKSUM ? "" : "NOT ");
1038  SCLogConfig("RTE_ETH_RX_OFFLOAD_TCP_LRO - %savailable",
1039  rx_offld_capa & RTE_ETH_RX_OFFLOAD_TCP_LRO ? "" : "NOT ");
1040  SCLogConfig("RTE_ETH_RX_OFFLOAD_QINQ_STRIP - %savailable",
1041  rx_offld_capa & RTE_ETH_RX_OFFLOAD_QINQ_STRIP ? "" : "NOT ");
1042  SCLogConfig("RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM - %savailable",
1043  rx_offld_capa & RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM ? "" : "NOT ");
1044  SCLogConfig("RTE_ETH_RX_OFFLOAD_MACSEC_STRIP - %savailable",
1045  rx_offld_capa & RTE_ETH_RX_OFFLOAD_MACSEC_STRIP ? "" : "NOT ");
1046 #if RTE_VERSION < RTE_VERSION_NUM(22, 11, 0, 0)
1047  SCLogConfig("RTE_ETH_RX_OFFLOAD_HEADER_SPLIT - %savailable",
1048  rx_offld_capa & RTE_ETH_RX_OFFLOAD_HEADER_SPLIT ? "" : "NOT ");
1049 #endif
1050  SCLogConfig("RTE_ETH_RX_OFFLOAD_VLAN_FILTER - %savailable",
1051  rx_offld_capa & RTE_ETH_RX_OFFLOAD_VLAN_FILTER ? "" : "NOT ");
1052  SCLogConfig("RTE_ETH_RX_OFFLOAD_VLAN_EXTEND - %savailable",
1053  rx_offld_capa & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND ? "" : "NOT ");
1054  SCLogConfig("RTE_ETH_RX_OFFLOAD_SCATTER - %savailable",
1055  rx_offld_capa & RTE_ETH_RX_OFFLOAD_SCATTER ? "" : "NOT ");
1056  SCLogConfig("RTE_ETH_RX_OFFLOAD_TIMESTAMP - %savailable",
1057  rx_offld_capa & RTE_ETH_RX_OFFLOAD_TIMESTAMP ? "" : "NOT ");
1058  SCLogConfig("RTE_ETH_RX_OFFLOAD_SECURITY - %savailable",
1059  rx_offld_capa & RTE_ETH_RX_OFFLOAD_SECURITY ? "" : "NOT ");
1060  SCLogConfig("RTE_ETH_RX_OFFLOAD_KEEP_CRC - %savailable",
1061  rx_offld_capa & RTE_ETH_RX_OFFLOAD_KEEP_CRC ? "" : "NOT ");
1062  SCLogConfig("RTE_ETH_RX_OFFLOAD_SCTP_CKSUM - %savailable",
1063  rx_offld_capa & RTE_ETH_RX_OFFLOAD_SCTP_CKSUM ? "" : "NOT ");
1064  SCLogConfig("RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM - %savailable",
1065  rx_offld_capa & RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM ? "" : "NOT ");
1066  SCLogConfig("RTE_ETH_RX_OFFLOAD_RSS_HASH - %savailable",
1067  rx_offld_capa & RTE_ETH_RX_OFFLOAD_RSS_HASH ? "" : "NOT ");
1068 #if RTE_VERSION >= RTE_VERSION_NUM(20, 11, 0, 0)
1069  SCLogConfig("RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT - %savailable",
1070  rx_offld_capa & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT ? "" : "NOT ");
1071 #endif
1072 }
1073 
1074 static int DeviceValidateMTU(const DPDKIfaceConfig *iconf, const struct rte_eth_dev_info *dev_info)
1075 {
1076  SCEnter();
1077  if (iconf->mtu > dev_info->max_mtu || iconf->mtu < dev_info->min_mtu) {
1078  SCLogError("%s: MTU out of bounds. "
1079  "Min MTU: %" PRIu16 " Max MTU: %" PRIu16,
1080  iconf->iface, dev_info->min_mtu, dev_info->max_mtu);
1081  SCReturnInt(-ERANGE);
1082  }
1083 
1084 #if RTE_VERSION < RTE_VERSION_NUM(21, 11, 0, 0)
1085  // check if jumbo frames are set and are available
1086  if (iconf->mtu > RTE_ETHER_MAX_LEN &&
1087  !(dev_info->rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME)) {
1088  SCLogError("%s: jumbo frames not supported, set MTU to 1500", iconf->iface);
1089  SCReturnInt(-EINVAL);
1090  }
1091 #endif
1092 
1093  SCReturnInt(0);
1094 }
1095 
1096 static void DeviceSetMTU(struct rte_eth_conf *port_conf, uint16_t mtu)
1097 {
1098 #if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0)
1099  port_conf->rxmode.mtu = mtu;
1100 #else
1101  port_conf->rxmode.max_rx_pkt_len = mtu;
1102  if (mtu > RTE_ETHER_MAX_LEN) {
1103  port_conf->rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1104  }
1105 #endif
1106 }
1107 
1108 /**
1109  * \param port_id - queried port
1110  * \param socket_id - socket ID of the queried port
1111  * \return non-negative number on success, negative on failure (errno)
1112  */
1113 static int32_t DeviceSetSocketID(uint16_t port_id, int32_t *socket_id)
1114 {
1115  rte_errno = 0;
1116  int retval = rte_eth_dev_socket_id(port_id);
1117  *socket_id = retval;
1118 
1119 #if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) // DPDK API changed since 22.11
1120  retval = -rte_errno;
1121 #else
1122  if (retval == SOCKET_ID_ANY)
1123  retval = 0; // DPDK couldn't determine socket ID of a port
1124 #endif
1125 
1126  return retval;
1127 }
1128 
1129 static void PortConfSetInterruptMode(const DPDKIfaceConfig *iconf, struct rte_eth_conf *port_conf)
1130 {
1131  SCLogConfig("%s: interrupt mode is %s", iconf->iface,
1132  iconf->flags & DPDK_IRQ_MODE ? "enabled" : "disabled");
1133  if (iconf->flags & DPDK_IRQ_MODE)
1134  port_conf->intr_conf.rxq = 1;
1135 }
1136 
1137 static void PortConfSetRSSConf(const DPDKIfaceConfig *iconf,
1138  const struct rte_eth_dev_info *dev_info, struct rte_eth_conf *port_conf)
1139 {
1140  if (dev_info->rx_offload_capa & RTE_ETH_RX_OFFLOAD_RSS_HASH) {
1141  if (iconf->nb_rx_queues > 1) {
1142  SCLogConfig("%s: RSS enabled for %d queues", iconf->iface, iconf->nb_rx_queues);
1143  port_conf->rx_adv_conf.rss_conf = (struct rte_eth_rss_conf){
1144  .rss_key = rss_hkey,
1145  .rss_key_len = RSS_HKEY_LEN,
1146  .rss_hf = iconf->rss_hf,
1147  };
1148 
1149  const char *dev_driver = dev_info->driver_name;
1150  if (strcmp(dev_info->driver_name, "net_bonding") == 0) {
1151  dev_driver = BondingDeviceDriverGet(iconf->port_id);
1152  }
1153 
1154  DeviceSetPMDSpecificRSS(&port_conf->rx_adv_conf.rss_conf, dev_driver);
1155 
1156  uint64_t rss_hf_tmp =
1157  port_conf->rx_adv_conf.rss_conf.rss_hf & dev_info->flow_type_rss_offloads;
1158  if (port_conf->rx_adv_conf.rss_conf.rss_hf != rss_hf_tmp) {
1159  DumpRSSFlags(port_conf->rx_adv_conf.rss_conf.rss_hf, rss_hf_tmp);
1160 
1161  SCLogWarning("%s: modified RSS hash function based on hardware support: "
1162  "requested:%#" PRIx64 ", configured:%#" PRIx64,
1163  iconf->iface, port_conf->rx_adv_conf.rss_conf.rss_hf, rss_hf_tmp);
1164  port_conf->rx_adv_conf.rss_conf.rss_hf = rss_hf_tmp;
1165  }
1166  port_conf->rxmode.mq_mode = RTE_ETH_MQ_RX_RSS;
1167  } else {
1168  SCLogConfig("%s: RSS not enabled", iconf->iface);
1169  port_conf->rx_adv_conf.rss_conf.rss_key = NULL;
1170  port_conf->rx_adv_conf.rss_conf.rss_hf = 0;
1171  }
1172  } else {
1173  SCLogConfig("%s: RSS not supported", iconf->iface);
1174  }
1175 }
1176 
1177 static void PortConfSetChsumOffload(const DPDKIfaceConfig *iconf,
1178  const struct rte_eth_dev_info *dev_info, struct rte_eth_conf *port_conf)
1179 {
1180  if (iconf->checksum_mode == CHECKSUM_VALIDATION_DISABLE) {
1181  SCLogConfig("%s: checksum validation disabled", iconf->iface);
1182  } else if ((dev_info->rx_offload_capa & RTE_ETH_RX_OFFLOAD_CHECKSUM) ==
1183  RTE_ETH_RX_OFFLOAD_CHECKSUM) { // multibit comparison to make sure all bits are set
1184  if (iconf->checksum_mode == CHECKSUM_VALIDATION_ENABLE &&
1185  iconf->flags & DPDK_RX_CHECKSUM_OFFLOAD) {
1186  SCLogConfig("%s: IP, TCP and UDP checksum validation offloaded", iconf->iface);
1187  port_conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_CHECKSUM;
1188  } else if (iconf->checksum_mode == CHECKSUM_VALIDATION_ENABLE &&
1189  !(iconf->flags & DPDK_RX_CHECKSUM_OFFLOAD)) {
1190  SCLogConfig("%s: checksum validation enabled (but can be offloaded)", iconf->iface);
1191  }
1192  }
1193 }
1194 
1195 static void DeviceInitPortConf(const DPDKIfaceConfig *iconf,
1196  const struct rte_eth_dev_info *dev_info, struct rte_eth_conf *port_conf)
1197 {
1198  DumpRXOffloadCapabilities(dev_info->rx_offload_capa);
1199  *port_conf = (struct rte_eth_conf){
1200  .rxmode = {
1201  .mq_mode = RTE_ETH_MQ_RX_NONE,
1202  .offloads = 0, // turn every offload off to prevent any packet modification
1203  },
1204  .txmode = {
1205  .mq_mode = RTE_ETH_MQ_TX_NONE,
1206  .offloads = 0,
1207  },
1208  };
1209 
1210  PortConfSetInterruptMode(iconf, port_conf);
1211 
1212  // configure RX offloads
1213  PortConfSetRSSConf(iconf, dev_info, port_conf);
1214  PortConfSetChsumOffload(iconf, dev_info, port_conf);
1215  DeviceSetMTU(port_conf, iconf->mtu);
1216 
1217  if (dev_info->tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) {
1218  port_conf->txmode.offloads |= RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
1219  }
1220 }
1221 
1222 static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_dev_info *dev_info,
1223  const struct rte_eth_conf *port_conf)
1224 {
1225  SCEnter();
1226  int retval;
1227  uint16_t mtu_size;
1228  uint16_t mbuf_size;
1229  struct rte_eth_rxconf rxq_conf;
1230  struct rte_eth_txconf txq_conf;
1231 
1232  char mempool_name[64];
1233  snprintf(mempool_name, 64, "mempool_%.20s", iconf->iface);
1234  // +4 for VLAN header
1235  mtu_size = iconf->mtu + RTE_ETHER_CRC_LEN + RTE_ETHER_HDR_LEN + 4;
1236  mbuf_size = ROUNDUP(mtu_size, 1024) + RTE_PKTMBUF_HEADROOM;
1237  SCLogConfig("%s: creating packet mbuf pool %s of size %d, cache size %d, mbuf size %d",
1238  iconf->iface, mempool_name, iconf->mempool_size, iconf->mempool_cache_size, mbuf_size);
1239 
1240  iconf->pkt_mempool = rte_pktmbuf_pool_create(mempool_name, iconf->mempool_size,
1241  iconf->mempool_cache_size, 0, mbuf_size, (int)iconf->socket_id);
1242  if (iconf->pkt_mempool == NULL) {
1243  retval = -rte_errno;
1244  SCLogError("%s: rte_pktmbuf_pool_create failed with code %d (mempool: %s): %s",
1245  iconf->iface, rte_errno, mempool_name, rte_strerror(rte_errno));
1246  SCReturnInt(retval);
1247  }
1248 
1249  for (uint16_t queue_id = 0; queue_id < iconf->nb_rx_queues; queue_id++) {
1250  rxq_conf = dev_info->default_rxconf;
1251  rxq_conf.offloads = port_conf->rxmode.offloads;
1252  rxq_conf.rx_thresh.hthresh = 0;
1253  rxq_conf.rx_thresh.pthresh = 0;
1254  rxq_conf.rx_thresh.wthresh = 0;
1255  rxq_conf.rx_free_thresh = 0;
1256  rxq_conf.rx_drop_en = 0;
1257  SCLogConfig("%s: setting up RX queue %d: rx_desc: %u offloads: 0x%" PRIx64
1258  " hthresh: %" PRIu8 " pthresh: %" PRIu8 " wthresh: %" PRIu8
1259  " free_thresh: %" PRIu16 " drop_en: %" PRIu8,
1260  iconf->iface, queue_id, iconf->nb_rx_desc, rxq_conf.offloads,
1261  rxq_conf.rx_thresh.hthresh, rxq_conf.rx_thresh.pthresh, rxq_conf.rx_thresh.wthresh,
1262  rxq_conf.rx_free_thresh, rxq_conf.rx_drop_en);
1263 
1264  retval = rte_eth_rx_queue_setup(iconf->port_id, queue_id, iconf->nb_rx_desc,
1265  iconf->socket_id, &rxq_conf, iconf->pkt_mempool);
1266  if (retval < 0) {
1267  rte_mempool_free(iconf->pkt_mempool);
1268  SCLogError("%s: failed to setup RX queue %u: %s", iconf->iface, queue_id,
1269  rte_strerror(-retval));
1270  SCReturnInt(retval);
1271  }
1272  }
1273 
1274  for (uint16_t queue_id = 0; queue_id < iconf->nb_tx_queues; queue_id++) {
1275  txq_conf = dev_info->default_txconf;
1276  txq_conf.offloads = port_conf->txmode.offloads;
1277  SCLogConfig("%s: setting up TX queue %d: tx_desc: %" PRIu16 " tx: offloads: 0x%" PRIx64
1278  " hthresh: %" PRIu8 " pthresh: %" PRIu8 " wthresh: %" PRIu8
1279  " tx_free_thresh: %" PRIu16 " tx_rs_thresh: %" PRIu16
1280  " txq_deferred_start: %" PRIu8,
1281  iconf->iface, queue_id, iconf->nb_tx_desc, txq_conf.offloads,
1282  txq_conf.tx_thresh.hthresh, txq_conf.tx_thresh.pthresh, txq_conf.tx_thresh.wthresh,
1283  txq_conf.tx_free_thresh, txq_conf.tx_rs_thresh, txq_conf.tx_deferred_start);
1284  retval = rte_eth_tx_queue_setup(
1285  iconf->port_id, queue_id, iconf->nb_tx_desc, iconf->socket_id, &txq_conf);
1286  if (retval < 0) {
1287  rte_mempool_free(iconf->pkt_mempool);
1288  SCLogError("%s: failed to setup TX queue %u: %s", iconf->iface, queue_id,
1289  rte_strerror(-retval));
1290  SCReturnInt(retval);
1291  }
1292  }
1293 
1294  SCReturnInt(0);
1295 }
1296 
1297 static int DeviceValidateOutIfaceConfig(DPDKIfaceConfig *iconf)
1298 {
1299  SCEnter();
1300  int retval;
1301  DPDKIfaceConfig *out_iconf = NULL;
1302  ConfigInit(&out_iconf);
1303  if (out_iconf == NULL) {
1304  FatalError("Copy interface of the interface \"%s\" is NULL", iconf->iface);
1305  }
1306 
1307  retval = ConfigLoad(out_iconf, iconf->out_iface);
1308  if (retval < 0) {
1309  SCLogError("%s: fail to load config of interface", iconf->out_iface);
1310  out_iconf->DerefFunc(out_iconf);
1311  SCReturnInt(-EINVAL);
1312  }
1313 
1314  if (iconf->nb_rx_queues != out_iconf->nb_tx_queues) {
1315  // the other direction is validated when the copy interface is configured
1316  SCLogError("%s: configured %d RX queues but copy interface %s has %d TX queues"
1317  " - number of queues must be equal",
1318  iconf->iface, iconf->nb_rx_queues, out_iconf->iface, out_iconf->nb_tx_queues);
1319  out_iconf->DerefFunc(out_iconf);
1320  SCReturnInt(-EINVAL);
1321  } else if (iconf->mtu != out_iconf->mtu) {
1322  SCLogError("%s: configured MTU of %d but copy interface %s has MTU set to %d"
1323  " - MTU must be equal",
1324  iconf->iface, iconf->mtu, out_iconf->iface, out_iconf->mtu);
1325  out_iconf->DerefFunc(out_iconf);
1326  SCReturnInt(-EINVAL);
1327  } else if (iconf->copy_mode != out_iconf->copy_mode) {
1328  SCLogError("%s: copy modes of interfaces %s and %s are not equal", iconf->iface,
1329  iconf->iface, out_iconf->iface);
1330  out_iconf->DerefFunc(out_iconf);
1331  SCReturnInt(-EINVAL);
1332  } else if (strcmp(iconf->iface, out_iconf->out_iface) != 0) {
1333  // check if the other iface has the current iface set as a copy iface
1334  SCLogError("%s: copy interface of %s is not set to %s", iconf->iface, out_iconf->iface,
1335  iconf->iface);
1336  out_iconf->DerefFunc(out_iconf);
1337  SCReturnInt(-EINVAL);
1338  }
1339 
1340  out_iconf->DerefFunc(out_iconf);
1341  SCReturnInt(0);
1342 }
1343 
1344 static int DeviceConfigureIPS(DPDKIfaceConfig *iconf)
1345 {
1346  SCEnter();
1347  if (iconf->out_iface != NULL) {
1348  if (!rte_eth_dev_is_valid_port(iconf->out_port_id)) {
1349  SCLogError("%s: retrieved copy interface port ID \"%d\" is invalid or the device is "
1350  "not attached ",
1351  iconf->iface, iconf->out_port_id);
1352  SCReturnInt(-ENODEV);
1353  }
1354  int32_t out_port_socket_id;
1355  int retval = DeviceSetSocketID(iconf->out_port_id, &out_port_socket_id);
1356  if (retval < 0) {
1357  SCLogError("%s: invalid socket id: %s", iconf->out_iface, rte_strerror(-retval));
1358  SCReturnInt(retval);
1359  }
1360 
1361  if (iconf->socket_id != out_port_socket_id) {
1362  SCLogWarning(
1363  "%s: out iface %s is not on the same NUMA node (%s - NUMA %d, %s - NUMA %d)",
1364  iconf->iface, iconf->out_iface, iconf->iface, iconf->socket_id,
1365  iconf->out_iface, out_port_socket_id);
1366  }
1367 
1368  retval = DeviceValidateOutIfaceConfig(iconf);
1369  if (retval != 0) {
1370  // Error will be written out by the validation function
1371  SCReturnInt(retval);
1372  }
1373 
1374  if (iconf->copy_mode == DPDK_COPY_MODE_IPS)
1375  SCLogInfo("%s: DPDK IPS mode activated: %s->%s", iconf->iface, iconf->iface,
1376  iconf->out_iface);
1377  else if (iconf->copy_mode == DPDK_COPY_MODE_TAP)
1378  SCLogInfo("%s: DPDK TAP mode activated: %s->%s", iconf->iface, iconf->iface,
1379  iconf->out_iface);
1380  }
1381  SCReturnInt(0);
1382 }
1383 
1384 /**
1385  * Function verifies changes in e.g. device info after configuration has
1386  * happened. Sometimes (e.g. DPDK Bond PMD with Intel NICs i40e/ixgbe) change
1387  * device info only after the device configuration.
1388  * @param iconf
1389  * @param dev_info
1390  * @return 0 on success, -EAGAIN when reconfiguration is needed, <0 on failure
1391  */
1392 static int32_t DeviceVerifyPostConfigure(
1393  const DPDKIfaceConfig *iconf, const struct rte_eth_dev_info *dev_info)
1394 {
1395  SCEnter();
1396  struct rte_eth_dev_info post_conf_dev_info = { 0 };
1397  int32_t ret = rte_eth_dev_info_get(iconf->port_id, &post_conf_dev_info);
1398  if (ret < 0) {
1399  SCLogError("%s: getting device info failed: %s", iconf->iface, rte_strerror(-ret));
1400  SCReturnInt(ret);
1401  }
1402 
1403  if (dev_info->flow_type_rss_offloads != post_conf_dev_info.flow_type_rss_offloads ||
1404  dev_info->rx_offload_capa != post_conf_dev_info.rx_offload_capa ||
1405  dev_info->tx_offload_capa != post_conf_dev_info.tx_offload_capa ||
1406  dev_info->max_rx_queues != post_conf_dev_info.max_rx_queues ||
1407  dev_info->max_tx_queues != post_conf_dev_info.max_tx_queues ||
1408  dev_info->max_mtu != post_conf_dev_info.max_mtu) {
1409  SCLogWarning("%s: device information severely changed after configuration, reconfiguring",
1410  iconf->iface);
1411  return -EAGAIN;
1412  }
1413 
1414  if (strcmp(dev_info->driver_name, "net_bonding") == 0) {
1415  ret = BondingAllDevicesSameDriver(iconf->port_id);
1416  if (ret < 0) {
1417  SCLogError("%s: bond port uses port with different DPDK drivers", iconf->iface);
1418  SCReturnInt(ret);
1419  }
1420  }
1421 
1422  return 0;
1423 }
1424 
1425 static int DeviceConfigure(DPDKIfaceConfig *iconf)
1426 {
1427  SCEnter();
1428  if (!rte_eth_dev_is_valid_port(iconf->port_id)) {
1429  SCLogError("%s: retrieved port ID \"%d\" is invalid or the device is not attached ",
1430  iconf->iface, iconf->port_id);
1431  SCReturnInt(-ENODEV);
1432  }
1433 
1434  int32_t retval = DeviceSetSocketID(iconf->port_id, &iconf->socket_id);
1435  if (retval < 0) {
1436  SCLogError("%s: invalid socket id: %s", iconf->iface, rte_strerror(-retval));
1437  SCReturnInt(retval);
1438  }
1439 
1440  struct rte_eth_dev_info dev_info = { 0 };
1441  retval = rte_eth_dev_info_get(iconf->port_id, &dev_info);
1442  if (retval < 0) {
1443  SCLogError("%s: getting device info failed: %s", iconf->iface, rte_strerror(-retval));
1444  SCReturnInt(retval);
1445  }
1446 
1447  if (iconf->nb_rx_queues > dev_info.max_rx_queues) {
1448  SCLogError("%s: configured RX queues %u is higher than device maximum (%" PRIu16 ")",
1449  iconf->iface, iconf->nb_rx_queues, dev_info.max_rx_queues);
1450  SCReturnInt(-ERANGE);
1451  }
1452 
1453  if (iconf->nb_tx_queues > dev_info.max_tx_queues) {
1454  SCLogError("%s: configured TX queues %u is higher than device maximum (%" PRIu16 ")",
1455  iconf->iface, iconf->nb_tx_queues, dev_info.max_tx_queues);
1456  SCReturnInt(-ERANGE);
1457  }
1458 
1459  retval = DeviceValidateMTU(iconf, &dev_info);
1460  if (retval < 0)
1461  return retval;
1462 
1463  struct rte_eth_conf port_conf = { 0 };
1464  DeviceInitPortConf(iconf, &dev_info, &port_conf);
1465  if (port_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM) {
1466  // Suricata does not need recalc checksums now
1467  iconf->checksum_mode = CHECKSUM_VALIDATION_OFFLOAD;
1468  }
1469 
1470  retval = rte_eth_dev_configure(
1471  iconf->port_id, iconf->nb_rx_queues, iconf->nb_tx_queues, &port_conf);
1472  if (retval < 0) {
1473  SCLogError("%s: failed to configure the device: %s", iconf->iface, rte_strerror(-retval));
1474  SCReturnInt(retval);
1475  }
1476 
1477  retval = DeviceVerifyPostConfigure(iconf, &dev_info);
1478  if (retval < 0)
1479  return retval;
1480 
1481  uint16_t tmp_nb_rx_desc = iconf->nb_rx_desc;
1482  uint16_t tmp_nb_tx_desc = iconf->nb_tx_desc;
1483  retval = rte_eth_dev_adjust_nb_rx_tx_desc(
1484  iconf->port_id, &iconf->nb_rx_desc, &iconf->nb_tx_desc);
1485  if (retval != 0) {
1486  SCLogError("%s: failed to adjust device queue descriptors: %s", iconf->iface,
1487  rte_strerror(-retval));
1488  SCReturnInt(retval);
1489  } else if (tmp_nb_rx_desc != iconf->nb_rx_desc || tmp_nb_tx_desc != iconf->nb_tx_desc) {
1490  SCLogWarning("%s: device queue descriptors adjusted (RX: from %u to %u, TX: from %u to %u)",
1491  iconf->iface, tmp_nb_rx_desc, iconf->nb_rx_desc, tmp_nb_tx_desc, iconf->nb_tx_desc);
1492  }
1493 
1494  retval = iconf->flags & DPDK_MULTICAST ? rte_eth_allmulticast_enable(iconf->port_id)
1495  : rte_eth_allmulticast_disable(iconf->port_id);
1496  if (retval == -ENOTSUP) {
1497  retval = rte_eth_allmulticast_get(iconf->port_id);
1498  // when multicast is enabled but set to disable or vice versa
1499  if ((retval == 1 && !(iconf->flags & DPDK_MULTICAST)) ||
1500  (retval == 0 && (iconf->flags & DPDK_MULTICAST))) {
1501  SCLogWarning("%s: cannot configure allmulticast, the port is %sin allmulticast mode",
1502  iconf->iface, retval == 1 ? "" : "not ");
1503  } else if (retval < 0) {
1504  SCLogError("%s: failed to get multicast mode: %s", iconf->iface, rte_strerror(-retval));
1505  SCReturnInt(retval);
1506  }
1507  } else if (retval < 0) {
1508  SCLogError("%s: error when changing multicast setting: %s", iconf->iface,
1509  rte_strerror(-retval));
1510  SCReturnInt(retval);
1511  }
1512 
1513  retval = iconf->flags & DPDK_PROMISC ? rte_eth_promiscuous_enable(iconf->port_id)
1514  : rte_eth_promiscuous_disable(iconf->port_id);
1515  if (retval == -ENOTSUP) {
1516  retval = rte_eth_promiscuous_get(iconf->port_id);
1517  if ((retval == 1 && !(iconf->flags & DPDK_PROMISC)) ||
1518  (retval == 0 && (iconf->flags & DPDK_PROMISC))) {
1519  SCLogError("%s: cannot configure promiscuous mode, the port is in %spromiscuous mode",
1520  iconf->iface, retval == 1 ? "" : "non-");
1522  } else if (retval < 0) {
1523  SCLogError(
1524  "%s: failed to get promiscuous mode: %s", iconf->iface, rte_strerror(-retval));
1525  SCReturnInt(retval);
1526  }
1527  } else if (retval < 0) {
1528  SCLogError("%s: error when changing promiscuous setting: %s", iconf->iface,
1529  rte_strerror(-retval));
1531  }
1532 
1533  // set maximum transmission unit
1534  SCLogConfig("%s: setting MTU to %d", iconf->iface, iconf->mtu);
1535  retval = rte_eth_dev_set_mtu(iconf->port_id, iconf->mtu);
1536  if (retval == -ENOTSUP) {
1537  // if it is not possible to set the MTU, retrieve it
1538  retval = rte_eth_dev_get_mtu(iconf->port_id, &iconf->mtu);
1539  if (retval < 0) {
1540  SCLogError("%s: failed to retrieve MTU: %s", iconf->iface, rte_strerror(-retval));
1541  SCReturnInt(retval);
1542  }
1543  SCLogWarning(
1544  "%s: changing MTU is not supported, current MTU: %u", iconf->iface, iconf->mtu);
1545  } else if (retval < 0) {
1546  SCLogError(
1547  "%s: failed to set MTU to %u: %s", iconf->iface, iconf->mtu, rte_strerror(-retval));
1548  SCReturnInt(retval);
1549  }
1550 
1551  retval = DeviceConfigureQueues(iconf, &dev_info, &port_conf);
1552  if (retval < 0) {
1553  SCReturnInt(retval);
1554  }
1555 
1556  retval = DeviceConfigureIPS(iconf);
1557  if (retval < 0) {
1558  SCReturnInt(retval);
1559  }
1560 
1561  SCReturnInt(0);
1562 }
1563 
1564 static void *ParseDpdkConfigAndConfigureDevice(const char *iface)
1565 {
1566  int retval;
1567  DPDKIfaceConfig *iconf = ConfigParse(iface);
1568  if (iconf == NULL) {
1569  FatalError("DPDK configuration could not be parsed");
1570  }
1571 
1572  retval = DeviceConfigure(iconf);
1573  if (retval == -EAGAIN) {
1574  // for e.g. bonding PMD it needs to be reconfigured
1575  retval = DeviceConfigure(iconf);
1576  }
1577 
1578  if (retval < 0) { // handles both configure attempts
1579  iconf->DerefFunc(iconf);
1580  if (rte_eal_cleanup() != 0)
1581  FatalError("EAL cleanup failed: %s", rte_strerror(-retval));
1582 
1583  if (retval == -ENOMEM) {
1584  FatalError("%s: memory allocation failed - consider"
1585  "%s freeing up some memory.",
1586  iface,
1587  rte_eal_has_hugepages() != 0 ? " increasing the number of hugepages or" : "");
1588  } else {
1589  FatalError("%s: failed to configure", iface);
1590  }
1591  }
1592 
1593  SC_ATOMIC_RESET(iconf->ref);
1594  (void)SC_ATOMIC_ADD(iconf->ref, iconf->threads);
1595  // This counter is increased by worker threads that individually pick queue IDs.
1596  SC_ATOMIC_RESET(iconf->queue_id);
1597  SC_ATOMIC_RESET(iconf->inconsistent_numa_cnt);
1598  iconf->workers_sync = SCCalloc(1, sizeof(*iconf->workers_sync));
1599  if (iconf->workers_sync == NULL) {
1600  FatalError("Failed to allocate memory for workers_sync");
1601  }
1602  SC_ATOMIC_RESET(iconf->workers_sync->worker_checked_in);
1603  iconf->workers_sync->worker_cnt = iconf->threads;
1604 
1605  // initialize LiveDev DPDK values
1606  LiveDevice *ldev_instance = LiveGetDevice(iface);
1607  if (ldev_instance == NULL) {
1608  FatalError("Device %s is not registered as a live device", iface);
1609  }
1610  ldev_instance->dpdk_vars.pkt_mp = iconf->pkt_mempool;
1611  return iconf;
1612 }
1613 
1614 /**
1615  * \brief extract information from config file
1616  *
1617  * The returned structure will be freed by the thread init function.
1618  * This is thus necessary to or copy the structure before giving it
1619  * to thread or to reparse the file for each thread (and thus have
1620  * new structure.
1621  *
1622  * After configuration is loaded, DPDK also configures the device according to the settings.
1623  *
1624  * \return a DPDKIfaceConfig corresponding to the interface name
1625  */
1626 
1627 static int DPDKConfigGetThreadsCount(void *conf)
1628 {
1629  if (conf == NULL)
1630  FatalError("Configuration file is NULL");
1631 
1632  DPDKIfaceConfig *dpdk_conf = (DPDKIfaceConfig *)conf;
1633  return dpdk_conf->threads;
1634 }
1635 
1636 #endif /* HAVE_DPDK */
1637 
1638 static int DPDKRunModeIsIPS(void)
1639 {
1640  /* Find initial node */
1641  const char dpdk_node_query[] = "dpdk.interfaces";
1642  ConfNode *dpdk_node = ConfGetNode(dpdk_node_query);
1643  if (dpdk_node == NULL) {
1644  FatalError("Unable to get %s configuration node", dpdk_node_query);
1645  }
1646 
1647  const char default_iface[] = "default";
1648  ConfNode *if_default = ConfNodeLookupKeyValue(dpdk_node, "interface", default_iface);
1649  int nlive = LiveGetDeviceCount();
1650  bool has_ips = false;
1651  bool has_ids = false;
1652  for (int ldev = 0; ldev < nlive; ldev++) {
1653  const char *live_dev = LiveGetDeviceName(ldev);
1654  if (live_dev == NULL)
1655  FatalError("Unable to get device id %d from LiveDevice list", ldev);
1656 
1657  ConfNode *if_root = ConfFindDeviceConfig(dpdk_node, live_dev);
1658  if (if_root == NULL) {
1659  if (if_default == NULL)
1660  FatalError("Unable to get %s or %s interface", live_dev, default_iface);
1661 
1662  if_root = if_default;
1663  }
1664 
1665  const char *copymodestr = NULL;
1666  if (ConfGetChildValueWithDefault(if_root, if_default, "copy-mode", &copymodestr) == 1) {
1667  if (strcmp(copymodestr, "ips") == 0) {
1668  has_ips = true;
1669  } else {
1670  has_ids = true;
1671  }
1672  } else {
1673  has_ids = true;
1674  }
1675 
1676  if (has_ids && has_ips) {
1677  FatalError("Copy-mode of interface %s mixes with the previously set copy-modes "
1678  "(only IDS/TAP and IPS copy-mode combinations are allowed in DPDK",
1679  live_dev);
1680  }
1681  }
1682 
1683  return has_ips;
1684 }
1685 
1686 static void DPDKRunModeEnableIPS(void)
1687 {
1688  if (DPDKRunModeIsIPS()) {
1689  SCLogInfo("Setting IPS mode");
1690  EngineModeSetIPS();
1691  }
1692 }
1693 
1694 const char *RunModeDpdkGetDefaultMode(void)
1695 {
1696  return "workers";
1697 }
1698 
1700 {
1702  "Workers DPDK mode, each thread does all"
1703  " tasks from acquisition to logging",
1704  RunModeIdsDpdkWorkers, DPDKRunModeEnableIPS);
1705 }
1706 
1707 /**
1708  * \brief Workers version of the DPDK processing.
1709  *
1710  * Start N threads with each thread doing all the work.
1711  *
1712  */
1714 {
1715  SCEnter();
1716 #ifdef HAVE_DPDK
1717  int ret;
1718 
1719  TimeModeSetLive();
1720 
1721  InitEal();
1722  ret = RunModeSetLiveCaptureWorkers(ParseDpdkConfigAndConfigureDevice, DPDKConfigGetThreadsCount,
1723  "ReceiveDPDK", "DecodeDPDK", thread_name_workers, NULL);
1724  if (ret != 0) {
1725  FatalError("Unable to start runmode");
1726  }
1727 
1728  SCLogDebug("RunModeIdsDpdkWorkers initialised");
1729 
1730 #endif /* HAVE_DPDK */
1731  SCReturnInt(0);
1732 }
1733 
1734 /**
1735  * @}
1736  */
thread_name_workers
const char * thread_name_workers
Definition: runmodes.c:81
DPDKIfaceConfigAttributes_::checksum_checks_offload
const char * checksum_checks_offload
Definition: runmode-dpdk.h:32
util-byte.h
DPDKIfaceConfigAttributes_::mempool_size
const char * mempool_size
Definition: runmode-dpdk.h:35
threading_set_cpu_affinity
bool threading_set_cpu_affinity
Definition: runmodes.c:75
CHECKSUM_VALIDATION_OFFLOAD
@ CHECKSUM_VALIDATION_OFFLOAD
Definition: decode.h:51
RunModeSetLiveCaptureWorkers
int RunModeSetLiveCaptureWorkers(ConfigIfaceParserFunc ConfigParser, ConfigIfaceThreadsCountFunc ModThreadsCount, const char *recv_mod_name, const char *decode_mod_name, const char *thread_name, const char *live_dev)
Definition: util-runmodes.c:321
DPDKSetTimevalOfMachineStart
void DPDKSetTimevalOfMachineStart(void)
DPDKIfaceConfigAttributes_::promisc
const char * promisc
Definition: runmode-dpdk.h:29
SC_ATOMIC_INIT
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
Definition: util-atomic.h:314
ConfNode_::val
char * val
Definition: conf.h:34
RUNMODE_DPDK
@ RUNMODE_DPDK
Definition: runmodes.h:40
DPDKIfaceConfigAttributes_::mempool_cache_size
const char * mempool_cache_size
Definition: runmode-dpdk.h:36
DPDK_COPY_MODE_IPS
@ DPDK_COPY_MODE_IPS
Definition: source-dpdk.h:33
ConfGetChildValueBoolWithDefault
int ConfGetChildValueBoolWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, int *val)
Definition: conf.c:514
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
ConfGetNode
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
Definition: conf.c:181
UtilAffinityGetAffinedCPUNum
uint16_t UtilAffinityGetAffinedCPUNum(ThreadsAffinityType *taf)
Definition: util-affinity.c:310
LiveDevice_
Definition: util-device.h:50
SC_ATOMIC_ADD
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
Definition: util-atomic.h:332
DPDKIfaceConfigAttributes_::copy_iface
const char * copy_iface
Definition: runmode-dpdk.h:40
RunModeIdsDpdkWorkers
int RunModeIdsDpdkWorkers(void)
Workers version of the DPDK processing.
Definition: runmode-dpdk.c:1713
util-runmodes.h
TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:252
RunModeRegisterNewRunMode
void RunModeRegisterNewRunMode(enum RunModes runmode, const char *name, const char *description, int(*RunModeFunc)(void), void(*RunModeIsIPSEnabled)(void))
Registers a new runmode.
Definition: runmodes.c:491
MIN
#define MIN(x, y)
Definition: suricata-common.h:391
ConfNodeLookupKeyValue
ConfNode * ConfNodeLookupKeyValue(const ConfNode *base, const char *key, const char *value)
Lookup for a key value under a specific node.
Definition: conf.c:831
CHECKSUM_VALIDATION_DISABLE
@ CHECKSUM_VALIDATION_DISABLE
Definition: decode.h:46
RunmodeGetActive
char * RunmodeGetActive(void)
Definition: runmodes.c:217
StringParseInt32
int StringParseInt32(int32_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:622
DPDKIfaceConfig_
Definition: source-dpdk.h:52
util-dpdk-ice.h
ConfGetChildValueIntWithDefault
int ConfGetChildValueIntWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, intmax_t *val)
Definition: conf.c:462
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:85
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
SCReturnBool
#define SCReturnBool(x)
Definition: util-debug.h:289
CHECKSUM_VALIDATION_ENABLE
@ CHECKSUM_VALIDATION_ENABLE
Definition: decode.h:47
RunModeDpdkGetDefaultMode
const char * RunModeDpdkGetDefaultMode(void)
Definition: runmode-dpdk.c:1694
decode.h
util-device.h
util-debug.h
DPDKIfaceConfigAttributes_::rx_descriptors
const char * rx_descriptors
Definition: runmode-dpdk.h:37
strlcat
size_t strlcat(char *, const char *src, size_t siz)
Definition: util-strlcatu.c:45
util-cpu.h
DPDKIfaceConfigAttributes_::checksum_checks
const char * checksum_checks
Definition: runmode-dpdk.h:31
LiveGetDevice
LiveDevice * LiveGetDevice(const char *name)
Get a pointer to the device at idx.
Definition: util-device.c:248
DPDK_RX_CHECKSUM_OFFLOAD
#define DPDK_RX_CHECKSUM_OFFLOAD
Definition: source-dpdk.h:43
ConfFindDeviceConfig
ConfNode * ConfFindDeviceConfig(ConfNode *node, const char *iface)
Find the configuration node for a specific device.
Definition: util-conf.c:121
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
util-affinity.h
EngineModeSetIPS
void EngineModeSetIPS(void)
Definition: suricata.c:246
ConfGetChildValueWithDefault
int ConfGetChildValueWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, const char **vptr)
Definition: conf.c:378
StringParseUint32
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:313
util-time.h
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:249
DPDKIfaceConfigAttributes_
Definition: runmode-dpdk.h:26
SC_ATOMIC_SUB
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
Definition: util-atomic.h:341
SCReturn
#define SCReturn
Definition: util-debug.h:273
DPDKIfaceConfigAttributes_::irq_mode
const char * irq_mode
Definition: runmode-dpdk.h:28
SCReturnPtr
#define SCReturnPtr(x, type)
Definition: util-debug.h:287
BIT_U64
#define BIT_U64(n)
Definition: suricata-common.h:401
runmodes.h
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:224
DPDKIfaceConfigAttributes_::threads
const char * threads
Definition: runmode-dpdk.h:27
TimeModeSetLive
void TimeModeSetLive(void)
Definition: util-time.c:99
DPDKIfaceConfigAttributes_::tx_descriptors
const char * tx_descriptors
Definition: runmode-dpdk.h:38
DPDK_IRQ_MODE
#define DPDK_IRQ_MODE
Definition: source-dpdk.h:41
util-dpdk.h
util-conf.h
StringParseUint64
int StringParseUint64(uint64_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:308
source-dpdk.h
suricata-common.h
LiveGetDeviceName
const char * LiveGetDeviceName(int number)
Get a pointer to the device name at idx.
Definition: util-device.c:184
DPDK_PROMISC
#define DPDK_PROMISC
Definition: source-dpdk.h:39
ConfNode_::name
char * name
Definition: conf.h:33
ConfNodeIsSequence
int ConfNodeIsSequence(const ConfNode *node)
Check if a node is a sequence or node.
Definition: conf.c:916
FatalError
#define FatalError(...)
Definition: util-debug.h:502
SC_ATOMIC_RESET
#define SC_ATOMIC_RESET(name)
wrapper for reinitializing an atomic variable.
Definition: util-atomic.h:323
ThreadsAffinityType_
Definition: util-affinity.h:65
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
SCFree
#define SCFree(p)
Definition: util-mem.h:61
ConfNode_
Definition: conf.h:32
util-dpdk-bonding.h
DPDKIfaceConfigAttributes_::multicast
const char * multicast
Definition: runmode-dpdk.h:30
RunModeDpdkRegister
void RunModeDpdkRegister(void)
Definition: runmode-dpdk.c:1699
util-dpdk-ixgbe.h
ConfSetRootAndDefaultNodes
int ConfSetRootAndDefaultNodes(const char *ifaces_node_name, const char *iface, ConfNode **if_root, ConfNode **if_default)
Finds and sets root and default node of the interface.
Definition: conf.c:953
util-dpdk-i40e.h
suricata.h
runmode-dpdk.h
DPDKIfaceConfigAttributes_::rss_hf
const char * rss_hf
Definition: runmode-dpdk.h:34
GetAffinityTypeFromName
ThreadsAffinityType * GetAffinityTypeFromName(const char *name)
find affinity by its name
Definition: util-affinity.c:68
LiveGetDeviceCount
int LiveGetDeviceCount(void)
Get the number of registered devices.
Definition: util-device.c:164
DPDKIfaceConfigAttributes_::mtu
const char * mtu
Definition: runmode-dpdk.h:33
DPDKIfaceConfigAttributes_::copy_mode
const char * copy_mode
Definition: runmode-dpdk.h:39
UtilCpuGetNumProcessorsOnline
uint16_t UtilCpuGetNumProcessorsOnline(void)
Get the number of cpus online in the system.
Definition: util-cpu.c:108
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:275
DPDK_COPY_MODE_TAP
@ DPDK_COPY_MODE_TAP
Definition: source-dpdk.h:33
DPDK_COPY_MODE_NONE
@ DPDK_COPY_MODE_NONE
Definition: source-dpdk.h:33
DPDK_MULTICAST
#define DPDK_MULTICAST
Definition: source-dpdk.h:40