Skip to content

Commit 985fd21

Browse files
tvyavahaborkmann
authored andcommitted
selftests/xsk: Move src_mac and dst_mac to the xsk_socket_info
Move the src_mac and dst_mac fields from the ifobject structure to the xsk_socket_info structure to achieve per-socket MAC address assignment. Require this in order to steer traffic to various sockets in subsequent patches. Signed-off-by: Tushar Vyavahare <tushar.vyavahare@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Magnus Karlsson <magnus.karlsson@intel.com> Link: https://lore.kernel.org/bpf/20230927135241.2287547-4-tushar.vyavahare@intel.com
1 parent 93ba112 commit 985fd21

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

tools/testing/selftests/bpf/xskxceiver.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@
104104
#include "../kselftest.h"
105105
#include "xsk_xdp_common.h"
106106

107-
static const char *MAC1 = "\x00\x0A\x56\x9E\xEE\x62";
108-
static const char *MAC2 = "\x00\x0A\x56\x9E\xEE\x61";
109-
110107
static bool opt_verbose;
111108
static bool opt_print_tests;
112109
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)
159156
ptr[i] = htonl(pkt_nb << 16 | (i + start));
160157
}
161158

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)
163160
{
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);
166163
eth_hdr->h_proto = htons(ETH_P_LOOPBACK);
167164
}
168165

@@ -445,6 +442,11 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
445442
ifobj->xsk_arr[j].pkt_stream = test->tx_pkt_stream_default;
446443
else
447444
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);
448450
}
449451
}
450452

@@ -726,16 +728,16 @@ static void pkt_stream_cancel(struct pkt_stream *pkt_stream)
726728
pkt_stream->current_pkt_nb--;
727729
}
728730

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)
731733
{
732-
void *data = xsk_umem__get_data(ifobject->umem->buffer, addr);
734+
void *data = xsk_umem__get_data(umem->buffer, addr);
733735

734736
if (len < MIN_PKT_SIZE)
735737
return;
736738

737739
if (!bytes_written) {
738-
gen_eth_hdr(ifobject, data);
740+
gen_eth_hdr(xsk, data);
739741

740742
len -= PKT_HDR_SIZE;
741743
data += PKT_HDR_SIZE;
@@ -1209,7 +1211,7 @@ static int __send_pkts(struct ifobject *ifobject, struct pollfd *fds, bool timeo
12091211
tx_desc->options = 0;
12101212
}
12111213
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,
12131215
bytes_written);
12141216
bytes_written += tx_desc->len;
12151217

@@ -2120,15 +2122,11 @@ static bool hugepages_present(void)
21202122
return true;
21212123
}
21222124

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)
21252126
{
21262127
LIBBPF_OPTS(bpf_xdp_query_opts, query_opts);
21272128
int err;
21282129

2129-
memcpy(ifobj->dst_mac, dst_mac, ETH_ALEN);
2130-
memcpy(ifobj->src_mac, src_mac, ETH_ALEN);
2131-
21322130
ifobj->func_ptr = func_ptr;
21332131

21342132
err = xsk_load_xdp_programs(ifobj);
@@ -2404,8 +2402,8 @@ int main(int argc, char **argv)
24042402
modes++;
24052403
}
24062404

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);
24092407

24102408
test_spec_init(&test, ifobj_tx, ifobj_rx, 0, &tests[0]);
24112409
tx_pkt_stream_default = pkt_stream_generate(ifobj_tx->umem, DEFAULT_PKT_CNT, MIN_PKT_SIZE);

tools/testing/selftests/bpf/xskxceiver.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#define HUGEPAGE_SIZE (2 * 1024 * 1024)
6060
#define PKT_DUMP_NB_TO_PRINT 16
6161
#define RUN_ALL_TESTS UINT_MAX
62+
#define NUM_MAC_ADDRESSES 4
6263

6364
#define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0)
6465

@@ -90,6 +91,8 @@ struct xsk_socket_info {
9091
struct pkt_stream *pkt_stream;
9192
u32 outstanding_tx;
9293
u32 rxqsize;
94+
u8 dst_mac[ETH_ALEN];
95+
u8 src_mac[ETH_ALEN];
9396
};
9497

9598
struct pkt {
@@ -140,8 +143,6 @@ struct ifobject {
140143
bool unaligned_supp;
141144
bool multi_buff_supp;
142145
bool multi_buff_zc_supp;
143-
u8 dst_mac[ETH_ALEN];
144-
u8 src_mac[ETH_ALEN];
145146
};
146147

147148
struct test_spec {
@@ -168,4 +169,6 @@ pthread_mutex_t pacing_mutex = PTHREAD_MUTEX_INITIALIZER;
168169

169170
int pkts_in_flight;
170171

172+
static const u8 g_mac[ETH_ALEN] = {0x55, 0x44, 0x33, 0x22, 0x11, 0x00};
173+
171174
#endif /* XSKXCEIVER_H_ */

0 commit comments

Comments
 (0)