Commit 8a9cba7e authored by Björn Töpel's avatar Björn Töpel Committed by Daniel Borkmann

selftests/bpf: Improve readability of xdpxceiver/worker_pkt_validate()

Introduce a local variable to get rid of lot of casting. Move common
code outside the if/else-clause.
Signed-off-by: default avatarBjörn Töpel <bjorn.topel@intel.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210122154725.22140-6-bjorn.topel@gmail.com
parent 4896d7e3
...@@ -726,16 +726,17 @@ static void worker_pkt_dump(void) ...@@ -726,16 +726,17 @@ static void worker_pkt_dump(void)
static void worker_pkt_validate(void) static void worker_pkt_validate(void)
{ {
u32 payloadseqnum = -2; u32 payloadseqnum = -2;
struct iphdr *iphdr;
while (1) { while (1) {
pkt_node_rx_q = TAILQ_LAST(&head, head_s); pkt_node_rx_q = TAILQ_LAST(&head, head_s);
if (!pkt_node_rx_q) if (!pkt_node_rx_q)
break; break;
iphdr = (struct iphdr *)(pkt_node_rx_q->pkt_frame + sizeof(struct ethhdr));
/*do not increment pktcounter if !(tos=0x9 and ipv4) */ /*do not increment pktcounter if !(tos=0x9 and ipv4) */
if ((((struct iphdr *)(pkt_node_rx_q->pkt_frame + if (iphdr->version == IP_PKT_VER && iphdr->tos == IP_PKT_TOS) {
sizeof(struct ethhdr)))->version == IP_PKT_VER) &&
(((struct iphdr *)(pkt_node_rx_q->pkt_frame + sizeof(struct ethhdr)))->tos ==
IP_PKT_TOS)) {
payloadseqnum = *((uint32_t *)(pkt_node_rx_q->pkt_frame + PKT_HDR_SIZE)); payloadseqnum = *((uint32_t *)(pkt_node_rx_q->pkt_frame + PKT_HDR_SIZE));
if (debug_pkt_dump && payloadseqnum != EOT) { if (debug_pkt_dump && payloadseqnum != EOT) {
pkt_obj = (struct pkt_frame *)malloc(sizeof(struct pkt_frame)); pkt_obj = (struct pkt_frame *)malloc(sizeof(struct pkt_frame));
...@@ -757,24 +758,18 @@ static void worker_pkt_validate(void) ...@@ -757,24 +758,18 @@ static void worker_pkt_validate(void)
ksft_exit_xfail(); ksft_exit_xfail();
} }
TAILQ_REMOVE(&head, pkt_node_rx_q, pkt_nodes);
free(pkt_node_rx_q->pkt_frame);
free(pkt_node_rx_q);
pkt_node_rx_q = NULL;
prev_pkt = payloadseqnum; prev_pkt = payloadseqnum;
pkt_counter++; pkt_counter++;
} else { } else {
ksft_print_msg("Invalid frame received: "); ksft_print_msg("Invalid frame received: ");
ksft_print_msg("[IP_PKT_VER: %02X], [IP_PKT_TOS: %02X]\n", ksft_print_msg("[IP_PKT_VER: %02X], [IP_PKT_TOS: %02X]\n", iphdr->version,
((struct iphdr *)(pkt_node_rx_q->pkt_frame + iphdr->tos);
sizeof(struct ethhdr)))->version,
((struct iphdr *)(pkt_node_rx_q->pkt_frame +
sizeof(struct ethhdr)))->tos);
TAILQ_REMOVE(&head, pkt_node_rx_q, pkt_nodes);
free(pkt_node_rx_q->pkt_frame);
free(pkt_node_rx_q);
pkt_node_rx_q = NULL;
} }
TAILQ_REMOVE(&head, pkt_node_rx_q, pkt_nodes);
free(pkt_node_rx_q->pkt_frame);
free(pkt_node_rx_q);
pkt_node_rx_q = NULL;
} }
} }
......
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