NET/3 is associated with the routing table in ARP and implemented closely, showing our narrative description of ARP usage samples.
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvve9erdkxmq==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
Below, we briefly outline the relevant points in the diagram.
The bidirectional list of 1.LLINFO_ARP structures includes a small amount of information for each ARP known hardware address. The global variable Llinfo_arp with the same name is the head node of the linked list. In the figure
Without drawing the first La_prev pointer to the last item, the La_next pointer to the last item points to the first item.
The list is processed by the ARP clock function every 5 minutes.
2. The IP address of each known hardware address corresponds to a Routing table node (rtentry structure).
The La_rt pointer member of the LLINFO_ARP structure is used to point to the corresponding rtentry
Structure. The same way. The Rt_llinfo pointer member of the RTENTRY structure points to the LLINFO_ARP structure.
3. The leftmost Fourth routing table node in the figure does not have a LLINFO_ARP structure, which corresponds to the route entry for local Ethernet (140.252.13.32). The node's
The C-bit is set in the Rt_flags. Indicates that the node is used to replicate to other nodes.
The Rt_gateway pointer member in the 4.RTENTRY structure points to a SOCKADDR_DL structure variable. Assuming that the structure that holds the physical address length has a Sdl_alen member of 6, then
The SOCKADDR_DL structure includes the corresponding hardware address information.
5. The corresponding pointer to the RT_IFP member of the routing node variable points to the ifnet structure of the corresponding network device interface.
The two routing nodes in the middle correspond to the other hosts on the Ethernet,
Both nodes point to le_softc[0]. The routing node on the right points to the loopback structure, loif. Because rt_ifp.if_output points to the output function, the destination is local data
The datagram is routed to the loopback interface.
6. Each route node also has pointer variables that point to the corresponding IN_IFADDR structure.
The 7.la_hold member is a pointer to the MBUF list. When you want to send a datagram to an IP, you need to broadcast an ARP request. When the kernel waits for the ARP to answer, save
The address information for the head node of the mbuf chain where the outgoing datagram is placed is stored in the la_hold. When the ARP answer is received, La_hold points to the IP data in the MBUF linked list
be sent out.
8. The variable rmx_expire of the rt_metric structure in the Routing table node holds the timing information associated with the corresponding ARP node, which is used to implement the delete timeout ARP node.
Shows the relationship of the ARP function to other kernel functions.
1.ARP structure
The format of the ARP packets that are transmitted in Ethernet is for example as seen:
The structure Ether_header defines the Ethernet frame header; The structure ARPHDR defines the next 5 fields whose information is used to transmit ARP requests on whatever type of media
and answer; The ETHER_ARP structure includes the address of the source host and destination host, in addition to the ARPHDR structure.
The definition of the structure ARPHDR for example with what is seen:
Shows the definition of the ETHER_ARP structure. This includes the ARPHDR structure, the IP address of the source host and the destination host, and the hardware address.
Each ARP node has a LLINFO_ARP structure, and the head nodes of all of these structures are assigned as global variables. We often put the linked list
Called the ARP fast cache.
The first two items of the doubly linked list are updated by two functions of Insque and Remque.
2.arpwhohas function
The Arpwhohas function is usually called by Arpresolve. Used to broadcast an ARP request.
It can also be called by each Ethernet device driver, assigning IP addresses to
The device interface is actively sending an address-linking message (SIOCSIFADDR). Active sending of address-linked information is not only capable of detecting the presence of IP in Ethernet
Address conflicts and enable other machines to update their corresponding information (free ARP). Arpwhohas is simply called under the Arprequest function.
3.arprequest function
The Arprequest function is called by the Arpwhohas function. Used to broadcast an ARP request.
The function establishes an ARP grouping. and pass it to the output function of the interface.
Shows the two data structures Mbuf and sockaddr created by the function. In addition, there are two pointers to the functions used in EH and EA.
The approximate process flow for functions such as the following:
1. Assign and initialize the MBUF. Assign a mbuf to the header of a grouped data and assign a value to two length fields.
2. Initialize the pointer. Assign a value to the EA and eh two pointers. and assigns the value of the ETHER_ARP structure to 0.
3. Fill the Ethernet frame header. The destination Ethernet address is set to the Ethernet broadcast address. and set the Ethernet frame type to Ethertype_arp.
Shows the different
Constant value of the Ethernet frame Type field.
4. Populate the ARP field. Populate all fields of the Ether_arp, except for the destination hardware address that the ARP request is to ask.
5. Fill the sockaddr. and call the interface output function.
The value of the sa_family member of the interface address structure is set to Ap_unspec. The value of the Sa_number member
Set to 16. Call the interface output function Ether_output.
4.arpintr function
When the Ether_input function receives an Ethernet frame with a Frame type field of Ethertype_arp, a software interrupt with a finite level of netisr_arp is generated and
The frame is closed behind the ARP input queue ARPINTRQ. The ARPINTR function is called when the kernel processes the software interrupt.
The approximate processing flow for a function is:
Only when the hardware type of the frame is indicated as an Ethernet address, and the length of the frame is greater than or equal to the length of the ARPHDR structure plus two hardware addresses and two protocol addresses
Length. The frame talent is processed. If the type of the protocol address is ETHERTYPE_IP or ethertype_iptrailers, call the In_arpinput function.
Otherwise the frame is discarded.
5.in_arpinput function
This function is called by ARPINTR to process the received ARP Request/answer. The concept of ARP itself is relatively simple, but with many rules, the implementation is more
Complex. The following two typical scenarios are seen below.
1. If you receive a request for a native IP address, send an answer. This is a common situation and it is very obvious that we will continue to receive from that host
Data report. It will then be returned to the paper. So. Suppose we don't have a corresponding ARP node for it. You should add an ARP node. Because then we
Already know each other's IP address and hardware address.
2. Assuming that an ARP answer is received, then the ARP node is complete and therefore knows the other's hardware address, which is stored in the SOCKADDR_DL structure.
All data destined for that address will be sent.
3. Assume that the other host sends an ARP request or answer, in which the sender's IP address is the same as the native, then there must be a host configuration error, NET/3 will detect
To the error, and a message to the administrator level.
4. Assume that the host receives a request or answer from another host. The corresponding ARP node already exists, but the hardware address sends a change. Then the ARP node is updated.
5. The host can be configured as a proxy arpserver. Such a case. The host can respond to ARP requests on behalf of other hosts. Provide the hardware address of the other host in the answer.
The host of the corresponding destination hardware address in the proxy ARP answer must be able to send the IP datagram to the destination address specified in the ARP request.
The approximate flow of the function is as follows:
1. Find the matching interface and IP address. Search the Internet address list for this computer (the list of IN_IFADDR structures). Remember that an interface can have multiple IP addresses.
2. Verify the sender's hardware address.
Assume that the sender's hardware address equals the hardware address of the native interface. That was due to a request sent by this machine. Ignore the grouping.
Assuming that the sender's hardware address equals the broadcast address of the Ethernet, the error is indicated.
Record the error and discard the group.
3. Check the sender IP address.
Suppose the sender IP address is equal to the one IP address that the computer is using, and there is a mistake in the native system configuration.
4. Search the routing table for the nodes that match the sender's IP address. The Arplookup function looks for the IP address of the sender in the ARP fast cache. When the ARP group
The destination address is the machine, always wear a piece of ARP node.
5. Update existing nodes or populate new nodes. The statement only runs when the following three conditions are true:
A. Find an existing ARP node or successfully create a new ARP node.
The B.arp node points to a route table node.
C. The Re_gateway field of the routing table node points to a SOCKADDR_DL structure.
6. Check to see if the sender's hardware address has changed. Assumptions have changed. The sender hardware address is logged and the recently resolved ARP node is updated.
7. Assume that the ARP operation is not a request. Then discard the received groupings.
8. Generate an answer corresponding to the ARP request. The ARP response is only generated when the following two scenarios are available:
A. This machine is the destination host that the request is looking for.
B. This machine is the ARP proxy server for the destination host that the request is looking for.
9. Fill the sockaddr with the Ethernet frame header.
10. Transfer the ARP answer to the interface output function. and returns.
6.ARP Timer function
ARP nodes are usually dynamic and are created when needed. Super-times to delete their own initiative. Also agrees to create a permanent node for the administrator.
The Arp_rtrequest function enables the Arptimer function to be called for the first time. The Arptimer then makes itself called once every 5 minutes.
Arptimer Viewing the list of ARP nodes
Each node in the Arptfree, assuming that it is not a permanent node, and the time has timed out, then the node is deleted.
7.arpresolve function
The Ether_output function calls the Arpresolve function to obtain an Ethernet address for a corresponding IP address. The Arpresolve function utilizes the la_hold of the LLINFO_ARP structure
The member pointer "keeps" outgoing IP datagrams, sends an ARP request, receives an ARP reply, and then sends the persisted IP datagram.
Arpresolve should avoid ARP flooding, that is to say. It should not quickly and repeatedly send ARP requests when an ARP response has not yet been received, in which case there are two main
Cause, first, there are multiple IP datagrams destined for the same host that has not yet resolved the hardware address. Second. Each shard of an IP datagram is grouped as a separate
Call Ether_output.
NET/3 uses the following method to avoid ARP flooding.
1.NET/3 does not send multiple ARP requests for the same destination in the same second.
2. Assuming that no answer has been received after 5 consecutive ARP requests (i.e. 5 seconds), the Rtf_reject flag of the routing node is set to 1. The implementation is set to 20 seconds in the future.
This causes Ether_output to reject IP datagrams destined for that destination within 20 seconds.
After 3.2 seconds, Arpresolve will continue to send ARP requests for that destination host.
8.arplookup function
arplookup function call routing function Rtalloc1 find the ARP node in the Internet route table, we have seen 3 calls to Arplookup:
1. In the in_arpinput. After receiving the ARP packet, the corresponding source IP address looks for or creates an ARP node.
2. In In_arpinput, after receiving the ARP request. See if there is a proxy ARP node for the destination hardware address.
4. In the Arpresolve. Find or create an ARP node that corresponds to the IP address of the datagram to be sent.
Assuming the arplookup runs successfully, it returns a pointer to the corresponding LLINFO_ARP structure, otherwise a null pointer is returned.
9.arp_rtrequest functionin Arp, we will call two route table functions. 1.arplookup calls Rtalloc1 to find the ARP node. If a matching node is not found, a new ARP node is created.
2.arptfree calls Rtrequest with the Rtm_delete command. Deletes the routing table node for the corresponding ARP node.
In addition, the ARP command manipulates the ARP fast cache by sending and receiving routing packets on the routing jack. ARP publishes routing information in the order of Rtm_resolve, Rtm_delete, and rt_get. The first two parameters are used to call Rtrequest, and the third parameter is used for Rtalloc1.
Finally, when the Ethernet device driver obtains the IP address given to the interface, Rtinit adds a network justification, so the rtrequest function is called and the number of references is Rtm_add, the flag is rtf_up and rtf_cloning. Each IFADDR structure has a pointer to a function (Ifa_rtrequest member). This function is invoked on its own initiative when creating or deleting a route table node, and for all Ethernet devices, In_ifinit points the pointer to the Arp_rtrequest function. Therefore, when the call route function creates or deletes a route table node for ARP , Arp_rtrequest is always called, and when the Discretionary route table function is called, the Arp_rtrequest function is doing all the work required to initialize or exit the processing. For example , when a new ARP node is created, memory is allocated to the LLINFO_ARP structure within arp_rtrequest. Same. When the routing function finishes processing a rtm_delete command , arp_rtrequest the job is to delete the Llinfo_arp struct.
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
TCP/IP Works detailed explanation 2: Reach "note--arp: Address Resolution Protocol