ntopng/include/LocalHost.h
Simone Mainardi e360f51124 Fixes crash and removes unused PortContactStats
Class was not used and didn't handle concurrent accesses to strings,
yielding crashes such as

Thread 14 "stats_update.lu" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffb3fff700 (LWP 25268)]
0x00005555556b9183 in IpAddress::intoa (this=0x28c, buf=0x7fffb3ffe030 "", bufLen=64, bitmask=255 '\377') at src/IpAddress.cpp:352
352     src/IpAddress.cpp: No such file or directory.
(gdb)
(gdb) bt
    at src/GenericHash.cpp:222
    #9  0x00005555556c0413 in NetworkInterface::walker (this=0x555556159e70, begin_slot=0x7fffb3ffe454, walk_all=true, wtype=walker_flows, walker=0x5555556c6b79 <host_flow_update_stats(GenericHashEntry*, void*, bool*)>,
        user_data=0x7fffb3ffe458) at src/NetworkInterface.cpp:795
	#10 0x00005555556c6f7c in NetworkInterface::periodicStatsUpdate (this=0x555556159e70, vm=0x7fffac0a5578) at src/NetworkInterface.cpp:2589
	#11 0x0000555555671d62 in ntop_periodic_stats_update (vm=0x7fffac0a5578) at src/LuaEngine.cpp:6304
	#12 0x000055555576c2f6 in luaD_precall ()
	#13 0x0000555555777acd in luaV_execute ()
	#14 0x000055555576c5cf in luaD_call ()
	#15 0x000055555576c621 in luaD_callnoyield ()
	#16 0x000055555576ba42 in luaD_rawrunprotected ()
	#17 0x000055555576c91b in luaD_pcall ()
	#18 0x0000555555769cd4 in lua_pcallk ()
	#19 0x0000555555681e8a in LuaEngine::run_loaded_script (this=0x7fffac01fe10) at src/LuaEngine.cpp:12188
	#20 0x000055555563eca2 in ThreadedActivity::runScript (this=0x555562aee4e0, now=1585309410, script_path=0x7fff88002620 "/usr/share/ntopng/scripts/callbacks/interface/stats_update.lua", iface=0x555556159e70, deadline=1585309420)
	    at src/ThreadedActivity.cpp:418
	    #21 0x00005555556ba04d in ThreadPool::run (this=0x5555624525a0) at src/ThreadPool.cpp:103
	    #22 0x00005555556b9c79 in doRun (ptr=0x5555624525a0) at src/ThreadPool.cpp:31
	    #23 0x00007ffff65aa6db in start_thread (arg=0x7fffb3fff700) at pthread_create.c:463
	    #24 0x00007ffff3ea388f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
2020-03-27 13:38:12 +01:00

89 lines
3.9 KiB
C++

/*
*
* (C) 2013-20 - ntop.org
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef _LOCAL_HOST_H_
#define _LOCAL_HOST_H_
#include "ntop_includes.h"
class LocalHost : public Host, public SerializableElement {
protected:
int16_t local_network_id;
bool systemHost;
time_t initialization_time;
HostTimeseriesPoint *initial_ts_point;
/* LocalHost data: update LocalHost::deleteHostData when adding new fields */
OperatingSystem os;
char *os_detail;
bool drop_all_host_traffic;
/* END Host data: */
void initialize();
void freeLocalHostData();
virtual void deleteHostData();
char* getMacBasedSerializationKey(char *redis_key, size_t size, char *mac_key);
char* getIpBasedSerializationKey(char *redis_key, size_t size);
public:
LocalHost(NetworkInterface *_iface, Mac *_mac, u_int16_t _vlanId, IpAddress *_ip);
LocalHost(NetworkInterface *_iface, char *ipAddress, u_int16_t _vlanId);
virtual ~LocalHost();
virtual void set_hash_entry_state_idle();
virtual int16_t get_local_network_id() const { return(local_network_id); };
virtual bool isLocalHost() const { return(true); };
virtual bool isSystemHost() const { return(systemHost); };
virtual NetworkStats* getNetworkStats(int16_t networkId) {
return(iface->getNetworkStats(networkId));
};
virtual u_int32_t getActiveHTTPHosts() const { return(getHTTPstats() ? getHTTPstats()->get_num_virtual_hosts() : 0); };
virtual HostStats* allocateStats() { return(new LocalHostStats(this)); };
virtual bool dropAllTraffic() const { return(drop_all_host_traffic); };
virtual void inlineSetOSDetail(const char *_os_detail);
virtual const char* getOSDetail(char * const buf, ssize_t buf_len);
virtual void updateHostTrafficPolicy(char *key);
virtual void luaHTTP(lua_State *vm) const { stats->luaHTTP(vm); };
virtual void luaDNS(lua_State *vm, bool verbose) const { stats->luaDNS(vm, verbose); };
virtual void luaICMP(lua_State *vm, bool isV4, bool verbose) const { stats->luaICMP(vm,isV4,verbose); };
virtual void incrVisitedWebSite(char *hostname) { stats->incrVisitedWebSite(hostname); };
virtual HTTPstats* getHTTPstats() const { return(stats->getHTTPstats()); };
virtual DnsStats* getDNSstats() const { return(stats->getDNSstats()); };
virtual ICMPstats* getICMPstats() const { return(stats->getICMPstats()); };
virtual void luaTCP(lua_State *vm) const { stats->lua(vm,false,details_normal); };
virtual u_int16_t getNumActiveContactsAsClient() const { return stats->getNumActiveContactsAsClient(); };
virtual u_int16_t getNumActiveContactsAsServer() const { return stats->getNumActiveContactsAsServer(); };
virtual void reloadPrefs();
virtual void deserialize(json_object *obj);
virtual void serialize(json_object *obj, DetailsLevel details_level) { return Host::serialize(obj, details_level); };
virtual char* getSerializationKey(char *buf, uint bufsize);
virtual void lua(lua_State* vm, AddressTree * ptree, bool host_details,
bool verbose, bool returnHost, bool asListElement);
virtual void tsLua(lua_State* vm);
};
#endif /* _LOCAL_HOST_H_ */