28 #define MAX_DEVNAME 10
44 typedef struct LiveDeviceName_ {
55 static TAILQ_HEAD(, LiveDeviceName_) pre_live_devices =
58 typedef struct BypassInfo_ {
68 static int live_devices_stats = 1;
71 static int LiveSafeDeviceName(
const char *devname,
72 char *newdevname,
size_t destlen);
74 static int g_live_devices_disable_offloading = 1;
78 g_live_devices_disable_offloading = 1;
83 g_live_devices_disable_offloading = 0;
88 return g_live_devices_disable_offloading;
141 if (
id > UINT16_MAX) {
157 pd->
id = (uint16_t)
id;
160 SCLogDebug(
"Device \"%s\" registered and created.", dev);
212 static int LiveSafeDeviceName(
const char *devname,
char *newdevname,
size_t destlen)
214 const size_t devnamelen = strlen(devname);
219 if (devnamelen >= 5 && strncmp(devname,
"0000:", 5) == 0) {
220 strlcpy(newdevname, devname + 5, destlen);
232 if ((destlen-1) > 10 || (destlen-1) < 6) {
238 SCLogInfo(
"%s: shortening device name to %s", devname, newdevname);
240 strlcpy(newdevname, devname, destlen);
274 if (live_dev == NULL)
296 if ((!strcmp(subchild->
name, itemname))) {
297 if (!strcmp(subchild->
val,
"default"))
300 itemname, subchild->
val);
316 live_devices_stats = 0;
329 if (live_devices_stats) {
330 SCLogNotice(
"%s: packets: %" PRIu64
", drops: %" PRIu64
331 " (%.2f%%), invalid chksum: %" PRIu64,
351 #ifdef BUILD_UNIX_SOCKET
352 TmEcode LiveDeviceIfaceStat(json_t *cmd, json_t *answer,
void *data)
356 const char *
name = NULL;
357 json_t *jarg = json_object_get(cmd,
"iface");
358 if(!json_is_string(jarg)) {
359 json_object_set_new(answer,
"message", json_string(
"Iface is not a string"));
362 name = json_string_value(jarg);
364 json_object_set_new(answer,
"message", json_string(
"Iface name is NULL"));
370 json_t *jdata = json_object();
372 json_object_set_new(answer,
"message",
373 json_string(
"internal error at json object creation"));
376 json_object_set_new(jdata,
"pkts",
378 json_object_set_new(jdata,
"invalid-checksums",
380 json_object_set_new(jdata,
"drop",
382 json_object_set_new(jdata,
"bypassed",
384 json_object_set_new(answer,
"message", jdata);
388 json_object_set_new(answer,
"message", json_string(
"Iface does not exist"));
392 TmEcode LiveDeviceIfaceList(json_t *cmd, json_t *answer,
void *data)
400 jdata = json_object();
402 json_object_set_new(answer,
"message",
403 json_string(
"internal error at json object creation"));
406 jarray = json_array();
407 if (jarray == NULL) {
408 json_object_set_new(answer,
"message",
409 json_string(
"internal error at json object creation"));
413 json_array_append_new(jarray, json_string(pd->
dev));
417 json_object_set_new(jdata,
"count", json_integer(i));
418 json_object_set_new(jdata,
"ifaces", jarray);
419 json_object_set_new(answer,
"message", jdata);
461 static void LiveDevExtensionFree(
void *x)
473 NULL, LiveDevExtensionFree);
482 if (bpinfo == NULL) {
483 SCLogError(
"Can't allocate bypass info structure");
505 if (family == AF_INET) {
507 }
else if (family == AF_INET6) {
524 if (family == AF_INET) {
526 }
else if (family == AF_INET6) {
543 if (family == AF_INET) {
545 }
else if (family == AF_INET6) {
562 if (family == AF_INET) {
564 }
else if (family == AF_INET6) {
570 #ifdef BUILD_UNIX_SOCKET
571 TmEcode LiveDeviceGetBypassedStats(json_t *cmd, json_t *answer,
void *data)
573 if (g_bypass_storage_id.
id < 0) {
574 json_object_set_new(answer,
"message", json_string(
"Bypass not enabled"));
578 json_t *ifaces = NULL;
582 uint64_t ipv4_hash_count =
SC_ATOMIC_GET(bpinfo->ipv4_hash_count);
583 uint64_t ipv6_hash_count =
SC_ATOMIC_GET(bpinfo->ipv6_hash_count);
588 json_t *iface = json_object();
589 if (ifaces == NULL) {
590 ifaces = json_object();
591 if (ifaces == NULL) {
592 json_object_set_new(answer,
"message",
593 json_string(
"internal error at json object creation"));
597 json_object_set_new(iface,
"ipv4_maps_count", json_integer(ipv4_hash_count));
598 json_object_set_new(iface,
"ipv4_success", json_integer(ipv4_success));
599 json_object_set_new(iface,
"ipv4_fail", json_integer(ipv4_fail));
600 json_object_set_new(iface,
"ipv6_maps_count", json_integer(ipv6_hash_count));
601 json_object_set_new(iface,
"ipv6_success", json_integer(ipv6_success));
602 json_object_set_new(iface,
"ipv6_fail", json_integer(ipv6_fail));
603 json_object_set_new(ifaces, ldev->
dev, iface);
607 json_object_set_new(answer,
"message", ifaces);
611 json_object_set_new(answer,
"message",
612 json_string(
"No interface using bypass"));