aboutsummaryrefslogtreecommitdiff
path: root/nDPIsrvd.c
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2021-04-08 20:33:25 +0200
committerToni Uhlig <matzeton@googlemail.com>2021-04-09 00:18:35 +0200
commit0a7ad7a76ac34d7a0c7635591203de08979b60da (patch)
tree28b1afb918be5733b85501df4affbded3c4fe100 /nDPIsrvd.c
parente576162a43c78290961b0b6c8cd3e5cc2965316f (diff)
nDPId-test: added JSON distribution + JSON parsing (Multithreaded design re-using most of nDPId/nDPIsrvd core)
* improved Makefile.old install targets * splitted nDPIsrvd_parse into nDPIsrvd_parse_line and nDPIsrvd_parse_all for the sake of readability * minor Python script improvments (check for nDPIsrvd.py on multiple locations, may be superseeded by setuptools in the future) * some paths needs to be absolute (chdir() during daemonize) and therefor additional checks introduced * test run script checks and fails if certain files are are missing (PCAP file <=> result output file) * removed not very useful "internal format error" JSON serialization if a BUG for same exists * fixed invalid l4 type statistics counters for nDPIsrvd-collectd Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'nDPIsrvd.c')
-rw-r--r--nDPIsrvd.c54
1 files changed, 40 insertions, 14 deletions
diff --git a/nDPIsrvd.c b/nDPIsrvd.c
index 105fec2b0..f687a29e6 100644
--- a/nDPIsrvd.c
+++ b/nDPIsrvd.c
@@ -277,11 +277,19 @@ static int nDPIsrvd_parse_options(int argc, char ** argv)
{
nDPIsrvd_options.pidfile = strdup(nDPIsrvd_PIDFILE);
}
+ if (is_path_absolute("Pidfile", nDPIsrvd_options.pidfile) != 0)
+ {
+ return 1;
+ }
if (nDPIsrvd_options.json_sockpath == NULL)
{
nDPIsrvd_options.json_sockpath = strdup(COLLECTOR_UNIX_SOCKET);
}
+ if (is_path_absolute("JSON socket", nDPIsrvd_options.json_sockpath) != 0)
+ {
+ return 1;
+ }
if (nDPIsrvd_options.serv_optarg == NULL)
{
@@ -293,6 +301,10 @@ static int nDPIsrvd_parse_options(int argc, char ** argv)
fprintf(stderr, "%s: Could not parse address `%s'\n", argv[0], nDPIsrvd_options.serv_optarg);
return 1;
}
+ if (serv_address.raw.sa_family == AF_UNIX && is_path_absolute("SERV socket", nDPIsrvd_options.serv_optarg) != 0)
+ {
+ return 1;
+ }
if (optind < argc)
{
@@ -303,6 +315,28 @@ static int nDPIsrvd_parse_options(int argc, char ** argv)
return 0;
}
+static struct remote_desc * accept_remote(int server_fd,
+ enum sock_type socktype,
+ struct sockaddr * const sockaddr,
+ socklen_t * const addrlen)
+{
+ int client_fd = accept(server_fd, sockaddr, addrlen);
+ if (client_fd < 0)
+ {
+ syslog(LOG_DAEMON | LOG_ERR, "Accept failed: %s", strerror(errno));
+ return NULL;
+ }
+
+ struct remote_desc * current = get_unused_remote_descriptor(socktype, client_fd);
+ if (current == NULL)
+ {
+ syslog(LOG_DAEMON | LOG_ERR, "Max number of connections reached: %zu", remotes.desc_used);
+ return NULL;
+ }
+
+ return current;
+}
+
static int new_connection(int epollfd, int eventfd)
{
union {
@@ -330,17 +364,9 @@ static int new_connection(int epollfd, int eventfd)
return 1;
}
- int client_fd = accept(server_fd, (struct sockaddr *)&sockaddr, &peer_addr_len);
- if (client_fd < 0)
- {
- syslog(LOG_DAEMON | LOG_ERR, "Accept failed: %s", strerror(errno));
- return 1;
- }
-
- struct remote_desc * current = get_unused_remote_descriptor(stype, client_fd);
+ struct remote_desc * current = accept_remote(server_fd, stype, (struct sockaddr *)&sockaddr, &peer_addr_len);
if (current == NULL)
{
- syslog(LOG_DAEMON | LOG_ERR, "Max number of connections reached: %zu", remotes.desc_used);
return 1;
}
@@ -628,20 +654,20 @@ static int handle_incoming_data_event(int epollfd, struct epoll_event * const ev
{
struct remote_desc * current = (struct remote_desc *)event->data.ptr;
- if (current == NULL)
+ if ((event->events & EPOLLIN) == 0)
{
- syslog(LOG_DAEMON | LOG_ERR, "%s", "remote descriptor got from event data invalid");
return 1;
}
- if (current->fd < 0)
+ if (current == NULL)
{
- syslog(LOG_DAEMON | LOG_ERR, "file descriptor `%d' got from event data invalid", current->fd);
+ syslog(LOG_DAEMON | LOG_ERR, "%s", "remote descriptor got from event data invalid");
return 1;
}
- if ((event->events & EPOLLIN) == 0)
+ if (current->fd < 0)
{
+ syslog(LOG_DAEMON | LOG_ERR, "file descriptor `%d' got from event data invalid", current->fd);
return 1;
}