Skip to content

Commit 912704b

Browse files
committed
Adds suppor for HyperScan in the bulid system
1 parent 2e69ce6 commit 912704b

File tree

16 files changed

+291
-23
lines changed

16 files changed

+291
-23
lines changed

build/hyperscan.m4

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
dnl Check for HyperScan Libraries
2+
dnl CHECK_YAJL(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
3+
4+
AC_DEFUN([PROG_HS], [
5+
6+
# Needed if pkg-config will be used.
7+
AC_REQUIRE([PKG_PROG_PKG_CONFIG])
8+
9+
10+
# Possible names for the hs library/package (pkg-config)
11+
HS_POSSIBLE_LIB_NAMES="hs libhs"
12+
13+
# Possible extensions for the library
14+
HS_POSSIBLE_EXTENSIONS="so la sl dll dylib"
15+
16+
# Possible paths (if pkg-config was not found, proceed with the file lookup)
17+
HS_POSSIBLE_PATHS="/usr/lib /usr/local/lib /usr/local/libhs /usr/local/hyperscan /usr/local /opt/libhs /opt/hs /opt /usr /usr/lib64"
18+
19+
# Variables to be set by this very own script.
20+
HS_VERSION=""
21+
HS_CFLAGS=""
22+
HS_CPPFLAGS=""
23+
HS_LDADD=""
24+
HS_LDFLAGS=""
25+
26+
AC_ARG_WITH(
27+
hyperscan,
28+
AC_HELP_STRING(
29+
[--with-hyperscan=PATH],
30+
[Path to HyperScan prefix or config script]
31+
)
32+
)
33+
34+
if test "x${with_hyperscan}" == "xno"; then
35+
AC_DEFINE(HAVE_HS, 0, [Support for HS was disabled by the utilization of --without-hyperscan or --with-hyperscan=no])
36+
AC_MSG_NOTICE([Support for HyperScan was disabled by the utilization of --without-hyperscan or --with-hyperscan=no])
37+
HS_DISABLED=yes
38+
else
39+
if test "x${with_hyperscan}" == "xyes"; then
40+
HS_MANDATORY=yes
41+
AC_MSG_NOTICE([HyperScan support was marked as mandatory by the utilization of --with-hyperscan=yes])
42+
fi
43+
# for x in ${HS_POSSIBLE_LIB_NAMES}; do
44+
# CHECK_FOR_HS_AT(${x})
45+
# if test -n "${HS_VERSION}"; then
46+
# break
47+
# fi
48+
# done
49+
50+
# if test "x${with_hs}" != "xyes" or test "x${with_hs}" == "xyes"; then
51+
if test "x${with_hyperscan}" == "x" || test "x${with_hyperscan}" == "xyes"; then
52+
# Nothing about HyperScan was informed, using the pkg-config to figure things out.
53+
if test -n "${PKG_CONFIG}"; then
54+
HS_PKG_NAME=""
55+
for x in ${HS_POSSIBLE_LIB_NAMES}; do
56+
if ${PKG_CONFIG} --exists ${x}; then
57+
HS_PKG_NAME="$x"
58+
break
59+
fi
60+
done
61+
fi
62+
AC_MSG_NOTICE([Nothing about HyperScan was informed during the configure phase. Trying to detect it on the platform...])
63+
if test -n "${HS_PKG_NAME}"; then
64+
# Package was found using the pkg-config scripts
65+
HS_VERSION="`${PKG_CONFIG} ${HS_PKG_NAME} --modversion`"
66+
HS_CFLAGS="`${PKG_CONFIG} ${HS_PKG_NAME} --cflags`"
67+
HS_LDADD="`${PKG_CONFIG} ${HS_PKG_NAME} --libs-only-l`"
68+
HS_LDFLAGS="`${PKG_CONFIG} ${HS_PKG_NAME} --libs-only-L --libs-only-other`"
69+
HS_DISPLAY="${HS_LDADD}, ${HS_CFLAGS}"
70+
else
71+
# If pkg-config did not find anything useful, go over file lookup.
72+
for x in ${HS_POSSIBLE_LIB_NAMES}; do
73+
CHECK_FOR_HS_AT(${x})
74+
if test -n "${HS_VERSION}"; then
75+
break
76+
fi
77+
done
78+
fi
79+
fi
80+
if test "x${with_hyperscan}" != "x"; then
81+
# An specific path was informed, lets check.
82+
HS_MANDATORY=yes
83+
CHECK_FOR_HS_AT(${with_hs})
84+
fi
85+
# fi
86+
fi
87+
88+
if test -z "${HS_LDADD}"; then
89+
if test -z "${HS_MANDATORY}"; then
90+
if test -z "${HS_DISABLED}"; then
91+
AC_MSG_NOTICE([HyperScan library was not found])
92+
HS_FOUND=0
93+
else
94+
HS_FOUND=2
95+
fi
96+
else
97+
AC_MSG_ERROR([HyperScan was explicitly referenced but it was not found])
98+
HS_FOUND=-1
99+
fi
100+
else
101+
HS_FOUND=1
102+
AC_MSG_NOTICE([using HyperScan v${HS_VERSION}])
103+
HS_CFLAGS="-DWITH_HS ${HS_CFLAGS}"
104+
HS_DISPLAY="${HS_LDADD}, ${HS_CFLAGS}"
105+
AC_SUBST(HS_VERSION)
106+
AC_SUBST(HS_LDADD)
107+
AC_SUBST(HS_LIBS)
108+
AC_SUBST(HS_LDFLAGS)
109+
AC_SUBST(HS_CFLAGS)
110+
AC_SUBST(HS_DISPLAY)
111+
fi
112+
113+
114+
115+
AC_SUBST(HS_FOUND)
116+
117+
]) # AC_DEFUN [PROG_HS]
118+
119+
120+
AC_DEFUN([CHECK_FOR_HS_AT], [
121+
path=$1
122+
for y in ${HS_POSSIBLE_EXTENSIONS}; do
123+
for z in ${HS_POSSIBLE_LIB_NAMES}; do
124+
if test -e "${path}/${z}.${y}"; then
125+
hs_lib_path="${path}/"
126+
hs_lib_name="${z}"
127+
hs_lib_file="${hs_lib_path}/${z}.${y}"
128+
break
129+
fi
130+
if test -e "${path}/lib${z}.${y}"; then
131+
hs_lib_path="${path}/"
132+
hs_lib_name="${z}"
133+
hs_lib_file="${hs_lib_path}/lib${z}.${y}"
134+
break
135+
fi
136+
if test -e "${path}/lib/lib${z}.${y}"; then
137+
hs_lib_path="${path}/lib/"
138+
hs_lib_name="${z}"
139+
hs_lib_file="${hs_lib_path}/lib${z}.${y}"
140+
break
141+
fi
142+
if test -e "${path}/lib/x86_64-linux-gnu/lib${z}.${y}"; then
143+
hs_lib_path="${path}/lib/x86_64-linux-gnu/"
144+
hs_lib_name="${z}"
145+
hs_lib_file="${hs_lib_path}/lib${z}.${y}"
146+
break
147+
fi
148+
done
149+
if test -n "$hs_lib_path"; then
150+
break
151+
fi
152+
done
153+
if test -e "${path}/include/hs.h"; then
154+
hs_inc_path="${path}/include"
155+
elif test -e "${path}/hs_common.h"; then
156+
hs_inc_path="${path}"
157+
elif test -e "${path}/include/hs/hs.h"; then
158+
hs_inc_path="${path}/include"
159+
fi
160+
161+
if test -n "${hs_lib_path}"; then
162+
AC_MSG_NOTICE([HyperScan library found at: ${hs_lib_file}])
163+
fi
164+
165+
if test -n "${hs_inc_path}"; then
166+
AC_MSG_NOTICE([HyperScan headers found at: ${hs_inc_path}])
167+
fi
168+
169+
if test -n "${hs_lib_path}" -a -n "${hs_inc_path}"; then
170+
# TODO: Compile a piece of code to check the version.
171+
HS_CFLAGS="-I${hs_inc_path}"
172+
HS_LDADD="-l${hs_lib_name}"
173+
HS_LDFLAGS="-L${hs_lib_path}"
174+
HS_DISPLAY="${hs_lib_file}, ${hs_inc_path}"
175+
fi
176+
]) # AC_DEFUN [CHECK_FOR_HS_AT]

configure.ac

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ AC_DEFUN([LIBINJECTION_VERSION], m4_esyscmd_s(cd "others/libinjection" && git de
7878
# SecLang test version
7979
AC_DEFUN([SECLANG_TEST_VERSION], m4_esyscmd_s(cd "test/test-cases/secrules-language-tests" && git log -1 --format="%h" --abbrev-commit && cd ../../..))
8080

81+
# Check for hyperscan
82+
PROG_HS
83+
AM_CONDITIONAL([HS_VERSION], [test "$HS_VERSION" != ""])
84+
8185

8286
# Check for yajl
8387
PROG_YAJL
@@ -553,6 +557,22 @@ if test "x$LUA_FOUND" = "x2"; then
553557
echo " + LUA ....disabled"
554558
fi
555559

560+
## HyperScan
561+
if test "x$HS_FOUND" = "x0"; then
562+
echo " + HyperScan ....not found"
563+
fi
564+
if test "x$HS_FOUND" = "x1"; then
565+
echo -n " + HyperScan ....found "
566+
if ! test "x$HS_VERSION" = "x"; then
567+
echo "v${HS_VERSION}"
568+
else
569+
echo ""
570+
fi
571+
echo " ${HS_DISPLAY}"
572+
fi
573+
if test "x$HS_FOUND" = "x2"; then
574+
echo " + HyperScan ....disabled"
575+
fi
556576

557577
echo " "
558578
echo " Other Options"

examples/multiprocess_c/Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ multi_LDADD = \
99
$(SSDEEP_LDADD) \
1010
$(LUA_LDADD) \
1111
$(MAXMIND_LDADD) \
12-
$(GLOBAL_LDADD)
12+
$(GLOBAL_LDADD) \
13+
$(HS_LDADD)
1314

1415
multi_LDFLAGS = \
1516
-L$(top_builddir)/src/.libs/ \
@@ -21,6 +22,7 @@ multi_LDFLAGS = \
2122
$(LUA_LDFLAGS) \
2223
$(SSDEEP_LDFLAGS) \
2324
$(MAXMIND_LDFLAGS) \
25+
$(HS_LDFLAGS) \
2426
$(YAJL_LDFLAGS)
2527

2628
multi_CFLAGS = \

examples/reading_logs_via_rule_message/Makefile.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ simple_request_LDADD = \
1515
$(LUA_LDADD) \
1616
$(PCRE_LDADD) \
1717
$(SSDEEP_LDADD) \
18-
$(YAJL_LDADD)
18+
$(YAJL_LDADD) \
19+
$(HS_LDADD)
1920

2021
simple_request_LDFLAGS = \
2122
-L$(top_builddir)/src/.libs/ \
@@ -28,6 +29,7 @@ simple_request_LDFLAGS = \
2829
$(LUA_LDFLAGS) \
2930
$(MAXMIND_LDFLAGS) \
3031
$(SSDEEP_LDFLAGS) \
32+
$(HS_LDFLAGS) \
3133
$(YAJL_LDFLAGS)
3234

3335
simple_request_CPPFLAGS = \
@@ -44,6 +46,7 @@ simple_request_CPPFLAGS = \
4446
$(GLOBAL_CPPFLAGS) \
4547
$(MODSEC_NO_LOGS) \
4648
$(YAJL_CFLAGS) \
49+
$(HS_CFLAGS) \
4750
$(LMDB_CFLAGS) \
4851
$(LUA_CFLAGS) \
4952
$(PCRE_CFLAGS) \

examples/reading_logs_with_offset/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ read_LDADD = \
1515
$(LUA_LDADD) \
1616
$(PCRE_LDADD) \
1717
$(SSDEEP_LDADD) \
18+
$(HS_LDADD) \
1819
$(YAJL_LDADD)
1920

2021
read_LDFLAGS = \
@@ -28,6 +29,7 @@ read_LDFLAGS = \
2829
$(LUA_LDFLAGS) \
2930
$(SSDEEP_LDFLAGS) \
3031
$(MAXMIND_LDFLAGS) \
32+
$(HS_LDFLAGS) \
3133
$(YAJL_LDFLAGS)
3234

3335
read_CPPFLAGS = \
@@ -48,6 +50,7 @@ read_CPPFLAGS = \
4850
$(LMDB_CFLAGS) \
4951
$(LUA_CFLAGS) \
5052
$(PCRE_CFLAGS) \
53+
$(HS_CFLAGS) \
5154
$(LIBXML2_CFLAGS)
5255

5356

examples/simple_example_using_c/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ test_SOURCES = \
88
test_LDADD = \
99
$(GLOBAL_LDADD) \
1010
$(LUA_LDADD) \
11+
$(HS_LDADD) \
1112
$(SSDEEP_LDADD)
1213

1314
test_LDFLAGS = \
@@ -18,6 +19,7 @@ test_LDFLAGS = \
1819
-lstdc++ \
1920
$(LUA_LDFLAGS) \
2021
$(SSDEEP_LDFLAGS) \
22+
$(HS_LDFLAGS) \
2123
$(YAJL_LDFLAGS)
2224

2325
test_CFLAGS = \

examples/using_bodies_in_chunks/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ simple_request_LDADD = \
1515
$(LUA_LDADD) \
1616
$(PCRE_LDADD) \
1717
$(SSDEEP_LDADD) \
18+
$(HS_LDADD) \
1819
$(YAJL_LDADD)
1920

2021
simple_request_LDFLAGS = \
@@ -29,6 +30,7 @@ simple_request_LDFLAGS = \
2930
-lpthread \
3031
$(LUA_LDFLAGS) \
3132
$(SSDEEP_LDFLAGS) \
33+
$(HS_LDFLAGS) \
3234
$(YAJL_LDFLAGS)
3335

3436
simple_request_CPPFLAGS = \
@@ -49,6 +51,7 @@ simple_request_CPPFLAGS = \
4951
$(LMDB_CFLAGS) \
5052
$(LUA_CFLAGS) \
5153
$(PCRE_CFLAGS) \
54+
$(HS_CFLAGS) \
5255
$(LIBXML2_CFLAGS)
5356

5457
MAINTAINERCLEANFILES = \

src/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ libmodsecurity_la_CPPFLAGS = \
326326
$(SSDEEP_CFLAGS) \
327327
$(MAXMIND_CFLAGS) \
328328
$(LUA_CFLAGS) \
329+
$(HS_CFLAGS) \
329330
$(LIBXML2_CFLAGS)
330331

331332

@@ -341,6 +342,7 @@ libmodsecurity_la_LDFLAGS = \
341342
$(SSDEEP_LDFLAGS) \
342343
$(MAXMIND_LDFLAGS) \
343344
$(YAJL_LDFLAGS) \
345+
$(HS_LDFLAGS) \
344346
-version-info @MSC_VERSION_INFO@
345347

346348

@@ -356,5 +358,6 @@ libmodsecurity_la_LIBADD = \
356358
$(PCRE_LDADD) \
357359
$(MAXMIND_LDADD) \
358360
$(SSDEEP_LDADD) \
361+
$(HS_LDADD) \
359362
$(YAJL_LDADD)
360363

0 commit comments

Comments
 (0)