suricata
util-device.c
Go to the documentation of this file.
1 /* Copyright (C) 2011-2026 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 #include "suricata-common.h"
19 #include "conf.h"
20 #include "util-device-private.h"
21 #include "util-ioctl.h"
22 #include "util-misc.h"
23 #include "util-dpdk.h"
24 
25 #include "device-storage.h"
26 #include "util-debug.h"
27 #include "util-affinity.h"
28 
29 #define MAX_DEVNAME 10
30 
31 static SCLiveDevStorageId g_bypass_storage_id = { .id = -1 };
32 
33 /**
34  * \file
35  *
36  * \author Eric Leblond <eric@regit.org>
37  *
38  * \brief Utility functions to handle device list
39  */
40 
41 /** private device list */
42 static TAILQ_HEAD(, LiveDevice_) live_devices =
43  TAILQ_HEAD_INITIALIZER(live_devices);
44 
45 typedef struct LiveDeviceName_ {
46  char *dev; /**< the device (e.g. "eth0") */
47  TAILQ_ENTRY(LiveDeviceName_) next;
49 
50 /** List of the name of devices
51  *
52  * As we don't know the size of the Storage on devices
53  * before the parsing we need to wait and use this list
54  * to create later the LiveDevice via LiveDeviceFinalize()
55  */
56 static TAILQ_HEAD(, LiveDeviceName_) pre_live_devices =
57  TAILQ_HEAD_INITIALIZER(pre_live_devices);
58 
59 typedef struct BypassInfo_ {
60  SC_ATOMIC_DECLARE(uint64_t, ipv4_hash_count);
61  SC_ATOMIC_DECLARE(uint64_t, ipv4_fail);
62  SC_ATOMIC_DECLARE(uint64_t, ipv4_success);
63  SC_ATOMIC_DECLARE(uint64_t, ipv6_hash_count);
64  SC_ATOMIC_DECLARE(uint64_t, ipv6_fail);
65  SC_ATOMIC_DECLARE(uint64_t, ipv6_success);
67 
68 /** if set to 0 when we don't have real devices */
69 static int live_devices_stats = 1;
70 
71 static void LiveDeviceFreeArray(void);
72 static int LiveSafeDeviceName(const char *devname,
73  char *newdevname, size_t destlen);
74 
75 static int g_live_devices_disable_offloading = 1;
76 
78 {
79  g_live_devices_disable_offloading = 1;
80 }
81 
83 {
84  g_live_devices_disable_offloading = 0;
85 }
86 
87 int LiveGetOffload(void)
88 {
89  return g_live_devices_disable_offloading;
90 }
91 
92 /**
93  * \brief Add a device for monitoring
94  *
95  * To be used during option parsing. When a device has
96  * to be created during runmode init, use LiveRegisterDevice()
97  *
98  * \param dev string with the device name
99  *
100  * \retval 0 on success.
101  * \retval -1 on failure.
102  */
103 int LiveRegisterDeviceName(const char *dev)
104 {
105  LiveDeviceName *pd = NULL;
106 
107  pd = SCCalloc(1, sizeof(LiveDeviceName));
108  if (unlikely(pd == NULL)) {
109  return -1;
110  }
111 
112  pd->dev = SCStrdup(dev);
113  if (unlikely(pd->dev == NULL)) {
114  SCFree(pd);
115  return -1;
116  }
117 
118  TAILQ_INSERT_TAIL(&pre_live_devices, pd, next);
119 
120  SCLogDebug("Device \"%s\" registered.", dev);
121  return 0;
122 }
123 
124 /**
125  * \brief Add a pcap device for monitoring and create structure
126  *
127  * \param dev string with the device name
128  *
129  * \retval 0 on success.
130  * \retval -1 on failure.
131  */
132 int LiveRegisterDevice(const char *dev)
133 {
134  LiveDevice *pd = NULL;
135 
136  pd = SCCalloc(1, sizeof(LiveDevice) + SCLiveDevStorageSize());
137  if (unlikely(pd == NULL)) {
138  return -1;
139  }
140 
141  /* +1 as the id space starts at 1 */
142  int id = LiveGetDeviceCount() + 1;
143  if (id > UINT16_MAX) {
144  SCFree(pd);
145  return -1;
146  }
147 
148  pd->dev = SCStrdup(dev);
149  if (unlikely(pd->dev == NULL)) {
150  SCFree(pd);
151  return -1;
152  }
153  /* create a short version to be used in thread names */
154  LiveSafeDeviceName(pd->dev, pd->dev_short, sizeof(pd->dev_short));
155 
156  SC_ATOMIC_INIT(pd->pkts);
157  SC_ATOMIC_INIT(pd->drop);
158  SC_ATOMIC_INIT(pd->invalid_checksums);
159  pd->id = (uint16_t)id;
160  TAILQ_INSERT_TAIL(&live_devices, pd, next);
161 
162  SCLogDebug("Device \"%s\" registered and created.", dev);
163  return 0;
164 }
165 
166 /**
167  * \brief Get the number of registered devices
168  *
169  * \retval cnt the number of registered devices
170  */
172 {
173  int i = 0;
174  LiveDevice *pd;
175 
176  TAILQ_FOREACH(pd, &live_devices, next) {
177  i++;
178  }
179 
180  return i;
181 }
182 
184 {
185  int i = 0;
186  LiveDevice *pd;
187 
188  TAILQ_FOREACH (pd, &live_devices, next) {
189  if (GetAffinityTypeForNameAndIface("worker-cpu-set", pd->dev) == NULL) {
190  i++;
191  }
192  }
193 
194  return i;
195 }
196 
197 /**
198  * \brief Get a pointer to the device name at idx
199  *
200  * \param number idx of the device in our list
201  *
202  * \retval ptr pointer to the string containing the device
203  * \retval NULL on error
204  */
205 const char *LiveGetDeviceName(int number)
206 {
207  int i = 0;
208  LiveDevice *pd;
209 
210  TAILQ_FOREACH(pd, &live_devices, next) {
211  if (i == number) {
212  return pd->dev;
213  }
214 
215  i++;
216  }
217 
218  return NULL;
219 }
220 
221 /** \internal
222  * \brief Shorten a device name that is to long
223  *
224  * \param device name from config and destination for modified
225  *
226  * \retval None, is added to destination char *newdevname
227  */
228 static int LiveSafeDeviceName(const char *devname, char *newdevname, size_t destlen)
229 {
230  const size_t devnamelen = strlen(devname);
231 
232  /* If we have to shorten the interface name */
233  if (devnamelen > MAX_DEVNAME) {
234  /* special mode for DPDK pci addresses */
235  if (devnamelen >= 5 && strncmp(devname, "0000:", 5) == 0) {
236  strlcpy(newdevname, devname + 5, destlen);
237  return 0;
238  }
239 
240  /* IF the dest length is over 10 chars long it will not do any
241  * good for the shortening. The shortening is done due to the
242  * max length of pthread names (15 chars) and we use 3 chars
243  * for the threadname indicator eg. "W#-" and one-two chars for
244  * the thread number. And if the destination buffer is under
245  * 6 chars there is no point in shortening it since we must at
246  * least enter two periods (.) into the string.
247  */
248  if ((destlen-1) > 10 || (destlen-1) < 6) {
249  return 1;
250  }
251 
252  ShortenString(devname, newdevname, destlen, '~');
253 
254  SCLogInfo("%s: shortening device name to %s", devname, newdevname);
255  } else {
256  strlcpy(newdevname, devname, destlen);
257  }
258  return 0;
259 }
260 
261 /**
262  * \brief Get a pointer to the device at idx
263  *
264  * \param number idx of the device in our list
265  *
266  * \retval ptr pointer to the string containing the device
267  * \retval NULL on error
268  */
270 {
271  LiveDevice *pd;
272 
273  if (name == NULL) {
274  SCLogWarning("Name of device should not be null");
275  return NULL;
276  }
277 
278  TAILQ_FOREACH(pd, &live_devices, next) {
279  if (!strcmp(name, pd->dev)) {
280  return pd;
281  }
282  }
283 
284  return NULL;
285 }
286 
287 const char *LiveGetShortName(const char *dev)
288 {
289  LiveDevice *live_dev = LiveGetDevice(dev);
290  if (live_dev == NULL)
291  return NULL;
292  return live_dev->dev_short;
293 }
294 
295 int LiveBuildDeviceList(const char *runmode)
296 {
297  return LiveBuildDeviceListCustom(runmode, "interface");
298 }
299 
300 int LiveBuildDeviceListCustom(const char *runmode, const char *itemname)
301 {
302  SCConfNode *base = SCConfGetNode(runmode);
303  SCConfNode *child;
304  int i = 0;
305 
306  if (base == NULL)
307  return 0;
308 
309  TAILQ_FOREACH(child, &base->head, next) {
310  SCConfNode *subchild;
311  TAILQ_FOREACH(subchild, &child->head, next) {
312  if ((!strcmp(subchild->name, itemname))) {
313  if (!strcmp(subchild->val, "default"))
314  break;
315  SCLogConfig("Adding %s %s from config file",
316  itemname, subchild->val);
317  LiveRegisterDeviceName(subchild->val);
318  i++;
319  }
320  }
321  }
322 
323  return i;
324 }
325 
326 /** Call this function to disable stat on live devices
327  *
328  * This can be useful in the case, this is not a real interface.
329  */
331 {
332  live_devices_stats = 0;
333 }
334 
336 {
337  SCEnter();
338  LiveDeviceFreeArray();
339  LiveDevice *pd, *tpd;
340 
341  /* dpdk: need to close all devices before freeing them. */
342  TAILQ_FOREACH (pd, &live_devices, next) {
343  DPDKCloseDevice(pd);
344  }
345  TAILQ_FOREACH_SAFE(pd, &live_devices, next, tpd) {
346  if (live_devices_stats) {
347  SCLogNotice("%s: packets: %" PRIu64 ", drops: %" PRIu64
348  " (%.2f%%), invalid chksum: %" PRIu64,
349  pd->dev, SC_ATOMIC_GET(pd->pkts), SC_ATOMIC_GET(pd->drop),
350  SC_ATOMIC_GET(pd->pkts) > 0 ? 100 * ((double)SC_ATOMIC_GET(pd->drop)) /
351  (double)SC_ATOMIC_GET(pd->pkts)
352  : 0,
353  SC_ATOMIC_GET(pd->invalid_checksums));
354  }
355 
357  DPDKFreeDevice(pd);
358 
359  if (pd->dev)
360  SCFree(pd->dev);
362  SCFree(pd);
363  }
364 
366 }
367 
368 #ifdef BUILD_UNIX_SOCKET
369 TmEcode LiveDeviceIfaceStat(json_t *cmd, json_t *answer, void *data)
370 {
371  SCEnter();
372  LiveDevice *pd;
373  const char * name = NULL;
374  json_t *jarg = json_object_get(cmd, "iface");
375  if(!json_is_string(jarg)) {
376  json_object_set_new(answer, "message", json_string("Iface is not a string"));
378  }
379  name = json_string_value(jarg);
380  if (name == NULL) {
381  json_object_set_new(answer, "message", json_string("Iface name is NULL"));
383  }
384 
385  TAILQ_FOREACH(pd, &live_devices, next) {
386  if (!strcmp(name, pd->dev)) {
387  json_t *jdata = json_object();
388  if (jdata == NULL) {
389  json_object_set_new(answer, "message",
390  json_string("internal error at json object creation"));
392  }
393  json_object_set_new(jdata, "pkts",
394  json_integer(SC_ATOMIC_GET(pd->pkts)));
395  json_object_set_new(jdata, "invalid-checksums",
396  json_integer(SC_ATOMIC_GET(pd->invalid_checksums)));
397  json_object_set_new(jdata, "drop",
398  json_integer(SC_ATOMIC_GET(pd->drop)));
399  json_object_set_new(jdata, "bypassed",
400  json_integer(SC_ATOMIC_GET(pd->bypassed)));
401  json_object_set_new(answer, "message", jdata);
403  }
404  }
405  json_object_set_new(answer, "message", json_string("Iface does not exist"));
407 }
408 
409 TmEcode LiveDeviceIfaceList(json_t *cmd, json_t *answer, void *data)
410 {
411  SCEnter();
412  json_t *jdata;
413  json_t *jarray;
414  LiveDevice *pd;
415  int i = 0;
416 
417  jdata = json_object();
418  if (jdata == NULL) {
419  json_object_set_new(answer, "message",
420  json_string("internal error at json object creation"));
421  return TM_ECODE_FAILED;
422  }
423  jarray = json_array();
424  if (jarray == NULL) {
425  json_object_set_new(answer, "message",
426  json_string("internal error at json object creation"));
427  return TM_ECODE_FAILED;
428  }
429  TAILQ_FOREACH(pd, &live_devices, next) {
430  json_array_append_new(jarray, json_string(pd->dev));
431  i++;
432  }
433 
434  json_object_set_new(jdata, "count", json_integer(i));
435  json_object_set_new(jdata, "ifaces", jarray);
436  json_object_set_new(answer, "message", jdata);
438 }
439 
440 #endif /* BUILD_UNIX_SOCKET */
441 
442 static LiveDevice **g_livedev_array = NULL;
443 static int g_livedev_array_size = 0;
444 
445 static void LiveDeviceFreeArray(void)
446 {
447  if (g_livedev_array)
448  SCFree(g_livedev_array);
449  g_livedev_array_size = 0;
450 }
451 
452 uint16_t LiveDeviceGetId(const LiveDevice *dev)
453 {
454  if (dev) {
455  return dev->id;
456  }
457  return 0;
458 }
459 
461 {
462  if (g_livedev_array != NULL && id < g_livedev_array_size) {
463  return g_livedev_array[id];
464  }
465  return NULL;
466 }
467 
469 {
470  if (*ldev == NULL) {
471  *ldev = TAILQ_FIRST(&live_devices);
472  *ndev = TAILQ_NEXT(*ldev, next);
473  return *ldev;
474  } else {
475  *ldev = *ndev;
476  if (*ldev) {
477  *ndev = TAILQ_NEXT(*ldev, next);
478  }
479  return *ldev;
480  }
481  return NULL;
482 }
483 
484 static void LiveDeviceFinalizeBuildArray(void)
485 {
486  BUG_ON(g_livedev_array);
487  /* +1 as the id space starts at 1 */
488  int max_id = LiveGetDeviceCount() + 1;
489  if (max_id <= 1)
490  return;
491 
492  g_livedev_array = SCCalloc(max_id + 1, sizeof(LiveDevice *));
493  if (g_livedev_array == NULL)
494  FatalError("failed to alloc livedev array");
495  g_livedev_array_size = max_id + 1;
496 
497  LiveDevice *ldev = NULL, *ndev = NULL;
498  while (LiveDeviceForEach(&ldev, &ndev)) {
499  g_livedev_array[ldev->id] = ldev;
500  }
501 }
502 
503 /**
504  * Create registered devices
505  *
506  * This function creates all needed LiveDevice from
507  * the LiveDeviceName list created via LiveRegisterDevice()
508  */
510 {
511  LiveDeviceName *ld, *pld;
512  SCLogDebug("Finalize live device");
513  /* Iter on devices and register them */
514  TAILQ_FOREACH_SAFE(ld, &pre_live_devices, next, pld) {
515  if (ld->dev) {
516  LiveRegisterDevice(ld->dev);
517  SCFree(ld->dev);
518  }
519  SCFree(ld);
520  }
521  LiveDeviceFinalizeBuildArray();
522 }
523 
524 static void LiveDevExtensionFree(void *x)
525 {
526  if (x)
527  SCFree(x);
528 }
529 
530 /**
531  * Register bypass stats storage
532  */
534 {
535  g_bypass_storage_id = SCLiveDevStorageRegister("bypass_stats", LiveDevExtensionFree);
536 }
537 
538 /**
539  * Prepare a LiveDevice so we can set bypass stats
540  */
542 {
543  BypassInfo *bpinfo = SCCalloc(1, sizeof(*bpinfo));
544  if (bpinfo == NULL) {
545  SCLogError("Can't allocate bypass info structure");
546  return -1;
547  }
548 
549  SC_ATOMIC_INIT(bpinfo->ipv4_hash_count);
550  SC_ATOMIC_INIT(bpinfo->ipv4_hash_count);
551 
552  SCLiveDevSetStorageById(dev, g_bypass_storage_id, bpinfo);
553  return 0;
554 }
555 
556 /**
557  * Increase number of currently bypassed flows for a protocol family
558  *
559  * \param dev pointer to LiveDevice to set stats for
560  * \param cnt number of flows to add
561  * \param family AF_INET to set IPv4 count or AF_INET6 to set IPv6 count
562  */
563 void LiveDevAddBypassStats(LiveDevice *dev, uint64_t cnt, int family)
564 {
565  BypassInfo *bpfdata = SCLiveDevGetStorageById(dev, g_bypass_storage_id);
566  if (bpfdata) {
567  if (family == AF_INET) {
568  SC_ATOMIC_ADD(bpfdata->ipv4_hash_count, cnt);
569  } else if (family == AF_INET6) {
570  SC_ATOMIC_ADD(bpfdata->ipv6_hash_count, cnt);
571  }
572  }
573 }
574 
575 /**
576  * Decrease number of currently bypassed flows for a protocol family
577  *
578  * \param dev pointer to LiveDevice to set stats for
579  * \param cnt number of flows to remove
580  * \param family AF_INET to set IPv4 count or AF_INET6 to set IPv6 count
581  */
582 void LiveDevSubBypassStats(LiveDevice *dev, uint64_t cnt, int family)
583 {
584  BypassInfo *bpfdata = SCLiveDevGetStorageById(dev, g_bypass_storage_id);
585  if (bpfdata) {
586  if (family == AF_INET) {
587  SC_ATOMIC_SUB(bpfdata->ipv4_hash_count, cnt);
588  } else if (family == AF_INET6) {
589  SC_ATOMIC_SUB(bpfdata->ipv6_hash_count, cnt);
590  }
591  }
592 }
593 
594 /**
595  * Increase number of failed captured flows for a protocol family
596  *
597  * \param dev pointer to LiveDevice to set stats for
598  * \param cnt number of flows to add
599  * \param family AF_INET to set IPv4 count or AF_INET6 to set IPv6 count
600  */
601 void LiveDevAddBypassFail(LiveDevice *dev, uint64_t cnt, int family)
602 {
603  BypassInfo *bpfdata = SCLiveDevGetStorageById(dev, g_bypass_storage_id);
604  if (bpfdata) {
605  if (family == AF_INET) {
606  SC_ATOMIC_ADD(bpfdata->ipv4_fail, cnt);
607  } else if (family == AF_INET6) {
608  SC_ATOMIC_ADD(bpfdata->ipv6_fail, cnt);
609  }
610  }
611 }
612 
613 /**
614  * Increase number of currently successfully bypassed flows for a protocol family
615  *
616  * \param dev pointer to LiveDevice to set stats for
617  * \param cnt number of flows to add
618  * \param family AF_INET to set IPv4 count or AF_INET6 to set IPv6 count
619  */
620 void LiveDevAddBypassSuccess(LiveDevice *dev, uint64_t cnt, int family)
621 {
622  BypassInfo *bpfdata = SCLiveDevGetStorageById(dev, g_bypass_storage_id);
623  if (bpfdata) {
624  if (family == AF_INET) {
625  SC_ATOMIC_ADD(bpfdata->ipv4_success, cnt);
626  } else if (family == AF_INET6) {
627  SC_ATOMIC_ADD(bpfdata->ipv6_success, cnt);
628  }
629  }
630 }
631 
632 #ifdef BUILD_UNIX_SOCKET
633 TmEcode LiveDeviceGetBypassedStats(json_t *cmd, json_t *answer, void *data)
634 {
635  if (g_bypass_storage_id.id < 0) {
636  json_object_set_new(answer, "message", json_string("Bypass not enabled"));
638  }
639  LiveDevice *ldev = NULL, *ndev = NULL;
640  json_t *ifaces = NULL;
641  while(LiveDeviceForEach(&ldev, &ndev)) {
642  BypassInfo *bpinfo = SCLiveDevGetStorageById(ldev, g_bypass_storage_id);
643  if (bpinfo) {
644  uint64_t ipv4_hash_count = SC_ATOMIC_GET(bpinfo->ipv4_hash_count);
645  uint64_t ipv6_hash_count = SC_ATOMIC_GET(bpinfo->ipv6_hash_count);
646  uint64_t ipv4_success = SC_ATOMIC_GET(bpinfo->ipv4_success);
647  uint64_t ipv4_fail = SC_ATOMIC_GET(bpinfo->ipv4_fail);
648  uint64_t ipv6_success = SC_ATOMIC_GET(bpinfo->ipv6_success);
649  uint64_t ipv6_fail = SC_ATOMIC_GET(bpinfo->ipv6_fail);
650  json_t *iface = json_object();
651  if (ifaces == NULL) {
652  ifaces = json_object();
653  if (ifaces == NULL) {
654  json_object_set_new(answer, "message",
655  json_string("internal error at json object creation"));
656  return TM_ECODE_FAILED;
657  }
658  }
659  json_object_set_new(iface, "ipv4_maps_count", json_integer(ipv4_hash_count));
660  json_object_set_new(iface, "ipv4_success", json_integer(ipv4_success));
661  json_object_set_new(iface, "ipv4_fail", json_integer(ipv4_fail));
662  json_object_set_new(iface, "ipv6_maps_count", json_integer(ipv6_hash_count));
663  json_object_set_new(iface, "ipv6_success", json_integer(ipv6_success));
664  json_object_set_new(iface, "ipv6_fail", json_integer(ipv6_fail));
665  json_object_set_new(ifaces, ldev->dev, iface);
666  }
667  }
668  if (ifaces) {
669  json_object_set_new(answer, "message", ifaces);
671  }
672 
673  json_object_set_new(answer, "message",
674  json_string("No interface using bypass"));
676 }
677 #endif
678 
680 {
681  return SC_ATOMIC_GET(dev->pkts);
682 }
683 
685 {
686  (void)SC_ATOMIC_ADD(dev->pkts, 1);
687 }
688 
689 void LiveDevicePktsAdd(LiveDevice *dev, uint64_t n)
690 {
691  (void)SC_ATOMIC_ADD(dev->pkts, n);
692 }
693 
694 void LiveDeviceDropAdd(LiveDevice *dev, uint64_t n)
695 {
696  (void)SC_ATOMIC_ADD(dev->drop, n);
697 }
698 
699 void LiveDeviceBypassedAdd(LiveDevice *dev, uint64_t n)
700 {
701  (void)SC_ATOMIC_ADD(dev->bypassed, n);
702 }
703 
705 {
706  return SC_ATOMIC_GET(dev->invalid_checksums);
707 }
LiveGetDeviceCountWithoutAssignedThreading
int LiveGetDeviceCountWithoutAssignedThreading(void)
Definition: util-device.c:183
util-device-private.h
LiveRegisterDevice
int LiveRegisterDevice(const char *dev)
Add a pcap device for monitoring and create structure.
Definition: util-device.c:132
LiveDeviceListClean
int LiveDeviceListClean(void)
Definition: util-device.c:335
GetAffinityTypeForNameAndIface
ThreadsAffinityType * GetAffinityTypeForNameAndIface(const char *name, const char *interface_name)
Find affinity by name (*-cpu-set name) and an interface name.
Definition: util-affinity.c:138
LiveGetShortName
const char * LiveGetShortName(const char *dev)
Definition: util-device.c:287
SC_ATOMIC_INIT
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
Definition: util-atomic.h:314
LiveDevStorageId_
Definition: device-storage.h:31
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
LiveDevRegisterExtension
void LiveDevRegisterExtension(void)
Definition: util-device.c:533
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
LiveGetOffload
int LiveGetOffload(void)
Definition: util-device.c:87
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
name
const char * name
Definition: detect-engine-proto.c:48
LiveBuildDeviceList
int LiveBuildDeviceList(const char *runmode)
Definition: util-device.c:295
LiveDevice_
Definition: util-device-private.h:32
SC_ATOMIC_ADD
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
Definition: util-atomic.h:332
LiveDevice_::id
uint16_t id
Definition: util-device-private.h:38
TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:252
LiveDeviceGetById
LiveDevice * LiveDeviceGetById(const int id)
Definition: util-device.c:460
LiveDeviceForEach
LiveDevice * LiveDeviceForEach(LiveDevice **ldev, LiveDevice **ndev)
Definition: util-device.c:468
device-storage.h
LiveDeviceHasNoStats
void LiveDeviceHasNoStats(void)
Definition: util-device.c:330
TAILQ_INSERT_TAIL
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:294
LiveDevicePktsAdd
void LiveDevicePktsAdd(LiveDevice *dev, uint64_t n)
Definition: util-device.c:689
LiveDevSubBypassStats
void LiveDevSubBypassStats(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:582
LiveDevicePktsGet
uint64_t LiveDevicePktsGet(LiveDevice *dev)
Definition: util-device.c:679
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:82
ShortenString
void ShortenString(const char *input, char *output, size_t output_size, char c)
Definition: util-misc.c:208
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:81
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
TAILQ_ENTRY
#define TAILQ_ENTRY(type)
Definition: queue.h:239
TAILQ_HEAD_INITIALIZER
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:236
util-debug.h
TAILQ_FIRST
#define TAILQ_FIRST(head)
Definition: queue.h:250
LiveSetOffloadDisable
void LiveSetOffloadDisable(void)
Definition: util-device.c:77
LiveBuildDeviceListCustom
int LiveBuildDeviceListCustom(const char *runmode, const char *itemname)
Definition: util-device.c:300
LiveGetDevice
LiveDevice * LiveGetDevice(const char *name)
Get a pointer to the device at idx.
Definition: util-device.c:269
SCEnter
#define SCEnter(...)
Definition: util-debug.h:284
util-affinity.h
LiveDeviceName
LiveDeviceName
Definition: util-device.c:48
RestoreIfaceOffloading
void RestoreIfaceOffloading(LiveDevice *dev)
Definition: util-ioctl.c:700
LiveDevice_::dev
char * dev
Definition: util-device-private.h:33
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:262
LiveDeviceInvalidChecksumsGet
uint64_t LiveDeviceInvalidChecksumsGet(LiveDevice *dev)
Definition: util-device.c:704
DPDKFreeDevice
void DPDKFreeDevice(LiveDevice *ldev)
Definition: util-dpdk.c:59
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:322
SC_ATOMIC_SUB
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
Definition: util-atomic.h:341
SC_ATOMIC_DECLARE
#define SC_ATOMIC_DECLARE(type, name)
wrapper for declaring atomic variables.
Definition: util-atomic.h:280
LiveDeviceGetId
uint16_t LiveDeviceGetId(const LiveDevice *dev)
Definition: util-device.c:452
LiveDeviceDropAdd
void LiveDeviceDropAdd(LiveDevice *dev, uint64_t n)
Definition: util-device.c:694
conf.h
LiveDevUseBypass
int LiveDevUseBypass(LiveDevice *dev)
Definition: util-device.c:541
TmEcode
TmEcode
Definition: tm-threads-common.h:80
LiveDevAddBypassStats
void LiveDevAddBypassStats(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:563
SCLiveDevFreeStorage
void SCLiveDevFreeStorage(LiveDevice *d)
Definition: device-storage.c:98
LiveDevAddBypassSuccess
void LiveDevAddBypassSuccess(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:620
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:232
TAILQ_FOREACH_SAFE
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:329
SCLiveDevGetStorageById
void * SCLiveDevGetStorageById(LiveDevice *d, SCLiveDevStorageId id)
Get a value from a given LiveDevice storage.
Definition: device-storage.c:87
DPDKCloseDevice
void DPDKCloseDevice(LiveDevice *ldev)
Definition: util-dpdk.c:41
cnt
uint32_t cnt
Definition: tmqh-packetpool.h:7
util-dpdk.h
suricata-common.h
LiveGetDeviceName
const char * LiveGetDeviceName(int number)
Get a pointer to the device name at idx.
Definition: util-device.c:205
TAILQ_NEXT
#define TAILQ_NEXT(elm, field)
Definition: queue.h:307
LiveSetOffloadWarn
void LiveSetOffloadWarn(void)
Definition: util-device.c:82
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
LiveDevAddBypassFail
void LiveDevAddBypassFail(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:601
FatalError
#define FatalError(...)
Definition: util-debug.h:517
LiveDeviceBypassedAdd
void LiveDeviceBypassedAdd(LiveDevice *dev, uint64_t n)
Definition: util-device.c:699
SCLiveDevStorageRegister
SCLiveDevStorageId SCLiveDevStorageRegister(const char *name, void(*Free)(void *))
Register a LiveDevice storage.
Definition: device-storage.c:59
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
SCConfGetNode
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
Definition: conf.c:182
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
SCFree
#define SCFree(p)
Definition: util-mem.h:61
SCLiveDevSetStorageById
int SCLiveDevSetStorageById(LiveDevice *d, SCLiveDevStorageId id, void *ptr)
Store a pointer in a given LiveDevice storage.
Definition: device-storage.c:74
MAX_DEVNAME
#define MAX_DEVNAME
Definition: util-device.c:29
util-ioctl.h
TAILQ_HEAD
#define TAILQ_HEAD(name, type)
Definition: queue.h:230
SCConfNode_::name
char * name
Definition: conf.h:38
LiveGetDeviceCount
int LiveGetDeviceCount(void)
Get the number of registered devices.
Definition: util-device.c:171
LiveRegisterDeviceName
int LiveRegisterDeviceName(const char *dev)
Add a device for monitoring.
Definition: util-device.c:103
LiveDeviceFinalize
void LiveDeviceFinalize(void)
Definition: util-device.c:509
SC_ATOMIC_GET
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:375
LiveDevice_::dev_short
char dev_short[MAX_DEVNAME+1]
Definition: util-device-private.h:34
util-misc.h
SCLogNotice
#define SCLogNotice(...)
Macro used to log NOTICE messages.
Definition: util-debug.h:250
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
LiveDevStorageId_::id
int id
Definition: device-storage.h:32
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:288
SCConfNode_
Definition: conf.h:37
SCConfNode_::val
char * val
Definition: conf.h:39
SCLiveDevStorageSize
unsigned int SCLiveDevStorageSize(void)
Definition: device-storage.c:32
BypassInfo
BypassInfo
Definition: util-device.c:66
LiveDevicePktsIncr
void LiveDevicePktsIncr(LiveDevice *dev)
Definition: util-device.c:684