Skip to content

Commit

Permalink
Add pcap and mirror logging
Browse files Browse the repository at this point in the history
- Do not clear libnet arp request packet, we send the same packet on
each iteration of the loop, so no need for a separate function to send
an arp request
- Fix ether type of ipv6 packets, needs testing
- Refactor for better log messages, remove redundant vars, free vars,
and use static vars and functions amap
- Fix var free and destroy on exit
- Refactor for var init and names
- Use correct print functions
- Increase mirror target loop count and pcap_handler packet processing
count for busy networks
- Use libpcap to recv arp replies instead of socket(2), because
socket(2) cannot recv any arp packets on OpenBSD, and fails sometimes on
Linux too
- Get mirror target ethernet address and check if reply is from target,
so we know target is up
- Exit failing if mirror target is down
- Refactor arp code, init libnet (and pcap) only once
- Remove new lines in libnet error messages, libnet already appends new
lines
- Move all pcap and mirror logging code into logpkt.c/h, use logpkt_
prefix now
- Fix values of nh and hl params of libnet_build_ipv6(), needs testing
- Add libnet ipv6 support to pcap logging, not tested with ipv6 yet, but
does not break ipv4 support, needs review and testing
- Keep the privsep socket open for pcap logging, now due to support for
separate files per connection
- Refactor for the new options
- Add -Y and -y options for pcap logging to separate files, similar to
-S and -F options, update conffile and its man page accordingly
- Fix documentation
- Remove redundant content log flags
- Handle error conditions while creating new lbs
- Prevent possible memory leak: create min number of lbs based on
enabled content loggers
- Create opts_set_* functions and conffile options for pcap and mirror
logging
- Separate content loggers, so they don't exclude each other now
- Prevent running as root by moving libnet_init() to somewhere before
privsep fork
- Fix compiler warnings for type mismatches, etc.
- Fix memory leak introduced in logbuf_write_free() by freeing buf
- Apply coding style and clean up
- Fix excessive fragmentation in HTTP packets in pcap logs by calling
write callback only once with a new buffer combining all accumulated log
buffers in the linked list Have to remove NONNULL(1) from
logbuf_write_free declaration now, because we check lb for NULL in while
condition
- Replace recursion in logbuf_write_free() with while loop
- Add libnet autodetection, temporary fix, needs review
- Add OPENBSD directive to fix OpenBSD specific differences, temporary
fix, needs review
- Fix memory leaks
- Fix build warnings
- Add license headers
- Improve log messages
- Fix coding style
- Clean-up
- Merge remote-tracking branch 'cihankom/master'
    # Conflicts:
    #       main.c
    #       opts.h
  • Loading branch information
sonertari authored and droe committed Sep 30, 2018
1 parent f8ecf15 commit b430b4b
Show file tree
Hide file tree
Showing 17 changed files with 1,652 additions and 147 deletions.
71 changes: 70 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#
# OPENSSL_BASE Prefix of OpenSSL library and headers to build against
# LIBEVENT_BASE Prefix of libevent library and headers to build against
# LIBNET_BASE Prefix of libnet library and headers to build against
# CHECK_BASE Prefix of check library and headers to build against (optional)
# PKGCONFIG Name/path of pkg-config program to use for auto-detection
# PCFLAGS Additional pkg-config flags
Expand Down Expand Up @@ -141,7 +142,11 @@ ifneq ($(wildcard /usr/include/linux/netfilter.h),)
FEATURES+= -DHAVE_NETFILTER
endif


# Autodetect OpenBSD
ifeq ($(shell uname),OpenBSD)
FEATURES+= -DOPENBSD
endif

### Variables you might need to override

PREFIX?= /usr/local
Expand Down Expand Up @@ -225,6 +230,14 @@ PKGS+= $(shell $(PKGCONFIG) $(PCFLAGS) --exists libevent_openssl \
PKGS+= $(shell $(PKGCONFIG) $(PCFLAGS) --exists libevent_pthreads \
&& echo libevent_pthreads)
endif
ifndef LIBNET_BASE
PKGS+= $(shell $(PKGCONFIG) $(PCFLAGS) --exists libnet \
&& echo libnet)
endif
ifndef LIBPCAP_BASE
PKGS+= $(shell $(PKGCONFIG) $(PCFLAGS) --exists libpcap \
&& echo libpcap)
endif
TPKGS:=
ifndef CHECK_BASE
TPKGS+= $(shell $(PKGCONFIG) $(PCFLAGS) --exists check \
Expand Down Expand Up @@ -269,6 +282,46 @@ $(error dependency 'libevent 2.x' not found; \
install it or point LIBEVENT_BASE to base path)
endif
endif
ifeq (,$(filter libnet,$(PKGS)))
# Linux /usr/include/libnet.h
# OpenBSD /usr/local/include/libnet-1.1/libnet.h
# XXX?
LIBNET_PAT:= libnet.h
ifdef LIBNET_BASE
LIBNET_FIND:= $(wildcard $(LIBNET_BASE)/$(LIBNET_PAT))
else
LIBNET_FIND:= $(wildcard \
/usr/local/opt/libnet/$(LIBNET_PAT) \
/opt/local/include/$(LIBNET_PAT) \
/usr/local/include/$(LIBNET_PAT) \
/usr/local/include/libnet-1.1/$(LIBNET_PAT) \
/usr/include/$(LIBNET_PAT))
endif
LIBNET_AVAIL:= $(LIBNET_FIND:/$(LIBNET_PAT)=)
LIBNET_FOUND:= $(word 1,$(LIBNET_AVAIL))
ifndef LIBNET_FOUND
$(error dependency 'libnet' not found; \
install it or point LIBNET_BASE to base path)
endif
endif
ifeq (,$(filter libpcap,$(PKGS)))
LIBPCAP_PAT:= include/pcap.h
ifdef LIBPCAP_BASE
LIBPCAP_FIND:= $(wildcard $(LIBPCAP_BASE)/$(LIBPCAP_PAT))
else
LIBPCAP_FIND:= $(wildcard \
/usr/local/opt/libpcap/$(LIBPCAP_PAT) \
/opt/local/$(LIBPCAP_PAT) \
/usr/local/$(LIBPCAP_PAT) \
/usr/$(LIBPCAP_PAT))
endif
LIBPCAP_AVAIL:=$(LIBPCAP_FIND:/$(LIBPCAP_PAT)=)
LIBPCAP_FOUND:=$(word 1,$(LIBPCAP_AVAIL))
ifndef LIBPCAP_FOUND
$(error dependency 'libpcap' not found; \
install it or point LIBPCAP_BASE to base path)
endif
endif
ifeq (,$(filter check,$(TPKGS)))
CHECK_PAT:= include/check.h
ifdef CHECK_BASE
Expand Down Expand Up @@ -303,6 +356,19 @@ endif
ifeq (,$(filter libevent_pthreads,$(PKGS)))
PKG_LIBS+= -levent_pthreads
endif
ifdef LIBNET_FOUND
# XXX?
LIBNET_INC_BASE:= $(LIBNET_FOUND:/libnet-1.1=)
PKG_CPPFLAGS+= -I$(LIBNET_INC_BASE)
LIBNET_LIB_BASE:= $(LIBNET_INC_BASE:/include=)
PKG_LDFLAGS+= -L$(LIBNET_LIB_BASE)/lib
PKG_LIBS+= -lnet
endif
ifdef LIBPCAP_FOUND
PKG_CPPFLAGS+= -I$(LIBPCAP_FOUND)/include
PKG_LDFLAGS+= -L$(LIBPCAP_FOUND)/lib
PKG_LIBS+= -lpcap
endif
ifdef CHECK_FOUND
TPKG_CPPFLAGS+= -I$(CHECK_FOUND)/include
TPKG_LDFLAGS+= -L$(CHECK_FOUND)/lib
Expand Down Expand Up @@ -377,6 +443,9 @@ endif
ifdef LIBEVENT_FOUND
$(info LIBEVENT_BASE: $(strip $(LIBEVENT_FOUND)))
endif
ifdef LIBNET_FOUND
$(info LIBNET_BASE: $(strip $(LIBNET_FOUND)))
endif
ifdef CHECK_FOUND
$(info CHECK_BASE: $(strip $(CHECK_FOUND)))
endif
Expand Down
Loading

0 comments on commit b430b4b

Please sign in to comment.