diff options
author | David Howells <dhowells@redhat.com> | 2007-04-02 23:19:53 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-04-26 01:28:33 -0400 |
commit | 716ea3a7aae3a2bfc44cb97b5419c1c9868c7bc9 (patch) | |
tree | d599c7ff113e815c2052e40ec71bdab3761a45fc /net/xfrm | |
parent | 926554c4b74e53d5da4cefdc3bbd7e92427fb1a9 (diff) |
[NET]: Move generic skbuff stuff from XFRM code to generic code
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 <dhowells@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/xfrm')
-rw-r--r-- | net/xfrm/xfrm_algo.c | 169 |
1 files changed, 0 insertions, 169 deletions
diff --git a/net/xfrm/xfrm_algo.c b/net/xfrm/xfrm_algo.c index f373a8a7d9c8..6249a9405bb8 100644 --- a/net/xfrm/xfrm_algo.c +++ b/net/xfrm/xfrm_algo.c | |||
@@ -612,175 +612,6 @@ EXPORT_SYMBOL_GPL(skb_icv_walk); | |||
612 | 612 | ||
613 | #if defined(CONFIG_INET_ESP) || defined(CONFIG_INET_ESP_MODULE) || defined(CONFIG_INET6_ESP) || defined(CONFIG_INET6_ESP_MODULE) | 613 | #if defined(CONFIG_INET_ESP) || defined(CONFIG_INET_ESP_MODULE) || defined(CONFIG_INET6_ESP) || defined(CONFIG_INET6_ESP_MODULE) |
614 | 614 | ||
615 | /* Looking generic it is not used in another places. */ | ||
616 | |||
617 | int | ||
618 | skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len) | ||
619 | { | ||
620 | int start = skb_headlen(skb); | ||
621 | int i, copy = start - offset; | ||
622 | int elt = 0; | ||
623 | |||
624 | if (copy > 0) { | ||
625 | if (copy > len) | ||
626 | copy = len; | ||
627 | sg[elt].page = virt_to_page(skb->data + offset); | ||
628 | sg[elt].offset = (unsigned long)(skb->data + offset) % PAGE_SIZE; | ||
629 | sg[elt].length = copy; | ||
630 | elt++; | ||
631 | if ((len -= copy) == 0) | ||
632 | return elt; | ||
633 | offset += copy; | ||
634 | } | ||
635 | |||
636 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | ||
637 | int end; | ||
638 | |||
639 | BUG_TRAP(start <= offset + len); | ||
640 | |||
641 | end = start + skb_shinfo(skb)->frags[i].size; | ||
642 | if ((copy = end - offset) > 0) { | ||
643 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | ||
644 | |||
645 | if (copy > len) | ||
646 | copy = len; | ||
647 | sg[elt].page = frag->page; | ||
648 | sg[elt].offset = frag->page_offset+offset-start; | ||
649 | sg[elt].length = copy; | ||
650 | elt++; | ||
651 | if (!(len -= copy)) | ||
652 | return elt; | ||
653 | offset += copy; | ||
654 | } | ||
655 | start = end; | ||
656 | } | ||
657 | |||
658 | if (skb_shinfo(skb)->frag_list) { | ||
659 | struct sk_buff *list = skb_shinfo(skb)->frag_list; | ||
660 | |||
661 | for (; list; list = list->next) { | ||
662 | int end; | ||
663 | |||
664 | BUG_TRAP(start <= offset + len); | ||
665 | |||
666 | end = start + list->len; | ||
667 | if ((copy = end - offset) > 0) { | ||
668 | if (copy > len) | ||
669 | copy = len; | ||
670 | elt += skb_to_sgvec(list, sg+elt, offset - start, copy); | ||
671 | if ((len -= copy) == 0) | ||
672 | return elt; | ||
673 | offset += copy; | ||
674 | } | ||
675 | start = end; | ||
676 | } | ||
677 | } | ||
678 | BUG_ON(len); | ||
679 | return elt; | ||
680 | } | ||
681 | EXPORT_SYMBOL_GPL(skb_to_sgvec); | ||
682 | |||
683 | /* Check that skb data bits are writable. If they are not, copy data | ||
684 | * to newly created private area. If "tailbits" is given, make sure that | ||
685 | * tailbits bytes beyond current end of skb are writable. | ||
686 | * | ||
687 | * Returns amount of elements of scatterlist to load for subsequent | ||
688 | * transformations and pointer to writable trailer skb. | ||
689 | */ | ||
690 | |||
691 | int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer) | ||
692 | { | ||
693 | int copyflag; | ||
694 | int elt; | ||
695 | struct sk_buff *skb1, **skb_p; | ||
696 | |||
697 | /* If skb is cloned or its head is paged, reallocate | ||
698 | * head pulling out all the pages (pages are considered not writable | ||
699 | * at the moment even if they are anonymous). | ||
700 | */ | ||
701 | if ((skb_cloned(skb) || skb_shinfo(skb)->nr_frags) && | ||
702 | __pskb_pull_tail(skb, skb_pagelen(skb)-skb_headlen(skb)) == NULL) | ||
703 | return -ENOMEM; | ||
704 | |||
705 | /* Easy case. Most of packets will go this way. */ | ||
706 | if (!skb_shinfo(skb)->frag_list) { | ||
707 | /* A little of trouble, not enough of space for trailer. | ||
708 | * This should not happen, when stack is tuned to generate | ||
709 | * good frames. OK, on miss we reallocate and reserve even more | ||
710 | * space, 128 bytes is fair. */ | ||
711 | |||
712 | if (skb_tailroom(skb) < tailbits && | ||
713 | pskb_expand_head(skb, 0, tailbits-skb_tailroom(skb)+128, GFP_ATOMIC)) | ||
714 | return -ENOMEM; | ||
715 | |||
716 | /* Voila! */ | ||
717 | *trailer = skb; | ||
718 | return 1; | ||
719 | } | ||
720 | |||
721 | /* Misery. We are in troubles, going to mincer fragments... */ | ||
722 | |||
723 | elt = 1; | ||
724 | skb_p = &skb_shinfo(skb)->frag_list; | ||
725 | copyflag = 0; | ||
726 | |||
727 | while ((skb1 = *skb_p) != NULL) { | ||
728 | int ntail = 0; | ||
729 | |||
730 | /* The fragment is partially pulled by someone, | ||
731 | * this can happen on input. Copy it and everything | ||
732 | * after it. */ | ||
733 | |||
734 | if (skb_shared(skb1)) | ||
735 | copyflag = 1; | ||
736 | |||
737 | /* If the skb is the last, worry about trailer. */ | ||
738 | |||
739 | if (skb1->next == NULL && tailbits) { | ||
740 | if (skb_shinfo(skb1)->nr_frags || | ||
741 | skb_shinfo(skb1)->frag_list || | ||
742 | skb_tailroom(skb1) < tailbits) | ||
743 | ntail = tailbits + 128; | ||
744 | } | ||
745 | |||
746 | if (copyflag || | ||
747 | skb_cloned(skb1) || | ||
748 | ntail || | ||
749 | skb_shinfo(skb1)->nr_frags || | ||
750 | skb_shinfo(skb1)->frag_list) { | ||
751 | struct sk_buff *skb2; | ||
752 | |||
753 | /* Fuck, we are miserable poor guys... */ | ||
754 | if (ntail == 0) | ||
755 | skb2 = skb_copy(skb1, GFP_ATOMIC); | ||
756 | else | ||
757 | skb2 = skb_copy_expand(skb1, | ||
758 | skb_headroom(skb1), | ||
759 | ntail, | ||
760 | GFP_ATOMIC); | ||
761 | if (unlikely(skb2 == NULL)) | ||
762 | return -ENOMEM; | ||
763 | |||
764 | if (skb1->sk) | ||
765 | skb_set_owner_w(skb2, skb1->sk); | ||
766 | |||
767 | /* Looking around. Are we still alive? | ||
768 | * OK, link new skb, drop old one */ | ||
769 | |||
770 | skb2->next = skb1->next; | ||
771 | *skb_p = skb2; | ||
772 | kfree_skb(skb1); | ||
773 | skb1 = skb2; | ||
774 | } | ||
775 | elt++; | ||
776 | *trailer = skb1; | ||
777 | skb_p = &skb1->next; | ||
778 | } | ||
779 | |||
780 | return elt; | ||
781 | } | ||
782 | EXPORT_SYMBOL_GPL(skb_cow_data); | ||
783 | |||
784 | void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len) | 615 | void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len) |
785 | { | 616 | { |
786 | if (tail != skb) { | 617 | if (tail != skb) { |