Support DNS64 synthesis using externally-discovered prefixes.
Currently, the DNS resolver supports DNS64 synthesis only for
prefixes that it discovered itself, and not for NAT64 prefixes
discovered via other means (e.g., RA).
Add a way to set a NAT64 prefix that was discovered by other
means. This new IPC is mutually exclusive with the existing
prefix discovery mechansisms:
- Setting the prefix has no effect if prefix discovery is
started.
- Starting (or stopping) prefix discovery clears the prefix.
- Setting the prefix does not result in any NAT64 prefix update
callback.
It is the responsibility of the caller (ConnectivityService,
Nat464Xlat) to ensure that prefix discovery is stopped before
setting the prefix.
This does not add any significant complexity to the connectivity
code, and it ensures that the behaviour of the existing IPCs
(startPrefix64Discovery and stopPrefix64Discovery) are unchanged.
This is necessary to ensure that DNS64 synthesis continues to
work on Q devices.
Disallowing concurrent use of prefix discovery and externally-set
prefixes also simplifies the implementation because it allows
reuse of most of the data structures and teardown code in
Dns64Configuration. The externally-set prefix is represented by a
Dns64Configuration with a special discovery ID of kNoDiscoveryId
(== 0), which cannot be used by any discovery attempt. That way,
if discovery is started, then stopped, and then the prefix is
set, if a stale discovery thread then completes, it will be
ignored because the thread's ID cannot be kNoDiscoveryId.
Bug: 153694684
Bug: 156914456
Test: new tests in resolv_integration_test
Original-Change: https://android-review.googlesource.com/1313740
Merged-In: I7c63fb62b70635a1b5cc7a21d60f091ba2705d72
Change-Id: I7c63fb62b70635a1b5cc7a21d60f091ba2705d72
diff --git a/Dns64Configuration.h b/Dns64Configuration.h
index 211079a..c06a6c1 100644
--- a/Dns64Configuration.h
+++ b/Dns64Configuration.h
@@ -82,6 +82,9 @@
void stopPrefixDiscovery(unsigned netId);
netdutils::IPPrefix getPrefix64(unsigned netId) const;
+ int setPrefix64(unsigned netId, const netdutils::IPPrefix* pfx);
+ int clearPrefix64(unsigned netId);
+
void dump(netdutils::DumpWriter& dw, unsigned netId);
private:
@@ -89,16 +92,24 @@
Dns64Config(unsigned pseudoRandomId, unsigned network)
: discoveryId(pseudoRandomId), netId(network) {}
+ // ID of the discovery operation, or kNoDiscoveryId if no discovery was performed (i.e., the
+ // prefix was discovered and passed in via setPrefix64).
const unsigned int discoveryId;
const unsigned int netId;
netdutils::IPPrefix prefix64{};
+
+ bool isFromPrefixDiscovery() const { return discoveryId != kNoDiscoveryId; }
};
+ static constexpr int kNoDiscoveryId = 0;
+
enum { PREFIX_REMOVED, PREFIX_ADDED };
static bool doRfc7050PrefixDiscovery(const android_net_context& netcontext, Dns64Config* cfg);
- unsigned getNextId() REQUIRES(mMutex) { return mNextId++; }
+ // Picks the next discovery ID. Never returns kNoDiscoveryId.
+ unsigned getNextId() REQUIRES(mMutex) { return ++mNextId ? mNextId : ++mNextId; }
+
netdutils::IPPrefix getPrefix64Locked(unsigned netId) const REQUIRES(mMutex);
bool isDiscoveryInProgress(const Dns64Config& cfg) const REQUIRES(mMutex);
bool reportNat64PrefixStatus(unsigned netId, bool added, const netdutils::IPPrefix& pfx)