From 502c9a404a7588d20f9947c58d72b71e9e2f9c2b Mon Sep 17 00:00:00 2001 From: Ryan Su Date: Sun, 18 Feb 2024 10:52:34 +0800 Subject: [PATCH] docs: arp doc --- src/en/guide/concepts/network/5-arp.md | 85 +++++++++++++++++++++++++- src/guide/concepts/network/5-arp.md | 84 ++++++++++++++++++++++++- 2 files changed, 167 insertions(+), 2 deletions(-) diff --git a/src/en/guide/concepts/network/5-arp.md b/src/en/guide/concepts/network/5-arp.md index 4a206e87..3369a5b1 100644 --- a/src/en/guide/concepts/network/5-arp.md +++ b/src/en/guide/concepts/network/5-arp.md @@ -3,4 +3,87 @@ order: 5 title: ARP --- -## \ No newline at end of file +## Introduction + +The **Address Resolution Protocol (ARP)** is an important protocol in IPv4 that is used to determine the MAC address of a target device based on its IP address, ensuring the correct delivery of data. + +::: tip MAC Address +The Media Access Control Address (MAC) is also known as the hardware address, which uniquely identifies network devices such as network cards and routers. The MAC address is 48 bits long, with the first 24 bits managed by IEEE and the last 24 bits managed by hardware vendors. Unlike the dynamic allocation of IP addresses, MAC addresses are generally written into firmware or hardware and cannot be modified. + +> MAC: `FF-FF-FF-FF-FF-FF` is the reserved broadcast address. + +::: details Structure of MAC Address + +| Bits | Meaning | +| -------------- | ---------------------------------------------- | +| 1st bit | Unicast address (0)/Multicast address (1) | +| 2nd bit | Global address (0)/Local address (1) | +| 3rd-24th bits | Managed by IEEE and guaranteed to be unique | +| 25th-48th bits | Managed by vendors and guaranteed to be unique | + +::: + +## ARP Packet + +### Packet Format + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Length (bits)4848161616881648324832
+ Data Type + Destination Ethernet AddressSource Ethernet AddressFrame TypeHardware TypeProtocol TypeHardware Address LengthProtocol Address LengthOperation CodeSource Hardware AddressSource Protocol AddressDestination Hardware AddressDestination Protocol Address
+ Composition + 14 bytes Ethernet header28 bytes ARP request/response
+ +::: tip + + +| Field | Length | Description | +| ------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------ | +| Ethernet destination MAC | 48 bits | Ethernet destination MAC address. This field in an ARP Request packet is the broadcast address `0xffff-ffff-ffff` | +| Ethernet source MAC | 48 bits | Ethernet source MAC address. | +| Frame type | 16 bits | Data type. The value of this field is `0x0806` for an ARP Request or Reply packet | +| Hardware type | 16 bits | Type of the hardware address. The value of this field is 1 for an Ethernet. | +| Protocol type | 16 bits | Type of the protocol address to be mapped on the sender. The value of this field is `0x0800` for an IP address. | +| Hardware address length | 8 bits | Hardware address length. The value of this field is `6` for an ARP Request or Reply packet. | +| Protocol address length | 8 bits | Protocol address length. The value of this field is `4` for an ARP Request or Reply packet. | +| OP | 16 bits | Operation type. The values are as follows: 1: ARP Request packet 2: ARP Reply packet | +| Source MAC | 48 bits | Source MAC address. The value of this field is the same as the Ethernet source MAC address in the Ethernet frame header. | +| Source IP | 32 bits | Source IP address | +| Destination MAC | 48 bits | Destination MAC address. The value of this field in an ARP Request packet is `0x0000-0000-0000` | +| Destination IP | 32 bits | Destination IP address | + +::: \ No newline at end of file diff --git a/src/guide/concepts/network/5-arp.md b/src/guide/concepts/network/5-arp.md index 4a206e87..ac56aafc 100644 --- a/src/guide/concepts/network/5-arp.md +++ b/src/guide/concepts/network/5-arp.md @@ -3,4 +3,86 @@ order: 5 title: ARP --- -## \ No newline at end of file +## 介绍 + +**地址解析协议(Address Resolution Protocol, ARP)** 是 IPV4 中重要的协议,主要用于通过 IP 地址确定目标设备的 MAC 地址,以保证数据的正确送达。 + +::: tip MAC 地址 +媒体访问控制地址 (Media Access Control Address, MAC) 又称为硬件地址,用来**唯一**标识网络设备,如网卡、路由器等。MAC 地址长度为 48 位,3 - 24 位由 IEEE 管理,后 24 位由硬件厂商管理。和 IP 的动态分配不同, MAC 地址一般会写入固件或硬件中,是不可修改的。 + +> MAC: `FF-FF-FF-FF-FF-FF` 是预留的广播地址 + +::: details MAC 地址的构成 + +| 位数 | 含义 | +| --------- | ------------------------ | +| 第1位 | 单播地址(0)/多播地址(1) | +| 第2位 | 全局地址(0)/本地地址(1) | +| 第3-24位 | 由 IEEE 管理并保证不重复 | +| 第25-48位 | 由厂商管理并保证不重复 | + +::: + +## ARP 报文 + +### 报文格式 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
长度(位)4848161616881648324832
+ 数据类型 + 目标以太网地址源以太网地址帧类型硬件类型协议类型硬件地址长度协议地址长度操作码源硬件地址源协议地址目标硬件地址目标协议地址
+ 组成 + 14字节 以太网首部28字节 ARP请求/应答
+ +::: tip + +| 字段 | 长度 | 描述 | +| ------------------- | ----- | --------------------------------------------------------------------------- | +| 以太网目标 MAC 地址 | 48 位 | 以太网目标 MAC 地址。在 ARP 请求报文中,该字段为广播地址 `0xffff-ffff-ffff` | +| 以太网源 MAC 地址 | 48 位 | 以太网源 MAC 地址 | +| 帧类型 | 16 位 | 数据类型。该字段的值在 ARP 请求或应答报文中为 `0x0806` | +| 硬件类型 | 16 位 | 硬件地址类型。该字段的值在以太网中为 1 | +| 协议类型 | 16 位 | 要映射到发送方的协议地址类型。该字段的值为 IP 地址时为 `0x0800` | +| 硬件地址长度 | 8 位 | 硬件地址长度。该字段的值在 ARP 请求或应答报文中为 `6` | +| 协议地址长度 | 8 位 | 协议地址长度。该字段的值在 ARP 请求或应答报文中为 `4` | +| 操作码 | 16 位 | 操作类型。值如下:1: ARP 请求报文 2: ARP 应答报文 | +| 源 MAC 地址 | 48 位 | 源 MAC 地址。该字段的值与以太网帧头中的以太网源 MAC 地址相同 | +| 源 IP 地址 | 32 位 | 源 IP 地址 | +| 目标 MAC 地址 | 48 位 | 目标 MAC 地址。在 ARP 请求报文中,该字段为 `0x0000-0000-0000` | +| 目标 IP 地址 | 32 位 | 目标 IP 地址 | + +::: \ No newline at end of file