Delete the clatd code that assigns IPv4 and IPv6 addresses.
The IPv4 and IPv6 address assignment code, and its tests, were
migrated to ClatdController in Q, and this code has been unused
since then.
This code is not only unused, it also *should* never be used,
because if it were, many parts of 464xlat on Android would not
work as expected. This includes 464xlat BPF offload and data
usage accounting, both of which require netd to know exactly
which IPv4 and IPv6 addresses are used by clatd at any given
time.
Most of the code is deleted, but the function to generate random
checksum-neutral IIDs was moved to the tests instead.
This change does not delete the configuration file parsing code.
That will be done in a follow-up CL.
Bug: 144730808
Bug: 150738490
Test: atest clatd_test
Test: atest netd_integration_test
Test: IPv6-only wifi continues to work
Change-Id: I8265e9bb04d44ed1dda445fa91881fcd1601dc47
diff --git a/clatd.c b/clatd.c
index 3f9dc71..50693f5 100644
--- a/clatd.c
+++ b/clatd.c
@@ -109,52 +109,15 @@
return 1;
}
-/* function: ipv4_address_generate
- * picks a free IPv4 address from the local subnet or exits if there are no free addresses
- * returns: the IPv4 address as an in_addr_t
- */
-static in_addr_t ipv4_address_generate() {
- // Pick an IPv4 address to use by finding a free address in the configured prefix. Technically,
- // there is a race here - if another clatd calls config_select_ipv4_address after we do, but
- // before we call add_address, it can end up having the same IP address as we do. But the time
- // window in which this can happen is extremely small, and even if we end up with a duplicate
- // address, the only damage is that IPv4 TCP connections won't be reset until both interfaces go
- // down.
- in_addr_t localaddr = config_select_ipv4_address(&Global_Clatd_Config.ipv4_local_subnet,
- Global_Clatd_Config.ipv4_local_prefixlen);
- if (localaddr == INADDR_NONE) {
- logmsg(ANDROID_LOG_FATAL, "No free IPv4 address in %s/%d",
- inet_ntoa(Global_Clatd_Config.ipv4_local_subnet),
- Global_Clatd_Config.ipv4_local_prefixlen);
- exit(1);
- }
- return localaddr;
-}
-
-/* function: ipv4_address_from_cmdline
- * configures the IPv4 address specified on the command line, or exits if the address is not valid
- * v4_addr - a string, the IPv4 address
- * returns: the IPv4 address as an in_addr_t
- */
-static in_addr_t ipv4_address_from_cmdline(const char *v4_addr) {
- in_addr_t localaddr;
- if (!inet_pton(AF_INET, v4_addr, &localaddr)) {
- logmsg(ANDROID_LOG_FATAL, "Invalid IPv4 address %s", v4_addr);
- exit(1);
- }
- return localaddr;
-}
-
/* function: configure_tun_ip
* configures the ipv4 and ipv6 addresses on the tunnel interface
* tunnel - tun device data
* mtu - mtu of tun device
*/
void configure_tun_ip(const struct tun_data *tunnel, const char *v4_addr, int mtu) {
- if (v4_addr) {
- Global_Clatd_Config.ipv4_local_subnet.s_addr = ipv4_address_from_cmdline(v4_addr);
- } else {
- Global_Clatd_Config.ipv4_local_subnet.s_addr = ipv4_address_generate();
+ if (!v4_addr || !inet_pton(AF_INET, v4_addr, &Global_Clatd_Config.ipv4_local_subnet.s_addr)) {
+ logmsg(ANDROID_LOG_FATAL, "Invalid IPv4 address %s", v4_addr);
+ exit(1);
}
char addrstr[INET_ADDRSTRLEN];
@@ -272,43 +235,6 @@
}
}
-/* function: clat_ipv6_address_from_interface
- * picks the clat IPv6 address based on the interface address
- * interface - uplink interface name
- * returns: 1 on success, 0 on failure
- */
-static int clat_ipv6_address_from_interface(const char *interface) {
- union anyip *interface_ip;
-
- // TODO: check that the prefix length is /64.
- interface_ip = getinterface_ip(interface, AF_INET6);
- if (!interface_ip) {
- logmsg(ANDROID_LOG_ERROR, "Unable to find an IPv6 address on interface %s", interface);
- return 0;
- }
-
- // Generate an interface ID.
- config_generate_local_ipv6_subnet(&interface_ip->ip6);
-
- Global_Clatd_Config.ipv6_local_subnet = interface_ip->ip6;
- free(interface_ip);
- return 1;
-}
-
-/* function: clat_ipv6_address_from_cmdline
- * parses the clat IPv6 address from the command line
- * v4_addr - a string, the IPv6 address
- * returns: 1 on success, 0 on failure
- */
-static int clat_ipv6_address_from_cmdline(const char *v6_addr) {
- if (!inet_pton(AF_INET6, v6_addr, &Global_Clatd_Config.ipv6_local_subnet)) {
- logmsg(ANDROID_LOG_FATAL, "Invalid source address %s", v6_addr);
- return 0;
- }
-
- return 1;
-}
-
/* function: configure_clat_ipv6_address
* picks the clat IPv6 address and configures packet translation to use it.
* tunnel - tun device data
@@ -317,13 +243,10 @@
*/
int configure_clat_ipv6_address(const struct tun_data *tunnel, const char *interface,
const char *v6_addr) {
- int ret;
- if (v6_addr) {
- ret = clat_ipv6_address_from_cmdline(v6_addr);
- } else {
- ret = clat_ipv6_address_from_interface(interface);
+ if (!v6_addr || !inet_pton(AF_INET6, v6_addr, &Global_Clatd_Config.ipv6_local_subnet)) {
+ logmsg(ANDROID_LOG_FATAL, "Invalid source address %s", v6_addr);
+ return 0;
}
- if (!ret) return 0;
char addrstr[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &Global_Clatd_Config.ipv6_local_subnet, addrstr, sizeof(addrstr));