diff options
author | Maciej Żenczykowski <maze@google.com> | 2020-06-03 02:18:53 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-06-03 02:18:53 +0000 |
commit | 63f08abe0e8f2b0b20b33076929977083ef6a4fc (patch) | |
tree | 78403ff0b4e610944bcedce389485e4e759d58c2 | |
parent | 60118314b724ce80dd30720b2127c8ab7bd42cc5 (diff) | |
parent | ba667df1c1f52c77c8bfefa55957c7e270b6e842 (diff) | |
download | platform_external_android-clat-63f08abe0e8f2b0b20b33076929977083ef6a4fc.tar.gz platform_external_android-clat-63f08abe0e8f2b0b20b33076929977083ef6a4fc.tar.bz2 platform_external_android-clat-63f08abe0e8f2b0b20b33076929977083ef6a4fc.zip |
cleanup - read_config() and ipv4_local_prefixlen am: ba667df1c1
Original change: https://android-review.googlesource.com/c/platform/external/android-clat/+/1322226
Change-Id: I6a3d6a123c6e01a9034e0701bfedac2667db25b0
-rw-r--r-- | clatd.c | 10 | ||||
-rw-r--r-- | clatd.conf | 1 | ||||
-rw-r--r-- | clatd_test.cpp | 4 | ||||
-rw-r--r-- | config.c | 34 | ||||
-rw-r--r-- | config.h | 4 |
5 files changed, 5 insertions, 48 deletions
@@ -98,7 +98,7 @@ int configure_packet_socket(int sock) { struct sockaddr_ll sll = { .sll_family = AF_PACKET, .sll_protocol = htons(ETH_P_IPV6), - .sll_ifindex = if_nametoindex(Global_Clatd_Config.default_pdp_interface), + .sll_ifindex = if_nametoindex(Global_Clatd_Config.native_ipv6_interface), .sll_pkttype = PACKET_OTHERHOST, // The 464xlat IPv6 address is not assigned to the kernel. }; if (bind(sock, (struct sockaddr *)&sll, sizeof(sll))) { @@ -318,11 +318,7 @@ int detect_mtu(const struct in6_addr *plat_subnet, uint32_t plat_suffix, uint32_ */ void configure_interface(const char *uplink_interface, const char *plat_prefix, const char *v4_addr, const char *v6_addr, struct tun_data *tunnel, uint32_t mark) { - if (!read_config("/system/etc/clatd.conf", uplink_interface)) { - logmsg(ANDROID_LOG_FATAL, "read_config failed"); - exit(1); - } - + Global_Clatd_Config.native_ipv6_interface = uplink_interface; if (!plat_prefix || inet_pton(AF_INET6, plat_prefix, &Global_Clatd_Config.plat_subnet) <= 0) { logmsg(ANDROID_LOG_FATAL, "invalid IPv6 address specified for plat prefix: %s", plat_prefix); exit(1); @@ -430,7 +426,7 @@ void event_loop(struct tun_data *tunnel) { time_t now = time(NULL); if (last_interface_poll < (now - INTERFACE_POLL_FREQUENCY)) { - if (ipv6_address_changed(Global_Clatd_Config.default_pdp_interface)) { + if (ipv6_address_changed(Global_Clatd_Config.native_ipv6_interface)) { break; } } @@ -1 +0,0 @@ -temporary_placeholder 0 diff --git a/clatd_test.cpp b/clatd_test.cpp index e24b036..514aaa8 100644 --- a/clatd_test.cpp +++ b/clatd_test.cpp @@ -585,7 +585,7 @@ class ClatdTest : public ::testing::Test { inet_pton(AF_INET, kIPv4LocalAddr, &Global_Clatd_Config.ipv4_local_subnet); inet_pton(AF_INET6, kIPv6PlatSubnet, &Global_Clatd_Config.plat_subnet); memset(&Global_Clatd_Config.ipv6_local_subnet, 0, sizeof(in6_addr)); - Global_Clatd_Config.default_pdp_interface = const_cast<char *>(sTun.name().c_str()); + Global_Clatd_Config.native_ipv6_interface = const_cast<char *>(sTun.name().c_str()); } // Static because setting up the tun interface takes about 40ms. @@ -631,8 +631,6 @@ TEST_F(ClatdTest, DetectMtu) { } TEST_F(ClatdTest, ConfigureTunIpManual) { - Global_Clatd_Config.ipv4_local_prefixlen = 29; - // Create an interface for configure_tun_ip to configure and bring up. TunInterface v4Iface; ASSERT_EQ(0, v4Iface.init()); @@ -42,37 +42,3 @@ struct clat_config Global_Clatd_Config; * returns: 0 if the subnets are different, 1 if they are the same. */ int ipv6_prefix_equal(struct in6_addr *a1, struct in6_addr *a2) { return !memcmp(a1, a2, 8); } - -/* function: read_config - * reads the config file and parses it into the global variable Global_Clatd_Config. returns 0 on - * failure, 1 on success - * file - filename to parse - * uplink_interface - interface to use to reach the internet and supplier of address space - */ -int read_config(const char *file, const char *uplink_interface) { - cnode *root = config_node("", ""); - - if (!root) { - logmsg(ANDROID_LOG_FATAL, "out of memory"); - return 0; - } - - memset(&Global_Clatd_Config, '\0', sizeof(Global_Clatd_Config)); - - config_load_file(root, file); - if (root->first_child == NULL) { - logmsg(ANDROID_LOG_FATAL, "Could not read config file %s", file); - goto failed; - } - - Global_Clatd_Config.default_pdp_interface = strdup(uplink_interface); - if (!Global_Clatd_Config.default_pdp_interface) goto failed; - - Global_Clatd_Config.ipv4_local_prefixlen = 29; - - return 1; - -failed: - free(root); - return 0; -} @@ -24,14 +24,12 @@ struct clat_config { struct in6_addr ipv6_local_subnet; struct in_addr ipv4_local_subnet; - int16_t ipv4_local_prefixlen; struct in6_addr plat_subnet; - char *default_pdp_interface; + const char *native_ipv6_interface; }; extern struct clat_config Global_Clatd_Config; -int read_config(const char *file, const char *uplink_interface); int ipv6_prefix_equal(struct in6_addr *a1, struct in6_addr *a2); #endif /* __CONFIG_H__ */ |