Do not destroy socket when VPN interface address is still in use
Normally when an IP address is removed, all sockets associated with the
addresses are destroyed. This patchset changes this behavior such that
if the address in question is still being used by another interface that
belongs to the same underlying virtual network, the destroy operation is
skipped. This change is needed to support VPN seamless handover where the
VPN app will establish a second TUN interface (with different config)
before tearing down the existing interface. The intention is that during
this handover existing socket connections should not be disturbed. There
is a companion change in the framework side to make sure during such
handover, the VPN netId remains unchanged so routing still works.
Bug: 64692591
Test: cts-tradefed run commandAndExit cts-dev -m CtsHostsideNetworkTests -t com.android.cts.net.HostsideVpnTests
Test: system/netd/tests/runtests.sh
Change-Id: I02c6b0db5f15cd1aef3e3fa6f0c36e86b4f427fd
Merged-In: I02c6b0db5f15cd1aef3e3fa6f0c36e86b4f427fd
(cherry picked from commit acbb6b7bbea17c5653929ee5224bd4f8e16c0f69)
diff --git a/server/RouteController.h b/server/RouteController.h
index de79b61..6e10cce 100644
--- a/server/RouteController.h
+++ b/server/RouteController.h
@@ -45,6 +45,15 @@
static int Init(unsigned localNetId) WARN_UNUSED_RESULT;
+ // Returns an ifindex given the interface name, by looking up in sInterfaceToTable.
+ // This is currently only used by NetworkController::addInterfaceToNetwork
+ // and should probabaly be changed to passing the ifindex into RouteController instead.
+ // We do this instead of calling if_nametoindex because the same interface name can
+ // correspond to different interface indices over time. This way, even if the interface
+ // index has changed, we can still free any map entries indexed by the ifindex that was
+ // used to add them.
+ static uint32_t getIfIndex(const char* interface);
+
static int addInterfaceToLocalNetwork(unsigned netId, const char* interface) WARN_UNUSED_RESULT;
static int removeInterfaceFromLocalNetwork(unsigned netId,
const char* interface) WARN_UNUSED_RESULT;