简体   繁体   中英

sk_buff copy & sk_buff clone

im writing a module for linux kernel & it try to steal the packet & its related sk_buff . to do so i want to use struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask) & then pass the return type to the kernel as packet is dropped .

so when kernel gets the info about packet drop it try to free the sk_buff. here my question comes will it affect my newly copied skb & its pointed data of the packet? or now i can play with my new sk_buff?

or is it possible to use skb_clone() & use the packet data part without deleting the referenced data by old sk_buff because it will reduse copying cost of the packet.

Using skb_copy will copy both the sk_buff and the packet to new memory. Meaning when the kernel frees the other one, the copy will not be affected.

skb_clone in the other hand copies the sk_buff structure to new memory, but not the packet. Meaning when the old one is freed, your copy will have the packet also freed.

Here are some links:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM