【发布时间】:2012-08-24 06:20:07
【问题描述】:
struct skbuff 中是否有任何信息可以区分转发流量(网桥转发和 ip 转发)和本地产生的流量?我们希望在网络驱动程序中区别对待这两种流量,因为转发流量不需要对整个数据包大小进行缓存失效。
感谢任何建议。非常感谢!
【问题讨论】:
标签: linux networking linux-kernel linux-device-driver
struct skbuff 中是否有任何信息可以区分转发流量(网桥转发和 ip 转发)和本地产生的流量?我们希望在网络驱动程序中区别对待这两种流量,因为转发流量不需要对整个数据包大小进行缓存失效。
感谢任何建议。非常感谢!
【问题讨论】:
标签: linux networking linux-kernel linux-device-driver
是的,有可能,您可以通过查看来自此函数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 */
}