Commit aa2d61c1 authored by Maciej Fijalkowski's avatar Maciej Fijalkowski Committed by Alexei Starovoitov

selftests: xsk: Simplify frame traversal in dumping thread

Store offsets to each layer in a separate variables rather than compute
them every single time.
Signed-off-by: default avatarBjörn Töpel <bjorn.topel@intel.com>
Signed-off-by: default avatarMaciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210329224316.17793-6-maciej.fijalkowski@intel.com
parent 965d2cb0
...@@ -658,45 +658,40 @@ static void tx_only_all(struct ifobject *ifobject) ...@@ -658,45 +658,40 @@ static void tx_only_all(struct ifobject *ifobject)
static void worker_pkt_dump(void) static void worker_pkt_dump(void)
{ {
struct in_addr ipaddr; struct ethhdr *ethhdr;
struct iphdr *iphdr;
struct udphdr *udphdr;
char s[128];
int payload;
void *ptr;
fprintf(stdout, "---------------------------------------\n"); fprintf(stdout, "---------------------------------------\n");
for (int iter = 0; iter < num_frames - 1; iter++) { for (int iter = 0; iter < num_frames - 1; iter++) {
ptr = pkt_buf[iter]->payload;
ethhdr = ptr;
iphdr = ptr + sizeof(*ethhdr);
udphdr = ptr + sizeof(*ethhdr) + sizeof(*iphdr);
/*extract L2 frame */ /*extract L2 frame */
fprintf(stdout, "DEBUG>> L2: dst mac: "); fprintf(stdout, "DEBUG>> L2: dst mac: ");
for (int i = 0; i < ETH_ALEN; i++) for (int i = 0; i < ETH_ALEN; i++)
fprintf(stdout, "%02X", ((struct ethhdr *) fprintf(stdout, "%02X", ethhdr->h_dest[i]);
pkt_buf[iter]->payload)->h_dest[i]);
fprintf(stdout, "\nDEBUG>> L2: src mac: "); fprintf(stdout, "\nDEBUG>> L2: src mac: ");
for (int i = 0; i < ETH_ALEN; i++) for (int i = 0; i < ETH_ALEN; i++)
fprintf(stdout, "%02X", ((struct ethhdr *) fprintf(stdout, "%02X", ethhdr->h_source[i]);
pkt_buf[iter]->payload)->h_source[i]);
/*extract L3 frame */ /*extract L3 frame */
fprintf(stdout, "\nDEBUG>> L3: ip_hdr->ihl: %02X\n", fprintf(stdout, "\nDEBUG>> L3: ip_hdr->ihl: %02X\n", iphdr->ihl);
((struct iphdr *)(pkt_buf[iter]->payload + sizeof(struct ethhdr)))->ihl); fprintf(stdout, "DEBUG>> L3: ip_hdr->saddr: %s\n",
inet_ntop(AF_INET, &iphdr->saddr, s, sizeof(s)));
ipaddr.s_addr = fprintf(stdout, "DEBUG>> L3: ip_hdr->daddr: %s\n",
((struct iphdr *)(pkt_buf[iter]->payload + sizeof(struct ethhdr)))->saddr; inet_ntop(AF_INET, &iphdr->daddr, s, sizeof(s)));
fprintf(stdout, "DEBUG>> L3: ip_hdr->saddr: %s\n", inet_ntoa(ipaddr));
ipaddr.s_addr =
((struct iphdr *)(pkt_buf[iter]->payload + sizeof(struct ethhdr)))->daddr;
fprintf(stdout, "DEBUG>> L3: ip_hdr->daddr: %s\n", inet_ntoa(ipaddr));
/*extract L4 frame */ /*extract L4 frame */
fprintf(stdout, "DEBUG>> L4: udp_hdr->src: %d\n", fprintf(stdout, "DEBUG>> L4: udp_hdr->src: %d\n", ntohs(udphdr->source));
ntohs(((struct udphdr *)(pkt_buf[iter]->payload + fprintf(stdout, "DEBUG>> L4: udp_hdr->dst: %d\n", ntohs(udphdr->dest));
sizeof(struct ethhdr) +
sizeof(struct iphdr)))->source));
fprintf(stdout, "DEBUG>> L4: udp_hdr->dst: %d\n",
ntohs(((struct udphdr *)(pkt_buf[iter]->payload +
sizeof(struct ethhdr) +
sizeof(struct iphdr)))->dest));
/*extract L5 frame */ /*extract L5 frame */
int payload = *((uint32_t *)(pkt_buf[iter]->payload + PKT_HDR_SIZE)); payload = *((uint32_t *)(ptr + PKT_HDR_SIZE));
if (payload == EOT) { if (payload == EOT) {
print_verbose("End-of-transmission frame received\n"); print_verbose("End-of-transmission frame received\n");
......
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