<rdar://problem/6434656> Sleep Proxy: Put owner OPT records in multicast announcement...
authorcheshire@apple.com <cheshire@apple.com@214c2c4a-bf3b-4dcf-9390-e4dd3010487d>
Wed, 2 Sep 2009 01:01:16 +0000 (01:01 +0000)
committercheshire@apple.com <cheshire@apple.com@214c2c4a-bf3b-4dcf-9390-e4dd3010487d>
Wed, 2 Sep 2009 01:01:16 +0000 (01:01 +0000)
Fixed incorrect calculation of OwnerRecordSpace.
Because of missing parentheses, and '+' binding tighter than '?:', the expression:
 DNSOpt_Header_Space +  mDNSSameEthAddress(&m->PrimaryMAC, &intf->MAC)  ? DNSOpt_OwnerData_ID_Space : DNSOpt_OwnerData_ID_Wake_Space
evaluated as
(DNSOpt_Header_Space +  mDNSSameEthAddress(&m->PrimaryMAC, &intf->MAC)) ? DNSOpt_OwnerData_ID_Space : DNSOpt_OwnerData_ID_Wake_Space
instead of
 DNSOpt_Header_Space + (mDNSSameEthAddress(&m->PrimaryMAC, &intf->MAC)  ? DNSOpt_OwnerData_ID_Space : DNSOpt_OwnerData_ID_Wake_Space)
This made the result *always* DNSOpt_OwnerData_ID_Space, when it should have been one of
(DNSOpt_Header_Space + DNSOpt_OwnerData_ID_Space) or
(DNSOpt_Header_Space + DNSOpt_OwnerData_ID_Wake_Space)

git-svn-id: http://svn.macosforge.org/repository/mDNSResponder/trunk@6640 214c2c4a-bf3b-4dcf-9390-e4dd3010487d

mDNSCore/mDNS.c
mDNSCore/mDNSEmbeddedAPI.h

index d9ba660..22c1b4a 100755 (executable)
@@ -1194,8 +1194,9 @@ mDNSlocal void SetupOwnerOpt(const mDNS *const m, const NetworkInterfaceInfo *co
        owner->u.owner.password = zeroEthAddr;
 
        // Don't try to compute the optlen until *after* we've set up the data fields
+       // Right now the DNSOpt_Owner_Space macro does not depend on the owner->u.owner being set up correctly, but in the future it might
        owner->opt              = kDNSOpt_Owner;
-       owner->optlen           = DNSOpt_Owner_Space(owner) - 4;
+       owner->optlen           = DNSOpt_Owner_Space(&m->PrimaryMAC, &intf->MAC) - 4;
        }
 
 mDNSlocal void GrantUpdateCredit(AuthRecord *rr)
@@ -1380,8 +1381,7 @@ mDNSlocal void SendResponses(mDNS *const m)
 
        while (intf)
                {
-               const int OwnerRecordSpace = (m->AnnounceOwner && intf->MAC.l[0]) ?
-                       DNSOpt_Header_Space + mDNSSameEthAddress(&m->PrimaryMAC, &intf->MAC) ? DNSOpt_OwnerData_ID_Space : DNSOpt_OwnerData_ID_Wake_Space : 0;
+               const int OwnerRecordSpace = (m->AnnounceOwner && intf->MAC.l[0]) ? DNSOpt_Header_Space + DNSOpt_Owner_Space(&m->PrimaryMAC, &intf->MAC) : 0;
                int numDereg    = 0;
                int numAnnounce = 0;
                int numAnswer   = 0;
@@ -2159,8 +2159,7 @@ mDNSlocal void SendQueries(mDNS *const m)
        // go through our interface list sending the appropriate queries on each interface
        while (intf)
                {
-               const int OwnerRecordSpace = (m->AnnounceOwner && intf->MAC.l[0]) ?
-                       DNSOpt_Header_Space + mDNSSameEthAddress(&m->PrimaryMAC, &intf->MAC) ? DNSOpt_OwnerData_ID_Space : DNSOpt_OwnerData_ID_Wake_Space : 0;
+               const int OwnerRecordSpace = (m->AnnounceOwner && intf->MAC.l[0]) ? DNSOpt_Header_Space + DNSOpt_Owner_Space(&m->PrimaryMAC, &intf->MAC) : 0;
                AuthRecord *rr;
                mDNSu8 *queryptr = m->omsg.data;
                InitializeDNSMessage(&m->omsg.h, zeroID, QueryFlags);
@@ -3311,8 +3310,7 @@ mDNSexport void mDNSCoreRestartQueries(mDNS *const m)
 
 mDNSlocal void SendSPSRegistration(mDNS *const m, NetworkInterfaceInfo *intf, const mDNSOpaque16 id)
        {
-       const int ownerspace = mDNSSameEthAddress(&m->PrimaryMAC, &intf->MAC) ? DNSOpt_OwnerData_ID_Space : DNSOpt_OwnerData_ID_Wake_Space;
-       const int optspace = DNSOpt_Header_Space + DNSOpt_LeaseData_Space + ownerspace;
+       const int optspace = DNSOpt_Header_Space + DNSOpt_LeaseData_Space + DNSOpt_Owner_Space(&m->PrimaryMAC, &intf->MAC);
        const int sps = intf->NextSPSAttempt / 3;
        AuthRecord *rr;
 
index ebe6b28..617f919 100755 (executable)
@@ -698,12 +698,12 @@ typedef packedstruct
                                                ((O)->opt == kDNSOpt_Lease && (O)->optlen == DNSOpt_LeaseData_Space - 4) || \
                                                ((O)->opt == kDNSOpt_Owner && ValidOwnerLength((O)->optlen)            )    )
 
-#define DNSOpt_Owner_Space(O) (mDNSSameEthAddress(&(O)->u.owner.HMAC, &(O)->u.owner.IMAC) ? DNSOpt_OwnerData_ID_Space : DNSOpt_OwnerData_ID_Wake_Space)
+#define DNSOpt_Owner_Space(A,B) (mDNSSameEthAddress((A),(B)) ? DNSOpt_OwnerData_ID_Space : DNSOpt_OwnerData_ID_Wake_Space)
 
 #define DNSOpt_Data_Space(O) (                                  \
        (O)->opt == kDNSOpt_LLQ   ? DNSOpt_LLQData_Space   :        \
        (O)->opt == kDNSOpt_Lease ? DNSOpt_LeaseData_Space :        \
-       (O)->opt == kDNSOpt_Owner ? DNSOpt_Owner_Space(O)  : 0x10000)
+       (O)->opt == kDNSOpt_Owner ? DNSOpt_Owner_Space(&(O)->u.owner.HMAC, &(O)->u.owner.IMAC) : 0x10000)
 
 // A maximal NSEC record is:
 //   256 bytes domainname 'nextname'