2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <rte_config.h>
28 #include "netdev-dpdk.h"
29 #include "openvswitch/list.h"
38 enum OVS_PACKED_ENUM dp_packet_source
{
39 DPBUF_MALLOC
, /* Obtained via malloc(). */
40 DPBUF_STACK
, /* Un-movable stack space or static buffer. */
41 DPBUF_STUB
, /* Starts on stack, may expand into heap. */
42 DPBUF_DPDK
, /* buffer data is from DPDK allocated memory.
43 * ref to dp_packet_init_dpdk() in dp-packet.c.
47 #define DP_PACKET_CONTEXT_SIZE 64
49 /* Buffer for holding packet data. A dp_packet is automatically reallocated
50 * as necessary if it grows too large for the available memory.
51 * By default the packet type is set to Ethernet (PT_ETH).
55 struct rte_mbuf mbuf
; /* DPDK mbuf */
57 void *base_
; /* First byte of allocated space. */
58 uint16_t allocated_
; /* Number of bytes allocated. */
59 uint16_t data_ofs
; /* First byte actually in use. */
60 uint32_t size_
; /* Number of bytes in use. */
61 uint32_t rss_hash
; /* Packet hash. */
62 bool rss_hash_valid
; /* Is the 'rss_hash' valid? */
64 enum dp_packet_source source
; /* Source of memory allocated as 'base'. */
66 /* All the following elements of this struct are copied in a single call
67 * of memcpy in dp_packet_clone_with_headroom. */
68 uint8_t l2_pad_size
; /* Detected l2 padding size.
69 * Padding is non-pullable. */
70 uint16_t l2_5_ofs
; /* MPLS label stack offset, or UINT16_MAX */
71 uint16_t l3_ofs
; /* Network-level header offset,
73 uint16_t l4_ofs
; /* Transport-level header offset,
75 uint32_t cutlen
; /* length in bytes to cut from the end. */
76 ovs_be32 packet_type
; /* Packet type as defined in OpenFlow */
78 struct pkt_metadata md
;
79 uint64_t data
[DP_PACKET_CONTEXT_SIZE
/ 8];
83 static inline void *dp_packet_data(const struct dp_packet
*);
84 static inline void dp_packet_set_data(struct dp_packet
*, void *);
85 static inline void *dp_packet_base(const struct dp_packet
*);
86 static inline void dp_packet_set_base(struct dp_packet
*, void *);
88 static inline uint32_t dp_packet_size(const struct dp_packet
*);
89 static inline void dp_packet_set_size(struct dp_packet
*, uint32_t);
91 static inline uint16_t dp_packet_get_allocated(const struct dp_packet
*);
92 static inline void dp_packet_set_allocated(struct dp_packet
*, uint16_t);
94 void *dp_packet_resize_l2(struct dp_packet
*, int increment
);
95 void *dp_packet_resize_l2_5(struct dp_packet
*, int increment
);
96 static inline void *dp_packet_eth(const struct dp_packet
*);
97 static inline void dp_packet_reset_offsets(struct dp_packet
*);
98 static inline uint8_t dp_packet_l2_pad_size(const struct dp_packet
*);
99 static inline void dp_packet_set_l2_pad_size(struct dp_packet
*, uint8_t);
100 static inline void *dp_packet_l2_5(const struct dp_packet
*);
101 static inline void dp_packet_set_l2_5(struct dp_packet
*, void *);
102 static inline void *dp_packet_l3(const struct dp_packet
*);
103 static inline void dp_packet_set_l3(struct dp_packet
*, void *);
104 static inline void *dp_packet_l4(const struct dp_packet
*);
105 static inline void dp_packet_set_l4(struct dp_packet
*, void *);
106 static inline size_t dp_packet_l4_size(const struct dp_packet
*);
107 static inline const void *dp_packet_get_tcp_payload(const struct dp_packet
*);
108 static inline const void *dp_packet_get_udp_payload(const struct dp_packet
*);
109 static inline const void *dp_packet_get_sctp_payload(const struct dp_packet
*);
110 static inline const void *dp_packet_get_icmp_payload(const struct dp_packet
*);
111 static inline const void *dp_packet_get_nd_payload(const struct dp_packet
*);
113 void dp_packet_use(struct dp_packet
*, void *, size_t);
114 void dp_packet_use_stub(struct dp_packet
*, void *, size_t);
115 void dp_packet_use_const(struct dp_packet
*, const void *, size_t);
117 void dp_packet_init_dpdk(struct dp_packet
*, size_t allocated
);
119 void dp_packet_init(struct dp_packet
*, size_t);
120 void dp_packet_uninit(struct dp_packet
*);
122 struct dp_packet
*dp_packet_new(size_t);
123 struct dp_packet
*dp_packet_new_with_headroom(size_t, size_t headroom
);
124 struct dp_packet
*dp_packet_clone(const struct dp_packet
*);
125 struct dp_packet
*dp_packet_clone_with_headroom(const struct dp_packet
*,
127 struct dp_packet
*dp_packet_clone_data(const void *, size_t);
128 struct dp_packet
*dp_packet_clone_data_with_headroom(const void *, size_t,
130 static inline void dp_packet_delete(struct dp_packet
*);
132 static inline void *dp_packet_at(const struct dp_packet
*, size_t offset
,
134 static inline void *dp_packet_at_assert(const struct dp_packet
*,
135 size_t offset
, size_t size
);
136 static inline void *dp_packet_tail(const struct dp_packet
*);
137 static inline void *dp_packet_end(const struct dp_packet
*);
139 void *dp_packet_put_uninit(struct dp_packet
*, size_t);
140 void *dp_packet_put_zeros(struct dp_packet
*, size_t);
141 void *dp_packet_put(struct dp_packet
*, const void *, size_t);
142 char *dp_packet_put_hex(struct dp_packet
*, const char *s
, size_t *n
);
143 void dp_packet_reserve(struct dp_packet
*, size_t);
144 void dp_packet_reserve_with_tailroom(struct dp_packet
*, size_t headroom
,
146 void *dp_packet_push_uninit(struct dp_packet
*, size_t);
147 void *dp_packet_push_zeros(struct dp_packet
*, size_t);
148 void *dp_packet_push(struct dp_packet
*, const void *, size_t);
150 static inline size_t dp_packet_headroom(const struct dp_packet
*);
151 static inline size_t dp_packet_tailroom(const struct dp_packet
*);
152 void dp_packet_prealloc_headroom(struct dp_packet
*, size_t);
153 void dp_packet_prealloc_tailroom(struct dp_packet
*, size_t);
154 void dp_packet_shift(struct dp_packet
*, int);
156 static inline void dp_packet_clear(struct dp_packet
*);
157 static inline void *dp_packet_pull(struct dp_packet
*, size_t);
158 static inline void *dp_packet_try_pull(struct dp_packet
*, size_t);
160 void *dp_packet_steal_data(struct dp_packet
*);
162 static inline bool dp_packet_equal(const struct dp_packet
*,
163 const struct dp_packet
*);
166 /* Frees memory that 'b' points to, as well as 'b' itself. */
168 dp_packet_delete(struct dp_packet
*b
)
171 if (b
->source
== DPBUF_DPDK
) {
172 /* If this dp_packet was allocated by DPDK it must have been
173 * created as a dp_packet */
174 free_dpdk_buf((struct dp_packet
*) b
);
183 /* If 'b' contains at least 'offset + size' bytes of data, returns a pointer to
184 * byte 'offset'. Otherwise, returns a null pointer. */
186 dp_packet_at(const struct dp_packet
*b
, size_t offset
, size_t size
)
188 return offset
+ size
<= dp_packet_size(b
)
189 ? (char *) dp_packet_data(b
) + offset
193 /* Returns a pointer to byte 'offset' in 'b', which must contain at least
194 * 'offset + size' bytes of data. */
196 dp_packet_at_assert(const struct dp_packet
*b
, size_t offset
, size_t size
)
198 ovs_assert(offset
+ size
<= dp_packet_size(b
));
199 return ((char *) dp_packet_data(b
)) + offset
;
202 /* Returns a pointer to byte following the last byte of data in use in 'b'. */
204 dp_packet_tail(const struct dp_packet
*b
)
206 return (char *) dp_packet_data(b
) + dp_packet_size(b
);
209 /* Returns a pointer to byte following the last byte allocated for use (but
210 * not necessarily in use) in 'b'. */
212 dp_packet_end(const struct dp_packet
*b
)
214 return (char *) dp_packet_base(b
) + dp_packet_get_allocated(b
);
217 /* Returns the number of bytes of headroom in 'b', that is, the number of bytes
218 * of unused space in dp_packet 'b' before the data that is in use. (Most
219 * commonly, the data in a dp_packet is at its beginning, and thus the
220 * dp_packet's headroom is 0.) */
222 dp_packet_headroom(const struct dp_packet
*b
)
224 return (char *) dp_packet_data(b
) - (char *) dp_packet_base(b
);
227 /* Returns the number of bytes that may be appended to the tail end of
228 * dp_packet 'b' before the dp_packet must be reallocated. */
230 dp_packet_tailroom(const struct dp_packet
*b
)
232 return (char *) dp_packet_end(b
) - (char *) dp_packet_tail(b
);
235 /* Clears any data from 'b'. */
237 dp_packet_clear(struct dp_packet
*b
)
239 dp_packet_set_data(b
, dp_packet_base(b
));
240 dp_packet_set_size(b
, 0);
243 /* Removes 'size' bytes from the head end of 'b', which must contain at least
244 * 'size' bytes of data. Returns the first byte of data removed. */
246 dp_packet_pull(struct dp_packet
*b
, size_t size
)
248 void *data
= dp_packet_data(b
);
249 ovs_assert(dp_packet_size(b
) - dp_packet_l2_pad_size(b
) >= size
);
250 dp_packet_set_data(b
, (char *) dp_packet_data(b
) + size
);
251 dp_packet_set_size(b
, dp_packet_size(b
) - size
);
255 /* If 'b' has at least 'size' bytes of data, removes that many bytes from the
256 * head end of 'b' and returns the first byte removed. Otherwise, returns a
257 * null pointer without modifying 'b'. */
259 dp_packet_try_pull(struct dp_packet
*b
, size_t size
)
261 return dp_packet_size(b
) - dp_packet_l2_pad_size(b
) >= size
262 ? dp_packet_pull(b
, size
) : NULL
;
266 dp_packet_equal(const struct dp_packet
*a
, const struct dp_packet
*b
)
268 return dp_packet_size(a
) == dp_packet_size(b
) &&
269 !memcmp(dp_packet_data(a
), dp_packet_data(b
), dp_packet_size(a
));
273 dp_packet_is_eth(const struct dp_packet
*b
)
275 return b
->packet_type
== htonl(PT_ETH
);
278 /* Get the start of the Ethernet frame. 'l3_ofs' marks the end of the l2
279 * headers, so return NULL if it is not set. */
281 dp_packet_eth(const struct dp_packet
*b
)
283 return (dp_packet_is_eth(b
) && b
->l3_ofs
!= UINT16_MAX
)
284 ? dp_packet_data(b
) : NULL
;
287 /* Resets all layer offsets. 'l3' offset must be set before 'l2' can be
290 dp_packet_reset_offsets(struct dp_packet
*b
)
293 b
->l2_5_ofs
= UINT16_MAX
;
294 b
->l3_ofs
= UINT16_MAX
;
295 b
->l4_ofs
= UINT16_MAX
;
298 static inline uint8_t
299 dp_packet_l2_pad_size(const struct dp_packet
*b
)
301 return b
->l2_pad_size
;
305 dp_packet_set_l2_pad_size(struct dp_packet
*b
, uint8_t pad_size
)
307 ovs_assert(pad_size
<= dp_packet_size(b
));
308 b
->l2_pad_size
= pad_size
;
312 dp_packet_l2_5(const struct dp_packet
*b
)
314 return b
->l2_5_ofs
!= UINT16_MAX
315 ? (char *) dp_packet_data(b
) + b
->l2_5_ofs
320 dp_packet_set_l2_5(struct dp_packet
*b
, void *l2_5
)
323 ? (char *) l2_5
- (char *) dp_packet_data(b
)
328 dp_packet_l3(const struct dp_packet
*b
)
330 return b
->l3_ofs
!= UINT16_MAX
331 ? (char *) dp_packet_data(b
) + b
->l3_ofs
336 dp_packet_set_l3(struct dp_packet
*b
, void *l3
)
338 b
->l3_ofs
= l3
? (char *) l3
- (char *) dp_packet_data(b
) : UINT16_MAX
;
342 dp_packet_l4(const struct dp_packet
*b
)
344 return b
->l4_ofs
!= UINT16_MAX
345 ? (char *) dp_packet_data(b
) + b
->l4_ofs
350 dp_packet_set_l4(struct dp_packet
*b
, void *l4
)
352 b
->l4_ofs
= l4
? (char *) l4
- (char *) dp_packet_data(b
) : UINT16_MAX
;
356 dp_packet_l4_size(const struct dp_packet
*b
)
358 return b
->l4_ofs
!= UINT16_MAX
359 ? (const char *)dp_packet_tail(b
) - (const char *)dp_packet_l4(b
)
360 - dp_packet_l2_pad_size(b
)
364 static inline const void *
365 dp_packet_get_tcp_payload(const struct dp_packet
*b
)
367 size_t l4_size
= dp_packet_l4_size(b
);
369 if (OVS_LIKELY(l4_size
>= TCP_HEADER_LEN
)) {
370 struct tcp_header
*tcp
= dp_packet_l4(b
);
371 int tcp_len
= TCP_OFFSET(tcp
->tcp_ctl
) * 4;
373 if (OVS_LIKELY(tcp_len
>= TCP_HEADER_LEN
&& tcp_len
<= l4_size
)) {
374 return (const char *)tcp
+ tcp_len
;
380 static inline const void *
381 dp_packet_get_udp_payload(const struct dp_packet
*b
)
383 return OVS_LIKELY(dp_packet_l4_size(b
) >= UDP_HEADER_LEN
)
384 ? (const char *)dp_packet_l4(b
) + UDP_HEADER_LEN
: NULL
;
387 static inline const void *
388 dp_packet_get_sctp_payload(const struct dp_packet
*b
)
390 return OVS_LIKELY(dp_packet_l4_size(b
) >= SCTP_HEADER_LEN
)
391 ? (const char *)dp_packet_l4(b
) + SCTP_HEADER_LEN
: NULL
;
394 static inline const void *
395 dp_packet_get_icmp_payload(const struct dp_packet
*b
)
397 return OVS_LIKELY(dp_packet_l4_size(b
) >= ICMP_HEADER_LEN
)
398 ? (const char *)dp_packet_l4(b
) + ICMP_HEADER_LEN
: NULL
;
401 static inline const void *
402 dp_packet_get_nd_payload(const struct dp_packet
*b
)
404 return OVS_LIKELY(dp_packet_l4_size(b
) >= ND_MSG_LEN
)
405 ? (const char *)dp_packet_l4(b
) + ND_MSG_LEN
: NULL
;
409 BUILD_ASSERT_DECL(offsetof(struct dp_packet
, mbuf
) == 0);
412 dp_packet_base(const struct dp_packet
*b
)
414 return b
->mbuf
.buf_addr
;
418 dp_packet_set_base(struct dp_packet
*b
, void *d
)
420 b
->mbuf
.buf_addr
= d
;
423 static inline uint32_t
424 dp_packet_size(const struct dp_packet
*b
)
426 return b
->mbuf
.pkt_len
;
430 dp_packet_set_size(struct dp_packet
*b
, uint32_t v
)
432 /* netdev-dpdk does not currently support segmentation; consequently, for
433 * all intents and purposes, 'data_len' (16 bit) and 'pkt_len' (32 bit) may
434 * be used interchangably.
436 * On the datapath, it is expected that the size of packets
437 * (and thus 'v') will always be <= UINT16_MAX; this means that there is no
438 * loss of accuracy in assigning 'v' to 'data_len'.
440 b
->mbuf
.data_len
= (uint16_t)v
; /* Current seg length. */
441 b
->mbuf
.pkt_len
= v
; /* Total length of all segments linked to
445 static inline uint16_t
446 __packet_data(const struct dp_packet
*b
)
448 return b
->mbuf
.data_off
;
452 __packet_set_data(struct dp_packet
*b
, uint16_t v
)
454 b
->mbuf
.data_off
= v
;
457 static inline uint16_t
458 dp_packet_get_allocated(const struct dp_packet
*b
)
460 return b
->mbuf
.buf_len
;
464 dp_packet_set_allocated(struct dp_packet
*b
, uint16_t s
)
470 dp_packet_base(const struct dp_packet
*b
)
476 dp_packet_set_base(struct dp_packet
*b
, void *d
)
481 static inline uint32_t
482 dp_packet_size(const struct dp_packet
*b
)
488 dp_packet_set_size(struct dp_packet
*b
, uint32_t v
)
493 static inline uint16_t
494 __packet_data(const struct dp_packet
*b
)
500 __packet_set_data(struct dp_packet
*b
, uint16_t v
)
505 static inline uint16_t
506 dp_packet_get_allocated(const struct dp_packet
*b
)
508 return b
->allocated_
;
512 dp_packet_set_allocated(struct dp_packet
*b
, uint16_t s
)
519 dp_packet_reset_cutlen(struct dp_packet
*b
)
524 static inline uint32_t
525 dp_packet_set_cutlen(struct dp_packet
*b
, uint32_t max_len
)
527 if (max_len
< ETH_HEADER_LEN
) {
528 max_len
= ETH_HEADER_LEN
;
531 if (max_len
>= dp_packet_size(b
)) {
534 b
->cutlen
= dp_packet_size(b
) - max_len
;
539 static inline uint32_t
540 dp_packet_get_cutlen(const struct dp_packet
*b
)
542 /* Always in valid range if user uses dp_packet_set_cutlen. */
546 static inline uint32_t
547 dp_packet_get_send_len(const struct dp_packet
*b
)
549 return dp_packet_size(b
) - dp_packet_get_cutlen(b
);
553 dp_packet_data(const struct dp_packet
*b
)
555 return __packet_data(b
) != UINT16_MAX
556 ? (char *) dp_packet_base(b
) + __packet_data(b
) : NULL
;
560 dp_packet_set_data(struct dp_packet
*b
, void *data
)
563 __packet_set_data(b
, (char *) data
- (char *) dp_packet_base(b
));
565 __packet_set_data(b
, UINT16_MAX
);
570 dp_packet_reset_packet(struct dp_packet
*b
, int off
)
572 dp_packet_set_size(b
, dp_packet_size(b
) - off
);
573 dp_packet_set_data(b
, ((unsigned char *) dp_packet_data(b
) + off
));
574 dp_packet_reset_offsets(b
);
577 /* Returns the RSS hash of the packet 'p'. Note that the returned value is
578 * correct only if 'dp_packet_rss_valid(p)' returns true */
579 static inline uint32_t
580 dp_packet_get_rss_hash(struct dp_packet
*p
)
583 return p
->mbuf
.hash
.rss
;
590 dp_packet_set_rss_hash(struct dp_packet
*p
, uint32_t hash
)
593 p
->mbuf
.hash
.rss
= hash
;
594 p
->mbuf
.ol_flags
|= PKT_RX_RSS_HASH
;
597 p
->rss_hash_valid
= true;
602 dp_packet_rss_valid(struct dp_packet
*p
)
605 return p
->mbuf
.ol_flags
& PKT_RX_RSS_HASH
;
607 return p
->rss_hash_valid
;
612 dp_packet_rss_invalidate(struct dp_packet
*p OVS_UNUSED
)
615 p
->rss_hash_valid
= false;
620 dp_packet_mbuf_rss_flag_reset(struct dp_packet
*p OVS_UNUSED
)
623 p
->mbuf
.ol_flags
&= ~PKT_RX_RSS_HASH
;
627 /* This initialization is needed for packets that do not come
628 * from DPDK interfaces, when vswitchd is built with --with-dpdk.
629 * The DPDK rte library will still otherwise manage the mbuf.
630 * We only need to initialize the mbuf ol_flags. */
632 dp_packet_mbuf_init(struct dp_packet
*p OVS_UNUSED
)
635 p
->mbuf
.ol_flags
= 0;
640 dp_packet_ip_checksum_valid(struct dp_packet
*p OVS_UNUSED
)
643 return (p
->mbuf
.ol_flags
& PKT_RX_IP_CKSUM_MASK
) ==
644 PKT_RX_IP_CKSUM_GOOD
;
651 dp_packet_ip_checksum_bad(struct dp_packet
*p OVS_UNUSED
)
654 return (p
->mbuf
.ol_flags
& PKT_RX_IP_CKSUM_MASK
) ==
662 dp_packet_l4_checksum_valid(struct dp_packet
*p OVS_UNUSED
)
665 return (p
->mbuf
.ol_flags
& PKT_RX_L4_CKSUM_MASK
) ==
666 PKT_RX_L4_CKSUM_GOOD
;
673 dp_packet_l4_checksum_bad(struct dp_packet
*p OVS_UNUSED
)
676 return (p
->mbuf
.ol_flags
& PKT_RX_L4_CKSUM_MASK
) ==
685 reset_dp_packet_checksum_ol_flags(struct dp_packet
*p
)
687 p
->mbuf
.ol_flags
&= ~(PKT_RX_L4_CKSUM_GOOD
| PKT_RX_L4_CKSUM_BAD
|
688 PKT_RX_IP_CKSUM_GOOD
| PKT_RX_IP_CKSUM_BAD
);
691 #define reset_dp_packet_checksum_ol_flags(arg)
694 enum { NETDEV_MAX_BURST
= 32 }; /* Maximum number packets in a batch. */
696 struct dp_packet_batch
{
698 bool trunc
; /* true if the batch needs truncate. */
699 struct dp_packet
*packets
[NETDEV_MAX_BURST
];
703 dp_packet_batch_init(struct dp_packet_batch
*batch
)
706 batch
->trunc
= false;
710 dp_packet_batch_add__(struct dp_packet_batch
*batch
,
711 struct dp_packet
*packet
, size_t limit
)
713 if (batch
->count
< limit
) {
714 batch
->packets
[batch
->count
++] = packet
;
716 dp_packet_delete(packet
);
720 /* When the batch is full, 'packet' will be dropped and freed. */
722 dp_packet_batch_add(struct dp_packet_batch
*batch
, struct dp_packet
*packet
)
724 dp_packet_batch_add__(batch
, packet
, NETDEV_MAX_BURST
);
728 dp_packet_batch_size(const struct dp_packet_batch
*batch
)
733 /* Clear 'batch' for refill. Use dp_packet_batch_refill() to add
734 * packets back into the 'batch'. */
736 dp_packet_batch_refill_init(struct dp_packet_batch
*batch
)
742 dp_packet_batch_refill(struct dp_packet_batch
*batch
,
743 struct dp_packet
*packet
, size_t idx
)
745 dp_packet_batch_add__(batch
, packet
, MIN(NETDEV_MAX_BURST
, idx
+ 1));
749 dp_packet_batch_init_packet(struct dp_packet_batch
*batch
, struct dp_packet
*p
)
751 dp_packet_batch_init(batch
);
753 batch
->packets
[0] = p
;
757 dp_packet_batch_is_empty(const struct dp_packet_batch
*batch
)
759 return !dp_packet_batch_size(batch
);
762 #define DP_PACKET_BATCH_FOR_EACH(PACKET, BATCH) \
763 for (size_t i = 0; i < dp_packet_batch_size(BATCH); i++) \
764 if (PACKET = BATCH->packets[i], true)
766 /* Use this macro for cases where some packets in the 'BATCH' may be
767 * dropped after going through each packet in the 'BATCH'.
769 * For packets to stay in the 'BATCH', they need to be refilled back
770 * into the 'BATCH' by calling dp_packet_batch_refill(). Caller owns
771 * the packets that are not refilled.
773 * Caller needs to supply 'SIZE', that stores the current number of
774 * packets in 'BATCH'. It is best to declare this variable with
775 * the 'const' modifier since it should not be modified by
777 #define DP_PACKET_BATCH_REFILL_FOR_EACH(IDX, SIZE, PACKET, BATCH) \
778 for (dp_packet_batch_refill_init(BATCH), IDX=0; IDX < SIZE; IDX++) \
779 if (PACKET = BATCH->packets[IDX], true)
782 dp_packet_batch_clone(struct dp_packet_batch
*dst
,
783 struct dp_packet_batch
*src
)
785 struct dp_packet
*packet
;
787 dp_packet_batch_init(dst
);
788 DP_PACKET_BATCH_FOR_EACH (packet
, src
) {
789 dp_packet_batch_add(dst
, dp_packet_clone(packet
));
791 dst
->trunc
= src
->trunc
;
795 dp_packet_delete_batch(struct dp_packet_batch
*batch
, bool may_steal
)
798 struct dp_packet
*packet
;
800 DP_PACKET_BATCH_FOR_EACH (packet
, batch
) {
801 dp_packet_delete(packet
);
803 dp_packet_batch_init(batch
);
808 dp_packet_batch_init_cutlen(struct dp_packet_batch
*batch
)
810 struct dp_packet
*packet
;
812 DP_PACKET_BATCH_FOR_EACH (packet
, batch
) {
813 dp_packet_reset_cutlen(packet
);
818 dp_packet_batch_apply_cutlen(struct dp_packet_batch
*batch
)
821 struct dp_packet
*packet
;
823 DP_PACKET_BATCH_FOR_EACH (packet
, batch
) {
824 dp_packet_set_size(packet
, dp_packet_get_send_len(packet
));
825 dp_packet_reset_cutlen(packet
);
827 batch
->trunc
= false;
832 dp_packet_batch_reset_cutlen(struct dp_packet_batch
*batch
)
835 struct dp_packet
*packet
;
837 DP_PACKET_BATCH_FOR_EACH (packet
, batch
) {
838 dp_packet_reset_cutlen(packet
);
840 batch
->trunc
= false;
848 #endif /* dp-packet.h */