aboutsummaryrefslogtreecommitdiffstats
path: root/net/ieee802154/6lowpan.c
diff options
context:
space:
mode:
authoralex.bluesman.smirnov@gmail.com <alex.bluesman.smirnov@gmail.com>2012-04-25 19:35:50 -0400
committerDavid S. Miller <davem@davemloft.net>2012-04-26 06:01:09 -0400
commitc2e94d73ea24df499f9183b7401e8d6b94efa417 (patch)
tree524a9e4393e9d32fcd7acc5e9d96f7538bb3925b /net/ieee802154/6lowpan.c
parent07003408fc219ca7c45d2f559999f6aca08d711a (diff)
6lowpan: move frame allocation code to a separate function
Separate frame allocation routine from data processing function. This makes code more human readable and easier for understanding. Signed-off-by: Alexander Smirnov <alex.bluesman.smirnov@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ieee802154/6lowpan.c')
-rw-r--r--net/ieee802154/6lowpan.c81
1 files changed, 48 insertions, 33 deletions
diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
index 58c8895716ff..ec03626a3114 100644
--- a/net/ieee802154/6lowpan.c
+++ b/net/ieee802154/6lowpan.c
@@ -650,6 +650,53 @@ static void lowpan_fragment_timer_expired(unsigned long entry_addr)
650 kfree(entry); 650 kfree(entry);
651} 651}
652 652
653static struct lowpan_fragment *
654lowpan_alloc_new_frame(struct sk_buff *skb, u8 iphc0, u8 len, u8 tag)
655{
656 struct lowpan_fragment *frame;
657
658 frame = kzalloc(sizeof(struct lowpan_fragment),
659 GFP_ATOMIC);
660 if (!frame)
661 goto frame_err;
662
663 INIT_LIST_HEAD(&frame->list);
664
665 frame->length = (iphc0 & 7) | (len << 3);
666 frame->tag = tag;
667
668 /* allocate buffer for frame assembling */
669 frame->skb = alloc_skb(frame->length +
670 sizeof(struct ipv6hdr), GFP_ATOMIC);
671
672 if (!frame->skb)
673 goto skb_err;
674
675 frame->skb->priority = skb->priority;
676 frame->skb->dev = skb->dev;
677
678 /* reserve headroom for uncompressed ipv6 header */
679 skb_reserve(frame->skb, sizeof(struct ipv6hdr));
680 skb_put(frame->skb, frame->length);
681
682 init_timer(&frame->timer);
683 /* time out is the same as for ipv6 - 60 sec */
684 frame->timer.expires = jiffies + LOWPAN_FRAG_TIMEOUT;
685 frame->timer.data = (unsigned long)frame;
686 frame->timer.function = lowpan_fragment_timer_expired;
687
688 add_timer(&frame->timer);
689
690 list_add_tail(&frame->list, &lowpan_fragments);
691
692 return frame;
693
694skb_err:
695 kfree(frame);
696frame_err:
697 return NULL;
698}
699
653static int 700static int
654lowpan_process_data(struct sk_buff *skb) 701lowpan_process_data(struct sk_buff *skb)
655{ 702{
@@ -692,41 +739,9 @@ lowpan_process_data(struct sk_buff *skb)
692 739
693 /* alloc new frame structure */ 740 /* alloc new frame structure */
694 if (!found) { 741 if (!found) {
695 frame = kzalloc(sizeof(struct lowpan_fragment), 742 frame = lowpan_alloc_new_frame(skb, iphc0, len, tag);
696 GFP_ATOMIC);
697 if (!frame) 743 if (!frame)
698 goto unlock_and_drop; 744 goto unlock_and_drop;
699
700 INIT_LIST_HEAD(&frame->list);
701
702 frame->length = (iphc0 & 7) | (len << 3);
703 frame->tag = tag;
704
705 /* allocate buffer for frame assembling */
706 frame->skb = alloc_skb(frame->length +
707 sizeof(struct ipv6hdr), GFP_ATOMIC);
708
709 if (!frame->skb) {
710 kfree(frame);
711 goto unlock_and_drop;
712 }
713
714 frame->skb->priority = skb->priority;
715 frame->skb->dev = skb->dev;
716
717 /* reserve headroom for uncompressed ipv6 header */
718 skb_reserve(frame->skb, sizeof(struct ipv6hdr));
719 skb_put(frame->skb, frame->length);
720
721 init_timer(&frame->timer);
722 /* time out is the same as for ipv6 - 60 sec */
723 frame->timer.expires = jiffies + LOWPAN_FRAG_TIMEOUT;
724 frame->timer.data = (unsigned long)frame;
725 frame->timer.function = lowpan_fragment_timer_expired;
726
727 add_timer(&frame->timer);
728
729 list_add_tail(&frame->list, &lowpan_fragments);
730 } 745 }
731 746
732 if ((iphc0 & LOWPAN_DISPATCH_MASK) == LOWPAN_DISPATCH_FRAG1) 747 if ((iphc0 & LOWPAN_DISPATCH_MASK) == LOWPAN_DISPATCH_FRAG1)