From patchwork Fri Mar 29 19:18:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jordan Rife X-Patchwork-Id: 13610974 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46F7413A879 for ; Fri, 29 Mar 2024 19:20:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711740003; cv=none; b=lHKvMZBWf5TK9PonCPx5n1tMki1cAYsH24JehTvRyZnySH/j90rWFE1REFHS8eltDZZO978M9nGiOXulDRSVAwqV1cnpx1ROOBVYK8ooGEeJTzdT9G0uf6U///wcROjBa/djQH0ZuYLgB6cTomoOyl5gyZWKVrMEFs2ZiJu7WHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711740003; c=relaxed/simple; bh=WvFjbe5Gio5p4zohr/Ppr/b/4wbz85m1gtQran9FEU0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lzJ5djwnodh+3oIHR5eEw5YaQv/QbFE/XpowdZ3/clqtQrQ5MJwx/IeREK6IIHKwx7cgpj7lApSnqoapqc+XJf89rFHAkTqqG4h58ShZzQjGgk9nedGFHWeguDWHPV9t7ZvzGMsDiNCIt2yLPuMEPshTQmixvB7J7PORq/EyDM4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jrife.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TvvCJknS; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jrife.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TvvCJknS" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcc58cddb50so3954330276.0 for ; Fri, 29 Mar 2024 12:20:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711740001; x=1712344801; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SbvV0u8XBY9xDuz2lN6+l2kDTrO5oaEqCBNhNq59mVw=; b=TvvCJknSETV2b5BHoBV+KHircI8RG0r3NWGwFE3P8O2fNVH8UhXhSyYWOs8xHMQwi+ JQcm/rFPV9qi9wcA+Cycz3qFdUQafYOqHgt7tcWjRmadeCspMxquKCarJlP/2Tt0gPyK vWBWsxJQVSYM2mQvfjpCnxIrozNIs1BqOlq0MMzjIL5TMfH1N+yqPtXN0G+CVKEBPePq mkDZI56i3WlEsh/Xdis8+3OyY5ZQE9BCFrRSqwID+0yRUt2ulb95t6T99qGGG9+ehzyQ ggprjrdAJgvVv0YtvPFnyS2ECmQzTXvgAF2wG/UoAlO5rA3wISh+LLYNTrg9KKpWV6Vu VIdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711740001; x=1712344801; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SbvV0u8XBY9xDuz2lN6+l2kDTrO5oaEqCBNhNq59mVw=; b=nL2Gdf9jC3CbxtMHnGPuMUSdNnIDH8a7OW2+MC//HyEwTO2oy74jZ0K7ynxZvSPgcm Ca1Y6ABxSnKxF5sjIp8SpYlT4eusJZCdWxYU5+aGZRFXMm5FaBiLJfGEkIdLORVtLpds HxWoxGCU5BO2hkbNGrNrVWGU4+QvoSz6VYYtnY974MbTaNCipG4Gwnz+sbzeoIvjuYHJ sJmLurPYXtJONHM+ASRdIW8O0Szq9cL44j5xko4ChBTfP0IHU2iEVx7jdh/EVKgkJ77y TwOIFa2RqQ9/6bN/4xb1ARxiPjDf2HWsHXqthjn9gWNzO9UluQQ95M1HilTh7ychrqnr zycQ== X-Gm-Message-State: AOJu0Yw6tE4qHgbjg1OjEyNL+ImMtmZFsqdgkKKseERh7FHI+lSv+bvw HV28bGp7Nlm9QFC77iwwDM9WrrNCpIjIkYlNAyhXibz8txCm4nh+avX9r8iYT00EIVXR6IBaGBj u93ZlkTCUjcqvRJeNUS7xr+8JcinfdOd7WjJZVgzraVdurfiN0xgIPAjLFJ1Z4krR4/1JVwfPMe 3Mk20ZakbAR2LjBG7eDrTQM7o= X-Google-Smtp-Source: AGHT+IHV9/yL97+mJdhDWN8bvqgaKmZP0Anot8i5ZOBRqXEQJ86jHkPNBbIG+1NcaUZYkN/9StR9FKyYew== X-Received: from jrife.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:9f]) (user=jrife job=sendgmr) by 2002:a05:6902:2404:b0:dcc:5a91:aee9 with SMTP id dr4-20020a056902240400b00dcc5a91aee9mr893141ybb.7.1711740000986; Fri, 29 Mar 2024 12:20:00 -0700 (PDT) Date: Fri, 29 Mar 2024 14:18:49 -0500 In-Reply-To: <20240329191907.1808635-1-jrife@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240329191907.1808635-1-jrife@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240329191907.1808635-5-jrife@google.com> Subject: [PATCH v1 bpf-next 4/8] selftests/bpf: Add recv_msg_from_client to network helpers From: Jordan Rife To: bpf@vger.kernel.org Cc: Jordan Rife , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , Daan De Meyer X-Patchwork-Delegate: bpf@iogearbox.net Copy recv_msg_from_client helper from test_sock_addr self test in order to use it in the sock_addr_kern test program. Signed-off-by: Jordan Rife --- tools/testing/selftests/bpf/network_helpers.c | 31 +++++++++++++++++++ tools/testing/selftests/bpf/network_helpers.h | 1 + 2 files changed, 32 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 8eae4afe3ec3d..ef0a94d9e9d5c 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -498,6 +498,37 @@ int get_socket_local_port(int sock_fd) return -1; } +int recvmsg_from_client(int sockfd, struct sockaddr_storage *src_addr) +{ + struct timeval tv; + struct msghdr hdr; + struct iovec iov; + char data[64]; + fd_set rfds; + + FD_ZERO(&rfds); + FD_SET(sockfd, &rfds); + + tv.tv_sec = 2; + tv.tv_usec = 0; + + if (select(sockfd + 1, &rfds, NULL, NULL, &tv) <= 0 || + !FD_ISSET(sockfd, &rfds)) + return -1; + + memset(&iov, 0, sizeof(iov)); + iov.iov_base = data; + iov.iov_len = sizeof(data); + + memset(&hdr, 0, sizeof(hdr)); + hdr.msg_name = src_addr; + hdr.msg_namelen = sizeof(struct sockaddr_storage); + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + + return recvmsg(sockfd, &hdr, 0); +} + int cmp_addr(const struct sockaddr_storage *addr1, socklen_t addr1_len, const struct sockaddr_storage *addr2, socklen_t addr2_len, bool cmp_port) diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index a4a458c858d59..f88f2470e3fcb 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -61,6 +61,7 @@ int make_sockaddr(int family, const char *addr_str, __u16 port, struct sockaddr_storage *addr, socklen_t *len); char *ping_command(int family); int get_socket_local_port(int sock_fd); +int recvmsg_from_client(int sockfd, struct sockaddr_storage *src_addr); int cmp_addr(const struct sockaddr_storage *addr1, socklen_t addr1_len, const struct sockaddr_storage *addr2, socklen_t addr2_len, bool cmp_port);