Received: by 10.213.65.68 with SMTP id h4csp44918imn; Mon, 19 Mar 2018 19:01:49 -0700 (PDT) X-Google-Smtp-Source: AG47ELvoHYetVeuAdvHYsj6iv8YgBlE4E7Lu+n7bZoJYcJBWlzpiLR+NsqIg6qDzON06GJ5oRgfy X-Received: by 10.101.101.133 with SMTP id u5mr10628647pgv.151.1521511308947; Mon, 19 Mar 2018 19:01:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521511308; cv=none; d=google.com; s=arc-20160816; b=m50uS1KsV1aaNtX0X+NWj3PVFQ7dEjrHutm8yY69Bz6KbbsAxiKL5Y3epR91F+y0p5 GN0xo+827kI+OpJGEJZSOj+bGgThJnHWPrKz+p/wh+6mAdBs6nG6fSEmULRA7pHljik4 5+C2DK3xHjsRxg+6oBpOesSB0lA5MrAp2aLIteZu9ZPZqSSwBJPUg5GR11hirT3YENSJ 3n8HSJv/Vdf09JRYnRHbt4NKmclF0GjYoOkbOxRrOKZH1FrPY+0x3fAFH8cj2xjjwEpM vAuslwm5o/esNW9rUZmJ1biW1OchAAenacvpX8gug5L2v6VlCecb3qj1kFXsk0+4jfSs L6jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=VVzIXZ1sDSuV/dyW2p1PlX/nFn9DgYOmSYRVIWDMV3E=; b=wzpV0zg5w5SBBwECOZ7zuoiSFyah8HeCwqh/BYnYhoQRLD9J5cKmPK0xnVD1iXKTvp 4E5C0qbR9m/aH9mewIXRkwNn/DvXdpPp01xCji0xMMqZ3kH2cplnvmKIJBblaK67TwnD kKAynWYIVJZC5T+EFT2BEB9NijXrW2Tu13wW3aJIbD44/zedNK8kGcY16unHa7SV7UK5 0OfDNDda+U8WkhJyw3bRUEKFkEE95XhMLsa85rcpeDpIvCiBiYKHAEm04ptpktFwCofj pFZMtAD5g+mMQJcBNY0meHPyoefMED1yoo5hrKxJtfZ+j/kQqbwvRN/4GF7zgqpM9QyM esQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=LzPQfUiz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g126si435639pfc.395.2018.03.19.19.01.34; Mon, 19 Mar 2018 19:01:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=LzPQfUiz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933903AbeCSWg4 (ORCPT + 99 others); Mon, 19 Mar 2018 18:36:56 -0400 Received: from mail-co1nam03on0122.outbound.protection.outlook.com ([104.47.40.122]:59200 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933301AbeCSPrj (ORCPT ); Mon, 19 Mar 2018 11:47:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=VVzIXZ1sDSuV/dyW2p1PlX/nFn9DgYOmSYRVIWDMV3E=; b=LzPQfUizJAwv/Vevge5WObIdsOhtsYCzFcAIur7i05i4gQ8j60pNJw9Dbyu7B7pgyEXsvEbhDli5isN0s/Q8GZmEETTPKREF6IwcakjP8nBzpZefEvDzj+UldV9cN7HiK8WhSPCLJmns83MSaaNzyX10duXwjTIgR0s5YDALLO8= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0998.namprd21.prod.outlook.com (52.132.133.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.631.0; Mon, 19 Mar 2018 15:47:30 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 15:47:30 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Sowmini Varadhan , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 029/124] selftests/net: fix bugs in address and port initialization Thread-Topic: [PATCH AUTOSEL for 4.15 029/124] selftests/net: fix bugs in address and port initialization Thread-Index: AQHTv5mVzIcLezXKeUeW6dJI+VkoBQ== Date: Mon, 19 Mar 2018 15:47:28 +0000 Message-ID: <20180319154645.11350-29-alexander.levin@microsoft.com> References: <20180319154645.11350-1-alexander.levin@microsoft.com> In-Reply-To: <20180319154645.11350-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0998;7:zWhBGCmxKKPwnWk+/eMQCFfkwVDwZC9G3JaASyiP4KIyf6fo0TV6JveRuhWAVAdq4/uCufbXrnNod2gXFGXAa5NMnC3gugE5eeIn+bFCKUh94ahLVY4/cIZT3TyQjvmwmjHjPUIOexWgSwtHLXF1tU3tmdVaAZJnMlwJ3ggYfIQAq3jkjTYbaRYy1jcSgUMuK9kII7IDSw4lWpiZnkN6E3//hM6F6pg6q+QL5sN+3b4tD7FBV7m9WWArO4+QYiYl;20:dgyrErk6NuCmwIuGHeayNXSNGofh6bf2XFnhLoHHn5sgKb4UzLxunrPSfVi5N8GThuETmZW6NCvQeGk4cxkkjJwZPL+lgOUuBfnPlw1pihb6zMSVn7kBV6Imc62N5brOJW+OKBMcJY5KvSyYI4b13Nk63FPXBlmob/ectU0Ks0A= x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 874bc67b-78e2-4a87-f4bb-08d58db0b960 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0998; x-ms-traffictypediagnostic: DM5PR2101MB0998: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(211936372134217)(153496737603132)(21532816269658)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231221)(944501300)(52105095)(3002001)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0998;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0998; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(39860400002)(366004)(376002)(396003)(346002)(199004)(189003)(3846002)(6116002)(8936002)(6486002)(102836004)(68736007)(6506007)(2900100001)(22452003)(25786009)(3660700001)(7736002)(76176011)(6512007)(72206003)(86362001)(575784001)(53936002)(8676002)(81156014)(6436002)(81166006)(305945005)(478600001)(99286004)(2950100002)(14454004)(10290500003)(186003)(107886003)(2501003)(106356001)(26005)(86612001)(97736004)(5660300001)(10090500001)(110136005)(54906003)(316002)(2906002)(66066001)(105586002)(4326008)(36756003)(3280700002)(1076002)(5250100002)(59450400001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0998;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: SQhUO77Ekfx/NSVj30WONVPmleKvjFs3RePBeMSXJWARty0XFf4qXQAfagVdQ6XMgcaS4R7wxzdzMLuEBe1ukVSrxgFzeEDRHNjEt78PwwxwfENimrTs/cblJMn88HwrJh0/J54ngQbF23JK47Ddkv3jp6ipJHFHqAAF1LXqKiQiAAXb42AC5DyXjFBlQOs7OO9tHkXImwJzKY1zVobM/aiWWQcYoluC/3+j3YSiz3hrnDYxEI4tTdblvmR6u2PiUXIHBBdQFosrHetCGyHgA/ojwn95l+RgJ+YWRRFZHox8xSCtOzmibmZQNaHxpvndJpBLn7LbwjnGfGcpX6ZAgg== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 874bc67b-78e2-4a87-f4bb-08d58db0b960 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 15:47:28.8720 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0998 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sowmini Varadhan [ Upstream commit d36f45e5b46723cf2d4147173e18c52d4143176d ] Address/port initialization should work correctly regardless of the order in which command line arguments are supplied, E.g, cfg_port should be used to connect to the remote host even if it is processed after -D, src/dst address initialization should not require that [-4|-6] be specified before the -S or -D args, receiver should be able to bind to *. Achieve this by making sure that the address/port structures are initialized after all command line options are parsed. Store cfg_port in host-byte order, and use htons() to set up the sin_port/sin6_port before bind/connect, so that the network system calls get the correct values in network-byte order. Signed-off-by: Sowmini Varadhan Acked-by: Willem de Bruijn Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- tools/testing/selftests/net/msg_zerocopy.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/net/msg_zerocopy.c b/tools/testing/sel= ftests/net/msg_zerocopy.c index 3ab6ec403905..e11fe84de0fd 100644 --- a/tools/testing/selftests/net/msg_zerocopy.c +++ b/tools/testing/selftests/net/msg_zerocopy.c @@ -259,22 +259,28 @@ static int setup_ip6h(struct ipv6hdr *ip6h, uint16_t = payload_len) return sizeof(*ip6h); } =20 -static void setup_sockaddr(int domain, const char *str_addr, void *sockadd= r) + +static void setup_sockaddr(int domain, const char *str_addr, + struct sockaddr_storage *sockaddr) { struct sockaddr_in6 *addr6 =3D (void *) sockaddr; struct sockaddr_in *addr4 =3D (void *) sockaddr; =20 switch (domain) { case PF_INET: + memset(addr4, 0, sizeof(*addr4)); addr4->sin_family =3D AF_INET; addr4->sin_port =3D htons(cfg_port); - if (inet_pton(AF_INET, str_addr, &(addr4->sin_addr)) !=3D 1) + if (str_addr && + inet_pton(AF_INET, str_addr, &(addr4->sin_addr)) !=3D 1) error(1, 0, "ipv4 parse error: %s", str_addr); break; case PF_INET6: + memset(addr6, 0, sizeof(*addr6)); addr6->sin6_family =3D AF_INET6; addr6->sin6_port =3D htons(cfg_port); - if (inet_pton(AF_INET6, str_addr, &(addr6->sin6_addr)) !=3D 1) + if (str_addr && + inet_pton(AF_INET6, str_addr, &(addr6->sin6_addr)) !=3D 1) error(1, 0, "ipv6 parse error: %s", str_addr); break; default: @@ -603,6 +609,7 @@ static void parse_opts(int argc, char **argv) sizeof(struct tcphdr) - 40 /* max tcp options */; int c; + char *daddr =3D NULL, *saddr =3D NULL; =20 cfg_payload_len =3D max_payload_len; =20 @@ -627,7 +634,7 @@ static void parse_opts(int argc, char **argv) cfg_cpu =3D strtol(optarg, NULL, 0); break; case 'D': - setup_sockaddr(cfg_family, optarg, &cfg_dst_addr); + daddr =3D optarg; break; case 'i': cfg_ifindex =3D if_nametoindex(optarg); @@ -638,7 +645,7 @@ static void parse_opts(int argc, char **argv) cfg_cork_mixed =3D true; break; case 'p': - cfg_port =3D htons(strtoul(optarg, NULL, 0)); + cfg_port =3D strtoul(optarg, NULL, 0); break; case 'r': cfg_rx =3D true; @@ -647,7 +654,7 @@ static void parse_opts(int argc, char **argv) cfg_payload_len =3D strtoul(optarg, NULL, 0); break; case 'S': - setup_sockaddr(cfg_family, optarg, &cfg_src_addr); + saddr =3D optarg; break; case 't': cfg_runtime_ms =3D 200 + strtoul(optarg, NULL, 10) * 1000; @@ -660,6 +667,8 @@ static void parse_opts(int argc, char **argv) break; } } + setup_sockaddr(cfg_family, daddr, &cfg_dst_addr); + setup_sockaddr(cfg_family, saddr, &cfg_src_addr); =20 if (cfg_payload_len > max_payload_len) error(1, 0, "-s: payload exceeds max (%d)", max_payload_len); --=20 2.14.1