home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / src / linux-headers-2.6.17-6 / include / linux / skbuff.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-08-11  |  38.5 KB  |  1,400 lines

  1. /*
  2.  *    Definitions for the 'struct sk_buff' memory handlers.
  3.  *
  4.  *    Authors:
  5.  *        Alan Cox, <gw4pts@gw4pts.ampr.org>
  6.  *        Florian La Roche, <rzsfl@rz.uni-sb.de>
  7.  *
  8.  *    This program is free software; you can redistribute it and/or
  9.  *    modify it under the terms of the GNU General Public License
  10.  *    as published by the Free Software Foundation; either version
  11.  *    2 of the License, or (at your option) any later version.
  12.  */
  13.  
  14. #ifndef _LINUX_SKBUFF_H
  15. #define _LINUX_SKBUFF_H
  16.  
  17. #include <linux/kernel.h>
  18. #include <linux/compiler.h>
  19. #include <linux/time.h>
  20. #include <linux/cache.h>
  21.  
  22. #include <asm/atomic.h>
  23. #include <asm/types.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/mm.h>
  26. #include <linux/highmem.h>
  27. #include <linux/poll.h>
  28. #include <linux/net.h>
  29. #include <linux/textsearch.h>
  30. #include <net/checksum.h>
  31.  
  32. #define HAVE_ALLOC_SKB        /* For the drivers to know */
  33. #define HAVE_ALIGNABLE_SKB    /* Ditto 8)           */
  34.  
  35. #define CHECKSUM_NONE 0
  36. #define CHECKSUM_HW 1
  37. #define CHECKSUM_UNNECESSARY 2
  38.  
  39. #define SKB_DATA_ALIGN(X)    (((X) + (SMP_CACHE_BYTES - 1)) & \
  40.                  ~(SMP_CACHE_BYTES - 1))
  41. #define SKB_MAX_ORDER(X, ORDER)    (((PAGE_SIZE << (ORDER)) - (X) - \
  42.                   sizeof(struct skb_shared_info)) & \
  43.                   ~(SMP_CACHE_BYTES - 1))
  44. #define SKB_MAX_HEAD(X)        (SKB_MAX_ORDER((X), 0))
  45. #define SKB_MAX_ALLOC        (SKB_MAX_ORDER(0, 2))
  46.  
  47. /* A. Checksumming of received packets by device.
  48.  *
  49.  *    NONE: device failed to checksum this packet.
  50.  *        skb->csum is undefined.
  51.  *
  52.  *    UNNECESSARY: device parsed packet and wouldbe verified checksum.
  53.  *        skb->csum is undefined.
  54.  *          It is bad option, but, unfortunately, many of vendors do this.
  55.  *          Apparently with secret goal to sell you new device, when you
  56.  *          will add new protocol to your host. F.e. IPv6. 8)
  57.  *
  58.  *    HW: the most generic way. Device supplied checksum of _all_
  59.  *        the packet as seen by netif_rx in skb->csum.
  60.  *        NOTE: Even if device supports only some protocols, but
  61.  *        is able to produce some skb->csum, it MUST use HW,
  62.  *        not UNNECESSARY.
  63.  *
  64.  * B. Checksumming on output.
  65.  *
  66.  *    NONE: skb is checksummed by protocol or csum is not required.
  67.  *
  68.  *    HW: device is required to csum packet as seen by hard_start_xmit
  69.  *    from skb->h.raw to the end and to record the checksum
  70.  *    at skb->h.raw+skb->csum.
  71.  *
  72.  *    Device must show its capabilities in dev->features, set
  73.  *    at device setup time.
  74.  *    NETIF_F_HW_CSUM    - it is clever device, it is able to checksum
  75.  *              everything.
  76.  *    NETIF_F_NO_CSUM - loopback or reliable single hop media.
  77.  *    NETIF_F_IP_CSUM - device is dumb. It is able to csum only
  78.  *              TCP/UDP over IPv4. Sigh. Vendors like this
  79.  *              way by an unknown reason. Though, see comment above
  80.  *              about CHECKSUM_UNNECESSARY. 8)
  81.  *
  82.  *    Any questions? No questions, good.         --ANK
  83.  */
  84.  
  85. struct net_device;
  86.  
  87. #ifdef CONFIG_NETFILTER
  88. struct nf_conntrack {
  89.     atomic_t use;
  90.     void (*destroy)(struct nf_conntrack *);
  91. };
  92.  
  93. #ifdef CONFIG_BRIDGE_NETFILTER
  94. struct nf_bridge_info {
  95.     atomic_t use;
  96.     struct net_device *physindev;
  97.     struct net_device *physoutdev;
  98. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  99.     struct net_device *netoutdev;
  100. #endif
  101.     unsigned int mask;
  102.     unsigned long data[32 / sizeof(unsigned long)];
  103. };
  104. #endif
  105.  
  106. #endif
  107.  
  108. struct sk_buff_head {
  109.     /* These two members must be first. */
  110.     struct sk_buff    *next;
  111.     struct sk_buff    *prev;
  112.  
  113.     __u32        qlen;
  114.     spinlock_t    lock;
  115. };
  116.  
  117. struct sk_buff;
  118.  
  119. /* To allow 64K frame to be packed as single skb without frag_list */
  120. #define MAX_SKB_FRAGS (65536/PAGE_SIZE + 2)
  121.  
  122. typedef struct skb_frag_struct skb_frag_t;
  123.  
  124. struct skb_frag_struct {
  125.     struct page *page;
  126.     __u16 page_offset;
  127.     __u16 size;
  128. };
  129.  
  130. /* This data is invariant across clones and lives at
  131.  * the end of the header data, ie. at skb->end.
  132.  */
  133. struct skb_shared_info {
  134.     atomic_t    dataref;
  135.     unsigned short    nr_frags;
  136.     unsigned short    tso_size;
  137.     unsigned short    tso_segs;
  138.     unsigned short  ufo_size;
  139.     unsigned int    ip6_frag_id;
  140.     struct sk_buff    *frag_list;
  141.     skb_frag_t    frags[MAX_SKB_FRAGS];
  142. };
  143.  
  144. /* We divide dataref into two halves.  The higher 16 bits hold references
  145.  * to the payload part of skb->data.  The lower 16 bits hold references to
  146.  * the entire skb->data.  It is up to the users of the skb to agree on
  147.  * where the payload starts.
  148.  *
  149.  * All users must obey the rule that the skb->data reference count must be
  150.  * greater than or equal to the payload reference count.
  151.  *
  152.  * Holding a reference to the payload part means that the user does not
  153.  * care about modifications to the header part of skb->data.
  154.  */
  155. #define SKB_DATAREF_SHIFT 16
  156. #define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1)
  157.  
  158. struct skb_timeval {
  159.     u32    off_sec;
  160.     u32    off_usec;
  161. };
  162.  
  163.  
  164. enum {
  165.     SKB_FCLONE_UNAVAILABLE,
  166.     SKB_FCLONE_ORIG,
  167.     SKB_FCLONE_CLONE,
  168. };
  169.  
  170. /** 
  171.  *    struct sk_buff - socket buffer
  172.  *    @next: Next buffer in list
  173.  *    @prev: Previous buffer in list
  174.  *    @sk: Socket we are owned by
  175.  *    @tstamp: Time we arrived
  176.  *    @dev: Device we arrived on/are leaving by
  177.  *    @input_dev: Device we arrived on
  178.  *    @h: Transport layer header
  179.  *    @nh: Network layer header
  180.  *    @mac: Link layer header
  181.  *    @dst: destination entry
  182.  *    @sp: the security path, used for xfrm
  183.  *    @cb: Control buffer. Free for use by every layer. Put private vars here
  184.  *    @len: Length of actual data
  185.  *    @data_len: Data length
  186.  *    @mac_len: Length of link layer header
  187.  *    @csum: Checksum
  188.  *    @local_df: allow local fragmentation
  189.  *    @cloned: Head may be cloned (check refcnt to be sure)
  190.  *    @nohdr: Payload reference only, must not modify header
  191.  *    @pkt_type: Packet class
  192.  *    @fclone: skbuff clone status
  193.  *    @ip_summed: Driver fed us an IP checksum
  194.  *    @priority: Packet queueing priority
  195.  *    @users: User count - see {datagram,tcp}.c
  196.  *    @protocol: Packet protocol from driver
  197.  *    @truesize: Buffer size 
  198.  *    @head: Head of buffer
  199.  *    @data: Data head pointer
  200.  *    @tail: Tail pointer
  201.  *    @end: End pointer
  202.  *    @destructor: Destruct function
  203.  *    @nfmark: Can be used for communication between hooks
  204.  *    @nfct: Associated connection, if any
  205.  *    @ipvs_property: skbuff is owned by ipvs
  206.  *    @nfctinfo: Relationship of this skb to the connection
  207.  *    @nfct_reasm: netfilter conntrack re-assembly pointer
  208.  *    @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
  209.  *    @tc_index: Traffic control index
  210.  *    @tc_verd: traffic control verdict
  211.  */
  212.  
  213. struct sk_buff {
  214.     /* These two members must be first. */
  215.     struct sk_buff        *next;
  216.     struct sk_buff        *prev;
  217.  
  218.     struct sock        *sk;
  219.     struct skb_timeval    tstamp;
  220.     struct net_device    *dev;
  221.     struct net_device    *input_dev;
  222.  
  223.     union {
  224.         struct tcphdr    *th;
  225.         struct udphdr    *uh;
  226.         struct icmphdr    *icmph;
  227.         struct igmphdr    *igmph;
  228.         struct iphdr    *ipiph;
  229.         struct ipv6hdr    *ipv6h;
  230.         unsigned char    *raw;
  231.     } h;
  232.  
  233.     union {
  234.         struct iphdr    *iph;
  235.         struct ipv6hdr    *ipv6h;
  236.         struct arphdr    *arph;
  237.         unsigned char    *raw;
  238.     } nh;
  239.  
  240.     union {
  241.           unsigned char     *raw;
  242.     } mac;
  243.  
  244.     struct  dst_entry    *dst;
  245.     struct    sec_path    *sp;
  246.  
  247.     /*
  248.      * This is the control buffer. It is free to use for every
  249.      * layer. Please put your private variables there. If you
  250.      * want to keep them across layers you have to do a skb_clone()
  251.      * first. This is owned by whoever has the skb queued ATM.
  252.      */
  253.     char            cb[48];
  254.  
  255.     unsigned int        len,
  256.                 data_len,
  257.                 mac_len,
  258.                 csum;
  259.     __u32            priority;
  260.     __u8            local_df:1,
  261.                 cloned:1,
  262.                 ip_summed:2,
  263.                 nohdr:1,
  264.                 nfctinfo:3;
  265.     __u8            pkt_type:3,
  266.                 fclone:2,
  267.                 ipvs_property:1;
  268.     __be16            protocol;
  269.  
  270.     void            (*destructor)(struct sk_buff *skb);
  271. #ifdef CONFIG_NETFILTER
  272.     struct nf_conntrack    *nfct;
  273. #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  274.     struct sk_buff        *nfct_reasm;
  275. #endif
  276. #ifdef CONFIG_BRIDGE_NETFILTER
  277.     struct nf_bridge_info    *nf_bridge;
  278. #endif
  279.     __u32            nfmark;
  280. #endif /* CONFIG_NETFILTER */
  281. #ifdef CONFIG_NET_SCHED
  282.     __u16            tc_index;    /* traffic control index */
  283. #ifdef CONFIG_NET_CLS_ACT
  284.     __u16            tc_verd;    /* traffic control verdict */
  285. #endif
  286. #endif
  287.  
  288.  
  289.     /* These elements must be at the end, see alloc_skb() for details.  */
  290.     unsigned int        truesize;
  291.     atomic_t        users;
  292.     unsigned char        *head,
  293.                 *data,
  294.                 *tail,
  295.                 *end;
  296. };
  297.  
  298. #ifdef __KERNEL__
  299. /*
  300.  *    Handling routines are only of interest to the kernel
  301.  */
  302. #include <linux/slab.h>
  303.  
  304. #include <asm/system.h>
  305.  
  306. extern void kfree_skb(struct sk_buff *skb);
  307. extern void           __kfree_skb(struct sk_buff *skb);
  308. extern struct sk_buff *__alloc_skb(unsigned int size,
  309.                    gfp_t priority, int fclone);
  310. static inline struct sk_buff *alloc_skb(unsigned int size,
  311.                     gfp_t priority)
  312. {
  313.     return __alloc_skb(size, priority, 0);
  314. }
  315.  
  316. static inline struct sk_buff *alloc_skb_fclone(unsigned int size,
  317.                            gfp_t priority)
  318. {
  319.     return __alloc_skb(size, priority, 1);
  320. }
  321.  
  322. extern struct sk_buff *alloc_skb_from_cache(kmem_cache_t *cp,
  323.                         unsigned int size,
  324.                         gfp_t priority);
  325. extern void           kfree_skbmem(struct sk_buff *skb);
  326. extern struct sk_buff *skb_clone(struct sk_buff *skb,
  327.                  gfp_t priority);
  328. extern struct sk_buff *skb_copy(const struct sk_buff *skb,
  329.                 gfp_t priority);
  330. extern struct sk_buff *pskb_copy(struct sk_buff *skb,
  331.                  gfp_t gfp_mask);
  332. extern int           pskb_expand_head(struct sk_buff *skb,
  333.                     int nhead, int ntail,
  334.                     gfp_t gfp_mask);
  335. extern struct sk_buff *skb_realloc_headroom(struct sk_buff *skb,
  336.                         unsigned int headroom);
  337. extern struct sk_buff *skb_copy_expand(const struct sk_buff *skb,
  338.                        int newheadroom, int newtailroom,
  339.                        gfp_t priority);
  340. extern struct sk_buff *        skb_pad(struct sk_buff *skb, int pad);
  341. #define dev_kfree_skb(a)    kfree_skb(a)
  342. extern void          skb_over_panic(struct sk_buff *skb, int len,
  343.                      void *here);
  344. extern void          skb_under_panic(struct sk_buff *skb, int len,
  345.                       void *here);
  346. extern void          skb_truesize_bug(struct sk_buff *skb);
  347.  
  348. static inline void skb_truesize_check(struct sk_buff *skb)
  349. {
  350.     if (unlikely((int)skb->truesize < sizeof(struct sk_buff) + skb->len))
  351.         skb_truesize_bug(skb);
  352. }
  353.  
  354. extern int skb_append_datato_frags(struct sock *sk, struct sk_buff *skb,
  355.             int getfrag(void *from, char *to, int offset,
  356.             int len,int odd, struct sk_buff *skb),
  357.             void *from, int length);
  358.  
  359. struct skb_seq_state
  360. {
  361.     __u32        lower_offset;
  362.     __u32        upper_offset;
  363.     __u32        frag_idx;
  364.     __u32        stepped_offset;
  365.     struct sk_buff    *root_skb;
  366.     struct sk_buff    *cur_skb;
  367.     __u8        *frag_data;
  368. };
  369.  
  370. extern void          skb_prepare_seq_read(struct sk_buff *skb,
  371.                        unsigned int from, unsigned int to,
  372.                        struct skb_seq_state *st);
  373. extern unsigned int   skb_seq_read(unsigned int consumed, const u8 **data,
  374.                    struct skb_seq_state *st);
  375. extern void          skb_abort_seq_read(struct skb_seq_state *st);
  376.  
  377. extern unsigned int   skb_find_text(struct sk_buff *skb, unsigned int from,
  378.                     unsigned int to, struct ts_config *config,
  379.                     struct ts_state *state);
  380.  
  381. /* Internal */
  382. #define skb_shinfo(SKB)        ((struct skb_shared_info *)((SKB)->end))
  383.  
  384. /**
  385.  *    skb_queue_empty - check if a queue is empty
  386.  *    @list: queue head
  387.  *
  388.  *    Returns true if the queue is empty, false otherwise.
  389.  */
  390. static inline int skb_queue_empty(const struct sk_buff_head *list)
  391. {
  392.     return list->next == (struct sk_buff *)list;
  393. }
  394.  
  395. /**
  396.  *    skb_get - reference buffer
  397.  *    @skb: buffer to reference
  398.  *
  399.  *    Makes another reference to a socket buffer and returns a pointer
  400.  *    to the buffer.
  401.  */
  402. static inline struct sk_buff *skb_get(struct sk_buff *skb)
  403. {
  404.     atomic_inc(&skb->users);
  405.     return skb;
  406. }
  407.  
  408. /*
  409.  * If users == 1, we are the only owner and are can avoid redundant
  410.  * atomic change.
  411.  */
  412.  
  413. /**
  414.  *    skb_cloned - is the buffer a clone
  415.  *    @skb: buffer to check
  416.  *
  417.  *    Returns true if the buffer was generated with skb_clone() and is
  418.  *    one of multiple shared copies of the buffer. Cloned buffers are
  419.  *    shared data so must not be written to under normal circumstances.
  420.  */
  421. static inline int skb_cloned(const struct sk_buff *skb)
  422. {
  423.     return skb->cloned &&
  424.            (atomic_read(&skb_shinfo(skb)->dataref) & SKB_DATAREF_MASK) != 1;
  425. }
  426.  
  427. /**
  428.  *    skb_header_cloned - is the header a clone
  429.  *    @skb: buffer to check
  430.  *
  431.  *    Returns true if modifying the header part of the buffer requires
  432.  *    the data to be copied.
  433.  */
  434. static inline int skb_header_cloned(const struct sk_buff *skb)
  435. {
  436.     int dataref;
  437.  
  438.     if (!skb->cloned)
  439.         return 0;
  440.  
  441.     dataref = atomic_read(&skb_shinfo(skb)->dataref);
  442.     dataref = (dataref & SKB_DATAREF_MASK) - (dataref >> SKB_DATAREF_SHIFT);
  443.     return dataref != 1;
  444. }
  445.  
  446. /**
  447.  *    skb_header_release - release reference to header
  448.  *    @skb: buffer to operate on
  449.  *
  450.  *    Drop a reference to the header part of the buffer.  This is done
  451.  *    by acquiring a payload reference.  You must not read from the header
  452.  *    part of skb->data after this.
  453.  */
  454. static inline void skb_header_release(struct sk_buff *skb)
  455. {
  456.     BUG_ON(skb->nohdr);
  457.     skb->nohdr = 1;
  458.     atomic_add(1 << SKB_DATAREF_SHIFT, &skb_shinfo(skb)->dataref);
  459. }
  460.  
  461. /**
  462.  *    skb_shared - is the buffer shared
  463.  *    @skb: buffer to check
  464.  *
  465.  *    Returns true if more than one person has a reference to this
  466.  *    buffer.
  467.  */
  468. static inline int skb_shared(const struct sk_buff *skb)
  469. {
  470.     return atomic_read(&skb->users) != 1;
  471. }
  472.  
  473. /**
  474.  *    skb_share_check - check if buffer is shared and if so clone it
  475.  *    @skb: buffer to check
  476.  *    @pri: priority for memory allocation
  477.  *
  478.  *    If the buffer is shared the buffer is cloned and the old copy
  479.  *    drops a reference. A new clone with a single reference is returned.
  480.  *    If the buffer is not shared the original buffer is returned. When
  481.  *    being called from interrupt status or with spinlocks held pri must
  482.  *    be GFP_ATOMIC.
  483.  *
  484.  *    NULL is returned on a memory allocation failure.
  485.  */
  486. static inline struct sk_buff *skb_share_check(struct sk_buff *skb,
  487.                           gfp_t pri)
  488. {
  489.     might_sleep_if(pri & __GFP_WAIT);
  490.     if (skb_shared(skb)) {
  491.         struct sk_buff *nskb = skb_clone(skb, pri);
  492.         kfree_skb(skb);
  493.         skb = nskb;
  494.     }
  495.     return skb;
  496. }
  497.  
  498. /*
  499.  *    Copy shared buffers into a new sk_buff. We effectively do COW on
  500.  *    packets to handle cases where we have a local reader and forward
  501.  *    and a couple of other messy ones. The normal one is tcpdumping
  502.  *    a packet thats being forwarded.
  503.  */
  504.  
  505. /**
  506.  *    skb_unshare - make a copy of a shared buffer
  507.  *    @skb: buffer to check
  508.  *    @pri: priority for memory allocation
  509.  *
  510.  *    If the socket buffer is a clone then this function creates a new
  511.  *    copy of the data, drops a reference count on the old copy and returns
  512.  *    the new copy with the reference count at 1. If the buffer is not a clone
  513.  *    the original buffer is returned. When called with a spinlock held or
  514.  *    from interrupt state @pri must be %GFP_ATOMIC
  515.  *
  516.  *    %NULL is returned on a memory allocation failure.
  517.  */
  518. static inline struct sk_buff *skb_unshare(struct sk_buff *skb,
  519.                       gfp_t pri)
  520. {
  521.     might_sleep_if(pri & __GFP_WAIT);
  522.     if (skb_cloned(skb)) {
  523.         struct sk_buff *nskb = skb_copy(skb, pri);
  524.         kfree_skb(skb);    /* Free our shared copy */
  525.         skb = nskb;
  526.     }
  527.     return skb;
  528. }
  529.  
  530. /**
  531.  *    skb_peek
  532.  *    @list_: list to peek at
  533.  *
  534.  *    Peek an &sk_buff. Unlike most other operations you _MUST_
  535.  *    be careful with this one. A peek leaves the buffer on the
  536.  *    list and someone else may run off with it. You must hold
  537.  *    the appropriate locks or have a private queue to do this.
  538.  *
  539.  *    Returns %NULL for an empty list or a pointer to the head element.
  540.  *    The reference count is not incremented and the reference is therefore
  541.  *    volatile. Use with caution.
  542.  */
  543. static inline struct sk_buff *skb_peek(struct sk_buff_head *list_)
  544. {
  545.     struct sk_buff *list = ((struct sk_buff *)list_)->next;
  546.     if (list == (struct sk_buff *)list_)
  547.         list = NULL;
  548.     return list;
  549. }
  550.  
  551. /**
  552.  *    skb_peek_tail
  553.  *    @list_: list to peek at
  554.  *
  555.  *    Peek an &sk_buff. Unlike most other operations you _MUST_
  556.  *    be careful with this one. A peek leaves the buffer on the
  557.  *    list and someone else may run off with it. You must hold
  558.  *    the appropriate locks or have a private queue to do this.
  559.  *
  560.  *    Returns %NULL for an empty list or a pointer to the tail element.
  561.  *    The reference count is not incremented and the reference is therefore
  562.  *    volatile. Use with caution.
  563.  */
  564. static inline struct sk_buff *skb_peek_tail(struct sk_buff_head *list_)
  565. {
  566.     struct sk_buff *list = ((struct sk_buff *)list_)->prev;
  567.     if (list == (struct sk_buff *)list_)
  568.         list = NULL;
  569.     return list;
  570. }
  571.  
  572. /**
  573.  *    skb_queue_len    - get queue length
  574.  *    @list_: list to measure
  575.  *
  576.  *    Return the length of an &sk_buff queue.
  577.  */
  578. static inline __u32 skb_queue_len(const struct sk_buff_head *list_)
  579. {
  580.     return list_->qlen;
  581. }
  582.  
  583. static inline void skb_queue_head_init(struct sk_buff_head *list)
  584. {
  585.     spin_lock_init(&list->lock);
  586.     list->prev = list->next = (struct sk_buff *)list;
  587.     list->qlen = 0;
  588. }
  589.  
  590. /*
  591.  *    Insert an sk_buff at the start of a list.
  592.  *
  593.  *    The "__skb_xxxx()" functions are the non-atomic ones that
  594.  *    can only be called with interrupts disabled.
  595.  */
  596.  
  597. /**
  598.  *    __skb_queue_after - queue a buffer at the list head
  599.  *    @list: list to use
  600.  *    @prev: place after this buffer
  601.  *    @newsk: buffer to queue
  602.  *
  603.  *    Queue a buffer int the middle of a list. This function takes no locks
  604.  *    and you must therefore hold required locks before calling it.
  605.  *
  606.  *    A buffer cannot be placed on two lists at the same time.
  607.  */
  608. static inline void __skb_queue_after(struct sk_buff_head *list,
  609.                      struct sk_buff *prev,
  610.                      struct sk_buff *newsk)
  611. {
  612.     struct sk_buff *next;
  613.     list->qlen++;
  614.  
  615.     next = prev->next;
  616.     newsk->next = next;
  617.     newsk->prev = prev;
  618.     next->prev  = prev->next = newsk;
  619. }
  620.  
  621. /**
  622.  *    __skb_queue_head - queue a buffer at the list head
  623.  *    @list: list to use
  624.  *    @newsk: buffer to queue
  625.  *
  626.  *    Queue a buffer at the start of a list. This function takes no locks
  627.  *    and you must therefore hold required locks before calling it.
  628.  *
  629.  *    A buffer cannot be placed on two lists at the same time.
  630.  */
  631. extern void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk);
  632. static inline void __skb_queue_head(struct sk_buff_head *list,
  633.                     struct sk_buff *newsk)
  634. {
  635.     __skb_queue_after(list, (struct sk_buff *)list, newsk);
  636. }
  637.  
  638. /**
  639.  *    __skb_queue_tail - queue a buffer at the list tail
  640.  *    @list: list to use
  641.  *    @newsk: buffer to queue
  642.  *
  643.  *    Queue a buffer at the end of a list. This function takes no locks
  644.  *    and you must therefore hold required locks before calling it.
  645.  *
  646.  *    A buffer cannot be placed on two lists at the same time.
  647.  */
  648. extern void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk);
  649. static inline void __skb_queue_tail(struct sk_buff_head *list,
  650.                    struct sk_buff *newsk)
  651. {
  652.     struct sk_buff *prev, *next;
  653.  
  654.     list->qlen++;
  655.     next = (struct sk_buff *)list;
  656.     prev = next->prev;
  657.     newsk->next = next;
  658.     newsk->prev = prev;
  659.     next->prev  = prev->next = newsk;
  660. }
  661.  
  662.  
  663. /**
  664.  *    __skb_dequeue - remove from the head of the queue
  665.  *    @list: list to dequeue from
  666.  *
  667.  *    Remove the head of the list. This function does not take any locks
  668.  *    so must be used with appropriate locks held only. The head item is
  669.  *    returned or %NULL if the list is empty.
  670.  */
  671. extern struct sk_buff *skb_dequeue(struct sk_buff_head *list);
  672. static inline struct sk_buff *__skb_dequeue(struct sk_buff_head *list)
  673. {
  674.     struct sk_buff *next, *prev, *result;
  675.  
  676.     prev = (struct sk_buff *) list;
  677.     next = prev->next;
  678.     result = NULL;
  679.     if (next != prev) {
  680.         result         = next;
  681.         next         = next->next;
  682.         list->qlen--;
  683.         next->prev   = prev;
  684.         prev->next   = next;
  685.         result->next = result->prev = NULL;
  686.     }
  687.     return result;
  688. }
  689.  
  690.  
  691. /*
  692.  *    Insert a packet on a list.
  693.  */
  694. extern void        skb_insert(struct sk_buff *old, struct sk_buff *newsk, struct sk_buff_head *list);
  695. static inline void __skb_insert(struct sk_buff *newsk,
  696.                 struct sk_buff *prev, struct sk_buff *next,
  697.                 struct sk_buff_head *list)
  698. {
  699.     newsk->next = next;
  700.     newsk->prev = prev;
  701.     next->prev  = prev->next = newsk;
  702.     list->qlen++;
  703. }
  704.  
  705. /*
  706.  *    Place a packet after a given packet in a list.
  707.  */
  708. extern void       skb_append(struct sk_buff *old, struct sk_buff *newsk, struct sk_buff_head *list);
  709. static inline void __skb_append(struct sk_buff *old, struct sk_buff *newsk, struct sk_buff_head *list)
  710. {
  711.     __skb_insert(newsk, old, old->next, list);
  712. }
  713.  
  714. /*
  715.  * remove sk_buff from list. _Must_ be called atomically, and with
  716.  * the list known..
  717.  */
  718. extern void       skb_unlink(struct sk_buff *skb, struct sk_buff_head *list);
  719. static inline void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
  720. {
  721.     struct sk_buff *next, *prev;
  722.  
  723.     list->qlen--;
  724.     next       = skb->next;
  725.     prev       = skb->prev;
  726.     skb->next  = skb->prev = NULL;
  727.     next->prev = prev;
  728.     prev->next = next;
  729. }
  730.  
  731.  
  732. /* XXX: more streamlined implementation */
  733.  
  734. /**
  735.  *    __skb_dequeue_tail - remove from the tail of the queue
  736.  *    @list: list to dequeue from
  737.  *
  738.  *    Remove the tail of the list. This function does not take any locks
  739.  *    so must be used with appropriate locks held only. The tail item is
  740.  *    returned or %NULL if the list is empty.
  741.  */
  742. extern struct sk_buff *skb_dequeue_tail(struct sk_buff_head *list);
  743. static inline struct sk_buff *__skb_dequeue_tail(struct sk_buff_head *list)
  744. {
  745.     struct sk_buff *skb = skb_peek_tail(list);
  746.     if (skb)
  747.         __skb_unlink(skb, list);
  748.     return skb;
  749. }
  750.  
  751.  
  752. static inline int skb_is_nonlinear(const struct sk_buff *skb)
  753. {
  754.     return skb->data_len;
  755. }
  756.  
  757. static inline unsigned int skb_headlen(const struct sk_buff *skb)
  758. {
  759.     return skb->len - skb->data_len;
  760. }
  761.  
  762. static inline int skb_pagelen(const struct sk_buff *skb)
  763. {
  764.     int i, len = 0;
  765.  
  766.     for (i = (int)skb_shinfo(skb)->nr_frags - 1; i >= 0; i--)
  767.         len += skb_shinfo(skb)->frags[i].size;
  768.     return len + skb_headlen(skb);
  769. }
  770.  
  771. static inline void skb_fill_page_desc(struct sk_buff *skb, int i,
  772.                       struct page *page, int off, int size)
  773. {
  774.     skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  775.  
  776.     frag->page          = page;
  777.     frag->page_offset      = off;
  778.     frag->size          = size;
  779.     skb_shinfo(skb)->nr_frags = i + 1;
  780. }
  781.  
  782. #define SKB_PAGE_ASSERT(skb)     BUG_ON(skb_shinfo(skb)->nr_frags)
  783. #define SKB_FRAG_ASSERT(skb)     BUG_ON(skb_shinfo(skb)->frag_list)
  784. #define SKB_LINEAR_ASSERT(skb)  BUG_ON(skb_is_nonlinear(skb))
  785.  
  786. /*
  787.  *    Add data to an sk_buff
  788.  */
  789. static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len)
  790. {
  791.     unsigned char *tmp = skb->tail;
  792.     SKB_LINEAR_ASSERT(skb);
  793.     skb->tail += len;
  794.     skb->len  += len;
  795.     return tmp;
  796. }
  797.  
  798. /**
  799.  *    skb_put - add data to a buffer
  800.  *    @skb: buffer to use
  801.  *    @len: amount of data to add
  802.  *
  803.  *    This function extends the used data area of the buffer. If this would
  804.  *    exceed the total buffer size the kernel will panic. A pointer to the
  805.  *    first byte of the extra data is returned.
  806.  */
  807. static inline unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
  808. {
  809.     unsigned char *tmp = skb->tail;
  810.     SKB_LINEAR_ASSERT(skb);
  811.     skb->tail += len;
  812.     skb->len  += len;
  813.     if (unlikely(skb->tail>skb->end))
  814.         skb_over_panic(skb, len, current_text_addr());
  815.     return tmp;
  816. }
  817.  
  818. static inline unsigned char *__skb_push(struct sk_buff *skb, unsigned int len)
  819. {
  820.     skb->data -= len;
  821.     skb->len  += len;
  822.     return skb->data;
  823. }
  824.  
  825. /**
  826.  *    skb_push - add data to the start of a buffer
  827.  *    @skb: buffer to use
  828.  *    @len: amount of data to add
  829.  *
  830.  *    This function extends the used data area of the buffer at the buffer
  831.  *    start. If this would exceed the total buffer headroom the kernel will
  832.  *    panic. A pointer to the first byte of the extra data is returned.
  833.  */
  834. static inline unsigned char *skb_push(struct sk_buff *skb, unsigned int len)
  835. {
  836.     skb->data -= len;
  837.     skb->len  += len;
  838.     if (unlikely(skb->data<skb->head))
  839.         skb_under_panic(skb, len, current_text_addr());
  840.     return skb->data;
  841. }
  842.  
  843. static inline unsigned char *__skb_pull(struct sk_buff *skb, unsigned int len)
  844. {
  845.     skb->len -= len;
  846.     BUG_ON(skb->len < skb->data_len);
  847.     return skb->data += len;
  848. }
  849.  
  850. /**
  851.  *    skb_pull - remove data from the start of a buffer
  852.  *    @skb: buffer to use
  853.  *    @len: amount of data to remove
  854.  *
  855.  *    This function removes data from the start of a buffer, returning
  856.  *    the memory to the headroom. A pointer to the next data in the buffer
  857.  *    is returned. Once the data has been pulled future pushes will overwrite
  858.  *    the old data.
  859.  */
  860. static inline unsigned char *skb_pull(struct sk_buff *skb, unsigned int len)
  861. {
  862.     return unlikely(len > skb->len) ? NULL : __skb_pull(skb, len);
  863. }
  864.  
  865. extern unsigned char *__pskb_pull_tail(struct sk_buff *skb, int delta);
  866.  
  867. static inline unsigned char *__pskb_pull(struct sk_buff *skb, unsigned int len)
  868. {
  869.     if (len > skb_headlen(skb) &&
  870.         !__pskb_pull_tail(skb, len-skb_headlen(skb)))
  871.         return NULL;
  872.     skb->len -= len;
  873.     return skb->data += len;
  874. }
  875.  
  876. static inline unsigned char *pskb_pull(struct sk_buff *skb, unsigned int len)
  877. {
  878.     return unlikely(len > skb->len) ? NULL : __pskb_pull(skb, len);
  879. }
  880.  
  881. static inline int pskb_may_pull(struct sk_buff *skb, unsigned int len)
  882. {
  883.     if (likely(len <= skb_headlen(skb)))
  884.         return 1;
  885.     if (unlikely(len > skb->len))
  886.         return 0;
  887.     return __pskb_pull_tail(skb, len-skb_headlen(skb)) != NULL;
  888. }
  889.  
  890. /**
  891.  *    skb_headroom - bytes at buffer head
  892.  *    @skb: buffer to check
  893.  *
  894.  *    Return the number of bytes of free space at the head of an &sk_buff.
  895.  */
  896. static inline int skb_headroom(const struct sk_buff *skb)
  897. {
  898.     return skb->data - skb->head;
  899. }
  900.  
  901. /**
  902.  *    skb_tailroom - bytes at buffer end
  903.  *    @skb: buffer to check
  904.  *
  905.  *    Return the number of bytes of free space at the tail of an sk_buff
  906.  */
  907. static inline int skb_tailroom(const struct sk_buff *skb)
  908. {
  909.     return skb_is_nonlinear(skb) ? 0 : skb->end - skb->tail;
  910. }
  911.  
  912. /**
  913.  *    skb_reserve - adjust headroom
  914.  *    @skb: buffer to alter
  915.  *    @len: bytes to move
  916.  *
  917.  *    Increase the headroom of an empty &sk_buff by reducing the tail
  918.  *    room. This is only allowed for an empty buffer.
  919.  */
  920. static inline void skb_reserve(struct sk_buff *skb, int len)
  921. {
  922.     skb->data += len;
  923.     skb->tail += len;
  924. }
  925.  
  926. /*
  927.  * CPUs often take a performance hit when accessing unaligned memory
  928.  * locations. The actual performance hit varies, it can be small if the
  929.  * hardware handles it or large if we have to take an exception and fix it
  930.  * in software.
  931.  *
  932.  * Since an ethernet header is 14 bytes network drivers often end up with
  933.  * the IP header at an unaligned offset. The IP header can be aligned by
  934.  * shifting the start of the packet by 2 bytes. Drivers should do this
  935.  * with:
  936.  *
  937.  * skb_reserve(NET_IP_ALIGN);
  938.  *
  939.  * The downside to this alignment of the IP header is that the DMA is now
  940.  * unaligned. On some architectures the cost of an unaligned DMA is high
  941.  * and this cost outweighs the gains made by aligning the IP header.
  942.  * 
  943.  * Since this trade off varies between architectures, we allow NET_IP_ALIGN
  944.  * to be overridden.
  945.  */
  946. #ifndef NET_IP_ALIGN
  947. #define NET_IP_ALIGN    2
  948. #endif
  949.  
  950. /*
  951.  * The networking layer reserves some headroom in skb data (via
  952.  * dev_alloc_skb). This is used to avoid having to reallocate skb data when
  953.  * the header has to grow. In the default case, if the header has to grow
  954.  * 16 bytes or less we avoid the reallocation.
  955.  *
  956.  * Unfortunately this headroom changes the DMA alignment of the resulting
  957.  * network packet. As for NET_IP_ALIGN, this unaligned DMA is expensive
  958.  * on some architectures. An architecture can override this value,
  959.  * perhaps setting it to a cacheline in size (since that will maintain
  960.  * cacheline alignment of the DMA). It must be a power of 2.
  961.  *
  962.  * Various parts of the networking layer expect at least 16 bytes of
  963.  * headroom, you should not reduce this.
  964.  */
  965. #ifndef NET_SKB_PAD
  966. #define NET_SKB_PAD    16
  967. #endif
  968.  
  969. extern int ___pskb_trim(struct sk_buff *skb, unsigned int len, int realloc);
  970.  
  971. static inline void __skb_trim(struct sk_buff *skb, unsigned int len)
  972. {
  973.     if (!skb->data_len) {
  974.         skb->len  = len;
  975.         skb->tail = skb->data + len;
  976.     } else
  977.         ___pskb_trim(skb, len, 0);
  978. }
  979.  
  980. /**
  981.  *    skb_trim - remove end from a buffer
  982.  *    @skb: buffer to alter
  983.  *    @len: new length
  984.  *
  985.  *    Cut the length of a buffer down by removing data from the tail. If
  986.  *    the buffer is already under the length specified it is not modified.
  987.  */
  988. static inline void skb_trim(struct sk_buff *skb, unsigned int len)
  989. {
  990.     if (skb->len > len)
  991.         __skb_trim(skb, len);
  992. }
  993.  
  994.  
  995. static inline int __pskb_trim(struct sk_buff *skb, unsigned int len)
  996. {
  997.     if (!skb->data_len) {
  998.         skb->len  = len;
  999.         skb->tail = skb->data+len;
  1000.         return 0;
  1001.     }
  1002.     return ___pskb_trim(skb, len, 1);
  1003. }
  1004.  
  1005. static inline int pskb_trim(struct sk_buff *skb, unsigned int len)
  1006. {
  1007.     return (len < skb->len) ? __pskb_trim(skb, len) : 0;
  1008. }
  1009.  
  1010. /**
  1011.  *    skb_orphan - orphan a buffer
  1012.  *    @skb: buffer to orphan
  1013.  *
  1014.  *    If a buffer currently has an owner then we call the owner's
  1015.  *    destructor function and make the @skb unowned. The buffer continues
  1016.  *    to exist but is no longer charged to its former owner.
  1017.  */
  1018. static inline void skb_orphan(struct sk_buff *skb)
  1019. {
  1020.     if (skb->destructor)
  1021.         skb->destructor(skb);
  1022.     skb->destructor = NULL;
  1023.     skb->sk        = NULL;
  1024. }
  1025.  
  1026. /**
  1027.  *    __skb_queue_purge - empty a list
  1028.  *    @list: list to empty
  1029.  *
  1030.  *    Delete all buffers on an &sk_buff list. Each buffer is removed from
  1031.  *    the list and one reference dropped. This function does not take the
  1032.  *    list lock and the caller must hold the relevant locks to use it.
  1033.  */
  1034. extern void skb_queue_purge(struct sk_buff_head *list);
  1035. static inline void __skb_queue_purge(struct sk_buff_head *list)
  1036. {
  1037.     struct sk_buff *skb;
  1038.     while ((skb = __skb_dequeue(list)) != NULL)
  1039.         kfree_skb(skb);
  1040. }
  1041.  
  1042. #ifndef CONFIG_HAVE_ARCH_DEV_ALLOC_SKB
  1043. /**
  1044.  *    __dev_alloc_skb - allocate an skbuff for sending
  1045.  *    @length: length to allocate
  1046.  *    @gfp_mask: get_free_pages mask, passed to alloc_skb
  1047.  *
  1048.  *    Allocate a new &sk_buff and assign it a usage count of one. The
  1049.  *    buffer has unspecified headroom built in. Users should allocate
  1050.  *    the headroom they think they need without accounting for the
  1051.  *    built in space. The built in space is used for optimisations.
  1052.  *
  1053.  *    %NULL is returned in there is no free memory.
  1054.  */
  1055. static inline struct sk_buff *__dev_alloc_skb(unsigned int length,
  1056.                           gfp_t gfp_mask)
  1057. {
  1058.     struct sk_buff *skb = alloc_skb(length + NET_SKB_PAD, gfp_mask);
  1059.     if (likely(skb))
  1060.         skb_reserve(skb, NET_SKB_PAD);
  1061.     return skb;
  1062. }
  1063. #else
  1064. extern struct sk_buff *__dev_alloc_skb(unsigned int length, int gfp_mask);
  1065. #endif
  1066.  
  1067. /**
  1068.  *    dev_alloc_skb - allocate an skbuff for sending
  1069.  *    @length: length to allocate
  1070.  *
  1071.  *    Allocate a new &sk_buff and assign it a usage count of one. The
  1072.  *    buffer has unspecified headroom built in. Users should allocate
  1073.  *    the headroom they think they need without accounting for the
  1074.  *    built in space. The built in space is used for optimisations.
  1075.  *
  1076.  *    %NULL is returned in there is no free memory. Although this function
  1077.  *    allocates memory it can be called from an interrupt.
  1078.  */
  1079. static inline struct sk_buff *dev_alloc_skb(unsigned int length)
  1080. {
  1081.     return __dev_alloc_skb(length, GFP_ATOMIC);
  1082. }
  1083.  
  1084. /**
  1085.  *    skb_cow - copy header of skb when it is required
  1086.  *    @skb: buffer to cow
  1087.  *    @headroom: needed headroom
  1088.  *
  1089.  *    If the skb passed lacks sufficient headroom or its data part
  1090.  *    is shared, data is reallocated. If reallocation fails, an error
  1091.  *    is returned and original skb is not changed.
  1092.  *
  1093.  *    The result is skb with writable area skb->head...skb->tail
  1094.  *    and at least @headroom of space at head.
  1095.  */
  1096. static inline int skb_cow(struct sk_buff *skb, unsigned int headroom)
  1097. {
  1098.     int delta = (headroom > NET_SKB_PAD ? headroom : NET_SKB_PAD) -
  1099.             skb_headroom(skb);
  1100.  
  1101.     if (delta < 0)
  1102.         delta = 0;
  1103.  
  1104.     if (delta || skb_cloned(skb))
  1105.         return pskb_expand_head(skb, (delta + (NET_SKB_PAD-1)) &
  1106.                 ~(NET_SKB_PAD-1), 0, GFP_ATOMIC);
  1107.     return 0;
  1108. }
  1109.  
  1110. /**
  1111.  *    skb_padto    - pad an skbuff up to a minimal size
  1112.  *    @skb: buffer to pad
  1113.  *    @len: minimal length
  1114.  *
  1115.  *    Pads up a buffer to ensure the trailing bytes exist and are
  1116.  *    blanked. If the buffer already contains sufficient data it
  1117.  *    is untouched. Returns the buffer, which may be a replacement
  1118.  *    for the original, or NULL for out of memory - in which case
  1119.  *    the original buffer is still freed.
  1120.  */
  1121.  
  1122. static inline struct sk_buff *skb_padto(struct sk_buff *skb, unsigned int len)
  1123. {
  1124.     unsigned int size = skb->len;
  1125.     if (likely(size >= len))
  1126.         return skb;
  1127.     return skb_pad(skb, len-size);
  1128. }
  1129.  
  1130. static inline int skb_add_data(struct sk_buff *skb,
  1131.                    char __user *from, int copy)
  1132. {
  1133.     const int off = skb->len;
  1134.  
  1135.     if (skb->ip_summed == CHECKSUM_NONE) {
  1136.         int err = 0;
  1137.         unsigned int csum = csum_and_copy_from_user(from,
  1138.                                 skb_put(skb, copy),
  1139.                                 copy, 0, &err);
  1140.         if (!err) {
  1141.             skb->csum = csum_block_add(skb->csum, csum, off);
  1142.             return 0;
  1143.         }
  1144.     } else if (!copy_from_user(skb_put(skb, copy), from, copy))
  1145.         return 0;
  1146.  
  1147.     __skb_trim(skb, off);
  1148.     return -EFAULT;
  1149. }
  1150.  
  1151. static inline int skb_can_coalesce(struct sk_buff *skb, int i,
  1152.                    struct page *page, int off)
  1153. {
  1154.     if (i) {
  1155.         struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1];
  1156.  
  1157.         return page == frag->page &&
  1158.                off == frag->page_offset + frag->size;
  1159.     }
  1160.     return 0;
  1161. }
  1162.  
  1163. /**
  1164.  *    skb_linearize - convert paged skb to linear one
  1165.  *    @skb: buffer to linarize
  1166.  *    @gfp: allocation mode
  1167.  *
  1168.  *    If there is no free memory -ENOMEM is returned, otherwise zero
  1169.  *    is returned and the old skb data released.
  1170.  */
  1171. extern int __skb_linearize(struct sk_buff *skb, gfp_t gfp);
  1172. static inline int skb_linearize(struct sk_buff *skb, gfp_t gfp)
  1173. {
  1174.     return __skb_linearize(skb, gfp);
  1175. }
  1176.  
  1177. /**
  1178.  *    skb_postpull_rcsum - update checksum for received skb after pull
  1179.  *    @skb: buffer to update
  1180.  *    @start: start of data before pull
  1181.  *    @len: length of data pulled
  1182.  *
  1183.  *    After doing a pull on a received packet, you need to call this to
  1184.  *    update the CHECKSUM_HW checksum, or set ip_summed to CHECKSUM_NONE
  1185.  *    so that it can be recomputed from scratch.
  1186.  */
  1187.  
  1188. static inline void skb_postpull_rcsum(struct sk_buff *skb,
  1189.                       const void *start, unsigned int len)
  1190. {
  1191.     if (skb->ip_summed == CHECKSUM_HW)
  1192.         skb->csum = csum_sub(skb->csum, csum_partial(start, len, 0));
  1193. }
  1194.  
  1195. unsigned char *skb_pull_rcsum(struct sk_buff *skb, unsigned int len);
  1196.  
  1197. /**
  1198.  *    pskb_trim_rcsum - trim received skb and update checksum
  1199.  *    @skb: buffer to trim
  1200.  *    @len: new length
  1201.  *
  1202.  *    This is exactly the same as pskb_trim except that it ensures the
  1203.  *    checksum of received packets are still valid after the operation.
  1204.  */
  1205.  
  1206. static inline int pskb_trim_rcsum(struct sk_buff *skb, unsigned int len)
  1207. {
  1208.     if (likely(len >= skb->len))
  1209.         return 0;
  1210.     if (skb->ip_summed == CHECKSUM_HW)
  1211.         skb->ip_summed = CHECKSUM_NONE;
  1212.     return __pskb_trim(skb, len);
  1213. }
  1214.  
  1215. static inline void *kmap_skb_frag(const skb_frag_t *frag)
  1216. {
  1217. #ifdef CONFIG_HIGHMEM
  1218.     BUG_ON(in_irq());
  1219.  
  1220.     local_bh_disable();
  1221. #endif
  1222.     return kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ);
  1223. }
  1224.  
  1225. static inline void kunmap_skb_frag(void *vaddr)
  1226. {
  1227.     kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
  1228. #ifdef CONFIG_HIGHMEM
  1229.     local_bh_enable();
  1230. #endif
  1231. }
  1232.  
  1233. #define skb_queue_walk(queue, skb) \
  1234.         for (skb = (queue)->next;                    \
  1235.              prefetch(skb->next), (skb != (struct sk_buff *)(queue));    \
  1236.              skb = skb->next)
  1237.  
  1238. #define skb_queue_reverse_walk(queue, skb) \
  1239.         for (skb = (queue)->prev;                    \
  1240.              prefetch(skb->prev), (skb != (struct sk_buff *)(queue));    \
  1241.              skb = skb->prev)
  1242.  
  1243.  
  1244. extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
  1245.                      int noblock, int *err);
  1246. extern unsigned int    datagram_poll(struct file *file, struct socket *sock,
  1247.                      struct poll_table_struct *wait);
  1248. extern int           skb_copy_datagram_iovec(const struct sk_buff *from,
  1249.                            int offset, struct iovec *to,
  1250.                            int size);
  1251. extern int           skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
  1252.                             int hlen,
  1253.                             struct iovec *iov);
  1254. extern void           skb_free_datagram(struct sock *sk, struct sk_buff *skb);
  1255. extern void           skb_kill_datagram(struct sock *sk, struct sk_buff *skb,
  1256.                      unsigned int flags);
  1257. extern unsigned int    skb_checksum(const struct sk_buff *skb, int offset,
  1258.                     int len, unsigned int csum);
  1259. extern int           skb_copy_bits(const struct sk_buff *skb, int offset,
  1260.                      void *to, int len);
  1261. extern int           skb_store_bits(const struct sk_buff *skb, int offset,
  1262.                       void *from, int len);
  1263. extern unsigned int    skb_copy_and_csum_bits(const struct sk_buff *skb,
  1264.                           int offset, u8 *to, int len,
  1265.                           unsigned int csum);
  1266. extern void           skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to);
  1267. extern void           skb_split(struct sk_buff *skb,
  1268.                  struct sk_buff *skb1, const u32 len);
  1269.  
  1270. extern void           skb_release_data(struct sk_buff *skb);
  1271.  
  1272. static inline void *skb_header_pointer(const struct sk_buff *skb, int offset,
  1273.                        int len, void *buffer)
  1274. {
  1275.     int hlen = skb_headlen(skb);
  1276.  
  1277.     if (hlen - offset >= len)
  1278.         return skb->data + offset;
  1279.  
  1280.     if (skb_copy_bits(skb, offset, buffer, len) < 0)
  1281.         return NULL;
  1282.  
  1283.     return buffer;
  1284. }
  1285.  
  1286. extern void skb_init(void);
  1287. extern void skb_add_mtu(int mtu);
  1288.  
  1289. /**
  1290.  *    skb_get_timestamp - get timestamp from a skb
  1291.  *    @skb: skb to get stamp from
  1292.  *    @stamp: pointer to struct timeval to store stamp in
  1293.  *
  1294.  *    Timestamps are stored in the skb as offsets to a base timestamp.
  1295.  *    This function converts the offset back to a struct timeval and stores
  1296.  *    it in stamp.
  1297.  */
  1298. static inline void skb_get_timestamp(const struct sk_buff *skb, struct timeval *stamp)
  1299. {
  1300.     stamp->tv_sec  = skb->tstamp.off_sec;
  1301.     stamp->tv_usec = skb->tstamp.off_usec;
  1302. }
  1303.  
  1304. /**
  1305.  *     skb_set_timestamp - set timestamp of a skb
  1306.  *    @skb: skb to set stamp of
  1307.  *    @stamp: pointer to struct timeval to get stamp from
  1308.  *
  1309.  *    Timestamps are stored in the skb as offsets to a base timestamp.
  1310.  *    This function converts a struct timeval to an offset and stores
  1311.  *    it in the skb.
  1312.  */
  1313. static inline void skb_set_timestamp(struct sk_buff *skb, const struct timeval *stamp)
  1314. {
  1315.     skb->tstamp.off_sec  = stamp->tv_sec;
  1316.     skb->tstamp.off_usec = stamp->tv_usec;
  1317. }
  1318.  
  1319. extern void __net_timestamp(struct sk_buff *skb);
  1320.  
  1321. extern unsigned int __skb_checksum_complete(struct sk_buff *skb);
  1322.  
  1323. /**
  1324.  *    skb_checksum_complete - Calculate checksum of an entire packet
  1325.  *    @skb: packet to process
  1326.  *
  1327.  *    This function calculates the checksum over the entire packet plus
  1328.  *    the value of skb->csum.  The latter can be used to supply the
  1329.  *    checksum of a pseudo header as used by TCP/UDP.  It returns the
  1330.  *    checksum.
  1331.  *
  1332.  *    For protocols that contain complete checksums such as ICMP/TCP/UDP,
  1333.  *    this function can be used to verify that checksum on received
  1334.  *    packets.  In that case the function should return zero if the
  1335.  *    checksum is correct.  In particular, this function will return zero
  1336.  *    if skb->ip_summed is CHECKSUM_UNNECESSARY which indicates that the
  1337.  *    hardware has already verified the correctness of the checksum.
  1338.  */
  1339. static inline unsigned int skb_checksum_complete(struct sk_buff *skb)
  1340. {
  1341.     return skb->ip_summed != CHECKSUM_UNNECESSARY &&
  1342.         __skb_checksum_complete(skb);
  1343. }
  1344.  
  1345. #ifdef CONFIG_NETFILTER
  1346. static inline void nf_conntrack_put(struct nf_conntrack *nfct)
  1347. {
  1348.     if (nfct && atomic_dec_and_test(&nfct->use))
  1349.         nfct->destroy(nfct);
  1350. }
  1351. static inline void nf_conntrack_get(struct nf_conntrack *nfct)
  1352. {
  1353.     if (nfct)
  1354.         atomic_inc(&nfct->use);
  1355. }
  1356. #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  1357. static inline void nf_conntrack_get_reasm(struct sk_buff *skb)
  1358. {
  1359.     if (skb)
  1360.         atomic_inc(&skb->users);
  1361. }
  1362. static inline void nf_conntrack_put_reasm(struct sk_buff *skb)
  1363. {
  1364.     if (skb)
  1365.         kfree_skb(skb);
  1366. }
  1367. #endif
  1368. #ifdef CONFIG_BRIDGE_NETFILTER
  1369. static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
  1370. {
  1371.     if (nf_bridge && atomic_dec_and_test(&nf_bridge->use))
  1372.         kfree(nf_bridge);
  1373. }
  1374. static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
  1375. {
  1376.     if (nf_bridge)
  1377.         atomic_inc(&nf_bridge->use);
  1378. }
  1379. #endif /* CONFIG_BRIDGE_NETFILTER */
  1380. static inline void nf_reset(struct sk_buff *skb)
  1381. {
  1382.     nf_conntrack_put(skb->nfct);
  1383.     skb->nfct = NULL;
  1384. #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  1385.     nf_conntrack_put_reasm(skb->nfct_reasm);
  1386.     skb->nfct_reasm = NULL;
  1387. #endif
  1388. #ifdef CONFIG_BRIDGE_NETFILTER
  1389.     nf_bridge_put(skb->nf_bridge);
  1390.     skb->nf_bridge = NULL;
  1391. #endif
  1392. }
  1393.  
  1394. #else /* CONFIG_NETFILTER */
  1395. static inline void nf_reset(struct sk_buff *skb) {}
  1396. #endif /* CONFIG_NETFILTER */
  1397.  
  1398. #endif    /* __KERNEL__ */
  1399. #endif    /* _LINUX_SKBUFF_H */
  1400.