Lines Matching +full:srv +full:- +full:ipv4 +full:- +full:multi +full:- +full:target
1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2003-2006 Apple Computer, Inc. All rights reserved.
9 * http://www.apache.org/licenses/LICENSE-2.0
47 // Apple-specific functionality, not required for other platforms
72 // User IDs 0-500 are system-wide processes, not actual users in the usual sense
78 #pragma mark -
79 #pragma mark - Types and Data Structures
103 …AuthRecord *rr; // Pointer to variable-sized AuthRecord (Why a pointer? Why not just embed it h…
116 mDNSBool default_local; // is this the "local." from an empty-string registration?
119 ServiceRecordSet srs; // note -- variable-sized object -- must be last field in struct
122 // for multi-domain default browsing
140 // Note: On a shared connection these fields in the primary structure, including hdr, are re-used
161 registered_record_entry *reg_recs; // list of registrations for a connection-oriented request
220 const ResourceRecord *srv; member
227 // struct physically sits between ipc message header and call-specific fields in the message buffer
246 #pragma mark -
247 #pragma mark - Globals
262 // 2. LocalDomainEnumRecords (locally-generated local-only PTR records -- equivalent to slElem->Aut…
266 …*AutoRegistrationDomains; // Domains where we automatically register for empty-string registrations
269 static ARListElem *LocalDomainEnumRecords; // List of locally-generated PTR records to augment …
270 mDNSexport DNameListElem *AutoBrowseDomains; // List created from those local-only PTR records plu…
283 #pragma mark -
284 #pragma mark - General Utility Functions
302 // hack to search-replace perror's to LogMsg's
310 if (req->terminate == (req_termination_fn)~0) in abort_request()
311 …{ LogMsg("abort_request: ERROR: Attempt to abort operation %p with req->terminate %p", req, req->t… in abort_request()
314 // If this is actually a shared connection operation, then its req->terminate function will scan in abort_request()
316 if (req->terminate) req->terminate(req); in abort_request()
318 if (!dnssd_SocketValid(req->sd)) in abort_request()
319 …{ LogMsg("abort_request: ERROR: Attempt to abort operation %p with invalid fd %d", req, req->s… in abort_request()
322 if (!req->primary) in abort_request()
324 …if (req->errsd != req->sd) LogOperation("%3d: Removing FD and closing errsd %d", req->sd, req->err… in abort_request()
325 else LogOperation("%3d: Removing FD", req->sd); in abort_request()
326 …udsSupportRemoveFDFromEventLoop(req->sd, req->platform_data); // Note: This also closes file desc… in abort_request()
327 if (req->errsd != req->sd) { dnssd_close(req->errsd); req->errsd = req->sd; } in abort_request()
329 while (req->replies) // free pending replies in abort_request()
331 reply_state *ptr = req->replies; in abort_request()
332 req->replies = req->replies->next; in abort_request()
337 // Set req->sd to something invalid, so that udsserver_idle knows to unlink and free this structure in abort_request()
339 …// Don't use dnssd_InvalidSocket (-1) because that's the sentinel value MACOSX_MDNS_MALLOC_DEBUGGI… in abort_request()
341 req->sd = req->errsd = -2; in abort_request()
343 req->sd = req->errsd = dnssd_InvalidSocket; in abort_request()
345 …// We also set req->terminate to a bogus value so we know if abort_request() gets called again for… in abort_request()
346 req->terminate = (req_termination_fn)~0; in abort_request()
353 while (*p && *p != req) p=&(*p)->next; in AbortUnlinkAndFree()
354 if (*p) { *p = req->next; freeL("request_state/AbortUnlinkAndFree", req); } in AbortUnlinkAndFree()
364 LogMsg("ERROR: create_reply - data length less than length of required fields"); in create_reply()
368 reply = mallocL("reply_state", sizeof(reply_state) + datalen - sizeof(reply_hdr)); in create_reply()
371 reply->next = mDNSNULL; in create_reply()
372 reply->totallen = (mDNSu32)datalen + sizeof(ipc_msg_hdr); in create_reply()
373 reply->nwriten = 0; in create_reply()
375 reply->mhdr->version = VERSION; in create_reply()
376 reply->mhdr->datalen = (mDNSu32)datalen; in create_reply()
377 reply->mhdr->ipc_flags = 0; in create_reply()
378 reply->mhdr->op = op; in create_reply()
379 reply->mhdr->client_context = request->hdr.client_context; in create_reply()
380 reply->mhdr->reg_index = 0; in create_reply()
389 request_state *r = req->primary ? req->primary : req; in append_reply()
390 reply_state **ptr = &r->replies; in append_reply()
391 while (*ptr) ptr = &(*ptr)->next; in append_reply()
393 rep->next = NULL; in append_reply()
429 (*rep)->rhdr->flags = dnssd_htonl(flags); in GenerateNTDResponse()
430 …(*rep)->rhdr->ifi = dnssd_htonl(mDNSPlatformInterfaceIndexfromInterfaceID(&mDNSStorage, id, mDNS… in GenerateNTDResponse()
431 (*rep)->rhdr->error = dnssd_htonl(err); in GenerateNTDResponse()
434 data = (char *)&(*rep)->rhdr[1]; in GenerateNTDResponse()
472 (*rep)->rhdr->flags = dnssd_htonl(flags); in GenerateBonjourBrowserResponse()
473 …(*rep)->rhdr->ifi = dnssd_htonl(mDNSPlatformInterfaceIndexfromInterfaceID(&mDNSStorage, id, mDNS… in GenerateBonjourBrowserResponse()
474 (*rep)->rhdr->error = dnssd_htonl(err); in GenerateBonjourBrowserResponse()
477 data = (char *)&(*rep)->rhdr[1]; in GenerateBonjourBrowserResponse()
485 // (ttl only extracted/set if ttl argument is non-zero). Returns NULL for a bad-parameter error
488 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend); in read_rr_from_ipc_msg()
489 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend); in read_rr_from_ipc_msg()
491 int str_err = get_string(&request->msgptr, request->msgend, name, sizeof(name)); in read_rr_from_ipc_msg()
492 mDNSu16 type = get_uint16(&request->msgptr, request->msgend); in read_rr_from_ipc_msg()
493 mDNSu16 class = get_uint16(&request->msgptr, request->msgend); in read_rr_from_ipc_msg()
494 mDNSu16 rdlen = get_uint16(&request->msgptr, request->msgend); in read_rr_from_ipc_msg()
495 const char *rdata = get_rdata (&request->msgptr, request->msgend, rdlen); in read_rr_from_ipc_msg()
496 mDNSu32 ttl = GetTTL ? get_uint32(&request->msgptr, request->msgend) : 0; in read_rr_from_ipc_msg()
502 request->flags = flags; in read_rr_from_ipc_msg()
504 if (str_err) { LogMsg("ERROR: read_rr_from_ipc_msg - get_string"); return NULL; } in read_rr_from_ipc_msg()
506 if (!request->msgptr) { LogMsg("Error reading Resource Record from client"); return NULL; } in read_rr_from_ipc_msg()
516 …rr = mallocL("AuthRecord/read_rr_from_ipc_msg", sizeof(AuthRecord) - sizeof(RDataBody) + storage_s… in read_rr_from_ipc_msg()
532 if (!MakeDomainNameFromDNSNameString(&rr->namestorage, name)) in read_rr_from_ipc_msg()
539 if (flags & kDNSServiceFlagsAllowRemoteQuery) rr->AllowRemoteQuery = mDNStrue; in read_rr_from_ipc_msg()
540 rr->resrec.rrclass = class; in read_rr_from_ipc_msg()
541 rr->resrec.rdlength = rdlen; in read_rr_from_ipc_msg()
542 rr->resrec.rdata->MaxRDLength = rdlen; in read_rr_from_ipc_msg()
543 mDNSPlatformMemCopy(rr->resrec.rdata->u.data, rdata, rdlen); in read_rr_from_ipc_msg()
544 if (GetTTL) rr->resrec.rroriginalttl = ttl; in read_rr_from_ipc_msg()
545 rr->resrec.namehash = DomainNameHashValue(rr->resrec.name); in read_rr_from_ipc_msg()
546 SetNewRData(&rr->resrec, mDNSNULL, 0); // Sets rr->rdatahash for us in read_rr_from_ipc_msg()
550 mDNSlocal int build_domainname_from_strings(domainname *srv, char *name, char *regtype, char *domai… in build_domainname_from_strings() argument
555 if (!MakeDomainLabelFromLiteralString(&n, name)) return -1; in build_domainname_from_strings()
556 if (!MakeDomainNameFromDNSNameString(&t, regtype)) return -1; in build_domainname_from_strings()
557 if (!MakeDomainNameFromDNSNameString(&d, domain)) return -1; in build_domainname_from_strings()
558 if (!ConstructServiceName(srv, &n, &t, &d)) return -1; in build_domainname_from_strings()
565 …// On a freshly-created Unix Domain Socket, the kernel should *never* fail to buffer a small write… in send_all()
577 int bestDelta = -1; // the delta of the best match, lower is better
581 if (SystemUID(request->uid)) return mDNStrue;
584 for (delem = doms; delem; delem = delem->next)
586 if (delem->uid)
588 int delemLabels = CountLabels(&delem->name);
589 int delta = dLabels - delemLabels;
590 …if ((bestDelta == -1 || delta <= bestDelta) && SameDomainName(&delem->name, SkipLeadingLabels(d, d…
593 allow = (allow || (delem->uid == request->uid));
598 return bestDelta == -1 ? mDNStrue : allow;
604 #pragma mark -
605 #pragma mark - external helpers
610 AuthRecord *st = instance->subtypes; in external_start_advertising_helper()
614 if (mDNSIPPortIsZero(instance->request->u.servicereg.port)) in external_start_advertising_helper()
624 // with the SRV record when advertising a service. in external_start_advertising_helper()
628 …if (instance->external_advertise) LogMsg("external_start_advertising_helper: external_advertise al… in external_start_advertising_helper()
630 for ( i = 0; i < instance->request->u.servicereg.num_subtypes; i++) in external_start_advertising_helper()
633 external_start_advertising_service(&instance->srs.RR_PTR.resrec); in external_start_advertising_helper()
634 external_start_advertising_service(&instance->srs.RR_TXT.resrec); in external_start_advertising_helper()
636 for (e = instance->srs.Extras; e; e = e->next) in external_start_advertising_helper()
637 external_start_advertising_service(&e->r.resrec); in external_start_advertising_helper()
639 instance->external_advertise = mDNStrue; in external_start_advertising_helper()
644 AuthRecord *st = instance->subtypes; in external_stop_advertising_helper()
648 if (!instance->external_advertise) return; in external_stop_advertising_helper()
652 for ( i = 0; i < instance->request->u.servicereg.num_subtypes; i++) in external_stop_advertising_helper()
655 external_stop_advertising_service(&instance->srs.RR_PTR.resrec); in external_stop_advertising_helper()
656 external_stop_advertising_service(&instance->srs.RR_TXT.resrec); in external_stop_advertising_helper()
658 for (e = instance->srs.Extras; e; e = e->next) in external_stop_advertising_helper()
659 external_stop_advertising_service(&e->r.resrec); in external_stop_advertising_helper()
661 instance->external_advertise = mDNSfalse; in external_stop_advertising_helper()
666 #pragma mark -
667 #pragma mark - DNSServiceRegister
672 ExtraResourceRecord *extra = (ExtraResourceRecord *)rr->RecordContext; in FreeExtraRR()
677 LogInfo(" FreeExtraRR %s", RRDisplayString(m, &rr->resrec)); in FreeExtraRR()
679 if (rr->resrec.rdata != &rr->rdatastorage) in FreeExtraRR()
680 freeL("Extra RData", rr->resrec.rdata); in FreeExtraRR()
684 mDNSlocal void unlink_and_free_service_instance(service_instance *srv) in unlink_and_free_service_instance() argument
686 ExtraResourceRecord *e = srv->srs.Extras, *tmp; in unlink_and_free_service_instance()
688 external_stop_advertising_helper(srv); in unlink_and_free_service_instance()
691 if (srv->request) in unlink_and_free_service_instance()
693 service_instance **p = &srv->request->u.servicereg.instances; in unlink_and_free_service_instance()
696 if (*p == srv) { *p = (*p)->next; break; } in unlink_and_free_service_instance()
697 p = &(*p)->next; in unlink_and_free_service_instance()
703 e->r.RecordContext = e; in unlink_and_free_service_instance()
705 e = e->next; in unlink_and_free_service_instance()
706 FreeExtraRR(&mDNSStorage, &tmp->r, mStatus_MemFree); in unlink_and_free_service_instance()
709 if (srv->srs.RR_TXT.resrec.rdata != &srv->srs.RR_TXT.rdatastorage) in unlink_and_free_service_instance()
710 freeL("TXT RData", srv->srs.RR_TXT.resrec.rdata); in unlink_and_free_service_instance()
712 if (srv->subtypes) { freeL("ServiceSubTypes", srv->subtypes); srv->subtypes = NULL; } in unlink_and_free_service_instance()
713 freeL("service_instance", srv); in unlink_and_free_service_instance()
717 // For auto-named services, we can have at most one per machine -- if we allowed two auto-named ser…
718 // the same type on the same machine, we'd get into an infinite autoimmune-response loop of continu…
722 ResourceRecord *r = &srs->RR_SRV.resrec; in CountPeerRegistrations()
725 for (rr = m->ResourceRecords; rr; rr=rr->next) in CountPeerRegistrations()
726 …if (rr->resrec.rrtype == kDNSType_SRV && SameDomainName(rr->resrec.name, r->name) && !IdenticalSam… in CountPeerRegistrations()
729 verbosedebugf("%d peer registrations for %##s", count, r->name->c); in CountPeerRegistrations()
733 mDNSexport int CountExistingRegistrations(domainname *srv, mDNSIPPort port) in CountExistingRegistrations() argument
737 for (rr = mDNSStorage.ResourceRecords; rr; rr=rr->next) in CountExistingRegistrations()
738 if (rr->resrec.rrtype == kDNSType_SRV && in CountExistingRegistrations()
739 mDNSSameIPPort(rr->resrec.rdata->u.srv.port, port) && in CountExistingRegistrations()
740 SameDomainName(rr->resrec.name, srv)) in CountExistingRegistrations()
748 service_instance *instance = srs->ServiceContext; in SendServiceRemovalNotification()
749 …if (GenerateNTDResponse(srs->RR_SRV.resrec.name, srs->RR_SRV.resrec.InterfaceID, instance->request… in SendServiceRemovalNotification()
750 …iceRemovalNotification: %##s is not valid DNS-SD SRV name", instance->request->sd, srs->RR_SRV.res… in SendServiceRemovalNotification()
751 else { append_reply(instance->request, rep); instance->clientnotified = mDNSfalse; } in SendServiceRemovalNotification()
754 // service registration callback performs three duties - frees memory for deregistered services,
766 instance = srs->ServiceContext; in regservice_callback()
767 if (!instance) { LogMsg("regservice_callback: srs->ServiceContext is NULL %d", result); return; } in regservice_callback()
769 // don't send errors up to client for wide-area, empty-string registrations in regservice_callback()
770 if (instance->request && in regservice_callback()
771 instance->request->u.servicereg.default_domain && in regservice_callback()
772 !instance->default_local) in regservice_callback()
782 char prefix[16] = "---:"; in regservice_callback()
783 if (instance->request) mDNS_snprintf(prefix, sizeof(prefix), "%3d:", instance->request->sd); in regservice_callback()
784 …LogOperation(fmt, prefix, srs->RR_SRV.resrec.name->c, mDNSVal16(srs->RR_SRV.resrec.rdata->u.srv.po… in regservice_callback()
788 …if (!instance->request && result != mStatus_MemFree) { LogMsg("regservice_callback: instance->requ… in regservice_callback()
792 if (instance->request->u.servicereg.allowremotequery) in regservice_callback()
795 srs->RR_ADV.AllowRemoteQuery = mDNStrue; in regservice_callback()
796 srs->RR_PTR.AllowRemoteQuery = mDNStrue; in regservice_callback()
797 srs->RR_SRV.AllowRemoteQuery = mDNStrue; in regservice_callback()
798 srs->RR_TXT.AllowRemoteQuery = mDNStrue; in regservice_callback()
799 for (e = instance->srs.Extras; e; e = e->next) e->r.AllowRemoteQuery = mDNStrue; in regservice_callback()
802 …if (GenerateNTDResponse(srs->RR_SRV.resrec.name, srs->RR_SRV.resrec.InterfaceID, instance->request… in regservice_callback()
803 …d: regservice_callback: %##s is not valid DNS-SD SRV name", instance->request->sd, srs->RR_SRV.res… in regservice_callback()
804 else { append_reply(instance->request, rep); instance->clientnotified = mDNStrue; } in regservice_callback()
806 …->request->u.servicereg.InterfaceID == mDNSInterface_P2P || (!instance->request->u.servicereg.Inte… in regservice_callback()
811 if (instance->request->u.servicereg.autoname && CountPeerRegistrations(m, srs) == 0) in regservice_callback()
816 if (instance->request && instance->renameonmemfree) in regservice_callback()
819 instance->renameonmemfree = 0; in regservice_callback()
820 err = mDNS_RenameAndReregisterService(m, srs, &instance->request->u.servicereg.name); in regservice_callback()
821 if (err) LogMsg("ERROR: regservice_callback - RenameAndReregisterService returned %d", err); in regservice_callback()
822 // error should never happen - safest to log and continue in regservice_callback()
829 if (instance->request->u.servicereg.autorename) in regservice_callback()
832 if (instance->request->u.servicereg.autoname && CountPeerRegistrations(m, srs) == 0) in regservice_callback()
835 IncrementLabelSuffix(&m->nicelabel, mDNStrue); in regservice_callback()
838 else // On conflict for a non-autoname service, rename and reregister just that one service in regservice_callback()
840 if (instance->clientnotified) SendServiceRemovalNotification(srs); in regservice_callback()
848 …if (GenerateNTDResponse(srs->RR_SRV.resrec.name, srs->RR_SRV.resrec.InterfaceID, instance->request… in regservice_callback()
849 …d: regservice_callback: %##s is not valid DNS-SD SRV name", instance->request->sd, srs->RR_SRV.res… in regservice_callback()
850 else { append_reply(instance->request, rep); instance->clientnotified = mDNStrue; } in regservice_callback()
859 …if (GenerateNTDResponse(srs->RR_SRV.resrec.name, srs->RR_SRV.resrec.InterfaceID, instance->request… in regservice_callback()
860 …d: regservice_callback: %##s is not valid DNS-SD SRV name", instance->request->sd, srs->RR_SRV.res… in regservice_callback()
861 else { append_reply(instance->request, rep); instance->clientnotified = mDNStrue; } in regservice_callback()
869 if (!rr->RecordContext) // parent struct already freed by termination callback in regrecord_callback()
879 …// with the old rdata (so that we can free it) and stores the new rdata in "rr->resrec.rdata". Thi… in regrecord_callback()
881 if (rr->resrec.rdata != &rr->rdatastorage) freeL("RData/regrecord_callback", rr->resrec.rdata); in regrecord_callback()
887 registered_record_entry *re = rr->RecordContext; in regrecord_callback()
888 request_state *request = re->request; in regrecord_callback()
896 LogOperation(fmt, request->sd, re->key, RRDisplayString(m, &rr->resrec), result); in regrecord_callback()
903 reply->mhdr->client_context = re->regrec_client_context; in regrecord_callback()
904 reply->rhdr->flags = dnssd_htonl(0); in regrecord_callback()
905 …reply->rhdr->ifi = dnssd_htonl(mDNSPlatformInterfaceIndexfromInterfaceID(m, rr->resrec.Interface… in regrecord_callback()
906 reply->rhdr->error = dnssd_htonl(result); in regrecord_callback()
913 registered_record_entry **ptr = &request->u.reg_recs; in regrecord_callback()
914 while (*ptr && (*ptr) != re) ptr = &(*ptr)->next; in regrecord_callback()
915 if (!*ptr) { LogMsg("regrecord_callback - record not in list!"); return; } in regrecord_callback()
916 *ptr = (*ptr)->next; in regrecord_callback()
917 freeL("registered_record_entry AuthRecord regrecord_callback", re->rr); in regrecord_callback()
922 if (re->external_advertise) LogMsg("regrecord_callback: external_advertise already set!"); in regrecord_callback()
924 …if (re->origInterfaceID == mDNSInterface_P2P || (!re->origInterfaceID && IsLocalDomain(&rr->namest… in regrecord_callback()
927 external_start_advertising_service(&rr->resrec); in regrecord_callback()
928 re->external_advertise = mDNStrue; in regrecord_callback()
940 LogOperation("%3d: DNSServiceCreateConnection STOP", request->sd); in connection_termination()
944 if ((*req)->primary == request) in connection_termination()
948 …if (tmp->primary == tmp) LogMsg("connection_termination ERROR (*req)->primary == *req for %p %d", … in connection_termination()
949 …if (tmp->replies) LogMsg("connection_termination ERROR How can subordinate req %p %d have r… in connection_termination()
951 *req = tmp->next; in connection_termination()
955 req = &(*req)->next; in connection_termination()
958 while (request->u.reg_recs) in connection_termination()
960 registered_record_entry *ptr = request->u.reg_recs; in connection_termination()
961 …d: DNSServiceRegisterRecord(%u %s) STOP", request->sd, ptr->key, RRDisplayString(&mDNSStorage, &pt… in connection_termination()
962 request->u.reg_recs = request->u.reg_recs->next; in connection_termination()
963 ptr->rr->RecordContext = NULL; in connection_termination()
964 if (ptr->external_advertise) in connection_termination()
966 ptr->external_advertise = mDNSfalse; in connection_termination()
967 external_stop_advertising_service(&ptr->rr->resrec); in connection_termination()
969 mDNS_Deregister(&mDNSStorage, ptr->rr); // Will free ptr->rr for us in connection_termination()
977 …LogOperation("%3d: Cancel %08X %08X", request->sd, request->hdr.client_context.u32[1], request->hd… in handle_cancel_request()
980 if ((*req)->primary == request && in handle_cancel_request()
981 (*req)->hdr.client_context.u32[0] == request->hdr.client_context.u32[0] && in handle_cancel_request()
982 (*req)->hdr.client_context.u32[1] == request->hdr.client_context.u32[1]) in handle_cancel_request()
987 *req = tmp->next; in handle_cancel_request()
991 req = &(*req)->next; in handle_cancel_request()
1002 // Don't allow non-local domains to be regsitered as LocalOnly. Allowing this would permit in handle_regrecord_request()
1004 if (rr->resrec.InterfaceID == mDNSInterface_LocalOnly && !IsLocalDomain(rr->resrec.name) && in handle_regrecord_request()
1005 …rr->resrec.rrclass == kDNSClass_IN && (rr->resrec.rrtype == kDNSType_A || rr->resrec.rrtype == kDN… in handle_regrecord_request()
1006 rr->resrec.rrtype == kDNSType_CNAME)) in handle_regrecord_request()
1014 re->key = request->hdr.reg_index; in handle_regrecord_request()
1015 re->rr = rr; in handle_regrecord_request()
1016 re->regrec_client_context = request->hdr.client_context; in handle_regrecord_request()
1017 re->request = request; in handle_regrecord_request()
1018 re->external_advertise = mDNSfalse; in handle_regrecord_request()
1019 rr->RecordContext = re; in handle_regrecord_request()
1020 rr->RecordCallback = regrecord_callback; in handle_regrecord_request()
1022 re->origInterfaceID = rr->resrec.InterfaceID; in handle_regrecord_request()
1023 if (rr->resrec.InterfaceID == mDNSInterface_P2P) rr->resrec.InterfaceID = mDNSInterface_Any; in handle_regrecord_request()
1025 …if (!AuthorizedDomain(request, rr->resrec.name, AutoRegistrationDomains)) return (mStatus_NoError); in handle_regrecord_request()
1027 if (rr->resrec.rroriginalttl == 0) in handle_regrecord_request()
1028 rr->resrec.rroriginalttl = DefaultTTLforRRType(rr->resrec.rrtype); in handle_regrecord_request()
1030 …%3d: DNSServiceRegisterRecord(%u %s) START", request->sd, re->key, RRDisplayString(&mDNSStorage, &… in handle_regrecord_request()
1034 …DNSServiceRegisterRecord(%u %s) ERROR (%d)", request->sd, re->key, RRDisplayString(&mDNSStorage, &… in handle_regrecord_request()
1040 re->next = request->u.reg_recs; in handle_regrecord_request()
1041 request->u.reg_recs = re; in handle_regrecord_request()
1052 while (request->u.servicereg.instances) in regservice_termination_callback()
1054 service_instance *p = request->u.servicereg.instances; in regservice_termination_callback()
1055 request->u.servicereg.instances = request->u.servicereg.instances->next; in regservice_termination_callback()
1058 request->sd, p->srs.RR_SRV.resrec.name->c, mDNSVal16(p->srs.RR_SRV.resrec.rdata->u.srv.port)); in regservice_termination_callback()
1064 …// request->u.servicereg.instances as we work our way through the list, implicitly cutting one ele… in regservice_termination_callback()
1065 …// We can't clear p->request *after* the calling mDNS_DeregisterService/unlink_and_free_service_in… in regservice_termination_callback()
1067 p->request = NULL; in regservice_termination_callback()
1068 if (mDNS_DeregisterService(&mDNSStorage, &p->srs)) unlink_and_free_service_instance(p); in regservice_termination_callback()
1069 // Don't touch service_instance *p after this -- it's likely to have been freed already in regservice_termination_callback()
1071 if (request->u.servicereg.txtdata) in regservice_termination_callback()
1072 …{ freeL("service_info txtdata", request->u.servicereg.txtdata); request->u.servicereg.txtdata = NU… in regservice_termination_callback()
1073 if (request->u.servicereg.autoname) in regservice_termination_callback()
1076 request->u.servicereg.autoname = mDNSfalse; in regservice_termination_callback()
1084 for (req = all_requests; req; req = req->next) in LocateSubordinateRequest()
1085 if (req->primary == request && in LocateSubordinateRequest()
1086 req->hdr.client_context.u32[0] == request->hdr.client_context.u32[0] && in LocateSubordinateRequest()
1087 req->hdr.client_context.u32[1] == request->hdr.client_context.u32[1]) return(req); in LocateSubordinateRequest()
1093 ServiceRecordSet *srs = &instance->srs; in add_record_to_service()
1096 …ExtraResourceRecord *extra = mallocL("ExtraResourceRecord", sizeof(*extra) - sizeof(RDataBody) + s… in add_record_to_service()
1100 extra->r.resrec.rrtype = rrtype; in add_record_to_service()
1101 extra->r.rdatastorage.MaxRDLength = (mDNSu16) size; in add_record_to_service()
1102 extra->r.resrec.rdlength = rdlen; in add_record_to_service()
1103 mDNSPlatformMemCopy(&extra->r.rdatastorage.u.data, rdata, rdlen); in add_record_to_service()
1105 result = mDNS_AddRecordToService(&mDNSStorage, srs, extra, &extra->r.rdatastorage, ttl, in add_record_to_service()
1106 (request->flags & kDNSServiceFlagsIncludeP2P) ? 1: 0); in add_record_to_service()
1109 extra->ClientID = request->hdr.reg_index; in add_record_to_service()
1110 …->external_advertise && (instance->request->u.servicereg.InterfaceID == mDNSInterface_P2P || (!ins… in add_record_to_service()
1113 external_start_advertising_service(&extra->r.resrec); in add_record_to_service()
1122 DNSServiceFlags flags = get_flags (&request->msgptr, request->msgend); in handle_add_request()
1123 mDNSu16 rrtype = get_uint16(&request->msgptr, request->msgend); in handle_add_request()
1124 mDNSu16 rdlen = get_uint16(&request->msgptr, request->msgend); in handle_add_request()
1125 const char *rdata = get_rdata (&request->msgptr, request->msgend, rdlen); in handle_add_request()
1126 mDNSu32 ttl = get_uint32(&request->msgptr, request->msgend); in handle_add_request()
1130 …if (!request->msgptr) { LogMsg("%3d: DNSServiceAddRecord(unreadable parameters)", request->sd); re… in handle_add_request()
1133 if (request->terminate == connection_termination) request = LocateSubordinateRequest(request); in handle_add_request()
1135 if (request->terminate != regservice_termination_callback) in handle_add_request()
1136 …{ LogMsg("%3d: DNSServiceAddRecord(not a registered service ref)", request->sd); return(mStatus_Ba… in handle_add_request()
1140 if (mDNSIPPortIsZero(request->u.servicereg.port)) in handle_add_request()
1141 …iceAddRecord: adding record to a service registered with zero port", request->sd); return(mStatus_… in handle_add_request()
1143 LogOperation("%3d: DNSServiceAddRecord(%X, %##s, %s, %d)", request->sd, flags, in handle_add_request()
1144 …(request->u.servicereg.instances) ? request->u.servicereg.instances->srs.RR_SRV.resrec.name->c : N… in handle_add_request()
1146 for (i = request->u.servicereg.instances; i; i = i->next) in handle_add_request()
1149 if (result && i->default_local) break; in handle_add_request()
1150 else result = mStatus_NoError; // suppress non-local default errors in handle_add_request()
1158 mDNSBool external_advertise = (rr->UpdateContext) ? *((mDNSBool *)rr->UpdateContext) : mDNSfalse; in update_callback()
1172 ResourceRecord ext = rr->resrec; in update_callback()
1173 …if (ext.rdlength == oldrdlen && mDNSPlatformMemSame(&ext.rdata->u, &oldrd->u, oldrdlen)) goto exit; in update_callback()
1177 external_start_advertising_service(&rr->resrec); in update_callback()
1180 if (oldrd != &rr->rdatastorage) freeL("RData/update_callback", oldrd); in update_callback()
1187 RData *newrd = mallocL("RData/update_record", sizeof(RData) - sizeof(RDataBody) + rdsize); in update_record()
1189 newrd->MaxRDLength = (mDNSu16) rdsize; in update_record()
1190 mDNSPlatformMemCopy(&newrd->u, rdata, rdlen); in update_record()
1192 …// BIND named (name daemon) doesn't allow TXT records with zero-length rdata. This is strictly spe… in update_record()
1193 …C 1035 specifies a TXT record as "One or more <character-string>s", not "Zero or more <character-s… in update_record()
1194 // Since some legacy apps try to create zero-length TXT records, we'll silently correct it here. in update_record()
1195 if (rr->resrec.rrtype == kDNSType_TXT && rdlen == 0) { rdlen = 1; newrd->u.txt.c[0] = 0; } in update_record()
1197 if (external_advertise) rr->UpdateContext = (void *)external_advertise; in update_record()
1206 const ipc_msg_hdr *const hdr = &request->hdr; in handle_update_request()
1212 DNSServiceFlags flags = get_flags (&request->msgptr, request->msgend); // flags unused in handle_update_request()
1213 mDNSu16 rdlen = get_uint16(&request->msgptr, request->msgend); in handle_update_request()
1214 const char *rdata = get_rdata (&request->msgptr, request->msgend, rdlen); in handle_update_request()
1215 mDNSu32 ttl = get_uint32(&request->msgptr, request->msgend); in handle_update_request()
1218 …if (!request->msgptr) { LogMsg("%3d: DNSServiceUpdateRecord(unreadable parameters)", request->sd);… in handle_update_request()
1221 if (request->terminate == connection_termination) request = LocateSubordinateRequest(request); in handle_update_request()
1223 if (request->terminate == connection_termination) in handle_update_request()
1227 for (reptr = request->u.reg_recs; reptr; reptr = reptr->next) in handle_update_request()
1229 if (reptr->key == hdr->reg_index) in handle_update_request()
1231 result = update_record(reptr->rr, rdlen, rdata, ttl, &reptr->external_advertise); in handle_update_request()
1233 …request->sd, reptr->rr->resrec.name->c, reptr->rr ? DNSTypeName(reptr->rr->resrec.rrtype) : "<NONE… in handle_update_request()
1241 if (request->terminate != regservice_termination_callback) in handle_update_request()
1242 …{ LogMsg("%3d: DNSServiceUpdateRecord(not a registered service ref)", request->sd); return(mStatus… in handle_update_request()
1244 …// For a service registered with zero port, only SRV record is initialized. Don't allow any update… in handle_update_request()
1245 if (mDNSIPPortIsZero(request->u.servicereg.port)) in handle_update_request()
1246 …Record: updating the record of a service registered with zero port", request->sd); return(mStatus_… in handle_update_request()
1249 if (hdr->reg_index == TXT_RECORD_INDEX) in handle_update_request()
1251 if (request->u.servicereg.txtdata) in handle_update_request()
1252 …{ freeL("service_info txtdata", request->u.servicereg.txtdata); request->u.servicereg.txtdata = NU… in handle_update_request()
1255 request->u.servicereg.txtdata = mallocL("service_info txtdata", rdlen); in handle_update_request()
1256 if (!request->u.servicereg.txtdata) FatalError("ERROR: handle_update_request - malloc"); in handle_update_request()
1257 mDNSPlatformMemCopy(request->u.servicereg.txtdata, rdata, rdlen); in handle_update_request()
1259 request->u.servicereg.txtlen = rdlen; in handle_update_request()
1263 for (i = request->u.servicereg.instances; i; i = i->next) in handle_update_request()
1265 if (hdr->reg_index == TXT_RECORD_INDEX) rr = &i->srs.RR_TXT; in handle_update_request()
1269 for (e = i->srs.Extras; e; e = e->next) in handle_update_request()
1270 if (e->ClientID == hdr->reg_index) { rr = &e->r; break; } in handle_update_request()
1274 result = update_record(rr, rdlen, rdata, ttl, &i->external_advertise); in handle_update_request()
1275 if (result && i->default_local) goto end; in handle_update_request()
1276 else result = mStatus_NoError; // suppress non-local default errors in handle_update_request()
1280 if (request->terminate == regservice_termination_callback) in handle_update_request()
1281 LogOperation("%3d: DNSServiceUpdateRecord(%##s, %s)", request->sd, in handle_update_request()
1282 …(request->u.servicereg.instances) ? request->u.servicereg.instances->srs.RR_SRV.resrec.name->c : N… in handle_update_request()
1283 rr ? DNSTypeName(rr->resrec.rrtype) : "<NONE>"); in handle_update_request()
1292 registered_record_entry *e, **ptr = &request->u.reg_recs; in remove_record()
1294 while (*ptr && (*ptr)->key != request->hdr.reg_index) ptr = &(*ptr)->next; in remove_record()
1295 …if (!*ptr) { LogMsg("%3d: DNSServiceRemoveRecord(%u) not found", request->sd, request->hdr.reg_ind… in remove_record()
1297 *ptr = e->next; // unlink in remove_record()
1299 …ation("%3d: DNSServiceRemoveRecord(%u %s)", request->sd, e->key, RRDisplayString(&mDNSStorage, &e-… in remove_record()
1300 e->rr->RecordContext = NULL; in remove_record()
1301 if (e->external_advertise) in remove_record()
1303 external_stop_advertising_service(&e->rr->resrec); in remove_record()
1304 e->external_advertise = mDNSfalse; in remove_record()
1306 …err = mDNS_Deregister(&mDNSStorage, e->rr); // Will free e->rr for us; we're responsible for free… in remove_record()
1310 freeL("registered_record_entry AuthRecord remove_record", e->rr); in remove_record()
1322 for (ptr = serv->srs.Extras; ptr; ptr = ptr->next) in remove_extra()
1324 if (ptr->ClientID == request->hdr.reg_index) // found match in remove_extra()
1326 *rrtype = ptr->r.resrec.rrtype; in remove_extra()
1327 if (serv->external_advertise) external_stop_advertising_service(&ptr->r.resrec); in remove_extra()
1328 err = mDNS_RemoveRecordFromService(&mDNSStorage, &serv->srs, ptr, FreeExtraRR, ptr); in remove_extra()
1338 get_flags(&request->msgptr, request->msgend); // flags unused in handle_removerecord_request()
1340 …if (!request->msgptr) { LogMsg("%3d: DNSServiceRemoveRecord(unreadable parameters)", request->sd);… in handle_removerecord_request()
1343 if (request->terminate == connection_termination) request = LocateSubordinateRequest(request); in handle_removerecord_request()
1345 if (request->terminate == connection_termination) in handle_removerecord_request()
1347 else if (request->terminate != regservice_termination_callback) in handle_removerecord_request()
1348 …{ LogMsg("%3d: DNSServiceRemoveRecord(not a registered service ref)", request->sd); return(mStatus… in handle_removerecord_request()
1353 LogOperation("%3d: DNSServiceRemoveRecord(%##s, %s)", request->sd, in handle_removerecord_request()
1354 …(request->u.servicereg.instances) ? request->u.servicereg.instances->srs.RR_SRV.resrec.name->c : N… in handle_removerecord_request()
1356 for (i = request->u.servicereg.instances; i; i = i->next) in handle_removerecord_request()
1359 if (err && i->default_local) break; in handle_removerecord_request()
1360 else err = mStatus_NoError; // suppress non-local default errors in handle_removerecord_request()
1403 // Returns -1 if illegal subtype found
1410 if (*stp == ',') return(-1); in ChopSubTypes()
1414 if (!stp) return(-1); in ChopSubTypes()
1441 …const int extra_size = (request->u.servicereg.txtlen > sizeof(RDataBody)) ? (request->u.servicereg… in register_service_instance()
1444 mDNSInterfaceID interfaceID = request->u.servicereg.InterfaceID; in register_service_instance()
1452 else if (request->flags & kDNSServiceFlagsIncludeP2P) in register_service_instance()
1456 if (request->flags & kDNSServiceFlagsForce) in register_service_instance()
1460 …// registration but for the wide-area registrations we don't (currently) have any concept of a wid… in register_service_instance()
1462 // (Specifying an interface with an apparently wide-area domain (i.e. something other than "local") in register_service_instance()
1463 …// currently forces the registration to use mDNS multicast despite the apparently wide-area domain… in register_service_instance()
1464 if (request->u.servicereg.default_domain && !DomainIsLocal) interfaceID = mDNSInterface_Any; in register_service_instance()
1466 for (ptr = &request->u.servicereg.instances; *ptr; ptr = &(*ptr)->next) in register_service_instance()
1468 if (SameDomainName(&(*ptr)->domain, domain)) in register_service_instance()
1471 domain->c, &request->u.servicereg.name, &request->u.servicereg.type); in register_service_instance()
1478 …// Special-case hack: On Mac OS X 10.6.x and earlier we don't advertise SMB service in AutoTunnel … in register_service_instance()
1481 if (SameDomainName(&request->u.servicereg.type, (const domainname *) "\x4" "_smb" "\x4" "_tcp")) in register_service_instance()
1484 if (AuthInfo && AuthInfo->AutoTunnel) return(kDNSServiceErr_Unsupported); in register_service_instance()
1491 instance->next = mDNSNULL; in register_service_instance()
1492 instance->request = request; in register_service_instance()
1493 …instance->subtypes = AllocateSubTypes(request->u.servicereg.num_subtypes, request->u.servicer… in register_service_instance()
1494 instance->renameonmemfree = 0; in register_service_instance()
1495 instance->clientnotified = mDNSfalse; in register_service_instance()
1496 instance->default_local = (request->u.servicereg.default_domain && DomainIsLocal); in register_service_instance()
1497 instance->external_advertise = mDNSfalse; in register_service_instance()
1498 AssignDomainName(&instance->domain, domain); in register_service_instance()
1500 if (request->u.servicereg.num_subtypes && !instance->subtypes) in register_service_instance()
1503 result = mDNS_RegisterService(&mDNSStorage, &instance->srs, in register_service_instance()
1504 &request->u.servicereg.name, &request->u.servicereg.type, domain, in register_service_instance()
1505 request->u.servicereg.host.c[0] ? &request->u.servicereg.host : NULL, in register_service_instance()
1506 request->u.servicereg.port, in register_service_instance()
1507 request->u.servicereg.txtdata, request->u.servicereg.txtlen, in register_service_instance()
1508 instance->subtypes, request->u.servicereg.num_subtypes, in register_service_instance()
1513 *ptr = instance; // Append this to the end of our request->u.servicereg.instances list in register_service_instance()
1515 …instance->request->sd, instance->srs.RR_SRV.resrec.name->c, mDNSVal16(request->u.servicereg.port)); in register_service_instance()
1520 &request->u.servicereg.name, &request->u.servicereg.type, domain->c, result); in register_service_instance()
1532 machserver_automatic_registration_domain_changed(&d->name, add); in udsserver_default_reg_domain_changed()
1535 LogMsg("%s registration domain %##s", add ? "Adding" : "Removing", d->name.c); in udsserver_default_reg_domain_changed()
1536 for (request = all_requests; request; request = request->next) in udsserver_default_reg_domain_changed()
1538 if (request->terminate != regservice_termination_callback) continue; in udsserver_default_reg_domain_changed()
1539 if (!request->u.servicereg.default_domain) continue; in udsserver_default_reg_domain_changed()
1540 if (!d->uid || SystemUID(request->uid) || request->uid == d->uid) in udsserver_default_reg_domain_changed()
1542 service_instance **ptr = &request->u.servicereg.instances; in udsserver_default_reg_domain_changed()
1543 while (*ptr && !SameDomainName(&(*ptr)->domain, &d->name)) ptr = &(*ptr)->next; in udsserver_default_reg_domain_changed()
1547 if (!*ptr) register_service_instance(request, &d->name); in udsserver_default_reg_domain_changed()
1548 … else debugf("udsserver_default_reg_domain_changed %##s already in list, not re-adding", &d->name); in udsserver_default_reg_domain_changed()
1557 &d->name, request->u.servicereg.name.c, request->u.servicereg.type_as_string); in udsserver_default_reg_domain_changed()
1561 for (p = AutoRegistrationDomains; p; p=p->next) in udsserver_default_reg_domain_changed()
1562 if (!p->uid || SystemUID(request->uid) || request->uid == p->uid) in udsserver_default_reg_domain_changed()
1563 if (SameDomainName(&d->name, &p->name)) break; in udsserver_default_reg_domain_changed()
1564 … if (p) debugf("udsserver_default_reg_domain_changed %##s still in list, not removing", &d->name); in udsserver_default_reg_domain_changed()
1569 *ptr = si->next; in udsserver_default_reg_domain_changed()
1570 …if (si->clientnotified) SendServiceRemovalNotification(&si->srs); // Do this *before* clearing si-… in udsserver_default_reg_domain_changed()
1571 …// Now that we've cut this service_instance from the list, we MUST clear the si->request backpoint… in udsserver_default_reg_domain_changed()
1579 …// a service_instance with a stale si->request backpointer pointing to memory that's already been … in udsserver_default_reg_domain_changed()
1580 si->request = NULL; in udsserver_default_reg_domain_changed()
1581 err = mDNS_DeregisterService(&mDNSStorage, &si->srs); in udsserver_default_reg_domain_changed()
1592 …char name[256]; // Lots of spare space for extra-long names that we'll auto-truncate down to 63 by… in handle_regservice_request()
1595 domainname d, srv; in handle_regservice_request() local
1599 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend); in handle_regservice_request()
1600 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend); in handle_regservice_request()
1603 …{ LogMsg("ERROR: handle_regservice_request - Couldn't find interfaceIndex %d", interfaceIndex); re… in handle_regservice_request()
1605 if (get_string(&request->msgptr, request->msgend, name, sizeof(name)) < 0 || in handle_regservice_request()
1606 get_string(&request->msgptr, request->msgend, type_as_string, MAX_ESCAPED_DOMAIN_NAME) < 0 || in handle_regservice_request()
1607 get_string(&request->msgptr, request->msgend, domain, MAX_ESCAPED_DOMAIN_NAME) < 0 || in handle_regservice_request()
1608 get_string(&request->msgptr, request->msgend, host, MAX_ESCAPED_DOMAIN_NAME) < 0) in handle_regservice_request()
1609 …{ LogMsg("ERROR: handle_regservice_request - Couldn't read name/regtype/domain"); return(mStatus_B… in handle_regservice_request()
1611 request->flags = flags; in handle_regservice_request()
1612 request->u.servicereg.InterfaceID = InterfaceID; in handle_regservice_request()
1613 request->u.servicereg.instances = NULL; in handle_regservice_request()
1614 request->u.servicereg.txtlen = 0; in handle_regservice_request()
1615 request->u.servicereg.txtdata = NULL; in handle_regservice_request()
1616 …mDNSPlatformStrLCopy(request->u.servicereg.type_as_string, type_as_string, sizeof(request->u.servi… in handle_regservice_request()
1618 if (request->msgptr + 2 > request->msgend) request->msgptr = NULL; in handle_regservice_request()
1621 request->u.servicereg.port.b[0] = *request->msgptr++; in handle_regservice_request()
1622 request->u.servicereg.port.b[1] = *request->msgptr++; in handle_regservice_request()
1625 request->u.servicereg.txtlen = get_uint16(&request->msgptr, request->msgend); in handle_regservice_request()
1626 msgTXTData = get_rdata(&request->msgptr, request->msgend, request->u.servicereg.txtlen); in handle_regservice_request()
1627 if (!request->msgptr) in handle_regservice_request()
1629 LogMsg("%3d: DNSServiceRegister(unreadable parameters)", request->sd); in handle_regservice_request()
1633 if (request->u.servicereg.txtlen) in handle_regservice_request()
1635 request->u.servicereg.txtdata = mallocL("service_info txtdata", request->u.servicereg.txtlen); in handle_regservice_request()
1636 if (!request->u.servicereg.txtdata) FatalError("ERROR: handle_regservice_request - malloc"); in handle_regservice_request()
1637 mDNSPlatformMemCopy(request->u.servicereg.txtdata, msgTXTData, request->u.servicereg.txtlen); in handle_regservice_request()
1640 // Check for sub-types after the service type in handle_regservice_request()
1641 …request->u.servicereg.num_subtypes = ChopSubTypes(request->u.servicereg.type_as_string); // Note: … in handle_regservice_request()
1642 if (request->u.servicereg.num_subtypes < 0) in handle_regservice_request()
1643 …{ LogMsg("ERROR: handle_regservice_request - ChopSubTypes failed %s", request->u.servicereg.type_a… in handle_regservice_request()
1646 …if (!*request->u.servicereg.type_as_string || !MakeDomainNameFromDNSNameString(&request->u.service… in handle_regservice_request()
1647 …{ LogMsg("ERROR: handle_regservice_request - type_as_string bad %s", request->u.servicereg.type_as… in handle_regservice_request()
1651 request->u.servicereg.name = mDNSStorage.nicelabel; in handle_regservice_request()
1652 request->u.servicereg.autoname = mDNStrue; in handle_regservice_request()
1662 if (!MakeDomainLabelFromLiteralString(&request->u.servicereg.name, name)) in handle_regservice_request()
1663 { LogMsg("ERROR: handle_regservice_request - name bad %s", name); return(mStatus_BadParamErr); } in handle_regservice_request()
1664 request->u.servicereg.autoname = mDNSfalse; in handle_regservice_request()
1669 request->u.servicereg.default_domain = mDNSfalse; in handle_regservice_request()
1671 …{ LogMsg("ERROR: handle_regservice_request - domain bad %s", domain); return(mStatus_BadParamErr);… in handle_regservice_request()
1675 request->u.servicereg.default_domain = mDNStrue; in handle_regservice_request()
1679 if (!ConstructServiceName(&srv, &request->u.servicereg.name, &request->u.servicereg.type, &d)) in handle_regservice_request()
1681 …LogMsg("ERROR: handle_regservice_request - Couldn't ConstructServiceName from, “%#s” “%##s” “%##s”… in handle_regservice_request()
1682 request->u.servicereg.name.c, request->u.servicereg.type.c, d.c); return(mStatus_BadParamErr); in handle_regservice_request()
1685 if (!MakeDomainNameFromDNSNameString(&request->u.servicereg.host, host)) in handle_regservice_request()
1686 { LogMsg("ERROR: handle_regservice_request - host bad %s", host); return(mStatus_BadParamErr); } in handle_regservice_request()
1687 request->u.servicereg.autorename = (flags & kDNSServiceFlagsNoAutoRename ) == 0; in handle_regservice_request()
1688 request->u.servicereg.allowremotequery = (flags & kDNSServiceFlagsAllowRemoteQuery) != 0; in handle_regservice_request()
1690 // Some clients use mDNS for lightweight copy protection, registering a pseudo-service with in handle_regservice_request()
1693 if (!mDNSIPPortIsZero(request->u.servicereg.port)) in handle_regservice_request()
1695 int count = CountExistingRegistrations(&srv, request->u.servicereg.port); in handle_regservice_request()
1698 count+1, srv.c, mDNSVal16(request->u.servicereg.port)); in handle_regservice_request()
1702 …request->sd, flags, interfaceIndex, name, request->u.servicereg.type_as_string, domain, host, mDNS… in handle_regservice_request()
1704 // We need to unconditionally set request->terminate, because even if we didn't successfully in handle_regservice_request()
1707 // We also need to set request->terminate first, before adding additional service instances, in handle_regservice_request()
1708 // because the uds_validatelists uses the request->terminate function pointer to determine in handle_regservice_request()
1710 request->terminate = regservice_termination_callback; in handle_regservice_request()
1719 if (request->u.servicereg.autoname) UpdateDeviceInfoRecord(&mDNSStorage); in handle_regservice_request()
1724 // Note that we don't report errors for non-local, non-explicit domains in handle_regservice_request()
1725 for (ptr = AutoRegistrationDomains; ptr; ptr = ptr->next) in handle_regservice_request()
1726 if (!ptr->uid || SystemUID(request->uid) || request->uid == ptr->uid) in handle_regservice_request()
1727 register_service_instance(request, &ptr->name); in handle_regservice_request()
1736 #pragma mark -
1737 #pragma mark - DNSServiceBrowse
1743 request_state *req = question->QuestionContext; in FoundInstance()
1747 if (answer->rrtype != kDNSType_PTR) in FoundInstance()
1748 …Instance: Should not be called with rrtype %d (not a PTR record)", req->sd, answer->rrtype); retur… in FoundInstance()
1750 …if (GenerateNTDResponse(&answer->rdata->u.name, answer->InterfaceID, req, &rep, browse_reply_op, f… in FoundInstance()
1752 …if (SameDomainName(&req->u.browser.regtype, (const domainname*)"\x09_services\x07_dns-sd\x04_udp")) in FoundInstance()
1756 …GenerateBonjourBrowserResponse(&answer->rdata->u.name, answer->InterfaceID, req, &rep, browse_repl… in FoundInstance()
1760 …LogMsg("%3d: FoundInstance: %##s PTR %##s received from network is not valid DNS-SD service pointe… in FoundInstance()
1761 req->sd, answer->name->c, answer->rdata->u.name.c); in FoundInstance()
1768 req->sd, question->qname.c, DNSTypeName(question->qtype), AddRecord ? "Add" : "Rmv", in FoundInstance()
1769 …mDNSPlatformInterfaceIndexfromInterfaceID(m, answer->InterfaceID, mDNSfalse), RRDisplayString(m, a… in FoundInstance()
1779 for (p = info->u.browser.browsers; p; p = p->next) in add_domain_to_browser()
1781 if (SameDomainName(&p->domain, d)) in add_domain_to_browser()
1782 { debugf("add_domain_to_browser %##s already in list", d->c); return mStatus_AlreadyRegistered; } in add_domain_to_browser()
1787 AssignDomainName(&b->domain, d); in add_domain_to_browser()
1788 err = mDNS_StartBrowse(&mDNSStorage, &b->q, in add_domain_to_browser()
1789 …&info->u.browser.regtype, d, info->u.browser.interface_id, info->u.browser.ForceMCast, FoundInstan… in add_domain_to_browser()
1792 …sg("mDNS_StartBrowse returned %d for type %##s domain %##s", err, info->u.browser.regtype.c, d->c); in add_domain_to_browser()
1797 b->next = info->u.browser.browsers; in add_domain_to_browser()
1798 info->u.browser.browsers = b; in add_domain_to_browser()
1799 LogOperation("%3d: DNSServiceBrowse(%##s) START", info->sd, b->q.qname.c); in add_domain_to_browser()
1800 …if (info->u.browser.interface_id == mDNSInterface_P2P || (!info->u.browser.interface_id && SameDom… in add_domain_to_browser()
1803 ConstructServiceName(&tmp, NULL, &info->u.browser.regtype, &b->domain); in add_domain_to_browser()
1813 while (info->u.browser.browsers) in browse_termination_callback()
1815 browser_t *ptr = info->u.browser.browsers; in browse_termination_callback()
1817 …if (info->u.browser.interface_id == mDNSInterface_P2P || (!info->u.browser.interface_id && SameDom… in browse_termination_callback()
1820 ConstructServiceName(&tmp, NULL, &info->u.browser.regtype, &ptr->domain); in browse_termination_callback()
1825 info->u.browser.browsers = ptr->next; in browse_termination_callback()
1826 LogOperation("%3d: DNSServiceBrowse(%##s) STOP", info->sd, ptr->q.qname.c); in browse_termination_callback()
1827 mDNS_StopBrowse(&mDNSStorage, &ptr->q); // no need to error-check result in browse_termination_callback()
1835 …tic_browse_domain_changed: %s default browse domain %##s", add ? "Adding" : "Removing", d->name.c); in udsserver_automatic_browse_domain_changed()
1838 machserver_automatic_browse_domain_changed(&d->name, add); in udsserver_automatic_browse_domain_changed()
1841 for (request = all_requests; request; request = request->next) in udsserver_automatic_browse_domain_changed()
1843 if (request->terminate != browse_termination_callback) continue; // Not a browse operation in udsserver_automatic_browse_domain_changed()
1844 if (!request->u.browser.default_domain) continue; // Not an auto-browse operation in udsserver_automatic_browse_domain_changed()
1845 if (!d->uid || SystemUID(request->uid) || request->uid == d->uid) in udsserver_automatic_browse_domain_changed()
1847 browser_t **ptr = &request->u.browser.browsers; in udsserver_automatic_browse_domain_changed()
1848 while (*ptr && !SameDomainName(&(*ptr)->domain, &d->name)) ptr = &(*ptr)->next; in udsserver_automatic_browse_domain_changed()
1852 if (!*ptr) add_domain_to_browser(request, &d->name); in udsserver_automatic_browse_domain_changed()
1853 … debugf("udsserver_automatic_browse_domain_changed %##s already in list, not re-adding", &d->name); in udsserver_automatic_browse_domain_changed()
1857 if (!*ptr) LogMsg("udsserver_automatic_browse_domain_changed ERROR %##s not found", &d->name); in udsserver_automatic_browse_domain_changed()
1861 for (p = AutoBrowseDomains; p; p=p->next) in udsserver_automatic_browse_domain_changed()
1862 if (!p->uid || SystemUID(request->uid) || request->uid == p->uid) in udsserver_automatic_browse_domain_changed()
1863 if (SameDomainName(&d->name, &p->name)) break; in udsserver_automatic_browse_domain_changed()
1864 …(p) debugf("udsserver_automatic_browse_domain_changed %##s still in list, not removing", &d->name); in udsserver_automatic_browse_domain_changed()
1868 *ptr = (*ptr)->next; in udsserver_automatic_browse_domain_changed()
1869 mDNS_StopQueryWithRemoves(&mDNSStorage, &rem->q); in udsserver_automatic_browse_domain_changed()
1890 while (*ptr && &(*ptr)->ar != rr) ptr = &(*ptr)->next; in FreeARElemCallback()
1891 …if (*ptr) { *ptr = (*ptr)->next; LogMsg("FreeARElemCallback: Have to cut %s", ARDisplayString(m, r… in FreeARElemCallback()
1892 mDNSPlatformMemFree(rr->RecordContext); in FreeARElemCallback()
1902 // allocate/register legacy and non-legacy _browse PTR record in RegisterLocalOnlyDomainEnumPTR()
1909 (type == mDNS_DomainTypeBrowseAutomatic) ? "automatic browse" : "?", d->c); in RegisterLocalOnlyDomainEnumPTR()
1911 …mDNS_SetupResourceRecord(&ptr->ar, mDNSNULL, mDNSInterface_LocalOnly, kDNSType_PTR, 7200, kDNSReco… in RegisterLocalOnlyDomainEnumPTR()
1912 MakeDomainNameFromDNSNameString(&ptr->ar.namestorage, mDNS_DomainTypeNames[type]); in RegisterLocalOnlyDomainEnumPTR()
1913 AppendDNSNameString (&ptr->ar.namestorage, "local"); in RegisterLocalOnlyDomainEnumPTR()
1914 AssignDomainName(&ptr->ar.resrec.rdata->u.name, d); in RegisterLocalOnlyDomainEnumPTR()
1915 err = mDNS_Register(m, &ptr->ar); in RegisterLocalOnlyDomainEnumPTR()
1923 ptr->next = LocalDomainEnumRecords; in RegisterLocalOnlyDomainEnumPTR()
1931 domainname lhs; // left-hand side of PTR, for comparison in DeregisterLocalOnlyDomainEnumPTR()
1936 (type == mDNS_DomainTypeBrowseAutomatic) ? "automatic browse" : "?", d->c); in DeregisterLocalOnlyDomainEnumPTR()
1943 …if (SameDomainName(&(*ptr)->ar.resrec.rdata->u.name, d) && SameDomainName((*ptr)->ar.resrec.name, … in DeregisterLocalOnlyDomainEnumPTR()
1946 *ptr = (*ptr)->next; in DeregisterLocalOnlyDomainEnumPTR()
1947 mDNS_Deregister(m, &rem->ar); in DeregisterLocalOnlyDomainEnumPTR()
1950 else ptr = &(*ptr)->next; in DeregisterLocalOnlyDomainEnumPTR()
1958 AssignDomainName(&new->name, name); in AddAutoBrowseDomain()
1959 new->uid = uid; in AddAutoBrowseDomain()
1960 new->next = AutoBrowseDomains; in AddAutoBrowseDomain()
1968 while (*p && (!SameDomainName(&(*p)->name, name) || (*p)->uid != uid)) p = &(*p)->next; in RmvAutoBrowseDomain()
1969 if (!*p) LogMsg("RmvAutoBrowseDomain: Got remove event for domain %##s not in list", name->c); in RmvAutoBrowseDomain()
1973 *p = ptr->next; in RmvAutoBrowseDomain()
1982 for (d = browseDomains; d; d = d->next) in SetPrefsBrowseDomains()
1986 RegisterLocalOnlyDomainEnumPTR(m, &d->name, mDNS_DomainTypeBrowse); in SetPrefsBrowseDomains()
1987 AddAutoBrowseDomain(d->uid, &d->name); in SetPrefsBrowseDomains()
1991 DeregisterLocalOnlyDomainEnumPTR(m, &d->name, mDNS_DomainTypeBrowse); in SetPrefsBrowseDomains()
1992 RmvAutoBrowseDomain(d->uid, &d->name); in SetPrefsBrowseDomains()
2001 for (req = all_requests; req; req = req->next) in UpdateDeviceInfoRecord()
2002 if (req->terminate == regservice_termination_callback && req->u.servicereg.autoname) in UpdateDeviceInfoRecord()
2006 if (m->DeviceInfo.resrec.RecordType != kDNSRecordTypeUnregistered) in UpdateDeviceInfoRecord()
2007 if (num_autoname == 0 || !SameDomainLabelCS(m->DeviceInfo.resrec.name->c, m->nicelabel.c)) in UpdateDeviceInfoRecord()
2009 LogOperation("UpdateDeviceInfoRecord Deregister %##s", m->DeviceInfo.resrec.name); in UpdateDeviceInfoRecord()
2010 mDNS_Deregister(m, &m->DeviceInfo); in UpdateDeviceInfoRecord()
2014 if (m->DeviceInfo.resrec.RecordType == kDNSRecordTypeUnregistered) in UpdateDeviceInfoRecord()
2017 mDNSu8 len = m->HIHardware.c[0] < 255 - 6 ? m->HIHardware.c[0] : 255 - 6; in UpdateDeviceInfoRecord()
2018 …mDNS_SetupResourceRecord(&m->DeviceInfo, mDNSNULL, mDNSNULL, kDNSType_TXT, kStandardTTL, kDNSRecor… in UpdateDeviceInfoRecord()
2019 ConstructServiceName(&m->DeviceInfo.namestorage, &m->nicelabel, &DeviceInfoName, &localdomain); in UpdateDeviceInfoRecord()
2020 mDNSPlatformMemCopy(m->DeviceInfo.resrec.rdata->u.data + 1, "model=", 6); in UpdateDeviceInfoRecord()
2021 mDNSPlatformMemCopy(m->DeviceInfo.resrec.rdata->u.data + 7, m->HIHardware.c + 1, len); in UpdateDeviceInfoRecord()
2022 m->DeviceInfo.resrec.rdata->u.data[0] = 6 + len; // "model=" plus the device string in UpdateDeviceInfoRecord()
2023 …m->DeviceInfo.resrec.rdlength = 7 + len; // One extra for the length byte at the start of … in UpdateDeviceInfoRecord()
2024 LogOperation("UpdateDeviceInfoRecord Register %##s", m->DeviceInfo.resrec.name); in UpdateDeviceInfoRecord()
2025 mDNS_Register(m, &m->DeviceInfo); in UpdateDeviceInfoRecord()
2040 for (req = all_requests; req; req = req->next) in udsserver_handle_configchange()
2041 if (req->terminate == regservice_termination_callback) in udsserver_handle_configchange()
2042 if (req->u.servicereg.autoname && !SameDomainLabelCS(req->u.servicereg.name.c, m->nicelabel.c)) in udsserver_handle_configchange()
2044 req->u.servicereg.name = m->nicelabel; in udsserver_handle_configchange()
2045 for (ptr = req->u.servicereg.instances; ptr; ptr = ptr->next) in udsserver_handle_configchange()
2047 ptr->renameonmemfree = 1; in udsserver_handle_configchange()
2048 if (ptr->clientnotified) SendServiceRemovalNotification(&ptr->srs); in udsserver_handle_configchange()
2049 …sserver_handle_configchange: Calling deregister for Service %##s", ptr->srs.RR_PTR.resrec.name->c); in udsserver_handle_configchange()
2050 if (mDNS_DeregisterService_drt(m, &ptr->srs, mDNS_Dereg_rapid)) in udsserver_handle_configchange()
2051 …regservice_callback(m, &ptr->srs, mStatus_MemFree); // If service deregistered already, we can re-… in udsserver_handle_configchange()
2065 for (p=RegDomains; p; p=p->next) in udsserver_handle_configchange()
2068 …while (*pp && ((*pp)->uid != p->uid || !SameDomainName(&(*pp)->name, &p->name))) pp = &(*pp)->next; in udsserver_handle_configchange()
2071 RegisterLocalOnlyDomainEnumPTR(m, &p->name, mDNS_DomainTypeRegistration); in udsserver_handle_configchange()
2077 *pp = (*pp)->next; in udsserver_handle_configchange()
2086 AutoRegistrationDomains = AutoRegistrationDomains->next; // Cut record from list FIRST, in udsserver_handle_configchange()
2087 DeregisterLocalOnlyDomainEnumPTR(m, &del->name, mDNS_DomainTypeRegistration); in udsserver_handle_configchange()
2105 SCPrefBrowseDomains = SCPrefBrowseDomains->next; in udsserver_handle_configchange()
2120 AddRecord ? "Adding" : "Removing", answer->rdata->u.name.c); in AutomaticBrowseDomainChange()
2122 if (AddRecord) AddAutoBrowseDomain(0, &answer->rdata->u.name); in AutomaticBrowseDomainChange()
2123 else RmvAutoBrowseDomain(0, &answer->rdata->u.name); in AutomaticBrowseDomainChange()
2128 get_flags(&request->msgptr, request->msgend); in handle_sethost_request()
2131 if (get_string(&request->msgptr, request->msgend, hostName, in handle_sethost_request()
2134 request->sd, request->flags); in handle_sethost_request()
2137 // request->terminate = sethost_termination_callback; in handle_sethost_request()
2156 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend); in handle_browse_request()
2157 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend); in handle_browse_request()
2161 if (get_string(&request->msgptr, request->msgend, regtype, MAX_ESCAPED_DOMAIN_NAME) < 0 || in handle_browse_request()
2162 …get_string(&request->msgptr, request->msgend, domain, MAX_ESCAPED_DOMAIN_NAME) < 0) return(mStatus… in handle_browse_request()
2164 …if (!request->msgptr) { LogMsg("%3d: DNSServiceBrowse(unreadable parameters)", request->sd); retur… in handle_browse_request()
2168 request->flags = flags; in handle_browse_request()
2177 // For over-long service types, we only allow domain "local" in handle_browse_request()
2181 request->u.browser.ForceMCast = (flags & kDNSServiceFlagsForceMulticast) != 0; in handle_browse_request()
2182 request->u.browser.interface_id = InterfaceID; in handle_browse_request()
2183 AssignDomainName(&request->u.browser.regtype, &typedn); in handle_browse_request()
2184 request->u.browser.default_domain = !domain[0]; in handle_browse_request()
2185 request->u.browser.browsers = NULL; in handle_browse_request()
2188 request->sd, request->flags, interfaceIndex, request->u.browser.regtype.c, domain); in handle_browse_request()
2190 // We need to unconditionally set request->terminate, because even if we didn't successfully in handle_browse_request()
2193 request->terminate = browse_termination_callback; in handle_browse_request()
2206 for (sdom = AutoBrowseDomains; sdom; sdom = sdom->next) in handle_browse_request()
2207 if (!sdom->uid || SystemUID(request->uid) || request->uid == sdom->uid) in handle_browse_request()
2209 err = add_domain_to_browser(request, &sdom->name); in handle_browse_request()
2212 if (SameDomainName(&sdom->name, &localdomain)) break; in handle_browse_request()
2213 else err = mStatus_NoError; // suppress errors for non-local "default" domains in handle_browse_request()
2223 #pragma mark -
2224 #pragma mark - DNSServiceResolve
2230 char fullname[MAX_ESCAPED_DOMAIN_NAME], target[MAX_ESCAPED_DOMAIN_NAME]; in resolve_result_callback() local
2233 request_state *req = question->QuestionContext; in resolve_result_callback()
2236 …LogOperation("%3d: DNSServiceResolve(%##s) %s %s", req->sd, question->qname.c, AddRecord ? "ADD" :… in resolve_result_callback()
2240 if (req->u.resolve.srv == answer) req->u.resolve.srv = mDNSNULL; in resolve_result_callback()
2241 if (req->u.resolve.txt == answer) req->u.resolve.txt = mDNSNULL; in resolve_result_callback()
2245 if (answer->rrtype == kDNSType_SRV) req->u.resolve.srv = answer; in resolve_result_callback()
2246 if (answer->rrtype == kDNSType_TXT) req->u.resolve.txt = answer; in resolve_result_callback()
2248 …if (!req->u.resolve.txt || !req->u.resolve.srv) return; // only deliver result to client if we ha… in resolve_result_callback()
2250 ConvertDomainNameToCString(answer->name, fullname); in resolve_result_callback()
2251 ConvertDomainNameToCString(&req->u.resolve.srv->rdata->u.srv.target, target); in resolve_result_callback()
2258 len += strlen(target) + 1; in resolve_result_callback()
2260 len += req->u.resolve.txt->rdlength; in resolve_result_callback()
2264 rep->rhdr->flags = dnssd_htonl(0); in resolve_result_callback()
2265 …rep->rhdr->ifi = dnssd_htonl(mDNSPlatformInterfaceIndexfromInterfaceID(m, answer->InterfaceID, m… in resolve_result_callback()
2266 rep->rhdr->error = dnssd_htonl(kDNSServiceErr_NoError); in resolve_result_callback()
2268 data = (char *)&rep->rhdr[1]; in resolve_result_callback()
2272 put_string(target, &data); in resolve_result_callback()
2273 *data++ = req->u.resolve.srv->rdata->u.srv.port.b[0]; in resolve_result_callback()
2274 *data++ = req->u.resolve.srv->rdata->u.srv.port.b[1]; in resolve_result_callback()
2275 put_uint16(req->u.resolve.txt->rdlength, &data); in resolve_result_callback()
2276 put_rdata (req->u.resolve.txt->rdlength, req->u.resolve.txt->rdata->u.data, &data); in resolve_result_callback()
2278 … DNSServiceResolve(%s) RESULT %s:%d", req->sd, fullname, target, mDNSVal16(req->u.resolve.srv->r… in resolve_result_callback()
2284 LogOperation("%3d: DNSServiceResolve(%##s) STOP", request->sd, request->u.resolve.qtxt.qname.c); in resolve_termination_callback()
2285 mDNS_StopQuery(&mDNSStorage, &request->u.resolve.qtxt); in resolve_termination_callback()
2286 mDNS_StopQuery(&mDNSStorage, &request->u.resolve.qsrv); in resolve_termination_callback()
2287 …if (request->u.resolve.external_advertise) external_stop_resolving_service(&request->u.resolve.qsr… in resolve_termination_callback()
2297 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend); in handle_resolve_request()
2298 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend); in handle_resolve_request()
2303 request->flags = flags; in handle_resolve_request()
2310 if (get_string(&request->msgptr, request->msgend, name, 256) < 0 || in handle_resolve_request()
2311 get_string(&request->msgptr, request->msgend, regtype, MAX_ESCAPED_DOMAIN_NAME) < 0 || in handle_resolve_request()
2312 get_string(&request->msgptr, request->msgend, domain, MAX_ESCAPED_DOMAIN_NAME) < 0) in handle_resolve_request()
2313 …{ LogMsg("ERROR: handle_resolve_request - Couldn't read name/regtype/domain"); return(mStatus_BadP… in handle_resolve_request()
2315 …if (!request->msgptr) { LogMsg("%3d: DNSServiceResolve(unreadable parameters)", request->sd); retu… in handle_resolve_request()
2320 mDNSPlatformMemZero(&request->u.resolve, sizeof(request->u.resolve)); in handle_resolve_request()
2323 request->u.resolve.qsrv.InterfaceID = InterfaceID; in handle_resolve_request()
2324 request->u.resolve.qsrv.Target = zeroAddr; in handle_resolve_request()
2325 AssignDomainName(&request->u.resolve.qsrv.qname, &fqdn); in handle_resolve_request()
2326 request->u.resolve.qsrv.qtype = kDNSType_SRV; in handle_resolve_request()
2327 request->u.resolve.qsrv.qclass = kDNSClass_IN; in handle_resolve_request()
2328 request->u.resolve.qsrv.LongLived = (flags & kDNSServiceFlagsLongLivedQuery ) != 0; in handle_resolve_request()
2329 request->u.resolve.qsrv.ExpectUnique = mDNStrue; in handle_resolve_request()
2330 request->u.resolve.qsrv.ForceMCast = (flags & kDNSServiceFlagsForceMulticast ) != 0; in handle_resolve_request()
2331 request->u.resolve.qsrv.ReturnIntermed = (flags & kDNSServiceFlagsReturnIntermediates) != 0; in handle_resolve_request()
2332 request->u.resolve.qsrv.SuppressUnusable = mDNSfalse; in handle_resolve_request()
2333 request->u.resolve.qsrv.SearchListIndex = 0; in handle_resolve_request()
2334 request->u.resolve.qsrv.AppendSearchDomains = 0; in handle_resolve_request()
2335 request->u.resolve.qsrv.RetryWithSearchDomains = mDNSfalse; in handle_resolve_request()
2336 request->u.resolve.qsrv.TimeoutQuestion = 0; in handle_resolve_request()
2337 request->u.resolve.qsrv.WakeOnResolve = (flags & kDNSServiceFlagsWakeOnResolve) != 0; in handle_resolve_request()
2338 request->u.resolve.qsrv.qnameOrig = mDNSNULL; in handle_resolve_request()
2339 request->u.resolve.qsrv.QuestionCallback = resolve_result_callback; in handle_resolve_request()
2340 request->u.resolve.qsrv.QuestionContext = request; in handle_resolve_request()
2342 request->u.resolve.qtxt.InterfaceID = InterfaceID; in handle_resolve_request()
2343 request->u.resolve.qtxt.Target = zeroAddr; in handle_resolve_request()
2344 AssignDomainName(&request->u.resolve.qtxt.qname, &fqdn); in handle_resolve_request()
2345 request->u.resolve.qtxt.qtype = kDNSType_TXT; in handle_resolve_request()
2346 request->u.resolve.qtxt.qclass = kDNSClass_IN; in handle_resolve_request()
2347 request->u.resolve.qtxt.LongLived = (flags & kDNSServiceFlagsLongLivedQuery ) != 0; in handle_resolve_request()
2348 request->u.resolve.qtxt.ExpectUnique = mDNStrue; in handle_resolve_request()
2349 request->u.resolve.qtxt.ForceMCast = (flags & kDNSServiceFlagsForceMulticast ) != 0; in handle_resolve_request()
2350 request->u.resolve.qtxt.ReturnIntermed = (flags & kDNSServiceFlagsReturnIntermediates) != 0; in handle_resolve_request()
2351 request->u.resolve.qtxt.SuppressUnusable = mDNSfalse; in handle_resolve_request()
2352 request->u.resolve.qtxt.SearchListIndex = 0; in handle_resolve_request()
2353 request->u.resolve.qtxt.AppendSearchDomains = 0; in handle_resolve_request()
2354 request->u.resolve.qtxt.RetryWithSearchDomains = mDNSfalse; in handle_resolve_request()
2355 request->u.resolve.qtxt.TimeoutQuestion = 0; in handle_resolve_request()
2356 request->u.resolve.qtxt.WakeOnResolve = 0; in handle_resolve_request()
2357 request->u.resolve.qtxt.qnameOrig = mDNSNULL; in handle_resolve_request()
2358 request->u.resolve.qtxt.QuestionCallback = resolve_result_callback; in handle_resolve_request()
2359 request->u.resolve.qtxt.QuestionContext = request; in handle_resolve_request()
2361 …request->u.resolve.ReportTime = NonZeroTime(mDNS_TimeNow(&mDNSStorage) + 130 * mDNSPlat… in handle_resolve_request()
2363 request->u.resolve.external_advertise = mDNSfalse; in handle_resolve_request()
2370 LogOperation("%3d: DNSServiceResolve(%##s) START", request->sd, request->u.resolve.qsrv.qname.c); in handle_resolve_request()
2371 err = mDNS_StartQuery(&mDNSStorage, &request->u.resolve.qsrv); in handle_resolve_request()
2374 err = mDNS_StartQuery(&mDNSStorage, &request->u.resolve.qtxt); in handle_resolve_request()
2375 if (err) mDNS_StopQuery(&mDNSStorage, &request->u.resolve.qsrv); in handle_resolve_request()
2378 request->terminate = resolve_termination_callback; in handle_resolve_request()
2380 …if (wasP2P || (!InterfaceID && IsLocalDomain(&fqdn) && (request->flags & kDNSServiceFlagsIncludeP2… in handle_resolve_request()
2382 request->u.resolve.external_advertise = mDNStrue; in handle_resolve_request()
2394 #pragma mark -
2395 #pragma mark - DNSServiceQueryRecord
2398 // mDNS operation functions. Each operation has 3 associated functions - a request handler that par…
2403 // Returns -1 to tell the caller that it should not try to reissue the query anymore
2411 // Sanity check: The caller already checks this. We use -1 to indicate that we have searched all in AppendNewSearchDomain()
2413 if (question->SearchListIndex == -1) in AppendNewSearchDomain()
2415 …ewSearchDomain: question %##s (%s) SearchListIndex is -1", question->qname.c, DNSTypeName(question… in AppendNewSearchDomain()
2416 return -1; in AppendNewSearchDomain()
2419 if (!question->AppendSearchDomains) in AppendNewSearchDomain()
2421 …main: question %##s (%s) AppendSearchDoamins is 0", question->qname.c, DNSTypeName(question->qtype… in AppendNewSearchDomain()
2422 return -1; in AppendNewSearchDomain()
2426 if (!question->qnameOrig) in AppendNewSearchDomain()
2428 question->qnameOrig = mallocL("AppendNewSearchDomain", sizeof(domainname)); in AppendNewSearchDomain()
2429 if (!question->qnameOrig) { LogMsg("AppendNewSearchDomain: ERROR!! malloc failure"); return -1; } in AppendNewSearchDomain()
2430 question->qnameOrig->c[0] = 0; in AppendNewSearchDomain()
2431 AssignDomainName(question->qnameOrig, &question->qname); in AppendNewSearchDomain()
2432 LogInfo("AppendSearchDomain: qnameOrig %##s", question->qnameOrig->c); in AppendNewSearchDomain()
2435 …sd = uDNS_GetNextSearchDomain(m, question->InterfaceID, &question->SearchListIndex, !question->App… in AppendNewSearchDomain()
2436 // We use -1 to indicate that we have searched all the domains and should try the single label in AppendNewSearchDomain()
2438 if (question->SearchListIndex == -1) in AppendNewSearchDomain()
2440 LogMsg("AppendNewSearchDomain: ERROR!! uDNS_GetNextSearchDomain returned -1"); in AppendNewSearchDomain()
2441 return -1; in AppendNewSearchDomain()
2445 if (sd && (DomainNameLength(question->qnameOrig) + DomainNameLength(sd)) > MAX_DOMAIN_NAME) in AppendNewSearchDomain()
2447 …d, Question name length %d", question->qnameOrig->c, DNSTypeName(question->qtype), sd->c, DomainNa… in AppendNewSearchDomain()
2448 return -1; in AppendNewSearchDomain()
2455 … question with name %##s (%s), not trying anymore", question->qname.c, DNSTypeName(question->qtype… in AppendNewSearchDomain()
2456 return -1; in AppendNewSearchDomain()
2463 …StopQuery: %d, while retrying with search domains", question->qname.c, DNSTypeName(question->qtype… in AppendNewSearchDomain()
2465 AssignDomainName(&question->qname, question->qnameOrig); in AppendNewSearchDomain()
2468 AppendDomainName(&question->qname, sd); in AppendNewSearchDomain()
2469 …: Returning question with name %##s, SearchListIndex %d", question->qname.c, question->SearchListI… in AppendNewSearchDomain()
2474 …uestion with name %##s (%s), trying one last time", question->qname.c, DNSTypeName(question->qtype… in AppendNewSearchDomain()
2483 for (s=SearchList; s; s=s->next) in DomainInSearchList()
2484 if (SameDomainName(&s->domain, domain)) return mDNStrue; in DomainInSearchList()
2489 // top-level domain
2494 … VALID_MSAD_SRV_TRANSPORT(T) (SameDomainLabel((T)->c, (const mDNSu8 *)"\x4_tcp") || SameDomainLabe… in SendAdditionalQuery()
2495 …#define VALID_MSAD_SRV(Q) ((Q)->qtype == kDNSType_SRV && VALID_MSAD_SRV_TRANSPORT(SecondLabel(&(Q)… in SendAdditionalQuery()
2498 if (request->hdr.op == query_request) in SendAdditionalQuery()
2499 question2 = &request->u.queryrecord.q2; in SendAdditionalQuery()
2500 else if (request->hdr.op == addrinfo_request) in SendAdditionalQuery()
2502 if (q->qtype == kDNSType_A) in SendAdditionalQuery()
2503 question2 = &request->u.addrinfo.q42; in SendAdditionalQuery()
2504 else if (q->qtype == kDNSType_AAAA) in SendAdditionalQuery()
2505 question2 = &request->u.addrinfo.q62; in SendAdditionalQuery()
2509 LogMsg("SendAdditionalQuery: question2 NULL for %##s (%s)", q->qname.c, DNSTypeName(q->qtype)); in SendAdditionalQuery()
2525 …tionalQuery: question2 already sent for %##s (%s), no more q2", q->qname.c, DNSTypeName(q->qtype)); in SendAdditionalQuery()
2529 if (!q->ForceMCast && SameDomainLabel(LastLabel(&q->qname), (const mDNSu8 *)&localdomain)) in SendAdditionalQuery()
2530 if (q->qtype == kDNSType_A || q->qtype == kDNSType_AAAA || VALID_MSAD_SRV(q)) in SendAdditionalQuery()
2533 int labels = CountLabels(&q->qname); in SendAdditionalQuery()
2538 q2->InterfaceID = mDNSInterface_Unicast; in SendAdditionalQuery()
2539 q2->ExpectUnique = mDNStrue; in SendAdditionalQuery()
2545 if (q->qnameOrig) in SendAdditionalQuery()
2547 (*question2)->qnameOrig = mallocL("SendAdditionalQuery", DomainNameLength(q->qnameOrig)); in SendAdditionalQuery()
2548 …if (!(*question2)->qnameOrig) { LogMsg("SendAdditionalQuery: ERROR!! malloc failure"); return mSt… in SendAdditionalQuery()
2549 (*question2)->qnameOrig->c[0] = 0; in SendAdditionalQuery()
2550 AssignDomainName((*question2)->qnameOrig, q->qnameOrig); in SendAdditionalQuery()
2551 LogInfo("SendAdditionalQuery: qnameOrig %##s", (*question2)->qnameOrig->c); in SendAdditionalQuery()
2553 …// For names of the form "<one-or-more-labels>.bar.local." we always do a second unicast query in … in SendAdditionalQuery()
2554 …// For names of the form "<one-label>.local." it's less clear whether we should do a unicast query. in SendAdditionalQuery()
2556 …// "domain" is my-small-company.local, and the user types "my-small-company.local" into their web … in SendAdditionalQuery()
2560 …// Note that in the "my-small-company.local" example above there will typically be an SOA record f… in SendAdditionalQuery()
2561 …// "my-small-company.local" but *not* for "local", which is why the "local SOA" check would fail i… in SendAdditionalQuery()
2564 …if (labels == 2 && !SameDomainName(&q->qname, &ActiveDirectoryPrimaryDomain) && !DomainInSearchLis… in SendAdditionalQuery()
2566 AssignDomainName(&q2->qname, &localdomain); in SendAdditionalQuery()
2567 q2->qtype = kDNSType_SOA; in SendAdditionalQuery()
2568 q2->LongLived = mDNSfalse; in SendAdditionalQuery()
2569 q2->ForceMCast = mDNSfalse; in SendAdditionalQuery()
2570 q2->ReturnIntermed = mDNStrue; in SendAdditionalQuery()
2572 q2->AppendSearchDomains = 0; in SendAdditionalQuery()
2573 q2->AppendLocalSearchDomains = 0; in SendAdditionalQuery()
2574 q2->RetryWithSearchDomains = mDNSfalse; in SendAdditionalQuery()
2575 q2->SearchListIndex = 0; in SendAdditionalQuery()
2576 q2->TimeoutQuestion = 0; in SendAdditionalQuery()
2578 …ion("%3d: DNSServiceQueryRecord(%##s, %s) unicast", request->sd, q2->qname.c, DNSTypeName(q2->qtyp… in SendAdditionalQuery()
2580 …DNSServiceQueryRecord %##s %s mDNS_StartQuery: %d", request->sd, q2->qname.c, DNSTypeName(q2->qtyp… in SendAdditionalQuery()
2598 if (!question->SuppressQuery && question->SearchListIndex != -1 && question->AppendSearchDomains) in RetryQuestionWithSearchDomains()
2600 question->RetryWithSearchDomains = 0; in RetryQuestionWithSearchDomains()
2607 if (result != -1) in RetryQuestionWithSearchDomains()
2613 …#s, %s), retrying after appending search domain", req->sd, question->qname.c, DNSTypeName(question… in RetryQuestionWithSearchDomains()
2616 if (!result) question->SearchListIndex = -1; in RetryQuestionWithSearchDomains()
2621 …rtQuery: %d, while retrying with search domains", req->sd, question->qname.c, DNSTypeName(question… in RetryQuestionWithSearchDomains()
2624 question->QuestionContext = mDNSNULL; in RetryQuestionWithSearchDomains()
2630 … domains - SuppressQuery %d, SearchListIndex %d, AppendSearchDomains %d", req->sd, question->Suppr… in RetryQuestionWithSearchDomains()
2638 request_state *req = question->QuestionContext; in queryrecord_result_callback()
2651 …lback: ERROR!! QuestionContext NULL for %##s (%s)", question->qname.c, DNSTypeName(question->qtype… in queryrecord_result_callback()
2654 if (req->hdr.op == query_request && question == req->u.queryrecord.q2) in queryrecord_result_callback()
2655 q = &req->u.queryrecord.q; in queryrecord_result_callback()
2656 else if (req->hdr.op == addrinfo_request && question == req->u.addrinfo.q42) in queryrecord_result_callback()
2657 q = &req->u.addrinfo.q4; in queryrecord_result_callback()
2658 else if (req->hdr.op == addrinfo_request && question == req->u.addrinfo.q62) in queryrecord_result_callback()
2659 q = &req->u.addrinfo.q6; in queryrecord_result_callback()
2661 if (q && question->qtype != q->qtype && !SameDomainName(&question->qname, &q->qname)) in queryrecord_result_callback()
2664 domainname *orig = question->qnameOrig; in queryrecord_result_callback()
2666 LogInfo("queryrecord_result_callback: Stopping q2 local %##s", question->qname.c); in queryrecord_result_callback()
2668 question->QuestionContext = mDNSNULL; in queryrecord_result_callback()
2674 if (answer->RecordType == kDNSRecordTypePacketNegative && !q->AppendSearchDomains) in queryrecord_result_callback()
2676 LogInfo("queryrecord_result_callback: question %##s AppendSearchDomains zero", q->qname.c); in queryrecord_result_callback()
2680 …// If we got a non-negative answer for our "local SOA" test query, start an additional parallel un… in queryrecord_result_callback()
2683 // RetryWithSearchDomains except for qnameOrig which can be non-NULL if the original question is in queryrecord_result_callback()
2687 question->InterfaceID = mDNSInterface_Unicast; in queryrecord_result_callback()
2688 question->ExpectUnique = mDNStrue; in queryrecord_result_callback()
2689 question->qnameOrig = orig; in queryrecord_result_callback()
2691 …ryRecord(%##s, %s) unicast, context %p", req->sd, question->qname.c, DNSTypeName(question->qtype),… in queryrecord_result_callback()
2695 question->QuestionContext = req; in queryrecord_result_callback()
2697 …ord_result_callback %##s %s mDNS_StartQuery: %d", req->sd, question->qname.c, DNSTypeName(question… in queryrecord_result_callback()
2700 if (answer->RecordType != kDNSRecordTypePacketNegative) return; in queryrecord_result_callback()
2709 question->AppendLocalSearchDomains = 0; in queryrecord_result_callback()
2712 if (q && AddRecord && (question->InterfaceID == mDNSInterface_Unicast) && !answer->rdlength) in queryrecord_result_callback()
2718 …#s (%s) as unicast after appending search domains", question->qname.c, DNSTypeName(question->qtype… in queryrecord_result_callback()
2721 …if (question->AppendSearchDomains && !question->AppendLocalSearchDomains && IsLocalDomain(&questio… in queryrecord_result_callback()
2727 …ult_callback: Disabling .local question %##s (%s)", question->qname.c, DNSTypeName(question->qtype… in queryrecord_result_callback()
2728 question->ThisQInterval = 0; in queryrecord_result_callback()
2736 if (answer->RecordType == kDNSRecordTypePacketNegative) in queryrecord_result_callback()
2744 if (question->TimeoutQuestion) in queryrecord_result_callback()
2746 if ((m->timenow - question->StopTime) >= 0) in queryrecord_result_callback()
2748 …ion %##s (%s) timing out, InterfaceID %p", question->qname.c, DNSTypeName(question->qtype), questi… in queryrecord_result_callback()
2753 …// When we're doing parallel unicast and multicast queries for dot-local names (for supporting Mic… in queryrecord_result_callback()
2761 if (!answer->InterfaceID && IsLocalDomain(answer->name)) in queryrecord_result_callback()
2763 …k:Question %##s (%s) answering local with unicast", question->qname.c, DNSTypeName(question->qtype… in queryrecord_result_callback()
2771 // - if we are timing out this question in queryrecord_result_callback()
2772 // - if the negative response was received as a result of a multicast query in queryrecord_result_callback()
2773 …// - if this is an additional query (q2), we already appended search domains above (indicated by "… in queryrecord_result_callback()
2776 if (!q && !answer->InterfaceID && !answer->rdlength && AddRecord) in queryrecord_result_callback()
2783 …question %##s (%s) after appending search domains", question->qname.c, DNSTypeName(question->qtype… in queryrecord_result_callback()
2798 ConvertDomainNameToCString(answer->name, name); in queryrecord_result_callback()
2800 LogOperation("%3d: %s(%##s, %s) %s %s", req->sd, in queryrecord_result_callback()
2801 req->hdr.op == query_request ? "DNSServiceQueryRecord" : "DNSServiceGetAddrInfo", in queryrecord_result_callback()
2802 …question->qname.c, DNSTypeName(question->qtype), AddRecord ? "ADD" : "RMV", RRDisplayString(m, ans… in queryrecord_result_callback()
2809 len += answer->rdlength; in queryrecord_result_callback()
2812 rep = create_reply(req->hdr.op == query_request ? query_reply_op : addrinfo_reply_op, len, req); in queryrecord_result_callback()
2814 rep->rhdr->flags = dnssd_htonl(AddRecord ? kDNSServiceFlagsAdd : 0); in queryrecord_result_callback()
2822 …rep->rhdr->ifi = dnssd_htonl(mDNSPlatformInterfaceIndexfromInterfaceID(m, answer->InterfaceID, m… in queryrecord_result_callback()
2823 rep->rhdr->error = dnssd_htonl(error); in queryrecord_result_callback()
2825 data = (char *)&rep->rhdr[1]; in queryrecord_result_callback()
2828 put_uint16(answer->rrtype, &data); in queryrecord_result_callback()
2829 put_uint16(answer->rrclass, &data); in queryrecord_result_callback()
2830 put_uint16(answer->rdlength, &data); in queryrecord_result_callback()
2833 if (answer->rdlength) in queryrecord_result_callback()
2834 if (!putRData(mDNSNULL, (mDNSu8 *)data, (mDNSu8 *)rep->rhdr + len, answer)) in queryrecord_result_callback()
2835 …LogMsg("queryrecord_result_callback putRData failed %d", (mDNSu8 *)rep->rhdr + len - (mDNSu8 *)dat… in queryrecord_result_callback()
2836 data += answer->rdlength; in queryrecord_result_callback()
2837 put_uint32(AddRecord ? answer->rroriginalttl : 0, &data); in queryrecord_result_callback()
2845 question->QuestionContext = mDNSNULL; in queryrecord_result_callback()
2854 if (WCFIsServerRunning((WCFConnection *)m->WCF) && answer->rdlength != 0) in queryrecord_result_callback()
2856 if (getsockopt(req->sd, 0, LOCAL_PEERCRED, &x, &xucredlen) >= 0 && in queryrecord_result_callback()
2860 const RDataBody2 *const rdb = (RDataBody2 *)answer->rdata->u.data; in queryrecord_result_callback()
2862 if (answer->rrtype == kDNSType_A || answer->rrtype == kDNSType_AAAA) in queryrecord_result_callback()
2864 if (answer->rrtype == kDNSType_A) in queryrecord_result_callback()
2867 sin->sin_port = 0; in queryrecord_result_callback()
2868 …if (!putRData(mDNSNULL, (mDNSu8 *)&sin->sin_addr, (mDNSu8 *)(&sin->sin_addr + sizeof(rdb->ipv4)), … in queryrecord_result_callback()
2876 else if (answer->rrtype == kDNSType_AAAA) in queryrecord_result_callback()
2879 sin6->sin6_port = 0; in queryrecord_result_callback()
2880 …if (!putRData(mDNSNULL, (mDNSu8 *)&sin6->sin6_addr, (mDNSu8 *)(&sin6->sin6_addr + sizeof(rdb->ipv6… in queryrecord_result_callback()
2893 WCFNameResolvesToAddr(m->WCF, name, (struct sockaddr *)&addr, x.cr_uid); in queryrecord_result_callback()
2897 else if (answer->rrtype == kDNSType_CNAME) in queryrecord_result_callback()
2908 WCFNameResolvesToName(m->WCF, name, cname_cstr, x.cr_uid); in queryrecord_result_callback()
2923 request->sd, request->u.queryrecord.q.qname.c, DNSTypeName(request->u.queryrecord.q.qtype)); in queryrecord_termination_callback()
2924 if (request->u.queryrecord.q.QuestionContext) in queryrecord_termination_callback()
2926 mDNS_StopQuery(&mDNSStorage, &request->u.queryrecord.q); // no need to error check in queryrecord_termination_callback()
2927 request->u.queryrecord.q.QuestionContext = mDNSNULL; in queryrecord_termination_callback()
2931 DNSQuestion *question = &request->u.queryrecord.q; in queryrecord_termination_callback()
2932 …##s (%s) already stopped, InterfaceID %p", question->qname.c, DNSTypeName(question->qtype), questi… in queryrecord_termination_callback()
2935 if (request->u.queryrecord.q.qnameOrig) in queryrecord_termination_callback()
2937 freeL("QueryTermination", request->u.queryrecord.q.qnameOrig); in queryrecord_termination_callback()
2938 request->u.queryrecord.q.qnameOrig = mDNSNULL; in queryrecord_termination_callback()
2940 …->u.queryrecord.q.InterfaceID == mDNSInterface_P2P || (!request->u.queryrecord.q.InterfaceID && Sa… in queryrecord_termination_callback()
2943 …external_stop_browsing_for_service(&mDNSStorage, &request->u.queryrecord.q.qname, request->u.query… in queryrecord_termination_callback()
2945 if (request->u.queryrecord.q2) in queryrecord_termination_callback()
2947 if (request->u.queryrecord.q2->QuestionContext) in queryrecord_termination_callback()
2949 … LogInfo("queryrecord_termination_callback: Stopping q2 %##s", request->u.queryrecord.q2->qname.c); in queryrecord_termination_callback()
2950 mDNS_StopQuery(&mDNSStorage, request->u.queryrecord.q2); in queryrecord_termination_callback()
2954 DNSQuestion *question = request->u.queryrecord.q2; in queryrecord_termination_callback()
2955 …##s (%s) already stopped, InterfaceID %p", question->qname.c, DNSTypeName(question->qtype), questi… in queryrecord_termination_callback()
2957 if (request->u.queryrecord.q2->qnameOrig) in queryrecord_termination_callback()
2959 …yrecord_termination_callback: freeing q2 qnameOrig %##s", request->u.queryrecord.q2->qnameOrig->c); in queryrecord_termination_callback()
2960 freeL("QueryTermination q2", request->u.queryrecord.q2->qnameOrig); in queryrecord_termination_callback()
2961 request->u.queryrecord.q2->qnameOrig = mDNSNULL; in queryrecord_termination_callback()
2963 freeL("queryrecord Q2", request->u.queryrecord.q2); in queryrecord_termination_callback()
2964 request->u.queryrecord.q2 = mDNSNULL; in queryrecord_termination_callback()
2970 DNSQuestion *const q = &request->u.queryrecord.q; in handle_queryrecord_request()
2975 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend); in handle_queryrecord_request()
2976 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend); in handle_queryrecord_request()
2980 if (get_string(&request->msgptr, request->msgend, name, 256) < 0) return(mStatus_BadParamErr); in handle_queryrecord_request()
2981 rrtype = get_uint16(&request->msgptr, request->msgend); in handle_queryrecord_request()
2982 rrclass = get_uint16(&request->msgptr, request->msgend); in handle_queryrecord_request()
2984 if (!request->msgptr) in handle_queryrecord_request()
2985 …{ LogMsg("%3d: DNSServiceQueryRecord(unreadable parameters)", request->sd); return(mStatus_BadPara… in handle_queryrecord_request()
2987 request->flags = flags; in handle_queryrecord_request()
2988 mDNSPlatformMemZero(&request->u.queryrecord, sizeof(request->u.queryrecord)); in handle_queryrecord_request()
2990 q->InterfaceID = InterfaceID; in handle_queryrecord_request()
2991 q->Target = zeroAddr; in handle_queryrecord_request()
2992 if (!MakeDomainNameFromDNSNameString(&q->qname, name)) return(mStatus_BadParamErr); in handle_queryrecord_request()
2994 if (!AuthorizedDomain(request, &q->qname, AutoBrowseDomains)) return (mStatus_NoError); in handle_queryrecord_request()
2996 q->qtype = rrtype; in handle_queryrecord_request()
2997 q->qclass = rrclass; in handle_queryrecord_request()
2998 q->LongLived = (flags & kDNSServiceFlagsLongLivedQuery ) != 0; in handle_queryrecord_request()
2999 q->ExpectUnique = mDNSfalse; in handle_queryrecord_request()
3000 q->ForceMCast = (flags & kDNSServiceFlagsForceMulticast ) != 0; in handle_queryrecord_request()
3001 q->ReturnIntermed = (flags & kDNSServiceFlagsReturnIntermediates) != 0; in handle_queryrecord_request()
3002 q->SuppressUnusable = (flags & kDNSServiceFlagsSuppressUnusable ) != 0; in handle_queryrecord_request()
3003 q->TimeoutQuestion = (flags & kDNSServiceFlagsTimeout ) != 0; in handle_queryrecord_request()
3004 q->WakeOnResolve = 0; in handle_queryrecord_request()
3005 q->QuestionCallback = queryrecord_result_callback; in handle_queryrecord_request()
3006 q->QuestionContext = request; in handle_queryrecord_request()
3007 q->SearchListIndex = 0; in handle_queryrecord_request()
3018 if ((rrtype == kDNSType_A || rrtype == kDNSType_AAAA) && name[strlen(name) - 1] != '.' && in handle_queryrecord_request()
3019 (AlwaysAppendSearchDomains || CountLabels(&q->qname) == 1)) in handle_queryrecord_request()
3021 q->AppendSearchDomains = 1; in handle_queryrecord_request()
3022 q->AppendLocalSearchDomains = 1; in handle_queryrecord_request()
3026 q->AppendSearchDomains = 0; in handle_queryrecord_request()
3027 q->AppendLocalSearchDomains = 0; in handle_queryrecord_request()
3034 q->RetryWithSearchDomains = ApplySearchDomainsFirst(q) ? 1 : 0; in handle_queryrecord_request()
3035 q->qnameOrig = mDNSNULL; in handle_queryrecord_request()
3037 …viceQueryRecord(%X, %d, %##s, %s) START", request->sd, flags, interfaceIndex, q->qname.c, DNSTypeN… in handle_queryrecord_request()
3039 … DNSServiceQueryRecord %##s %s mDNS_StartQuery: %d", request->sd, q->qname.c, DNSTypeName(q->qtype… in handle_queryrecord_request()
3042 request->terminate = queryrecord_termination_callback; in handle_queryrecord_request()
3043 …if (q->InterfaceID == mDNSInterface_P2P || (!q->InterfaceID && SameDomainName((const domainname *)… in handle_queryrecord_request()
3046 external_start_browsing_for_service(&mDNSStorage, &q->qname, q->qtype); in handle_queryrecord_request()
3059 #pragma mark -
3060 #pragma mark - DNSServiceEnumerateDomains
3076 reply->rhdr->flags = dnssd_htonl(flags); in format_enumeration_reply()
3077 reply->rhdr->ifi = dnssd_htonl(ifi); in format_enumeration_reply()
3078 reply->rhdr->error = dnssd_htonl(err); in format_enumeration_reply()
3079 data = (char *)&reply->rhdr[1]; in format_enumeration_reply()
3086 mDNS_StopGetDomains(&mDNSStorage, &request->u.enumeration.q_all); in enum_termination_callback()
3087 mDNS_StopGetDomains(&mDNSStorage, &request->u.enumeration.q_default); in enum_termination_callback()
3094 request_state *request = question->QuestionContext; in enum_result_callback()
3099 if (answer->rrtype != kDNSType_PTR) return; in enum_result_callback()
3102 …if (!AuthorizedDomain(request, &answer->rdata->u.name, request->u.enumeration.flags ? AutoRegistra… in enum_result_callback()
3107 if (question == &request->u.enumeration.q_default && !AddRecord) return; in enum_result_callback()
3112 if (question == &request->u.enumeration.q_default) flags |= kDNSServiceFlagsDefault; in enum_result_callback()
3115 ConvertDomainNameToCString(&answer->rdata->u.name, domain); in enum_result_callback()
3116 …// Note that we do NOT propagate specific interface indexes to the client - for example, a domain … in enum_result_callback()
3122 …LogOperation("%3d: DNSServiceEnumerateDomains(%#2s) RESULT %s: %s", request->sd, question->qname.c… in enum_result_callback()
3130 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend); in handle_enum_request()
3134 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend); in handle_enum_request()
3138 if (!request->msgptr) in handle_enum_request()
3139 …{ LogMsg("%3d: DNSServiceEnumerateDomains(unreadable parameters)", request->sd); return(mStatus_Ba… in handle_enum_request()
3146 request->u.enumeration.flags = reg; in handle_enum_request()
3151 request->u.enumeration.q_all .QuestionContext = request; in handle_enum_request()
3152 request->u.enumeration.q_default.QuestionContext = request; in handle_enum_request()
3154 …// if the caller hasn't specified an explicit interface, we use local-only to get the system-wide … in handle_enum_request()
3158 LogOperation("%3d: DNSServiceEnumerateDomains(%X=%s)", request->sd, flags, in handle_enum_request()
3161 …err = mDNS_GetDomains(&mDNSStorage, &request->u.enumeration.q_all, t_all, NULL, InterfaceID, enum_… in handle_enum_request()
3164 …err = mDNS_GetDomains(&mDNSStorage, &request->u.enumeration.q_default, t_default, NULL, InterfaceI… in handle_enum_request()
3165 if (err) mDNS_StopGetDomains(&mDNSStorage, &request->u.enumeration.q_all); in handle_enum_request()
3166 else request->terminate = enum_termination_callback; in handle_enum_request()
3174 #pragma mark -
3175 #pragma mark - DNSServiceReconfirmRecord & Misc
3184 status = mDNS_ReconfirmByValue(&mDNSStorage, &rr->resrec); in handle_reconfirm_request()
3189 request->sd, RRDisplayString(&mDNSStorage, &rr->resrec), in handle_reconfirm_request()
3190 …mDNSPlatformInterfaceIndexfromInterfaceID(&mDNSStorage, rr->resrec.InterfaceID, mDNSfalse), status… in handle_reconfirm_request()
3200 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend); in handle_setdomain_request()
3202 if (get_string(&request->msgptr, request->msgend, domainstr, MAX_ESCAPED_DOMAIN_NAME) < 0 || in handle_setdomain_request()
3204 …{ LogMsg("%3d: DNSServiceSetDefaultDomainForUser(unreadable parameters)", request->sd); return(mSt… in handle_setdomain_request()
3206 LogOperation("%3d: DNSServiceSetDefaultDomainForUser(%##s)", request->sd, domain.c); in handle_setdomain_request()
3221 if (get_string(&request->msgptr, request->msgend, prop, sizeof(prop)) >= 0) in handle_getproperty_request()
3223 LogOperation("%3d: DNSServiceGetProperty(%s)", request->sd, prop); in handle_getproperty_request()
3227 send_all(request->sd, (const char *)&x, sizeof(x)); in handle_getproperty_request()
3233 send_all(request->sd, (const char *)&BadParamErr, sizeof(BadParamErr)); in handle_getproperty_request()
3238 #pragma mark -
3239 #pragma mark - DNSServiceNATPortMappingCreate
3246 LogOperation("%3d: DNSServiceNATPortMappingCreate(%X, %u, %u, %d) STOP", request->sd, in port_mapping_termination_callback()
3247 DNSServiceProtocol(request->u.pm.NATinfo.Protocol), in port_mapping_termination_callback()
3248 …mDNSVal16(request->u.pm.NATinfo.IntPort), mDNSVal16(request->u.pm.ReqExt), request->u.pm.NATinfo.N… in port_mapping_termination_callback()
3249 mDNS_StopNATOperation(&mDNSStorage, &request->u.pm.NATinfo); in port_mapping_termination_callback()
3252 // Called via function pointer when we get a NAT-PMP address request or port mapping response
3255 request_state *request = (request_state *)n->clientContext; in port_mapping_create_request_callback()
3271 rep->rhdr->flags = dnssd_htonl(0); in port_mapping_create_request_callback()
3272 …rep->rhdr->ifi = dnssd_htonl(mDNSPlatformInterfaceIndexfromInterfaceID(m, n->InterfaceID, mDNSfa… in port_mapping_create_request_callback()
3273 rep->rhdr->error = dnssd_htonl(n->Result); in port_mapping_create_request_callback()
3275 data = (char *)&rep->rhdr[1]; in port_mapping_create_request_callback()
3277 *data++ = request->u.pm.NATinfo.ExternalAddress.b[0]; in port_mapping_create_request_callback()
3278 *data++ = request->u.pm.NATinfo.ExternalAddress.b[1]; in port_mapping_create_request_callback()
3279 *data++ = request->u.pm.NATinfo.ExternalAddress.b[2]; in port_mapping_create_request_callback()
3280 *data++ = request->u.pm.NATinfo.ExternalAddress.b[3]; in port_mapping_create_request_callback()
3281 *data++ = DNSServiceProtocol(request->u.pm.NATinfo.Protocol); in port_mapping_create_request_callback()
3282 *data++ = request->u.pm.NATinfo.IntPort.b[0]; in port_mapping_create_request_callback()
3283 *data++ = request->u.pm.NATinfo.IntPort.b[1]; in port_mapping_create_request_callback()
3284 *data++ = request->u.pm.NATinfo.ExternalPort.b[0]; in port_mapping_create_request_callback()
3285 *data++ = request->u.pm.NATinfo.ExternalPort.b[1]; in port_mapping_create_request_callback()
3286 put_uint32(request->u.pm.NATinfo.Lifetime, &data); in port_mapping_create_request_callback()
3288 …LogOperation("%3d: DNSServiceNATPortMappingCreate(%X, %u, %u, %d) RESULT %.4a:%u TTL %u", request-… in port_mapping_create_request_callback()
3289 DNSServiceProtocol(request->u.pm.NATinfo.Protocol), in port_mapping_create_request_callback()
3290 …mDNSVal16(request->u.pm.NATinfo.IntPort), mDNSVal16(request->u.pm.ReqExt), request->u.pm.NATinfo.N… in port_mapping_create_request_callback()
3291 …&request->u.pm.NATinfo.ExternalAddress, mDNSVal16(request->u.pm.NATinfo.ExternalPort), request->u.… in port_mapping_create_request_callback()
3301 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend); in handle_port_mapping_request()
3302 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend); in handle_port_mapping_request()
3304 mDNSu8 protocol = (mDNSu8)get_uint32(&request->msgptr, request->msgend); in handle_port_mapping_request()
3307 if (request->msgptr + 8 > request->msgend) request->msgptr = NULL; in handle_port_mapping_request()
3310 request->u.pm.NATinfo.IntPort.b[0] = *request->msgptr++; in handle_port_mapping_request()
3311 request->u.pm.NATinfo.IntPort.b[1] = *request->msgptr++; in handle_port_mapping_request()
3312 request->u.pm.ReqExt.b[0] = *request->msgptr++; in handle_port_mapping_request()
3313 request->u.pm.ReqExt.b[1] = *request->msgptr++; in handle_port_mapping_request()
3314 ttl = get_uint32(&request->msgptr, request->msgend); in handle_port_mapping_request()
3317 if (!request->msgptr) in handle_port_mapping_request()
3318 …{ LogMsg("%3d: DNSServiceNATPortMappingCreate(unreadable parameters)", request->sd); return(mStatu… in handle_port_mapping_request()
3322 …if (!mDNSIPPortIsZero(request->u.pm.NATinfo.IntPort) || !mDNSIPPortIsZero(request->u.pm.ReqExt) ||… in handle_port_mapping_request()
3326 if (mDNSIPPortIsZero(request->u.pm.NATinfo.IntPort)) return(mStatus_BadParamErr); in handle_port_mapping_request()
3330 …request->u.pm.NATinfo.Protocol = !protocol ? NATOp_AddrRequest : (protocol == kDNSServicePro… in handle_port_mapping_request()
3332 request->u.pm.NATinfo.RequestedPort = request->u.pm.ReqExt; in handle_port_mapping_request()
3333 request->u.pm.NATinfo.NATLease = ttl; in handle_port_mapping_request()
3334 request->u.pm.NATinfo.clientCallback = port_mapping_create_request_callback; in handle_port_mapping_request()
3335 request->u.pm.NATinfo.clientContext = request; in handle_port_mapping_request()
3337 LogOperation("%3d: DNSServiceNATPortMappingCreate(%X, %u, %u, %d) START", request->sd, in handle_port_mapping_request()
3338 …protocol, mDNSVal16(request->u.pm.NATinfo.IntPort), mDNSVal16(request->u.pm.ReqExt), request->u.pm… in handle_port_mapping_request()
3339 err = mDNS_StartNATOperation(&mDNSStorage, &request->u.pm.NATinfo); in handle_port_mapping_request()
3341 else request->terminate = port_mapping_termination_callback; in handle_port_mapping_request()
3348 #pragma mark -
3349 #pragma mark - DNSServiceGetAddrInfo
3354 LogOperation("%3d: DNSServiceGetAddrInfo(%##s) STOP", request->sd, request->u.addrinfo.q4.qname.c); in addrinfo_termination_callback()
3356 if (request->u.addrinfo.q4.QuestionContext) in addrinfo_termination_callback()
3358 mDNS_StopQuery(&mDNSStorage, &request->u.addrinfo.q4); in addrinfo_termination_callback()
3359 request->u.addrinfo.q4.QuestionContext = mDNSNULL; in addrinfo_termination_callback()
3361 if (request->u.addrinfo.q4.qnameOrig) in addrinfo_termination_callback()
3363 freeL("QueryTermination", request->u.addrinfo.q4.qnameOrig); in addrinfo_termination_callback()
3364 request->u.addrinfo.q4.qnameOrig = mDNSNULL; in addrinfo_termination_callback()
3366 if (request->u.addrinfo.q42) in addrinfo_termination_callback()
3368 if (request->u.addrinfo.q42->QuestionContext) in addrinfo_termination_callback()
3370 LogInfo("addrinfo_termination_callback: Stopping q42 %##s", request->u.addrinfo.q42->qname.c); in addrinfo_termination_callback()
3371 mDNS_StopQuery(&mDNSStorage, request->u.addrinfo.q42); in addrinfo_termination_callback()
3373 if (request->u.addrinfo.q42->qnameOrig) in addrinfo_termination_callback()
3375 …addrinfo_termination_callback: freeing q42 qnameOrig %##s", request->u.addrinfo.q42->qnameOrig->c); in addrinfo_termination_callback()
3376 freeL("QueryTermination q42", request->u.addrinfo.q42->qnameOrig); in addrinfo_termination_callback()
3377 request->u.addrinfo.q42->qnameOrig = mDNSNULL; in addrinfo_termination_callback()
3379 freeL("addrinfo Q42", request->u.addrinfo.q42); in addrinfo_termination_callback()
3380 request->u.addrinfo.q42 = mDNSNULL; in addrinfo_termination_callback()
3383 if (request->u.addrinfo.q6.QuestionContext) in addrinfo_termination_callback()
3385 mDNS_StopQuery(&mDNSStorage, &request->u.addrinfo.q6); in addrinfo_termination_callback()
3386 request->u.addrinfo.q6.QuestionContext = mDNSNULL; in addrinfo_termination_callback()
3388 if (request->u.addrinfo.q6.qnameOrig) in addrinfo_termination_callback()
3390 freeL("QueryTermination", request->u.addrinfo.q6.qnameOrig); in addrinfo_termination_callback()
3391 request->u.addrinfo.q6.qnameOrig = mDNSNULL; in addrinfo_termination_callback()
3393 if (request->u.addrinfo.q62) in addrinfo_termination_callback()
3395 if (request->u.addrinfo.q62->QuestionContext) in addrinfo_termination_callback()
3397 LogInfo("addrinfo_termination_callback: Stopping q62 %##s", request->u.addrinfo.q62->qname.c); in addrinfo_termination_callback()
3398 mDNS_StopQuery(&mDNSStorage, request->u.addrinfo.q62); in addrinfo_termination_callback()
3400 if (request->u.addrinfo.q62->qnameOrig) in addrinfo_termination_callback()
3402 …addrinfo_termination_callback: freeing q62 qnameOrig %##s", request->u.addrinfo.q62->qnameOrig->c); in addrinfo_termination_callback()
3403 freeL("QueryTermination q62", request->u.addrinfo.q62->qnameOrig); in addrinfo_termination_callback()
3404 request->u.addrinfo.q62->qnameOrig = mDNSNULL; in addrinfo_termination_callback()
3406 freeL("addrinfo Q62", request->u.addrinfo.q62); in addrinfo_termination_callback()
3407 request->u.addrinfo.q62 = mDNSNULL; in addrinfo_termination_callback()
3417 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend); in handle_addrinfo_request()
3418 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend); in handle_addrinfo_request()
3420 mDNSPlatformMemZero(&request->u.addrinfo, sizeof(request->u.addrinfo)); in handle_addrinfo_request()
3421 …request->u.addrinfo.interface_id = mDNSPlatformInterfaceIDfromInterfaceIndex(&mDNSStorage, interfa… in handle_addrinfo_request()
3422 request->u.addrinfo.flags = flags; in handle_addrinfo_request()
3423 request->u.addrinfo.protocol = get_uint32(&request->msgptr, request->msgend); in handle_addrinfo_request()
3425 if (interfaceIndex && !request->u.addrinfo.interface_id) return(mStatus_BadParamErr); in handle_addrinfo_request()
3426 …if (request->u.addrinfo.protocol > (kDNSServiceProtocol_IPv4|kDNSServiceProtocol_IPv6)) return(mSt… in handle_addrinfo_request()
3428 if (get_string(&request->msgptr, request->msgend, hostname, 256) < 0) return(mStatus_BadParamErr); in handle_addrinfo_request()
3430 …if (!request->msgptr) { LogMsg("%3d: DNSServiceGetAddrInfo(unreadable parameters)", request->sd); … in handle_addrinfo_request()
3439 if (!request->u.addrinfo.protocol) in handle_addrinfo_request()
3442 request->u.addrinfo.protocol = (kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6); in handle_addrinfo_request()
3445 …request->u.addrinfo.q4.InterfaceID = request->u.addrinfo.q6.InterfaceID = request->u.add… in handle_addrinfo_request()
3446 request->u.addrinfo.q4.Target = request->u.addrinfo.q6.Target = zeroAddr; in handle_addrinfo_request()
3447 request->u.addrinfo.q4.qname = request->u.addrinfo.q6.qname = d; in handle_addrinfo_request()
3448 …request->u.addrinfo.q4.qclass = request->u.addrinfo.q6.qclass = kDNSServiceCla… in handle_addrinfo_request()
3449 …request->u.addrinfo.q4.LongLived = request->u.addrinfo.q6.LongLived = (flags & kDNSS… in handle_addrinfo_request()
3450 request->u.addrinfo.q4.ExpectUnique = request->u.addrinfo.q6.ExpectUnique = mDNSfalse; in handle_addrinfo_request()
3451 …request->u.addrinfo.q4.ForceMCast = request->u.addrinfo.q6.ForceMCast = (flags & kDNSS… in handle_addrinfo_request()
3452 …request->u.addrinfo.q4.ReturnIntermed = request->u.addrinfo.q6.ReturnIntermed = (flags & kDNSS… in handle_addrinfo_request()
3453 …request->u.addrinfo.q4.SuppressUnusable = request->u.addrinfo.q6.SuppressUnusable = (flags & kDNSS… in handle_addrinfo_request()
3454 …request->u.addrinfo.q4.TimeoutQuestion = request->u.addrinfo.q6.TimeoutQuestion = (flags & kDNSS… in handle_addrinfo_request()
3455 request->u.addrinfo.q4.WakeOnResolve = request->u.addrinfo.q6.WakeOnResolve = 0; in handle_addrinfo_request()
3456 request->u.addrinfo.q4.qnameOrig = request->u.addrinfo.q6.qnameOrig = mDNSNULL; in handle_addrinfo_request()
3458 if (request->u.addrinfo.protocol & kDNSServiceProtocol_IPv4) in handle_addrinfo_request()
3460 request->u.addrinfo.q4.qtype = kDNSServiceType_A; in handle_addrinfo_request()
3461 request->u.addrinfo.q4.SearchListIndex = 0; in handle_addrinfo_request()
3466 if (hostname[strlen(hostname) - 1] != '.' && (AlwaysAppendSearchDomains || CountLabels(&d) == 1)) in handle_addrinfo_request()
3468 request->u.addrinfo.q4.AppendSearchDomains = 1; in handle_addrinfo_request()
3469 request->u.addrinfo.q4.AppendLocalSearchDomains = 1; in handle_addrinfo_request()
3473 request->u.addrinfo.q4.AppendSearchDomains = 0; in handle_addrinfo_request()
3474 request->u.addrinfo.q4.AppendLocalSearchDomains = 0; in handle_addrinfo_request()
3476 …request->u.addrinfo.q4.RetryWithSearchDomains = (ApplySearchDomainsFirst(&request->u.addrinfo.q4) … in handle_addrinfo_request()
3477 request->u.addrinfo.q4.QuestionCallback = queryrecord_result_callback; in handle_addrinfo_request()
3478 request->u.addrinfo.q4.QuestionContext = request; in handle_addrinfo_request()
3479 err = mDNS_StartQuery(&mDNSStorage, &request->u.addrinfo.q4); in handle_addrinfo_request()
3483 request->u.addrinfo.q4.QuestionContext = mDNSNULL; in handle_addrinfo_request()
3486 err = SendAdditionalQuery(&request->u.addrinfo.q4, request, err); in handle_addrinfo_request()
3490 if (!err && (request->u.addrinfo.protocol & kDNSServiceProtocol_IPv6)) in handle_addrinfo_request()
3492 request->u.addrinfo.q6.qtype = kDNSServiceType_AAAA; in handle_addrinfo_request()
3493 request->u.addrinfo.q6.SearchListIndex = 0; in handle_addrinfo_request()
3494 if (hostname[strlen(hostname) - 1] != '.' && (AlwaysAppendSearchDomains || CountLabels(&d) == 1)) in handle_addrinfo_request()
3496 request->u.addrinfo.q6.AppendSearchDomains = 1; in handle_addrinfo_request()
3497 request->u.addrinfo.q6.AppendLocalSearchDomains = 1; in handle_addrinfo_request()
3501 request->u.addrinfo.q6.AppendSearchDomains = 0; in handle_addrinfo_request()
3502 request->u.addrinfo.q6.AppendLocalSearchDomains = 0; in handle_addrinfo_request()
3504 …request->u.addrinfo.q6.RetryWithSearchDomains = (ApplySearchDomainsFirst(&request->u.addrinfo.q6) … in handle_addrinfo_request()
3505 request->u.addrinfo.q6.QuestionCallback = queryrecord_result_callback; in handle_addrinfo_request()
3506 request->u.addrinfo.q6.QuestionContext = request; in handle_addrinfo_request()
3507 err = mDNS_StartQuery(&mDNSStorage, &request->u.addrinfo.q6); in handle_addrinfo_request()
3511 request->u.addrinfo.q6.QuestionContext = mDNSNULL; in handle_addrinfo_request()
3512 if (request->u.addrinfo.protocol & kDNSServiceProtocol_IPv4) in handle_addrinfo_request()
3514 // If we started a query for IPv4, we need to cancel it in handle_addrinfo_request()
3515 mDNS_StopQuery(&mDNSStorage, &request->u.addrinfo.q4); in handle_addrinfo_request()
3516 request->u.addrinfo.q4.QuestionContext = mDNSNULL; in handle_addrinfo_request()
3520 err = SendAdditionalQuery(&request->u.addrinfo.q6, request, err); in handle_addrinfo_request()
3525 request->sd, flags, interfaceIndex, request->u.addrinfo.protocol, d.c); in handle_addrinfo_request()
3527 if (!err) request->terminate = addrinfo_termination_callback; in handle_addrinfo_request()
3534 #pragma mark -
3535 #pragma mark - Main Request Handler etc.
3541 while (*p) p=&(*p)->next; in NewRequest()
3548 // read_msg may be called any time when the transfer state (req->ts) is t_morecoming.
3552 if (req->ts == t_terminated || req->ts == t_error) in read_msg()
3553 …{ LogMsg("%3d: ERROR: read_msg called with transfer state terminated or error", req->sd); req->ts … in read_msg()
3555 if (req->ts == t_complete) // this must be death or something is wrong in read_msg()
3558 int nread = udsSupportReadFD(req->sd, buf, 4, 0, req->platform_data); in read_msg()
3559 if (!nread) { req->ts = t_terminated; return; } in read_msg()
3561 LogMsg("%3d: ERROR: read data from a completed request", req->sd); in read_msg()
3562 req->ts = t_error; in read_msg()
3566 if (req->ts != t_morecoming) in read_msg()
3567 …{ LogMsg("%3d: ERROR: read_msg called with invalid transfer state (%d)", req->sd, req->ts); req->t… in read_msg()
3569 if (req->hdr_bytes < sizeof(ipc_msg_hdr)) in read_msg()
3571 mDNSu32 nleft = sizeof(ipc_msg_hdr) - req->hdr_bytes; in read_msg()
3572 …int nread = udsSupportReadFD(req->sd, (char *)&req->hdr + req->hdr_bytes, nleft, 0, req->platform_… in read_msg()
3573 if (nread == 0) { req->ts = t_terminated; return; } in read_msg()
3575 req->hdr_bytes += nread; in read_msg()
3576 if (req->hdr_bytes > sizeof(ipc_msg_hdr)) in read_msg()
3577 …{ LogMsg("%3d: ERROR: read_msg - read too many header bytes", req->sd); req->ts = t_error; return;… in read_msg()
3580 if (req->hdr_bytes == sizeof(ipc_msg_hdr)) in read_msg()
3582 ConvertHeaderBytes(&req->hdr); in read_msg()
3583 if (req->hdr.version != VERSION) in read_msg()
3584 … ERROR: client version 0x%08X daemon version 0x%08X", req->sd, req->hdr.version, VERSION); req->ts… in read_msg()
3589 if (req->hdr.datalen > 70000) in read_msg()
3590 … ERROR: read_msg: hdr.datalen %u (0x%X) > 70000", req->sd, req->hdr.datalen, req->hdr.datalen); re… in read_msg()
3591 req->msgbuf = mallocL("request_state msgbuf", req->hdr.datalen + MSG_PAD_BYTES); in read_msg()
3592 if (!req->msgbuf) { my_perror("ERROR: malloc"); req->ts = t_error; return; } in read_msg()
3593 req->msgptr = req->msgbuf; in read_msg()
3594 req->msgend = req->msgbuf + req->hdr.datalen; in read_msg()
3595 mDNSPlatformMemZero(req->msgbuf, req->hdr.datalen + MSG_PAD_BYTES); in read_msg()
3600 …// Note: For cancel_request req->hdr.datalen == 0, but there's no error return socket for cancel_r… in read_msg()
3602 // (even if only the one-byte empty C string placeholder for the old ctrl_path parameter) in read_msg()
3603 if (req->hdr_bytes == sizeof(ipc_msg_hdr) && req->data_bytes < req->hdr.datalen) in read_msg()
3605 mDNSu32 nleft = req->hdr.datalen - req->data_bytes; in read_msg()
3608 …struct iovec vec = { req->msgbuf + req->data_bytes, nleft }; // Tell recvmsg where we want the byt… in read_msg()
3619 nread = recvmsg(req->sd, &msg, 0); in read_msg()
3621 …nread = udsSupportReadFD(req->sd, (char *)req->msgbuf + req->data_bytes, nleft, 0, req->platform_d… in read_msg()
3623 if (nread == 0) { req->ts = t_terminated; return; } in read_msg()
3625 req->data_bytes += nread; in read_msg()
3626 if (req->data_bytes > req->hdr.datalen) in read_msg()
3627 … { LogMsg("%3d: ERROR: read_msg - read too many data bytes", req->sd); req->ts = t_error; return; } in read_msg()
3631 …LogMsg("%3d: Expecting %d %d %d %d", req->sd, sizeof(cbuf), sizeof(cbuf), SOL_SOCKET, … in read_msg()
3632 …LogMsg("%3d: Got %d %d %d %d", req->sd, msg.msg_controllen, cmsg->cmsg_len, cmsg->cmsg_level… in read_msg()
3635 cmsg->cmsg_len == CMSG_LEN(sizeof(dnssd_sock_t)) && in read_msg()
3636 cmsg->cmsg_level == SOL_SOCKET && in read_msg()
3637 cmsg->cmsg_type == SCM_RIGHTS) in read_msg()
3642 // and it's convenient to repurpose the existing fd-passing code here for that task in read_msg()
3643 if (req->hdr.op == send_bpf) in read_msg()
3646 LogOperation("%3d: Got BPF %d", req->sd, x); in read_msg()
3651 req->errsd = *(dnssd_sock_t *)CMSG_DATA(cmsg); in read_msg()
3653 LogMsg("%3d: read req->errsd %d", req->sd, req->errsd); in read_msg()
3655 if (req->data_bytes < req->hdr.datalen) in read_msg()
3657 …LogMsg("%3d: Client sent error socket %d via SCM_RIGHTS with req->data_bytes %d < req->hdr.datalen… in read_msg()
3658 req->sd, req->errsd, req->data_bytes, req->hdr.datalen); in read_msg()
3659 req->ts = t_error; in read_msg()
3667 if (req->hdr_bytes == sizeof(ipc_msg_hdr) && req->data_bytes == req->hdr.datalen) in read_msg()
3669 if (req->terminate && req->hdr.op != cancel_request) in read_msg()
3675 port.b[0] = req->msgptr[0]; in read_msg()
3676 port.b[1] = req->msgptr[1]; in read_msg()
3677 req->msgptr += 2; in read_msg()
3683 …get_string(&req->msgptr, req->msgend, ctrl_path, MAX_CTLPATH); // path is first element in message… in read_msg()
3692 if (req->errsd == req->sd) in read_msg()
3693 …{ LogMsg("%3d: read_msg: ERROR failed to get errsd via SCM_RIGHTS", req->sd); req->ts = t_error; r… in read_msg()
3698 req->errsd = socket(AF_DNSSD, SOCK_STREAM, 0); in read_msg()
3699 if (!dnssd_SocketValid(req->errsd)) { my_perror("ERROR: socket"); req->ts = t_error; return; } in read_msg()
3701 if (connect(req->errsd, (struct sockaddr *)&cliaddr, sizeof(cliaddr)) < 0) in read_msg()
3706 req->sd, cliaddr.sun_path, dnssd_errno, dnssd_strerror(dnssd_errno)); in read_msg()
3708 …LogMsg("%3d: read_msg: stat failed “%s” errno %d (%s)", req->sd, cliaddr.sun_path, dnssd_errno, dn… in read_msg()
3710 …LogMsg("%3d: read_msg: file “%s” mode %o (octal) uid %d gid %d", req->sd, cliaddr.sun_path, sb.st_… in read_msg()
3712 req->ts = t_error; in read_msg()
3719 …ion("%3d: Error socket %d created %08X %08X", req->sd, req->errsd, req->hdr.client_context.u32[1],… in read_msg()
3721 if (ioctlsocket(req->errsd, FIONBIO, &opt) != 0) in read_msg()
3723 if (fcntl(req->errsd, F_SETFL, fcntl(req->errsd, F_GETFL, 0) | O_NONBLOCK) != 0) in read_msg()
3726 LogMsg("%3d: ERROR: could not set control socket to non-blocking mode errno %d (%s)", in read_msg()
3727 req->sd, dnssd_errno, dnssd_strerror(dnssd_errno)); in read_msg()
3728 req->ts = t_error; in read_msg()
3733 req->ts = t_complete; in read_msg()
3740 LogMsg("%3d: ERROR: read_msg errno %d (%s)", req->sd, dnssd_errno, dnssd_strerror(dnssd_errno)); in read_msg()
3741 req->ts = t_error; in read_msg()
3761 if (req->ts == t_morecoming) return; in request_callback()
3762 if (req->ts == t_terminated || req->ts == t_error) { AbortUnlinkAndFree(req); return; } in request_callback()
3763 …if (req->ts != t_complete) { LogMsg("req->ts %d != t_complete", req->ts); AbortUnlinkAndFree(req);… in request_callback()
3765 if (req->hdr.version != VERSION) in request_callback()
3767 … LogMsg("ERROR: client version %d incompatible with daemon version %d", req->hdr.version, VERSION); in request_callback()
3772 switch(req->hdr.op) // Interface + other data in request_callback()
3792 …default: LogMsg("ERROR: validate_message - unsupported req type: %d", req->hdr.op); min_size = -1;… in request_callback()
3795 if ((mDNSs32)req->data_bytes < min_size) in request_callback()
3796 …{ LogMsg("Invalid message %d bytes; min for %d is %d", req->data_bytes, req->hdr.op, min_size); Ab… in request_callback()
3798 if (LightweightOp(req->hdr.op) && !req->terminate) in request_callback()
3799 …{ LogMsg("Reg/Add/Update/Remove %d require existing connection", req->hdr.op); Ab… in request_callback()
3802 if (req->hdr.ipc_flags & IPC_FLAGS_NOREPLY) req->no_reply = 1; in request_callback()
3804 // If req->terminate is already set, this means this operation is sharing an existing connection in request_callback()
3805 if (req->terminate && !LightweightOp(req->hdr.op)) in request_callback()
3808 newreq->primary = req; in request_callback()
3809 newreq->sd = req->sd; in request_callback()
3810 newreq->errsd = req->errsd; in request_callback()
3811 newreq->uid = req->uid; in request_callback()
3812 newreq->hdr = req->hdr; in request_callback()
3813 newreq->msgbuf = req->msgbuf; in request_callback()
3814 newreq->msgptr = req->msgptr; in request_callback()
3815 newreq->msgend = req->msgend; in request_callback()
3821 …if (mDNSStorage.ShutdownTime && req->hdr.op != cancel_request && req->hdr.op != getproperty_reques… in request_callback()
3825 else switch(req->hdr.op) in request_callback()
3827 // These are all operations that have their own first-class request_state object in request_callback()
3828 … case connection_request: LogOperation("%3d: DNSServiceCreateConnection START", req->sd); in request_callback()
3829 req->terminate = connection_termination; break; in request_callback()
3849 default: LogMsg("%3d: ERROR: Unsupported UDS req: %d", req->sd, req->hdr.op); in request_callback()
3852 // req->msgbuf may be NULL, e.g. for connection_request or remove_record_request in request_callback()
3853 if (req->msgbuf) freeL("request_state msgbuf", req->msgbuf); in request_callback()
3857 …if (req->hdr.op != cancel_request && req->hdr.op != getproperty_request && req->hdr.op != send_bpf) in request_callback()
3860 send_all(req->errsd, (const char *)&err_netorder, sizeof(err_netorder)); in request_callback()
3861 if (req->errsd != req->sd) in request_callback()
3864 req->sd, req->errsd, req->hdr.client_context.u32[1], req->hdr.client_context.u32[0], err); in request_callback()
3865 dnssd_close(req->errsd); in request_callback()
3866 req->errsd = req->sd; in request_callback()
3868 if (req->primary) req->primary->errsd = req->primary->sd; in request_callback()
3873 if (req->primary) req = req->primary; in request_callback()
3874 req->ts = t_morecoming; in request_callback()
3875 req->hdr_bytes = 0; in request_callback()
3876 req->data_bytes = 0; in request_callback()
3877 req->msgbuf = mDNSNULL; in request_callback()
3878 req->msgptr = mDNSNULL; in request_callback()
3879 req->msgend = 0; in request_callback()
3904 …LogMsg("%3d: WARNING: setsockopt - SO_NOSIGPIPE %d (%s)", sd, dnssd_errno, dnssd_strerror(dnssd_er… in connect_callback()
3913 my_perror("ERROR: fcntl(sd, F_SETFL, O_NONBLOCK) - aborting client"); in connect_callback()
3920 request->ts = t_morecoming; in connect_callback()
3921 request->sd = sd; in connect_callback()
3922 request->errsd = sd; in connect_callback()
3926 …0, LOCAL_PEERCRED, &x, &xucredlen) >= 0 && x.cr_version == XUCRED_VERSION) request->uid = x.cr_uid; in connect_callback()
3930 LogOperation("%3d: Adding FD for uid %u", request->sd, request->uid); in connect_callback()
3931 udsSupportAddFDToEventLoop(sd, request_callback, request, &request->platform_data); in connect_callback()
3943 my_perror("WARNING: could not set sockopt - SO_NP_EXTENSIONS"); in uds_socket_setup()
3947 // This socket will be given to WSAEventSelect which will automatically set it to non-blocking in uds_socket_setup()
3954 my_perror("ERROR: could not set listen socket to non-blocking mode"); in uds_socket_setup()
4080 …Add "local" as recommended registration domain ("dns-sd -E"), recommended browsing domain ("dns-sd… in udsserver_init()
4091 return -1; in udsserver_init()
4104 LocalDomainEnumRecords = LocalDomainEnumRecords->next; in udsserver_exit()
4105 mDNS_Deregister(&mDNSStorage, &rem->ar); in udsserver_exit()
4130 if (req->primary) mDNS_snprintf(prefix, sizeof(prefix), " -> "); in LogClientInfo()
4131 else mDNS_snprintf(prefix, sizeof(prefix), "%3d:", req->sd); in LogClientInfo()
4133 usleep((m->KnownBugs & mDNS_KnownBug_LossySyslog) ? 3333 : 1000); in LogClientInfo()
4135 if (!req->terminate) in LogClientInfo()
4137 else if (req->terminate == connection_termination) in LogClientInfo()
4142 for (p = req->u.reg_recs; p; p=p->next) num_records++; in LogClientInfo()
4143 for (r = req->next; r; r=r->next) if (r->primary == req) num_ops++; in LogClientInfo()
4147 for (p = req->u.reg_recs; p; p=p->next) in LogClientInfo()
4148 LogMsgNoIdent(" -> DNSServiceRegisterRecord %3d %s", p->key, ARDisplayString(m, p->rr)); in LogClientInfo()
4149 for (r = req->next; r; r=r->next) if (r->primary == req) LogClientInfo(m, r); in LogClientInfo()
4151 else if (req->terminate == regservice_termination_callback) in LogClientInfo()
4154 for (ptr = req->u.servicereg.instances; ptr; ptr = ptr->next) in LogClientInfo()
4156 (ptr == req->u.servicereg.instances) ? prefix : " ", in LogClientInfo()
4157 ptr->srs.RR_SRV.resrec.name->c, mDNSVal16(req->u.servicereg.port), SRS_PORT(&ptr->srs)); in LogClientInfo()
4159 else if (req->terminate == browse_termination_callback) in LogClientInfo()
4162 for (blist = req->u.browser.browsers; blist; blist = blist->next) in LogClientInfo()
4163 …t("%s DNSServiceBrowse %##s", (blist == req->u.browser.browsers) ? prefix : " ", blis… in LogClientInfo()
4165 else if (req->terminate == resolve_termination_callback) in LogClientInfo()
4166 LogMsgNoIdent("%s DNSServiceResolve %##s", prefix, req->u.resolve.qsrv.qname.c); in LogClientInfo()
4167 else if (req->terminate == queryrecord_termination_callback) in LogClientInfo()
4168 …("%s DNSServiceQueryRecord %##s (%s)", prefix, req->u.queryrecord.q.qname.c, DNSTypeName(req-… in LogClientInfo()
4169 else if (req->terminate == enum_termination_callback) in LogClientInfo()
4170 LogMsgNoIdent("%s DNSServiceEnumerateDomains %##s", prefix, req->u.enumeration.q_all.qname.c); in LogClientInfo()
4171 else if (req->terminate == port_mapping_termination_callback) in LogClientInfo()
4174 &req->u.pm.NATinfo.ExternalAddress, in LogClientInfo()
4175 req->u.pm.NATinfo.Protocol & NATOp_MapTCP ? "TCP" : " ", in LogClientInfo()
4176 req->u.pm.NATinfo.Protocol & NATOp_MapUDP ? "UDP" : " ", in LogClientInfo()
4177 mDNSVal16(req->u.pm.NATinfo.IntPort), in LogClientInfo()
4178 mDNSVal16(req->u.pm.ReqExt), in LogClientInfo()
4179 mDNSVal16(req->u.pm.NATinfo.ExternalPort), in LogClientInfo()
4180 req->u.pm.NATinfo.NATLease, in LogClientInfo()
4181 req->u.pm.NATinfo.Lifetime); in LogClientInfo()
4182 else if (req->terminate == addrinfo_termination_callback) in LogClientInfo()
4184 req->u.addrinfo.protocol & kDNSServiceProtocol_IPv4 ? "v4" : " ", in LogClientInfo()
4185 req->u.addrinfo.protocol & kDNSServiceProtocol_IPv6 ? "v6" : " ", in LogClientInfo()
4186 req->u.addrinfo.q4.qname.c); in LogClientInfo()
4188 LogMsgNoIdent("%s Unrecognized operation %p", prefix, req->terminate); in LogClientInfo()
4218 if (m->rrauth.rrauth_hash[slot]) authslot++; in LogEtcHosts()
4219 for (ag = m->rrauth.rrauth_hash[slot]; ag; ag = ag->next) in LogEtcHosts()
4220 for (ar = ag->members; ar; ar = ar->next) in LogEtcHosts()
4222 if (ar->RecordCallback != FreeEtcHosts) continue; in LogEtcHosts()
4227 if (ar->ARType == AuthRecordLocalOnly) in LogEtcHosts()
4229 if (ar->resrec.InterfaceID == mDNSInterface_LocalOnly) in LogEtcHosts()
4230 LogMsgNoIdent(" %s LO %s", RecordTypeName(ar->resrec.RecordType), ARDisplayString(m, ar)); in LogEtcHosts()
4233 mDNSu32 scopeid = (mDNSu32)(uintptr_t)ar->resrec.InterfaceID; in LogEtcHosts()
4234 …LogMsgNoIdent(" %s %u %s", RecordTypeName(ar->resrec.RecordType), scopeid, ARDisplayString(m, a… in LogEtcHosts()
4237 usleep((m->KnownBugs & mDNS_KnownBug_LossySyslog) ? 3333 : 1000); in LogEtcHosts()
4242 …0 records, Total records %d, Total Auth Groups %d, Auth Slots %d>", count, m->rrauth.rrauth_totalu… in LogEtcHosts()
4254 for (ag = m->rrauth.rrauth_hash[slot]; ag; ag = ag->next) in LogLocalOnlyAuthRecords()
4255 for (ar = ag->members; ar; ar = ar->next) in LogLocalOnlyAuthRecords()
4257 if (ar->RecordCallback == FreeEtcHosts) continue; in LogLocalOnlyAuthRecords()
4261 if (ar->ARType == AuthRecordLocalOnly) in LogLocalOnlyAuthRecords()
4262 LogMsgNoIdent(" %s LO %s", RecordTypeName(ar->resrec.RecordType), ARDisplayString(m, ar)); in LogLocalOnlyAuthRecords()
4263 else if (ar->ARType == AuthRecordP2P) in LogLocalOnlyAuthRecords()
4264 LogMsgNoIdent(" %s PP %s", RecordTypeName(ar->resrec.RecordType), ARDisplayString(m, ar)); in LogLocalOnlyAuthRecords()
4265 usleep((m->KnownBugs & mDNS_KnownBug_LossySyslog) ? 3333 : 1000); in LogLocalOnlyAuthRecords()
4277 for (ar = ResourceRecords; ar; ar=ar->next) in LogAuthRecords()
4279 const char *const ifname = InterfaceNameForID(m, ar->resrec.InterfaceID); in LogAuthRecords()
4280 if ((ar->WakeUp.HMAC.l[0] != 0) == (proxy != mDNSNULL)) in LogAuthRecords()
4284 if (!mDNSPlatformMemSame(&owner, &ar->WakeUp, sizeof(owner))) in LogAuthRecords()
4286 owner = ar->WakeUp; in LogAuthRecords()
4288 …LogMsgNoIdent("Proxying for H-MAC %.6a I-MAC %.6a Password %.6a seq %d", &owner.HMAC, &owner.IMAC,… in LogAuthRecords()
4290 …LogMsgNoIdent("Proxying for H-MAC %.6a I-MAC %.6a seq %d", &owner.HMAC, &owner.IMAC,… in LogAuthRecords()
4296 ar->ThisAPInterval / mDNSPlatformOneSecond, in LogAuthRecords()
4297 (ar->LastAPTime + ar->ThisAPInterval - now) / mDNSPlatformOneSecond, in LogAuthRecords()
4298 ar->expire ? (ar->expire - now) / mDNSPlatformOneSecond : 0, in LogAuthRecords()
4299 ar->state, ARDisplayString(m, ar)); in LogAuthRecords()
4300 else if (ar->ARType == AuthRecordLocalOnly) in LogAuthRecords()
4302 else if (ar->ARType == AuthRecordP2P) in LogAuthRecords()
4306 ar->ThisAPInterval / mDNSPlatformOneSecond, in LogAuthRecords()
4307 ar->AnnounceCount ? (ar->LastAPTime + ar->ThisAPInterval - now) / mDNSPlatformOneSecond : 0, in LogAuthRecords()
4308 ar->TimeExpire ? (ar->TimeExpire - now) / mDNSPlatformOneSecond : 0, in LogAuthRecords()
4311 usleep((m->KnownBugs & mDNS_KnownBug_LossySyslog) ? 3333 : 1000); in LogAuthRecords()
4330 LogMsgNoIdent("------------ Cache -------------"); in udsserver_info()
4333 for (cg = m->rrcache_hash[slot]; cg; cg=cg->next) in udsserver_info()
4336 for (cr = cg->members; cr; cr=cr->next) in udsserver_info()
4338 const mDNSs32 remain = cr->resrec.rroriginalttl - (now - cr->TimeRcvd) / mDNSPlatformOneSecond; in udsserver_info()
4340 mDNSInterfaceID InterfaceID = cr->resrec.InterfaceID; in udsserver_info()
4341 if (!InterfaceID && cr->resrec.rDNSServer) in udsserver_info()
4342 InterfaceID = cr->resrec.rDNSServer->interface; in udsserver_info()
4345 if (cr->CRActiveQuestion) CacheActive++; in udsserver_info()
4346 LogMsgNoIdent("%3d %s%8ld %-7s%s %-6s%s", in udsserver_info()
4348 cr->CRActiveQuestion ? "*" : " ", in udsserver_info()
4350 ifname ? ifname : "-U-", in udsserver_info()
4351 (cr->resrec.RecordType == kDNSRecordTypePacketNegative) ? "-" : in udsserver_info()
4352 (cr->resrec.RecordType & kDNSRecordTypePacketUniqueMask) ? " " : "+", in udsserver_info()
4353 DNSTypeName(cr->resrec.rrtype), in udsserver_info()
4355 usleep((m->KnownBugs & mDNS_KnownBug_LossySyslog) ? 3333 : 1000); in udsserver_info()
4359 if (m->rrcache_totalused != CacheUsed) in udsserver_info()
4360 …LogMsgNoIdent("Cache use mismatch: rrcache_totalused is %lu, true count %lu", m->rrcache_totalused… in udsserver_info()
4361 if (m->rrcache_active != CacheActive) in udsserver_info()
4362 …LogMsgNoIdent("Cache use mismatch: rrcache_active is %lu, true count %lu", m->rrcache_active, Cach… in udsserver_info()
4365 LogMsgNoIdent("--------- Auth Records ---------"); in udsserver_info()
4366 LogAuthRecords(m, now, m->ResourceRecords, mDNSNULL); in udsserver_info()
4368 LogMsgNoIdent("--------- LocalOnly, P2P Auth Records ---------"); in udsserver_info()
4371 LogMsgNoIdent("--------- /etc/hosts ---------"); in udsserver_info()
4374 LogMsgNoIdent("------ Duplicate Records -------"); in udsserver_info()
4375 LogAuthRecords(m, now, m->DuplicateRecords, mDNSNULL); in udsserver_info()
4377 LogMsgNoIdent("----- Auth Records Proxied -----"); in udsserver_info()
4378 LogAuthRecords(m, now, m->ResourceRecords, &ProxyA); in udsserver_info()
4380 LogMsgNoIdent("-- Duplicate Records Proxied ---"); in udsserver_info()
4381 LogAuthRecords(m, now, m->DuplicateRecords, &ProxyD); in udsserver_info()
4383 LogMsgNoIdent("---------- Questions -----------"); in udsserver_info()
4384 if (!m->Questions) LogMsgNoIdent("<None>"); in udsserver_info()
4390 for (q = m->Questions; q; q=q->next) in udsserver_info()
4392 mDNSs32 i = q->ThisQInterval / mDNSPlatformOneSecond; in udsserver_info()
4393 mDNSs32 n = (NextQSendTime(q) - now) / mDNSPlatformOneSecond; in udsserver_info()
4394 char *ifname = InterfaceNameForID(m, q->InterfaceID); in udsserver_info()
4396 if (q->ThisQInterval) CacheActive++; in udsserver_info()
4397 LogMsgNoIdent("%6d%6d %-7s%s%s %5d 0x%x%x 0x%p 0x%p %1d %2d %-5s%##s%s", in udsserver_info()
4399 ifname ? ifname : mDNSOpaque16IsZero(q->TargetQID) ? "" : "-U-", in udsserver_info()
4400 mDNSOpaque16IsZero(q->TargetQID) ? (q->LongLived ? "l" : " ") : (q->LongLived ? "L" : "O"), in udsserver_info()
4402 q->CurrentAnswers, q->validDNSServers.l[1], q->validDNSServers.l[0], q, q->DuplicateOf, in udsserver_info()
4403 …q->SuppressUnusable, q->SuppressQuery, DNSTypeName(q->qtype), q->qname.c, q->DuplicateOf ? " (dup)… in udsserver_info()
4404 usleep((m->KnownBugs & mDNS_KnownBug_LossySyslog) ? 3333 : 1000); in udsserver_info()
4409 LogMsgNoIdent("----- Local-Only Questions -----"); in udsserver_info()
4410 if (!m->LocalOnlyQuestions) LogMsgNoIdent("<None>"); in udsserver_info()
4411 else for (q = m->LocalOnlyQuestions; q; q=q->next) in udsserver_info()
4412 LogMsgNoIdent(" %5d %-6s%##s%s", in udsserver_info()
4413 q->CurrentAnswers, DNSTypeName(q->qtype), q->qname.c, q->DuplicateOf ? " (dup)" : ""); in udsserver_info()
4415 LogMsgNoIdent("---- Active Client Requests ----"); in udsserver_info()
4420 for (req = all_requests; req; req=req->next) in udsserver_info()
4422 if (req->primary) // If this is a subbordinate operation, check that the parent is in the list in udsserver_info()
4424 for (r = all_requests; r && r != req; r=r->next) if (r == req->primary) goto foundparent; in udsserver_info()
4425 LogMsgNoIdent("%3d: Orhpan operation %p; parent %p not found in request list", req->sd); in udsserver_info()
4427 …// For non-subbordinate operations, and subbordinate operations that have lost their parent, write… in udsserver_info()
4433 LogMsgNoIdent("-------- NAT Traversals --------"); in udsserver_info()
4434 if (!m->NATTraversals) LogMsgNoIdent("<None>"); in udsserver_info()
4438 for (nat = m->NATTraversals; nat; nat=nat->next) in udsserver_info()
4440 if (nat->Protocol) in udsserver_info()
4442 nat, nat->Protocol == NATOp_MapTCP ? "TCP" : "UDP", in udsserver_info()
4443 mDNSVal16(nat->IntPort), mDNSVal16(nat->ExternalPort), nat->Result, in udsserver_info()
4444 nat->retryPortMap ? (nat->retryPortMap - now) / mDNSPlatformOneSecond : 0, in udsserver_info()
4445 nat->retryInterval / mDNSPlatformOneSecond, in udsserver_info()
4446 nat->ExpiryTime ? (nat->ExpiryTime - now) / mDNSPlatformOneSecond : 0); in udsserver_info()
4449 (m->retryGetAddr - now) / mDNSPlatformOneSecond, in udsserver_info()
4450 m->retryIntervalGetAddr / mDNSPlatformOneSecond); in udsserver_info()
4451 usleep((m->KnownBugs & mDNS_KnownBug_LossySyslog) ? 3333 : 1000); in udsserver_info()
4455 LogMsgNoIdent("--------- AuthInfoList ---------"); in udsserver_info()
4456 if (!m->AuthInfoList) LogMsgNoIdent("<None>"); in udsserver_info()
4460 for (a = m->AuthInfoList; a; a = a->next) in udsserver_info()
4461 …ent("%##s %##s %##s %d %s", a->domain.c, a->keyname.c, a->hostname.c, (a->port.b[0] << 8 | a->port… in udsserver_info()
4465 LogMsgNoIdent("--------- TunnelClients --------"); in udsserver_info()
4466 if (!m->TunnelClients) LogMsgNoIdent("<None>"); in udsserver_info()
4470 for (c = m->TunnelClients; c; c = c->next) in udsserver_info()
4472 …c->prefix, c->dstname.c, &c->loc_inner, &c->loc_outer, &c->loc_outer6, &c->rmt_inner, &c->rmt_oute… in udsserver_info()
4476 LogMsgNoIdent("---------- Misc State ----------"); in udsserver_info()
4478 LogMsgNoIdent("PrimaryMAC: %.6a", &m->PrimaryMAC); in udsserver_info()
4480 LogMsgNoIdent("m->SleepState %d (%s) seq %d", in udsserver_info()
4481 m->SleepState, in udsserver_info()
4482 m->SleepState == SleepState_Awake ? "Awake" : in udsserver_info()
4483 m->SleepState == SleepState_Transferring ? "Transferring" : in udsserver_info()
4484 m->SleepState == SleepState_Sleeping ? "Sleeping" : "?", in udsserver_info()
4485 m->SleepSeqNum); in udsserver_info()
4487 if (!m->SPSSocket) LogMsgNoIdent("Not offering Sleep Proxy Service"); in udsserver_info()
4488 else LogMsgNoIdent("Offering Sleep Proxy Service: %#s", m->SPSRecords.RR_SRV.resrec.name->c); in udsserver_info()
4490 …if (m->ProxyRecords == ProxyA + ProxyD) LogMsgNoIdent("ProxyRecords: %d + %d = %d", ProxyA, ProxyD… in udsserver_info()
4491 …else LogMsgNoIdent("ProxyRecords: MISMATCH %d + %d = %d ≠ %d", ProxyA, ProxyD, ProxyA + ProxyD, m-… in udsserver_info()
4493 LogMsgNoIdent("------ Auto Browse Domains -----"); in udsserver_info()
4495 else for (d=AutoBrowseDomains; d; d=d->next) LogMsgNoIdent("%##s", d->name.c); in udsserver_info()
4497 LogMsgNoIdent("--- Auto Registration Domains --"); in udsserver_info()
4499 else for (d=AutoRegistrationDomains; d; d=d->next) LogMsgNoIdent("%##s", d->name.c); in udsserver_info()
4501 LogMsgNoIdent("--- Search Domains --"); in udsserver_info()
4505 for (s=SearchList; s; s=s->next) in udsserver_info()
4507 char *ifname = InterfaceNameForID(m, s->InterfaceID); in udsserver_info()
4508 LogMsgNoIdent("%##s %s", s->domain.c, ifname ? ifname : ""); in udsserver_info()
4512 LogMsgNoIdent("---- Task Scheduling Timers ----"); in udsserver_info()
4514 if (!m->NewQuestions) in udsserver_info()
4518 m->NewQuestions->DelayAnswering, m->NewQuestions->DelayAnswering-now, in udsserver_info()
4519 m->NewQuestions->qname.c, DNSTypeName(m->NewQuestions->qtype)); in udsserver_info()
4521 if (!m->NewLocalOnlyQuestions) in udsserver_info()
4525 m->NewLocalOnlyQuestions->qname.c, DNSTypeName(m->NewLocalOnlyQuestions->qtype)); in udsserver_info()
4527 if (!m->NewLocalRecords) in udsserver_info()
4530 …LogMsgNoIdent("NewLocalRecords %02X %s", m->NewLocalRecords->resrec.RecordType, ARDisplayString(m,… in udsserver_info()
4532 LogMsgNoIdent("SPSProxyListChanged%s", m->SPSProxyListChanged ? "" : " <NONE>"); in udsserver_info()
4533 LogMsgNoIdent("LocalRemoveEvents%s", m->LocalRemoveEvents ? "" : " <NONE>"); in udsserver_info()
4534 LogMsgNoIdent("m->RegisterAutoTunnel6 %08X", m->RegisterAutoTunnel6); in udsserver_info()
4535 LogMsgNoIdent("m->AutoTunnelRelayAddrIn %.16a", &m->AutoTunnelRelayAddrIn); in udsserver_info()
4536 LogMsgNoIdent("m->AutoTunnelRelayAddrOut %.16a", &m->AutoTunnelRelayAddrOut); in udsserver_info()
4538 #define LogTimer(MSG,T) LogMsgNoIdent( MSG " %08X %11d %08X %11d", (T), (T), (T)-now, (T)-now) in udsserver_info()
4541 LogMsgNoIdent("m->timenow %08X %11d", now, now); in udsserver_info()
4542 LogMsgNoIdent("m->timenow_adjust %08X %11d", m->timenow_adjust, m->timenow_adjust); in udsserver_info()
4543 LogTimer("m->NextScheduledEvent ", m->NextScheduledEvent); in udsserver_info()
4546 LogTimer("m->NextuDNSEvent ", m->NextuDNSEvent); in udsserver_info()
4547 LogTimer("m->NextSRVUpdate ", m->NextSRVUpdate); in udsserver_info()
4548 LogTimer("m->NextScheduledNATOp ", m->NextScheduledNATOp); in udsserver_info()
4549 LogTimer("m->retryGetAddr ", m->retryGetAddr); in udsserver_info()
4552 LogTimer("m->NextCacheCheck ", m->NextCacheCheck); in udsserver_info()
4553 LogTimer("m->NextScheduledSPS ", m->NextScheduledSPS); in udsserver_info()
4554 LogTimer("m->NextScheduledSPRetry ", m->NextScheduledSPRetry); in udsserver_info()
4555 LogTimer("m->DelaySleep ", m->DelaySleep); in udsserver_info()
4557 LogTimer("m->NextScheduledQuery ", m->NextScheduledQuery); in udsserver_info()
4558 LogTimer("m->NextScheduledProbe ", m->NextScheduledProbe); in udsserver_info()
4559 LogTimer("m->NextScheduledResponse", m->NextScheduledResponse); in udsserver_info()
4561 LogTimer("m->SuppressSending ", m->SuppressSending); in udsserver_info()
4562 LogTimer("m->SuppressProbes ", m->SuppressProbes); in udsserver_info()
4563 LogTimer("m->ProbeFailTime ", m->ProbeFailTime); in udsserver_info()
4564 LogTimer("m->DelaySleep ", m->DelaySleep); in udsserver_info()
4565 LogTimer("m->SleepLimit ", m->SleepLimit); in udsserver_info()
4566 LogTimer("m->NextScheduledStopTime ", m->NextScheduledStopTime); in udsserver_info()
4573 for (req = all_requests; req; req=req->next) in uds_validatelists()
4575 if (req->next == (request_state *)~0 || (req->sd < 0 && req->sd != -2)) in uds_validatelists()
4576 LogMemCorruption("UDS request list: %p is garbage (%d)", req, req->sd); in uds_validatelists()
4578 if (req->primary == req) in uds_validatelists()
4579 LogMemCorruption("UDS request list: req->primary should not point to self %p/%d", req, req->sd); in uds_validatelists()
4581 if (req->primary && req->replies) in uds_validatelists()
4583 req, req->sd, req->primary && req->replies); in uds_validatelists()
4585 p = req->primary; in uds_validatelists()
4587 LogMemCorruption("UDS request list: req %p primary %p is misaligned (%d)", req, p, req->sd); in uds_validatelists()
4588 else if (p && (p->next == (request_state *)~0 || (p->sd < 0 && p->sd != -2))) in uds_validatelists()
4589 LogMemCorruption("UDS request list: req %p primary %p is garbage (%d)", req, p, p->sd); in uds_validatelists()
4592 for (rep = req->replies; rep; rep=rep->next) in uds_validatelists()
4593 if (rep->next == (reply_state *)~0) in uds_validatelists()
4594 LogMemCorruption("UDS req->replies: %p is garbage", rep); in uds_validatelists()
4596 if (req->terminate == connection_termination) in uds_validatelists()
4599 for (r = req->u.reg_recs; r; r=r->next) in uds_validatelists()
4600 if (r->next == (registered_record_entry *)~0) in uds_validatelists()
4601 LogMemCorruption("UDS req->u.reg_recs: %p is garbage", r); in uds_validatelists()
4603 else if (req->terminate == regservice_termination_callback) in uds_validatelists()
4606 for (s = req->u.servicereg.instances; s; s=s->next) in uds_validatelists()
4607 if (s->next == (service_instance *)~0) in uds_validatelists()
4608 LogMemCorruption("UDS req->u.servicereg.instances: %p is garbage", s); in uds_validatelists()
4610 else if (req->terminate == browse_termination_callback) in uds_validatelists()
4613 for (b = req->u.browser.browsers; b; b=b->next) in uds_validatelists()
4614 if (b->next == (browser_t *)~0) in uds_validatelists()
4615 LogMemCorruption("UDS req->u.browser.browsers: %p is garbage", b); in uds_validatelists()
4620 for (d = SCPrefBrowseDomains; d; d=d->next) in uds_validatelists()
4621 if (d->next == (DNameListElem *)~0 || d->name.c[0] > 63) in uds_validatelists()
4622 LogMemCorruption("SCPrefBrowseDomains: %p is garbage (%d)", d, d->name.c[0]); in uds_validatelists()
4625 for (b = LocalDomainEnumRecords; b; b=b->next) in uds_validatelists()
4626 if (b->next == (ARListElem *)~0 || b->ar.resrec.name->c[0] > 63) in uds_validatelists()
4627 LogMemCorruption("LocalDomainEnumRecords: %p is garbage (%d)", b, b->ar.resrec.name->c[0]); in uds_validatelists()
4629 for (d = AutoBrowseDomains; d; d=d->next) in uds_validatelists()
4630 if (d->next == (DNameListElem *)~0 || d->name.c[0] > 63) in uds_validatelists()
4631 LogMemCorruption("AutoBrowseDomains: %p is garbage (%d)", d, d->name.c[0]); in uds_validatelists()
4633 for (d = AutoRegistrationDomains; d; d=d->next) in uds_validatelists()
4634 if (d->next == (DNameListElem *)~0 || d->name.c[0] > 63) in uds_validatelists()
4635 LogMemCorruption("AutoRegistrationDomains: %p is garbage (%d)", d, d->name.c[0]); in uds_validatelists()
4641 reply_state *const rep = req->replies; // Send the first waiting reply in send_msg()
4643 if (req->no_reply) return(t_complete); in send_msg()
4645 ConvertHeaderBytes(rep->mhdr); in send_msg()
4646 nwriten = send(req->sd, (char *)&rep->mhdr + rep->nwriten, rep->totallen - rep->nwriten, 0); in send_msg()
4647 ConvertHeaderBytes(rep->mhdr); in send_msg()
4656 return(req->ts = t_terminated); in send_msg()
4661 … rep->totallen - rep->nwriten, rep->totallen, req->sd, dnssd_errno, dnssd_strerror(dnssd_errno)); in send_msg()
4666 rep->nwriten += nwriten; in send_msg()
4667 return (rep->nwriten == rep->totallen) ? t_complete : t_morecoming; in send_msg()
4679 if (r->terminate == resolve_termination_callback) in udsserver_idle()
4680 if (r->u.resolve.ReportTime && now - r->u.resolve.ReportTime >= 0) in udsserver_idle()
4682 r->u.resolve.ReportTime = 0; in udsserver_idle()
4684 "This places considerable burden on the network.", r->u.resolve.qsrv.qname.c); in udsserver_idle()
4688 while (r->replies) // Send queued replies in udsserver_idle()
4691 if (r->replies->next) r->replies->rhdr->flags |= dnssd_htonl(kDNSServiceFlagsMoreComing); in udsserver_idle()
4695 reply_state *fptr = r->replies; in udsserver_idle()
4696 r->replies = r->replies->next; in udsserver_idle()
4698 r->time_blocked = 0; // reset failure counter after successful send in udsserver_idle()
4699 r->unresponsiveness_reports = 0; in udsserver_idle()
4704 LogMsg("%3d: Could not write data to client because of error - aborting connection", r->sd); in udsserver_idle()
4711 if (r->replies) // If we failed to send everything, check our time_blocked timer in udsserver_idle()
4713 if (nextevent - now > mDNSPlatformOneSecond) nextevent = now + mDNSPlatformOneSecond; in udsserver_idle()
4715 if (mDNSStorage.SleepState != SleepState_Awake) r->time_blocked = 0; in udsserver_idle()
4716 else if (!r->time_blocked) r->time_blocked = NonZeroTime(now); in udsserver_idle()
4717 else if (now - r->time_blocked >= 10 * mDNSPlatformOneSecond * (r->unresponsiveness_reports+1)) in udsserver_idle()
4720 struct reply_state *x = r->replies; in udsserver_idle()
4721 while (x) { num++; x=x->next; } in udsserver_idle()
4723 r->sd, (now - r->time_blocked) / mDNSPlatformOneSecond, num, num == 1 ? "y" : "ies"); in udsserver_idle()
4724 if (++r->unresponsiveness_reports >= 60) in udsserver_idle()
4726 LogMsg("%3d: Client unresponsive; aborting connection", r->sd); in udsserver_idle()
4733 …if (!dnssd_SocketValid(r->sd)) // If this request is finished, unlink it from the list and free th… in udsserver_idle()
4736 *req = r->next; in udsserver_idle()
4740 req = &r->next; in udsserver_idle()
4747 // Check our structures are reasonable sizes. Including overly-large buffers, or embedding
4748 // other overly-large structures instead of having a pointer to them, can inadvertently
4750 char sizecheck_request_state [(sizeof(request_state) <= 1784) ? 1 : -1];
4751 char sizecheck_registered_record_entry[(sizeof(registered_record_entry) <= 60) ? 1 : -1];
4752 char sizecheck_service_instance [(sizeof(service_instance) <= 6552) ? 1 : -1];
4753 char sizecheck_browser_t [(sizeof(browser_t) <= 1050) ? 1 : -1];
4754 char sizecheck_reply_hdr [(sizeof(reply_hdr) <= 12) ? 1 : -1];
4755 char sizecheck_reply_state [(sizeof(reply_state) <= 64) ? 1 : -1];