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
40 * @has_virt_hdr: device uses virtio header
43 void net_rx_pkt_init(struct NetRxPkt
**pkt
, bool has_virt_hdr
);
46 * returns total length of data attached to rx context
53 size_t net_rx_pkt_get_total_len(struct NetRxPkt
*pkt
);
56 * parse and set packet analysis results
59 * @data: pointer to the data buffer to be parsed
63 void net_rx_pkt_set_protocols(struct NetRxPkt
*pkt
, const void *data
,
67 * fetches packet analysis results
70 * @isip4: whether the packet given is IPv4
71 * @isip6: whether the packet given is IPv6
72 * @isudp: whether the packet given is UDP
73 * @istcp: whether the packet given is TCP
76 void net_rx_pkt_get_protocols(struct NetRxPkt
*pkt
,
77 bool *isip4
, bool *isip6
,
78 bool *isudp
, bool *istcp
);
81 * fetches L3 header offset
86 size_t net_rx_pkt_get_l3_hdr_offset(struct NetRxPkt
*pkt
);
89 * fetches L4 header offset
94 size_t net_rx_pkt_get_l4_hdr_offset(struct NetRxPkt
*pkt
);
97 * fetches L5 header offset
102 size_t net_rx_pkt_get_l5_hdr_offset(struct NetRxPkt
*pkt
);
105 * fetches IP6 header analysis results
107 * Return: pointer to analysis results structure which is stored in internal
111 eth_ip6_hdr_info
*net_rx_pkt_get_ip6_info(struct NetRxPkt
*pkt
);
114 * fetches IP4 header analysis results
116 * Return: pointer to analysis results structure which is stored in internal
120 eth_ip4_hdr_info
*net_rx_pkt_get_ip4_info(struct NetRxPkt
*pkt
);
123 * fetches L4 header analysis results
125 * Return: pointer to analysis results structure which is stored in internal
129 eth_l4_hdr_info
*net_rx_pkt_get_l4_info(struct NetRxPkt
*pkt
);
144 * calculates RSS hash for packet
147 * @type: RSS hash type
149 * Return: Toeplitz RSS hash.
153 net_rx_pkt_calc_rss_hash(struct NetRxPkt
*pkt
,
154 NetRxPktRssType type
,
158 * fetches IP identification for the packet
163 uint16_t net_rx_pkt_get_ip_id(struct NetRxPkt
*pkt
);
166 * check if given packet is a TCP ACK packet
171 bool net_rx_pkt_is_tcp_ack(struct NetRxPkt
*pkt
);
174 * check if given packet contains TCP data
179 bool net_rx_pkt_has_tcp_data(struct NetRxPkt
*pkt
);
182 * returns virtio header stored in rx context
185 * @ret: virtio header
188 struct virtio_net_hdr
*net_rx_pkt_get_vhdr(struct NetRxPkt
*pkt
);
191 * returns packet type
197 eth_pkt_types_e
net_rx_pkt_get_packet_type(struct NetRxPkt
*pkt
);
206 uint16_t net_rx_pkt_get_vlan_tag(struct NetRxPkt
*pkt
);
209 * tells whether vlan was stripped from the packet
212 * @ret: VLAN stripped sign
215 bool net_rx_pkt_is_vlan_stripped(struct NetRxPkt
*pkt
);
218 * notifies caller if the packet has virtio header
221 * @ret: true if packet has virtio header, false otherwize
224 bool net_rx_pkt_has_virt_hdr(struct NetRxPkt
*pkt
);
227 * attach scatter-gather data to rx packet
230 * @iov: received data scatter-gather list
231 * @iovcnt number of elements in iov
232 * @iovoff data start offset in the iov
233 * @strip_vlan: should the module strip vlan from data
236 void net_rx_pkt_attach_iovec(struct NetRxPkt
*pkt
,
237 const struct iovec
*iov
,
238 int iovcnt
, size_t iovoff
,
242 * attach scatter-gather data to rx packet
245 * @iov: received data scatter-gather list
246 * @iovcnt number of elements in iov
247 * @iovoff data start offset in the iov
248 * @strip_vlan: should the module strip vlan from data
249 * @vet: VLAN tag Ethernet type
252 void net_rx_pkt_attach_iovec_ex(struct NetRxPkt
*pkt
,
253 const struct iovec
*iov
, int iovcnt
,
254 size_t iovoff
, bool strip_vlan
,
258 * attach data to rx packet
261 * @data: pointer to the data buffer
263 * @strip_vlan: should the module strip vlan from data
267 net_rx_pkt_attach_data(struct NetRxPkt
*pkt
, const void *data
,
268 size_t len
, bool strip_vlan
)
270 const struct iovec iov
= {
271 .iov_base
= (void *) data
,
275 net_rx_pkt_attach_iovec(pkt
, &iov
, 1, 0, strip_vlan
);
279 * returns io vector that holds the attached data
282 * @ret: pointer to IOVec
285 struct iovec
*net_rx_pkt_get_iovec(struct NetRxPkt
*pkt
);
288 * returns io vector length that holds the attached data
294 uint16_t net_rx_pkt_get_iovec_len(struct NetRxPkt
*pkt
);
297 * prints rx packet data if debug is enabled
302 void net_rx_pkt_dump(struct NetRxPkt
*pkt
);
305 * copy passed vhdr data to packet context
311 void net_rx_pkt_set_vhdr(struct NetRxPkt
*pkt
,
312 struct virtio_net_hdr
*vhdr
);
315 * copy passed vhdr data to packet context
319 * @iovcnt: VHDR iov array size
322 void net_rx_pkt_set_vhdr_iovec(struct NetRxPkt
*pkt
,
323 const struct iovec
*iov
, int iovcnt
);
326 * save packet type in packet context
329 * @packet_type: the packet type
332 void net_rx_pkt_set_packet_type(struct NetRxPkt
*pkt
,
333 eth_pkt_types_e packet_type
);
336 * validate TCP/UDP checksum of the packet
339 * @csum_valid: checksum validation result
340 * @ret: true if validation was performed, false in case packet is
341 * not TCP/UDP or checksum validation is not possible
344 bool net_rx_pkt_validate_l4_csum(struct NetRxPkt
*pkt
, bool *csum_valid
);
347 * validate IPv4 checksum of the packet
350 * @csum_valid: checksum validation result
351 * @ret: true if validation was performed, false in case packet is
352 * not TCP/UDP or checksum validation is not possible
355 bool net_rx_pkt_validate_l3_csum(struct NetRxPkt
*pkt
, bool *csum_valid
);
358 * fix IPv4 checksum of the packet
361 * @ret: true if checksum was fixed, false in case packet is
362 * not TCP/UDP or checksum correction is not possible
365 bool net_rx_pkt_fix_l4_csum(struct NetRxPkt
*pkt
);