原始来源:https://www.sharetechnote.com/html/Handbook_LTE_IPv6_Establish.html
正文
本节只从 NAS 信令和 NDP(Network Discovery Protocol,网络发现协议)的角度解释一种 IPv6 分配。如果您不熟悉一般 IP 分配(包括 PCO)以及 NDP 的作用,也请参阅以下页面。
-
IP 分配
-
PCO(Protocol Configuration Option,协议配置选项)
-
路由器发现 关于规范的更多细节,请参阅以下规范
-
3GPP 23.401 - 5.3.1.2.2 Allocation, renewal and release of the IPv6 default prefix via IPv6 stateless address autoconfiguration.
-
3GPP 23.060 - 9.2.1.1 Stateless IPv6 Address Autoconfiguration
-
3GPP 29.061-Figure 11bb: Ipv6 Stateless Address Autoconfiguration
-
3GPP 29.061-Figure 11bc: Ipv6 Stateless Address Autoconfiguration for GTP-based S5/S8
-
3GPP 29.061-Figure 11bd: Ipv6 Stateless Address Autoconfiguration for PMIP-based S5/S8
-
RFC4862 - IPv6 Stateless Address Autoconfiguration
-
RFC6459 - IPv6 in 3rd Generation Partnership Project (3GPP),Evolved Packet System (EPS) IPv6 的分配有几种不同方式。整体逻辑完全相同,但根据是用于 LTE 还是 WCDMA、是仅 IPv6 还是 IPv4v6 双栈,NAS 消息或 IE(Information Element,信息元素)的值会略有不同。
-
情形 1:LTE 中仅分配 IPv6
-
情形 2:WCDMA 中仅分配 IPv4v6
-
NAS 消息实际承载什么
-
参考资料 下面的图用四个步骤展示一次 LTE attach。UE 请求双栈承载,网络只回复 IPv6,而 UE 最终使用的地址根本不在 NAS 消息中。四步中有两步是 NAS,两步是 ICMPv6。

图注:(原页面未提供图示说明)
上图右侧的面板就是那两条 NAS 消息。PDN connectivity request 把其 PDN type 值设为 IPv4v6。它的 access point name 读作 03696D73,即一个长度字节后跟 ims。Activate default EPS bearer context request 以 PDN type 值 IPv6 应答,其 PDN address 的信息以 01 结尾。
该序列的最后两步在下面再次出现,这次展开了 ICMPv6 包。它们不携带 NAS,而是在用户面上、在默认承载刚刚建立的链路上运行。

图注:(原页面未提供图示说明)
- UE 请求的比得到的多:PDN connectivity request 携带 PDN type IPv4v6,而应答携带的是 PDN type IPv6。
- NAS 应答携带的是接口标识,而不是地址:PDN address 信息以 01 结尾,这就是网络所分配的全部内容。
- Router Solicitation 从 fe80::1 发往 ff02::2:源是 UE 根据 NAS 消息提供的接口标识构造出的链路本地地址。
- Router Advertisement 回到一个地址:从 fe80::200:ff:fe00:2 到 fe80::1,110 个字节,携带一个 prefix information option。
- 通告的前缀是 2001:0:0:2::,前缀长度为 64:valid lifetime 读作 2592000 秒,preferred lifetime 为 604800。 24.301 第 9.9.4.9 节说明该 NAS 元素能做什么。PDN address 元素可以给 UE 分配一个 IPv4 地址,并向 UE 提供一个用于构造 IPv6 链路本地地址的接口标识。对 PDN type IPv6,内容是第 4 至第 11 字节,这八个字节就是接口标识。该元素没有容纳前缀的空间。
23.401 第 5.3.1.2.2 节提供了另一半。PDN GW 通过 Router Advertisement 分配一个全局唯一的 64 位前缀。默认承载建立后,UE 可以发送 Router Solicitation 来促使该通告发出,而通告携带的是承载建立时提供的同一个前缀。
两半在抓包中相遇。接口标识以 01 结尾,因此链路本地地址是 fe80::1,solicitation 从它发出。通告的前缀是 2001:0:0:2::,前缀长度为 64。于是全局地址是 2001:0:0:2::1,对应一个保持相同接口标识的 UE。
图中省略了一个同样属于这里但在图外的字段。24.301 第 6.5.1.3 节要求:当网络限制 IP 版本时,Activate default EPS bearer context request 中必须带有 ESM cause。对仅允许 PDN type IPv6,该 cause 为 51;对仅允许单地址承载,为 52。面板只展开了该消息的三条分支,因此该 cause 不在视野内,而不是不存在。
- NAS 消息确定低 64 位:24.301 给 PDN type IPv6 一个 8 字节的接口标识,仅此而已。
- Router Advertisement 确定高 64:23.401 让 PDN GW 以这种方式分配一个全局唯一的 64 位前缀。
- 链路本地地址先出现:UE 需要先有一个链路本地地址才能发送 Router Solicitation,这就是接口标识要在 NAS 中传送的原因。
- 不需要重复地址检测:23.401 让通告的前缀全局唯一,因此链路上没有其他东西能持有相同地址。 同样的四步在 WCDMA 中运行,只是消息名称不同,内容上也有一处真实差异。这里的网络同时授予两种地址族,NAS 消息携带的是完整的 128 位 IPv6 地址,而不是接口标识。

图注:(原页面未提供图示说明)
上图右侧的面板是那两条会话管理消息。Activate PDP context request 携带一个 requested PDP address,其 PDP type 为 IPv4v6。它的 access point name 读作 0570686F6E65,即一个长度字节后跟 phone。Activate PDP context accept 携带的地址信息是 C0A89D0B2011000000000000010000000000000001。
这二十个字节分三部分。C0A89D0B 是 192.168.157.11。接下来的八个字节读作 2011:0:0:1,最后八个读作 0000000000000001,因此两者合起来是 2011:0:0:1::1。
步骤 3 和 4 在下面展示得更详细,就像 LTE 那样。

图注:(原页面未提供图示说明)
- requested PDP address 只给出类型而没有值:24.008 第 10.5.6.4 节规定,contents length 为 2 意味着不包含地址,采用动态寻址。
- accept 携带 22 字节内容:两个字节用于组织和类型,四个用于 IPv4 地址,十六个用于 IPv6 地址。这把该元素填到 24.008 允许的 24 字节。
- Router Solicitation 与 LTE 中的一致:从 fe80::1 到 ff02::2,62 字节,因此这个 UE 用同样的方式构造了它的链路本地地址。
- 通告的前缀重复了 NAS 地址:2011:0:0:1::,前缀长度 64,即 2011:0:0:1::1 的上半部分。
- flag 字节读作 0xC0:RFC 4861 第 4.6.2 节把 L 和 A 放在该字节的两个最高位,因此这个通告同时置位了两者。 29.061 第 11.2.1.3.2 节解释了这种重复。Router Advertisements 中发送的前缀应与 Create PDP Context Response 中返回的前缀相同,且应恰好包含一个前缀。因此这两个值的一致是出于要求,而非偶然。
同一节还要求两件这份抓包没做的事。它要求置位 A 标志并清除 L 标志,因为该前缀不应用于 on-link determination,而 0xC0 把两者都置位了。它还要求把前缀的 lifetime 设为无穷大,而该通告携带的是 2592000 和 604800 秒。这个框记录的是一个网络,并保持其原样。
29.061 第 11.2.1.3.2 节还确定了 NAS 地址的哪一半起作用。它说这种上下文的 IPv6 前缀仅由地址的 prefix 部分标识,MS 可以为接口标识部分选择任何值。唯一的例外是链路本地地址,其接口标识由 GGSN 分配,以免与 GGSN 自身的地址冲突。
Activate PDP Context Request
两条会话管理消息中的第一条,完整解码。它搭载在 RRC uplink direct transfer 中,因此框中的开头几行是 RRC 而非 NAS。要找的字段是 requested PDP address、access point name 和 protocol configuration options。
从 RRC uplink direct transfer 解码出的 Activate PDP Context Request 抓包。数值是某个网络实际发送的,并不是规范要求的值。
DLT: 147, Payload: rrc.ul.dcch (Radio Resource Control (RRC) protocol) UL-DCCH-Message integrityCheckInfo messageAuthenticationCode: 6bec984f [bit length 32, 0110 1011 1110 1100 1001 1000 0100 1111 decimal value 1810667599] rrc-MessageSequenceNumber: 1 message: uplinkDirectTransfer (27) uplinkDirectTransfer cn-DomainIdentity: ps-domain (1) nas-Message: 0a4105030e000000000000000000000000000002018d2806... GSM A-I/F DTAP - Activate PDP Context Request Protocol Discriminator: GPRS session management messages .... 1010 = Protocol discriminator: GPRS session management messages (0x0a) 0... .... = TI flag: allocated by sender .000 .... = TIO: 0 01.. .... = Sequence number: 1 DTAP GPRS Session Management Message Type: Activate PDP Context Request (0x41) Network Service Access Point Identifier - Requested NSAPI NSAPI: 0x05 (5) LLC Service Access Point Identifier - Requested LLC SAPI 0000 .... = Spare bit(s): 0 .... 0011 = LLC SAPI: SAPI 3 (3) Quality Of Service - Requested QoS Length: 14 00.. .... = Spare bit(s): 0 ..00 0... = Quality of Service Delay class: Subscribed delay class (in MS to network direction) (0) .... .000 = Reliability class: Subscribed reliability class (in MS to network direction) (0) 0000 .... = Peak throughput: Subscribed peak throughput/reserved (0) .... 0... = Spare bit(s): 0 .... .000 = Precedence class: Subscribed precedence/reserved (0) 000. .... = Spare bit(s): 0 ...0 0000 = Mean throughput: Subscribed peak throughput/reserved (0) 000. .... = Traffic class: Subscribed traffic class/Reserved (0) ...0 0... = Delivery order: Subscribed delivery order/Reserved (0) .... .000 = Delivery of erroneous SDUs: Subscribed delivery of erroneous SDUs/Reserved (0) Maximum SDU size: Subscribed maximum SDU size/reserved (0) Maximum bitrate for uplink: Subscribed maximum bit rate for uplink/reserved (0) Maximum bitrate for downlink: Subscribed maximum bit rate for downlink/reserved (0) 0000 .... = Residual Bit Error Rate (BER): Subscribed residual BER/Reserved (0) .... 0000 = SDU error ratio: Subscribed SDU error ratio/Reserved (0) 0000 00.. = Transfer delay: Subscribed transfer delay/reserved (0) .... ..00 = Traffic handling priority: Subscribed traffic handling priority/Reserved (0) Guaranteed bitrate for uplink: Subscribed guaranteed bit rate for uplink/reserved (0) Guaranteed bitrate for downlink: Subscribed guaranteed bit rate for downlink/reserved (0) 000. .... = Spare bit(s): 0 ...0 .... = Signalling indication: Not optimised for signalling traffic .... 0000 = Source statistics description: unknown (0) Maximum bitrate for downlink (extended): Use the value indicated by the Maximum bit rate for downlink (0) Guaranteed bitrate for downlink (extended): Use the value indicated by the Guaranteed bit rate for downlink (0) Packet Data Protocol Address - Requested PDP address Length: 2 0000 .... = Spare bit(s): 0 .... 0001 = PDP type organization: IETF allocated address (1) PDP type number: IPv4v6 address (141) Dynamic addressing Access Point Name Element ID: 0x28 Length: 6 APN: phone Protocol Configuration Options Element ID: 0x27 Length: 29 [Link direction: MS to network (0)] 1... .... = Extension: True Configuration Protocol: PPP for use with IP PDP type or IP PDN type (0) Protocol or Container ID: Internet Protocol Control Protocol (0x8021) Length: 0x10 (16) PPP IP Control Protocol Code: Configuration Request (1) Identifier: 0 (0x00) Length: 16 Options: (12 bytes), Primary DNS Server IP Address, Secondary DNS Server IP Address Primary DNS Server IP Address: 0.0.0.0 Type: Primary DNS Server IP Address (129) Length: 6 Primary DNS Address: 0.0.0.0 (0.0.0.0) Secondary DNS Server IP Address: 0.0.0.0 Type: Secondary DNS Server IP Address (131) Length: 6 Secondary DNS Address: 0.0.0.0 (0.0.0.0) Protocol or Container ID: DNS Server IPv4 Address Request (0x000d) Length: 0x00 (0) Protocol or Container ID: DNS Server IPv6 Address Request (0x0003) Length: 0x00 (0) Protocol or Container ID: MS Support of Network Requested Bearer Control indicator (0x0005) Length: 0x00 (0)
- NAS payload 可从其自身的十六进制串读出:nas-Message 以 0a4105030e 开头。这五个字节分别是 protocol discriminator、消息类型 0x41、NSAPI 5、LLC SAPI 3 和 QoS length 14。
- 每个请求的 QoS 值都读作 Subscribed:UE 没有特别要求什么,把整个 profile 留给网络决定。
- requested PDP address 长为两个字节:IPv4v6 且无值,24.008 将其解读为动态寻址。
- 三个容器以长度零上行:000D 对应 IPv4 DNS 服务器,0003 对应 IPv6 DNS 服务器,0005 对应 MS support of network requested bearer control indicator。 options 元素的长度可以核对。24.008 第 10.5.6.3 节给每个协议单元两个字节的标识、一个字节的长度然后是内容,容器也按同样方式编码。数一数:扩展位和配置协议占一个字节,IPCP 单元占十九个,三个容器各占三个。总数为 29,正是解码器打印的长度。
8021 下面的单元不是 3GPP 材料。同一节把每个协议单元的内容交给拥有该标识的 RFC,并称这些内容为去掉了协议和填充字节的 PPP packet。其中的 IPCP configuration request 把两个 DNS 选项都设为 0.0.0.0,因此它是运行在 NAS 消息中的 RFC 1332 材料。
Activate PDP Context Accept
应答,以同样方式解码。QoS 值现在是真实数字而不是 Subscribed 这个词,PDP address 携带两种地址族,options 元素同时在两条路径上作答。
从 RRC downlink direct transfer 解码出的 Activate PDP Context Accept 抓包。数值是某个网络实际发送的,并不是规范要求的值。
DLT: 147, Payload: rrc.dl.dcch (Radio Resource Control (RRC) protocol) DL-DCCH-Message integrityCheckInfo messageAuthenticationCode: 36d2872b [bit length 32, 0011 0110 1101 0010 1000 0111 0010 1011 decimal value 919766827] rrc-MessageSequenceNumber: 0 message: downlinkDirectTransfer (5) downlinkDirectTransfer: r3 (0) r3 downlinkDirectTransfer-r3 rrc-TransactionIdentifier: 0 cn-DomainIdentity: ps-domain (1) nas-Message: 8a42030e23920a9396d3fe7400407f005000012b16018dc0... GSM A-I/F DTAP - Activate PDP Context Accept Protocol Discriminator: GPRS session management messages .... 1010 = Protocol discriminator: GPRS session management messages (0x0a) 1... .... = TI flag: allocated by receiver .000 .... = TIO: 0 01.. .... = Sequence number: 1 DTAP GPRS Session Management Message Type: Activate PDP Context Accept (0x42) LLC Service Access Point Identifier - Negotiated LLC SAPI 0000 .... = Spare bit(s): 0 .... 0011 = LLC SAPI: SAPI 3 (3) Quality Of Service - Negotiated QoS Length: 14 00.. .... = Spare bit(s): 0 ..10 0... = Quality of Service Delay class: Delay class 4 (best effort) (4) .... .011 = Reliability class: Unacknowledged GTP/LLC, Ack RLC, Protected data (3) 1001 .... = Peak throughput: Up to 256 000 octet/s (9) .... 0... = Spare bit(s): 0 .... .010 = Precedence class: Normal priority (2) 000. .... = Spare bit(s): 0 ...0 1010 = Mean throughput: 100 000 octet/h (10) 100. .... = Traffic class: Background class (4) ...1 0... = Delivery order: Without delivery order ('no') (2) .... .011 = Delivery of erroneous SDUs: Erroneous SDUs are not delivered('No') (3) Maximum SDU size: 1500 octets (150) Maximum bitrate for uplink: 5888 kbps (211) Maximum bitrate for downlink: 8640 kbps (254) 0111 .... = Residual Bit Error Rate (BER): 1*10-5 (7) .... 0100 = SDU error ratio: 1*10-4 (4) 0000 00.. = Transfer delay: Subscribed transfer delay/reserved (0) .... ..00 = Traffic handling priority: Subscribed traffic handling priority/Reserved (0) Guaranteed bitrate for uplink: 64 kbps (64) Guaranteed bitrate for downlink: 568 kbps (127) 000. .... = Spare bit(s): 0 ...0 .... = Signalling indication: Not optimised for signalling traffic .... 0000 = Source statistics description: unknown (0) Maximum bitrate for downlink (extended): 22 Mbps (80) Guaranteed bitrate for downlink (extended): Use the value indicated by the Guaranteed bit rate for downlink (0) Radio Priority Radio Priority (PDP or SMS): priority level 1 (highest) (1) Packet Data Protocol Address - PDP address Element ID: 0x2b Length: 22 0000 .... = Spare bit(s): 0 .... 0001 = PDP type organization: IETF allocated address (1) PDP type number: IPv4v6 address (141) IPv4 address: 192.168.157.11 (192.168.157.11) IPv6 address: 2011:0:0:1::1 (2011:0:0:1::1) Protocol Configuration Options Element ID: 0x27 Length: 40 [Link direction: Network to MS (1)] 1... .... = Extension: True Configuration Protocol: PPP for use with IP PDP type or IP PDN type (0) Protocol or Container ID: Internet Protocol Control Protocol (0x8021) Length: 0x0a (10) PPP IP Control Protocol Code: Configuration Nak (3) Identifier: 0 (0x00) Length: 10 Options: (6 bytes), Primary DNS Server IP Address Primary DNS Server IP Address: 192.168.157.18 Type: Primary DNS Server IP Address (129) Length: 6 Primary DNS Address: 192.168.157.18 (192.168.157.18) Protocol or Container ID: DNS Server IPv4 Address (0x000d) Length: 0x04 (4) IPv4: 192.168.157.18 Protocol or Container ID: DNS Server IPv6 Address (0x0003) Length: 0x10 (16) IPv6: 2011:0:0:1::2
- QoS profile 到达时已填好:background 业务类,上行最大比特率 5888 kbps、下行 8640 kbps,扩展下行字段上为 22 Mbps。
- 两个地址一起到达:192.168.157.11 和 2011:0:0:1::1,位于同一个 22 字节的元素中。
- IPCP 应答是 Configuration Nak:UE 为两个 DNS 服务器都提议了 0.0.0.0,因此网络纠正了主 DNS,而不是确认该请求。
- PPP 路径上只返回主 DNS:options 字段是六个字节,而请求中是十二个。
- 容器 0005 没有返回:24.008 在下行把 0005 命名为 Selected Bearer Control Mode,其缺失使 MS 保持 bearer control mode 为 MS only。 下行 options 元素同样可以加总。再数一遍:扩展位和配置协议占一个字节,IPCP 单元占十三个,IPv4 DNS 容器占七个,IPv6 容器占十九个。总数为 40。
这里还有一个标识符随方向改变含义。24.008 把 000D 在上行列为 DNS Server IPv4 Address Request from the MS,在下行列为 DNS Server IPv4 Address from the network,对 0003(IPv6)也作同样处理。上行时它们不携带内容,下行时分别携带四个和十六个字节。
两条路径说的不一样。IPCP Nak 把 192.168.157.18 命名为主 DNS 服务器,且未提及备用 DNS;而容器 000D 命名的是同一地址,容器 0003 又增加了 2011:0:0:1::2。只读 PPP 路径的 UE 根本得不到 IPv6 DNS 服务器。
- accept 在两条路径上作答:8021 下的 PPP 协商,以及它旁边的容器列表。
- 携带 IPv6 的是容器路径:IPCP 没有针对 IPv6 DNS 服务器的选项。
- 长度字段都可核对:PDP address 为 22,options 为 40,IPCP 单元为 10。
- 这些值属于同一个网络:两个框中的任何内容都没有依据规范做过修正。 两种情形在相同的位置放入不同的东西,而这一差异正是本节的重点。下图把两个信息元素按相同比例并排放置,并把抓包中的值列在它们下方。
左为 24.301 的 PDN address 元素,右为 24.008 的 packet data protocol address 元素,每列一个字节,两者比例相同。它们下方的值来自本页的两份抓包。
24.301 第 9.9.4.9 节有意让 LTE 元素保持小巧。PDN address 是一个 type 4 元素,长度为 7 至 15 字节。对 PDN type IPv6,内容从第 4 字节到第 11 字节,该节称其为一个接口标识,用于构造 IPv6 链路本地地址。
24.008 第 10.5.6.4 节允许的空间大得多。packet data protocol address 可达 24 字节。对 PDP type IPv4v6,第 5 至第 8 字节存放 IPv4 地址,第 9 至第 24 字节存放 IPv6 地址,共 128 位。
这些空间大部分未使用。29.061 第 11.2.1.3.2 节说这种上下文的 IPv6 前缀仅由地址的 prefix 部分标识,MS 可以为接口标识部分选择任何值。对 EPS,23.401 第 5.3.1.2.2 节说得更直接:如果 UE 在 PDP 上下文激活流程中从 SGSN 收到 IPv6 前缀,它应忽略它。
因此 WCDMA NAS 消息中的前缀是建议性的,而 Router Advertisement 中的前缀是有约束力的。LTE 消息只携带必须经由 NAS 传送的那部分。UE 需要先有链路本地地址,才能发送 Router Solicitation。
- 一个元素携带 8 字节,另一个携带 16:24.301 发送接口标识,24.008 发送完整地址。
- 两种情形下都只有低 64 位具有约束力:前缀两次都由 Router Advertisement 送达。
- 接口标识有一个必需的用途:链路本地地址,使 UE 和网关不会在它们共享的链路上冲突。
- UE 可以为全局地址挑选自己的标识:23.401 和 29.061 都这么说,且两者都不让网络参与该选择。 24.301:3GPP - EPS 的非接入层协议;Stage 3,v20.0.0。第 9.9.4.9 节给出 PDN address 元素及其 IPv6 接口标识,第 6.5.1.3 节给出网络限制 IP 版本时发送的 ESM cause。
24.008:3GPP - 移动无线接口第 3 层规范;核心网协议;Stage 3,v20.0.0。第 10.5.6.4 节给出 packet data protocol address,第 10.5.6.3 节给出 protocol configuration options 以及每个方向的容器标识列表。
23.401:3GPP - E-UTRAN 接入的 GPRS 增强,v20.0.0。第 5.3.1.2.2 节给出通过 Router Advertisement 获得的 64 位前缀、用于链路本地地址的接口标识,以及忽略来自 SGSN 的前缀的规则。
29.061:3GPP - 支持分组业务的 PLMN 与 PDN 之间的互通,v20.0.0。第 11.2.1.3.2 节给出无状态自动配置流程、prefix information option 中要求的标志和 lifetime,以及前缀部分作为地址中唯一有约束力的那一半。
RFC 4861:IETF - IPv6 的邻居发现。第 4.6.2 节给出 prefix information option,其 flag 字节以 L 开头然后是 A。本节只阅读了这一节。