skb_header_pointer和skb_transport_header之间的区别? [英] Difference between skb_header_pointer and skb_transport_header?

查看:1007
本文介绍了skb_header_pointer和skb_transport_header之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一个netfilter模块,在处理sk_buff时,我发现了两种可能的方法来检索TCP标头:

I'm trying to implement a netfilter module, while processing sk_buff I found two possible ways to retrieve TCP header:

struct iphdr *ip_header = (struct iphdr *)skb_network_header(skb);
struct tcphdr *tcp_header = (struct tcphdr *)skb_transport_header(skb);

还有

struct iphdr *ip_header = skb_header_pointer(skb, 0, sizeof(struct iphdr), &_iph)
struct tcphdr *tcp_header = skb_header_pointer(skb, ip_header->ihl * 4, sizeof(struct tcphdr), &_tcph);

我应该使用哪个?

推荐答案

您应使用 paged- skb

You should use ip_hdr() from /include/linux/ip.h and tcp_hdr() from /include/linux/tcp.h in case you know that there cannot be paged-skb here:

struct iphdr *ip_header = ip_hdr(skb);
if (ip_header->protocol == IPPROTO_TCP) {
    struct tcphdr *tcp_header = tcp_hdr(skb);
    //...


如果可能出现页面-skb,则应使用

skb_header_pointer().示例: IP TCP ICMP 等.
因此,如果标头位于页面数据中(全部或部分),则skb_header_pointer()将正确处理它.
另外请记住检查skb_header_pointer()的返回值,它可以返回NULL.


skb_header_pointer() should be used in case the appearance of paged-skb is possible. Examples: IP, TCP, ICMP, etc.
So if the header is in paged data (fully or partially) - skb_header_pointer() will correctly handle it.
Also remember to check the return value of skb_header_pointer(), it can return NULL.

有用的链接: 1 2

这篇关于skb_header_pointer和skb_transport_header之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆