Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: nettest: Add --{force,no}-bind-key-ifindex

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 <cdleonard@gmail.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Leonard Crestez and committed by
David S. Miller
78a9cf61 a76c2315

+26 -2
+26 -2
tools/testing/selftests/net/nettest.c
··· 28 28 #include <unistd.h> 29 29 #include <time.h> 30 30 #include <errno.h> 31 + #include <getopt.h> 31 32 32 33 #include <linux/xfrm.h> 33 34 #include <linux/ipsec.h> ··· 102 101 struct sockaddr_in6 v6; 103 102 } md5_prefix; 104 103 unsigned int prefix_len; 104 + /* 0: default, -1: force off, +1: force on */ 105 + int bind_key_ifindex; 105 106 106 107 /* expected addresses and device index for connection */ 107 108 const char *expected_dev; ··· 274 271 } 275 272 memcpy(&md5sig.tcpm_addr, addr, alen); 276 273 277 - if (args->ifindex) { 274 + if ((args->ifindex && args->bind_key_ifindex >= 0) || args->bind_key_ifindex >= 1) { 278 275 opt = TCP_MD5SIG_EXT; 279 276 md5sig.tcpm_flags |= TCP_MD5SIG_FLAG_IFINDEX; 280 277 281 278 md5sig.tcpm_ifindex = args->ifindex; 279 + log_msg("TCP_MD5SIG_FLAG_IFINDEX set tcpm_ifindex=%d\n", md5sig.tcpm_ifindex); 280 + } else { 281 + log_msg("TCP_MD5SIG_FLAG_IFINDEX off\n", md5sig.tcpm_ifindex); 282 282 } 283 283 284 284 rc = setsockopt(sd, IPPROTO_TCP, opt, &md5sig, sizeof(md5sig)); ··· 1828 1822 } 1829 1823 1830 1824 #define GETOPT_STR "sr:l:c:p:t:g:P:DRn:M:X:m:d:I:BN:O:SCi6xL:0:1:2:3:Fbq" 1825 + #define OPT_FORCE_BIND_KEY_IFINDEX 1001 1826 + #define OPT_NO_BIND_KEY_IFINDEX 1002 1827 + 1828 + static struct option long_opts[] = { 1829 + {"force-bind-key-ifindex", 0, 0, OPT_FORCE_BIND_KEY_IFINDEX}, 1830 + {"no-bind-key-ifindex", 0, 0, OPT_NO_BIND_KEY_IFINDEX}, 1831 + {0, 0, 0, 0} 1832 + }; 1831 1833 1832 1834 static void print_usage(char *prog) 1833 1835 { ··· 1872 1858 " -M password use MD5 sum protection\n" 1873 1859 " -X password MD5 password for client mode\n" 1874 1860 " -m prefix/len prefix and length to use for MD5 key\n" 1861 + " --no-bind-key-ifindex: Force TCP_MD5SIG_FLAG_IFINDEX off\n" 1862 + " --force-bind-key-ifindex: Force TCP_MD5SIG_FLAG_IFINDEX on\n" 1863 + " (default: only if -I is passed)\n" 1864 + "\n" 1875 1865 " -g grp multicast group (e.g., 239.1.1.1)\n" 1876 1866 " -i interactive mode (default is echo and terminate)\n" 1877 1867 "\n" ··· 1911 1893 * process input args 1912 1894 */ 1913 1895 1914 - while ((rc = getopt(argc, argv, GETOPT_STR)) != -1) { 1896 + while ((rc = getopt_long(argc, argv, GETOPT_STR, long_opts, NULL)) != -1) { 1915 1897 switch (rc) { 1916 1898 case 'B': 1917 1899 both_mode = 1; ··· 1983 1965 break; 1984 1966 case 'M': 1985 1967 args.password = optarg; 1968 + break; 1969 + case OPT_FORCE_BIND_KEY_IFINDEX: 1970 + args.bind_key_ifindex = 1; 1971 + break; 1972 + case OPT_NO_BIND_KEY_IFINDEX: 1973 + args.bind_key_ifindex = -1; 1986 1974 break; 1987 1975 case 'X': 1988 1976 args.client_pw = optarg;