diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2020-11-19 19:34:11 +0100 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2020-12-01 10:22:47 +0100 |
commit | f8692c6be11c664e4345ceaaec5c6b35ba9b3feb (patch) | |
tree | 5f19272d7bef0f3f0413e973f988ba44c91e87d5 /nDPIsrvd.c | |
parent | a9b87e573964603e3932b4995b6045ed2f91bdc5 (diff) |
Let travis use pcap files from nDPI to produce some JSON output. (disabled, needs further testing..)
* Added pcap diff script
* Added \n to JSON string end (useful for debugging and readability)
* Use first host/server name character for hash calculation as well
* Removed error'ing EPOLLHUP handling in nDPIsrvd (connection closing will be detected via read())
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'nDPIsrvd.c')
-rw-r--r-- | nDPIsrvd.c | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/nDPIsrvd.c b/nDPIsrvd.c index ca8f2560d..5bbfd9763 100644 --- a/nDPIsrvd.c +++ b/nDPIsrvd.c @@ -548,44 +548,32 @@ int main(int argc, char ** argv) continue; } - if (events[i].events & EPOLLHUP) - { - syslog(LOG_DAEMON, - "%s connection closed", - (current->type == JSON_SOCK ? "collector" : "distributor")); - disconnect_client(epollfd, current); - continue; - } - if (events[i].events & EPOLLIN && current->type == JSON_SOCK) { /* read JSON strings (or parts) from the UNIX socket (collecting) */ if (current->buf.used == current->buf.max) { syslog(LOG_DAEMON, "Collector read buffer full. No more read possible."); - disconnect_client(epollfd, current); - continue; } - - errno = 0; - ssize_t bytes_read = - read(current->fd, current->buf.ptr + current->buf.used, current->buf.max - current->buf.used); - if (errno == EAGAIN) - { - continue; - } - if (bytes_read < 0 || errno != 0) + else { - disconnect_client(epollfd, current); - continue; - } - if (bytes_read == 0) - { - syslog(LOG_DAEMON, "collector connection closed during read"); - disconnect_client(epollfd, current); - continue; + errno = 0; + ssize_t bytes_read = read(current->fd, + current->buf.ptr + current->buf.used, + current->buf.max - current->buf.used); + if (bytes_read < 0 || errno != 0) + { + disconnect_client(epollfd, current); + continue; + } + if (bytes_read == 0) + { + syslog(LOG_DAEMON, "Collector connection closed during read"); + disconnect_client(epollfd, current); + continue; + } + current->buf.used += bytes_read; } - current->buf.used += bytes_read; while (current->buf.used >= nDPIsrvd_JSON_BYTES + 1) { @@ -632,7 +620,8 @@ int main(int argc, char ** argv) break; } - if (current->buf.ptr[current->event_json.json_bytes - 1] != '}') + if (current->buf.ptr[current->event_json.json_bytes - 2] != '}' || + current->buf.ptr[current->event_json.json_bytes - 1] != '\n') { syslog(LOG_DAEMON | LOG_ERR, "BUG: Invalid JSON string: %.*s", |