Determining the number of add-ons added to an Ethernet frame

I am working on a driver for the Linux kernel. For the success of my project, I need to determine the number of add-ons added to Ethernet frames that are less than the minimum size of 60 bytes (excluding FCS). I do not create this framework; I get them in the NIC for processing.

With struct sk_buff , is it possible to determine the number of trailing zeros added to a package directly?

Of course, I can determine this value by going through the whole package, finding out where the contents of the highest level end, and then simply subtracting this position from the frame size (in this case, 60 bytes). But is there a more efficient way to do this directly from the information stored on struct sk_buff ?

+4
source share
2 answers

EDIT: As far as I know, there is no way to check for zero padding directly with the sk_buff structure without looking at the ethernet header, which is quite simple.

However, using simple pointer arithmetic and subtracting bytes, you can use the length field in the IP data to determine padding.

This is a good link for sk_buff: http://vger.kernel.org/~davem/skb_data.html

And here is a good link for the package structure, showing the "length" field in the bottom image in the "data".

http://nerdcrunch.com/wp-content/uploads/2011/05/Ethernet-Frame-Explained.png

I think this is how it should be done, but it does not require parsing, as you previously supported. The fields of the header / data structure are configured in such a way that they can be referenced / deleted directly through the pointer / array without parsing, and then by subtracting the length of the header + data from the raw packet length, you can get filling without checking the data.

Hope this helps.

Also, for best practice, you probably should have included your driver account for both versions of 802.3. You can do this by checking the Ethertype / length field. If the value is greater than 1536 (0x0600) than you know, it is an Ethernet II type packet and the field contains an ethertype type that tells you that the ethernet packet is encapsulating. There are some popular ones if you are Wikipedia for "Ethertype".

For example, IP = 0x0800. If the field stands for Ethertype, you should resort to searching the data length field inside to find the indentation. If this does not happen, which is not on the Ethernet LAN, then you can directly use the field specified as the length to do your job.

+1
source

IPv4 does almost the same thing, there are probably no better ways. Check ip_rcv ():

 len = ntohs(iph->tot_len); if (skb->len < len) { IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INTRUNCATEDPKTS); goto drop; } else if (len < (iph->ihl*4)) goto inhdr_error; /* Our transport medium may have padded the buffer out. Now we know it * is IP we can trim to the true length of the frame. * Note this now means skb->len holds ntohs(iph->tot_len). */ if (pskb_trim_rcsum(skb, len)) { IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INDISCARDS); goto drop; } 
0
source

All Articles