Data transmission on the link layer of the Linux protocol stack (bridge processing of data (5))

  

So far, the configuration of the bridge has been described. Let's take a look at how the bridge handles the data packet processing. The bridge returns to the handle_bridge function at the beginning of this chapter. It calls br_handle_frame_hook to process the received data. In the bridge initialization code, br_handle_frame_hook is assigned. In order for br_handle_frame to be correct, this is the handler for the bridge. Follow a function nt br_handle_frame(struct net_bridge_port *p, struct sk_buff **pskb){struct sk_buff *skb = *pskb;//destination mac address const unsigned char *dest = eth_hdr(skb)->h_dest;//port Disable if (p->state == BR_STATE_DISABLED)goto err;//source mac is multicast or broadcast, discard //f.XX.XX.XX.XX.XX form if (eth_hdr(skb)->h_source [0] & 1) goto err; //If the state is learning or forwarding, then learn source mac update CAM table if (p->state == BR_STATE_LEARNING | | P->state == BR_STATE_FORWARDING)//br_fdb_insert function We have previously analyzed br_fdb_insert(p->br, p, eth_hdr(skb)->h_source, 0); //stp processing, stp- Enabled Whether to enable the multicast mac address used by the stp protocol //bridge_ula stp if (p->br->stp_enabled &&!memcmp(dest, bridge_ula, 5) &!(dest[5] & ; 0xF0)) {if (!dest[5]) {NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,

NULL, br_stp_handle_bpdu);return 1;}}else if (p-> ;state == BR_STATE_FORWARDING) {//In the initialization, and finally assign br_should_route_hook //so br_should_route_hook is false if (br_should_route_hook) {if (br_should_route_hook(pskb))

return 0;skb = *pskb ;dest = eth_hdr(skb)->h_dest;}//The destination address is the same as the bridge address. Then pass and the upper layer processing //set skb-> pkt_type = PACKET_HOSTif (! memcmp (p-> br-> dev-> dev_addr, dest, ETH_ALEN)) skb-> pkt_type = PACKET_HOST; //bridge Netfiter at NF_BR_PRE_ROUTING points NF_HOOK (PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb-> dev, NULL, br_handle_frame_finish); return 1;}err:kfree_skb(skb);return 1;} In this function, make the relevant entry After the judgment, the source MAC of the current data packet and the interface corresponding to the update to the CAM table, the update function br_fdb_insert () has been analyzed in the past, do not understand can look down, but note, this is not done Inserted for static items. Then judge whether the packet is passed to the local machine. If it is, then the pkt_type of the packet is PACKET_HOST about the NF_HOOK() macro. We have a special analysis in the future netfiter. This is as long as we know that normal packets will flow into br_handle_frame_finish() for processing /* note: already called with rcu_read_lock (preempt_disabled) */int br_handle_frame_finish(struct sk_buff *skb){//Get the destination MAC address const unsigned char * Dest = eth_hdr(skb)->h_dest;struct net_bridge_port *p = skb->dev->br_port;struct net_bridge *br = p->br;struct net_bridge_fdb_entry *dst;int passedup = 0;//mixed Mode/* If the virtual network card of the bridge is in promiscuous mode, each received packet needs to be cloned and sent to the AF_PACKET protocol handler (the processing of the ptype_all chain in the network soft interrupt function net_rx_action). */if (br->dev->flags & IFF_PROMISC) {struct sk_buff *skb2;skb2 = skb_clone(skb, GFP_ATOMIC);if (skb2 != NULL) {passedup = 1;br_pass_frame_up(br, skb2) ;}}//The destination mac is multicast or broadcast, then it needs to be passed to the upper layer for processing //passedup as the transfer flag. When it is 1, it means that if (dest[0] & 1) {br_flood_forward(br, Skb, !passedup);if (!passedup)br_pass_frame_up(br, skb);goto out;}//Query CAM table dst = __br_fdb_get(br, dest);//to the local? Pass to the upper layer protocol if (dst != NULL && dst->is_local) {if (!passedup)br_pass_frame_up(br, skb); elsekfree_skb(skb);goto out;}

//is not native data, then forward if (dst != NULL) {br_forward(dst->dst, skb); goto out;} //If not queried, send this package br_flood_forward on other ports (br , skb, 0); out:

Copyright © Windows knowledge All Rights Reserved