aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-06-15 21:41:25 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-06-15 21:41:25 +0000
commit2e0aebb55b8e786ba9b3589a5d6e74a8e8aad87b (patch)
tree6eb0369981268c07ff9b815b3fdc0d689761bcbc
parent796145647dfd82621a073c8dadc14be77350d17f (diff)
parent367fbcafb56896f8da3bf09581becc6161ae2563 (diff)
downloadmdnsresponder-aml_tz3_314012010.tar.gz
Change-Id: I512e1ec8071f3bdcf51c18e036d9050da57a7f5e
-rw-r--r--Android.bp74
-rw-r--r--METADATA4
-rw-r--r--OWNERS7
-rwxr-xr-xmDNSCore/mDNS.c2
-rw-r--r--mDNSPosix/mDNSPosix.c102
-rwxr-xr-xmDNSPosix/mDNSUNP.c2
-rw-r--r--mDNSShared/dnssd_clientstub.c2
7 files changed, 96 insertions, 97 deletions
diff --git a/Android.bp b/Android.bp
index ff8eec8..30cba16 100644
--- a/Android.bp
+++ b/Android.bp
@@ -102,31 +102,85 @@ cc_defaults {
cc_binary {
name: "mdnsd",
defaults: ["mdnsresponder_default_cflags"],
+ host_supported: true,
srcs: [
- "mDNSCore/DNSCommon.c",
- "mDNSCore/DNSDigest.c",
"mDNSCore/mDNS.c",
+ "mDNSCore/DNSDigest.c",
"mDNSCore/uDNS.c",
- "mDNSPosix/mDNSPosix.c",
- "mDNSPosix/mDNSUNP.c",
- "mDNSPosix/PosixDaemon.c",
+ "mDNSCore/DNSCommon.c",
+ "mDNSShared/uds_daemon.c",
+ "mDNSShared/mDNSDebug.c",
"mDNSShared/dnssd_ipc.c",
"mDNSShared/GenLinkedList.c",
- "mDNSShared/mDNSDebug.c",
- "mDNSShared/PlatformCommon.c",
- "mDNSShared/uds_daemon.c",
],
local_include_dirs: [
"mDNSCore",
- "mDNSPosix",
"mDNSShared",
],
init_rc: ["mdnsd.rc"],
cflags: ["-DMDNS_VERSIONSTR_NODTS=1"],
- shared_libs: [
+ target: {
+ android: {
+ static_executable: true,
+ local_include_dirs: ["mDNSPosix"],
+ srcs: [
+ "mDNSShared/PlatformCommon.c",
+ "mDNSPosix/PosixDaemon.c",
+ "mDNSPosix/mDNSPosix.c",
+ "mDNSPosix/mDNSUNP.c",
+ ],
+ },
+ not_windows: {
+ local_include_dirs: ["mDNSPosix"],
+ srcs: [
+ "mDNSShared/PlatformCommon.c",
+ "mDNSPosix/PosixDaemon.c",
+ "mDNSPosix/mDNSPosix.c",
+ "mDNSPosix/mDNSUNP.c",
+ ],
+ },
+ windows: {
+ cflags: [
+ "-DTARGET_OS_WIN32",
+ "-D_CONSOLE",
+ "-DPLATFORM_NO_STRSEP",
+ "-DPLATFORM_NO_EPIPE",
+ "-DPLATFORM_NO_RLIMIT",
+ "-DPID_FILE=\"\"",
+ "-DUNICODE",
+ "-D_UNICODE",
+ "-D_LEGACY_NAT_TRAVERSAL",
+ "-Wno-empty-body",
+ ],
+
+ ldflags: ["-municode"],
+ host_ldlibs: [
+ "-lws2_32",
+ "-liphlpapi",
+ "-lpowrprof",
+ "-lnetapi32",
+ ],
+
+ srcs: [
+ "mDNSWindows/SystemService/main.c",
+ "mDNSWindows/SystemService/Service.c",
+ "mDNSWindows/SystemService/EventLog.mc",
+ "mDNSWindows/Secret.c",
+ "mDNSWindows/mDNSWin32.c",
+ "mDNSShared/DebugServices.c",
+ "android/windows_firewall_dummy.c",
+ ],
+
+ local_include_dirs: [
+ "mDNSWindows/SystemService",
+ ],
+ },
+ },
+
+ static_libs: [
"libcutils",
"liblog",
],
diff --git a/METADATA b/METADATA
index 71acc7b..d97975c 100644
--- a/METADATA
+++ b/METADATA
@@ -1,7 +1,3 @@
third_party {
license_type: NOTICE
- security {
- # Common Platform Enumeration tags
- tag: "NVD-CPE2.3:cpe:/a:apple:mdnsresponder:320.10.80"
- }
}
diff --git a/OWNERS b/OWNERS
index d95f549..fe287c2 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,4 +1,5 @@
-set noparent
-file:platform/packages/modules/Connectivity:master:/OWNERS_core_networking
-
+# Default code reviewers picked from top 3 or more developers.
+# Please update this list if you find better candidates.
+sadmac@google.com
include platform/packages/modules/adb:/OWNERS
+include platform/system/netd:/OWNERS
diff --git a/mDNSCore/mDNS.c b/mDNSCore/mDNS.c
index 257ddfd..e126754 100755
--- a/mDNSCore/mDNS.c
+++ b/mDNSCore/mDNS.c
@@ -4436,7 +4436,7 @@ mDNSexport mDNSs32 mDNS_Execute(mDNS *const m)
}
}
m->NewLocalRecords = head;
- debugf("mDNS_Execute: Setting NewLocalRecords to %s", (head ? ARDisplayString(m, head) : "NULL"));
+ // debugf("mDNS_Execute: Setting NewLocalRecords to %s", (head ? ARDisplayString(m, head) : "NULL"));
if (i >= 1000) LogMsg("mDNS_Execute: m->NewLocalRecords exceeded loop limit");
diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c
index 8960c93..5e47657 100644
--- a/mDNSPosix/mDNSPosix.c
+++ b/mDNSPosix/mDNSPosix.c
@@ -505,7 +505,7 @@ mDNSexport int ParseDNSServers(mDNS *m, const char *filePath)
{
char line[256];
char nameserver[16];
- char keyword[11];
+ char keyword[10];
int numOfServers = 0;
FILE *fp = fopen(filePath, "r");
if (fp == NULL) return -1;
@@ -581,88 +581,42 @@ mDNSexport mDNSu32 mDNSPlatformInterfaceIndexfromInterfaceID(mDNS *const m, mDNS
return intf ? intf->index : 0;
}
-// Remove an interface identified by its index from the provided list, and return it.
-// This takes a pointer to a list of interfaces, where NULL represents the empty list.
-mDNSlocal PosixNetworkInterface *RemoveInterfaceFromListByIndex(PosixNetworkInterface **list, int index)
- {
- while (list && *list)
- {
- PosixNetworkInterface *current = *list;
- if (current->index == index)
- {
- *list = (PosixNetworkInterface*)current->coreIntf.next;
- current->coreIntf.next = NULL;
- return current;
- }
- list = (PosixNetworkInterface**)&(current->coreIntf.next);
- }
- return NULL;
- }
-
-// Close sockets on the specified PosixNetworkInterface structure. The underlying
+// Frees the specified PosixNetworkInterface structure. The underlying
// interface must have already been deregistered with the mDNS core.
-mDNSlocal void ClosePosixNetworkInterface(PosixNetworkInterface *intf)
+mDNSlocal void FreePosixNetworkInterface(PosixNetworkInterface *intf)
{
assert(intf != NULL);
+ if (intf->intfName != NULL) free((void *)intf->intfName);
if (intf->multicastSocket4 != -1)
{
int ipv4_closed = close(intf->multicastSocket4);
assert(ipv4_closed == 0);
- intf->multicastSocket4 = -1;
}
#if HAVE_IPV6
if (intf->multicastSocket6 != -1)
{
int ipv6_closed = close(intf->multicastSocket6);
assert(ipv6_closed == 0);
- intf->multicastSocket6 = -1;
}
#endif
- }
-
-// Free the specified PosixNetworkInterface structure. The underlying
-// interface must have already been deregistered with the mDNS core.
-mDNSlocal void FreePosixNetworkInterface(PosixNetworkInterface *intf)
- {
- assert(intf != NULL);
- assert(intf->coreIntf.next == NULL);
- ClosePosixNetworkInterface(intf);
- free((void *)intf->intfName);
free(intf);
}
-// Frees a list of PosixNetworkInterfaces
-mDNSlocal void FreePosixNetworkInterfaceList(PosixNetworkInterface *intfList)
- {
- while (intfList)
- {
- PosixNetworkInterface *next = (PosixNetworkInterface*)(intfList->coreIntf.next);
- intfList->coreIntf.next = NULL;
- FreePosixNetworkInterface(intfList);
- intfList = next;
- }
- }
-
-// Grab the first interface, deregister it, close it, and repeat until done.
-// Returns the list of deregistered interfaces, or NULL if none.
-mDNSlocal PosixNetworkInterface *CloseInterfaceList(mDNS *const m)
+// Grab the first interface, deregister it, free it, and repeat until done.
+mDNSlocal void ClearInterfaceList(mDNS *const m)
{
assert(m != NULL);
- PosixNetworkInterface *ret = NULL;
+
while (m->HostInterfaces)
{
PosixNetworkInterface *intf = (PosixNetworkInterface*)(m->HostInterfaces);
mDNS_DeregisterInterface(m, &intf->coreIntf, mDNSfalse);
if (gMDNSPlatformPosixVerboseLevel > 0) fprintf(stderr, "Deregistered interface %s\n", intf->intfName);
- ClosePosixNetworkInterface(intf);
- assert(intf->coreIntf.next == NULL);
- intf->coreIntf.next = (NetworkInterfaceInfo*)ret;
- ret = intf;
+ FreePosixNetworkInterface(intf);
}
num_registered_interfaces = 0;
num_pkts_accepted = 0;
num_pkts_rejected = 0;
- return ret;
}
// Sets up a send/receive socket.
@@ -894,10 +848,10 @@ mDNSlocal int SetupSocket(struct sockaddr *intfAddr, mDNSIPPort port, int interf
// Creates a PosixNetworkInterface for the interface whose IP address is
// intfAddr and whose name is intfName and registers it with mDNS core.
-mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct sockaddr *intfMask, const char *intfName, int intfIndex, PosixNetworkInterface **cachedList)
+mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct sockaddr *intfMask, const char *intfName, int intfIndex)
{
int err = 0;
- PosixNetworkInterface *intf = NULL;
+ PosixNetworkInterface *intf;
PosixNetworkInterface *alias = NULL;
assert(m != NULL);
@@ -905,18 +859,15 @@ mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct
assert(intfName != NULL);
assert(intfMask != NULL);
- intf = RemoveInterfaceFromListByIndex(cachedList, intfIndex);
- if (intf == NULL)
+ // Allocate the interface structure itself.
+ intf = (PosixNetworkInterface*)malloc(sizeof(*intf));
+ if (intf == NULL) { assert(0); err = ENOMEM; }
+
+ // And make a copy of the intfName.
+ if (err == 0)
{
- // Allocate the interface structure itself.
- intf = (PosixNetworkInterface*)malloc(sizeof(*intf));
- if (intf == NULL) { assert(0); err = ENOMEM; }
- // And make a copy of the intfName.
- if (err == 0)
- {
- intf->intfName = strdup(intfName);
- if (intf->intfName == NULL) { assert(0); err = ENOMEM; }
- }
+ intf->intfName = strdup(intfName);
+ if (intf->intfName == NULL) { assert(0); err = ENOMEM; }
}
if (err == 0)
@@ -982,7 +933,7 @@ mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct
}
// Call get_ifi_info() to obtain a list of active interfaces and call SetupOneInterface() on each one.
-mDNSlocal int SetupInterfaceList(mDNS *const m, PosixNetworkInterface **cachedList)
+mDNSlocal int SetupInterfaceList(mDNS *const m)
{
mDNSBool foundav4 = mDNSfalse;
int err = 0;
@@ -1021,7 +972,7 @@ mDNSlocal int SetupInterfaceList(mDNS *const m, PosixNetworkInterface **cachedLi
}
else if (i->ifi_flags & (IFF_MULTICAST | IFF_BROADCAST)) // http://b/25669326
{
- if (SetupOneInterface(m, i->ifi_addr, i->ifi_netmask, i->ifi_name, i->ifi_index, cachedList) == 0)
+ if (SetupOneInterface(m, i->ifi_addr, i->ifi_netmask, i->ifi_name, i->ifi_index) == 0)
if (i->ifi_addr->sa_family == AF_INET)
foundav4 = mDNStrue;
}
@@ -1035,7 +986,7 @@ mDNSlocal int SetupInterfaceList(mDNS *const m, PosixNetworkInterface **cachedLi
// In the interim, we skip loopback interface only if we found at least one v4 interface to use
// if ((m->HostInterfaces == NULL) && (firstLoopback != NULL))
if (!foundav4 && firstLoopback)
- (void) SetupOneInterface(m, firstLoopback->ifi_addr, firstLoopback->ifi_netmask, firstLoopback->ifi_name, firstLoopback->ifi_index, cachedList);
+ (void) SetupOneInterface(m, firstLoopback->ifi_addr, firstLoopback->ifi_netmask, firstLoopback->ifi_name, firstLoopback->ifi_index);
}
// Clean up.
@@ -1319,7 +1270,7 @@ mDNSexport mStatus mDNSPlatformInit(mDNS *const m)
#endif
// Tell mDNS core about the network interfaces on this machine.
- if (err == mStatus_NoError) err = SetupInterfaceList(m, NULL);
+ if (err == mStatus_NoError) err = SetupInterfaceList(m);
// Tell mDNS core about DNS Servers
mDNS_Lock(m);
@@ -1351,9 +1302,7 @@ mDNSexport mStatus mDNSPlatformInit(mDNS *const m)
mDNSexport void mDNSPlatformClose(mDNS *const m)
{
assert(m != NULL);
- PosixNetworkInterface *closedList = CloseInterfaceList(m);
- FreePosixNetworkInterfaceList(closedList);
-
+ ClearInterfaceList(m);
if (m->p->unicastSocket4 != -1)
{
int ipv4_closed = close(m->p->unicastSocket4);
@@ -1371,9 +1320,8 @@ mDNSexport void mDNSPlatformClose(mDNS *const m)
mDNSexport mStatus mDNSPlatformPosixRefreshInterfaceList(mDNS *const m)
{
int err;
- PosixNetworkInterface *closedList = CloseInterfaceList(m);
- err = SetupInterfaceList(m, &closedList);
- FreePosixNetworkInterfaceList(closedList);
+ ClearInterfaceList(m);
+ err = SetupInterfaceList(m);
return PosixErrorToStatus(err);
}
diff --git a/mDNSPosix/mDNSUNP.c b/mDNSPosix/mDNSUNP.c
index f5d0c52..5379b6b 100755
--- a/mDNSPosix/mDNSUNP.c
+++ b/mDNSPosix/mDNSUNP.c
@@ -106,7 +106,7 @@ struct ifi_info *get_ifi_info_linuxv6(int family, int doaliases)
goto gotError;
}
while (fscanf(fp,
- "%4s%4s%4s%4s%4s%4s%4s%4s %x %02x %02x %02x %15s\n",
+ "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %15s\n",
addr[0],addr[1],addr[2],addr[3],
addr[4],addr[5],addr[6],addr[7],
&index, &plen, &scope, &flags, ifname) != EOF) {
diff --git a/mDNSShared/dnssd_clientstub.c b/mDNSShared/dnssd_clientstub.c
index 574c77b..637c83c 100644
--- a/mDNSShared/dnssd_clientstub.c
+++ b/mDNSShared/dnssd_clientstub.c
@@ -75,7 +75,7 @@ static int gDaemonErr = kDNSServiceErr_NoError;
#else
#ifndef __ANDROID__
- #include <fcntl.h> // For O_RDWR etc.
+ #include <sys/fcntl.h> // For O_RDWR etc.
#else
#include <fcntl.h>
#define LOG_TAG "libmdns"