From 3cbf8c89107975ae7d6ece9e1a10aa8dcf415e66 Mon Sep 17 00:00:00 2001 From: pgray Date: Wed, 28 Aug 2019 12:52:08 -0700 Subject: [PATCH] add -x|--nolock arg tab and 5 spaces... --- src/Makefile | 16 +++------------- src/pktvisor.c | 25 +++++++++++++++---------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/Makefile b/src/Makefile index 56ea111..79911b3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -45,13 +45,6 @@ MAKEFLAGS += -rR MAKEFLAGS += --warn-undefined-variables MAKEFLAGS += --jobs=$(shell grep "^processor" /proc/cpuinfo | wc -l) -# Debugging option -ifeq ("$(origin DEBUG)", "command line") - DEBUG := 1 -else - DEBUG := 0 -endif - # Compiler detection ifneq ($(CC),) ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1) @@ -67,17 +60,14 @@ endif CFLAGS_DEF = -std=gnu99 CFLAGS_DEF += -pipe -ifeq ($(DEBUG), 1) +ifeq ($(DISTRO), 1) CFLAGS_DEF += -O2 CFLAGS_DEF += -g else - ifeq ($(DISTRO), 1) - CFLAGS_DEF += -O2 - else CFLAGS_DEF += -march=native CFLAGS_DEF += -mtune=native CFLAGS_DEF += -O3 - endif + CFLAGS_DEF += -g endif ifeq ($(HARDENING), 1) CFLAGS_DEF += -fPIE -pie @@ -128,7 +118,7 @@ VERSION_LONG = "$(VERSION_SHORT)$(CONFIG_RC) ($(NAME))" export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION export CROSS_COMPILE -export DEBUG DISTRO HARDENING +export DISTRO HARDENING bold = $(shell tput bold) normal = $(shell tput sgr0) diff --git a/src/pktvisor.c b/src/pktvisor.c index 793d960..60884f5 100644 --- a/src/pktvisor.c +++ b/src/pktvisor.c @@ -65,7 +65,7 @@ struct ctx { unsigned long kpull, dump_interval, tx_bytes, tx_packets; size_t reserve_size; bool randomize, promiscuous, enforce, jumbo, dump_bpf, hwtimestamp, verbose, - ui; + ui, nolock; enum pcap_ops_groups pcap; enum dump_mode dump_mode; uid_t uid; gid_t gid; uint32_t link_type, magic; struct dnsctxt dns_ctxt; @@ -74,7 +74,7 @@ struct ctx { static volatile sig_atomic_t sigint = 0; static volatile bool next_dump = false; -static const char *short_options = "d:i:o:rf:MNJt:S:k:n:b:HQmcZYsqXlvhF:GAP:Vu:g:T:DBUL:W:C:a:"; +static const char *short_options = "d:i:o:rf:MNJt:S:k:n:b:HQmcZYsqXxlvhF:GAP:Vu:g:T:DBUL:W:C:a:"; static const struct option long_options[] = { {"dev", required_argument, NULL, 'd'}, {"in", required_argument, NULL, 'i'}, @@ -89,6 +89,7 @@ static const struct option long_options[] = { {"prefix", required_argument, NULL, 'P'}, {"user", required_argument, NULL, 'u'}, {"group", required_argument, NULL, 'g'}, + {"nomemlock", no_argument, NULL, 'x'}, {"magic", required_argument, NULL, 'T'}, {"rand", no_argument, NULL, 'r'}, // {"rfraw", no_argument, NULL, 'R'}, @@ -1156,11 +1157,11 @@ static void init_ctx(struct ctx *ctx) ctx->uid = getgid(); ctx->cpu = -1; - ctx->packet_type = -1; - ctx->local_prefix = -1; + ctx->packet_type = -1; + ctx->local_prefix = -1; ctx->magic = ORIGINAL_TCPDUMP_MAGIC; - ctx->print_mode = PRINT_NONE; + ctx->print_mode = PRINT_NONE; ctx->pcap = PCAP_OPS_SG; ctx->dump_mode = DUMP_INTERVAL_TIME; @@ -1168,9 +1169,9 @@ static void init_ctx(struct ctx *ctx) ctx->promiscuous = true; ctx->randomize = false; - ctx->hwtimestamp = true; - ctx->ui = false; - + ctx->nolock = false; + ctx->hwtimestamp = true; + ctx->ui = false; } static void destroy_ctx(struct ctx *ctx) @@ -1214,6 +1215,7 @@ static void __noreturn help(void) " -b|--bind-cpu Bind to specific CPU\n" " -u|--user Drop privileges and change to userid\n" " -g|--group Drop privileges and change to groupid\n" + " -x|--nolock Don't lock memory\n" " -H|--prio-high Make this high priority process\n" " -Q|--notouch-irq Do not touch IRQ CPU affinity of NIC\n" " -s|--silent Do not print captured packets\n" @@ -1324,6 +1326,9 @@ int main(int argc, char **argv) ctx.gid = strtoul(optarg, NULL, 0); ctx.enforce = true; break; + case 'x': + ctx.nolock = true; + break; case 't': if (!strncmp(optarg, "host", strlen("host"))) ctx.packet_type = PACKET_HOST; @@ -1581,7 +1586,7 @@ int main(int argc, char **argv) init_geoip(ctx.geoip_loc, ctx.geoip_asn); if (setsockmem) set_system_socket_memory(vals, array_size(vals)); - if (!ctx.enforce) + if (!ctx.enforce && !ctx.nolock) xlockme(); if (ctx.verbose) @@ -1595,7 +1600,7 @@ int main(int argc, char **argv) if (ctx.ui) pktvisor_ui_shutdown(); - if (!ctx.enforce) + if (!ctx.enforce && !ctx.nolock) xunlockme(); if (setsockmem) reset_system_socket_memory(vals, array_size(vals));