Compare commits

...
8 Commits
Author SHA1 Message Date
Luca Deri 299fc4d1ff Improved AESNI check 2022-10-26 14:02:09 +02:00
Luca Deri 13b9a27e83 Leak fix 2022-10-26 12:23:57 +02:00
Alfredo Cardigliano 0aeb97492c Degine libdir for EL9 2022-09-13 11:19:22 +02:00
Alfredo Cardigliano 9b775fc100 Replace obsolete linux macro 2022-09-13 10:42:30 +02:00
Luca Deri d2e7673a1e Improved AES-NI check 2022-08-30 16:38:36 +02:00
Luca Deri 3dc1129cb2 Fixes AES-NI presence check 2022-08-29 17:46:35 +02:00
Luca dd8953cb64 Added pointer checks
Added -O2 (lost in release)
2022-07-14 18:13:42 +02:00
Luca Deri 2c5258b19d Version 4.4 2022-07-06 12:44:31 +02:00
6 changed files with 73 additions and 33 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
AC_INIT([libndpi],[4.3.0]) AC_INIT([libndpi],[4.4.0])
AC_CONFIG_AUX_DIR([.]) AC_CONFIG_AUX_DIR([.])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
@@ -31,7 +31,7 @@ AS_IF([test "${with_sanitizer+set}" = set -a "${with_thread_sanitizer+set}" = se
AS_IF([test "${with_sanitizer+set}" = set -o "${with_thread_sanitizer+set}" = set],[ AS_IF([test "${with_sanitizer+set}" = set -o "${with_thread_sanitizer+set}" = set],[
CFLAGS="${CFLAGS} -O0 -g3" CFLAGS="${CFLAGS} -O0 -g3"
],[ ],[
CFLAGS="${CFLAGS} -g" CFLAGS="${CFLAGS} -O2"
]) ])
AS_IF([test "${with_sanitizer+set}" = set],[ AS_IF([test "${with_sanitizer+set}" = set],[
+7 -7
View File
@@ -20,7 +20,7 @@
#include "ndpi_config.h" #include "ndpi_config.h"
#ifdef linux #ifdef __linux__
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
@@ -105,7 +105,7 @@ static u_int16_t num_loops = 1;
static u_int8_t shutdown_app = 0, quiet_mode = 0; static u_int8_t shutdown_app = 0, quiet_mode = 0;
static u_int8_t num_threads = 1; static u_int8_t num_threads = 1;
static struct timeval startup_time, begin, end; static struct timeval startup_time, begin, end;
#ifdef linux #ifdef __linux__
static int core_affinity[MAX_NUM_READER_THREADS]; static int core_affinity[MAX_NUM_READER_THREADS];
#endif #endif
static struct timeval pcap_start = { 0, 0}, pcap_end = { 0, 0 }; static struct timeval pcap_start = { 0, 0}, pcap_end = { 0, 0 };
@@ -456,7 +456,7 @@ static void help(u_int long_help) {
" -k <file> | Specify a file to write serialized detection results\n" " -k <file> | Specify a file to write serialized detection results\n"
" -K <format> | Specify the serialization format for `-k'\n" " -K <format> | Specify the serialization format for `-k'\n"
" | Valid formats are tlv, csv or json (default)\n" " | Valid formats are tlv, csv or json (default)\n"
#ifdef linux #ifdef __linux__
" -g <id:id...> | Thread affinity mask (one core id per thread)\n" " -g <id:id...> | Thread affinity mask (one core id per thread)\n"
#endif #endif
" -a <mode> | Generates option values for GUIs\n" " -a <mode> | Generates option values for GUIs\n"
@@ -781,7 +781,7 @@ static void parseOptions(int argc, char **argv) {
#ifndef USE_DPDK #ifndef USE_DPDK
char *__pcap_file = NULL; char *__pcap_file = NULL;
int thread_id, do_capture = 0; int thread_id, do_capture = 0;
#ifdef linux #ifdef __linux__
char *bind_mask = NULL; char *bind_mask = NULL;
u_int num_cores = sysconf(_SC_NPROCESSORS_ONLN); u_int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
#endif #endif
@@ -853,7 +853,7 @@ static void parseOptions(int argc, char **argv) {
break; break;
#ifndef USE_DPDK #ifndef USE_DPDK
#ifdef linux #ifdef __linux__
case 'g': case 'g':
bind_mask = optarg; bind_mask = optarg;
break; break;
@@ -1091,7 +1091,7 @@ static void parseOptions(int argc, char **argv) {
} }
} }
#ifdef linux #ifdef __linux__
#ifndef USE_DPDK #ifndef USE_DPDK
for(thread_id = 0; thread_id < num_threads; thread_id++) for(thread_id = 0; thread_id < num_threads; thread_id++)
core_affinity[thread_id] = -1; core_affinity[thread_id] = -1;
@@ -4017,7 +4017,7 @@ void * processing_thread(void *_thread_id) {
char pcap_error_buffer[PCAP_ERRBUF_SIZE]; char pcap_error_buffer[PCAP_ERRBUF_SIZE];
#endif #endif
#if defined(linux) && defined(HAVE_PTHREAD_SETAFFINITY_NP) #if defined(__linux__) && defined(HAVE_PTHREAD_SETAFFINITY_NP)
if(core_affinity[thread_id] >= 0) { if(core_affinity[thread_id] >= 0) {
cpu_set_t cpuset; cpu_set_t cpuset;
+1
View File
@@ -51,6 +51,7 @@ PATH=/usr/bin:/bin:/usr/sbin:/sbin
%{?el6:%define libdir /usr/lib} %{?el6:%define libdir /usr/lib}
%{?el7:%define libdir /usr/lib} %{?el7:%define libdir /usr/lib}
%{?el8:%define libdir /usr/lib64} %{?el8:%define libdir /usr/lib64}
%{?el9:%define libdir /usr/lib64}
%define bindir /usr/bin %define bindir /usr/bin
%install %install
+6
View File
@@ -2182,6 +2182,7 @@ static u_int64_t ndpi_host_ip_risk_ptree_match(struct ndpi_detection_module_stru
/* Check isuerDN exception */ /* Check isuerDN exception */
u_int8_t ndpi_check_issuerdn_risk_exception(struct ndpi_detection_module_struct *ndpi_str, u_int8_t ndpi_check_issuerdn_risk_exception(struct ndpi_detection_module_struct *ndpi_str,
char *issuerDN) { char *issuerDN) {
if(issuerDN != NULL) {
ndpi_list *head = ndpi_str->trusted_issuer_dn; ndpi_list *head = ndpi_str->trusted_issuer_dn;
while(head != NULL) { while(head != NULL) {
@@ -2190,6 +2191,7 @@ u_int8_t ndpi_check_issuerdn_risk_exception(struct ndpi_detection_module_struct
else else
head = head->next; head = head->next;
} }
}
return(0 /* no exception */); return(0 /* no exception */);
} }
@@ -2200,6 +2202,9 @@ u_int8_t ndpi_check_issuerdn_risk_exception(struct ndpi_detection_module_struct
static u_int8_t ndpi_check_hostname_risk_exception(struct ndpi_detection_module_struct *ndpi_str, static u_int8_t ndpi_check_hostname_risk_exception(struct ndpi_detection_module_struct *ndpi_str,
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow,
char *hostname) { char *hostname) {
if(hostname == NULL)
return(0);
else {
ndpi_automa *automa = &ndpi_str->host_risk_mask_automa; ndpi_automa *automa = &ndpi_str->host_risk_mask_automa;
u_int8_t ret = 0; u_int8_t ret = 0;
@@ -2217,6 +2222,7 @@ static u_int8_t ndpi_check_hostname_risk_exception(struct ndpi_detection_module_
} }
return(ret); return(ret);
}
} }
/* ********************************************************************************* */ /* ********************************************************************************* */
+37 -4
View File
@@ -42,6 +42,10 @@
#include <intrin.h> #include <intrin.h>
#endif #endif
#if defined(linux) || defined(__linux__)
static u_int8_t cached_has_aesni = 0, has_aesni_checked = 0;
#endif
/* /*
* AES-NI support detection routine * AES-NI support detection routine
*/ */
@@ -56,12 +60,41 @@ int mbedtls_aesni_has_support( unsigned int what )
#if defined(linux) || defined(__linux__) #if defined(linux) || defined(__linux__)
unsigned int eax, ebx, ecx, edx; unsigned int eax, ebx, ecx, edx;
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) == 0) if(has_aesni_checked == 0) {
{ /*
return 0; NOTE
This code is necessary as __get_cpuid() is not reliable
Example with Intel(R) Celeron(R) CPU N2930 (that has NO AES-NI)
the code based on __get_cpuid() reports that AES-NI is present
and thus nDPI crashes on such platform.
*/
FILE *fd = fopen("/proc/cpuinfo", "r");
if(fd != NULL) {
char *line = NULL;
size_t len = 0;
u_int8_t num_lines = 0;
while(getline(&line, &len, fd) != -1) {
if(strstr(line, "aes")) {
/* printf("FOUND %s", line); */
cached_has_aesni = 1;
break;
} }
return ( (ecx & what) != 0 ); if(++num_lines > 99)
break; /* We giveup */
}
free(line);
fclose(fd);
has_aesni_checked = 1;
}
}
return(cached_has_aesni);
#elif defined(WIN32) || defined(WIN64) #elif defined(WIN32) || defined(WIN64)
int cpuInfo[4]; int cpuInfo[4];
+1 -1
View File
@@ -18,7 +18,7 @@
* *
*/ */
#ifdef linux #ifdef __linux__
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif