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;
149 SCLogDebug(
"Device \"%s\" registered and created.", dev);
201 static int LiveSafeDeviceName(
const char *devname,
char *newdevname,
size_t destlen)
203 const size_t devnamelen = strlen(devname);
208 if (devnamelen >= 5 && strncmp(devname,
"0000:", 5) == 0) {
209 strlcpy(newdevname, devname + 5, destlen);
221 if ((destlen-1) > 10 || (destlen-1) < 6) {
227 SCLogInfo(
"%s: shortening device name to %s", devname, newdevname);
229 strlcpy(newdevname, devname, destlen);
252 if (!strcmp(name, pd->
dev)) {
263 if (live_dev == NULL)
285 if ((!strcmp(subchild->
name, itemname))) {
286 if (!strcmp(subchild->
val,
"default"))
289 itemname, subchild->
val);
305 live_devices_stats = 0;
314 if (live_devices_stats) {
315 SCLogNotice(
"%s: packets: %" PRIu64
", drops: %" PRIu64
316 " (%.2f%%), invalid chksum: %" PRIu64,
334 #ifdef BUILD_UNIX_SOCKET
335 TmEcode LiveDeviceIfaceStat(json_t *cmd, json_t *answer,
void *data)
339 const char * name = NULL;
340 json_t *jarg = json_object_get(cmd,
"iface");
341 if(!json_is_string(jarg)) {
342 json_object_set_new(answer,
"message", json_string(
"Iface is not a string"));
345 name = json_string_value(jarg);
347 json_object_set_new(answer,
"message", json_string(
"Iface name is NULL"));
352 if (!strcmp(name, pd->
dev)) {
353 json_t *jdata = json_object();
355 json_object_set_new(answer,
"message",
356 json_string(
"internal error at json object creation"));
359 json_object_set_new(jdata,
"pkts",
361 json_object_set_new(jdata,
"invalid-checksums",
363 json_object_set_new(jdata,
"drop",
365 json_object_set_new(jdata,
"bypassed",
367 json_object_set_new(answer,
"message", jdata);
371 json_object_set_new(answer,
"message", json_string(
"Iface does not exist"));
375 TmEcode LiveDeviceIfaceList(json_t *cmd, json_t *answer,
void *data)
383 jdata = json_object();
385 json_object_set_new(answer,
"message",
386 json_string(
"internal error at json object creation"));
389 jarray = json_array();
390 if (jarray == NULL) {
391 json_object_set_new(answer,
"message",
392 json_string(
"internal error at json object creation"));
396 json_array_append_new(jarray, json_string(pd->
dev));
400 json_object_set_new(jdata,
"count", json_integer(i));
401 json_object_set_new(jdata,
"ifaces", jarray);
402 json_object_set_new(answer,
"message", jdata);
444 static void LiveDevExtensionFree(
void *x)
456 NULL, LiveDevExtensionFree);
465 if (bpinfo == NULL) {
466 SCLogError(
"Can't allocate bypass info structure");
488 if (family == AF_INET) {
490 }
else if (family == AF_INET6) {
507 if (family == AF_INET) {
509 }
else if (family == AF_INET6) {
526 if (family == AF_INET) {
528 }
else if (family == AF_INET6) {
545 if (family == AF_INET) {
547 }
else if (family == AF_INET6) {
564 if (family == AF_INET) {
566 }
else if (family == AF_INET6) {
572 #ifdef BUILD_UNIX_SOCKET
573 TmEcode LiveDeviceGetBypassedStats(json_t *cmd, json_t *answer,
void *data)
577 json_t *ifaces = NULL;
581 uint64_t ipv4_hash_count =
SC_ATOMIC_GET(bpinfo->ipv4_hash_count);
582 uint64_t ipv6_hash_count =
SC_ATOMIC_GET(bpinfo->ipv6_hash_count);
587 json_t *iface = json_object();
588 if (ifaces == NULL) {
589 ifaces = json_object();
590 if (ifaces == NULL) {
591 json_object_set_new(answer,
"message",
592 json_string(
"internal error at json object creation"));
596 json_object_set_new(iface,
"ipv4_maps_count", json_integer(ipv4_hash_count));
597 json_object_set_new(iface,
"ipv4_success", json_integer(ipv4_success));
598 json_object_set_new(iface,
"ipv4_fail", json_integer(ipv4_fail));
599 json_object_set_new(iface,
"ipv6_maps_count", json_integer(ipv6_hash_count));
600 json_object_set_new(iface,
"ipv6_success", json_integer(ipv6_success));
601 json_object_set_new(iface,
"ipv6_fail", json_integer(ipv6_fail));
602 json_object_set_new(ifaces, ldev->
dev, iface);
606 json_object_set_new(answer,
"message", ifaces);
610 json_object_set_new(answer,
"message",
611 json_string(
"No interface using bypass"));