Skip to content

Commit

Permalink
Use pcap thread, new options -miT and possible bugfix for -p and …
Browse files Browse the repository at this point in the history
…a small memory leak fix

Three new runtime options for `dsc`:
- `-m` sets monitor mode on interfaces
- `-i` sets immediate mode on interfaces
- `-T` disable the usage of threads in pcap thread

Also put all flag `int`'s as external in configure hooks, the integer for
promiscuous mode was not like that before which would mean that `-p` flag
have never worked before.

Device name was `strdup()`'ed in `Pcap_init()` but never freed later.
  • Loading branch information
jelu committed Aug 26, 2016
1 parent 6141765 commit d95190a
Show file tree
Hide file tree
Showing 13 changed files with 366 additions and 141 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*.la
config.log
config.status
config.guess
config.sub
stamp-h1
.deps
.libs
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "src/pcap_layers"]
path = src/pcap_layers
url = https://github.com/DNS-OARC/pcap_layers.git
[submodule "src/pcap-thread"]
path = src/pcap-thread
url = https://github.com/DNS-OARC/pcap-thread.git
2 changes: 1 addition & 1 deletion autogen.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh -e

autoreconf --force --install --no-recursive
autoreconf --force --install --no-recursive --include=src/pcap-thread/m4
4 changes: 3 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ AC_PROG_CC
AC_PROG_INSTALL
AM_PROG_CC_C_O

# pcap thread
AX_PCAP_THREAD

# Checks for libraries.
AC_CHECK_LIB([resolv], [inet_aton])
AC_CHECK_LIB([nsl], [gethostbyname])
AC_CHECK_LIB([socket], [connect])
AC_CHECK_LIB([pcap], [pcap_open_live])
AC_CHECK_LIB([GeoIP], [GeoIP_open])

# Checks for header files.
Expand Down
17 changes: 12 additions & 5 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ SUBDIRS = test

AM_CFLAGS = -I$(srcdir) \
-Wall \
-DUSE_IPV6=1
-DUSE_IPV6=1 \
$(PTHREAD_CFLAGS)

AM_CPPFLAGS = -I$(srcdir) \
-ITmfBase/Hapy/src/include \
-I$(srcdir)/TmfBase/Hapy/src/include \
-Wall \
-DUSE_IPV6=1
-DUSE_IPV6=1 \
$(PTHREAD_CFLAGS)

AM_CXXFLAGS = $(AM_CPPFLAGS)

EXTRA_DIST = TmfBase \
dsc.sh \
Expand Down Expand Up @@ -67,7 +71,8 @@ dsc_SOURCES = base64.c \
hashtbl.c \
lookup3.c \
xmalloc.c \
inX_addr.c
inX_addr.c \
pcap-thread/pcap_thread.c
dist_dsc_SOURCES = base64.h \
byteorder.h \
certain_qnames_index.h \
Expand Down Expand Up @@ -110,8 +115,10 @@ dist_dsc_SOURCES = base64.h \
transport_index.h \
xmalloc.h \
pcap_layers/byteorder.h \
pcap_layers/pcap_layers.h
dsc_LDADD = TmfBase/Hapy/src/.libs/libHapy.a
pcap_layers/pcap_layers.h \
pcap-thread/pcap_thread.h
dsc_LDADD = TmfBase/Hapy/src/.libs/libHapy.a \
$(PTHREAD_LIBS)
man1_MANS = dsc.1
man5_MANS = dsc.conf.5

Expand Down
35 changes: 35 additions & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,44 @@
/* Define to 1 if you have the <netinet/ip_compat.h> header file. */
#undef HAVE_NETINET_IP_COMPAT_H

/* Define to 1 if you have the `pcap_create' function. */
#undef HAVE_PCAP_CREATE

/* Define to 1 if the system has the type `pcap_direction_t'. */
#undef HAVE_PCAP_DIRECTION_T

/* Define to 1 if you have the `pcap_open_offline_with_tstamp_precision'
function. */
#undef HAVE_PCAP_OPEN_OFFLINE_WITH_TSTAMP_PRECISION

/* Define to 1 if you have the `pcap_setdirection' function. */
#undef HAVE_PCAP_SETDIRECTION

/* Define to 1 if you have the `pcap_set_immediate_mode' function. */
#undef HAVE_PCAP_SET_IMMEDIATE_MODE

/* Define to 1 if you have the `pcap_set_tstamp_precision' function. */
#undef HAVE_PCAP_SET_TSTAMP_PRECISION

/* Define to 1 if you have the `pcap_set_tstamp_type' function. */
#undef HAVE_PCAP_SET_TSTAMP_TYPE

/* Define if you have POSIX threads libraries and header files. */
#undef HAVE_PTHREAD

/* Have PTHREAD_PRIO_INHERIT. */
#undef HAVE_PTHREAD_PRIO_INHERIT

/* Define to 1 if your system has a GNU libc compatible `realloc' function,
and to 0 otherwise. */
#undef HAVE_REALLOC

/* Define to 1 if you have the `regcomp' function. */
#undef HAVE_REGCOMP

/* Define to 1 if you have the `sched_yield' function. */
#undef HAVE_SCHED_YIELD

/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT

Expand Down Expand Up @@ -187,6 +218,10 @@
/* Define to the version of this package. */
#undef PACKAGE_VERSION

/* Define to necessary symbol if this constant uses a non-standard name on
your system. */
#undef PTHREAD_CREATE_JOINABLE

/* Define to the type of arg 1 for `select'. */
#undef SELECT_TYPE_ARG1

Expand Down
9 changes: 6 additions & 3 deletions src/config_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@
#include "dns_message.h"
#include "syslog_debug.h"
#include "hashtbl.h"
#include "pcap.h"

int promisc_flag;
void Pcap_init(const char *device, int promisc);
extern int promisc_flag;
extern int monitor_flag;
extern int immediate_flag;
extern int threads_flag;
uint64_t minfree_bytes = 0;
int output_format_xml = 0;
int output_format_json = 0;
Expand All @@ -69,7 +72,7 @@ int
open_interface(const char *interface)
{
dsyslogf(LOG_INFO, "Opening interface %s", interface);
Pcap_init(interface, promisc_flag);
Pcap_init(interface, promisc_flag, monitor_flag, immediate_flag, threads_flag);
return 1;
}

Expand Down
37 changes: 32 additions & 5 deletions src/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
char *progname = NULL;
char *pid_file_name = NULL;
int promisc_flag = 1;
int monitor_flag = 0;
int immediate_flag = 0;
int threads_flag = 1;
int debug_flag = 0;
int nodaemon_flag = 0;
int have_reports = 0;
Expand Down Expand Up @@ -216,10 +219,15 @@ void
usage(void)
{
fprintf(stderr, "usage: %s [opts] dsc.conf\n", progname);
fprintf(stderr, "\t-d\tDebug mode. Exits after first write.\n");
fprintf(stderr, "\t-f\tForeground mode. Don't become a daemon.\n");
fprintf(stderr, "\t-p\tDon't put interface in promiscuous mode.\n");
fprintf(stderr, "\t-v\tPrint version and exit.\n");
fprintf(stderr,
"\t-d\tDebug mode. Exits after first write.\n"
"\t-f\tForeground mode. Don't become a daemon.\n"
"\t-p\tDon't put interface in promiscuous mode.\n"
"\t-m\tEnable monitor mode on interfaces.\n"
"\t-i\tEnable immediate mode on interfaces.\n"
"\t-T\tDisable usage of threads in pcap thread.\n"
"\t-v\tPrint version and exit.\n"
);
exit(1);
}

Expand Down Expand Up @@ -339,7 +347,7 @@ main(int argc, char *argv[])
srandom(time(NULL));
openlog(progname, LOG_PID | LOG_NDELAY, LOG_DAEMON);

while ((x = getopt(argc, argv, "fpdv")) != -1) {
while ((x = getopt(argc, argv, "fpdvmiT")) != -1) {
switch (x) {
case 'f':
nodaemon_flag = 1;
Expand All @@ -351,6 +359,15 @@ main(int argc, char *argv[])
debug_flag++;
nodaemon_flag = 1;
break;
case 'm':
monitor_flag = 1;
break;
case 'i':
immediate_flag = 1;
break;
case 'T':
threads_flag = 0;
break;
case 'v':
version();
default:
Expand All @@ -363,6 +380,16 @@ main(int argc, char *argv[])

if (argc != 1)
usage();

if (!promisc_flag)
dsyslog(LOG_INFO, "disabling interface promiscuous mode");
if (monitor_flag)
dsyslog(LOG_INFO, "enabling interface monitor mode");
if (immediate_flag)
dsyslog(LOG_INFO, "enabling interface immediate mode");
if (!threads_flag)
dsyslog(LOG_INFO, "disabling usage of threads in pcap thread");

dns_message_init();
ParseConfig(argv[0]);
#if HAVE_LIBGEOIP
Expand Down
11 changes: 10 additions & 1 deletion src/dsc.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dsc \- DNS Statistics Collector
.SH SYNOPSIS
.B dsc
[
.B \-dfp
.B \-dfpmiTv
]
.I dsc.conf
.SH DESCRIPTION
Expand All @@ -64,6 +64,15 @@ Foreground mode. Don't become a daemon.
.B \-p
Don't put interface in promiscuous mode.
.TP
.B \-m
Enable monitor mode on interfaces.
.TP
.B \-i
Enable immediate mode on interfaces.
.TP
.B \-T
Disable usage of threads in pcap thread.
.TP
.B \-v
Print version and exit.
.SH FILES
Expand Down
1 change: 1 addition & 0 deletions src/pcap-thread
Submodule pcap-thread added at 2768c8
Loading

0 comments on commit d95190a

Please sign in to comment.