skbuff.h 35 KB

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