29 #define MAX_DEVNAME 10
45 typedef struct LiveDeviceName_ {
56 static TAILQ_HEAD(, LiveDeviceName_) pre_live_devices =
59 typedef struct BypassInfo_ {
69 static int live_devices_stats = 1;
71 static void LiveDeviceFreeArray(
void);
72 static int LiveSafeDeviceName(
const char *devname,
73 char *newdevname,
size_t destlen);
75 static 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;
143 if (
id > UINT16_MAX) {
159 pd->
id = (uint16_t)
id;
162 SCLogDebug(
"Device \"%s\" registered and created.", dev);
228 static int LiveSafeDeviceName(
const char *devname,
char *newdevname,
size_t destlen)
230 const size_t devnamelen = strlen(devname);
235 if (devnamelen >= 5 && strncmp(devname,
"0000:", 5) == 0) {
236 strlcpy(newdevname, devname + 5, destlen);
248 if ((destlen-1) > 10 || (destlen-1) < 6) {
254 SCLogInfo(
"%s: shortening device name to %s", devname, newdevname);
256 strlcpy(newdevname, devname, destlen);
290 if (live_dev == NULL)
312 if ((!strcmp(subchild->
name, itemname))) {
313 if (!strcmp(subchild->
val,
"default"))
316 itemname, subchild->
val);
332 live_devices_stats = 0;
338 LiveDeviceFreeArray();
346 if (live_devices_stats) {
347 SCLogNotice(
"%s: packets: %" PRIu64
", drops: %" PRIu64
348 " (%.2f%%), invalid chksum: %" PRIu64,
368 #ifdef BUILD_UNIX_SOCKET
369 TmEcode LiveDeviceIfaceStat(json_t *cmd, json_t *answer,
void *data)
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"));
379 name = json_string_value(jarg);
381 json_object_set_new(answer,
"message", json_string(
"Iface name is NULL"));
387 json_t *jdata = json_object();
389 json_object_set_new(answer,
"message",
390 json_string(
"internal error at json object creation"));
393 json_object_set_new(jdata,
"pkts",
395 json_object_set_new(jdata,
"invalid-checksums",
397 json_object_set_new(jdata,
"drop",
399 json_object_set_new(jdata,
"bypassed",
401 json_object_set_new(answer,
"message", jdata);
405 json_object_set_new(answer,
"message", json_string(
"Iface does not exist"));
409 TmEcode LiveDeviceIfaceList(json_t *cmd, json_t *answer,
void *data)
417 jdata = json_object();
419 json_object_set_new(answer,
"message",
420 json_string(
"internal error at json object creation"));
423 jarray = json_array();
424 if (jarray == NULL) {
425 json_object_set_new(answer,
"message",
426 json_string(
"internal error at json object creation"));
430 json_array_append_new(jarray, json_string(pd->
dev));
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);
443 static int g_livedev_array_size = 0;
445 static void LiveDeviceFreeArray(
void)
449 g_livedev_array_size = 0;
462 if (g_livedev_array != NULL &&
id < g_livedev_array_size) {
463 return g_livedev_array[id];
484 static void LiveDeviceFinalizeBuildArray(
void)
493 if (g_livedev_array == NULL)
495 g_livedev_array_size = max_id + 1;
499 g_livedev_array[ldev->
id] = ldev;
521 LiveDeviceFinalizeBuildArray();
524 static void LiveDevExtensionFree(
void *x)
544 if (bpinfo == NULL) {
545 SCLogError(
"Can't allocate bypass info structure");
567 if (family == AF_INET) {
569 }
else if (family == AF_INET6) {
586 if (family == AF_INET) {
588 }
else if (family == AF_INET6) {
605 if (family == AF_INET) {
607 }
else if (family == AF_INET6) {
624 if (family == AF_INET) {
626 }
else if (family == AF_INET6) {
632 #ifdef BUILD_UNIX_SOCKET
633 TmEcode LiveDeviceGetBypassedStats(json_t *cmd, json_t *answer,
void *data)
635 if (g_bypass_storage_id.
id < 0) {
636 json_object_set_new(answer,
"message", json_string(
"Bypass not enabled"));
640 json_t *ifaces = NULL;
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);
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"));
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);
669 json_object_set_new(answer,
"message", ifaces);
673 json_object_set_new(answer,
"message",
674 json_string(
"No interface using bypass"));