From: Chia-chi Yeh Date: Wed, 29 Jun 2011 22:39:15 +0000 (-0700) Subject: ip-up-vpn: remove the code of generating routing rules. X-Git-Tag: android-x86-4.0-r1~2 X-Git-Url: http://git.osdn.net/view?p=android-x86%2Fexternal-ppp.git;a=commitdiff_plain;h=1a20c542261d686e3c865b5e8294d176d84c7152 ip-up-vpn: remove the code of generating routing rules. They will be generated by LegacyVpnRunner. Change-Id: I85a087440b6214aa9ada5db9c3ecc4e18f042313 --- diff --git a/android/ip-up-vpn.c b/android/ip-up-vpn.c index afc85f4..bbf6b14 100644 --- a/android/ip-up-vpn.c +++ b/android/ip-up-vpn.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 The Android Open Source Project + * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,73 +17,19 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include -static inline struct in_addr *in_addr(struct sockaddr *sa) -{ - return &((struct sockaddr_in *)sa)->sin_addr; -} - int main(int argc, char **argv) { - struct rtentry route = { - .rt_dst = {.sa_family = AF_INET}, - .rt_genmask = {.sa_family = AF_INET}, - .rt_gateway = {.sa_family = AF_INET}, - .rt_flags = RTF_UP | RTF_GATEWAY, - }; - FILE *f; - int s; - - errno = EINVAL; - if (argc > 5 && inet_aton(argv[5], in_addr(&route.rt_gateway)) && - (f = fopen("/proc/net/route", "r")) != NULL && - (s = socket(AF_INET, SOCK_DGRAM, 0)) != -1) { - uint32_t *address = &in_addr(&route.rt_dst)->s_addr; - uint32_t *netmask = &in_addr(&route.rt_genmask)->s_addr; - char device[64]; - - fscanf(f, "%*[^\n]\n"); - while (fscanf(f, "%63s%X%*X%*X%*d%*u%*d%X%*d%*u%*u\n", - device, address, netmask) == 3) { - if (strcmp(argv[1], device)) { - uint32_t bit = ntohl(*netmask); - bit = htonl(bit ^ (1 << 31 | bit >> 1)); - if (bit) { - *netmask |= bit; - if (ioctl(s, SIOCADDRT, &route) == -1 && errno != EEXIST) { - break; - } - *address ^= bit; - if (ioctl(s, SIOCADDRT, &route) == -1 && errno != EEXIST) { - break; - } - errno = 0; - } - } - } - } + if (argc > 1 && strlen(argv[1]) > 0) { + char dns[PROPERTY_VALUE_MAX]; + char *dns1 = getenv("DNS1"); + char *dns2 = getenv("DNS2"); - if (!errno) { - char *dns = getenv("DNS1"); - property_set("vpn.dns1", dns ? dns : ""); - dns = getenv("DNS2"); - property_set("vpn.dns2", dns ? dns : ""); - property_set("vpn.status", "ok"); - __android_log_print(ANDROID_LOG_INFO, "ip-up-vpn", - "All traffic is now redirected to %s", argv[5]); - } else { - property_set("vpn.status", "error"); - __android_log_write(ANDROID_LOG_ERROR, "ip-up-vpn", strerror(errno)); + snprintf(dns, sizeof(dns), "%s %s", dns1 ? dns1 : "", dns2 ? dns2 : ""); + property_set("vpn.dns", dns); + property_set("vpn.via", argv[1]); } - return errno; + return 0; }