0
votes

The struct sk_buff is really HARD to understand (at least for me, when you deal with it at the first time).

Before anyone say I should google the web before asking questions, please understand I DID that, but with no luck. There are some GOOD but OLD AND OBSOLETE documentation and papers out there, and looking the sources at GIT and even browsing the sources http://lxr.free-electrons.com just makes everything more and more confuse.

I'm going to ask more than I need to make any final conclusions in this page more complete so anyone who get's here will (hopefully) have his/her questions answered.

Can you explain me those members of the struct sk_buff?

  • mac_header, network_header, transport_header

    They seem to be offsets. But counting from where? From head?

    To tell everyone my struct has no mac_header, for example, what should I do? Because the source of skb_mac_header_was_set() Returns this: skb->mac_header != (typeof(skb->mac_header))~0U

    But there is no skb_network_header_was_set() function; and there is one for transport_header... Crazyness!

  • len

Background:

What I am trying to do is this: i'm editing packets in a netfilter hook, and when I'm done, I'm rebuilding the entire headers (UDP/TCP, IP4/IP6, Ethernet)... As I may have included/removed new option in those headers, their size change, the skb->data moves... and that's why I need to deal with those members.

My module works in every netfilter hook (PREROUTING, POSTROUTING, FORWARD, INPUT)...

1
Is your code using the IP netfilter hooks or the bridge netfilter hooks ?srd
I'm using using IP netfilter...Willian Britto

1 Answers

0
votes

At the IP layer you do not need to worry about the MAC header. The neighbouring and bridging subsystems either have already done their work (rx path) or will add the MAC header later (tx path).

mac_header, network_header, transport_header: are offsets counting from skb->data. Try not to manipulate those directly and always use the API in skbuff.h

You did not give much details about what you are doing, but you might want to consider:

  1. ip_send_check(iph) : fixes the cheksum of the IP header
  2. skb_set_network_header(): re-sets the IP header offset to a new point
  3. skb_set_transport_header(): re-sets the TCP/UDP header offset to a new point
  4. udph->check = csum_tcpudp_magic(): fixes UDP header checksum