[LEDE-DEV] [PATCH umdns 2/3] Allow filtering with instance name in service_reply

Rafał Miłecki zajec5 at gmail.com
Wed May 10 13:45:48 PDT 2017


From: Rafał Miłecki <rafal at milecki.pl>

This will allow sending replies more flexibly.

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 dns.c     | 4 ++--
 service.c | 9 ++++++---
 service.h | 2 +-
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/dns.c b/dns.c
index 68a088f..bccaa29 100644
--- a/dns.c
+++ b/dns.c
@@ -369,7 +369,7 @@ parse_question(struct interface *iface, struct sockaddr *from, char *name, struc
 	case TYPE_ANY:
 		if (!strcmp(name, mdns_hostname_local)) {
 			dns_reply_a(iface, to, announce_ttl);
-			service_reply(iface, to, NULL, announce_ttl);
+			service_reply(iface, to, NULL, NULL, announce_ttl);
 		}
 		break;
 
@@ -386,7 +386,7 @@ parse_question(struct interface *iface, struct sockaddr *from, char *name, struc
 			/* Make sure it's query for the instance name we use */
 			if (len && len == strlen(umdns_host_label) &&
 			    !strncmp(name, umdns_host_label, len))
-				service_reply(iface, to, dot + 1, announce_ttl);
+				service_reply(iface, to, NULL, dot + 1, announce_ttl);
 		}
 		break;
 
diff --git a/service.c b/service.c
index e6d9618..67e8f40 100644
--- a/service.c
+++ b/service.c
@@ -152,13 +152,16 @@ service_reply_single(struct interface *iface, struct sockaddr *to, struct servic
 }
 
 void
-service_reply(struct interface *iface, struct sockaddr *to, const char *match, int ttl)
+service_reply(struct interface *iface, struct sockaddr *to, const char *instance, const char *service_domain, int ttl)
 {
 	struct service *s;
 
 	vlist_for_each_element(&services, s, node) {
-		if (!match || !strcmp(s->service, match))
-			service_reply_single(iface, to, s, ttl, 0);
+		if (instance && strcmp(s->instance, instance))
+			continue;
+		if (service_domain && strcmp(s->service, service_domain))
+			continue;
+		service_reply_single(iface, to, s, ttl, 0);
 	}
 }
 
diff --git a/service.h b/service.h
index 086a0af..db8f374 100644
--- a/service.h
+++ b/service.h
@@ -16,7 +16,7 @@
 
 extern void service_init(int announce);
 extern void service_cleanup(void);
-extern void service_reply(struct interface *iface, struct sockaddr *to, const char *match, int ttl);
+extern void service_reply(struct interface *iface, struct sockaddr *to, const char *instance, const char *service_domain, int ttl);
 extern void service_announce_services(struct interface *iface, struct sockaddr *to, int ttl);
 
 #endif
-- 
2.11.0




More information about the Lede-dev mailing list