.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
---|
1 | 2 | /* |
---|
2 | 3 | * Definitions for the 'struct sk_buff' memory handlers. |
---|
3 | 4 | * |
---|
4 | 5 | * Authors: |
---|
5 | 6 | * Alan Cox, <gw4pts@gw4pts.ampr.org> |
---|
6 | 7 | * 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 | 8 | */ |
---|
13 | 9 | |
---|
14 | 10 | #ifndef _LINUX_SKBUFF_H |
---|
.. | .. |
---|
18 | 14 | #include <linux/compiler.h> |
---|
19 | 15 | #include <linux/time.h> |
---|
20 | 16 | #include <linux/bug.h> |
---|
| 17 | +#include <linux/bvec.h> |
---|
21 | 18 | #include <linux/cache.h> |
---|
22 | 19 | #include <linux/rbtree.h> |
---|
23 | 20 | #include <linux/socket.h> |
---|
.. | .. |
---|
40 | 37 | #include <linux/in6.h> |
---|
41 | 38 | #include <linux/if_packet.h> |
---|
42 | 39 | #include <net/flow.h> |
---|
| 40 | +#if IS_ENABLED(CONFIG_NF_CONNTRACK) |
---|
| 41 | +#include <linux/netfilter/nf_conntrack_common.h> |
---|
| 42 | +#endif |
---|
| 43 | +#include <linux/android_kabi.h> |
---|
| 44 | +#include <linux/android_vendor.h> |
---|
43 | 45 | |
---|
44 | 46 | /* The interface for checksum offload between the stack and networking drivers |
---|
45 | 47 | * is as follows... |
---|
.. | .. |
---|
47 | 49 | * A. IP checksum related features |
---|
48 | 50 | * |
---|
49 | 51 | * Drivers advertise checksum offload capabilities in the features of a device. |
---|
50 | | - * From the stack's point of view these are capabilities offered by the driver, |
---|
51 | | - * a driver typically only advertises features that it is capable of offloading |
---|
| 52 | + * From the stack's point of view these are capabilities offered by the driver. |
---|
| 53 | + * A driver typically only advertises features that it is capable of offloading |
---|
52 | 54 | * to its device. |
---|
53 | 55 | * |
---|
54 | 56 | * The checksum related features are: |
---|
.. | .. |
---|
63 | 65 | * TCP or UDP packets over IPv4. These are specifically |
---|
64 | 66 | * unencapsulated packets of the form IPv4|TCP or |
---|
65 | 67 | * IPv4|UDP where the Protocol field in the IPv4 header |
---|
66 | | - * is TCP or UDP. The IPv4 header may contain IP options |
---|
| 68 | + * is TCP or UDP. The IPv4 header may contain IP options. |
---|
67 | 69 | * This feature cannot be set in features for a device |
---|
68 | 70 | * with NETIF_F_HW_CSUM also set. This feature is being |
---|
69 | 71 | * DEPRECATED (see below). |
---|
.. | .. |
---|
71 | 73 | * NETIF_F_IPV6_CSUM - Driver (device) is only able to checksum plain |
---|
72 | 74 | * TCP or UDP packets over IPv6. These are specifically |
---|
73 | 75 | * unencapsulated packets of the form IPv6|TCP or |
---|
74 | | - * IPv4|UDP where the Next Header field in the IPv6 |
---|
| 76 | + * IPv6|UDP where the Next Header field in the IPv6 |
---|
75 | 77 | * header is either TCP or UDP. IPv6 extension headers |
---|
76 | 78 | * are not supported with this feature. This feature |
---|
77 | 79 | * cannot be set in features for a device with |
---|
.. | .. |
---|
79 | 81 | * DEPRECATED (see below). |
---|
80 | 82 | * |
---|
81 | 83 | * NETIF_F_RXCSUM - Driver (device) performs receive checksum offload. |
---|
82 | | - * This flag is used only used to disable the RX checksum |
---|
| 84 | + * This flag is only used to disable the RX checksum |
---|
83 | 85 | * feature for a device. The stack will accept receive |
---|
84 | 86 | * checksum indication in packets received on a device |
---|
85 | 87 | * regardless of whether NETIF_F_RXCSUM is set. |
---|
86 | 88 | * |
---|
87 | 89 | * B. Checksumming of received packets by device. Indication of checksum |
---|
88 | | - * verification is in set skb->ip_summed. Possible values are: |
---|
| 90 | + * verification is set in skb->ip_summed. Possible values are: |
---|
89 | 91 | * |
---|
90 | 92 | * CHECKSUM_NONE: |
---|
91 | 93 | * |
---|
.. | .. |
---|
115 | 117 | * the packet minus one that have been verified as CHECKSUM_UNNECESSARY. |
---|
116 | 118 | * For instance if a device receives an IPv6->UDP->GRE->IPv4->TCP packet |
---|
117 | 119 | * and a device is able to verify the checksums for UDP (possibly zero), |
---|
118 | | - * GRE (checksum flag is set), and TCP-- skb->csum_level would be set to |
---|
| 120 | + * GRE (checksum flag is set) and TCP, skb->csum_level would be set to |
---|
119 | 121 | * two. If the device were only able to verify the UDP checksum and not |
---|
120 | | - * GRE, either because it doesn't support GRE checksum of because GRE |
---|
| 122 | + * GRE, either because it doesn't support GRE checksum or because GRE |
---|
121 | 123 | * checksum is bad, skb->csum_level would be set to zero (TCP checksum is |
---|
122 | 124 | * not considered in this case). |
---|
123 | 125 | * |
---|
124 | 126 | * CHECKSUM_COMPLETE: |
---|
125 | 127 | * |
---|
126 | 128 | * This is the most generic way. The device supplied checksum of the _whole_ |
---|
127 | | - * packet as seen by netif_rx() and fills out in skb->csum. Meaning, the |
---|
| 129 | + * packet as seen by netif_rx() and fills in skb->csum. This means the |
---|
128 | 130 | * hardware doesn't need to parse L3/L4 headers to implement this. |
---|
129 | 131 | * |
---|
130 | 132 | * Notes: |
---|
.. | .. |
---|
153 | 155 | * from skb->csum_start up to the end, and to record/write the checksum at |
---|
154 | 156 | * offset skb->csum_start + skb->csum_offset. A driver may verify that the |
---|
155 | 157 | * csum_start and csum_offset values are valid values given the length and |
---|
156 | | - * offset of the packet, however they should not attempt to validate that the |
---|
157 | | - * checksum refers to a legitimate transport layer checksum-- it is the |
---|
| 158 | + * offset of the packet, but it should not attempt to validate that the |
---|
| 159 | + * checksum refers to a legitimate transport layer checksum -- it is the |
---|
158 | 160 | * purview of the stack to validate that csum_start and csum_offset are set |
---|
159 | 161 | * correctly. |
---|
160 | 162 | * |
---|
.. | .. |
---|
178 | 180 | * |
---|
179 | 181 | * CHECKSUM_UNNECESSARY: |
---|
180 | 182 | * |
---|
181 | | - * This has the same meaning on as CHECKSUM_NONE for checksum offload on |
---|
| 183 | + * This has the same meaning as CHECKSUM_NONE for checksum offload on |
---|
182 | 184 | * output. |
---|
183 | 185 | * |
---|
184 | 186 | * CHECKSUM_COMPLETE: |
---|
185 | 187 | * Not used in checksum output. If a driver observes a packet with this value |
---|
186 | | - * set in skbuff, if should treat as CHECKSUM_NONE being set. |
---|
| 188 | + * set in skbuff, it should treat the packet as if CHECKSUM_NONE were set. |
---|
187 | 189 | * |
---|
188 | 190 | * D. Non-IP checksum (CRC) offloads |
---|
189 | 191 | * |
---|
190 | 192 | * NETIF_F_SCTP_CRC - This feature indicates that a device is capable of |
---|
191 | 193 | * offloading the SCTP CRC in a packet. To perform this offload the stack |
---|
192 | | - * will set set csum_start and csum_offset accordingly, set ip_summed to |
---|
| 194 | + * will set csum_start and csum_offset accordingly, set ip_summed to |
---|
193 | 195 | * CHECKSUM_PARTIAL and set csum_not_inet to 1, to provide an indication in |
---|
194 | 196 | * the skbuff that the CHECKSUM_PARTIAL refers to CRC32c. |
---|
195 | 197 | * A driver that supports both IP checksum offload and SCTP CRC32c offload |
---|
.. | .. |
---|
200 | 202 | * NETIF_F_FCOE_CRC - This feature indicates that a device is capable of |
---|
201 | 203 | * offloading the FCOE CRC in a packet. To perform this offload the stack |
---|
202 | 204 | * will set ip_summed to CHECKSUM_PARTIAL and set csum_start and csum_offset |
---|
203 | | - * accordingly. Note the there is no indication in the skbuff that the |
---|
204 | | - * CHECKSUM_PARTIAL refers to an FCOE checksum, a driver that supports |
---|
| 205 | + * accordingly. Note that there is no indication in the skbuff that the |
---|
| 206 | + * CHECKSUM_PARTIAL refers to an FCOE checksum, so a driver that supports |
---|
205 | 207 | * both IP checksum offload and FCOE CRC offload must verify which offload |
---|
206 | | - * is configured for a packet presumably by inspecting packet headers. |
---|
| 208 | + * is configured for a packet, presumably by inspecting packet headers. |
---|
207 | 209 | * |
---|
208 | 210 | * E. Checksumming on output with GSO. |
---|
209 | 211 | * |
---|
.. | .. |
---|
211 | 213 | * is implied by the SKB_GSO_* flags in gso_type. Most obviously, if the |
---|
212 | 214 | * gso_type is SKB_GSO_TCPV4 or SKB_GSO_TCPV6, TCP checksum offload as |
---|
213 | 215 | * part of the GSO operation is implied. If a checksum is being offloaded |
---|
214 | | - * with GSO then ip_summed is CHECKSUM_PARTIAL, csum_start and csum_offset |
---|
215 | | - * are set to refer to the outermost checksum being offload (two offloaded |
---|
216 | | - * checksums are possible with UDP encapsulation). |
---|
| 216 | + * with GSO then ip_summed is CHECKSUM_PARTIAL, and both csum_start and |
---|
| 217 | + * csum_offset are set to refer to the outermost checksum being offloaded |
---|
| 218 | + * (two offloaded checksums are possible with UDP encapsulation). |
---|
217 | 219 | */ |
---|
218 | 220 | |
---|
219 | 221 | /* Don't change this without changing skb_csum_unnecessary! */ |
---|
.. | .. |
---|
238 | 240 | SKB_DATA_ALIGN(sizeof(struct sk_buff)) + \ |
---|
239 | 241 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) |
---|
240 | 242 | |
---|
| 243 | +struct ahash_request; |
---|
241 | 244 | struct net_device; |
---|
242 | 245 | struct scatterlist; |
---|
243 | 246 | struct pipe_inode_info; |
---|
244 | 247 | struct iov_iter; |
---|
245 | 248 | struct napi_struct; |
---|
| 249 | +struct bpf_prog; |
---|
| 250 | +union bpf_attr; |
---|
| 251 | +struct skb_ext; |
---|
246 | 252 | |
---|
247 | | -#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
---|
248 | | -struct nf_conntrack { |
---|
249 | | - atomic_t use; |
---|
250 | | -}; |
---|
251 | | -#endif |
---|
252 | | -#include <linux/android_kabi.h> |
---|
253 | | - |
---|
| 253 | +#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
---|
254 | 254 | struct nf_bridge_info { |
---|
255 | | - refcount_t use; |
---|
256 | 255 | enum { |
---|
257 | 256 | BRNF_PROTO_UNCHANGED, |
---|
258 | 257 | BRNF_PROTO_8021Q, |
---|
.. | .. |
---|
278 | 277 | char neigh_header[8]; |
---|
279 | 278 | }; |
---|
280 | 279 | }; |
---|
| 280 | +#endif |
---|
| 281 | + |
---|
| 282 | +#if IS_ENABLED(CONFIG_NET_TC_SKB_EXT) |
---|
| 283 | +/* Chain in tc_skb_ext will be used to share the tc chain with |
---|
| 284 | + * ovs recirc_id. It will be set to the current chain by tc |
---|
| 285 | + * and read by ovs to recirc_id. |
---|
| 286 | + */ |
---|
| 287 | +struct tc_skb_ext { |
---|
| 288 | + __u32 chain; |
---|
| 289 | + __u16 mru; |
---|
| 290 | +}; |
---|
| 291 | +#endif |
---|
281 | 292 | |
---|
282 | 293 | struct sk_buff_head { |
---|
283 | 294 | /* These two members must be first. */ |
---|
.. | .. |
---|
309 | 320 | */ |
---|
310 | 321 | #define GSO_BY_FRAGS 0xFFFF |
---|
311 | 322 | |
---|
312 | | -typedef struct skb_frag_struct skb_frag_t; |
---|
| 323 | +typedef struct bio_vec skb_frag_t; |
---|
313 | 324 | |
---|
314 | | -struct skb_frag_struct { |
---|
315 | | - struct { |
---|
316 | | - struct page *p; |
---|
317 | | - } page; |
---|
318 | | -#if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536) |
---|
319 | | - __u32 page_offset; |
---|
320 | | - __u32 size; |
---|
321 | | -#else |
---|
322 | | - __u16 page_offset; |
---|
323 | | - __u16 size; |
---|
324 | | -#endif |
---|
325 | | -}; |
---|
326 | | - |
---|
| 325 | +/** |
---|
| 326 | + * skb_frag_size() - Returns the size of a skb fragment |
---|
| 327 | + * @frag: skb fragment |
---|
| 328 | + */ |
---|
327 | 329 | static inline unsigned int skb_frag_size(const skb_frag_t *frag) |
---|
328 | 330 | { |
---|
329 | | - return frag->size; |
---|
| 331 | + return frag->bv_len; |
---|
330 | 332 | } |
---|
331 | 333 | |
---|
| 334 | +/** |
---|
| 335 | + * skb_frag_size_set() - Sets the size of a skb fragment |
---|
| 336 | + * @frag: skb fragment |
---|
| 337 | + * @size: size of fragment |
---|
| 338 | + */ |
---|
332 | 339 | static inline void skb_frag_size_set(skb_frag_t *frag, unsigned int size) |
---|
333 | 340 | { |
---|
334 | | - frag->size = size; |
---|
| 341 | + frag->bv_len = size; |
---|
335 | 342 | } |
---|
336 | 343 | |
---|
| 344 | +/** |
---|
| 345 | + * skb_frag_size_add() - Increments the size of a skb fragment by @delta |
---|
| 346 | + * @frag: skb fragment |
---|
| 347 | + * @delta: value to add |
---|
| 348 | + */ |
---|
337 | 349 | static inline void skb_frag_size_add(skb_frag_t *frag, int delta) |
---|
338 | 350 | { |
---|
339 | | - frag->size += delta; |
---|
| 351 | + frag->bv_len += delta; |
---|
340 | 352 | } |
---|
341 | 353 | |
---|
| 354 | +/** |
---|
| 355 | + * skb_frag_size_sub() - Decrements the size of a skb fragment by @delta |
---|
| 356 | + * @frag: skb fragment |
---|
| 357 | + * @delta: value to subtract |
---|
| 358 | + */ |
---|
342 | 359 | static inline void skb_frag_size_sub(skb_frag_t *frag, int delta) |
---|
343 | 360 | { |
---|
344 | | - frag->size -= delta; |
---|
| 361 | + frag->bv_len -= delta; |
---|
345 | 362 | } |
---|
346 | 363 | |
---|
| 364 | +/** |
---|
| 365 | + * skb_frag_must_loop - Test if %p is a high memory page |
---|
| 366 | + * @p: fragment's page |
---|
| 367 | + */ |
---|
347 | 368 | static inline bool skb_frag_must_loop(struct page *p) |
---|
348 | 369 | { |
---|
349 | 370 | #if defined(CONFIG_HIGHMEM) |
---|
.. | .. |
---|
357 | 378 | * skb_frag_foreach_page - loop over pages in a fragment |
---|
358 | 379 | * |
---|
359 | 380 | * @f: skb frag to operate on |
---|
360 | | - * @f_off: offset from start of f->page.p |
---|
| 381 | + * @f_off: offset from start of f->bv_page |
---|
361 | 382 | * @f_len: length from f_off to loop over |
---|
362 | 383 | * @p: (temp var) current page |
---|
363 | 384 | * @p_off: (temp var) offset from start of current page, |
---|
.. | .. |
---|
478 | 499 | } |
---|
479 | 500 | |
---|
480 | 501 | void sock_zerocopy_put(struct ubuf_info *uarg); |
---|
481 | | -void sock_zerocopy_put_abort(struct ubuf_info *uarg); |
---|
| 502 | +void sock_zerocopy_put_abort(struct ubuf_info *uarg, bool have_uref); |
---|
482 | 503 | |
---|
483 | 504 | void sock_zerocopy_callback(struct ubuf_info *uarg, bool success); |
---|
484 | 505 | |
---|
| 506 | +int skb_zerocopy_iter_dgram(struct sk_buff *skb, struct msghdr *msg, int len); |
---|
485 | 507 | int skb_zerocopy_iter_stream(struct sock *sk, struct sk_buff *skb, |
---|
486 | 508 | struct msghdr *msg, int len, |
---|
487 | 509 | struct ubuf_info *uarg); |
---|
.. | .. |
---|
510 | 532 | /* Intermediate layers must ensure that destructor_arg |
---|
511 | 533 | * remains valid until skb destructor */ |
---|
512 | 534 | void * destructor_arg; |
---|
| 535 | + |
---|
| 536 | + ANDROID_OEM_DATA_ARRAY(1, 3); |
---|
513 | 537 | |
---|
514 | 538 | /* must be last field, see pskb_expand_head() */ |
---|
515 | 539 | skb_frag_t frags[MAX_SKB_FRAGS]; |
---|
.. | .. |
---|
574 | 598 | SKB_GSO_UDP = 1 << 16, |
---|
575 | 599 | |
---|
576 | 600 | SKB_GSO_UDP_L4 = 1 << 17, |
---|
| 601 | + |
---|
| 602 | + SKB_GSO_FRAGLIST = 1 << 18, |
---|
577 | 603 | }; |
---|
578 | 604 | |
---|
579 | 605 | #if BITS_PER_LONG > 32 |
---|
.. | .. |
---|
586 | 612 | typedef unsigned char *sk_buff_data_t; |
---|
587 | 613 | #endif |
---|
588 | 614 | |
---|
589 | | -/** |
---|
| 615 | +/** |
---|
590 | 616 | * struct sk_buff - socket buffer |
---|
591 | 617 | * @next: Next buffer in list |
---|
592 | 618 | * @prev: Previous buffer in list |
---|
593 | 619 | * @tstamp: Time we arrived/left |
---|
| 620 | + * @skb_mstamp_ns: (aka @tstamp) earliest departure time; start point |
---|
| 621 | + * for retransmit timer |
---|
594 | 622 | * @rbnode: RB tree node, alternative to next/prev for netem/tcp |
---|
| 623 | + * @list: queue head |
---|
595 | 624 | * @sk: Socket we are owned by |
---|
| 625 | + * @ip_defrag_offset: (aka @sk) alternate use of @sk, used in |
---|
| 626 | + * fragmentation management |
---|
596 | 627 | * @dev: Device we arrived on/are leaving by |
---|
| 628 | + * @dev_scratch: (aka @dev) alternate use of @dev when @dev would be %NULL |
---|
597 | 629 | * @cb: Control buffer. Free for use by every layer. Put private vars here |
---|
598 | 630 | * @_skb_refdst: destination entry (with norefcount bit) |
---|
599 | 631 | * @sp: the security path, used for xfrm |
---|
.. | .. |
---|
612 | 644 | * @pkt_type: Packet class |
---|
613 | 645 | * @fclone: skbuff clone status |
---|
614 | 646 | * @ipvs_property: skbuff is owned by ipvs |
---|
| 647 | + * @inner_protocol_type: whether the inner protocol is |
---|
| 648 | + * ENCAP_TYPE_ETHER or ENCAP_TYPE_IPPROTO |
---|
| 649 | + * @remcsum_offload: remote checksum offload is enabled |
---|
| 650 | + * @offload_fwd_mark: Packet was L2-forwarded in hardware |
---|
| 651 | + * @offload_l3_fwd_mark: Packet was L3-forwarded in hardware |
---|
615 | 652 | * @tc_skip_classify: do not classify packet. set by IFB device |
---|
616 | 653 | * @tc_at_ingress: used within tc_classify to distinguish in/egress |
---|
617 | | - * @tc_redirected: packet was redirected by a tc action |
---|
618 | | - * @tc_from_ingress: if tc_redirected, tc_at_ingress at time of redirect |
---|
| 654 | + * @redirected: packet was redirected by packet classifier |
---|
| 655 | + * @from_ingress: packet was redirected from the ingress path |
---|
619 | 656 | * @peeked: this packet has been seen already, so stats have been |
---|
620 | 657 | * done for it, don't do them again |
---|
621 | 658 | * @nf_trace: netfilter packet trace flag |
---|
.. | .. |
---|
628 | 665 | * @tc_index: Traffic control index |
---|
629 | 666 | * @hash: the packet hash |
---|
630 | 667 | * @queue_mapping: Queue mapping for multiqueue devices |
---|
631 | | - * @xmit_more: More SKBs are pending for this queue |
---|
| 668 | + * @head_frag: skb was allocated from page fragments, |
---|
| 669 | + * not allocated by kmalloc() or vmalloc(). |
---|
632 | 670 | * @pfmemalloc: skbuff was allocated from PFMEMALLOC reserves |
---|
| 671 | + * @active_extensions: active extensions (skb_ext_id types) |
---|
633 | 672 | * @ndisc_nodetype: router type (from link layer) |
---|
634 | 673 | * @ooo_okay: allow the mapping of a socket to a queue to be changed |
---|
635 | 674 | * @l4_hash: indicate hash is a canonical 4-tuple hash over transport |
---|
.. | .. |
---|
638 | 677 | * @wifi_acked_valid: wifi_acked was set |
---|
639 | 678 | * @wifi_acked: whether frame was acked on wifi or not |
---|
640 | 679 | * @no_fcs: Request NIC to treat last 4 bytes as Ethernet FCS |
---|
| 680 | + * @encapsulation: indicates the inner headers in the skbuff are valid |
---|
| 681 | + * @encap_hdr_csum: software checksum is needed |
---|
| 682 | + * @csum_valid: checksum is already valid |
---|
641 | 683 | * @csum_not_inet: use CRC32c to resolve CHECKSUM_PARTIAL |
---|
| 684 | + * @csum_complete_sw: checksum was completed by software |
---|
| 685 | + * @csum_level: indicates the number of consecutive checksums found in |
---|
| 686 | + * the packet minus one that have been verified as |
---|
| 687 | + * CHECKSUM_UNNECESSARY (max 3) |
---|
| 688 | + * @scm_io_uring: SKB holds io_uring registered files |
---|
642 | 689 | * @dst_pending_confirm: need to confirm neighbour |
---|
643 | 690 | * @decrypted: Decrypted SKB |
---|
644 | | - * @napi_id: id of the NAPI struct this skb came from |
---|
| 691 | + * @napi_id: id of the NAPI struct this skb came from |
---|
| 692 | + * @sender_cpu: (aka @napi_id) source CPU in XPS |
---|
645 | 693 | * @secmark: security marking |
---|
646 | 694 | * @mark: Generic packet mark |
---|
| 695 | + * @reserved_tailroom: (aka @mark) number of bytes of free space available |
---|
| 696 | + * at the tail of an sk_buff |
---|
| 697 | + * @vlan_present: VLAN tag is present |
---|
647 | 698 | * @vlan_proto: vlan encapsulation protocol |
---|
648 | 699 | * @vlan_tci: vlan tag control information |
---|
649 | 700 | * @inner_protocol: Protocol (encapsulation) |
---|
| 701 | + * @inner_ipproto: (aka @inner_protocol) stores ipproto when |
---|
| 702 | + * skb->inner_protocol_type == ENCAP_TYPE_IPPROTO; |
---|
650 | 703 | * @inner_transport_header: Inner transport layer header (encapsulation) |
---|
651 | 704 | * @inner_network_header: Network layer header (encapsulation) |
---|
652 | 705 | * @inner_mac_header: Link layer header (encapsulation) |
---|
.. | .. |
---|
659 | 712 | * @data: Data head pointer |
---|
660 | 713 | * @truesize: Buffer size |
---|
661 | 714 | * @users: User count - see {datagram,tcp}.c |
---|
| 715 | + * @extensions: allocated extensions, valid if active_extensions is nonzero |
---|
662 | 716 | */ |
---|
663 | 717 | |
---|
664 | 718 | struct sk_buff { |
---|
.. | .. |
---|
688 | 742 | |
---|
689 | 743 | union { |
---|
690 | 744 | ktime_t tstamp; |
---|
691 | | - u64 skb_mstamp; |
---|
| 745 | + u64 skb_mstamp_ns; /* earliest departure time */ |
---|
692 | 746 | }; |
---|
693 | 747 | /* |
---|
694 | 748 | * This is the control buffer. It is free to use for every |
---|
.. | .. |
---|
706 | 760 | struct list_head tcp_tsorted_anchor; |
---|
707 | 761 | }; |
---|
708 | 762 | |
---|
709 | | -#ifdef CONFIG_XFRM |
---|
710 | | - struct sec_path *sp; |
---|
711 | | -#endif |
---|
712 | 763 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
---|
713 | 764 | unsigned long _nfct; |
---|
714 | 765 | #endif |
---|
715 | | - struct nf_bridge_info *nf_bridge; |
---|
716 | 766 | unsigned int len, |
---|
717 | 767 | data_len; |
---|
718 | 768 | __u16 mac_len, |
---|
.. | .. |
---|
731 | 781 | #endif |
---|
732 | 782 | #define CLONED_OFFSET() offsetof(struct sk_buff, __cloned_offset) |
---|
733 | 783 | |
---|
| 784 | + /* private: */ |
---|
734 | 785 | __u8 __cloned_offset[0]; |
---|
| 786 | + /* public: */ |
---|
735 | 787 | __u8 cloned:1, |
---|
736 | 788 | nohdr:1, |
---|
737 | 789 | fclone:2, |
---|
738 | 790 | peeked:1, |
---|
739 | 791 | head_frag:1, |
---|
740 | | - xmit_more:1, |
---|
741 | 792 | pfmemalloc:1; |
---|
742 | | - |
---|
| 793 | +#ifdef CONFIG_SKB_EXTENSIONS |
---|
| 794 | + __u8 active_extensions; |
---|
| 795 | +#endif |
---|
743 | 796 | /* fields enclosed in headers_start/headers_end are copied |
---|
744 | 797 | * using a single memcpy() in __copy_skb_header() |
---|
745 | 798 | */ |
---|
.. | .. |
---|
755 | 808 | #endif |
---|
756 | 809 | #define PKT_TYPE_OFFSET() offsetof(struct sk_buff, __pkt_type_offset) |
---|
757 | 810 | |
---|
| 811 | + /* private: */ |
---|
758 | 812 | __u8 __pkt_type_offset[0]; |
---|
| 813 | + /* public: */ |
---|
759 | 814 | __u8 pkt_type:3; |
---|
760 | 815 | __u8 ignore_df:1; |
---|
761 | 816 | __u8 nf_trace:1; |
---|
.. | .. |
---|
772 | 827 | __u8 encap_hdr_csum:1; |
---|
773 | 828 | __u8 csum_valid:1; |
---|
774 | 829 | |
---|
| 830 | +#ifdef __BIG_ENDIAN_BITFIELD |
---|
| 831 | +#define PKT_VLAN_PRESENT_BIT 7 |
---|
| 832 | +#else |
---|
| 833 | +#define PKT_VLAN_PRESENT_BIT 0 |
---|
| 834 | +#endif |
---|
| 835 | +#define PKT_VLAN_PRESENT_OFFSET() offsetof(struct sk_buff, __pkt_vlan_present_offset) |
---|
| 836 | + /* private: */ |
---|
| 837 | + __u8 __pkt_vlan_present_offset[0]; |
---|
| 838 | + /* public: */ |
---|
| 839 | + __u8 vlan_present:1; |
---|
775 | 840 | __u8 csum_complete_sw:1; |
---|
776 | 841 | __u8 csum_level:2; |
---|
777 | 842 | __u8 csum_not_inet:1; |
---|
.. | .. |
---|
779 | 844 | #ifdef CONFIG_IPV6_NDISC_NODETYPE |
---|
780 | 845 | __u8 ndisc_nodetype:2; |
---|
781 | 846 | #endif |
---|
782 | | - __u8 ipvs_property:1; |
---|
783 | 847 | |
---|
| 848 | + __u8 ipvs_property:1; |
---|
784 | 849 | __u8 inner_protocol_type:1; |
---|
785 | 850 | __u8 remcsum_offload:1; |
---|
786 | 851 | #ifdef CONFIG_NET_SWITCHDEV |
---|
787 | 852 | __u8 offload_fwd_mark:1; |
---|
788 | | - __u8 offload_mr_fwd_mark:1; |
---|
| 853 | + __u8 offload_l3_fwd_mark:1; |
---|
789 | 854 | #endif |
---|
790 | 855 | #ifdef CONFIG_NET_CLS_ACT |
---|
791 | 856 | __u8 tc_skip_classify:1; |
---|
792 | 857 | __u8 tc_at_ingress:1; |
---|
793 | | - __u8 tc_redirected:1; |
---|
794 | | - __u8 tc_from_ingress:1; |
---|
| 858 | +#endif |
---|
| 859 | +#ifdef CONFIG_NET_REDIRECT |
---|
| 860 | + __u8 redirected:1; |
---|
| 861 | + __u8 from_ingress:1; |
---|
795 | 862 | #endif |
---|
796 | 863 | #ifdef CONFIG_TLS_DEVICE |
---|
797 | 864 | __u8 decrypted:1; |
---|
.. | .. |
---|
846 | 913 | __u32 headers_end[0]; |
---|
847 | 914 | /* public: */ |
---|
848 | 915 | |
---|
849 | | - ANDROID_KABI_RESERVE(1); |
---|
| 916 | + /* Android KABI preservation. |
---|
| 917 | + * |
---|
| 918 | + * "open coded" version of ANDROID_KABI_USE() to pack more |
---|
| 919 | + * fields/variables into the space that we have. |
---|
| 920 | + * |
---|
| 921 | + * scm_io_uring is from 04df9719df18 ("io_uring/af_unix: defer |
---|
| 922 | + * registered files gc to io_uring release") |
---|
| 923 | + */ |
---|
| 924 | + _ANDROID_KABI_REPLACE(_ANDROID_KABI_RESERVE(1), |
---|
| 925 | + struct { |
---|
| 926 | + __u8 scm_io_uring:1; |
---|
| 927 | + __u8 android_kabi_reserved1_padding1; |
---|
| 928 | + __u16 android_kabi_reserved1_padding2; |
---|
| 929 | + __u32 android_kabi_reserved1_padding3; |
---|
| 930 | + }); |
---|
850 | 931 | ANDROID_KABI_RESERVE(2); |
---|
851 | 932 | |
---|
852 | 933 | /* These elements must be at the end, see alloc_skb() for details. */ |
---|
.. | .. |
---|
856 | 937 | *data; |
---|
857 | 938 | unsigned int truesize; |
---|
858 | 939 | refcount_t users; |
---|
| 940 | + |
---|
| 941 | +#ifdef CONFIG_SKB_EXTENSIONS |
---|
| 942 | + /* only useable after checking ->active_extensions != 0 */ |
---|
| 943 | + struct skb_ext *extensions; |
---|
| 944 | +#endif |
---|
859 | 945 | }; |
---|
860 | 946 | |
---|
861 | 947 | #ifdef __KERNEL__ |
---|
.. | .. |
---|
867 | 953 | #define SKB_ALLOC_RX 0x02 |
---|
868 | 954 | #define SKB_ALLOC_NAPI 0x04 |
---|
869 | 955 | |
---|
870 | | -/* Returns true if the skb was allocated from PFMEMALLOC reserves */ |
---|
| 956 | +/** |
---|
| 957 | + * skb_pfmemalloc - Test if the skb was allocated from PFMEMALLOC reserves |
---|
| 958 | + * @skb: buffer |
---|
| 959 | + */ |
---|
871 | 960 | static inline bool skb_pfmemalloc(const struct sk_buff *skb) |
---|
872 | 961 | { |
---|
873 | 962 | return unlikely(skb->pfmemalloc); |
---|
.. | .. |
---|
880 | 969 | #define SKB_DST_NOREF 1UL |
---|
881 | 970 | #define SKB_DST_PTRMASK ~(SKB_DST_NOREF) |
---|
882 | 971 | |
---|
883 | | -#define SKB_NFCT_PTRMASK ~(7UL) |
---|
884 | 972 | /** |
---|
885 | 973 | * skb_dst - returns skb dst_entry |
---|
886 | 974 | * @skb: buffer |
---|
.. | .. |
---|
889 | 977 | */ |
---|
890 | 978 | static inline struct dst_entry *skb_dst(const struct sk_buff *skb) |
---|
891 | 979 | { |
---|
892 | | - /* If refdst was not refcounted, check we still are in a |
---|
| 980 | + /* If refdst was not refcounted, check we still are in a |
---|
893 | 981 | * rcu_read_lock section |
---|
894 | 982 | */ |
---|
895 | 983 | WARN_ON((skb->_skb_refdst & SKB_DST_NOREF) && |
---|
.. | .. |
---|
936 | 1024 | return (skb->_skb_refdst & SKB_DST_NOREF) && skb_dst(skb); |
---|
937 | 1025 | } |
---|
938 | 1026 | |
---|
| 1027 | +/** |
---|
| 1028 | + * skb_rtable - Returns the skb &rtable |
---|
| 1029 | + * @skb: buffer |
---|
| 1030 | + */ |
---|
939 | 1031 | static inline struct rtable *skb_rtable(const struct sk_buff *skb) |
---|
940 | 1032 | { |
---|
941 | 1033 | return (struct rtable *)skb_dst(skb); |
---|
.. | .. |
---|
950 | 1042 | return ptype <= PACKET_OTHERHOST; |
---|
951 | 1043 | } |
---|
952 | 1044 | |
---|
| 1045 | +/** |
---|
| 1046 | + * skb_napi_id - Returns the skb's NAPI id |
---|
| 1047 | + * @skb: buffer |
---|
| 1048 | + */ |
---|
953 | 1049 | static inline unsigned int skb_napi_id(const struct sk_buff *skb) |
---|
954 | 1050 | { |
---|
955 | 1051 | #ifdef CONFIG_NET_RX_BUSY_POLL |
---|
.. | .. |
---|
959 | 1055 | #endif |
---|
960 | 1056 | } |
---|
961 | 1057 | |
---|
962 | | -/* decrement the reference count and return true if we can free the skb */ |
---|
| 1058 | +/** |
---|
| 1059 | + * skb_unref - decrement the skb's reference count |
---|
| 1060 | + * @skb: buffer |
---|
| 1061 | + * |
---|
| 1062 | + * Returns true if we can free the skb. |
---|
| 1063 | + */ |
---|
963 | 1064 | static inline bool skb_unref(struct sk_buff *skb) |
---|
964 | 1065 | { |
---|
965 | 1066 | if (unlikely(!skb)) |
---|
.. | .. |
---|
975 | 1076 | void skb_release_head_state(struct sk_buff *skb); |
---|
976 | 1077 | void kfree_skb(struct sk_buff *skb); |
---|
977 | 1078 | void kfree_skb_list(struct sk_buff *segs); |
---|
| 1079 | +void skb_dump(const char *level, const struct sk_buff *skb, bool full_pkt); |
---|
978 | 1080 | void skb_tx_error(struct sk_buff *skb); |
---|
| 1081 | + |
---|
| 1082 | +#ifdef CONFIG_TRACEPOINTS |
---|
979 | 1083 | void consume_skb(struct sk_buff *skb); |
---|
| 1084 | +#else |
---|
| 1085 | +static inline void consume_skb(struct sk_buff *skb) |
---|
| 1086 | +{ |
---|
| 1087 | + return kfree_skb(skb); |
---|
| 1088 | +} |
---|
| 1089 | +#endif |
---|
| 1090 | + |
---|
980 | 1091 | void __consume_stateless_skb(struct sk_buff *skb); |
---|
981 | 1092 | void __kfree_skb(struct sk_buff *skb); |
---|
982 | 1093 | extern struct kmem_cache *skbuff_head_cache; |
---|
.. | .. |
---|
989 | 1100 | int node); |
---|
990 | 1101 | struct sk_buff *__build_skb(void *data, unsigned int frag_size); |
---|
991 | 1102 | struct sk_buff *build_skb(void *data, unsigned int frag_size); |
---|
| 1103 | +struct sk_buff *build_skb_around(struct sk_buff *skb, |
---|
| 1104 | + void *data, unsigned int frag_size); |
---|
| 1105 | + |
---|
| 1106 | +/** |
---|
| 1107 | + * alloc_skb - allocate a network buffer |
---|
| 1108 | + * @size: size to allocate |
---|
| 1109 | + * @priority: allocation mask |
---|
| 1110 | + * |
---|
| 1111 | + * This function is a convenient wrapper around __alloc_skb(). |
---|
| 1112 | + */ |
---|
992 | 1113 | static inline struct sk_buff *alloc_skb(unsigned int size, |
---|
993 | 1114 | gfp_t priority) |
---|
994 | 1115 | { |
---|
.. | .. |
---|
1000 | 1121 | int max_page_order, |
---|
1001 | 1122 | int *errcode, |
---|
1002 | 1123 | gfp_t gfp_mask); |
---|
| 1124 | +struct sk_buff *alloc_skb_for_msg(struct sk_buff *first); |
---|
1003 | 1125 | |
---|
1004 | 1126 | /* Layout of fast clones : [skb1][skb2][fclone_ref] */ |
---|
1005 | 1127 | struct sk_buff_fclones { |
---|
.. | .. |
---|
1031 | 1153 | fclones->skb2.sk == sk; |
---|
1032 | 1154 | } |
---|
1033 | 1155 | |
---|
| 1156 | +/** |
---|
| 1157 | + * alloc_skb_fclone - allocate a network buffer from fclone cache |
---|
| 1158 | + * @size: size to allocate |
---|
| 1159 | + * @priority: allocation mask |
---|
| 1160 | + * |
---|
| 1161 | + * This function is a convenient wrapper around __alloc_skb(). |
---|
| 1162 | + */ |
---|
1034 | 1163 | static inline struct sk_buff *alloc_skb_fclone(unsigned int size, |
---|
1035 | 1164 | gfp_t priority) |
---|
1036 | 1165 | { |
---|
.. | .. |
---|
1079 | 1208 | return __skb_pad(skb, pad, true); |
---|
1080 | 1209 | } |
---|
1081 | 1210 | #define dev_kfree_skb(a) consume_skb(a) |
---|
1082 | | - |
---|
1083 | | -int skb_append_datato_frags(struct sock *sk, struct sk_buff *skb, |
---|
1084 | | - int getfrag(void *from, char *to, int offset, |
---|
1085 | | - int len, int odd, struct sk_buff *skb), |
---|
1086 | | - void *from, int length); |
---|
1087 | 1211 | |
---|
1088 | 1212 | int skb_append_pagefrags(struct sk_buff *skb, struct page *page, |
---|
1089 | 1213 | int offset, size_t size); |
---|
.. | .. |
---|
1192 | 1316 | const struct flow_dissector_key *key, |
---|
1193 | 1317 | unsigned int key_count); |
---|
1194 | 1318 | |
---|
1195 | | -bool __skb_flow_dissect(const struct sk_buff *skb, |
---|
| 1319 | +struct bpf_flow_dissector; |
---|
| 1320 | +bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx, |
---|
| 1321 | + __be16 proto, int nhoff, int hlen, unsigned int flags); |
---|
| 1322 | + |
---|
| 1323 | +bool __skb_flow_dissect(const struct net *net, |
---|
| 1324 | + const struct sk_buff *skb, |
---|
1196 | 1325 | struct flow_dissector *flow_dissector, |
---|
1197 | 1326 | void *target_container, |
---|
1198 | 1327 | void *data, __be16 proto, int nhoff, int hlen, |
---|
.. | .. |
---|
1202 | 1331 | struct flow_dissector *flow_dissector, |
---|
1203 | 1332 | void *target_container, unsigned int flags) |
---|
1204 | 1333 | { |
---|
1205 | | - return __skb_flow_dissect(skb, flow_dissector, target_container, |
---|
1206 | | - NULL, 0, 0, 0, flags); |
---|
| 1334 | + return __skb_flow_dissect(NULL, skb, flow_dissector, |
---|
| 1335 | + target_container, NULL, 0, 0, 0, flags); |
---|
1207 | 1336 | } |
---|
1208 | 1337 | |
---|
1209 | 1338 | static inline bool skb_flow_dissect_flow_keys(const struct sk_buff *skb, |
---|
.. | .. |
---|
1211 | 1340 | unsigned int flags) |
---|
1212 | 1341 | { |
---|
1213 | 1342 | memset(flow, 0, sizeof(*flow)); |
---|
1214 | | - return __skb_flow_dissect(skb, &flow_keys_dissector, flow, |
---|
1215 | | - NULL, 0, 0, 0, flags); |
---|
| 1343 | + return __skb_flow_dissect(NULL, skb, &flow_keys_dissector, |
---|
| 1344 | + flow, NULL, 0, 0, 0, flags); |
---|
1216 | 1345 | } |
---|
1217 | 1346 | |
---|
1218 | 1347 | static inline bool |
---|
1219 | | -skb_flow_dissect_flow_keys_basic(const struct sk_buff *skb, |
---|
| 1348 | +skb_flow_dissect_flow_keys_basic(const struct net *net, |
---|
| 1349 | + const struct sk_buff *skb, |
---|
1220 | 1350 | struct flow_keys_basic *flow, void *data, |
---|
1221 | 1351 | __be16 proto, int nhoff, int hlen, |
---|
1222 | 1352 | unsigned int flags) |
---|
1223 | 1353 | { |
---|
1224 | 1354 | memset(flow, 0, sizeof(*flow)); |
---|
1225 | | - return __skb_flow_dissect(skb, &flow_keys_basic_dissector, flow, |
---|
| 1355 | + return __skb_flow_dissect(net, skb, &flow_keys_basic_dissector, flow, |
---|
1226 | 1356 | data, proto, nhoff, hlen, flags); |
---|
1227 | 1357 | } |
---|
1228 | 1358 | |
---|
| 1359 | +void skb_flow_dissect_meta(const struct sk_buff *skb, |
---|
| 1360 | + struct flow_dissector *flow_dissector, |
---|
| 1361 | + void *target_container); |
---|
| 1362 | + |
---|
| 1363 | +/* Gets a skb connection tracking info, ctinfo map should be a |
---|
| 1364 | + * map of mapsize to translate enum ip_conntrack_info states |
---|
| 1365 | + * to user states. |
---|
| 1366 | + */ |
---|
| 1367 | +void |
---|
| 1368 | +skb_flow_dissect_ct(const struct sk_buff *skb, |
---|
| 1369 | + struct flow_dissector *flow_dissector, |
---|
| 1370 | + void *target_container, |
---|
| 1371 | + u16 *ctinfo_map, |
---|
| 1372 | + size_t mapsize); |
---|
1229 | 1373 | void |
---|
1230 | 1374 | skb_flow_dissect_tunnel_info(const struct sk_buff *skb, |
---|
1231 | 1375 | struct flow_dissector *flow_dissector, |
---|
1232 | 1376 | void *target_container); |
---|
| 1377 | + |
---|
| 1378 | +void skb_flow_dissect_hash(const struct sk_buff *skb, |
---|
| 1379 | + struct flow_dissector *flow_dissector, |
---|
| 1380 | + void *target_container); |
---|
1233 | 1381 | |
---|
1234 | 1382 | static inline __u32 skb_get_hash(struct sk_buff *skb) |
---|
1235 | 1383 | { |
---|
.. | .. |
---|
1266 | 1414 | to->l4_hash = from->l4_hash; |
---|
1267 | 1415 | }; |
---|
1268 | 1416 | |
---|
| 1417 | +static inline void skb_copy_decrypted(struct sk_buff *to, |
---|
| 1418 | + const struct sk_buff *from) |
---|
| 1419 | +{ |
---|
| 1420 | +#ifdef CONFIG_TLS_DEVICE |
---|
| 1421 | + to->decrypted = from->decrypted; |
---|
| 1422 | +#endif |
---|
| 1423 | +} |
---|
| 1424 | + |
---|
1269 | 1425 | #ifdef NET_SKBUFF_DATA_USES_OFFSET |
---|
1270 | 1426 | static inline unsigned char *skb_end_pointer(const struct sk_buff *skb) |
---|
1271 | 1427 | { |
---|
.. | .. |
---|
1276 | 1432 | { |
---|
1277 | 1433 | return skb->end; |
---|
1278 | 1434 | } |
---|
| 1435 | + |
---|
| 1436 | +static inline void skb_set_end_offset(struct sk_buff *skb, unsigned int offset) |
---|
| 1437 | +{ |
---|
| 1438 | + skb->end = offset; |
---|
| 1439 | +} |
---|
1279 | 1440 | #else |
---|
1280 | 1441 | static inline unsigned char *skb_end_pointer(const struct sk_buff *skb) |
---|
1281 | 1442 | { |
---|
.. | .. |
---|
1285 | 1446 | static inline unsigned int skb_end_offset(const struct sk_buff *skb) |
---|
1286 | 1447 | { |
---|
1287 | 1448 | return skb->end - skb->head; |
---|
| 1449 | +} |
---|
| 1450 | + |
---|
| 1451 | +static inline void skb_set_end_offset(struct sk_buff *skb, unsigned int offset) |
---|
| 1452 | +{ |
---|
| 1453 | + skb->end = skb->head + offset; |
---|
1288 | 1454 | } |
---|
1289 | 1455 | #endif |
---|
1290 | 1456 | |
---|
.. | .. |
---|
1303 | 1469 | return is_zcopy ? skb_uarg(skb) : NULL; |
---|
1304 | 1470 | } |
---|
1305 | 1471 | |
---|
1306 | | -static inline void skb_zcopy_set(struct sk_buff *skb, struct ubuf_info *uarg) |
---|
| 1472 | +static inline void skb_zcopy_set(struct sk_buff *skb, struct ubuf_info *uarg, |
---|
| 1473 | + bool *have_ref) |
---|
1307 | 1474 | { |
---|
1308 | 1475 | if (skb && uarg && !skb_zcopy(skb)) { |
---|
1309 | | - sock_zerocopy_get(uarg); |
---|
| 1476 | + if (unlikely(have_ref && *have_ref)) |
---|
| 1477 | + *have_ref = false; |
---|
| 1478 | + else |
---|
| 1479 | + sock_zerocopy_get(uarg); |
---|
1310 | 1480 | skb_shinfo(skb)->destructor_arg = uarg; |
---|
1311 | 1481 | skb_shinfo(skb)->tx_flags |= SKBTX_ZEROCOPY_FRAG; |
---|
1312 | 1482 | } |
---|
.. | .. |
---|
1353 | 1523 | struct ubuf_info *uarg = skb_zcopy(skb); |
---|
1354 | 1524 | |
---|
1355 | 1525 | if (uarg) { |
---|
1356 | | - sock_zerocopy_put_abort(uarg); |
---|
| 1526 | + sock_zerocopy_put_abort(uarg, false); |
---|
1357 | 1527 | skb_shinfo(skb)->tx_flags &= ~SKBTX_ZEROCOPY_FRAG; |
---|
1358 | 1528 | } |
---|
1359 | 1529 | } |
---|
.. | .. |
---|
1501 | 1671 | return 0; |
---|
1502 | 1672 | } |
---|
1503 | 1673 | |
---|
| 1674 | +/* This variant of skb_unclone() makes sure skb->truesize |
---|
| 1675 | + * and skb_end_offset() are not changed, whenever a new skb->head is needed. |
---|
| 1676 | + * |
---|
| 1677 | + * Indeed there is no guarantee that ksize(kmalloc(X)) == ksize(kmalloc(X)) |
---|
| 1678 | + * when various debugging features are in place. |
---|
| 1679 | + */ |
---|
| 1680 | +int __skb_unclone_keeptruesize(struct sk_buff *skb, gfp_t pri); |
---|
| 1681 | +static inline int skb_unclone_keeptruesize(struct sk_buff *skb, gfp_t pri) |
---|
| 1682 | +{ |
---|
| 1683 | + might_sleep_if(gfpflags_allow_blocking(pri)); |
---|
| 1684 | + |
---|
| 1685 | + if (skb_cloned(skb)) |
---|
| 1686 | + return __skb_unclone_keeptruesize(skb, pri); |
---|
| 1687 | + return 0; |
---|
| 1688 | +} |
---|
| 1689 | + |
---|
1504 | 1690 | /** |
---|
1505 | 1691 | * skb_header_cloned - is the header a clone |
---|
1506 | 1692 | * @skb: buffer to check |
---|
.. | .. |
---|
1641 | 1827 | } |
---|
1642 | 1828 | |
---|
1643 | 1829 | /** |
---|
| 1830 | + * __skb_peek - peek at the head of a non-empty &sk_buff_head |
---|
| 1831 | + * @list_: list to peek at |
---|
| 1832 | + * |
---|
| 1833 | + * Like skb_peek(), but the caller knows that the list is not empty. |
---|
| 1834 | + */ |
---|
| 1835 | +static inline struct sk_buff *__skb_peek(const struct sk_buff_head *list_) |
---|
| 1836 | +{ |
---|
| 1837 | + return list_->next; |
---|
| 1838 | +} |
---|
| 1839 | + |
---|
| 1840 | +/** |
---|
1644 | 1841 | * skb_peek_next - peek skb following the given one from a queue |
---|
1645 | 1842 | * @skb: skb to start from |
---|
1646 | 1843 | * @list_: list to peek at |
---|
.. | .. |
---|
1748 | 1945 | * The "__skb_xxxx()" functions are the non-atomic ones that |
---|
1749 | 1946 | * can only be called with interrupts disabled. |
---|
1750 | 1947 | */ |
---|
1751 | | -void skb_insert(struct sk_buff *old, struct sk_buff *newsk, |
---|
1752 | | - struct sk_buff_head *list); |
---|
1753 | 1948 | static inline void __skb_insert(struct sk_buff *newsk, |
---|
1754 | 1949 | struct sk_buff *prev, struct sk_buff *next, |
---|
1755 | 1950 | struct sk_buff_head *list) |
---|
.. | .. |
---|
1879 | 2074 | * |
---|
1880 | 2075 | * A buffer cannot be placed on two lists at the same time. |
---|
1881 | 2076 | */ |
---|
1882 | | -void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk); |
---|
1883 | 2077 | static inline void __skb_queue_head(struct sk_buff_head *list, |
---|
1884 | 2078 | struct sk_buff *newsk) |
---|
1885 | 2079 | { |
---|
1886 | 2080 | __skb_queue_after(list, (struct sk_buff *)list, newsk); |
---|
1887 | 2081 | } |
---|
| 2082 | +void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk); |
---|
1888 | 2083 | |
---|
1889 | 2084 | /** |
---|
1890 | 2085 | * __skb_queue_tail - queue a buffer at the list tail |
---|
.. | .. |
---|
1896 | 2091 | * |
---|
1897 | 2092 | * A buffer cannot be placed on two lists at the same time. |
---|
1898 | 2093 | */ |
---|
1899 | | -void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk); |
---|
1900 | 2094 | static inline void __skb_queue_tail(struct sk_buff_head *list, |
---|
1901 | 2095 | struct sk_buff *newsk) |
---|
1902 | 2096 | { |
---|
1903 | 2097 | __skb_queue_before(list, (struct sk_buff *)list, newsk); |
---|
1904 | 2098 | } |
---|
| 2099 | +void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk); |
---|
1905 | 2100 | |
---|
1906 | 2101 | /* |
---|
1907 | 2102 | * remove sk_buff from list. _Must_ be called atomically, and with |
---|
.. | .. |
---|
1928 | 2123 | * so must be used with appropriate locks held only. The head item is |
---|
1929 | 2124 | * returned or %NULL if the list is empty. |
---|
1930 | 2125 | */ |
---|
1931 | | -struct sk_buff *skb_dequeue(struct sk_buff_head *list); |
---|
1932 | 2126 | static inline struct sk_buff *__skb_dequeue(struct sk_buff_head *list) |
---|
1933 | 2127 | { |
---|
1934 | 2128 | struct sk_buff *skb = skb_peek(list); |
---|
.. | .. |
---|
1936 | 2130 | __skb_unlink(skb, list); |
---|
1937 | 2131 | return skb; |
---|
1938 | 2132 | } |
---|
| 2133 | +struct sk_buff *skb_dequeue(struct sk_buff_head *list); |
---|
1939 | 2134 | |
---|
1940 | 2135 | /** |
---|
1941 | 2136 | * __skb_dequeue_tail - remove from the tail of the queue |
---|
.. | .. |
---|
1945 | 2140 | * so must be used with appropriate locks held only. The tail item is |
---|
1946 | 2141 | * returned or %NULL if the list is empty. |
---|
1947 | 2142 | */ |
---|
1948 | | -struct sk_buff *skb_dequeue_tail(struct sk_buff_head *list); |
---|
1949 | 2143 | static inline struct sk_buff *__skb_dequeue_tail(struct sk_buff_head *list) |
---|
1950 | 2144 | { |
---|
1951 | 2145 | struct sk_buff *skb = skb_peek_tail(list); |
---|
.. | .. |
---|
1953 | 2147 | __skb_unlink(skb, list); |
---|
1954 | 2148 | return skb; |
---|
1955 | 2149 | } |
---|
| 2150 | +struct sk_buff *skb_dequeue_tail(struct sk_buff_head *list); |
---|
1956 | 2151 | |
---|
1957 | 2152 | |
---|
1958 | 2153 | static inline bool skb_is_nonlinear(const struct sk_buff *skb) |
---|
.. | .. |
---|
2002 | 2197 | * that not all callers have unique ownership of the page but rely |
---|
2003 | 2198 | * on page_is_pfmemalloc doing the right thing(tm). |
---|
2004 | 2199 | */ |
---|
2005 | | - frag->page.p = page; |
---|
2006 | | - frag->page_offset = off; |
---|
| 2200 | + frag->bv_page = page; |
---|
| 2201 | + frag->bv_offset = off; |
---|
2007 | 2202 | skb_frag_size_set(frag, size); |
---|
2008 | 2203 | |
---|
2009 | 2204 | page = compound_head(page); |
---|
.. | .. |
---|
2038 | 2233 | void skb_coalesce_rx_frag(struct sk_buff *skb, int i, int size, |
---|
2039 | 2234 | unsigned int truesize); |
---|
2040 | 2235 | |
---|
2041 | | -#define SKB_PAGE_ASSERT(skb) BUG_ON(skb_shinfo(skb)->nr_frags) |
---|
2042 | | -#define SKB_FRAG_ASSERT(skb) BUG_ON(skb_has_frag_list(skb)) |
---|
2043 | 2236 | #define SKB_LINEAR_ASSERT(skb) BUG_ON(skb_is_nonlinear(skb)) |
---|
2044 | 2237 | |
---|
2045 | 2238 | #ifdef NET_SKBUFF_DATA_USES_OFFSET |
---|
.. | .. |
---|
2076 | 2269 | } |
---|
2077 | 2270 | |
---|
2078 | 2271 | #endif /* NET_SKBUFF_DATA_USES_OFFSET */ |
---|
| 2272 | + |
---|
| 2273 | +static inline void skb_assert_len(struct sk_buff *skb) |
---|
| 2274 | +{ |
---|
| 2275 | +#ifdef CONFIG_DEBUG_NET |
---|
| 2276 | + if (WARN_ONCE(!skb->len, "%s\n", __func__)) |
---|
| 2277 | + DO_ONCE_LITE(skb_dump, KERN_ERR, skb, false); |
---|
| 2278 | +#endif /* CONFIG_DEBUG_NET */ |
---|
| 2279 | +} |
---|
2079 | 2280 | |
---|
2080 | 2281 | /* |
---|
2081 | 2282 | * Add data to an sk_buff |
---|
.. | .. |
---|
2174 | 2375 | return unlikely(len > skb->len) ? NULL : __pskb_pull(skb, len); |
---|
2175 | 2376 | } |
---|
2176 | 2377 | |
---|
2177 | | -static inline int pskb_may_pull(struct sk_buff *skb, unsigned int len) |
---|
| 2378 | +static inline bool pskb_may_pull(struct sk_buff *skb, unsigned int len) |
---|
2178 | 2379 | { |
---|
2179 | 2380 | if (likely(len <= skb_headlen(skb))) |
---|
2180 | | - return 1; |
---|
| 2381 | + return true; |
---|
2181 | 2382 | if (unlikely(len > skb->len)) |
---|
2182 | | - return 0; |
---|
| 2383 | + return false; |
---|
2183 | 2384 | return __pskb_pull_tail(skb, len - skb_headlen(skb)) != NULL; |
---|
2184 | 2385 | } |
---|
2185 | 2386 | |
---|
.. | .. |
---|
2403 | 2604 | return skb->mac_header != (typeof(skb->mac_header))~0U; |
---|
2404 | 2605 | } |
---|
2405 | 2606 | |
---|
| 2607 | +static inline void skb_unset_mac_header(struct sk_buff *skb) |
---|
| 2608 | +{ |
---|
| 2609 | + skb->mac_header = (typeof(skb->mac_header))~0U; |
---|
| 2610 | +} |
---|
| 2611 | + |
---|
2406 | 2612 | static inline void skb_reset_mac_header(struct sk_buff *skb) |
---|
2407 | 2613 | { |
---|
2408 | 2614 | skb->mac_header = skb->data - skb->head; |
---|
.. | .. |
---|
2419 | 2625 | skb->mac_header = skb->network_header; |
---|
2420 | 2626 | } |
---|
2421 | 2627 | |
---|
2422 | | -static inline void skb_probe_transport_header(struct sk_buff *skb, |
---|
2423 | | - const int offset_hint) |
---|
| 2628 | +static inline void skb_probe_transport_header(struct sk_buff *skb) |
---|
2424 | 2629 | { |
---|
2425 | 2630 | struct flow_keys_basic keys; |
---|
2426 | 2631 | |
---|
2427 | 2632 | if (skb_transport_header_was_set(skb)) |
---|
2428 | 2633 | return; |
---|
2429 | 2634 | |
---|
2430 | | - if (skb_flow_dissect_flow_keys_basic(skb, &keys, NULL, 0, 0, 0, 0)) |
---|
| 2635 | + if (skb_flow_dissect_flow_keys_basic(NULL, skb, &keys, |
---|
| 2636 | + NULL, 0, 0, 0, 0)) |
---|
2431 | 2637 | skb_set_transport_header(skb, keys.control.thoff); |
---|
2432 | | - else if (offset_hint >= 0) |
---|
2433 | | - skb_set_transport_header(skb, offset_hint); |
---|
2434 | 2638 | } |
---|
2435 | 2639 | |
---|
2436 | 2640 | static inline void skb_mac_header_rebuild(struct sk_buff *skb) |
---|
.. | .. |
---|
2524 | 2728 | * |
---|
2525 | 2729 | * Using max(32, L1_CACHE_BYTES) makes sense (especially with RPS) |
---|
2526 | 2730 | * to reduce average number of cache lines per packet. |
---|
2527 | | - * get_rps_cpus() for example only access one 64 bytes aligned block : |
---|
| 2731 | + * get_rps_cpu() for example only access one 64 bytes aligned block : |
---|
2528 | 2732 | * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8) |
---|
2529 | 2733 | */ |
---|
2530 | 2734 | #ifndef NET_SKB_PAD |
---|
.. | .. |
---|
2535 | 2739 | |
---|
2536 | 2740 | static inline void __skb_set_length(struct sk_buff *skb, unsigned int len) |
---|
2537 | 2741 | { |
---|
2538 | | - if (unlikely(skb_is_nonlinear(skb))) { |
---|
2539 | | - WARN_ON(1); |
---|
| 2742 | + if (WARN_ON(skb_is_nonlinear(skb))) |
---|
2540 | 2743 | return; |
---|
2541 | | - } |
---|
2542 | 2744 | skb->len = len; |
---|
2543 | 2745 | skb_set_tail_pointer(skb, len); |
---|
2544 | 2746 | } |
---|
.. | .. |
---|
2646 | 2848 | * the list and one reference dropped. This function does not take the |
---|
2647 | 2849 | * list lock and the caller must hold the relevant locks to use it. |
---|
2648 | 2850 | */ |
---|
2649 | | -void skb_queue_purge(struct sk_buff_head *list); |
---|
2650 | 2851 | static inline void __skb_queue_purge(struct sk_buff_head *list) |
---|
2651 | 2852 | { |
---|
2652 | 2853 | struct sk_buff *skb; |
---|
2653 | 2854 | while ((skb = __skb_dequeue(list)) != NULL) |
---|
2654 | 2855 | kfree_skb(skb); |
---|
2655 | 2856 | } |
---|
| 2857 | +void skb_queue_purge(struct sk_buff_head *list); |
---|
2656 | 2858 | |
---|
2657 | 2859 | unsigned int skb_rbtree_purge(struct rb_root *root); |
---|
2658 | 2860 | |
---|
.. | .. |
---|
2794 | 2996 | */ |
---|
2795 | 2997 | static inline unsigned int skb_frag_off(const skb_frag_t *frag) |
---|
2796 | 2998 | { |
---|
2797 | | - return frag->page_offset; |
---|
| 2999 | + return frag->bv_offset; |
---|
| 3000 | +} |
---|
| 3001 | + |
---|
| 3002 | +/** |
---|
| 3003 | + * skb_frag_off_add() - Increments the offset of a skb fragment by @delta |
---|
| 3004 | + * @frag: skb fragment |
---|
| 3005 | + * @delta: value to add |
---|
| 3006 | + */ |
---|
| 3007 | +static inline void skb_frag_off_add(skb_frag_t *frag, int delta) |
---|
| 3008 | +{ |
---|
| 3009 | + frag->bv_offset += delta; |
---|
| 3010 | +} |
---|
| 3011 | + |
---|
| 3012 | +/** |
---|
| 3013 | + * skb_frag_off_set() - Sets the offset of a skb fragment |
---|
| 3014 | + * @frag: skb fragment |
---|
| 3015 | + * @offset: offset of fragment |
---|
| 3016 | + */ |
---|
| 3017 | +static inline void skb_frag_off_set(skb_frag_t *frag, unsigned int offset) |
---|
| 3018 | +{ |
---|
| 3019 | + frag->bv_offset = offset; |
---|
| 3020 | +} |
---|
| 3021 | + |
---|
| 3022 | +/** |
---|
| 3023 | + * skb_frag_off_copy() - Sets the offset of a skb fragment from another fragment |
---|
| 3024 | + * @fragto: skb fragment where offset is set |
---|
| 3025 | + * @fragfrom: skb fragment offset is copied from |
---|
| 3026 | + */ |
---|
| 3027 | +static inline void skb_frag_off_copy(skb_frag_t *fragto, |
---|
| 3028 | + const skb_frag_t *fragfrom) |
---|
| 3029 | +{ |
---|
| 3030 | + fragto->bv_offset = fragfrom->bv_offset; |
---|
2798 | 3031 | } |
---|
2799 | 3032 | |
---|
2800 | 3033 | /** |
---|
.. | .. |
---|
2805 | 3038 | */ |
---|
2806 | 3039 | static inline struct page *skb_frag_page(const skb_frag_t *frag) |
---|
2807 | 3040 | { |
---|
2808 | | - return frag->page.p; |
---|
| 3041 | + return frag->bv_page; |
---|
2809 | 3042 | } |
---|
2810 | 3043 | |
---|
2811 | 3044 | /** |
---|
.. | .. |
---|
2863 | 3096 | */ |
---|
2864 | 3097 | static inline void *skb_frag_address(const skb_frag_t *frag) |
---|
2865 | 3098 | { |
---|
2866 | | - return page_address(skb_frag_page(frag)) + frag->page_offset; |
---|
| 3099 | + return page_address(skb_frag_page(frag)) + skb_frag_off(frag); |
---|
2867 | 3100 | } |
---|
2868 | 3101 | |
---|
2869 | 3102 | /** |
---|
.. | .. |
---|
2879 | 3112 | if (unlikely(!ptr)) |
---|
2880 | 3113 | return NULL; |
---|
2881 | 3114 | |
---|
2882 | | - return ptr + frag->page_offset; |
---|
| 3115 | + return ptr + skb_frag_off(frag); |
---|
| 3116 | +} |
---|
| 3117 | + |
---|
| 3118 | +/** |
---|
| 3119 | + * skb_frag_page_copy() - sets the page in a fragment from another fragment |
---|
| 3120 | + * @fragto: skb fragment where page is set |
---|
| 3121 | + * @fragfrom: skb fragment page is copied from |
---|
| 3122 | + */ |
---|
| 3123 | +static inline void skb_frag_page_copy(skb_frag_t *fragto, |
---|
| 3124 | + const skb_frag_t *fragfrom) |
---|
| 3125 | +{ |
---|
| 3126 | + fragto->bv_page = fragfrom->bv_page; |
---|
2883 | 3127 | } |
---|
2884 | 3128 | |
---|
2885 | 3129 | /** |
---|
.. | .. |
---|
2891 | 3135 | */ |
---|
2892 | 3136 | static inline void __skb_frag_set_page(skb_frag_t *frag, struct page *page) |
---|
2893 | 3137 | { |
---|
2894 | | - frag->page.p = page; |
---|
| 3138 | + frag->bv_page = page; |
---|
2895 | 3139 | } |
---|
2896 | 3140 | |
---|
2897 | 3141 | /** |
---|
.. | .. |
---|
2927 | 3171 | enum dma_data_direction dir) |
---|
2928 | 3172 | { |
---|
2929 | 3173 | return dma_map_page(dev, skb_frag_page(frag), |
---|
2930 | | - frag->page_offset + offset, size, dir); |
---|
| 3174 | + skb_frag_off(frag) + offset, size, dir); |
---|
2931 | 3175 | } |
---|
2932 | 3176 | |
---|
2933 | 3177 | static inline struct sk_buff *pskb_copy(struct sk_buff *skb, |
---|
.. | .. |
---|
3030 | 3274 | } |
---|
3031 | 3275 | |
---|
3032 | 3276 | /** |
---|
3033 | | - * skb_put_padto - increase size and pad an skbuff up to a minimal size |
---|
| 3277 | + * __skb_put_padto - increase size and pad an skbuff up to a minimal size |
---|
3034 | 3278 | * @skb: buffer to pad |
---|
3035 | 3279 | * @len: minimal length |
---|
3036 | 3280 | * @free_on_error: free buffer on error |
---|
.. | .. |
---|
3095 | 3339 | if (skb_zcopy(skb)) |
---|
3096 | 3340 | return false; |
---|
3097 | 3341 | if (i) { |
---|
3098 | | - const struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1]; |
---|
| 3342 | + const skb_frag_t *frag = &skb_shinfo(skb)->frags[i - 1]; |
---|
3099 | 3343 | |
---|
3100 | 3344 | return page == skb_frag_page(frag) && |
---|
3101 | | - off == frag->page_offset + skb_frag_size(frag); |
---|
| 3345 | + off == skb_frag_off(frag) + skb_frag_size(frag); |
---|
3102 | 3346 | } |
---|
3103 | 3347 | return false; |
---|
3104 | 3348 | } |
---|
.. | .. |
---|
3317 | 3561 | for (iter = skb_shinfo(skb)->frag_list; iter; iter = iter->next) |
---|
3318 | 3562 | |
---|
3319 | 3563 | |
---|
3320 | | -int __skb_wait_for_more_packets(struct sock *sk, int *err, long *timeo_p, |
---|
| 3564 | +int __skb_wait_for_more_packets(struct sock *sk, struct sk_buff_head *queue, |
---|
| 3565 | + int *err, long *timeo_p, |
---|
3321 | 3566 | const struct sk_buff *skb); |
---|
3322 | 3567 | struct sk_buff *__skb_try_recv_from_queue(struct sock *sk, |
---|
3323 | 3568 | struct sk_buff_head *queue, |
---|
3324 | 3569 | unsigned int flags, |
---|
3325 | | - void (*destructor)(struct sock *sk, |
---|
3326 | | - struct sk_buff *skb), |
---|
3327 | | - int *peeked, int *off, int *err, |
---|
| 3570 | + int *off, int *err, |
---|
3328 | 3571 | struct sk_buff **last); |
---|
3329 | | -struct sk_buff *__skb_try_recv_datagram(struct sock *sk, unsigned flags, |
---|
3330 | | - void (*destructor)(struct sock *sk, |
---|
3331 | | - struct sk_buff *skb), |
---|
3332 | | - int *peeked, int *off, int *err, |
---|
| 3572 | +struct sk_buff *__skb_try_recv_datagram(struct sock *sk, |
---|
| 3573 | + struct sk_buff_head *queue, |
---|
| 3574 | + unsigned int flags, int *off, int *err, |
---|
3333 | 3575 | struct sk_buff **last); |
---|
3334 | | -struct sk_buff *__skb_recv_datagram(struct sock *sk, unsigned flags, |
---|
3335 | | - void (*destructor)(struct sock *sk, |
---|
3336 | | - struct sk_buff *skb), |
---|
3337 | | - int *peeked, int *off, int *err); |
---|
| 3576 | +struct sk_buff *__skb_recv_datagram(struct sock *sk, |
---|
| 3577 | + struct sk_buff_head *sk_queue, |
---|
| 3578 | + unsigned int flags, int *off, int *err); |
---|
3338 | 3579 | struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock, |
---|
3339 | 3580 | int *err); |
---|
3340 | 3581 | __poll_t datagram_poll(struct file *file, struct socket *sock, |
---|
.. | .. |
---|
3348 | 3589 | } |
---|
3349 | 3590 | int skb_copy_and_csum_datagram_msg(struct sk_buff *skb, int hlen, |
---|
3350 | 3591 | struct msghdr *msg); |
---|
| 3592 | +int skb_copy_and_hash_datagram_iter(const struct sk_buff *skb, int offset, |
---|
| 3593 | + struct iov_iter *to, int len, |
---|
| 3594 | + struct ahash_request *hash); |
---|
3351 | 3595 | int skb_copy_datagram_from_iter(struct sk_buff *skb, int offset, |
---|
3352 | 3596 | struct iov_iter *from, int len); |
---|
3353 | 3597 | int zerocopy_sg_from_iter(struct sk_buff *skb, struct iov_iter *frm); |
---|
.. | .. |
---|
3362 | 3606 | int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len); |
---|
3363 | 3607 | int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len); |
---|
3364 | 3608 | __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, u8 *to, |
---|
3365 | | - int len, __wsum csum); |
---|
| 3609 | + int len); |
---|
3366 | 3610 | int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset, |
---|
3367 | 3611 | struct pipe_inode_info *pipe, unsigned int len, |
---|
3368 | 3612 | unsigned int flags); |
---|
3369 | 3613 | int skb_send_sock_locked(struct sock *sk, struct sk_buff *skb, int offset, |
---|
3370 | 3614 | int len); |
---|
3371 | | -int skb_send_sock(struct sock *sk, struct sk_buff *skb, int offset, int len); |
---|
3372 | 3615 | void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to); |
---|
3373 | 3616 | unsigned int skb_zerocopy_headlen(const struct sk_buff *from); |
---|
3374 | 3617 | int skb_zerocopy(struct sk_buff *to, struct sk_buff *from, |
---|
.. | .. |
---|
3379 | 3622 | bool skb_gso_validate_network_len(const struct sk_buff *skb, unsigned int mtu); |
---|
3380 | 3623 | bool skb_gso_validate_mac_len(const struct sk_buff *skb, unsigned int len); |
---|
3381 | 3624 | struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features); |
---|
| 3625 | +struct sk_buff *skb_segment_list(struct sk_buff *skb, netdev_features_t features, |
---|
| 3626 | + unsigned int offset); |
---|
3382 | 3627 | struct sk_buff *skb_vlan_untag(struct sk_buff *skb); |
---|
3383 | 3628 | int skb_ensure_writable(struct sk_buff *skb, int write_len); |
---|
3384 | 3629 | int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci); |
---|
3385 | 3630 | int skb_vlan_pop(struct sk_buff *skb); |
---|
3386 | 3631 | int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci); |
---|
| 3632 | +int skb_eth_pop(struct sk_buff *skb); |
---|
| 3633 | +int skb_eth_push(struct sk_buff *skb, const unsigned char *dst, |
---|
| 3634 | + const unsigned char *src); |
---|
| 3635 | +int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto, |
---|
| 3636 | + int mac_len, bool ethernet); |
---|
| 3637 | +int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len, |
---|
| 3638 | + bool ethernet); |
---|
| 3639 | +int skb_mpls_update_lse(struct sk_buff *skb, __be32 mpls_lse); |
---|
| 3640 | +int skb_mpls_dec_ttl(struct sk_buff *skb); |
---|
3387 | 3641 | struct sk_buff *pskb_extract(struct sk_buff *skb, int off, int to_copy, |
---|
3388 | 3642 | gfp_t gfp); |
---|
3389 | 3643 | |
---|
.. | .. |
---|
3487 | 3741 | /** |
---|
3488 | 3742 | * skb_get_timestamp - get timestamp from a skb |
---|
3489 | 3743 | * @skb: skb to get stamp from |
---|
3490 | | - * @stamp: pointer to struct timeval to store stamp in |
---|
| 3744 | + * @stamp: pointer to struct __kernel_old_timeval to store stamp in |
---|
3491 | 3745 | * |
---|
3492 | 3746 | * Timestamps are stored in the skb as offsets to a base timestamp. |
---|
3493 | 3747 | * This function converts the offset back to a struct timeval and stores |
---|
3494 | 3748 | * it in stamp. |
---|
3495 | 3749 | */ |
---|
3496 | 3750 | static inline void skb_get_timestamp(const struct sk_buff *skb, |
---|
3497 | | - struct timeval *stamp) |
---|
| 3751 | + struct __kernel_old_timeval *stamp) |
---|
3498 | 3752 | { |
---|
3499 | | - *stamp = ktime_to_timeval(skb->tstamp); |
---|
| 3753 | + *stamp = ns_to_kernel_old_timeval(skb->tstamp); |
---|
| 3754 | +} |
---|
| 3755 | + |
---|
| 3756 | +static inline void skb_get_new_timestamp(const struct sk_buff *skb, |
---|
| 3757 | + struct __kernel_sock_timeval *stamp) |
---|
| 3758 | +{ |
---|
| 3759 | + struct timespec64 ts = ktime_to_timespec64(skb->tstamp); |
---|
| 3760 | + |
---|
| 3761 | + stamp->tv_sec = ts.tv_sec; |
---|
| 3762 | + stamp->tv_usec = ts.tv_nsec / 1000; |
---|
3500 | 3763 | } |
---|
3501 | 3764 | |
---|
3502 | 3765 | static inline void skb_get_timestampns(const struct sk_buff *skb, |
---|
3503 | | - struct timespec *stamp) |
---|
| 3766 | + struct __kernel_old_timespec *stamp) |
---|
3504 | 3767 | { |
---|
3505 | | - *stamp = ktime_to_timespec(skb->tstamp); |
---|
| 3768 | + struct timespec64 ts = ktime_to_timespec64(skb->tstamp); |
---|
| 3769 | + |
---|
| 3770 | + stamp->tv_sec = ts.tv_sec; |
---|
| 3771 | + stamp->tv_nsec = ts.tv_nsec; |
---|
| 3772 | +} |
---|
| 3773 | + |
---|
| 3774 | +static inline void skb_get_new_timestampns(const struct sk_buff *skb, |
---|
| 3775 | + struct __kernel_timespec *stamp) |
---|
| 3776 | +{ |
---|
| 3777 | + struct timespec64 ts = ktime_to_timespec64(skb->tstamp); |
---|
| 3778 | + |
---|
| 3779 | + stamp->tv_sec = ts.tv_sec; |
---|
| 3780 | + stamp->tv_nsec = ts.tv_nsec; |
---|
3506 | 3781 | } |
---|
3507 | 3782 | |
---|
3508 | 3783 | static inline void __net_timestamp(struct sk_buff *skb) |
---|
.. | .. |
---|
3544 | 3819 | #define __it(x, op) (x -= sizeof(u##op)) |
---|
3545 | 3820 | #define __it_diff(a, b, op) (*(u##op *)__it(a, op)) ^ (*(u##op *)__it(b, op)) |
---|
3546 | 3821 | case 32: diffs |= __it_diff(a, b, 64); |
---|
| 3822 | + fallthrough; |
---|
3547 | 3823 | case 24: diffs |= __it_diff(a, b, 64); |
---|
| 3824 | + fallthrough; |
---|
3548 | 3825 | case 16: diffs |= __it_diff(a, b, 64); |
---|
| 3826 | + fallthrough; |
---|
3549 | 3827 | case 8: diffs |= __it_diff(a, b, 64); |
---|
3550 | 3828 | break; |
---|
3551 | 3829 | case 28: diffs |= __it_diff(a, b, 64); |
---|
| 3830 | + fallthrough; |
---|
3552 | 3831 | case 20: diffs |= __it_diff(a, b, 64); |
---|
| 3832 | + fallthrough; |
---|
3553 | 3833 | case 12: diffs |= __it_diff(a, b, 64); |
---|
| 3834 | + fallthrough; |
---|
3554 | 3835 | case 4: diffs |= __it_diff(a, b, 32); |
---|
3555 | 3836 | break; |
---|
3556 | 3837 | } |
---|
.. | .. |
---|
3611 | 3892 | * must call this function to return the skb back to the stack with a |
---|
3612 | 3893 | * timestamp. |
---|
3613 | 3894 | * |
---|
3614 | | - * @skb: clone of the the original outgoing packet |
---|
| 3895 | + * @skb: clone of the original outgoing packet |
---|
3615 | 3896 | * @hwtstamps: hardware time stamps |
---|
3616 | 3897 | * |
---|
3617 | 3898 | */ |
---|
.. | .. |
---|
3714 | 3995 | skb->csum_level++; |
---|
3715 | 3996 | } else if (skb->ip_summed == CHECKSUM_NONE) { |
---|
3716 | 3997 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
---|
| 3998 | + skb->csum_level = 0; |
---|
| 3999 | + } |
---|
| 4000 | +} |
---|
| 4001 | + |
---|
| 4002 | +static inline void __skb_reset_checksum_unnecessary(struct sk_buff *skb) |
---|
| 4003 | +{ |
---|
| 4004 | + if (skb->ip_summed == CHECKSUM_UNNECESSARY) { |
---|
| 4005 | + skb->ip_summed = CHECKSUM_NONE; |
---|
3717 | 4006 | skb->csum_level = 0; |
---|
3718 | 4007 | } |
---|
3719 | 4008 | } |
---|
.. | .. |
---|
3833 | 4122 | return (skb->ip_summed == CHECKSUM_NONE && skb->csum_valid); |
---|
3834 | 4123 | } |
---|
3835 | 4124 | |
---|
3836 | | -static inline void __skb_checksum_convert(struct sk_buff *skb, |
---|
3837 | | - __sum16 check, __wsum pseudo) |
---|
| 4125 | +static inline void __skb_checksum_convert(struct sk_buff *skb, __wsum pseudo) |
---|
3838 | 4126 | { |
---|
3839 | 4127 | skb->csum = ~pseudo; |
---|
3840 | 4128 | skb->ip_summed = CHECKSUM_COMPLETE; |
---|
3841 | 4129 | } |
---|
3842 | 4130 | |
---|
3843 | | -#define skb_checksum_try_convert(skb, proto, check, compute_pseudo) \ |
---|
| 4131 | +#define skb_checksum_try_convert(skb, proto, compute_pseudo) \ |
---|
3844 | 4132 | do { \ |
---|
3845 | 4133 | if (__skb_checksum_convert_check(skb)) \ |
---|
3846 | | - __skb_checksum_convert(skb, check, \ |
---|
3847 | | - compute_pseudo(skb, proto)); \ |
---|
| 4134 | + __skb_checksum_convert(skb, compute_pseudo(skb, proto)); \ |
---|
3848 | 4135 | } while (0) |
---|
3849 | 4136 | |
---|
3850 | 4137 | static inline void skb_remcsum_adjust_partial(struct sk_buff *skb, void *ptr, |
---|
.. | .. |
---|
3884 | 4171 | static inline struct nf_conntrack *skb_nfct(const struct sk_buff *skb) |
---|
3885 | 4172 | { |
---|
3886 | 4173 | #if IS_ENABLED(CONFIG_NF_CONNTRACK) |
---|
3887 | | - return (void *)(skb->_nfct & SKB_NFCT_PTRMASK); |
---|
| 4174 | + return (void *)(skb->_nfct & NFCT_PTRMASK); |
---|
3888 | 4175 | #else |
---|
3889 | 4176 | return NULL; |
---|
3890 | 4177 | #endif |
---|
3891 | 4178 | } |
---|
3892 | 4179 | |
---|
3893 | | -#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
---|
3894 | | -void nf_conntrack_destroy(struct nf_conntrack *nfct); |
---|
3895 | | -static inline void nf_conntrack_put(struct nf_conntrack *nfct) |
---|
| 4180 | +static inline unsigned long skb_get_nfct(const struct sk_buff *skb) |
---|
3896 | 4181 | { |
---|
3897 | | - if (nfct && atomic_dec_and_test(&nfct->use)) |
---|
3898 | | - nf_conntrack_destroy(nfct); |
---|
3899 | | -} |
---|
3900 | | -static inline void nf_conntrack_get(struct nf_conntrack *nfct) |
---|
3901 | | -{ |
---|
3902 | | - if (nfct) |
---|
3903 | | - atomic_inc(&nfct->use); |
---|
3904 | | -} |
---|
| 4182 | +#if IS_ENABLED(CONFIG_NF_CONNTRACK) |
---|
| 4183 | + return skb->_nfct; |
---|
| 4184 | +#else |
---|
| 4185 | + return 0UL; |
---|
3905 | 4186 | #endif |
---|
| 4187 | +} |
---|
| 4188 | + |
---|
| 4189 | +static inline void skb_set_nfct(struct sk_buff *skb, unsigned long nfct) |
---|
| 4190 | +{ |
---|
| 4191 | +#if IS_ENABLED(CONFIG_NF_CONNTRACK) |
---|
| 4192 | + skb->_nfct = nfct; |
---|
| 4193 | +#endif |
---|
| 4194 | +} |
---|
| 4195 | + |
---|
| 4196 | +#ifdef CONFIG_SKB_EXTENSIONS |
---|
| 4197 | +enum skb_ext_id { |
---|
3906 | 4198 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
---|
3907 | | -static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge) |
---|
| 4199 | + SKB_EXT_BRIDGE_NF, |
---|
| 4200 | +#endif |
---|
| 4201 | +#ifdef CONFIG_XFRM |
---|
| 4202 | + SKB_EXT_SEC_PATH, |
---|
| 4203 | +#endif |
---|
| 4204 | +#if IS_ENABLED(CONFIG_NET_TC_SKB_EXT) |
---|
| 4205 | + TC_SKB_EXT, |
---|
| 4206 | +#endif |
---|
| 4207 | +#if IS_ENABLED(CONFIG_MPTCP) |
---|
| 4208 | + SKB_EXT_MPTCP, |
---|
| 4209 | +#endif |
---|
| 4210 | +#if IS_ENABLED(CONFIG_KCOV) |
---|
| 4211 | + SKB_EXT_KCOV_HANDLE, |
---|
| 4212 | +#endif |
---|
| 4213 | + SKB_EXT_NUM, /* must be last */ |
---|
| 4214 | +}; |
---|
| 4215 | + |
---|
| 4216 | +/** |
---|
| 4217 | + * struct skb_ext - sk_buff extensions |
---|
| 4218 | + * @refcnt: 1 on allocation, deallocated on 0 |
---|
| 4219 | + * @offset: offset to add to @data to obtain extension address |
---|
| 4220 | + * @chunks: size currently allocated, stored in SKB_EXT_ALIGN_SHIFT units |
---|
| 4221 | + * @data: start of extension data, variable sized |
---|
| 4222 | + * |
---|
| 4223 | + * Note: offsets/lengths are stored in chunks of 8 bytes, this allows |
---|
| 4224 | + * to use 'u8' types while allowing up to 2kb worth of extension data. |
---|
| 4225 | + */ |
---|
| 4226 | +struct skb_ext { |
---|
| 4227 | + refcount_t refcnt; |
---|
| 4228 | + u8 offset[SKB_EXT_NUM]; /* in chunks of 8 bytes */ |
---|
| 4229 | + u8 chunks; /* same */ |
---|
| 4230 | + char data[] __aligned(8); |
---|
| 4231 | +}; |
---|
| 4232 | + |
---|
| 4233 | +struct skb_ext *__skb_ext_alloc(gfp_t flags); |
---|
| 4234 | +void *__skb_ext_set(struct sk_buff *skb, enum skb_ext_id id, |
---|
| 4235 | + struct skb_ext *ext); |
---|
| 4236 | +void *skb_ext_add(struct sk_buff *skb, enum skb_ext_id id); |
---|
| 4237 | +void __skb_ext_del(struct sk_buff *skb, enum skb_ext_id id); |
---|
| 4238 | +void __skb_ext_put(struct skb_ext *ext); |
---|
| 4239 | + |
---|
| 4240 | +static inline void skb_ext_put(struct sk_buff *skb) |
---|
3908 | 4241 | { |
---|
3909 | | - if (nf_bridge && refcount_dec_and_test(&nf_bridge->use)) |
---|
3910 | | - kfree(nf_bridge); |
---|
| 4242 | + if (skb->active_extensions) |
---|
| 4243 | + __skb_ext_put(skb->extensions); |
---|
3911 | 4244 | } |
---|
3912 | | -static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge) |
---|
| 4245 | + |
---|
| 4246 | +static inline void __skb_ext_copy(struct sk_buff *dst, |
---|
| 4247 | + const struct sk_buff *src) |
---|
3913 | 4248 | { |
---|
3914 | | - if (nf_bridge) |
---|
3915 | | - refcount_inc(&nf_bridge->use); |
---|
| 4249 | + dst->active_extensions = src->active_extensions; |
---|
| 4250 | + |
---|
| 4251 | + if (src->active_extensions) { |
---|
| 4252 | + struct skb_ext *ext = src->extensions; |
---|
| 4253 | + |
---|
| 4254 | + refcount_inc(&ext->refcnt); |
---|
| 4255 | + dst->extensions = ext; |
---|
| 4256 | + } |
---|
3916 | 4257 | } |
---|
3917 | | -#endif /* CONFIG_BRIDGE_NETFILTER */ |
---|
3918 | | -static inline void nf_reset(struct sk_buff *skb) |
---|
| 4258 | + |
---|
| 4259 | +static inline void skb_ext_copy(struct sk_buff *dst, const struct sk_buff *src) |
---|
| 4260 | +{ |
---|
| 4261 | + skb_ext_put(dst); |
---|
| 4262 | + __skb_ext_copy(dst, src); |
---|
| 4263 | +} |
---|
| 4264 | + |
---|
| 4265 | +static inline bool __skb_ext_exist(const struct skb_ext *ext, enum skb_ext_id i) |
---|
| 4266 | +{ |
---|
| 4267 | + return !!ext->offset[i]; |
---|
| 4268 | +} |
---|
| 4269 | + |
---|
| 4270 | +static inline bool skb_ext_exist(const struct sk_buff *skb, enum skb_ext_id id) |
---|
| 4271 | +{ |
---|
| 4272 | + return skb->active_extensions & (1 << id); |
---|
| 4273 | +} |
---|
| 4274 | + |
---|
| 4275 | +static inline void skb_ext_del(struct sk_buff *skb, enum skb_ext_id id) |
---|
| 4276 | +{ |
---|
| 4277 | + if (skb_ext_exist(skb, id)) |
---|
| 4278 | + __skb_ext_del(skb, id); |
---|
| 4279 | +} |
---|
| 4280 | + |
---|
| 4281 | +static inline void *skb_ext_find(const struct sk_buff *skb, enum skb_ext_id id) |
---|
| 4282 | +{ |
---|
| 4283 | + if (skb_ext_exist(skb, id)) { |
---|
| 4284 | + struct skb_ext *ext = skb->extensions; |
---|
| 4285 | + |
---|
| 4286 | + return (void *)ext + (ext->offset[id] << 3); |
---|
| 4287 | + } |
---|
| 4288 | + |
---|
| 4289 | + return NULL; |
---|
| 4290 | +} |
---|
| 4291 | + |
---|
| 4292 | +static inline void skb_ext_reset(struct sk_buff *skb) |
---|
| 4293 | +{ |
---|
| 4294 | + if (unlikely(skb->active_extensions)) { |
---|
| 4295 | + __skb_ext_put(skb->extensions); |
---|
| 4296 | + skb->active_extensions = 0; |
---|
| 4297 | + } |
---|
| 4298 | +} |
---|
| 4299 | + |
---|
| 4300 | +static inline bool skb_has_extensions(struct sk_buff *skb) |
---|
| 4301 | +{ |
---|
| 4302 | + return unlikely(skb->active_extensions); |
---|
| 4303 | +} |
---|
| 4304 | +#else |
---|
| 4305 | +static inline void skb_ext_put(struct sk_buff *skb) {} |
---|
| 4306 | +static inline void skb_ext_reset(struct sk_buff *skb) {} |
---|
| 4307 | +static inline void skb_ext_del(struct sk_buff *skb, int unused) {} |
---|
| 4308 | +static inline void __skb_ext_copy(struct sk_buff *d, const struct sk_buff *s) {} |
---|
| 4309 | +static inline void skb_ext_copy(struct sk_buff *dst, const struct sk_buff *s) {} |
---|
| 4310 | +static inline bool skb_has_extensions(struct sk_buff *skb) { return false; } |
---|
| 4311 | +#endif /* CONFIG_SKB_EXTENSIONS */ |
---|
| 4312 | + |
---|
| 4313 | +static inline void nf_reset_ct(struct sk_buff *skb) |
---|
3919 | 4314 | { |
---|
3920 | 4315 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
---|
3921 | 4316 | nf_conntrack_put(skb_nfct(skb)); |
---|
3922 | 4317 | skb->_nfct = 0; |
---|
3923 | 4318 | #endif |
---|
3924 | | -#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
---|
3925 | | - nf_bridge_put(skb->nf_bridge); |
---|
3926 | | -#endif |
---|
3927 | | - skb->nf_bridge = NULL; |
---|
3928 | 4319 | } |
---|
3929 | 4320 | |
---|
3930 | 4321 | static inline void nf_reset_trace(struct sk_buff *skb) |
---|
.. | .. |
---|
3941 | 4332 | #endif |
---|
3942 | 4333 | } |
---|
3943 | 4334 | |
---|
3944 | | -/* Note: This doesn't put any conntrack and bridge info in dst. */ |
---|
| 4335 | +/* Note: This doesn't put any conntrack info in dst. */ |
---|
3945 | 4336 | static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src, |
---|
3946 | 4337 | bool copy) |
---|
3947 | 4338 | { |
---|
3948 | 4339 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
---|
3949 | 4340 | dst->_nfct = src->_nfct; |
---|
3950 | 4341 | nf_conntrack_get(skb_nfct(src)); |
---|
3951 | | -#endif |
---|
3952 | | -#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
---|
3953 | | - dst->nf_bridge = src->nf_bridge; |
---|
3954 | | - nf_bridge_get(src->nf_bridge); |
---|
3955 | 4342 | #endif |
---|
3956 | 4343 | #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE) || defined(CONFIG_NF_TABLES) |
---|
3957 | 4344 | if (copy) |
---|
.. | .. |
---|
3963 | 4350 | { |
---|
3964 | 4351 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
---|
3965 | 4352 | nf_conntrack_put(skb_nfct(dst)); |
---|
3966 | | -#endif |
---|
3967 | | -#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
---|
3968 | | - nf_bridge_put(dst->nf_bridge); |
---|
3969 | 4353 | #endif |
---|
3970 | 4354 | __nf_copy(dst, src, true); |
---|
3971 | 4355 | } |
---|
.. | .. |
---|
3988 | 4372 | { } |
---|
3989 | 4373 | #endif |
---|
3990 | 4374 | |
---|
| 4375 | +static inline int secpath_exists(const struct sk_buff *skb) |
---|
| 4376 | +{ |
---|
| 4377 | +#ifdef CONFIG_XFRM |
---|
| 4378 | + return skb_ext_exist(skb, SKB_EXT_SEC_PATH); |
---|
| 4379 | +#else |
---|
| 4380 | + return 0; |
---|
| 4381 | +#endif |
---|
| 4382 | +} |
---|
| 4383 | + |
---|
3991 | 4384 | static inline bool skb_irq_freeable(const struct sk_buff *skb) |
---|
3992 | 4385 | { |
---|
3993 | 4386 | return !skb->destructor && |
---|
3994 | | -#if IS_ENABLED(CONFIG_XFRM) |
---|
3995 | | - !skb->sp && |
---|
3996 | | -#endif |
---|
| 4387 | + !secpath_exists(skb) && |
---|
3997 | 4388 | !skb_nfct(skb) && |
---|
3998 | 4389 | !skb->_skb_refdst && |
---|
3999 | 4390 | !skb_has_frag_list(skb); |
---|
.. | .. |
---|
4039 | 4430 | return skb->dst_pending_confirm != 0; |
---|
4040 | 4431 | } |
---|
4041 | 4432 | |
---|
4042 | | -static inline struct sec_path *skb_sec_path(struct sk_buff *skb) |
---|
| 4433 | +static inline struct sec_path *skb_sec_path(const struct sk_buff *skb) |
---|
4043 | 4434 | { |
---|
4044 | 4435 | #ifdef CONFIG_XFRM |
---|
4045 | | - return skb->sp; |
---|
| 4436 | + return skb_ext_find(skb, SKB_EXT_SEC_PATH); |
---|
4046 | 4437 | #else |
---|
4047 | 4438 | return NULL; |
---|
4048 | 4439 | #endif |
---|
.. | .. |
---|
4063 | 4454 | __wsum csum; |
---|
4064 | 4455 | __u16 csum_start; |
---|
4065 | 4456 | }; |
---|
4066 | | -#define SKB_SGO_CB_OFFSET 32 |
---|
4067 | | -#define SKB_GSO_CB(skb) ((struct skb_gso_cb *)((skb)->cb + SKB_SGO_CB_OFFSET)) |
---|
| 4457 | +#define SKB_GSO_CB_OFFSET 32 |
---|
| 4458 | +#define SKB_GSO_CB(skb) ((struct skb_gso_cb *)((skb)->cb + SKB_GSO_CB_OFFSET)) |
---|
4068 | 4459 | |
---|
4069 | 4460 | static inline int skb_tnl_header_len(const struct sk_buff *inner_skb) |
---|
4070 | 4461 | { |
---|
.. | .. |
---|
4225 | 4616 | /* Local Checksum Offload. |
---|
4226 | 4617 | * Compute outer checksum based on the assumption that the |
---|
4227 | 4618 | * inner checksum will be offloaded later. |
---|
4228 | | - * See Documentation/networking/checksum-offloads.txt for |
---|
| 4619 | + * See Documentation/networking/checksum-offloads.rst for |
---|
4229 | 4620 | * explanation of how this works. |
---|
4230 | 4621 | * Fill in outer checksum adjustment (e.g. with sum of outer |
---|
4231 | 4622 | * pseudo-header) before calling. |
---|
.. | .. |
---|
4247 | 4638 | return csum_partial(l4_hdr, csum_start - l4_hdr, partial); |
---|
4248 | 4639 | } |
---|
4249 | 4640 | |
---|
| 4641 | +static inline bool skb_is_redirected(const struct sk_buff *skb) |
---|
| 4642 | +{ |
---|
| 4643 | +#ifdef CONFIG_NET_REDIRECT |
---|
| 4644 | + return skb->redirected; |
---|
| 4645 | +#else |
---|
| 4646 | + return false; |
---|
| 4647 | +#endif |
---|
| 4648 | +} |
---|
| 4649 | + |
---|
| 4650 | +static inline void skb_set_redirected(struct sk_buff *skb, bool from_ingress) |
---|
| 4651 | +{ |
---|
| 4652 | +#ifdef CONFIG_NET_REDIRECT |
---|
| 4653 | + skb->redirected = 1; |
---|
| 4654 | + skb->from_ingress = from_ingress; |
---|
| 4655 | + if (skb->from_ingress) |
---|
| 4656 | + skb->tstamp = 0; |
---|
| 4657 | +#endif |
---|
| 4658 | +} |
---|
| 4659 | + |
---|
| 4660 | +static inline void skb_reset_redirect(struct sk_buff *skb) |
---|
| 4661 | +{ |
---|
| 4662 | +#ifdef CONFIG_NET_REDIRECT |
---|
| 4663 | + skb->redirected = 0; |
---|
| 4664 | +#endif |
---|
| 4665 | +} |
---|
| 4666 | + |
---|
| 4667 | +#if IS_ENABLED(CONFIG_KCOV) && IS_ENABLED(CONFIG_SKB_EXTENSIONS) |
---|
| 4668 | +static inline void skb_set_kcov_handle(struct sk_buff *skb, |
---|
| 4669 | + const u64 kcov_handle) |
---|
| 4670 | +{ |
---|
| 4671 | + /* Do not allocate skb extensions only to set kcov_handle to zero |
---|
| 4672 | + * (as it is zero by default). However, if the extensions are |
---|
| 4673 | + * already allocated, update kcov_handle anyway since |
---|
| 4674 | + * skb_set_kcov_handle can be called to zero a previously set |
---|
| 4675 | + * value. |
---|
| 4676 | + */ |
---|
| 4677 | + if (skb_has_extensions(skb) || kcov_handle) { |
---|
| 4678 | + u64 *kcov_handle_ptr = skb_ext_add(skb, SKB_EXT_KCOV_HANDLE); |
---|
| 4679 | + |
---|
| 4680 | + if (kcov_handle_ptr) |
---|
| 4681 | + *kcov_handle_ptr = kcov_handle; |
---|
| 4682 | + } |
---|
| 4683 | +} |
---|
| 4684 | + |
---|
| 4685 | +static inline u64 skb_get_kcov_handle(struct sk_buff *skb) |
---|
| 4686 | +{ |
---|
| 4687 | + u64 *kcov_handle = skb_ext_find(skb, SKB_EXT_KCOV_HANDLE); |
---|
| 4688 | + |
---|
| 4689 | + return kcov_handle ? *kcov_handle : 0; |
---|
| 4690 | +} |
---|
| 4691 | +#else |
---|
| 4692 | +static inline void skb_set_kcov_handle(struct sk_buff *skb, |
---|
| 4693 | + const u64 kcov_handle) { } |
---|
| 4694 | +static inline u64 skb_get_kcov_handle(struct sk_buff *skb) { return 0; } |
---|
| 4695 | +#endif /* CONFIG_KCOV && CONFIG_SKB_EXTENSIONS */ |
---|
| 4696 | + |
---|
4250 | 4697 | #endif /* __KERNEL__ */ |
---|
4251 | 4698 | #endif /* _LINUX_SKBUFF_H */ |
---|