nDPId-test: Set max buffer size for remote descriptors useful to test caching/buffering.

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
Toni Uhlig
2021-11-04 14:08:25 +01:00
parent 1f6d1fbd67
commit 9075706714
3 changed files with 19 additions and 8 deletions

View File

@@ -100,13 +100,13 @@ static void * nDPIsrvd_mainloop_thread(void * const arg)
THREAD_ERROR_GOTO(arg);
}
mock_json_desc = get_unused_remote_descriptor(JSON_SOCK, mock_pipefds[PIPE_nDPIsrvd]);
mock_json_desc = get_unused_remote_descriptor(JSON_SOCK, mock_pipefds[PIPE_nDPIsrvd], NETWORK_BUFFER_MAX_SIZE);
if (mock_json_desc == NULL)
{
THREAD_ERROR_GOTO(arg);
}
mock_serv_desc = get_unused_remote_descriptor(SERV_SOCK, mock_servfds[PIPE_WRITE]);
mock_serv_desc = get_unused_remote_descriptor(SERV_SOCK, mock_servfds[PIPE_WRITE], NETWORK_BUFFER_MAX_SIZE / 4);
if (mock_serv_desc == NULL)
{
THREAD_ERROR_GOTO(arg);
@@ -150,6 +150,8 @@ static void * nDPIsrvd_mainloop_thread(void * const arg)
}
error:
drain_cache_blocking(mock_serv_desc);
del_event(epollfd, mock_pipefds[PIPE_nDPIsrvd]);
del_event(epollfd, mock_servfds[PIPE_WRITE]);
close(mock_pipefds[PIPE_nDPIsrvd]);

View File

@@ -2,6 +2,7 @@
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/tcp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -381,7 +382,7 @@ static int create_listen_sockets(void)
return 0;
}
static struct remote_desc * get_unused_remote_descriptor(enum sock_type type, int remote_fd)
static struct remote_desc * get_unused_remote_descriptor(enum sock_type type, int remote_fd, size_t max_buffer_size)
{
if (remotes.desc_used == remotes.desc_size)
{
@@ -394,7 +395,7 @@ static struct remote_desc * get_unused_remote_descriptor(enum sock_type type, in
{
remotes.desc_used++;
utarray_new(remotes.desc[i].buf_cache, &nDPIsrvd_buffer_array_icd);
if (nDPIsrvd_buffer_init(&remotes.desc[i].buf, NETWORK_BUFFER_MAX_SIZE) != 0 ||
if (nDPIsrvd_buffer_init(&remotes.desc[i].buf, max_buffer_size) != 0 ||
remotes.desc[i].buf_cache == NULL)
{
return NULL;
@@ -569,7 +570,7 @@ static struct remote_desc * accept_remote(int server_fd,
return NULL;
}
struct remote_desc * current = get_unused_remote_descriptor(socktype, client_fd);
struct remote_desc * current = get_unused_remote_descriptor(socktype, client_fd, NETWORK_BUFFER_MAX_SIZE);
if (current == NULL)
{
syslog(LOG_DAEMON | LOG_ERR, "Max number of connections reached: %zu", remotes.desc_used);
@@ -625,10 +626,18 @@ static int new_connection(int epollfd, int eventfd)
if (setsockopt(current->fd, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt)) < 0)
{
syslog(LOG_DAEMON | LOG_ERR, "Error setting socket option SO_RCVBUF: %s", strerror(errno));
return 1;
}
break;
case SERV_SOCK:
sock_type = "distributor";
if (setsockopt(current->fd, SOL_SOCKET, SO_SNDBUF, &sockopt, sizeof(sockopt)) < 0)
{
syslog(LOG_DAEMON | LOG_ERR, "Error setting socket option SO_SNDBUF: %s", strerror(errno));
return 1;
}
if (inet_ntop(current->event_serv.peer.sin_family,
&current->event_serv.peer.sin_addr,
&current->event_serv.peer_addr[0],
@@ -813,14 +822,13 @@ static int handle_incoming_data(int epollfd, struct remote_desc * const current)
syslog(LOG_DAEMON, "Buffer capacity threshold (%zu bytes) reached, caching JSON strings.", remotes.desc[i].buf.used);
#endif
errno = 0;
if (add_out_event(epollfd, remotes.desc[i].fd, &remotes.desc[i]) != 0)
if (add_out_event(epollfd, remotes.desc[i].fd, &remotes.desc[i]) != 0 && errno != EEXIST /* required for nDPId-test */)
{
syslog(LOG_DAEMON | LOG_ERR, "%s: %s", "Could not add event, disconnecting", strerror(errno));
disconnect_client(epollfd, &remotes.desc[i]);
continue;
}
}
if (add_to_cache(&remotes.desc[i], current->buf.ptr.raw, current->event_json.json_bytes) != 0)
{
disconnect_client(epollfd, &remotes.desc[i]);

View File

@@ -19,7 +19,8 @@ fi
git submodule update --init ./libnDPI
NDPID_GIT_VERSION="$(git describe --tags)"
cd ./libnDPI && \
LIBNDPI_GIT_VERSION="$(git describe --tags)"
LIBNDPI_GIT_VERSION="$(git describe --tags)" && \
printf '%s\n' "Creating $(realpath ./libnDPI-${LIBNDPI_GIT_VERSION}.tar)" && \
git archive --prefix="nDPId-${NDPID_GIT_VERSION}/libnDPI/" -o "../libnDPI-${LIBNDPI_GIT_VERSION}.tar" HEAD && \
cd ..
git archive --prefix="nDPId-${NDPID_GIT_VERSION}/" -o "./nDPId-${NDPID_GIT_VERSION}.tar" HEAD