28 #define MAX_DEVNAME 10
53 typedef struct BypassInfo_ {
63 static int live_devices_stats = 1;
66 static int LiveSafeDeviceName(
const char *devname,
67 char *newdevname,
size_t destlen);
69 static int g_live_devices_disable_offloading = 1;
73 g_live_devices_disable_offloading = 1;
78 g_live_devices_disable_offloading = 0;
83 return g_live_devices_disable_offloading;
136 if (
id > UINT16_MAX) {
152 pd->
id = (uint16_t)
id;
155 SCLogDebug(
"Device \"%s\" registered and created.", dev);
207 static int LiveSafeDeviceName(
const char *devname,
char *newdevname,
size_t destlen)
209 const size_t devnamelen = strlen(devname);
214 if (devnamelen >= 5 && strncmp(devname,
"0000:", 5) == 0) {
215 strlcpy(newdevname, devname + 5, destlen);
227 if ((destlen-1) > 10 || (destlen-1) < 6) {
233 SCLogInfo(
"%s: shortening device name to %s", devname, newdevname);
235 strlcpy(newdevname, devname, destlen);
258 if (!strcmp(name, pd->
dev)) {
269 if (live_dev == NULL)
291 if ((!strcmp(subchild->
name, itemname))) {
292 if (!strcmp(subchild->
val,
"default"))
295 itemname, subchild->
val);
311 live_devices_stats = 0;
324 if (live_devices_stats) {
325 SCLogNotice(
"%s: packets: %" PRIu64
", drops: %" PRIu64
326 " (%.2f%%), invalid chksum: %" PRIu64,
346 #ifdef BUILD_UNIX_SOCKET
347 TmEcode LiveDeviceIfaceStat(json_t *cmd, json_t *answer,
void *data)
351 const char * name = NULL;
352 json_t *jarg = json_object_get(cmd,
"iface");
353 if(!json_is_string(jarg)) {
354 json_object_set_new(answer,
"message", json_string(
"Iface is not a string"));
357 name = json_string_value(jarg);
359 json_object_set_new(answer,
"message", json_string(
"Iface name is NULL"));
364 if (!strcmp(name, pd->
dev)) {
365 json_t *jdata = json_object();
367 json_object_set_new(answer,
"message",
368 json_string(
"internal error at json object creation"));
371 json_object_set_new(jdata,
"pkts",
373 json_object_set_new(jdata,
"invalid-checksums",
375 json_object_set_new(jdata,
"drop",
377 json_object_set_new(jdata,
"bypassed",
379 json_object_set_new(answer,
"message", jdata);
383 json_object_set_new(answer,
"message", json_string(
"Iface does not exist"));
387 TmEcode LiveDeviceIfaceList(json_t *cmd, json_t *answer,
void *data)
395 jdata = json_object();
397 json_object_set_new(answer,
"message",
398 json_string(
"internal error at json object creation"));
401 jarray = json_array();
402 if (jarray == NULL) {
403 json_object_set_new(answer,
"message",
404 json_string(
"internal error at json object creation"));
408 json_array_append_new(jarray, json_string(pd->
dev));
412 json_object_set_new(jdata,
"count", json_integer(i));
413 json_object_set_new(jdata,
"ifaces", jarray);
414 json_object_set_new(answer,
"message", jdata);
456 static void LiveDevExtensionFree(
void *x)
468 NULL, LiveDevExtensionFree);
477 if (bpinfo == NULL) {
478 SCLogError(
"Can't allocate bypass info structure");
500 if (family == AF_INET) {
502 }
else if (family == AF_INET6) {
519 if (family == AF_INET) {
521 }
else if (family == AF_INET6) {
538 if (family == AF_INET) {
540 }
else if (family == AF_INET6) {
557 if (family == AF_INET) {
559 }
else if (family == AF_INET6) {
565 #ifdef BUILD_UNIX_SOCKET
566 TmEcode LiveDeviceGetBypassedStats(json_t *cmd, json_t *answer,
void *data)
568 if (g_bypass_storage_id.
id < 0) {
569 json_object_set_new(answer,
"message", json_string(
"Bypass not enabled"));
573 json_t *ifaces = NULL;
577 uint64_t ipv4_hash_count =
SC_ATOMIC_GET(bpinfo->ipv4_hash_count);
578 uint64_t ipv6_hash_count =
SC_ATOMIC_GET(bpinfo->ipv6_hash_count);
583 json_t *iface = json_object();
584 if (ifaces == NULL) {
585 ifaces = json_object();
586 if (ifaces == NULL) {
587 json_object_set_new(answer,
"message",
588 json_string(
"internal error at json object creation"));
592 json_object_set_new(iface,
"ipv4_maps_count", json_integer(ipv4_hash_count));
593 json_object_set_new(iface,
"ipv4_success", json_integer(ipv4_success));
594 json_object_set_new(iface,
"ipv4_fail", json_integer(ipv4_fail));
595 json_object_set_new(iface,
"ipv6_maps_count", json_integer(ipv6_hash_count));
596 json_object_set_new(iface,
"ipv6_success", json_integer(ipv6_success));
597 json_object_set_new(iface,
"ipv6_fail", json_integer(ipv6_fail));
598 json_object_set_new(ifaces, ldev->
dev, iface);
602 json_object_set_new(answer,
"message", ifaces);
606 json_object_set_new(answer,
"message",
607 json_string(
"No interface using bypass"));