Linux kernel Analysis

Source: Internet
Author: User
Tags hash linux

After reading the routing table, back to the NETIF_RECEIVE_SKB () function, before submitting to the upper layer protocol processing, will execute the following sentence, this is the network bridge operation, is also the content to explain.

SKB = Handle_bridge (SKB, &pt_prev, &ret, Orig_dev);

Network Bridge can be simply understood as a switch, the following diagram, for example, a Linux machine can be seen as a combination of bridge and routing, the Network bridge will be physical two LAN LAN1, LAN2 as a LAN processing, routing connected to two subnets 1.0 and 2.0. Messages received from eth0 and eth1 cards are processed in bridge modules and are received by bridge, so Bridge is also equivalent to a virtual NIC.

STP Five kinds of state

DISABLED

BLOCKING

Listening

LEARNING

Forwarding

Create a new network Bridge Br_add_bridge [NET\BRIDGE\BR_IF.C]

When you call IOCTL with SIOCBRADDBR, a new bridge Br_add_bridge is created.

The first is to create a new network bridge:

dev = new_bridge_dev (NET, name);

The Dev->dev.type is then set to Br_type, and Br_type is a global variable, and only one name variable is initialized

Set_netdev_devtype (Dev, &br_type);     
static struct Device_type Br_type = {     
 . Name = "Bridge",     
};

Then register the newly created device Dev, Network Bridge is quite a virtual network card equipment, registered equipment with Ifconfig can be found:

ret = Register_netdevice (dev);

Finally, the items are also created in the Sysfs file system for easy viewing and management:

ret = BR_SYSFS_ADDBR (dev);

Join the port to the bridge br_add_if () [NET\BRIDGE\BR_IF.C]

When IOCTL is invoked using SIOCBRADDIF, a new port br_add_if is added to the NIC.

Creates a new Net_bridge_port p that assigns an unused port_no,p->br from the br->port_list to the br,p->state set to br_state_disabled. Here the P actually represents the network card device.

p = new_nbp (BR, dev);

Add the newly created p to the Cam table, the cam table is used to record the corresponding relationship between the MAC address and the physical port, and has just created the p, so also to join the Cam table, and the table entries should be local [relationship as follows], you can see that the cam table in the implementation as a Net_bridge The hash table, which is addr as a hash value, is chained to the net_bridge_fdb_entry, and then its DST points to net_bridge_port.

Err = Br_fdb_insert (BR, p, dev->dev_addr);

The br_port of the device points to p. It is understood here that Net_bridge can be considered as a global volume, a bridge, and Net_bridge_port is the port corresponding to the NIC, so each device dev has a pointer br_port to that port.

Rcu_assign_pointer (Dev->br_port, p);

Adding the newly created Net_bridge_port to the BR port_list, when a new net_bridge_port is created, an unused port_no is allocated, and this port_no is based on Br->port_ List of the net_bridge_port that have been added to find unused port_no [details as shown below].

List_add_rcu (&p->list, &br->port_list);

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.