am 759356bb
: Merge "Cleanup: Delete dead code." into lmp-dev
* commit '759356bbd889d780a57c51c19761b32cbba8e6ef': Cleanup: Delete dead code.
This commit is contained in:
commit
f2af027d5b
3 changed files with 0 additions and 316 deletions
|
@ -31,9 +31,6 @@ extern int ifc_get_hwaddr(const char *name, void *ptr);
|
|||
extern int ifc_up(const char *name);
|
||||
extern int ifc_down(const char *name);
|
||||
|
||||
extern int ifc_enable(const char *ifname);
|
||||
extern int ifc_disable(const char *ifname);
|
||||
|
||||
#define RESET_IPV4_ADDRESSES 0x01
|
||||
#define RESET_IPV6_ADDRESSES 0x02
|
||||
#define RESET_ALL_ADDRESSES (RESET_IPV4_ADDRESSES | RESET_IPV6_ADDRESSES)
|
||||
|
@ -49,19 +46,8 @@ extern int ifc_set_prefixLength(const char *name, int prefixLength);
|
|||
extern int ifc_set_hwaddr(const char *name, const void *ptr);
|
||||
extern int ifc_clear_addresses(const char *name);
|
||||
|
||||
/* This function is deprecated. Use ifc_add_route instead. */
|
||||
extern int ifc_add_host_route(const char *name, in_addr_t addr);
|
||||
extern int ifc_remove_host_routes(const char *name);
|
||||
extern int ifc_get_default_route(const char *ifname);
|
||||
/* This function is deprecated. Use ifc_add_route instead */
|
||||
extern int ifc_set_default_route(const char *ifname, in_addr_t gateway);
|
||||
/* This function is deprecated. Use ifc_add_route instead */
|
||||
extern int ifc_create_default_route(const char *name, in_addr_t addr);
|
||||
extern int ifc_remove_default_route(const char *ifname);
|
||||
extern int ifc_add_route(const char *name, const char *addr, int prefix_length,
|
||||
const char *gw);
|
||||
extern int ifc_remove_route(const char *ifname, const char *dst,
|
||||
int prefix_length, const char *gw);
|
||||
extern int ifc_get_info(const char *name, in_addr_t *addr, int *prefixLength,
|
||||
unsigned *flags);
|
||||
|
||||
|
|
|
@ -563,47 +563,6 @@ int ifc_create_default_route(const char *name, in_addr_t gw)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/* deprecated v4-only */
|
||||
int ifc_add_host_route(const char *name, in_addr_t dst)
|
||||
{
|
||||
struct in_addr in_dst, in_gw;
|
||||
|
||||
in_dst.s_addr = dst;
|
||||
in_gw.s_addr = 0;
|
||||
|
||||
return ifc_act_on_ipv4_route(SIOCADDRT, name, in_dst, 32, in_gw);
|
||||
}
|
||||
|
||||
int ifc_enable(const char *ifname)
|
||||
{
|
||||
int result;
|
||||
|
||||
ifc_init();
|
||||
result = ifc_up(ifname);
|
||||
ifc_close();
|
||||
return result;
|
||||
}
|
||||
|
||||
int ifc_disable(const char *ifname)
|
||||
{
|
||||
unsigned addr, count;
|
||||
int result;
|
||||
|
||||
ifc_init();
|
||||
result = ifc_down(ifname);
|
||||
|
||||
ifc_set_addr(ifname, 0);
|
||||
for (count=0, addr=1;((addr != 0) && (count < 255)); count++) {
|
||||
if (ifc_get_addr(ifname, &addr) < 0)
|
||||
break;
|
||||
if (addr)
|
||||
ifc_set_addr(ifname, 0);
|
||||
}
|
||||
|
||||
ifc_close();
|
||||
return result;
|
||||
}
|
||||
|
||||
int ifc_reset_connections(const char *ifname, const int reset_mask)
|
||||
{
|
||||
#ifdef HAVE_ANDROID_OS
|
||||
|
@ -647,118 +606,6 @@ int ifc_reset_connections(const char *ifname, const int reset_mask)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove the routes associated with the named interface.
|
||||
*/
|
||||
int ifc_remove_host_routes(const char *name)
|
||||
{
|
||||
char ifname[64];
|
||||
in_addr_t dest, gway, mask;
|
||||
int flags, refcnt, use, metric, mtu, win, irtt;
|
||||
struct rtentry rt;
|
||||
FILE *fp;
|
||||
struct in_addr addr;
|
||||
|
||||
fp = fopen("/proc/net/route", "r");
|
||||
if (fp == NULL)
|
||||
return -1;
|
||||
/* Skip the header line */
|
||||
if (fscanf(fp, "%*[^\n]\n") < 0) {
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
ifc_init();
|
||||
for (;;) {
|
||||
int nread = fscanf(fp, "%63s%X%X%X%d%d%d%X%d%d%d\n",
|
||||
ifname, &dest, &gway, &flags, &refcnt, &use, &metric, &mask,
|
||||
&mtu, &win, &irtt);
|
||||
if (nread != 11) {
|
||||
break;
|
||||
}
|
||||
if ((flags & (RTF_UP|RTF_HOST)) != (RTF_UP|RTF_HOST)
|
||||
|| strcmp(ifname, name) != 0) {
|
||||
continue;
|
||||
}
|
||||
memset(&rt, 0, sizeof(rt));
|
||||
rt.rt_dev = (void *)name;
|
||||
init_sockaddr_in(&rt.rt_dst, dest);
|
||||
init_sockaddr_in(&rt.rt_gateway, gway);
|
||||
init_sockaddr_in(&rt.rt_genmask, mask);
|
||||
addr.s_addr = dest;
|
||||
if (ioctl(ifc_ctl_sock, SIOCDELRT, &rt) < 0) {
|
||||
ALOGD("failed to remove route for %s to %s: %s",
|
||||
ifname, inet_ntoa(addr), strerror(errno));
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
ifc_close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the address of the default gateway
|
||||
*
|
||||
* TODO: factor out common code from this and remove_host_routes()
|
||||
* so that we only scan /proc/net/route in one place.
|
||||
*
|
||||
* DEPRECATED
|
||||
*/
|
||||
int ifc_get_default_route(const char *ifname)
|
||||
{
|
||||
char name[64];
|
||||
in_addr_t dest, gway, mask;
|
||||
int flags, refcnt, use, metric, mtu, win, irtt;
|
||||
int result;
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen("/proc/net/route", "r");
|
||||
if (fp == NULL)
|
||||
return 0;
|
||||
/* Skip the header line */
|
||||
if (fscanf(fp, "%*[^\n]\n") < 0) {
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
ifc_init();
|
||||
result = 0;
|
||||
for (;;) {
|
||||
int nread = fscanf(fp, "%63s%X%X%X%d%d%d%X%d%d%d\n",
|
||||
name, &dest, &gway, &flags, &refcnt, &use, &metric, &mask,
|
||||
&mtu, &win, &irtt);
|
||||
if (nread != 11) {
|
||||
break;
|
||||
}
|
||||
if ((flags & (RTF_UP|RTF_GATEWAY)) == (RTF_UP|RTF_GATEWAY)
|
||||
&& dest == 0
|
||||
&& strcmp(ifname, name) == 0) {
|
||||
result = gway;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
ifc_close();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the specified gateway as the default route for the named interface.
|
||||
* DEPRECATED
|
||||
*/
|
||||
int ifc_set_default_route(const char *ifname, in_addr_t gateway)
|
||||
{
|
||||
struct in_addr addr;
|
||||
int result;
|
||||
|
||||
ifc_init();
|
||||
addr.s_addr = gateway;
|
||||
if ((result = ifc_create_default_route(ifname, gateway)) < 0) {
|
||||
ALOGD("failed to add %s as default route for %s: %s",
|
||||
inet_ntoa(addr), ifname, strerror(errno));
|
||||
}
|
||||
ifc_close();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes the default route for the named interface.
|
||||
*/
|
||||
|
@ -821,151 +668,3 @@ ifc_configure(const char *ifname,
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ifc_act_on_ipv6_route(int action, const char *ifname, struct in6_addr dst, int prefix_length,
|
||||
struct in6_addr gw)
|
||||
{
|
||||
struct in6_rtmsg rtmsg;
|
||||
int result;
|
||||
int ifindex;
|
||||
|
||||
memset(&rtmsg, 0, sizeof(rtmsg));
|
||||
|
||||
ifindex = if_nametoindex(ifname);
|
||||
if (ifindex == 0) {
|
||||
printerr("if_nametoindex() failed: interface %s\n", ifname);
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
rtmsg.rtmsg_ifindex = ifindex;
|
||||
rtmsg.rtmsg_dst = dst;
|
||||
rtmsg.rtmsg_dst_len = prefix_length;
|
||||
rtmsg.rtmsg_flags = RTF_UP;
|
||||
|
||||
if (prefix_length == 128) {
|
||||
rtmsg.rtmsg_flags |= RTF_HOST;
|
||||
}
|
||||
|
||||
if (memcmp(&gw, &in6addr_any, sizeof(in6addr_any))) {
|
||||
rtmsg.rtmsg_flags |= RTF_GATEWAY;
|
||||
rtmsg.rtmsg_gateway = gw;
|
||||
}
|
||||
|
||||
ifc_init6();
|
||||
|
||||
if (ifc_ctl_sock6 < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
result = ioctl(ifc_ctl_sock6, action, &rtmsg);
|
||||
if (result < 0) {
|
||||
if (errno == EEXIST) {
|
||||
result = 0;
|
||||
} else {
|
||||
result = -errno;
|
||||
}
|
||||
}
|
||||
ifc_close6();
|
||||
return result;
|
||||
}
|
||||
|
||||
int ifc_act_on_route(int action, const char *ifname, const char *dst, int prefix_length,
|
||||
const char *gw)
|
||||
{
|
||||
int ret = 0;
|
||||
struct sockaddr_in ipv4_dst, ipv4_gw;
|
||||
struct sockaddr_in6 ipv6_dst, ipv6_gw;
|
||||
struct addrinfo hints, *addr_ai, *gw_ai;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
|
||||
ret = getaddrinfo(dst, NULL, &hints, &addr_ai);
|
||||
|
||||
if (ret != 0) {
|
||||
printerr("getaddrinfo failed: invalid address %s\n", dst);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (gw == NULL || (strlen(gw) == 0)) {
|
||||
if (addr_ai->ai_family == AF_INET6) {
|
||||
gw = "::";
|
||||
} else if (addr_ai->ai_family == AF_INET) {
|
||||
gw = "0.0.0.0";
|
||||
}
|
||||
}
|
||||
|
||||
if (((addr_ai->ai_family == AF_INET6) && (prefix_length < 0 || prefix_length > 128)) ||
|
||||
((addr_ai->ai_family == AF_INET) && (prefix_length < 0 || prefix_length > 32))) {
|
||||
printerr("ifc_add_route: invalid prefix length");
|
||||
freeaddrinfo(addr_ai);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = getaddrinfo(gw, NULL, &hints, &gw_ai);
|
||||
if (ret != 0) {
|
||||
printerr("getaddrinfo failed: invalid gateway %s\n", gw);
|
||||
freeaddrinfo(addr_ai);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (addr_ai->ai_family != gw_ai->ai_family) {
|
||||
printerr("ifc_add_route: different address families: %s and %s\n", dst, gw);
|
||||
freeaddrinfo(addr_ai);
|
||||
freeaddrinfo(gw_ai);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (addr_ai->ai_family == AF_INET6) {
|
||||
memcpy(&ipv6_dst, addr_ai->ai_addr, sizeof(struct sockaddr_in6));
|
||||
memcpy(&ipv6_gw, gw_ai->ai_addr, sizeof(struct sockaddr_in6));
|
||||
ret = ifc_act_on_ipv6_route(action, ifname, ipv6_dst.sin6_addr,
|
||||
prefix_length, ipv6_gw.sin6_addr);
|
||||
} else if (addr_ai->ai_family == AF_INET) {
|
||||
memcpy(&ipv4_dst, addr_ai->ai_addr, sizeof(struct sockaddr_in));
|
||||
memcpy(&ipv4_gw, gw_ai->ai_addr, sizeof(struct sockaddr_in));
|
||||
ret = ifc_act_on_ipv4_route(action, ifname, ipv4_dst.sin_addr,
|
||||
prefix_length, ipv4_gw.sin_addr);
|
||||
} else {
|
||||
printerr("ifc_add_route: getaddrinfo returned un supported address family %d\n",
|
||||
addr_ai->ai_family);
|
||||
ret = -EAFNOSUPPORT;
|
||||
}
|
||||
|
||||
freeaddrinfo(addr_ai);
|
||||
freeaddrinfo(gw_ai);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* DEPRECATED
|
||||
*/
|
||||
int ifc_add_ipv4_route(const char *ifname, struct in_addr dst, int prefix_length,
|
||||
struct in_addr gw)
|
||||
{
|
||||
int i =ifc_act_on_ipv4_route(SIOCADDRT, ifname, dst, prefix_length, gw);
|
||||
if (DBG) printerr("ifc_add_ipv4_route(%s, xx, %d, xx) = %d", ifname, prefix_length, i);
|
||||
return i;
|
||||
}
|
||||
|
||||
/*
|
||||
* DEPRECATED
|
||||
*/
|
||||
int ifc_add_ipv6_route(const char *ifname, struct in6_addr dst, int prefix_length,
|
||||
struct in6_addr gw)
|
||||
{
|
||||
return ifc_act_on_ipv6_route(SIOCADDRT, ifname, dst, prefix_length, gw);
|
||||
}
|
||||
|
||||
int ifc_add_route(const char *ifname, const char *dst, int prefix_length, const char *gw)
|
||||
{
|
||||
int i = ifc_act_on_route(SIOCADDRT, ifname, dst, prefix_length, gw);
|
||||
if (DBG) printerr("ifc_add_route(%s, %s, %d, %s) = %d", ifname, dst, prefix_length, gw, i);
|
||||
return i;
|
||||
}
|
||||
|
||||
int ifc_remove_route(const char *ifname, const char*dst, int prefix_length, const char *gw)
|
||||
{
|
||||
return ifc_act_on_route(SIOCDELRT, ifname, dst, prefix_length, gw);
|
||||
}
|
||||
|
|
|
@ -102,7 +102,6 @@ struct
|
|||
{ "dhcp", 1, do_dhcp },
|
||||
{ "up", 1, ifc_up },
|
||||
{ "down", 1, ifc_down },
|
||||
{ "flhosts", 1, ifc_remove_host_routes },
|
||||
{ "deldefault", 1, ifc_remove_default_route },
|
||||
{ "hwaddr", 2, set_hwaddr },
|
||||
{ 0, 0, 0 },
|
||||
|
|
Loading…
Reference in a new issue