mirror of
https://github.com/outbackdingo/nDPId.git
synced 2026-01-27 18:19:39 +00:00
CMake: do not add /usr/include/ndpi to include dirs if BUILD_NDPI or STATIC_LIBNDPI_INSTALLDIR used.
* c-collectd: fixed memory leak on failure * py-flow-info.py: fancy spinners and stats counting improved Signed-off-by: lns <matzeton@googlemail.com>
This commit is contained in:
@@ -233,21 +233,24 @@ if(STATIC_LIBNDPI_INSTALLDIR OR BUILD_NDPI)
|
||||
"static library \"${STATIC_LIBNDPI_LIB}\" does not exist!")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
unset(DEFAULT_NDPI_INCLUDE CACHE)
|
||||
else()
|
||||
if(NOT NDPI_NO_PKGCONFIG)
|
||||
pkg_check_modules(NDPI REQUIRED libndpi>=3.5.0)
|
||||
pkg_check_modules(NDPI REQUIRED libndpi>=4.3.0)
|
||||
|
||||
unset(STATIC_LIBNDPI_INC CACHE)
|
||||
unset(STATIC_LIBNDPI_LIB CACHE)
|
||||
endif()
|
||||
|
||||
set(DEFAULT_NDPI_INCLUDE ${NDPI_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
find_package(PCAP "1.8.1" REQUIRED)
|
||||
|
||||
target_compile_options(nDPId PRIVATE "-pthread")
|
||||
target_compile_definitions(nDPId PRIVATE -D_GNU_SOURCE=1 -DGIT_VERSION=\"${GIT_VERSION}\" ${NDPID_DEFS} ${ZLIB_DEFS})
|
||||
target_include_directories(nDPId PRIVATE
|
||||
"${STATIC_LIBNDPI_INC}" "${NDPI_INCLUDEDIR}" "${NDPI_INCLUDEDIR}/ndpi")
|
||||
target_include_directories(nDPId PRIVATE "${STATIC_LIBNDPI_INC}" "${DEFAULT_NDPI_INCLUDE}")
|
||||
target_link_libraries(nDPId "${STATIC_LIBNDPI_LIB}" "${pkgcfg_lib_NDPI_ndpi}"
|
||||
"${pkgcfg_lib_PCRE_pcre}" "${pkgcfg_lib_MAXMINDDB_maxminddb}" "${pkgcfg_lib_ZLIB_z}"
|
||||
"${GCRYPT_LIBRARY}" "${GCRYPT_ERROR_LIBRARY}" "${PCAP_LIBRARY}" "${LIBM_LIB}"
|
||||
@@ -269,8 +272,7 @@ target_compile_options(nDPId-test PRIVATE "-Wno-unused-function" "-pthread")
|
||||
target_compile_definitions(nDPId-test PRIVATE -D_GNU_SOURCE=1 -DNO_MAIN=1 -DGIT_VERSION=\"${GIT_VERSION}\"
|
||||
${NDPID_DEFS} ${ZLIB_DEFS} ${NDPID_TEST_MPROF_DEFS})
|
||||
target_include_directories(nDPId-test PRIVATE
|
||||
"${STATIC_LIBNDPI_INC}" "${NDPI_INCLUDEDIR}" "${NDPI_INCLUDEDIR}/ndpi"
|
||||
"${CMAKE_SOURCE_DIR}/dependencies/uthash/src")
|
||||
"${STATIC_LIBNDPI_INC}" "${DEFAULT_NDPI_INCLUDE}" "${CMAKE_SOURCE_DIR}/dependencies/uthash/src")
|
||||
target_link_libraries(nDPId-test "${STATIC_LIBNDPI_LIB}" "${pkgcfg_lib_NDPI_ndpi}"
|
||||
"${pkgcfg_lib_PCRE_pcre}" "${pkgcfg_lib_MAXMINDDB_maxminddb}" "${pkgcfg_lib_ZLIB_z}"
|
||||
"${GCRYPT_LIBRARY}" "${GCRYPT_ERROR_LIBRARY}" "${PCAP_LIBRARY}" "${LIBM_LIB}"
|
||||
@@ -291,8 +293,7 @@ if(BUILD_EXAMPLES)
|
||||
endif()
|
||||
target_compile_definitions(nDPIsrvd-captured PRIVATE ${NDPID_DEFS})
|
||||
target_include_directories(nDPIsrvd-captured PRIVATE
|
||||
"${STATIC_LIBNDPI_INC}" "${NDPI_INCLUDEDIR}" "${NDPI_INCLUDEDIR}/ndpi"
|
||||
"${CMAKE_SOURCE_DIR}"
|
||||
"${STATIC_LIBNDPI_INC}" "${DEFAULT_NDPI_INCLUDE}" "${CMAKE_SOURCE_DIR}"
|
||||
"${CMAKE_SOURCE_DIR}/dependencies"
|
||||
"${CMAKE_SOURCE_DIR}/dependencies/jsmn"
|
||||
"${CMAKE_SOURCE_DIR}/dependencies/uthash/src")
|
||||
@@ -376,4 +377,7 @@ message(STATUS "- NDPI_WITH_GCRYPT......: ${NDPI_WITH_GCRYPT}")
|
||||
message(STATUS "- NDPI_WITH_PCRE........: ${NDPI_WITH_PCRE}")
|
||||
message(STATUS "- NDPI_WITH_MAXMINDDB...: ${NDPI_WITH_MAXMINDDB}")
|
||||
endif()
|
||||
if(NOT STATIC_LIBNDPI_INSTALLDIR AND NOT BUILD_NDPI)
|
||||
message(STATUS "- DEFAULT_NDPI_INCLUDE..: ${DEFAULT_NDPI_INCLUDE}")
|
||||
endif()
|
||||
message(STATUS "--------------------------")
|
||||
|
||||
@@ -686,7 +686,7 @@ int main(int argc, char ** argv)
|
||||
|
||||
if (parse_options(argc, argv, sock) != 0)
|
||||
{
|
||||
return 1;
|
||||
goto failure;
|
||||
}
|
||||
|
||||
if (getenv("COLLECTD_HOSTNAME") == NULL && getenv("COLLECTD_INTERVAL") == NULL)
|
||||
@@ -705,15 +705,13 @@ int main(int argc, char ** argv)
|
||||
if (connect_ret != CONNECT_OK)
|
||||
{
|
||||
LOG(LOG_DAEMON | LOG_ERR, "nDPIsrvd socket connect to %s failed!", serv_optarg);
|
||||
nDPIsrvd_socket_free(&sock);
|
||||
return 1;
|
||||
goto failure;
|
||||
}
|
||||
|
||||
if (nDPIsrvd_set_nonblock(sock) != 0)
|
||||
{
|
||||
LOG(LOG_DAEMON | LOG_ERR, "nDPIsrvd set nonblock failed: %s", strerror(errno));
|
||||
nDPIsrvd_socket_free(&sock);
|
||||
return 1;
|
||||
goto failure;
|
||||
}
|
||||
|
||||
signal(SIGINT, sighandler);
|
||||
@@ -726,13 +724,13 @@ int main(int argc, char ** argv)
|
||||
if (epollfd < 0)
|
||||
{
|
||||
LOG(LOG_DAEMON | LOG_ERR, "Error creating epoll: %s", strerror(errno));
|
||||
return 1;
|
||||
goto failure;
|
||||
}
|
||||
|
||||
if (create_collectd_timer() != 0)
|
||||
{
|
||||
LOG(LOG_DAEMON | LOG_ERR, "Error creating timer: %s", strerror(errno));
|
||||
return 1;
|
||||
goto failure;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -740,7 +738,7 @@ int main(int argc, char ** argv)
|
||||
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, collectd_timerfd, &timer_event) < 0)
|
||||
{
|
||||
LOG(LOG_DAEMON | LOG_ERR, "Error adding JSON fd to epoll: %s", strerror(errno));
|
||||
return 1;
|
||||
goto failure;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -749,13 +747,14 @@ int main(int argc, char ** argv)
|
||||
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, sock->fd, &socket_event) < 0)
|
||||
{
|
||||
LOG(LOG_DAEMON | LOG_ERR, "Error adding nDPIsrvd socket fd to epoll: %s", strerror(errno));
|
||||
return 1;
|
||||
goto failure;
|
||||
}
|
||||
}
|
||||
|
||||
LOG(LOG_DAEMON | LOG_NOTICE, "%s", "Initialization succeeded.");
|
||||
retval = mainloop(epollfd, sock);
|
||||
|
||||
failure:
|
||||
nDPIsrvd_socket_free(&sock);
|
||||
close(collectd_timerfd);
|
||||
close(epollfd);
|
||||
|
||||
@@ -51,7 +51,12 @@ class Stats:
|
||||
self.spinner_state += 1
|
||||
|
||||
def getSpinner(self):
|
||||
spinner_states = ['-', '\\', '|', '/']
|
||||
#spinner_states = ['-', '\\', '|', '/']
|
||||
#spinner_states = ['▉', '▊', '▋', '▌', '▍', '▎', '▏', '▎', '▍', '▌', '▋', '▊', '▉']
|
||||
spinner_states = ['←', '↖', '↑', '↗', '→', '↘', '↓', '↙']
|
||||
#spinner_states = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█', '▇', '▆', '▅', '▄', '▃', '▁']
|
||||
#spinner_states = ['▖', '▘', '▝', '▗']
|
||||
#spinner_states = ['┤', '┘', '┴', '└', '├', '┌', '┬', '┐']
|
||||
return spinner_states[self.spinner_state % len(spinner_states)]
|
||||
|
||||
def getDataFromJson(self, json_dict, current_flow):
|
||||
@@ -66,16 +71,16 @@ class Stats:
|
||||
set_attr_from_dict(current_flow, {}, 'flow_risk', {})
|
||||
set_attr_from_dict(current_flow, json_dict, 'midstream', 0)
|
||||
set_attr_from_dict(current_flow, json_dict, 'flow_event_name', '')
|
||||
set_attr_if_not_set(current_flow, 'guessed', False)
|
||||
set_attr_if_not_set(current_flow, 'not_detected', False)
|
||||
set_attr_if_not_set(current_flow, 'guessed', 0)
|
||||
set_attr_if_not_set(current_flow, 'not_detected', 0)
|
||||
|
||||
if current_flow.flow_event_name == 'detected' or \
|
||||
current_flow.flow_event_name == 'detection-update':
|
||||
current_flow.guessed = False
|
||||
current_flow.guessed = 0
|
||||
elif current_flow.flow_event_name == 'guessed':
|
||||
current_flow.guessed = True
|
||||
current_flow.guessed = 1
|
||||
elif current_flow.flow_event_name == 'not-detected':
|
||||
current_flow.not_detected = True
|
||||
current_flow.not_detected = 1
|
||||
|
||||
def update(self, json_dict, current_flow):
|
||||
self.updateSpinner()
|
||||
@@ -90,8 +95,8 @@ class Stats:
|
||||
self.expired_avg_l4_payload_len += current_flow.flow_avg_l4_payload_len
|
||||
self.risky_flows += 1 if len(current_flow.flow_risk) > 0 else 0
|
||||
self.midstream_flows += 1 if current_flow.midstream != 0 else 0
|
||||
self.guessed_flows += 1 if current_flow.guessed is True else 0
|
||||
self.not_detected_flows += 1 if current_flow.not_detected is True else 0
|
||||
self.guessed_flows += 1 if current_flow.guessed != 0 else 0
|
||||
self.not_detected_flows += 1 if current_flow.not_detected != 0 else 0
|
||||
|
||||
def getStatsFromFlowMgr(self):
|
||||
alias_count = 0
|
||||
@@ -117,8 +122,8 @@ class Stats:
|
||||
flow_avg_l4_payload_len += current_flow.flow_avg_l4_payload_len
|
||||
risky += 1 if len(current_flow.flow_risk) > 0 else 0
|
||||
midstream += 1 if current_flow.midstream != 0 else 0
|
||||
guessed += 1 if current_flow.guessed is True else 0
|
||||
not_detected = 1 if current_flow.not_detected is True else 0
|
||||
guessed += 1 if current_flow.guessed != 0 else 0
|
||||
not_detected = 1 if current_flow.not_detected != 0 else 0
|
||||
|
||||
return alias_count, source_count, flow_count, \
|
||||
flow_tot_l4_payload_len, flow_avg_l4_payload_len, \
|
||||
|
||||
Reference in New Issue
Block a user