| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From: Uwe Kleine-König <uwe@kleine-koenig.org> |
| 2 | Date: Sat, 8 Oct 2022 19:22:52 +0200 |
| 3 | Subject: [PATCH] nslookup: ensure unique transaction IDs for the DNS queries |
| 4 | |
| 5 | The transaction IDs generated by res_mkquery() for both glibc and musl only |
| 6 | depends on the state of the monotonic clock. |
| 7 | For some machines (here: a TP-Link RE200 powered by a MediaTek MT7620A) |
| 8 | the monotonic clock has a coarse resolution (here: 20 µs) and it can happen |
| 9 | that the requests for A and AAAA share the same transaction ID. |
| 10 | |
| 11 | In that case the mapping from received responses to the sent queries |
| 12 | doesn't work and name resolution fails as follows: |
| 13 | |
| 14 | # /bin/busybox nslookup heise.de |
| 15 | Server: 127.0.0.1 |
| 16 | Address: 127.0.0.1:53 |
| 17 | |
| 18 | Non-authoritative answer: |
| 19 | Name: heise.de |
| 20 | Address: 193.99.144.80 |
| 21 | |
| 22 | *** Can't find heise.de: No answer |
| 23 | |
| 24 | because the AAAA reply is dropped as a duplicate reply to the A query. |
| 25 | |
| 26 | To prevent this make sure the transaction IDs are unique. |
| 27 | |
| 28 | Forwarded: http://lists.busybox.net/pipermail/busybox/2022-October/089911.html |
| 29 | --- |
| 30 | --- a/networking/nslookup.c |
| 31 | +++ b/networking/nslookup.c |
| 32 | @@ -978,6 +978,10 @@ int nslookup_main(int argc UNUSED_PARAM, |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | + /* Ensure the Transaction IDs are unique */ |
| 37 | + for (rc = 1; rc < G.query_count; rc++) |
| 38 | + G.query[rc].query[1] = G.query[rc - 1].query[1] + 1; |
| 39 | + |
| 40 | for (rc = 0; rc < G.serv_count;) { |
| 41 | int c; |
| 42 | |