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