|
104 | 104 | #include "../kselftest.h" |
105 | 105 | #include "xsk_xdp_common.h" |
106 | 106 |
|
107 | | -static const char *MAC1 = "\x00\x0A\x56\x9E\xEE\x62"; |
108 | | -static const char *MAC2 = "\x00\x0A\x56\x9E\xEE\x61"; |
109 | | - |
110 | 107 | static bool opt_verbose; |
111 | 108 | static bool opt_print_tests; |
112 | 109 | static enum test_mode opt_mode = TEST_MODE_ALL; |
@@ -159,10 +156,10 @@ static void write_payload(void *dest, u32 pkt_nb, u32 start, u32 size) |
159 | 156 | ptr[i] = htonl(pkt_nb << 16 | (i + start)); |
160 | 157 | } |
161 | 158 |
|
162 | | -static void gen_eth_hdr(struct ifobject *ifobject, struct ethhdr *eth_hdr) |
| 159 | +static void gen_eth_hdr(struct xsk_socket_info *xsk, struct ethhdr *eth_hdr) |
163 | 160 | { |
164 | | - memcpy(eth_hdr->h_dest, ifobject->dst_mac, ETH_ALEN); |
165 | | - memcpy(eth_hdr->h_source, ifobject->src_mac, ETH_ALEN); |
| 161 | + memcpy(eth_hdr->h_dest, xsk->dst_mac, ETH_ALEN); |
| 162 | + memcpy(eth_hdr->h_source, xsk->src_mac, ETH_ALEN); |
166 | 163 | eth_hdr->h_proto = htons(ETH_P_LOOPBACK); |
167 | 164 | } |
168 | 165 |
|
@@ -445,6 +442,11 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, |
445 | 442 | ifobj->xsk_arr[j].pkt_stream = test->tx_pkt_stream_default; |
446 | 443 | else |
447 | 444 | ifobj->xsk_arr[j].pkt_stream = test->rx_pkt_stream_default; |
| 445 | + |
| 446 | + memcpy(ifobj->xsk_arr[j].src_mac, g_mac, ETH_ALEN); |
| 447 | + memcpy(ifobj->xsk_arr[j].dst_mac, g_mac, ETH_ALEN); |
| 448 | + ifobj->xsk_arr[j].src_mac[5] += ((j * 2) + 0); |
| 449 | + ifobj->xsk_arr[j].dst_mac[5] += ((j * 2) + 1); |
448 | 450 | } |
449 | 451 | } |
450 | 452 |
|
@@ -726,16 +728,16 @@ static void pkt_stream_cancel(struct pkt_stream *pkt_stream) |
726 | 728 | pkt_stream->current_pkt_nb--; |
727 | 729 | } |
728 | 730 |
|
729 | | -static void pkt_generate(struct ifobject *ifobject, u64 addr, u32 len, u32 pkt_nb, |
730 | | - u32 bytes_written) |
| 731 | +static void pkt_generate(struct xsk_socket_info *xsk, struct xsk_umem_info *umem, u64 addr, u32 len, |
| 732 | + u32 pkt_nb, u32 bytes_written) |
731 | 733 | { |
732 | | - void *data = xsk_umem__get_data(ifobject->umem->buffer, addr); |
| 734 | + void *data = xsk_umem__get_data(umem->buffer, addr); |
733 | 735 |
|
734 | 736 | if (len < MIN_PKT_SIZE) |
735 | 737 | return; |
736 | 738 |
|
737 | 739 | if (!bytes_written) { |
738 | | - gen_eth_hdr(ifobject, data); |
| 740 | + gen_eth_hdr(xsk, data); |
739 | 741 |
|
740 | 742 | len -= PKT_HDR_SIZE; |
741 | 743 | data += PKT_HDR_SIZE; |
@@ -1209,7 +1211,7 @@ static int __send_pkts(struct ifobject *ifobject, struct pollfd *fds, bool timeo |
1209 | 1211 | tx_desc->options = 0; |
1210 | 1212 | } |
1211 | 1213 | if (pkt->valid) |
1212 | | - pkt_generate(ifobject, tx_desc->addr, tx_desc->len, pkt->pkt_nb, |
| 1214 | + pkt_generate(xsk, umem, tx_desc->addr, tx_desc->len, pkt->pkt_nb, |
1213 | 1215 | bytes_written); |
1214 | 1216 | bytes_written += tx_desc->len; |
1215 | 1217 |
|
@@ -2120,15 +2122,11 @@ static bool hugepages_present(void) |
2120 | 2122 | return true; |
2121 | 2123 | } |
2122 | 2124 |
|
2123 | | -static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char *src_mac, |
2124 | | - thread_func_t func_ptr) |
| 2125 | +static void init_iface(struct ifobject *ifobj, thread_func_t func_ptr) |
2125 | 2126 | { |
2126 | 2127 | LIBBPF_OPTS(bpf_xdp_query_opts, query_opts); |
2127 | 2128 | int err; |
2128 | 2129 |
|
2129 | | - memcpy(ifobj->dst_mac, dst_mac, ETH_ALEN); |
2130 | | - memcpy(ifobj->src_mac, src_mac, ETH_ALEN); |
2131 | | - |
2132 | 2130 | ifobj->func_ptr = func_ptr; |
2133 | 2131 |
|
2134 | 2132 | err = xsk_load_xdp_programs(ifobj); |
@@ -2404,8 +2402,8 @@ int main(int argc, char **argv) |
2404 | 2402 | modes++; |
2405 | 2403 | } |
2406 | 2404 |
|
2407 | | - init_iface(ifobj_rx, MAC1, MAC2, worker_testapp_validate_rx); |
2408 | | - init_iface(ifobj_tx, MAC2, MAC1, worker_testapp_validate_tx); |
| 2405 | + init_iface(ifobj_rx, worker_testapp_validate_rx); |
| 2406 | + init_iface(ifobj_tx, worker_testapp_validate_tx); |
2409 | 2407 |
|
2410 | 2408 | test_spec_init(&test, ifobj_tx, ifobj_rx, 0, &tests[0]); |
2411 | 2409 | tx_pkt_stream_default = pkt_stream_generate(ifobj_tx->umem, DEFAULT_PKT_CNT, MIN_PKT_SIZE); |
|
0 commit comments