From 503cafde589122072d44f1b6d53b320e25231946 Mon Sep 17 00:00:00 2001 From: lancethepants Date: Thu, 25 Aug 2022 14:42:47 -0600 Subject: [PATCH 1/6] Change instances of __in6_u.__u6_addr32 to s6_addr32. Freebsd defines s6_addr32 so remove its define statement. This is to increase compatibility with musl. --- ip.cpp | 8 +++---- ip.h | 68 +++++++++++++++++++++++++++------------------------------- 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/ip.cpp b/ip.cpp index 67dab967f..bb0cc2d95 100644 --- a/ip.cpp +++ b/ip.cpp @@ -29,7 +29,7 @@ bool vmIP::setFromString(const char *ip_str) { ip_str_tmp[min(ip_str_length - 2, (unsigned)sizeof(ip_str_tmp))] = 0; if(inet_pton(AF_INET6, ip_str_tmp, &ip.v6)) { for(unsigned i = 0; i < 4; i++) { - ip.v6.__in6_u.__u6_addr32[i] = ntohl(ip.v6.__in6_u.__u6_addr32[i]); + ip.v6.s6_addr32[i] = ntohl(ip.v6.s6_addr32[i]); } return(true); } @@ -37,7 +37,7 @@ bool vmIP::setFromString(const char *ip_str) { } else { if(inet_pton(AF_INET6, ip_str, &ip.v6)) { for(unsigned i = 0; i < 4; i++) { - ip.v6.__in6_u.__u6_addr32[i] = ntohl(ip.v6.__in6_u.__u6_addr32[i]); + ip.v6.s6_addr32[i] = ntohl(ip.v6.s6_addr32[i]); } return(true); } @@ -83,7 +83,7 @@ bool vmIP::setFromString(const char *ip_str, const char **end_ptr) { ip_str_tmp[min(ip_str_length, (unsigned)sizeof(ip_str_tmp))] = 0; if(inet_pton(AF_INET6, ip_str_tmp, &ip.v6)) { for(unsigned i = 0; i < 4; i++) { - ip.v6.__in6_u.__u6_addr32[i] = ntohl(ip.v6.__in6_u.__u6_addr32[i]); + ip.v6.s6_addr32[i] = ntohl(ip.v6.s6_addr32[i]); } if(end_ptr) { *end_ptr = ip_str + ip_str_length + (ip_str[ip_str_length] == ']' ? 1 : 0); @@ -122,7 +122,7 @@ std::string vmIP::getString(bool ipv6_in_brackets) const { char ip_str[IP_STR_MAX_LENGTH]; in6_addr ip_v6; for(unsigned i = 0; i < 4; i++) { - ip_v6.__in6_u.__u6_addr32[i] = htonl(ip.v6.__in6_u.__u6_addr32[i]); + ip_v6.s6_addr32[i] = htonl(ip.v6.s6_addr32[i]); } inet_ntop(AF_INET6, &ip_v6, ip_str, IP_STR_MAX_LENGTH); return(ipv6_in_brackets ? diff --git a/ip.h b/ip.h index d5bccd281..fdacb7193 100644 --- a/ip.h +++ b/ip.h @@ -34,10 +34,6 @@ #include "endian.h" - -#ifdef FREEBSD -#define __in6_u __u6_addr -#endif #define IP_STR_MAX_LENGTH 50 #define IPPROTO_ESP_HEADER_SIZE 8 @@ -81,7 +77,7 @@ struct vmIP { case 16: memcpy((u_char*)&ip.v6 + (sizeof(ip.v6) - data_ip_length), data_ip, data_ip_length); for(unsigned i = 0; i < 4; i++) { - ip.v6.__in6_u.__u6_addr32[i] = ntohl(ip.v6.__in6_u.__u6_addr32[i]); + ip.v6.s6_addr32[i] = ntohl(ip.v6.s6_addr32[i]); } v6 = true; break; @@ -108,7 +104,7 @@ struct vmIP { this->ip.v6 = ip; if(ntoh) { for(unsigned i = 0; i < 4; i++) { - this->ip.v6.__in6_u.__u6_addr32[i] = ntohl(this->ip.v6.__in6_u.__u6_addr32[i]); + this->ip.v6.s6_addr32[i] = ntohl(this->ip.v6.s6_addr32[i]); } } v6 = true; @@ -124,7 +120,7 @@ struct vmIP { if(hton) { in6_addr _ip = this->ip.v6; for(unsigned i = 0; i < 4; i++) { - _ip.__in6_u.__u6_addr32[i] = htonl(_ip.__in6_u.__u6_addr32[i]); + _ip.s6_addr32[i] = htonl(_ip.s6_addr32[i]); } return(_ip); } else { @@ -144,14 +140,14 @@ struct vmIP { return((ip.v4.n >> 8) == 0x7F0000); #if VM_IPV6 } else { - return((ip.v6.__in6_u.__u6_addr32[0] == 0 && - ip.v6.__in6_u.__u6_addr32[1] == 0 && - ip.v6.__in6_u.__u6_addr32[2] == 0 && - ip.v6.__in6_u.__u6_addr32[3] == 1) || - (ip.v6.__in6_u.__u6_addr32[0] == 0 && - ip.v6.__in6_u.__u6_addr32[1] == 0 && - ip.v6.__in6_u.__u6_addr32[2] == 0xFFFF && - (ip.v6.__in6_u.__u6_addr32[3] >> 8) == 0x7F0000)); + return((ip.v6.s6_addr32[0] == 0 && + ip.v6.s6_addr32[1] == 0 && + ip.v6.s6_addr32[2] == 0 && + ip.v6.s6_addr32[3] == 1) || + (ip.v6.s6_addr32[0] == 0 && + ip.v6.s6_addr32[1] == 0 && + ip.v6.s6_addr32[2] == 0xFFFF && + (ip.v6.s6_addr32[3] >> 8) == 0x7F0000)); } #endif } @@ -198,20 +194,20 @@ struct vmIP { return(ip.v4.n != 0); #if VM_IPV6 } else { - return(ip.v6.__in6_u.__u6_addr32[0] != 0 || - ip.v6.__in6_u.__u6_addr32[1] != 0 || - ip.v6.__in6_u.__u6_addr32[2] != 0 || - ip.v6.__in6_u.__u6_addr32[3] != 0); + return(ip.v6.s6_addr32[0] != 0 || + ip.v6.s6_addr32[1] != 0 || + ip.v6.s6_addr32[2] != 0 || + ip.v6.s6_addr32[3] != 0); } #endif } inline void clear(u_int32_t set = 0) { #if VM_IPV6 v6 = false; - ip.v6.__in6_u.__u6_addr32[0] = set; - ip.v6.__in6_u.__u6_addr32[1] = set; - ip.v6.__in6_u.__u6_addr32[2] = set; - ip.v6.__in6_u.__u6_addr32[3] = set; + ip.v6.s6_addr32[0] = set; + ip.v6.s6_addr32[1] = set; + ip.v6.s6_addr32[2] = set; + ip.v6.s6_addr32[3] = set; #else ip.v4.n = set; #endif @@ -225,7 +221,7 @@ struct vmIP { #if VM_IPV6 } else { for(unsigned i = 0; i < 4; i++) { - ip.ip.v6.__in6_u.__u6_addr32[i] &= mask.ip.v6.__in6_u.__u6_addr32[i]; + ip.ip.v6.s6_addr32[i] &= mask.ip.v6.s6_addr32[i]; } } #endif @@ -240,7 +236,7 @@ struct vmIP { #if VM_IPV6 } else { for(unsigned i = 0; i < 4; i++) { - ip.ip.v6.__in6_u.__u6_addr32[i] |= mask.ip.v6.__in6_u.__u6_addr32[i]; + ip.ip.v6.s6_addr32[i] |= mask.ip.v6.s6_addr32[i]; } } #endif @@ -268,11 +264,11 @@ struct vmIP { for(unsigned i = 0; i < 4; i++) { int _mask = mask - i * 32; if(mask == 0 || _mask <= 0) { - ip.ip.v6.__in6_u.__u6_addr32[i] = 0; + ip.ip.v6.s6_addr32[i] = 0; } else if(_mask >= 32) { - ip.ip.v6.__in6_u.__u6_addr32[i] = (u_int32_t)-1; + ip.ip.v6.s6_addr32[i] = (u_int32_t)-1; } else { - ip.ip.v6.__in6_u.__u6_addr32[i] = ((u_int32_t)-1 << (32 - _mask)) & (u_int32_t)-1; + ip.ip.v6.s6_addr32[i] = ((u_int32_t)-1 << (32 - _mask)) & (u_int32_t)-1; } } } @@ -298,11 +294,11 @@ struct vmIP { for(unsigned i = 0; i < 4; i++) { int _mask = mask - i * 32; if(mask == 0 || _mask <= 0) { - ip.ip.v6.__in6_u.__u6_addr32[i] = (u_int32_t)-1; + ip.ip.v6.s6_addr32[i] = (u_int32_t)-1; } else if(_mask >= 32) { - ip.ip.v6.__in6_u.__u6_addr32[i] = 0; + ip.ip.v6.s6_addr32[i] = 0; } else { - ip.ip.v6.__in6_u.__u6_addr32[i] = (u_int32_t)(pow(2, 32 -_mask) - 1); + ip.ip.v6.s6_addr32[i] = (u_int32_t)(pow(2, 32 -_mask) - 1); } } } @@ -322,7 +318,7 @@ struct vmIP { return(ip.v4.n); #if VM_IPV6 } else { - return(ip.v6.__in6_u.__u6_addr32[3]); + return(ip.v6.s6_addr32[3]); } #endif } @@ -399,27 +395,27 @@ struct ip6hdr2 { inline vmIP get_saddr() { in6_addr __saddr = _saddr; for(unsigned i = 0; i < 4; i++) { - __saddr.__in6_u.__u6_addr32[i] = ntohl(__saddr.__in6_u.__u6_addr32[i]); + __saddr.s6_addr32[i] = ntohl(__saddr.s6_addr32[i]); } return(__saddr); } inline vmIP get_daddr() { in6_addr __daddr = _daddr; for(unsigned i = 0; i < 4; i++) { - __daddr.__in6_u.__u6_addr32[i] = ntohl(__daddr.__in6_u.__u6_addr32[i]); + __daddr.s6_addr32[i] = ntohl(__daddr.s6_addr32[i]); } return(__daddr); } inline void set_saddr(vmIP &ip) { _saddr = ip.getIPv6(); for(unsigned i = 0; i < 4; i++) { - _saddr.__in6_u.__u6_addr32[i] = htonl(_saddr.__in6_u.__u6_addr32[i]); + _saddr.s6_addr32[i] = htonl(_saddr.s6_addr32[i]); } } inline void set_daddr(vmIP &ip) { _daddr = ip.getIPv6(); for(unsigned i = 0; i < 4; i++) { - _daddr.__in6_u.__u6_addr32[i] = htonl(_daddr.__in6_u.__u6_addr32[i]); + _daddr.s6_addr32[i] = htonl(_daddr.s6_addr32[i]); } } static inline bool is_ext_header(u_int8_t header_id) { From 223cf38026e649b9aa5131956129ebfb54eebd8f Mon Sep 17 00:00:00 2001 From: lancethepants Date: Thu, 25 Aug 2022 14:42:47 -0600 Subject: [PATCH 2/6] Explicitly include #include --- dpdk.cpp | 1 + heap_safe.h | 1 + 2 files changed, 2 insertions(+) diff --git a/dpdk.cpp b/dpdk.cpp index b95e3b5a9..3f8402569 100644 --- a/dpdk.cpp +++ b/dpdk.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "pstat.h" #include "tools_global.h" diff --git a/heap_safe.h b/heap_safe.h index 08567a718..832ff7bef 100644 --- a/heap_safe.h +++ b/heap_safe.h @@ -2,6 +2,7 @@ #define HEAP_SAFE_H +#include #include #include #include From 150951528e0ca3af7a9b3f3835bf3fa8661a33cf Mon Sep 17 00:00:00 2001 From: lancethepants Date: Thu, 25 Aug 2022 14:42:47 -0600 Subject: [PATCH 3/6] Check for __GLIBC__ instead of not FREEBSD. --- heap_safe.cpp | 2 +- tools.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/heap_safe.cpp b/heap_safe.cpp index 4dcf87688..889e262f2 100644 --- a/heap_safe.cpp +++ b/heap_safe.cpp @@ -791,7 +791,7 @@ std::string addThousandSeparators(u_int64_t num) { } void printMemoryStat(bool all) { -#ifndef FREEBSD +#ifdef __GLIBC__ malloc_trim(0); #endif std::cout << getMemoryStat(all); diff --git a/tools.cpp b/tools.cpp index 4f0392127..6d1991e15 100644 --- a/tools.cpp +++ b/tools.cpp @@ -8683,7 +8683,7 @@ unsigned RTPSENSOR_VERSION_INT() { void rss_purge(bool force) { - #ifndef FREEBSD + #ifdef __GLIBC__ malloc_trim(0); if(sverb.malloc_trim) { syslog(LOG_NOTICE, "malloc trim"); From cd33e4ad1158a41088a55e74bd906bbeab5f7bb3 Mon Sep 17 00:00:00 2001 From: lancethepants Date: Thu, 25 Aug 2022 14:42:47 -0600 Subject: [PATCH 4/6] mgcp.cpp: Return false instead of NULL. --- mgcp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mgcp.cpp b/mgcp.cpp index 72dbd5122..7cddb3dd0 100644 --- a/mgcp.cpp +++ b/mgcp.cpp @@ -180,13 +180,13 @@ void *handle_mgcp(packet_s_process *packetS) { break; } } - call->removeFindTables(NULL, true); + call->removeFindTables(false, true); calltable->unlock_calls_listMAP(); } else { calltable->lock_calls_listMAP(); map::iterator callMAPIT = calltable->calls_by_stream_listMAP.find(sStreamId(packetS->saddr_(), packetS->source_(), packetS->daddr_(), packetS->dest_(), true)); if(callMAPIT != calltable->calls_by_stream_listMAP.end()) { - callMAPIT->second->removeFindTables(NULL, true); + callMAPIT->second->removeFindTables(false, true); } calltable->unlock_calls_listMAP(); } From 45554890f7c509e61c57c4c6b9252c5ab34046ac Mon Sep 17 00:00:00 2001 From: lancethepants Date: Thu, 25 Aug 2022 14:42:47 -0600 Subject: [PATCH 5/6] Add MIN definition Depending on order of includes min/max become undefined Here we just create a MIN definition like in sniff.cpp and others. --- manager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/manager.cpp b/manager.cpp index b087e706f..6bb86cb96 100644 --- a/manager.cpp +++ b/manager.cpp @@ -112,6 +112,10 @@ int opt_block_alloc_stack = 0; using namespace std; +#ifndef MIN +#define MIN(x,y) ((x) < (y) ? (x) : (y)) +#endif + int sendvm(int socket, cClient *c_client, const char *buf, size_t len, int /*mode*/); std::map MgmtCmdsRegTable; From 6042d15ce666d43c091061b3dec284c1ca506c74 Mon Sep 17 00:00:00 2001 From: lancethepants Date: Thu, 25 Aug 2022 14:53:44 -0600 Subject: [PATCH 6/6] Remove SIGCLD as it is depcrated and not supported on musl. --- voipmonitor.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/voipmonitor.cpp b/voipmonitor.cpp index 34ecec71e..9c8ad0324 100644 --- a/voipmonitor.cpp +++ b/voipmonitor.cpp @@ -152,7 +152,6 @@ signal_def signal_data[] = { "SIGTERM", SIGTERM, "Termination (ANSI)" }, { "SIGSTKFLT", SIGSTKFLT, "Stack fault" }, { "SIGCHLD", SIGCHLD, "Child status has changed (POSIX)" }, - { "SIGCLD", SIGCLD, "Same as SIGCHLD (System V)" }, { "SIGCONT", SIGCONT, "Continue (POSIX)" }, { "SIGSTOP", SIGSTOP, "Stop, unblockable (POSIX)" }, { "SIGTSTP", SIGTSTP, "Keyboard stop (POSIX)" },