A detailed study of the IPv6 address structure

A detailed study of the IPv6 address structure

IPv6 stands for Internet Protocol Version 6, which is the next-generation IP protocol designed by the Internet Engineering Task Force (IETF) to replace IPv4. It is said that the number of addresses it has is enough to encode an address for every grain of sand in the world.

[[331423]]

The biggest problem with IPv4 is the lack of network address (public IP) resources. Whether it is PCs, mobile phones or PADs, they all need IP addresses. IPv4 is facing the dilemma of being exhausted, which seriously restricts the application and development of the Internet. The use of IPv6 can not only solve the problem of the number of network address resources, but also solve the obstacles for various access devices to connect to the Internet.

IPv6 addresses and specifications will gradually become popular. On March 23, 2020, the Ministry of Industry and Information Technology issued the "Notice on Launching a Special Action to Improve IPv6 End-to-End Connectivity in 2020", requiring that by the end of 2020, the number of active IPv6 connections will reach 1.15 billion, a 43% increase from the target of 800 million connections in 2019. With the development and gradual popularization of IPv6, our software will also add support for IPv6 addresses, not just IPv4.

This article briefly sorts out the IP address structure and allocation method of IPv6, and also introduces the basic usage methods, which are shared with everyone here.

1. Definition of IPv6 address structure

The concepts of nodes, links, sites, and interfaces in IPv6 are as follows:

  • Node: Any system with an IPv6 address and an interface configured to support IPv6, which can be understood as a host and a router. Each node must have at least one link-local unicast address, and can also be assigned any type (unicast, anycast, and multicast) or range of IPv6 addresses.
  • Link: A single, continuous network medium with routers connected at both ends. The network where the node is located is the local scope of the link, which usually cannot cross routers, that is, it is on one link. Ethernet means that all devices under a switch are on one link.
  • Site: It is a network within an enterprise, which can have multiple network segments, similar to the private network range of IPv4. However, it has been abolished by RFC, and IPv6 generally does not need the existence of private networks.
  • Interface: For example, the network port of a network card, the telephone line port for Internet access, a node can be assigned multiple interfaces, and each interface can have multiple IPv6 addresses. All types of IPv6 addresses belong to interfaces rather than nodes. In a unicast address, the last 64 bits of the IPv6 address are the interface identifier that is unique to the 64-bit prefix of the IPv6 address (generated automatically by the MAC address, or manually according to the EUI-64 specification). An interface is unique in a subnet prefix.

1. IPv6 address representation

1) Hexadecimal notation: An IPv6 address consists of 128 bits, grouped into 16 bits, and each 16-bit group is written as 4 hexadecimal numbers separated by colons.

  • 21DA:00D3:0000:0000:02AA:00FF:FE28:9C5A

2) The representation method is not case-sensitive: 16-bit hexadecimal numbers are not case-sensitive, such as:

  • 21DA:00D3:0000:0000:02aa:00ff:fe28:9C5A.

3) The leading zeros in each group can be simplified: The leading zeros in each 16-bit group in the IPv6 address can be removed for simplified representation, such as:

  • 21DA:D3:0:0:2AA:FF:FE28:9C5A

4) When the middle bits are consecutively 0: You can omit the consecutive 0s and use :: instead (note that :: can only appear once, otherwise it is impossible to determine how many omitted 0s there are). This symbol can also be used to compress the adjacent consecutive zero bits at the front and end of the address, as shown below:

  • 21DA:D3:0:0:2AA:FF:FE28:9C5A is equivalent to 21DA:D3::2AA:FF:FE28:9C5A
  • FF01:0:0:0:0:0:0:101 is equivalent to FF01::101
  • 0:0:0:0:0:0:0:1 is equivalent to::1
  • 0:0:0:0:0:0:0:0 is equivalent to::

5) In a mixed IPv4 and IPv6 environment: x:x:x:x:x:x:dddd, where x is the hexadecimal value of the 6 high-order 16-bit groups in the address, and d is the decimal value of the 4 low-order 8-bit groups in the address (standard IPv4 representation). For example, the address 0:0:0:0:0:0:13.1.68.3,

  • 0:0:0:0:0:FFFF:129.144.52.38 is written in compressed form as ::13.1.68.3, ::FFFF.129.144.52.38.

6) Use text IPv6 address in URL: Text address should be enclosed by symbols '[' and ']'. For example, text IPv6 address

  • FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 is written as URL http://[
  • FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html.

7) Prefix representation method:

  • ipv6-address/prefix-length: ipv6-address is a 128-bit address in hexadecimal notation; prefix-length is the length of the address prefix in decimal notation. Similar to IPv4, the subnet prefix of IPv6 is associated with the link, and multiple subnet prefixes can be assigned to the same link.

For example, 2001:0DB8:0:CD30::/60

When writing a node address and the prefix of the node address (for example, the node's subnet prefix), the two are combined and written as follows:

Node Address

  • 2001:0DB8:0:CD30:123:4567:89AB:CDEF
  • and its subnet number 2001:0DB8:0:CD30::/60

Both can be abbreviated as

  • 2001:0DB8:0:CD30:123:4567:89AB:CDEF/60

2. EUI-64 format

EUI-64 format: Extended Unique Identifier

In IPV6, the stateless autoconfiguration mechanism uses the EUI-64 format to automatically configure the IPV6 address. The so-called stateless autoconfiguration refers to a mechanism that allows nodes to configure their own IPV6 addresses when there is no DHCP server in the network.

EUI-64 construction rules: Generate an IPV6 address based on the interface's MAC address plus a fixed prefix.

Working principle: Automatically expand the 48-bit Ethernet MAC address to 64 bits, and then add a 64-bit prefix to form an IPV6 address

Step 1 : Split the 48-bit MAC address in the middle and insert a fixed value FFFE

0050:3EE4:4C00-->0050:3EFF:FEE4:4C00

Step 2: Invert the 7th bit. If it was originally 0, it will become 1. If it was originally 1, it will become 0.

0050:3EFF:FEE4:4C00-->0250:3EFF:FEE4:4C00

Step 3. Add a prefix: For example, add the link-local address prefix FE80, FE80::0250:3EFF:FEE4:4C00. This is a complete IPV6 address.

Reason for reversal: In the MAC address, the 7th bit is 1 for local management and 0 for global management; in the EUI-64 format, the 7th bit is 1 for global uniqueness and 0 for local uniqueness

3. IPv6 address classification

  1. IPv6 addresses are divided into unicast addresses, anycast addresses, and multicast addresses. Compared with IPv4, the broadcast address type is cancelled and replaced by a richer multicast address, while the anycast address type is added. Anycast addresses are taken from the unicast address space (with any range), and anycast addresses are difficult to distinguish from unicast addresses in terms of syntax.
  2. "Unassigned addresses" (all zeros), loopback addresses (::1), and IPv6 addresses with embedded IPv4 addresses are assigned from a prefix of the format 0000 0000.
  3. Except for multicast addresses (format prefix 1111 1111), addresses with format prefixes from 001 to 111 must have a 64-bit interface identifier in EUI-64 format.
  4. All IPv6 addresses whose format prefix is ​​not the multicast format prefix (1111 1111) are in IPv6 unicast format (anycast and IPv6 unicast formats are the same). IPv6 unicast addresses are aggregatable like IPv4 unicast addresses.

4. IPv6 unicast address

An identifier for a single interface, used for one-to-one connections.

An IPv6 unicast address consists of two parts: a subnet prefix and an interface ID. The subnet prefix is ​​assigned by IANA, ISPs, and other organizations. The interface identifier is currently defined as 64 bits and can be generated by the local link identifier MAC or by using a random algorithm in EUI-64 format to ensure uniqueness.

There are six types:

1) Global unicast addresses can be aggregated

Currently allocated address prefixes:

  • 2001::/3, 2000::
  • ~3fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff

The prefixes currently used for IPv6 Internet operations are:

  • 2001::/16;
  • 2002::/16 is reserved for nodes using the 6to4 transition mechanism;
  • 3ffe::/16 is a prefix for 6bone testing purposes.

2) Link-local address

When the node enables IPv6, each interface will automatically generate a local link address. The prefix 64 bits is fixed, and the subsequent 64 bits of the interface ID are constructed according to the EUI-64 format.

Link-local addresses can only communicate on the local link and cannot be routed.

3) Site-local address

IPV6 private network addresses, like IPV4 private network addresses, can only be used within a site and cannot be used on the public network.

Site-local addresses were originally designed for site-internal addressing that did not require a global prefix. Site-local addresses are now deprecated, and new implementations MUST no longer support the special properties of this prefix as defined in [RFC3513] (i.e., new implementations MUST treat this prefix as global unicast).

Existing implementations and deployments may continue to use this prefix.

4) Unsure of address

The unicast address 0:0:0:0:0:0:0:0 is called an uncertain address. It cannot be assigned to any node. An example of its application is that when a host is initialized, before the host obtains its own address, the uncertain address can be placed in the source address field of any IPv6 packet it sends. The uncertain address cannot be used as the destination address in an IPv6 packet, nor can it be used in the IPv6 routing header;

5) Loopback address

The unicast address 0:0:0:0:0:0:0:1 is called the loopback address. A node uses it to send IPv6 packets to itself. It cannot be assigned to any physical interface.

6) ipv6 address with embedded ipv4 address

There are two categories: IPv4-compatible IPv6 addresses and IPv4-mapped IPv6 addresses.

Ipv4-compatible ipv6 address: ipv4 addresses must be globally unique. Addresses such as ::13.1.68.3, where the first 96 bits are all 0, are mainly used in an automatic tunnel technology. Messages with this address as the destination will be automatically encapsulated in an IPv4 tunnel. Since this technology cannot solve the problem of address exhaustion, it has gradually been abandoned.

IPv4-mapped IPv6 address: For example, ::FFFF.129.144.52.38, the first 80 bits are all 0, the middle 16 bits are all 1, and the last 32 bits are IPv4 addresses. This address is used to represent nodes that only support IPv4 with IPv6 addresses. On IPv6 nodes that support dual stacks, when an IPv6 application sends a destination message with this address, the message actually sent is an IPv4 message (the destination address is the IPv4 address in the "IPv4-mapped IPv6 address").

5. IPv6 Anycast Address

In one-to-near mode, multiple devices share one address.

An IPv6 anycast address is a global address assigned to a set of interfaces belonging to different nodes. The address format is the same as that of an IPv6 unicast address and is used to identify the addresses of a group of interfaces. Generally, these interfaces belong to different nodes.

Assign the same IPv6 address to devices with the same function. The sender sends a packet with the anycast address as the destination. After the router receives the packet, it forwards it to the device with the address closest to it. When a unicast address is assigned to multiple interfaces, the unicast address automatically becomes an anycast address.

As shown in the following two figures, the first one has a non-conflicting address, and the second one has the same address as another host. When two hosts on the same link are configured with the same IPv6 address, the address behind it is marked as "copy".

use:

One of the uses of IPv6 anycast addresses is to identify a group of routers belonging to the same organization that provides Internet services. These addresses can be used as intermediate forwarding routers in the IPv6 routing header to enable packets to be forwarded through a specific group of routers.

Another use is to identify a group of routers in a specific subnet. The message only needs to be received by one of the routers.

Some of these anycast addresses are already defined, such as the subnet router anycast address, which has the following format.

The "subnet prefix" in an anycast address is used to identify a specific link. This anycast address is syntactically identical to the unicast address of the interface on that link with the interface identifier set to 0. A message sent to the subnet router anycast address is delivered to a router in the subnet. All routers must support subnet anycast addresses.

Subnet router anycast addresses are used when a node needs to communicate with one of all routers on a remote subnet (it doesn't matter which one). For example, a mobile node needs to communicate with one of all mobility agents on its "home" subnet.

Anycast addresses have the following limitations:

  • Anycast addresses MUST NOT be used as source addresses in IPv6 packets;
  • Anycast addresses MUST NOT be assigned to IPv6 hosts, but MAY be assigned to IPv6 routers.

6. IPv6 multicast address

One-to-many mode.

IPv6 multicast addresses are used to identify a group of interfaces, which generally belong to different nodes. A node may belong to 0 or more multicast groups. Messages sent to a multicast address are received by all interfaces identified by the multicast address.

1) IPv6 multicast address format definition:

FF00::/8

in:

① 11111111: 8 bits. Identifies this address as a multicast address

② Flags: 4 bits. The flag field is defined as follows:

The highest 3 bits are reserved and must be 0.

  • T = 0 indicates a permanently assigned ("well-known") multicast address (assigned by IANA);
  • T = 1 indicates multicast, which means a temporary multicast address that can be used by users

③ Scope: 4 bits. Used to mark the application scope of this multicast group.

④ group ID

Identifies a multicast group (may be permanent or temporary, the scope is defined by scope)

2) IPv6 permanently allocated multicast addresses

The current permanently assigned ("well-known") multicast groups are as follows:

Reserved multicast addresses:

  • FF00::---FF0F::(16 addresses in total)

Addresses of all nodes:

  • FF01:0:0:0:0:0:0:1 (node ​​local)
  • FF02:0:0:0:0:0:0:1 (link-local, all nodes within the local link range)

All router addresses:

  • FF01:0:0:0:0:0:0:2 (node ​​local)
  • FF02:0:0:0:0:0:0:2 (link-local, all routers within the link-local range)
  • FF05:0:0:0:0:0:0:2 (site local)

The address of the requested node:

  • FF02:0:0:0:0:1:FFXX:XXXX/104

The above address is formed by the unicast or anycast address of the requested node: take the lower 24 bits of the unicast or anycast address of the requested node and add the prefix FF02:0:0:0:0:1:FF00::/104 in front.

For each unicast address or anycast address configured on the interface of a node or router, a corresponding multicast address of the requested node is automatically generated. It is only valid in the local link scope.

Features:

  • On the local link, the multicast address of the requested node usually contains only one user
  • As long as the IPv6 address of a node is known, its requested node multicast address can be calculated. For example, the requested node multicast address corresponding to the IPv6 address 4037::01:800:200E:8C6C is FF02::1:FF0E:8C6C.

effect:

  • There is no ARP in IPV6. ICMP replaces the function of ARP. The multicast address of the requested node is used in the IPv6 neighbor discovery protocol and in the neighbor request message. Since only nodes with the same last 24 bits of the unicast address will receive messages with this destination address, the communication traffic is reduced (compared with IPv4 ARP).
  • Used for duplicate address detection (DAD). In stateless configuration, a node uses DAD to verify whether this address is used in its local link.

7. IPv6 addresses that must be supported

1) IPv6 addresses that nodes must support

  • Each host must use the following address as its own address
  • Link-local address of the own interface
  • Assigned unicast address
  • Loopback address
  • All nodes multicast address
  • The solicited-node multicast address for each assigned unicast or multicast address
  • Other multicast group addresses to which this host belongs

2) IPv6 addresses that the router must support

  • The interface is configured as the subnet router anycast address of the router interface
  • Any other router configured anycast address
  • All Routers Multicast Address
  • Other multicast group addresses to which this router belongs

2. IPv6 Address Allocation

1. Address configuration

IPv6 supports two address autoconfiguration modes: stateless address autoconfiguration and stateful address autoconfiguration.

Stateless address autoconfiguration:

  • Stateless autoconfiguration requires no manual configuration of hosts, minimal configuration of routers (if any), and no additional servers. The stateless mechanism allows hosts to generate their own addresses. The stateless mechanism uses local information as well as non-local information advertised by routers to generate addresses.
  • The network interface that needs to be configured with an address first uses the neighbor discovery mechanism to obtain a link-local address. After the network interface obtains the link-local address, it receives the address prefix announced by the router and obtains a global address in combination with the interface identifier. The IPv6 node obtains the IPv6 address and gateway address through address automatic configuration.

During the autoconfiguration process, the host does the following:

  • Creates a link-local address for each interface, which does not require a router on the link.
  • Verify that the address is unique on the link. This operation does not require a router on the link.
  • Determines whether global addresses should be obtained through a stateless mechanism, a stateful mechanism, or both. (Requires a router on the link.)

Stateful address automatic configuration: such as Dynamic Host Configuration Protocol (DHCP), requires a DHCP server to obtain address configuration information from the DHCP server through the client/server mode.

2. Address allocation

① Global unicast address space allocation

The Internet Assigned Number Authority (IANA) is responsible for the allocation of IPv6 address space. Currently, IANA allocates 2001::/16 from the entire aggregatable global unicast address space (format prefix 001).

② IPv6 experimental network address allocation (6BONE)

The 6BONE network is a global IPv6 experimental network that uses the network prefix 3ffe:0000::/16. Each pseudo top-level aggregation is allocated a /28 prefix in the range of 3ffe:0800::/28, supporting up to 2048 pseudo top-level aggregations. The end site obtains a /48 prefix from the upstream provider, and each site can be further subdivided into multiple /64 prefixes.

The 6BONE network allocates addresses in a hierarchical structure. The address space is defined by IANA and the allocation strategy is defined in RFC2921 (6BONE Pseudo Top-level Aggregation and Network Layer Aggregation Format).

3. Use of IPv6

1) First enable ipv6, as follows:

Local testing uses the Windows environment.

Or command line form: ipv6 install

In XP system, you can use netsh-->interface-->ipv6-->install to install the ipv6 protocol.

You can also add the protocol part as shown in the figure below, and then install ipv6.

After enabling IPv6, the host will automatically generate an IPv6 link-local address.

2) You can also manually configure the ipv6 address

You can use the interface configuration:

It can also be configured via the command line:

  • cmd
  • netsh
  • i ipv6
  • show i remembers the index value in the local connection
  • add address int=index value ipv6 address
  • show address int=index value

3) Check the IPv6 address

ipconfig

When you check, you will find that the tunnel address is as follows:

IPv6 and IPv4 communicate through tunnels, which requires the support of special protocols and equipment, such as teredo in the above picture. This will be introduced in the next case study when there is an opportunity.

When Teredo is enabled, a Teredo tunnel address will be created, which is usually used to communicate with external hosts. For local testing, you can use a local link address or a manually configured address.

Note: Generally, the link local automatic generation uses the EUI-64 format as the interface ID based on the MAC address, but this is not the case on my computer. When I checked other computers, they were generated based on the MAC, and it seems to be generated using a random code. As long as the address is unique within the link, it will be fine.

4) A brief introduction to IPv6

① PfcNtop and PfcPton

PfcNtop and PfcPton provided by the PFC module encapsulate the functions of inet_ntop and inet_pton, and are mainly used to convert IP addresses and their string representations.

② Structure PFC_IPADDR

  1. typedef struct PROTO_API tagPFC_IPADDR  
  2. {  
  3. PFC_TRANSPORT_TYPE m_emType; ///< transport type  
  4. PFC_IPADDR_UNION m_tAddr; ///< IP address
  5.   u16 m_wPort; ///< port number, host format  
  6. PFC_DISTRIBUTION_TYPE m_emDistribution;  
  7. }

The structure provided by the protocol component to represent ipv4 or ipv6.

  1. m_emType indicates whether it is ipv4 or ipv6, and the default value is the invalid value none.  
  2. m_tAddr is a union type, which indicates the specific IP address of ipv4 or ipv6. The specific representation of ipv6 is as follows:  
  3. /// PFC IPv6 address  
  4. typedef struct  
  5. {  
  6. u8 m_abyIP[PFC_IPV6_ADDR_SIZE]; ///< 16 byte IP address  
  7. u16 m_wScopeId; ///< scope  
  8. } PFC_IPADDRv6;

PFC_IPV6_ADDR_SIZE is a 16-byte macro. So the ipv6 address is represented by a 16-byte u8 array. m_wScopeId is mainly used for link-local addresses, because link-local addresses are unique on a link, and a host can use the same link-local address to access two different links, so scopeid is used to distinguish them. This field corresponds to uint32_t sin6_scope_id in the sockaddr_in6 structure. After testing, if the system has only one link-local address, win7 and win10 do not need to fill in this field to communicate with the machines on the link, but there is a problem with communicating with the XP system.

③ getaddrinfo function

Get the IP address. The gethostbyname and gethostbyaddr functions only support IPv4, while getaddrinfo supports both IPv4 and IPv6. It returns a linked list of sockaddr structures instead of an address list. This method is not encapsulated by the protocol component yet. Please use it if you have the need.

at last

IPv6 involves a lot of things, and some of the concepts are sometimes difficult to understand. You must look up information and then understand them. This article only introduces part of IPv6 based on rfc4291. You will need to refer to more information on other aspects of IPv6 in the future.

<<:  Network as a Service (NaaS) Demand is Changing the Enterprise Market

>>:  Digital transformation enters the "immersion period". Huawei helps government and enterprise industries embrace digitalization without blind spots.

Recommend

GSMA: By 2030, 5G will contribute more than $600 billion to the global economy

On February 24, the 2021 Mobile World Congress Sh...

Analysis of 5G network security issues

The fifth generation of mobile communication tech...

You have to know these eleven functions of the router

Many friends often leave messages asking, how to ...

You must know the five common misconceptions about HTTPS

Nowadays, the https protocol is widely valued and...

Java Server Model - TCP Connection/Flow Optimization

Usually, our applications do not need to handle t...

The Internet of Identity is coming, and IAM will undergo a major change

What is the difference between the Internet of Id...

ICO was wiped out, is blockchain technology a blessing or a curse?

In the first half of this year, with the skyrocke...