Skip to content

Commit eb70002

Browse files
Dmitry Fleytmanjasowang
Dmitry Fleytman
authored andcommitted
net_pkt: Extend packet abstraction as required by e1000e functionality
This patch extends the TX/RX packet abstractions with features that will be used by the e1000e device implementation. Changes are: 1. Support iovec lists for RX buffers 2. Deeper RX packets parsing 3. Loopback option for TX packets 4. Extended VLAN headers handling 5. RSS processing for RX packets Signed-off-by: Dmitry Fleytman <dmitry.fleytman@ravellosystems.com> Signed-off-by: Leonid Bloch <leonid.bloch@ravellosystems.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
1 parent 66409b7 commit eb70002

File tree

9 files changed

+1336
-205
lines changed

9 files changed

+1336
-205
lines changed

hw/net/net_rx_pkt.c

+443-30
Large diffs are not rendered by default.

hw/net/net_rx_pkt.h

+191-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,103 @@ void net_rx_pkt_get_protocols(struct NetRxPkt *pkt,
7777
bool *isip4, bool *isip6,
7878
bool *isudp, bool *istcp);
7979

80+
/**
81+
* fetches L3 header offset
82+
*
83+
* @pkt: packet
84+
*
85+
*/
86+
size_t net_rx_pkt_get_l3_hdr_offset(struct NetRxPkt *pkt);
87+
88+
/**
89+
* fetches L4 header offset
90+
*
91+
* @pkt: packet
92+
*
93+
*/
94+
size_t net_rx_pkt_get_l4_hdr_offset(struct NetRxPkt *pkt);
95+
96+
/**
97+
* fetches L5 header offset
98+
*
99+
* @pkt: packet
100+
*
101+
*/
102+
size_t net_rx_pkt_get_l5_hdr_offset(struct NetRxPkt *pkt);
103+
104+
/**
105+
* fetches IP6 header analysis results
106+
*
107+
* Return: pointer to analysis results structure which is stored in internal
108+
* packet area.
109+
*
110+
*/
111+
eth_ip6_hdr_info *net_rx_pkt_get_ip6_info(struct NetRxPkt *pkt);
112+
113+
/**
114+
* fetches IP4 header analysis results
115+
*
116+
* Return: pointer to analysis results structure which is stored in internal
117+
* packet area.
118+
*
119+
*/
120+
eth_ip4_hdr_info *net_rx_pkt_get_ip4_info(struct NetRxPkt *pkt);
121+
122+
/**
123+
* fetches L4 header analysis results
124+
*
125+
* Return: pointer to analysis results structure which is stored in internal
126+
* packet area.
127+
*
128+
*/
129+
eth_l4_hdr_info *net_rx_pkt_get_l4_info(struct NetRxPkt *pkt);
130+
131+
typedef enum {
132+
NetPktRssIpV4,
133+
NetPktRssIpV4Tcp,
134+
NetPktRssIpV6Tcp,
135+
NetPktRssIpV6,
136+
NetPktRssIpV6Ex
137+
} NetRxPktRssType;
138+
139+
/**
140+
* calculates RSS hash for packet
141+
*
142+
* @pkt: packet
143+
* @type: RSS hash type
144+
*
145+
* Return: Toeplitz RSS hash.
146+
*
147+
*/
148+
uint32_t
149+
net_rx_pkt_calc_rss_hash(struct NetRxPkt *pkt,
150+
NetRxPktRssType type,
151+
uint8_t *key);
152+
153+
/**
154+
* fetches IP identification for the packet
155+
*
156+
* @pkt: packet
157+
*
158+
*/
159+
uint16_t net_rx_pkt_get_ip_id(struct NetRxPkt *pkt);
160+
161+
/**
162+
* check if given packet is a TCP ACK packet
163+
*
164+
* @pkt: packet
165+
*
166+
*/
167+
bool net_rx_pkt_is_tcp_ack(struct NetRxPkt *pkt);
168+
169+
/**
170+
* check if given packet contains TCP data
171+
*
172+
* @pkt: packet
173+
*
174+
*/
175+
bool net_rx_pkt_has_tcp_data(struct NetRxPkt *pkt);
176+
80177
/**
81178
* returns virtio header stored in rx context
82179
*
@@ -122,6 +219,37 @@ bool net_rx_pkt_is_vlan_stripped(struct NetRxPkt *pkt);
122219
*/
123220
bool net_rx_pkt_has_virt_hdr(struct NetRxPkt *pkt);
124221

222+
/**
223+
* attach scatter-gather data to rx packet
224+
*
225+
* @pkt: packet
226+
* @iov: received data scatter-gather list
227+
* @iovcnt number of elements in iov
228+
* @iovoff data start offset in the iov
229+
* @strip_vlan: should the module strip vlan from data
230+
*
231+
*/
232+
void net_rx_pkt_attach_iovec(struct NetRxPkt *pkt,
233+
const struct iovec *iov,
234+
int iovcnt, size_t iovoff,
235+
bool strip_vlan);
236+
237+
/**
238+
* attach scatter-gather data to rx packet
239+
*
240+
* @pkt: packet
241+
* @iov: received data scatter-gather list
242+
* @iovcnt number of elements in iov
243+
* @iovoff data start offset in the iov
244+
* @strip_vlan: should the module strip vlan from data
245+
* @vet: VLAN tag Ethernet type
246+
*
247+
*/
248+
void net_rx_pkt_attach_iovec_ex(struct NetRxPkt *pkt,
249+
const struct iovec *iov, int iovcnt,
250+
size_t iovoff, bool strip_vlan,
251+
uint16_t vet);
252+
125253
/**
126254
* attach data to rx packet
127255
*
@@ -131,8 +259,17 @@ bool net_rx_pkt_has_virt_hdr(struct NetRxPkt *pkt);
131259
* @strip_vlan: should the module strip vlan from data
132260
*
133261
*/
134-
void net_rx_pkt_attach_data(struct NetRxPkt *pkt, const void *data,
135-
size_t len, bool strip_vlan);
262+
static inline void
263+
net_rx_pkt_attach_data(struct NetRxPkt *pkt, const void *data,
264+
size_t len, bool strip_vlan)
265+
{
266+
const struct iovec iov = {
267+
.iov_base = (void *) data,
268+
.iov_len = len
269+
};
270+
271+
net_rx_pkt_attach_iovec(pkt, &iov, 1, 0, strip_vlan);
272+
}
136273

137274
/**
138275
* returns io vector that holds the attached data
@@ -143,6 +280,15 @@ void net_rx_pkt_attach_data(struct NetRxPkt *pkt, const void *data,
143280
*/
144281
struct iovec *net_rx_pkt_get_iovec(struct NetRxPkt *pkt);
145282

283+
/**
284+
* returns io vector length that holds the attached data
285+
*
286+
* @pkt: packet
287+
* @ret: IOVec length
288+
*
289+
*/
290+
uint16_t net_rx_pkt_get_iovec_len(struct NetRxPkt *pkt);
291+
146292
/**
147293
* prints rx packet data if debug is enabled
148294
*
@@ -161,6 +307,17 @@ void net_rx_pkt_dump(struct NetRxPkt *pkt);
161307
void net_rx_pkt_set_vhdr(struct NetRxPkt *pkt,
162308
struct virtio_net_hdr *vhdr);
163309

310+
/**
311+
* copy passed vhdr data to packet context
312+
*
313+
* @pkt: packet
314+
* @iov: VHDR iov
315+
* @iovcnt: VHDR iov array size
316+
*
317+
*/
318+
void net_rx_pkt_set_vhdr_iovec(struct NetRxPkt *pkt,
319+
const struct iovec *iov, int iovcnt);
320+
164321
/**
165322
* save packet type in packet context
166323
*
@@ -171,4 +328,36 @@ void net_rx_pkt_set_vhdr(struct NetRxPkt *pkt,
171328
void net_rx_pkt_set_packet_type(struct NetRxPkt *pkt,
172329
eth_pkt_types_e packet_type);
173330

331+
/**
332+
* validate TCP/UDP checksum of the packet
333+
*
334+
* @pkt: packet
335+
* @csum_valid: checksum validation result
336+
* @ret: true if validation was performed, false in case packet is
337+
* not TCP/UDP or checksum validation is not possible
338+
*
339+
*/
340+
bool net_rx_pkt_validate_l4_csum(struct NetRxPkt *pkt, bool *csum_valid);
341+
342+
/**
343+
* validate IPv4 checksum of the packet
344+
*
345+
* @pkt: packet
346+
* @csum_valid: checksum validation result
347+
* @ret: true if validation was performed, false in case packet is
348+
* not TCP/UDP or checksum validation is not possible
349+
*
350+
*/
351+
bool net_rx_pkt_validate_l3_csum(struct NetRxPkt *pkt, bool *csum_valid);
352+
353+
/**
354+
* fix IPv4 checksum of the packet
355+
*
356+
* @pkt: packet
357+
* @ret: true if checksum was fixed, false in case packet is
358+
* not TCP/UDP or checksum correction is not possible
359+
*
360+
*/
361+
bool net_rx_pkt_fix_l4_csum(struct NetRxPkt *pkt);
362+
174363
#endif

0 commit comments

Comments
 (0)