Skip to content

Commit d4c03cd

Browse files
authored
Merge pull request #7 from ns1/pgray-DOPS-642
add -x|--nolock arg
2 parents 7938afc + 3cbf8c8 commit d4c03cd

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

src/Makefile

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ MAKEFLAGS += -rR
4545
MAKEFLAGS += --warn-undefined-variables
4646
MAKEFLAGS += --jobs=$(shell grep "^processor" /proc/cpuinfo | wc -l)
4747

48-
# Debugging option
49-
ifeq ("$(origin DEBUG)", "command line")
50-
DEBUG := 1
51-
else
52-
DEBUG := 0
53-
endif
54-
5548
# Compiler detection
5649
ifneq ($(CC),)
5750
ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
@@ -67,17 +60,14 @@ endif
6760
CFLAGS_DEF = -std=gnu99
6861
CFLAGS_DEF += -pipe
6962

70-
ifeq ($(DEBUG), 1)
63+
ifeq ($(DISTRO), 1)
7164
CFLAGS_DEF += -O2
7265
CFLAGS_DEF += -g
7366
else
74-
ifeq ($(DISTRO), 1)
75-
CFLAGS_DEF += -O2
76-
else
7767
CFLAGS_DEF += -march=native
7868
CFLAGS_DEF += -mtune=native
7969
CFLAGS_DEF += -O3
80-
endif
70+
CFLAGS_DEF += -g
8171
endif
8272
ifeq ($(HARDENING), 1)
8373
CFLAGS_DEF += -fPIE -pie
@@ -128,7 +118,7 @@ VERSION_LONG = "$(VERSION_SHORT)$(CONFIG_RC) ($(NAME))"
128118

129119
export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
130120
export CROSS_COMPILE
131-
export DEBUG DISTRO HARDENING
121+
export DISTRO HARDENING
132122

133123
bold = $(shell tput bold)
134124
normal = $(shell tput sgr0)

src/pktvisor.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct ctx {
6565
unsigned long kpull, dump_interval, tx_bytes, tx_packets;
6666
size_t reserve_size;
6767
bool randomize, promiscuous, enforce, jumbo, dump_bpf, hwtimestamp, verbose,
68-
ui;
68+
ui, nolock;
6969
enum pcap_ops_groups pcap; enum dump_mode dump_mode;
7070
uid_t uid; gid_t gid; uint32_t link_type, magic;
7171
struct dnsctxt dns_ctxt;
@@ -74,7 +74,7 @@ struct ctx {
7474
static volatile sig_atomic_t sigint = 0;
7575
static volatile bool next_dump = false;
7676

77-
static const char *short_options = "d:i:o:rf:MNJt:S:k:n:b:HQmcZYsqXlvhF:GAP:Vu:g:T:DBUL:W:C:a:";
77+
static const char *short_options = "d:i:o:rf:MNJt:S:k:n:b:HQmcZYsqXxlvhF:GAP:Vu:g:T:DBUL:W:C:a:";
7878
static const struct option long_options[] = {
7979
{"dev", required_argument, NULL, 'd'},
8080
{"in", required_argument, NULL, 'i'},
@@ -89,6 +89,7 @@ static const struct option long_options[] = {
8989
{"prefix", required_argument, NULL, 'P'},
9090
{"user", required_argument, NULL, 'u'},
9191
{"group", required_argument, NULL, 'g'},
92+
{"nomemlock", no_argument, NULL, 'x'},
9293
{"magic", required_argument, NULL, 'T'},
9394
{"rand", no_argument, NULL, 'r'},
9495
// {"rfraw", no_argument, NULL, 'R'},
@@ -1156,21 +1157,21 @@ static void init_ctx(struct ctx *ctx)
11561157
ctx->uid = getgid();
11571158

11581159
ctx->cpu = -1;
1159-
ctx->packet_type = -1;
1160-
ctx->local_prefix = -1;
1160+
ctx->packet_type = -1;
1161+
ctx->local_prefix = -1;
11611162

11621163
ctx->magic = ORIGINAL_TCPDUMP_MAGIC;
1163-
ctx->print_mode = PRINT_NONE;
1164+
ctx->print_mode = PRINT_NONE;
11641165
ctx->pcap = PCAP_OPS_SG;
11651166

11661167
ctx->dump_mode = DUMP_INTERVAL_TIME;
11671168
ctx->dump_interval = 60;
11681169

11691170
ctx->promiscuous = true;
11701171
ctx->randomize = false;
1171-
ctx->hwtimestamp = true;
1172-
ctx->ui = false;
1173-
1172+
ctx->nolock = false;
1173+
ctx->hwtimestamp = true;
1174+
ctx->ui = false;
11741175
}
11751176

11761177
static void destroy_ctx(struct ctx *ctx)
@@ -1214,6 +1215,7 @@ static void __noreturn help(void)
12141215
" -b|--bind-cpu <cpu> Bind to specific CPU\n"
12151216
" -u|--user <userid> Drop privileges and change to userid\n"
12161217
" -g|--group <groupid> Drop privileges and change to groupid\n"
1218+
" -x|--nolock Don't lock memory\n"
12171219
" -H|--prio-high Make this high priority process\n"
12181220
" -Q|--notouch-irq Do not touch IRQ CPU affinity of NIC\n"
12191221
" -s|--silent Do not print captured packets\n"
@@ -1324,6 +1326,9 @@ int main(int argc, char **argv)
13241326
ctx.gid = strtoul(optarg, NULL, 0);
13251327
ctx.enforce = true;
13261328
break;
1329+
case 'x':
1330+
ctx.nolock = true;
1331+
break;
13271332
case 't':
13281333
if (!strncmp(optarg, "host", strlen("host")))
13291334
ctx.packet_type = PACKET_HOST;
@@ -1581,7 +1586,7 @@ int main(int argc, char **argv)
15811586
init_geoip(ctx.geoip_loc, ctx.geoip_asn);
15821587
if (setsockmem)
15831588
set_system_socket_memory(vals, array_size(vals));
1584-
if (!ctx.enforce)
1589+
if (!ctx.enforce && !ctx.nolock)
15851590
xlockme();
15861591

15871592
if (ctx.verbose)
@@ -1595,7 +1600,7 @@ int main(int argc, char **argv)
15951600
if (ctx.ui)
15961601
pktvisor_ui_shutdown();
15971602

1598-
if (!ctx.enforce)
1603+
if (!ctx.enforce && !ctx.nolock)
15991604
xunlockme();
16001605
if (setsockmem)
16011606
reset_system_socket_memory(vals, array_size(vals));

0 commit comments

Comments
 (0)