18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci#define _GNU_SOURCE
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <stddef.h>
68c2ecf20Sopenharmony_ci#include <arpa/inet.h>
78c2ecf20Sopenharmony_ci#include <error.h>
88c2ecf20Sopenharmony_ci#include <errno.h>
98c2ecf20Sopenharmony_ci#include <net/if.h>
108c2ecf20Sopenharmony_ci#include <linux/in.h>
118c2ecf20Sopenharmony_ci#include <linux/netlink.h>
128c2ecf20Sopenharmony_ci#include <linux/rtnetlink.h>
138c2ecf20Sopenharmony_ci#include <netinet/if_ether.h>
148c2ecf20Sopenharmony_ci#include <netinet/ip.h>
158c2ecf20Sopenharmony_ci#include <netinet/ip6.h>
168c2ecf20Sopenharmony_ci#include <netinet/udp.h>
178c2ecf20Sopenharmony_ci#include <stdbool.h>
188c2ecf20Sopenharmony_ci#include <stdlib.h>
198c2ecf20Sopenharmony_ci#include <stdio.h>
208c2ecf20Sopenharmony_ci#include <string.h>
218c2ecf20Sopenharmony_ci#include <sys/ioctl.h>
228c2ecf20Sopenharmony_ci#include <sys/socket.h>
238c2ecf20Sopenharmony_ci#include <sys/stat.h>
248c2ecf20Sopenharmony_ci#include <sys/time.h>
258c2ecf20Sopenharmony_ci#include <sys/types.h>
268c2ecf20Sopenharmony_ci#include <unistd.h>
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#ifndef ETH_MAX_MTU
298c2ecf20Sopenharmony_ci#define ETH_MAX_MTU	0xFFFFU
308c2ecf20Sopenharmony_ci#endif
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#ifndef UDP_SEGMENT
338c2ecf20Sopenharmony_ci#define UDP_SEGMENT		103
348c2ecf20Sopenharmony_ci#endif
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#ifndef UDP_MAX_SEGMENTS
378c2ecf20Sopenharmony_ci#define UDP_MAX_SEGMENTS	(1 << 6UL)
388c2ecf20Sopenharmony_ci#endif
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define CONST_MTU_TEST	1500
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define CONST_HDRLEN_V4		(sizeof(struct iphdr) + sizeof(struct udphdr))
438c2ecf20Sopenharmony_ci#define CONST_HDRLEN_V6		(sizeof(struct ip6_hdr) + sizeof(struct udphdr))
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define CONST_MSS_V4		(CONST_MTU_TEST - CONST_HDRLEN_V4)
468c2ecf20Sopenharmony_ci#define CONST_MSS_V6		(CONST_MTU_TEST - CONST_HDRLEN_V6)
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define CONST_MAX_SEGS_V4	(ETH_MAX_MTU / CONST_MSS_V4)
498c2ecf20Sopenharmony_ci#define CONST_MAX_SEGS_V6	(ETH_MAX_MTU / CONST_MSS_V6)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistatic bool		cfg_do_ipv4;
528c2ecf20Sopenharmony_cistatic bool		cfg_do_ipv6;
538c2ecf20Sopenharmony_cistatic bool		cfg_do_connected;
548c2ecf20Sopenharmony_cistatic bool		cfg_do_connectionless;
558c2ecf20Sopenharmony_cistatic bool		cfg_do_msgmore;
568c2ecf20Sopenharmony_cistatic bool		cfg_do_setsockopt;
578c2ecf20Sopenharmony_cistatic int		cfg_specific_test_id = -1;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic const char	cfg_ifname[] = "lo";
608c2ecf20Sopenharmony_cistatic unsigned short	cfg_port = 9000;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistatic char buf[ETH_MAX_MTU];
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistruct testcase {
658c2ecf20Sopenharmony_ci	int tlen;		/* send() buffer size, may exceed mss */
668c2ecf20Sopenharmony_ci	bool tfail;		/* send() call is expected to fail */
678c2ecf20Sopenharmony_ci	int gso_len;		/* mss after applying gso */
688c2ecf20Sopenharmony_ci	int r_num_mss;		/* recv(): number of calls of full mss */
698c2ecf20Sopenharmony_ci	int r_len_last;		/* recv(): size of last non-mss dgram, if any */
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ciconst struct in6_addr addr6 = IN6ADDR_LOOPBACK_INIT;
738c2ecf20Sopenharmony_ciconst struct in_addr addr4 = { .s_addr = __constant_htonl(INADDR_LOOPBACK + 2) };
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistruct testcase testcases_v4[] = {
768c2ecf20Sopenharmony_ci	{
778c2ecf20Sopenharmony_ci		/* no GSO: send a single byte */
788c2ecf20Sopenharmony_ci		.tlen = 1,
798c2ecf20Sopenharmony_ci		.r_len_last = 1,
808c2ecf20Sopenharmony_ci	},
818c2ecf20Sopenharmony_ci	{
828c2ecf20Sopenharmony_ci		/* no GSO: send a single MSS */
838c2ecf20Sopenharmony_ci		.tlen = CONST_MSS_V4,
848c2ecf20Sopenharmony_ci		.r_num_mss = 1,
858c2ecf20Sopenharmony_ci	},
868c2ecf20Sopenharmony_ci	{
878c2ecf20Sopenharmony_ci		/* no GSO: send a single MSS + 1B: fail */
888c2ecf20Sopenharmony_ci		.tlen = CONST_MSS_V4 + 1,
898c2ecf20Sopenharmony_ci		.tfail = true,
908c2ecf20Sopenharmony_ci	},
918c2ecf20Sopenharmony_ci	{
928c2ecf20Sopenharmony_ci		/* send a single MSS: will fall back to no GSO */
938c2ecf20Sopenharmony_ci		.tlen = CONST_MSS_V4,
948c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V4,
958c2ecf20Sopenharmony_ci		.r_num_mss = 1,
968c2ecf20Sopenharmony_ci	},
978c2ecf20Sopenharmony_ci	{
988c2ecf20Sopenharmony_ci		/* send a single MSS + 1B */
998c2ecf20Sopenharmony_ci		.tlen = CONST_MSS_V4 + 1,
1008c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V4,
1018c2ecf20Sopenharmony_ci		.r_num_mss = 1,
1028c2ecf20Sopenharmony_ci		.r_len_last = 1,
1038c2ecf20Sopenharmony_ci	},
1048c2ecf20Sopenharmony_ci	{
1058c2ecf20Sopenharmony_ci		/* send exactly 2 MSS */
1068c2ecf20Sopenharmony_ci		.tlen = CONST_MSS_V4 * 2,
1078c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V4,
1088c2ecf20Sopenharmony_ci		.r_num_mss = 2,
1098c2ecf20Sopenharmony_ci	},
1108c2ecf20Sopenharmony_ci	{
1118c2ecf20Sopenharmony_ci		/* send 2 MSS + 1B */
1128c2ecf20Sopenharmony_ci		.tlen = (CONST_MSS_V4 * 2) + 1,
1138c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V4,
1148c2ecf20Sopenharmony_ci		.r_num_mss = 2,
1158c2ecf20Sopenharmony_ci		.r_len_last = 1,
1168c2ecf20Sopenharmony_ci	},
1178c2ecf20Sopenharmony_ci	{
1188c2ecf20Sopenharmony_ci		/* send MAX segs */
1198c2ecf20Sopenharmony_ci		.tlen = (ETH_MAX_MTU / CONST_MSS_V4) * CONST_MSS_V4,
1208c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V4,
1218c2ecf20Sopenharmony_ci		.r_num_mss = (ETH_MAX_MTU / CONST_MSS_V4),
1228c2ecf20Sopenharmony_ci	},
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	{
1258c2ecf20Sopenharmony_ci		/* send MAX bytes */
1268c2ecf20Sopenharmony_ci		.tlen = ETH_MAX_MTU - CONST_HDRLEN_V4,
1278c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V4,
1288c2ecf20Sopenharmony_ci		.r_num_mss = CONST_MAX_SEGS_V4,
1298c2ecf20Sopenharmony_ci		.r_len_last = ETH_MAX_MTU - CONST_HDRLEN_V4 -
1308c2ecf20Sopenharmony_ci			      (CONST_MAX_SEGS_V4 * CONST_MSS_V4),
1318c2ecf20Sopenharmony_ci	},
1328c2ecf20Sopenharmony_ci	{
1338c2ecf20Sopenharmony_ci		/* send MAX + 1: fail */
1348c2ecf20Sopenharmony_ci		.tlen = ETH_MAX_MTU - CONST_HDRLEN_V4 + 1,
1358c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V4,
1368c2ecf20Sopenharmony_ci		.tfail = true,
1378c2ecf20Sopenharmony_ci	},
1388c2ecf20Sopenharmony_ci	{
1398c2ecf20Sopenharmony_ci		/* send a single 1B MSS: will fall back to no GSO */
1408c2ecf20Sopenharmony_ci		.tlen = 1,
1418c2ecf20Sopenharmony_ci		.gso_len = 1,
1428c2ecf20Sopenharmony_ci		.r_num_mss = 1,
1438c2ecf20Sopenharmony_ci	},
1448c2ecf20Sopenharmony_ci	{
1458c2ecf20Sopenharmony_ci		/* send 2 1B segments */
1468c2ecf20Sopenharmony_ci		.tlen = 2,
1478c2ecf20Sopenharmony_ci		.gso_len = 1,
1488c2ecf20Sopenharmony_ci		.r_num_mss = 2,
1498c2ecf20Sopenharmony_ci	},
1508c2ecf20Sopenharmony_ci	{
1518c2ecf20Sopenharmony_ci		/* send 2B + 2B + 1B segments */
1528c2ecf20Sopenharmony_ci		.tlen = 5,
1538c2ecf20Sopenharmony_ci		.gso_len = 2,
1548c2ecf20Sopenharmony_ci		.r_num_mss = 2,
1558c2ecf20Sopenharmony_ci		.r_len_last = 1,
1568c2ecf20Sopenharmony_ci	},
1578c2ecf20Sopenharmony_ci	{
1588c2ecf20Sopenharmony_ci		/* send max number of min sized segments */
1598c2ecf20Sopenharmony_ci		.tlen = UDP_MAX_SEGMENTS,
1608c2ecf20Sopenharmony_ci		.gso_len = 1,
1618c2ecf20Sopenharmony_ci		.r_num_mss = UDP_MAX_SEGMENTS,
1628c2ecf20Sopenharmony_ci	},
1638c2ecf20Sopenharmony_ci	{
1648c2ecf20Sopenharmony_ci		/* send max number + 1 of min sized segments: fail */
1658c2ecf20Sopenharmony_ci		.tlen = UDP_MAX_SEGMENTS + 1,
1668c2ecf20Sopenharmony_ci		.gso_len = 1,
1678c2ecf20Sopenharmony_ci		.tfail = true,
1688c2ecf20Sopenharmony_ci	},
1698c2ecf20Sopenharmony_ci	{
1708c2ecf20Sopenharmony_ci		/* EOL */
1718c2ecf20Sopenharmony_ci	}
1728c2ecf20Sopenharmony_ci};
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci#ifndef IP6_MAX_MTU
1758c2ecf20Sopenharmony_ci#define IP6_MAX_MTU	(ETH_MAX_MTU + sizeof(struct ip6_hdr))
1768c2ecf20Sopenharmony_ci#endif
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_cistruct testcase testcases_v6[] = {
1798c2ecf20Sopenharmony_ci	{
1808c2ecf20Sopenharmony_ci		/* no GSO: send a single byte */
1818c2ecf20Sopenharmony_ci		.tlen = 1,
1828c2ecf20Sopenharmony_ci		.r_len_last = 1,
1838c2ecf20Sopenharmony_ci	},
1848c2ecf20Sopenharmony_ci	{
1858c2ecf20Sopenharmony_ci		/* no GSO: send a single MSS */
1868c2ecf20Sopenharmony_ci		.tlen = CONST_MSS_V6,
1878c2ecf20Sopenharmony_ci		.r_num_mss = 1,
1888c2ecf20Sopenharmony_ci	},
1898c2ecf20Sopenharmony_ci	{
1908c2ecf20Sopenharmony_ci		/* no GSO: send a single MSS + 1B: fail */
1918c2ecf20Sopenharmony_ci		.tlen = CONST_MSS_V6 + 1,
1928c2ecf20Sopenharmony_ci		.tfail = true,
1938c2ecf20Sopenharmony_ci	},
1948c2ecf20Sopenharmony_ci	{
1958c2ecf20Sopenharmony_ci		/* send a single MSS: will fall back to no GSO */
1968c2ecf20Sopenharmony_ci		.tlen = CONST_MSS_V6,
1978c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V6,
1988c2ecf20Sopenharmony_ci		.r_num_mss = 1,
1998c2ecf20Sopenharmony_ci	},
2008c2ecf20Sopenharmony_ci	{
2018c2ecf20Sopenharmony_ci		/* send a single MSS + 1B */
2028c2ecf20Sopenharmony_ci		.tlen = CONST_MSS_V6 + 1,
2038c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V6,
2048c2ecf20Sopenharmony_ci		.r_num_mss = 1,
2058c2ecf20Sopenharmony_ci		.r_len_last = 1,
2068c2ecf20Sopenharmony_ci	},
2078c2ecf20Sopenharmony_ci	{
2088c2ecf20Sopenharmony_ci		/* send exactly 2 MSS */
2098c2ecf20Sopenharmony_ci		.tlen = CONST_MSS_V6 * 2,
2108c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V6,
2118c2ecf20Sopenharmony_ci		.r_num_mss = 2,
2128c2ecf20Sopenharmony_ci	},
2138c2ecf20Sopenharmony_ci	{
2148c2ecf20Sopenharmony_ci		/* send 2 MSS + 1B */
2158c2ecf20Sopenharmony_ci		.tlen = (CONST_MSS_V6 * 2) + 1,
2168c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V6,
2178c2ecf20Sopenharmony_ci		.r_num_mss = 2,
2188c2ecf20Sopenharmony_ci		.r_len_last = 1,
2198c2ecf20Sopenharmony_ci	},
2208c2ecf20Sopenharmony_ci	{
2218c2ecf20Sopenharmony_ci		/* send MAX segs */
2228c2ecf20Sopenharmony_ci		.tlen = (IP6_MAX_MTU / CONST_MSS_V6) * CONST_MSS_V6,
2238c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V6,
2248c2ecf20Sopenharmony_ci		.r_num_mss = (IP6_MAX_MTU / CONST_MSS_V6),
2258c2ecf20Sopenharmony_ci	},
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	{
2288c2ecf20Sopenharmony_ci		/* send MAX bytes */
2298c2ecf20Sopenharmony_ci		.tlen = IP6_MAX_MTU - CONST_HDRLEN_V6,
2308c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V6,
2318c2ecf20Sopenharmony_ci		.r_num_mss = CONST_MAX_SEGS_V6,
2328c2ecf20Sopenharmony_ci		.r_len_last = IP6_MAX_MTU - CONST_HDRLEN_V6 -
2338c2ecf20Sopenharmony_ci			      (CONST_MAX_SEGS_V6 * CONST_MSS_V6),
2348c2ecf20Sopenharmony_ci	},
2358c2ecf20Sopenharmony_ci	{
2368c2ecf20Sopenharmony_ci		/* send MAX + 1: fail */
2378c2ecf20Sopenharmony_ci		.tlen = IP6_MAX_MTU - CONST_HDRLEN_V6 + 1,
2388c2ecf20Sopenharmony_ci		.gso_len = CONST_MSS_V6,
2398c2ecf20Sopenharmony_ci		.tfail = true,
2408c2ecf20Sopenharmony_ci	},
2418c2ecf20Sopenharmony_ci	{
2428c2ecf20Sopenharmony_ci		/* send a single 1B MSS: will fall back to no GSO */
2438c2ecf20Sopenharmony_ci		.tlen = 1,
2448c2ecf20Sopenharmony_ci		.gso_len = 1,
2458c2ecf20Sopenharmony_ci		.r_num_mss = 1,
2468c2ecf20Sopenharmony_ci	},
2478c2ecf20Sopenharmony_ci	{
2488c2ecf20Sopenharmony_ci		/* send 2 1B segments */
2498c2ecf20Sopenharmony_ci		.tlen = 2,
2508c2ecf20Sopenharmony_ci		.gso_len = 1,
2518c2ecf20Sopenharmony_ci		.r_num_mss = 2,
2528c2ecf20Sopenharmony_ci	},
2538c2ecf20Sopenharmony_ci	{
2548c2ecf20Sopenharmony_ci		/* send 2B + 2B + 1B segments */
2558c2ecf20Sopenharmony_ci		.tlen = 5,
2568c2ecf20Sopenharmony_ci		.gso_len = 2,
2578c2ecf20Sopenharmony_ci		.r_num_mss = 2,
2588c2ecf20Sopenharmony_ci		.r_len_last = 1,
2598c2ecf20Sopenharmony_ci	},
2608c2ecf20Sopenharmony_ci	{
2618c2ecf20Sopenharmony_ci		/* send max number of min sized segments */
2628c2ecf20Sopenharmony_ci		.tlen = UDP_MAX_SEGMENTS,
2638c2ecf20Sopenharmony_ci		.gso_len = 1,
2648c2ecf20Sopenharmony_ci		.r_num_mss = UDP_MAX_SEGMENTS,
2658c2ecf20Sopenharmony_ci	},
2668c2ecf20Sopenharmony_ci	{
2678c2ecf20Sopenharmony_ci		/* send max number + 1 of min sized segments: fail */
2688c2ecf20Sopenharmony_ci		.tlen = UDP_MAX_SEGMENTS + 1,
2698c2ecf20Sopenharmony_ci		.gso_len = 1,
2708c2ecf20Sopenharmony_ci		.tfail = true,
2718c2ecf20Sopenharmony_ci	},
2728c2ecf20Sopenharmony_ci	{
2738c2ecf20Sopenharmony_ci		/* EOL */
2748c2ecf20Sopenharmony_ci	}
2758c2ecf20Sopenharmony_ci};
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_cistatic unsigned int get_device_mtu(int fd, const char *ifname)
2788c2ecf20Sopenharmony_ci{
2798c2ecf20Sopenharmony_ci	struct ifreq ifr;
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	memset(&ifr, 0, sizeof(ifr));
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	strcpy(ifr.ifr_name, ifname);
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	if (ioctl(fd, SIOCGIFMTU, &ifr))
2868c2ecf20Sopenharmony_ci		error(1, errno, "ioctl get mtu");
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	return ifr.ifr_mtu;
2898c2ecf20Sopenharmony_ci}
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_cistatic void __set_device_mtu(int fd, const char *ifname, unsigned int mtu)
2928c2ecf20Sopenharmony_ci{
2938c2ecf20Sopenharmony_ci	struct ifreq ifr;
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci	memset(&ifr, 0, sizeof(ifr));
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci	ifr.ifr_mtu = mtu;
2988c2ecf20Sopenharmony_ci	strcpy(ifr.ifr_name, ifname);
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci	if (ioctl(fd, SIOCSIFMTU, &ifr))
3018c2ecf20Sopenharmony_ci		error(1, errno, "ioctl set mtu");
3028c2ecf20Sopenharmony_ci}
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_cistatic void set_device_mtu(int fd, int mtu)
3058c2ecf20Sopenharmony_ci{
3068c2ecf20Sopenharmony_ci	int val;
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci	val = get_device_mtu(fd, cfg_ifname);
3098c2ecf20Sopenharmony_ci	fprintf(stderr, "device mtu (orig): %u\n", val);
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci	__set_device_mtu(fd, cfg_ifname, mtu);
3128c2ecf20Sopenharmony_ci	val = get_device_mtu(fd, cfg_ifname);
3138c2ecf20Sopenharmony_ci	if (val != mtu)
3148c2ecf20Sopenharmony_ci		error(1, 0, "unable to set device mtu to %u\n", val);
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	fprintf(stderr, "device mtu (test): %u\n", val);
3178c2ecf20Sopenharmony_ci}
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_cistatic void set_pmtu_discover(int fd, bool is_ipv4)
3208c2ecf20Sopenharmony_ci{
3218c2ecf20Sopenharmony_ci	int level, name, val;
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	if (is_ipv4) {
3248c2ecf20Sopenharmony_ci		level	= SOL_IP;
3258c2ecf20Sopenharmony_ci		name	= IP_MTU_DISCOVER;
3268c2ecf20Sopenharmony_ci		val	= IP_PMTUDISC_DO;
3278c2ecf20Sopenharmony_ci	} else {
3288c2ecf20Sopenharmony_ci		level	= SOL_IPV6;
3298c2ecf20Sopenharmony_ci		name	= IPV6_MTU_DISCOVER;
3308c2ecf20Sopenharmony_ci		val	= IPV6_PMTUDISC_DO;
3318c2ecf20Sopenharmony_ci	}
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	if (setsockopt(fd, level, name, &val, sizeof(val)))
3348c2ecf20Sopenharmony_ci		error(1, errno, "setsockopt path mtu");
3358c2ecf20Sopenharmony_ci}
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_cistatic unsigned int get_path_mtu(int fd, bool is_ipv4)
3388c2ecf20Sopenharmony_ci{
3398c2ecf20Sopenharmony_ci	socklen_t vallen;
3408c2ecf20Sopenharmony_ci	unsigned int mtu;
3418c2ecf20Sopenharmony_ci	int ret;
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	vallen = sizeof(mtu);
3448c2ecf20Sopenharmony_ci	if (is_ipv4)
3458c2ecf20Sopenharmony_ci		ret = getsockopt(fd, SOL_IP, IP_MTU, &mtu, &vallen);
3468c2ecf20Sopenharmony_ci	else
3478c2ecf20Sopenharmony_ci		ret = getsockopt(fd, SOL_IPV6, IPV6_MTU, &mtu, &vallen);
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci	if (ret)
3508c2ecf20Sopenharmony_ci		error(1, errno, "getsockopt mtu");
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	fprintf(stderr, "path mtu (read):  %u\n", mtu);
3548c2ecf20Sopenharmony_ci	return mtu;
3558c2ecf20Sopenharmony_ci}
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci/* very wordy version of system("ip route add dev lo mtu 1500 127.0.0.3/32") */
3588c2ecf20Sopenharmony_cistatic void set_route_mtu(int mtu, bool is_ipv4)
3598c2ecf20Sopenharmony_ci{
3608c2ecf20Sopenharmony_ci	struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
3618c2ecf20Sopenharmony_ci	struct nlmsghdr *nh;
3628c2ecf20Sopenharmony_ci	struct rtattr *rta;
3638c2ecf20Sopenharmony_ci	struct rtmsg *rt;
3648c2ecf20Sopenharmony_ci	char data[NLMSG_ALIGN(sizeof(*nh)) +
3658c2ecf20Sopenharmony_ci		  NLMSG_ALIGN(sizeof(*rt)) +
3668c2ecf20Sopenharmony_ci		  NLMSG_ALIGN(RTA_LENGTH(sizeof(addr6))) +
3678c2ecf20Sopenharmony_ci		  NLMSG_ALIGN(RTA_LENGTH(sizeof(int))) +
3688c2ecf20Sopenharmony_ci		  NLMSG_ALIGN(RTA_LENGTH(0) + RTA_LENGTH(sizeof(int)))];
3698c2ecf20Sopenharmony_ci	int fd, ret, alen, off = 0;
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	alen = is_ipv4 ? sizeof(addr4) : sizeof(addr6);
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
3748c2ecf20Sopenharmony_ci	if (fd == -1)
3758c2ecf20Sopenharmony_ci		error(1, errno, "socket netlink");
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	memset(data, 0, sizeof(data));
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	nh = (void *)data;
3808c2ecf20Sopenharmony_ci	nh->nlmsg_type = RTM_NEWROUTE;
3818c2ecf20Sopenharmony_ci	nh->nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE;
3828c2ecf20Sopenharmony_ci	off += NLMSG_ALIGN(sizeof(*nh));
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ci	rt = (void *)(data + off);
3858c2ecf20Sopenharmony_ci	rt->rtm_family = is_ipv4 ? AF_INET : AF_INET6;
3868c2ecf20Sopenharmony_ci	rt->rtm_table = RT_TABLE_MAIN;
3878c2ecf20Sopenharmony_ci	rt->rtm_dst_len = alen << 3;
3888c2ecf20Sopenharmony_ci	rt->rtm_protocol = RTPROT_BOOT;
3898c2ecf20Sopenharmony_ci	rt->rtm_scope = RT_SCOPE_UNIVERSE;
3908c2ecf20Sopenharmony_ci	rt->rtm_type = RTN_UNICAST;
3918c2ecf20Sopenharmony_ci	off += NLMSG_ALIGN(sizeof(*rt));
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	rta = (void *)(data + off);
3948c2ecf20Sopenharmony_ci	rta->rta_type = RTA_DST;
3958c2ecf20Sopenharmony_ci	rta->rta_len = RTA_LENGTH(alen);
3968c2ecf20Sopenharmony_ci	if (is_ipv4)
3978c2ecf20Sopenharmony_ci		memcpy(RTA_DATA(rta), &addr4, alen);
3988c2ecf20Sopenharmony_ci	else
3998c2ecf20Sopenharmony_ci		memcpy(RTA_DATA(rta), &addr6, alen);
4008c2ecf20Sopenharmony_ci	off += NLMSG_ALIGN(rta->rta_len);
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci	rta = (void *)(data + off);
4038c2ecf20Sopenharmony_ci	rta->rta_type = RTA_OIF;
4048c2ecf20Sopenharmony_ci	rta->rta_len = RTA_LENGTH(sizeof(int));
4058c2ecf20Sopenharmony_ci	*((int *)(RTA_DATA(rta))) = 1; //if_nametoindex("lo");
4068c2ecf20Sopenharmony_ci	off += NLMSG_ALIGN(rta->rta_len);
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci	/* MTU is a subtype in a metrics type */
4098c2ecf20Sopenharmony_ci	rta = (void *)(data + off);
4108c2ecf20Sopenharmony_ci	rta->rta_type = RTA_METRICS;
4118c2ecf20Sopenharmony_ci	rta->rta_len = RTA_LENGTH(0) + RTA_LENGTH(sizeof(int));
4128c2ecf20Sopenharmony_ci	off += NLMSG_ALIGN(rta->rta_len);
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	/* now fill MTU subtype. Note that it fits within above rta_len */
4158c2ecf20Sopenharmony_ci	rta = (void *)(((char *) rta) + RTA_LENGTH(0));
4168c2ecf20Sopenharmony_ci	rta->rta_type = RTAX_MTU;
4178c2ecf20Sopenharmony_ci	rta->rta_len = RTA_LENGTH(sizeof(int));
4188c2ecf20Sopenharmony_ci	*((int *)(RTA_DATA(rta))) = mtu;
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_ci	nh->nlmsg_len = off;
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	ret = sendto(fd, data, off, 0, (void *)&nladdr, sizeof(nladdr));
4238c2ecf20Sopenharmony_ci	if (ret != off)
4248c2ecf20Sopenharmony_ci		error(1, errno, "send netlink: %uB != %uB\n", ret, off);
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci	if (close(fd))
4278c2ecf20Sopenharmony_ci		error(1, errno, "close netlink");
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci	fprintf(stderr, "route mtu (test): %u\n", mtu);
4308c2ecf20Sopenharmony_ci}
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_cistatic bool __send_one(int fd, struct msghdr *msg, int flags)
4338c2ecf20Sopenharmony_ci{
4348c2ecf20Sopenharmony_ci	int ret;
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	ret = sendmsg(fd, msg, flags);
4378c2ecf20Sopenharmony_ci	if (ret == -1 &&
4388c2ecf20Sopenharmony_ci	    (errno == EMSGSIZE || errno == ENOMEM || errno == EINVAL))
4398c2ecf20Sopenharmony_ci		return false;
4408c2ecf20Sopenharmony_ci	if (ret == -1)
4418c2ecf20Sopenharmony_ci		error(1, errno, "sendmsg");
4428c2ecf20Sopenharmony_ci	if (ret != msg->msg_iov->iov_len)
4438c2ecf20Sopenharmony_ci		error(1, 0, "sendto: %d != %llu", ret,
4448c2ecf20Sopenharmony_ci			(unsigned long long)msg->msg_iov->iov_len);
4458c2ecf20Sopenharmony_ci	if (msg->msg_flags)
4468c2ecf20Sopenharmony_ci		error(1, 0, "sendmsg: return flags 0x%x\n", msg->msg_flags);
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci	return true;
4498c2ecf20Sopenharmony_ci}
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_cistatic bool send_one(int fd, int len, int gso_len,
4528c2ecf20Sopenharmony_ci		     struct sockaddr *addr, socklen_t alen)
4538c2ecf20Sopenharmony_ci{
4548c2ecf20Sopenharmony_ci	char control[CMSG_SPACE(sizeof(uint16_t))] = {0};
4558c2ecf20Sopenharmony_ci	struct msghdr msg = {0};
4568c2ecf20Sopenharmony_ci	struct iovec iov = {0};
4578c2ecf20Sopenharmony_ci	struct cmsghdr *cm;
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ci	iov.iov_base = buf;
4608c2ecf20Sopenharmony_ci	iov.iov_len = len;
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci	msg.msg_iov = &iov;
4638c2ecf20Sopenharmony_ci	msg.msg_iovlen = 1;
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	msg.msg_name = addr;
4668c2ecf20Sopenharmony_ci	msg.msg_namelen = alen;
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci	if (gso_len && !cfg_do_setsockopt) {
4698c2ecf20Sopenharmony_ci		msg.msg_control = control;
4708c2ecf20Sopenharmony_ci		msg.msg_controllen = sizeof(control);
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_ci		cm = CMSG_FIRSTHDR(&msg);
4738c2ecf20Sopenharmony_ci		cm->cmsg_level = SOL_UDP;
4748c2ecf20Sopenharmony_ci		cm->cmsg_type = UDP_SEGMENT;
4758c2ecf20Sopenharmony_ci		cm->cmsg_len = CMSG_LEN(sizeof(uint16_t));
4768c2ecf20Sopenharmony_ci		*((uint16_t *) CMSG_DATA(cm)) = gso_len;
4778c2ecf20Sopenharmony_ci	}
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci	/* If MSG_MORE, send 1 byte followed by remainder */
4808c2ecf20Sopenharmony_ci	if (cfg_do_msgmore && len > 1) {
4818c2ecf20Sopenharmony_ci		iov.iov_len = 1;
4828c2ecf20Sopenharmony_ci		if (!__send_one(fd, &msg, MSG_MORE))
4838c2ecf20Sopenharmony_ci			error(1, 0, "send 1B failed");
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci		iov.iov_base++;
4868c2ecf20Sopenharmony_ci		iov.iov_len = len - 1;
4878c2ecf20Sopenharmony_ci	}
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	return __send_one(fd, &msg, 0);
4908c2ecf20Sopenharmony_ci}
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_cistatic int recv_one(int fd, int flags)
4938c2ecf20Sopenharmony_ci{
4948c2ecf20Sopenharmony_ci	int ret;
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci	ret = recv(fd, buf, sizeof(buf), flags);
4978c2ecf20Sopenharmony_ci	if (ret == -1 && errno == EAGAIN && (flags & MSG_DONTWAIT))
4988c2ecf20Sopenharmony_ci		return 0;
4998c2ecf20Sopenharmony_ci	if (ret == -1)
5008c2ecf20Sopenharmony_ci		error(1, errno, "recv");
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci	return ret;
5038c2ecf20Sopenharmony_ci}
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_cistatic void run_one(struct testcase *test, int fdt, int fdr,
5068c2ecf20Sopenharmony_ci		    struct sockaddr *addr, socklen_t alen)
5078c2ecf20Sopenharmony_ci{
5088c2ecf20Sopenharmony_ci	int i, ret, val, mss;
5098c2ecf20Sopenharmony_ci	bool sent;
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ci	fprintf(stderr, "ipv%d tx:%d gso:%d %s\n",
5128c2ecf20Sopenharmony_ci			addr->sa_family == AF_INET ? 4 : 6,
5138c2ecf20Sopenharmony_ci			test->tlen, test->gso_len,
5148c2ecf20Sopenharmony_ci			test->tfail ? "(fail)" : "");
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci	val = test->gso_len;
5178c2ecf20Sopenharmony_ci	if (cfg_do_setsockopt) {
5188c2ecf20Sopenharmony_ci		if (setsockopt(fdt, SOL_UDP, UDP_SEGMENT, &val, sizeof(val)))
5198c2ecf20Sopenharmony_ci			error(1, errno, "setsockopt udp segment");
5208c2ecf20Sopenharmony_ci	}
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci	sent = send_one(fdt, test->tlen, test->gso_len, addr, alen);
5238c2ecf20Sopenharmony_ci	if (sent && test->tfail)
5248c2ecf20Sopenharmony_ci		error(1, 0, "send succeeded while expecting failure");
5258c2ecf20Sopenharmony_ci	if (!sent && !test->tfail)
5268c2ecf20Sopenharmony_ci		error(1, 0, "send failed while expecting success");
5278c2ecf20Sopenharmony_ci	if (!sent)
5288c2ecf20Sopenharmony_ci		return;
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ci	if (test->gso_len)
5318c2ecf20Sopenharmony_ci		mss = test->gso_len;
5328c2ecf20Sopenharmony_ci	else
5338c2ecf20Sopenharmony_ci		mss = addr->sa_family == AF_INET ? CONST_MSS_V4 : CONST_MSS_V6;
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ci	/* Recv all full MSS datagrams */
5378c2ecf20Sopenharmony_ci	for (i = 0; i < test->r_num_mss; i++) {
5388c2ecf20Sopenharmony_ci		ret = recv_one(fdr, 0);
5398c2ecf20Sopenharmony_ci		if (ret != mss)
5408c2ecf20Sopenharmony_ci			error(1, 0, "recv.%d: %d != %d", i, ret, mss);
5418c2ecf20Sopenharmony_ci	}
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_ci	/* Recv the non-full last datagram, if tlen was not a multiple of mss */
5448c2ecf20Sopenharmony_ci	if (test->r_len_last) {
5458c2ecf20Sopenharmony_ci		ret = recv_one(fdr, 0);
5468c2ecf20Sopenharmony_ci		if (ret != test->r_len_last)
5478c2ecf20Sopenharmony_ci			error(1, 0, "recv.%d: %d != %d (last)",
5488c2ecf20Sopenharmony_ci			      i, ret, test->r_len_last);
5498c2ecf20Sopenharmony_ci	}
5508c2ecf20Sopenharmony_ci
5518c2ecf20Sopenharmony_ci	/* Verify received all data */
5528c2ecf20Sopenharmony_ci	ret = recv_one(fdr, MSG_DONTWAIT);
5538c2ecf20Sopenharmony_ci	if (ret)
5548c2ecf20Sopenharmony_ci		error(1, 0, "recv: unexpected datagram");
5558c2ecf20Sopenharmony_ci}
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_cistatic void run_all(int fdt, int fdr, struct sockaddr *addr, socklen_t alen)
5588c2ecf20Sopenharmony_ci{
5598c2ecf20Sopenharmony_ci	struct testcase *tests, *test;
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci	tests = addr->sa_family == AF_INET ? testcases_v4 : testcases_v6;
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_ci	for (test = tests; test->tlen; test++) {
5648c2ecf20Sopenharmony_ci		/* if a specific test is given, then skip all others */
5658c2ecf20Sopenharmony_ci		if (cfg_specific_test_id == -1 ||
5668c2ecf20Sopenharmony_ci		    cfg_specific_test_id == test - tests)
5678c2ecf20Sopenharmony_ci			run_one(test, fdt, fdr, addr, alen);
5688c2ecf20Sopenharmony_ci	}
5698c2ecf20Sopenharmony_ci}
5708c2ecf20Sopenharmony_ci
5718c2ecf20Sopenharmony_cistatic void run_test(struct sockaddr *addr, socklen_t alen)
5728c2ecf20Sopenharmony_ci{
5738c2ecf20Sopenharmony_ci	struct timeval tv = { .tv_usec = 100 * 1000 };
5748c2ecf20Sopenharmony_ci	int fdr, fdt, val;
5758c2ecf20Sopenharmony_ci
5768c2ecf20Sopenharmony_ci	fdr = socket(addr->sa_family, SOCK_DGRAM, 0);
5778c2ecf20Sopenharmony_ci	if (fdr == -1)
5788c2ecf20Sopenharmony_ci		error(1, errno, "socket r");
5798c2ecf20Sopenharmony_ci
5808c2ecf20Sopenharmony_ci	if (bind(fdr, addr, alen))
5818c2ecf20Sopenharmony_ci		error(1, errno, "bind");
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci	/* Have tests fail quickly instead of hang */
5848c2ecf20Sopenharmony_ci	if (setsockopt(fdr, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)))
5858c2ecf20Sopenharmony_ci		error(1, errno, "setsockopt rcv timeout");
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci	fdt = socket(addr->sa_family, SOCK_DGRAM, 0);
5888c2ecf20Sopenharmony_ci	if (fdt == -1)
5898c2ecf20Sopenharmony_ci		error(1, errno, "socket t");
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_ci	/* Do not fragment these datagrams: only succeed if GSO works */
5928c2ecf20Sopenharmony_ci	set_pmtu_discover(fdt, addr->sa_family == AF_INET);
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ci	if (cfg_do_connectionless) {
5958c2ecf20Sopenharmony_ci		set_device_mtu(fdt, CONST_MTU_TEST);
5968c2ecf20Sopenharmony_ci		run_all(fdt, fdr, addr, alen);
5978c2ecf20Sopenharmony_ci	}
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci	if (cfg_do_connected) {
6008c2ecf20Sopenharmony_ci		set_device_mtu(fdt, CONST_MTU_TEST + 100);
6018c2ecf20Sopenharmony_ci		set_route_mtu(CONST_MTU_TEST, addr->sa_family == AF_INET);
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ci		if (connect(fdt, addr, alen))
6048c2ecf20Sopenharmony_ci			error(1, errno, "connect");
6058c2ecf20Sopenharmony_ci
6068c2ecf20Sopenharmony_ci		val = get_path_mtu(fdt, addr->sa_family == AF_INET);
6078c2ecf20Sopenharmony_ci		if (val != CONST_MTU_TEST)
6088c2ecf20Sopenharmony_ci			error(1, 0, "bad path mtu %u\n", val);
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_ci		run_all(fdt, fdr, addr, 0 /* use connected addr */);
6118c2ecf20Sopenharmony_ci	}
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_ci	if (close(fdt))
6148c2ecf20Sopenharmony_ci		error(1, errno, "close t");
6158c2ecf20Sopenharmony_ci	if (close(fdr))
6168c2ecf20Sopenharmony_ci		error(1, errno, "close r");
6178c2ecf20Sopenharmony_ci}
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_cistatic void run_test_v4(void)
6208c2ecf20Sopenharmony_ci{
6218c2ecf20Sopenharmony_ci	struct sockaddr_in addr = {0};
6228c2ecf20Sopenharmony_ci
6238c2ecf20Sopenharmony_ci	addr.sin_family = AF_INET;
6248c2ecf20Sopenharmony_ci	addr.sin_port = htons(cfg_port);
6258c2ecf20Sopenharmony_ci	addr.sin_addr = addr4;
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_ci	run_test((void *)&addr, sizeof(addr));
6288c2ecf20Sopenharmony_ci}
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_cistatic void run_test_v6(void)
6318c2ecf20Sopenharmony_ci{
6328c2ecf20Sopenharmony_ci	struct sockaddr_in6 addr = {0};
6338c2ecf20Sopenharmony_ci
6348c2ecf20Sopenharmony_ci	addr.sin6_family = AF_INET6;
6358c2ecf20Sopenharmony_ci	addr.sin6_port = htons(cfg_port);
6368c2ecf20Sopenharmony_ci	addr.sin6_addr = addr6;
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci	run_test((void *)&addr, sizeof(addr));
6398c2ecf20Sopenharmony_ci}
6408c2ecf20Sopenharmony_ci
6418c2ecf20Sopenharmony_cistatic void parse_opts(int argc, char **argv)
6428c2ecf20Sopenharmony_ci{
6438c2ecf20Sopenharmony_ci	int c;
6448c2ecf20Sopenharmony_ci
6458c2ecf20Sopenharmony_ci	while ((c = getopt(argc, argv, "46cCmst:")) != -1) {
6468c2ecf20Sopenharmony_ci		switch (c) {
6478c2ecf20Sopenharmony_ci		case '4':
6488c2ecf20Sopenharmony_ci			cfg_do_ipv4 = true;
6498c2ecf20Sopenharmony_ci			break;
6508c2ecf20Sopenharmony_ci		case '6':
6518c2ecf20Sopenharmony_ci			cfg_do_ipv6 = true;
6528c2ecf20Sopenharmony_ci			break;
6538c2ecf20Sopenharmony_ci		case 'c':
6548c2ecf20Sopenharmony_ci			cfg_do_connected = true;
6558c2ecf20Sopenharmony_ci			break;
6568c2ecf20Sopenharmony_ci		case 'C':
6578c2ecf20Sopenharmony_ci			cfg_do_connectionless = true;
6588c2ecf20Sopenharmony_ci			break;
6598c2ecf20Sopenharmony_ci		case 'm':
6608c2ecf20Sopenharmony_ci			cfg_do_msgmore = true;
6618c2ecf20Sopenharmony_ci			break;
6628c2ecf20Sopenharmony_ci		case 's':
6638c2ecf20Sopenharmony_ci			cfg_do_setsockopt = true;
6648c2ecf20Sopenharmony_ci			break;
6658c2ecf20Sopenharmony_ci		case 't':
6668c2ecf20Sopenharmony_ci			cfg_specific_test_id = strtoul(optarg, NULL, 0);
6678c2ecf20Sopenharmony_ci			break;
6688c2ecf20Sopenharmony_ci		default:
6698c2ecf20Sopenharmony_ci			error(1, 0, "%s: parse error", argv[0]);
6708c2ecf20Sopenharmony_ci		}
6718c2ecf20Sopenharmony_ci	}
6728c2ecf20Sopenharmony_ci}
6738c2ecf20Sopenharmony_ci
6748c2ecf20Sopenharmony_ciint main(int argc, char **argv)
6758c2ecf20Sopenharmony_ci{
6768c2ecf20Sopenharmony_ci	parse_opts(argc, argv);
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci	if (cfg_do_ipv4)
6798c2ecf20Sopenharmony_ci		run_test_v4();
6808c2ecf20Sopenharmony_ci	if (cfg_do_ipv6)
6818c2ecf20Sopenharmony_ci		run_test_v6();
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci	fprintf(stderr, "OK\n");
6848c2ecf20Sopenharmony_ci	return 0;
6858c2ecf20Sopenharmony_ci}
686