SEN2008 · Week 4 · Data Link Layer Concepts (II) : Channel allocation problem, multiple Access, Ethernet

Ethernet, MAC addresses, switches and ARP

The fields of an Ethernet frame, minimum and maximum size, the structure of the 48-bit MAC address, the switch learning table, going from IP to MAC with ARP, and attacks on these such as ARP spoofing and MAC flooding.

Ethernet framepreambleEtherTypepayload paddingFCSMAC addressOUIunicast / multicast / broadcastswitchself-learningforwarding table (CAM)floodingfilteringcollision domainbroadcast domainARPARP cacheARP spoofingMAC floodingVLAN

On the previous page you saw who gets to talk on a shared channel. Today almost all wired LANs are Ethernet, and in modern Ethernet the hosts are connected one by one to a switch. This page covers the “address” side of the link layer: MAC addresses, how a switch learns, and how to get from an IP address to a MAC address (ARP). You will come back to this page many times in the security half of the course, because the protocols at this layer do no authentication.

Golden rules:

  1. An Ethernet frame is 64 to 1518 bytes (excluding the preamble). The payload is at least 46 bytes; if shorter, it is padded.
  2. A switch learns the source address and forwards by the destination address.
  3. An ARP request is broadcast, the reply is unicast.
  4. The IP address stays the same end to end, the MAC address changes on every link.

The Ethernet frame

+----------+---------+---------+------+--------------+-----+
| Preamble | Dst MAC | Src MAC | Type |   Payload    | FCS |
|  8 byte  | 6 byte  | 6 byte  | 2 B  | 46-1500 byte | 4 B |
+----------+---------+---------+------+--------------+-----+
FieldJob
Preamble7 bytes 10101010 + 1 byte 10101011 (SFD). The receiver synchronizes its clock. Not counted in the frame size.
Dst / Src MACDestination and source interface addresses
Type (EtherType)The protocol in the payload: 0x0800 IPv4, 0x0806 ARP, 0x86DD IPv6
PayloadUsually an IP datagram. MTU = 1500 bytes
FCSCRC-32 (week 3). A corrupted frame is silently discarded

Ethernet is connectionless and unreliable: no handshake, no ACK. A frame that fails the CRC is discarded; noticing the loss is the job of the upper layer (TCP).

Sizes and padding

Minimum: 6+6+2+46+4=646 + 6 + 2 + 46 + 4 = 64 bytes. This limit comes from the CSMA/CD minimum frame rule on the previous page (512 bits). For a 20-byte datagram, 46−20=2646 - 20 = 26 bytes of padding are added.

Maximum: 6+6+2+1500+4=15186 + 6 + 2 + 1500 + 4 = 1518 bytes.

Efficiency

On the wire, every frame is preceded by an 8-byte preamble and followed by a 12-byte inter-frame gap.

Max payload (1500) : 1500 / (1518 + 8 + 12) = 1500 / 1538 = 97.53%
Min payload (46)   : 46 / (64 + 8 + 12)     = 46 / 84     = 54.76%
1518 B @100 Mbps   : 12,144 bit / 10^8      = 121.44 us

MAC addresses

A MAC (LAN, physical) address is 48 bits and is written in hexadecimal: 3C:22:FB:10:A4:7E. It is written into the network card (NIC) at manufacture, but it can be changed in software (this is a security issue).

PartBitsMeaning
OUIfirst 24Prefix the IEEE assigns to the manufacturer
NIC-specificlast 24Serial number assigned by the manufacturer
I/G bitlowest bit of the first byte0 unicast, 1 group (multicast)
U/L bitsecond-lowest bit of the first byte0 global (from the manufacturer), 1 locally assigned
first byte  binary      I/G  U/L  type
0x00        00000000    0    0    unicast, global
0x01        00000001    1    0    multicast (01:00:5E -> IPv4 multicast)
0x3A        00111010    0    1    unicast, locally assigned (random MAC)
0xFF        11111111    1    1    FF:FF:FF:FF:FF:FF = broadcast

MAC versus IP. A MAC address is a flat identity like a social security number and carries no location information; it stays the same whichever network the laptop joins. An IP address is hierarchical like a postal address and changes with the network you connect to. Routing is done with IP, and delivery on the last link with MAC.

TIP · random MAC. Phones connect to each Wi-Fi network with a different, locally assigned (U/L = 1) MAC. The goal is to make it harder to track a user across networks by MAC: a privacy measure.

Switch: the self-learning bridge

A hub is a physical-layer device that just copies bits to all ports; everyone connected stays in one collision domain. A switch is a link-layer device: it reads the frame and sends it only to the port that needs it. Hosts are unaware that the switch exists (transparent).

A switch has a forwarding table (CAM): MAC → port, time. Nobody fills the table by hand; the switch learns it itself (self-learning):

  1. A frame arrived from port xx. Write the source MAC into the table as “port xx” (or refresh its timer).
  2. Look up the destination MAC in the table:
    • If it is not there: send the frame to all ports except the one it arrived on (flooding).
    • If it is there and the port is xx: discard (filtering), the destination is already on the same segment.
    • If it is there and the port is another port yy: forward only to yy (forwarding).
  3. Entries are deleted if unused for a certain time (aging time, typically 300 s).

Worked example: a learning trace

Frame (source -> destination, in port)   Decision     Table after
A -> B, port 1                           flood        A=1
B -> A, port 2                           port 1       A=1 B=2
C -> A, port 3                           port 1       A=1 B=2 C=3
A -> C, port 1                           port 3       A=1 B=2 C=3
D -> B, port 4                           port 2       A=1 B=2 C=3 D=4

Note: B is not learned from the first frame. The switch learns only from the source address; B enters the table only when it sends a frame itself.

Collision domain and broadcast domain

DeviceLayerCollision domainBroadcast domain
Hub1All ports in one domainOne
Switch2Each port is a separate domainOne (broadcast goes to every port)
Router3Each interface separateEach interface separate

On a full-duplex switch connection (separate send and receive wires between host and switch) collisions never occur; CSMA/CD is effectively disabled.

A VLAN (virtual LAN) logically splits a single physical switch into several switches. Different VLANs are different broadcast domains; traffic between them must pass through a router. Organizations use them to separate guest, student and management networks: a security boundary.

ARP: from IP address to MAC address

A host wants to send an IP datagram to a host on the same subnet. It needs to write the destination MAC in the frame but knows only the IP. ARP (Address Resolution Protocol) does this mapping.

  1. The host looks in its ARP cache. If there is an entry, it uses it.
  2. If not, it broadcasts an ARP request: destination MAC FF:FF:FF:FF:FF:FF, content “Who has 10.0.0.9? I’m 10.0.0.5, my MAC is this.”
  3. Everyone on the LAN receives the request, and only 10.0.0.9 answers. The ARP reply goes directly to the asker as a unicast.
  4. The asker stores the mapping in its cache with a TTL (minutes).

ARP is plug-and-play: the administrator configures nothing.

Sending to another subnet

H1 (192.168.1.10/24) is writing to a web server (93.184.216.34). Since the destination is on a different subnet:

1. H1 checks its mask: the destination is not in my subnet -> send to the default gateway
2. H1 does ARP for the gateway IP (192.168.1.1) and learns the MAC of the router interface
3. Frame: dst MAC = router interface, dst IP = 93.184.216.34
4. The router strips the frame, looks at the IP, and builds a NEW frame for the next link
   (new src MAC = router's outgoing interface, dst MAC = next node)

PITFALL · no ARP for the remote server. ARP works only within the same subnet; a broadcast does not cross a router. In an exam, the answer to “what is the dst MAC?” is the MAC of the gateway, not of the server. The addresses in the IP header, on the other hand, do not change along the way (except with NAT, week 5).

Ethernet and ARP assume that everyone on the local network is honest. When that assumption collapses:

AttackHow it worksEffectDefense
ARP spoofing (poisoning)The attacker uses unsolicited ARP replies to say “the gateway’s IP is at my MAC”Traffic flows through the attacker: MITMDynamic ARP Inspection, static ARP, TLS
MAC floodingThousands of frames with fake source MACs fill the CAM tableThe switch floods unknown destinations, and the attacker sees everythingPort security (MAC limit per port)
MAC spoofingThe card’s MAC is changed to someone else’sMAC-based access control is bypassed802.1X authentication
Rogue DHCPA fake DHCP server hands out itself as the gatewayMITMDHCP snooping

The common lesson: at the link layer, identity is claimed, not verified. That is why we rely on end-to-end encryption (week 12, TLS) for confidentiality and integrity.

Common mistakes

Wrong ideaCorrect
Ethernet minimum frame is 46 bytes46 bytes is the payload; the frame is 64 bytes.
The preamble is included in the frame sizeThe 64 and 1518 limits do not include the preamble.
A switch learns the destination addressIt learns the source address and looks up the destination.
A frame for a destination not in the table is droppedIt is flooded. What is dropped is a destination on the same port.
The ARP reply is also broadcastThe reply is unicast.
ARP is done for the remote server’s MACIt is done for the gateway.
A switch splits the broadcast domainIt doesn’t; a router or a VLAN does.
A MAC address cannot be changedIt is easily changed in software; it is not proof of identity.

Test yourself

Exam-style questions. Solve them on paper first, then reveal the answer.

Question 1easy

An IP datagram of only 20 bytes is sent inside an Ethernet frame. How many bytes of padding must be added to the payload?

Show answer
26 bytes

The Ethernet payload must be at least 46 bytes (frame 6 + 6 + 2 + 46 + 4 = 64 bytes). 46−20=2646 - 20 = 26 bytes of padding.
The receiver works out the padding from the total length field in the IP header and discards it.

Question 2easy

Which Ethernet header field tells the receiver which network-layer protocol is carried in the payload?

  1. Preamble
  2. Destination MAC address
  3. EtherType
  4. FCS (CRC)
Show answer
C) EtherType

EtherType: 0x0800 IPv4, 0x0806 ARP, 0x86DD IPv6. From this the receiver knows which protocol to hand the payload to (demultiplexing).
The FCS is for error detection, and the preamble is for clock synchronization.

Question 3easy

How many bits are in a MAC address, and how many bits form the OUI (vendor prefix)?

  1. 32 and 16
  2. 48 and 24
  3. 48 and 16
  4. 64 and 32
Show answer
B) 48 and 24

A MAC is 48 bits (6 bytes), for example 3C:22:FB:10:A4:7E. The first 24 bits are the OUI that the IEEE assigns to the manufacturer, and the last 24 bits are the manufacturer's serial number.
The address space is 248≈2.8×10142^{48} \approx 2.8 \times 10^{14}.

Question 4medium

A frame's destination MAC address begins with the byte 0x01. What kind of address is it?

  1. Unicast, globally administered
  2. Unicast, locally administered
  3. Multicast (group) address
  4. Invalid address
Show answer
C) Multicast (group) address

The lowest bit of the first byte is the I/G bit: 1 means a group (multicast/broadcast), 0 means a single interface (unicast).0x01 = 00000001, the lowest bit is 1: multicast. The second-lowest bit (U/L) is 0: global. The MAC equivalent of IPv4 multicast starts with 01:00:5E.

Question 5medium

A switch with an empty table receives these frames in order (source, destination, incoming port): (A, B, 1), (B, A, 2), (C, A, 3), (A, C, 1). What does the switch do with each frame?

Show answer
flood, port 1, port 1, port 3

For each frame the switch records the source address with the incoming port in the table, and looks up the destination in the table.
1) A→B: A=1 is learned, B is unknown → flood (all ports except 1).
2) B→A: B=2 is learned, A is in the table at port 1 → only port 1.
3) C→A: C=3 is learned, A is at port 1 → port 1.
4) A→C: C is at port 3 → port 3.

Question 6medium

A switch receives a frame on port 4 whose destination MAC is already in the table, mapped to port 4. What does it do?

  1. Floods it to all ports
  2. Forwards it back out port 4
  3. Discards it (filtering)
  4. Sends an ARP request
Show answer
C) Discards it (filtering)

The destination is on the segment the frame came from. The destination has already seen the frame (same segment), so the switch has no need to forward it: it discards the frame. This is called filtering.

Question 7easy

Host H1 (IP 10.0.0.5) wants to send an IP datagram to 10.0.0.9 on the same LAN but does not know its MAC address. Which statement about ARP is correct?

  1. The ARP request is unicast to 10.0.0.9 and the reply is broadcast
  2. The ARP request is broadcast to FF:FF:FF:FF:FF:FF and the reply is unicast to H1
  3. Both request and reply are broadcast
  4. ARP queries a DNS server for the MAC address
Show answer
B) The ARP request is broadcast to FF:FF:FF:FF:FF:FF and the reply is unicast to H1

Since H1 doesn't know the MAC, it broadcasts the question to everyone: "Who has 10.0.0.9? Tell 10.0.0.5."
Only 10.0.0.9 answers, and since the asker's MAC is in the request, it sends the reply directly to H1 (unicast). H1 stores the result in its ARP cache with a TTL.

Question 8hard

Host H1 (subnet 192.168.1.0/24) sends a datagram to a web server at 93.184.216.34. In the Ethernet frame that leaves H1, what are the destination IP and the destination MAC?

  1. IP of the server; MAC of the server
  2. IP of the router; MAC of the router
  3. IP of the server; MAC of H1's default gateway (router interface)
  4. IP of the router; MAC of the server
Show answer
C) IP of the server; MAC of H1's default gateway (router interface)

The destination is on a different subnet. H1 performs ARP not for the server but for the default gateway.
The IP header stays the same end to end (the destination is the server). The MAC header is rewritten on every link; on this link the destination is the MAC of the router interface.

Question 9medium

Counting the 8-byte preamble and the 12-byte inter-frame gap as overhead, what fraction of the wire time carries payload for a maximum-size frame (1500-byte payload)?

Show answer
≈ 97.53%

Frame: 6+6+2+1500+4=15186+6+2+1500+4 = 1518 bytes. On the wire there are also an 8-byte preamble and a 12-byte gap.1500/(1518+8+12)=1500/1538≈0.97531500 / (1518 + 8 + 12) = 1500 / 1538 \approx 0.9753.
With the minimum payload (46 bytes) it drops to 46/84≈54.76%46/84 \approx 54.76\%.

Question 10easy

How long does it take to transmit a maximum-size 1518-byte Ethernet frame (excluding preamble) at 100 Mbps?

Show answer
121.44 µs

L=1518×8=12,144L = 1518 \times 8 = 12{,}144 bits. L/R=12144/108=1.2144×10−4L/R = 12144 / 10^8 = 1.2144 \times 10^{-4} s =121.44 μs= 121.44\ \mu s.

Question 11hard

An attacker on the LAN keeps sending unsolicited ARP replies saying 'IP 192.168.1.1 is at the attacker's MAC'. What is the attack and a suitable defense?

  1. MAC flooding; increase the switch table size
  2. ARP spoofing (poisoning) enabling man-in-the-middle; Dynamic ARP Inspection or static ARP entries for the gateway
  3. DNS spoofing; use DNSSEC
  4. SYN flood; use SYN cookies
Show answer
B) ARP spoofing (poisoning) enabling man-in-the-middle; Dynamic ARP Inspection or static ARP entries for the gateway

ARP has no authentication, and hosts store even replies they never asked for in their cache. The victims send the traffic meant for the gateway to the attacker: a man-in-the-middle (MITM), who can eavesdrop or modify.
Defense: Dynamic ARP Inspection on the switch (drop ARP that doesn't match DHCP records), static ARP for critical addresses, and most importantly end-to-end encryption (TLS), because even if the attacker gets in the middle, they can't read it.

Question 12hard

A network has 3 hubs, each with 4 hosts, all connected to one 3-port switch. How many collision domains and how many broadcast domains are there?

Show answer
3 collision domains, 1 broadcast domain

A hub merges all its ports into a single collision domain. Each port of a switch is a separate collision domain: 3 ports → 3 collision domains (each hub with its hosts is one domain).
A switch forwards broadcasts to all ports, so everything is one broadcast domain. What splits a broadcast domain is a router (or a VLAN).

Verification: Frame sizes, padding, efficiency, transmission time, MAC bit fields (I/G, U/L) and the switch learning trace were computed with node (verify/SEN2008/04.mjs). The ARP and collision domain questions are conceptual; they were checked against the protocol definitions.

Review card

Ethernet: [preamble 8][dst 6][src 6][type 2][data 46-1500][FCS 4] min frame 64 B (with padding), max 1518 B; FCS = CRC-32; preamble not counted EtherType: 0800 IPv4, 0806 ARP, 86DD IPv6 MAC 48 bit: OUI (24) + serial (24). Broadcast FF:FF:FF:FF:FF:FF lowest bit of first byte 1 -> multicast; second bit 1 -> locally administered Switch: LEARN the SOURCE (MAC -> port, TTL), LOOK UP the DESTINATION: not found -> flood | same port -> filter (drop) | other port -> only there Hub: one collision domain. Switch: collision domain per port, one broadcast domain Router and VLAN split the broadcast domain ARP: request broadcast, reply unicast; cache TTL; only within the same subnet Remote destination: dst IP = server, dst MAC = default gateway No authentication in ARP -> ARP spoofing -> MITM (defense: DAI, static ARP, TLS) MAC flooding: CAM overflows, switch floods like a hub (defense: port security)