【问题标题】:How does the mac related functions work in linux kernel, in skbuff.h?mac 相关函数如何在 linux 内核中工作,在 skbuff.h 中?
【发布时间】:2014-04-02 05:21:29
【问题描述】:

我阅读了源代码,但它确实让我感到困惑。例如函数 sib_mac_header 函数,它是下面代码中的第三个函数,sib -> head 是指向已分配缓冲区头部的指针,而 sib -> mac_header 是指向该缓冲区中 mac_header 地址的指针。为什么两个地址相加的结果是指向MAC ether结构的指针??

skbuff.h中的源代码如下:

1609 static inline void skb_reset_network_header(struct sk_buff *skb)
1610 {
1611         skb->network_header = skb->data - skb->head;
1612 }
1613 
1614 static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
1615 {
1616         skb_reset_network_header(skb);
1617         skb->network_header += offset;
1618 }
1619 
1620 static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
1621 {
1622         return skb->head + skb->mac_header;
1623 }

【问题讨论】:

    标签: c linux-kernel network-protocols


    【解决方案1】:

    您误读了代码。 skb->mac_header 不是直接指针……它存储的是 skb->head 的 mac 头的偏移量。事实上,在 64 位架构上,sk_buff_data_t 是无符号整数,struct sk_buff 的许多成员都是明确的偏移量(此技巧用于通过将信息存储在 4 字节字段而不是 8 字节指针中来节省内存)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-06
      • 2020-05-16
      • 2015-08-21
      • 2021-10-31
      • 1970-01-01
      • 2022-08-24
      • 2011-09-25
      相关资源
      最近更新 更多