Skip to content

Commit

Permalink
Add atomic to check for concurrency issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cardigliano committed Aug 9, 2024
1 parent 112bf29 commit 0ba4c2f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions include/NetworkInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,14 @@ class NetworkInterface : public NetworkInterfaceAlertableEntity {
hostAlertsDequeueLoopCreated;
bool has_too_many_hosts, has_too_many_flows, mtuWarningShown;
bool flow_dump_disabled_by_user, flow_dump_disabled_by_backend;
u_int32_t ifSpeed, numL2Devices, totalNumHosts,
numTotalRxOnlyHosts /* subset of numTotalRxOnlyHosts that have received
u_int32_t ifSpeed, scalingFactor;
u_int32_t numL2Devices;
std::atomic<u_int64_t> totalNumHosts;
std::atomic<u_int64_t> numTotalRxOnlyHosts; /* subset of numTotalRxOnlyHosts that have received
but never sent any traffic */
,
numLocalHosts,
numLocalRxOnlyHosts /* subset of numLocalHosts that have received but
std::atomic<u_int64_t> numLocalHosts;
std::atomic<u_int64_t> numLocalRxOnlyHosts; /* subset of numLocalHosts that have received but
never sent any traffic */
,
scalingFactor;
/* Those will hold counters at checkpoints */
u_int64_t checkpointPktCount, checkpointBytesCount, checkpointPktDropCount,
checkpointDroppedAlertsCount;
Expand Down
2 changes: 1 addition & 1 deletion src/HostStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void HostStats::incStats(time_t when, u_int8_t l4_proto, u_int ndpi_proto,
sent_bytes);

if (host->isRxOnlyHost() && !isReceiveOnly()) /* no longer RX-only */
host->toggleRxOnlyHost(false);
host->toggleRxOnlyHost(false);
}

#ifdef NTOPNG_PRO
Expand Down
2 changes: 1 addition & 1 deletion src/NetworkInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11140,7 +11140,7 @@ void NetworkInterface::decNumHosts(bool local, bool rxOnlyHost) {
if(rxOnlyHost) {
/* Decrease total number of RX only hosts */
if (!numTotalRxOnlyHosts) {
ntop->getTrace()->traceEvent(TRACE_WARNING, "Internal Error (%d) on interface %s: Counter overflow", 3, ifname); // <---
ntop->getTrace()->traceEvent(TRACE_WARNING, "Internal Error (%d) on interface %s: Counter overflow", 3, ifname);
} else {
numTotalRxOnlyHosts--;
}
Expand Down
2 changes: 1 addition & 1 deletion src/RemoteHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ RemoteHost::RemoteHost(NetworkInterface *_iface, int32_t _iface_idx,
RemoteHost::~RemoteHost() {
/* Decrease number of active hosts */
if(isUnicastHost())
iface->decNumHosts(isLocalHost(), isRxOnlyHost());
iface->decNumHosts(isLocalHost(), is_rx_only);
}

/* *************************************** */
Expand Down

0 comments on commit 0ba4c2f

Please sign in to comment.