Skip to content

Commit

Permalink
Display more srv attributes in output of ubus browse function.
Browse files Browse the repository at this point in the history
Namely: domain, ttl, last_update, priority and weight.

Signed-off-by: Mohd Husaam <[email protected]
  • Loading branch information
Mohd Husaam Mehdi committed Jan 14, 2024
1 parent e91ed40 commit bb9fd45
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,59 @@ cache_dump_records(struct blob_buf *buf, const char *name, int array,
if (hostname)
*hostname = (char *)r->rdata + sizeof(struct dns_srv_data);
}
if (r->port)
blobmsg_add_u32(buf, "port", r->port);


if (r->record) {
char *domain = NULL;
/*
* search for ._udp. or ._tcp. because:
* Service Instance Name = <InstanceName> . <Service> . <Domain>
* <Service> = _<ApplicationProtocol> . _<TransportProtocol>
* and, according to rfc6763, _<TransportProtocol> can be **tcp or udp only**
*/
domain = strstr(r->record, "._udp.");

/* udp not found */
if (!domain)
domain = strstr(r->record, "._tcp.");

/* tcp also not found, seems like a wrong record */
if (!domain) {
break;
}

/* tcp could have been used instead of udp, they have the same length */
domain = domain + strlen("._udp.");
blobmsg_add_string(buf, "domain", domain);

if (r->port)
blobmsg_add_u32(buf, "port", r->port);

if (r->ttl)
blobmsg_add_u32(buf, "ttl", r->ttl);

if (r->time) {
struct tm *local_time;
char str_tm[32] = {0};
/*
* last_update_real_seconds =
* current_real_seconds - (current_monotonic_seconds - srv_last_update_monotonic_seconds)
*/
time_t last_update = time(NULL) - (monotonic_time() - r->time);
local_time = localtime(&last_update);
strftime(str_tm, sizeof(str_tm), "%Y-%m-%dT%H:%M:%SZ", local_time);

blobmsg_add_string(buf, "last_update", str_tm);
}

const struct dns_srv_data *dsd = (const struct dns_srv_data*)r->rdata;

if (r->rdlength > sizeof(*dsd)) {
blobmsg_add_u32(buf, "priority", be16_to_cpu(dsd->priority));
blobmsg_add_u32(buf, "weight", be16_to_cpu(dsd->weight));
}
}

break;
}

Expand Down

0 comments on commit bb9fd45

Please sign in to comment.