Add debug output for service_timeout Signed-off-by: Philipp Meier <philipp.meier@neratec.com>
Support specifying instance name in JSON file So far we were using host label as the instance name for every service. This change allows specifying it manually and fallbacks to the label for backward compatibility. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
Allow filtering with instance name in service_reply This will allow sending replies more flexibly. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Store instance name in the struct service This will allow using custom instace names in the future. Right now we always set it to the host-specific label so there is no behavior change yet with this patch. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rename service_name function to the service_instance_name This name matches what is really returned by the function according to the RFC 6763. Also document it while at it. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rename mdns_hostname variable to the umdns_host_label In the whole RFC 6762 document "host name" means a fully qualified domain name. The value we store in this variable is just a first label of the name so rename it properly to make the code just a bit easier to follow. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Use one define for DNS-Based Service Discovery service name Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Use unicast IP address when sending unicast service reply For each protocol (IPv4 and IPv6) we have two interfaces (sockets): one for unicast and one for multicast. If we noticed CLASS_UNICAST in the multicast query we were switching to unicast interface for sending reply. The problem was not passing destination IP address. It was resulting in sending packet to multicast IP using unicast interface. As we don't set IP_MULTICAST_TTL / IPV6_MULTICAST_HOPS for unicast ones TTL was 1 and packets were ignored. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Prepare support for sending unicast DNS answers This adds extra argument to dns_send_answer & interface_send_packet functions. For now we pass NULL-s only. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Print error if parsing service JSON fails Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Make sdudp string const It musn't be changed. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Load service JSONs from /etc/umdns/ It matches recent project rename & uses directory that sholud be persistent. Using /tmp/ could result in user having to setup JSONs after every reboot. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
Drop one-liner service_announce function Now we have service_announce simplified so much there is no reason to keep it as a helper. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
Don't use _services._dns-sd._tcp.local It seems mdns(d) was trying to support queries for two records with following names: 1) _services._dns-sd._udp.local 2) _services._dns-sd._tcp.local According to the RFC 6763 Section 9 only the first one should be used and response PTR records should include services of both protocols: UDP and TCP. This fixes discovering TCP services as in practice no other software was sending queries with _services._dns-sd._tcp.local. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
Simplify UDP vs. TCP handling in service_announce_services Out of 3 calls of this function only one doesn't have TCP vs. UDP hardcoded. It's easier to move string check to that place and make this function take "int tcp" argument instead. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Check correct attributes when loading service from blob We access SERVICE_TXT so we should check for this entry. Checking SERVICE_SERVICE doesn't make sense anyway as it's verified few lines above (in the same funcion). Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
Avoid duplicated iteration over services when announcing In function service_announce_services we iterate over services and handle every single one so calling service_reply which also iterates doesn't make sense. In simple cases it was just wasting CPU cycles. We got service, we were passing its name and we were looking for it again comparing names. In cases with one service available on few different ports it was worse. For every iterated service we were announcing that one and all other sharing the same name. It resulted in sending n^2 records. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
Move matching logic out of service_reply_single function There is only 1 place in project calling this function with the match argument. It's easier to add prooper condition in this place and have service_reply_single simplified by taking 1 less argument. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Don't call dns_reply_a from service_reply This simplifies code without changing any behavior. Having this call in service_reply required checking two conditions and was making code flow harder to follow. There are 2 more service_reply calls in the project: 1) In service_announce_services where we iterate over &services and every element of this list has "service" field filled. It means match argument was never NULL and dns_reply_a was never called from there. 2) In parse_question which also receives some name (there is a proper check in the dns_handle_packet). No call there neither. So after all there was only 1 place that was indeed calling dns_reply_a. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
Rename service_reply_a to dns_reply_a and move it to proper file This function doesn't really do anything service specify, it just sends an A(AAA) records. It could probably be used even without any services registered. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>