After reading the FIB search, I found out some data structures. Let's take a look at how the route table is created from the two notification chains registered by ip_fib_init, when the IP address is changed, the notification chain processing function is triggered, and the fib_add_ifaddr () is called to add the address to the route. In this case, the fib_magic is called to perform the routing address operation. Static void maid (INT cmd, int type, _ be32 DST, int dst_len, struct in_ifaddr * IFA)
{
Struct net * Net = dev_net (IFA-> ifa_dev-> Dev );
Struct fib_table * TB;
Struct fib_config CFG = {route Configuration Structure
. Fc_protocol = rtprot_kernel,
. Fc_type = type,
. Fc_dst = DST,
. Fc_dst_len = dst_len,
. Fc_prefsrc = IFA-> ifa_local,
. Fc_oif = IFA-> ifa_dev-> Dev-> ifindex,
. Fc_nlflags = nlm_f_create | nlm_f_append,
. Fc_nlinfo = {
. Nl_net = net,
},
};
If (type = rtn_unicast)
TB = maid (net, rt_table_main );
Else
TB = maid (net, rt_table_local );
If (TB = NULL)
Return;
Cfg. fc_table = Tb-> tb_id;
If (type! = Rtn_local)
Cfg. fc_scope = rt_scope_link;
Else
Cfg. fc_scope = rt_scope_host;
If (cmd = rtm_newroute)
TB-> tb_insert (TB, & CFG); fn_hash_insert;
Else
TB-> tb_delete (TB, & CFG); otherwise, delete
}
Fib_new_table ()
When config_ip_multiple_tables is enabled Struct maid * maid (struct net * Net, u32 ID)
{
Struct fib_table * TB;
Unsigned int h;
If (ID = 0)
Id = rt_table_main;
TB = maid (net, ID); Use Id to find the route table function
If (TB)
Return TB;
TB = maid (ID); apply to create a route table
If (! TB)
Return NULL;
H = ID & (maid-1 );
Hlist_add_head_rcu (& TB-> tb_hlist, & net-> ipv4.fib _ table_hash [H]);
Return TB;
}
Struct maid * maid (struct net * Net, u32 ID)
{
Struct fib_table * TB;
Struct hlist_node * node;
Struct hlist_head * head;
Unsigned int h;
If (ID = 0)
Id = rt_table_main;
H = ID & (maid-1 );
Rcu_read_lock ();
Head = & net-> ipv4.fib _ table_hash [H ];
Hlist_for_each_entry_rcu (TB, node, Head, tb_hlist) {match
If (Tb-> tb_id = ID ){
Rcu_read_unlock ();
Return TB;
}
}
Rcu_read_unlock ();
Return NULL;
}
Of course, there are still many items in fib, and the data structure is complex. Given the time and energy, we cannot further analyze the data. Here we just find out the general process and pull the entire protocol stack, when we have the concept of a system and a full process, we will analyze the specific modules carefully. Here is a good article on the Linux kernel Routing Mechanism http://blog.csdn.net/bin323/article/details/642192 is a summary of the above process analysis