From nobody Sat Jan 11 22:52:04 2025 X-Original-To: dev-commits-src-main@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 4YVv0m25Vpz5jxY6; Sat, 11 Jan 2025 22:52:08 +0000 (UTC) (envelope-from rpokala@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YVv0m1ZHzz4Xht; Sat, 11 Jan 2025 22:52:08 +0000 (UTC) (envelope-from rpokala@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736635928; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=upnsuLm6O2HC5qv9G5skywoKrWuzTsAYCBcQWr0GMM0=; b=tLUfRJkoZI/6xdLzoB34NcjUYdzYW9hoWzRjGou97/aFnlhJi3YlY3WVRSf9dIr2DBJAJl VY3Vrc0d2pqE64C/T79EfBh+ekGtDlCSaQl1k0UoekT2Tfkgqco4TdwmfUJCjjCWMwUpfo XAZCJYcYXx7XGSKsb15yoxCxeWu9zbdgPfIzc7dpROk0ebKRvMoQifOx+7qfJKsmT7LJo/ gkNEqQ5+hTxvgOUiPJCxqCe7jv1RgaNs4vdWTQe7ZWqWpMYudoeCqIhP5+MTKTst3ON5zk Xtn6sEFYMCsg3U5zLk3RFHzwgV2AYjUe7y5bMj0qar1wK1XfaB8VpEfbrbTp0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736635928; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=upnsuLm6O2HC5qv9G5skywoKrWuzTsAYCBcQWr0GMM0=; b=NYpa5OwTzAStXKOxrzRR3IS1LmDKq2uFYoAqsZbhaiXLEM9YU2re1mpl7M0JMnWg2msFL9 XFQuBpAxna6UYsH0GetKrSdydnmvhEL29lBlCQ10UCNy89V/ecj9W/ZSZH+4r/KLzbkxF1 uQ/hlbmjyH8CGRkBs7x4QB5/H1FFGruuN/vZLjdsb1rHRLyTM/oZPaw3eiT5VcmoWzkXIS CC59C7IHpAMaZFED7CVSuCfnoqIIXrCuXn+or1iuAXrrvk8NpVUbXzkB+6YmtC6jDO/xeS 36mZVKlB2NG6zR0pgJeLUX9zcWGAguRaju7eEy+upDvc0i502aQw9Vu0/rPrVg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736635928; a=rsa-sha256; cv=none; b=uPR3ELbsjjWKw0rpoLJT5GcBzWcJU5hY7/gE+Sui3DLxWpPektdhfit9t4hSTTyEr7/m1u aivtTWMOvntV5TZYRsPCIXKeA9EiveorJokxLVreU2l6TFCVo3nocT8PCjKWlN3+z8WNjY lIoYrUaWkUpnm07pMfgElnjRCF43etHsb77djPBqx3LePrtO7vISLtyLJEG+js2hnULvsG 1wHb688Nb0HQ3H+VrRkUIRROb8gFpNeeKEEhleS4Y8k+dSZ37nvZ5u5VKMcoCtUNY7SaY+ UPCxq3DLiYIF5blCIztWqAHke0ZOheLjM2sYJ6I0PI4r7KpVEpmqP7nCt7T2yQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from [192.168.1.53] (c-73-231-46-254.hsd1.ca.comcast.net [73.231.46.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: rpokala) by smtp.freebsd.org (Postfix) with ESMTPSA id 4YVv0l4S0HzJXL; Sat, 11 Jan 2025 22:52:07 +0000 (UTC) (envelope-from rpokala@freebsd.org) User-Agent: Microsoft-MacOutlook/16.92.24120731 Date: Sat, 11 Jan 2025 14:52:04 -0800 Subject: Re: 9234a50752cd - main - ng_ksocket: add IPv6 support for address parsing and unparsing From: Ravi Pokala To: Gleb Smirnoff , , , Message-ID: <700C69CF-197C-42A9-A651-F2BCC7EF666F@panasas.com> Thread-Topic: 9234a50752cd - main - ng_ksocket: add IPv6 support for address parsing and unparsing References: <202501102004.50AK4Jo0018399@gitrepo.freebsd.org> In-Reply-To: <202501102004.50AK4Jo0018399@gitrepo.freebsd.org> List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org Mime-version: 1.0 Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: quoted-printable Hi Gleb, I believe this change breaks LINT-NOINET6 and LINT-NOIP: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >>> stage 3.1: building everything -------------------------------------------------------------- linking kernel ld: error: undefined symbol: in6_getscope >>> referenced by ng_ksocket.c >>> ng_ksocket.o:(ng_ksocket_sockaddr_parse) ld: error: undefined symbol: in6_getscopezone >>> referenced by ng_ksocket.c >>> ng_ksocket.o:(ng_ksocket_sockaddr_parse) --- kernel --- *** [kernel] Error code 1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Thanks, Ravi (rpokala@0 =EF=BB=BF-----Original Message----- From: > on behalf of Gleb Smirnoff > Date: Friday, January 10, 2025 at 12:04 To: >, >, > Subject: git: 9234a50752cd - main - ng_ksocket: add IPv6 support for addres= s parsing and unparsing The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=3D9234a50752cd47887849d4665af0f9= f4abdefb5d commit 9234a50752cd47887849d4665af0f9f4abdefb5d Author: Seyed Pouria Mousavizadeh Tehrani > AuthorDate: 2025-01-10 09:16:18 +0000 Commit: Gleb Smirnoff > CommitDate: 2025-01-10 20:00:58 +0000 ng_ksocket: add IPv6 support for address parsing and unparsing Differential Revision: https://reviews.freebsd.org/D48204 --- share/man/man4/ng_ksocket.4 | 13 +++++-- sys/netgraph/ng_ksocket.c | 94 ++++++++++++++++++++++++++++++++++++++++++--= - 2 files changed, 98 insertions(+), 9 deletions(-) diff --git a/share/man/man4/ng_ksocket.4 b/share/man/man4/ng_ksocket.4 index 1f32d39dc7d0..bb653c3688ad 100644 --- a/share/man/man4/ng_ksocket.4 +++ b/share/man/man4/ng_ksocket.4 @@ -32,7 +32,7 @@ .\" .\" Author: Archie Cobbs > .\" -.Dd January 9, 2012 +.Dd January 9, 2025 .Dt NG_KSOCKET 4 .Os .Sh NAME @@ -183,7 +183,8 @@ in the argument field, the normal equivalent of the C structure is an acceptable form. For the -.Dv PF_INET +.Dv PF_INET , +.Dv PF_INET6 and .Dv PF_LOCAL address families, a more convenient form is also used, which is @@ -191,7 +192,11 @@ the protocol family name, followed by a slash, followe= d by the actual address. For .Dv PF_INET , -the address is an IP address followed by an optional colon and port number= . +the address is an IPv4 address followed by an optional colon and port numb= er. +For +.Dv PF_INET6 , +the address is an IPv6 address enclosed in square brackets followed +by an optional colon and port number. For .Dv PF_LOCAL , the address is the pathname as a doubly quoted string. @@ -202,6 +207,8 @@ Examples: local/"/tmp/foo.socket" .It Dv PF_INET inet/192.168.1.1:1234 +.It Dv PF_INET6 +inet6/[2001::1]:1234 .It Other .Dv "\&{ family=3D16 len=3D16 data=3D[0x70 0x00 0x01 0x23] \&}" .El diff --git a/sys/netgraph/ng_ksocket.c b/sys/netgraph/ng_ksocket.c index 3e4427f9e387..43a2747224f3 100644 --- a/sys/netgraph/ng_ksocket.c +++ b/sys/netgraph/ng_ksocket.c @@ -58,6 +58,9 @@ #include #include +#include +#include + #include #include #include @@ -66,6 +69,8 @@ #include #include +#include + #ifdef NG_SEPARATE_MALLOC static MALLOC_DEFINE(M_NETGRAPH_KSOCKET, "netgraph_ksock", "netgraph ksock node"); @@ -147,6 +152,19 @@ static const struct ng_ksocket_alias ng_ksocket_protos= [] =3D { { "swipe", IPPROTO_SWIPE, PF_INET }, { "encap", IPPROTO_ENCAP, PF_INET }, { "pim", IPPROTO_PIM, PF_INET }, + { "ip6", IPPROTO_IPV6, PF_INET6 }, + { "raw6", IPPROTO_RAW, PF_INET6 }, + { "icmp6", IPPROTO_ICMPV6, PF_INET6 }, + { "igmp6", IPPROTO_IGMP, PF_INET6 }, + { "tcp6", IPPROTO_TCP, PF_INET6 }, + { "udp6", IPPROTO_UDP, PF_INET6 }, + { "gre6", IPPROTO_GRE, PF_INET6 }, + { "esp6", IPPROTO_ESP, PF_INET6 }, + { "ah6", IPPROTO_AH, PF_INET6 }, + { "swipe6", IPPROTO_SWIPE, PF_INET6 }, + { "encap6", IPPROTO_ENCAP, PF_INET6 }, + { "divert6", IPPROTO_DIVERT, PF_INET6 }, + { "pim6", IPPROTO_PIM, PF_INET6 }, { NULL, -1 }, }; @@ -296,9 +314,58 @@ ng_ksocket_sockaddr_parse(const struct ng_parse_type *= type, break; } -#if 0 - case PF_INET6: /* XXX implement this someday */ -#endif + case PF_INET6: + { + struct sockaddr_in6 *const sin6 =3D (struct sockaddr_in6 *)sa; + char *eptr; + char addr[INET6_ADDRSTRLEN]; + char ifname[16]; + u_long port; + bool hasifname =3D true; + + /* RFC 3986 Section 3.2.2, Validate IP literal within square brackets. */ + if (s[*off] =3D=3D '[' && (strstr(&s[*off], "]"))) + (*off)++; + else + return (EINVAL); + if ((eptr =3D strstr(&s[*off], "%")) =3D=3D NULL) { + hasifname =3D false; + eptr =3D strstr(&s[*off], "]"); + } + snprintf(addr, eptr - (s + *off) + 1, "%s", &s[*off]); + *off +=3D (eptr - (s + *off)); + if (!inet_pton(AF_INET6, addr, &sin6->sin6_addr)) + return (EINVAL); + + if (hasifname) { + uint16_t scope; + + eptr =3D strstr(&s[*off], "]"); + (*off)++; + snprintf(ifname, eptr - (s + *off) + 1, "%s", &s[*off]); + *off +=3D (eptr - (s + *off)); + + if (sin6->sin6_addr.s6_addr16[0] !=3D IPV6_ADDR_INT16_ULL) + return (EINVAL); + scope =3D in6_getscope(&sin6->sin6_addr); + sin6->sin6_scope_id =3D + in6_getscopezone(ifunit(ifname), scope); + } + + (*off)++; + if (s[*off] =3D=3D ':') { + (*off)++; + port =3D strtoul(s + *off, &eptr, 10); + if (port > 0xffff || eptr =3D=3D s + *off) + return (EINVAL); + *off +=3D (eptr - (s + *off)); + sin6->sin6_port =3D htons(port); + } else + sin6->sin6_port =3D 0; + + sin6->sin6_len =3D sizeof(*sin6); + break; + } default: return (EINVAL); @@ -358,9 +425,24 @@ ng_ksocket_sockaddr_unparse(const struct ng_parse_type= *type, return(0); } -#if 0 - case PF_INET6: /* XXX implement this someday */ -#endif + case PF_INET6: + { + const struct sockaddr_in6 *sin6 =3D (const struct sockaddr_in6 *)sa; + char addr[INET6_ADDRSTRLEN]; + + inet_ntop(AF_INET6, &sin6->sin6_addr, addr, INET6_ADDRSTRLEN); + slen +=3D snprintf(cbuf, cbuflen, "inet6/[%s]", addr); + + if (sin6->sin6_port !=3D 0) { + slen +=3D snprintf(cbuf + strlen(cbuf), + cbuflen - strlen(cbuf), ":%d", + (u_int)ntohs(sin6->sin6_port)); + } + if (slen >=3D cbuflen) + return (ERANGE); + *off +=3D sizeof(*sin6); + return(0); + } default: return (*ng_ksocket_generic_sockaddr_type.supertype->unparse)