Bridging Details
Initialization
Creating a Bridge
Bridge devices are created and removed using br_add_bridge() and br_del_bridge()
Ports are added to a bridge device with br_add_if() and removed with br_del_if()
The above routines execute with NETLINK routing lock held.The routines rtnl_lock() and rtnl_unlock() help in acquiring and releasing the locks.
br_add_bridge() and br_del_bridge() take care of locking on their own.
br_add_if() and br_del_if() uses dev_ioctl() to take care of locking/unlocking.
Bridge Device Creation
Bridge Device Setup
The Bridges use the br_dev_setup(struct net_device* netdev) routine to set up the bridge.The br_dev_setup()
The kernel distinguishes the bridge from other devices if the IFF_EBRIDGEflag is set in struct net_device.
The function br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) processes some of the ioctl commands
The bridging device driver initializes the br_dev_xmit(struct sk_buff *skb,struct net_device *dev) which
Deleting a Bridge
Forwarding Database
Each Bridge instance has its own forwarding database used regardless whether
The Forwarding database is placed in the net_bridge data structure and defined as hash table.
An instance of the net_bridge_fdb_entry data structure is added to the database for each MAC address learnt on the bridge ports.
Lookups
2. struct net_bridge_fdb_entry *br_fdb_get(struct net_bridge *br,const unsigned char *addr)
3. Adding/Updating/Removing Entries
The net_bridge_fdb_entry data structure is populated with the device MAC
address using the br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source, const unsigned char *addr) which is called by the br_add_if(struct net_bridge *br, struct net_device *dev) routine which is called by add_del_if() routine called by br_dev_ioctl() routine which processes the ioctl commands by the user.
Removing
Handling Ingress Traffic
Reciept of frame is handled by netif_receive_skb() which calls
If the kernel has support for bridging,handle_bridge() processes the
The br_handle_frame_hook is initialized with br_handle_frame in the routine during the
Transmitting on a Bridge Device
Overall Process
When a NIC is configured as a bridge port, the br_port member of the
Receipt of frame is handled by netif_receive_skb() which calls
To transmit the frame, dev_queue_xmit() function is called which invokes the
The bridging forwarding database is searched for destination MAC address.
In case of a success, the frame is sent to the bridge port by making a call
If the MAC lookup is a failure, the frame is flooded using br_flood()
Following are the Data Structures
net_bridge_fdb_entry - Entry of the Forwarding Database.There is one for each MAC address learned by the bridge.
net_bridge - Information about the bridge.
Routing/Forwarding Subsystem
Routing table is implemented using the struct fib_table data structure.
Reading entries in the routing table is done by calling the fib_lookup() function.
Routing tables are consulted using the ip_route_input_slow() and ip_route_output_slow() functions.
Two versions of fib_lookup() exist,one used when the kernel has support for policy routing and the other when the support is not included.
All routing table lookups regardless the direction of the traffic, is done using the fn_hash_lookup() function.This function's lookup
Routing Lookup
The ip_route_input() is called and makes a cache lookup. If the cache lookup
If the cache lookup results in a MISS then call to fib_lookup() is made and
If the route does not exist in the LOCAL FIB, the MAIN FIB is looked up and
Packet Forwarding
Forwarding is split into two functions
