27 #define MAX_DEVNAME 10
52 typedef struct BypassInfo_ {
62 static int live_devices_stats = 1;
65 static int LiveSafeDeviceName(
const char *devname,
66 char *newdevname,
size_t destlen);
68 static int g_live_devices_disable_offloading = 1;
72 g_live_devices_disable_offloading = 1;
77 g_live_devices_disable_offloading = 0;
82 return g_live_devices_disable_offloading;
148 SCLogDebug(
"Device \"%s\" registered and created.", dev);
243 static int LiveSafeDeviceName(
const char *devname,
char *newdevname,
size_t destlen)
245 const size_t devnamelen = strlen(devname);
258 if ((destlen-1) > 10 || (destlen-1) < 6) {
264 SCLogInfo(
"Shortening device name to: %s", newdevname);
266 strlcpy(newdevname, devname, destlen);
290 if (!strcmp(name, pd->
dev)) {
303 if (live_dev == NULL)
325 if ((!strcmp(subchild->
name, itemname))) {
326 if (!strcmp(subchild->
val,
"default"))
329 itemname, subchild->
val);
345 live_devices_stats = 0;
354 if (live_devices_stats) {
355 SCLogNotice(
"Stats for '%s': pkts: %" PRIu64
", drop: %" PRIu64
356 " (%.2f%%), invalid chksum: %" PRIu64,
374 #ifdef BUILD_UNIX_SOCKET
375 TmEcode LiveDeviceIfaceStat(json_t *cmd, json_t *answer,
void *data)
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"));
385 name = json_string_value(jarg);
387 json_object_set_new(answer,
"message", json_string(
"Iface name is NULL"));
392 if (!strcmp(name, pd->
dev)) {
393 json_t *jdata = json_object();
395 json_object_set_new(answer,
"message",
396 json_string(
"internal error at json object creation"));
399 json_object_set_new(jdata,
"pkts",
401 json_object_set_new(jdata,
"invalid-checksums",
403 json_object_set_new(jdata,
"drop",
405 json_object_set_new(jdata,
"bypassed",
407 json_object_set_new(answer,
"message", jdata);
411 json_object_set_new(answer,
"message", json_string(
"Iface does not exist"));
415 TmEcode LiveDeviceIfaceList(json_t *cmd, json_t *answer,
void *data)
423 jdata = json_object();
425 json_object_set_new(answer,
"message",
426 json_string(
"internal error at json object creation"));
429 jarray = json_array();
430 if (jarray == NULL) {
431 json_object_set_new(answer,
"message",
432 json_string(
"internal error at json object creation"));
436 json_array_append_new(jarray, json_string(pd->
dev));
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);
484 static void LiveDevExtensionFree(
void *x)
496 NULL, LiveDevExtensionFree);
505 if (bpinfo == NULL) {
528 if (family == AF_INET) {
530 }
else if (family == AF_INET6) {
547 if (family == AF_INET) {
549 }
else if (family == AF_INET6) {
566 if (family == AF_INET) {
568 }
else if (family == AF_INET6) {
585 if (family == AF_INET) {
587 }
else if (family == AF_INET6) {
604 if (family == AF_INET) {
606 }
else if (family == AF_INET6) {
612 #ifdef BUILD_UNIX_SOCKET
613 TmEcode LiveDeviceGetBypassedStats(json_t *cmd, json_t *answer,
void *data)
617 json_t *ifaces = NULL;
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);
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"));
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);
646 json_object_set_new(answer,
"message", ifaces);
650 json_object_set_new(answer,
"message",
651 json_string(
"No interface using bypass"));