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
LOCAL_MODULE:= ndc
-LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
+LOCAL_C_INCLUDES :=
-LOCAL_CFLAGS :=
+LOCAL_CFLAGS :=
LOCAL_SHARED_LIBRARIES := libcutils
#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>
#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";
char *buff;
const char *opFlag;
- ALOGV("makeIptablesQuotaCmd(%d, %lld)", op, quota);
+ ALOGV("makeIptablesQuotaCmd(%d, %" PRId64")", op, quota);
switch (op) {
case IptOpInsert:
}
// 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);
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;
}
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;
}
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;
*/
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;
}
} 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) {
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;
}
#include <string.h>
#include <linux/if.h>
+#define __STDC_FORMAT_MACROS 1
+#include <inttypes.h>
+
#define LOG_TAG "CommandListener"
#include <cutils/log.h>
}
char *msg;
- asprintf(&msg, "%lld", bytes);
+ asprintf(&msg, "%" PRId64, bytes);
cli->sendMsg(ResponseCode::QuotaCounterResult, msg, false);
free(msg);
return 0;
return 0;
}
char *msg;
- asprintf(&msg, "%lld", bytes);
+ asprintf(&msg, "%" PRId64, bytes);
cli->sendMsg(ResponseCode::QuotaCounterResult, msg, false);
free(msg);
return 0;
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;
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;
* limitations under the License.
*/
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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")) {
}
}
-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);
}
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);
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
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;
}
static const int ServiceGetAddrInfoSuccess = 612;
static const int InterfaceClassActivity = 613;
static const int InterfaceAddressChange = 614;
+ static const int InterfaceDnsInfo = 615;
};
#endif
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");
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++]));