45typedef struct LiveDeviceName_ {
56static TAILQ_HEAD(, LiveDeviceName_) pre_live_devices =
59typedef struct BypassInfo_ {
69static int live_devices_stats = 1;
72static int LiveSafeDeviceName(
const char *devname,
73 char *newdevname,
size_t destlen);
75static int g_live_devices_disable_offloading = 1;
79 g_live_devices_disable_offloading = 1;
84 g_live_devices_disable_offloading = 0;
89 return g_live_devices_disable_offloading;
142 if (
id > UINT16_MAX) {
158 pd->
id = (uint16_t)
id;
161 SCLogDebug(
"Device \"%s\" registered and created.", dev);
227static int LiveSafeDeviceName(
const char *devname,
char *newdevname,
size_t destlen)
229 const size_t devnamelen = strlen(devname);
234 if (devnamelen >= 5 && strncmp(devname,
"0000:", 5) == 0) {
235 strlcpy(newdevname, devname + 5, destlen);
247 if ((destlen-1) > 10 || (destlen-1) < 6) {
253 SCLogInfo(
"%s: shortening device name to %s", devname, newdevname);
255 strlcpy(newdevname, devname, destlen);
289 if (live_dev == NULL)
311 if ((!strcmp(subchild->
name, itemname))) {
312 if (!strcmp(subchild->
val,
"default"))
315 itemname, subchild->
val);
331 live_devices_stats = 0;
344 if (live_devices_stats) {
345 SCLogNotice(
"%s: packets: %" PRIu64
", drops: %" PRIu64
346 " (%.2f%%), invalid chksum: %" PRIu64,
366#ifdef BUILD_UNIX_SOCKET
367TmEcode LiveDeviceIfaceStat(json_t *cmd, json_t *answer,
void *data)
371 const char *
name = NULL;
372 json_t *jarg = json_object_get(cmd,
"iface");
373 if(!json_is_string(jarg)) {
374 json_object_set_new(answer,
"message", json_string(
"Iface is not a string"));
377 name = json_string_value(jarg);
379 json_object_set_new(answer,
"message", json_string(
"Iface name is NULL"));
385 json_t *jdata = json_object();
387 json_object_set_new(answer,
"message",
388 json_string(
"internal error at json object creation"));
391 json_object_set_new(jdata,
"pkts",
393 json_object_set_new(jdata,
"invalid-checksums",
395 json_object_set_new(jdata,
"drop",
397 json_object_set_new(jdata,
"bypassed",
399 json_object_set_new(answer,
"message", jdata);
403 json_object_set_new(answer,
"message", json_string(
"Iface does not exist"));
407TmEcode LiveDeviceIfaceList(json_t *cmd, json_t *answer,
void *data)
415 jdata = json_object();
417 json_object_set_new(answer,
"message",
418 json_string(
"internal error at json object creation"));
421 jarray = json_array();
422 if (jarray == NULL) {
423 json_object_set_new(answer,
"message",
424 json_string(
"internal error at json object creation"));
428 json_array_append_new(jarray, json_string(pd->
dev));
432 json_object_set_new(jdata,
"count", json_integer(i));
433 json_object_set_new(jdata,
"ifaces", jarray);
434 json_object_set_new(answer,
"message", jdata);
476static void LiveDevExtensionFree(
void *x)
488 NULL, LiveDevExtensionFree);
497 if (bpinfo == NULL) {
498 SCLogError(
"Can't allocate bypass info structure");
520 if (family == AF_INET) {
522 }
else if (family == AF_INET6) {
539 if (family == AF_INET) {
541 }
else if (family == AF_INET6) {
558 if (family == AF_INET) {
560 }
else if (family == AF_INET6) {
577 if (family == AF_INET) {
579 }
else if (family == AF_INET6) {
585#ifdef BUILD_UNIX_SOCKET
586TmEcode LiveDeviceGetBypassedStats(json_t *cmd, json_t *answer,
void *data)
588 if (g_bypass_storage_id.
id < 0) {
589 json_object_set_new(answer,
"message", json_string(
"Bypass not enabled"));
593 json_t *ifaces = NULL;
597 uint64_t ipv4_hash_count =
SC_ATOMIC_GET(bpinfo->ipv4_hash_count);
598 uint64_t ipv6_hash_count =
SC_ATOMIC_GET(bpinfo->ipv6_hash_count);
603 json_t *iface = json_object();
604 if (ifaces == NULL) {
605 ifaces = json_object();
606 if (ifaces == NULL) {
607 json_object_set_new(answer,
"message",
608 json_string(
"internal error at json object creation"));
612 json_object_set_new(iface,
"ipv4_maps_count", json_integer(ipv4_hash_count));
613 json_object_set_new(iface,
"ipv4_success", json_integer(ipv4_success));
614 json_object_set_new(iface,
"ipv4_fail", json_integer(ipv4_fail));
615 json_object_set_new(iface,
"ipv6_maps_count", json_integer(ipv6_hash_count));
616 json_object_set_new(iface,
"ipv6_success", json_integer(ipv6_success));
617 json_object_set_new(iface,
"ipv6_fail", json_integer(ipv6_fail));
618 json_object_set_new(ifaces, ldev->
dev, iface);
622 json_object_set_new(answer,
"message", ifaces);
626 json_object_set_new(answer,
"message",
627 json_string(
"No interface using bypass"));
struct HtpBodyChunk_ * next
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
void LiveDevFreeStorage(LiveDevice *d)
unsigned int LiveDevStorageSize(void)
int LiveDevSetStorageById(LiveDevice *d, LiveDevStorageId id, void *ptr)
Store a pointer in a given LiveDevice storage.
void * LiveDevGetStorageById(LiveDevice *d, LiveDevStorageId id)
Get a value from a given LiveDevice storage.
LiveDevStorageId LiveDevStorageRegister(const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void(*Free)(void *))
Register a LiveDevice storage.
#define TAILQ_FOREACH(var, head, field)
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
#define TAILQ_HEAD(name, type)
#define TAILQ_INSERT_TAIL(head, elm, field)
#define TAILQ_FIRST(head)
#define TAILQ_NEXT(elm, field)
#define TAILQ_HEAD_INITIALIZER(head)
#define TAILQ_ENTRY(type)
char dev_short[MAX_DEVNAME+1]
size_t strlcpy(char *dst, const char *src, size_t siz)
ThreadsAffinityType * GetAffinityTypeForNameAndIface(const char *name, const char *interface_name)
Find affinity by name (*-cpu-set name) and an interface name.
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
#define SC_ATOMIC_DECLARE(type, name)
wrapper for declaring atomic variables.
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
#define SCLogNotice(...)
Macro used to log NOTICE messages.
#define SCLogWarning(...)
Macro used to log WARNING messages.
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define SCLogError(...)
Macro used to log ERROR messages.
void LiveDeviceHasNoStats(void)
void LiveDevSubBypassStats(LiveDevice *dev, uint64_t cnt, int family)
void LiveDeviceFinalize(void)
uint64_t LiveDevicePktsGet(LiveDevice *dev)
uint64_t LiveDeviceInvalidChecksumsGet(LiveDevice *dev)
void LiveDevicePktsAdd(LiveDevice *dev, uint64_t n)
const char * LiveGetShortName(const char *dev)
LiveDevice * LiveGetDevice(const char *name)
Get a pointer to the device at idx.
LiveDevice * LiveDeviceForEach(LiveDevice **ldev, LiveDevice **ndev)
void LiveDevAddBypassStats(LiveDevice *dev, uint64_t cnt, int family)
int LiveGetDeviceCount(void)
Get the number of registered devices.
int LiveBuildDeviceList(const char *runmode)
int LiveDevUseBypass(LiveDevice *dev)
int LiveRegisterDevice(const char *dev)
Add a pcap device for monitoring and create structure.
int LiveGetDeviceCountWithoutAssignedThreading(void)
void LiveDeviceBypassedAdd(LiveDevice *dev, uint64_t n)
void LiveSetOffloadDisable(void)
void LiveDevRegisterExtension(void)
int LiveBuildDeviceListCustom(const char *runmode, const char *itemname)
void LiveSetOffloadWarn(void)
int LiveRegisterDeviceName(const char *dev)
Add a device for monitoring.
void LiveDevAddBypassSuccess(LiveDevice *dev, uint64_t cnt, int family)
void LiveDevAddBypassFail(LiveDevice *dev, uint64_t cnt, int family)
void LiveDevicePktsIncr(LiveDevice *dev)
int LiveDeviceListClean(void)
const char * LiveGetDeviceName(int number)
Get a pointer to the device name at idx.
void LiveDeviceDropAdd(LiveDevice *dev, uint64_t n)
void DPDKFreeDevice(LiveDevice *ldev)
void DPDKCloseDevice(LiveDevice *ldev)
void RestoreIfaceOffloading(LiveDevice *dev)
void ShortenString(const char *input, char *output, size_t output_size, char c)