aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2021-01-27 17:53:18 +0100
committerToni Uhlig <matzeton@googlemail.com>2021-01-27 18:05:13 +0100
commit257cce1dccb19190ebcb4c48bac421a21daa4a56 (patch)
tree97de2a779654101691458573d7ed32b5a9cea1ab
parent9564b0ce2c239b02235414d908829fff9c684a8c (diff)
Fixed braindead failure - Increase of NETWORK_BUFFER_MAX_SIZE > 9999 means to also increase NETWORK_BUFFER_LENGTH_DIGITS to 5.
* Fixed ARM32 xcompile warnings; Other GCC versions, other uint64_t's.. * Replaced ridiculous nDPIsrvd_JSON_BYTES with NETWORK_BUFFER_LENGTH_DIGITS. Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--README.md2
-rw-r--r--config.h3
-rw-r--r--dependencies/nDPIsrvd.h4
-rw-r--r--dependencies/nDPIsrvd.py2
-rw-r--r--examples/c-json-stdout/c-json-stdout.c8
-rw-r--r--examples/go-dashboard/main.go26
-rw-r--r--nDPId.c25
-rw-r--r--nDPIsrvd.c8
8 files changed, 40 insertions, 38 deletions
diff --git a/README.md b/README.md
index 2d3876ede..8b511179b 100644
--- a/README.md
+++ b/README.md
@@ -42,7 +42,7 @@ It doesn't use a producer/consumer design pattern, so the wording is not precise
All JSON strings sent need to be in the following format:
```text
-[4-digit-number][JSON string]
+[5-digit-number][JSON string]
```
## Example:
diff --git a/config.h b/config.h
index 75fcf0e16..b744746c0 100644
--- a/config.h
+++ b/config.h
@@ -12,6 +12,8 @@
* e.g. dependencies/nDPIsrvd.py
*/
#define NETWORK_BUFFER_MAX_SIZE 12288 /* 8192 + 4096 */
+#define NETWORK_BUFFER_LENGTH_DIGITS 5
+#define NETWORK_BUFFER_LENGTH_DIGITS_STR "5"
/* nDPId default config options */
#define nDPId_PIDFILE "/tmp/ndpid.pid"
@@ -28,6 +30,5 @@
/* nDPIsrvd default config options */
#define nDPIsrvd_PIDFILE "/tmp/ndpisrvd.pid"
-#define nDPIsrvd_JSON_BYTES 4
#endif
diff --git a/dependencies/nDPIsrvd.h b/dependencies/nDPIsrvd.h
index 21067a676..001e06500 100644
--- a/dependencies/nDPIsrvd.h
+++ b/dependencies/nDPIsrvd.h
@@ -447,9 +447,9 @@ static inline enum nDPIsrvd_parse_return nDPIsrvd_parse(struct nDPIsrvd_socket *
json_callback cb,
void * user_data)
{
- while (sock->buffer.used >= nDPIsrvd_JSON_BYTES + 1)
+ while (sock->buffer.used >= NETWORK_BUFFER_LENGTH_DIGITS + 1)
{
- if (sock->buffer.raw[nDPIsrvd_JSON_BYTES] != '{')
+ if (sock->buffer.raw[NETWORK_BUFFER_LENGTH_DIGITS] != '{')
{
return PARSE_INVALID_OPENING_CHAR;
}
diff --git a/dependencies/nDPIsrvd.py b/dependencies/nDPIsrvd.py
index 573792bba..4510658a4 100644
--- a/dependencies/nDPIsrvd.py
+++ b/dependencies/nDPIsrvd.py
@@ -19,7 +19,7 @@ DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 7000
DEFAULT_UNIX = '/tmp/ndpid-distributor.sock'
-NETWORK_BUFFER_MIN_SIZE = 5
+NETWORK_BUFFER_MIN_SIZE = 6 # NETWORK_BUFFER_LENGTH_DIGITS + 1
NETWORK_BUFFER_MAX_SIZE = 12288 # Please keep this value in sync with the one in config.h
PKT_TYPE_ETH_IP4 = 0x0800
diff --git a/examples/c-json-stdout/c-json-stdout.c b/examples/c-json-stdout/c-json-stdout.c
index e17f16a1c..7265feec1 100644
--- a/examples/c-json-stdout/c-json-stdout.c
+++ b/examples/c-json-stdout/c-json-stdout.c
@@ -57,11 +57,11 @@ int main(void)
}
buf_used += bytes_read;
- while (buf_used >= nDPIsrvd_JSON_BYTES + 1)
+ while (buf_used >= NETWORK_BUFFER_LENGTH_DIGITS + 1)
{
- if (buf[nDPIsrvd_JSON_BYTES] != '{')
+ if (buf[NETWORK_BUFFER_LENGTH_DIGITS] != '{')
{
- fprintf(stderr, "BUG: JSON invalid opening character: '%c'\n", buf[nDPIsrvd_JSON_BYTES]);
+ fprintf(stderr, "BUG: JSON invalid opening character: '%c'\n", buf[NETWORK_BUFFER_LENGTH_DIGITS]);
exit(1);
}
@@ -77,7 +77,7 @@ int main(void)
}
if ((uint8_t *)json_str_start == buf)
{
- fprintf(stderr, "BUG: Missing size before JSON string: \"%.*s\"\n", nDPIsrvd_JSON_BYTES, buf);
+ fprintf(stderr, "BUG: Missing size before JSON string: \"%.*s\"\n", NETWORK_BUFFER_LENGTH_DIGITS, buf);
exit(1);
}
if (json_bytes > sizeof(buf))
diff --git a/examples/go-dashboard/main.go b/examples/go-dashboard/main.go
index f1acfebb3..ef468f3d9 100644
--- a/examples/go-dashboard/main.go
+++ b/examples/go-dashboard/main.go
@@ -20,7 +20,7 @@ var (
ErrorLogger *log.Logger
NETWORK_BUFFER_MAX_SIZE uint16 = 12288
- nDPIsrvd_JSON_BYTES uint16 = 4
+ NETWORK_BUFFER_LENGTH_DIGITS uint16 = 5
)
type packet_event struct {
@@ -158,20 +158,20 @@ func main() {
jsonStrLen += uint16(nread)
for {
- if jsonStrLen < nDPIsrvd_JSON_BYTES+1 {
+ if jsonStrLen < NETWORK_BUFFER_LENGTH_DIGITS+1 {
break
}
- if jsonStr[nDPIsrvd_JSON_BYTES] != '{' {
+ if jsonStr[NETWORK_BUFFER_LENGTH_DIGITS] != '{' {
ErrorLogger.Printf("BUG: JSON invalid opening character at position %d: '%s' (%x)\n",
- nDPIsrvd_JSON_BYTES,
- string(jsonStr[:nDPIsrvd_JSON_BYTES]), jsonStr[nDPIsrvd_JSON_BYTES])
+ NETWORK_BUFFER_LENGTH_DIGITS,
+ string(jsonStr[:NETWORK_BUFFER_LENGTH_DIGITS]), jsonStr[NETWORK_BUFFER_LENGTH_DIGITS])
os.Exit(1)
}
if jsonLen == 0 {
var tmp uint64
- if tmp, err = strconv.ParseUint(strings.TrimLeft(jsonStr[:4], "0"), 10, 16); err != nil {
+ if tmp, err = strconv.ParseUint(strings.TrimLeft(jsonStr[:NETWORK_BUFFER_LENGTH_DIGITS], "0"), 10, 16); err != nil {
ErrorLogger.Printf("BUG: Could not parse length of a JSON string: %v\n", err)
os.Exit(1)
} else {
@@ -179,21 +179,21 @@ func main() {
}
}
- if jsonStrLen < jsonLen+nDPIsrvd_JSON_BYTES {
+ if jsonStrLen < jsonLen+NETWORK_BUFFER_LENGTH_DIGITS {
break
}
- if jsonStr[jsonLen+nDPIsrvd_JSON_BYTES-2] != '}' || jsonStr[jsonLen+nDPIsrvd_JSON_BYTES-1] != '\n' {
+ if jsonStr[jsonLen+NETWORK_BUFFER_LENGTH_DIGITS-2] != '}' || jsonStr[jsonLen+NETWORK_BUFFER_LENGTH_DIGITS-1] != '\n' {
ErrorLogger.Printf("BUG: JSON invalid closing character at position %d: '%s'\n",
- jsonLen+nDPIsrvd_JSON_BYTES,
- string(jsonStr[jsonLen+nDPIsrvd_JSON_BYTES-1]))
+ jsonLen+NETWORK_BUFFER_LENGTH_DIGITS,
+ string(jsonStr[jsonLen+NETWORK_BUFFER_LENGTH_DIGITS-1]))
os.Exit(1)
}
- writer <- jsonStr[nDPIsrvd_JSON_BYTES : nDPIsrvd_JSON_BYTES+jsonLen]
+ writer <- jsonStr[NETWORK_BUFFER_LENGTH_DIGITS : NETWORK_BUFFER_LENGTH_DIGITS+jsonLen]
- jsonStr = jsonStr[jsonLen+nDPIsrvd_JSON_BYTES:]
- jsonStrLen -= (jsonLen + nDPIsrvd_JSON_BYTES)
+ jsonStr = jsonStr[jsonLen+NETWORK_BUFFER_LENGTH_DIGITS:]
+ jsonStrLen -= (jsonLen + NETWORK_BUFFER_LENGTH_DIGITS)
jsonLen = 0
}
}
diff --git a/nDPId.c b/nDPId.c
index 41a7f1442..f83168243 100644
--- a/nDPId.c
+++ b/nDPId.c
@@ -26,7 +26,7 @@
#error "nDPI >= 3.3.0 requiired"
#endif
-#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+#if !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
#error "Compare and Fetch aka __sync_fetch_and_add not available on your platform!"
#endif
@@ -912,12 +912,12 @@ static void check_for_idle_flows(struct nDPId_reader_thread * const reader_threa
"MemoryProfiler: %llu allocs, %llu frees, %llu bytes allocated, %llu bytes freed, %llu blocks in "
"use, "
"%llu bytes in use",
- alloc_count,
- free_count,
- alloc_bytes,
- free_bytes,
- alloc_count - free_count,
- alloc_bytes - free_bytes);
+ (long long unsigned int)alloc_count,
+ (long long unsigned int)free_count,
+ (long long unsigned int)alloc_bytes,
+ (long long unsigned int)free_bytes,
+ (long long unsigned int)(alloc_count - free_count),
+ (long long unsigned int)(alloc_bytes - free_bytes));
}
#endif
@@ -1108,11 +1108,12 @@ static void send_to_json_sink(struct nDPId_reader_thread * const reader_thread,
int s_ret;
char newline_json_str[NETWORK_BUFFER_MAX_SIZE];
-#if nDPIsrvd_JSON_BYTES != 4
-#error "Please do not forget to change the format string if you've changed the value of nDPIsrvd_JSON_BYTES."
-#endif
- s_ret = snprintf(
- newline_json_str, sizeof(newline_json_str), "%04zu%.*s\n", json_str_len + 1, (int)json_str_len, json_str);
+ s_ret = snprintf(newline_json_str,
+ sizeof(newline_json_str),
+ "%0" NETWORK_BUFFER_LENGTH_DIGITS_STR "zu%.*s\n",
+ json_str_len + 1,
+ (int)json_str_len,
+ json_str);
if (s_ret < 0 || s_ret > (int)sizeof(newline_json_str))
{
syslog(LOG_DAEMON | LOG_ERR,
diff --git a/nDPIsrvd.c b/nDPIsrvd.c
index 379cfc20a..d9d3e3777 100644
--- a/nDPIsrvd.c
+++ b/nDPIsrvd.c
@@ -575,13 +575,13 @@ int main(int argc, char ** argv)
current->buf.used += bytes_read;
}
- while (current->buf.used >= nDPIsrvd_JSON_BYTES + 1)
+ while (current->buf.used >= NETWORK_BUFFER_LENGTH_DIGITS + 1)
{
- if (current->buf.ptr[nDPIsrvd_JSON_BYTES] != '{')
+ if (current->buf.ptr[NETWORK_BUFFER_LENGTH_DIGITS] != '{')
{
syslog(LOG_DAEMON | LOG_ERR,
"BUG: JSON invalid opening character: '%c'",
- current->buf.ptr[nDPIsrvd_JSON_BYTES]);
+ current->buf.ptr[NETWORK_BUFFER_LENGTH_DIGITS]);
disconnect_client(epollfd, current);
break;
}
@@ -601,7 +601,7 @@ int main(int argc, char ** argv)
{
syslog(LOG_DAEMON | LOG_ERR,
"BUG: Missing size before JSON string: \"%.*s\"",
- nDPIsrvd_JSON_BYTES,
+ NETWORK_BUFFER_LENGTH_DIGITS,
current->buf.ptr);
disconnect_client(epollfd, current);
break;