summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsanketk <sanketk@codeaurora.org>2015-06-12 16:38:56 +0800
committerSteve Kondik <steve@cyngn.com>2016-06-30 23:32:23 -0700
commit00c551e284b61d458f05759a489d615933e3667b (patch)
tree1fb7f4489c480bd1707610b4e38e11038f5b074f
parent64caba3c021a9b86f093476b343df9bd3d3a4dbb (diff)
downloadsystem_core-00c551e284b61d458f05759a489d615933e3667b.zip
system_core-00c551e284b61d458f05759a489d615933e3667b.tar.gz
system_core-00c551e284b61d458f05759a489d615933e3667b.tar.bz2
Don't use global variable in libnetutils.
In netd, both CommandListener and NetlinkHandler thread will use libnetutils' function. Original implementation will use a global file descriptor in mutiple functions. It will cause problems when these functions are invoked from different thread. This change will make NetlinkHandler thread use local file descriptor instead of global one. CRs-fixed: 853158 Change-Id: I66458e99e48197e7a56cbb212344423290db12bd
-rw-r--r--libnetutils/ifc_utils.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c
index 3bd59c7..0bd7628 100644
--- a/libnetutils/ifc_utils.c
+++ b/libnetutils/ifc_utils.c
@@ -597,23 +597,26 @@ int ifc_disable(const char *ifname)
int ifc_reset_connections(const char *ifname, const int reset_mask)
{
#ifdef HAVE_ANDROID_OS
- int result, success;
+ int result = 0, success;
in_addr_t myaddr = 0;
struct ifreq ifr;
struct in6_ifreq ifr6;
+ int ctl_sock = -1;
if (reset_mask & RESET_IPV4_ADDRESSES) {
/* IPv4. Clear connections on the IP address. */
- ifc_init();
- if (!(reset_mask & RESET_IGNORE_INTERFACE_ADDRESS)) {
- ifc_get_info(ifname, &myaddr, NULL, NULL);
+ ctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (ctl_sock >= 0) {
+ if (!(reset_mask & RESET_IGNORE_INTERFACE_ADDRESS)) {
+ ifc_get_info(ifname, &myaddr, NULL, NULL);
+ }
+ ifc_init_ifr(ifname, &ifr);
+ init_sockaddr_in(&ifr.ifr_addr, myaddr);
+ result = ioctl(ctl_sock, SIOCKILLADDR, &ifr);
+ close(ctl_sock);
+ } else {
+ result = -1;
}
- ifc_init_ifr(ifname, &ifr);
- init_sockaddr_in(&ifr.ifr_addr, myaddr);
- result = ioctl(ifc_ctl_sock, SIOCKILLADDR, &ifr);
- ifc_close();
- } else {
- result = 0;
}
if (reset_mask & RESET_IPV6_ADDRESSES) {
@@ -623,14 +626,18 @@ int ifc_reset_connections(const char *ifname, const int reset_mask)
* So we clear all unused IPv6 connections on the device by specifying an
* empty IPv6 address.
*/
- ifc_init6();
+ ctl_sock = socket(AF_INET6, SOCK_DGRAM, 0);
// This implicitly specifies an address of ::, i.e., kill all IPv6 sockets.
memset(&ifr6, 0, sizeof(ifr6));
- success = ioctl(ifc_ctl_sock6, SIOCKILLADDR, &ifr6);
- if (result == 0) {
- result = success;
+ if (ctl_sock >= 0) {
+ success = ioctl(ctl_sock, SIOCKILLADDR, &ifr6);
+ if (result == 0) {
+ result = success;
+ }
+ close(ctl_sock);
+ } else {
+ result = -1;
}
- ifc_close6();
}
return result;