ClatdTracker - do not store pointer to NetworkController

Test: build, atest libbpf_android_test libnetdbpf_test netd_integration_test netd_unit_test netdutils_test resolv_integration_test resolv_unit_test
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I677f40fa5f3694ecdc33be999996768e4e851480
diff --git a/server/ClatdController.cpp b/server/ClatdController.cpp
index 50880f8..77eaf5a 100644
--- a/server/ClatdController.cpp
+++ b/server/ClatdController.cpp
@@ -342,14 +342,9 @@
 }
 
 // Initializes a ClatdTracker for the specified interface.
-int ClatdController::ClatdTracker::init(const std::string& interface,
+int ClatdController::ClatdTracker::init(unsigned networkId, const std::string& interface,
                                         const std::string& nat64Prefix) {
-    netId = netCtrl->getNetworkForInterface(interface.c_str());
-    if (netId == NETID_UNSET) {
-        ALOGE("Interface %s not assigned to any netId", interface.c_str());
-        errno = ENODEV;
-        return -errno;
-    }
+    netId = networkId;
 
     fwmark.netId = netId;
     fwmark.explicitlySelected = true;
@@ -406,11 +401,17 @@
         return -errno;
     }
 
-    ClatdTracker tracker(mNetCtrl);
-    if (int ret = tracker.init(interface, nat64Prefix)) {
-        return ret;
+    unsigned networkId = mNetCtrl->getNetworkForInterface(interface.c_str());
+    if (networkId == NETID_UNSET) {
+        ALOGE("Interface %s not assigned to any netId", interface.c_str());
+        errno = ENODEV;
+        return -errno;
     }
 
+    ClatdTracker tracker;
+    int ret = tracker.init(networkId, interface, nat64Prefix);
+    if (ret) return ret;
+
     std::string progname("clatd-");
     progname += tracker.iface;
 
diff --git a/server/ClatdController.h b/server/ClatdController.h
index c93d298..2ea8ee8 100644
--- a/server/ClatdController.h
+++ b/server/ClatdController.h
@@ -54,7 +54,6 @@
 
   private:
     struct ClatdTracker {
-        const NetworkController* netCtrl = nullptr;
         pid_t pid = -1;
         unsigned ifIndex;
         char iface[IFNAMSIZ];
@@ -69,10 +68,7 @@
         in6_addr pfx96;
         char pfx96String[INET6_ADDRSTRLEN];
 
-        ClatdTracker() = default;
-        explicit ClatdTracker(const NetworkController* netCtrl) : netCtrl(netCtrl) {}
-
-        int init(const std::string& interface, const std::string& nat64Prefix);
+        int init(unsigned networkId, const std::string& interface, const std::string& nat64Prefix);
     };
 
     std::mutex mutex;