knowledge

Lecture 3

NAT Mappings and Traversal

NATs came to IP as an afterthought, yet they are widely deployed, mostly with IPv4 and sometimes with IPv6.A NAT is both a translator and a filter.As a translator, it rewrites packets by the mappings in its NAT table.

Inbound filter. The inbound filter decides who may use a mapping.It admits or drops each packet that arrives from outside.

The mapping says where to send; the filter says who gets in.

UPnP and STUN

UPnP (Universal Plug and Play). UPnP is a protocol that lets an internal host configure its own NAT.The host can set port forwarding and the inbound filter, and it can ask for the public address of the NAT.

STUN (Session Traversal Utilities for NAT). STUN is a protocol in which a public server reports the source IP:port of a host's request.This source is the public IP:port of the host's mapping toward the server.

A192.168.1.10:5000NAT A198.51.100.1SSTUN serversource 192.168.1.10:5000source 198.51.100.1:40001the source S sawrequest to Srequest to S198.51.100.1:40001LANinternet
S reports the request's source IP:port after NAT A translates it.

NAT Types

Endpoint-independent mapping. The NAT assigns one public port to each internal IP:port, whatever the destination.Every outside peer sees this port.

Endpoint-dependent mapping. The NAT assigns one public port to each pair of an internal IP:port and a destination IP:port.Each new destination gets a new port.

NAT typeMappingWho can send in?
Full coneindependentany outside host
Address-restricted coneindependentonly contacted IP addresses
Port-restricted coneindependentonly contacted IP:ports
Symmetricdependentonly contacted IP:ports

Each row is harder to traverse than the one above.A port-restricted cone and a symmetric NAT have the same filter.They differ only in their mapping.

A mapping needs a port, but ICMP has none.Some NATs do not support ICMP, and others use the identifier of an echo request (ping) as the port.

Example 1. How many hosts can a NAT serve?

A NAT has one public address and serves the private block 10.0.0.0/8.How many internal hosts can the NAT serve at most?

Count the private addresses.A /8 leaves 32−8=2432 - 8 = 24 bits for the host part, so the block holds 2242^{24} addresses.

Count the NAT ports.The NAT gives each entry its own NAT port, so entries never collide.A port has 16 bits, so TCP and UDP each have 216=65 5362^{16} = 65\,536 ports.Some ports are reserved or blocked, so the NAT has fewer than 2×2162 \times 2^{16} usable ports.

Compare.The ports set the limit, because 2×216=2172 \times 2^{16} = 2^{17} is far below 2242^{24}.Each host needs at least one port, so the NAT serves fewer than 2×65 5362 \times 65\,536 hosts.It serves one host per usable port only if each host has a single connection.

Two Peers Behind NATs

Two hosts behind NATs want to start a call and exchange UDP media (e.g. a browser video call or a SIP-phone call).At first, neither host knows its own public IP:port.

Signalling channel. A signalling channel is a path between the peers through a public server that both peers already reach.In a browser video call, this server is the web server of the call service.

A192.168.1.10:5000NAT A198.51.100.1NAT B198.51.100.2B10.0.0.7:6000S203.0.113.9:34781132signalling channelLANinternetLAN
Call setup: STUN (1), signalling (2), direct packets (3).
  1. Each peer asks S for its public IP:port.
  2. The peers exchange these IP:ports over the signalling channel.
  3. Each peer sends packets to the public IP:port of the other peer.

Example 2. Full cone NATs against symmetric NATs.

Each cell gives the NAT port that the packet leaves from.

PacketFull coneSymmetric
A to S4000140001
A to B4000140002
B to S5000150001
B to A5000150002

With full cones, each NAT keeps one port toward every destination, so S reports the port that the other peer must use.A sends to 198.51.100.2:50001, and NAT B admits any outside host, so the packet reaches B.B's packets reach A in the same way.

With symmetric NATs, B sends to port 40001, but NAT A bound this port to S.NAT A therefore drops the packet.NAT A uses port 40002 toward B, but nobody tells B.The same happens in the other direction.

A packet can also hit a port with no mapping, and the NAT drops it too.The drop happens at the NAT, so nothing reaches the operating system.

STUN is not wrong: it reports the mapping toward S.Neither peer needs this mapping.A second STUN server only reports a second useless mapping.TCP fails too, because its mappings behave the same, and a TCP simultaneous open rarely survives a NAT.

Hole Punching

With port-restricted cones, STUN reports the right IP:ports, but each filter still drops the first packet of the other peer.

Hole punching. Hole punching is a technique in which both peers send to each other's public IP:port at about the same time.Each outgoing packet opens the sender's own filter for the other peer.

First packets: each filter admits only SANAT ANAT BBNAT A admits203.0.113.9:3478 (S)NAT B admits203.0.113.9:3478 (S)Retransmissions: each filter also admits the peerANAT ANAT BBNAT A admits203.0.113.9:3478 (S)198.51.100.2:50001 (B)opened by A's first packetNAT B admits203.0.113.9:3478 (S)198.51.100.1:40001 (A)opened by B's first packetto :50001to :40001retransmissionretransmission
Hole punching between two port-restricted cone NATs.

Hole punching needs the signalling channel to coordinate the peers.It works with address-restricted and port-restricted cones.Full cones do not need it, and it often fails with symmetric NATs.

Symmetric NATs and TURN

Symmetric NATs persist.

  • They combine easily with a per-flow stateful firewall.
  • They ease load balancing, since a cluster can avoid shared state.
  • They are common in carrier-grade NATs, where UPnP is usually unavailable.

Guessing the next port of a symmetric NAT is unreliable.If no direct path works, the peers use a relay server.

TURN (Traversal Using Relays around NAT). TURN is a protocol in which a public relay server relays the packets of a peer.

Relayed address. A relayed address is the public IP:port that a TURN relay lends to a peer.The relay forwards to the peer the packets that arrive there from the IP addresses that the peer permits.

Example 3. A relay between two symmetric NATs.

Take the symmetric NATs of Example 2 and a relay T at 203.0.113.20:3478.T lends A the relayed address 203.0.113.20:49152, and A sends it to B over the signalling channel.A then permits B's public IP address 198.51.100.2 at T.

ANAT ATNAT BBto T's port 3478A's relayed addressB's IP addressto T's port 49152NAT A admits itNAT B admits itallocate:49152permit Bmediamediareply
TURN between the two symmetric NATs of Example 2.

Each outgoing packet opens its NAT's filter for the T port it contacts.NAT A admits T's port 3478, and NAT B admits T's port 49152.T reads each peer's NAT port from the source of its packets, and a permission names only an IP address.Nobody therefore needs to predict a port.

T carries every packet of the call, so TURN is the last resort.

ICE

A peer does not know in advance which method works.It knows neither the NAT types nor whether both peers share a LAN.

Candidate. A candidate is an IP:port at which a peer may be reachable.

CandidateComes fromExample for A
HostA's own interface192.168.1.10:5000
Server reflexiveSTUN: A's mapping toward S198.51.100.1:40001
Peer reflexivethe source of A's check, as B sees it198.51.100.1:40002
RelayedTURN: A's relayed address203.0.113.20:49152

ICE (Interactive Connectivity Establishment). ICE is a procedure in which the peers test candidate pairs and keep the best working pair.

  1. Each peer gathers candidates from its interface, from S and from T.
  2. The peers exchange their candidate lists over the signalling channel.
  3. Each peer pairs its candidates with those of the other peer.It ranks the pairs, with direct paths before relayed ones.
  4. Each peer sends a STUN check on every pair, best first.An answer proves that the pair works.A check from an unknown source reveals a peer-reflexive candidate.

Both peers send checks at once, so the checks also punch the holes.

Only a symmetric NAT gives A's check a new port, such as 40002.Behind a cone NAT, both reflexive candidates are the same.

The best escape is IPv6, because an IPv6 network usually needs no NAT.

NAT64 and DNS64

IPv4 and IPv6 are not compatible.Interworking needs dual-stack devices, translation, or both.

An IPv6-only host (client6) and an IPv4-only server (server4) cannot parse each other's packets.

NAT64. NAT64 is a translator between IPv6 and IPv4 networks.It sits where the IPv6 provider meets the IPv4 internet, and it rewrites the header of each packet.

IPv4-embedded IPv6 address. An IPv4-embedded IPv6 address is an IPv6 address whose last 32 bits are an IPv4 address.Its first 96 bits are a prefix.

The prefix is the well-known 64:ff9b::/96, or a /96 of the provider.A provider that holds 2001:db8:64::/48 can use 2001:db8:64::/96.To embed 203.0.113.5, write its four bytes in hex: cb.00.71.05.

Prefixserver4 at 203.0.113.5
64:ff9b::/9664:ff9b::cb00:7105
2001:db8:64::/962001:db8:64::cb00:7105

NAT64 translates the two addresses of a packet in different ways.

AddressIPv6 sideIPv4 sideTranslation
Source2001:db8:1234:1::dan address from a poolstateful, in a classic NAT table
Destination64:ff9b::cb00:7105203.0.113.5stateless, by dropping the prefix

DNS64. DNS64 is a DNS resolver that synthesizes an AAAA record for a name that has only an A record, by embedding its IPv4 address.If the name has a real AAAA record, DNS64 returns it unchanged.

client62001:db8:1234:1::dDNS64resolverNAT64translatorserver4203.0.113.5only an A record exists64:ff9b::cb00:7105routed to NAT64to 203.0.113.5translated backIPv6: home network and providerIPv4 internetAAAA queryAAAA answerIPv6 packetIPv4 packetIPv4 replyIPv6 reply
client6 reaches server4 through DNS64 and NAT64.

The client uses the synthesized address like any other IPv6 address, and it never learns that IPv4 is involved.DNS64 steers traffic by the address it returns, as DNS does in content delivery networks and load balancers.

Configuring an Interface

A host's IP interface needs an IP address and a subnet mask.It also needs the IP addresses of the default gateway and a DNS server.An administrator sets these four items by hand, or a protocol sets them.

DHCP (Dynamic Host Configuration Protocol). DHCP is a protocol in which a server gives hosts their configuration.In IPv4, DHCP gives all four items.

Stateful DHCP is a two-phase commit.The host commits to an offer, and the server confirms the commitment.

The host does not know the IP address of the server, so it broadcasts in IPv4 and multicasts in IPv6.An IPv4 DISCOVER is a UDP packet from port 68 to port 67.Its source is 0.0.0.0, because the host has no address yet, and its destination is the broadcast address 255.255.255.255.It carries the MAC address of the client.

A broadcast never leaves the LAN.The server must therefore sit on the LAN, or the gateway must relay.

DHCP relay. A DHCP relay is a gateway that forwards DHCP messages between its LAN and a server in another network.One server can then serve many subnets.

ClientRelayServerbroadcast: find a serverthe relay forwards itproposes a configurationcommits to the offerconfirms the commitmentDISCOVERDISCOVEROFFERREQUESTACK
Stateful DHCP through a relay.

Lease. A lease gives a host an IP address for a limited time.The DHCP server keeps the lease as state after the ACK, and the client renews it when it expires.

IPv4 self-autoconfiguration. An IPv4 host configures itself at boot if no DHCP server answers and nobody configured it by hand.

Address duplication test. An address duplication test checks that no other host on the link uses a given address.

ARP probe. An ARP probe is an ARP request with sender IP 0.0.0.0.An IPv4 host broadcasts it as its duplication test.

  1. The host picks a random link-local address in 169.254.0.0/16.
  2. The host broadcasts an ARP probe for this address.If nobody answers, the host keeps the address.

Self-autoconfiguration serves unmanaged networks with no router (e.g. old AppleTalk networks).It is not for general use.Windows implements it, and Linux does not always support it.

Autoconfiguration in IPv6

An IPv6 host gets its configuration by stateful DHCP or by SLAAC.

Router solicitation (RS). An RS is a message in which a host asks the routers of its link for their configuration.The host sends it to all routers on the link, at ff02::2.

Router advertisement (RA). An RA is a message in which a router advertises the configuration of its link, such as the /64 prefix.A router answers an RS with an RA, and it also sends periodic RAs to all nodes at ff02::1.A host takes the router that sends an RA as its default gateway.

SLAAC

SLAAC (Stateless Address AutoConfiguration). SLAAC is a method in which an IPv6 host builds its own addresses, with no DHCP server.

  1. The host builds its link-local address from fe80::/64 and a 64-bit host part.
  2. The host runs the duplication test on this address.It sends the test to the solicited-node multicast address.This address is ff02::1:ff00:0/104 plus the last 24 bits of the host part.If nobody answers, the host keeps the address.
  3. A router answers the host's RS with an RA.The host builds its global unicast address from the /64 prefix of this RA and its host part.

SLAAC ignores a prefix that is not 64 bits long.SLAAC always gives a link-local address.It gives a global unicast address only if a router answers with an RA.

Host partDerived fromChanges
Manual (e.g. ::1)the administratornever
Modified EUI-64the MAC addressnever
Temporarya random numberover time
RFC 7217a hash with a secret keyper subnet
Cryptographically generated (CGA)a hash of a public keyper subnet

Modified EUI-64. Modified EUI-64 turns a MAC address into a host part.It inserts ff:fe between the two halves of the 48-bit MAC address, then flips the second-lowest bit of the first byte.

Example 4. A MAC-derived address.

A host with MAC address 08:00:20:78:30:f9 uses modified EUI-64.An RA on its link advertises the prefix 2001:620:618:1ad::/64.

MAC address          08:00:20:78:30:f9
insert ff:fe         08:00:20:ff:fe:78:30:f9
flip the bit         0a:00:20:ff:fe:78:30:f9
link-local address   fe80::a00:20ff:fe78:30f9
solicited node       ff02::1:ff78:30f9
global address       2001:620:618:1ad:a00:20ff:fe78:30f9

Flipping the bit turns 08 (0000 1000) into 0a (0000 1010).

SLAAC gives no DNS server address.

  • Stateless DHCP. A DHCP server without lease state gives the DNS server address to every host that asks.
  • RA option (RFC 8106). The host asks the link's routers by multicast, and a router adds the DNS server address to its RA.The periodic RAs can carry it too.

Temporary and RFC 7217 Addresses

A MAC-derived host part is the same on every network, so anyone who collects addresses can track the host as it moves.Temporary and RFC 7217 addresses prevent this tracking.

Temporary address. A temporary address is an IPv6 address with a random host part and a limited lifetime.

StateLasts untilUse
Tentativethe duplication test succeedsnone
Preferredthe preferred timer expiresnormal
Deprecatedthe validity timer expiresno new TCP connections
Invalidnone

RFC 7217 address ("secure autoconf"). An RFC 7217 address is an IPv6 address whose host part is a hash with a secret key.

host part=hash(interface id, subnet prefix, secret key)\text{host part} = \text{hash}(\text{interface id},\ \text{subnet prefix},\ \text{secret key})

The operating system picks the secret key at installation.The address stays the same whenever the host returns to a subnet, and it changes unpredictably from one subnet to the next.

A host thus holds several IPv6 addresses.Inside its subnet, it uses the link-local one.

Configuring a Router's Provider Interface

A router's interface toward its provider needs a configuration too.In IPv4, PPP (Point-to-Point Protocol) configures it on telecom lines (e.g. a modem or ADSL).In IPv6, PPP or DHCP with prefix delegation configures it.

The devices of a home configure themselves by SLAAC, so the home router needs a prefix to advertise.

DHCP with prefix delegation. In DHCP with prefix delegation, the provider's DHCP server gives a router an IPv6 address and a prefix.A home or enterprise router then advertises this prefix on its LAN.The provider's DHCP server is called the delegating router.

If the link to the provider uses a prefix of the delegated block, the delegation excludes that prefix (RFC 6603).

Example 5. A delegated /60.

Swisscom delegates 2004:aaaa:bbbb:cc00::/60 to home router R0.The /60 holds 264−60=162^{64-60} = 16 /64 prefixes, cc00 to cc0f.

The ISP link uses cc01, so the delegation excludes it.R0's address on the ISP link is cc01 followed by its EUI-64 host part.R0 advertises cc02 on the home LAN, and each home host appends its EUI-64 host part to it.Fourteen prefixes stay free.

ISP DHCP serverdelegating routerrouter R0Home hostsby SLAAC2004:aaaa:bbbb:cc00::/60 holds 16 /64 prefixescc00cc03cc04cc05cc06cc07cc08cc09cc0acc0bcc0ccc0dcc0ecc0fcc01cc02cc01: ISP link, excludedcc02: home LANDHCP: /60RA: cc02 /64
Prefix delegation of 2004:aaaa:bbbb:cc00::/60 to router R0.

The IP Header

An IP header starts with control fields, then holds its two addresses.

IPv4 header, first 12 of 20 bytes08162431VersionIHLType of ServiceTotal LengthIdentificationFlagsFragment OffsetTime to LiveProtocolHeader ChecksumIPv6 header, first 8 of 40 bytes08162431VersionTraffic ClassFlow LabelPayload LengthNext HeaderHop Limit
IPv4 and IPv6 headers up to the addresses. Tinted: the fields explained below.

Hop Limit

Transient loop. A transient loop is a temporary routing cycle.The routers on the cycle forward a packet around and around.A change to forwarding tables reaches routers at different times, so their tables can disagree for a while.

If propagation is short compared to transmission, a single looping packet keeps the link busy and can congest it.

Router ARouter BHL 64HL 63HL 62transmissionpropagation
One packet loops between routers A and B, with its hop limit (HL). Time runs down.

Hop limit. The hop limit is an 8-bit field (0 to 255) of every IP packet.Every router and every NAT decrements it, and a switch does not.IPv6 calls it Hop Limit (HL), and IPv4 calls it Time to Live (TTL).

The source sets the hop limit to 64 in principle.When it reaches 0, the router discards the packet, so no packet loops forever.

Example 6. A packet with hop limit 1.

A packet with HL = 1 is valid.A router cannot forward it, because decrementing gives 0.A switch can forward it, because it ignores the IP header.Sources set HL = 1 to keep a packet inside the LAN.

Other Header Fields

MTU (Maximum Transmission Unit). The MTU is the largest packet that a link carries in one frame.Ethernet has an MTU of 1500 bytes.

  • Type of Service / Traffic Class. This byte has two fields.Differentiated Services takes the first 6 bits and acts roughly as a priority (e.g. for voice over IP).Only networks under a single administration use it.Explicit Congestion Notification takes the last 2 bits and serves congestion control.
  • Total Length / Payload Length. This field gives the size in bytes, with the header in IPv4 and without it in IPv6.It is at most 65 535, and in practice the MTU of the link limits it.
  • Header Checksum. Only IPv4 has this field.It detects bit errors in the header.IPv6 drops it, because data link and network hardware already detect errors efficiently.

The Protocol / Next Header field names the upper layer.

Protocol / Next HeaderUpper layer
1ICMP, for IPv4
6TCP
17UDP
58ICMPv6, for IPv6
4IPv4, encapsulated in IP (a tunnel)
41IPv6, encapsulated in IP (a tunnel)
50ESP, an encrypted payload
51AH, an authentication header

Traceroute

Traceroute. Traceroute is a tool that finds the routers on a path.It makes each router, in turn, report an expired packet.

  1. The source sends UDP probes with TTL = 1, 2, 3, and so on.
  2. The router where the TTL of a probe expires discards the probe, and it sends an ICMP error back to the source.
  3. The source address of the error reveals the router.The probe with TTL nn reveals the nn-th router.
SourceR1R2Destinationexpires at R1reveals R1expires at R2reveals R2reaches the hosttrace completeTTL=1ICMP errorTTL=2ICMP errorTTL=3ICMP error
Traceroute to a destination two routers away.

The last probe reaches the destination.The destination answers with an ICMP error, because no application listens on the probe's port.Windows tracert sends ICMP echo requests instead of UDP probes.

Example 7. Reading a traceroute.

The command tracert runs from an EPFL host to Google over IPv6.Each hop shows three round-trip times, then the router that answered.

Tracing route to www.google.com [2a00:1450:4008:800::1012]
over a maximum of 30 hops:
 
 1    1 ms   <1 ms   <1 ms  cv-ic-dit-v151-ro.epfl.ch
                            [2001:620:618:197:1:80b2:9701:1]
 2   <1 ms   <1 ms   <1 ms  cv-gigado-v100.epfl.ch
                            [2001:620:618:164:1:80b2:6412:1]
 3   <1 ms   <1 ms   <1 ms  c6-ext-v200.epfl.ch
                            [2001:620:618:1c8:1:80b2:c801:1]
 4    1 ms   <1 ms   <1 ms  swiEL2-10GE-3-2.switch.ch
                            [2001:620:0:ffdc::1]
 5   <1 ms   <1 ms   <1 ms  swiLS2-10GE-1-2.switch.ch
                            [2001:620:0:c00c::2]
 6    7 ms    7 ms    7 ms  swiEZ1-10GE-2-7.switch.ch
                            [2001:620:0:c03c::2]
 7    8 ms    8 ms    7 ms  swiEZ2-P2.switch.ch
                            [2001:620:0:c0c3::2]
 8    8 ms    8 ms    8 ms  swiIX2-P1.switch.ch
                            [2001:620:0:c00a::2]
 9    8 ms    8 ms    8 ms  swissix.google.com
                            [2001:7f8:24::4a]
10   38 ms   34 ms   15 ms  2001:4860::1:0:4ca2
11   14 ms   14 ms   17 ms  2001:4860::8:0:5038
12   17 ms   50 ms   17 ms  2001:4860::8:0:8f8e
13   24 ms   24 ms   24 ms  2001:4860::8:0:6400
14   25 ms   25 ms   25 ms  2001:4860::1:0:6e0f
15   25 ms   24 ms   25 ms  2001:4860:0:1::4b
16   25 ms   25 ms   25 ms  ber01s08-in-x12.1e100.net
                            [2a00:1450:4008:800::1012]
HopsNetworkNote
1 to 3EPFLinside 2001:620:618::/48
4 to 8SWITCHinside 2001:620::/32, which contains EPFL's /48
9SwissIXthe exchange where SWITCH hands over to Google
10 to 15Googleno names
16destinationwww.google.com

The round-trip times grow along the path, but not strictly:hop 10 shows 38 ms, and hop 11 only 14 ms.The output is a very good approximation of the path, not a guarantee.

The nested prefixes illustrate IP rule 2:each interface has a structured address.With longest prefix match, aggregation keeps forwarding tables small.This is enough for most routers, but not for all.

From IP Address to MAC Address

By IP rule 1, routers and NATs interconnect subnets and are never used inside one.Inside a subnet, the MAC layer moves the data, so a frame needs the MAC address of the neighbor that receives it.

MAC address resolution. Resolution maps the IP address of a neighbor to the MAC address of the same interface.

Host A has a packet for a neighbor B in its subnet.B is the destination, or the next hop toward it (e.g. the default gateway).

A knows only the IP address of B.A asks the LAN "who has this IP address?".The hosts that listen to this IP address answer with their MAC address.Normally only B listens to it.

Resolve the neighbor that receives the frame, never the far destination.

Example 8. M1 just boots.

Host M1 has just booted and sends a packet to host M3.M1 knows M3's IP address q.h1.Does M1 resolve q.h1 or p.1?

subnet pM1p.h1M2p.h2Routersubnet qM3q.h1M4q.h3p.1, MAC M9q.1, MAC M8
Hosts M1 to M4 in subnets p and q, joined by a router.

M1 resolves p.1.M3 is outside M1's subnet, so the frame goes to the default gateway.M1 knows the gateway's IP address from its configuration, but not the gateway's MAC address.M1 sends the frame to MAC address M9, and the packet inside keeps destination IP q.h1.The router then resolves q.h1 on subnet q.

NDP (Neighbor Discovery Protocol). NDP resolves addresses in IPv6.Its messages are ICMPv6 packets, carried in IPv6 packets with next header 58 (0x3a).

  • Neighbor Solicitation (NS). The NS asks "who has IP address B?".
  • Neighbor Advertisement (NA). The NA gives the MAC address of B.

The RS and RA of SLAAC are NDP messages too.SLAAC's duplication test is an NS for the host's own tentative address.

Neighbor cache. The neighbor cache holds the IP-to-MAC mappings that resolution learned.An entry expires after a configurable idle time, and feedback from higher-layer protocols can extend it.

Example 9. Resolving B in IPv6.

A and B share a LAN, and A resolves the IPv6 address of B.

A   IPv4   128.178.15.221
    IPv6   2001:620:618:1a6:1:80b2:f01:1
    MAC    08:00:20:71:0d:d4
B   IPv4   128.178.15.7
    IPv6   2001:620:618:1a6:1:80b2:f66:1
    MAC    00:00:d0:b3:d2:8d
PacketDestination IPDestination MAC
NS, A to Bff02::1:ff66:133:33:ff:66:00:01
NA, B to A2001:620:618:1a6:1:80b2:f01:108:00:20:71:0d:d4
Data, A to B2001:620:618:1a6:1:80b2:f66:100:00:d0:b3:d2:8d

When the NA arrives, A stores B's mapping in its neighbor cache.A can then send data to B directly.

The NA and the data are unicast, but the NS goes to B's solicited-node group, not to the whole LAN.Every host joins the solicited-node group of each of its addresses.A group holds the hosts whose addresses share its last 24 bits, normally only the target.

The MAC address of a group is 33:33 plus its last 32 bits.

B's address2001:620:618:1a6:1:80b2:f66:120010620061801a6000180b20f660001Solicited nodeff02::1:ff66:1ff0200000000000000000001ff660001Multicast MAC33:33:ff:66:00:013333ff660001last 24 bitslast 32 bits
From B's address to the destination IP and destination MAC of an NS for B.

Only IPv6 uses solicited-node multicast, for NDP and other protocols.IPv4 broadcasts instead.

Ethertype. The Ethertype is the MAC header field that names the protocol inside the frame.IPv6 has Ethertype 0x86dd, and IPv4 has 0x0800.

Example 10. A captured NS.

ETHER:  Packet size = 86 bytes
ETHER:  Destination = 33:33:ff:01:00:01
ETHER:  Source = 3c:07:54:3e:ab:f2
ETHER:  Ethertype = 0x86dd
IP:     Version = 6
IP:     Traffic class = 0x00000000
IP:         0000 00.. = Default Differentiated Service Field
IP:         .... ..0. = No ECN-Capable Transport (ECT)
IP:         .... ...0 = No ECN-CE
IP:     Flowlabel = 0x00000000
IP:     Payload length = 32
IP:     NextHeader = 58
IP:     Hop limit = 255
IP:     Source address = 2001:620:618:197:1:80b2:97c0:1
IP:     Destination address = ff02::1:ff01:1
ICMPv6: Type = 135
ICMPv6: Code = 0
ICMPv6: Checksum = 0xb199 [correct]
ICMPv6: Reserved = 0
ICMPv6: Target Address = 2001:620:618:197:1:80b2:9701:1

ICMPv6 type 135 is an NS.Expand the last two groups of the target as 9701:0001.Their last 24 bits are 01:00:01.The destination IP is therefore ff02::1:ff01:1, and the destination MAC is 33:33:ff:01:00:01.

The frame has 14+40+32=8614 + 40 + 32 = 86 bytes:the Ethernet header, the IPv6 header and the ICMPv6 payload.The target is hop 1 of Example 7, so a host is resolving its router.

ARP (Address Resolution Protocol). ARP resolves addresses in IPv4.

NDP (IPv6)ARP (IPv4)
RequestNSARP request
ReplyNAARP reply
Cacheneighbor cacheARP table
CarrierICMPv6 inside IPv6MAC frame, Ethertype 0x0806
Recipientssolicited-node groupwhole LAN, by broadcast

Example 11. A captured ARP request.

Ethernet II
    Destination: ff:ff:ff:ff:ff:ff (ff:ff:ff:ff:ff:ff)
    Source: 00:03:93:a3:83:3a (Apple_a3:83:3a)
    Type: ARP (0x0806)
    Trailer: 000000000000000000000000000000000...
Address Resolution Protocol (request)
    Hardware type: Ethernet (0x0001)
    Protocol type: IP (0x0800)
    Hardware size: 6
    Protocol size: 4
    Opcode: request (0x0001)
    Sender MAC address: 00:03:93:a3:83:3a (Apple_a3:83:3a)
    Sender IP address: 129.88.38.135 (129.88.38.135)
    Target MAC address: 00:00:00:00:00:00 (00:00:00_00:00:00)
    Target IP address: 129.88.38.254 (129.88.38.254)

The frame goes to the broadcast MAC address ff:ff:ff:ff:ff:ff.Its type is ARP, not IP.The protocol type IP (0x0800) shows that IPv4 asks.The target MAC address is all zeros, because the request asks for it.

Securing Address Resolution

ARP and NDP trust any answer, because nothing authenticates it.

ARP spoofing. In ARP spoofing, an attacker forges an ARP reply or NA, and the victim maps another host's IP address to the attacker's MAC.

  1. The attacker sees the request of A for the MAC address of B.This step is easiest in IPv4, where ARP requests are broadcast.
  2. The attacker sends a bogus reply with its own MAC address.
  3. If the bogus reply arrives first and A accepts it, A maps B's IP address to the attacker's MAC address.
ABAttackerbroadcast: B and the attacker see itthe attacker's MAC, firstB's MAC, secondsent to the attacker's MACARP requestbogus replyARP replytraffic for B
ARP spoofing in IPv4, with the attacker on the same LAN as A and B.

Rogue RA. A rogue RA is an unauthorized router advertisement.A single rogue RA can make its sender everyone's default gateway.Most rogue RAs are accidents.Misconfigured virtual machine hosts send them, and so does Windows internet connection sharing.

Man-in-the-middle attack. In a man-in-the-middle attack, an attacker relays the traffic of its victims and can read or change it.ARP spoofing and rogue RAs both make this attack possible.

Switch Defences

The defences sit in the LAN switch or the WiFi base station.

  • DHCP snooping. The switch or base station watches all DHCP traffic and records each IP-to-MAC mapping that the server hands out.Two defences use these mappings.
    • Dynamic ARP inspection. The switch filters ARP (or NDP) traffic and lets only valid answers through.It removes invalid broadcasts (IPv4) and multicasts (IPv6).
    • ARP proxy. The WiFi base station answers ARP requests itself.
  • RA guard (RFC 6105). The switch drops RAs that arrive on ports where no router exists.

Enterprise networks deploy these defences, but homes and WiFi access points rarely do.

SEND

Public-key cryptography. Public-key cryptography is a scheme in which each party holds two keys (e.g. RSA).Everyone knows the public key PP.Only the owner knows the private key pp.What one key encrypts, only the other key decrypts.

Digital signature. The digital signature of a message mm is mm encrypted with the private key pp.It is written p(m)p(m), and the sender sends {m,p(m)}\{m, p(m)\}.The receiver decrypts it with PP and compares the result with mm.

A signature guarantees authenticity.If the check fails, the receiver discards mm as forged.If it succeeds, only the owner of pp can have signed mm.

SEND (Secure Neighbor Discovery). SEND is NDP with signatures.It binds each address to its owner's public key, so attackers can no longer spoof NDP.

CGA (Cryptographically Generated Address). A CGA is an address whose host part is a hash of the public key of its owner.

host part≈hash(P, prefix, CGA parameters)\text{host part} \approx \text{hash}(P,\ \text{prefix},\ \text{CGA parameters})

The CGA parameters include counters.

  1. B creates an RSA key pair {p,P}\{p, P\}.
  2. B computes its CGA from PP, the prefix and the CGA parameters.The hash binds the IP address of B to PP.
  3. B puts PP and the CGA parameters in its NA, and signs the NA with pp.The signature binds the NA to {p,P}\{p, P\}, and therefore to the CGA.
  4. A recomputes the hash from PP and the parameters in the NA.A match proves that the CGA belongs to PP.A then checks the signature with PP, so the sender owns {p,P}\{p, P\}.

Anyone can claim a CGA, but only the owner of pp can sign for it.

Nonce. A nonce is a value used only once.An NA can carry a nonce, so an attacker cannot replay an old valid NA.

SEND needs a strong hash function (SHA-1 today), and it may need a trusted certification authority (e.g. RPKI).SEND is therefore not widespread yet.