An article brings you Lwip network port interface netif

An article brings you Lwip network port interface netif

[[395199]]

01Introduction to Network Interface

In the TCP/IP reference model, the network is divided into four layers: application layer, transport layer, network layer and network interface layer. The network interface layer corresponds to our actual network card. LWIP supports multi-port design. LWIP uses netif to describe the characteristics of each network interface, such as the IP address of the interface, interface status, etc. So if there are multiple network cards, how does LWIP organize these network cards? In LWIP, the linked list netif_list is used to manage many network cards. When the upper layer has data to send, LWIP will select a suitable network card from the netif_list linked list to send the data.

02netif structure

The netif structure is defined in the file netif.h. The meaning of each member variable in the netif structure is as follows:

next : This field points to the next neitif type structure. Because LWIP can support multiple network interfaces, when the device has multiple network interfaces, LWIP will organize all netif structures into a linked list to manage these network interfaces.

ipaddr, netmask and gw : the IP address, subnet mask and default gateway of the network interface respectively.

input : This field is a function that passes the data received by the network card to the IP layer.

output : This field is a function that is called when the IP layer sends a data packet to the interface. This function usually resolves the hardware address first and then sends the data packet. For this field, we generally use the etharp_output() function in etharp.c.

linkoutput : This field is a function that is called by the ARP module to complete the transmission of network data. After the etharp_output function mentioned above encapsulates the IP data packet into an Ethernet data frame, it will call the linkoutput function to send the data out.

state : used to define some information about the interface, which can be set by the user.

mtu : The maximum data length that the network interface can transmit, usually set to 1500.

hwaddr_len : Network card MAC address length, 6 bytes.

hwaddr : MAC address.

flags : Network interface status, attribute information field.

name : The name of the network card.

num : This field is a number set by the protocol stack for each network interface, starting from 0.

The value of flags:

in

In network initialization, in ethernetif.c

They all correspond to a function

etharp_output : IP layer sends data packet function

low_level_output : ARP module sending function, a lower-level function, in fact, etharp_output still calls this function

03 Related functions

3.1、netif_add

  1. netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t
  2. *gw, void *state, netif_init_fn init, netif_input_fn input)

That is, add the netif network interface to the network list queue and add a network card to the network card list

3.2, netif_set_default

  1. netif_set_default(struct netif *netif)

Set this network card as the default network card

3.3, netif_set_up

  1. netif_set_up(struct netif *netif)

Open the network card

<<:  China Unicom's net profit in the first quarter was 3.843 billion yuan, a year-on-year increase of 21.4%

>>:  Z-Wave not concerned about potential threats from Project CHIP

Recommend

16 real-life digital transformation success stories

【51CTO.com Quick Translation】CIOs of leading comp...

5G refreshes your digital reading experience

Digital reading has unlimited potential [[400428]...

5G Massive MIMO Says Goodbye to Power-hungry 5G Base Stations

The attacks on the large-scale construction of 5G...

The development trend of enterprise-level wireless coverage (WiFi6)

[[402903]] 1. Trends in enterprise-level wireless...

Six advantages of deploying SD-WAN

With the increase in data analysis, media traffic...

5G is not about mobile phones, but about the Internet of Things.

[[321085]] Recently, new infrastructure has conti...