LINUX协议栈详解 ARP协议

ARP协议负责从IP地址到物理MAC地址的转换。

ARP格式

/*
 *     This structure defines an ethernet arpheader.
 */
 
struct arphdr {
         __be16              ar_hrd;              /* format of hardware address       */
         __be16              ar_pro;              /* format of protocol address */
         unsignedchar  ar_hln;               /* length of hardware address        */
         unsignedchar  ar_pln;               /* length of protocol address  */
         __be16              ar_op;                /* ARP opcode (command)                */
 
#if 0
          /*
           *  Ethernet looks like this : This bit is variable sized however...
           */
         unsignedchar           ar_sha[ETH_ALEN];          /* sender hardware address   */
         unsignedchar           ar_sip[4];          /* sender IP address                 */
         unsignedchar           ar_tha[ETH_ALEN]; /* target hardware address    */
         unsignedchar           ar_tip[4];          /* target IP address                  */
#endif
 
};


 

接收ARP的函数是arp_rcv,在跑完NFPROTO_ARP钩子后,调用arp_process处理ARP请求,简单考虑,ARP操作分为

/* ARP protocol opcodes. */
#define     ARPOP_REQUEST    1                /*ARP request                            */
#define     ARPOP_REPLY 2                /*ARP reply                        */
#define     ARPOP_RREQUEST  3                /*RARP request                         */
#define     ARPOP_RREPLY        4                /*RARP reply                     */
#define     ARPOP_InREQUEST 8                /*InARP request               */
#define     ARPOP_InREPLY       9                /*InARP reply                    */
#define     ARPOP_NAK     10              /*(ATM)ARP NAK                       */

1,  ARPOP_REQUEST

如果到本地,则更新arp表,并且发送ARPOP_REPLY回应。

如果是到其他地方,则看是否开启arp代理,如果开启,则发送,并且更新arp表。

2,  如果为其他的操作,则也更新neigh_update

 

发送ARP的函数是arp_send,调用arp_create负责创建一个新的skb包,最后调用arp_xmit发送,当然发送过程也要经过NFPROTO_ARP钩子,最后调用最通用的发送函数:dev_queue_xmit。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值