aboutsummaryrefslogtreecommitdiff
path: root/examples/c-simple/c-simple.c
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2022-09-19 19:31:21 +0200
committerToni Uhlig <matzeton@googlemail.com>2022-09-19 19:39:49 +0200
commit08f263e40981483e96fab9d7c864722abe45df0d (patch)
tree939dfce1c2f18a37cb355de5413f8b9852a220e7 /examples/c-simple/c-simple.c
parent015a739efda638737adeed521ca5ba43708949f0 (diff)
nDPId: Reduced flow-updates for TCP flows to 1/4 of the timeout value.
* nDPId: Fixed broken validation tests. * nDPId: Removed TICK_RESOLUTION, not required anymore. * c-collectd: Improved total layer4 payload calculation/update handling. * c-collectd: Updated RRD Graph script according to total layer4 payload changes. * py-flow-info.py: Fixed several bugs and syntax errors. * Python scripts: Added dirname(argv[0]) as search path for nDPIsrvd.py. * nDPIsrvd&nDPId-test: Fixed missing EPOLLERR check. Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'examples/c-simple/c-simple.c')
-rw-r--r--examples/c-simple/c-simple.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/examples/c-simple/c-simple.c b/examples/c-simple/c-simple.c
index aeb0726c3..9d1ca54b4 100644
--- a/examples/c-simple/c-simple.c
+++ b/examples/c-simple/c-simple.c
@@ -83,8 +83,6 @@ static void nDPIsrvd_verify_flows_cb(struct nDPIsrvd_thread_data const * const t
{
fprintf(stderr, "Thread [UNKNOWN], Flow %llu verification failed\n", flow->id_as_ull);
}
-
- exit(1);
}
static void sighandler(int signum)
@@ -108,6 +106,9 @@ static void sighandler(int signum)
if (verification_failed == 0)
{
fprintf(stderr, "%s\n", "Flow verification succeeded.");
+ } else {
+ /* FATAL! */
+ exit(EXIT_FAILURE);
}
}
else if (main_thread_shutdown == 0)
@@ -129,10 +130,19 @@ static enum nDPIsrvd_callback_return simple_json_callback(struct nDPIsrvd_socket
return CALLBACK_OK;
}
+ struct nDPIsrvd_json_token const * const alias = TOKEN_GET_SZ(sock, "alias");
+ struct nDPIsrvd_json_token const * const source = TOKEN_GET_SZ(sock, "source");
+ if (alias == NULL || source == NULL)
+ {
+ return CALLBACK_ERROR;
+ }
+
struct nDPIsrvd_json_token const * const flow_event_name = TOKEN_GET_SZ(sock, "flow_event_name");
if (TOKEN_VALUE_EQUALS_SZ(flow_event_name, "new") != 0)
{
- printf("Instance 0x%x, Thread %d, Flow %llu new\n",
+ printf("Instance %.*s/%.*s (HT-Key: 0x%x), Thread %d, Flow %llu new\n",
+ alias->value_length, alias->value,
+ source->value_length, source->value,
instance->alias_source_key,
flow->thread_id,
flow->id_as_ull);
@@ -150,8 +160,19 @@ static void simple_flow_cleanup_callback(struct nDPIsrvd_socket * const sock,
(void)sock;
(void)thread_data;
+ struct nDPIsrvd_json_token const * const alias = TOKEN_GET_SZ(sock, "alias");
+ struct nDPIsrvd_json_token const * const source = TOKEN_GET_SZ(sock, "source");
+ if (alias == NULL || source == NULL)
+ {
+ /* FATAL! */
+ fprintf(stderr, "BUG: Missing JSON token alias/source.\n");
+ exit(EXIT_FAILURE);
+ }
+
char const * const reason_str = nDPIsrvd_enum_to_string(reason);
- printf("Instance 0x%x, Thread %d, Flow %llu cleanup, reason: %s\n",
+ printf("Instance %.*s/%.*s (HT-Key: 0x%x), Thread %d, Flow %llu cleanup, reason: %s\n",
+ alias->value_length, alias->value,
+ source->value_length, source->value,
instance->alias_source_key,
flow->thread_id,
flow->id_as_ull,
@@ -159,7 +180,9 @@ static void simple_flow_cleanup_callback(struct nDPIsrvd_socket * const sock,
if (reason == CLEANUP_REASON_FLOW_TIMEOUT)
{
+ /* FATAL! */
fprintf(stderr, "Flow %llu timeouted.\n", flow->id_as_ull);
+ exit(EXIT_FAILURE);
}
}