mirror of
https://github.com/optim-enterprises-bv/nDPId.git
synced 2025-11-01 18:57:48 +00:00
introduced NETWORK_BUFFER_MAX_SIZE to replace BUFSIZ as this might change depending on the arch/libc used
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
2
config.h
2
config.h
@@ -6,6 +6,8 @@
|
|||||||
#define DISTRIBUTOR_HOST "127.0.0.1"
|
#define DISTRIBUTOR_HOST "127.0.0.1"
|
||||||
#define DISTRIBUTOR_PORT 7000
|
#define DISTRIBUTOR_PORT 7000
|
||||||
|
|
||||||
|
#define NETWORK_BUFFER_MAX_SIZE 8192
|
||||||
|
|
||||||
/* nDPId default config options */
|
/* nDPId default config options */
|
||||||
#define nDPId_MAX_FLOW_ROOTS_PER_THREAD 2048
|
#define nDPId_MAX_FLOW_ROOTS_PER_THREAD 2048
|
||||||
#define nDPId_MAX_IDLE_FLOWS_PER_THREAD 64
|
#define nDPId_MAX_IDLE_FLOWS_PER_THREAD 64
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ int main(void)
|
|||||||
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
struct sockaddr_in remote_addr = {};
|
struct sockaddr_in remote_addr = {};
|
||||||
socklen_t remote_addrlen = sizeof(remote_addr);
|
socklen_t remote_addrlen = sizeof(remote_addr);
|
||||||
uint8_t buf[BUFSIZ];
|
uint8_t buf[NETWORK_BUFFER_MAX_SIZE];
|
||||||
//size_t buf_used = 0;
|
//size_t buf_used = 0;
|
||||||
//unsigned long long int buf_wanted = 0;
|
//unsigned long long int buf_wanted = 0;
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ int main(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("RECV[%zd]: '%.*s'\n", bytes_read, (int) bytes_read, buf);
|
printf("RECV[%zd]: '%.*s'\n\n", bytes_read, (int) bytes_read, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
10
nDPId.c
10
nDPId.c
@@ -267,7 +267,7 @@ static struct nDPId_workflow * init_workflow(char const * const file_or_device)
|
|||||||
ndpi_set_protocol_detection_bitmask2(workflow->ndpi_struct, &protos);
|
ndpi_set_protocol_detection_bitmask2(workflow->ndpi_struct, &protos);
|
||||||
ndpi_finalize_initalization(workflow->ndpi_struct);
|
ndpi_finalize_initalization(workflow->ndpi_struct);
|
||||||
|
|
||||||
if (ndpi_init_serializer_ll(&workflow->ndpi_serializer, ndpi_serialization_format_json, BUFSIZ) != 1)
|
if (ndpi_init_serializer_ll(&workflow->ndpi_serializer, ndpi_serialization_format_json, NETWORK_BUFFER_MAX_SIZE) != 1)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -671,10 +671,10 @@ static void send_to_json_sink(struct nDPId_reader_thread * const reader_thread,
|
|||||||
struct nDPId_workflow * const workflow = reader_thread->workflow;
|
struct nDPId_workflow * const workflow = reader_thread->workflow;
|
||||||
int saved_errno;
|
int saved_errno;
|
||||||
int s_ret;
|
int s_ret;
|
||||||
char newline_json_str[BUFSIZ];
|
char newline_json_str[NETWORK_BUFFER_MAX_SIZE];
|
||||||
|
|
||||||
s_ret =
|
s_ret =
|
||||||
snprintf(newline_json_str, sizeof(newline_json_str), "%zu%.*s\n", json_str_len, (int)json_str_len, json_str);
|
snprintf(newline_json_str, sizeof(newline_json_str), "%zu%.*s", json_str_len, (int)json_str_len, json_str);
|
||||||
if (s_ret < 0 || s_ret > (int)sizeof(newline_json_str))
|
if (s_ret < 0 || s_ret > (int)sizeof(newline_json_str))
|
||||||
{
|
{
|
||||||
syslog(LOG_DAEMON | LOG_ERR,
|
syslog(LOG_DAEMON | LOG_ERR,
|
||||||
@@ -843,7 +843,7 @@ static void jsonize_packet_event(struct nDPId_reader_thread * const reader_threa
|
|||||||
jsonize_basic(reader_thread);
|
jsonize_basic(reader_thread);
|
||||||
|
|
||||||
size_t base64_data_len = base64_out_len(header->caplen);
|
size_t base64_data_len = base64_out_len(header->caplen);
|
||||||
char base64_data[BUFSIZ];
|
char base64_data[NETWORK_BUFFER_MAX_SIZE];
|
||||||
if (ndpi_serialize_string_boolean(&workflow->ndpi_serializer,
|
if (ndpi_serialize_string_boolean(&workflow->ndpi_serializer,
|
||||||
"pkt_oversize",
|
"pkt_oversize",
|
||||||
base64_data_len > sizeof(base64_data)) != 0 ||
|
base64_data_len > sizeof(base64_data)) != 0 ||
|
||||||
@@ -894,7 +894,7 @@ static void vjsonize_basic_eventf(struct nDPId_reader_thread * const reader_thre
|
|||||||
{
|
{
|
||||||
uint8_t got_jsonkey = 0;
|
uint8_t got_jsonkey = 0;
|
||||||
uint8_t is_long_long = 0;
|
uint8_t is_long_long = 0;
|
||||||
char json_key[BUFSIZ];
|
char json_key[NETWORK_BUFFER_MAX_SIZE];
|
||||||
uint32_t format_index = 0;
|
uint32_t format_index = 0;
|
||||||
|
|
||||||
while (*format)
|
while (*format)
|
||||||
|
|||||||
25
nDPIsrvd.c
25
nDPIsrvd.c
@@ -25,7 +25,7 @@ struct remote_desc
|
|||||||
{
|
{
|
||||||
enum ev_type type;
|
enum ev_type type;
|
||||||
int fd;
|
int fd;
|
||||||
uint8_t buf[BUFSIZ];
|
uint8_t buf[NETWORK_BUFFER_MAX_SIZE];
|
||||||
size_t buf_used;
|
size_t buf_used;
|
||||||
unsigned long long int buf_wanted;
|
unsigned long long int buf_wanted;
|
||||||
union {
|
union {
|
||||||
@@ -367,18 +367,19 @@ int main(void)
|
|||||||
}
|
}
|
||||||
if ((uint8_t *)json_str_start == current->buf)
|
if ((uint8_t *)json_str_start == current->buf)
|
||||||
{
|
{
|
||||||
current->buf_used = 0;
|
|
||||||
current->buf_wanted = 0;
|
|
||||||
syslog(LOG_DAEMON | LOG_ERR,
|
syslog(LOG_DAEMON | LOG_ERR,
|
||||||
"Missing size before JSON string: %.*s",
|
"Missing size before JSON string: %.*s",
|
||||||
(int) current->buf_wanted, current->buf);
|
(int) current->buf_used, current->buf);
|
||||||
continue;
|
current->buf_used = 0;
|
||||||
}
|
current->buf_wanted = 0;
|
||||||
if (current->buf_wanted > BUFSIZ)
|
continue;
|
||||||
{
|
}
|
||||||
|
if (current->buf_wanted > sizeof(current->buf))
|
||||||
|
{
|
||||||
|
syslog(LOG_DAEMON | LOG_ERR, "BUG: JSON string too big: %llu > %zu",
|
||||||
|
current->buf_wanted, sizeof(current->buf));
|
||||||
current->buf_used = 0;
|
current->buf_used = 0;
|
||||||
current->buf_wanted = 0;
|
current->buf_wanted = 0;
|
||||||
syslog(LOG_DAEMON | LOG_ERR, "BUG: JSON string too big: %llu > %d", current->buf_wanted, BUFSIZ);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -390,10 +391,10 @@ int main(void)
|
|||||||
/* after buffering complete, last character should always be a '}' (end of object) */
|
/* after buffering complete, last character should always be a '}' (end of object) */
|
||||||
if (current->buf[current->buf_wanted - 1] != '}')
|
if (current->buf[current->buf_wanted - 1] != '}')
|
||||||
{
|
{
|
||||||
current->buf_used = 0;
|
|
||||||
current->buf_wanted = 0;
|
|
||||||
syslog(LOG_DAEMON | LOG_ERR, "Invalid JSON string: %.*s",
|
syslog(LOG_DAEMON | LOG_ERR, "Invalid JSON string: %.*s",
|
||||||
(int) current->buf_wanted, current->buf);
|
(int) current->buf_wanted, current->buf);
|
||||||
|
current->buf_used = 0;
|
||||||
|
current->buf_wanted = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,7 +431,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
memmove(current->buf, current->buf + current->buf_wanted, current->buf_used - current->buf_wanted);
|
memmove(current->buf, current->buf + current->buf_wanted, current->buf_used - current->buf_wanted);
|
||||||
current->buf_used = 0;
|
current->buf_used -= current->buf_wanted;
|
||||||
current->buf_wanted = 0;
|
current->buf_wanted = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user