[PATCH 2/9] AF_RXRPC: Move generic skbuff stuff from XFRM code to generic code

2007-04-02 Thread David Howells
Move generic skbuff stuff from XFRM code to generic code so that AF_RXRPC can
use it too.

The kdoc comments I've attached to the functions needs to be checked by whoever
wrote them as I had to make some guesses about the workings of these functions.

Signed-Off-By: David Howells <[EMAIL PROTECTED]>
---

 include/linux/skbuff.h |6 ++
 include/net/esp.h  |2 -
 net/core/skbuff.c  |  188 
 net/xfrm/xfrm_algo.c   |  169 ---
 4 files changed, 194 insertions(+), 171 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 82f43ad..d53ff7c 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -83,6 +83,7 @@
  */
 
 struct net_device;
+struct scatterlist;
 
 #ifdef CONFIG_NETFILTER
 struct nf_conntrack {
@@ -364,6 +365,11 @@ extern struct sk_buff *skb_realloc_headroom(struct sk_buff 
*skb,
 extern struct sk_buff *skb_copy_expand(const struct sk_buff *skb,
   int newheadroom, int newtailroom,
   gfp_t priority);
+extern intskb_to_sgvec(struct sk_buff *skb,
+   struct scatterlist *sg, int offset,
+   int len);
+extern intskb_cow_data(struct sk_buff *skb, int tailbits,
+   struct sk_buff **trailer);
 extern intskb_pad(struct sk_buff *skb, int pad);
 #define dev_kfree_skb(a)   kfree_skb(a)
 extern void  skb_over_panic(struct sk_buff *skb, int len,
diff --git a/include/net/esp.h b/include/net/esp.h
index 713d039..d05d8d2 100644
--- a/include/net/esp.h
+++ b/include/net/esp.h
@@ -40,8 +40,6 @@ struct esp_data
} auth;
 };
 
-extern int skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int 
offset, int len);
-extern int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff 
**trailer);
 extern void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len);
 
 static inline int esp_mac_digest(struct esp_data *esp, struct sk_buff *skb,
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 87573ae..156b9c0 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -55,6 +55,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -2060,6 +2061,190 @@ void __init skb_init(void)
NULL, NULL);
 }
 
+/**
+ * skb_to_sgvec - Fill a scatter-gather list from a socket buffer
+ * @skb: Socket buffer containing the buffers to be mapped
+ * @sg: The scatter-gather list to map into
+ * @offset: The offset into the buffer's contents to start mapping
+ * @len: Length of buffer space to be mapped
+ *
+ * Fill the specified scatter-gather list with mappings/pointers into a
+ * region of the buffer space attached to a socket buffer.
+ */
+int
+skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len)
+{
+   int start = skb_headlen(skb);
+   int i, copy = start - offset;
+   int elt = 0;
+
+   if (copy > 0) {
+   if (copy > len)
+   copy = len;
+   sg[elt].page = virt_to_page(skb->data + offset);
+   sg[elt].offset = (unsigned long)(skb->data + offset) % 
PAGE_SIZE;
+   sg[elt].length = copy;
+   elt++;
+   if ((len -= copy) == 0)
+   return elt;
+   offset += copy;
+   }
+
+   for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
+   int end;
+
+   BUG_TRAP(start <= offset + len);
+
+   end = start + skb_shinfo(skb)->frags[i].size;
+   if ((copy = end - offset) > 0) {
+   skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
+
+   if (copy > len)
+   copy = len;
+   sg[elt].page = frag->page;
+   sg[elt].offset = frag->page_offset+offset-start;
+   sg[elt].length = copy;
+   elt++;
+   if (!(len -= copy))
+   return elt;
+   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;
+
+   BUG_TRAP(start <= offset + len);
+
+   end = start + list->len;
+   if ((copy = end - offset) > 0) {
+   if (copy > len)
+   copy = len;
+   elt += skb_to_sgvec(list, sg+elt, offset - 
start, copy);
+   if ((len -= copy) == 0)
+   return elt;
+ 

Re: [PATCH 2/9] AF_RXRPC: Move generic skbuff stuff from XFRM code to generic code

2007-04-02 Thread David Miller
From: David Howells <[EMAIL PROTECTED]>
Date: Mon, 02 Apr 2007 23:45:03 +0100

> Move generic skbuff stuff from XFRM code to generic code so that AF_RXRPC can
> use it too.
> 
> The kdoc comments I've attached to the functions needs to be checked by 
> whoever
> wrote them as I had to make some guesses about the workings of these 
> functions.
> 
> Signed-Off-By: David Howells <[EMAIL PROTECTED]>

Patch applied to net-2.6.22, thanks a lot David.
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html