Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3170881pxb; Tue, 12 Oct 2021 23:52:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6n0j+GbsdkWkbuIRsSb48vI2umWmEopCazZ6Zk+lvLl/ctfxR8fTGfe7pP2iB0RR/hjXf X-Received: by 2002:a65:6187:: with SMTP id c7mr26445406pgv.317.1634107970558; Tue, 12 Oct 2021 23:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634107970; cv=none; d=google.com; s=arc-20160816; b=Oj3gMC6Wi35g6ryoMTduL7GnAjfwB2CSupjLs0uSTwFhU05CQqHtFdPlPX7KTYnXfr M6TBDX4H0E+OLZhGqS++Us4sNIqwWsY6y4sOag0tQPo30/iRHPckoAjf4WP/UlCEtGqb tuOUDBVaJQeVbeUPPb+DbPeGOcq3K8p3rqBkm5JAl53ZLBKQojOxBVWXzpeSzl4edPHH Y1mBOjz3XbQ6lloKb5jaf7KagzhCr9H3lzOw/7I0jHUVK9l0408Yu1FiDcE29hXpCnQI bXsgUGRrj7Nqoiu0LidmPDOYI+q6P+EYHFEXYwM6mzXttkn5ZGzdIdKUDgASipKNlEPv 7OZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6N39G7ZGCVEFusy0Xx0rScelbxpLk6pfw5D48AWuodI=; b=QVllMZuBmAUxSjWMMCgWiMI0Ez2RiAvzN51IuWxsKuxHFaaZHqCgxEaPXLVV2xtvYW zfRN/WWWpgW60CA2ujmymRoCOsfB3O5M8YI6wLV1B9XbIXICE3Y3vMiMpzi3cyG8bdbL 4xbTsPQHqq1PmOeelec3myYNkaICgcYjZcmSfVwUhFuCP8M3V5dPfFz71EnGQ8ejuyEl z2OduC3TIK1MWO1WCXH43uDxrY//ZeAmqPn9lc1/vQihm0RFP1knWWaGU3Tsbn24ft7w 6qfKDgDrbKivxyQxZ4hzl9uS3bBWMn6r3ffgwlrCVMXL29JaF2GtEPIxxUAX/oMUpiZ8 D+VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iiGu5rUu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p187si18440656pfg.247.2021.10.12.23.52.37; Tue, 12 Oct 2021 23:52:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iiGu5rUu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238163AbhJMGxE (ORCPT + 99 others); Wed, 13 Oct 2021 02:53:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238124AbhJMGw7 (ORCPT ); Wed, 13 Oct 2021 02:52:59 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEC59C061570; Tue, 12 Oct 2021 23:50:56 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id d3so5850159edp.3; Tue, 12 Oct 2021 23:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6N39G7ZGCVEFusy0Xx0rScelbxpLk6pfw5D48AWuodI=; b=iiGu5rUuqINXoeXJUal9rU7i/ufLOqi883k0R9zY26ivnP0Ey1Ial4tu3/Mr8csIx2 AKVi6Yj7426iy8nJsbhyj5TJ5FZrwdgyQBmfivKhICpGJIZAWaBLo4xahssDdEnphTPN 3qMrK8knr2tMoaTV+n0gRp20IYekBjqoQxYT55042Qzo4Vmz5IENiLuC4ntygeS9lWPQ LhFh50Mt7IA40Az8RuN8BBILGYP0Xq9WqslXNHfSbbEQGqkQ7yuy7wK8aplCAXcpcyhx PF8jMyFB+GZi/j1e0nY6l+21m3qejIQAuwOeEDn0u9NIpNmsH9dBb9qIpCk567OTYRDt RBmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6N39G7ZGCVEFusy0Xx0rScelbxpLk6pfw5D48AWuodI=; b=Vf9y3kJwvmHbeUuqNNt6uqGI/tdRrWt70EG/Ugv5vDLNAQ9nMD2Ucq6CbSItmWJ2by y5HT8PnhMHPM1ZB6e4ZHskVkSdF1wP0H6qlIEbXY78/FlfcFYynrYqG3Qm05Yu9jerCJ wHyS2+xzlwvGNqZcw9t8XZZ2aWdnb0aTY+3kK1jzHmoDWYFcnLqm8oWGZZN8b3Srfl0t 1gNnD4SKRWg1ba+IhQuPg/FkDBsvsgWj9bJke6nhHGkm5cQVrCbrsfAmpmONPZ6B3q5w Mb6F4tGU9+O3w7YxqKP7vAbqrWgbgGzCWuyxgAhMg8dPlxlbLJEU2EVVrwBn/GBK9Cz2 SDRQ== X-Gm-Message-State: AOAM531qYIQIdNdOyN5ggcAb+6hu7c7XkN37Jt/YA8ftlhg83wbQbiyM FATP4i3VGwDxVnJa1WmKwa4= X-Received: by 2002:a50:d84c:: with SMTP id v12mr6731644edj.201.1634107854528; Tue, 12 Oct 2021 23:50:54 -0700 (PDT) Received: from ponky.lan ([2a04:241e:501:3870:6346:a6a3:f7ea:349e]) by smtp.gmail.com with ESMTPSA id m15sm4568710edd.5.2021.10.12.23.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 23:50:54 -0700 (PDT) From: Leonard Crestez To: David Ahern , Eric Dumazet Cc: "David S. Miller" , Hideaki YOSHIFUJI , Jakub Kicinski , Martin KaFai Lau , Kuniyuki Iwashima , Yonghong Song , Alexander Duyck , Florian Westphal , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] selftests: nettest: Add --{do,no}-bind-key-ifindex Date: Wed, 13 Oct 2021 09:50:37 +0300 Message-Id: <122a68cd7fd28e9a5580f16f650826437f7397a1.1634107317.git.cdleonard@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These options allow explicit control over the TCP_MD5SIG_FLAG_IFINDEX flag instead of always setting it based on binding to an interface. Do this by converting to getopt_long because nettest has too many single-character flags already and getopt_long is widely used in selftests. Signed-off-by: Leonard Crestez --- tools/testing/selftests/net/nettest.c | 28 +++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/nettest.c b/tools/testing/selftests/net/nettest.c index bd6288302094..acf5cd153eaf 100644 --- a/tools/testing/selftests/net/nettest.c +++ b/tools/testing/selftests/net/nettest.c @@ -26,10 +26,11 @@ #include #include #include #include #include +#include #include #include #include @@ -99,10 +100,12 @@ struct sock_args { union { struct sockaddr_in v4; struct sockaddr_in6 v6; } md5_prefix; unsigned int prefix_len; + /* 0: default, -1: force off, +1: force on */ + int bind_key_ifindex; /* expected addresses and device index for connection */ const char *expected_dev; const char *expected_server_dev; int expected_ifindex; @@ -269,15 +272,18 @@ static int tcp_md5sig(int sd, void *addr, socklen_t alen, struct sock_args *args md5sig.tcpm_prefixlen = args->prefix_len; addr = &args->md5_prefix; } memcpy(&md5sig.tcpm_addr, addr, alen); - if (args->ifindex) { + if ((args->ifindex && args->bind_key_ifindex >= 0) || args->bind_key_ifindex >= 1) { opt = TCP_MD5SIG_EXT; md5sig.tcpm_flags |= TCP_MD5SIG_FLAG_IFINDEX; md5sig.tcpm_ifindex = args->ifindex; + log_msg("TCP_MD5SIG_FLAG_IFINDEX set tcpm_ifindex=%d\n", md5sig.tcpm_ifindex); + } else { + log_msg("TCP_MD5SIG_FLAG_IFINDEX off\n", md5sig.tcpm_ifindex); } rc = setsockopt(sd, IPPROTO_TCP, opt, &md5sig, sizeof(md5sig)); if (rc < 0) { /* ENOENT is harmless. Returned when a password is cleared */ @@ -1820,10 +1826,18 @@ static int ipc_parent(int cpid, int fd, struct sock_args *args) wait(&status); return client_status; } #define GETOPT_STR "sr:l:c:p:t:g:P:DRn:M:X:m:d:I:BN:O:SCi6xL:0:1:2:3:Fbq" +#define OPT_DO_BIND_KEY_IFINDEX 1001 +#define OPT_NO_BIND_KEY_IFINDEX 1002 + +static struct option long_opts[] = { + {"do-bind-key-ifindex", 0, 0, OPT_DO_BIND_KEY_IFINDEX}, + {"no-bind-key-ifindex", 0, 0, OPT_NO_BIND_KEY_IFINDEX}, + {0, 0, 0, 0} +}; static void print_usage(char *prog) { printf( "usage: %s OPTS\n" @@ -1856,10 +1870,14 @@ static void print_usage(char *prog) " -n num number of times to send message\n" "\n" " -M password use MD5 sum protection\n" " -X password MD5 password for client mode\n" " -m prefix/len prefix and length to use for MD5 key\n" + " --no-bind-key-ifindex: Force TCP_MD5SIG_FLAG_IFINDEX off\n" + " --do-bind-key-ifindex: Force TCP_MD5SIG_FLAG_IFINDEX on\n" + " (default: only if -I is passed)\n" + "\n" " -g grp multicast group (e.g., 239.1.1.1)\n" " -i interactive mode (default is echo and terminate)\n" "\n" " -0 addr Expected local address\n" " -1 addr Expected remote address\n" @@ -1891,11 +1909,11 @@ int main(int argc, char *argv[]) /* * process input args */ - while ((rc = getopt(argc, argv, GETOPT_STR)) != -1) { + while ((rc = getopt_long(argc, argv, GETOPT_STR, long_opts, NULL)) != -1) { switch (rc) { case 'B': both_mode = 1; break; case 's': @@ -1964,10 +1982,16 @@ int main(int argc, char *argv[]) msg = random_msg(atoi(optarg)); break; case 'M': args.password = optarg; break; + case OPT_DO_BIND_KEY_IFINDEX: + args.bind_key_ifindex = 1; + break; + case OPT_NO_BIND_KEY_IFINDEX: + args.bind_key_ifindex = -1; + break; case 'X': args.client_pw = optarg; break; case 'm': args.md5_prefix_str = optarg; -- 2.25.1