Add reset_mask as parameter to ifc_reset_connections
The reset_mask allows either IPv4 and or IPv6 connections of an interface to be reset. Bug: 4981919 Change-Id: Id2d9ab90e30091d3d0764c66d4b01b73c0edbfcc
This commit is contained in:
parent
04cf629be5
commit
979203ee34
2 changed files with 33 additions and 23 deletions
|
|
@ -34,7 +34,7 @@ extern int ifc_down(const char *name);
|
||||||
extern int ifc_enable(const char *ifname);
|
extern int ifc_enable(const char *ifname);
|
||||||
extern int ifc_disable(const char *ifname);
|
extern int ifc_disable(const char *ifname);
|
||||||
|
|
||||||
extern int ifc_reset_connections(const char *ifname);
|
extern int ifc_reset_connections(const char *ifname, const int reset_mask);
|
||||||
|
|
||||||
extern int ifc_get_addr(const char *name, in_addr_t *addr);
|
extern int ifc_get_addr(const char *name, in_addr_t *addr);
|
||||||
extern int ifc_set_addr(const char *name, in_addr_t addr);
|
extern int ifc_set_addr(const char *name, in_addr_t addr);
|
||||||
|
|
|
||||||
|
|
@ -353,7 +353,11 @@ int ifc_disable(const char *ifname)
|
||||||
return result;
|
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
|
#ifdef HAVE_ANDROID_OS
|
||||||
int result, success;
|
int result, success;
|
||||||
|
|
@ -361,28 +365,34 @@ int ifc_reset_connections(const char *ifname)
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
struct in6_ifreq ifr6;
|
struct in6_ifreq ifr6;
|
||||||
|
|
||||||
/* IPv4. Clear connections on the IP address. */
|
if (reset_mask & RESET_IPV4_ADDRESSES) {
|
||||||
ifc_init();
|
/* IPv4. Clear connections on the IP address. */
|
||||||
ifc_get_info(ifname, &myaddr, NULL, NULL);
|
ifc_init();
|
||||||
ifc_init_ifr(ifname, &ifr);
|
ifc_get_info(ifname, &myaddr, NULL, NULL);
|
||||||
init_sockaddr_in(&ifr.ifr_addr, myaddr);
|
ifc_init_ifr(ifname, &ifr);
|
||||||
result = ioctl(ifc_ctl_sock, SIOCKILLADDR, &ifr);
|
init_sockaddr_in(&ifr.ifr_addr, myaddr);
|
||||||
ifc_close();
|
result = ioctl(ifc_ctl_sock, SIOCKILLADDR, &ifr);
|
||||||
|
ifc_close();
|
||||||
/*
|
} else {
|
||||||
* IPv6. On Linux, when an interface goes down it loses all its IPv6
|
result = 0;
|
||||||
* 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.
|
if (reset_mask & RESET_IPV6_ADDRESSES) {
|
||||||
*/
|
/*
|
||||||
ifc_init6();
|
* IPv6. On Linux, when an interface goes down it loses all its IPv6
|
||||||
// This implicitly specifies an address of ::, i.e., kill all IPv6 sockets.
|
* addresses, so we don't know which connections belonged to that interface
|
||||||
memset(&ifr6, 0, sizeof(ifr6));
|
* So we clear all unused IPv6 connections on the device by specifying an
|
||||||
success = ioctl(ifc_ctl_sock6, SIOCKILLADDR, &ifr6);
|
* empty IPv6 address.
|
||||||
if (result == 0) {
|
*/
|
||||||
result = success;
|
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;
|
return result;
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue