diff options
author | Paul Jensen <pauljensen@google.com> | 2014-05-30 13:19:10 -0400 |
---|---|---|
committer | Lorenzo Colitti <lorenzo@google.com> | 2014-06-13 11:47:35 +0900 |
commit | 247dd7199b4e89c6a974794056b468bfac5f0e51 (patch) | |
tree | 53efe2a41e590496c9414436f602165bf86d96a0 /clatd.c | |
parent | e64eccb68b8101d8fa2effb826e185db7f82dba9 (diff) | |
download | platform_external_android-clat-247dd7199b4e89c6a974794056b468bfac5f0e51.tar.gz platform_external_android-clat-247dd7199b4e89c6a974794056b468bfac5f0e51.tar.bz2 platform_external_android-clat-247dd7199b4e89c6a974794056b468bfac5f0e51.zip |
Make DNS request for plat prefix detection network specific.
When plat prefix detection is done on a non-default network it
must use the network specific version of getaddrinfo() so the
plat prefix corresponds to the particular network. The network
is specified to clatd via a NetID command line argument.
(cherry picked from commit a1c871c8efad6c0b69e27d3b85e82a27e282b8be)
Change-Id: I270c5afc4b445cf20e95fd3e58eada6bc24b16ef
Diffstat (limited to 'clatd.c')
-rw-r--r-- | clatd.c | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -42,6 +42,7 @@ #include "clatd.h" #include "config.h" #include "logging.h" +#include "resolv_netid.h" #include "setif.h" #include "setroute.h" #include "mtu.h" @@ -252,11 +253,12 @@ void drop_root() { * uplink_interface - network interface to use to reach the ipv6 internet * plat_prefix - PLAT prefix to use * tunnel - tun device data + * net_id - NetID to use, NETID_UNSET indicates use of default network */ -void configure_interface(const char *uplink_interface, const char *plat_prefix, struct tun_data *tunnel) { +void configure_interface(const char *uplink_interface, const char *plat_prefix, struct tun_data *tunnel, unsigned net_id) { int error; - if(!read_config("/system/etc/clatd.conf", uplink_interface, plat_prefix)) { + if(!read_config("/system/etc/clatd.conf", uplink_interface, plat_prefix, net_id)) { logmsg(ANDROID_LOG_FATAL,"read_config failed"); exit(1); } @@ -374,6 +376,7 @@ void print_help() { printf("android-clat arguments:\n"); printf("-i [uplink interface]\n"); printf("-p [plat prefix]\n"); + printf("-n [NetId]\n"); } /* function: main @@ -382,12 +385,13 @@ void print_help() { int main(int argc, char **argv) { struct tun_data tunnel; int opt; - char *uplink_interface = NULL, *plat_prefix = NULL; + char *uplink_interface = NULL, *plat_prefix = NULL, *net_id_str = NULL; + unsigned net_id = NETID_UNSET; strcpy(tunnel.device6, DEVICENAME6); strcpy(tunnel.device4, DEVICENAME4); - while((opt = getopt(argc, argv, "i:p:h")) != -1) { + while((opt = getopt(argc, argv, "i:p:n:h")) != -1) { switch(opt) { case 'i': uplink_interface = optarg; @@ -395,6 +399,9 @@ int main(int argc, char **argv) { case 'p': plat_prefix = optarg; break; + case 'n': + net_id_str = optarg; + break; case 'h': default: print_help(); @@ -408,6 +415,14 @@ int main(int argc, char **argv) { printf("I need an interface\n"); exit(1); } + if (net_id_str != NULL) { + char *end_ptr; + net_id = strtoul(net_id_str, &end_ptr, 0); + if (net_id == ULONG_MAX || *net_id_str == 0 || *end_ptr != 0) { + logmsg(ANDROID_LOG_FATAL, "clatd called with invalid NetID %s", net_id_str); + exit(1); + } + } logmsg(ANDROID_LOG_INFO, "Starting clat version %s on %s", CLATD_VERSION, uplink_interface); // open the tunnel device before dropping privs @@ -438,7 +453,7 @@ int main(int argc, char **argv) { // "local", but that only works for the netd process itself. unsetenv("ANDROID_DNS_MODE"); - configure_interface(uplink_interface, plat_prefix, &tunnel); + configure_interface(uplink_interface, plat_prefix, &tunnel, net_id); set_forwarding(forwarding_fd,"1\n"); |