2.2.3.2 输出路由查找
ip_route_output_key
功能:
调用ip_route_output_flow
ip_route_output_flow
功能:
1)路由发包查找
2)ipsec处理流程
功能:
查找路由缓存
未找到缓存,慢速发送
ip_route_output_key
功能:
调用ip_route_output_flow
ip_route_output_flow
功能:
1)路由发包查找
2)ipsec处理流程
int ip_route_output_flow(struct net *net, struct rtable **rp, struct flowi *flp,struct sock *sk, int flags)
//参数说明:net为网络设备;
// rp当查询成功,返回查询到的路由缓存项;
// flp用于查询缓存项的条件;
// sk,flags用于ipsec路由查找
{
int err;
//路由查找
if ((err = __ip_route_output_key(net, rp, flp)) != 0)
return err;
//ipsec路由查找
if (flp->proto) {
if (!flp->fl4_src)
flp->fl4_src = (*rp)->rt_src;
if (!flp->fl4_dst)
flp->fl4_dst = (*rp)->rt_dst;
err = __xfrm_lookup(net, (struct dst_entry **)rp, flp, sk,
flags ? XFRM_LOOKUP_WAIT : 0);//ipsec处理
if (err == -EREMOTE)
err = ipv4_dst_blackhole(net, rp, flp);
return err;
}
return 0;
}
__ip_route_output_key功能:
查找路由缓存
未找到缓存,慢速发送
int __ip_route_output_key(struct net *net, struct rtable **rp,const struct flowi *flp)
{
unsigned hash;
struct rtable *rth;
if (!rt_caching(net)) //查路由缓存
goto slow_output;
hash = rt_hash(flp->fl4_dst, flp->fl4_src, flp->oif, rt_genid(net));//计算hash
rcu_read_lock_bh();
for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
rth = rcu_dereference(rth->u.dst.rt_next))