Vous êtes sur la page 1sur 17

Address Resolution Protocol

(ARP)

Reading: Chapter 15

|  | 
   
ARP
‡ Mapping between layer 3 and layer 2
addresses
± IP and MAC addresses
± Given an IP address, what is the
corresponding MAC address?
‡ Built on top of data-link layer
± Encapsulated and transmitted in data-link
layer data frames
|  | 
   
An example
ARP-Request to MAC FF:FF:FF:FF:FF:FF

MAC address of 129.25.10.11 ?


1 Reply to: 49:72:16:08:64:14 (129.25.10.72)

ARP-Reply to MAC 49:72:16:08:64:14

Reply:t: 129.25.10.11 (49:78:21:21:23:90)


Requested by:: 129.25.10.72 (49:72:16:08:64:14)

a 

  

Router R

a  

  

Computer A: Computer B: Computer C:


a   a  a 

   
   
  

|  | 
  
ARP packet format
ARP Protocol Data Unit
0 15 31

å  e type (l ye 2) Potocol type (l ye 3)

Aess length Aess length


L ye 2 (n) L ye 3 (m)
Ope tion

Souce ess (l ye 2): n bytes

Souce ess (l ye 3): m bytes

Destini tion ess (l ye 2): n bytes

Destin tion ess (l ye 3): m bytes

L ye-2 he e L ye-2 p ylo  L ye-3 t ile

|  | 
   
ARP packet format: example
ARP-Request to FF:FF:FF:FF:FF:FF ARP-Reply to 49:72:16:08:64:14

0 15 31 0 15 31

0x00 01 (Ethernet) 0x80 00 (Internet Protocol) 0x00 01 (Ethernet) 0x80 00 (Internet Protocol)

6 4 0x00 01 (ARP-Request) 6 4 0x00 02 (ARP-Reply)

49 72 16 08 49 72 16 08

64 14 129 25 64 14 129 25

10 72 00 00 10 72 49 78

00 00 00 00 21 21 23 90

129 25 10 11 129 25 10 11

|  | 
  

Receiving ARP packet and


replying
‡ Insert layer 2 address (MAC address)
‡ Swapping source ± destination address
fields
‡ Changing operation field (reply)
‡ Sending ARP reply

‡ Source¶s IP/MAC pair also inserted into


ARP cache at receiver
|  | 
   
Implementation
‡ Neighbors
± Computers that can be directly reachable
‡ Data structures
± arp_tbl
± neigh_table
± neighbor
± neigh_ops
‡ Functions
± Sending/receiving ARP packets
± Managing ARP data structures

|  | 
   
Data structures
neigh_table
neigh_tables

arp_tbl
neigh_table
neigh_table
next
family: AF_INET
...
constructor Y  

...
gc_timer     

...
0 neighbour neighbour
hash_buckets[NEIGH..]

neighbour
1
next
neigh_table net_device
neigh_parms
dev
   
timer Y

neigh_ops
ha
hh_cache
hh_cache
nud_state
next output
ref_cnt sk_buff
arp_queue
hh_type: ETH_P_IP ...
hh_output
hh_data:
00 80 23 32 12
49 72 16 08 64 14 neighbour
NEIGH_-
49 78 21 21 23 90
HASHMASK -1

|  | 
   
neighbor
‡ dev:
± Pointer to corresponding network device
‡ timer:
± Pointer to timer to initiate handling routine neigh_timer_handler()
‡ ha:
± Hardware address of the neighbor
‡ hh:
± Hardware header
‡ nud_state:
± State concerning the neighboring computer
‡ output:
± Function to send data packet to the neighbor
‡ arp_queue
± Queue of packets waiting to be transmitted
‡ opts:
± Pointer to a neigh_ops structure

|  | 
  
neigh_table
‡ family
± Address family, for IP, it is AF_INET
‡ constructor
± Function to construct a neighbor structure
‡ gc_timer
± Garbage collection timer
‡ hash_buckets[NEIGH_HASHMASK+1]
± Hash table for maintaining neighbor info
|  | 
   
neigh_ops
‡ Different neighbor characteristics
± Generic, direct, hh, and broken
‡ This structure defines the corresponding
functions for different devices
± destructor, solicit, error_report, output,
connected_output, hh_output, queue_xmit

|  | 
   
States
No sign of life in
Y Y  
  Set timer
NUD_STALE

Receive
packet

receive
NUD_ ARP-Reply
REACHABLE NUD_DELAY

Time
Receive ARP-Reply out

NUD_
INCOMPLETE NUD_PROBE

NUD_NONE
Y    Y  
initialize an entry, Requests sent,
Send an ARP request No reply

Permanent
Eintrag

NUD_NONE NUD_
FAILED
NOARP-
Device


 Y  Garbage Collection
Create an entry completed.
NUD_NOARP
Delete entry

No
Emtru

|  | 
   
ARP operation
Higher LYyers

IPv4 IPv4

ip_queue_xmit

ip_finish_output2

Yrp.c, neighbour.c
Yrp.c, neighbour.c neigh_update
arp_tbl

ARP-Reply neigh_lookup

neigh_esolve_
output
ARP-Request
arp_rcv arp_send

dev.c dev.c
ETå_P_ARP

net_rx_action dev_queue_xmit

|  | 
   
Handling ARP PDUs
‡ arp_rcv()
± Some sanity check
± NF_ARP_IN
± arp_process()
‡ arp_process()
± Some more sanity check
± For both request/reply
‡ Update ARP cache (neigh_lookup())
± For request
‡ arp_send() to send a reply

|  | 
   
Handling ARP packets
‡ arp_send()
± Allocating socket buffer
± Filling hardware header
± Filling ARP data
± NF_ARP_OUT
± dev_queue_xmit()
‡ neigh_update()
± Updating neighbor entry state
± Setting up corresponding output function, etc
|  | 
   

Handling unresolved IP
packets
‡ neigh_resolve_output()
± Sending the packet if it is OK (e.g., REACHALBE
state)
± Otherwise (e.g., INCOMPLETE state)
‡ Storing the pkt in arp_queue queue by
neigh_event_send()
‡ neigh_event_send()
± Checking if the pkt can be sent
± If not, storing IP packet and sending ARP request
(arp_solicit())
‡ arp_solicit()
± Send ARP request by arp_send()
|  | 
   
Some other neighbor
managing functions
‡ neigh_connect()
‡ neigh_suspect()
‡ neigh_destroy()
‡ neigh_sync()
‡ neigh_periodic_timer()
‡ neigh_timer_handler()

|  |