26 #define MAX_DEVNAME 10
28 static int g_bypass_storage_id = -1;
51 typedef struct BypassInfo_ {
61 static int live_devices_stats = 1;
64 static int LiveSafeDeviceName(
const char *devname,
65 char *newdevname,
size_t destlen);
67 static int g_live_devices_disable_offloading = 1;
71 g_live_devices_disable_offloading = 1;
76 g_live_devices_disable_offloading = 0;
81 return g_live_devices_disable_offloading;
147 SCLogDebug(
"Device \"%s\" registered and created.", dev);
242 static int LiveSafeDeviceName(
const char *devname,
char *newdevname,
size_t destlen)
244 const size_t devnamelen = strlen(devname);
257 if ((destlen-1) > 10 || (destlen-1) < 6) {
263 SCLogInfo(
"Shortening device name to: %s", newdevname);
265 strlcpy(newdevname, devname, destlen);
289 if (!strcmp(name, pd->
dev)) {
302 if (live_dev == NULL)
324 if ((!strcmp(subchild->
name, itemname))) {
325 if (!strcmp(subchild->
val,
"default"))
328 itemname, subchild->
val);
344 live_devices_stats = 0;
353 if (live_devices_stats) {
354 SCLogNotice(
"Stats for '%s': pkts: %" PRIu64
", drop: %" PRIu64
" (%.2f%%), invalid chksum: %" PRIu64,
373 #ifdef BUILD_UNIX_SOCKET
374 TmEcode LiveDeviceIfaceStat(json_t *cmd, json_t *answer,
void *data)
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"));
384 name = json_string_value(jarg);
386 json_object_set_new(answer,
"message", json_string(
"Iface name is NULL"));
391 if (!strcmp(name, pd->
dev)) {
392 json_t *jdata = json_object();
394 json_object_set_new(answer,
"message",
395 json_string(
"internal error at json object creation"));
398 json_object_set_new(jdata,
"pkts",
400 json_object_set_new(jdata,
"invalid-checksums",
402 json_object_set_new(jdata,
"drop",
404 json_object_set_new(jdata,
"bypassed",
406 json_object_set_new(answer,
"message", jdata);
410 json_object_set_new(answer,
"message", json_string(
"Iface does not exist"));
414 TmEcode LiveDeviceIfaceList(json_t *cmd, json_t *answer,
void *data)
422 jdata = json_object();
424 json_object_set_new(answer,
"message",
425 json_string(
"internal error at json object creation"));
428 jarray = json_array();
429 if (jarray == NULL) {
430 json_object_set_new(answer,
"message",
431 json_string(
"internal error at json object creation"));
435 json_array_append_new(jarray, json_string(pd->
dev));
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);
483 static void LiveDevExtensionFree(
void *x)
495 NULL, LiveDevExtensionFree);
504 if (bpinfo == NULL) {
527 if (family == AF_INET) {
529 }
else if (family == AF_INET6) {
546 if (family == AF_INET) {
548 }
else if (family == AF_INET6) {
565 if (family == AF_INET) {
567 }
else if (family == AF_INET6) {
584 if (family == AF_INET) {
586 }
else if (family == AF_INET6) {
603 if (family == AF_INET) {
605 }
else if (family == AF_INET6) {
611 #ifdef BUILD_UNIX_SOCKET
612 TmEcode LiveDeviceGetBypassedStats(json_t *cmd, json_t *answer,
void *data)
616 json_t *ifaces = NULL;
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);
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"));
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);
645 json_object_set_new(answer,
"message", ifaces);
649 json_object_set_new(answer,
"message",
650 json_string(
"No interface using bypass"));