diff options
author | Ravinder Konka <rkonka@codeaurora.org> | 2014-09-10 18:16:44 +0530 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2014-10-04 13:31:17 -0700 |
commit | 491d61b1a9dc3a3ca12b3f734a6bb36863d51462 (patch) | |
tree | aeae49f6ac71e1c6543a300d46cf70e3a7f52e83 | |
parent | afb0b265dc7abd0d37527ca8b6e23bad1a572cd0 (diff) | |
download | android_system_netd-stable/cm-11.0-XNF8Y.tar.gz android_system_netd-stable/cm-11.0-XNF8Y.tar.bz2 android_system_netd-stable/cm-11.0-XNF8Y.zip |
netd: Add support for ipv6 tethering when using dun.cm-11.0-XNPH05Q-tomato-9828f8e9cccm-11.0-XNPH05Q-bacon-5229c4ef56stable/cm-11.0-XNG3Cstable/cm-11.0-XNG2Sstable/cm-11.0-XNF9Xstable/cm-11.0-XNF8Ystable/cm-11.0shipping/cm-11.0
Change-Id: I24e4bf2cc1b10ee4f3196c87da392fc301b2a18a
-rw-r--r-- | CommandListener.cpp | 7 | ||||
-rw-r--r-- | TetherController.cpp | 53 | ||||
-rw-r--r-- | TetherController.h | 6 |
3 files changed, 51 insertions, 15 deletions
diff --git a/CommandListener.cpp b/CommandListener.cpp index 52024de0..63c2615f 100644 --- a/CommandListener.cpp +++ b/CommandListener.cpp @@ -54,6 +54,8 @@ #include "qsap_api.h" #endif +#define INVALID_TABLE_NUMBER -1 + TetherController *CommandListener::sTetherCtrl = NULL; NatController *CommandListener::sNatCtrl = NULL; PppController *CommandListener::sPppCtrl = NULL; @@ -208,7 +210,7 @@ CommandListener::CommandListener(UidMarkMap *map) : if (!sSecondaryTableCtrl) sSecondaryTableCtrl = new SecondaryTableController(map); if (!sTetherCtrl) - sTetherCtrl = new TetherController(); + sTetherCtrl = new TetherController(sSecondaryTableCtrl); if (!sNatCtrl) sNatCtrl = new NatController(sSecondaryTableCtrl); if (!sPppCtrl) @@ -916,10 +918,9 @@ int CommandListener::V6RtrAdvCmd::runCommand(SocketClient *cli, } if (!strcmp(argv[1], "start")) { - int num_ifaces = argc - 2; int arg_index = 2; - rc = sTetherCtrl->startV6RtrAdv(num_ifaces, &argv[arg_index]); + rc = sTetherCtrl->startV6RtrAdv(num_ifaces, &argv[arg_index], INVALID_TABLE_NUMBER); } else if (!strcmp(argv[1], "interface")) { if (!strcmp(argv[2], "add")) { rc = sTetherCtrl->tetherInterface(argv[3]); diff --git a/TetherController.cpp b/TetherController.cpp index 1ade2ca0..ca31cc76 100644 --- a/TetherController.cpp +++ b/TetherController.cpp @@ -34,8 +34,10 @@ #define LOG_NIDEBUG 0 #include <cutils/log.h> #include <cutils/properties.h> +#include <logwrap/logwrap.h> #include "TetherController.h" +#include "SecondaryTableController.h" #include <private/android_filesystem_config.h> #include <unistd.h> @@ -47,12 +49,23 @@ #define IP6_IFACE_CFG_ACCEPT_RA "/proc/sys/net/ipv6/conf/%s/accept_ra" #define PROC_PATH_SIZE 255 -TetherController::TetherController() { +#define RTRADVDAEMON_MIN_IFACES 2 +#define MAX_TABLE_LEN 11 +#define MIN_TABLE_NUMBER 0 + +/* This is the number of arguments for RTRADVDAEMON which accounts for the + * location of the daemon, the table name option, the name of the table + * and a final empty string + */ +#define RTRADVDAEMON_ARGS_COUNT 4 + +TetherController::TetherController(SecondaryTableController *ctrl) { mInterfaces = new InterfaceCollection(); mUpstreamInterfaces = new InterfaceCollection(); mDnsForwarders = new NetAddressCollection(); mDaemonFd = -1; mDaemonPid = 0; + secondaryTableCtrl = ctrl; } TetherController::~TetherController() { @@ -247,8 +260,7 @@ bool TetherController::isTetheringStarted() { return (mDaemonPid == 0 ? false : true); } - -int TetherController::startV6RtrAdv(int num_ifaces, char **ifaces) { +int TetherController::startV6RtrAdv(int num_ifaces, char **ifaces, int table_number) { int pid; int num_processed_args = 1; gid_t groups [] = { AID_NET_ADMIN, AID_NET_RAW, AID_INET }; @@ -261,16 +273,32 @@ int TetherController::startV6RtrAdv(int num_ifaces, char **ifaces) { char **args; const char *cmd = RTRADVDAEMON; - args = (char **)calloc(num_ifaces * 3 + 2, sizeof(char *)); + args = (char **)calloc(num_ifaces * 3 + RTRADVDAEMON_ARGS_COUNT, sizeof(char *)); + if (!args) { + ALOGE("%s: failed to allocate memory", __func__); + return -1; + } args[0] = strdup(RTRADVDAEMON); + int aidx = 0; for (int i=0; i < num_ifaces; i++) { - int aidx = 3 * i + num_processed_args; - args[aidx] = (char *)"-i"; - args[aidx + 1] = ifaces[i]; - args[aidx + 2] = (char *)"-x"; + aidx = 3 * i + num_processed_args; + args[aidx++] = (char *)"-i"; + args[aidx++] = ifaces[i]; + args[aidx++] = (char *)"-x"; + } + if (table_number >= MIN_TABLE_NUMBER) { + char table_name[MAX_TABLE_LEN]; + unsigned int retval = 0; + retval = snprintf(table_name, sizeof(table_name), + "%d", table_number + BASE_TABLE_NUMBER); + if (retval >= sizeof(table_name)) { + ALOGE("%s: String truncation occured", __func__); + } else { + args[aidx++] = (char *)"-t"; + args[aidx] = table_name; + } } - setgroups(sizeof(groups)/sizeof(groups[0]), groups); setresgid(AID_RADIO, AID_RADIO, AID_RADIO); @@ -307,6 +335,8 @@ int TetherController::addV6RtrAdvIface(const char *iface) { int i; int len; InterfaceCollection::iterator it; + char *upstream = NULL; + int table_number = -1; /* For now, just stop and start the daemon with the new interface list */ len = mInterfaces->size() + mUpstreamInterfaces->size(); @@ -324,10 +354,13 @@ int TetherController::addV6RtrAdvIface(const char *iface) { for (it = mUpstreamInterfaces->begin(); i < len && it != mUpstreamInterfaces->end(); it++, i++) { args[i] = *it; + upstream = args[i]; + table_number = secondaryTableCtrl->findTableNumber(upstream); + ALOGD("%s: Upstream Iface: %s table number: %d", __func__, upstream, table_number); } stopV6RtrAdv(); - startV6RtrAdv(i, args); + startV6RtrAdv(i, args, table_number); free(args); diff --git a/TetherController.h b/TetherController.h index 4065c5fb..b67a19cb 100644 --- a/TetherController.h +++ b/TetherController.h @@ -20,6 +20,7 @@ #include <netinet/in.h> #include "List.h" +#include "SecondaryTableController.h" #define HOUR 3600 @@ -39,7 +40,7 @@ class TetherController { InterfaceCollection *mUpstreamInterfaces; public: - TetherController(); + TetherController(SecondaryTableController *ctrl); virtual ~TetherController(); int setIpFwdEnabled(bool enable); @@ -56,7 +57,7 @@ public: int tetherInterface(const char *interface); int untetherInterface(const char *interface); InterfaceCollection *getTetheredInterfaceList(); - int startV6RtrAdv(int num_ifaces, char **ifaces); + int startV6RtrAdv(int num_ifaces, char **ifaces, int table_number); int stopV6RtrAdv(); bool isV6RtrAdvStarted(); int addV6RtrAdvIface(const char *iface); @@ -65,6 +66,7 @@ public: int removeUpstreamInterface(char *iface); private: + SecondaryTableController *secondaryTableCtrl; int applyDnsInterfaces(); }; |