linux内核 路由fib表之输出查找

这篇博客详细探讨了Linux内核中的路由FIB表,通过程序流程图揭示了路由查找的过程,深入理解路由决策在操作系统底层的工作原理。
摘要由CSDN通过智能技术生成
2.2.3.2 输出路由查找
    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))
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值