-mDNSexport mStatus uDNS_SetupSearchDomains(mDNS *const m, int action)
- {
- SearchListElem **p = &SearchList, *ptr;
- mStatus err;
-
- // step 1: mark each element for removal
- for (ptr = SearchList; ptr; ptr = ptr->next) ptr->flag |= SLE_DELETE;
-
- // Make sure we have the search domains from the platform layer so that if we start the WAB
- // queries below, we have the latest information
- mDNS_Lock(m);
- mDNSPlatformSetDNSConfig(m, mDNSfalse, mDNStrue, mDNSNULL, mDNSNULL, mDNSNULL);
- mDNS_Unlock(m);
-
- if (action & UDNS_START_WAB_QUERY)
- m->StartWABQueries = mDNStrue;
-
- // delete elems marked for removal, do queries for elems marked add
- while (*p)
- {
- ptr = *p;
- LogInfo("uDNS_SetupSearchDomains:action %d: Flags %d, AuthRecs %p, InterfaceID %p %##s", action, ptr->flag, ptr->AuthRecs, ptr->InterfaceID, ptr->domain.c);
- if (ptr->flag & SLE_DELETE)
- {
- ARListElem *arList = ptr->AuthRecs;
- ptr->AuthRecs = mDNSNULL;
- *p = ptr->next;
-
- // If the user has "local" in their DNS searchlist, we ignore that for the purposes of domain enumeration queries
- // We suppressed the domain enumeration for scoped search domains below. When we enable that
- // enable this.
- if ((ptr->flag & SLE_WAB_QUERY_STARTED) &&
- !SameDomainName(&ptr->domain, &localdomain) && (ptr->InterfaceID == mDNSInterface_Any))
- {
- mDNS_StopGetDomains(m, &ptr->BrowseQ);
- mDNS_StopGetDomains(m, &ptr->RegisterQ);
- mDNS_StopGetDomains(m, &ptr->DefBrowseQ);
- mDNS_StopGetDomains(m, &ptr->DefRegisterQ);
- mDNS_StopGetDomains(m, &ptr->AutomaticBrowseQ);
- }
-
- mDNSPlatformMemFree(ptr);
-
- // deregister records generated from answers to the query
- while (arList)
- {
- ARListElem *dereg = arList;
- arList = arList->next;
- debugf("Deregistering PTR %##s -> %##s", dereg->ar.resrec.name->c, dereg->ar.resrec.rdata->u.name.c);
- err = mDNS_Deregister(m, &dereg->ar);
- if (err) LogMsg("uDNS_SetupSearchDomains:: ERROR!! mDNS_Deregister returned %d", err);
- // Memory will be freed in the FreeARElemCallback
- }
- continue;
- }
-
- if ((action & UDNS_START_WAB_QUERY) && !(ptr->flag & SLE_WAB_QUERY_STARTED))
- {
- // If the user has "local" in their DNS searchlist, we ignore that for the purposes of domain enumeration queries.
- // Also, suppress the domain enumeration for scoped search domains for now until there is a need.
- if (!SameDomainName(&ptr->domain, &localdomain) && (ptr->InterfaceID == mDNSInterface_Any))
- {
- mStatus err1, err2, err3, err4, err5;
- err1 = mDNS_GetDomains(m, &ptr->BrowseQ, mDNS_DomainTypeBrowse, &ptr->domain, ptr->InterfaceID, FoundDomain, ptr);
- err2 = mDNS_GetDomains(m, &ptr->DefBrowseQ, mDNS_DomainTypeBrowseDefault, &ptr->domain, ptr->InterfaceID, FoundDomain, ptr);
- err3 = mDNS_GetDomains(m, &ptr->RegisterQ, mDNS_DomainTypeRegistration, &ptr->domain, ptr->InterfaceID, FoundDomain, ptr);
- err4 = mDNS_GetDomains(m, &ptr->DefRegisterQ, mDNS_DomainTypeRegistrationDefault, &ptr->domain, ptr->InterfaceID, FoundDomain, ptr);
- err5 = mDNS_GetDomains(m, &ptr->AutomaticBrowseQ, mDNS_DomainTypeBrowseAutomatic, &ptr->domain, ptr->InterfaceID, FoundDomain, ptr);
- if (err1 || err2 || err3 || err4 || err5)
- LogMsg("uDNS_SetupSearchDomains: GetDomains for domain %##s returned error(s):\n"
- "%d (mDNS_DomainTypeBrowse)\n"
- "%d (mDNS_DomainTypeBrowseDefault)\n"
- "%d (mDNS_DomainTypeRegistration)\n"
- "%d (mDNS_DomainTypeRegistrationDefault)"
- "%d (mDNS_DomainTypeBrowseAutomatic)\n",
- ptr->domain.c, err1, err2, err3, err4, err5);
- ptr->flag |= SLE_WAB_QUERY_STARTED;
- }
- }
-
- p = &ptr->next;
- }
- return mStatus_NoError;
- }
+mDNSlocal void uDNS_DeleteWABQueries(mDNS *const m, SearchListElem *ptr, int delete)
+{
+ const char *name1 = mDNSNULL;
+ const char *name2 = mDNSNULL;
+ ARListElem **arList = &ptr->AuthRecs;
+ domainname namestorage1, namestorage2;
+ mStatus err;
+
+ // "delete" parameter indicates the type of query.
+ switch (delete)
+ {
+ case UDNS_WAB_BROWSE_QUERY:
+ mDNS_StopGetDomains(m, &ptr->BrowseQ);
+ mDNS_StopGetDomains(m, &ptr->DefBrowseQ);
+ name1 = mDNS_DomainTypeNames[mDNS_DomainTypeBrowse];
+ name2 = mDNS_DomainTypeNames[mDNS_DomainTypeBrowseDefault];
+ break;
+ case UDNS_WAB_LBROWSE_QUERY:
+ mDNS_StopGetDomains(m, &ptr->AutomaticBrowseQ);
+ name1 = mDNS_DomainTypeNames[mDNS_DomainTypeBrowseAutomatic];
+ break;
+ case UDNS_WAB_REG_QUERY:
+ mDNS_StopGetDomains(m, &ptr->RegisterQ);
+ mDNS_StopGetDomains(m, &ptr->DefRegisterQ);
+ name1 = mDNS_DomainTypeNames[mDNS_DomainTypeRegistration];
+ name2 = mDNS_DomainTypeNames[mDNS_DomainTypeRegistrationDefault];
+ break;
+ default:
+ LogMsg("uDNS_DeleteWABQueries: ERROR!! returning from default");
+ return;
+ }
+ // When we get the results to the domain enumeration queries, we add a LocalOnly
+ // entry. For example, if we issue a domain enumeration query for b._dns-sd._udp.xxxx.com,
+ // and when we get a response, we add a LocalOnly entry b._dns-sd._udp.local whose RDATA
+ // points to what we got in the response. Locate the appropriate LocalOnly entries and delete
+ // them.
+ if (name1)
+ {
+ MakeDomainNameFromDNSNameString(&namestorage1, name1);
+ AppendDNSNameString(&namestorage1, "local");
+ }
+ if (name2)
+ {
+ MakeDomainNameFromDNSNameString(&namestorage2, name2);
+ AppendDNSNameString(&namestorage2, "local");
+ }
+ while (*arList)
+ {
+ ARListElem *dereg = *arList;
+ if ((name1 && SameDomainName(&dereg->ar.namestorage, &namestorage1)) ||
+ (name2 && SameDomainName(&dereg->ar.namestorage, &namestorage2)))
+ {
+ LogInfo("uDNS_DeleteWABQueries: Deregistering PTR %##s -> %##s", dereg->ar.resrec.name->c, dereg->ar.resrec.rdata->u.name.c);
+ *arList = dereg->next;
+ err = mDNS_Deregister(m, &dereg->ar);
+ if (err) LogMsg("uDNS_DeleteWABQueries:: ERROR!! mDNS_Deregister returned %d", err);
+ // Memory will be freed in the FreeARElemCallback
+ }
+ else
+ {
+ LogInfo("uDNS_DeleteWABQueries: Skipping PTR %##s -> %##s", dereg->ar.resrec.name->c, dereg->ar.resrec.rdata->u.name.c);
+ arList = &(*arList)->next;
+ }
+ }
+}
+
+mDNSexport void uDNS_SetupWABQueries(mDNS *const m)
+{
+ SearchListElem **p = &SearchList, *ptr;
+ mStatus err;
+ int action = 0;
+
+ // step 1: mark each element for removal
+ for (ptr = SearchList; ptr; ptr = ptr->next)
+ ptr->flag |= SLE_DELETE;
+
+ // Make sure we have the search domains from the platform layer so that if we start the WAB
+ // queries below, we have the latest information.
+ mDNS_Lock(m);
+ if (!mDNSPlatformSetDNSConfig(m, mDNSfalse, mDNStrue, mDNSNULL, mDNSNULL, mDNSNULL, mDNSfalse))
+ {
+ // If the configuration did not change, clear the flag so that we don't free the searchlist.
+ // We still have to start the domain enumeration queries as we may not have started them
+ // before.
+ for (ptr = SearchList; ptr; ptr = ptr->next)
+ ptr->flag &= ~SLE_DELETE;
+ LogInfo("uDNS_SetupWABQueries: No config change");
+ }
+ mDNS_Unlock(m);
+
+ if (m->WABBrowseQueriesCount)
+ action |= UDNS_WAB_BROWSE_QUERY;
+ if (m->WABLBrowseQueriesCount)
+ action |= UDNS_WAB_LBROWSE_QUERY;
+ if (m->WABRegQueriesCount)
+ action |= UDNS_WAB_REG_QUERY;
+
+
+ // delete elems marked for removal, do queries for elems marked add
+ while (*p)
+ {
+ ptr = *p;
+ LogInfo("uDNS_SetupWABQueries:action 0x%x: Flags 0x%x, AuthRecs %p, InterfaceID %p %##s", action, ptr->flag, ptr->AuthRecs, ptr->InterfaceID, ptr->domain.c);
+ // If SLE_DELETE is set, stop all the queries, deregister all the records and free the memory.
+ // Otherwise, check to see what the "action" requires. If a particular action bit is not set and
+ // we have started the corresponding queries as indicated by the "flags", stop those queries and
+ // deregister the records corresponding to them.
+ if ((ptr->flag & SLE_DELETE) ||
+ (!(action & UDNS_WAB_BROWSE_QUERY) && (ptr->flag & SLE_WAB_BROWSE_QUERY_STARTED)) ||
+ (!(action & UDNS_WAB_LBROWSE_QUERY) && (ptr->flag & SLE_WAB_LBROWSE_QUERY_STARTED)) ||
+ (!(action & UDNS_WAB_REG_QUERY) && (ptr->flag & SLE_WAB_REG_QUERY_STARTED)))
+ {
+ if (ptr->flag & SLE_DELETE)
+ {
+ ARListElem *arList = ptr->AuthRecs;
+ ptr->AuthRecs = mDNSNULL;
+ *p = ptr->next;
+
+ // If the user has "local" in their DNS searchlist, we ignore that for the purposes of domain enumeration queries
+ // We suppressed the domain enumeration for scoped search domains below. When we enable that
+ // enable this.
+ if ((ptr->flag & SLE_WAB_BROWSE_QUERY_STARTED) &&
+ !SameDomainName(&ptr->domain, &localdomain) && (ptr->InterfaceID == mDNSInterface_Any))
+ {
+ LogInfo("uDNS_SetupWABQueries: DELETE Browse for domain %##s", ptr->domain.c);
+ mDNS_StopGetDomains(m, &ptr->BrowseQ);
+ mDNS_StopGetDomains(m, &ptr->DefBrowseQ);
+ }
+ if ((ptr->flag & SLE_WAB_LBROWSE_QUERY_STARTED) &&
+ !SameDomainName(&ptr->domain, &localdomain) && (ptr->InterfaceID == mDNSInterface_Any))
+ {
+ LogInfo("uDNS_SetupWABQueries: DELETE Legacy Browse for domain %##s", ptr->domain.c);
+ mDNS_StopGetDomains(m, &ptr->AutomaticBrowseQ);
+ }
+ if ((ptr->flag & SLE_WAB_REG_QUERY_STARTED) &&
+ !SameDomainName(&ptr->domain, &localdomain) && (ptr->InterfaceID == mDNSInterface_Any))
+ {
+ LogInfo("uDNS_SetupWABQueries: DELETE Registration for domain %##s", ptr->domain.c);
+ mDNS_StopGetDomains(m, &ptr->RegisterQ);
+ mDNS_StopGetDomains(m, &ptr->DefRegisterQ);
+ }
+
+ mDNSPlatformMemFree(ptr);
+
+ // deregister records generated from answers to the query
+ while (arList)
+ {
+ ARListElem *dereg = arList;
+ arList = arList->next;
+ LogInfo("uDNS_SetupWABQueries: DELETE Deregistering PTR %##s -> %##s", dereg->ar.resrec.name->c, dereg->ar.resrec.rdata->u.name.c);
+ err = mDNS_Deregister(m, &dereg->ar);
+ if (err) LogMsg("uDNS_SetupWABQueries:: ERROR!! mDNS_Deregister returned %d", err);
+ // Memory will be freed in the FreeARElemCallback
+ }
+ continue;
+ }
+
+ // If the user has "local" in their DNS searchlist, we ignore that for the purposes of domain enumeration queries
+ // We suppressed the domain enumeration for scoped search domains below. When we enable that
+ // enable this.
+ if (!(action & UDNS_WAB_BROWSE_QUERY) && (ptr->flag & SLE_WAB_BROWSE_QUERY_STARTED) &&
+ !SameDomainName(&ptr->domain, &localdomain) && (ptr->InterfaceID == mDNSInterface_Any))
+ {
+ LogInfo("uDNS_SetupWABQueries: Deleting Browse for domain %##s", ptr->domain.c);
+ ptr->flag &= ~SLE_WAB_BROWSE_QUERY_STARTED;
+ uDNS_DeleteWABQueries(m, ptr, UDNS_WAB_BROWSE_QUERY);
+ }
+
+ if (!(action & UDNS_WAB_LBROWSE_QUERY) && (ptr->flag & SLE_WAB_LBROWSE_QUERY_STARTED) &&
+ !SameDomainName(&ptr->domain, &localdomain) && (ptr->InterfaceID == mDNSInterface_Any))
+ {
+ LogInfo("uDNS_SetupWABQueries: Deleting Legacy Browse for domain %##s", ptr->domain.c);
+ ptr->flag &= ~SLE_WAB_LBROWSE_QUERY_STARTED;
+ uDNS_DeleteWABQueries(m, ptr, UDNS_WAB_LBROWSE_QUERY);
+ }
+
+ if (!(action & UDNS_WAB_REG_QUERY) && (ptr->flag & SLE_WAB_REG_QUERY_STARTED) &&
+ !SameDomainName(&ptr->domain, &localdomain) && (ptr->InterfaceID == mDNSInterface_Any))
+ {
+ LogInfo("uDNS_SetupWABQueries: Deleting Registration for domain %##s", ptr->domain.c);
+ ptr->flag &= ~SLE_WAB_REG_QUERY_STARTED;
+ uDNS_DeleteWABQueries(m, ptr, UDNS_WAB_REG_QUERY);
+ }
+
+ // Fall through to handle the ADDs
+ }
+
+ if ((action & UDNS_WAB_BROWSE_QUERY) && !(ptr->flag & SLE_WAB_BROWSE_QUERY_STARTED))
+ {
+ // If the user has "local" in their DNS searchlist, we ignore that for the purposes of domain enumeration queries.
+ // Also, suppress the domain enumeration for scoped search domains for now until there is a need.
+ if (!SameDomainName(&ptr->domain, &localdomain) && (ptr->InterfaceID == mDNSInterface_Any))
+ {
+ mStatus err1, err2;
+ err1 = mDNS_GetDomains(m, &ptr->BrowseQ, mDNS_DomainTypeBrowse, &ptr->domain, ptr->InterfaceID, FoundDomain, ptr);
+ if (err1)
+ {
+ LogMsg("uDNS_SetupWABQueries: GetDomains for domain %##s returned error(s):\n"
+ "%d (mDNS_DomainTypeBrowse)\n", ptr->domain.c, err1);
+ }
+ else
+ {
+ LogInfo("uDNS_SetupWABQueries: Starting Browse for domain %##s", ptr->domain.c);
+ }
+ err2 = mDNS_GetDomains(m, &ptr->DefBrowseQ, mDNS_DomainTypeBrowseDefault, &ptr->domain, ptr->InterfaceID, FoundDomain, ptr);
+ if (err2)
+ {
+ LogMsg("uDNS_SetupWABQueries: GetDomains for domain %##s returned error(s):\n"
+ "%d (mDNS_DomainTypeBrowseDefault)\n", ptr->domain.c, err2);
+ }
+ else
+ {
+ LogInfo("uDNS_SetupWABQueries: Starting Default Browse for domain %##s", ptr->domain.c);
+ }
+ // For simplicity, we mark a single bit for denoting that both the browse queries have started.
+ // It is not clear as to why one would fail to start and the other would succeed in starting up.
+ // If that happens, we will try to stop both the queries and one of them won't be in the list and
+ // it is not a hard error.
+ if (!err1 || !err2)
+ {
+ ptr->flag |= SLE_WAB_BROWSE_QUERY_STARTED;
+ }
+ }
+ }
+ if ((action & UDNS_WAB_LBROWSE_QUERY) && !(ptr->flag & SLE_WAB_LBROWSE_QUERY_STARTED))
+ {
+ // If the user has "local" in their DNS searchlist, we ignore that for the purposes of domain enumeration queries.
+ // Also, suppress the domain enumeration for scoped search domains for now until there is a need.
+ if (!SameDomainName(&ptr->domain, &localdomain) && (ptr->InterfaceID == mDNSInterface_Any))
+ {
+ mStatus err1;
+ err1 = mDNS_GetDomains(m, &ptr->AutomaticBrowseQ, mDNS_DomainTypeBrowseAutomatic, &ptr->domain, ptr->InterfaceID, FoundDomain, ptr);
+ if (err1)
+ {
+ LogMsg("uDNS_SetupWABQueries: GetDomains for domain %##s returned error(s):\n"
+ "%d (mDNS_DomainTypeBrowseAutomatic)\n",
+ ptr->domain.c, err1);
+ }
+ else
+ {
+ ptr->flag |= SLE_WAB_LBROWSE_QUERY_STARTED;
+ LogInfo("uDNS_SetupWABQueries: Starting Legacy Browse for domain %##s", ptr->domain.c);
+ }
+ }
+ }
+ if ((action & UDNS_WAB_REG_QUERY) && !(ptr->flag & SLE_WAB_REG_QUERY_STARTED))
+ {
+ // If the user has "local" in their DNS searchlist, we ignore that for the purposes of domain enumeration queries.
+ // Also, suppress the domain enumeration for scoped search domains for now until there is a need.
+ if (!SameDomainName(&ptr->domain, &localdomain) && (ptr->InterfaceID == mDNSInterface_Any))
+ {
+ mStatus err1, err2;
+ err1 = mDNS_GetDomains(m, &ptr->RegisterQ, mDNS_DomainTypeRegistration, &ptr->domain, ptr->InterfaceID, FoundDomain, ptr);
+ if (err1)
+ {
+ LogMsg("uDNS_SetupWABQueries: GetDomains for domain %##s returned error(s):\n"
+ "%d (mDNS_DomainTypeRegistration)\n", ptr->domain.c, err1);
+ }
+ else
+ {
+ LogInfo("uDNS_SetupWABQueries: Starting Registration for domain %##s", ptr->domain.c);
+ }
+ err2 = mDNS_GetDomains(m, &ptr->DefRegisterQ, mDNS_DomainTypeRegistrationDefault, &ptr->domain, ptr->InterfaceID, FoundDomain, ptr);
+ if (err2)
+ {
+ LogMsg("uDNS_SetupWABQueries: GetDomains for domain %##s returned error(s):\n"
+ "%d (mDNS_DomainTypeRegistrationDefault)", ptr->domain.c, err2);
+ }
+ else
+ {
+ LogInfo("uDNS_SetupWABQueries: Starting Default Registration for domain %##s", ptr->domain.c);
+ }
+ if (!err1 || !err2)
+ {
+ ptr->flag |= SLE_WAB_REG_QUERY_STARTED;
+ }
+ }
+ }
+
+ p = &ptr->next;
+ }
+}
+
+// mDNS_StartWABQueries is called once per API invocation where normally
+// one of the bits is set.
+mDNSexport void uDNS_StartWABQueries(mDNS *const m, int queryType)
+{
+ if (queryType & UDNS_WAB_BROWSE_QUERY)
+ {
+ m->WABBrowseQueriesCount++;
+ LogInfo("uDNS_StartWABQueries: Browse query count %d", m->WABBrowseQueriesCount);
+ }
+ if (queryType & UDNS_WAB_LBROWSE_QUERY)
+ {
+ m->WABLBrowseQueriesCount++;
+ LogInfo("uDNS_StartWABQueries: Legacy Browse query count %d", m->WABLBrowseQueriesCount);
+ }
+ if (queryType & UDNS_WAB_REG_QUERY)
+ {
+ m->WABRegQueriesCount++;
+ LogInfo("uDNS_StartWABQueries: Reg query count %d", m->WABRegQueriesCount);
+ }
+ uDNS_SetupWABQueries(m);
+}
+
+// mDNS_StopWABQueries is called once per API invocation where normally
+// one of the bits is set.
+mDNSexport void uDNS_StopWABQueries(mDNS *const m, int queryType)
+{
+ if (queryType & UDNS_WAB_BROWSE_QUERY)
+ {
+ m->WABBrowseQueriesCount--;
+ LogInfo("uDNS_StopWABQueries: Browse query count %d", m->WABBrowseQueriesCount);
+ }
+ if (queryType & UDNS_WAB_LBROWSE_QUERY)
+ {
+ m->WABLBrowseQueriesCount--;
+ LogInfo("uDNS_StopWABQueries: Legacy Browse query count %d", m->WABLBrowseQueriesCount);
+ }
+ if (queryType & UDNS_WAB_REG_QUERY)
+ {
+ m->WABRegQueriesCount--;
+ LogInfo("uDNS_StopWABQueries: Reg query count %d", m->WABRegQueriesCount);
+ }
+ uDNS_SetupWABQueries(m);
+}