From b739f532bd2d0d84ba63d8984c7dc308b2bc13e9 Mon Sep 17 00:00:00 2001 From: Vladimir Sokolovsky Date: Wed, 22 Feb 2012 13:45:09 +0200 Subject: [PATCH] Add skb_frag_size_{set|add|sub}() for Linux 3.1 and older Signed-off-by: Vladimir Sokolovsky --- include/linux/compat-3.2.h | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/include/linux/compat-3.2.h b/include/linux/compat-3.2.h index fd8d1f9..921e288 100644 --- a/include/linux/compat-3.2.h +++ b/include/linux/compat-3.2.h @@ -25,6 +25,48 @@ static inline struct page *skb_frag_page(const skb_frag_t *frag) return frag->page; } +/** + * __skb_frag_set_page - sets the page contained in a paged fragment + * @frag: the paged fragment + * @page: the page to set + * + * Sets the fragment @frag to contain @page. + */ +static inline void __skb_frag_set_page(skb_frag_t *frag, struct page *page) +{ + frag->page = page; +} + +/** + * skb_frag_set_page - sets the page contained in a paged fragment of an skb + * @skb: the buffer + * @f: the fragment offset + * @page: the page to set + * + * Sets the @f'th fragment of @skb to contain @page. + */ +static inline void skb_frag_set_page(struct sk_buff *skb, int f, + struct page *page) +{ + __skb_frag_set_page(&skb_shinfo(skb)->frags[f], page); +} + +/** + * skb_frag_address_safe - gets the address of the data contained in a paged fragment + * @frag: the paged fragment buffer + * + * Returns the address of the data within @frag. Checks that the page + * is mapped and returns %NULL otherwise. + */ +static inline void *skb_frag_address_safe(const skb_frag_t *frag) +{ + void *ptr = page_address(skb_frag_page(frag)); + if (unlikely(!ptr)) + return NULL; + + return ptr + frag->page_offset; +} + /** * skb_frag_dma_map - maps a paged fragment via the DMA API * @device: the device to map the fragment to @@ -52,6 +94,21 @@ static inline unsigned int skb_frag_size(const skb_frag_t *frag) return frag->size; } +static inline void skb_frag_size_set(skb_frag_t *frag, unsigned int size) +{ + frag->size = size; +} + +static inline void skb_frag_size_add(skb_frag_t *frag, int delta) +{ + frag->size += delta; +} + +static inline void skb_frag_size_sub(skb_frag_t *frag, int delta) +{ + frag->size -= delta; +} + static inline char *hex_byte_pack(char *buf, u8 byte) { *buf++ = hex_asc_hi(byte); -- 2.41.0