Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3604235ybt; Tue, 23 Jun 2020 06:33:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwS9EyauR6EraOznV0KJiDoTukpydeQbaBtWU6ylFOrBJrMgetmrDG5q2pLDTt6fcl+LAMR X-Received: by 2002:a05:6402:1c96:: with SMTP id cy22mr10819790edb.79.1592919227353; Tue, 23 Jun 2020 06:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592919227; cv=none; d=google.com; s=arc-20160816; b=TLZIuJeOgripGEqSdYv8D6O4c0MpeV5WainE5ux1QHcSJm80KwFgk/QYTUOMGcjOM8 shsJhNebabQ55EJ9SxxjlZI7liavO0/WFKCWFTgelX9IQTNrtLZpch4XvWJjX7f9CBw+ e94Hp1ByVngUC4E6ktj9eVSskjIQN0LHwiLTbx3fejUXiSfh9h1o0/v4jouLDEl0/FG1 tHDwro+uK+vP33ylChxxvBkLV14A8TnweAtU5iH5h+IW/FPWmQpWnYLy8WtWdRykWBA9 x2Sc+8nPEBEsYTbJDfh5cuNkghQjFVwhC0LUwltZXc7knPf5I4UyGh7+V9cckGeu2qu1 mGiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=ub6EIb3TgA8Jpo13OBAXtKbeSL766tFVGHvGjNMyMNQ=; b=o1qD9o6TZAIVz68AvkRR4TJh0BCTT1jltuJgBCRMGNyqj9d3dgnalFGZZKkUG6PGEw y9KbA/0hbocsP+0zGqiS9Y43cnGn8ut27kA63vGNKoaKnzPZXr5bQujtsKMssoEygbVp NIVlTQGnYh1w/L9WmeQm/jXBQwah/O8tWcedaexP4+ylJaWMD9/D3gazSuoN9Ynkx597 b5/Ofp08mnaiIxfz8s0d/WYxXXiG0W69pfb9l/Nnzk+tVBRMYtzXeZaRtUqozpdWsc4k OufCgVnSvjOXbcaj02lEQhEL44BVLEexk7byxt2BYoU0M1G/53NphM8QOszpHCsx1J7N 7mgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=eSAbODrX; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t11si1470473ejd.575.2020.06.23.06.33.24; Tue, 23 Jun 2020 06:33:47 -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=fail header.i=@gmail.com header.s=20161025 header.b=eSAbODrX; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732658AbgFWN3m (ORCPT + 99 others); Tue, 23 Jun 2020 09:29:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732594AbgFWN3l (ORCPT ); Tue, 23 Jun 2020 09:29:41 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66C8CC061573; Tue, 23 Jun 2020 06:29:40 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id j189so18780396oih.10; Tue, 23 Jun 2020 06:29:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:reply-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ub6EIb3TgA8Jpo13OBAXtKbeSL766tFVGHvGjNMyMNQ=; b=eSAbODrX5kXYXDbA/fGJ8GyyGgKRWH6pNPtlaFIoNcI4PfOAEEFmclsdo51VfHNdvh W2KS48ylKo7JtbHZ7/vMJdcPqN4hMhnBkFXG97qy/rcHUJEuA66fWTpQcQTgTIuVJEkg lJEZ88POgBqnNZxW9/MshYsv2Rnh+00hAWthvUi6DIWu6RbgkYJmczKSy32Br5Lb9NH8 nnLAQjseaf5x5jpDsbAbG66GGXYJ6bW7yEXMSt1NrdOPNQhmSKD6FtYd91/8r9e1LOJN cOYTXUwcTDjOrd+g6/p6Xa/Idll1rEsJscfTLdvaZu0nqyrtBeHaKC+B44XHXoj2cKDz HZtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :reply-to:references:mime-version:content-disposition:in-reply-to :user-agent; bh=ub6EIb3TgA8Jpo13OBAXtKbeSL766tFVGHvGjNMyMNQ=; b=gYxPDCjR1aX87Xz3Jnb/cZKVVa2y98l0dYVGWN0kyCPVtUsQtRh60xV2QUGPoD1ImZ RV+iMDPF7sOZ8qV7DSoc+60HyITv2CwDrfm+7TWS+4sLlr4hRcTh26bjP1/Adt8Rv58u VgaorPnHANc+1vza+/6FIGgnDfcnprsZWQftuIWHIXtScfyLtr8jSnkNlIpXO/CTvIQg lQgjy0JPmnD1nvoAzQCoQgbxJqitJjoQhKwjgBIqoZgRJZJMgfWL1DeBvW1lPZxCOmQR PXsjupq2BnmZHx5Uj1mr8oeY+3I2+Pp00SzigFARyy1pwL9MfF4SBeEiRiWFvosceDjQ jwsg== X-Gm-Message-State: AOAM531vfCAehRW+BLux6fWjeo1tU8BTdRPMJiP+osF/5ipzR9s8ADj3 XE6a8Ft3t0o+sqbXI7tapB2JgB8= X-Received: by 2002:aca:41c2:: with SMTP id o185mr15689600oia.94.1592918979567; Tue, 23 Jun 2020 06:29:39 -0700 (PDT) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id i2sm4052113otp.77.2020.06.23.06.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2020 06:29:38 -0700 (PDT) Received: from minyard.net (unknown [IPv6:2001:470:b8f6:1b:acca:171:3424:849f]) by serve.minyard.net (Postfix) with ESMTPSA id E22B1180050; Tue, 23 Jun 2020 13:29:37 +0000 (UTC) Date: Tue, 23 Jun 2020 08:29:36 -0500 From: Corey Minyard To: Xin Long Cc: Michael Tuexen , Marcelo Ricardo Leitner , Vlad Yasevich , Neil Horman , linux-sctp@vger.kernel.org, LKML Subject: Re: Strange problem with SCTP+IPv6 Message-ID: <20200623132936.GC3235@minyard.net> Reply-To: minyard@acm.org References: <20200621155604.GA23135@minyard.net> <20200622165759.GA3235@minyard.net> <4B68D06C-00F4-42C3-804A-B5531AABCE21@lurchi.franken.de> <20200622183253.GQ2491@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 23, 2020 at 06:13:30PM +0800, Xin Long wrote: > On Tue, Jun 23, 2020 at 2:34 AM Michael Tuexen > wrote: > > > > > On 22. Jun 2020, at 20:32, Marcelo Ricardo Leitner wrote: > > > > > > On Mon, Jun 22, 2020 at 08:01:24PM +0200, Michael Tuexen wrote: > > >>> On 22. Jun 2020, at 18:57, Corey Minyard wrote: > > >>> > > >>> On Mon, Jun 22, 2020 at 08:01:23PM +0800, Xin Long wrote: > > >>>> On Sun, Jun 21, 2020 at 11:56 PM Corey Minyard wrote: > > >>>>> > > >>>>> I've stumbled upon a strange problem with SCTP and IPv6. If I create an > > >>>>> sctp listening socket on :: and set the IPV6_V6ONLY socket option on it, > > >>>>> then I make a connection to it using ::1, the connection will drop after > > >>>>> 2.5 seconds with an ECONNRESET error. > > >>>>> > > >>>>> It only happens on SCTP, it doesn't have the issue if you connect to a > > >>>>> full IPv6 address instead of ::1, and it doesn't happen if you don't > > >>>>> set IPV6_V6ONLY. I have verified current end of tree kernel.org. > > >>>>> I tried on an ARM system and x86_64. > > >>>>> > > >>>>> I haven't dug into the kernel to see if I could find anything yet, but I > > >>>>> thought I would go ahead and report it. I am attaching a reproducer. > > >>>>> Basically, compile the following code: > > >>>> The code only set IPV6_V6ONLY on server side, so the client side will > > >>>> still bind all the local ipv4 addresses (as you didn't call bind() to > > >>>> bind any specific addresses ). Then after the connection is created, > > >>>> the client will send HB on the v4 paths to the server. The server > > >>>> will abort the connection, as it can't support v4. > > >>>> > > >>>> So you can work around it by either: > > >>>> > > >>>> - set IPV6_V6ONLY on client side. > > >>>> > > >>>> or > > >>>> > > >>>> - bind to the specific v6 addresses on the client side. > > >>>> > > >>>> I don't see RFC said something about this. > > >>>> So it may not be a good idea to change the current behaviour > > >>>> to not establish the connection in this case, which may cause regression. > > >>> > > >>> Ok, I understand this. It's a little strange, but I see why it works > > >>> this way. > > >> I don't. I would expect it to work as I described in my email. > > >> Could someone explain me how and why it is behaving different from > > >> my expectation? > > > > > > It looks like a bug to me. Testing with this test app here, I can see > > > the INIT_ACK being sent with a bunch of ipv4 addresses in it and > > > that's unexpected for a v6only socket. As is, it's the server saying > > > "I'm available at these other addresses too, but not." > > I agree. > Then we need a fix in sctp_bind_addrs_to_raw(): > > @@ -238,6 +240,9 @@ union sctp_params sctp_bind_addrs_to_raw(const > struct sctp_bind_addr *bp, > addrparms = retval; > > list_for_each_entry(addr, &bp->address_list, list) { > + if ((PF_INET6 == sk->sk_family) && inet_v6_ipv6only(sk) && > + (AF_INET == addr->a.sa.sa_family)) > + continue; This does not compile in the latest mainline. sk is not defined. Also, if you could send a normal git patch, that would be easier to manage. Thanks, -corey > af = sctp_get_af_specific(addr->a.v4.sin_family); > len = af->to_addr_param(&addr->a, &rawaddr); > memcpy(addrparms.v, &rawaddr, len); > > > > > Best regards > > Michael > > > > > > Thanks, > > > Marcelo > > > > > >> > > >> Best regards > > >> Michael > > >>> > > >>> Thanks, > > >>> > > >>> -corey > > >>> > > >>>> > > >>>>> > > >>>>> gcc -g -o sctptest -Wall sctptest.c > > >>>>> > > >>>>> and run it in one window as a server: > > >>>>> > > >>>>> ./sctptest a > > >>>>> > > >>>>> (Pass in any option to be the server) and run the following in another > > >>>>> window as the client: > > >>>>> > > >>>>> ./sctptest > > >>>>> > > >>>>> It disconnects after about 2.5 seconds. If it works, it should just sit > > >>>>> there forever. > > >>>>> > > >>>>> -corey > > >>>>> > > >>>>> > > >>>>> #include > > >>>>> #include > > >>>>> #include > > >>>>> #include > > >>>>> #include > > >>>>> #include > > >>>>> #include > > >>>>> #include > > >>>>> #include > > >>>>> #include > > >>>>> #include > > >>>>> > > >>>>> static int > > >>>>> getaddr(const char *addr, const char *port, bool listen, > > >>>>> struct addrinfo **rai) > > >>>>> { > > >>>>> struct addrinfo *ai, hints; > > >>>>> > > >>>>> memset(&hints, 0, sizeof(hints)); > > >>>>> hints.ai_flags = AI_ADDRCONFIG; > > >>>>> if (listen) > > >>>>> hints.ai_flags |= AI_PASSIVE; > > >>>>> hints.ai_family = AF_UNSPEC; > > >>>>> hints.ai_socktype = SOCK_STREAM; > > >>>>> hints.ai_protocol = IPPROTO_SCTP; > > >>>>> if (getaddrinfo(addr, port, &hints, &ai)) { > > >>>>> perror("getaddrinfo"); > > >>>>> return -1; > > >>>>> } > > >>>>> > > >>>>> *rai = ai; > > >>>>> return 0; > > >>>>> } > > >>>>> > > >>>>> static int > > >>>>> waitread(int s) > > >>>>> { > > >>>>> char data[1]; > > >>>>> ssize_t rv; > > >>>>> > > >>>>> rv = read(s, data, sizeof(data)); > > >>>>> if (rv == -1) { > > >>>>> perror("read"); > > >>>>> return -1; > > >>>>> } > > >>>>> printf("Read %d bytes\n", (int) rv); > > >>>>> return 0; > > >>>>> } > > >>>>> > > >>>>> static int > > >>>>> do_server(void) > > >>>>> { > > >>>>> int err, ls, s, optval; > > >>>>> struct addrinfo *ai; > > >>>>> > > >>>>> printf("Server\n"); > > >>>>> > > >>>>> err = getaddr("::", "3023", true, &ai); > > >>>>> if (err) > > >>>>> return err; > > >>>>> > > >>>>> ls = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); > > >>>>> if (ls == -1) { > > >>>>> perror("socket"); > > >>>>> return -1; > > >>>>> } > > >>>>> > > >>>>> optval = 1; > > >>>>> if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, > > >>>>> (void *)&optval, sizeof(optval)) == -1) { > > >>>>> perror("setsockopt reuseaddr"); > > >>>>> return -1; > > >>>>> } > > >>>>> > > >>>>> /* Comment this out and it will work. */ > > >>>>> if (setsockopt(ls, IPPROTO_IPV6, IPV6_V6ONLY, &optval, > > >>>>> sizeof(optval)) == -1) { > > >>>>> perror("setsockopt ipv6 only"); > > >>>>> return -1; > > >>>>> } > > >>>>> > > >>>>> err = bind(ls, ai->ai_addr, ai->ai_addrlen); > > >>>>> if (err == -1) { > > >>>>> perror("bind"); > > >>>>> return -1; > > >>>>> } > > >>>>> > > >>>>> err = listen(ls, 5); > > >>>>> if (err == -1) { > > >>>>> perror("listen"); > > >>>>> return -1; > > >>>>> } > > >>>>> > > >>>>> s = accept(ls, NULL, NULL); > > >>>>> if (s == -1) { > > >>>>> perror("accept"); > > >>>>> return -1; > > >>>>> } > > >>>>> > > >>>>> close(ls); > > >>>>> > > >>>>> err = waitread(s); > > >>>>> close(s); > > >>>>> return err; > > >>>>> } > > >>>>> > > >>>>> static int > > >>>>> do_client(void) > > >>>>> { > > >>>>> int err, s; > > >>>>> struct addrinfo *ai; > > >>>>> > > >>>>> printf("Client\n"); > > >>>>> > > >>>>> err = getaddr("::1", "3023", false, &ai); > > >>>>> if (err) > > >>>>> return err; > > >>>>> > > >>>>> s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); > > >>>>> if (s == -1) { > > >>>>> perror("socket"); > > >>>>> return -1; > > >>>>> } > > >>>>> > > >>>>> err = connect(s, ai->ai_addr, ai->ai_addrlen); > > >>>>> if (err == -1) { > > >>>>> perror("connect"); > > >>>>> return -1; > > >>>>> } > > >>>>> > > >>>>> err = waitread(s); > > >>>>> close(s); > > >>>>> return err; > > >>>>> } > > >>>>> > > >>>>> int > > >>>>> main(int argc, char *argv[]) > > >>>>> { > > >>>>> int err; > > >>>>> > > >>>>> if (argc > 1) > > >>>>> err = do_server(); > > >>>>> else > > >>>>> err = do_client(); > > >>>>> return !!err; > > >>>>> } > > >>>>> > > >> > >