Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to increase compatibility with musl libc #103

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dpdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <unistd.h>
#include <sys/resource.h>
#include <string.h>
#include <sys/types.h>

#include "pstat.h"
#include "tools_global.h"
Expand Down
2 changes: 1 addition & 1 deletion heap_safe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions heap_safe.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define HEAP_SAFE_H


#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
Expand Down
8 changes: 4 additions & 4 deletions ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ 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);
}
}
} 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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 ?
Expand Down
68 changes: 32 additions & 36 deletions ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}
}
Expand All @@ -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);
}
}
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, int> MgmtCmdsRegTable;
Expand Down
4 changes: 2 additions & 2 deletions mgcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<sStreamId, Call*>::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();
}
Expand Down
2 changes: 1 addition & 1 deletion tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 0 additions & 1 deletion voipmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)" },
Expand Down