当前位置:网站首页>Implementation of ARP module in LwIP
Implementation of ARP module in LwIP
2022-06-27 00:45:00 【Longchizi】
One : data structure
Here we mainly introduce arp Table structure
struct etharp_entry {
#if ARP_QUEUEING
/**
* Pointer to queue of pending outgoing packets on this ARP entry.
*/
struct pbuf *p;
#endif
struct ip_addr ipaddr;
struct eth_addr ethaddr;
enum etharp_state state;
u8_t ctime;
};
The structure is ARP The main data structure of module operation , The main data items include :
IP Address : Indicates that you want to get the ip Of the port corresponding to the address mac Address
MAC Address : Used to save the acquired mac Address
state : Indicates the status of the current table item
Time count : Each table item has a valid time , Through this field, you can know whether the current table entry is still valid
in addition , It may also include a pbuf The pointer , Used to point to packets waiting for the entry . Whether this data item is selected or not depends on the external settings .
Usually ,arp A table is an array , Each of these items represents a ip-mac The address of , at all times , New address pairs are constantly added , At the same time, clear the invalid address pairs , This can be done through certain strategies .( The invalid address pair here is not necessarily the time invalid address pair )
Two : The function interface
Function name :etharp_init()
function :arp Module initialization
operation : The main operation is initialization arp surface , The time of the table item is cleared , The status is set to empty status .
Function name :etharp_tmr()
function : The function is arp The timer timed out to execute the function , whenever arp When the timing arrives, execute the function , It will clear arp Invalid in table ( timeout ?)entry
operation : This function traverses the entire arp Table item , Each table item is judged , The state of the next time of the table item is determined according to the state and time of the current table item .
Function name :find_entry(struct ip_addr *ipaddr, u8_t flags)
function : Inquire about arp surface , Find a match or a new entry
operation : three , First, traverse the whole query arp surface , Remember the candidacy , Secondly, select the entry with candidate qualifications , Finally, create a new entry . In a simple traversal query , The following work needs to be done : Remember the first empty entrance ; Remember the oldest stable entrance ; Remember the oldest , Pending entry without queued packets ; Remember the oldest pending entry with queued packets . Except for the empty state , For other states , If it ip Address matching , Directly return the index of the table item . in addition , Parameters flags Decide whether to choose try_hard Pattern , If this mode is selected , Then it is allowed to create a new entry through the entry of the recycling activity , That is to say, in this mode, even if all portals are in use , Then, according to the corresponding algorithm, the least important entry will be recycled and provided to the new request . If no match is found , also flag The parameters are set try_hard Pattern , The new entrance will be selected according to the following strategies : Empty inlet ; The oldest stable entrance ; Oldest pending entry without queued packets ; Oldest pending entry with queued packets . If you can find one according to the above strategy arp Index of table entries , Use the index as a new entry .
Function name :update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *ethaddr, u8_t flags)
function : stay arp Update or insert a in the table IP/MAC The address of . If a pending entry has been decided , Then all queued packets on it will be sent .
operation : First, judge the... In the parameter IP Address , If it's not a unicast address , When the error parameter is processed . Then call find_entry Found an index entry , Set the index entry . If there are queued packets on it , Send these packets
Function name :etharp_ip_input(struct netif *netif, struct pbuf *p)
function : Use the received ip The source address of the packet updates the address of the local network arp surface . The call to this function occurs after the packet is received , Pass to IP Before layer . The call to this function is mainly used to update arp surface , The basic operation is to extract IP Address information , If it belongs to local area network , Call update_arp_entry Conduct arp Table update .
operation : First, determine the source address of the packet , If not on the local network , And do nothing , return ; otherwise , call update_arp_entry to update arp surface .
Function name :eth_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
function : Respond to arp request ; about arp Respond to , Add entry item , And send queued packets ; Update address pair . in addition , This function releases pbuf The operation of , That is to say, for the received arp Packet allocated pbuf Will be released here . If it is arp request , Then directly reuse the pbuf, Modify settings , send out arp Respond to .
operation : If the currently entered arp The destination address of the package is the local address , with try_hard Mode call update_arp_entry to update arp surface , otherwise , Update using normal mode arp surface . after , according to arp The opcode of determines what to do : If it is arp request , And the destination address is the local address , Then the local structure arp Response package , Will the machine mac Fill in the address , And then send ; If it is arp Response package , Update local arp surface ( It has been done before ). Final release pbuf.
Function name :etharp_output(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
function : Add Ethernet header to the output packet or solve the problem of Ethernet address . Packets from the upper layer are sent before calling the driver interface , Call this function to set mac Address
operation : If it is a broadcast packet or a multicast packet , Directly set its mac Address , And send it directly . If it is a unicast packet , Then check whether the package is going out of the local network . If the destination address is on the local LAN , Call directly etharp_query Interface , Inquire about arp surface , Send packet ; otherwise , Check whether the interface has a default gateway . If there is no default gateway , Returns an error , If there is a default gateway , Will IP The address is set to the address of the gateway , Also called etharp_query Interface send .
Function name :etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
function : send out arp Request and / Or queued packets . If you want to send a packet ip The address is not arp In the table , Then add a pending Status and send a arp Request to a given ip Address , Finally, the packets are queued on the portal ; If there is already one pending State of arp Table item , A new arp Request to send , Packet queuing ; If it's time to ip The address is already arp One of the tables stable term , And the packet is not empty , Send the packet directly , Do not send at this time arp request ; The foregoing , If the packet is empty , At this point, send a arp request .
operation : call find_entry Find an entry index , If the status of this entry is empty, Is set to pending. about pending Status entry or empty packet condition , call etharp_request send out arp request . If the packet is not empty , And the current entry is stable state , Then fill the package mac Address , And then send . If the status of the entry is pending, Queue the packet .
Function name :etharp_request(struct netif *netif, struct ip_addr *ipaddr)
function : According to the given interface and ip Address , Send a request
operation : First of all to arp Request to assign a pbuf, Set the pbuf, send out arp Request package , Final release pbuf.
Online about lwip Of arp The analysis diagram of the module is as follows
About arp Part of the question is whether it is necessary to receive each IP All packages need to be updated arp surface ( namely etharp_ip_input Whether the function needs ), It seems a bit wasteful

边栏推荐
- 国内外最好的12款项目管理系统优劣势分析
- Employment prospect of GIS and remote sensing specialty and ranking selection of universities in 2022
- Big guys talk about the experience sharing of the operation of the cutting-edge mindspore open source community. Come up with a small notebook!
- 直播回顾 | 子芽&CCF TF:云原生场景下软件供应链风险治理技术浅谈
- 论文学习——降雨场次划分方法对降雨控制率的影响分析
- Lwip之ARP模块实现
- 05 | standard design (Part 2): how to standardize the different styles of commit information, which are difficult to read?
- 全网最全的混合精度训练原理
- xml学习笔记
- Batch generate folders based on file names
猜你喜欢

PHP code audit series (I) basis: methods, ideas and processes

如何通俗易懂的描述机器学习的流程?

气液滑环与其他滑环的工作原理有什么区别

【Mysql】时间字段默认设置为当前时间

万字详解-MindArmour 小白教程!

全网最全的混合精度训练原理
![[vscode] setting sync, a plug-in for synchronizing extensions and settings](/img/e0/4889b59105e9815d11ae31988f58f2.jpg)
[vscode] setting sync, a plug-in for synchronizing extensions and settings
![Cve-2022-30190 follina office rce analysis [attached with customized word template POC]](/img/69/8f0381e99655009159c5119c7b896f.png)
Cve-2022-30190 follina office rce analysis [attached with customized word template POC]

kubernetes可视化界面dashboard

Redis detailed tutorial
随机推荐
技术干货|什么是大模型?超大模型?Foundation Model?
统计无向图中无法互相到达点对数[经典建邻接表+DFS统计 -> 并查集优化][并查集手册/写的详细]
Kubernetes visual interface dashboard
国内外最好的12款项目管理系统优劣势分析
1+1<2 ?! Interpretation of hesic papers
光谱共焦如何测量玻璃基板厚度
Understanding of "the eigenvectors corresponding to different eigenvalues cannot be orthogonalized"
My advanced learning notes of C language ----- keywords
手机能开户炒股吗 网上开户炒股安全吗
Com. Faster XML. Jackson. DataBind. Exc.mismatchedinputexception: tableau ou chaîne attendu. At [Source: X
2022年地理信息系统与遥感专业就业前景与升学高校排名选择
小白看MySQL--windows环境安装MySQL
滑环安装有哪些技巧和方法
XML learning notes
Employment prospect of GIS and remote sensing specialty and ranking selection of universities in 2022
滑环选型选购时需要注意的技巧
The most complete hybrid precision training principle in the whole network
手机炒股靠谱吗 网上开户炒股安全吗
大健康行业年度必参盛会,2022山东国际大健康产业博览会
“message“:“Bad capabilities. Specify either app or appTopLevelWindow to create a session“