Skip to content

Commit acc4edc

Browse files
andrewchiGitHub Enterprise
authored andcommitted
Merge pull request #506 from network-intelligence/dev
Merging dev into trunk for 2.8.0
2 parents 87d392a + cc1a256 commit acc4edc

File tree

175 files changed

+6782
-1399
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+6782
-1399
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ unit_tests/pcaps/*.pcap
1818
.vscode/
1919
*.mk
2020
*.tgz
21-
src/libmerc/asn1/oid.cc
22-
src/libmerc/asn1/oid.h
21+
*CMakeCache.txt
22+
*CMakeFiles/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "src/libmerc/xsimd"]
2+
path = src/libmerc/xsimd
3+
url = https://github.com/xtensor-stack/xsimd.git

Makefile

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ifneq ($(MERCURY_CFG),)
4444
$(INSTALLDATA) $(MERCURY_CFG) /etc/mercury/mercury.cfg
4545
else
4646
@echo $(COLOR_RED) "error: no configuration file specified; run as 'make install MERCURY_CFG=filename'" $(COLOR_OFF)
47-
@/bin/false
47+
@false
4848
endif
4949
endif
5050

@@ -121,6 +121,69 @@ libs:
121121
test:
122122
cd src && $(MAKE) test
123123

124+
.PHONY: test-coverage
125+
test-coverage:
126+
@bash -e -c -o pipefail ' \
127+
mkdir -p coverage && \
128+
make && \
129+
make clean-helper > /dev/null && \
130+
make --directory=src COVERAGE_ENABLED=1 use_fsanitize=no run_unit_test > /dev/null && \
131+
lcov -q --directory . --capture --output-file ./coverage/mercury_unit_tests_1.info && \
132+
echo -e $(COLOR_GREEN) "created coverage file for unit tests" $(COLOR_OFF) && \
133+
make clean-helper > /dev/null && \
134+
\
135+
make --directory=src/libmerc COVERAGE_ENABLED=1 use_fsanitize=no libmerc.so > /dev/null && \
136+
make --directory=unit_tests COVERAGE_ENABLED=1 use_fsanitize=no libmerc_driver_tls_only > /dev/null && \
137+
make --directory=unit_tests run_libmerc_tls_only_tests > /dev/null && \
138+
lcov -q --directory . --capture --output-file ./coverage/mercury_libmerc_driver_tls_only.info && \
139+
echo -e $(COLOR_GREEN) "created coverage file for libmerc driver tls tests" $(COLOR_OFF) && \
140+
make clean-helper > /dev/null && \
141+
\
142+
make --directory=src/libmerc COVERAGE_ENABLED=1 use_fsanitize=no libmerc.so > /dev/null && \
143+
make --directory=unit_tests COVERAGE_ENABLED=1 use_fsanitize=no libmerc_driver_multiprotocol > /dev/null && \
144+
make --directory=unit_tests run_libmerc_multiprotocol_tests > /dev/null && \
145+
lcov -q --directory . --capture --output-file ./coverage/mercury_libmerc_driver_multiprotocol.info && \
146+
echo -e $(COLOR_GREEN) "created coverage file for libmerc driver multiprotocol tests" $(COLOR_OFF) && \
147+
make clean-helper > /dev/null && \
148+
\
149+
make --directory=src COVERAGE_ENABLED=1 use_fsanitize=no mercury > /dev/null && \
150+
make --directory=test COVERAGE_ENABLED=1 clean comp analysis cert-check memcheck json-validity-test stats > /dev/null && \
151+
lcov -q --directory . --capture --output-file ./coverage/mercury_unit_tests_2.info && \
152+
echo -e $(COLOR_GREEN) "created coverage file for other unit tests" $(COLOR_OFF) && \
153+
make clean-helper > /dev/null && \
154+
\
155+
lcov --add-tracefile ./coverage/mercury_unit_tests_1.info \
156+
--add-tracefile ./coverage/mercury_libmerc_driver_tls_only.info \
157+
--add-tracefile ./coverage/mercury_libmerc_driver_multiprotocol.info \
158+
--add-tracefile ./coverage/mercury_unit_tests_2.info \
159+
--output-file ./coverage/mercury_total.info 2>&1 | grep -v "function data mismatch" && \
160+
lcov -q --remove ./coverage/mercury_total.info "/usr/include/*" "*/src/libmerc/rapidjson/*" "*/unit_tests/*" -o ./coverage/mercury_filtered_coverage.info && \
161+
genhtml --no-function-coverage --output-directory coverage_html_report ./coverage/mercury_filtered_coverage.info && \
162+
echo -e $(COLOR_GREEN) "created coverage report" $(COLOR_OFF) \
163+
' || { echo $(COLOR_RED) "failed to build coverage report" $(COLOR_OFF); exit 1; }
164+
165+
.PHONY: test-coverage-fuzz
166+
test-coverage-fuzz:
167+
@bash -e -c -o pipefail ' \
168+
mkdir -p coverage_fuzz && \
169+
make --directory=test COVERAGE_ENABLED=1 fuzz-test && \
170+
find . -name "*.profraw" | xargs -I {} sh -c "llvm-profdata merge -sparse '{}' -o \$$(dirname '{}')/default.profdata" && \
171+
find . -name "*exec" | xargs -I {} sh -c "llvm-cov export -format=lcov --instr-profile \$$(dirname '{}')/default.profdata {} > \$$(dirname '{}')/default.info" && \
172+
find ./test/fuzz -name "*.info" | sed "s/\\(\\S\\+\\)/--add-tracefile \\1/g" | xargs lcov --output-file ./coverage_fuzz/mercury_fuzz_test_1.info > /dev/null && \
173+
lcov -q --directory ./src --capture --output-file ./coverage_fuzz/mercury_fuzz_test_2.info && \
174+
echo -e $(COLOR_GREEN) "created coverage files for fuzz tests" $(COLOR_OFF) && \
175+
make clean-helper > /dev/null && \
176+
\
177+
lcov --add-tracefile ./coverage_fuzz/mercury_fuzz_test_1.info \
178+
--add-tracefile ./coverage_fuzz/mercury_fuzz_test_2.info \
179+
--output-file ./coverage_fuzz/mercury_total_with_fuzz.info 2>&1 | grep -v "function data mismatch" && \
180+
lcov -q --remove ./coverage_fuzz/mercury_total_with_fuzz.info \
181+
"/usr/include/*" "*/src/libmerc/rapidjson/*" "*/test/fuzz/*" \
182+
-o ./coverage_fuzz/mercury_filtered_coverage_with_fuzz.info && \
183+
genhtml --no-function-coverage --output-directory coverage_html_report_fuzz ./coverage_fuzz/mercury_filtered_coverage_with_fuzz.info && \
184+
echo -e $(COLOR_GREEN) "created final fuzz coverage report" $(COLOR_OFF) \
185+
' || { echo $(COLOR_RED) "failed to build fuzz coverage report" $(COLOR_OFF); exit 1; }
186+
124187
.PHONY: test_strict
125188
test_strict:
126189
cd src && $(MAKE) test
@@ -158,26 +221,34 @@ clean: sphinx-clean
158221
for file in Makefile README.md configure.ac Doxyfile; do if [ -e "$$file~" ]; then rm -f "$$file~" ; fi; done
159222
ifneq ($(wildcard src/Makefile), src/Makefile)
160223
@echo $(COLOR_RED) "error: run ./configure before running make (src/Makefile is missing)" $(COLOR_OFF)
161-
@/bin/false
224+
@false
162225
else
163-
cd src && $(MAKE) clean
164-
cd test && $(MAKE) clean
165-
cd unit_tests && $(MAKE) clean
226+
$(MAKE) clean-helper
166227
rm -rf doc/latex
228+
rm -rf coverage coverage_fuzz coverage_html_report coverage_html_report_fuzz
167229
endif
168230

169231
.PHONY: distclean
170232
distclean: clean
171233
ifneq ($(wildcard src/Makefile), src/Makefile)
172234
@echo $(COLOR_RED) "error: run ./configure before running make (src/Makefile is missing)" $(COLOR_OFF)
173-
@/bin/false
235+
@false
174236
else
175237
cd src && $(MAKE) distclean
176238
cd test && $(MAKE) distclean
177239
rm -rf autom4te.cache config.log config.status Makefile_helper.mk
178240
rm -f lib/*.so
179241
endif
180242

243+
.PHONY: clean-helper
244+
clean-helper:
245+
find . -name "*.gcda" -delete
246+
find . -name "*.gcno" -delete
247+
find . -name "*.gcov" -delete
248+
cd src && $(MAKE) clean
249+
cd test && $(MAKE) clean
250+
cd unit_tests && $(MAKE) clean
251+
181252
.PHONY: package-deb
182253
package-deb: mercury
183254
ifneq ($(wildcard src/Makefile), src/Makefile)

Makefile_helper.mk.in

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ is_macos = @IS_MACOS@
3535
#
3636
is_macos_arm = @IS_MACOS_ARM@
3737

38+
#The variable platform is used to represent intel or arm based architecture.
39+
# platform=intel for intel based platform
40+
# =arm for arm based platform
41+
# =unknown otherwise
42+
platform = @PLATFORM@
43+
3844
CXX = @CXX@
3945
CC = @CC@
40-
CFLAGS = --std=c++17
46+
CFLAGS += --std=c++17
4147
CFLAGS += -O3
4248
# CFLAGS += -march=x86-64 -mtune=generic
4349
CFLAGS += -Wall -Wextra -Wno-deprecated $(CDEFS) $(MSV)
@@ -52,6 +58,7 @@ CFLAGS += -Wno-deprecated-declarations
5258
CFLAGS += -Wno-long-long
5359
CFLAGS += -Wmissing-noreturn
5460
CFLAGS += -Wunreachable-code
61+
CFLAGS += -Wno-psabi
5562
CFLAGS += -fvisibility=hidden
5663
CFLAGS += -DNDEBUG
5764
# CFLAGS += -g

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ make
3838
```
3939
to build the package (and check for the programs and python modules required to test it). TPACKETv3 is present in Linux kernels newer than 3.2.
4040

41+
Building mercury on macOS Apple Silicon is currently experimental. Note that on
42+
macOS, standalone mercury can read pcap as input but not capture on an
43+
interface, since AF_PACKET is Linux-specific. The following has been tested
44+
on an M2 mac with Python 3.13.2 installed via the Homebrew command below.
45+
```
46+
brew install python openssl zlib
47+
mkdir -p ~/.envs
48+
python3 -m venv ~/.envs/merc
49+
source ~/.envs/merc/bin/activate
50+
python3 -m pip install --upgrade pip
51+
python3 -m pip install --upgrade jsonschema cryptography Cython wheel setuptools
52+
./configure && make
53+
cd src/cython && make && make wheel
54+
```
55+
4156
### Installation
4257
In the root directory, edit mercury.cfg with the network interface you want to capture from, then run
4358
```
@@ -77,7 +92,7 @@ which will remove the mercury program, resources directory, user, group, and sys
7792
### Compile-time options
7893
To create a debugging version of mercury, use the **make debug-mercury** target in the src/ subdirectory. Be sure to run **make clean** first.
7994

80-
There are compile-time options that can tune mercury for your hardware. Each of these options is set via a C/C++ preprocessor directive, which should be passed as an argument to "make" through the OPTFLAGS variable. Frst run **make clean** to remove the previous build, then run **make "OPTFLAGS=<DIRECTIVE>"**. This runs make, telling it to pass <DIRECTIVE> to the C/C++ compiler. The available compile time options are:
95+
There are compile-time options that can tune mercury for your hardware. Each of these options is set via a C/C++ preprocessor directive, which should be passed as an argument to "make" through the OPTFLAGS variable. First run **make clean** to remove the previous build, then run **make "OPTFLAGS=<DIRECTIVE>"**. This runs make, telling it to pass <DIRECTIVE> to the C/C++ compiler. The available compile time options are:
8196

8297
* -DDEBUG, which turns on debugging, and
8398
* -FBUFSIZE=16384, which sets the fwrite/fread buffer to 16,384 bytes (for instance).
@@ -212,7 +227,7 @@ DETAILS
212227
--reassembly enables reassembly
213228
This option allows mercury to keep track of tcp or udp segment state and
214229
and reassemble these segments based on the application in payload
215-
230+
216231
"[-u or --user] u" sets the UID and GID to those of user u, so that
217232
output file(s) are owned by this user. If this option is not set, then
218233
the UID is set to SUDO_UID, so that privileges are dropped to those of
@@ -310,9 +325,9 @@ are grateful to the copyright holders for making their excellent
310325
software available under licensing terms that allow its
311326
redistribution.
312327
* RapidJSON
313-
[https://github.com/cisco/mercury/src/rapidjson/license.txt](src/rapidjson/license.txt);
328+
[https://github.com/cisco/mercury/blob/main/src/libmerc/rapidjson/license.txt](src/libmerc/rapidjson/license.txt);
314329
this package is Copyright 2015 THL A29 Limited, a Tencent company,
315330
and Milo Yip.
316-
* lctrie [https://github.com/cisco/mercury/src/lctrie](src/lctrie);
331+
* lctrie [https://github.com/cisco/mercury/tree/main/src/libmerc/lctrie](src/libmerc/lctrie);
317332
this package is copyright 2016-2017 Charles Stewart
318333
<chuckination_at_gmail_dot_com>

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.7.1
1+
2.8.0

aclocal.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# generated automatically by aclocal 1.16.5 -*- Autoconf -*-
1+
# generated automatically by aclocal 1.16.1 -*- Autoconf -*-
22

3-
# Copyright (C) 1996-2021 Free Software Foundation, Inc.
3+
# Copyright (C) 1996-2018 Free Software Foundation, Inc.
44

55
# This file is free software; the Free Software Foundation
66
# gives unlimited permission to copy and/or distribute it,

build_pkg.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,14 @@ elif [ "$BUILDTYPE" == "rpm" ]; then
9595

9696
# note: we could detect libssl version here
9797

98+
# detect platform ID (e.g., "el8" or "el9")
99+
source /etc/os-release
100+
ELX=$(echo $PLATFORM_ID | cut -f2 -d:)
101+
98102
fpm -s dir -t rpm -n mercury $FPM_LINUX_OPTIONS \
99-
--depends 'libssl.so.10()(64bit)' \
100-
--depends 'libz.so.1()(64bit)' \
101-
--rpm-dist el7 \
103+
--depends 'openssl' \
104+
--depends 'zlib' \
105+
--rpm-dist $ELX \
102106
--rpm-attr 775,mercury,mercury:/usr/local/var/mercury \
103107
--description "$DESCRIPTION" \
104108
--after-remove ./install_mercury/postuninstall_rpm \

configure

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ ac_includes_default="\
639639
ac_header_c_list=
640640
ac_func_c_list=
641641
ac_subst_vars='LTLIBOBJS
642+
LCOV
642643
LLVM
643644
CLANGPP
644645
HAVE_AFL
@@ -656,6 +657,7 @@ USE_FSANITIZE
656657
USE_NO_GNU_UNIQUE
657658
IS_MACOS_ARM
658659
IS_MACOS
660+
PLATFORM
659661
host_os
660662
host_vendor
661663
host_cpu
@@ -4659,6 +4661,27 @@ IFS=$ac_save_IFS
46594661
case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
46604662

46614663

4664+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for platform architecture" >&5
4665+
printf %s "checking for platform architecture... " >&6; }
4666+
case "$host_cpu" in
4667+
i?86 | x86_64)
4668+
PLATFORM="intel"
4669+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Intel-compatible ($host_cpu)" >&5
4670+
printf "%s\n" "Intel-compatible ($host_cpu)" >&6; }
4671+
;;
4672+
arm* | aarch64)
4673+
PLATFORM="arm"
4674+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ARM-compatible ($host_cpu)" >&5
4675+
printf "%s\n" "ARM-compatible ($host_cpu)" >&6; }
4676+
;;
4677+
*)
4678+
PLATFORM="unknown"
4679+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Unknown architecture: $host_cpu" >&5
4680+
printf "%s\n" "$as_me: WARNING: Unknown architecture: $host_cpu" >&2;}
4681+
;;
4682+
esac
4683+
4684+
46624685
# Update lib and include paths for Apple Silicon
46634686
case $host_os in
46644687
darwin* )
@@ -5869,6 +5892,49 @@ printf "%s\n" "no" >&6; }
58695892
fi
58705893

58715894

5895+
# Extract the first word of "lcov", so it can be a program name with args.
5896+
set dummy lcov; ac_word=$2
5897+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
5898+
printf %s "checking for $ac_word... " >&6; }
5899+
if test ${ac_cv_prog_LCOV+y}
5900+
then :
5901+
printf %s "(cached) " >&6
5902+
else case e in #(
5903+
e) if test -n "$LCOV"; then
5904+
ac_cv_prog_LCOV="$LCOV" # Let the user override the test.
5905+
else
5906+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
5907+
for as_dir in $PATH
5908+
do
5909+
IFS=$as_save_IFS
5910+
case $as_dir in #(((
5911+
'') as_dir=./ ;;
5912+
*/) ;;
5913+
*) as_dir=$as_dir/ ;;
5914+
esac
5915+
for ac_exec_ext in '' $ac_executable_extensions; do
5916+
if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
5917+
ac_cv_prog_LCOV="yes"
5918+
printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
5919+
break 2
5920+
fi
5921+
done
5922+
done
5923+
IFS=$as_save_IFS
5924+
5925+
fi ;;
5926+
esac
5927+
fi
5928+
LCOV=$ac_cv_prog_LCOV
5929+
if test -n "$LCOV"; then
5930+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LCOV" >&5
5931+
printf "%s\n" "$LCOV" >&6; }
5932+
else
5933+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
5934+
printf "%s\n" "no" >&6; }
5935+
fi
5936+
5937+
58725938
if test "x$TCPREPLAY" = xyes
58735939
then :
58745940

@@ -5925,6 +5991,14 @@ else case e in #(
59255991
printf "%s\n" "$as_me: WARNING: llvm not found; make fuzz-test may not work" >&2;} ;;
59265992
esac
59275993
fi
5994+
if test "x$LCOV" = xyes
5995+
then :
5996+
5997+
else case e in #(
5998+
e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: lcov not found; make test-coverage and test-coverage-fuzz will not work" >&5
5999+
printf "%s\n" "$as_me: WARNING: lcov not found; make test-coverage and test-coverage-fuzz will not work" >&2;} ;;
6000+
esac
6001+
fi
59286002
ac_config_files="$ac_config_files src/libmerc/Makefile src/cython/Makefile src/Makefile test/Makefile unit_tests/Makefile Makefile_helper.mk install_mercury/mercury.service"
59296003

59306004
cat >confcache <<\_ACEOF

configure.ac

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ AC_USE_SYSTEM_EXTENSIONS
66
#AC_PROG_CC
77
AC_PROG_CXX
88
AC_CANONICAL_HOST
9+
AC_MSG_CHECKING([for platform architecture])
10+
case "$host_cpu" in
11+
i?86 | x86_64)
12+
PLATFORM="intel"
13+
AC_MSG_RESULT([Intel-compatible ($host_cpu)])
14+
;;
15+
arm* | aarch64)
16+
PLATFORM="arm"
17+
AC_MSG_RESULT([ARM-compatible ($host_cpu)])
18+
;;
19+
*)
20+
PLATFORM="unknown"
21+
AC_MSG_WARN([Unknown architecture: $host_cpu])
22+
;;
23+
esac
24+
AC_SUBST([PLATFORM])
25+
926
# Update lib and include paths for Apple Silicon
1027
case $host_os in
1128
darwin* )
@@ -32,6 +49,7 @@ AC_CHECK_FUNCS([munmap])
3249
AC_CHECK_FUNCS([socket])
3350
AC_CHECK_FUNCS([strerror])
3451
AC_CHECK_FUNCS([strtol])
52+
AC_CHECK_FUNCS([gettid], [AC_DEFINE([HAVE_GETTID], [1], [Define if gettid exists.])])
3553
AC_CHECK_HEADERS([arpa/inet.h])
3654
AC_CHECK_HEADERS([fcntl.h])
3755
AC_CHECK_HEADERS([stddef.h])
@@ -81,6 +99,7 @@ AC_CHECK_PROG(VALGRIND,valgrind,yes)
8199
AC_CHECK_PROG(HAVE_AFL,afl-g++,yes)
82100
AC_CHECK_PROG(CLANGPP, clang++, yes)
83101
AC_CHECK_PROG(LLVM,llvm-link,yes)
102+
AC_CHECK_PROG(LCOV, lcov, yes)
84103
AS_IF([test "x$TCPREPLAY" = xyes],
85104
[],
86105
[AC_MSG_WARN([tcpreplay not found; test/Makefile dummy-capture test will not work])])
@@ -102,5 +121,8 @@ AS_IF([test "x$CLANGPP" = xyes],
102121
AS_IF([test "x$LLVM" = xyes],
103122
[],
104123
[AC_MSG_WARN([llvm not found; make fuzz-test may not work])])
124+
AS_IF([test "x$LCOV" = xyes],
125+
[],
126+
[AC_MSG_WARN([lcov not found; make test-coverage and test-coverage-fuzz will not work])])
105127
AC_CONFIG_FILES(src/libmerc/Makefile src/cython/Makefile src/Makefile test/Makefile unit_tests/Makefile Makefile_helper.mk install_mercury/mercury.service)
106128
AC_OUTPUT

0 commit comments

Comments
 (0)