summaryrefslogtreecommitdiffstats
path: root/clatd.c
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2013-03-27 12:39:10 +0900
committerLorenzo Colitti <lorenzo@google.com>2013-03-27 15:46:47 +0900
commit3ca0302031b14c6fcb9be147e875fb794bfc583b (patch)
treedd895a75638c8df0b418b6ccfc7273158a13566d /clatd.c
parent41e758e33e6c3b43f363591d4113dea54a4330d9 (diff)
downloadandroid_external_android-clat-3ca0302031b14c6fcb9be147e875fb794bfc583b.tar.gz
android_external_android-clat-3ca0302031b14c6fcb9be147e875fb794bfc583b.tar.bz2
android_external_android-clat-3ca0302031b14c6fcb9be147e875fb794bfc583b.zip
Configure the interface before bringing it up
Currently, clatd brings the clat4 interface up before assigning its IPv4 address. This can cause a race condition, because as soon as the interface comes up, the framework notices and reads the interface configuration into the LinkProperties. If this happens before the IPv4 address is configured, then the framework ends up thinking clat4's IPv4 address is 0.0.0.0/0. Fix this by configuring the address before the interface is brought up. Currently the framework does not use this address for anything, so this is purely cosmetic, but it could make debugging more confusing. Bug: 8276725 Change-Id: I2bfee586a0d70050c53b10cc3f7eb9a98173e11d
Diffstat (limited to 'clatd.c')
-rw-r--r--clatd.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/clatd.c b/clatd.c
index ea8363c..edd8a2d 100644
--- a/clatd.c
+++ b/clatd.c
@@ -192,25 +192,26 @@ void interface_poll(const struct tun_data *tunnel) {
* tunnel - tun device data
*/
void configure_tun_ip(const struct tun_data *tunnel) {
- struct in_addr default_4;
int status;
- default_4.s_addr = INADDR_ANY;
+ // Configure the interface before bringing it up. As soon as we bring the interface up, the
+ // framework will be notified and will assume the interface's configuration has been finalized.
+ status = add_address(tunnel->device4, AF_INET, &Global_Clatd_Config.ipv4_local_subnet,
+ 32, &Global_Clatd_Config.ipv4_local_subnet);
+ if(status < 0) {
+ logmsg(ANDROID_LOG_FATAL,"configure_tun_ip/if_address(4) failed: %s",strerror(-status));
+ exit(1);
+ }
if((status = if_up(tunnel->device6, Global_Clatd_Config.mtu)) < 0) {
logmsg(ANDROID_LOG_FATAL,"configure_tun_ip/if_up(6) failed: %s",strerror(-status));
exit(1);
}
+
if((status = if_up(tunnel->device4, Global_Clatd_Config.ipv4mtu)) < 0) {
logmsg(ANDROID_LOG_FATAL,"configure_tun_ip/if_up(4) failed: %s",strerror(-status));
exit(1);
}
- status = add_address(tunnel->device4, AF_INET, &Global_Clatd_Config.ipv4_local_subnet,
- 32, &Global_Clatd_Config.ipv4_local_subnet);
- if(status < 0) {
- logmsg(ANDROID_LOG_FATAL,"configure_tun_ip/if_address(4) failed: %s",strerror(-status));
- exit(1);
- }
configure_tun_ipv6(tunnel);
}