From 0fcc652d6fdaebdb0ceb3899af4ab8903542f49c Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Wed, 23 Feb 2005 03:18:34 -0800 Subject: [NET]: Add skb_header_cloned and use it in e1000/tg3 This patch adds skb_header_cloned which tells us whether we need to copy the data before we can modify the header part of the skb. Again, what constitutes the header is left up to the users of the skb to define. This patch then uses this function in e1000/tg3 to copy the data before the TCP/IP header is modified. Signed-off-by: Herbert Xu Signed-off-by: David S. Miller --- include/linux/skbuff.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include/linux/skbuff.h') diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index a8b55c4f4d2f..ca05008ba5b5 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -390,6 +390,25 @@ static inline int skb_cloned(const struct sk_buff *skb) (atomic_read(&skb_shinfo(skb)->dataref) & SKB_DATAREF_MASK) != 1; } +/** + * skb_header_cloned - is the header a clone + * @skb: buffer to check + * + * Returns true if modifying the header part of the buffer requires + * the data to be copied. + */ +static inline int skb_header_cloned(const struct sk_buff *skb) +{ + int dataref; + + if (!skb->cloned) + return 0; + + dataref = atomic_read(&skb_shinfo(skb)->dataref); + dataref = (dataref & SKB_DATAREF_MASK) - (dataref >> SKB_DATAREF_SHIFT); + return dataref != 1; +} + /** * skb_header_release - release reference to header * @skb: buffer to operate on -- cgit v1.2.3