Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / hw / net / net_rx_pkt.h
blobea077f5fdb19efa324e9ffe3692f3ecb92d9c60c
1 /*
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)
8 * Authors:
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.
18 #ifndef NET_RX_PKT_H
19 #define NET_RX_PKT_H
21 #include "net/eth.h"
23 /* defines to enable packet dump functions */
24 /*#define NET_RX_PKT_DEBUG*/
26 struct NetRxPkt;
28 /**
29 * Clean all rx packet resources
31 * @pkt: packet
34 void net_rx_pkt_uninit(struct NetRxPkt *pkt);
36 /**
37 * Init function for rx packet functionality
39 * @pkt: packet pointer
42 void net_rx_pkt_init(struct NetRxPkt **pkt);
44 /**
45 * returns total length of data attached to rx context
47 * @pkt: packet
49 * Return: nothing
52 size_t net_rx_pkt_get_total_len(struct NetRxPkt *pkt);
54 /**
55 * parse and set packet analysis results
57 * @pkt: packet
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,
65 size_t iovoff);
67 /**
68 * fetches packet analysis results
70 * @pkt: packet
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);
80 /**
81 * fetches L4 header offset
83 * @pkt: packet
86 size_t net_rx_pkt_get_l4_hdr_offset(struct NetRxPkt *pkt);
88 /**
89 * fetches L5 header offset
91 * @pkt: packet
94 size_t net_rx_pkt_get_l5_hdr_offset(struct NetRxPkt *pkt);
96 /**
97 * fetches IP6 header analysis results
99 * Return: pointer to analysis results structure which is stored in internal
100 * packet area.
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
109 * packet area.
112 eth_ip4_hdr_info *net_rx_pkt_get_ip4_info(struct NetRxPkt *pkt);
114 typedef enum {
115 NetPktRssIpV4,
116 NetPktRssIpV4Tcp,
117 NetPktRssIpV6Tcp,
118 NetPktRssIpV6,
119 NetPktRssIpV6Ex,
120 NetPktRssIpV6TcpEx,
121 NetPktRssIpV4Udp,
122 NetPktRssIpV6Udp,
123 NetPktRssIpV6UdpEx,
124 } NetRxPktRssType;
127 * calculates RSS hash for packet
129 * @pkt: packet
130 * @type: RSS hash type
132 * Return: Toeplitz RSS hash.
135 uint32_t
136 net_rx_pkt_calc_rss_hash(struct NetRxPkt *pkt,
137 NetRxPktRssType type,
138 uint8_t *key);
141 * fetches IP identification for the packet
143 * @pkt: packet
146 uint16_t net_rx_pkt_get_ip_id(struct NetRxPkt *pkt);
149 * check if given packet is a TCP ACK packet
151 * @pkt: packet
154 bool net_rx_pkt_is_tcp_ack(struct NetRxPkt *pkt);
157 * check if given packet contains TCP data
159 * @pkt: packet
162 bool net_rx_pkt_has_tcp_data(struct NetRxPkt *pkt);
165 * returns virtio header stored in rx context
167 * @pkt: packet
168 * @ret: virtio header
171 struct virtio_net_hdr *net_rx_pkt_get_vhdr(struct NetRxPkt *pkt);
174 * returns packet type
176 * @pkt: packet
177 * @ret: packet type
180 eth_pkt_types_e net_rx_pkt_get_packet_type(struct NetRxPkt *pkt);
183 * returns vlan tag
185 * @pkt: packet
186 * @ret: VLAN tag
189 uint16_t net_rx_pkt_get_vlan_tag(struct NetRxPkt *pkt);
192 * tells whether vlan was stripped from the packet
194 * @pkt: 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
203 * @pkt: 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,
213 bool strip_vlan);
216 * attach scatter-gather data to rx packet
218 * @pkt: 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
235 * @pkt: packet
236 * @data: pointer to the data buffer
237 * @len: data length
238 * @strip_vlan: should the module strip vlan from data
241 static inline void
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,
247 .iov_len = len
250 net_rx_pkt_attach_iovec(pkt, &iov, 1, 0, strip_vlan);
254 * returns io vector that holds the attached data
256 * @pkt: packet
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
265 * @pkt: packet
268 void net_rx_pkt_dump(struct NetRxPkt *pkt);
271 * copy passed vhdr data to packet context
273 * @pkt: packet
274 * @vhdr: VHDR buffer
277 void net_rx_pkt_set_vhdr(struct NetRxPkt *pkt,
278 struct virtio_net_hdr *vhdr);
281 * copy passed vhdr data to packet context
283 * @pkt: packet
284 * @iov: VHDR iov
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
294 * @pkt: packet
297 void net_rx_pkt_unset_vhdr(struct NetRxPkt *pkt);
300 * save packet type in packet context
302 * @pkt: packet
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
312 * @pkt: 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
323 * @pkt: 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
334 * @pkt: 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);
341 #endif