4.3 Control-plane protocol
4.3.1 ARP
当一个host需要得到目的host的mac时,它会广播一个arp request。目的host(或gateway)会应答一个arp reply(单播)。
hardware addresstype 和protocoladdress type表明哪个协议用在链路层或网络层。如果是Ethernet则hardware address type为1,如果是IP,则protocol address type为0x0800。
H.Addr Len:硬件地址长度,如果是Ethernet则hardware address type为6
P.Addr Len:协议地址长度,如果是IP,则protocol address type为4
operation code:arp的操作:request (1), reply (2), RARP request (3),and RARP reply (4)
紧接着的是发送者的mac和ip地址,最后两个field是接收者的mac和ip地址。
Remark:Ethernet的type id是0x0806为arp。就是ethernet header后接arp header。Arp请求的广播地址为0xFFFFFFFFFFFF.
Implementation for linux
Arp的大部分代码在src/net/ipv4/arp.c。
Arp最重要的数据结构是struct neigh_table arp_tbl,包括一个hash_buckets成员,而hash_buckets指向arp cache。
arp_send() 和arp_rcv()分别处理arp的发送和接收。下图是arp_send() 和 arp_rcv()的调用框图。
arp_send() 调用arp_create() 来生成一个 ARP packet 然后调用arp_xmit() ,最后调用 dev_queue_xmit() 来发送arp packet。
当一个arppacket被接收时arp_process()被调用,在arp_process()中,_niegh_lookp()被调用来搜索hash_buckets hash table,hash key是source IP address。
arp_process()来处理一个请求并发送应答,无论该请求来自于本机器本身,还是来自于其他的机器。