diff options
| author | Felix Fietkau | 2025-05-28 22:22:02 +0000 |
|---|---|---|
| committer | Felix Fietkau | 2025-05-28 22:22:17 +0000 |
| commit | ce508467a533424f97d1c3f9997e19bb1a1900fb (patch) | |
| tree | a8877bfea514c9fc18ae11d1864a37975c7e3672 | |
| parent | 55d0c1bc1ac594af413e2d94a56e21b0d78346dc (diff) | |
| download | mdnsd-ce508467a533424f97d1c3f9997e19bb1a1900fb.tar.gz | |
service: add support for setting service specific hostname
Fixes: https://github.com/openwrt/mdnsd/issues/17
Signed-off-by: Felix Fietkau <nbd@nbd.name>
| -rw-r--r-- | service.c | 14 | ||||
| -rw-r--r-- | service.h | 1 |
2 files changed, 9 insertions, 6 deletions
@@ -94,7 +94,7 @@ service_add_srv(const char *name, struct service *s, int ttl) struct dns_srv_data *sd = (struct dns_srv_data *) mdns_buf; int len = sizeof(*sd); - len += dn_comp(mdns_hostname_local, mdns_buf + len, sizeof(mdns_buf) - len, NULL, NULL); + len += dn_comp(s->hostname, mdns_buf + len, sizeof(mdns_buf) - len, NULL, NULL); if (len <= sizeof(*sd)) return; @@ -124,7 +124,6 @@ service_reply_single(struct interface *iface, struct sockaddr *to, struct servic char *service = strstr(host, "._"); time_t t = service_timeout(s); - if (!force && (!s->active || !service || !t)) return; @@ -239,7 +238,7 @@ service_load_blob(struct blob_attr *b) { struct blob_attr *txt, *_tb[__SERVICE_MAX]; struct service *s; - char *d_instance, *d_service, *d_id; + char *d_instance, *d_hostname, *d_service, *d_id; uint8_t *d_txt; int rem2; int txt_len = 0; @@ -248,10 +247,8 @@ service_load_blob(struct blob_attr *b) blobmsg_parse(service_policy, ARRAY_SIZE(service_policy), _tb, blobmsg_data(b), blobmsg_data_len(b)); - if (_tb[SERVICE_HOSTNAME]) { + if (_tb[SERVICE_HOSTNAME]) service_load_hostname(_tb[SERVICE_HOSTNAME]); - return; - } if (!_tb[SERVICE_PORT] || !_tb[SERVICE_SERVICE]) return; @@ -263,6 +260,7 @@ service_load_blob(struct blob_attr *b) n = strlen(blobmsg_name(b)); s = calloc_a(sizeof(*s), &d_id, n + 1, + &d_hostname, _tb[SERVICE_HOSTNAME] ? strlen(blobmsg_get_string(_tb[SERVICE_HOSTNAME])) + 1 : 0, &d_instance, _tb[SERVICE_INSTANCE] ? strlen(blobmsg_get_string(_tb[SERVICE_INSTANCE])) + 1 : 0, &d_service, strlen(blobmsg_get_string(_tb[SERVICE_SERVICE])) + 1, &d_txt, txt_len); @@ -271,6 +269,10 @@ service_load_blob(struct blob_attr *b) s->port = blobmsg_get_u32(_tb[SERVICE_PORT]); s->id = strncpy(d_id, blobmsg_name(b), n); + if (_tb[SERVICE_HOSTNAME]) + s->hostname = strcpy(d_hostname, blobmsg_get_string(_tb[SERVICE_HOSTNAME])); + else + s->hostname = mdns_hostname_local; if (_tb[SERVICE_INSTANCE]) s->instance = strcpy(d_instance, blobmsg_get_string(_tb[SERVICE_INSTANCE])); else @@ -25,6 +25,7 @@ struct service { const char *id; const char *instance; const char *service; + const char *hostname; const uint8_t *txt; int txt_len; int port; |