Skip to content

Commit fda8247

Browse files
rluboscfriedt
authored andcommitted
net: llmnr_responder: Align with dns_unpack_query() change
dns_unpack_query() no longer prepends the unpacked query with extra dot, therefore LLMNR responder needs to be aligned with this change when parsing result and preparing response. Signed-off-by: Robert Lubos <[email protected]>
1 parent 9e59229 commit fda8247

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

subsys/net/lib/dns/llmnr_responder.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -192,23 +192,19 @@ static void setup_dns_hdr(uint8_t *buf, uint16_t answers, uint16_t dns_id)
192192

193193
static void add_question(struct net_buf *query, enum dns_rr_type qtype)
194194
{
195-
char *dot = query->data + DNS_MSG_HEADER_SIZE;
196-
char *prev = NULL;
195+
char *dot = query->data + DNS_MSG_HEADER_SIZE + 1;
196+
char *prev = query->data + DNS_MSG_HEADER_SIZE;
197197
uint16_t offset;
198198

199-
while ((dot = strchr(dot, '.'))) {
200-
if (!prev) {
201-
prev = dot++;
202-
continue;
203-
}
199+
/* For the length of the first label. */
200+
query->len += 1;
204201

202+
while ((dot = strchr(dot, '.')) != NULL) {
205203
*prev = dot - prev - 1;
206204
prev = dot++;
207205
}
208206

209-
if (prev) {
210-
*prev = strlen(prev) - 1;
211-
}
207+
*prev = strlen(prev + 1);
212208

213209
offset = DNS_MSG_HEADER_SIZE + query->len + 1;
214210
UNALIGNED_PUT(htons(qtype), (uint16_t *)(query->data+offset));
@@ -245,14 +241,15 @@ static int create_answer(enum dns_rr_type qtype,
245241
/* Prepare the response into the query buffer: move the name
246242
* query buffer has to get enough free space: dns_hdr + query + answer
247243
*/
248-
if ((net_buf_max_len(query) - query->len) < (DNS_MSG_HEADER_SIZE +
244+
if ((net_buf_max_len(query) - query->len) < (DNS_MSG_HEADER_SIZE + 1 +
249245
(DNS_QTYPE_LEN + DNS_QCLASS_LEN) * 2 +
250246
DNS_TTL_LEN + DNS_RDLENGTH_LEN +
251247
addr_len + query->len)) {
252248
return -ENOBUFS;
253249
}
254250

255-
memmove(query->data + DNS_MSG_HEADER_SIZE, query->data, query->len);
251+
/* +1 for the initial label length */
252+
memmove(query->data + DNS_MSG_HEADER_SIZE + 1, query->data, query->len);
256253

257254
setup_dns_hdr(query->data, 1, dns_id);
258255

@@ -488,8 +485,8 @@ static int dns_read(int sock,
488485
result->data, ret);
489486

490487
/* If the query matches to our hostname, then send reply */
491-
if (!strncasecmp(hostname, result->data + 1, hostname_len) &&
492-
(result->len - 1) >= hostname_len) {
488+
if (!strncasecmp(hostname, result->data, hostname_len) &&
489+
(result->len) >= hostname_len) {
493490
NET_DBG("%s query to our hostname %s", "LLMNR",
494491
hostname);
495492
ret = send_response(sock, src_addr, addrlen, result, qtype,

0 commit comments

Comments
 (0)