Skip to content

Commit

Permalink
Merge pull request #7 from ns1/pgray-DOPS-642
Browse files Browse the repository at this point in the history
add -x|--nolock arg
  • Loading branch information
pgray authored Aug 29, 2019
2 parents 7938afc + 3cbf8c8 commit d4c03cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
16 changes: 3 additions & 13 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 15 additions & 10 deletions src/pktvisor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'},
Expand All @@ -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'},
Expand Down Expand Up @@ -1156,21 +1157,21 @@ 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;
ctx->dump_interval = 60;

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)
Expand Down Expand Up @@ -1214,6 +1215,7 @@ static void __noreturn help(void)
" -b|--bind-cpu <cpu> Bind to specific CPU\n"
" -u|--user <userid> Drop privileges and change to userid\n"
" -g|--group <groupid> 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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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));
Expand Down

0 comments on commit d4c03cd

Please sign in to comment.