mirror of
https://github.com/optim-enterprises-bv/nDPId.git
synced 2025-10-29 01:12:22 +00:00
Fixed more SonarCloud complaints.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
13
Dockerfile
13
Dockerfile
@@ -1,12 +1,11 @@
|
|||||||
FROM ubuntu:22.04 AS builder
|
FROM ubuntu:22.04 AS builder
|
||||||
|
|
||||||
WORKDIR /root
|
WORKDIR /root
|
||||||
|
RUN apt-get -y update && apt-get install -y --no-install-recommends autoconf automake build-essential ca-certificates wget unzip git make cmake pkg-config libpcap-dev autoconf libtool && apt-get clean
|
||||||
RUN env DEBIAN_FRONTEND=noninteractive apt-get -y update && apt-get install -y --no-install-recommends autoconf automake build-essential ca-certificates wget unzip git make cmake pkg-config libpcap-dev autoconf libtool
|
|
||||||
RUN env DEBIAN_FRONTEND=noninteractive apt-get clean
|
|
||||||
RUN env DEBIAN_FRONTEND=noninteractive apt-get autoclean
|
|
||||||
RUN git clone https://github.com/utoni/nDPId.git
|
RUN git clone https://github.com/utoni/nDPId.git
|
||||||
RUN cd nDPId && mkdir -p build && cd build && cmake .. -DBUILD_NDPI=ON && make
|
|
||||||
|
WORKDIR /root/nDPId
|
||||||
|
RUN cmake -S . -B build -DBUILD_NDPI=ON && cmake --build build --verbose
|
||||||
|
|
||||||
FROM ubuntu:22.04
|
FROM ubuntu:22.04
|
||||||
USER root
|
USER root
|
||||||
@@ -15,9 +14,7 @@ WORKDIR /
|
|||||||
COPY --from=builder /root/nDPId/build/nDPId /usr/sbin/nDPId
|
COPY --from=builder /root/nDPId/build/nDPId /usr/sbin/nDPId
|
||||||
COPY --from=builder /root/nDPId/build/nDPIsrvd /usr/bin/nDPIsrvd
|
COPY --from=builder /root/nDPId/build/nDPIsrvd /usr/bin/nDPIsrvd
|
||||||
|
|
||||||
RUN env DEBIAN_FRONTEND=noninteractive apt-get -y update && apt-get install -y --no-install-recommends libpcap-dev
|
RUN apt-get -y update && apt-get install -y --no-install-recommends libpcap-dev && apt-get clean
|
||||||
RUN env DEBIAN_FRONTEND=noninteractive apt-get clean
|
|
||||||
RUN env DEBIAN_FRONTEND=noninteractive apt-get autoclean
|
|
||||||
|
|
||||||
USER nobody
|
USER nobody
|
||||||
RUN /usr/bin/nDPIsrvd -h || { RC=$?; test ${RC} -eq 1; }
|
RUN /usr/bin/nDPIsrvd -h || { RC=$?; test ${RC} -eq 1; }
|
||||||
|
|||||||
2
dependencies/nDPIsrvd.py
vendored
2
dependencies/nDPIsrvd.py
vendored
@@ -369,7 +369,7 @@ class nDPIsrvdSocket:
|
|||||||
sys.stderr.write('Error while evaluating expression "{}"\n'.format(jf.filter_string))
|
sys.stderr.write('Error while evaluating expression "{}"\n'.format(jf.filter_string))
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
if type(json_filter_retval) != bool:
|
if not isinstance(json_filter_retval, bool):
|
||||||
print()
|
print()
|
||||||
sys.stderr.write('Error while evaluating expression "{}"\n'.format(jf.filter_string))
|
sys.stderr.write('Error while evaluating expression "{}"\n'.format(jf.filter_string))
|
||||||
raise nDPIsrvdException('JSON Filter returned an invalid type: expected bool, got {}'.format(type(json_filter_retval)))
|
raise nDPIsrvdException('JSON Filter returned an invalid type: expected bool, got {}'.format(type(json_filter_retval)))
|
||||||
|
|||||||
@@ -666,7 +666,8 @@ static void syslog_event(struct nDPIsrvd_socket * const sock,
|
|||||||
}
|
}
|
||||||
if (src_port != NULL && dst_port != NULL)
|
if (src_port != NULL && dst_port != NULL)
|
||||||
{
|
{
|
||||||
size_t src_port_len = 0, dst_port_len = 0;
|
size_t src_port_len = 0;
|
||||||
|
size_t dst_port_len = 0;
|
||||||
char const * const tmp_src_port_str = TOKEN_GET_VALUE(sock, src_port, &src_port_len);
|
char const * const tmp_src_port_str = TOKEN_GET_VALUE(sock, src_port, &src_port_len);
|
||||||
char const * const tmp_dst_port_str = TOKEN_GET_VALUE(sock, dst_port, &dst_port_len);
|
char const * const tmp_dst_port_str = TOKEN_GET_VALUE(sock, dst_port, &dst_port_len);
|
||||||
if (tmp_src_port_str != NULL && tmp_dst_port_str != NULL)
|
if (tmp_src_port_str != NULL && tmp_dst_port_str != NULL)
|
||||||
@@ -938,8 +939,8 @@ static enum nDPIsrvd_callback_return captured_json_callback(struct nDPIsrvd_sock
|
|||||||
syslog_event(sock, flow, "midstream");
|
syslog_event(sock, flow, "midstream");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flow_user->packets == NULL || flow_user->flow_max_packets == 0 ||
|
if (flow_user->packets == NULL || flow_user->flow_max_packets == 0 ||
|
||||||
utarray_len(flow_user->packets) == 0))
|
utarray_len(flow_user->packets) == 0)
|
||||||
{
|
{
|
||||||
if (logging_mode != 0)
|
if (logging_mode != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ enum dbus_level
|
|||||||
|
|
||||||
static char const * const flow_severities[] = {"Low", "Medium", "High", "Severe", "Critical", "Emergency"};
|
static char const * const flow_severities[] = {"Low", "Medium", "High", "Severe", "Critical", "Emergency"};
|
||||||
static char const * const flow_breeds[] = {
|
static char const * const flow_breeds[] = {
|
||||||
"Safe", "Acceptable", "Fun", "Unsafe", "Potentially Dangerous", "Tracker/Ads", "Dangerous", "Unrated", "???"};
|
"Safe", "Acceptable", "Fun", "Unsafe", "Potentially Dangerous", "Tracker\\/Ads", "Dangerous", "Unrated", "???"};
|
||||||
static char const * const flow_categories[] = {"Unspecified",
|
static char const * const flow_categories[] = {"Unspecified",
|
||||||
"Media",
|
"Media",
|
||||||
"VPN",
|
"VPN",
|
||||||
|
|||||||
@@ -273,8 +273,7 @@ def plot_worker(shared_shutdown_event, shared_plot_queue):
|
|||||||
ys2 = []
|
ys2 = []
|
||||||
ys3 = []
|
ys3 = []
|
||||||
ys4 = []
|
ys4 = []
|
||||||
x = 0
|
ani.FuncAnimation(fig, plot_animate, fargs=(shared_plot_queue, (ax1, ax2, ax3, ax4), xs, (ys1, ys2, ys3, ys4)), interval=1000, cache_frame_data=False)
|
||||||
a = ani.FuncAnimation(fig, plot_animate, fargs=(shared_plot_queue, (ax1, ax2, ax3, ax4), xs, (ys1, ys2, ys3, ys4)), interval=1000, cache_frame_data=False)
|
|
||||||
plt.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.05)
|
plt.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.05)
|
||||||
plt.margins(x=0, y=0)
|
plt.margins(x=0, y=0)
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|||||||
@@ -627,9 +627,9 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s
|
|||||||
goto callback_error;
|
goto callback_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
nDPIsrvd_ull pkt_id = 0ull;
|
nDPIsrvd_ull pkt_id = 0ULL;
|
||||||
TOKEN_VALUE_TO_ULL(sock, packet_id, &pkt_id);
|
TOKEN_VALUE_TO_ULL(sock, packet_id, &pkt_id);
|
||||||
if (pkt_id == 0ull)
|
if (pkt_id == 0ULL)
|
||||||
{
|
{
|
||||||
logger(1, "%s", "Missing packet id");
|
logger(1, "%s", "Missing packet id");
|
||||||
goto callback_error;
|
goto callback_error;
|
||||||
|
|||||||
26
nDPId.c
26
nDPId.c
@@ -1560,8 +1560,12 @@ static int setup_reader_threads(void)
|
|||||||
"Could not get netmask for pcap device %s: %s",
|
"Could not get netmask for pcap device %s: %s",
|
||||||
get_cmdarg(&nDPId_options.pcap_file_or_interface),
|
get_cmdarg(&nDPId_options.pcap_file_or_interface),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
} else {
|
}
|
||||||
logger_early(1, "Unexpected error while retrieving netmask for pcap device %s", get_cmdarg(&nDPId_options.pcap_file_or_interface));
|
else
|
||||||
|
{
|
||||||
|
logger_early(1,
|
||||||
|
"Unexpected error while retrieving netmask for pcap device %s",
|
||||||
|
get_cmdarg(&nDPId_options.pcap_file_or_interface));
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -2661,15 +2665,13 @@ static void jsonize_packet_event(struct nDPId_reader_thread * const reader_threa
|
|||||||
reader_thread->workflow->packets_captured,
|
reader_thread->workflow->packets_captured,
|
||||||
reader_thread->array_index);
|
reader_thread->array_index);
|
||||||
}
|
}
|
||||||
else if (base64_data_len > 0)
|
else if (base64_data_len > 0 &&
|
||||||
|
ndpi_serialize_string_binary(&workflow->ndpi_serializer, "pkt", base64_data, (uint16_t)base64_data_len) != 0)
|
||||||
{
|
{
|
||||||
if (ndpi_serialize_string_binary(&workflow->ndpi_serializer, "pkt", base64_data, base64_data_len) != 0)
|
logger(1,
|
||||||
{
|
"[%8llu, %zu] JSON serializing base64 packet buffer failed",
|
||||||
logger(1,
|
reader_thread->workflow->packets_captured,
|
||||||
"[%8llu, %zu] JSON serializing base64 packet buffer failed",
|
reader_thread->array_index);
|
||||||
reader_thread->workflow->packets_captured,
|
|
||||||
reader_thread->array_index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
serialize_and_send(reader_thread);
|
serialize_and_send(reader_thread);
|
||||||
}
|
}
|
||||||
@@ -4391,8 +4393,8 @@ static void run_pcap_loop(struct nDPId_reader_thread * const reader_thread)
|
|||||||
struct nio io;
|
struct nio io;
|
||||||
nio_init(&io);
|
nio_init(&io);
|
||||||
#ifdef ENABLE_EPOLL
|
#ifdef ENABLE_EPOLL
|
||||||
if ((nDPId_options.use_poll == 0 && nio_use_epoll(&io, 32) != NIO_SUCCESS)
|
if ((nDPId_options.use_poll == 0 && nio_use_epoll(&io, 32) != NIO_SUCCESS) ||
|
||||||
|| (nDPId_options.use_poll != 0 && nio_use_poll(&io, nDPIsrvd_MAX_REMOTE_DESCRIPTORS) != NIO_SUCCESS))
|
(nDPId_options.use_poll != 0 && nio_use_poll(&io, nDPIsrvd_MAX_REMOTE_DESCRIPTORS) != NIO_SUCCESS))
|
||||||
#else
|
#else
|
||||||
if (nio_use_poll(&io, nDPIsrvd_MAX_REMOTE_DESCRIPTORS) != NIO_SUCCESS)
|
if (nio_use_poll(&io, nDPIsrvd_MAX_REMOTE_DESCRIPTORS) != NIO_SUCCESS)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -384,6 +384,7 @@ static int drain_write_buffers(struct remote_desc * const remote)
|
|||||||
while ((written = write(remote->fd, buf->buf.ptr.raw + buf->written, buf->buf.used - buf->written)) < 0 &&
|
while ((written = write(remote->fd, buf->buf.ptr.raw + buf->written, buf->buf.used - buf->written)) < 0 &&
|
||||||
errno == EINTR)
|
errno == EINTR)
|
||||||
{
|
{
|
||||||
|
// Retry if interrupted by a signal.
|
||||||
}
|
}
|
||||||
switch (written)
|
switch (written)
|
||||||
{
|
{
|
||||||
@@ -447,7 +448,7 @@ static int handle_outgoing_data(struct nio * const io, struct remote_desc * cons
|
|||||||
}
|
}
|
||||||
if (utarray_len(additional_write_buffers) == 0)
|
if (utarray_len(additional_write_buffers) == 0)
|
||||||
{
|
{
|
||||||
struct nDPIsrvd_write_buffer * const write_buffer = get_write_buffer(remote);
|
struct nDPIsrvd_write_buffer const * const write_buffer = get_write_buffer(remote);
|
||||||
|
|
||||||
if (write_buffer->buf.used == 0)
|
if (write_buffer->buf.used == 0)
|
||||||
{
|
{
|
||||||
@@ -1261,6 +1262,7 @@ static int handle_incoming_data(struct nio * const io, struct remote_desc * cons
|
|||||||
json_read_buffer->buf.max - json_read_buffer->buf.used)) < 0 &&
|
json_read_buffer->buf.max - json_read_buffer->buf.used)) < 0 &&
|
||||||
errno == EINTR)
|
errno == EINTR)
|
||||||
{
|
{
|
||||||
|
// Retry if interrupted by a signal.
|
||||||
}
|
}
|
||||||
if (bytes_read < 0 || errno != 0)
|
if (bytes_read < 0 || errno != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
2
nio.c
2
nio.c
@@ -329,7 +329,7 @@ int nio_check(struct nio * io, int index, int event_flags)
|
|||||||
return NIO_ERROR_INTERNAL;
|
return NIO_ERROR_INTERNAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nio_is_valid(struct nio * io, int index)
|
int nio_is_valid(struct nio const * const io, int index)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= io->nready)
|
if (index < 0 || index >= io->nready)
|
||||||
return NIO_ERROR_INTERNAL;
|
return NIO_ERROR_INTERNAL;
|
||||||
|
|||||||
2
nio.h
2
nio.h
@@ -53,7 +53,7 @@ static inline int nio_get_nready(struct nio const * const io)
|
|||||||
|
|
||||||
int nio_check(struct nio * io, int index, int events);
|
int nio_check(struct nio * io, int index, int events);
|
||||||
|
|
||||||
int nio_is_valid(struct nio * io, int index);
|
int nio_is_valid(struct nio const * const io, int index);
|
||||||
|
|
||||||
int nio_get_fd(struct nio * io, int index);
|
int nio_get_fd(struct nio * io, int index);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user