NetworkController: Clear all clsact stubs in initialization
Test: build, atest
Change-Id: I9fb8cd2a0cd10d1dd516aad5e79876013a844b92
diff --git a/server/NetworkController.cpp b/server/NetworkController.cpp
index 6a11f92..4a5b5b3 100644
--- a/server/NetworkController.cpp
+++ b/server/NetworkController.cpp
@@ -36,6 +36,7 @@
#include "DummyNetwork.h"
#include "Fwmark.h"
#include "LocalNetwork.h"
+#include "OffloadUtils.h"
#include "PhysicalNetwork.h"
#include "RouteController.h"
#include "VirtualNetwork.h"
@@ -141,6 +142,22 @@
mProtectableUsers({AID_VPN}) {
mNetworks[LOCAL_NET_ID] = new LocalNetwork(LOCAL_NET_ID);
mNetworks[DUMMY_NET_ID] = new DummyNetwork(DUMMY_NET_ID);
+
+ // Clear all clsact stubs on all interfaces.
+ // TODO: perhaps only remove the clsact on the interface which is added by
+ // RouteController::addInterfaceToPhysicalNetwork. Currently, the netd only
+ // attach the clsact to the interface for the physical network.
+ if (bpf::isBpfSupported()) {
+ const auto& ifaces = InterfaceController::getIfaceNames();
+ if (isOk(ifaces)) {
+ for (const std::string& iface : ifaces.value()) {
+ if (int ifIndex = if_nametoindex(iface.c_str())) {
+ // Ignore the error because the interface might not have a clsact.
+ tcQdiscDelDevClsact(ifIndex);
+ }
+ }
+ }
+ }
}
unsigned NetworkController::getDefaultNetwork() const {