Detecting/Ensuring SKB allocation and free

905 views Asked by At

Usually The sk_buff is allocated by the module(interface to the network driver) developed by me on transmit side through "alloc_skb" and given to the network driver. It's basically free'd by the network driver after send.

Is there a way to do the SKB free from my developed module or Is there a way to ensure whether the network driver is freeing skb buff properly?

1

There are 1 answers

1
AudioBubble On

If I recall correctly, you may use skb_get() to increment reference counter of your buffer on the "send side". This means that as soon as the network driver decides to free the buffer after putting it on wire, it will call a proper function which will decrement the reference counter but it will still remain non-zero (because of your previous + 1), so it won't be freed. Then you will be able to hold the buffer and free it (as you are the last user) whenever you want.

However, if you have a chain of sk_buff-s, I'm afraid you need to perform skb_get() on each segment.

As for your need to make sure that the network driver itself frees the buffer correctly, you may, for example, find the places in the network driver where a buffer is freed on transmit and insert debug printouts. Then recompile, try to interact with the driver in a normal way (i.e. without doing skb_get() prior handing the buffer on to the driver) and observe debug printouts appearing in dmesg.