1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-09-28 19:05:55 +08:00
This commit is contained in:
stefanocasazza 2018-05-21 15:57:13 +02:00
parent d4dfd5d9a8
commit 6f299d2ccb
34 changed files with 1274 additions and 366 deletions

View File

@ -463,11 +463,13 @@ static bool setAccessPoint()
U_RETURN(true); U_RETURN(true);
} }
static inline void setSessionkey() static inline void setSessionkey(const UString& lmac)
{ {
U_TRACE_NO_PARAM(5, "::setSessionkey()") U_TRACE(5, "::setSessionkey(%V)", lmac.rep)
key_session->setBuffer(200U); key_session->snprintf(U_CONSTANT_TO_PARAM("captiveId:%u;apId:%v;deviceId:%v;ip:%v"), addr, ap_label->rep, mac->rep, ip->rep); U_INTERNAL_ASSERT(u_isXMacAddr(U_STRING_TO_PARAM(lmac)))
key_session->setBuffer(200U); key_session->snprintf(U_CONSTANT_TO_PARAM("captiveId:%u;apId:%v;deviceId:%v;ip:%v"), addr, ap_label->rep, lmac.rep, ip->rep);
} }
static void setSessionPolicy() static void setSessionPolicy()
@ -670,6 +672,11 @@ static bool getDataFromPOST(bool bpeer)
// $3 -> ip // $3 -> ip
// $4 -> peer // $4 -> peer
ip->clear();
mac->clear();
peer = U_NULLPTR;
UFlatBuffer fb, vec; UFlatBuffer fb, vec;
fb.setRoot(*UClientImage_Base::body); fb.setRoot(*UClientImage_Base::body);
@ -685,13 +692,30 @@ static bool getDataFromPOST(bool bpeer)
*ip = vec.AsVectorGet<UString>(2); *ip = vec.AsVectorGet<UString>(2);
U_INTERNAL_ASSERT(u_isIPv4Addr(U_STRING_TO_PARAM(*ip))) U_INTERNAL_ASSERT(u_isIPv4Addr(U_STRING_TO_PARAM(*ip)))
U_INTERNAL_ASSERT(u_isXMacAddr(U_STRING_TO_PARAM(*mac)))
setSessionPolicy(); if (bpeer == false) setSessionPolicy();
else
if (bpeer)
{ {
peer = (void*) vec.AsVectorGet<uint64_t>(3); peer = (void*) vec.AsVectorGet<uint64_t>(3);
UString mac_old = vec.AsVectorGet<UString>(4),
label_old = vec.AsVectorGet<UString>(5);
if (mac_old)
{
setSessionkey(mac_old);
if (getSession(U_CONSTANT_TO_PARAM("getDataFromPOST(true)")))
{
deleteSession();
writeSessionToLOG(U_CONSTANT_TO_PARAM("DENY_NO_TRAFFIC"));
}
}
setSessionPolicy();
ok = checkDevice(); ok = checkDevice();
} }
} }
@ -705,6 +729,22 @@ static void lostSession(bool bclean)
if (getSession(U_CONSTANT_TO_PARAM("lostSession"))) if (getSession(U_CONSTANT_TO_PARAM("lostSession")))
{ {
*ip = rc->getString(9);
if (u_isIPv4Addr(U_STRING_TO_PARAM(*ip)) == false)
{
(void) rc->del(U_CONSTANT_TO_PARAM("SESSION:%v"), key_session->rep);
(void) rc->zrem(U_CONSTANT_TO_PARAM("SESSION:byLastUpdate %v"), key_session->rep);
U_LOGGER("*** SESSION(%V) have a wrong ip: %V ***", key_session->rep, ip->rep);
return;
}
*mac = rc->getString(8);
U_INTERNAL_ASSERT(u_isXMacAddr(U_STRING_TO_PARAM(*mac)))
if (bclean) if (bclean)
{ {
*ap_label = rc->getString(7); *ap_label = rc->getString(7);
@ -715,15 +755,21 @@ static void lostSession(bool bclean)
*ap_hostname = rc->getString(1); *ap_hostname = rc->getString(1);
} }
*mac = rc->getString(8);
*ip = rc->getString(9);
U_INTERNAL_ASSERT(u_isIPv4Addr(U_STRING_TO_PARAM(*ip)))
writeSessionToLOG(U_CONSTANT_TO_PARAM("DENY_LOST")); writeSessionToLOG(U_CONSTANT_TO_PARAM("DENY_LOST"));
deleteSession(); deleteSession();
} }
else
{
uint32_t pos = U_STRING_FIND(*key_session, 10, "deviceId:"); // 10 => U_CONSTANT_SIZE("captiveId:")
U_INTERNAL_ASSERT_DIFFERS(pos, U_NOT_FOUND)
const char* ptr = key_session->c_pointer(pos);
(void) rc->zrem(U_CONSTANT_TO_PARAM("SESSION:byCaptiveIdAndApId %.*s"), key_session->remain(ptr), ptr);
(void) rc->zrem(U_CONSTANT_TO_PARAM("SESSION:byLastUpdate %v"), key_session->rep);
}
} }
static void GET_anagrafica() static void GET_anagrafica()
@ -748,7 +794,9 @@ static void GET_clean()
(void) rc->zrangebyscore(U_CONSTANT_TO_PARAM("SESSION:byLastUpdate 0 %u"), last_update); (void) rc->zrangebyscore(U_CONSTANT_TO_PARAM("SESSION:byLastUpdate 0 %u"), last_update);
if ((n = rc->vitem.size())) n = rc->vitem.size();
if (n)
{ {
UVector<UString> vec(n); UVector<UString> vec(n);
@ -764,14 +812,19 @@ static void GET_clean()
(void) rc->zrangebyscore(U_CONSTANT_TO_PARAM("CAPTIVE:byLastUpdate 0 %u"), last_update); (void) rc->zrangebyscore(U_CONSTANT_TO_PARAM("CAPTIVE:byLastUpdate 0 %u"), last_update);
if ((n = rc->vitem.size())) n = rc->vitem.size();
if (n)
{ {
uint8_t status; uint8_t status;
UString url(100U); UString url(100U);
UVector<UString> vec(n);
vec.copy(rc->vitem);
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
{ {
*ap_address = rc->vitem[i]; *ap_address = vec[i];
(void) UIPAddress::getBinaryForm(ap_address->c_str(), addr, true); (void) UIPAddress::getBinaryForm(ap_address->c_str(), addr, true);
@ -807,26 +860,6 @@ static void GET_clean()
(void) rc->hmset(U_CONSTANT_TO_PARAM("CAPTIVE:id:%u status %c"), addr, status); (void) rc->hmset(U_CONSTANT_TO_PARAM("CAPTIVE:id:%u status %c"), addr, status);
} }
} }
/*
(void) rc->zrangebyscore(U_CONSTANT_TO_PARAM("DEVICE:bylastAccess 0 %u"), u_now->tv_sec - U_CLEAN_INTERVAL);
if ((n = rc->vitem.size()))
{
UString x;
UVector<UString> vec(n);
vec.copy(rc->vitem);
for (i = 0; i < n; ++i)
{
x = vec[i];
(void) rc->del(U_CONSTANT_TO_PARAM("DEVICE:%v"), x.rep);
(void) rc->zrem(U_CONSTANT_TO_PARAM("DEVICE:bylastAccess %v"), x.rep);
}
}
*/
} }
} }
@ -1070,6 +1103,8 @@ static void GET_welcome()
UHTTP::getFormValue(*mac, U_CONSTANT_TO_PARAM("mac"), 0, 3, 8); UHTTP::getFormValue(*mac, U_CONSTANT_TO_PARAM("mac"), 0, 3, 8);
UHTTP::getFormValue(*ap_label, U_CONSTANT_TO_PARAM("apid"), 0, 5, 8); UHTTP::getFormValue(*ap_label, U_CONSTANT_TO_PARAM("apid"), 0, 5, 8);
U_INTERNAL_ASSERT(u_isXMacAddr(U_STRING_TO_PARAM(*mac)))
setSessionPolicy(); setSessionPolicy();
ok = checkDevice(); ok = checkDevice();
@ -1089,11 +1124,9 @@ static void POST_login()
// $3 -> ip // $3 -> ip
// $4 -> peer // $4 -> peer
peer = U_NULLPTR;
bool ko = (getDataFromPOST(true) == false); bool ko = (getDataFromPOST(true) == false);
if (*ap_address) if (*mac)
{ {
UFlatBuffer fb; UFlatBuffer fb;
char buffer[2] = { '1'-ko, '0'+policySessionNotify }; // deny|permit: ('0'|'1') policy: notify|no_notify|strict_notify ('0'|'1'|'2') char buffer[2] = { '1'-ko, '0'+policySessionNotify }; // deny|permit: ('0'|'1') policy: notify|no_notify|strict_notify ('0'|'1'|'2')
@ -1106,7 +1139,7 @@ static void POST_login()
if (ko) writeSessionToLOG(U_CONSTANT_TO_PARAM("DENY_POLICY")); if (ko) writeSessionToLOG(U_CONSTANT_TO_PARAM("DENY_POLICY"));
else else
{ {
setSessionkey(); setSessionkey(*mac);
(void) rc->hmset(U_CONSTANT_TO_PARAM("SESSION:%v captiveId %u apId %v deviceId %v ip %v created %u pId %v notify %c consume %c counter 0 lastUpdate %u"), key_session->rep, (void) rc->hmset(U_CONSTANT_TO_PARAM("SESSION:%v captiveId %u apId %v deviceId %v ip %v created %u pId %v notify %c consume %c counter 0 lastUpdate %u"), key_session->rep,
addr, ap_label->rep, mac->rep, ip->rep, u_now->tv_sec, policySessionId->rep, buffer[1], '0'+ap_consume, u_now->tv_sec); addr, ap_label->rep, mac->rep, ip->rep, u_now->tv_sec, policySessionId->rep, buffer[1], '0'+ap_consume, u_now->tv_sec);
@ -1288,7 +1321,9 @@ static void POST_info()
continue; continue;
} }
setSessionkey(); U_INTERNAL_ASSERT(u_isXMacAddr(U_STRING_TO_PARAM(*mac)))
setSessionkey(*mac);
if (getSession(U_CONSTANT_TO_PARAM("POST_info")) == false) goto del_login; if (getSession(U_CONSTANT_TO_PARAM("POST_info")) == false) goto del_login;

View File

@ -514,6 +514,8 @@ static inline void u_gettimenow(void)
#endif #endif
*/ */
U_EXPORT uint32_t u_isDayOfWeek(const char* restrict str) __pure;
U_EXPORT uint32_t u_strftime1(char* restrict buffer, uint32_t buffer_size, const char* restrict fmt, uint32_t fmt_size); U_EXPORT uint32_t u_strftime1(char* restrict buffer, uint32_t buffer_size, const char* restrict fmt, uint32_t fmt_size);
static inline uint32_t u_strftime2(char* restrict buffer, uint32_t buffer_size, const char* restrict fmt, uint32_t fmt_size, time_t when) static inline uint32_t u_strftime2(char* restrict buffer, uint32_t buffer_size, const char* restrict fmt, uint32_t fmt_size, time_t when)
{ {

View File

@ -553,6 +553,7 @@ U_EXPORT bool u_isDigit( const char* restrict s, uint32_t n) __pure;
U_EXPORT bool u_isBase64( const char* restrict s, uint32_t n) __pure; U_EXPORT bool u_isBase64( const char* restrict s, uint32_t n) __pure;
U_EXPORT bool u_isBase64Url( const char* restrict s, uint32_t n) __pure; U_EXPORT bool u_isBase64Url( const char* restrict s, uint32_t n) __pure;
U_EXPORT bool u_isMacAddr( const char* restrict s, uint32_t n) __pure; U_EXPORT bool u_isMacAddr( const char* restrict s, uint32_t n) __pure;
U_EXPORT bool u_isXMacAddr( const char* restrict s, uint32_t n) __pure;
U_EXPORT bool u_isHostName( const char* restrict s, uint32_t n) __pure; U_EXPORT bool u_isHostName( const char* restrict s, uint32_t n) __pure;
U_EXPORT bool u_isFileName( const char* restrict s, uint32_t n) __pure; U_EXPORT bool u_isFileName( const char* restrict s, uint32_t n) __pure;
U_EXPORT bool u_isWhiteSpace(const char* restrict s, uint32_t n) __pure; U_EXPORT bool u_isWhiteSpace(const char* restrict s, uint32_t n) __pure;
@ -563,6 +564,33 @@ U_EXPORT bool u_isUrlEncoded( const char* restrict s, uint32_t n, bool bquer
U_EXPORT const char* u_isUrlScheme(const char* restrict url, uint32_t len) __pure; U_EXPORT const char* u_isUrlScheme(const char* restrict url, uint32_t len) __pure;
static inline void u_getXMAC(const char* restrict src, char* restrict dst)
{
U_INTERNAL_TRACE("u_getXMAC(%p,%p)", src, dst)
U_INTERNAL_ASSERT(u_isMacAddr(src,12+5))
/**
* %2u:%2u:%2u:%2u:%2u:%2u
*
* (void) memcpy(dst, src, 2);
* (void) memcpy(dst+ 2, src+ 2+1, 2);
* (void) memcpy(dst+ 4, src+ 4+2, 2);
* (void) memcpy(dst+ 6, src+ 6+3, 2);
* (void) memcpy(dst+ 8, src+ 8+4, 2);
* (void) memcpy(dst+10, src+10+5, 2);
*/
u_put_unalignedp16(dst, *(uint16_t*)src);
u_put_unalignedp16(dst+ 2, *(uint16_t*)(src+ 2+1));
u_put_unalignedp16(dst+ 4, *(uint16_t*)(src+ 4+2));
u_put_unalignedp16(dst+ 6, *(uint16_t*)(src+ 6+3));
u_put_unalignedp16(dst+ 8, *(uint16_t*)(src+ 8+4));
u_put_unalignedp16(dst+10, *(uint16_t*)(src+10+5));
U_INTERNAL_ASSERT(u_isXMacAddr(dst,12))
}
static inline int u_equal(const void* restrict s1, const void* restrict s2, uint32_t n, bool ignore_case) /* Equal with ignore case */ static inline int u_equal(const void* restrict s1, const void* restrict s2, uint32_t n, bool ignore_case) /* Equal with ignore case */
{ {
U_INTERNAL_TRACE("u_equal(%p,%p,%u)", s1, s2, n) U_INTERNAL_TRACE("u_equal(%p,%p,%u)", s1, s2, n)

View File

@ -82,24 +82,6 @@ protected:
uint32_t addr, ctraffic, time_no_traffic; uint32_t addr, ctraffic, time_no_traffic;
uucflag flag; uucflag flag;
void getMAC(char* dst)
{
U_TRACE(0, "UModNoDogPeer::getMAC(%p)", dst)
U_INTERNAL_ASSERT(u_isMacAddr(U_STRING_TO_PARAM(mac)))
char* src = mac.data();
// "%2u:%2u:%2u:%2u:%2u:%2u"
(void) memcpy(dst, src, 2);
(void) memcpy(dst+ 2, src+ 2+1, 2);
(void) memcpy(dst+ 4, src+ 4+2, 2);
(void) memcpy(dst+ 6, src+ 6+3, 2);
(void) memcpy(dst+ 8, src+ 8+4, 2);
(void) memcpy(dst+10, src+10+5, 2);
}
private: private:
U_DISALLOW_ASSIGN(UModNoDogPeer) U_DISALLOW_ASSIGN(UModNoDogPeer)
@ -177,6 +159,8 @@ protected:
static UString* fw_env; static UString* fw_env;
static UString* extdev; static UString* extdev;
static UString* intdev; static UString* intdev;
static UString* mac_old;
static UString* label_old;
static UString* hostname; static UString* hostname;
static UString* localnet; static UString* localnet;
static UString* info_data; static UString* info_data;
@ -185,6 +169,7 @@ protected:
static UString* IP_address_trust; static UString* IP_address_trust;
static UString* auth_host; static UString* auth_host;
static UString* auth_deny;
static UString* auth_info; static UString* auth_info;
static UString* auth_login; static UString* auth_login;
static UString* auth_notify; static UString* auth_notify;
@ -198,7 +183,7 @@ protected:
static UIptAccount* ipt; static UIptAccount* ipt;
static uint32_t check_expire, T1, T2; static uint32_t check_expire, T1, T2;
static UHttpClient<UTCPSocket>* client; static UHttpClient<UTCPSocket>* client;
static bool mac_from_dhcp_data_file, bnetwork_interface; static bool mac_from_dhcp_data_file, bnetwork_interface, bdifferent;
static UIPAllow* pallow; static UIPAllow* pallow;
static UModNoDogPeer* peer; static UModNoDogPeer* peer;
@ -210,43 +195,43 @@ protected:
static UVector<UString>* vLocalNetworkLabel; static UVector<UString>* vLocalNetworkLabel;
static UVector<UIPAllow*>* vLocalNetworkMask; static UVector<UIPAllow*>* vLocalNetworkMask;
static void setNewPeer(); static bool setNewPeer();
static bool preallocatePeersFault(); static bool preallocatePeersFault();
static void executeCommand(const char* type, uint32_t len); static void executeCommand(const char* type, uint32_t len, const UString& mac);
static void deny() static void deny(const UString& mac)
{ {
U_TRACE_NO_PARAM(0, "UNoDogPlugIn::deny()") U_TRACE(0, "UNoDogPlugIn::deny(%V)", mac.rep)
U_INTERNAL_ASSERT_POINTER(peer) U_INTERNAL_ASSERT_POINTER(peer)
U_INTERNAL_ASSERT(U_peer_permit) U_INTERNAL_ASSERT(U_peer_permit)
if (U_peer_allowed) if (U_peer_allowed)
{ {
U_SRV_LOG("WARNING: I should to deny user allowed: IP %v MAC %v", peer->ip.rep, peer->mac.rep); U_SRV_LOG("WARNING: I should to deny user allowed: IP %v MAC %v", peer->ip.rep, mac.rep);
return; return;
} }
executeCommand(U_CONSTANT_TO_PARAM("deny")); executeCommand(U_CONSTANT_TO_PARAM("deny"), mac);
U_SRV_LOG("Peer denied: IP %v MAC %v", peer->ip.rep, peer->mac.rep); U_SRV_LOG("Peer denied: IP %v MAC %v", peer->ip.rep, mac.rep);
} }
static void permit() static void permit(const UString& mac)
{ {
U_TRACE_NO_PARAM(0, "UNoDogPlugIn::permit()") U_TRACE(0, "UNoDogPlugIn::permit(%V)", mac.rep)
U_INTERNAL_ASSERT_POINTER(peer) U_INTERNAL_ASSERT_POINTER(peer)
U_INTERNAL_ASSERT_EQUALS(U_peer_permit, false) U_INTERNAL_ASSERT_EQUALS(U_peer_permit, false)
executeCommand(U_CONSTANT_TO_PARAM("permit")); executeCommand(U_CONSTANT_TO_PARAM("permit"), mac);
peer->_ctime = u_now->tv_sec; peer->_ctime = u_now->tv_sec;
U_peer_flag |= U_PEER_PERMIT; U_peer_flag |= U_PEER_PERMIT;
U_SRV_LOG("Peer permitted: IP %v MAC %v", peer->ip.rep, peer->mac.rep); U_SRV_LOG("Peer permitted: IP %v MAC %v", peer->ip.rep, mac.rep);
} }
static UString getUrlForSendMsgToPortal(const char* service, uint32_t service_len) static UString getUrlForSendMsgToPortal(const char* service, uint32_t service_len)
@ -262,13 +247,6 @@ protected:
static UString getUrlForSendMsgToPortal(const UString& service) { return getUrlForSendMsgToPortal(U_STRING_TO_PARAM(service)); } static UString getUrlForSendMsgToPortal(const UString& service) { return getUrlForSendMsgToPortal(U_STRING_TO_PARAM(service)); }
static uint32_t setRedirect(char* buffer, uint32_t bufsize)
{
U_TRACE(0, "UNoDogPlugIn::setRedirect(%p,%u)", buffer, bufsize)
return u__snprintf(buffer, bufsize, U_CONSTANT_TO_PARAM("http://%.*s%.*s"), U_HTTP_HOST_TO_TRACE, U_HTTP_URI_QUERY_TO_TRACE);
}
static uint32_t getApInfo(char* buffer, uint32_t bufsize, const UString& lbl) static uint32_t getApInfo(char* buffer, uint32_t bufsize, const UString& lbl)
{ {
U_TRACE(0, "UNoDogPlugIn::getApInfo(%p,%u,%V)", buffer, bufsize, lbl.rep) U_TRACE(0, "UNoDogPlugIn::getApInfo(%p,%u,%V)", buffer, bufsize, lbl.rep)
@ -276,18 +254,19 @@ protected:
return u__snprintf(buffer, bufsize, U_CONSTANT_TO_PARAM("%v@%v/%v"), lbl.rep, UServer_Base::IP_address->rep, hostname->rep); return u__snprintf(buffer, bufsize, U_CONSTANT_TO_PARAM("%v@%v/%v"), lbl.rep, UServer_Base::IP_address->rep, hostname->rep);
} }
static uint32_t checkUrl(char* buffer, uint32_t buffer_len, uint32_t sz, const char* user, uint32_t user_len);
private: private:
U_DISALLOW_COPY_AND_ASSIGN(UNoDogPlugIn) U_DISALLOW_COPY_AND_ASSIGN(UNoDogPlugIn)
static bool getPeer() U_NO_EXPORT; static bool getPeer() U_NO_EXPORT;
static void erasePeer() U_NO_EXPORT; static void erasePeer() U_NO_EXPORT;
static void setMAC() U_NO_EXPORT; static bool setMAC() U_NO_EXPORT;
static void sendLogin() U_NO_EXPORT; static void sendLogin() U_NO_EXPORT;
static void sendNotify() U_NO_EXPORT; static void sendNotify() U_NO_EXPORT;
static void eraseTimer() U_NO_EXPORT; static void eraseTimer() U_NO_EXPORT;
static bool checkOldPeer() U_NO_EXPORT; static bool setLabelAndMAC() U_NO_EXPORT;
static void setLabelAndMAC() U_NO_EXPORT;
static void sendStrictNotify() U_NO_EXPORT; static void sendStrictNotify() U_NO_EXPORT;
// static void printPeers(const char* fmt, uint32_t len) U_NO_EXPORT; // static void printPeers(const char* fmt, uint32_t len) U_NO_EXPORT;

View File

@ -374,8 +374,6 @@ public:
return cRemoteAddress.getInAddr(); return cRemoteAddress.getInAddr();
} }
UString getMacAddress(const char* device = "eth0");
/** /**
* This method manage the buffer of the socket connection * This method manage the buffer of the socket connection
*/ */

View File

@ -437,6 +437,19 @@ public:
void String(const char* key, uint32_t len1, const char* str, uint32_t len2) { Key(key, len1); CreateString(str, len2); } void String(const char* key, uint32_t len1, const char* str, uint32_t len2) { Key(key, len1); CreateString(str, len2); }
void StringNull()
{
U_TRACE_NO_PARAM(0, "UFlatBuffer::StringNull()")
buffer_str[buffer_idx++] = 0;
U_INTERNAL_DUMP("buffer_idx = %u buffer_max = %u", buffer_idx, buffer_max)
U_INTERNAL_ASSERT_MINOR(buffer_idx, buffer_max)
pushOnStack(buffer_idx, UFlatBufferValue::TYPE_STRING, UFlatBufferValue::BIT_WIDTH_8);
}
// Overloaded Add that tries to call the correct function above // Overloaded Add that tries to call the correct function above
static void Add() { Null(); } static void Add() { Null(); }
@ -1296,15 +1309,19 @@ protected:
{ {
U_TRACE(0, "UFlatBuffer::CreateString(%.*S,%u)", len, data, len) U_TRACE(0, "UFlatBuffer::CreateString(%.*S,%u)", len, data, len)
uint8_t bit_width = UFlatBufferValue::WidthL(len); if (len == 0) StringNull();
else
{
uint8_t bit_width = UFlatBufferValue::WidthL(len);
WriteScalar<uint32_t>(len, Align(bit_width)); WriteScalar<uint32_t>(len, Align(bit_width));
uint32_t sloc = buffer_idx; uint32_t sloc = buffer_idx;
WriteBytes(data, len); WriteBytes(data, len);
pushOnStack(sloc, UFlatBufferValue::TYPE_STRING, bit_width); pushOnStack(sloc, UFlatBufferValue::TYPE_STRING, bit_width);
}
} }
void CreateVector(uint32_t start, uint32_t vec_len, uint32_t step, bool typed, bool fixed, UFlatBufferValue* pval); void CreateVector(uint32_t start, uint32_t vec_len, uint32_t step, bool typed, bool fixed, UFlatBufferValue* pval);
@ -1363,6 +1380,8 @@ protected:
{ {
U_TRACE(0, "UFlatBuffer::WriteBytes<T>(%#.*S,%u)", len, val, len) U_TRACE(0, "UFlatBuffer::WriteBytes<T>(%#.*S,%u)", len, val, len)
U_INTERNAL_ASSERT_MAJOR(len, 0)
(void) memcpy(getPointer(), val, len); (void) memcpy(getPointer(), val, len);
buffer_idx += len; buffer_idx += len;

View File

@ -673,6 +673,17 @@ public:
U_RETURN(false); U_RETURN(false);
} }
bool isXMacAddr() const
{
U_TRACE_NO_PARAM(0, "UStringRep::isXMacAddr()")
U_CHECK_MEMORY
if (u_isXMacAddr(str, _length)) U_RETURN(true);
U_RETURN(false);
}
bool isEndHeader(uint32_t pos) const __pure; bool isEndHeader(uint32_t pos) const __pure;
bool findEndHeader(uint32_t pos) const __pure bool findEndHeader(uint32_t pos) const __pure
{ {
@ -2000,6 +2011,7 @@ public:
bool isNull() const { return (rep == UStringRep::string_rep_null); } bool isNull() const { return (rep == UStringRep::string_rep_null); }
bool isNullTerminated() const { return rep->isNullTerminated(); } bool isNullTerminated() const { return rep->isNullTerminated(); }
bool isXMacAddr() const { return rep->isXMacAddr(); }
bool isText(uint32_t pos = 0) const { return rep->isText(pos); } bool isText(uint32_t pos = 0) const { return rep->isText(pos); }
bool isUTF8(uint32_t pos = 0) const { return rep->isUTF8(pos); } bool isUTF8(uint32_t pos = 0) const { return rep->isUTF8(pos); }
bool isUTF16(uint32_t pos = 0) const { return rep->isUTF16(pos); } bool isUTF16(uint32_t pos = 0) const { return rep->isUTF16(pos); }

View File

@ -588,12 +588,14 @@ public:
{ {
U_TRACE(0, "Url::encode(%.*S,%u,%p)", len, input, len, &buffer) U_TRACE(0, "Url::encode(%.*S,%u,%p)", len, input, len, &buffer)
U_ASSERT(buffer.capacity() >= len * 3) U_ASSERT(buffer.capacity() >= len * 2)
U_INTERNAL_ASSERT_EQUALS(u_isBase64(input, len), false) U_INTERNAL_ASSERT_EQUALS(u_isBase64(input, len), false)
buffer.rep->_length = u_url_encode((const unsigned char*)input, len, (unsigned char*)buffer.data()); buffer.rep->_length = u_url_encode((const unsigned char*)input, len, (unsigned char*)buffer.data());
U_INTERNAL_DUMP("buffer(%u) = %#V", buffer.size(), buffer.rep) U_INTERNAL_DUMP("buffer(%u) = %#V", buffer.size(), buffer.rep)
U_INTERNAL_ASSERT(buffer.invariant())
} }
static void encode(const UString& input, UString& buffer) { encode(input.data(), input.size(), buffer); } static void encode(const UString& input, UString& buffer) { encode(input.data(), input.size(), buffer); }
@ -602,12 +604,14 @@ public:
{ {
U_TRACE(0, "Url::encode_add(%.*S,%u,%p)", len, input, len, &buffer) U_TRACE(0, "Url::encode_add(%.*S,%u,%p)", len, input, len, &buffer)
U_ASSERT(buffer.space() >= len * 3) U_ASSERT(buffer.space() >= (len * 2))
U_INTERNAL_ASSERT_EQUALS(u_isBase64(input, len), false) U_INTERNAL_ASSERT_EQUALS(u_isBase64(input, len), false)
buffer.rep->_length += u_url_encode((const unsigned char*)input, len, (unsigned char*)buffer.pend()); buffer.rep->_length += u_url_encode((const unsigned char*)input, len, (unsigned char*)buffer.pend());
U_INTERNAL_DUMP("buffer(%u) = %#V", buffer.size(), buffer.rep) U_INTERNAL_DUMP("buffer(%u) = %#V", buffer.size(), buffer.rep)
U_INTERNAL_ASSERT(buffer.invariant())
} }
static void encode_add(const UString& input, UString& buffer) { encode_add(input.data(), input.size(), buffer); } static void encode_add(const UString& input, UString& buffer) { encode_add(input.data(), input.size(), buffer); }
@ -629,6 +633,8 @@ public:
buffer.rep->_length = u_url_decode(input, len, (unsigned char*)buffer.data()); buffer.rep->_length = u_url_decode(input, len, (unsigned char*)buffer.data());
U_INTERNAL_DUMP("buffer(%u) = %#V", buffer.size(), buffer.rep) U_INTERNAL_DUMP("buffer(%u) = %#V", buffer.size(), buffer.rep)
U_INTERNAL_ASSERT(buffer.invariant())
} }
static void decode(const UString& input, UString& buffer) { decode(U_STRING_TO_PARAM(input), buffer); } static void decode(const UString& input, UString& buffer) { decode(U_STRING_TO_PARAM(input), buffer); }

View File

@ -64,10 +64,11 @@ public:
static bool getARPCache(UString& cache, UVector<UString>& vec); static bool getARPCache(UString& cache, UVector<UString>& vec);
static UString getNetworkDevice(const char* exclude); // eth0 static UString getNetworkDevice(const char* exclude = "eth0");
static UString getIPAddress(int fd, const char* device); // eth0 static UString getIPAddress(int fd, const char* device = "eth0");
static UString getMacAddress(int fd, const char* device); // eth0 static UString getMacAddress(int fd, const char* device = "eth0");
static UString getNetworkAddress(int fd, const char* device); // eth0 static UString getMacAddress(USocket* s, const char* device = "eth0");
static UString getNetworkAddress(int fd, const char* device = "eth0");
static UString getMacAddress( const char* ip, uint32_t ip_len); static UString getMacAddress( const char* ip, uint32_t ip_len);
static UString getNetworkInterfaceName(const char* ip, uint32_t ip_len); static UString getNetworkInterfaceName(const char* ip, uint32_t ip_len);

View File

@ -463,6 +463,27 @@ public:
setDynamicResponse(); setDynamicResponse();
} }
static uint32_t setUrl(char* buffer, uint32_t sz)
{
U_TRACE(0, "UHTTP::setUrl(%p,%u)", buffer, sz)
uint32_t len = 7+U_http_host_len+U_HTTP_URI_QUERY_LEN;
if (sz > len)
{
u_put_unalignedp64(buffer, U_MULTICHAR_CONSTANT64('h','t','t','p',':','/','/','\0'));
buffer += 7;
u__memcpy(buffer, u_clientimage_info.http_info.host, U_http_host_len, __PRETTY_FUNCTION__);
u__memcpy(buffer+U_http_host_len, u_clientimage_info.http_info.uri, U_HTTP_URI_QUERY_LEN, __PRETTY_FUNCTION__);
U_RETURN(len);
}
U_RETURN(0);
}
static void setDynamicResponse(); static void setDynamicResponse();
static void setResponse(const UString& content_type, UString* pbody = U_NULLPTR); static void setResponse(const UString& content_type, UString* pbody = U_NULLPTR);
static void setRedirectResponse(int mode, const char* ptr_location, uint32_t len_location); static void setRedirectResponse(int mode, const char* ptr_location, uint32_t len_location);

View File

@ -212,7 +212,7 @@ static inline char* u_itoa(uint32_t u, char* restrict p, uint32_t d, uint32_t n)
static char* num2str32(uint32_t u, char* restrict p) static char* num2str32(uint32_t u, char* restrict p)
{ {
uint32_t d, n; uint32_t n, d = 0;
U_INTERNAL_TRACE("num2str32(%u,%p)", u, p) U_INTERNAL_TRACE("num2str32(%u,%p)", u, p)
@ -773,6 +773,25 @@ void u_init_ulib(char** restrict argv)
U_DEBUG("u_flag_sse = %u", u_flag_sse) U_DEBUG("u_flag_sse = %u", u_flag_sse)
} }
__pure uint32_t u_isDayOfWeek(const char* restrict str)
{
uint32_t i;
U_INTERNAL_TRACE("u_isDayOfWeek(%.4s)", str)
for (i = 0; i < 7; ++i)
{
if (u_get_unalignedp32(str) == U_MULTICHAR_CONSTANT32(u_day_name[i][0],
u_day_name[i][1],
u_day_name[i][2],' '))
{
return i;
}
}
return U_NOT_FOUND;
}
/** /**
* Places characters into the array pointed to by s as controlled by the string * Places characters into the array pointed to by s as controlled by the string
* pointed to by format. If the total number of resulting characters including * pointed to by format. If the total number of resulting characters including

View File

@ -3445,6 +3445,20 @@ __pure bool u_isMacAddr(const char* restrict p, uint32_t len)
return false; return false;
} }
__pure bool u_isXMacAddr(const char* restrict s, uint32_t n)
{
U_INTERNAL_TRACE("u_isXMacAddr(%.*s,%u)", U_min(n,128), s, n)
if (n == 12)
{
U_LOOP_STRING( if (u__isxdigit(c) == false) return false )
return true;
}
return false;
}
/************************************************************************ /************************************************************************
* From rfc2044: encoding of the Unicode values on UTF-8: * * From rfc2044: encoding of the Unicode values on UTF-8: *
* * * *

View File

@ -297,9 +297,10 @@ time_t UTimeDate::getSecondFromDate(const char* str, bool gmt, struct tm* tm, co
if ((tm->tm_mon = u_getMonth(str))) if ((tm->tm_mon = u_getMonth(str)))
{ {
/** /**
* Jan 25 11:54:00 2005 GMT * Jan 25 11:54:00 2005 GMT
* | | | | | | * | | | | | |
* 0 4 7 10 13 16 * 0 4 7 10 13 16
*
*/ */
str += 4; str += 4;
@ -320,7 +321,37 @@ time_t UTimeDate::getSecondFromDate(const char* str, bool gmt, struct tm* tm, co
tm->tm_year = u__strtoul(str, 4); tm->tm_year = u__strtoul(str, 4);
} }
else else if (u_isDayOfWeek(str) != U_NOT_FOUND)
{
/**
* Fri May 4 08:09:15 2018
* | | | | | | |
* 0 4 8 11 14 17 20
*/
str += 4;
tm->tm_mon = u_getMonth(str);
str += 4;
tm->tm_mday = u_strtoulp(&str);
tm->tm_hour = u__strtoul(str, 2);
str += 3;
tm->tm_min = u__strtoul(str, 2);
str += 3;
tm->tm_sec = u__strtoul(str, 2);
str += 3;
tm->tm_year = u__strtoul(str, 4);
}
else if (str[12] == 'Z')
{ {
/** /**
* 100212124550Z (zulu time) * 100212124550Z (zulu time)
@ -351,8 +382,10 @@ time_t UTimeDate::getSecondFromDate(const char* str, bool gmt, struct tm* tm, co
str += 2; str += 2;
tm->tm_sec = u__strtoul(str, 2); tm->tm_sec = u__strtoul(str, 2);
}
// U_INTERNAL_ASSERT_EQUALS(str[2], 'Z') else
{
U_RETURN(0);
} }
} }

View File

@ -477,15 +477,6 @@ U_NO_EXPORT void URDB::copy1(URDB* prdb, uint32_t _offset) // entry present on c
uint32_t size_key = RDB_cache_node(n, key.dsize), uint32_t size_key = RDB_cache_node(n, key.dsize),
size_data = RDB_cache_node(n,data.dsize); size_data = RDB_cache_node(n,data.dsize);
union uucdb_record_header {
uint32_t* p;
UCDB::cdb_record_header* prec;
};
union uucdb_record_header u = { &size_key };
U_INTERNAL_DUMP("prec = { %u, %u }", u.prec->klen, u.prec->dlen)
const char* ptr_key = (const char*)((ptrdiff_t)RDB_cache_node(n, key.dptr) + (ptrdiff_t)journal.map); const char* ptr_key = (const char*)((ptrdiff_t)RDB_cache_node(n, key.dptr) + (ptrdiff_t)journal.map);
prdb->UCDB::data.dsize = size_data; prdb->UCDB::data.dsize = size_data;
@ -515,10 +506,11 @@ U_NO_EXPORT void URDB::copy1(URDB* prdb, uint32_t _offset) // entry present on c
char* journal_ptr = prdb->journal.map + RDB_off(prdb); char* journal_ptr = prdb->journal.map + RDB_off(prdb);
U_MEMCPY(journal_ptr, u.prec, sizeof(UCDB::cdb_record_header));
// i == 0 // i == 0
u_put_unalignedp32(journal_ptr, size_key);
u_put_unalignedp32(journal_ptr+4, size_data);
journal_ptr += sizeof(UCDB::cdb_record_header); journal_ptr += sizeof(UCDB::cdb_record_header);
U_MEMCPY(journal_ptr, ptr_key, size_key); U_MEMCPY(journal_ptr, ptr_key, size_key);

View File

@ -601,7 +601,7 @@ void ULog::log(const struct iovec* iov, const char* type, int ncount, const char
U_INTERNAL_ASSERT_MAJOR(ncount, 0) U_INTERNAL_ASSERT_MAJOR(ncount, 0)
char buffer1[2000], buffer2[8192]; char buffer1[8192], buffer2[8192];
const char* ptr = (const char*)iov[2].iov_base; const char* ptr = (const char*)iov[2].iov_base;
uint32_t len, u_printf_string_max_length_save = u_printf_string_max_length, uint32_t len, u_printf_string_max_length_save = u_printf_string_max_length,
sz = iov[2].iov_len, sz1 = iov[0].iov_len + iov[1].iov_len, sz_header = sz1 + sz; sz = iov[2].iov_len, sz1 = iov[0].iov_len + iov[1].iov_len, sz_header = sz1 + sz;

View File

@ -1390,7 +1390,7 @@ void UNoCatPlugIn::setNewPeer()
{ {
U_INTERNAL_ASSERT(peer->ifname.isNullTerminated()) U_INTERNAL_ASSERT(peer->ifname.isNullTerminated())
UString mac = UServer_Base::csocket->getMacAddress(peer->ifname.data()); UString mac = USocketExt::getMacAddress(UServer_Base::csocket, peer->ifname.data());
if (mac) peer->mac = mac; if (mac) peer->mac = mac;
else else
@ -1464,7 +1464,7 @@ void UNoCatPlugIn::checkOldPeer()
if ((check_type & U_CHECK_MAC) != 0) // not unifi (L2) if ((check_type & U_CHECK_MAC) != 0) // not unifi (L2)
{ {
mac = UServer_Base::csocket->getMacAddress(peer->ifname.data()); mac = USocketExt::getMacAddress(UServer_Base::csocket, peer->ifname.data());
if (mac.empty()) return; if (mac.empty()) return;

View File

@ -33,6 +33,7 @@
U_CREAT_FUNC(server_plugin_nodog, UNoDogPlugIn) U_CREAT_FUNC(server_plugin_nodog, UNoDogPlugIn)
int UNoDogPlugIn::fd_stderr; int UNoDogPlugIn::fd_stderr;
bool UNoDogPlugIn::bdifferent;
bool UNoDogPlugIn::bnetwork_interface; bool UNoDogPlugIn::bnetwork_interface;
bool UNoDogPlugIn::mac_from_dhcp_data_file; bool UNoDogPlugIn::mac_from_dhcp_data_file;
void* UNoDogPlugIn::pdata; void* UNoDogPlugIn::pdata;
@ -45,14 +46,17 @@ UString* UNoDogPlugIn::fw_env;
UString* UNoDogPlugIn::fw_cmd; UString* UNoDogPlugIn::fw_cmd;
UString* UNoDogPlugIn::extdev; UString* UNoDogPlugIn::extdev;
UString* UNoDogPlugIn::intdev; UString* UNoDogPlugIn::intdev;
UString* UNoDogPlugIn::info_data; UString* UNoDogPlugIn::mac_old;
UString* UNoDogPlugIn::arp_cache; UString* UNoDogPlugIn::label_old;
UString* UNoDogPlugIn::hostname; UString* UNoDogPlugIn::hostname;
UString* UNoDogPlugIn::localnet; UString* UNoDogPlugIn::localnet;
UString* UNoDogPlugIn::info_data;
UString* UNoDogPlugIn::arp_cache;
UString* UNoDogPlugIn::allowed_members; UString* UNoDogPlugIn::allowed_members;
UString* UNoDogPlugIn::IP_address_trust; UString* UNoDogPlugIn::IP_address_trust;
UString* UNoDogPlugIn::auth_host; UString* UNoDogPlugIn::auth_host;
UString* UNoDogPlugIn::auth_deny;
UString* UNoDogPlugIn::auth_info; UString* UNoDogPlugIn::auth_info;
UString* UNoDogPlugIn::auth_login; UString* UNoDogPlugIn::auth_login;
UString* UNoDogPlugIn::auth_notify; UString* UNoDogPlugIn::auth_notify;
@ -84,6 +88,8 @@ UNoDogPlugIn::UNoDogPlugIn() : UEventTime(300L,0L)
U_NEW_STRING(fw_env, UString); U_NEW_STRING(fw_env, UString);
U_NEW_STRING(extdev, UString); U_NEW_STRING(extdev, UString);
U_NEW_STRING(intdev, UString); U_NEW_STRING(intdev, UString);
U_NEW_STRING(mac_old, UString);
U_NEW_STRING(label_old, UString);
U_NEW_STRING(hostname, UString); U_NEW_STRING(hostname, UString);
U_NEW_STRING(localnet, UString); U_NEW_STRING(localnet, UString);
U_NEW_STRING(info_data, UString); U_NEW_STRING(info_data, UString);
@ -92,6 +98,7 @@ UNoDogPlugIn::UNoDogPlugIn() : UEventTime(300L,0L)
U_NEW_STRING(IP_address_trust, UString); U_NEW_STRING(IP_address_trust, UString);
U_NEW_STRING(auth_host, UString); U_NEW_STRING(auth_host, UString);
U_NEW_STRING(auth_deny, UString);
U_NEW_STRING(auth_info, UString); U_NEW_STRING(auth_info, UString);
U_NEW_STRING(auth_login, UString); U_NEW_STRING(auth_login, UString);
U_NEW_STRING(auth_notify, UString); U_NEW_STRING(auth_notify, UString);
@ -123,21 +130,22 @@ UNoDogPlugIn::~UNoDogPlugIn()
U_DELETE(fw_env) U_DELETE(fw_env)
U_DELETE(extdev) U_DELETE(extdev)
U_DELETE(intdev) U_DELETE(intdev)
U_DELETE(mac_old)
U_DELETE(label_old)
U_DELETE(hostname) U_DELETE(hostname)
U_DELETE(localnet) U_DELETE(localnet)
U_DELETE(info_data) U_DELETE(info_data)
U_DELETE(arp_cache)
U_DELETE(allowed_members) U_DELETE(allowed_members)
U_DELETE(IP_address_trust) U_DELETE(IP_address_trust)
U_DELETE(auth_host) U_DELETE(auth_host)
U_DELETE(auth_deny)
U_DELETE(auth_info) U_DELETE(auth_info)
U_DELETE(auth_login) U_DELETE(auth_login)
U_DELETE(auth_notify) U_DELETE(auth_notify)
U_DELETE(auth_service) U_DELETE(auth_service)
U_DELETE(auth_strict_notify) U_DELETE(auth_strict_notify)
U_DELETE(varp_cache)
U_DELETE(vInternalDevice) U_DELETE(vInternalDevice)
U_DELETE(vLocalNetworkSpec) U_DELETE(vLocalNetworkSpec)
U_DELETE(vLocalNetworkLabel) U_DELETE(vLocalNetworkLabel)
@ -148,6 +156,9 @@ UNoDogPlugIn::~UNoDogPlugIn()
if (ipt) U_DELETE(ipt) if (ipt) U_DELETE(ipt)
if (peers) U_DELETE(peers) if (peers) U_DELETE(peers)
U_DELETE(varp_cache)
U_DELETE( arp_cache) // NB: must be here to avoid DEAD OF SOURCE STRING WITH CHILD ALIVE...
#ifdef USE_LIBTDB #ifdef USE_LIBTDB
if (pdata) U_DELETE((UTDB*)pdata) if (pdata) U_DELETE((UTDB*)pdata)
#endif #endif
@ -159,7 +170,7 @@ int UModNoDogPeer::handlerTime()
UNoDogPlugIn::peer = this; UNoDogPlugIn::peer = this;
if (U_peer_permit == false) UNoDogPlugIn::permit(); if (U_peer_permit == false) UNoDogPlugIn::permit(U_peer_mac_from_dhcp_data_file ? *UString::str_without_mac : UNoDogPlugIn::peer->mac);
U_RETURN(-1); // normal U_RETURN(-1); // normal
} }
@ -246,7 +257,7 @@ U_NO_EXPORT void UNoDogPlugIn::makeInfoData(UFlatBuffer* pfb, void* param)
// $6 -> time_no_traffic // $6 -> time_no_traffic
// ----------------------------------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------------------------------
peer->getMAC(buffer); u_getXMAC(peer->mac.data(), buffer);
pfb->String(buffer, 12); pfb->String(buffer, 12);
pfb->UInt(ntohl(peer->addr)); pfb->UInt(ntohl(peer->addr));
@ -291,31 +302,6 @@ U_NO_EXPORT void UNoDogPlugIn::makeInfoData(UFlatBuffer* pfb, void* param)
} }
} }
U_NO_EXPORT void UNoDogPlugIn::makeNotifyData(UFlatBuffer* pfb, void* param)
{
U_TRACE(0, "UNoDogPlugIn::makeNotifyData(%p,%p)", pfb, param)
U_INTERNAL_DUMP("peer->mac = %V peer->ip = %V peer->label = %V", peer->mac.rep, peer->ip.rep, peer->label.rep)
char buffer[256];
pfb->String(buffer, getApInfo(buffer, sizeof(buffer), peer->label));
peer->getMAC(buffer);
pfb->String(buffer, 12);
pfb->String(peer->ip);
}
U_NO_EXPORT void UNoDogPlugIn::makeLoginData(UFlatBuffer* pfb, void* param)
{
U_TRACE(0, "UNoDogPlugIn::makeLoginData(%p,%p)", pfb, param)
makeNotifyData(pfb, param);
pfb->UInt(U_PTR2INT(peer));
}
int UNoDogPlugIn::handlerTime() int UNoDogPlugIn::handlerTime()
{ {
U_TRACE_NO_PARAM(0, "UNoDogPlugIn::handlerTime()") U_TRACE_NO_PARAM(0, "UNoDogPlugIn::handlerTime()")
@ -345,25 +331,25 @@ int UNoDogPlugIn::handlerTime()
U_RETURN(0); // monitoring U_RETURN(0); // monitoring
} }
void UNoDogPlugIn::executeCommand(const char* type, uint32_t len) void UNoDogPlugIn::executeCommand(const char* type, uint32_t len, const UString& mac)
{ {
U_TRACE(0, "UNoDogPlugIn::executeCommand(%.*S,%u)", len, type, len) U_TRACE(0, "UNoDogPlugIn::executeCommand(%.*S,%u,%V)", len, type, len, mac.rep)
U_INTERNAL_ASSERT_POINTER(peer) U_INTERNAL_ASSERT_POINTER(peer)
U_INTERNAL_ASSERT(u_isMacAddr(U_STRING_TO_PARAM(mac)))
char buffer[256]; char buffer[256];
// NB: request(arp|deny|clear|reset|permit|openlist|initialize) mac ip class(Owner|Member|Public) UserDownloadRate UserUploadRate // NB: request(arp|deny|clear|reset|permit|openlist|initialize) mac ip class(Owner|Member|Public) UserDownloadRate UserUploadRate
UCommand cmd(buffer, u__snprintf(buffer, sizeof(buffer), U_CONSTANT_TO_PARAM("/bin/sh %v %.*s %v %v Member 0 0"), UCommand cmd(buffer, u__snprintf(buffer, sizeof(buffer), U_CONSTANT_TO_PARAM("/bin/sh %v %.*s %v %v Member 0 0"), fw_cmd->rep, len, type, mac.rep, peer->ip.rep), fw_env);
fw_cmd->rep, len, type, (U_peer_mac_from_dhcp_data_file ? *UString::str_without_mac : peer->mac).rep, peer->ip.rep), fw_env);
(void) cmd.executeAndWait(U_NULLPTR, -1, fd_stderr); (void) cmd.executeAndWait(U_NULLPTR, -1, fd_stderr);
U_SRV_LOG_CMD_MSG_ERR(cmd, false); U_SRV_LOG_CMD_MSG_ERR(cmd, false);
} }
U_NO_EXPORT void UNoDogPlugIn::setMAC() U_NO_EXPORT bool UNoDogPlugIn::setMAC()
{ {
U_TRACE_NO_PARAM(0, "UNoDogPlugIn::setMAC()") U_TRACE_NO_PARAM(0, "UNoDogPlugIn::setMAC()")
@ -384,7 +370,7 @@ U_NO_EXPORT void UNoDogPlugIn::setMAC()
U_INTERNAL_ASSERT(ifname.isNullTerminated()) U_INTERNAL_ASSERT(ifname.isNullTerminated())
peer->mac = UServer_Base::csocket->getMacAddress(ifname.data()); peer->mac = USocketExt::getMacAddress(UServer_Base::csocket, ifname.data());
if (peer->mac.empty()) if (peer->mac.empty())
{ {
@ -405,19 +391,31 @@ U_NO_EXPORT void UNoDogPlugIn::setMAC()
U_INTERNAL_DUMP("peer->mac = %V", peer->mac.rep) U_INTERNAL_DUMP("peer->mac = %V", peer->mac.rep)
if (peer->mac.empty())
{
peer->mac = *UString::str_without_mac;
U_RETURN(false);
}
U_INTERNAL_ASSERT(peer->mac) U_INTERNAL_ASSERT(peer->mac)
U_INTERNAL_ASSERT(u_isMacAddr(U_STRING_TO_PARAM(peer->mac))) U_INTERNAL_ASSERT(u_isMacAddr(U_STRING_TO_PARAM(peer->mac)))
U_ASSERT_EQUALS(peer->mac, USocketExt::getMacAddress(peer->ip)) U_ASSERT_EQUALS(peer->mac, USocketExt::getMacAddress(peer->ip))
} }
U_RETURN(true);
} }
U_NO_EXPORT void UNoDogPlugIn::setLabelAndMAC() U_NO_EXPORT bool UNoDogPlugIn::setLabelAndMAC()
{ {
U_TRACE_NO_PARAM(0, "UNoDogPlugIn::setLabelAndMAC()") U_TRACE_NO_PARAM(0, "UNoDogPlugIn::setLabelAndMAC()")
U_INTERNAL_DUMP("pdata = %p mac_from_dhcp_data_file = %b peer->label = %V", pdata, mac_from_dhcp_data_file, peer->label.rep) U_INTERNAL_DUMP("pdata = %p mac_from_dhcp_data_file = %b peer->label = %V", pdata, mac_from_dhcp_data_file, peer->label.rep)
if (pdata == U_NULLPTR) setMAC(); if (pdata == U_NULLPTR)
{
if (setMAC() == false) U_RETURN(false);
}
#ifdef USE_LIBTDB #ifdef USE_LIBTDB
else else
{ {
@ -441,7 +439,7 @@ U_NO_EXPORT void UNoDogPlugIn::setLabelAndMAC()
{ {
uint32_t t5, t6; uint32_t t5, t6;
setMAC(); if (setMAC() == false) U_RETURN(false);
if (U_SYSCALL(sscanf, "%p,%S,%p,%p,%p,%p,%p,%p", peer->mac.data(), "%x:%x:%x:%x:%x:%x", &t1, &t2, &t3, &t4, &t5, &t6) == 6) if (U_SYSCALL(sscanf, "%p,%S,%p,%p,%p,%p,%p,%p", peer->mac.data(), "%x:%x:%x:%x:%x:%x", &t1, &t2, &t3, &t4, &t5, &t6) == 6)
{ {
@ -483,18 +481,29 @@ U_NO_EXPORT void UNoDogPlugIn::setLabelAndMAC()
mac.snprintf(U_CONSTANT_TO_PARAM("%02x:%02x:%02x:%02x:%02x:%02x"), bytep[0], bytep[1], bytep[2], bytep[3], bytep[4], bytep[5]); mac.snprintf(U_CONSTANT_TO_PARAM("%02x:%02x:%02x:%02x:%02x:%02x"), bytep[0], bytep[1], bytep[2], bytep[3], bytep[4], bytep[5]);
peer->mac = mac; peer->mac = mac;
U_INTERNAL_ASSERT(u_isMacAddr(U_STRING_TO_PARAM(mac)))
} }
U_SRV_LOG("get data from DHCP_DATA_FILE - key: %#.*S data: %#.10S peer->label = %V peer->mac = %V", sz, (const char*)&ks+start, value.data(), peer->label.rep, peer->mac.rep); U_SRV_LOG("get data from DHCP_DATA_FILE - key: %#.*S data: %#.10S peer->label = %V peer->mac = %V", sz, (const char*)&ks+start, value.data(), peer->label.rep, peer->mac.rep);
} }
} }
if (peer->mac.empty())
{
peer->mac = *UString::str_without_mac;
U_RETURN(false);
}
} }
#endif #endif
U_INTERNAL_DUMP("peer->label = %V peer->mac = %V", peer->label.rep, peer->mac.rep) U_INTERNAL_DUMP("peer->label = %V peer->mac = %V", peer->label.rep, peer->mac.rep)
U_RETURN(true);
} }
void UNoDogPlugIn::setNewPeer() bool UNoDogPlugIn::setNewPeer()
{ {
U_TRACE_NO_PARAM(0, "UNoDogPlugIn::setNewPeer()") U_TRACE_NO_PARAM(0, "UNoDogPlugIn::setNewPeer()")
@ -504,16 +513,23 @@ void UNoDogPlugIn::setNewPeer()
if (U_peer_index_network == 0xFF) if (U_peer_index_network == 0xFF)
{ {
U_ERROR("IP address for new peer %V not found in LocalNetworkMask %V", peer->ip.rep, localnet->rep); U_SRV_LOG("WARNING: IP address for new peer %V not found in LocalNetworkMask %V", peer->ip.rep, localnet->rep);
U_RETURN(false);
} }
peer->label = ((uint32_t)U_peer_index_network >= vLocalNetworkLabel->size() ? *UString::str_without_label : (*vLocalNetworkLabel)[U_peer_index_network]); peer->label = ((uint32_t)U_peer_index_network >= vLocalNetworkLabel->size() ? *UString::str_without_label : (*vLocalNetworkLabel)[U_peer_index_network]);
setLabelAndMAC(); if (setLabelAndMAC())
{
if (mac_from_dhcp_data_file) U_peer_flag |= U_PEER_MAC_FROM_DHCP_DATA_FILE;
if (mac_from_dhcp_data_file) U_peer_flag |= U_PEER_MAC_FROM_DHCP_DATA_FILE; peers->insert((const char*)&(peer->addr), sizeof(uint32_t), peer); // peers->insert(peer->ip, peer);
peers->insert((const char*)&(peer->addr), sizeof(uint32_t), peer); // peers->insert(peer->ip, peer); U_RETURN(true);
}
U_RETURN(false);
} }
U_NO_EXPORT bool UNoDogPlugIn::getPeer() U_NO_EXPORT bool UNoDogPlugIn::getPeer()
@ -577,6 +593,50 @@ U_NO_EXPORT void UNoDogPlugIn::eraseTimer()
} }
} }
U_NO_EXPORT void UNoDogPlugIn::makeNotifyData(UFlatBuffer* pfb, void* param)
{
U_TRACE(0, "UNoDogPlugIn::makeNotifyData(%p,%p)", pfb, param)
U_INTERNAL_DUMP("peer->mac = %V peer->ip = %V peer->label = %V", peer->mac.rep, peer->ip.rep, peer->label.rep)
char buffer[256];
pfb->String(buffer, getApInfo(buffer, sizeof(buffer), (bdifferent == false ? peer->label : *label_old)));
u_getXMAC(peer->mac.data(), buffer);
pfb->String(buffer, 12);
pfb->String(peer->ip);
}
U_NO_EXPORT void UNoDogPlugIn::makeLoginData(UFlatBuffer* pfb, void* param)
{
U_TRACE(0, "UNoDogPlugIn::makeLoginData(%p,%p)", pfb, param)
makeNotifyData(pfb, param);
pfb->UInt(U_PTR2INT(peer));
if (bdifferent == false)
{
pfb->StringNull();
pfb->StringNull();
}
else
{
bdifferent = false;
pfb->String(peer->label);
peer->label = *label_old;
char buffer[16];
u_getXMAC(mac_old->data(), buffer);
pfb->String(buffer, 12);
}
}
U_NO_EXPORT void UNoDogPlugIn::sendLogin() U_NO_EXPORT void UNoDogPlugIn::sendLogin()
{ {
U_TRACE_NO_PARAM(0, "UNoDogPlugIn::sendLogin()") U_TRACE_NO_PARAM(0, "UNoDogPlugIn::sendLogin()")
@ -614,53 +674,6 @@ U_NO_EXPORT void UNoDogPlugIn::sendStrictNotify()
} }
} }
U_NO_EXPORT bool UNoDogPlugIn::checkOldPeer()
{
U_TRACE_NO_PARAM(0, "UNoDogPlugIn::checkOldPeer()")
U_INTERNAL_ASSERT_POINTER(peer)
U_ASSERT(peer->ip.equal(U_CLIENT_ADDRESS_TO_PARAM))
UString mac = peer->mac,
llabel = peer->label;
peer->mac = *UString::str_without_mac;
setLabelAndMAC();
if ( mac != peer->mac ||
llabel != peer->label)
{
// NB: we assume that the current peer is a different user that has acquired the same IP address from the DHCP...
U_SRV_LOG("WARNING: different user for peer (IP %v): (MAC %v LABEL %v) => (MAC %v LABEL %v)", peer->ip.rep, mac.rep, llabel.rep, peer->mac.rep, peer->label.rep);
U_INTERNAL_ASSERT(mac)
U_INTERNAL_ASSERT(llabel)
U_INTERNAL_ASSERT(peer->mac)
U_INTERNAL_ASSERT(peer->label)
if (U_peer_permit)
{
UString x;
if (U_peer_mac_from_dhcp_data_file == false)
{
x = peer->mac;
peer->mac = mac;
}
deny();
if (U_peer_mac_from_dhcp_data_file == false) peer->mac = x;
}
U_RETURN(false);
}
U_RETURN(true);
}
// Server-wide hooks // Server-wide hooks
int UNoDogPlugIn::handlerConfig(UFileConfig& cfg) int UNoDogPlugIn::handlerConfig(UFileConfig& cfg)
@ -859,6 +872,7 @@ int UNoDogPlugIn::handlerInit()
} }
*auth_info = getUrlForSendMsgToPortal(U_CONSTANT_TO_PARAM("/info")); *auth_info = getUrlForSendMsgToPortal(U_CONSTANT_TO_PARAM("/info"));
*auth_deny = getUrlForSendMsgToPortal(U_CONSTANT_TO_PARAM("/deny"));
*auth_login = getUrlForSendMsgToPortal(U_CONSTANT_TO_PARAM("/login")); *auth_login = getUrlForSendMsgToPortal(U_CONSTANT_TO_PARAM("/login"));
*auth_notify = getUrlForSendMsgToPortal(U_CONSTANT_TO_PARAM("/notify")); *auth_notify = getUrlForSendMsgToPortal(U_CONSTANT_TO_PARAM("/notify"));
*auth_strict_notify = getUrlForSendMsgToPortal(U_CONSTANT_TO_PARAM("/strict_notify")); *auth_strict_notify = getUrlForSendMsgToPortal(U_CONSTANT_TO_PARAM("/strict_notify"));
@ -1036,15 +1050,40 @@ end:
U_peer_index_network = index_network; U_peer_index_network = index_network;
setNewPeer(); (void) setNewPeer();
permit(); permit(peer->mac);
} }
} }
U_RETURN(U_PLUGIN_HANDLER_OK); U_RETURN(U_PLUGIN_HANDLER_OK);
} }
uint32_t UNoDogPlugIn::checkUrl(char* buffer, uint32_t buffer_len, uint32_t sz, const char* user, uint32_t user_len)
{
U_TRACE(0, "UNoDogPlugIn::checkUrl(%p,%u,%u,%.*S,%u)", buffer, buffer_len, sz, user_len, user, user_len)
if (sz > (buffer_len / 3))
{
U_SRV_LOG("url request size (%u bytes) too big from %.*s USER", sz, user_len, user);
U_RETURN(0);
}
if (auth_host->equal(U_HTTP_HOST_TO_PARAM))
{
U_SRV_LOG("request url (%.*S) invalid from %.*s USER", U_HTTP_HOST_TO_TRACE, user_len, user);
U_RETURN(0);
}
sz = UHTTP::setUrl(buffer, buffer_len);
U_INTERNAL_ASSERT_MAJOR(sz, 0)
U_RETURN(sz);
}
// Connection-wide hooks // Connection-wide hooks
int UNoDogPlugIn::handlerRequest() int UNoDogPlugIn::handlerRequest()
@ -1116,7 +1155,7 @@ int UNoDogPlugIn::handlerRequest()
{ {
eraseTimer(); eraseTimer();
if (U_peer_permit) deny(); if (U_peer_permit) deny(U_peer_mac_from_dhcp_data_file ? *UString::str_without_mac : peer->mac);
erasePeer(); erasePeer();
@ -1135,7 +1174,7 @@ int UNoDogPlugIn::handlerRequest()
{ {
eraseTimer(); eraseTimer();
if (U_peer_permit == false) permit(); if (U_peer_permit == false) permit(U_peer_mac_from_dhcp_data_file ? *UString::str_without_mac : peer->mac);
goto end; goto end;
} }
@ -1183,7 +1222,7 @@ int UNoDogPlugIn::handlerRequest()
U_SRV_LOG("AUTH request to logout user(%u): IP %v MAC %v", i, peer->ip.rep, peer->mac.rep); U_SRV_LOG("AUTH request to logout user(%u): IP %v MAC %v", i, peer->ip.rep, peer->mac.rep);
if (U_peer_permit) deny(); if (U_peer_permit) deny(U_peer_mac_from_dhcp_data_file ? *UString::str_without_mac : peer->mac);
else else
{ {
eraseTimer(); eraseTimer();
@ -1194,10 +1233,7 @@ int UNoDogPlugIn::handlerRequest()
erasePeer(); erasePeer();
} }
} }
else if (U_HTTP_URI_STREQ("/ping")) else if (U_HTTP_URI_STREQ("/ping") == false)
{
}
else
{ {
bad: UHTTP::setBadRequest(); bad: UHTTP::setBadRequest();
} }
@ -1209,6 +1245,15 @@ bad: UHTTP::setBadRequest();
// printPeers(U_CONSTANT_TO_PARAM("user request")); // printPeers(U_CONSTANT_TO_PARAM("user request"));
if (U_HTTP_URI_QUERY_LEN > (sizeof(buffer) / 4))
{
U_SRV_LOG("request url query size (%u bytes) too big", U_HTTP_URI_QUERY_LEN);
goto end;
}
sz = 7+U_http_host_len+U_HTTP_URI_QUERY_LEN;
addr = UServer_Base::getClientAddress(); addr = UServer_Base::getClientAddress();
if (getPeer()) if (getPeer())
@ -1220,9 +1265,45 @@ bad: UHTTP::setBadRequest();
U_SRV_LOG("Start REQUEST_FROM_OLD_USER phase of plugin nodog: peer = %p", peer); U_SRV_LOG("Start REQUEST_FROM_OLD_USER phase of plugin nodog: peer = %p", peer);
U_INTERNAL_ASSERT(peer->mac) U_INTERNAL_ASSERT(peer->mac)
U_INTERNAL_ASSERT(peer->label)
U_ASSERT(peer->ip.equal(U_CLIENT_ADDRESS_TO_PARAM)) U_ASSERT(peer->ip.equal(U_CLIENT_ADDRESS_TO_PARAM))
U_INTERNAL_ASSERT(u_isMacAddr(U_STRING_TO_PARAM(peer->mac))) U_INTERNAL_ASSERT(u_isMacAddr(U_STRING_TO_PARAM(peer->mac)))
if (checkUrl(buffer, sizeof(buffer), sz, U_CONSTANT_TO_PARAM("OLD")) == 0) goto end;
*mac_old = peer->mac;
*label_old = peer->label;
peer->mac.clear();
if (setLabelAndMAC() == false) goto end;
if ( *mac_old != peer->mac ||
*label_old != peer->label)
{
// NB: we assume that the current peer is a different user that has acquired the same IP address from the DHCP...
U_SRV_LOG("WARNING: different user for peer (IP %v): (MAC %v LABEL %v) => (MAC %v LABEL %v)", peer->ip.rep, mac_old->rep, label_old->rep, peer->mac.rep, peer->label.rep);
U_INTERNAL_ASSERT(peer->mac)
U_INTERNAL_ASSERT(peer->label)
if (peer->mac != *mac_old)
{
bdifferent = true;
if (U_peer_permit &&
U_peer_mac_from_dhcp_data_file == false)
{
deny(*mac_old);
}
goto log;
}
goto welcome;
}
if (U_HTTP_URI_MEMEQ("/nodog_peer_allow.sh")) if (U_HTTP_URI_MEMEQ("/nodog_peer_allow.sh"))
{ {
if (U_HTTP_QUERY_MEMEQ("url=") && if (U_HTTP_QUERY_MEMEQ("url=") &&
@ -1252,7 +1333,7 @@ bad: UHTTP::setBadRequest();
{ {
sendStrictNotify(); sendStrictNotify();
goto next1; goto next;
} }
U_INTERNAL_DUMP("T2 = %u U_peer_policy = %C", T2, U_peer_policy) U_INTERNAL_DUMP("T2 = %u U_peer_policy = %C", T2, U_peer_policy)
@ -1262,9 +1343,9 @@ bad: UHTTP::setBadRequest();
{ {
sendNotify(); sendNotify();
next1: eraseTimer(); next: eraseTimer();
if (U_peer_permit == false) permit(); if (U_peer_permit == false) permit(U_peer_mac_from_dhcp_data_file ? *UString::str_without_mac : peer->mac);
UHTTP::setRedirectResponse(UHTTP::NO_BODY, U_STRING_TO_PARAM(redirect)); UHTTP::setRedirectResponse(UHTTP::NO_BODY, U_STRING_TO_PARAM(redirect));
} }
@ -1297,10 +1378,6 @@ next1: eraseTimer();
goto end; goto end;
} }
sz = setRedirect(buffer, sizeof(buffer));
if (checkOldPeer() == false) goto log;
goto welcome; goto welcome;
} }
@ -1308,6 +1385,16 @@ next1: eraseTimer();
// request from NEW user // request from NEW user
// --------------------- // ---------------------
if (U_HTTP_URI_MEMEQ("/nodog_peer_allow.sh") ||
U_HTTP_URI_MEMEQ("/nodog_peer_delay.sh"))
{
U_SRV_LOG("/nodog_peer_(allow|delay).sh from NEW USER: %.*s", U_CLIENT_ADDRESS_TO_PARAM);
goto end;
}
if (checkUrl(buffer, sizeof(buffer), sz, U_CONSTANT_TO_PARAM("NEW")) == 0) goto end;
index_network = UIPAllow::find(UServer_Base::client_address, *vLocalNetworkMask); index_network = UIPAllow::find(UServer_Base::client_address, *vLocalNetworkMask);
U_INTERNAL_DUMP("index_network = %u", index_network) U_INTERNAL_DUMP("index_network = %u", index_network)
@ -1332,9 +1419,12 @@ next1: eraseTimer();
U_ASSERT_EQUALS(peer->ip, UIPAddress::toString(peer->addr)) U_ASSERT_EQUALS(peer->ip, UIPAddress::toString(peer->addr))
setNewPeer(); if (setNewPeer() == false)
{
U_DELETE(peer)
sz = setRedirect(buffer, sizeof(buffer)); goto end;
}
log: sendLogin(); log: sendLogin();
@ -1342,7 +1432,7 @@ log: sendLogin();
if (T1 == 0) if (T1 == 0)
{ {
permit(); permit(U_peer_mac_from_dhcp_data_file ? *UString::str_without_mac : peer->mac);
UHTTP::setRedirectResponse(UHTTP::NO_BODY, buffer, sz); UHTTP::setRedirectResponse(UHTTP::NO_BODY, buffer, sz);
} }
@ -1363,7 +1453,7 @@ welcome: x = UString::getUBuffer();
Url::encode_add(buffer, sz, x); Url::encode_add(buffer, sz, x);
peer->getMAC(buffer); u_getXMAC(peer->mac.data(), buffer);
x.snprintf_add(U_CONSTANT_TO_PARAM("&mac=%.12s&apid=%v&gateway=%v%%3A%u"), x.snprintf_add(U_CONSTANT_TO_PARAM("&mac=%.12s&apid=%v&gateway=%v%%3A%u"),
buffer, peer->label.rep, (bnetwork_interface ? pallow->host : *UServer_Base::IP_address).rep, UServer_Base::port); buffer, peer->label.rep, (bnetwork_interface ? pallow->host : *UServer_Base::IP_address).rep, UServer_Base::port);

View File

@ -32,13 +32,6 @@ U_DUMP_KERNEL_VERSION(LINUX_VERSION_CODE)
# include <ulib/ssl/net/sslsocket.h> # include <ulib/ssl/net/sslsocket.h>
#endif #endif
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <net/if_arp.h>
#endif
int USocket::incoming_cpu = -1; int USocket::incoming_cpu = -1;
int USocket::iBackLog = SOMAXCONN; int USocket::iBackLog = SOMAXCONN;
int USocket::accept4_flags; // If flags is 0, then accept4() is the same as accept() int USocket::accept4_flags; // If flags is 0, then accept4() is the same as accept()
@ -215,78 +208,6 @@ void USocket::setLocal()
} }
} }
UString USocket::getMacAddress(const char* device)
{
U_TRACE(1, "USocket::getMacAddress(%S)", device)
U_INTERNAL_ASSERT_POINTER(device)
UString result(100U);
#if defined(U_LINUX) && defined(HAVE_SYS_IOCTL_H) && defined(HAVE_ARPA_INET_H)
U_INTERNAL_ASSERT(isOpen())
/**
* ARP ioctl request
*
* struct arpreq {
* struct sockaddr arp_pa; // Protocol address
* struct sockaddr arp_ha; // Hardware address
* int arp_flags; // Flags
* struct sockaddr arp_netmask; // Netmask (only for proxy arps)
* char arp_dev[16];
* };
*/
struct arpreq arpreq;
(void) U_SYSCALL(memset, "%p,%d,%u", &arpreq, 0, sizeof(arpreq));
union uupsockaddr {
struct sockaddr* p;
struct sockaddr_in* psin;
};
union uupsockaddr u = { &arpreq.arp_pa };
// arp_pa must be an AF_INET address
// arp_ha must have the same type as the device which is specified in arp_dev
// arp_dev is a zero-terminated string which names a device
u.psin->sin_family = AF_INET;
u.psin->sin_addr.s_addr = cRemoteAddress.getInAddr();
arpreq.arp_ha.sa_family = AF_INET;
(void) u__strncpy(arpreq.arp_dev, device, 15);
if (U_SYSCALL(ioctl, "%d,%d,%p", iSockDesc, SIOCGARP, &arpreq) == 0)
{
if ((arpreq.arp_flags & ATF_COM) != 0)
{
unsigned char* hwaddr = (unsigned char*)arpreq.arp_ha.sa_data;
result.snprintf(U_CONSTANT_TO_PARAM("%02x:%02x:%02x:%02x:%02x:%02x"),
hwaddr[0] & 0xFF,
hwaddr[1] & 0xFF,
hwaddr[2] & 0xFF,
hwaddr[3] & 0xFF,
hwaddr[4] & 0xFF,
hwaddr[5] & 0xFF);
/**
* if (arpreq.arp_flags & ATF_PERM) printf("PERM");
* if (arpreq.arp_flags & ATF_PUBL) printf("PUBLISHED");
* if (arpreq.arp_flags & ATF_USETRAILERS) printf("TRAILERS");
* if (arpreq.arp_flags & ATF_PROXY) printf("PROXY");
*/
}
// else printf("*** INCOMPLETE ***");
}
#endif
U_RETURN_STRING(result);
}
/** /**
* The method is called with a local IP address and port number to bind the socket to. * The method is called with a local IP address and port number to bind the socket to.
* A default port number of zero is a wildcard and lets the OS choose the port number * A default port number of zero is a wildcard and lets the OS choose the port number

View File

@ -36,6 +36,9 @@
#ifdef HAVE_SYS_IOCTL_H #ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h> # include <sys/ioctl.h>
#endif #endif
#ifdef HAVE_ARPA_INET_H
# include <net/if_arp.h>
#endif
#ifdef USE_C_ARES #ifdef USE_C_ARES
# include <ares.h> # include <ares.h>
@ -513,7 +516,7 @@ loop:
for (int i = 0; i < iovcnt; ++i) sum += iov[i].iov_len; for (int i = 0; i < iovcnt; ++i) sum += iov[i].iov_len;
U_INTERNAL_ASSERT_EQUALS(sum, count) U_INTERNAL_ASSERT_EQUALS(sum, count-byte_written)
#endif #endif
/* /*
@ -1074,6 +1077,82 @@ UString USocketExt::getMacAddress(int fd, const char* device)
hwaddr[3] & 0xFF, hwaddr[3] & 0xFF,
hwaddr[4] & 0xFF, hwaddr[4] & 0xFF,
hwaddr[5] & 0xFF); hwaddr[5] & 0xFF);
U_INTERNAL_ASSERT(u_isMacAddr(U_STRING_TO_PARAM(result)))
}
#endif
U_RETURN_STRING(result);
}
UString USocketExt::getMacAddress(USocket* socket, const char* device)
{
U_TRACE(1, "USocketExt::getMacAddress(%p,%S)", socket, device)
U_INTERNAL_ASSERT_POINTER(device)
UString result(100U);
#if defined(U_LINUX) && defined(HAVE_SYS_IOCTL_H) && defined(HAVE_ARPA_INET_H)
U_INTERNAL_ASSERT(socket->isOpen())
/**
* ARP ioctl request
*
* struct arpreq {
* struct sockaddr arp_pa; // Protocol address
* struct sockaddr arp_ha; // Hardware address
* int arp_flags; // Flags
* struct sockaddr arp_netmask; // Netmask (only for proxy arps)
* char arp_dev[16];
* };
*/
struct arpreq arpreq;
(void) U_SYSCALL(memset, "%p,%d,%u", &arpreq, 0, sizeof(arpreq));
union uupsockaddr {
struct sockaddr* p;
struct sockaddr_in* psin;
};
union uupsockaddr u = { &arpreq.arp_pa };
// arp_pa must be an AF_INET address
// arp_ha must have the same type as the device which is specified in arp_dev
// arp_dev is a zero-terminated string which names a device
u.psin->sin_family = AF_INET;
u.psin->sin_addr.s_addr = socket->getClientAddress();
arpreq.arp_ha.sa_family = AF_INET;
(void) u__strncpy(arpreq.arp_dev, device, 15);
if (U_SYSCALL(ioctl, "%d,%d,%p", socket->iSockDesc, SIOCGARP, &arpreq) == 0)
{
if ((arpreq.arp_flags & ATF_COM) != 0)
{
unsigned char* hwaddr = (unsigned char*)arpreq.arp_ha.sa_data;
result.snprintf(U_CONSTANT_TO_PARAM("%02x:%02x:%02x:%02x:%02x:%02x"),
hwaddr[0] & 0xFF,
hwaddr[1] & 0xFF,
hwaddr[2] & 0xFF,
hwaddr[3] & 0xFF,
hwaddr[4] & 0xFF,
hwaddr[5] & 0xFF);
U_INTERNAL_ASSERT(u_isMacAddr(U_STRING_TO_PARAM(result)))
/**
* if (arpreq.arp_flags & ATF_PERM) printf("PERM");
* if (arpreq.arp_flags & ATF_PUBL) printf("PUBLISHED");
* if (arpreq.arp_flags & ATF_USETRAILERS) printf("TRAILERS");
* if (arpreq.arp_flags & ATF_PROXY) printf("PROXY");
*/
}
// else printf("*** INCOMPLETE ***");
} }
#endif #endif

View File

@ -6957,6 +6957,7 @@ void UHTTP::setRedirectResponse(int mode, const char* ptr_location, uint32_t len
UClientImage_Base::resetPipelineAndSetCloseConnection(); UClientImage_Base::resetPipelineAndSetCloseConnection();
uint32_t sz;
UString tmp(100U + len_location); UString tmp(100U + len_location);
tmp.snprintf(U_CONSTANT_TO_PARAM("%s%.*s\r\n"), tmp.snprintf(U_CONSTANT_TO_PARAM("%s%.*s\r\n"),
@ -6979,12 +6980,11 @@ void UHTTP::setRedirectResponse(int mode, const char* ptr_location, uint32_t len
if ((mode & NO_BODY) != 0) if ((mode & NO_BODY) != 0)
{ {
ext->setBuffer(U_CAPACITY); sz = tmp.size();
UClientImage_Base::body->clear(); // clean body to avoid writev() in response... ext->setBuffer(sz + U_CONSTANT_SIZE("Content-Length: 0\r\n\r\n"));
char* ptr = ext->data(); char* ptr = ext->data();
uint32_t sz = tmp.size();
U_MEMCPY(ptr, tmp.data(), sz); U_MEMCPY(ptr, tmp.data(), sz);
ptr += sz; ptr += sz;
@ -6993,38 +6993,40 @@ void UHTTP::setRedirectResponse(int mode, const char* ptr_location, uint32_t len
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' ')); u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
u_put_unalignedp64(ptr+16, U_MULTICHAR_CONSTANT64('0','\r','\n','\r','\n','\0','\0','\0')); u_put_unalignedp64(ptr+16, U_MULTICHAR_CONSTANT64('0','\r','\n','\r','\n','\0','\0','\0'));
ext->size_adjust(ptr + U_CONSTANT_SIZE("Content-Length: 0\r\n\r\n")); ext->size_adjust(sz);
UClientImage_Base::body->clear(); // clean body to avoid writev() in response...
handlerResponse(); handlerResponse();
return;
}
char msg[4096];
uint32_t sz, len;
if ((mode & NETWORK_AUTHENTICATION_REQUIRED) != 0)
{
len = u__snprintf(msg, sizeof(msg), U_CONSTANT_TO_PARAM("You need to <a href=\"%.*s\">authenticate with the local network</a> in order to get access"),
len_location, ptr_location);
} }
else else
{ {
len = u__snprintf(msg, sizeof(msg), U_CONSTANT_TO_PARAM("The document has moved <a href=\"%.*s\">here</a>"), len_location, ptr_location); uint32_t len;
char msg[4096];
if ((mode & NETWORK_AUTHENTICATION_REQUIRED) != 0)
{
len = u__snprintf(msg, sizeof(msg), U_CONSTANT_TO_PARAM("You need to <a href=\"%.*s\">authenticate with the local network</a> in order to get access"),
len_location, ptr_location);
}
else
{
len = u__snprintf(msg, sizeof(msg), U_CONSTANT_TO_PARAM("The document has moved <a href=\"%.*s\">here</a>"), len_location, ptr_location);
}
const char* status = getStatusDescription(&sz);
UString body(500U + len_location), content_type(U_CAPACITY);
body.snprintf(U_CONSTANT_TO_PARAM(U_STR_FMR_BODY),
U_http_info.nResponseCode, sz, status,
sz, status,
len, msg);
(void) content_type.assign(U_CONSTANT_TO_PARAM(U_CTYPE_HTML "\r\n"));
(void) content_type.append(tmp);
setResponse(content_type, &body);
} }
const char* status = getStatusDescription(&sz);
UString body(500U + len_location), content_type(U_CAPACITY);
body.snprintf(U_CONSTANT_TO_PARAM(U_STR_FMR_BODY),
U_http_info.nResponseCode, sz, status,
sz, status,
len, msg);
(void) content_type.assign(U_CONSTANT_TO_PARAM(U_CTYPE_HTML "\r\n"));
(void) content_type.append(tmp);
setResponse(content_type, &body);
} }
void UHTTP::setErrorResponse(const UString& content_type, int code, const char* fmt, uint32_t fmt_size, bool bformat) void UHTTP::setErrorResponse(const UString& content_type, int code, const char* fmt, uint32_t fmt_size, bool bformat)

View File

@ -28,37 +28,37 @@ export ORM_DRIVER ORM_OPTION UMEMPOOL
# ---------------------------------------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------------------------------------
#Running 15s test @ http://localhost:8080/plaintext #Running 15s test @ http://localhost:8080/plaintext
# 4 threads and 256 connections # 4 threads and 256 connections
# Thread Stats Avg Stdev Max +/- Stdev # Thread Stats Avg Stdev Max +/- Stdev
# Latency 1.86ms 2.30ms 28.08ms 88.21% # Latency 0.91ms 564.97us 25.85ms 97.24%
# Req/Sec 552.42k 200.56k 1.39M 68.22% # Req/Sec 615.24k 52.86k 0.90M 75.81%
# Latency Distribution # Latency Distribution
# 50% 1.00ms # 50% 0.86ms
# 75% 2.46ms # 75% 0.95ms
# 90% 4.53ms # 90% 1.04ms
# 99% 11.03ms # 99% 1.80ms
# 30638208 requests in 14.99s, 3.68GB read # 34769232 requests in 15.00s, 4.18GB read
#Requests/sec: 2044562.05 #Requests/sec: 2318061.92
#Transfer/sec: 251.53MB #Transfer/sec: 285.18MB
# ---------------------------------------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------------------------------------
# JSON # JSON
# ---------------------------------------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------------------------------------
#UMEMPOOL="58,0,0,41,273,-15,-14,-20,36" #UMEMPOOL="58,0,0,41,16401,-14,-15,11,25"
#sed -i "s|TCP_LINGER_SET .*|TCP_LINGER_SET 0|g" benchmark/FrameworkBenchmarks/fbenchmark.cfg #sed -i "s|TCP_LINGER_SET .*|TCP_LINGER_SET 0|g" benchmark/FrameworkBenchmarks/fbenchmark.cfg
#sed -i "s|LISTEN_BACKLOG .*|LISTEN_BACKLOG 256|g" benchmark/FrameworkBenchmarks/fbenchmark.cfg #sed -i "s|LISTEN_BACKLOG .*|LISTEN_BACKLOG 256|g" benchmark/FrameworkBenchmarks/fbenchmark.cfg
# ---------------------------------------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------------------------------------
#Running 15s test @ http://localhost:8080/json #Running 15s test @ http://localhost:8080/json
# 4 threads and 256 connections # 4 threads and 256 connections
# Thread Stats Avg Stdev Max +/- Stdev # Thread Stats Avg Stdev Max +/- Stdev
# Latency 0.90ms 2.52ms 36.05ms 93.49% # Latency 404.71us 577.61us 13.07ms 98.46%
# Req/Sec 89.35k 47.88k 229.78k 65.55% # Req/Sec 92.85k 19.62k 174.55k 79.88%
# Latency Distribution # Latency Distribution
# 50% 166.00us # 50% 333.00us
# 75% 408.00us # 75% 458.00us
# 90% 2.27ms # 90% 581.00us
# 99% 11.68ms # 99% 1.86ms
# 4845404 requests in 15.00s, 688.52MB read # 5256998 requests in 15.00s, 747.01MB read
#Requests/sec: 323059.07 #Requests/sec: 350480.62
#Transfer/sec: 45.91MB #Transfer/sec: 49.80MB
# ---------------------------------------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------------------------------------
# DB # DB
# ---------------------------------------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -2,7 +2,6 @@
"framework": "ulib", "framework": "ulib",
"tests": [{ "tests": [{
"default": { "default": {
"setup_file": "setup_plaintext",
"plaintext_url": "/plaintext", "plaintext_url": "/plaintext",
"port": 8080, "port": 8080,
"approach": "Realistic", "approach": "Realistic",
@ -20,7 +19,6 @@
"versus": "" "versus": ""
}, },
"plaintext_fit": { "plaintext_fit": {
"setup_file": "setup_plaintext_fit",
"plaintext_url": "/plaintext", "plaintext_url": "/plaintext",
"port": 8080, "port": 8080,
"approach": "Realistic", "approach": "Realistic",
@ -38,7 +36,6 @@
"versus": "" "versus": ""
}, },
"json": { "json": {
"setup_file": "setup_json",
"json_url": "/json", "json_url": "/json",
"port": 8080, "port": 8080,
"approach": "Realistic", "approach": "Realistic",
@ -56,7 +53,6 @@
"versus": "" "versus": ""
}, },
"json_fit": { "json_fit": {
"setup_file": "setup_json_fit",
"json_url": "/json", "json_url": "/json",
"port": 8080, "port": 8080,
"approach": "Realistic", "approach": "Realistic",
@ -74,7 +70,6 @@
"versus": "" "versus": ""
}, },
"mysql": { "mysql": {
"setup_file": "setup_mysql",
"db_url": "/db", "db_url": "/db",
"query_url": "/query?queries=", "query_url": "/query?queries=",
"fortune_url": "/fortune", "fortune_url": "/fortune",
@ -96,7 +91,6 @@
"versus": "" "versus": ""
}, },
"postgres": { "postgres": {
"setup_file": "setup_postgres",
"db_url": "/db", "db_url": "/db",
"query_url": "/query?queries=", "query_url": "/query?queries=",
"fortune_url": "/fortune", "fortune_url": "/fortune",
@ -118,7 +112,6 @@
"versus": "" "versus": ""
}, },
"postgres_fit": { "postgres_fit": {
"setup_file": "setup_postgres_fit",
"db_url": "/db", "db_url": "/db",
"query_url": "/query?queries=", "query_url": "/query?queries=",
"fortune_url": "/fortune", "fortune_url": "/fortune",

View File

@ -0,0 +1,80 @@
FROM ubuntu:18.04
COPY ./ ./
RUN apt update -yqq && \
apt install -yqq software-properties-common build-essential curl locales wget unzip git \
libmysqlclient-dev libpq-dev \
libpcre3 libpcre3-dev \
libssl-dev libcurl4-openssl-dev \
zlib1g-dev \
libreadline6-dev \
libbz2-dev \
libxslt-dev libgdbm-dev ncurses-dev \
libffi-dev libtool bison libevent-dev \
liborc-0.4-0 \
libmcrypt-dev libicu-dev \
re2c libnuma-dev \
postgresql-server-dev-all libcap2-bin && \
add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
apt update -yqq && \
apt install -yqq gcc-8 g++-8
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV DEBIAN_FRONTEND noninteractive
ENV CC=gcc-8
ENV CXX=g++-8
ENV AR=gcc-ar-8
ENV RANLIB=gcc-ranlib-8
ENV IROOT=/install
ENV ULIB_ROOT=$IROOT/ULib
ENV ULIB_VERSION=1.4.2
ENV ULIB_DOCUMENT_ROOT=$ULIB_ROOT/ULIB_DOCUMENT_ROOT
WORKDIR $IROOT
RUN mkdir -p $ULIB_DOCUMENT_ROOT
RUN wget -q -O ULib-${ULIB_VERSION}.tar.gz https://github.com/stefanocasazza/ULib/archive/v${ULIB_VERSION}.tar.gz
RUN tar xf ULib-${ULIB_VERSION}.tar.gz
WORKDIR $IROOT/ULib-$ULIB_VERSION
# AVOID "configure: error: newly created file is older than distributed files! Check your system clock"
#RUN cp /src/* src/ulib/net/server/plugin/usp
RUN find . -exec touch {} \;
RUN echo "userver {" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PORT 8080" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PREFORK_CHILD $(( 3 * $(nproc) / 2 ))" >> $ULIB_ROOT/benchmark.cfg
RUN echo "TCP_LINGER_SET 0" >> $ULIB_ROOT/benchmark.cfg
RUN echo "LISTEN_BACKLOG 256" >> $ULIB_ROOT/benchmark.cfg
RUN echo "DOCUMENT_ROOT $ULIB_DOCUMENT_ROOT " >> $ULIB_ROOT/benchmark.cfg
RUN echo "}" >> $ULIB_ROOT/benchmark.cfg
RUN USP_FLAGS="-DAS_cpoll_cppsp_DO" \
./configure --prefix=$ULIB_ROOT \
--disable-static --disable-examples \
--without-ssl --disable-HCRS --without-pcre --without-expat \
--without-libz --without-libuuid --disable-HPRS --without-magic --without-libares \
--enable-static-server-plugin=http
RUN make install && \
cd examples/userver && make install && \
cd ../../src/ulib/net/server/plugin/usp && \
make json.la && \
cp .libs/json.so $ULIB_DOCUMENT_ROOT
ENV PATH=${ULIB_ROOT}/bin:${PATH}
ADD ./ /ulib
WORKDIR /ulib
ENV UMEMPOOL="58,0,0,41,273,-15,-14,-20,36"
CMD setcap cap_sys_nice,cap_sys_resource,cap_net_bind_service,cap_net_raw+eip $IROOT/ULib/bin/userver_tcp && \
$IROOT/ULib/bin/userver_tcp -c $IROOT/ULib/benchmark.cfg

View File

@ -0,0 +1,80 @@
FROM ubuntu:18.04
COPY ./ ./
RUN apt update -yqq && \
apt install -yqq software-properties-common build-essential curl locales wget unzip git \
libmysqlclient-dev libpq-dev \
libpcre3 libpcre3-dev \
libssl-dev libcurl4-openssl-dev \
zlib1g-dev \
libreadline6-dev \
libbz2-dev \
libxslt-dev libgdbm-dev ncurses-dev \
libffi-dev libtool bison libevent-dev \
liborc-0.4-0 \
libmcrypt-dev libicu-dev \
re2c libnuma-dev \
postgresql-server-dev-all libcap2-bin && \
add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
apt update -yqq && \
apt install -yqq gcc-8 g++-8
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV DEBIAN_FRONTEND noninteractive
ENV CC=gcc-8
ENV CXX=g++-8
ENV AR=gcc-ar-8
ENV RANLIB=gcc-ranlib-8
ENV IROOT=/install
ENV ULIB_ROOT=$IROOT/ULib
ENV ULIB_VERSION=1.4.2
ENV ULIB_DOCUMENT_ROOT=$ULIB_ROOT/ULIB_DOCUMENT_ROOT
WORKDIR $IROOT
RUN mkdir -p $ULIB_DOCUMENT_ROOT
RUN wget -q -O ULib-${ULIB_VERSION}.tar.gz https://github.com/stefanocasazza/ULib/archive/v${ULIB_VERSION}.tar.gz
RUN tar xf ULib-${ULIB_VERSION}.tar.gz
WORKDIR $IROOT/ULib-$ULIB_VERSION
# AVOID "configure: error: newly created file is older than distributed files! Check your system clock"
#RUN cp /src/* src/ulib/net/server/plugin/usp
RUN find . -exec touch {} \;
RUN echo "userver {" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PORT 8080" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PREFORK_CHILD $(nproc)" >> $ULIB_ROOT/benchmark.cfg
RUN echo "TCP_LINGER_SET 0" >> $ULIB_ROOT/benchmark.cfg
RUN echo "LISTEN_BACKLOG 256" >> $ULIB_ROOT/benchmark.cfg
RUN echo "DOCUMENT_ROOT $ULIB_DOCUMENT_ROOT " >> $ULIB_ROOT/benchmark.cfg
RUN echo "}" >> $ULIB_ROOT/benchmark.cfg
RUN USP_FLAGS="-DAS_cpoll_cppsp_DO" \
./configure --prefix=$ULIB_ROOT \
--disable-static --disable-examples \
--without-ssl --disable-HCRS --without-pcre --without-expat \
--without-libz --without-libuuid --disable-HPRS --without-magic --without-libares \
--enable-static-server-plugin=http
RUN make install && \
cd examples/userver && make install && \
cd ../../src/ulib/net/server/plugin/usp && \
make json.la && \
cp .libs/json.so $ULIB_DOCUMENT_ROOT
ENV PATH=${ULIB_ROOT}/bin:${PATH}
ADD ./ /ulib
WORKDIR /ulib
ENV UMEMPOOL="58,0,0,41,273,-15,-14,-20,36"
CMD setcap cap_sys_nice,cap_sys_resource,cap_net_bind_service,cap_net_raw+eip $IROOT/ULib/bin/userver_tcp && \
$IROOT/ULib/bin/userver_tcp -c $IROOT/ULib/benchmark.cfg

View File

@ -0,0 +1,88 @@
FROM ubuntu:18.04
COPY ./ ./
RUN apt update -yqq && \
apt install -yqq software-properties-common build-essential curl locales wget unzip git \
libmysqlclient-dev libpq-dev \
libpcre3 libpcre3-dev \
libssl-dev libcurl4-openssl-dev \
zlib1g-dev \
libreadline6-dev \
libbz2-dev \
libxslt-dev libgdbm-dev ncurses-dev \
libffi-dev libtool bison libevent-dev \
liborc-0.4-0 \
libmcrypt-dev libicu-dev \
re2c libnuma-dev \
postgresql-server-dev-all libcap2-bin && \
add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
apt update -yqq && \
apt install -yqq gcc-8 g++-8
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV DEBIAN_FRONTEND noninteractive
ENV CC=gcc-8
ENV CXX=g++-8
ENV AR=gcc-ar-8
ENV RANLIB=gcc-ranlib-8
ENV IROOT=/install
ENV ULIB_ROOT=$IROOT/ULib
ENV ULIB_VERSION=1.4.2
ENV ULIB_DOCUMENT_ROOT=$ULIB_ROOT/ULIB_DOCUMENT_ROOT
WORKDIR $IROOT
RUN wget -q https://github.com/mongodb/mongo-c-driver/releases/download/1.4.0/mongo-c-driver-1.4.0.tar.gz
RUN tar xf mongo-c-driver-1.4.0.tar.gz
RUN cd mongo-c-driver-1.4.0/ && \
./configure --prefix=${IROOT} --libdir=${IROOT} --disable-automatic-init-and-cleanup && \
make && make install
RUN mkdir -p $ULIB_DOCUMENT_ROOT
RUN wget -q -O ULib-${ULIB_VERSION}.tar.gz https://github.com/stefanocasazza/ULib/archive/v${ULIB_VERSION}.tar.gz
RUN tar xf ULib-${ULIB_VERSION}.tar.gz
WORKDIR $IROOT/ULib-$ULIB_VERSION
# AVOID "configure: error: newly created file is older than distributed files! Check your system clock"
#RUN cp /src/* src/ulib/net/server/plugin/usp
RUN find . -exec touch {} \;
RUN echo "userver {" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PORT 8080" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PREFORK_CHILD $(( 3 * $(nproc) / 2 ))" >> $ULIB_ROOT/benchmark.cfg
RUN echo "TCP_LINGER_SET -2" >> $ULIB_ROOT/benchmark.cfg
RUN echo "LISTEN_BACKLOG 256" >> $ULIB_ROOT/benchmark.cfg
RUN echo "DOCUMENT_ROOT $ULIB_DOCUMENT_ROOT " >> $ULIB_ROOT/benchmark.cfg
RUN echo "}" >> $ULIB_ROOT/benchmark.cfg
RUN USP_FLAGS="-DAS_cpoll_cppsp_DO" \
./configure --prefix=$ULIB_ROOT \
--disable-static --disable-examples \
--without-ssl --disable-HCRS --without-pcre --without-expat \
--without-libz --without-libuuid --disable-HPRS --without-magic --without-libares \
--enable-static-server-plugin=http \
--with-mongodb --with-mongodb-includes="-I$IROOT/include/libbson-1.0 -I$IROOT/include/libmongoc-1.0" --with-mongodb-ldflags="-L$IROOT"
RUN make install && \
cd examples/userver && make install && \
cd ../../src/ulib/net/server/plugin/usp && \
make mdb.la mquery.la mupdate.la mfortune.la && \
cp .libs/mdb.so .libs/mquery.so .libs/mupdate.so .libs/mfortune.so $ULIB_DOCUMENT_ROOT
ENV PATH=${ULIB_ROOT}/bin:${PATH}
ADD ./ /ulib
WORKDIR /ulib
ENV MONGODB_HOST=tfb-database
ENV UMEMPOOL="96,0,0,47,16401,-14,-20,-18,26"
CMD setcap cap_sys_nice,cap_sys_resource,cap_net_bind_service,cap_net_raw+eip $IROOT/ULib/bin/userver_tcp && \
$IROOT/ULib/bin/userver_tcp -c $IROOT/ULib/benchmark.cfg

View File

@ -0,0 +1,84 @@
FROM ubuntu:18.04
COPY ./ ./
RUN apt update -yqq && \
apt install -yqq software-properties-common build-essential curl locales wget unzip git \
libmysqlclient-dev libpq-dev \
libpcre3 libpcre3-dev \
libssl-dev libcurl4-openssl-dev \
zlib1g-dev \
libreadline6-dev \
libbz2-dev \
libxslt-dev libgdbm-dev ncurses-dev \
libffi-dev libtool bison libevent-dev \
liborc-0.4-0 \
libmcrypt-dev libicu-dev \
re2c libnuma-dev \
postgresql-server-dev-all libcap2-bin && \
add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
apt update -yqq && \
apt install -yqq gcc-8 g++-8
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV DEBIAN_FRONTEND noninteractive
ENV CC=gcc-8
ENV CXX=g++-8
ENV AR=gcc-ar-8
ENV RANLIB=gcc-ranlib-8
ENV IROOT=/install
ENV ULIB_ROOT=$IROOT/ULib
ENV ULIB_VERSION=1.4.2
ENV ULIB_DOCUMENT_ROOT=$ULIB_ROOT/ULIB_DOCUMENT_ROOT
WORKDIR $IROOT
RUN mkdir -p $ULIB_DOCUMENT_ROOT
RUN wget -q -O ULib-${ULIB_VERSION}.tar.gz https://github.com/stefanocasazza/ULib/archive/v${ULIB_VERSION}.tar.gz
RUN tar xf ULib-${ULIB_VERSION}.tar.gz
WORKDIR $IROOT/ULib-$ULIB_VERSION
# AVOID "configure: error: newly created file is older than distributed files! Check your system clock"
#RUN cp /src/* src/ulib/net/server/plugin/usp
RUN find . -exec touch {} \;
RUN echo "userver {" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PORT 8080" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PREFORK_CHILD $(nproc)" >> $ULIB_ROOT/benchmark.cfg
RUN echo "TCP_LINGER_SET -2" >> $ULIB_ROOT/benchmark.cfg
RUN echo "LISTEN_BACKLOG 256" >> $ULIB_ROOT/benchmark.cfg
RUN echo "ORM_DRIVER mysql" >> $ULIB_ROOT/benchmark.cfg
RUN echo "DOCUMENT_ROOT $ULIB_DOCUMENT_ROOT " >> $ULIB_ROOT/benchmark.cfg
RUN echo "}" >> $ULIB_ROOT/benchmark.cfg
RUN USP_FLAGS="-DAS_cpoll_cppsp_DO" \
./configure --prefix=$ULIB_ROOT \
--with-mysql \
--disable-static --disable-examples \
--without-ssl --disable-HCRS --without-pcre --without-expat \
--without-libz --without-libuuid --disable-HPRS --without-magic --without-libares \
--enable-static-orm-driver='mysql' --enable-static-server-plugin=http
RUN make install && \
cd examples/userver && make install && \
cd ../../src/ulib/net/server/plugin/usp && \
make db.la query.la update.la fortune.la cached_worlds.la && \
cp .libs/db.so .libs/query.so .libs/update.so .libs/fortune.so .libs/cached_worlds.so $ULIB_DOCUMENT_ROOT
ENV PATH=${ULIB_ROOT}/bin:${PATH}
ADD ./ /ulib
WORKDIR /ulib
ENV ORM_DRIVER="mysql"
ENV ORM_OPTION="host=tfb-database user=benchmarkdbuser password=benchmarkdbpass character-set=utf8 dbname=hello_world"
ENV UMEMPOOL="581,0,0,59,16409,-7,-20,-23,31"
CMD setcap cap_sys_nice,cap_sys_resource,cap_net_bind_service,cap_net_raw+eip $IROOT/ULib/bin/userver_tcp && \
$IROOT/ULib/bin/userver_tcp -c $IROOT/ULib/benchmark.cfg

View File

@ -0,0 +1,80 @@
FROM ubuntu:18.04
COPY ./ ./
RUN apt update -yqq && \
apt install -yqq software-properties-common build-essential curl locales wget unzip git \
libmysqlclient-dev libpq-dev \
libpcre3 libpcre3-dev \
libssl-dev libcurl4-openssl-dev \
zlib1g-dev \
libreadline6-dev \
libbz2-dev \
libxslt-dev libgdbm-dev ncurses-dev \
libffi-dev libtool bison libevent-dev \
liborc-0.4-0 \
libmcrypt-dev libicu-dev \
re2c libnuma-dev \
postgresql-server-dev-all libcap2-bin && \
add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
apt update -yqq && \
apt install -yqq gcc-8 g++-8
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV DEBIAN_FRONTEND noninteractive
ENV CC=gcc-8
ENV CXX=g++-8
ENV AR=gcc-ar-8
ENV RANLIB=gcc-ranlib-8
ENV IROOT=/install
ENV ULIB_ROOT=$IROOT/ULib
ENV ULIB_VERSION=1.4.2
ENV ULIB_DOCUMENT_ROOT=$ULIB_ROOT/ULIB_DOCUMENT_ROOT
WORKDIR $IROOT
RUN mkdir -p $ULIB_DOCUMENT_ROOT
RUN wget -q -O ULib-${ULIB_VERSION}.tar.gz https://github.com/stefanocasazza/ULib/archive/v${ULIB_VERSION}.tar.gz
RUN tar xf ULib-${ULIB_VERSION}.tar.gz
WORKDIR $IROOT/ULib-$ULIB_VERSION
# AVOID "configure: error: newly created file is older than distributed files! Check your system clock"
#RUN cp /src/* src/ulib/net/server/plugin/usp
RUN find . -exec touch {} \;
RUN echo "userver {" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PORT 8080" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PREFORK_CHILD $(nproc)" >> $ULIB_ROOT/benchmark.cfg
RUN echo "TCP_LINGER_SET 0" >> $ULIB_ROOT/benchmark.cfg
RUN echo "LISTEN_BACKLOG 16384" >> $ULIB_ROOT/benchmark.cfg
RUN echo "DOCUMENT_ROOT $ULIB_DOCUMENT_ROOT " >> $ULIB_ROOT/benchmark.cfg
RUN echo "}" >> $ULIB_ROOT/benchmark.cfg
RUN USP_FLAGS="-DAS_cpoll_cppsp_DO" \
./configure --prefix=$ULIB_ROOT \
--disable-static --disable-examples \
--without-ssl --without-pcre --without-expat \
--without-libz --without-libuuid --without-magic --without-libares \
--enable-static-server-plugin=http
RUN make install && \
cd examples/userver && make install && \
cd ../../src/ulib/net/server/plugin/usp && \
make plaintext.la && \
cp .libs/plaintext.so $ULIB_DOCUMENT_ROOT
ENV PATH=${ULIB_ROOT}/bin:${PATH}
ADD ./ /ulib
WORKDIR /ulib
ENV UMEMPOOL="58,0,0,41,16401,-14,-15,11,25"
CMD setcap cap_sys_nice,cap_sys_resource,cap_net_bind_service,cap_net_raw+eip $IROOT/ULib/bin/userver_tcp && \
$IROOT/ULib/bin/userver_tcp -c $IROOT/ULib/benchmark.cfg

View File

@ -0,0 +1,84 @@
FROM ubuntu:18.04
COPY ./ ./
RUN apt update -yqq && \
apt install -yqq software-properties-common build-essential curl locales wget unzip git \
libmysqlclient-dev libpq-dev \
libpcre3 libpcre3-dev \
libssl-dev libcurl4-openssl-dev \
zlib1g-dev \
libreadline6-dev \
libbz2-dev \
libxslt-dev libgdbm-dev ncurses-dev \
libffi-dev libtool bison libevent-dev \
liborc-0.4-0 \
libmcrypt-dev libicu-dev \
re2c libnuma-dev \
postgresql-server-dev-all libcap2-bin && \
add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
apt update -yqq && \
apt install -yqq gcc-8 g++-8
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV DEBIAN_FRONTEND noninteractive
ENV CC=gcc-8
ENV CXX=g++-8
ENV AR=gcc-ar-8
ENV RANLIB=gcc-ranlib-8
ENV IROOT=/install
ENV ULIB_ROOT=$IROOT/ULib
ENV ULIB_VERSION=1.4.2
ENV ULIB_DOCUMENT_ROOT=$ULIB_ROOT/ULIB_DOCUMENT_ROOT
WORKDIR $IROOT
RUN mkdir -p $ULIB_DOCUMENT_ROOT
RUN wget -q -O ULib-${ULIB_VERSION}.tar.gz https://github.com/stefanocasazza/ULib/archive/v${ULIB_VERSION}.tar.gz
RUN tar xf ULib-${ULIB_VERSION}.tar.gz
WORKDIR $IROOT/ULib-$ULIB_VERSION
# AVOID "configure: error: newly created file is older than distributed files! Check your system clock"
#RUN cp /src/* src/ulib/net/server/plugin/usp
RUN find . -exec touch {} \;
RUN echo "userver {" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PORT 8080" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PREFORK_CHILD $(( 2 * $(nproc)))" >> $ULIB_ROOT/benchmark.cfg
RUN echo "TCP_LINGER_SET -2" >> $ULIB_ROOT/benchmark.cfg
RUN echo "LISTEN_BACKLOG 256" >> $ULIB_ROOT/benchmark.cfg
RUN echo "ORM_DRIVER pgsql" >> $ULIB_ROOT/benchmark.cfg
RUN echo "DOCUMENT_ROOT $ULIB_DOCUMENT_ROOT " >> $ULIB_ROOT/benchmark.cfg
RUN echo "}" >> $ULIB_ROOT/benchmark.cfg
RUN USP_FLAGS="-DAS_cpoll_cppsp_DO" \
./configure --prefix=$ULIB_ROOT \
--disable-static --disable-examples \
--with-pgsql \
--without-ssl --disable-HCRS --without-pcre --without-expat \
--without-libz --without-libuuid --disable-HPRS --without-magic --without-libares \
--enable-static-orm-driver='pgsql' --enable-static-server-plugin=http
RUN make install && \
cd examples/userver && make install && \
cd ../../src/ulib/net/server/plugin/usp && \
make db.la query.la update.la fortune.la cached_worlds.la && \
cp .libs/db.so .libs/query.so .libs/update.so .libs/fortune.so .libs/cached_worlds.so $ULIB_DOCUMENT_ROOT
ENV PATH=${ULIB_ROOT}/bin:${PATH}
ADD ./ /ulib
WORKDIR /ulib
ENV ORM_DRIVER="pgsql"
ENV UMEMPOOL="581,0,0,59,16409,-7,-20,-23,31"
ENV ORM_OPTION="host=tfb-database user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world client_encoding=UTF8"
CMD setcap cap_sys_nice,cap_sys_resource,cap_net_bind_service,cap_net_raw+eip $IROOT/ULib/bin/userver_tcp && \
$IROOT/ULib/bin/userver_tcp -c $IROOT/ULib/benchmark.cfg

View File

@ -0,0 +1,84 @@
FROM ubuntu:18.04
COPY ./ ./
RUN apt update -yqq && \
apt install -yqq software-properties-common build-essential curl locales wget unzip git \
libmysqlclient-dev libpq-dev \
libpcre3 libpcre3-dev \
libssl-dev libcurl4-openssl-dev \
zlib1g-dev \
libreadline6-dev \
libbz2-dev \
libxslt-dev libgdbm-dev ncurses-dev \
libffi-dev libtool bison libevent-dev \
liborc-0.4-0 \
libmcrypt-dev libicu-dev \
re2c libnuma-dev \
postgresql-server-dev-all libcap2-bin && \
add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
apt update -yqq && \
apt install -yqq gcc-8 g++-8
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV DEBIAN_FRONTEND noninteractive
ENV CC=gcc-8
ENV CXX=g++-8
ENV AR=gcc-ar-8
ENV RANLIB=gcc-ranlib-8
ENV IROOT=/install
ENV ULIB_ROOT=$IROOT/ULib
ENV ULIB_VERSION=1.4.2
ENV ULIB_DOCUMENT_ROOT=$ULIB_ROOT/ULIB_DOCUMENT_ROOT
WORKDIR $IROOT
RUN mkdir -p $ULIB_DOCUMENT_ROOT
RUN wget -q -O ULib-${ULIB_VERSION}.tar.gz https://github.com/stefanocasazza/ULib/archive/v${ULIB_VERSION}.tar.gz
RUN tar xf ULib-${ULIB_VERSION}.tar.gz
WORKDIR $IROOT/ULib-$ULIB_VERSION
# AVOID "configure: error: newly created file is older than distributed files! Check your system clock"
#RUN cp /src/* src/ulib/net/server/plugin/usp
RUN find . -exec touch {} \;
RUN echo "userver {" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PORT 8080" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PREFORK_CHILD $(nproc)" >> $ULIB_ROOT/benchmark.cfg
RUN echo "TCP_LINGER_SET -2" >> $ULIB_ROOT/benchmark.cfg
RUN echo "LISTEN_BACKLOG 256" >> $ULIB_ROOT/benchmark.cfg
RUN echo "ORM_DRIVER pgsql" >> $ULIB_ROOT/benchmark.cfg
RUN echo "DOCUMENT_ROOT $ULIB_DOCUMENT_ROOT " >> $ULIB_ROOT/benchmark.cfg
RUN echo "}" >> $ULIB_ROOT/benchmark.cfg
RUN USP_FLAGS="-DAS_cpoll_cppsp_DO" \
./configure --prefix=$ULIB_ROOT \
--disable-static --disable-examples \
--with-pgsql \
--without-ssl --disable-HCRS --without-pcre --without-expat \
--without-libz --without-libuuid --disable-HPRS --without-magic --without-libares \
--enable-static-orm-driver='pgsql' --enable-static-server-plugin=http
RUN make install && \
cd examples/userver && make install && \
cd ../../src/ulib/net/server/plugin/usp && \
make db.la query.la update.la fortune.la cached_worlds.la && \
cp .libs/db.so .libs/query.so .libs/update.so .libs/fortune.so .libs/cached_worlds.so $ULIB_DOCUMENT_ROOT
ENV PATH=${ULIB_ROOT}/bin:${PATH}
ADD ./ /ulib
WORKDIR /ulib
ENV ORM_DRIVER="pgsql"
ENV UMEMPOOL="581,0,0,59,16409,-7,-20,-23,31"
ENV ORM_OPTION="host=tfb-database user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world client_encoding=UTF8"
CMD setcap cap_sys_nice,cap_sys_resource,cap_net_bind_service,cap_net_raw+eip $IROOT/ULib/bin/userver_tcp && \
$IROOT/ULib/bin/userver_tcp -c $IROOT/ULib/benchmark.cfg

View File

@ -0,0 +1,80 @@
FROM ubuntu:18.04
COPY ./ ./
RUN apt update -yqq && \
apt install -yqq software-properties-common build-essential curl locales wget unzip git \
libmysqlclient-dev libpq-dev \
libpcre3 libpcre3-dev \
libssl-dev libcurl4-openssl-dev \
zlib1g-dev \
libreadline6-dev \
libbz2-dev \
libxslt-dev libgdbm-dev ncurses-dev \
libffi-dev libtool bison libevent-dev \
liborc-0.4-0 \
libmcrypt-dev libicu-dev \
re2c libnuma-dev \
postgresql-server-dev-all libcap2-bin && \
add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
apt update -yqq && \
apt install -yqq gcc-8 g++-8
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV DEBIAN_FRONTEND noninteractive
ENV CC=gcc-8
ENV CXX=g++-8
ENV AR=gcc-ar-8
ENV RANLIB=gcc-ranlib-8
ENV IROOT=/install
ENV ULIB_ROOT=$IROOT/ULib
ENV ULIB_VERSION=1.4.2
ENV ULIB_DOCUMENT_ROOT=$ULIB_ROOT/ULIB_DOCUMENT_ROOT
WORKDIR $IROOT
RUN mkdir -p $ULIB_DOCUMENT_ROOT
RUN wget -q -O ULib-${ULIB_VERSION}.tar.gz https://github.com/stefanocasazza/ULib/archive/v${ULIB_VERSION}.tar.gz
RUN tar xf ULib-${ULIB_VERSION}.tar.gz
WORKDIR $IROOT/ULib-$ULIB_VERSION
# AVOID "configure: error: newly created file is older than distributed files! Check your system clock"
#RUN cp /src/* src/ulib/net/server/plugin/usp
RUN find . -exec touch {} \;
RUN echo "userver {" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PORT 8080" >> $ULIB_ROOT/benchmark.cfg
RUN echo "PREFORK_CHILD $(( 3 * $(nproc) / 2 ))" >> $ULIB_ROOT/benchmark.cfg
RUN echo "TCP_LINGER_SET 0" >> $ULIB_ROOT/benchmark.cfg
RUN echo "LISTEN_BACKLOG 16384" >> $ULIB_ROOT/benchmark.cfg
RUN echo "DOCUMENT_ROOT $ULIB_DOCUMENT_ROOT " >> $ULIB_ROOT/benchmark.cfg
RUN echo "}" >> $ULIB_ROOT/benchmark.cfg
RUN USP_FLAGS="-DAS_cpoll_cppsp_DO" \
./configure --prefix=$ULIB_ROOT \
--disable-static --disable-examples \
--without-ssl --without-pcre --without-expat \
--without-libz --without-libuuid --without-magic --without-libares \
--enable-static-server-plugin=http
RUN make install && \
cd examples/userver && make install && \
cd ../../src/ulib/net/server/plugin/usp && \
make plaintext.la && \
cp .libs/plaintext.so $ULIB_DOCUMENT_ROOT
ENV PATH=${ULIB_ROOT}/bin:${PATH}
ADD ./ /ulib
WORKDIR /ulib
ENV UMEMPOOL="58,0,0,41,16401,-14,-15,11,25"
CMD setcap cap_sys_nice,cap_sys_resource,cap_net_bind_service,cap_net_raw+eip $IROOT/ULib/bin/userver_tcp && \
$IROOT/ULib/bin/userver_tcp -c $IROOT/ULib/benchmark.cfg

View File

@ -13,7 +13,7 @@ rm -f /tmp/uclient.log \
trace.*userver_*.[0-9]* object.*userver_*.[0-9]* stack.*userver_*.[0-9]* mempool.*userver_*.[0-9]* \ trace.*userver_*.[0-9]* object.*userver_*.[0-9]* stack.*userver_*.[0-9]* mempool.*userver_*.[0-9]* \
$DOC_ROOT/trace.*userver_*.[0-9]* $DOC_ROOT/object.*userver_*.[0-9]* $DOC_ROOT/stack.*userver_*.[0-9]* $DOC_ROOT/mempool.*userver_*.[0-9]* $DOC_ROOT/trace.*userver_*.[0-9]* $DOC_ROOT/object.*userver_*.[0-9]* $DOC_ROOT/stack.*userver_*.[0-9]* $DOC_ROOT/mempool.*userver_*.[0-9]*
#UTRACE="0 100M -1" UTRACE="0 100M -1"
UTRACE_FOLDER=/tmp UTRACE_FOLDER=/tmp
TMPDIR=/tmp TMPDIR=/tmp
#UOBJDUMP="0 10M 100" #UOBJDUMP="0 10M 100"
@ -62,7 +62,7 @@ nodog {
FW_CMD ../firewall/nodog.fw FW_CMD ../firewall/nodog.fw
DECRYPT_KEY vivalatopa DECRYPT_KEY vivalatopa
CHECK_EXPIRE_INTERVAL 60 CHECK_EXPIRE_INTERVAL 60
FW_ENV "MasqueradeDevice=eth0 'AuthServiceAddr=http://localhost' FullPrivateNetwork=192.168.0.0/12 LocalNetwork=192.168.0.0/24 InternalDevice=wlan0 'ExternalDevice=eth0 tun0 tun2'" FW_ENV "MasqueradeDevice=eth0 'AuthServiceAddr=http://localhost' FullPrivateNetwork=192.168.0.0/12 LocalNetwork=192.168.0.0/16 InternalDevice=usb0 'ExternalDevice=eth0 tun0 tun2'"
LOCAL_NETWORK_LABEL 1000 LOCAL_NETWORK_LABEL 1000
#DHCP_DATA_FILE /tmp/kea-leases.tdb #DHCP_DATA_FILE /tmp/kea-leases.tdb
} }
@ -84,6 +84,8 @@ wait_server_ready localhost 5280
sync sync
echo "PID = `cat /tmp/nodog.pid`" echo "PID = `cat /tmp/nodog.pid`"
#netcat -w 10 192.168.42.129 5280 < /mnt/storage/srv/realtime.req
#$SLEEP #$SLEEP
#kill_prg userver_tcp TERM #kill_prg userver_tcp TERM

View File

@ -12,7 +12,7 @@ rm -f out/userver_tcp.out err/wi-auth2.err err/uclient.err \
trace.*userver_*.[0-9]* object.*userver_*.[0-9]* stack.*userver_*.[0-9]* mempool.*userver_*.[0-9]* \ trace.*userver_*.[0-9]* object.*userver_*.[0-9]* stack.*userver_*.[0-9]* mempool.*userver_*.[0-9]* \
$DOC_ROOT/trace.*userver_*.[0-9]* $DOC_ROOT/object.*userver_*.[0-9]* $DOC_ROOT/stack.*userver_*.[0-9]* $DOC_ROOT/mempool.*userver_*.[0-9]* $DOC_ROOT/trace.*userver_*.[0-9]* $DOC_ROOT/object.*userver_*.[0-9]* $DOC_ROOT/stack.*userver_*.[0-9]* $DOC_ROOT/mempool.*userver_*.[0-9]*
UTRACE="0 100M -1" #UTRACE="0 100M -1"
UTRACE_FOLDER=/tmp UTRACE_FOLDER=/tmp
TMPDIR=/tmp TMPDIR=/tmp
#UOBJDUMP="0 10M 100" #UOBJDUMP="0 10M 100"

View File

@ -584,14 +584,15 @@ int U_EXPORT main(int argc, char* argv[], char* env[])
fb.IndirectUInt(INT_MAX); fb.IndirectUInt(INT_MAX);
fb.IndirectUInt(UINT_MAX); fb.IndirectUInt(UINT_MAX);
fb.IndirectFloat(3.5); fb.IndirectFloat(3.5);
fb.StringNull();
}); });
U_INTERNAL_ASSERT_EQUALS(size, 607) // U_INTERNAL_ASSERT_EQUALS(size, 607)
fb.setRoot(); fb.setRoot();
fb.AsVector(vec); fb.AsVector(vec);
U_ASSERT_EQUALS(vec.GetSize(), 36) U_ASSERT_EQUALS(vec.GetSize(), 37)
U_ASSERT_EQUALS(vec.AsVectorGet<uint64_t>(0), 1) U_ASSERT_EQUALS(vec.AsVectorGet<uint64_t>(0), 1)
U_ASSERT_EQUALS(vec.AsVectorGet<int64_t>(1), INT_MIN) U_ASSERT_EQUALS(vec.AsVectorGet<int64_t>(1), INT_MIN)
U_ASSERT_EQUALS(vec.AsVectorGet<uint64_t>(2), 2) U_ASSERT_EQUALS(vec.AsVectorGet<uint64_t>(2), 2)
@ -709,6 +710,7 @@ int U_EXPORT main(int argc, char* argv[], char* env[])
U_ASSERT_EQUALS(vec.AsVectorGetIndirect<uint64_t>(33), INT_MAX) U_ASSERT_EQUALS(vec.AsVectorGetIndirect<uint64_t>(33), INT_MAX)
U_ASSERT_EQUALS(vec.AsVectorGetIndirect<uint64_t>(34), UINT_MAX) U_ASSERT_EQUALS(vec.AsVectorGetIndirect<uint64_t>(34), UINT_MAX)
U_ASSERT_EQUALS(vec.AsVectorGetIndirect<double>(35), 3.5) U_ASSERT_EQUALS(vec.AsVectorGetIndirect<double>(35), 3.5)
U_ASSERT_EQUALS(vec.AsVectorGet<UString>(36), UString::getStringNull())
size = fb.encodeMap([&]() { size = fb.encodeMap([&]() {
fb.UInt(U_CONSTANT_TO_PARAM("a"), 1); fb.UInt(U_CONSTANT_TO_PARAM("a"), 1);

View File

@ -156,7 +156,7 @@ static void TCPEchoServer(unsigned int iPortNumber, bool bIPv6)
cout << "Host name = " << cServerSocket.localIPAddress().getHostName() << '\n' cout << "Host name = " << cServerSocket.localIPAddress().getHostName() << '\n'
<< "Host address = " << cServerSocket.localIPAddress().getAddressString() << '\n' << "Host address = " << cServerSocket.localIPAddress().getAddressString() << '\n'
<< "Node name = " << USocketExt::getNodeName() << '\n' << "Node name = " << USocketExt::getNodeName() << '\n'
<< "MAC address = " << pcClientSocket->getMacAddress("eth0") << '\n' << "MAC address = " << USocketExt::getMacAddress(pcClientSocket, "eth0") << '\n'
<< "Network device = " << USocketExt::getNetworkDevice("eth0") << '\n' << "Network device = " << USocketExt::getNetworkDevice("eth0") << '\n'
<< "Gateway address = " << USocketExt::getGatewayAddress(U_CONSTANT_TO_PARAM("192.168.1.0/24")) << '\n' << "Gateway address = " << USocketExt::getGatewayAddress(U_CONSTANT_TO_PARAM("192.168.1.0/24")) << '\n'
<< "Network address = " << USocketExt::getNetworkAddress(fd, "eth0") << "\n\n"; << "Network address = " << USocketExt::getNetworkAddress(fd, "eth0") << "\n\n";