summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChia-chi Yeh <chiachi@android.com>2011-06-29 15:39:15 -0700
committerChia-chi Yeh <chiachi@android.com>2011-06-29 15:39:15 -0700
commit1a20c542261d686e3c865b5e8294d176d84c7152 (patch)
tree3efb35d0f8486c6a8c2c3b06acc36565f7603427
parent43a588f9a7e28c06b780a6813c55cf30482b4fbe (diff)
downloadppp-1a20c542261d686e3c865b5e8294d176d84c7152.tar.gz
ip-up-vpn: remove the code of generating routing rules.
They will be generated by LegacyVpnRunner. Change-Id: I85a087440b6214aa9ada5db9c3ecc4e18f042313
-rw-r--r--android/ip-up-vpn.c72
1 files changed, 9 insertions, 63 deletions
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <linux/route.h>
-#include <android/log.h>
#include <cutils/properties.h>
-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;
}