From 48d5a1d50750ffa5d14b64841fc7e81dadafd1a4 Mon Sep 17 00:00:00 2001 From: Irfan Sheriff Date: Wed, 23 May 2012 11:51:34 -0700 Subject: Reuse system properties for p2p p2p interfaces keep increasing. Reuse a single "p2p" phrase to track all p2p specific properties. Longer term, we will remove the use of system properties for dhcp Bug: 6522164 Change-Id: Ic9c54dc1904d2e1e8c33bbbc17234ed801f845dc --- dhcpcd-hooks/20-dns.conf | 13 ++++++++++--- dhcpcd-hooks/95-configured | 27 +++++++++++++++++---------- dhcpcd.c | 18 ++++++++++++++++-- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/dhcpcd-hooks/20-dns.conf b/dhcpcd-hooks/20-dns.conf index a92e91d..6165824 100644 --- a/dhcpcd-hooks/20-dns.conf +++ b/dhcpcd-hooks/20-dns.conf @@ -1,6 +1,13 @@ # Set net..dnsN properties that contain the # DNS server addresses given by the DHCP server. +if [[ $interface == p2p* ]] + then + intf=p2p + else + intf=$interface +fi + set_dns_props() { case "${new_domain_name_servers}" in @@ -9,12 +16,12 @@ set_dns_props() count=1 for i in 1 2 3 4; do - setprop dhcp.${interface}.dns${i} "" + setprop dhcp.${intf}.dns${i} "" done count=1 for dnsaddr in ${new_domain_name_servers}; do - setprop dhcp.${interface}.dns${count} ${dnsaddr} + setprop dhcp.${intf}.dns${count} ${dnsaddr} count=$(($count + 1)) done } @@ -22,7 +29,7 @@ set_dns_props() unset_dns_props() { for i in 1 2 3 4; do - setprop dhcp.${interface}.dns${i} "" + setprop dhcp.${intf}.dns${i} "" done } diff --git a/dhcpcd-hooks/95-configured b/dhcpcd-hooks/95-configured index d67236a..7f1b0ab 100644 --- a/dhcpcd-hooks/95-configured +++ b/dhcpcd-hooks/95-configured @@ -3,25 +3,32 @@ # know that setting up the interface is complete. # For debugging: -setprop dhcp.${interface}.reason "${reason}" + +if [[ $interface == p2p* ]] + then + intf=p2p + else + intf=$interface +fi +setprop dhcp.${intf}.reason "${reason}" case "${reason}" in BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) - setprop dhcp.${interface}.ipaddress "${new_ip_address}" - setprop dhcp.${interface}.gateway "${new_routers%% *}" - setprop dhcp.${interface}.mask "${new_subnet_mask}" - setprop dhcp.${interface}.leasetime "${new_dhcp_lease_time}" - setprop dhcp.${interface}.server "${new_dhcp_server_identifier}" - setprop dhcp.${interface}.vendorInfo "${new_vendor_encapsulated_options}" + setprop dhcp.${intf}.ipaddress "${new_ip_address}" + setprop dhcp.${intf}.gateway "${new_routers%% *}" + setprop dhcp.${intf}.mask "${new_subnet_mask}" + setprop dhcp.${intf}.leasetime "${new_dhcp_lease_time}" + setprop dhcp.${intf}.server "${new_dhcp_server_identifier}" + setprop dhcp.${intf}.vendorInfo "${new_vendor_encapsulated_options}" - setprop dhcp.${interface}.result "ok" + setprop dhcp.${intf}.result "ok" ;; EXPIRE|FAIL|IPV4LL|STOP) - setprop dhcp.${interface}.result "failed" + setprop dhcp.${intf}.result "failed" ;; RELEASE) - setprop dhcp.${interface}.result "released" + setprop dhcp.${intf}.result "released" ;; esac diff --git a/dhcpcd.c b/dhcpcd.c index 15c087b..155c07b 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -1751,6 +1751,8 @@ main(int argc, char **argv) struct timespec ts; #ifdef ANDROID + /* Reuse system properties for a p2p interface */ + char p2p_interface[PROPERTY_KEY_MAX]; switchUser(); #endif closefrom(3); @@ -1915,9 +1917,15 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } + if (strncmp(argv[optind], "p2p", 3) == 0) { + strncpy(p2p_interface, "p2p", sizeof(p2p_interface)); + } else { + strncpy(p2p_interface, argv[optind], sizeof(p2p_interface)); + } + if (snprintf(pidpropname, sizeof(pidpropname), - "dhcp.%s.pid", argv[optind]) >= PROPERTY_KEY_MAX) + "dhcp.%s.pid", p2p_interface) >= PROPERTY_KEY_MAX) exit(EXIT_FAILURE); property_get(pidpropname, pidpropval, NULL); if (strlen(pidpropval) == 0) @@ -2000,9 +2008,15 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } + if (strncmp(argv[optind], "p2p", 3) == 0) { + strncpy(p2p_interface, "p2p", sizeof(p2p_interface)); + } else { + strncpy(p2p_interface, argv[optind], sizeof(p2p_interface)); + } + if (snprintf(pidpropname, sizeof(pidpropname), - "dhcp.%s.pid", argv[optind]) >= PROPERTY_KEY_MAX) + "dhcp.%s.pid", p2p_interface) >= PROPERTY_KEY_MAX) exit(EXIT_FAILURE); if (snprintf(pidpropval, sizeof(pidpropval), "%d", getpid()) >= PROPERTY_VALUE_MAX) exit(EXIT_FAILURE); -- cgit v1.1