linux - ip_hdr 和 ipip_hdr 有什么区别?

标签 linux networking kernel

在include/linux/ip.h中,

23 static inline struct iphdr *ip_hdr(const struct sk_buff *skb)
24 {
25         return (struct iphdr *)skb_network_header(skb);
26 }
27 
28 static inline struct iphdr *inner_ip_hdr(const struct sk_buff *skb)
29 {
30         return (struct iphdr *)skb_inner_network_header(skb);
31 }
32 
33 static inline struct iphdr *ipip_hdr(const struct sk_buff *skb)
34 {
35         return (struct iphdr *)skb_transport_header(skb);
36 }
37 #endif  /* _LINUX_IP_H */

如果我将 sk_buff 传递给 ip_hdr 和 ipip_hdr

struct iphdr *ip_hdr ip_hdr_net = ip_hdr(skb);
struct iphdr *ip_hdr ip_hdr_trans = ipip_hdr(skb);

ip_hdr_net->saddr 和 ip_hdr_trans->saddr 指向同一个东西?我在代码上试过了。它没有。好像只有ip_hdr_net->saddr指向源IP地址。

所以问题:

(1) ip_hdr 和 ipip_hdr 有什么区别?为什么我们有它们?没有任何文件可以解决这个问题。

(2) 访问ip_hdr成员数据时,是否应该使用ntohX函数转换?例如,ip_hdr_net->saddr。

最佳答案

ipip 是 ip over ip 隧道协议(protocol)。

关于协议(protocol)的详细信息在这里:

http://lartc.org/howto/lartc.tunnel.ip-ip.html

您可以在此处浏览有关其 Linux 实现的源代码:

ip over ip tunnel code xref in kernel

关于linux - ip_hdr 和 ipip_hdr 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39013454/

相关文章:

linux - 为什么 File::FcntlLock 的 l_type 总是 "F_UNLCK"即使文件被锁定?

linux - 使用 Sed 按列替换字符串

node.js - 除非手动执行,否则 Elastic Beanstalk 上的 "npm install"失败

c++ - cURL 是一个网络库吗?

c - 用户堆栈上的机器代码 - 操作系统

linux - bash 读取 : group read results by timeout

C++,接受后无法接收数据和无效套接字

linux - 在查询我的计算机上本地运行的 DNS 服务器时,如何让 dig 使用 localhost 以外的源 IP?

linux - 我可以将内核线程从一个命名空间移动到另一个命名空间吗?

macos - 在 Mac OS X 上本地存储内核核心转储