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;
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;
142 if (
id > UINT16_MAX) {
158 pd->
id = (uint16_t)
id;
161 SCLogDebug(
"Device \"%s\" registered and created.", dev);
227 static 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
367 TmEcode 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"));
407 TmEcode 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);
476 static 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
586 TmEcode 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"));