From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202606 header.b=XDNx6FOR; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 0F8D05A0272 for ; Thu, 02 Jul 2026 02:59:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1782953982; bh=3N9QXbp3aBIo1/1/0JJdY7r81lvyR8WoprKhQN85hbU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XDNx6FORfFbkhKqCM3/A794g4Ku0gJh0dxmndTTPm1PIZrUsCYJsGb7L/R4u5KcF5 6wfcS+IlOuIGdfjJU8NSXYtIrTa2ctAxNVRG6OWQ/ExfmFzLEHM2jEhM4bjZff3dMO YWJabF8RQVH3Y/ps++phYI75MKaczkQDmOzf4/kpmbzy1xxQ38UcrjFj5gcG9G++3s qoKFdQSa01fyhw0IQWY3Ns2Js2R4kcngZqcdH2FVLYzBwtw0CQnLirxS9OlUoS03gr dPbZ/B1hNfTPoaYXJvt7/9p9nQUzTIjPpNE/GZMa61aWHY/aiX9rcOETb5I5JxXBQ7 cAnWEr65DiXmw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4grJSZ1yhNz58mr; Thu, 02 Jul 2026 10:59:42 +1000 (AEST) Date: Thu, 2 Jul 2026 10:59:34 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v2 13/13] fwd_rule: Rewrite forward rule parsing using parse.c helpers Message-ID: References: <20260701053155.1219264-1-david@gibson.dropbear.id.au> <20260701053155.1219264-14-david@gibson.dropbear.id.au> <20260702011159.0aed0531@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="zIuk4KOYE33ny0VC" Content-Disposition: inline In-Reply-To: <20260702011159.0aed0531@elisabeth> Message-ID-Hash: 64MR66X6EHH6XRMF2HZ7W2PGCA2BT4XD X-Message-ID-Hash: 64MR66X6EHH6XRMF2HZ7W2PGCA2BT4XD X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --zIuk4KOYE33ny0VC Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jul 02, 2026 at 01:12:00AM +0200, Stefano Brivio wrote: > On Wed, 1 Jul 2026 15:31:55 +1000 > David Gibson wrote: >=20 > > +++ b/parse.c > > @@ -18,6 +18,7 @@ > > #include > > #include > > #include > > +#include > > =20 > > #include "common.h" > > #include "parse.h" > > @@ -213,3 +214,31 @@ bool parse_inany_(const char **cursor, union inany= _addr *addr, > > =20 > > return false; > > } > > + > > +/** > > + * parse_ifspec() - Parse a interface name specifier (starting with %) > > + * @ifname: On success updated with parsed name (must have IFNAMSIZ sp= ace) > > + * > > + * This will accept a missing specifier (empty string), setting ifname= to "" > > + */ > > +bool parse_ifspec(const char **cursor, char *ifname) > > +{ > > + const char *p =3D *cursor; > > + size_t len; > > + > > + if (!parse_literal(&p, "%")) { > > + /* No interface specifier */ > > + ifname[0] =3D '\0'; > > + return true; > > + } > > + > > + /* ifnames can have anything that's not '/', '.' or whitespace */ > > + len =3D strcspn(p, "/. \f\n\r\t\v"); >=20 > I was about to apply the series when I spotted this: '.' is definitely > valid in interface names, and even commonly used (think of VLANs), it's > just "." and ".." _as an interface name_ that are not supported. Oh, right, I misuderstood. Should have looked at the kernel code myself to confirm, oops. > If we forbid any interface name with '.' we might very well break > somebody's use case. I can fix this up with: >=20 > /* ifnames can't contain /, :, or whitespace */ > len =3D strcspn(p, "/: \f\n\r\t\v"); > if (!len || len >=3D IFNAMSIZ) > return false; >=20 > /* ...and they can't be '..' or '.' either */ > if (!strcmp(p, ".") || !strcmp(p, "..")) > return false; >=20 > if you're fine with it That won't quite work: the string doesn't end at the end of the interface name. Plus, in my experience you get much better error reporting if you generally try to lexically accept as *much* as possible, then validate, rather than restricting the parser to only accept the minimum it must. I've added a validation of the parsed ifname up in fwd_rule_parse(), instead. I'll post the new spin momentarily. . >=20 > > + if (!len || len >=3D IFNAMSIZ) > > + return false; > > + > > + memcpy(ifname, p, len); > > + ifname[len] =3D '\0'; > > + *cursor =3D p + len; > > + return true; > > +} > > diff --git a/parse.h b/parse.h > > index ab1d5adb..257b9c58 100644 > > --- a/parse.h > > +++ b/parse.h > > @@ -32,4 +32,6 @@ bool parse_inany_(const char **cursor, union inany_ad= dr *addr, > > =20 > > #define parse_inany(cursor, addr) parse_inany_((cursor), (addr), NULL) > > =20 > > +bool parse_ifspec(const char **cursor, char *ifname); > > + > > #endif /* _PARSE_H */ >=20 > --=20 > Stefano >=20 --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --zIuk4KOYE33ny0VC Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmpFt+YACgkQzQJF27ox 2GdZlA//b+FlgloELM45U98uTzUuy3STsovjxGgBvJFQIAvL0ronpCDG0D1uHo+3 cU/c1L2Pvejb+bRfcQq05gfOpH21g5AhJKVT/FhpzaKWKsXSnv5FZQ0ebhq1I44W ks+RUQcVfVpy3wnhLRdJrycYBJHHh+6i69zDzk4rP+nVbmPeWP/ZGTUtwWH0S7Mo r/USA3EZS2Jb6/eZsMtybszkqf3UjIDMQrOJnQYCMeTBpd3hDv+B0515z7y38MeZ A7tYATz+PfKcK6xW4A8cgdE0XTarqwC5SnIKnFxgLcGB2ACYAnxWQNTXT05Dgiy4 XmIixQ22bsp40DFcLUavFyrKPSbCekaylwvYMfJv/IgjYj1o4lUY57mOp3eySeMd YIwoULiHgWnzR2VLeASXrjig4BMQpA6rkszBCMV/mNKMIUX8/+MjKHKdnlkwXSoP wLn3x8dmg38CYk75+Hgk855udQF5W+B9VoFXXOV4+zcIOD0rIrD+pEgJApg+sMoY tVYWNnJa/rfYPlLUsw4MmcmYAsM8MU6FsrflAIVgqRPsNLwuRtxSzwKg4toEJC5B 6S+wW0O+/GND9Q76A0Ops9s48ap57puvb9g5EW2ahtf3kQUyuyBgR8pEvqCe+Q2O ByPWWFjAvQfSF+fX1wv1jrjbqufjw5tM9bcWCLo9vQ2J2TFcujw= =G9kD -----END PGP SIGNATURE----- --zIuk4KOYE33ny0VC--