问题原文
原帖链接 · ZaZa · CC BY-SA 4.0
I'm working on implementing a little DNS stub server, and I'm having trouble interpreting part of DNS RFC 1035.
The compression scheme allows a domain name in a message to be
represented as either:
- a sequence of labels ending in a zero octet
- a pointer
- a sequence of labels ending with a pointer
Is it valid for a DNS name to follow multiple pointers? i.e a sequence of labels ending with a pointer to a sequence of labels ending with a pointer, potentially multiple times. Or when using compression, it is only valid to have a sequence of labels ending with a pointer to a sequence of labels ending in a zero octet? Thanks.
已采纳解答
原帖链接 · Patrick Mevzek · CC BY-SA 4.0
Is it valid for a DNS name to follow multiple pointers?
Yes and No.
Imagine you have the names (not writing the end dot for each):
example.coma.example.comb.a.example.comc.example.com.example.net
They can be encoded, if in this order, as:
example+com+\0(2 labels + zero octet)a+ pointer to previous item- either:
b+ pointer to previous item (should be preferred, stronger compression)- or
b+a+ pointer to first item
c+example+com+example+net+\0
In last case you can not do c + pointer to first example.com because if you do so, then with example.com you go up to the final \0 and hence you are done, you encoded only c.example.com and NOT c.example.com.example.net.
Basically you can view compression as compressing suffixes. Not arbitrary compression anywhere in the name.
But third case variant 1 show you can follow multiple pointers: b + pointer to (a + pointer to (example + com + \0))
Section 4.1.4 of RFC 1035 has a full example:
For example, a datagram might need to use the domain names F.ISI.ARPA,
FOO.F.ISI.ARPA, ARPA, and the root. Ignoring the other fields of the
message, these domain names might be represented as:
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
20 | 1 | F |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
22 | 3 | I |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
24 | S | I |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
26 | 4 | A |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
28 | R | P |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
30 | A | 0 |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
40 | 3 | F |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
42 | O | O |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
44 | 1 1| 20 |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
64 | 1 1| 26 |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
92 | 0 | |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
The domain name for F.ISI.ARPA is shown at offset 20. The domain name
FOO.F.ISI.ARPA is shown at offset 40; this definition uses a pointer to
concatenate a label for FOO to the previously defined F.ISI.ARPA. The
domain name ARPA is defined at offset 64 using a pointer to the ARPA
component of the name F.ISI.ARPA at 20; note that this pointer relies on
ARPA being the last label in the string at 20. The root domain name is
defined by a single octet of zeros at 92; the root domain name has no
labels.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
