|
@@ -338,6 +338,98 @@ fault:
|
|
|
return -EFAULT;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * skb_copy_datagram_const_iovec - Copy a datagram to an iovec.
|
|
|
+ * @skb: buffer to copy
|
|
|
+ * @offset: offset in the buffer to start copying from
|
|
|
+ * @to: io vector to copy to
|
|
|
+ * @to_offset: offset in the io vector to start copying to
|
|
|
+ * @len: amount of data to copy from buffer to iovec
|
|
|
+ *
|
|
|
+ * Returns 0 or -EFAULT.
|
|
|
+ * Note: the iovec is not modified during the copy.
|
|
|
+ */
|
|
|
+int skb_copy_datagram_const_iovec(const struct sk_buff *skb, int offset,
|
|
|
+ const struct iovec *to, int to_offset,
|
|
|
+ int len)
|
|
|
+{
|
|
|
+ int start = skb_headlen(skb);
|
|
|
+ int i, copy = start - offset;
|
|
|
+
|
|
|
+ /* Copy header. */
|
|
|
+ if (copy > 0) {
|
|
|
+ if (copy > len)
|
|
|
+ copy = len;
|
|
|
+ if (memcpy_toiovecend(to, skb->data + offset, to_offset, copy))
|
|
|
+ goto fault;
|
|
|
+ if ((len -= copy) == 0)
|
|
|
+ return 0;
|
|
|
+ offset += copy;
|
|
|
+ to_offset += copy;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Copy paged appendix. Hmm... why does this look so complicated? */
|
|
|
+ for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
|
|
|
+ int end;
|
|
|
+
|
|
|
+ WARN_ON(start > offset + len);
|
|
|
+
|
|
|
+ end = start + skb_shinfo(skb)->frags[i].size;
|
|
|
+ if ((copy = end - offset) > 0) {
|
|
|
+ int err;
|
|
|
+ u8 *vaddr;
|
|
|
+ skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
|
|
|
+ struct page *page = frag->page;
|
|
|
+
|
|
|
+ if (copy > len)
|
|
|
+ copy = len;
|
|
|
+ vaddr = kmap(page);
|
|
|
+ err = memcpy_toiovecend(to, vaddr + frag->page_offset +
|
|
|
+ offset - start, to_offset, copy);
|
|
|
+ kunmap(page);
|
|
|
+ if (err)
|
|
|
+ goto fault;
|
|
|
+ if (!(len -= copy))
|
|
|
+ return 0;
|
|
|
+ offset += copy;
|
|
|
+ to_offset += copy;
|
|
|
+ }
|
|
|
+ start = end;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (skb_shinfo(skb)->frag_list) {
|
|
|
+ struct sk_buff *list = skb_shinfo(skb)->frag_list;
|
|
|
+
|
|
|
+ for (; list; list = list->next) {
|
|
|
+ int end;
|
|
|
+
|
|
|
+ WARN_ON(start > offset + len);
|
|
|
+
|
|
|
+ end = start + list->len;
|
|
|
+ if ((copy = end - offset) > 0) {
|
|
|
+ if (copy > len)
|
|
|
+ copy = len;
|
|
|
+ if (skb_copy_datagram_const_iovec(list,
|
|
|
+ offset - start,
|
|
|
+ to, to_offset,
|
|
|
+ copy))
|
|
|
+ goto fault;
|
|
|
+ if ((len -= copy) == 0)
|
|
|
+ return 0;
|
|
|
+ offset += copy;
|
|
|
+ to_offset += copy;
|
|
|
+ }
|
|
|
+ start = end;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!len)
|
|
|
+ return 0;
|
|
|
+
|
|
|
+fault:
|
|
|
+ return -EFAULT;
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(skb_copy_datagram_const_iovec);
|
|
|
+
|
|
|
/**
|
|
|
* skb_copy_datagram_from_iovec - Copy a datagram from an iovec.
|
|
|
* @skb: buffer to copy
|