From nobody Sun Jun 12 17:21:12 2022 X-Original-To: freebsd-net@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E0FC685E3AE; Sun, 12 Jun 2022 17:21:24 +0000 (UTC) (envelope-from tuexen@freebsd.org) Received: from drew.franken.de (mail-n.franken.de [193.175.24.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.franken.de", Issuer "Sectigo RSA Domain Validation Secure Server CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LLhLr0z1Nz4jmr; Sun, 12 Jun 2022 17:21:24 +0000 (UTC) (envelope-from tuexen@freebsd.org) Received: from smtpclient.apple (unknown [IPv6:2a02:8109:1140:c3d:c1b4:b153:a9c1:8f80]) (Authenticated sender: macmic) by drew.franken.de (Postfix) with ESMTPSA id F03C67446B3C6; Sun, 12 Jun 2022 19:21:13 +0200 (CEST) Content-Type: text/plain; charset=utf-8 List-Id: Networking and TCP/IP with FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-net List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-net@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) Subject: Re: Troubles with adding IPv6 support to a program From: tuexen@freebsd.org In-Reply-To: Date: Sun, 12 Jun 2022 19:21:12 +0200 Cc: freebsd-net , freebsd-transport@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: <91695911-4B92-4D3D-A532-9D51B8ACB22F@freebsd.org> References: To: Chris Ross X-Mailer: Apple Mail (2.3696.100.31) X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on mail-n.franken.de X-Rspamd-Queue-Id: 4LLhLr0z1Nz4jmr X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=softfail (mx1.freebsd.org: 193.175.24.27 is neither permitted nor denied by domain of tuexen@freebsd.org) smtp.mailfrom=tuexen@freebsd.org X-Spamd-Result: default: False [-2.05 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FREEFALL_USER(0.00)[tuexen]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; MV_CASE(0.50)[]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_RCPT(0.00)[freebsd]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[freebsd.org]; R_SPF_SOFTFAIL(0.00)[~all:c]; NEURAL_HAM_LONG(-1.00)[-1.000]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_HAM_SHORT(-0.35)[-0.351]; FROM_NO_DN(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; MLMMJ_DEST(0.00)[freebsd-net,freebsd-transport]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:680, ipnet:193.174.0.0/15, country:DE]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; RCVD_IN_DNSWL_LOW(-0.10)[193.175.24.27:from] X-ThisMailContainsUnwantedMimeParts: N > On 12. Jun 2022, at 18:40, Chris Ross = wrote: >=20 >=20 > Tl;dr; > I don=E2=80=99t know why I=E2=80=99m getting an EINVAL from a call to = bind for a second socket >=20 >=20 >=20 >=20 > 20 years ago, I spent a lot of time adding IPv6 support to IPv4-only = programs. > So I thought this (adding IPv6 support to simpleproxy[1]) would be an = easy > project to pick up. I=E2=80=99ve gotten most of the framework in, = delayed only > slightly when I learned that FreeBSD is =E2=80=9Cdifferent=E2=80=9D in = not routing IPv4 > traffic to AF_INET6 sockets [2]. >=20 > However, I=E2=80=99m getting an issue from one of my bind(2) calls = that I=E2=80=99m not able > to figure out. I was hoping someone else had a few minutes to take a = quick > look and help me find out what I=E2=80=99m doing wrong. >=20 > A ~70 line relevant section of the source is at = https://justpaste.it/6u3jd >=20 > The tl;dr; of this is that I: >=20 > * getaddrinfo(NULL, portIwant) > * for each address returned: > * create a socket > * setsockopt(SO_REUSEADDR) > * bind > * listen >=20 > The first address I get is IPv6 localhost, and that binds and listens, = then > continues to the next address. A new socket is created, = setsockopt=E2=80=99d, but > bind for the second address (IPv4 localhost) fails with EINVAL. >=20 > As you can see in the code shared, I have lots of debugging logs in = the code, > and it looks like everything is as it should be. I=E2=80=99m probably = just missing > Something simple, and am looking for another set of eyes. >=20 > Thanks all. Contact me off list if you like, or on-list if it=E2=80=99s= obvious > what I=E2=80=99ve done and it will help others. Can you provide the output of truss whatever_you_need_to_call_your_program which shows the socket call and the failing bind call? Best regards Michael >=20 > - Chris >=20 >=20 > [1] https://github.com/vzaliva/simpleproxy > [2] inet6(4), "Interaction between IPv4/v6 sockets" >=20