clatd: remove ipv6 address monitoring
This code/logic is spurious, because the majority of packets
are translated by eBPF, so whether the daemon runs or not,
usually just doesn't matter - bpf will handle them anyway.
As such what we actually care about is that the daemon
is terminated at the same time as the bpf map configuration
is removed. This is done by jni native code stopClatdProcess()
which is called from ClatCoordinator java code immediately
after maybeStopBpf().
Additionally on ipv6 address change we don't even terminate
the daemon - we simply stop the event loop, but still block
in main() until we receive SIGTERM/SIGKILL.
(This was done a while ago to fix a bunch of issues with
daemon dieing and being killed racing with each other)
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I86d203a244838166ed1fbec1bc48a680e433f9fa
diff --git a/clatd.c b/clatd.c
index d1bfa5e..7cee4e8 100644
--- a/clatd.c
+++ b/clatd.c
@@ -44,7 +44,6 @@
#include "checksum.h"
#include "config.h"
#include "dump.h"
-#include "getaddr.h"
#include "logging.h"
#include "translate.h"
@@ -55,29 +54,6 @@
volatile sig_atomic_t running = 1;
-int ipv6_address_changed(const char *interface) {
- union anyip *interface_ip;
-
- 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 1;
- }
-
- if (!ipv6_prefix_equal(&interface_ip->ip6, &Global_Clatd_Config.ipv6_local_subnet)) {
- char oldstr[INET6_ADDRSTRLEN];
- char newstr[INET6_ADDRSTRLEN];
- inet_ntop(AF_INET6, &Global_Clatd_Config.ipv6_local_subnet, oldstr, sizeof(oldstr));
- inet_ntop(AF_INET6, &interface_ip->ip6, newstr, sizeof(newstr));
- logmsg(ANDROID_LOG_INFO, "IPv6 prefix on %s changed: %s -> %s", interface, oldstr, newstr);
- free(interface_ip);
- return 1;
- } else {
- free(interface_ip);
- return 0;
- }
-}
-
// reads IPv6 packet from AF_PACKET socket, translates to IPv4, writes to tun
void process_packet_6_to_4(struct tun_data *tunnel) {
// ethernet header is 14 bytes, plus 4 for a normal VLAN tag or 8 for Q-in-Q
@@ -300,17 +276,13 @@
// TODO: actually perform true DAD
send_dad(tunnel->write_fd6, &Global_Clatd_Config.ipv6_local_subnet);
- time_t last_interface_poll;
struct pollfd wait_fd[] = {
{ tunnel->read_fd6, POLLIN, 0 },
{ tunnel->fd4, POLLIN, 0 },
};
- // start the poll timer
- last_interface_poll = time(NULL);
-
while (running) {
- if (poll(wait_fd, ARRAY_SIZE(wait_fd), NO_TRAFFIC_INTERFACE_POLL_FREQUENCY * 1000) == -1) {
+ if (poll(wait_fd, ARRAY_SIZE(wait_fd), -1) == -1) {
if (errno != EINTR) {
logmsg(ANDROID_LOG_WARN, "event_loop/poll returned an error: %s", strerror(errno));
}
@@ -323,13 +295,5 @@
if (wait_fd[0].revents) process_packet_6_to_4(tunnel);
if (wait_fd[1].revents) process_packet_4_to_6(tunnel);
}
-
- time_t now = time(NULL);
- if (now >= (last_interface_poll + INTERFACE_POLL_FREQUENCY)) {
- last_interface_poll = now;
- if (ipv6_address_changed(Global_Clatd_Config.native_ipv6_interface)) {
- break;
- }
- }
}
}