From 765b305020957d88cfe98544c3377d10cd44e5aa Mon Sep 17 00:00:00 2001 From: YellowMan Date: Thu, 7 Nov 2024 13:12:18 +0100 Subject: [PATCH] Moved asset management tracking only to LocalHost --- include/Host.h | 28 ++++---- include/LocalHost.h | 16 +++++ src/Host.cpp | 116 ++++++--------------------------- src/LocalHost.cpp | 154 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 205 insertions(+), 109 deletions(-) diff --git a/include/Host.h b/include/Host.h index 975920d4cbf7..0f23c4f8cacb 100644 --- a/include/Host.h +++ b/include/Host.h @@ -240,32 +240,32 @@ class Host : public GenericHashEntry, inline bool isDhcpServer() const { return (host_services_bitmap & (1 << HOST_IS_DHCP_SERVER)); } - void setDhcpServer(char *name); + virtual void setDhcpServer(char *name); inline bool isDnsServer() const { return (host_services_bitmap & (1 << HOST_IS_DNS_SERVER)); } - void setDnsServer(char *name); + virtual void setDnsServer(char *name); inline bool isSmtpServer() const { return (host_services_bitmap & (1 << HOST_IS_SMTP_SERVER)); } - void setSmtpServer(char *name); + virtual void setSmtpServer(char *name); inline bool isImapServer() const { return (host_services_bitmap & (1 << HOST_IS_IMAP_SERVER)); } - void setImapServer(char *name); + virtual void setImapServer(char *name); inline bool isPopServer() const { return (host_services_bitmap & (1 << HOST_IS_POP_SERVER)); } - void setPopServer(char *name); + virtual void setPopServer(char *name); inline bool isNtpServer() const { return (host_services_bitmap & (1 << HOST_IS_NTP_SERVER)); } - void setNtpServer(char *name); + virtual void setNtpServer(char *name); inline u_int16_t getServicesMap() { return (host_services_bitmap); } /* @@ -771,15 +771,15 @@ class Host : public GenericHashEntry, virtual void inlineSetOSDetail(const char *detail) {} virtual const char *getOSDetail(char *const buf, ssize_t buf_len); void offlineSetTLSName(const char *n); - void offlineSetHTTPName(const char *n); - void offlineSetNetbiosName(const char *n); + virtual void offlineSetHTTPName(const char *n); + virtual void offlineSetNetbiosName(const char *n); void offlineSetSSDPLocation(const char *url); - void offlineSetMDNSInfo(char *const s); - void offlineSetMDNSName(const char *n); - void offlineSetMDNSTXTName(const char *n); - void offlineSetDHCPName(const char *n); - void setServerName(const char *n); - void setResolvedName(const char *resolved_name); + virtual void offlineSetMDNSInfo(char *const s); + virtual void offlineSetMDNSName(const char *n); + virtual void offlineSetMDNSTXTName(const char *n); + virtual void offlineSetDHCPName(const char *n); + virtual void setServerName(const char *n); + virtual void setResolvedName(const char *resolved_name); virtual Fingerprint *getJA4Fingerprint() { return (NULL); } virtual Fingerprint *getHASSHFingerprint() { return (NULL); } diff --git a/include/LocalHost.h b/include/LocalHost.h index 33d13b15cff0..6e7c7fe3299d 100644 --- a/include/LocalHost.h +++ b/include/LocalHost.h @@ -208,6 +208,22 @@ class LocalHost : public Host { SPSCQueue> *getContactedServerPorts() { return (&contacted_server_ports);}; + void setDhcpServer(char *name); + void setDnsServer(char *name); + void setSmtpServer(char *name); + void setNtpServer(char *name); + void setImapServer(char *name); + void setPopServer(char *name); + + void offlineSetMDNSInfo(char *const s); + void offlineSetMDNSName(const char *n); + void offlineSetDHCPName(const char *n); + void offlineSetMDNSTXTName(const char *n); + void offlineSetNetbiosName(const char *n); + void offlineSetHTTPName(const char *n); + void setServerName(const char *n); + void setResolvedName(const char *resolved_name); + }; #endif /* _LOCAL_HOST_H_ */ diff --git a/src/Host.cpp b/src/Host.cpp index 57208e4275ed..43ac14595043 100644 --- a/src/Host.cpp +++ b/src/Host.cpp @@ -1692,10 +1692,6 @@ void Host::offlineSetMDNSInfo(char *const str) { /* Time to set the actual info */ names.mdns_info = cur_info; - -#ifdef NTOPNG_PRO - ntop->get_am()->setResolvedName(this, label_mdns_info, names.mdns_info); -#endif } return; @@ -1714,48 +1710,31 @@ void Host::offlineSetSSDPLocation(const char *url) { void Host::offlineSetMDNSName(const char *mdns_n) { if (!isValidHostName(mdns_n)) return; - - if (!names.mdns && mdns_n && - (names.mdns = Utils::toLowerResolvedNames(mdns_n))) { -#ifdef NTOPNG_PRO - ntop->get_am()->setResolvedName(this, label_mdns, names.mdns); -#endif - } + if (!names.mdns && mdns_n) + names.mdns = Utils::toLowerResolvedNames(mdns_n); } /* *************************************** */ void Host::offlineSetDHCPName(const char *dhcp_n) { if (!isValidHostName(dhcp_n)) return; - if (!names.dhcp && dhcp_n && (names.dhcp = strdup(dhcp_n))) { -#ifdef NTOPNG_PRO - ntop->get_am()->setResolvedName(this, label_dhcp, names.dhcp); -#endif - } + if (!names.dhcp && dhcp_n) + names.dhcp = strdup(dhcp_n); } /* *************************************** */ void Host::offlineSetMDNSTXTName(const char *mdns_n_txt) { - if (!names.mdns_txt && mdns_n_txt && - (names.mdns_txt = Utils::toLowerResolvedNames(mdns_n_txt))) { -#ifdef NTOPNG_PRO - ntop->get_am()->setResolvedName(this, label_mdns_txt, names.mdns_txt); -#endif - } + if (!names.mdns_txt && mdns_n_txt) + names.mdns_txt = Utils::toLowerResolvedNames(mdns_n_txt); } /* *************************************** */ void Host::offlineSetNetbiosName(const char *netbios_n) { if (!isValidHostName(netbios_n)) return; - - if (!names.netbios && netbios_n && - (names.netbios = Utils::toLowerResolvedNames(netbios_n))) { -#ifdef NTOPNG_PRO - ntop->get_am()->setResolvedName(this, label_netbios, names.netbios); -#endif - } + if (!names.netbios && netbios_n) + names.netbios = Utils::toLowerResolvedNames(netbios_n); } /* *************************************** */ @@ -1771,25 +1750,16 @@ void Host::offlineSetTLSName(const char *tls_n) { return; } - if (!names.tls && tls_n && (names.tls = Utils::toLowerResolvedNames(tls_n))) { -#ifdef NTOPNG_PRO - if (ntop->getPrefs()->do_tls_quic_hostnaming()) - ntop->get_am()->setResolvedName(this, label_tls, names.tls); -#endif - } + if (!names.tls && tls_n) + names.tls = Utils::toLowerResolvedNames(tls_n); } /* *************************************** */ void Host::offlineSetHTTPName(const char *http_n) { if (!isValidHostName(http_n)) return; - - if (!names.http && http_n && - (names.http = Utils::toLowerResolvedNames(http_n))) { -#ifdef NTOPNG_PRO - ntop->get_am()->setResolvedName(this, label_http, names.http); -#endif - } + if (!names.http && http_n) + names.http = Utils::toLowerResolvedNames(http_n); } /* *************************************** */ @@ -1813,16 +1783,9 @@ bool Host::isValidHostName(const char *name) { /* *************************************** */ void Host::setServerName(const char *server_n) { - /* Discard invalid strings */ - if (!isValidHostName(server_n)) return; - - if (!names.server_name && server_n && - (names.server_name = Utils::toLowerResolvedNames(server_n))) { -#ifdef NTOPNG_PRO - ntop->get_am()->setResolvedName(this, label_server_name, names.server_name); -#endif - } + if (!names.server_name && server_n) + names.server_name = Utils::toLowerResolvedNames(server_n); } /* *************************************** */ @@ -1831,15 +1794,8 @@ void Host::setResolvedName(const char *resolved_name) { /* Multiple threads can set this so we must lock */ if (resolved_name && resolved_name[0] != '\0') { m.lock(__FILE__, __LINE__); - - if (!names.resolved /* Don't set hostnames already set */) { + if (!names.resolved /* Don't set hostnames already set */) names.resolved = Utils::toLowerResolvedNames(resolved_name); - -#ifdef NTOPNG_PRO - ntop->get_am()->setResolvedName(this, label_resolver, names.resolved); -#endif - } - m.unlock(__FILE__, __LINE__); } } @@ -2682,73 +2638,43 @@ void Host::visit(std::vector *v, HostWalkMode mode) { /* *************************************** */ void Host::setDhcpServer(char *name) { - if (!isDhcpServer()) { + if (!isDhcpServer()) host_services_bitmap |= 1 << HOST_IS_DHCP_SERVER; - -#ifdef NTOPNG_PRO - ntop->get_am()->setServerInfo(this, dhcp_server, name); -#endif - } } /* *************************************** */ void Host::setDnsServer(char *name) { - if (!isDnsServer()) { + if (!isDnsServer()) host_services_bitmap |= 1 << HOST_IS_DNS_SERVER; - -#ifdef NTOPNG_PRO - ntop->get_am()->setServerInfo(this, dns_server, name); -#endif - } } /* *************************************** */ void Host::setSmtpServer(char *name) { - if (!isSmtpServer()) { + if (!isSmtpServer()) host_services_bitmap |= 1 << HOST_IS_SMTP_SERVER; - -#ifdef NTOPNG_PRO - ntop->get_am()->setServerInfo(this, smtp_server, name); -#endif - } } /* *************************************** */ void Host::setNtpServer(char *name) { - if (!isNtpServer()) { + if (!isNtpServer()) host_services_bitmap |= 1 << HOST_IS_NTP_SERVER; - -#ifdef NTOPNG_PRO - ntop->get_am()->setServerInfo(this, ntp_server, name); -#endif - } } /* *************************************** */ void Host::setImapServer(char *name) { - if (!isImapServer()) { + if (!isImapServer()) host_services_bitmap |= 1 << HOST_IS_IMAP_SERVER; - -#ifdef NTOPNG_PRO - ntop->get_am()->setServerInfo(this, imap_server, name); -#endif - } } /* *************************************** */ void Host::setPopServer(char *name) { - if (!isPopServer()) { + if (!isPopServer()) host_services_bitmap |= 1 << HOST_IS_POP_SERVER; - -#ifdef NTOPNG_PRO - ntop->get_am()->setServerInfo(this, pop_server, name); -#endif - } } /* *************************************** */ diff --git a/src/LocalHost.cpp b/src/LocalHost.cpp index 38047307477a..256161c357e8 100644 --- a/src/LocalHost.cpp +++ b/src/LocalHost.cpp @@ -778,3 +778,157 @@ void LocalHost::dumpAssetInfo() { ndpi_term_serializer(&device_json); } #endif + +/* *************************************** */ + +void LocalHost::setDhcpServer(char *name) { + bool previousDhcpServer = isDhcpServer(); + Host::setDhcpServer(name); + #ifdef NTOPNG_PRO + if (!previousDhcpServer && isDhcpServer()) + ntop->get_am()->setServerInfo(this, dhcp_server, name); + #endif +} + +/* *************************************** */ + +void LocalHost::setDnsServer(char *name) { + bool previous_DnsServer = isDnsServer(); + Host::setDnsServer(name); + #ifdef NTOPNG_PRO + if (!previous_DnsServer && isDnsServer()) + ntop->get_am()->setServerInfo(this, dns_server, name); + #endif +} + +/* *************************************** */ + +void LocalHost::setSmtpServer(char *name) { + bool previous_SmtpServer = isSmtpServer(); + Host::setSmtpServer(name); + #ifdef NTOPNG_PRO + if (!previous_SmtpServer && isSmtpServer()) + ntop->get_am()->setServerInfo(this, smtp_server, name); + #endif +} + +/* *************************************** */ + +void LocalHost::setNtpServer(char *name) { + bool previous_NtpServer = isNtpServer(); + Host::setNtpServer(name); + #ifdef NTOPNG_PRO + if (!previous_NtpServer && isNtpServer()) + ntop->get_am()->setServerInfo(this, ntp_server, name); + #endif +} + +/* *************************************** */ + +void LocalHost::setImapServer(char *name) { + bool previous_ImapServer = isImapServer(); + Host::setImapServer(name); + #ifdef NTOPNG_PRO + if (!previous_ImapServer && isImapServer()) + ntop->get_am()->setServerInfo(this, imap_server, name); + #endif +} + +/* *************************************** */ + +void LocalHost::setPopServer(char *name) { + bool previous_popServer = isPopServer(); + Host::setPopServer(name); + #ifdef NTOPNG_PRO + if (!previous_popServer && isPopServer()) + ntop->get_am()->setServerInfo(this, pop_server, name); + #endif +} + +/* *************************************** */ + +void LocalHost::offlineSetMDNSInfo(char *const str) { + bool previous_mdns_info = names.mdns_info ? true : false; + Host::offlineSetMDNSInfo(str); + #ifdef NTOPNG_PRO + if (names.mdns_info && !previous_mdns_info) + ntop->get_am()->setResolvedName(this, label_mdns_info, names.mdns_info); + #endif +} + +/* *************************************** */ + +void LocalHost::offlineSetMDNSName(const char *mdns_n) { + bool previous_mdns = names.mdns ? true : false; + Host::offlineSetMDNSName(mdns_n); + #ifdef NTOPNG_PRO + if (names.mdns && !previous_mdns) + ntop->get_am()->setResolvedName(this, label_mdns, names.mdns); + #endif +} + +/* *************************************** */ + +void LocalHost::offlineSetDHCPName(const char *dhcp_n) { + bool previous_dhcp = names.dhcp ? true : false; + Host::offlineSetDHCPName(dhcp_n); + #ifdef NTOPNG_PRO + if (names.dhcp && !previous_dhcp) + ntop->get_am()->setResolvedName(this, label_dhcp, names.dhcp); + #endif +} + +/* *************************************** */ + +void LocalHost::offlineSetMDNSTXTName(const char *mdns_n_txt) { + bool previous_mdns_txt = names.mdns_txt ? true : false; + Host::offlineSetMDNSTXTName(mdns_n_txt); + #ifdef NTOPNG_PRO + if (names.mdns_txt && !previous_mdns_txt) + ntop->get_am()->setResolvedName(this, label_mdns_txt, names.mdns_txt); + #endif +} + +/* *************************************** */ + +void LocalHost::offlineSetNetbiosName(const char *netbios_n) { + bool previous_netbios = names.netbios ? true : false; + Host::offlineSetNetbiosName(netbios_n); + #ifdef NTOPNG_PRO + if (names.netbios && !previous_netbios) + ntop->get_am()->setResolvedName(this, label_netbios, names.netbios); + #endif +} + +/* *************************************** */ + +void LocalHost::offlineSetHTTPName(const char *http_n) { + bool previous_http = names.http ? true : false; + Host::offlineSetHTTPName(http_n); + #ifdef NTOPNG_PRO + if(names.http && !previous_http) + ntop->get_am()->setResolvedName(this, label_http, names.http); + #endif +} + +/* *************************************** */ + +void LocalHost::setServerName(const char *server_n) { + bool previous_server_name = names.server_name ? true : false; + Host::setServerName(server_n); + #ifdef NTOPNG_PRO + if(names.server_name && !previous_server_name) + ntop->get_am()->setResolvedName(this, label_server_name, names.server_name); + #endif +} + +/* *************************************** */ + +void LocalHost::setResolvedName(const char *resolved_name) { + bool previous_resolved = names.resolved ? true : false; + Host::setResolvedName(resolved_name); + #ifdef NTOPNG_PRO + if(names.resolved && !previous_resolved) + ntop->get_am()->setResolvedName(this, label_resolver, names.resolved); + #endif +} \ No newline at end of file