【问题标题】:Distinguish forwarding traffic and locally originated traffic in Linux network driver在 Linux 网络驱动程序中区分转发流量和本地流量
【发布时间】:2012-08-24 06:20:07
【问题描述】:

struct skbuff 中是否有任何信息可以区分转发流量(网桥转发和 ip 转发)和本地产生的流量?我们希望在网络驱动程序中区别对待这两种流量,因为转发流量不需要对整个数据包大小进行缓存失效。

感谢任何建议。非常感谢!

【问题讨论】:

    标签: linux networking linux-kernel linux-device-driver


    【解决方案1】:

    是的,有可能,您可以通过查看来自此函数ip_rcv_finish (http://lxr.free-electrons.com/source/net/ipv4/ip_input.c?v=3.3#L317) 的所有调用来尝试跟踪接收数据包的生命周期。

    结构体struct sk_buff 包含一个指向目标条目的指针:

    struct  dst_entry   *dst;
    

    其中包含一个函数指针:

    int (*input)(struct sk_buff*);
    

    调用输入数据包,对于本地数据包,内核调用ip_local_deliver函数,对于转发数据包,它调用ip_forward函数。

    我认为你可以,像这样检查本地和转发的数据包:

    - 本地:

    /*  struct sk_buff *skb : Entry packet */
    if (((struct rtable *)skb->dst)->rt_type == RTN_LOCAL)
    {
        /* This packet is to consume locally */
    }
    

    - 前进:

    if (((struct rtable *)skb->dst)->rt_type == RTN_UNICAST)
    {
        /* This packet will be forwarded */
    }
    

    【讨论】:

    • 非常感谢@TOC 的回答!根据您的提示,我们可以在ip_forward(用于IP转发)和br_handle_frame_finish(用于网桥转发)内标记转发数据包
    • @toc 的answer 很棒。如需进一步了解数据包从用户空间到内核并返回的路径,请参阅 Ashwin Chimata 的优秀论文 here
    猜你喜欢
    • 1970-01-01
    • 2015-03-14
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多