1 #include <linux/module.h>
2 #include <linux/netdevice.h>
3 #include <linux/skbuff.h>
5 #if !defined(HAVE_SKB_WARN_LRO) && defined(NETIF_F_LRO)
7 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9 void __skb_warn_lro_forwarding(const struct sk_buff *skb)
12 pr_warn("%s: received packets cannot be forwarded while LRO is enabled\n",
18 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
20 static inline bool head_frag(const struct sk_buff *skb)
22 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
23 return skb->head_frag;
30 * skb_zerocopy_headlen - Calculate headroom needed for skb_zerocopy()
31 * @from: source buffer
33 * Calculates the amount of linear headroom needed in the 'to' skb passed
34 * into skb_zerocopy().
37 skb_zerocopy_headlen(const struct sk_buff *from)
39 unsigned int hlen = 0;
41 if (!head_frag(from) ||
42 skb_headlen(from) < L1_CACHE_BYTES ||
43 skb_shinfo(from)->nr_frags >= MAX_SKB_FRAGS)
44 hlen = skb_headlen(from);
46 if (skb_has_frag_list(from))
53 * skb_zerocopy - Zero copy skb to skb
54 * @to: destination buffer
55 * @source: source buffer
56 * @len: number of bytes to copy from source buffer
57 * @hlen: size of linear headroom in destination buffer
59 * Copies up to `len` bytes from `from` to `to` by creating references
60 * to the frags in the source buffer.
62 * The `hlen` as calculated by skb_zerocopy_headlen() specifies the
63 * headroom in the `to` buffer.
66 skb_zerocopy(struct sk_buff *to, const struct sk_buff *from, int len, int hlen)
69 int plen = 0; /* length of skb->head fragment */
73 BUG_ON(!head_frag(from) && !hlen);
75 /* dont bother with small payloads */
76 if (len <= skb_tailroom(to)) {
77 skb_copy_bits(from, 0, skb_put(to, len), len);
82 skb_copy_bits(from, 0, skb_put(to, hlen), hlen);
85 plen = min_t(int, skb_headlen(from), len);
87 page = virt_to_head_page(from->head);
88 offset = from->data - (unsigned char *)page_address(page);
89 __skb_fill_page_desc(to, 0, page, offset, plen);
96 to->truesize += len + plen;
97 to->len += len + plen;
98 to->data_len += len + plen;
100 for (i = 0; i < skb_shinfo(from)->nr_frags; i++) {
103 skb_shinfo(to)->frags[j] = skb_shinfo(from)->frags[i];
104 skb_shinfo(to)->frags[j].size = min_t(int, skb_shinfo(to)->frags[j].size, len);
105 len -= skb_shinfo(to)->frags[j].size;
109 skb_shinfo(to)->nr_frags = j;