理解IPv6地址

Last Updated: 2023-04-21 10:09:00 Friday

-- TOC --

IPv6地址分配给Interface,而不是Host。Host可由它的任意一个接口上的任意unicast地址确定。IPv6没有广播地址。

IPv6地址长度和表示

Colon Hexadecimal Format

IPv6地址的长度为128位,由8个16位字段组成,8x16Bytes,表示方法为,相邻16bit用冒号:分隔。IPv6地址中的每个字段都必须包含一个16进制数字,而IPv4地址则以点分十进制表示法表示(Dotted-Decimal Format)。

详解IPv6报文头结构

X:X:X:X:X:X:X:X  # 8个X,每个X表示16bit
--1-- 2 ---3---

举个例子:

2001:0db8:3c4d:0015:0000:0000:1a2f:1a2b

The relatively large size of the IPv6 address is designed to be divided into hierarchical unicast routing domains that reflect the topology of the modern-day Internet. The use of 128 bits allows for multiple levels of hierarchy and flexibility in designing hierarchical unicast addressing and routing that is currently lacking on the IPv4-based Internet.

缩短IPv6地址

连续的16位全0,可以使用双冒号::(double colon)来简化,比如上例中的IPv6地址,可以简化为:

2001:0db8:3c4d:0015::1a2f:1a2b

每个X的前导0可以被省略,每个X至少要有一个数字:

2001:0db8:3c4d:0015:0:0:1a2f:1a2b
2001:db8:3c4d:15::1a2f:1a2b

在一个IPv6地址中,不能出现多个::的情况,这种情况会导致无法将IPv6地址还原:

2001:0db8:3c4d:0015:0000:d234:3eee:0000

2001:db8:3c4d:15:0:d234:3eee::
2001:db8:3c4d:15::d234:3eee:0

Interface ID

64bit Interface ID,这是个非常大的空间,如此设计是为了做底层地址的mapping。

This length was not fixed at 64 bits to allow up to 2^64 possible hosts on the same subnet. Rather, the IPv6 interface ID is 64 bits long to accommodate the mapping of current 48-bit MAC addresses used by many local area network (LAN) technologies such as Ethernet and the mapping of 64-bit MAC addresses of IEEE 1394 (also known as FireWire) and future LAN technologies.

IPv6未指定地址

未指定地址,就是没有地址:

0:0:0:0:0:0:0:0
::

The address 0:0:0:0:0:0:0:0, or :: is called the unspecified address. It must never be assigned to any node. It indicates the absence of an address. One example of its use is in the Source Address field of any IPv6 packets sent by an initializing host before it has learned its own address.

The unspecified address must not be used as the destination address of IPv6 packets or in IPv6 Routing headers. An IPv6 packet with a source address of unspecified must never be forwarded by an IPv6 router.

socket编程时,设置监听地址,可以使用::,它表示在所有地址上监听,并且同时支持IPv4和IPv6,实现所谓的支持双栈。

IPv6环回地址

环回地址,它属于unicast地址:

0:0:0:0:0:0:0:1
::1

The unicast address 0:0:0:0:0:0:0:1, or ::1 is called the loopback address. It may be used by a node to send an IPv6 packet to itself. It must not be assigned to any physical interface. It is treated as having Link-Local scope, and may be thought of as the Link-Local unicast address of a virtual interface (typically called the "loopback interface") to an imaginary link that goes nowhere.

The loopback address must not be used as the source address in IPv6 packets that are sent outside of a single node. An IPv6 packet with a destination address of loopback must never be sent outside of a single node and must never be forwarded by an IPv6 router. A packet received on an interface with a destination address of loopback must be dropped.

IPv6地址Prefix

IPv6在表达网段时,使用与IPv4一样的CIDR表示法,即address/prefix-length。结合前面的知识,addr::/64表示一个subnet,而addr::/48表示一条聚合路由。

Unicast IPv6地址的prefix永远是固定的64,因此就没有必要写出来了。

2001:DB8::2AC4:2AA:FF:FE9A:82D4
2001:DB8::2AC4:2AA:FF:FE9A:82D4/64

单播地址Unicast

One to One

A unicast address identifies a single interface within the scope of the type of address. The scope of an address is the region of the IPv6 network over which the address is unique. With the appropriate unicast routing topology, packets addressed to a unicast address are delivered to a single interface. To accommodate load-balancing systems, RFC 4291 allows for multiple interfaces to use the same address as long as they appear as a single interface to the IPv6 implementation on the host.

Global Unicast Address

global_unicast_addr.png

3层拓扑结构

48bit public topology
  + 16bit site topology
  + 64bit interface

Link-local addresses are always automaticlly configured. They are used between on-link neighbors and for Neighbor Discovery processes. An IPv6 router never forwards link-local traffic beyond the link.

link_local_addr.png

FE80::/64 # link local address prefix
inet6 fe80::216:3fff:fe00:677b  prefixlen 64  scopeid 0x20<link> # by ifconfig
inet6 fe80::216:3fff:fe00:677b/64 scope link # by ip addr

IPv6 link-local addresses are similar to IPv4 link-local addresses defined in RFC 3927 that use the 169.254.0.0/16 prefix. The use of IPv4 link-local addresses is known as Automatic Private IP Addressing (APIPA) in Windows System.

EUI-64

这是host用来给自己的interface配置link local ipv6地址的方法。EUI,Extended Unique Identifier。64表示这个unique identifier是64bit。

The IPv6 EUI-64 format address is obtained through the 48-bit MAC address. The MAC address is first separated into two 24-bits, with one being OUI (Organizationally Unique Identifier) and the other being NIC specific. The 16-bit 0xFFFE is then inserted between these two 24-bits for the 64-bit EUI address. IEEE has chosen FFFE as a reserved value which can only appear in EUI-64 generated from the an EUI-48 MAC address.

eui-64-1.png

Next, the seventh bit from the left, or the universal/local (U/L) bit, needs to be inverted. The reason for inverting can be found in RFC4291 section 2.5.1.

eui-64-2.png

最后,在前面插入link local prefix,就得到了EUI-64格式的地址:

FE08::221:2FFF:FEB5:6E10

EUI-64格式的link local,包含了接口的MAC地址。

Site-Local Address

site local地址,就像IPv4里的私有地址。但RFC3879不建议使用。

Site-local addresses, identified by setting the first 10 bits to 1111 1110 11, are equivalent to the IPv4 private address space (10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16).

site_local_addr.png

The first 10 bits are always fixed for site-local addresses, beginning with FEC0::/10. After the 10 fixed bits is a 54-bit Subnet ID field that provides 54 bits with which you can create subnets within your organization.

Zone ID

由于link local地址和site local地址是可以reuse的,即在不同的link上,或在不同的site内,可能会出现完全一样的link local或site local地址。为了以示区分,RFC4007定了一个zone id和格式,用来区分:

# address%zone_id
fe80::1%eth0
fec0::1%eth0

Zone ID是一个标识符,可以是数字、字母或其他字符。它的格式和内容取决于特定的实现和网络设备。

Site Local地址已经被弃用,现在建议使用Unique Local Address (ULA)代替。在RFC 3484中建议将Zone ID与Link-Local地址和Site-Local地址一起废除,因此未来可能不再使用Zone ID。

Unique Local Address(ULA)

由于Site Local地址没有全局唯一性,因此出现了Unique Local Address(ULA)。

The ambiguity of site-local addresses in an organization adds complexity and difficulty for applications, routers, and network managers. For more information, see section 2 of RFC 3879.

unique_local_addr.png

The first 7 bits have the fixed binary value of 1111110. All local addresses have the address prefix FC00::/7. The Local (L) flag is set 1 to indicate that the prefix is locally assigned. The L flag value set to 0 is not defined in RFC 3879. Therefore, unique local addresses within an organization with the L flag set to 1 have the address prefix of FD00::/8.

40bit的Global ID是随机产生的,这个随机数足够大,统计意义上可以实现一个site内不重复,甚至在几个组织合并的时候,各个组织内部也有极大概率不重复。也因此,前48bit都是随机的,这48bit没有要做summary的设计。

16bit的Subnet ID,与Global Unicast地址相同。这样在一个site内,内部的subnet划分可以完全一样,两套地址,一套global访问公网,一套unique local内部使用。

Transition Address

多播地址Multicast

One to Many

A multicast address identifies zero or more interfaces on the same or different hosts. With the appropriate multicast routing topology, packets addressed to a multicast address are delivered to all interfaces identified by the address.

任意地址Anycast

One to One-of-Many

An anycast address identifies multiple interfaces. With the appropriate unicast routing topology, packets addressed to an anycast address are delivered to a single interface -- the nearest interface that is identified by the address. The nearest interface is defined as being the closest in terms of routing distance.

本文链接:https://cs.pynote.net/net/ip/202304101/

-- EOF --

-- MORE --