Its' packets all the way down.
TCP packets run inside IPv[46] packets which might run inside Ethernet packets, or they might run inside an 802.2 LLC header on another network (e.g. Token Ring), etc, etc.
If you're dealing with IPv4, then you also need the Ethernet ARP (Address Resolution Protocol) in order to do, well, address resolution (that is, you use ARP to ask and receive the answer to the question "What is the MAC address of 80.34.2.17"). For IPv6, the NDP (Neighbor Discovery Protocol) is used. This is a subprotocol of ICMPv6 (The IPv6 Control Message Protocol).
There are three general ways a machine gets an address:
- Manual configuration. Enough said.
- Link local addresses. For IPv6, every lower layer port has its' own link local address; for IPv4, they're the fallback when the machine isnt' statically configured and doesn't find a DHCP server. Machines basically allocate these by asking "Who is fe80::32", then after a timeout declaring "I am fe80::32." The IPv6 traditional method of picking an address is to use the network card's 64-bit EUI number (expanded from a 48-bit MAC for Ethernet) for the last 64 bits. (The first 20 bits are the link local prefix, followed by 44 zero bits)
- Route Advertisements. This is the preferred mechanism in IPv6
- The Dynamic Host Configuration Protocol. This is the common mechanism in IPv4 and also used in IPv6 where route advertisements aren't good enough.
Route AdvertisementsThese are ICMPv6 messages. There are two important ones:
- Route solicitation. Link local multicast. "Hello, is there a router out there?"
- Route advertisement. "Hi, I'm fe80::64 delegating prefix 2001:DB8::0000"
You send a route solicitation, hope for a route advertisement, and when you get one you claim your IP the same way as for link local addresses.
DHCPDHCP is largely the same on IPv6 and IPv4, with subtle differences: on IPv4, there are no link local addresses, so every packet is broadcast. For IPv6, just the initial discovery packet is link local mutlcast; after that, everything is done using link local addresses. DHCP runs on UDP.
DHCP normally proceeds in 4 stages:
- DHCPDISCOVER. "Hey, is there a DHCP server out there?"
- DHCPOFFER. "Hi, I'm 2001:DB8::0001 and I offer you 2001:DB8::0002/64. Your default gateway is 2001:DB8::0003 and your DNS servers are 2001:DB8::0004 and 2001:DB8::0005."
- DHCPREQUEST. "Hi, I'd like to claim 2001:DB8::0002"
- DHCPACK "OK, you're 2001:DB8::0002 for the next 86400 seconds. Your default gateway is 2001:DB8::0003 and your DNS servers are 2001:DB8::0004 and 2001:DB8::0005" (I have no idea why it bothered including all of that lot in the DHCPOFFER...)
MiscellanyThere are ways to speed up or slow down the IP acquisition process. Traditionally Linux dhclient tries your
last DHCP server for
30 seconds before it gives up and does a DHCPDISCOVER, which as you might imagine sucks if you take your laptop places often.
Modern devices have a very quick process for getting an IPv4 address:
- Send out a router solicitation packet. Simultaneously ARP/NDP the last 5 used DHCP servers, pause a moment
- If one of them IPs exists on this network, try and DHCPREQUEST for our last IP. We will hopefully get an IP shortly
- After a short timeout (~200ms) broadcast DHCPDISCOVER and go through the motions