stack smasher
stack smasher

Reputation: 463

What do the sk_buff functions skb_network_header() and skb_mac_header() do?

Do they return the IP header and mac header respectively? I'm a little confused because just looking at the implementation, they are returning pointers that are skb->head + skb->network_header and the like. Why not just get the network header by doing skb->network_header?

Thanks!

Upvotes: 0

Views: 5894

Answers (2)

Digital Trauma
Digital Trauma

Reputation: 15996

I assume you're looking at the kernel source code somewhere like this

If we cut out some of the code, I think it becomes something like this:

#ifdef NET_SKBUFF_DATA_USES_OFFSET
static inline unsigned char *skb_network_header(const struct sk_buff *skb)
{
        return skb->head + skb->network_header;
}

static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
{
        return skb->head + skb->mac_header;
}

#else /* NET_SKBUFF_DATA_USES_OFFSET */

static inline unsigned char *skb_network_header(const struct sk_buff *skb)
{
        return skb->network_header;
}

static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
{
        return skb->mac_header;
}

#endif /* NET_SKBUFF_DATA_USES_OFFSET */

Upvotes: 0

nos
nos

Reputation: 229108

There are 2 versions of skb_network_header()

#ifdef NET_SKBUFF_DATA_USES_OFFSET

static inline unsigned char *skb_network_header(const struct sk_buff )
{
        return skb->head + skb->network_header;
}
#else
static inline unsigned char *skb_network_header(const struct sk_buff *skb)
{
     return skb->network_header;
}

Basically, if NET_SKBUFF_DATA_USES_OFFSET is in effect (e.g. for 64 bit architectures), .network_header is an offset from the start.

Upvotes: 1

Related Questions