Commit 8abf6f72 authored by Magnus Karlsson's avatar Magnus Karlsson Committed by Daniel Borkmann

selftests: xsk: Allow for invalid packets

Allow for invalid packets to be sent. These are verified by the Rx
thread not to be received. Or put in another way, if they are
received, the test will fail. This feature will be used to eliminate
an if statement for a stats test and will also be used by other tests
in later patches. The previous code could only deal with valid
packets.
Signed-off-by: default avatarMagnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarMaciej Fijalkowski <maciej.fijalkowski@intel.com>
Link: https://lore.kernel.org/bpf/20210907071928.9750-16-magnus.karlsson@gmail.com
parent 8ce7192b
...@@ -473,6 +473,11 @@ static struct pkt_stream *pkt_stream_generate(struct xsk_umem_info *umem, u32 nb ...@@ -473,6 +473,11 @@ static struct pkt_stream *pkt_stream_generate(struct xsk_umem_info *umem, u32 nb
pkt_stream->pkts[i].addr = (i % umem->num_frames) * umem->frame_size; pkt_stream->pkts[i].addr = (i % umem->num_frames) * umem->frame_size;
pkt_stream->pkts[i].len = pkt_len; pkt_stream->pkts[i].len = pkt_len;
pkt_stream->pkts[i].payload = i; pkt_stream->pkts[i].payload = i;
if (pkt_len > umem->frame_size)
pkt_stream->pkts[i].valid = false;
else
pkt_stream->pkts[i].valid = true;
} }
return pkt_stream; return pkt_stream;
...@@ -658,7 +663,7 @@ static void receive_pkts(struct pkt_stream *pkt_stream, struct xsk_socket_info * ...@@ -658,7 +663,7 @@ static void receive_pkts(struct pkt_stream *pkt_stream, struct xsk_socket_info *
static u32 __send_pkts(struct ifobject *ifobject, u32 pkt_nb) static u32 __send_pkts(struct ifobject *ifobject, u32 pkt_nb)
{ {
struct xsk_socket_info *xsk = ifobject->xsk; struct xsk_socket_info *xsk = ifobject->xsk;
u32 i, idx; u32 i, idx, valid_pkts = 0;
while (xsk_ring_prod__reserve(&xsk->tx, BATCH_SIZE, &idx) < BATCH_SIZE) while (xsk_ring_prod__reserve(&xsk->tx, BATCH_SIZE, &idx) < BATCH_SIZE)
complete_pkts(xsk, BATCH_SIZE); complete_pkts(xsk, BATCH_SIZE);
...@@ -673,14 +678,13 @@ static u32 __send_pkts(struct ifobject *ifobject, u32 pkt_nb) ...@@ -673,14 +678,13 @@ static u32 __send_pkts(struct ifobject *ifobject, u32 pkt_nb)
tx_desc->addr = pkt->addr; tx_desc->addr = pkt->addr;
tx_desc->len = pkt->len; tx_desc->len = pkt->len;
pkt_nb++; pkt_nb++;
if (pkt->valid)
valid_pkts++;
} }
xsk_ring_prod__submit(&xsk->tx, i); xsk_ring_prod__submit(&xsk->tx, i);
if (stat_test_type != STAT_TEST_TX_INVALID) xsk->outstanding_tx += valid_pkts;
xsk->outstanding_tx += i; complete_pkts(xsk, BATCH_SIZE);
else if (xsk_ring_prod__needs_wakeup(&xsk->tx))
kick_tx(xsk);
complete_pkts(xsk, i);
return i; return i;
} }
......
...@@ -96,6 +96,7 @@ struct pkt { ...@@ -96,6 +96,7 @@ struct pkt {
u64 addr; u64 addr;
u32 len; u32 len;
u32 payload; u32 payload;
bool valid;
}; };
struct pkt_stream { struct pkt_stream {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment