diff options
| author | Wink Saville <wink@google.com> | 2011-07-08 12:28:18 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2011-07-08 12:28:18 -0700 |
| commit | 7da24861ea933db3bd27509f91717b5c63fd6dde (patch) | |
| tree | 891fd945753f391d2edf487f688599cd6f386d43 /libnetutils | |
| parent | 1384e50b4d757931ccdbd76b61fd68006eddb531 (diff) | |
| parent | 436deea5bbd43ae402ca8ee5bbc7fed3daaf3fce (diff) | |
| download | system_core-7da24861ea933db3bd27509f91717b5c63fd6dde.tar.gz system_core-7da24861ea933db3bd27509f91717b5c63fd6dde.tar.bz2 system_core-7da24861ea933db3bd27509f91717b5c63fd6dde.zip | |
am 436deea5: am 979203ee: Add reset_mask as parameter to ifc_reset_connections
* commit '436deea5bbd43ae402ca8ee5bbc7fed3daaf3fce':
Add reset_mask as parameter to ifc_reset_connections
Diffstat (limited to 'libnetutils')
| -rw-r--r-- | libnetutils/ifc_utils.c | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c index 208402c9..04b0dfa1 100644 --- a/libnetutils/ifc_utils.c +++ b/libnetutils/ifc_utils.c @@ -394,7 +394,11 @@ int ifc_disable(const char *ifname) return result; } -int ifc_reset_connections(const char *ifname) +#define RESET_IPV4_ADDRESSES 0x01 +#define RESET_IPV6_ADDRESSES 0x02 +#define RESET_ALL_ADDRESSES (RESET_IPV4_ADDRESSES | RESET_IPV6_ADDRESSES) + +int ifc_reset_connections(const char *ifname, const int reset_mask) { #ifdef HAVE_ANDROID_OS int result, success; @@ -402,28 +406,34 @@ int ifc_reset_connections(const char *ifname) struct ifreq ifr; struct in6_ifreq ifr6; - /* IPv4. Clear connections on the IP address. */ - ifc_init(); - ifc_get_info(ifname, &myaddr, NULL, NULL); - ifc_init_ifr(ifname, &ifr); - init_sockaddr_in(&ifr.ifr_addr, myaddr); - result = ioctl(ifc_ctl_sock, SIOCKILLADDR, &ifr); - ifc_close(); - - /* - * IPv6. On Linux, when an interface goes down it loses all its IPv6 - * addresses, so we don't know which connections belonged to that interface - * So we clear all unused IPv6 connections on the device by specifying an - * empty IPv6 address. - */ - ifc_init6(); - // 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 (reset_mask & RESET_IPV4_ADDRESSES) { + /* IPv4. Clear connections on the IP address. */ + ifc_init(); + ifc_get_info(ifname, &myaddr, NULL, NULL); + 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) { + /* + * IPv6. On Linux, when an interface goes down it loses all its IPv6 + * addresses, so we don't know which connections belonged to that interface + * So we clear all unused IPv6 connections on the device by specifying an + * empty IPv6 address. + */ + ifc_init6(); + // 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; + } + ifc_close6(); } - ifc_close6(); return result; #else |
