diff --git a/include/HostPools.h b/include/HostPools.h index 009e1a17fb..516fb280be 100644 --- a/include/HostPools.h +++ b/include/HostPools.h @@ -36,7 +36,7 @@ class HostPools { public: HostPools(NetworkInterface *_iface); - void reloadPools(u_int16_t pool_id); + void reloadPools(); u_int16_t getPool(Host *h); void addToPool(u_int16_t pool_id, u_int16_t vlan_id, int family, void *addr); }; diff --git a/include/NetworkInterface.h b/include/NetworkInterface.h index 6fce65802f..7d441d9085 100644 --- a/include/NetworkInterface.h +++ b/include/NetworkInterface.h @@ -380,7 +380,7 @@ class NetworkInterface { void updateHostsL7Policy(u_int16_t host_pool_id); void updateFlowsL7Policy(); #endif - void refreshHostPools(u_int16_t ost_pool_id); + void refreshHostPools(); inline u_int16_t getHostPool(Host *h) { if(h && host_pools) return host_pools->getPool(h); return NO_HOST_POOL_ID; }; diff --git a/src/HostPools.cpp b/src/HostPools.cpp index 67089fff0c..51158f58d5 100644 --- a/src/HostPools.cpp +++ b/src/HostPools.cpp @@ -28,10 +28,10 @@ HostPools::HostPools(NetworkInterface *_iface) { if(_iface) iface = _iface; - reloadPools(0); + reloadPools(); } -void HostPools::reloadPools(u_int16_t pool_id) { +void HostPools::reloadPools() { char kname[CONST_MAX_LEN_REDIS_KEY]; char **pools, **pool_members, *at, *member; int num_pools, num_members; @@ -83,14 +83,18 @@ void HostPools::reloadPools(u_int16_t pool_id) { bool rc; _pool_id = (u_int16_t)atoi(pools[i]); - rc = new_tree[vlan_id]->addAddress(member, _pool_id); - + if(!(rc = new_tree[vlan_id]->addAddress(member, _pool_id)) #ifdef HOST_POOLS_DEBUG - ntop->getTrace()->traceEvent(TRACE_NORMAL, "%s tree node for %s [vlan %i] [host pool: %s]", - rc ? "Successfully added" : "Unable to add", - member, vlan_id, - pools[i]); + || true #endif + ) + + ntop->getTrace()->traceEvent(rc ? TRACE_WARNING : TRACE_NORMAL, + "%s tree node for %s [vlan %i] [host pool: %s]", + rc ? "Successfully added" : "Unable to add", + member, vlan_id, + pools[i]); + } free(member); @@ -114,7 +118,7 @@ void HostPools::reloadPools(u_int16_t pool_id) { tree = new_tree; - iface->refreshHostPools(pool_id); + iface->refreshHostPools(); } u_int16_t HostPools::getPool(Host *h) { diff --git a/src/Lua.cpp b/src/Lua.cpp index df17df4704..e9a5dee491 100644 --- a/src/Lua.cpp +++ b/src/Lua.cpp @@ -3250,13 +3250,8 @@ static int ntop_reload_host_pools(lua_State *vm) { ntop->getTrace()->traceEvent(TRACE_DEBUG, "%s() called", __FUNCTION__); if(ntop_interface) { - u_int16_t host_pool_id; - if(ntop_lua_check(vm, __FUNCTION__, 1, LUA_TNUMBER)) return(CONST_LUA_PARAM_ERROR); - - host_pool_id = (u_int16_t)lua_tonumber(vm, 1); - - ntop_interface->getHostPools()->reloadPools(host_pool_id); + ntop_interface->getHostPools()->reloadPools(); return(CONST_LUA_OK); } else diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp index 522fa679da..987d86dd1f 100644 --- a/src/NetworkInterface.cpp +++ b/src/NetworkInterface.cpp @@ -1941,7 +1941,6 @@ void NetworkInterface::periodicStatsUpdate() { /* **************************************************** */ struct update_host_pool_l7policy { - u_int16_t host_pool_id; bool update_pool_id; bool update_l7policy; }; @@ -1949,50 +1948,42 @@ struct update_host_pool_l7policy { static bool update_host_host_pool_l7policy(GenericHashEntry *node, void *user_data) { Host *h = (Host*)node; update_host_pool_l7policy *up = (update_host_pool_l7policy*)user_data; - u_int16_t cur_pool_id = h->get_host_pool(); - - if((up->host_pool_id == NO_HOST_POOL_ID) - || (cur_pool_id == NO_HOST_POOL_ID) - || (up->host_pool_id == cur_pool_id)) { - - if(up->update_pool_id) - h->updateHostPool(); - - if(up->update_l7policy) - h->updateHostL7Policy(); - #ifdef HOST_POOLS_DEBUG - char buf[128]; - ntop->getTrace()->traceEvent(TRACE_NORMAL, - "Going to refresh pool for %s " - "[refresh pool id: %i] " - "[refresh l7policy: %i] " - "[pool id to refresh: %i] " - "[host pool id before refresh: %i] " - "[host pool id after refresh: %i] ", - h->get_ip()->print(buf, sizeof(buf)), - up->update_pool_id ? 1 : 0, - up->update_l7policy ? 1 : 0, - up->host_pool_id, - cur_pool_id, - h->get_host_pool()); + char buf[128]; + u_int16_t cur_pool_id = h->get_host_pool(); #endif - } + if(up->update_pool_id) + h->updateHostPool(); + + if(up->update_l7policy) + h->updateHostL7Policy(); + +#ifdef HOST_POOLS_DEBUG + + ntop->getTrace()->traceEvent(TRACE_NORMAL, + "Going to refresh pool for %s " + "[refresh pool id: %i] " + "[refresh l7policy: %i] " + "[host pool id before refresh: %i] " + "[host pool id after refresh: %i] ", + h->get_ip()->print(buf, sizeof(buf)), + up->update_pool_id ? 1 : 0, + up->update_l7policy ? 1 : 0, + cur_pool_id, + h->get_host_pool()); + +#endif return(false); /* false = keep on walking */ } /* **************************************************** */ -void NetworkInterface::refreshHostPools(u_int16_t host_pool_id) { +void NetworkInterface::refreshHostPools() { if(isView()) return; - - struct update_host_pool_l7policy update_host; - update_host.host_pool_id = host_pool_id; - update_host.update_pool_id = true; update_host.update_l7policy = false; @@ -2031,7 +2022,6 @@ void NetworkInterface::updateHostsL7Policy(u_int16_t host_pool_id) { if(isView()) return; struct update_host_pool_l7policy update_host; - update_host.host_pool_id = host_pool_id; update_host.update_pool_id = false; update_host.update_l7policy = true;