From: Geliang Tang <[email protected]>

The first user of send_to_addr_str() is send_udp_packets() in xdp_bonding.
Use sprintf() to generate "addr_str" string from ifindex, sll_halen and
sll_addr, and pass it to send_to_addr_str(). Since IPPROTO_ICMP is used,
set it as opts.proto and pass opts to the helper too.

Use ASSERT_OK_FD() to check the return fd of send_to_addr_str().

Signed-off-by: Geliang Tang <[email protected]>
---
 .../selftests/bpf/prog_tests/xdp_bonding.c    | 20 +++++++------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c 
b/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
index 6d8b54124cb3..5c60268b805c 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
@@ -206,6 +206,9 @@ static void bonding_cleanup(struct skeletons *skeletons)
 
 static int send_udp_packets(int vary_dst_ip)
 {
+       struct network_helper_opts opts = {
+               .proto = IPPROTO_RAW,
+       };
        struct ethhdr eh = {
                .h_source = BOND1_MAC,
                .h_dest = BOND2_MAC,
@@ -213,17 +216,15 @@ static int send_udp_packets(int vary_dst_ip)
        };
        struct iphdr iph = {};
        struct udphdr uh = {};
+       char addr_str[32];
        uint8_t buf[128];
        int i, s = -1;
        int ifindex;
 
-       s = socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW);
-       if (!ASSERT_GE(s, 0, "socket"))
-               goto err;
-
        ifindex = if_nametoindex("bond1");
        if (!ASSERT_GT(ifindex, 0, "get bond1 ifindex"))
                goto err;
+       sprintf(addr_str, "%d %c %s", ifindex, ETH_ALEN, BOND2_MAC_STR);
 
        iph.ihl = 5;
        iph.version = 4;
@@ -237,13 +238,6 @@ static int send_udp_packets(int vary_dst_ip)
        iph.check = 0;
 
        for (i = 1; i <= NPACKETS; i++) {
-               int n;
-               struct sockaddr_ll saddr_ll = {
-                       .sll_ifindex = ifindex,
-                       .sll_halen = ETH_ALEN,
-                       .sll_addr = BOND2_MAC,
-               };
-
                /* vary the UDP destination port for even distribution with 
roundrobin/xor modes */
                uh.dest++;
 
@@ -255,8 +249,8 @@ static int send_udp_packets(int vary_dst_ip)
                memcpy(buf + sizeof(eh), &iph, sizeof(iph));
                memcpy(buf + sizeof(eh) + sizeof(iph), &uh, sizeof(uh));
 
-               n = sendto(s, buf, sizeof(buf), 0, (struct sockaddr 
*)&saddr_ll, sizeof(saddr_ll));
-               if (!ASSERT_EQ(n, sizeof(buf), "sendto"))
+               s = send_to_addr_str(AF_PACKET, SOCK_RAW, addr_str, 0, buf, 
sizeof(buf), 0, &opts);
+               if (!ASSERT_OK_FD(s, "send_to_addr_str"))
                        goto err;
        }
 
-- 
2.43.0


Reply via email to