<rdar://problem/7144871> back-merge v6, No IOPOWER, No IPSec, etc. changes
authorrlpm@apple.com <rlpm@apple.com@214c2c4a-bf3b-4dcf-9390-e4dd3010487d>
Fri, 2 Oct 2009 00:06:59 +0000 (00:06 +0000)
committerrlpm@apple.com <rlpm@apple.com@214c2c4a-bf3b-4dcf-9390-e4dd3010487d>
Fri, 2 Oct 2009 00:06:59 +0000 (00:06 +0000)
git-svn-id: http://svn.macosforge.org/repository/mDNSResponder/trunk@6731 214c2c4a-bf3b-4dcf-9390-e4dd3010487d

mDNSMacOSX/daemon.c
mDNSMacOSX/helper.c
mDNSMacOSX/mDNSMacOSX.c
mDNSMacOSX/mDNSMacOSX.h
mDNSMacOSX/pfkey.c
mDNSMacOSX/safe_vproc.c

index 0778e52..e4881cc 100644 (file)
@@ -47,6 +47,7 @@
 #include <SystemConfiguration/SCDynamicStoreCopyDHCPInfo.h>
 
 #if TARGET_OS_EMBEDDED
+#define NO_IOPOWER 1
 #include <bootstrap_priv.h>
 
 #define bootstrap_register(A,B,C) bootstrap_register2((A),(B),(C),0)
@@ -2193,7 +2194,7 @@ mDNSlocal mDNSBool AllowSleepNow(mDNS *const m, mDNSs32 now)
                }
 
        LogSPS("AllowSleepNow: %s(%lX) %s at %ld (%d ticks remaining)",
-#ifdef kIOPMAcknowledgmentOptionSystemCapabilityRequirements
+#if !defined(NO_IOPOWER) && defined(kIOPMAcknowledgmentOptionSystemCapabilityRequirements)
                (m->p->IOPMConnection) ? "IOPMConnectionAcknowledgeEventWithOptions" :
 #endif
                (result == kIOReturnSuccess) ? "IOAllowPowerChange" : "IOCancelPowerChange",
@@ -2201,7 +2202,7 @@ mDNSlocal mDNSBool AllowSleepNow(mDNS *const m, mDNSs32 now)
 
        m->SleepLimit = 0;      // Don't clear m->SleepLimit until after we've logged it above
 
-#ifdef kIOPMAcknowledgmentOptionSystemCapabilityRequirements
+#if !defined(NO_IOPOWER) && defined(kIOPMAcknowledgmentOptionSystemCapabilityRequirements)
        if (m->p->IOPMConnection) IOPMConnectionAcknowledgeEventWithOptions(m->p->IOPMConnection, m->p->SleepCookie, opts);
        else
 #endif
index 96622df..06e37f6 100644 (file)
@@ -60,6 +60,9 @@
 #endif
 
 #if TARGET_OS_EMBEDDED
+#ifndef MDNS_NO_IPSEC
+#define MDNS_NO_IPSEC 1
+#endif
 #define NO_CFUSERNOTIFICATION 1
 #define NO_SECURITYFRAMEWORK 1
 #endif
@@ -273,6 +276,9 @@ kern_return_t do_mDNSNotify(__unused mach_port_t port, const char *title, const
        if (err) helplog(ASL_LEVEL_ERR, "CFUserNotificationDisplayNotice returned %d", err);
        CFRelease(alertHeader);
        CFRelease(alertMessage);
+#else
+       (void)title;
+       (void)msg;
 #endif /* NO_CFUSERNOTIFICATION */
 
        update_idle_timer();
@@ -1093,7 +1099,6 @@ do_mDNSAutoTunnelInterfaceUpDown(__unused mach_port_t port, int updown,
 fin:
 #else
        (void)port; (void)updown; (void)address; (void)token;
-       *err = kmDNSHelperIPsecDisabled;
 #endif
        update_idle_timer();
        return KERN_SUCCESS;
@@ -1670,7 +1675,6 @@ do_mDNSConfigureServer(__unused mach_port_t port, int updown, const char *fqdn,
 fin:
 #else
        (void)port; (void)updown; (void)fqdn; (void)token;
-       *err = kmDNSHelperIPsecDisabled;
 #endif
        update_idle_timer();
        return KERN_SUCCESS;
@@ -2188,7 +2192,7 @@ fin:
        unlink(tmp_path);
 #else
        (void)replacedelete; (void)loc_inner; (void)loc_outer; (void)loc_port; (void)rmt_inner;
-       (void)rmt_outer; (void)rmt_port; (void)keydata; (void)token;
+       (void)rmt_outer; (void)rmt_port; (void)fqdn; (void)token;
        
        *err = kmDNSHelperIPsecDisabled;
 #endif /* MDNS_NO_IPSEC */
index eceb23b..37c6ad3 100644 (file)
@@ -79,6 +79,7 @@
 #if TARGET_OS_EMBEDDED
 #define NO_SECURITYFRAMEWORK 1
 #define NO_CFUSERNOTIFICATION 1
+#define NO_IOPOWER 1
 #endif
 
 #ifndef NO_SECURITYFRAMEWORK
@@ -391,6 +392,7 @@ mDNSexport mStatus mDNSPlatformSendUDP(const mDNS *const m, const void *const ms
                                }
                        }
                }
+#ifndef NO_IPV6
        else if (dst->type == mDNSAddrType_IPv6)
                {
                struct sockaddr_in6 *sin6_to = (struct sockaddr_in6*)&to;
@@ -407,6 +409,7 @@ mDNSexport mStatus mDNSPlatformSendUDP(const mDNS *const m, const void *const ms
                        if (err < 0) LogMsg("setsockopt - IPV6_MULTICAST_IF error %d errno %d (%s)", err, errno, strerror(errno));
                        }
                }
+#endif
        else
                {
                LogMsg("mDNSPlatformSendUDP: dst is not an IPv4 or IPv6 address!");
@@ -551,11 +554,17 @@ mDNSlocal void myKQSocketCallBack(int s1, short filter, void *context)
        if (filter != EVFILT_READ)
                LogMsg("myKQSocketCallBack: Why is filter %d not EVFILT_READ (%d)?", filter, EVFILT_READ);
 
-       if (s1 != ss->sktv4 && s1 != ss->sktv6)
+       if (s1 != ss->sktv4
+#ifndef NO_IPV6
+               && s1 != ss->sktv6
+#endif
+               )
                {
                LogMsg("myKQSocketCallBack: native socket %d", s1);
                LogMsg("myKQSocketCallBack: sktv4 %d", ss->sktv4);
+#ifndef NO_IPV6
                LogMsg("myKQSocketCallBack: sktv6 %d", ss->sktv6);
+#endif
                }
 
        while (!closed)
@@ -1158,12 +1167,21 @@ mDNSexport int mDNSPlatformTCPGetFD(TCPSocket *sock)
 // If mDNSIPPort port is zero, then it's a randomly assigned port number, used for sending unicast queries
 mDNSlocal mStatus SetupSocket(KQSocketSet *cp, const mDNSIPPort port, u_short sa_family, mDNSIPPort *const outport)
        {
+#ifndef NO_IPV6
        int         *s        = (sa_family == AF_INET) ? &cp->sktv4 : &cp->sktv6;
        KQueueEntry     *k        = (sa_family == AF_INET) ? &cp->kqsv4 : &cp->kqsv6;
+#else
+       int         *s        = &cp->sktv4;
+       KQueueEntry     *k        = &cp->kqsv4;
+#endif
        const int on = 1;
        const int twofivefive = 255;
        mStatus err = mStatus_NoError;
        char *errstr = mDNSNULL;
+
+#ifdef NO_IPV6
+       if (sa_family != AF_INET) return -1;
+#endif
        
        cp->closeFlag = mDNSNULL;
 
@@ -1205,6 +1223,7 @@ mDNSlocal mStatus SetupSocket(KQSocketSet *cp, const mDNSIPPort port, u_short sa
                if (err) { errstr = "bind"; goto fail; }
                if (outport) outport->NotAnInteger = listening_sockaddr.sin_port;
                }
+#ifndef NO_IPV6
        else if (sa_family == AF_INET6)
                {
                // NAT-PMP Announcements make no sense on IPv6, so bail early w/o error
@@ -1248,6 +1267,7 @@ mDNSlocal mStatus SetupSocket(KQSocketSet *cp, const mDNSIPPort port, u_short sa
                if (err) { errstr = "bind"; goto fail; }
                if (outport) outport->NotAnInteger = listening_sockaddr6.sin6_port;
                }
+#endif
 
        fcntl(skt, F_SETFL, fcntl(skt, F_GETFL, 0) | O_NONBLOCK); // set non-blocking
        fcntl(skt, F_SETFD, 1); // set close-on-exec
@@ -1292,18 +1312,22 @@ mDNSexport UDPSocket *mDNSPlatformUDPSocket(mDNS *const m, const mDNSIPPort requ
        p->ss.port  = zeroIPPort;
        p->ss.m     = m;
        p->ss.sktv4 = -1;
+#ifndef NO_IPV6
        p->ss.sktv6 = -1;
+#endif
 
        do
                {
                // The kernel doesn't do cryptographically strong random port allocation, so we do it ourselves here
                if (randomizePort) port = mDNSOpaque16fromIntVal(0xC000 + mDNSRandom(0x3FFF));
                err = SetupSocket(&p->ss, port, AF_INET, &p->ss.port);
+#ifndef NO_IPV6
                if (!err)
                        {
                        err = SetupSocket(&p->ss, port, AF_INET6, &p->ss.port);
                        if (err) { close(p->ss.sktv4); p->ss.sktv4 = -1; }
                        }
+#endif
                i--;
                } while (err == EADDRINUSE && randomizePort && i);
 
@@ -1329,11 +1353,13 @@ mDNSlocal void CloseSocketSet(KQSocketSet *ss)
                close(ss->sktv4);
                ss->sktv4 = -1;
                }
+#ifndef NO_IPV6
        if (ss->sktv6 != -1)
                {
                close(ss->sktv6);
                ss->sktv6 = -1;
                }
+#endif
        if (ss->closeFlag) *ss->closeFlag = 1;
        }
 
@@ -2057,8 +2083,6 @@ mDNSlocal void RemoveAutoTunnelDomainStatus(const mDNS *const m, const DomainAut
        CFRelease(domain);
        }
 
-#endif // ndef NO_SECURITYFRAMEWORK
-
 mDNSlocal mStatus CheckQuestionForStatus(const DNSQuestion *const q)
        {
        if (q->LongLived)
@@ -2074,6 +2098,8 @@ mDNSlocal mStatus CheckQuestionForStatus(const DNSQuestion *const q)
        return mStatus_NoError;
 }
 
+#endif // ndef NO_SECURITYFRAMEWORK
+
 // MUST be called with lock held
 mDNSlocal void UpdateAutoTunnelDomainStatus(const mDNS *const m, const DomainAuthInfo *const info)
        {
@@ -4750,6 +4776,7 @@ mDNSlocal void PowerChanged(void *refcon, io_service_t service, natural_t messag
                case kIOMessageSystemWillRestart:               LogInfo("PowerChanged kIOMessageSystemWillRestart     (no action)");    break;  // E0000310
                case kIOMessageSystemWillPowerOn:               LogInfo("PowerChanged kIOMessageSystemWillPowerOn");                                                    // E0000320
 
+                                                                                       #if ! TARGET_OS_EMBEDDED
                                                                                                // On Leopard and earlier, on wake from sleep, instead of reporting link state down, Apple
                                                                                                // Ethernet drivers report "hardware incapable of detecting link state", which the kernel
                                                                                                // interprets as "should assume we have networking", which results in the first 4-5 seconds
@@ -4761,6 +4788,7 @@ mDNSlocal void PowerChanged(void *refcon, io_service_t service, natural_t messag
                                                                                                        LogMsg("Running on Mac OS X version 10.%d earlier than 10.6; "
                                                                                                                "PowerChanged did sleep(5) to wait for Ethernet hardware", OSXVers - OSXVers_Base);
                                                                                                        }
+                                                                                       #endif
 
                                                                                                // Make sure our interface list is cleared to the empty state, then tell mDNSCore to wake
                                                                                                if (m->SleepState != SleepState_Sleeping)
@@ -4935,10 +4963,16 @@ mDNSlocal mStatus mDNSPlatformInit_setup(mDNS *const m)
 
        m->p->permanentsockets.port  = MulticastDNSPort;
        m->p->permanentsockets.m     = m;
-       m->p->permanentsockets.sktv4 = m->p->permanentsockets.sktv6 = -1;
-       m->p->permanentsockets.kqsv4.KQcallback = m->p->permanentsockets.kqsv6.KQcallback = myKQSocketCallBack;
-       m->p->permanentsockets.kqsv4.KQcontext  = m->p->permanentsockets.kqsv6.KQcontext  = &m->p->permanentsockets;
-       m->p->permanentsockets.kqsv4.KQtask     = m->p->permanentsockets.kqsv6.KQtask     = "UDP packet reception";
+       m->p->permanentsockets.sktv4 = -1;
+       m->p->permanentsockets.kqsv4.KQcallback = myKQSocketCallBack;
+       m->p->permanentsockets.kqsv4.KQcontext  = &m->p->permanentsockets;
+       m->p->permanentsockets.kqsv4.KQtask     = "UDP packet reception";
+#ifndef NO_IPV6
+       m->p->permanentsockets.sktv6 = -1;
+       m->p->permanentsockets.kqsv6.KQcallback = myKQSocketCallBack;
+       m->p->permanentsockets.kqsv6.KQcontext  = &m->p->permanentsockets;
+       m->p->permanentsockets.kqsv6.KQtask     = "UDP packet reception";
+#endif
 
        err = SetupSocket(&m->p->permanentsockets, MulticastDNSPort, AF_INET, mDNSNULL);
 #ifndef NO_IPV6
index 22fa04e..c236964 100644 (file)
@@ -47,8 +47,10 @@ typedef struct
        mDNS                    *m;
        int                      sktv4;
        KQueueEntry                              kqsv4;
+#ifndef NO_IPV6
        int                      sktv6;
        KQueueEntry                  kqsv6;
+#endif
        int                     *closeFlag;
        } KQSocketSet;
 
index 0944810..9d75414 100644 (file)
 #include <string.h>
 #include <errno.h>
 #include <stdio.h>
+#include <TargetConditionals.h>
 
 #include "ipsec_strerror.h"
 #include "libpfkey.h"
 #include "ipsec_options.h"
 
+#if TARGET_OS_EMBEDDED
+#ifndef MDNS_NO_IPSEC
+#define MDNS_NO_IPSEC 1
+#endif
+#endif
+
 #ifndef MDNS_NO_IPSEC
 
 #define CALLOC(size, cast) (cast)calloc(1, (size))
index 3305981..a6b737e 100644 (file)
@@ -20,8 +20,9 @@
 #include <vproc.h>
 #include "safe_vproc.h"
 #include "mDNSDebug.h"
+#include <TargetConditionals.h>
 
-#ifdef VPROC_HAS_TRANSACTIONS
+#if defined(VPROC_HAS_TRANSACTIONS) && !TARGET_OS_EMBEDDED
 
 static vproc_transaction_t transaction = NULL;
 
@@ -45,6 +46,7 @@ void safe_vproc_transaction_end(void)
 
 #else
 
+#if ! TARGET_OS_EMBEDDED
 #include <stdio.h>
 #include <CoreFoundation/CFString.h>
 
@@ -71,6 +73,12 @@ void safe_vproc_transaction_begin(void)
                }
        }
 
+#else
+
+void safe_vproc_transaction_begin(void) { }
+
+#endif
+
 void safe_vproc_transaction_end(void) { }
 
 #endif