Lines Matching defs:rr

58 #define SetNextuDNSEvent(m, rr) { \
59 if ((m)->NextuDNSEvent - ((rr)->LastAPTime + (rr)->ThisAPInterval) >= 0) \
60 (m)->NextuDNSEvent = ((rr)->LastAPTime + (rr)->ThisAPInterval); \
71 mDNSlocal void SetRecordRetry(mDNS *const m, AuthRecord *rr, mDNSu32 random)
73 rr->LastAPTime = m->timenow;
75 if (rr->expire && rr->refreshCount < MAX_UPDATE_REFRESH_COUNT)
77 mDNSs32 remaining = rr->expire - m->timenow;
78 rr->refreshCount++;
82 rr->ThisAPInterval = 7 * (remaining/10) + (random ? random : mDNSRandom(remaining/10));
84 if (rr->ThisAPInterval < MIN_UPDATE_REFRESH_TIME)
85 rr->ThisAPInterval = MIN_UPDATE_REFRESH_TIME;
87 rr->ThisAPInterval/mDNSPlatformOneSecond, (rr->expire - m->timenow)/mDNSPlatformOneSecond, ARDisplayString(m, rr));
91 rr->ThisAPInterval = MIN_UPDATE_REFRESH_TIME;
93 rr->ThisAPInterval/mDNSPlatformOneSecond, (rr->expire - m->timenow)/mDNSPlatformOneSecond, ARDisplayString(m, rr));
98 rr->expire = 0;
100 rr->ThisAPInterval = rr->ThisAPInterval * QuestionIntervalStep; // Same Retry logic as Unicast Queries
101 if (rr->ThisAPInterval < INIT_RECORD_REG_INTERVAL)
102 rr->ThisAPInterval = INIT_RECORD_REG_INTERVAL;
103 if (rr->ThisAPInterval > MAX_RECORD_REG_INTERVAL)
104 rr->ThisAPInterval = MAX_RECORD_REG_INTERVAL;
106 LogInfo("SetRecordRetry retry in %d ms for %s", rr->ThisAPInterval, ARDisplayString(m, rr));
1000 AuthRecord rr;
1001 ResourceRecord *opt = &rr.resrec;
1011 // format opt rr (fields not specified are zero-valued)
1012 mDNS_SetupResourceRecord(&rr, mDNSNULL, mDNSInterface_Any, kDNSType_OPT, kStandardTTL, kDNSRecordTypeKnownUnique, AuthRecordAny, mDNSNULL, mDNSNULL);
1017 optRD = &rr.resrec.rdata->u.opt[0];
1268 tcpInfo->rr ? &tcpInfo->rr->tcp : mDNSNULL;
1270 LogMsg("tcpCallback: %d backpointer %p incorrect tcpInfo %p question %p rr %p",
1271 mDNSPlatformTCPGetFD(tcpInfo->sock), *backpointer, tcpInfo, q, tcpInfo->rr);
1282 if (tcpInfo->rr && tcpInfo->rr->resrec.name != &tcpInfo->rr->namestorage)
1283 LogMsg("tcpCallback: ERROR: tcpInfo->rr->resrec.name %p != &tcpInfo->rr->namestorage %p",
1284 tcpInfo->rr->resrec.name, &tcpInfo->rr->namestorage);
1285 if (tcpInfo->rr && tcpInfo->rr->resrec.name != &tcpInfo->rr->namestorage) return;
1287 AuthInfo = tcpInfo->rr ? GetAuthInfoForName(m, tcpInfo->rr->resrec.name) : mDNSNULL;
1440 // Note: Sleep code depends on us clearing *backpointer here -- it uses the clearing of rr->tcp
1541 DNSQuestion *const question, AuthRecord *const rr)
1561 info->rr = rr;
1710 mDNSexport const domainname *GetServiceTarget(mDNS *m, AuthRecord *const rr)
1712 debugf("GetServiceTarget %##s", rr->resrec.name->c);
1714 if (!rr->AutoTarget) // If not automatically tracking this host's current name, just return the existing target
1715 return(&rr->resrec.rdata->u.srv.target);
1719 DomainAuthInfo *AuthInfo = GetAuthInfoForName_internal(m, rr->resrec.name);
1730 const int srvcount = CountLabels(rr->resrec.name);
1739 if (SameDomainName(SkipLeadingLabels(rr->resrec.name, srvcount - x), SkipLeadingLabels(&hi->fqdn, hostcount - x)))
1747 LogInfo("GetServiceTarget: Returning NULL for %s", ARDisplayString(m, rr));
2001 mDNSlocal void SendRecordRegistration(mDNS *const m, AuthRecord *rr);
2002 mDNSlocal void SendRecordDeregistration(mDNS *m, AuthRecord *rr);
2003 mDNSlocal mDNSBool IsRecordMergeable(mDNS *const m, AuthRecord *rr, mDNSs32 time);
2007 mDNSlocal void UpdateAllServiceRecords(mDNS *const m, AuthRecord *rr, mDNSBool reg)
2011 if (rr->resrec.rrtype != kDNSType_SRV) { LogMsg("UpdateAllServiceRecords:ERROR!! ResourceRecord not a service record %s", ARDisplayString(m, rr)); return; }
2013 if (reg && rr->state == regState_NoTarget) { LogMsg("UpdateAllServiceRecords:ERROR!! SRV record %s in noTarget state during registration", ARDisplayString(m, rr)); return; }
2015 LogInfo("UpdateAllServiceRecords: ResourceRecord %s", ARDisplayString(m, rr));
2027 if (srvRR == rr)
2066 AuthRecord *rr = (AuthRecord *)n->clientContext;
2069 if (!rr) { LogMsg("CompleteRecordNatMap called with unknown AuthRecord object"); return; }
2070 if (!n->NATLease) { LogMsg("CompleteRecordNatMap No NATLease for %s", ARDisplayString(m, rr)); return; }
2072 if (rr->resrec.rrtype != kDNSType_SRV) {LogMsg("CompleteRecordNatMap: Not a service record %s", ARDisplayString(m, rr)); return; }
2074 if (rr->resrec.RecordType == kDNSRecordTypeDeregistering) { LogInfo("CompleteRecordNatMap called for %s, Service deregistering", ARDisplayString(m, rr)); return; }
2076 if (rr->state == regState_DeregPending) { LogInfo("CompleteRecordNatMap called for %s, record in DeregPending", ARDisplayString(m, rr)); return; }
2081 if (!rr->nta || mDNSIPv4AddressIsZero(rr->nta->Addr.ip.v4))
2083 LogInfo("CompleteRecordNatMap called for %s but no zone information!", ARDisplayString(m, rr));
2086 if (rr->NATinfo.clientContext)
2088 mDNS_StopNATOperation_internal(m, &rr->NATinfo);
2089 rr->NATinfo.clientContext = mDNSNULL;
2091 rr->state = regState_Pending;
2092 rr->ThisAPInterval = INIT_RECORD_REG_INTERVAL;
2093 rr->LastAPTime = m->timenow - INIT_RECORD_REG_INTERVAL;
2100 target = GetServiceTarget(m, rr);
2101 srvt = GetRRDomainNameTarget(&rr->resrec);
2105 LogInfo("CompleteRecordNatMap - Target %##s for ResourceRecord %##s, ExternalPort %d", target->c, rr->resrec.name->c, mDNSVal16(n->ExternalPort));
2107 LogInfo("CompleteRecordNatMap - no target for %##s, ExternalPort %d", rr->resrec.name->c, mDNSVal16(n->ExternalPort));
2109 rr->state = regState_NoTarget;
2110 rr->resrec.rdlength = rr->resrec.rdestimate = 0;
2112 UpdateAllServiceRecords(m, rr, mDNSfalse);
2115 LogInfo("CompleteRecordNatMap - Target %##s for ResourceRecord %##s, ExternalPort %d", target->c, rr->resrec.name->c, mDNSVal16(n->ExternalPort));
2123 SetNewRData(&rr->resrec, mDNSNULL, 0); // Update rdlength, rdestimate, rdatahash
2136 rr->SRVChanged = mDNSfalse;
2142 rr->state = regState_Pending;
2143 rr->ThisAPInterval = INIT_RECORD_REG_INTERVAL;
2144 rr->LastAPTime = m->timenow - INIT_RECORD_REG_INTERVAL;
2145 if (IsRecordMergeable(m, rr, m->timenow + MERGE_DELAY_TIME))
2148 rr->LastAPTime += MERGE_DELAY_TIME;
2155 UpdateAllServiceRecords(m, rr, mDNStrue);
2158 mDNSlocal void StartRecordNatMap(mDNS *m, AuthRecord *rr)
2163 if (rr->resrec.rrtype != kDNSType_SRV)
2165 LogInfo("StartRecordNatMap: Resource Record %##s type %d, not supported", rr->resrec.name->c, rr->resrec.rrtype);
2168 p = rr->resrec.name->c;
2175 else { LogMsg("StartRecordNatMap: could not determine transport protocol of service %##s", rr->resrec.name->c); return; }
2178 // rr->NATinfo.clientContext, mDNSVal16(rr->NATinfo.IntPort), mDNSVal16(rr->resrec.rdata->u.srv.port), ARDisplayString(m, rr));
2179 if (rr->NATinfo.clientContext) mDNS_StopNATOperation_internal(m, &rr->NATinfo);
2180 rr->NATinfo.Protocol = protocol;
2184 rr->NATinfo.IntPort = rr->resrec.rdata->u.srv.port;
2185 rr->NATinfo.RequestedPort = rr->resrec.rdata->u.srv.port;
2186 rr->NATinfo.NATLease = 0; // Request default lease
2187 rr->NATinfo.clientCallback = CompleteRecordNatMap;
2188 rr->NATinfo.clientContext = rr;
2189 mDNS_StartNATOperation_internal(m, &rr->NATinfo);
2211 mDNSlocal mStatus UnlinkResourceRecord(mDNS *const m, AuthRecord *const rr)
2214 while (*list && *list != rr) list = &(*list)->next;
2217 *list = rr->next;
2218 rr->next = mDNSNULL;
2221 if (rr->NATinfo.clientContext)
2223 mDNS_StopNATOperation_internal(m, &rr->NATinfo);
2224 rr->NATinfo.clientContext = mDNSNULL;
2225 if (rr->resrec.rrtype == kDNSType_SRV) rr->resrec.rdata->u.srv.port = rr->NATinfo.IntPort;
2230 LogMsg("UnlinkResourceRecord:ERROR!! - no such active record %##s", rr->resrec.name->c);
2237 mDNSlocal void RegisterAllServiceRecords(mDNS *const m, AuthRecord *rr)
2239 LogInfo("RegisterAllServiceRecords: Service Record %##s", rr->resrec.name->c);
2242 rr->SRVChanged = mDNSfalse;
2243 UnlinkResourceRecord(m, rr);
2244 mDNS_Register_internal(m, rr);
2246 UpdateAllServiceRecords(m, rr, mDNStrue);
2250 mDNSlocal void UpdateOneSRVRecord(mDNS *m, AuthRecord *rr)
2257 domainname *curtarget = &rr->resrec.rdata->u.srv.target;
2258 const domainname *const nt = GetServiceTarget(m, rr);
2260 mDNSBool TargetChanged = (newtarget->c[0] && rr->state == regState_NoTarget) || !SameDomainName(curtarget, newtarget);
2261 mDNSBool HaveZoneData = rr->nta && !mDNSIPv4AddressIsZero(rr->nta->Addr.ip.v4);
2268 mDNSIPPort port = rr->resrec.rdata->u.srv.port;
2269 mDNSBool NowNeedNATMAP = (rr->AutoTarget == Target_AutoHostAndNATMAP && !mDNSIPPortIsZero(port) && mDNSv4AddrIsRFC1918(&m->AdvertisedV4.ip.v4) && rr->nta && !mDNSAddrIsRFC1918(&rr->nta->Addr));
2270 mDNSBool WereBehindNAT = (rr->NATinfo.clientContext != mDNSNULL);
2271 mDNSBool PortWasMapped = (rr->NATinfo.clientContext && !mDNSSameIPPort(rr->NATinfo.RequestedPort, port)); // I think this is always false -- SC Sept 07
2276 LogInfo("UpdateOneSRVRecord: Resource Record %s TargetChanged %d, NewTarget %##s", ARDisplayString(m, rr), TargetChanged, nt->c);
2279 rr->resrec.name->c, newtarget,
2287 if (rr->resrec.RecordType == kDNSRecordTypeDeregistering)
2290 rr->resrec.name->c, rr->state);
2295 LogInfo("UpdateOneSRVRecord: TargetChanged %d, NATChanged %d for %##s, state %d, newtarget %##s", TargetChanged, NATChanged, rr->resrec.name->c, rr->state, newtarget->c);
2297 LogInfo("UpdateOneSRVRecord: TargetChanged %d, NATChanged %d for %##s, state %d, null newtarget", TargetChanged, NATChanged, rr->resrec.name->c, rr->state);
2298 switch(rr->state)
2318 LogInfo("UpdateOneSRVRecord: No target yet for Resource Record %s", ARDisplayString(m, rr));
2321 RegisterAllServiceRecords(m, rr);
2349 rr->SRVChanged = mDNStrue;
2350 rr->ThisAPInterval = INIT_RECORD_REG_INTERVAL;
2351 rr->LastAPTime = m->timenow - INIT_RECORD_REG_INTERVAL;
2355 rr->resrec.name->c, newtarget->c);
2356 rr->state = regState_Pending;
2360 LogInfo("UpdateOneSRVRecord: SRV record changed for service %##s de-registering", rr->resrec.name->c);
2361 rr->state = regState_DeregPending;
2362 UpdateAllServiceRecords(m, rr, mDNSfalse);
2366 default: LogMsg("UpdateOneSRVRecord: Unknown state %d for %##s", rr->state, rr->resrec.name->c);
2388 mDNSlocal void HostnameCallback(mDNS *const m, AuthRecord *const rr, mStatus result);
2458 mDNSlocal void HostnameCallback(mDNS *const m, AuthRecord *const rr, mStatus result)
2460 HostnameInfo *hi = (HostnameInfo *)rr->RecordContext;
2468 LogInfo("HostnameCallback: Got mStatus_MemFree for %p %p %s", hi, rr, ARDisplayString(m, rr));
2470 if (rr == &i->arv4 || rr == &i->arv6)
2488 if (rr->resrec.rrtype == kDNSType_A)
2489 LogMsg("HostnameCallback: Error %d for registration of %##s IP %.4a", result, rr->resrec.name->c, &rr->resrec.rdata->u.ipv4);
2491 LogMsg("HostnameCallback: Error %d for registration of %##s IP %.16a", result, rr->resrec.name->c, &rr->resrec.rdata->u.ipv6);
2492 if (!hi) { mDNSPlatformMemFree(rr); return; }
2493 if (rr->state != regState_Unregistered) LogMsg("Error: HostnameCallback invoked with error code for record not in regState_Unregistered!");
2499 rr->RecordContext = (void *)hi->StatusContext;
2501 hi->StatusCallback(m, rr, result); // client may NOT make API calls here
2502 rr->RecordContext = (void *)hi;
2514 if (rr->resrec.rrtype == kDNSType_A)
2515 LogInfo("Registered hostname %##s IP %.4a", rr->resrec.name->c, &rr->resrec.rdata->u.ipv4);
2517 LogInfo("Registered hostname %##s IP %.16a", rr->resrec.name->c, &rr->resrec.rdata->u.ipv6);
2519 rr->RecordContext = (void *)hi->StatusContext;
2521 hi->StatusCallback(m, rr, result); // client may NOT make API calls here
2522 rr->RecordContext = (void *)hi;
2898 mDNSlocal mDNSu8* BuildUpdateMessage(mDNS *const m, mDNSu8 *ptr, AuthRecord *rr, mDNSu8 *limit)
2901 if (rr->state == regState_DeregPending)
2903 rr->expire = 0; // Indicate that we have no active registration any more
2904 ptr = putDeletionRecordWithLimit(&m->omsg, ptr, &rr->resrec, limit);
2911 if (rr->state == regState_Registered) rr->state = regState_Refresh;
2912 if (rr->state != regState_Refresh && rr->state != regState_UpdatePending)
2913 rr->state = regState_Pending;
2917 if (rr->resrec.RecordType != kDNSRecordTypeAdvisory) rr->RequireGoodbye = mDNStrue;
2919 if ((rr->resrec.rrtype == kDNSType_SRV) && (rr->AutoTarget == Target_AutoHostAndNATMAP) &&
2920 !mDNSIPPortIsZero(rr->NATinfo.ExternalPort))
2922 rr->resrec.rdata->u.srv.port = rr->NATinfo.ExternalPort;
2925 if (rr->state == regState_UpdatePending)
2928 SetNewRData(&rr->resrec, rr->OrigRData, rr->OrigRDLen);
2929 if (!(ptr = putDeletionRecordWithLimit(&m->omsg, ptr, &rr->resrec, limit))) goto exit; // delete old rdata
2932 SetNewRData(&rr->resrec, rr->InFlightRData, rr->InFlightRDLen);
2933 if (!(ptr = PutResourceRecordTTLWithLimit(&m->omsg, ptr, &m->omsg.h.mDNS_numUpdates, &rr->resrec, rr->resrec.rroriginalttl, limit))) goto exit;
2937 if (rr->resrec.RecordType == kDNSRecordTypeKnownUnique || rr->resrec.RecordType == kDNSRecordTypeVerified)
2942 ptr = putDeleteRRSetWithLimit(&m->omsg, ptr, rr->resrec.name, rr->resrec.rrtype, limit);
2945 else if (rr->resrec.RecordType != kDNSRecordTypeShared)
2948 //ptr = putPrereqNameNotInUse(rr->resrec.name, &m->omsg, ptr, end);
2952 ptr = PutResourceRecordTTLWithLimit(&m->omsg, ptr, &m->omsg.h.mDNS_numUpdates, &rr->resrec, rr->resrec.rroriginalttl, limit);
2958 LogMsg("BuildUpdateMessage: Error formatting message for %s", ARDisplayString(m, rr));
2963 mDNSlocal void SendRecordRegistration(mDNS *const m, AuthRecord *rr)
2974 AuthInfo = GetAuthInfoForName_internal(m, rr->resrec.name);
2979 if (!rr->nta || mDNSIPv4AddressIsZero(rr->nta->Addr.ip.v4))
2982 LogMsg("SendRecordRegistration: No Zone information, should not happen %s", ARDisplayString(m, rr));
2986 rr->updateid = mDNS_NewMessageID(m);
2987 InitializeDNSMessage(&m->omsg.h, rr->updateid, UpdateReqFlags);
2990 ptr = putZone(&m->omsg, ptr, limit, rr->zone, mDNSOpaque16fromIntVal(rr->resrec.rrclass));
2993 if (!(ptr = BuildUpdateMessage(m, ptr, rr, limit))) goto exit;
2995 if (rr->uselease)
3000 if (rr->Private)
3002 LogInfo("SendRecordRegistration TCP %p %s", rr->tcp, ARDisplayString(m, rr));
3003 if (rr->tcp) LogInfo("SendRecordRegistration: Disposing existing TCP connection for %s", ARDisplayString(m, rr));
3004 if (rr->tcp) { DisposeTCPConn(rr->tcp); rr->tcp = mDNSNULL; }
3005 if (!rr->nta) { LogMsg("SendRecordRegistration:Private:ERROR!! nta is NULL for %s", ARDisplayString(m, rr)); return; }
3006 rr->tcp = MakeTCPConn(m, &m->omsg, ptr, kTCPSocketFlags_UseTLS, &rr->nta->Addr, rr->nta->Port, &rr->nta->Host, mDNSNULL, rr);
3010 LogInfo("SendRecordRegistration UDP %s", ARDisplayString(m, rr));
3011 if (!rr->nta) { LogMsg("SendRecordRegistration:ERROR!! nta is NULL for %s", ARDisplayString(m, rr)); return; }
3012 err = mDNSSendDNSMessage(m, &m->omsg, ptr, mDNSInterface_Any, mDNSNULL, &rr->nta->Addr, rr->nta->Port, mDNSNULL, GetAuthInfoForName_internal(m, rr->resrec.name), mDNSfalse);
3016 SetRecordRetry(m, rr, 0);
3019 LogMsg("SendRecordRegistration: Error formatting message for %s, disabling further updates", ARDisplayString(m, rr));
3021 rr->state = regState_NoTarget;
3024 // Is the given record "rr" eligible for merging ?
3025 mDNSlocal mDNSBool IsRecordMergeable(mDNS *const m, AuthRecord *rr, mDNSs32 time)
3045 if (!AuthRecord_uDNS(rr)) return mDNSfalse;
3047 if (rr->LastAPTime + rr->ThisAPInterval - time > 0)
3048 { debugf("IsRecordMergeable: Time %d not reached for %s", rr->LastAPTime + rr->ThisAPInterval - m->timenow, ARDisplayString(m, rr)); return mDNSfalse; }
3050 if (!rr->zone) return mDNSfalse;
3052 info = GetAuthInfoForName_internal(m, rr->zone);
3056 if (rr->state != regState_DeregPending && rr->state != regState_Pending && rr->state != regState_Registered && rr->state != regState_Refresh && rr->state != regState_UpdatePending)
3057 { debugf("IsRecordMergeable: state %d not right %s", rr->state, ARDisplayString(m, rr)); return mDNSfalse; }
3059 if (!rr->nta || mDNSIPv4AddressIsZero(rr->nta->Addr.ip.v4)) return mDNSfalse;
3061 if (!rr->uselease) return mDNSfalse;
3063 if (rr->mState == mergeState_DontMerge) {debugf("IsRecordMergeable Dontmerge true %s", ARDisplayString(m, rr)); return mDNSfalse;}
3064 debugf("IsRecordMergeable: Returning true for %s", ARDisplayString(m, rr));
3068 // Is the resource record "rr" eligible to merge to with "currentRR" ?
3069 mDNSlocal mDNSBool AreRecordsMergeable(mDNS *const m, AuthRecord *currentRR, AuthRecord *rr, mDNSs32 time)
3073 if (!IsRecordMergeable(m, rr, time)) return mDNSfalse;
3075 if (!SameDomainName(currentRR->zone, rr->zone))
3076 { debugf("AreRecordMergeable zone mismatch current rr Zone %##s, rr zone %##s", currentRR->zone->c, rr->zone->c); return mDNSfalse; }
3078 if (!mDNSSameIPv4Address(currentRR->nta->Addr.ip.v4, rr->nta->Addr.ip.v4)) return mDNSfalse;
3080 if (!mDNSSameIPPort(currentRR->nta->Port, rr->nta->Port)) return mDNSfalse;
3082 debugf("AreRecordsMergeable: Returning true for %s", ARDisplayString(m, rr));
3090 AuthRecord *rr;
3091 for (rr = m->ResourceRecords; rr; rr = rr->next)
3093 rr->mState = mergeState_DontMerge;
3094 rr->SendRNow = mDNSNULL;
3097 ActivateUnicastRegistration(m, rr);
3139 mDNSlocal mDNSu32 RREstimatedSize(AuthRecord *rr, int zoneSize)
3146 if (rr->state == regState_UpdatePending)
3149 rdlength = rr->OrigRDLen + rr->InFlightRDLen;
3151 rdlength = rr->resrec.rdestimate;
3153 if (rr->state == regState_DeregPending)
3156 rr->resrec.name->c, DNSTypeName(rr->resrec.rrtype), DomainNameLength(rr->resrec.name), zoneSize, rdlength);
3157 return DomainNameLength(rr->resrec.name) - zoneSize + 2 + 10 + rdlength;
3161 if (rr->resrec.RecordType == kDNSRecordTypeKnownUnique || rr->resrec.RecordType == kDNSRecordTypeVerified)
3167 rr->resrec.name->c, DNSTypeName(rr->resrec.rrtype), DomainNameLength(rr->resrec.name), zoneSize, rdlength);
3168 return DomainNameLength(rr->resrec.name) - zoneSize + 2 + 10 + 2 + 10 + rdlength;
3172 return DomainNameLength(rr->resrec.name) - zoneSize + 2 + 10 + rdlength;
3178 AuthRecord *rr;
3195 for (rr = m->ResourceRecords; rr; rr = rr->next)
3199 if (!IsRecordMergeable(m, rr, m->timenow + MERGE_DELAY_TIME)) continue;
3200 firstRR = rr;
3202 else if (!AreRecordsMergeable(m, firstRR, rr, m->timenow + MERGE_DELAY_TIME)) continue;
3204 if (rr->SendRNow) LogMsg("MarkRRForSending: Resourcerecord %s already marked for sending", ARDisplayString(m, rr));
3205 rr->SendRNow = uDNSInterfaceMark;
3222 for (rr = m->ResourceRecords; rr; rr = rr->next)
3224 if ((rr->state != regState_Registered && rr->state != regState_Refresh) ||
3225 (rr->SendRNow == uDNSInterfaceMark) ||
3226 (!AreRecordsMergeable(m, firstRR, rr, m->timenow + rr->ThisAPInterval/2)))
3228 rr->SendRNow = uDNSInterfaceMark;
3243 AuthRecord *rr;
3272 for (rr = startRR; rr; rr = rr->next)
3274 if (rr->SendRNow != uDNSInterfaceMark) continue;
3276 rr->SendRNow = mDNSNULL;
3280 AuthInfo = GetAuthInfoForName_internal(m, rr->zone);
3305 zoneSize = DomainNameLength(rr->zone) + 4;
3313 next = putZone(&m->omsg, next, limit, rr->zone, mDNSOpaque16fromIntVal(rr->resrec.rrclass));
3320 anchorRR = rr;
3323 rrSize = RREstimatedSize(rr, zoneSize - 4);
3331 LogInfo("SendGroupUpdates: Skipping message %s, spaceleft %d, rrSize %d", ARDisplayString(m, rr), spaceleft, rrSize);
3333 rr->SendRNow = uDNSInterfaceMark;
3335 rr->ThisAPInterval = INIT_RECORD_REG_INTERVAL;
3336 rr->LastAPTime = m->timenow - INIT_RECORD_REG_INTERVAL;
3337 rr = rr->next;
3350 LogInfo("SendGroupUpdates: Building a message with resource record %s, next %p, state %d, ttl %d", ARDisplayString(m, rr), next, rr->state, rr->resrec.rroriginalttl);
3351 if (!(next = BuildUpdateMessage(m, next, rr, limit)))
3355 LogMsg("SendGroupUpdates: ptr NULL while building message with %s", ARDisplayString(m, rr));
3361 LogMsg("SendGroupUpdates: ERROR!! Record size estimation is wrong for %s, Estimate %d, Actual %d, state %d", ARDisplayString(m, rr), rrSize, next - oldnext, rr->state);
3365 // We could have sent an update earlier with this "rr" as anchorRR for which we never got a response.
3367 if (rr->tcp) { DisposeTCPConn(rr->tcp); rr->tcp = mDNSNULL;}
3368 rr->updateid = msgid;
3372 SetRecordRetry(m, rr, 0);
3374 // Either we have parsed all the records or stopped at "rr" above due to lack of space
3375 startRR = rr;
3390 AuthRecord *rr, *nextRR;
3397 for (rr = m->ResourceRecords; rr; rr = nextRR)
3399 // SendRecordRegistrtion might delete the rr from list, hence
3401 nextRR = rr->next;
3402 if (rr->SendRNow == uDNSInterfaceMark)
3406 if (rr->LastAPTime + rr->ThisAPInterval - m->timenow > 0)
3407 { LogMsg("CheckGroupRecordUpdates: ERROR!! Resourcerecord %s not ready", ARDisplayString(m, rr)); continue; }
3408 rr->SendRNow = mDNSNULL;
3409 SendRecordRegistration(m, rr);
3419 mDNSlocal void hndlSRVChanged(mDNS *const m, AuthRecord *rr)
3424 const domainname *target = GetServiceTarget(m, rr);
3428 if (rr->state == regState_DeregPending)
3430 LogInfo("hndlSRVChanged: SRVChanged, No Target, SRV Deregistered for %##s, state %d", rr->resrec.name->c,
3431 rr->state);
3432 rr->SRVChanged = mDNSfalse;
3433 dt = GetRRDomainNameTarget(&rr->resrec);
3435 rr->state = regState_NoTarget; // Wait for the next target change
3436 rr->resrec.rdlength = rr->resrec.rdestimate = 0;
3441 if (rr->state == regState_Pending)
3443 LogInfo("hndlSRVChanged: SRVChanged, No Target, Deregistering again %##s, state %d", rr->resrec.name->c, rr->state);
3444 rr->ThisAPInterval = INIT_RECORD_REG_INTERVAL;
3445 rr->LastAPTime = m->timenow - INIT_RECORD_REG_INTERVAL;
3446 rr->state = regState_DeregPending;
3449 LogInfo("hndlSRVChanged: Not in DeregPending or RegPending state %##s, state %d", rr->resrec.name->c, rr->state);
3460 if ((rr->state == regState_DeregPending) ||
3461 (rr->state == regState_Pending && !SameDomainName(target, &rr->resrec.rdata->u.srv.target)))
3463 dt = GetRRDomainNameTarget(&rr->resrec);
3465 rr->state = regState_NoTarget; // NoTarget will allow us to pick up new target OR nat traversal state
3466 rr->resrec.rdlength = rr->resrec.rdestimate = 0;
3468 target->c, rr->resrec.name->c, rr->state);
3469 rr->SRVChanged = mDNSfalse;
3470 UpdateOneSRVRecord(m, rr);
3475 if (rr->state == regState_Pending) rr->state = regState_Registered;
3478 rr->SRVChanged = mDNSfalse;
3482 mDNSlocal void hndlRecordUpdateReply(mDNS *m, AuthRecord *rr, mStatus err, mDNSu32 random)
3489 LogInfo("hndlRecordUpdateReply: err %d ID %d state %d %s(%p)", err, mDNSVal16(rr->updateid), rr->state, ARDisplayString(m, rr), rr);
3491 rr->updateError = err;
3496 SetRecordRetry(m, rr, random);
3498 rr->updateid = zeroID; // Make sure that this is not considered as part of a group anymore
3509 if (rr->nta)
3514 if (rr->nta->question.ThisQInterval != -1)
3516 ARDisplayString(m, rr), rr->nta->question.qname.c, DNSTypeName(rr->nta->question.qtype), rr->nta->question.ThisQInterval);
3517 UpdatePort = rr->nta->Port;
3518 CancelGetZoneData(m, rr->nta);
3519 rr->nta = mDNSNULL;
3524 if (rr->resrec.RecordType == kDNSRecordTypeDeregistering && rr->state == regState_DeregPending)
3526 debugf("hndlRecordUpdateReply: Received reply for deregister record %##s type %d", rr->resrec.name->c, rr->resrec.rrtype);
3528 rr->resrec.name->c, rr->resrec.rrtype, err);
3529 rr->state = regState_Unregistered;
3530 CompleteDeregistration(m, rr);
3542 if (rr->resrec.rrtype == kDNSType_SRV && rr->state == regState_DeregPending)
3543 rr->state = regState_NoTarget;
3547 if (rr->state == regState_UpdatePending)
3549 if (err) LogMsg("Update record failed for %##s (err %d)", rr->resrec.name->c, err);
3550 rr->state = regState_Registered;
3552 if (rr->UpdateCallback) rr->UpdateCallback(m, rr, rr->OrigRData, rr->OrigRDLen);
3553 SetNewRData(&rr->resrec, rr->InFlightRData, rr->InFlightRDLen);
3554 rr->OrigRData = mDNSNULL;
3555 rr->InFlightRData = mDNSNULL;
3558 if (rr->SRVChanged)
3560 if (rr->resrec.rrtype == kDNSType_SRV)
3561 hndlSRVChanged(m, rr);
3564 LogInfo("hndlRecordUpdateReply: Deregistered %##s (%s), state %d", rr->resrec.name->c, DNSTypeName(rr->resrec.rrtype), rr->state);
3565 rr->SRVChanged = mDNSfalse;
3566 if (rr->state != regState_DeregPending) LogMsg("hndlRecordUpdateReply: ResourceRecord %s not in DeregPending state %d", ARDisplayString(m, rr), rr->state);
3567 rr->state = regState_NoTarget; // Wait for the next target change
3572 if (rr->state == regState_Pending || rr->state == regState_Refresh)
3576 if (rr->state == regState_Refresh) InvokeCallback = mDNSfalse;
3577 rr->state = regState_Registered;
3582 LogMsg("hndlRecordUpdateReply: Registration of record %##s type %d failed with error %d", rr->resrec.name->c, rr->resrec.rrtype, err);
3583 if (!rr->Private && rr->uselease && err == mStatus_UnknownErr && mDNSSameIPPort(UpdatePort, UnicastDNSPort))
3585 LogMsg("hndlRecordUpdateReply: Will retry update of record %##s without lease option", rr->resrec.name->c);
3586 rr->uselease = mDNSfalse;
3587 rr->ThisAPInterval = INIT_RECORD_REG_INTERVAL;
3588 rr->LastAPTime = m->timenow - INIT_RECORD_REG_INTERVAL;
3589 SetNextuDNSEvent(m, rr);
3596 if (rr->QueuedRData && rr->state == regState_Registered)
3598 rr->state = regState_UpdatePending;
3599 rr->InFlightRData = rr->QueuedRData;
3600 rr->InFlightRDLen = rr->QueuedRDLen;
3601 rr->OrigRData = rr->resrec.rdata;
3602 rr->OrigRDLen = rr->resrec.rdlength;
3603 rr->QueuedRData = mDNSNULL;
3604 rr->ThisAPInterval = INIT_RECORD_REG_INTERVAL;
3605 rr->LastAPTime = m->timenow - INIT_RECORD_REG_INTERVAL;
3606 SetNextuDNSEvent(m, rr);
3613 if (!err && InvokeCallback && rr->RecordCallback)
3615 LogInfo("hndlRecordUpdateReply: Calling record callback on %##s", rr->resrec.name->c);
3617 rr->RecordCallback(m, rr, err);
3620 // CAUTION: MUST NOT do anything more with rr after calling rr->Callback(), because the client's callback function
4435 mDNSlocal void SendRecordDeregistration(mDNS *m, AuthRecord *rr)
4443 if (!rr->nta || mDNSIPv4AddressIsZero(rr->nta->Addr.ip.v4))
4445 LogMsg("SendRecordDeRegistration: No zone info for Resource record %s RecordType %d", ARDisplayString(m, rr), rr->resrec.RecordType);
4450 AuthInfo = GetAuthInfoForName_internal(m, rr->resrec.name);
4453 rr->updateid = mDNS_NewMessageID(m);
4454 InitializeDNSMessage(&m->omsg.h, rr->updateid, UpdateReqFlags);
4457 ptr = putZone(&m->omsg, ptr, limit, rr->zone, mDNSOpaque16fromIntVal(rr->resrec.rrclass));
4460 ptr = BuildUpdateMessage(m, ptr, rr, limit);
4464 if (rr->Private)
4466 LogInfo("SendRecordDeregistration TCP %p %s", rr->tcp, ARDisplayString(m, rr));
4467 if (rr->tcp) LogInfo("SendRecordDeregistration: Disposing existing TCP connection for %s", ARDisplayString(m, rr));
4468 if (rr->tcp) { DisposeTCPConn(rr->tcp); rr->tcp = mDNSNULL; }
4469 if (!rr->nta) { LogMsg("SendRecordDeregistration:Private:ERROR!! nta is NULL for %s", ARDisplayString(m, rr)); return; }
4470 rr->tcp = MakeTCPConn(m, &m->omsg, ptr, kTCPSocketFlags_UseTLS, &rr->nta->Addr, rr->nta->Port, &rr->nta->Host, mDNSNULL, rr);
4475 LogInfo("SendRecordDeregistration UDP %s", ARDisplayString(m, rr));
4476 if (!rr->nta) { LogMsg("SendRecordDeregistration:ERROR!! nta is NULL for %s", ARDisplayString(m, rr)); return; }
4477 err = mDNSSendDNSMessage(m, &m->omsg, ptr, mDNSInterface_Any, mDNSNULL, &rr->nta->Addr, rr->nta->Port, mDNSNULL, GetAuthInfoForName_internal(m, rr->resrec.name), mDNSfalse);
4479 //if (rr->state == regState_DeregPending) CompleteDeregistration(m, rr); // Don't touch rr after this
4481 SetRecordRetry(m, rr, 0);
4484 LogMsg("SendRecordDeregistration: Error formatting message for %s", ARDisplayString(m, rr));
4487 mDNSexport mStatus uDNS_DeregisterRecord(mDNS *const m, AuthRecord *const rr)
4491 LogInfo("uDNS_DeregisterRecord: Resource Record %s, state %d", ARDisplayString(m, rr), rr->state);
4493 switch (rr->state)
4511 LogInfo("uDNS_DeregisterRecord: State %d for %##s type %s", rr->state, rr->resrec.name->c, DNSTypeName(rr->resrec.rrtype));
4513 if (rr->resrec.RecordType == kDNSRecordTypeDeregistering) CompleteDeregistration(m, rr);
4531 if (rr->InFlightRData && rr->UpdateCallback)
4533 if (rr->InFlightRData != rr->resrec.rdata)
4535 LogInfo("uDNS_DeregisterRecord: Freeing InFlightRData for %s", ARDisplayString(m, rr));
4536 rr->UpdateCallback(m, rr, rr->InFlightRData, rr->InFlightRDLen);
4537 rr->InFlightRData = mDNSNULL;
4540 LogInfo("uDNS_DeregisterRecord: InFlightRData same as rdata for %s", ARDisplayString(m, rr));
4543 if (rr->QueuedRData && rr->UpdateCallback)
4545 if (rr->QueuedRData == rr->resrec.rdata)
4546 LogMsg("uDNS_DeregisterRecord: ERROR!! QueuedRData same as rdata for %s", ARDisplayString(m, rr));
4549 LogInfo("uDNS_DeregisterRecord: Freeing QueuedRData for %s", ARDisplayString(m, rr));
4550 rr->UpdateCallback(m, rr, rr->QueuedRData, rr->QueuedRDLen);
4551 rr->QueuedRData = mDNSNULL;
4568 if (!mDNSOpaque16IsZero(rr->updateid))
4574 if (AuthRecord_uDNS(rr) && mDNSSameOpaque16(anchorRR->updateid, rr->updateid) && anchorRR->tcp)
4584 if (!found) LogInfo("uDNSDeregisterRecord: Cannot find the anchor Resource Record for %s, not an error", ARDisplayString(m, rr));
4589 rr->state = regState_DeregPending;
4590 rr->ThisAPInterval = INIT_RECORD_REG_INTERVAL;
4591 rr->LastAPTime = m->timenow - INIT_RECORD_REG_INTERVAL;
4592 info = GetAuthInfoForName_internal(m, rr->resrec.name);
4593 if (IsRecordMergeable(m, rr, m->timenow + MERGE_DELAY_TIME))
4599 if (info && info->deltime) rr->LastAPTime += (2 * MERGE_DELAY_TIME);
4600 else rr->LastAPTime += MERGE_DELAY_TIME;
4606 if (m->NextuDNSEvent - (rr->LastAPTime + rr->ThisAPInterval) >= 0)
4607 m->NextuDNSEvent = (rr->LastAPTime + rr->ThisAPInterval);
4612 mDNSexport mStatus uDNS_UpdateRecord(mDNS *m, AuthRecord *rr)
4614 LogInfo("uDNS_UpdateRecord: Resource Record %##s, state %d", rr->resrec.name->c, rr->state);
4615 switch(rr->state)
4625 if (rr->UpdateCallback) rr->UpdateCallback(m, rr, rr->resrec.rdata, rr->resrec.rdlength);
4626 SetNewRData(&rr->resrec, rr->NewRData, rr->newrdlength);
4627 rr->NewRData = mDNSNULL;
4634 if (rr->QueuedRData && rr->UpdateCallback)
4636 rr->UpdateCallback(m, rr, rr->QueuedRData, rr->QueuedRDLen);
4637 rr->QueuedRData = rr->NewRData;
4638 rr->QueuedRDLen = rr->newrdlength;
4639 rr->NewRData = mDNSNULL;
4643 rr->OrigRData = rr->resrec.rdata;
4644 rr->OrigRDLen = rr->resrec.rdlength;
4645 rr->InFlightRData = rr->NewRData;
4646 rr->InFlightRDLen = rr->newrdlength;
4647 rr->NewRData = mDNSNULL;
4648 rr->state = regState_UpdatePending;
4649 rr->ThisAPInterval = INIT_RECORD_REG_INTERVAL;
4650 rr->LastAPTime = m->timenow - INIT_RECORD_REG_INTERVAL;
4651 SetNextuDNSEvent(m, rr);
4655 LogMsg("ERROR: uDNS_UpdateRecord called for record %##s with bad state regState_NATError", rr->resrec.name->c);
4658 default: LogMsg("uDNS_UpdateRecord: Unknown state %d for %##s", rr->state, rr->resrec.name->c);
4663 rr->resrec.name->c, rr->resrec.rrtype, rr->state);
4891 CacheRecord *rr;
4940 for (rr = cg->members; rr; rr=rr->next)
4942 if (SameNameRecordAnswersQuestion(&rr->resrec, q))
4944 LogInfo("uDNS_CheckCurrentQuestion: Purged resourcerecord %s", CRDisplayString(m, rr));
4945 mDNS_PurgeCacheResourceRecord(m, rr);
4957 // To solve this problem we set rr->DelayDelivery to a nonzero value (which happens to be 'now') so that we
5108 AuthRecord *rr;
5113 for (rr = m->ResourceRecords; rr; rr = rr->next)
5115 if (!AuthRecord_uDNS(rr)) continue;
5116 if (rr->state == regState_NoTarget) {debugf("CheckRecordUpdates: Record %##s in NoTarget", rr->resrec.name->c); continue;}
5119 if (rr->state == regState_NATMap) {debugf("CheckRecordUpdates: Record %##s in NATMap", rr->resrec.name->c); continue;}
5120 if (rr->state == regState_Pending || rr->state == regState_DeregPending || rr->state == regState_UpdatePending ||
5121 rr->state == regState_Refresh || rr->state == regState_Registered)
5123 if (rr->LastAPTime + rr->ThisAPInterval - m->timenow <= 0)
5125 if (rr->tcp) { DisposeTCPConn(rr->tcp); rr->tcp = mDNSNULL; }
5126 if (!rr->nta || mDNSIPv4AddressIsZero(rr->nta->Addr.ip.v4))
5130 if (rr->nta) { rr->updateid = zeroID; CancelGetZoneData(m, rr->nta); }
5131 rr->nta = StartGetZoneData(m, rr->resrec.name, ZoneServiceUpdate, RecordRegistrationGotZoneData, rr);
5150 SetRecordRetry(m, rr, 0);
5152 else if (rr->state == regState_DeregPending) SendRecordDeregistration(m, rr);
5153 else SendRecordRegistration(m, rr);
5156 if (nextevent - (rr->LastAPTime + rr->ThisAPInterval) > 0)
5157 nextevent = (rr->LastAPTime + rr->ThisAPInterval);
5215 AuthRecord *rr;
5216 for (rr = m->ResourceRecords; rr; rr=rr->next)
5218 if (AuthRecord_uDNS(rr))
5222 if (rr->nta) { rr->updateid = zeroID; CancelGetZoneData(m, rr->nta); rr->nta = mDNSNULL; }
5224 if (rr->NATinfo.clientContext)
5226 mDNS_StopNATOperation_internal(m, &rr->NATinfo);
5227 rr->NATinfo.clientContext = mDNSNULL;
5232 if (rr->state == regState_UpdatePending)
5235 rr->state = regState_Registered;
5237 if (rr->UpdateCallback) rr->UpdateCallback(m, rr, rr->OrigRData, rr->OrigRDLen);
5238 SetNewRData(&rr->resrec, rr->InFlightRData, rr->InFlightRDLen);
5239 rr->OrigRData = mDNSNULL;
5240 rr->InFlightRData = mDNSNULL;
5245 uDNS_DeregisterRecord(m, rr);
5289 mDNSlocal void FreeARElemCallback(mDNS *const m, AuthRecord *const rr, mStatus result)
5292 if (result == mStatus_MemFree) mDNSPlatformMemFree(rr->RecordContext);
5835 mDNSexport const domainname *GetServiceTarget(mDNS *m, AuthRecord *const rr)
5838 (void) rr;