2 * QEMU RX packets abstraction
4 * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
6 * Developed by Daynix Computing LTD (http://www.daynix.com)
9 * Dmitry Fleytman <dmitry@daynix.com>
10 * Tamir Shomer <tamirs@daynix.com>
11 * Yan Vugenfirer <yan@daynix.com>
13 * This work is licensed under the terms of the GNU GPL, version 2 or later.
14 * See the COPYING file in the top-level directory.
23 /* defines to enable packet dump functions */
24 /*#define NET_RX_PKT_DEBUG*/
29 * Clean all rx packet resources
34 void net_rx_pkt_uninit(struct NetRxPkt
*pkt
);
37 * Init function for rx packet functionality
39 * @pkt: packet pointer
42 void net_rx_pkt_init(struct NetRxPkt
**pkt
);
45 * returns total length of data attached to rx context
52 size_t net_rx_pkt_get_total_len(struct NetRxPkt
*pkt
);
55 * parse and set packet analysis results
58 * @iov: received data scatter-gather list
59 * @iovcnt: number of elements in iov
60 * @iovoff: data start offset in the iov
63 void net_rx_pkt_set_protocols(struct NetRxPkt
*pkt
,
64 const struct iovec
*iov
, size_t iovcnt
,
68 * fetches packet analysis results
71 * @hasip4: whether the packet has an IPv4 header
72 * @hasip6: whether the packet has an IPv6 header
73 * @l4hdr_proto: protocol of L4 header
76 void net_rx_pkt_get_protocols(struct NetRxPkt
*pkt
,
77 bool *hasip4
, bool *hasip6
,
78 EthL4HdrProto
*l4hdr_proto
);
81 * fetches L4 header offset
86 size_t net_rx_pkt_get_l4_hdr_offset(struct NetRxPkt
*pkt
);
89 * fetches L5 header offset
94 size_t net_rx_pkt_get_l5_hdr_offset(struct NetRxPkt
*pkt
);
97 * fetches IP6 header analysis results
99 * Return: pointer to analysis results structure which is stored in internal
103 eth_ip6_hdr_info
*net_rx_pkt_get_ip6_info(struct NetRxPkt
*pkt
);
106 * fetches IP4 header analysis results
108 * Return: pointer to analysis results structure which is stored in internal
112 eth_ip4_hdr_info
*net_rx_pkt_get_ip4_info(struct NetRxPkt
*pkt
);
127 * calculates RSS hash for packet
130 * @type: RSS hash type
132 * Return: Toeplitz RSS hash.
136 net_rx_pkt_calc_rss_hash(struct NetRxPkt
*pkt
,
137 NetRxPktRssType type
,
141 * fetches IP identification for the packet
146 uint16_t net_rx_pkt_get_ip_id(struct NetRxPkt
*pkt
);
149 * check if given packet is a TCP ACK packet
154 bool net_rx_pkt_is_tcp_ack(struct NetRxPkt
*pkt
);
157 * check if given packet contains TCP data
162 bool net_rx_pkt_has_tcp_data(struct NetRxPkt
*pkt
);
165 * returns virtio header stored in rx context
168 * @ret: virtio header
171 struct virtio_net_hdr
*net_rx_pkt_get_vhdr(struct NetRxPkt
*pkt
);
174 * returns packet type
180 eth_pkt_types_e
net_rx_pkt_get_packet_type(struct NetRxPkt
*pkt
);
189 uint16_t net_rx_pkt_get_vlan_tag(struct NetRxPkt
*pkt
);
192 * tells whether vlan was stripped from the packet
195 * @ret: VLAN stripped sign
198 bool net_rx_pkt_is_vlan_stripped(struct NetRxPkt
*pkt
);
201 * attach scatter-gather data to rx packet
204 * @iov: received data scatter-gather list
205 * @iovcnt number of elements in iov
206 * @iovoff data start offset in the iov
207 * @strip_vlan: should the module strip vlan from data
210 void net_rx_pkt_attach_iovec(struct NetRxPkt
*pkt
,
211 const struct iovec
*iov
,
212 int iovcnt
, size_t iovoff
,
216 * attach scatter-gather data to rx packet
219 * @iov: received data scatter-gather list
220 * @iovcnt: number of elements in iov
221 * @iovoff: data start offset in the iov
222 * @strip_vlan_index: index of Q tag if it is to be stripped. negative otherwise.
223 * @vet: VLAN tag Ethernet type
224 * @vet_ext: outer VLAN tag Ethernet type
227 void net_rx_pkt_attach_iovec_ex(struct NetRxPkt
*pkt
,
228 const struct iovec
*iov
, int iovcnt
,
229 size_t iovoff
, int strip_vlan_index
,
230 uint16_t vet
, uint16_t vet_ext
);
233 * attach data to rx packet
236 * @data: pointer to the data buffer
238 * @strip_vlan: should the module strip vlan from data
242 net_rx_pkt_attach_data(struct NetRxPkt
*pkt
, const void *data
,
243 size_t len
, bool strip_vlan
)
245 const struct iovec iov
= {
246 .iov_base
= (void *) data
,
250 net_rx_pkt_attach_iovec(pkt
, &iov
, 1, 0, strip_vlan
);
254 * returns io vector that holds the attached data
257 * @ret: pointer to IOVec
260 struct iovec
*net_rx_pkt_get_iovec(struct NetRxPkt
*pkt
);
263 * prints rx packet data if debug is enabled
268 void net_rx_pkt_dump(struct NetRxPkt
*pkt
);
271 * copy passed vhdr data to packet context
277 void net_rx_pkt_set_vhdr(struct NetRxPkt
*pkt
,
278 struct virtio_net_hdr
*vhdr
);
281 * copy passed vhdr data to packet context
285 * @iovcnt: VHDR iov array size
288 void net_rx_pkt_set_vhdr_iovec(struct NetRxPkt
*pkt
,
289 const struct iovec
*iov
, int iovcnt
);
292 * unset vhdr data from packet context
297 void net_rx_pkt_unset_vhdr(struct NetRxPkt
*pkt
);
300 * save packet type in packet context
303 * @packet_type: the packet type
306 void net_rx_pkt_set_packet_type(struct NetRxPkt
*pkt
,
307 eth_pkt_types_e packet_type
);
310 * validate TCP/UDP checksum of the packet
313 * @csum_valid: checksum validation result
314 * @ret: true if validation was performed, false in case packet is
315 * not TCP/UDP or checksum validation is not possible
318 bool net_rx_pkt_validate_l4_csum(struct NetRxPkt
*pkt
, bool *csum_valid
);
321 * validate IPv4 checksum of the packet
324 * @csum_valid: checksum validation result
325 * @ret: true if validation was performed, false in case packet is
326 * not TCP/UDP or checksum validation is not possible
329 bool net_rx_pkt_validate_l3_csum(struct NetRxPkt
*pkt
, bool *csum_valid
);
332 * fix IPv4 checksum of the packet
335 * @ret: true if checksum was fixed, false in case packet is
336 * not TCP/UDP or checksum correction is not possible
339 bool net_rx_pkt_fix_l4_csum(struct NetRxPkt
*pkt
);