From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by mail.toke.dk (Postfix) with ESMTPS id EEB61A17E3D for ; Fri, 7 Jul 2023 21:30:28 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20221208 header.b=XTJck82f Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-569e7aec37bso26090687b3.2 for ; Fri, 07 Jul 2023 12:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688758228; x=1691350228; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=uP/xR8GNlI9E0++CqO6Or9j9eKuQF1wvhQ+qGbLlU6w=; b=XTJck82fPkG97J5gsOeXeYkqH8nCywY1DDfNbK8/nCi8t2cRVkhEjX8VEAXIHg7/Zk 8g6Kh8zn0HGfyoY1rXtGJmMTI79oYlidN/7ViT6Q3c4iAECAx/xkDR5s08nnVFf2T8xK XJtNYubm6/9qj6SSR7ZtaWfPq4QGnkORBbD+Oai538WBbEXAQ63/th5VRP+1HmV7rs00 7YILxTLE9vBCRh/N1XUKP5whua8XBXiOkxXaHkhIYE7CIK8t4v4ilzSXq8lGb48xwd+3 nmpMCdv1klmBA8Kz9Sz43YV66mRNR456QizOykw48EnUtcNoOdbF/J03eMmfAG9PQ1oI /ubQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688758228; x=1691350228; 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=uP/xR8GNlI9E0++CqO6Or9j9eKuQF1wvhQ+qGbLlU6w=; b=PVc3oK4nTsmi0n/VCdyjUytCuD2ZE6gp0gw5tshqwvxgvjs7hWhbUU3XCqHdYKvyOM 7thKS1fH8wppEAZaCe3lgjI4FBH3aMJeua/wuW/FWxhy3uvi0HEX1DzNPwXJEc0JH5Yw XsTgtmF81CksKLU8Ocw6D+LELkExUY7VAFA8sV8zzkVuEdT4jHwR+mO9VXu4OPBVwzt7 DQPd118MZdPxlApJM16hOuojNUV7U8ZX/yWOrCSye5By0Hv6jA3pRm8nsZQVX4U/Ltnu 5g4eAoDWrbLSJEx/zQXbKNI7nNmuppuUyE3Q1N8LELh1jKg2OllnIYFnw61L/oLaDNkX ncCg== X-Gm-Message-State: ABy/qLaAq7+vflH8AZYh2lTnCDaQTCJ+LxsgHchqqG5eBAASpwrH5Rg9 lJU2O2WKeVrrek5b9VyZHKlgqDM= X-Google-Smtp-Source: APBJJlFgJMbRpngCZb0FDr/VhvFmrEwCo2d0zmU6ymIwzLko5drtS0s4gPqFvXqZBR5r/curoHpemlM= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a81:4323:0:b0:56c:e585:8b17 with SMTP id q35-20020a814323000000b0056ce5858b17mr44285ywa.5.1688758227697; Fri, 07 Jul 2023 12:30:27 -0700 (PDT) Date: Fri, 7 Jul 2023 12:30:03 -0700 In-Reply-To: <20230707193006.1309662-1-sdf@google.com> Mime-Version: 1.0 References: <20230707193006.1309662-1-sdf@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230707193006.1309662-12-sdf@google.com> From: Stanislav Fomichev To: bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Message-ID-Hash: CQ236GSPAENSDH4BWDT5NDYK5SKPDVSV X-Message-ID-Hash: CQ236GSPAENSDH4BWDT5NDYK5SKPDVSV X-MailFrom: 302eoZAMKCXAgRTUccUZS.QcalRd-VWbhglRd-dfcXSQh.bSh@flex--sdf.bounces.google.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, kuba@kernel.org, toke@kernel.org, willemb@google.com, dsahern@kernel.org, magnus.karlsson@intel.com, bjorn@kernel.org, maciej.fijalkowski@intel.com, hawk@kernel.org, netdev@vger.kernel.org, xdp-hints@xdp-project.net X-Mailman-Version: 3.3.8 Precedence: list Subject: [xdp-hints] [RFC bpf-next v3 11/14] selftests/bpf: Add helper to query current netns cookie List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Will be used to filter out netdev in AF_XDP metadata selftests. The helper returns netns cookie of the current process. Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/bpf/network_helpers.c | 21 +++++++++++++++++++ tools/testing/selftests/bpf/network_helpers.h | 1 + 2 files changed, 22 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index a105c0cd008a..34102fce5a88 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -450,3 +450,24 @@ int get_socket_local_port(int sock_fd) return -1; } + +#ifndef SO_NETNS_COOKIE +#define SO_NETNS_COOKIE 71 +#endif + +__u64 get_net_cookie(void) +{ + socklen_t optlen; + __u64 optval = 0; + int fd; + + fd = socket(AF_LOCAL, SOCK_DGRAM, 0); + if (fd >= 0) { + optlen = sizeof(optval); + getsockopt(fd, SOL_SOCKET, SO_NETNS_COOKIE, &optval, &optlen); + close(fd); + } + + return optval; +} + diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 694185644da6..380047161aac 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -57,6 +57,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); +__u64 get_net_cookie(void); struct nstoken; /** -- 2.41.0.255.g8b1d071c50-goog