在Linux网络驱动程序中区分转发流量和本地源流量
在Linux网络驱动程序中区分转发流量和本地源流量,linux,networking,linux-kernel,linux-device-driver,Linux,Networking,Linux Kernel,Linux Device Driver,struct skbuff中是否有任何信息来区分转发流量(网桥转发和ip转发)和本地发起的流量?我们希望在网络驱动程序中区别对待这两种流量,因为转发流量不需要对整个数据包大小进行缓存失效 如有任何建议,我们将不胜感激。多谢各位 是的,您可以通过查看来自此函数的所有调用来尝试跟踪接收数据包的生命周期ip\u rcv\u finish() structstruct sk_buff包含指向目标条目的指针: struct dst_entry *dst; 其中包含函数指针: int (*input
struct skbuff
中是否有任何信息来区分转发流量(网桥转发和ip转发)和本地发起的流量?我们希望在网络驱动程序中区别对待这两种流量,因为转发流量不需要对整个数据包大小进行缓存失效
如有任何建议,我们将不胜感激。多谢各位 是的,您可以通过查看来自此函数的所有调用来尝试跟踪接收数据包的生命周期
ip\u rcv\u finish
()
structstruct sk_buff
包含指向目标条目的指针:
struct dst_entry *dst;
其中包含函数指针:
int (*input)(struct sk_buff*);
为了调用输入数据包,在本地数据包的情况下,内核调用ip\u local\u deliver
函数,对于转发数据包,它调用ip\u 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 */
}
-转发:
/* 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\u-forward
(用于ip-forward)和br\u handle\u frame\u finish
(用于网桥转发)中标记转发包@toc太棒了。要进一步了解数据包从用户空间到内核的路径,请参阅Ashwin Chimata的优秀论文