From patchwork Sat Jul 13 05:55:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13732304 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (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 ABA611CAB5 for ; Sat, 13 Jul 2024 05:56:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850176; cv=none; b=Nhlg5IOwocsi7nHq/LXKO92lES70oTI0SwWpAS0vz6VTH0ljHwY1nMK6eyNElL/Pw39v/4dOOH2d/64Hz0GY/fJMOEcYflynaCf4xzjIurVqK2DMpFqS8m5KTiqYrY7dR9ZuNRHLAW8eCl3wIl6sgFloCqJZDYlH41lEVOpiX+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850176; c=relaxed/simple; bh=MEyjrM9VGJUQBd/B9NZhBJDoxpMXlgJazNUySD3I4Ls=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jJyZHqhvnyPPcA9FHK5F8C6BGD4/3PKSBCJY2zHqhcpsfbOvydjcr+6uGhfUsNVmb/3IRq3OcKz/TPTICm6dHsHOyVokxV99xjNwD1PmzSvRpudSxh+SC24VWv5zk4NgmZwNijbSoppHy7pVV9NwwEXXgUVsVzNZ4OkP+uDuKyg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PsuqZGuR; arc=none smtp.client-ip=209.85.219.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PsuqZGuR" Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e057ae1adbeso2070398276.0 for ; Fri, 12 Jul 2024 22:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850173; x=1721454973; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X4jrDVvRScQJn3SQpX4VDmp2a9Cda2Pz6eZWzHp+x6I=; b=PsuqZGuRT/fK5+XeqvLVms5ChGOVEcMN1DWiANEPy7WPKskv97tCH/PaeSA1L3g8xj bftdGmRSiZka2m3Ms+X9Jy81y6Jz50Phk/Mz6BA/w8vX0LZjRSTBzhid5N+QoqWnBcIw TI47RnBpB+KNUbQwtVscwfANxqziuLedMokslPD/SNriAOxmnvQT+2J+xJSlKX1hDr6N 0sqRinWk94bXJ3DH9AmaQHNifS0DdtUgb6ePkYS7HgttwPE73NqEYuciQHn635Okvt+K BXPkYURBfs6iSkVfgM2H6QDEnkJGNXMYfO7KeCG9/RVD5S1sN/SOo1cMUkiDV4Xfx0zE CXqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850173; x=1721454973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X4jrDVvRScQJn3SQpX4VDmp2a9Cda2Pz6eZWzHp+x6I=; b=Huh5+Ydsha+FMsPwImUnNf4dBvLq5jzpxNYB1rxbP/9nFjKXoyJYYTyxv+i3CiuNIl rgDGeXHlAlJFjbKRFO7nH3RfOsSJWYkZMCHA0gO252A1ZhA+6SHaIm5xiKnDPUJgYspq 66YmosQea13yXBW/Tx1c1ggUwqijPqjgdWAiOp6QUsLZZQel2gA8oytOznT/bYE+zidh YNEZZg3IMotvi67L+WX7sHqNEEsBiIMc0guRiJeM6X9JUN6bJe+98qrtjVedqxyuWRqU RdgPDxV6ytbRyUmrsOZFSHqZ3YZ0yAjKln1+RQNTp1plcWX9IkEwQDxiMKuVOnBHugV8 xPRA== X-Gm-Message-State: AOJu0Yzxv3FzIExYbU4uvBIi2lqohwNMTFJ+pcDHVTXIxiH4O0JeSB2r nOt1z0r2PJa0ZT+TJFzBufC4tYpahK9YkVpgqZnW/MS4wln2EVcyrwr1j6CU X-Google-Smtp-Source: AGHT+IE9rlR19YZpjdMFqmdNlZnhr3T/ZvDvax47lRFek8iSesd2EQRJtkLHQgwIvfEAhcXuBqaS9g== X-Received: by 2002:a0d:ea47:0:b0:65f:7c41:30b2 with SMTP id 00721157ae682-65f7c413160mr7015097b3.3.1720850173462; Fri, 12 Jul 2024 22:56:13 -0700 (PDT) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1e:9d09:4e82:b45e]) by smtp.gmail.com with ESMTPSA id 00721157ae682-65fc445165dsm761927b3.105.2024.07.12.22.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:56:13 -0700 (PDT) From: Kui-Feng Lee To: bpf@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, song@kernel.org, kernel-team@meta.com, andrii@kernel.org Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH bpf-next 1/4] selftests/bpf: Add traffic monitor functions. Date: Fri, 12 Jul 2024 22:55:49 -0700 Message-Id: <20240713055552.2482367-2-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055552.2482367-1-thinker.li@gmail.com> References: <20240713055552.2482367-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Add functions that run tcpdump in the background, report the traffic log captured by tcpdump, and stop tcpdump. They are supposed to be used for debugging flaky network test cases. A monitored test case should call traffic_monitor_start() to start a tcpdump process in the background for a given namespace, call traffic_monitor_report() to print the log from tcpdump, and call traffic_monitor_stop() to shutdown the tcpdump process. Signed-off-by: Kui-Feng Lee --- tools/testing/selftests/bpf/network_helpers.c | 244 ++++++++++++++++++ tools/testing/selftests/bpf/network_helpers.h | 5 + 2 files changed, 249 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 44c2c8fa542a..cf0e03f3b95c 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include @@ -575,6 +577,248 @@ int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param) return 0; } +struct tmonitor_ctx { + pid_t pid; + const char *netns; + char log_name[PATH_MAX]; +}; + +/* Make sure that tcpdump has handled all previous packets. + * + * Send one or more UDP packets to the loopback interface. The packet + * contains a mark string. The mark is used to check if tcpdump has handled + * the packet. The function waits for tcpdump to print a message for the + * packet containing the mark (by checking the payload length and the + * destination). This is not a perfect solution, but it should be enough + * for testing purposes. + * + * log_name is the file name where tcpdump writes its output. + * mark is the string that is sent in the UDP packet. + * repeat specifies if the function should send multiple packets. + * + * Device "lo" should be up in the namespace for this to work. This + * function should be called in the same network namespace as a + * tmonitor_ctx created for in order to create a socket for sending mark + * packets. + */ +static int traffic_monitor_sync(const char *log_name, const char *mark, + bool repeat) +{ + const int max_loop = 1000; /* 10s */ + char mark_pkt_pattern[64]; + struct sockaddr_in addr; + int sock, log_fd, rd_pos = 0; + int pattern_size; + struct stat st; + char buf[4096]; + int send_cnt = repeat ? max_loop : 1; + bool found; + int i, n; + + sock = socket(AF_INET, SOCK_DGRAM, 0); + if (sock < 0) { + log_err("Failed to create socket"); + return -1; + } + + /* Check only the destination and the payload length */ + pattern_size = snprintf(mark_pkt_pattern, sizeof(mark_pkt_pattern), + " > 127.0.0.241.4321: UDP, length %ld", + strlen(mark)); + + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = inet_addr("127.0.0.241"); + addr.sin_port = htons(4321); + + /* Wait for the log file to be created */ + for (i = 0; i < max_loop; i++) { + log_fd = open(log_name, O_RDONLY); + if (log_fd >= 0) { + fstat(log_fd, &st); + rd_pos = st.st_size; + break; + } + usleep(10000); + } + /* Wait for the mark packet */ + for (found = false; i < max_loop && !found; i++) { + if (send_cnt-- > 0) { + /* Send an UDP packet */ + if (sendto(sock, mark, strlen(mark), 0, + (struct sockaddr *)&addr, + sizeof(addr)) != strlen(mark)) + log_err("Failed to sendto"); + } + + usleep(10000); + fstat(log_fd, &st); + /* Check the content of the log file */ + while (rd_pos + pattern_size <= st.st_size) { + lseek(log_fd, rd_pos, SEEK_SET); + n = read(log_fd, buf, sizeof(buf) - 1); + if (n < pattern_size) + break; + buf[n] = 0; + if (strstr(buf, mark_pkt_pattern)) { + found = true; + break; + } + rd_pos += n - pattern_size + 1; + } + } + + close(log_fd); + close(sock); + + if (!found) { + log_err("Waited too long for synchronizing traffic monitor"); + return -1; + } + + return 0; +} + +/* Start a tcpdump process to monitor traffic. + * + * netns specifies what network namespace you want to monitor. It will + * monitor the current namespace if netns is NULL. + */ +struct tmonitor_ctx *traffic_monitor_start(const char *netns) +{ + struct tmonitor_ctx *ctx = NULL; + struct nstoken *nstoken = NULL; + char log_name[PATH_MAX]; + int status, log_fd; + pid_t pid; + + if (netns) { + nstoken = open_netns(netns); + if (!nstoken) + return NULL; + } + + pid = fork(); + if (pid < 0) { + log_err("Failed to fork"); + goto error; + } + + if (pid == 0) { + /* Child */ + pid = getpid(); + snprintf(log_name, sizeof(log_name), "/tmp/tmon_tcpdump_%d.log", pid); + log_fd = open(log_name, O_WRONLY | O_CREAT | O_TRUNC, 0644); + dup2(log_fd, STDOUT_FILENO); + dup2(log_fd, STDERR_FILENO); + if (log_fd != STDOUT_FILENO && log_fd != STDERR_FILENO) + close(log_fd); + + /* -n don't convert addresses to hostnames. + * + * --immediate-mode handle captured packets immediately. + * + * -l print messages with line buffer. With this option, + * the output will be written at the end of each line + * rather than when the output buffer is full. This is + * needed to sync with tcpdump efficiently. + */ + execlp("tcpdump", "tcpdump", "-i", "any", "-n", "--immediate-mode", "-l", NULL); + log_err("Failed to exec tcpdump"); + exit(1); + } + + ctx = malloc(sizeof(*ctx)); + if (!ctx) { + log_err("Failed to malloc ctx"); + goto error; + } + + ctx->pid = pid; + ctx->netns = netns; + snprintf(ctx->log_name, sizeof(ctx->log_name), "/tmp/tmon_tcpdump_%d.log", pid); + + /* Wait for tcpdump to be ready */ + if (traffic_monitor_sync(ctx->log_name, "hello", true)) { + status = 0; + if (waitpid(pid, &status, WNOHANG) >= 0 && + !WIFEXITED(status) && !WIFSIGNALED(status)) + log_err("Wait too long for tcpdump"); + else + log_err("Fail to start tcpdump"); + goto error; + } + + close_netns(nstoken); + + return ctx; + +error: + close_netns(nstoken); + if (pid > 0) { + kill(pid, SIGTERM); + waitpid(pid, NULL, 0); + snprintf(log_name, sizeof(log_name), "/tmp/tmon_tcpdump_%d.log", pid); + unlink(log_name); + } + free(ctx); + + return NULL; +} + +void traffic_monitor_stop(struct tmonitor_ctx *ctx) +{ + if (!ctx) + return; + kill(ctx->pid, SIGTERM); + /* Wait the tcpdump process in case that the log file is created + * after this line. + */ + waitpid(ctx->pid, NULL, 0); + unlink(ctx->log_name); + free(ctx); +} + +/* Report the traffic monitored by tcpdump. + * + * The function reads the log file created by tcpdump and writes the + * content to stderr. + */ +void traffic_monitor_report(struct tmonitor_ctx *ctx) +{ + struct nstoken *nstoken = NULL; + char buf[4096]; + int log_fd, n; + + if (!ctx) + return; + + /* Make sure all previous packets have been handled by + * tcpdump. + */ + if (ctx->netns) { + nstoken = open_netns(ctx->netns); + if (!nstoken) { + log_err("Failed to open netns: %s", ctx->netns); + goto out; + } + } + traffic_monitor_sync(ctx->log_name, "sync for report", false); + close_netns(nstoken); + + /* Read the log file and write to stderr */ + log_fd = open(ctx->log_name, O_RDONLY); + if (log_fd < 0) { + log_err("Failed to open log file"); + return; + } + + while ((n = read(log_fd, buf, sizeof(buf))) > 0) + fwrite(buf, n, 1, stderr); + +out: + close(log_fd); +} + struct send_recv_arg { int fd; uint32_t bytes; diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 9ea36524b9db..d757e495fb39 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -72,6 +72,11 @@ int get_socket_local_port(int sock_fd); int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param); int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param); +struct tmonitor_ctx; +struct tmonitor_ctx *traffic_monitor_start(const char *netns); +void traffic_monitor_stop(struct tmonitor_ctx *ctx); +void traffic_monitor_report(struct tmonitor_ctx *ctx); + struct nstoken; /** * open_netns() - Switch to specified network namespace by name. From patchwork Sat Jul 13 05:55:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13732305 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) (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 ACA7028689 for ; Sat, 13 Jul 2024 05:56:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850177; cv=none; b=H6+7fqDPKgSIa9pZ0hEYlVJZTuklQitu8dlppW3lOrgwqMU/W9M2v/GXIu/m4IlCUc+hewqxGVnDhUWlgGwMWZ+MG/6aNY4RmrKcSGvdYN4tw96UnWwCsWISNIZkIv+023zXe0WnnDa0U5hcawjAQmKrVMIDR/WeAFheRvILPQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850177; c=relaxed/simple; bh=7khdQnEJ0ug3UX1cbBYgoEiTvh2APvh8tRPXDUxKH6s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nv/h/YWQ115W/NmMyd/bgnB660SKksznvOhF6fPOd0TXXbmlfLFRAO6tNPpRk2oAclBonodNZ3V+rUEBWA0YBJ3aimefnyT2tJXs9VTeHRV5wiqkIw15x9qSQJDsLzVLl3KM7sDSpKPTEP5yQR45yK1IaHno+wtnEWSYG6aryBY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=b2xxOnfK; arc=none smtp.client-ip=209.85.128.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b2xxOnfK" Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-6510c0c8e29so25766927b3.0 for ; Fri, 12 Jul 2024 22:56:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850174; x=1721454974; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vygrSp4r5MkVvW5GrKzhp80O2jMP7V18WOP+Br2r2Tc=; b=b2xxOnfKOdH0IxbptLZQtsz3Q/SF9g2ZOyNIQqerd1TqF/yG4cVXG0VYsSoewZh3+n ywE6skLWBRWLY8klXgBUVDzg9rXKu7jj3hu/NMS+c/UjpN0NtfRGwFVwxJ4s3j4xwErL IfzDzhVy+K5sxm2YDDrP0oDDnCJLYwH4bm9dp4ZnAjaZINcbfaw/Jww0Xp+yk4UnnlGu qwYVxmWg2X2yHzgLp3rlhEcNmdH+nA4r/MzvjeJQFNXc6Qdl+cT1H1kkKafWfUTkFAyg lCsWA+JW96qbCS3E85H/74qQ/akcnhCauMqoCH7zLca+W/Z+Mfxq5lC7HTv4zQyJL7P3 2t/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850174; x=1721454974; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vygrSp4r5MkVvW5GrKzhp80O2jMP7V18WOP+Br2r2Tc=; b=fza+VownLeVXLpxZPrt9xSTjGBm6iAO/FIWa6dTzmjVm3DEyMm5mOv2tRG+bQYB8aH 0lCvsmoJJ9/O3boPVBKM/Q57tQ7pymigDEyag3UhEm3Fv7AQdcoPWaaI16DhCyZSZSp7 vAr2dFIzbx4TljUZUXfuL7gtRsAsBZynx+jOpgEShqTWi5b9aQ8IDK/OI2+4PuDnBZkc CIdR2b1oTs/ILniGoDXUfb1v0Nr6pJIQdYOhQ5oGmN/T1mSu2H0pi06fqbfBWPNB+Y7b NfvqWx1Z0ylRf/J1UCzTpY4XiCg1vY4PbJL9qrkX8GIzHxvd+WlmB+bCODWpqw1W3LjI VVuA== X-Gm-Message-State: AOJu0Yz9NY6hePzCOeRYfc/ffQgC6VFnwkHXGCjJ4XZaUjv3KutSING9 /UdkP0lw4erdqs8vSFhHxnjDctNwpOf0DQ5S3+Tf5sXRGLF71Ivin98MGcya X-Google-Smtp-Source: AGHT+IFCgMWXh2B9PSfNdtEQYGYfg1XjiHm8QpZrR/9FZvCbBUUtNmgue6PHXNYuOMPm4a1L/fiSxQ== X-Received: by 2002:a05:690c:6c84:b0:652:e90f:cd15 with SMTP id 00721157ae682-658ef34123amr159729057b3.25.1720850174556; Fri, 12 Jul 2024 22:56:14 -0700 (PDT) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1e:9d09:4e82:b45e]) by smtp.gmail.com with ESMTPSA id 00721157ae682-65fc445165dsm761927b3.105.2024.07.12.22.56.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:56:14 -0700 (PDT) From: Kui-Feng Lee To: bpf@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, song@kernel.org, kernel-team@meta.com, andrii@kernel.org Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH bpf-next 2/4] selftests/bpf: Monitor traffic for tc_redirect/tc_redirect_dtime. Date: Fri, 12 Jul 2024 22:55:50 -0700 Message-Id: <20240713055552.2482367-3-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055552.2482367-1-thinker.li@gmail.com> References: <20240713055552.2482367-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Enable traffic monitoring for the test case tc_redirect/tc_redirect_dtime. The traffic log is only printed when the subtest fails. Signed-off-by: Kui-Feng Lee --- tools/testing/selftests/bpf/prog_tests/tc_redirect.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/tc_redirect.c b/tools/testing/selftests/bpf/prog_tests/tc_redirect.c index 327d51f59142..345f8ce93b29 100644 --- a/tools/testing/selftests/bpf/prog_tests/tc_redirect.c +++ b/tools/testing/selftests/bpf/prog_tests/tc_redirect.c @@ -900,6 +900,7 @@ static void test_udp_dtime(struct test_tc_dtime *skel, int family, bool bpf_fwd) static void test_tc_redirect_dtime(struct netns_setup_result *setup_result) { struct test_tc_dtime *skel; + struct tmonitor_ctx *tmon = NULL; struct nstoken *nstoken; int hold_tstamp_fd, err; @@ -934,6 +935,9 @@ static void test_tc_redirect_dtime(struct netns_setup_result *setup_result) if (!ASSERT_OK(err, "disable forwarding")) goto done; + tmon = traffic_monitor_start(NS_DST); + ASSERT_NEQ(tmon, NULL, "traffic_monitor_start"); + test_tcp_clear_dtime(skel); test_tcp_dtime(skel, AF_INET, true); @@ -958,6 +962,9 @@ static void test_tc_redirect_dtime(struct netns_setup_result *setup_result) test_udp_dtime(skel, AF_INET6, false); done: + if (env.subtest_state->error_cnt) + traffic_monitor_report(tmon); + traffic_monitor_stop(tmon); test_tc_dtime__destroy(skel); close(hold_tstamp_fd); } From patchwork Sat Jul 13 05:55:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13732306 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 D366443ADE for ; Sat, 13 Jul 2024 05:56:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850178; cv=none; b=OB54qD2hKufNIky5PefQBIYAGPSwT9NPffHNNwKbmL56ScYM9y1TVpRzw8lRj8bgpeekSOtqfVhFc/kdZUbg0h+Ti23EKCAVdoBWtGqh+YSRTAxJQ1RLBE/RmKIbgHUllWoywVENg+Sjd8X+6+L9prmUM8cykM/OZj3VlP+3Xgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850178; c=relaxed/simple; bh=5UB+H7afer7Q1F/cRx1O9WOZqOcKTx6nxD7GHnP5t1c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=vBW1fR9ghM+mRzeUroQScR0RnlLN2+XvlgTWjQ54odYx80QDk/mQdCxyXJeNqnM8Vybx0Sd2JA7oaAUK6/PR4jQghiwMqbv0sQ+GggeQIHjcswpi8Vyuc26silK+lt7ZNUcF6A/jrSuDaY0G0E5c35kIWzbs3aiFOngGmRyyLG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c6R0mo1g; arc=none smtp.client-ip=209.85.128.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c6R0mo1g" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-65cd720cee2so24356957b3.1 for ; Fri, 12 Jul 2024 22:56:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850176; x=1721454976; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=65cVLOLQcbcCMiFNilAC6jq20HN1woAX0MoCJC3+7Ns=; b=c6R0mo1g9BiHWzYnP3UzDzc/q5hgLuJK9Odguclyc867yB90FmnqpL8riZWcrIkRkY tADcPIarojttEt+0G8ReaSrB3LLvOVFGSUWcjh+0RZ9q5Br5KZi6PmVw0MS6Xxlvg/Hx +sp3/0YK4uQM8r7ATIPdr1QzHWDol9z6qNVDglPO9WyLJ69pjizNKmtEseu7C/ywCxix MH6Z+2XVRYFPTHgR/uxYWnt31b98W1AzzO+y1q0/m3x0fceC+Cw4Rvk4u3Dol+fBuXox H08tOOAt1Zobdqzd+2YVtkzkpSYo5tM1mOx0bnfn2G+PqwAwXIHFd2YY5Irxj0ttYG6b qCzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850176; x=1721454976; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=65cVLOLQcbcCMiFNilAC6jq20HN1woAX0MoCJC3+7Ns=; b=e9vv6dDLYhLAbHmy+UHODQ0J+6gBEolbgaDbIMgEoDhL336fcx9tA38iQBpYX4W9YE /euU4CB+OGzX9GragacTUCV4qAwktBnuarAsASXahgGJMqwhLbnmP2VmkpEZDzTEahMv Y6k8X0Yt7TFwOY0Dg6JxCiI7UqGaquTyoDm1EJX1b2dasV1UNpLjOsXr+fBoXvEkoP7s yBgLpQrzZ5iqR0GOLe52Mxc6A4ffgiDEWxiVURWFxF2nHN8XHcxuKa+cKCWjJ2DcWgPz lxNJ0mvPTWFia+qErj/Ko6unzgELdu+QK6t4+wLDmKgijQOhSgvX4n+6UQE3cYLzHkZP CPlg== X-Gm-Message-State: AOJu0Yx8Qeq+wlzY7Fc8mqZiI6Rc/CspH2LAvsKkp8wdG9ReVSwARegf MbHSRVs8NYdMLm68E4Zd2G7vg1vVjzfWMHzMgaMGTvdByehRzipLPb1a3w3r X-Google-Smtp-Source: AGHT+IGIz2dY8fjKUXGjpaVNnTNr7CawK7GI4VGXv3FS0/KgT45h26zLHgUhOk7purt08uaaiYTi5A== X-Received: by 2002:a05:690c:648a:b0:64b:14bf:2fcf with SMTP id 00721157ae682-658ee79084fmr179437727b3.8.1720850175772; Fri, 12 Jul 2024 22:56:15 -0700 (PDT) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1e:9d09:4e82:b45e]) by smtp.gmail.com with ESMTPSA id 00721157ae682-65fc445165dsm761927b3.105.2024.07.12.22.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:56:15 -0700 (PDT) From: Kui-Feng Lee To: bpf@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, song@kernel.org, kernel-team@meta.com, andrii@kernel.org Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH bpf-next 3/4] selftests/bpf: Monitor traffic for sockmap_listen. Date: Fri, 12 Jul 2024 22:55:51 -0700 Message-Id: <20240713055552.2482367-4-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055552.2482367-1-thinker.li@gmail.com> References: <20240713055552.2482367-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Enable traffic monitor for each subtest of sockmap_listen. A subtest prints the traffic log only if it fails. Signed-off-by: Kui-Feng Lee --- .../testing/selftests/bpf/prog_tests/sockmap_listen.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c index e91b59366030..617d73671a90 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c @@ -28,6 +28,7 @@ #include "test_sockmap_listen.skel.h" #include "sockmap_helpers.h" +#include "network_helpers.h" static void test_insert_invalid(struct test_sockmap_listen *skel __always_unused, int family, int sotype, int mapfd) @@ -1893,14 +1894,23 @@ static void test_udp_unix_redir(struct test_sockmap_listen *skel, struct bpf_map { const char *family_name, *map_name; char s[MAX_TEST_NAME]; + struct tmonitor_ctx *tmon; family_name = family_str(family); map_name = map_type_str(map); snprintf(s, sizeof(s), "%s %s %s", map_name, family_name, __func__); if (!test__start_subtest(s)) return; + + tmon = traffic_monitor_start(NULL); + ASSERT_TRUE(tmon, "traffic_monitor_start"); + inet_unix_skb_redir_to_connected(skel, map, family); unix_inet_skb_redir_to_connected(skel, map, family); + + if (env.subtest_state->error_cnt) + traffic_monitor_report(tmon); + traffic_monitor_stop(tmon); } static void run_tests(struct test_sockmap_listen *skel, struct bpf_map *map, From patchwork Sat Jul 13 05:55:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13732307 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (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 D898C45945 for ; Sat, 13 Jul 2024 05:56:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850179; cv=none; b=s9hv/7mm3Sb0fKGkZ/1MZdStyzM86weHtqpsfu5Fdl6VefToC0zjk/6g2dun5LZ7sdD7Sg7rP2lKhKtaMEjvDsSX7ZQqg/kFjtJAtdlAdpgJHz2JWJpN6LCTeslXRo/sDp5zwa3SzsWV5ne0oqcMlgFnWeCB/GWbS1UAjbw6eBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850179; c=relaxed/simple; bh=/PCfE3BTYZYNQYmPCbC+tDIFS7AphJIHGF3r2T1S7H4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C/vs/DTHq+skP4GU4GA7sVrqtey+Xb/rtn3LVdj8lRfa8kybp7jxHTw6sq/UUBu/H1/GVxS2BLlf6IoD44R+nj8gR+hR3Be53qcsyFPFmtnuOwfoHUPANHlA6l3z+4VIJbH/GeeqEvt6QHpmRcGQrrBIrF47vII5nbTLs1mR/Oc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Lg0CQ5cM; arc=none smtp.client-ip=209.85.128.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Lg0CQ5cM" Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-64b29539d86so24624107b3.2 for ; Fri, 12 Jul 2024 22:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850177; x=1721454977; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dyk8Zo+IJe2i1qbmhcGTVbWi2DljTxMOeCNJyTmtkME=; b=Lg0CQ5cMMO8ezXcvVyzWx7QPl6xNEOfG6E+c50pFaWLBOYqIQJM9HUX+EQzV65Y8SI Ok/5JrCVnOhlyWzaP4t67kJygytuIJxJ1tQP/j3xUBvl/A1tzQ9rBiPiG9mGT4q4dSw/ mLzM2VE4SpGewMeUEoz+BFl1JDtruu/g616ouPbfCroDPTe/B8MPYLx1bZa7Rksfluq8 yrTL3/KGgCPL2fcl0ZzLW4vstDbYSBpissmj9CjCsib7D4wzbcB7VCxJ+wzPCr0FVxid +Xdnl7HK4ORhuqBCRlh4DaBVmz7xkYGuTUOTn5AhAP8Gjz/Ls9O6/1H422o1leJlMD2G OJfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850177; x=1721454977; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dyk8Zo+IJe2i1qbmhcGTVbWi2DljTxMOeCNJyTmtkME=; b=HmA2VE1xsZ9Fm5Ms/lYEi4cg1uVwXVIwPY+dOPyHJUWIeD8CSxWpd7ifYjkcYro/pO ZYDU4U5VBGFLOcdJhS2MmHsX2SrQmxbHFwrckHjeUSzx5GE73jgnpIh9tCyhGU7NSV6b BPPTAccWqWOwcZwxBGGUgeBSlhtAN7XYaQPS/9v/I7FGRh7DgwkVG1qOhyYr6w4RTDbF hriJncysvYwQ4+wMGwzXwvAW7TjdM2jKH3QYXWtuTDxBwSLtHDLkxclROQylCXhkCbwF 8m59N9Ur//sXRIjzHvwO5afsxuYnfiy3mUryZaXBnpY8MQ5TBTHlyZQwDzbE+YcFonzo eDNw== X-Gm-Message-State: AOJu0YwW6gkR28XtRT0kXCwtaIwG5AnzOHpQfrv1EFrjB/+sHrJ6bglx eR5Q9T2iBYUgF/oAfOLBztfSWNmwODumRZaqE6oKw+4Yy5BmgPhriINUrHPM X-Google-Smtp-Source: AGHT+IG/zWTVLACZV1/KV9cHluY91/6fKiS5ISfzkqgow/OaBn9Zi8MIttBQwoh+ZAV4erqeHF7KjQ== X-Received: by 2002:a05:690c:fd4:b0:627:dfbd:3175 with SMTP id 00721157ae682-658ee79113emr210296167b3.10.1720850176872; Fri, 12 Jul 2024 22:56:16 -0700 (PDT) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1e:9d09:4e82:b45e]) by smtp.gmail.com with ESMTPSA id 00721157ae682-65fc445165dsm761927b3.105.2024.07.12.22.56.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:56:16 -0700 (PDT) From: Kui-Feng Lee To: bpf@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, song@kernel.org, kernel-team@meta.com, andrii@kernel.org Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH bpf-next 4/4] selftests/bpf: Monitor traffic for select_reuseport. Date: Fri, 12 Jul 2024 22:55:52 -0700 Message-Id: <20240713055552.2482367-5-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055552.2482367-1-thinker.li@gmail.com> References: <20240713055552.2482367-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Enable traffic monitoring for the subtests of select_reuseport. The subtest prints the traffic log only ifit fails. Signed-off-by: Kui-Feng Lee --- .../testing/selftests/bpf/prog_tests/select_reuseport.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c index 64c5f5eb2994..567e8083e7cf 100644 --- a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c +++ b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c @@ -22,6 +22,7 @@ #include "test_progs.h" #include "test_select_reuseport_common.h" +#include "network_helpers.h" #define MAX_TEST_NAME 80 #define MIN_TCPHDR_LEN 20 @@ -795,6 +796,7 @@ static void test_config(int sotype, sa_family_t family, bool inany) }; char s[MAX_TEST_NAME]; const struct test *t; + struct tmonitor_ctx *tmon; for (t = tests; t < tests + ARRAY_SIZE(tests); t++) { if (t->need_sotype && t->need_sotype != sotype) @@ -808,9 +810,16 @@ static void test_config(int sotype, sa_family_t family, bool inany) if (!test__start_subtest(s)) continue; + tmon = traffic_monitor_start(NULL); + ASSERT_TRUE(tmon, "traffic_monitor_start"); + setup_per_test(sotype, family, inany, t->no_inner_map); t->fn(sotype, family); cleanup_per_test(t->no_inner_map); + + if (env.subtest_state->error_cnt) + traffic_monitor_report(tmon); + traffic_monitor_stop(tmon); } }