OSDN Git Service

am 954d5d1b: Merge "Update clearifaceforuidrange to take the interface" into klp-dev
authorChad Brubaker <cbrubaker@google.com>
Fri, 21 Mar 2014 23:09:25 +0000 (23:09 +0000)
committerAndroid Git Automerger <android-git-automerger@android.com>
Fri, 21 Mar 2014 23:09:25 +0000 (23:09 +0000)
* commit '954d5d1bcdcdfe4522a64ae48827501a6a6d64c0':
  Update clearifaceforuidrange to take the interface

Android.mk
BandwidthController.cpp
CommandListener.cpp
DnsProxyListener.cpp
NetlinkHandler.cpp
NetlinkHandler.h
NetlinkManager.cpp
ResponseCode.h
TetherController.cpp

index da4a7ad..359831a 100644 (file)
@@ -28,12 +28,12 @@ LOCAL_SRC_FILES:=                                      \
 
 LOCAL_MODULE:= netd
 
-LOCAL_C_INCLUDES := $(KERNEL_HEADERS) \
+LOCAL_C_INCLUDES := \
                     external/mdnsresponder/mDNSShared \
                     external/openssl/include \
                     external/stlport/stlport \
                     bionic \
-                    bionic/libc/private \
+                    bionic/libc/dns/include \
                     $(call include-path-for, libhardware_legacy)/hardware_legacy
 
 LOCAL_CFLAGS := -Werror=format
@@ -50,9 +50,9 @@ LOCAL_SRC_FILES:=          \
 
 LOCAL_MODULE:= ndc
 
-LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
+LOCAL_C_INCLUDES :=
 
-LOCAL_CFLAGS := 
+LOCAL_CFLAGS :=
 
 LOCAL_SHARED_LIBRARIES := libcutils
 
index 664211d..83baea0 100644 (file)
@@ -28,6 +28,9 @@
 #include <stdlib.h>
 #include <string.h>
 
+#define __STDC_FORMAT_MACROS 1
+#include <inttypes.h>
+
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -48,7 +51,7 @@
 #include "ResponseCode.h"
 
 /* Alphabetical */
-#define ALERT_IPT_TEMPLATE "%s %s -m quota2 ! --quota %lld --name %s"
+#define ALERT_IPT_TEMPLATE "%s %s -m quota2 ! --quota %" PRId64" --name %s"
 const char BandwidthController::ALERT_GLOBAL_NAME[] = "globalAlert";
 const char* BandwidthController::LOCAL_INPUT = "bw_INPUT";
 const char* BandwidthController::LOCAL_FORWARD = "bw_FORWARD";
@@ -475,7 +478,7 @@ std::string BandwidthController::makeIptablesQuotaCmd(IptOp op, const char *cost
     char *buff;
     const char *opFlag;
 
-    ALOGV("makeIptablesQuotaCmd(%d, %lld)", op, quota);
+    ALOGV("makeIptablesQuotaCmd(%d, %" PRId64")", op, quota);
 
     switch (op) {
     case IptOpInsert:
@@ -494,7 +497,7 @@ std::string BandwidthController::makeIptablesQuotaCmd(IptOp op, const char *cost
     }
 
     // The requried IP version specific --jump REJECT ... will be added later.
-    asprintf(&buff, "%s bw_costly_%s -m quota2 ! --quota %lld --name %s", opFlag, costName, quota,
+    asprintf(&buff, "%s bw_costly_%s -m quota2 ! --quota %" PRId64" --name %s", opFlag, costName, quota,
              costName);
     res = buff;
     free(buff);
@@ -780,8 +783,8 @@ int BandwidthController::getInterfaceQuota(const char *costName, int64_t *bytes)
         ALOGE("Reading quota %s failed (%s)", costName, strerror(errno));
         return -1;
     }
-    scanRes = fscanf(fp, "%lld", bytes);
-    ALOGV("Read quota res=%d bytes=%lld", scanRes, *bytes);
+    scanRes = fscanf(fp, "%" PRId64, bytes);
+    ALOGV("Read quota res=%d bytes=%" PRId64, scanRes, *bytes);
     fclose(fp);
     return scanRes == 1 ? 0 : -1;
 }
@@ -830,7 +833,7 @@ int BandwidthController::updateQuota(const char *quotaName, int64_t bytes) {
         ALOGE("Updating quota %s failed (%s)", quotaName, strerror(errno));
         return -1;
     }
-    fprintf(fp, "%lld\n", bytes);
+    fprintf(fp, "%" PRId64"\n", bytes);
     fclose(fp);
     return 0;
 }
@@ -1110,9 +1113,9 @@ int BandwidthController::parseForwardChainStats(SocketClient *cli, const TetherS
     while (NULL != (buffPtr = fgets(lineBuffer, MAX_IPT_OUTPUT_LINE_LEN, fp))) {
         /* Clean up, so a failed parse can still print info */
         iface0[0] = iface1[0] = rest[0] = packets = bytes = 0;
-        res = sscanf(buffPtr, "%lld %lld RETURN all -- %s %s 0.%s",
+        res = sscanf(buffPtr, "%" PRId64" %" PRId64" RETURN all -- %s %s 0.%s",
                 &packets, &bytes, iface0, iface1, rest);
-        ALOGV("parse res=%d iface0=<%s> iface1=<%s> pkts=%lld bytes=%lld rest=<%s> orig line=<%s>", res,
+        ALOGV("parse res=%d iface0=<%s> iface1=<%s> pkts=%" PRId64" bytes=%" PRId64" rest=<%s> orig line=<%s>", res,
              iface0, iface1, packets, bytes, rest, buffPtr);
         extraProcessingInfo += buffPtr;
 
@@ -1126,23 +1129,23 @@ int BandwidthController::parseForwardChainStats(SocketClient *cli, const TetherS
          */
         if (filter.intIface[0] && filter.extIface[0]) {
             if (filter.intIface == iface0 && filter.extIface == iface1) {
-                ALOGV("2Filter RX iface_in=%s iface_out=%s rx_bytes=%lld rx_packets=%lld ", iface0, iface1, bytes, packets);
+                ALOGV("2Filter RX iface_in=%s iface_out=%s rx_bytes=%" PRId64" rx_packets=%" PRId64" ", iface0, iface1, bytes, packets);
                 stats.rxPackets = packets;
                 stats.rxBytes = bytes;
             } else if (filter.intIface == iface1 && filter.extIface == iface0) {
-                ALOGV("2Filter TX iface_in=%s iface_out=%s rx_bytes=%lld rx_packets=%lld ", iface0, iface1, bytes, packets);
+                ALOGV("2Filter TX iface_in=%s iface_out=%s rx_bytes=%" PRId64" rx_packets=%" PRId64" ", iface0, iface1, bytes, packets);
                 stats.txPackets = packets;
                 stats.txBytes = bytes;
             }
         } else if (filter.intIface[0] || filter.extIface[0]) {
             if (filter.intIface == iface0 || filter.extIface == iface1) {
-                ALOGV("1Filter RX iface_in=%s iface_out=%s rx_bytes=%lld rx_packets=%lld ", iface0, iface1, bytes, packets);
+                ALOGV("1Filter RX iface_in=%s iface_out=%s rx_bytes=%" PRId64" rx_packets=%" PRId64" ", iface0, iface1, bytes, packets);
                 stats.intIface = iface0;
                 stats.extIface = iface1;
                 stats.rxPackets = packets;
                 stats.rxBytes = bytes;
             } else if (filter.intIface == iface1 || filter.extIface == iface0) {
-                ALOGV("1Filter TX iface_in=%s iface_out=%s rx_bytes=%lld rx_packets=%lld ", iface0, iface1, bytes, packets);
+                ALOGV("1Filter TX iface_in=%s iface_out=%s rx_bytes=%" PRId64" rx_packets=%" PRId64" ", iface0, iface1, bytes, packets);
                 stats.intIface = iface1;
                 stats.extIface = iface0;
                 stats.txPackets = packets;
@@ -1150,19 +1153,19 @@ int BandwidthController::parseForwardChainStats(SocketClient *cli, const TetherS
             }
         } else /* if (!filter.intFace[0] && !filter.extIface[0]) */ {
             if (!stats.intIface[0]) {
-                ALOGV("0Filter RX iface_in=%s iface_out=%s rx_bytes=%lld rx_packets=%lld ", iface0, iface1, bytes, packets);
+                ALOGV("0Filter RX iface_in=%s iface_out=%s rx_bytes=%" PRId64" rx_packets=%" PRId64" ", iface0, iface1, bytes, packets);
                 stats.intIface = iface0;
                 stats.extIface = iface1;
                 stats.rxPackets = packets;
                 stats.rxBytes = bytes;
             } else if (stats.intIface == iface1 && stats.extIface == iface0) {
-                ALOGV("0Filter TX iface_in=%s iface_out=%s rx_bytes=%lld rx_packets=%lld ", iface0, iface1, bytes, packets);
+                ALOGV("0Filter TX iface_in=%s iface_out=%s rx_bytes=%" PRId64" rx_packets=%" PRId64" ", iface0, iface1, bytes, packets);
                 stats.txPackets = packets;
                 stats.txBytes = bytes;
             }
         }
         if (stats.rxBytes != -1 && stats.txBytes != -1) {
-            ALOGV("rx_bytes=%lld tx_bytes=%lld filterPair=%d", stats.rxBytes, stats.txBytes, filterPair);
+            ALOGV("rx_bytes=%" PRId64" tx_bytes=%" PRId64" filterPair=%d", stats.rxBytes, stats.txBytes, filterPair);
             /* Send out stats, and prep for the next if needed. */
             char *msg = stats.getStatsLine();
             if (filterPair) {
@@ -1185,7 +1188,7 @@ int BandwidthController::parseForwardChainStats(SocketClient *cli, const TetherS
 
 char *BandwidthController::TetherStats::getStatsLine(void) const {
     char *msg;
-    asprintf(&msg, "%s %s %lld %lld %lld %lld", intIface.c_str(), extIface.c_str(),
+    asprintf(&msg, "%s %s %" PRId64" %" PRId64" %" PRId64" %" PRId64, intIface.c_str(), extIface.c_str(),
             rxBytes, rxPackets, txBytes, txPackets);
     return msg;
 }
index 9706fe1..7f374fc 100644 (file)
@@ -26,6 +26,9 @@
 #include <string.h>
 #include <linux/if.h>
 
+#define __STDC_FORMAT_MACROS 1
+#include <inttypes.h>
+
 #define LOG_TAG "CommandListener"
 
 #include <cutils/log.h>
@@ -1113,7 +1116,7 @@ int CommandListener::BandwidthControlCmd::runCommand(SocketClient *cli, int argc
         }
 
         char *msg;
-        asprintf(&msg, "%lld", bytes);
+        asprintf(&msg, "%" PRId64, bytes);
         cli->sendMsg(ResponseCode::QuotaCounterResult, msg, false);
         free(msg);
         return 0;
@@ -1132,7 +1135,7 @@ int CommandListener::BandwidthControlCmd::runCommand(SocketClient *cli, int argc
             return 0;
         }
         char *msg;
-        asprintf(&msg, "%lld", bytes);
+        asprintf(&msg, "%" PRId64, bytes);
         cli->sendMsg(ResponseCode::QuotaCounterResult, msg, false);
         free(msg);
         return 0;
index 6990f26..e0619f7 100644 (file)
@@ -344,10 +344,10 @@ void DnsProxyListener::GetHostByNameHandler::run() {
     hp = android_gethostbynameforiface(mName, mAf, mIface ? mIface : iface, mMark);
 
     if (DBG) {
-        ALOGD("GetHostByNameHandler::run gethostbyname errno: %s hp->h_name = %s, name_len = %d\n",
+        ALOGD("GetHostByNameHandler::run gethostbyname errno: %s hp->h_name = %s, name_len = %zu\n",
                 hp ? "success" : strerror(errno),
-                (hp && hp->h_name) ? hp->h_name: "null",
-                (hp && hp->h_name) ? strlen(hp->h_name)+ 1 : 0);
+                (hp && hp->h_name) ? hp->h_name : "null",
+                (hp && hp->h_name) ? strlen(hp->h_name) + 1 : 0);
     }
 
     bool success = true;
@@ -481,10 +481,10 @@ void DnsProxyListener::GetHostByAddrHandler::run() {
             mIface ? mIface : tmp, mark);
 
     if (DBG) {
-        ALOGD("GetHostByAddrHandler::run gethostbyaddr errno: %s hp->h_name = %s, name_len = %d\n",
+        ALOGD("GetHostByAddrHandler::run gethostbyaddr errno: %s hp->h_name = %s, name_len = %zu\n",
                 hp ? "success" : strerror(errno),
-                (hp && hp->h_name) ? hp->h_name: "null",
-                (hp && hp->h_name) ? strlen(hp->h_name)+ 1 : 0);
+                (hp && hp->h_name) ? hp->h_name : "null",
+                (hp && hp->h_name) ? strlen(hp->h_name) + 1 : 0);
     }
 
     bool success = true;
index 5d8a8b5..534f386 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -75,6 +76,12 @@ void NetlinkHandler::onEvent(NetlinkEvent *evt) {
             if (iface && flags && scope) {
                 notifyAddressChanged(action, address, iface, flags, scope);
             }
+        } else if (action == evt->NlActionRdnss) {
+            const char *lifetime = evt->findParam("LIFETIME");
+            const char *servers = evt->findParam("SERVERS");
+            if (lifetime && servers) {
+                notifyInterfaceDnsServers(iface, lifetime, servers);
+            }
         }
 
     } else if (!strcmp(subsys, "qlog")) {
@@ -101,67 +108,59 @@ void NetlinkHandler::onEvent(NetlinkEvent *evt) {
     }
 }
 
-void NetlinkHandler::notifyInterfaceAdded(const char *name) {
-    char msg[255];
-    snprintf(msg, sizeof(msg), "Iface added %s", name);
+void NetlinkHandler::notify(int code, const char *format, ...) {
+    char *msg;
+    va_list args;
+    va_start(args, format);
+    if (vasprintf(&msg, format, args) >= 0) {
+        mNm->getBroadcaster()->sendBroadcast(code, msg, false);
+        free(msg);
+    } else {
+        SLOGE("Failed to send notification: vasprintf: %s", strerror(errno));
+    }
+    va_end(args);
+}
 
-    mNm->getBroadcaster()->sendBroadcast(ResponseCode::InterfaceChange,
-            msg, false);
+void NetlinkHandler::notifyInterfaceAdded(const char *name) {
+    notify(ResponseCode::InterfaceChange, "Iface added %s", name);
 }
 
 void NetlinkHandler::notifyInterfaceRemoved(const char *name) {
-    char msg[255];
-    snprintf(msg, sizeof(msg), "Iface removed %s", name);
-
-    mNm->getBroadcaster()->sendBroadcast(ResponseCode::InterfaceChange,
-            msg, false);
+    notify(ResponseCode::InterfaceChange, "Iface removed %s", name);
 }
 
 void NetlinkHandler::notifyInterfaceChanged(const char *name, bool isUp) {
-    char msg[255];
-    snprintf(msg, sizeof(msg), "Iface changed %s %s", name,
-             (isUp ? "up" : "down"));
-
-    mNm->getBroadcaster()->sendBroadcast(ResponseCode::InterfaceChange,
-            msg, false);
+    notify(ResponseCode::InterfaceChange,
+           "Iface changed %s %s", name, (isUp ? "up" : "down"));
 }
 
 void NetlinkHandler::notifyInterfaceLinkChanged(const char *name, bool isUp) {
-    char msg[255];
-    snprintf(msg, sizeof(msg), "Iface linkstate %s %s", name,
-             (isUp ? "up" : "down"));
-
-    mNm->getBroadcaster()->sendBroadcast(ResponseCode::InterfaceChange,
-            msg, false);
+    notify(ResponseCode::InterfaceChange,
+           "Iface linkstate %s %s", name, (isUp ? "up" : "down"));
 }
 
 void NetlinkHandler::notifyQuotaLimitReached(const char *name, const char *iface) {
-    char msg[255];
-    snprintf(msg, sizeof(msg), "limit alert %s %s", name, iface);
-
-    mNm->getBroadcaster()->sendBroadcast(ResponseCode::BandwidthControl,
-            msg, false);
+    notify(ResponseCode::BandwidthControl, "limit alert %s %s", name, iface);
 }
 
 void NetlinkHandler::notifyInterfaceClassActivity(const char *name,
                                                   bool isActive) {
-    char msg[255];
-
-    snprintf(msg, sizeof(msg), "IfaceClass %s %s",
-             isActive ? "active" : "idle", name);
-    ALOGV("Broadcasting interface activity msg: %s", msg);
-    mNm->getBroadcaster()->sendBroadcast(
-        ResponseCode::InterfaceClassActivity, msg, false);
+    notify(ResponseCode::InterfaceClassActivity,
+           "IfaceClass %s %s", isActive ? "active" : "idle", name);
 }
 
 void NetlinkHandler::notifyAddressChanged(int action, const char *addr,
                                           const char *iface, const char *flags,
                                           const char *scope) {
-    char msg[255];
-    snprintf(msg, sizeof(msg), "Address %s %s %s %s %s",
-             (action == NetlinkEvent::NlActionAddressUpdated) ?
-             "updated" : "removed", addr, iface, flags, scope);
+    notify(ResponseCode::InterfaceAddressChange,
+           "Address %s %s %s %s %s",
+           (action == NetlinkEvent::NlActionAddressUpdated) ?
+           "updated" : "removed", addr, iface, flags, scope);
+}
 
-    mNm->getBroadcaster()->sendBroadcast(ResponseCode::InterfaceAddressChange,
-            msg, false);
+void NetlinkHandler::notifyInterfaceDnsServers(const char *iface,
+                                               const char *lifetime,
+                                               const char *servers) {
+    notify(ResponseCode::InterfaceDnsInfo, "DnsInfo servers %s %s %s",
+           iface, lifetime, servers);
 }
index 0cbf339..94b7282 100644 (file)
@@ -33,6 +33,7 @@ public:
 protected:
     virtual void onEvent(NetlinkEvent *evt);
 
+    void notify(int code, const char *format, ...);
     void notifyInterfaceAdded(const char *name);
     void notifyInterfaceRemoved(const char *name);
     void notifyInterfaceChanged(const char *name, bool isUp);
@@ -41,5 +42,8 @@ protected:
     void notifyInterfaceClassActivity(const char *name, bool isActive);
     void notifyAddressChanged(int action, const char *addr, const char *iface,
                               const char *flags, const char *scope);
+    void notifyInterfaceDnsServers(const char *iface, const char *lifetime,
+                                   const char *servers);
+
 };
 #endif
index d3cffd7..32578a1 100644 (file)
@@ -104,7 +104,8 @@ int NetlinkManager::start() {
     if ((mRouteHandler = setupSocket(&mRouteSock, NETLINK_ROUTE,
                                      RTMGRP_LINK |
                                      RTMGRP_IPV4_IFADDR |
-                                     RTMGRP_IPV6_IFADDR,
+                                     RTMGRP_IPV6_IFADDR |
+                                     (1 << (RTNLGRP_ND_USEROPT - 1)),
          NetlinkListener::NETLINK_FORMAT_BINARY)) == NULL) {
         return -1;
     }
index 46b842d..d8fafbb 100644 (file)
@@ -76,5 +76,6 @@ public:
     static const int ServiceGetAddrInfoSuccess      = 612;
     static const int InterfaceClassActivity         = 613;
     static const int InterfaceAddressChange         = 614;
+    static const int InterfaceDnsInfo               = 615;
 };
 #endif
index 743742c..32a0b43 100644 (file)
@@ -96,6 +96,8 @@ bool TetherController::getIpFwdEnabled() {
     return (enabled  == '1' ? true : false);
 }
 
+#define TETHER_START_CONST_ARG        8
+
 int TetherController::startTethering(int num_addrs, struct in_addr* addrs) {
     if (mDaemonPid != 0) {
         ALOGE("Tethering already started");
@@ -134,19 +136,20 @@ int TetherController::startTethering(int num_addrs, struct in_addr* addrs) {
             close(pipefd[0]);
         }
 
-        int num_processed_args = 7 + (num_addrs/2) + 1; // 1 null for termination
+        int num_processed_args = TETHER_START_CONST_ARG + (num_addrs/2) + 1;
         char **args = (char **)malloc(sizeof(char *) * num_processed_args);
         args[num_processed_args - 1] = NULL;
         args[0] = (char *)"/system/bin/dnsmasq";
         args[1] = (char *)"--keep-in-foreground";
         args[2] = (char *)"--no-resolv";
         args[3] = (char *)"--no-poll";
+        args[4] = (char *)"--dhcp-authoritative";
         // TODO: pipe through metered status from ConnService
-        args[4] = (char *)"--dhcp-option-force=43,ANDROID_METERED";
-        args[5] = (char *)"--pid-file";
-        args[6] = (char *)"";
+        args[5] = (char *)"--dhcp-option-force=43,ANDROID_METERED";
+        args[6] = (char *)"--pid-file";
+        args[7] = (char *)"";
 
-        int nextArg = 7;
+        int nextArg = TETHER_START_CONST_ARG;
         for (int addrIndex=0; addrIndex < num_addrs;) {
             char *start = strdup(inet_ntoa(addrs[addrIndex++]));
             char *end = strdup(inet_ntoa(addrs[addrIndex++]));