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