大网数据广告活动
服务器运维问答

Multiple levels of DNS name compression

· 52CE 我爱测

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…

问题原文

原帖链接 · 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.com
  • a.example.com
  • b.a.example.com
  • c.example.com.example.net

They can be encoded, if in this order, as:

  1. example + com + \0 (2 labels + zero octet)
  2. a + pointer to previous item
  3. either:
    1. b + pointer to previous item (should be preferred, stronger compression)
    2. or b + a + pointer to first item
  4. 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-03-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。