LWIP dual Nic porting and special solutions.

Source: Internet
Author: User

 

My company's product is a dual-network port. The original program is a self-written TCP/IP protocol stack, because it simply implements the simplest situation of ARP, TCP, and UDP, so sometimes problems may occur on the Internet.

Later, LWIP and lightweight TCP/IP protocol stack were transplanted to a single network port product, and the problem was solved to some extent. Therefore, dual network card products also need the LWIP protocol stack. This job falls into my head.

I will not repeat the porting of a single Nic. I will only describe the problems and solutions encountered during the porting from a single Nic to a dual Nic.

First, I checked the changes made during the migration of the NIC.

  • When the hardware is started, initialize the hardware and call my_lwip_init (). In this function, create a task and add the NIC configuration.
  • The low_level_init () function sets the MAC address when the NIC is initialized.
  • The low_level_output () function processes output information.
  • The low_level_input () function processes input information.
  • The ethernetif_input () function is used to differentiate how received packets are processed.

As a result, we can know that the main changes I need to make are to address these functions and their related functions.

  1. Create more netif blocks, add one more netif_add in the mylwip_init () function during hardware initialization, and call netif_set_up ().
  2. In low_level_init (), separate the MAC addresses of two NICs and fill them in the netif block. [From this code, we can see that after the hardware MAC address is modified, the program must reset the netif linked list to correctly execute it.]
  3. In low_level_output (), determine the NIC to which the returned data is sent, copy the data to the NIC sending buffer, and then send the data.
  4. In low_level_input (), determine which Nic receives the data and copy the data in the NIC accept buffer to the payload data of the netif block.

After completing these steps, the Ping program is ready, but there are some strange phenomena, the same network port can communicate with the content of two IP addresses [ping two NICs at one network port], so it is in ethernetif_input () the function determines that the target address is added to the network adapter and then enters the TCP/IP process. At this time, the problem is also solved.

Then there was a strange problem. Ping net1 OK, Ping net 2 OK, TCP net1 error, and TCP net2 OK. In addition, net1 and net2. Therefore, it is suspected that there is a problem with the routing. Only by checking the LWIP document can we find that the ip_route () function is based on the data of the local network card when the target address is in the network segment of the local network card, otherwise, use the default route configuration. Because our module is a dual-nic set for hot data backup or multi-Communication Eloquence, the two NICs are configured with one network segment. In this case, ip_route () the function finds the first route in the default route table and returns the result directly. In desperation, I wrote ip_route2 () to determine which Nic is used to send data by comparing the source address.

So far, test OK, happy! record it quickly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.