diff options
-rw-r--r-- | .travis.yml | 3 | ||||
-rw-r--r-- | CMakeLists.txt | 7 | ||||
-rwxr-xr-x | daemon.sh | 44 | ||||
-rw-r--r-- | nDPId.c | 14 |
4 files changed, 65 insertions, 3 deletions
diff --git a/.travis.yml b/.travis.yml index df3300587..fd43b0a91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,3 +13,6 @@ script: cmake .. -DBUILD_EXAMPLES=ON -DENABLE_SANITIZER=ON -DENABLE_MEMORY_PROFILING=ON && make && cd .. - ./build/nDPId-test || test $? -eq 1 - ./build/nDPId -h || test $? -eq 1 +# dameon start/stop test +- ./daemon.sh ./build/nDPId ./build/nDPIsrvd +- ./daemon.sh ./build/nDPId ./build/nDPIsrvd diff --git a/CMakeLists.txt b/CMakeLists.txt index c4fff16df..243fbfae8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,13 @@ add_executable(nDPId nDPId.c utils.c) add_executable(nDPIsrvd nDPIsrvd.c utils.c) add_executable(nDPId-test nDPId-test.c utils.c) +add_custom_target(daemon) +add_custom_command( + TARGET daemon + COMMAND "${CMAKE_SOURCE_DIR}/daemon.sh" "$<TARGET_FILE:nDPId>" "$<TARGET_FILE:nDPIsrvd>" + DEPENDS nDPId nDPIsrvd +) + if(BUILD_NDPI) enable_testing() add_test(NAME run_tests diff --git a/daemon.sh b/daemon.sh new file mode 100755 index 000000000..dc9b5abe1 --- /dev/null +++ b/daemon.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env sh +# +# Simple nDPId/nDPIsrvd start/stop script for testing purposes. +# + +NUSER="nobody" +NSUFFIX="${NSUFFIX:-daemon-test}" + +if [ x"${1}" = x -o x"${2}" = x ]; then + printf '%s\n' "usage: ${0} [nDPId-path] [nDPIsrvd-path]" >&2 + printf '\n\t%s=%s\n' 'env NUSER' "${NUSER}" >&2 + printf '\t%s=%s\n' 'env NSUFFIX' "${NSUFFIX}" >&2 + exit 1 +fi + +if [ -r "/tmp/nDPId-${NSUFFIX}.pid" -o -r "/tmp/nDPIsrvd-${NSUFFIX}.pid" ]; then + nDPId_PID="$(cat "/tmp/nDPId-${NSUFFIX}.pid" 2>/dev/null)" + nDPIsrvd_PID="$(cat "/tmp/nDPIsrvd-${NSUFFIX}.pid" 2>/dev/null)" + + if [ x"${nDPId_PID}" != x ]; then + sudo kill "${nDPId_PID}" + wait "${nDPId_PID}" + else + printf '%s\n' "${1} not started .." >&2 + fi + + if [ x"${nDPIsrvd_PID}" != x ]; then + kill "${nDPIsrvd_PID}" + wait "${nDPIsrvd_PID}" + else + printf '%s\n' "${2} not started .." >&2 + fi + + sudo rm -f "/tmp/nDPId-${NSUFFIX}.pid" + rm -f "/tmp/nDPIsrvd-${NSUFFIX}.pid" + printf '%s\n' "daemons stopped" >&2 +else + ${2} -p "/tmp/nDPIsrvd-${NSUFFIX}.pid" -c "/tmp/nDPIsrvd-${NSUFFIX}-collector.sock" -s "/tmp/nDPIsrvd-${NSUFFIX}-distributor.sock" -d + sudo chgrp "$(id -n -g "${NUSER}")" "/tmp/nDPIsrvd-${NSUFFIX}-collector.sock" + sudo chmod g+w "/tmp/nDPIsrvd-${NSUFFIX}-collector.sock" + sudo ${1} -p "/tmp/nDPId-${NSUFFIX}.pid" -c "/tmp/nDPIsrvd-${NSUFFIX}-collector.sock" -d -u "${NUSER}" + printf '%s\n' "daemons started" >&2 + printf '%s\n' "You may now run examples e.g.: ./examples/py-flow-info/flow-info.py --unix /tmp/nDPIsrvd-${NSUFFIX}-distributor.sock" +fi @@ -1009,6 +1009,14 @@ static uint64_t get_l4_protocol_idle_time(uint8_t l4_protocol) } } +static int is_l4_protocol_timed_out(struct nDPId_workflow const * const workflow, + struct nDPId_flow_basic const * const flow_basic) +{ + return flow_basic->last_seen + get_l4_protocol_idle_time(flow_basic->l4_protocol) < workflow->last_time || + (flow_basic->tcp_fin_rst_seen == 1 && + flow_basic->last_seen + nDPId_options.tcp_max_post_end_flow_time < workflow->last_time); +} + static void ndpi_idle_scan_walker(void const * const A, ndpi_VISIT which, int depth, void * const user_data) { struct nDPId_workflow * const workflow = (struct nDPId_workflow *)user_data; @@ -1028,9 +1036,7 @@ static void ndpi_idle_scan_walker(void const * const A, ndpi_VISIT which, int de if (which == ndpi_preorder || which == ndpi_leaf) { - if (flow_basic->last_seen + get_l4_protocol_idle_time(flow_basic->l4_protocol) < workflow->last_time || - (flow_basic->tcp_fin_rst_seen == 1 && - flow_basic->last_seen + nDPId_options.tcp_max_post_end_flow_time < workflow->last_time)) + if (is_l4_protocol_timed_out(workflow, flow_basic) != 0) { workflow->ndpi_flows_idle[workflow->cur_idle_flows++] = flow_basic; switch (flow_basic->type) @@ -2004,6 +2010,7 @@ static int process_datalink_layer(struct nDPId_reader_thread * const reader_thre break; } case DLT_PPP_SERIAL: + { if (header->len < sizeof(struct ndpi_chdlc)) { jsonize_packet_event(reader_thread, header, packet, 0, 0, 0, 0, NULL, PACKET_EVENT_PAYLOAD); @@ -2015,6 +2022,7 @@ static int process_datalink_layer(struct nDPId_reader_thread * const reader_thre *ip_offset = sizeof(struct ndpi_chdlc); *layer3_type = ntohs(chdlc->proto_code); break; + } case DLT_C_HDLC: case DLT_PPP: if (header->len < sizeof(struct ndpi_chdlc)) |