From nobody Thu Oct 2 14:26:15 2025 Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBCA43218DD; Mon, 15 Sep 2025 14:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947670; cv=none; b=hn3dn+2WG7OfrG4VJ7dOZ63j4IahOeMjAMoeYiTUrOjG9FxaO3jlDimLiwXSS2D1NIrqVzOb2MVLGZQn0IqoU41TT8aopkXLcOwkxwFvwttr19EDC9ovPkAatWYvT4b0fKcoD1UHM10+dFZzmmmkQYm9aBbGAs7OM47bUxL4Q9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947670; c=relaxed/simple; bh=pnz1Z9RsFEA/w79qMxEPA9j3gcVp4d2qUkVblwMqsWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Nm5FcHDISQQ1bxxM98vbFyOan75Gyb1fFPJ8SyWYoBSpLyShH5vumqYOs2areao52f2pFhlnVml3F4Hxuwnuic/Pe45/PhX9zcUJ6L2SmsJ1rAsUDNJtynr16i0Cs9vlRcDrLRbyxLQG+9FZOGk5aASt46r1/Z+MdE9kR1ImEuQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=hoMUSXVK; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="hoMUSXVK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757947660; bh=pnz1Z9RsFEA/w79qMxEPA9j3gcVp4d2qUkVblwMqsWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hoMUSXVKFfde3bsoRfAP+zKKVg8wQ4eLCkWF1SzvhH1Wb6HPrw1v8MmYimae+etjC Sn9cxM2gVRlBrAJuYUrDNhJMzt9o5bHQg/M67nFE8tf/b5V7cwR3spDypevXEYSKp/ IccJ6FRAys2IHLZOPcLEy61sP/qfB4LJGQDbAHROORyWNHwoffBho6lYDWUb8X/hPF lw59aqHGpAJ0oUVcEIXYIyA/2oTwtWXagwKy9bjzk8Lr7o7DPy1GiKvpypIuRa3o7w +jmI9PQiTe8MEDl3ZeVoyohEV43LO1fMh3WPu34OExv4gZIuJtSiRhSTAaL6RMm2Za VQtXhQFWrs7pQ== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id CD0FB6000C; Mon, 15 Sep 2025 14:47:39 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 06495201B79; Mon, 15 Sep 2025 14:43:06 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: "Jason A. Donenfeld" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Donald Hunter , Simon Horman , Jacob Keller , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 01/11] tools: ynl-gen: allow overriding name-prefix for constants Date: Mon, 15 Sep 2025 14:42:46 +0000 Message-ID: <20250915144301.725949-2-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250915144301.725949-1-ast@fiberby.net> References: <20250915144301.725949-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Allow using custom name-prefix with constants, just like it is for enum and flags declarations. This is needed for generating WG_KEY_LEN in include/uapi/linux/wireguard.h from a spec. Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen Reviewed-by: Donald Hunter Reviewed-by: Jakub Kicinski Reviewed-by: Jacob Keller --- tools/net/ynl/pyynl/ynl_gen_c.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen= _c.py index 101d8ba9626f..c8b15569ecc1 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -3208,8 +3208,9 @@ def render_uapi(family, cw): cw.block_end(line=3D';') cw.nl() elif const['type'] =3D=3D 'const': + name_pfx =3D const.get('name-prefix', f"{family.ident_name}-") defines.append([c_upper(family.get('c-define-name', - f"{family.ident_name}-{cons= t['name']}")), + f"{name_pfx}{const['name']}= ")), const['value']]) =20 if defines: --=20 2.51.0 From nobody Thu Oct 2 14:26:15 2025 Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48CEE33EB09; Mon, 15 Sep 2025 14:47:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947673; cv=none; b=Im5x5Y/PcwnHZGwzjtF4qjyX3jymAU4uNW9AGJiw6FaOj7BeNZQiWkRc6HnwQxtBqG/MkPTBrA5/bj/5IVaYv84QjNj7imtdEz6VbJk+lYoAhGbfR3L+ECF1xZ7lFlSlGqw2AF1EE9EWoIEd79+qU6VmoMlSmxQs0/A4lM+MpDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947673; c=relaxed/simple; bh=B0xFRM28DmWIgrG1Q+a6XZkJNRKEo5x4SQ82oQgZwfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Gf/cadaPyzljy6id84QCbIs4Xpfe2RCCpIJ+6P8shGhjJnrSDfdCLwb2hBqTcK3lCob28poRnfwlM3nYO0tA1t4rXIpyyylloEVHSF/3MvDPUJd/10/kQsWgWdwxibG2woOpQTDvyOusDfBuXyyqbpouRLZqlTPyZ5g8m8wM7HA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=qDvQ26vR; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="qDvQ26vR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757947661; bh=B0xFRM28DmWIgrG1Q+a6XZkJNRKEo5x4SQ82oQgZwfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qDvQ26vRLKp8i/bEPYw5f4D7LjdmgecCLOqtlqjFfF5l0wVHgFXa4uwnAWbqcqaTP +1sw4c+O/AyHt9MnNr6E1JjFG/p8+c+zGiIiKIZHGWY+sce+BNYcJNcexivo4Pp6yW kE5aQ7cVNg6+t5nykwb5JSo/GCy+PfB41cWY0jKLuc6B5TDHxLe326YyR9N3fhdSZz ps4jyP/ox7fPio/XIgdcm8pdnAEXbEJoGXKQxRNRR0nFr21s6pU+7ESh9nCj9fTp6f klVbOR8Z4CL6GcE10oKX95NjIFPPpAMcK5vzhMtmgegHofhCluz9vM6iyMlvDRaQMU SuVsY3PW6r1nA== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 044A56013A; Mon, 15 Sep 2025 14:47:41 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 139BB202FBF; Mon, 15 Sep 2025 14:43:06 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: "Jason A. Donenfeld" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Donald Hunter , Simon Horman , Jacob Keller , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 02/11] tools: ynl-gen: generate nested array policies Date: Mon, 15 Sep 2025 14:42:47 +0000 Message-ID: <20250915144301.725949-3-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250915144301.725949-1-ast@fiberby.net> References: <20250915144301.725949-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This patch adds support for NLA_POLICY_NESTED_ARRAY() policies. Example spec (from future wireguard.yaml): - name: wgpeer attributes: - name: allowedips type: indexed-array sub-type: nest nested-attributes: wgallowedip yields NLA_POLICY_NESTED_ARRAY(wireguard_wgallowedip_nl_policy). This doesn't change any currently generated code, as it isn't used in any specs currently used for generating code. Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen Reviewed-by: Donald Hunter Reviewed-by: Jakub Kicinski --- tools/net/ynl/pyynl/ynl_gen_c.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen= _c.py index c8b15569ecc1..95a60fdaf14e 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -815,6 +815,11 @@ class TypeArrayNest(Type): f'unsigned int n_{self.c_name}'] return super().arg_member(ri) =20 + def _attr_policy(self, policy): + if self.attr['sub-type'] =3D=3D 'nest': + return f'NLA_POLICY_NESTED_ARRAY({self.nested_render_name}_nl_= policy)' + return super()._attr_policy(policy) + def _attr_typol(self): if self.attr['sub-type'] in scalars: return f'.type =3D YNL_PT_U{c_upper(self.sub_type[1:])}, ' --=20 2.51.0 From nobody Thu Oct 2 14:26:15 2025 Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48C5B33EB06; Mon, 15 Sep 2025 14:47:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947674; cv=none; b=tJ10FKMU3A9cA3UyMIKbuaBNTSSvfU3HIlOAOY4yMV8FXVgxw95wmHQHlFaQMM0wLQzRpmnOHRO1R+PXGpYNFEjIspcir8Y3Dx1//6MfRLc1K6rVH9r6h4FLE5W8XCulMRxIKf3eOLaPh7nTKPoGKFhxoApT4kH0TyjbFyOb9XQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947674; c=relaxed/simple; bh=EZJrSC8HKLIZeYkZ/ou7/O3NW58W1W8t+y2LSY8Uu94=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mVUqQNEJZKHeOZAQm5VLLuFdlgjtqbsnHVQm8F6PPgYe39BHjGT2CIJdNcH5Dy2C6qVXGoi61KzMJHoZuodx3sq3U+e9lVB9qReV5/mljRJF+cAiurp0ZtlW50WSqFpkOrJ2gQbLK4l2F/c9LOqUyqcQtixizjEtzxwwPcsr0rI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=tyjBku43; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="tyjBku43" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757947661; bh=EZJrSC8HKLIZeYkZ/ou7/O3NW58W1W8t+y2LSY8Uu94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tyjBku43tj5Ngtx33BqGjDhluLloINzzLYhgEj0Aw6/Xg/XCW6Hqz6mGydYZJVZdO xGYD1rPntX8gDe/oiDlrHjS/GyytFUk/XyxMZcmr333KyFWEozze0OD0c6m0hMFXGM 2Bq90pXxy3ygMazeyZIcDZcdDzqt3jRwGlQDxlzK/+KG1NS27tIpS+YjtCakQcdAWc dDUWRZsb0yuAWDWiKgoNetqq2wyi6gr4WtJT6CxJ2C5QkUCYiAJyxf8f7GZ/wcyK2N m4AJeWRKDcnxvaCzOQKLhmseH6PodzaK3zI3q0jQ4n1JKdo7Q8OHpQnJ7hIuEz49B2 I8u8GHu5EsThg== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 063BD6013C; Mon, 15 Sep 2025 14:47:41 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 202DB20393F; Mon, 15 Sep 2025 14:43:06 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: "Jason A. Donenfeld" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Donald Hunter , Simon Horman , Jacob Keller , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 03/11] tools: ynl-gen: add sub-type check Date: Mon, 15 Sep 2025 14:42:48 +0000 Message-ID: <20250915144301.725949-4-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250915144301.725949-1-ast@fiberby.net> References: <20250915144301.725949-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Add a check to verify that the sub-type is "nest", and throw an exception if no policy could be generated, as a guard to prevent against generating a bad policy. This is a trivial patch with no behavioural changes intended. Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen Reviewed-by: Donald Hunter Reviewed-by: Jakub Kicinski Reviewed-by: Jacob Keller --- tools/net/ynl/pyynl/ynl_gen_c.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen= _c.py index 95a60fdaf14e..3266af19edcd 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -825,8 +825,10 @@ class TypeArrayNest(Type): return f'.type =3D YNL_PT_U{c_upper(self.sub_type[1:])}, ' elif self.attr['sub-type'] =3D=3D 'binary' and 'exact-len' in self= .checks: return f'.type =3D YNL_PT_BINARY, .len =3D {self.checks["exact= -len"]}, ' - else: + elif self.attr['sub-type'] =3D=3D 'nest': return f'.type =3D YNL_PT_NEST, .nest =3D &{self.nested_render= _name}_nest, ' + else: + raise Exception(f"Typol for ArrayNest sub-type {self.attr['sub= -type']} not supported, yet") =20 def _attr_get(self, ri, var): local_vars =3D ['const struct nlattr *attr2;'] --=20 2.51.0 From nobody Thu Oct 2 14:26:15 2025 Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 941BE340D8A; Mon, 15 Sep 2025 14:47:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947675; cv=none; b=Yu+E1BFIBoDywB0voekCJPp8LNpVVu1ECDqJDs6V5Td0xgHUKG88UJyP84WutDmUg/EEsEnUHIx9HZ0v42wQtES0qAFld7noh7aziiWfcIobSP9B3Db62Bz1a9UMNoxCZqJieooStVdlgL4nac7Hgtrm6jrxJuB5PgJZe8qe1zU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947675; c=relaxed/simple; bh=IsmjNeaXavqPvifeThqRq8BNJU4LPyh8Y4FXmPIrN2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SoIJhFb1ZoovT0snWB76C5lnXJtSYBldW8XJA8bWLrAKPemaE5AGqtUOZSMoH5/hjgc4gudYxGJSbOLORiwA1DS8xQ58sF9RYCWIklSsIwmJsj6fWXbA+Otswi129NaQ7qK884Bwx95ozEL3Oq3zvHVg4toHm9J/B6Znq2/hddw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=WEW24BMr; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="WEW24BMr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757947661; bh=IsmjNeaXavqPvifeThqRq8BNJU4LPyh8Y4FXmPIrN2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WEW24BMrMoIAB6//FCu9YqsdwI5AcZBBuX+35+Ggi7+lMKwLnQ+a52vkM1tbBhyPd ebI37IDVsiZJeeKtMvFrihYh3b5MTjPu1nmXdWJ40CencVLpV8KguEPlHAhoswSvJl oDQZ36lRXm6+Rd/uQiqxSjhwGUv13Q47Ytj1v7B7juFEmrBf8pRrGr4hLVnPESTfnH 3PP8pbEQhqMp1PkYLWDdtliGMAmyt+Vsey8OoSviFnscS0Cm0excutaR55atOpJnpi Vrxvjox43wlpUJpZrzcbUXSKzGI+vm6/uWGmu5SOSS0rsM7Uuj/rom/GKRMlHC+SRL BwlE1zzNqdtXg== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 044D06013B; Mon, 15 Sep 2025 14:47:41 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 2BC77203CF3; Mon, 15 Sep 2025 14:43:06 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: "Jason A. Donenfeld" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Donald Hunter , Simon Horman , Jacob Keller , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 04/11] tools: ynl-gen: refactor local vars for .attr_put() callers Date: Mon, 15 Sep 2025 14:42:49 +0000 Message-ID: <20250915144301.725949-5-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250915144301.725949-1-ast@fiberby.net> References: <20250915144301.725949-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Refactor the generation of local variables needed when building requests, by moving the logic from put_req_nested() into a new helper put_local_vars(), and use the helper before .attr_put() is called, thus generating the local variables assumed by .attr_put(). Previously only put_req_nested() generated the variables assumed by .attr_put(), print_req() only generated the count iterator `i`, and print_dump() neither generated `i` nor `array`. This patch fixes the build errors below: $ make -C tools/net/ynl/generated/ [...] -e GEN wireguard-user.c -e GEN wireguard-user.h -e CC wireguard-user.o wireguard-user.c: In function =E2=80=98wireguard_get_device_dump=E2=80=99: wireguard-user.c:480:9: error: =E2=80=98array=E2=80=99 undeclared (first us= e in func) 480 | array =3D ynl_attr_nest_start(nlh, WGDEVICE_A_PEERS); | ^~~~~ wireguard-user.c:480:9: note: each undeclared identifier is reported only once for each function it appears in wireguard-user.c:481:14: error: =E2=80=98i=E2=80=99 undeclared (first use i= n func) 481 | for (i =3D 0; i < req->_count.peers; i++) | ^ wireguard-user.c: In function =E2=80=98wireguard_set_device=E2=80=99: wireguard-user.c:533:9: error: =E2=80=98array=E2=80=99 undeclared (first us= e in func) 533 | array =3D ynl_attr_nest_start(nlh, WGDEVICE_A_PEERS); | ^~~~~ make: *** [Makefile:52: wireguard-user.o] Error 1 make: Leaving directory '/usr/src/linux/tools/net/ynl/generated' Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen Reviewed-by: Jakub Kicinski --- tools/net/ynl/pyynl/ynl_gen_c.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen= _c.py index 3266af19edcd..a0c571456236 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -2040,6 +2040,20 @@ def put_enum_to_str(family, cw, enum): _put_enum_to_str_helper(cw, enum.render_name, map_name, 'value', enum= =3Denum) =20 =20 +def put_local_vars(struct): + local_vars =3D [] + has_array =3D False + has_count =3D False + for _, arg in struct.member_list(): + has_array |=3D arg.type =3D=3D 'indexed-array' + has_count |=3D arg.presence_type() =3D=3D 'count' + if has_array: + local_vars.append('struct nlattr *array;') + if has_count: + local_vars.append('unsigned int i;') + return local_vars + + def put_req_nested_prototype(ri, struct, suffix=3D';'): func_args =3D ['struct nlmsghdr *nlh', 'unsigned int attr_type', @@ -2062,15 +2076,7 @@ def put_req_nested(ri, struct): init_lines.append(f"hdr =3D ynl_nlmsg_put_extra_header(nlh, {struc= t_sz});") init_lines.append(f"memcpy(hdr, &obj->_hdr, {struct_sz});") =20 - has_anest =3D False - has_count =3D False - for _, arg in struct.member_list(): - has_anest |=3D arg.type =3D=3D 'indexed-array' - has_count |=3D arg.presence_type() =3D=3D 'count' - if has_anest: - local_vars.append('struct nlattr *array;') - if has_count: - local_vars.append('unsigned int i;') + local_vars +=3D put_local_vars(struct) =20 put_req_nested_prototype(ri, struct, suffix=3D'') ri.cw.block_start() @@ -2354,10 +2360,7 @@ def print_req(ri): local_vars +=3D ['size_t hdr_len;', 'void *hdr;'] =20 - for _, attr in ri.struct["request"].member_list(): - if attr.presence_type() =3D=3D 'count': - local_vars +=3D ['unsigned int i;'] - break + local_vars +=3D put_local_vars(ri.struct['request']) =20 print_prototype(ri, direction, terminate=3DFalse) ri.cw.block_start() @@ -2424,6 +2427,9 @@ def print_dump(ri): local_vars +=3D ['size_t hdr_len;', 'void *hdr;'] =20 + if 'request' in ri.op[ri.op_mode]: + local_vars +=3D put_local_vars(ri.struct['request']) + ri.cw.write_func_lvar(local_vars) =20 ri.cw.p('yds.yarg.ys =3D ys;') --=20 2.51.0 From nobody Thu Oct 2 14:26:15 2025 Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E17BC340DAA; Mon, 15 Sep 2025 14:47:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947675; cv=none; b=jfyfg97kYLbMLUVEibd/spTtQiq2RAAGIXJ40uh6/FNrHXdYhWywxqI50Nxlmh20r2ME7eREq76RWCtmJeGtIU0Rmha72U2wy1HA1G+ilVoMenvMfk5+C1WjKZV0RDihf5GOW/BUAjsYBnydZaoAh8/Ha4TrReoyv4X8u4m6rCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947675; c=relaxed/simple; bh=LLyu7PizKBvF6PcAcs8jJH0K9Wfc0Q/trc3t4+4AZ/I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j0S2et/cDRhYP3qdJtYAZIyPN2HK/qTSFlXKg+Ze44rd+VzybrkJng5ruzp6hGD/sa5kFm5RYbdJhEghC8FwAXr+s4zdhxXpJX7ryXbv4Jn4zxHc6AjgienOuQti2yKSQcXJfFkdJEfE8CyALZoRjD41bzMGBiW7D0bo6ff7fSc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=QTl2Bgt1; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="QTl2Bgt1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757947661; bh=LLyu7PizKBvF6PcAcs8jJH0K9Wfc0Q/trc3t4+4AZ/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QTl2Bgt1gvfoUc82TkXiq+cSPM+xaVpSdCq2O7ilg3JRvSCFniUcpoj0XyIo8fAkH C5/ECXd5chT0vSWwyohZr8wS4ugbU8Zca7xgrLeKiF362vRmIZA3gDLPZEggwaMeww AeJ9EcA5t7l68M5uH4GtJL7YqlLfwjxv9MkrXOap941bjWXVqkZgUX2RoE+2d1LT0j Nbyg1C6o5PB6boOIH7HLZcoOOdmh9+dnQF7hUvwxBfkO35HpGlpWaxBC2bpiXGXl3X IAGvuqN6WrEhN51EpEBHXKDPXWsoDg1I6N1Jd0WNT9wLhm68nwXcTVIMk7TJ286I4v nZzBJAGhb58yg== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 075F66013D; Mon, 15 Sep 2025 14:47:41 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 372D0204AFE; Mon, 15 Sep 2025 14:43:06 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: "Jason A. Donenfeld" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Donald Hunter , Simon Horman , Jacob Keller , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 05/11] tools: ynl-gen: avoid repetitive variables definitions Date: Mon, 15 Sep 2025 14:42:50 +0000 Message-ID: <20250915144301.725949-6-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250915144301.725949-1-ast@fiberby.net> References: <20250915144301.725949-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable In the generated attribute parsing code, avoid repetitively defining the same variables over and over again, local to the conditional block for each attribute. This patch consolidates the definitions of local variables for attribute parsing, so that they are defined at the function level, and re-used across attributes, thus making the generated code read more natural. If attributes defines identical local_vars, then they will be deduplicated, attributes are assumed to only use their local variables transiently. The example below shows how `len` was defined repeatedly in tools/net/ynl/generated/nl80211-user.c: nl80211_iftype_data_attrs_parse(..) { [..] ynl_attr_for_each_nested(attr, nested) { unsigned int type =3D ynl_attr_type(attr); if (type =3D=3D NL80211_BAND_IFTYPE_ATTR_IFTYPES) { unsigned int len; [..] } else if (type =3D=3D NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC) { unsigned int len; [..] [same pattern 8 times, so 11 times in total] } else if (type =3D=3D NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE) { unsigned int len; [..] } } return 0; } This patch results in this diffstat for the generated code: $ diff -Naur pre/ post/ | diffstat devlink-user.c | 187 +++---------------- dpll-user.c | 10 - ethtool-user.c | 49 +---- fou-user.c | 5 handshake-user.c | 3 mptcp_pm-user.c | 3 nfsd-user.c | 16 - nl80211-user.c | 159 +--------------- nlctrl-user.c | 21 -- ovpn-user.c | 7 ovs_datapath-user.c | 9 ovs_flow-user.c | 89 --------- ovs_vport-user.c | 7 rt-addr-user.c | 14 - rt-link-user.c | 183 ++---------------- rt-neigh-user.c | 14 - rt-route-user.c | 26 -- rt-rule-user.c | 11 - tc-user.c | 380 +++++---------------------------------- tcp_metrics-user.c | 7 team-user.c | 5 21 files changed, 175 insertions(+), 1030 deletions(-) The changed lines are mostly `unsigned int len;` definitions: $ diff -Naur pre/ post/ | grep ^[-+] | grep -v '^[-+]\{3\}' | grep -v '^.$' | sed -e 's/\t\+/ /g' | sort | uniq -c | sort -nr 488 - unsigned int len; 153 + unsigned int len; 24 - const struct nlattr *attr2; 18 + const struct nlattr *attr2; 1 - __u32 policy_id, attr_id; 1 + __u32 policy_id, attr_id; 1 - __u32 op_id; 1 + __u32 op_id; 1 - const struct nlattr *attr_policy_id, *attr_attr_id; 1 + const struct nlattr *attr_policy_id, *attr_attr_id; 1 - const struct nlattr *attr_op_id; 1 + const struct nlattr *attr_op_id; Suggested-by: Jakub Kicinski Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen Reviewed-by: Jakub Kicinski --- tools/net/ynl/pyynl/ynl_gen_c.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen= _c.py index a0c571456236..a7c65edc863d 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -242,7 +242,7 @@ class Type(SpecAttr): raise Exception(f"Attr get not implemented for class type {self.ty= pe}") =20 def attr_get(self, ri, var, first): - lines, init_lines, local_vars =3D self._attr_get(ri, var) + lines, init_lines, _ =3D self._attr_get(ri, var) if type(lines) is str: lines =3D [lines] if type(init_lines) is str: @@ -250,10 +250,6 @@ class Type(SpecAttr): =20 kw =3D 'if' if first else 'else if' ri.cw.block_start(line=3Df"{kw} (type =3D=3D {self.enum_name})") - if local_vars: - for local in local_vars: - ri.cw.p(local) - ri.cw.nl() =20 if not self.is_multi_val(): ri.cw.p("if (ynl_attr_validate(yarg, attr))") @@ -2113,6 +2109,7 @@ def _multi_parse(ri, struct, init_lines, local_vars): else: raise Exception("Per-op fixed header not supported, yet") =20 + var_set =3D set() array_nests =3D set() multi_attrs =3D set() needs_parg =3D False @@ -2130,6 +2127,13 @@ def _multi_parse(ri, struct, init_lines, local_vars): multi_attrs.add(arg) needs_parg |=3D 'nested-attributes' in aspec needs_parg |=3D 'sub-message' in aspec + + try: + _, _, l_vars =3D aspec._attr_get(ri, '') + var_set |=3D set(l_vars) if l_vars else set() + except Exception: + pass # _attr_get() not implemented by simple types, ignore + local_vars +=3D list(var_set) if array_nests or multi_attrs: local_vars.append('int i;') if needs_parg: --=20 2.51.0 From nobody Thu Oct 2 14:26:15 2025 Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F03C32F76A; Mon, 15 Sep 2025 14:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947671; cv=none; b=RKWOcfD1xBKaF4VVVWQkXSqHqSjvihDA+XwAaRkr4n4L/aGn5HfDIR2N/m4UQ8cb+ciktZu8IsYHq2xslCHaq6fvxv0DH6xmOrscktDwAWBT3mwWBGZ2JfxicO7S669EPZY4CxKSR91u001IdYQRlo9iltArf96+k/hK/+F41us= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947671; c=relaxed/simple; bh=+kb1Z2x/UKU6OTxYCfMpVoKjYlmKBpw2h4XRUfikwbw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GKkT3JPILk/bw2sHzV+cnVCSFSCvs7jl+KeiYhipSzGhZTFPSB7ga34DNqjKzmbcFEAH4gbhYQ/yV0prglQs06lTMafHAwcreXgbw2VRFpo1rkYUXHJ0jgyvpFrGU0MHOcwBALfGcpmcFdUQjiiey8wSD1c/Ll6a0Bv/cSOXn5o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=q/4oJWLm; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="q/4oJWLm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757947660; bh=+kb1Z2x/UKU6OTxYCfMpVoKjYlmKBpw2h4XRUfikwbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q/4oJWLmSwqkQ2ZFm/oyO2cG0AsqK1vDE8VsgfsgB3StH5QjpR5zNt7VTAJ0wzcld VYTHfKuCXAf8bjI6P4YRVWDci0HhGqKhLDWVdHJgJ3jmzVLKyKDFpmhlDxJEtVD0sH DJbn5V5Q9a5tRnwDyQ27blxyurW4aLY1DHnRbF5aWjQyrdEFxvE+6AOxwnhzatEEzO JtmzQaLRYqLLwFhVLtygW5swahMvxe7cl5HW6MY5zjYcn65oVGjDtOm4zCIJvvqSyC CWTYkoBsH1GcCILMbZVKrUUGbMeYYiLlrks2w7xpKpCE8a2rT3sVtZvOXwBcgVqNg3 UNI8PsiuuYbXg== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 696136012E; Mon, 15 Sep 2025 14:47:39 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 4170D204C71; Mon, 15 Sep 2025 14:43:06 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: "Jason A. Donenfeld" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Donald Hunter , Simon Horman , Jacob Keller , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 06/11] tools: ynl-gen: validate nested arrays Date: Mon, 15 Sep 2025 14:42:51 +0000 Message-ID: <20250915144301.725949-7-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250915144301.725949-1-ast@fiberby.net> References: <20250915144301.725949-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable In nested arrays don't require that the intermediate attribute type should be a valid attribute type, it might just be zero or an incrementing index, it is often not even used. See include/net/netlink.h about NLA_NESTED_ARRAY: > The difference to NLA_NESTED is the structure: > NLA_NESTED has the nested attributes directly inside > while an array has the nested attributes at another > level down and the attribute types directly in the > nesting don't matter. Example based on include/uapi/linux/wireguard.h: > WGDEVICE_A_PEERS: NLA_NESTED > 0: NLA_NESTED > WGPEER_A_PUBLIC_KEY: NLA_EXACT_LEN, len WG_KEY_LEN > [..] > 0: NLA_NESTED > ... > ... Previous the check required that the nested type was valid in the parent attribute set, which in this case resolves to WGDEVICE_A_UNSPEC, which is YNL_PT_REJECT, and it took the early exit and returned YNL_PARSE_CB_ERROR. This patch renames the old nl_attr_validate() to __nl_attr_validate(), and creates a new inline function nl_attr_validate() to mimic the old one. The new __nl_attr_validate() takes the attribute type as an argument, so we can use it to validate attributes of a nested attribute, in the context of the parents attribute type, which in the above case is generated as: [WGDEVICE_A_PEERS] =3D { .name =3D "peers", .type =3D YNL_PT_NEST, .nest =3D &wireguard_wgpeer_nest, }, __nl_attr_validate() only checks if the attribute length is plausible for a given attribute type, so the .nest in the above example is not used. As the new inline function needs to be defined after ynl_attr_type(), then the definitions are moved down, so we avoid a forward declaration of ynl_attr_type(). Some other examples are NL80211_BAND_ATTR_FREQS (nest) and NL80211_ATTR_SUPPORTED_COMMANDS (u32) both in nl80211-user.c $ make -C tools/net/ynl/generated nl80211-user.c Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen Reviewed-by: Jakub Kicinski --- tools/net/ynl/lib/ynl-priv.h | 10 +++++++++- tools/net/ynl/lib/ynl.c | 6 +++--- tools/net/ynl/pyynl/ynl_gen_c.py | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/net/ynl/lib/ynl-priv.h b/tools/net/ynl/lib/ynl-priv.h index 824777d7e05e..29481989ea76 100644 --- a/tools/net/ynl/lib/ynl-priv.h +++ b/tools/net/ynl/lib/ynl-priv.h @@ -106,7 +106,6 @@ ynl_gemsg_start_req(struct ynl_sock *ys, __u32 id, __u8= cmd, __u8 version); struct nlmsghdr * ynl_gemsg_start_dump(struct ynl_sock *ys, __u32 id, __u8 cmd, __u8 version= ); =20 -int ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *att= r); int ynl_submsg_failed(struct ynl_parse_arg *yarg, const char *field_name, const char *sel_name); =20 @@ -467,4 +466,13 @@ ynl_attr_put_sint(struct nlmsghdr *nlh, __u16 type, __= s64 data) else ynl_attr_put_s64(nlh, type, data); } + +int __ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *a= ttr, + unsigned int type); + +static inline int ynl_attr_validate(struct ynl_parse_arg *yarg, + const struct nlattr *attr) +{ + return __ynl_attr_validate(yarg, attr, ynl_attr_type(attr)); +} #endif diff --git a/tools/net/ynl/lib/ynl.c b/tools/net/ynl/lib/ynl.c index 2a169c3c0797..2bcd781111d7 100644 --- a/tools/net/ynl/lib/ynl.c +++ b/tools/net/ynl/lib/ynl.c @@ -360,15 +360,15 @@ static int ynl_cb_done(const struct nlmsghdr *nlh, st= ruct ynl_parse_arg *yarg) =20 /* Attribute validation */ =20 -int ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *att= r) +int __ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *a= ttr, + unsigned int type) { const struct ynl_policy_attr *policy; - unsigned int type, len; unsigned char *data; + unsigned int len; =20 data =3D ynl_attr_data(attr); len =3D ynl_attr_data_len(attr); - type =3D ynl_attr_type(attr); if (type > yarg->rsp_policy->max_attr) { yerr(yarg->ys, YNL_ERROR_INTERNAL, "Internal error, validating unknown attribute"); diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen= _c.py index a7c65edc863d..9b42e75d24e9 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -830,7 +830,7 @@ class TypeArrayNest(Type): local_vars =3D ['const struct nlattr *attr2;'] get_lines =3D [f'attr_{self.c_name} =3D attr;', 'ynl_attr_for_each_nested(attr2, attr) {', - '\tif (ynl_attr_validate(yarg, attr2))', + '\tif (__ynl_attr_validate(yarg, attr2, type))', '\t\treturn YNL_PARSE_CB_ERROR;', f'\tn_{self.c_name}++;', '}'] --=20 2.51.0 From nobody Thu Oct 2 14:26:15 2025 Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6B4132F74A; Mon, 15 Sep 2025 14:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947670; cv=none; b=Z0/W5p0GS7ymFvtUW620d6am/OQgJL+JBuSFnmXTjY6Jhqwb2bgLz/GRVh9e4NkmHdl4deBVaE1kxpufd+OlLkRRBkqA2CN+RFg24BopgEpUdD8EPBLyYaHEoSn46FLLvgze04xG6kc5mt5KAR3Gx1n2mM2aTiVvaVMwNj8E794= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947670; c=relaxed/simple; bh=WdiVKtISm6Es87M4VHX7uCkXtl/4BmGjMgtxhRNpB9Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OeudOa2mpI5S8QOXxX3j2z8ClR3iARIPkuW5gUletxQaFdwNkClYeLA3kwm90ylbOuaZcXPPEnceam0bbte9yKb05KfY4fBQTgivsZ5namC7JIkO6GYk5/2hu1e5y54rNrqFXu0mpnQwOquLLjLOTj7KIT/jXgEOuyzguowXU9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=qL53Cmjn; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="qL53Cmjn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757947660; bh=WdiVKtISm6Es87M4VHX7uCkXtl/4BmGjMgtxhRNpB9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qL53CmjnKs48CG8RjylDneBngqZToh9zAYg8ENvXjLiLN6hN+bo5opJEc57ObFxvl UH1aFwlk4/BtmlDKcdoe2SJjnprwr3FNbZCpnlsh3N+IxGJvl1lLFZoZHWSJf2VyTy M+j/cUXdxwE1JdDPl1Wje+9ArT15oRageXT5lM01LIU71RMoDqyq/1cEwWKiZsash7 JSd5OQNYWm38Korn4ynhyJKiAdcaqt54zDsmNn4nL+A0c72hOKiGb6ZA23F8R+V03F e9tI41ZUf4LMQvvuyol6VD1Lobkc+BCObeR47zOeWiILOA70zMDefiiS+GF58fisyw BtPS9ZplPELbQ== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id E0993600C4; Mon, 15 Sep 2025 14:47:39 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 4BB6B204CAF; Mon, 15 Sep 2025 14:43:06 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: "Jason A. Donenfeld" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Donald Hunter , Simon Horman , Jacob Keller , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 07/11] tools: ynl-gen: rename TypeArrayNest to TypeIndexedArray Date: Mon, 15 Sep 2025 14:42:52 +0000 Message-ID: <20250915144301.725949-8-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250915144301.725949-1-ast@fiberby.net> References: <20250915144301.725949-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Since TypeArrayNest can now be used with many other sub-types than nest, then rename it to TypeIndexedArray, to reduce confusion. This patch continues the rename, that was started in commit aa6485d813ad ("ynl: rename array-nest to indexed-array"), when the YNL type was renamed. In order to get rid of all references to the old naming, within ynl, then renaming some variables in _multi_parse(). This is a trivial patch with no behavioural changes intended. Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen Reviewed-by: Donald Hunter Reviewed-by: Jakub Kicinski --- tools/net/ynl/pyynl/ynl_gen_c.py | 36 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen= _c.py index 9b42e75d24e9..c064e6df41bd 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -787,7 +787,7 @@ class TypeMultiAttr(Type): f"{presence} =3D n_{self.c_name};"] =20 =20 -class TypeArrayNest(Type): +class TypeIndexedArray(Type): def is_multi_val(self): return True =20 @@ -824,7 +824,7 @@ class TypeArrayNest(Type): elif self.attr['sub-type'] =3D=3D 'nest': return f'.type =3D YNL_PT_NEST, .nest =3D &{self.nested_render= _name}_nest, ' else: - raise Exception(f"Typol for ArrayNest sub-type {self.attr['sub= -type']} not supported, yet") + raise Exception(f"Typol for IndexedArray sub-type {self.attr['= sub-type']} not supported, yet") =20 def _attr_get(self, ri, var): local_vars =3D ['const struct nlattr *attr2;'] @@ -850,7 +850,7 @@ class TypeArrayNest(Type): ri.cw.p(f'for (i =3D 0; i < {var}->_count.{self.c_name}; i++)') ri.cw.p(f"{self.nested_render_name}_put(nlh, i, &{var}->{self.= c_name}[i]);") else: - raise Exception(f"Put for ArrayNest sub-type {self.attr['sub-t= ype']} not supported, yet") + raise Exception(f"Put for IndexedArray sub-type {self.attr['su= b-type']} not supported, yet") ri.cw.p('ynl_attr_nest_end(nlh, array);') =20 def _setter_lines(self, ri, member, presence): @@ -1127,7 +1127,7 @@ class AttrSet(SpecAttrSet): t =3D TypeNest(self.family, self, elem, value) elif elem['type'] =3D=3D 'indexed-array' and 'sub-type' in elem: if elem["sub-type"] in ['binary', 'nest', 'u32']: - t =3D TypeArrayNest(self.family, self, elem, value) + t =3D TypeIndexedArray(self.family, self, elem, value) else: raise Exception(f'new_attr: unsupported sub-type {elem["su= b-type"]}') elif elem['type'] =3D=3D 'nest-type-value': @@ -2109,18 +2109,18 @@ def _multi_parse(ri, struct, init_lines, local_vars= ): else: raise Exception("Per-op fixed header not supported, yet") =20 - var_set =3D set() - array_nests =3D set() + indexed_arrays =3D set() multi_attrs =3D set() needs_parg =3D False + var_set =3D set() for arg, aspec in struct.member_list(): if aspec['type'] =3D=3D 'indexed-array' and 'sub-type' in aspec: if aspec["sub-type"] in {'binary', 'nest'}: local_vars.append(f'const struct nlattr *attr_{aspec.c_nam= e};') - array_nests.add(arg) + indexed_arrays.add(arg) elif aspec['sub-type'] in scalars: local_vars.append(f'const struct nlattr *attr_{aspec.c_nam= e};') - array_nests.add(arg) + indexed_arrays.add(arg) else: raise Exception(f'Not supported sub-type {aspec["sub-type"= ]}') if 'multi-attr' in aspec: @@ -2134,16 +2134,16 @@ def _multi_parse(ri, struct, init_lines, local_vars= ): except Exception: pass # _attr_get() not implemented by simple types, ignore local_vars +=3D list(var_set) - if array_nests or multi_attrs: + if indexed_arrays or multi_attrs: local_vars.append('int i;') if needs_parg: local_vars.append('struct ynl_parse_arg parg;') init_lines.append('parg.ys =3D yarg->ys;') =20 - all_multi =3D array_nests | multi_attrs + all_multi =3D indexed_arrays | multi_attrs =20 - for anest in sorted(all_multi): - local_vars.append(f"unsigned int n_{struct[anest].c_name} =3D 0;") + for arg in sorted(all_multi): + local_vars.append(f"unsigned int n_{struct[arg].c_name} =3D 0;") =20 ri.cw.block_start() ri.cw.write_func_lvar(local_vars) @@ -2163,8 +2163,8 @@ def _multi_parse(ri, struct, init_lines, local_vars): else: ri.cw.p('hdr =3D ynl_nlmsg_data_offset(nlh, sizeof(struct genl= msghdr));') ri.cw.p(f"memcpy(&dst->_hdr, hdr, sizeof({struct.fixed_header}));") - for anest in sorted(all_multi): - aspec =3D struct[anest] + for arg in sorted(all_multi): + aspec =3D struct[arg] ri.cw.p(f"if (dst->{aspec.c_name})") ri.cw.p(f'return ynl_error_parse(yarg, "attribute already present = ({struct.attr_set.name}.{aspec.name})");') =20 @@ -2182,8 +2182,8 @@ def _multi_parse(ri, struct, init_lines, local_vars): ri.cw.block_end() ri.cw.nl() =20 - for anest in sorted(array_nests): - aspec =3D struct[anest] + for arg in sorted(indexed_arrays): + aspec =3D struct[arg] =20 ri.cw.block_start(line=3Df"if (n_{aspec.c_name})") ri.cw.p(f"dst->{aspec.c_name} =3D calloc(n_{aspec.c_name}, sizeof(= *dst->{aspec.c_name}));") @@ -2208,8 +2208,8 @@ def _multi_parse(ri, struct, init_lines, local_vars): ri.cw.block_end() ri.cw.nl() =20 - for anest in sorted(multi_attrs): - aspec =3D struct[anest] + for arg in sorted(multi_attrs): + aspec =3D struct[arg] ri.cw.block_start(line=3Df"if (n_{aspec.c_name})") ri.cw.p(f"dst->{aspec.c_name} =3D calloc(n_{aspec.c_name}, sizeof(= *dst->{aspec.c_name}));") ri.cw.p(f"dst->_count.{aspec.c_name} =3D n_{aspec.c_name};") --=20 2.51.0 From nobody Thu Oct 2 14:26:15 2025 Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 940FE340D83; Mon, 15 Sep 2025 14:47:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947674; cv=none; b=diCSb1Ytk1f19+ToX5AiPd39reRu/7uMAwO1kbuxny/bLmgG6aFAocYhWkqn7pUTiDv7aDyaNvk0xPvFsZpf+h459hYj3b+h+jIqaFMVNKj3I2/Yov8vAqU2ANEPF6sqsxr6N7BTzM3DTT0mua9KwxBErzJx8Az7xqZ21TyjbkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947674; c=relaxed/simple; bh=HqyIhwC1Ng9W9Rs+TyJnvWCNwSRIXH4apSsRMl21lQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gwdYAumoBhSvmjvi2JWwMtri2ZZWqYfJ8eU/i76OTwrvUTnmPyNjqHoMksxzpx6dv5TsRWtIYa2dyfN0ngeXY/D19IVO6O2g0fv5d7TmZRuGlzpiYBTFXvXpS0V9if++P4CwsAHfyLnil6GAruTcrNx575jzn4V3GD6RC8dbww4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=YQuirKBE; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="YQuirKBE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757947661; bh=HqyIhwC1Ng9W9Rs+TyJnvWCNwSRIXH4apSsRMl21lQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YQuirKBE7nmnkHnjZ+/f5UNewQW0CsnPpiH2DG62E5cu/dGlE/dwMyOTAzJqBhjG6 vqUROmNXoNGpG+WqNETsk7hHD6oJXL2zLInMgiqpnItA6bRYWbl/VlT3lReGQJEZQw rPeqmojL3dkmfkIy147FLlilZD1NUQmTNzjn51EEISChIc9PzU0JavUwmA6oeAfHBR 38OKjZRSbgeOLJd3FOwNXjL6CcYPu7O2vGOJFEQprcHnFt0HPloNMxd8ufTPzNx/Xc vw2GX6NnKpcJXlinvpX8P1JBNIaNQC6+IZyu2z5DuBWEdu1rFv+KKYonzaXZZOLChL OdrgDMAwKoxSw== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 0CEFF6013E; Mon, 15 Sep 2025 14:47:41 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 56735204EE2; Mon, 15 Sep 2025 14:43:06 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: "Jason A. Donenfeld" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Donald Hunter , Simon Horman , Jacob Keller , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 08/11] tools: ynl: move nest packing to a helper function Date: Mon, 15 Sep 2025 14:42:53 +0000 Message-ID: <20250915144301.725949-9-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250915144301.725949-1-ast@fiberby.net> References: <20250915144301.725949-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This patch moves nest packing into a helper function, that can also be used for packing indexed arrays. No behavioural changes intended. Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen Reviewed-by: Donald Hunter --- tools/net/ynl/pyynl/lib/ynl.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py index 50805e05020a..92ff26f34f4d 100644 --- a/tools/net/ynl/pyynl/lib/ynl.py +++ b/tools/net/ynl/pyynl/lib/ynl.py @@ -561,11 +561,8 @@ class YnlFamily(SpecFamily): =20 if attr["type"] =3D=3D 'nest': nl_type |=3D Netlink.NLA_F_NESTED - attr_payload =3D b'' sub_space =3D attr['nested-attributes'] - sub_attrs =3D SpaceAttrs(self.attr_sets[sub_space], value, sea= rch_attrs) - for subname, subvalue in value.items(): - attr_payload +=3D self._add_attr(sub_space, subname, subva= lue, sub_attrs) + attr_payload =3D self._add_nest_attrs(value, sub_space, search= _attrs) elif attr["type"] =3D=3D 'flag': if not value: # If value is absent or false then skip attribute creation. @@ -622,6 +619,14 @@ class YnlFamily(SpecFamily): pad =3D b'\x00' * ((4 - len(attr_payload) % 4) % 4) return struct.pack('HH', len(attr_payload) + 4, nl_type) + attr_pa= yload + pad =20 + def _add_nest_attrs(self, value, sub_space, search_attrs): + sub_attrs =3D SpaceAttrs(self.attr_sets[sub_space], value, search_= attrs) + attr_payload =3D b'' + for subname, subvalue in value.items(): + attr_payload +=3D self._add_attr(sub_space, subname, subvalue, + sub_attrs) + return attr_payload + def _get_enum_or_unknown(self, enum, raw): try: name =3D enum.entries_by_val[raw].name --=20 2.51.0 From nobody Thu Oct 2 14:26:15 2025 Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1840340DAB; Mon, 15 Sep 2025 14:47:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947674; cv=none; b=d91ubmHq3BMCKtFOPVXnj10ranPU5/yk0geEgqzERxqG/4YnqdS3QLOseRG96NwBVB18cUB6PSyCpQCrKKUy68BJfGg4MuE+X/vrIZAWZkbp3H5lgOugCdeXQWDsqMyEBEyPkVgPaKqKgsC4n5sxwZ2RKU7ODMUBBTq7Ih/y8r8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947674; c=relaxed/simple; bh=+xB7OdBH5/hOoPqTnhZSd84UXQV32QC9Igc+BZIJ9TQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lzvMoooF5NKvtLVK9eyuTIwwiKoLp8T2m6AZ3KFGf3utjyF2P+tB41mm2CyDlSFc66Wt1RS/CU7MKv8iAGK8nO64qLJHIkLm32rv34YgJQ+FPXb7Hz5Ko5MOau0cq0YwUvugThxlnW0FGIICAxT+3XBvHcOr9JzswS9HYzeMjKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=R3xdIgxC; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="R3xdIgxC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757947661; bh=+xB7OdBH5/hOoPqTnhZSd84UXQV32QC9Igc+BZIJ9TQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R3xdIgxCeA3n4EbMNYcIrRdec2kx3Q55RbVNs+fSZKSnNH5f96l+aN38xj69pVEAt db26hmc7StGFTbOrlTaTgzK1klDBXy7P1S7lqjLT6P/LWOC5cvG6Bj5dRfeskgLJpZ /R2sICGICoqeRWvob38nD55yijrLSrt268BJkwPAJrq0IhSxX1jy2I51aRjxuSUBLl vQ0XTBI1pTD9sALnALoMt25Kb+Kv+7lFY+ArK6S7FbU0eu7TnKpn0psSQ2PQ//7XNP Leyzagw/8nm2vQsAzjv6hvQOIJSlZuk8JrN/8jiNamkdoJqAS4Gso4KCtKEcIudQ3l IFk5MM98qlD5Q== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 1A8A960140; Mon, 15 Sep 2025 14:47:41 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 60EC0204FB3; Mon, 15 Sep 2025 14:43:06 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: "Jason A. Donenfeld" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Donald Hunter , Simon Horman , Jacob Keller , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 09/11] tools: ynl: encode indexed-arrays Date: Mon, 15 Sep 2025 14:42:54 +0000 Message-ID: <20250915144301.725949-10-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250915144301.725949-1-ast@fiberby.net> References: <20250915144301.725949-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This patch adds support for encoding indexed-array attributes with sub-type nest in pyynl. Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen Reviewed-by: Donald Hunter --- tools/net/ynl/pyynl/lib/ynl.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py index 92ff26f34f4d..9fd83f8b091f 100644 --- a/tools/net/ynl/pyynl/lib/ynl.py +++ b/tools/net/ynl/pyynl/lib/ynl.py @@ -563,6 +563,11 @@ class YnlFamily(SpecFamily): nl_type |=3D Netlink.NLA_F_NESTED sub_space =3D attr['nested-attributes'] attr_payload =3D self._add_nest_attrs(value, sub_space, search= _attrs) + elif attr['type'] =3D=3D 'indexed-array' and attr['sub-type'] =3D= =3D 'nest': + nl_type |=3D Netlink.NLA_F_NESTED + sub_space =3D attr['nested-attributes'] + attr_payload =3D self._encode_indexed_array(value, sub_space, + search_attrs) elif attr["type"] =3D=3D 'flag': if not value: # If value is absent or false then skip attribute creation. @@ -616,6 +621,9 @@ class YnlFamily(SpecFamily): else: raise Exception(f'Unknown type at {space} {name} {value} {attr= ["type"]}') =20 + return self._add_attr_raw(nl_type, attr_payload) + + def _add_attr_raw(self, nl_type, attr_payload): pad =3D b'\x00' * ((4 - len(attr_payload) % 4) % 4) return struct.pack('HH', len(attr_payload) + 4, nl_type) + attr_pa= yload + pad =20 @@ -627,6 +635,14 @@ class YnlFamily(SpecFamily): sub_attrs) return attr_payload =20 + def _encode_indexed_array(self, vals, sub_space, search_attrs): + attr_payload =3D b'' + for i, val in enumerate(vals): + idx =3D i | Netlink.NLA_F_NESTED + val_payload =3D self._add_nest_attrs(val, sub_space, search_at= trs) + attr_payload +=3D self._add_attr_raw(idx, val_payload) + return attr_payload + def _get_enum_or_unknown(self, enum, raw): try: name =3D enum.entries_by_val[raw].name --=20 2.51.0 From nobody Thu Oct 2 14:26:15 2025 Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1911341AA3; Mon, 15 Sep 2025 14:47:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947676; cv=none; b=fRyawuFCs09LMsJvL7AbuAGIluvE7//BiIaSGwslPbK/l8lJyNsTlZjzVpk8VWr5XDep2Vqs8f/J4EbglfohTmVa6YlEf/wqUNJWETVyhqXOQFNam/eY7BX5HhkUZRlGHZkDLf79OAwGQ+V+pi8AnlZz6dbUF4UqOQd40KTKsyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947676; c=relaxed/simple; bh=CklzBOgUQddwzBO3UlL2pkEPjFixeUSxqIJvFTCFOhk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HZAtwng9o3vbfHa9+Xj8wBXthQkpWgR7z1YVkC5txozYxz+cuUR3flOZ+4qx0zPgCMKSTw8xV+f565uhjOCGff85CXbxRhAYCouxrnbmN3THACFeAZR67fd9PEQt/8+Mkd5D53XhS9MEw73QkWrDdhWyTuNdTH1Y0l4tJAGKr5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=NbaxkH1V; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="NbaxkH1V" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757947661; bh=CklzBOgUQddwzBO3UlL2pkEPjFixeUSxqIJvFTCFOhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NbaxkH1VfBJI70Q8opnolbnjhvJ1jUIqdURF+XM4qienrRTxTbBacP/Pw/cmf1Cdx OSNJpX2wL5Flr4MC81YhmyL+TJCYYQsUulAdZfdRU/d2OI1uDeHIuzmhIUjc/aMNPJ tijZZqTH/dwvDdA9PrdgHEW/bnXTlKcICBtdArHZGgODGK4Pe6gRdgLQFZ3Xx2lsBc FRRfrykrJ0EKgz6K6a6mZ33FuTe9x8fK9lg14ZajECK8xJhItyI1K4ZWECkhbIsIIP kMkhJql1ilT2J3iiReDSVGLJz/a/qFXGLsFdeqXXEYjNf7Rbur+7PEkMd1LC0B7vHs n1kuyYAByvgAA== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 1556C6013F; Mon, 15 Sep 2025 14:47:41 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 6B8212051A8; Mon, 15 Sep 2025 14:43:06 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: "Jason A. Donenfeld" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Donald Hunter , Simon Horman , Jacob Keller , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 10/11] tools: ynl: decode hex input Date: Mon, 15 Sep 2025 14:42:55 +0000 Message-ID: <20250915144301.725949-11-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250915144301.725949-1-ast@fiberby.net> References: <20250915144301.725949-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This patch adds support for decoding hex input, so that binary attributes can be read through --json. Example (using future wireguard.yaml): $ sudo ./tools/net/ynl/pyynl/cli.py --family wireguard \ --do set-device --json '{"ifindex":3, "private-key":"2a ae 6c 35 c9 4f cf <... to 32 bytes>"}' In order to somewhat mirror what is done in _formatted_string(), then for non-binary attributes attempt to convert it to an int. Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen Reviewed-by: Donald Hunter --- tools/net/ynl/pyynl/lib/ynl.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py index 9fd83f8b091f..707753e371e2 100644 --- a/tools/net/ynl/pyynl/lib/ynl.py +++ b/tools/net/ynl/pyynl/lib/ynl.py @@ -971,6 +971,11 @@ class YnlFamily(SpecFamily): raw =3D ip.packed else: raw =3D int(ip) + elif attr_spec.display_hint =3D=3D 'hex': + if attr_spec['type'] =3D=3D 'binary': + raw =3D bytes.fromhex(string) + else: + raw =3D int(string, 16) else: raise Exception(f"Display hint '{attr_spec.display_hint}' not = implemented" f" when parsing '{attr_spec['name']}'") --=20 2.51.0 From nobody Thu Oct 2 14:26:15 2025 Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6A9A321F34; Mon, 15 Sep 2025 14:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947673; cv=none; b=haqUyIb6IXrUBx90s1NZFMitdg+Hnnbd3U1fiM5xAaHYbhIBHgeA/c6WauRWxy6dRkX3X3aiFhBeipzKerJkKFkdJXO8+rJzCkWaS39rI1xJnrbQlbSDeHep10NpcN4816xprOSlWql+/g157NW0b7GCQqD+u8hMfY6oHPL8row= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757947673; c=relaxed/simple; bh=M8RZw0PcAr23td7B4SWZsTm8GfTk/HQcBuK2/+z1TOk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VafUUbQK1YVpee+XtsaTYTsggkJ7TsOLGCbWuNR7+xhCxSJqZJBP1LDw0Nkld9kSQJSkzGw26XR6/BBO5HGs4/I1xd2/6genakR+tSayoLWXLeaHpXpdNU0ZKUsGSAMbwpXJnsLQB6l9LKP6pS5Rg2SKvH6k5ci1w3suM1/TI5E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=as0GBHV0; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="as0GBHV0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757947660; bh=M8RZw0PcAr23td7B4SWZsTm8GfTk/HQcBuK2/+z1TOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=as0GBHV0zPBIF3vPf/Xn8QmEv/ATEJXmEpq/t/DjKQB1j5tfGayg5uClH77bjdVEU SCyE/KncrSDIGYFVYvocihwMR2GOmjT/baz1ppscCC0j3s+zfzOidwDmRp0imzTIA8 6f9M8vpaiC7+3gF2JIitPTSHBaT6TtcgjzjBq7om8KLce6RxQkJCvp4PYrfZwwLSnI zcY0FBdEB1i5Wmc1HiDQqXTZucwYr6J0Digh/KrY+y2YVmYHxsYbe+IsoyJrVf6SfR ANBLXkN3BCS9SEpVbLA+geKOXqYFRIUZSc2bBdsbSvbDIQRRd2xM9Kf6noj1OUYh66 TJOyDOG/owh4Q== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id E316860128; Mon, 15 Sep 2025 14:47:39 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 75DD42054AD; Mon, 15 Sep 2025 14:43:06 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: "Jason A. Donenfeld" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Donald Hunter , Simon Horman , Jacob Keller , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 11/11] tools: ynl: add ipv4-or-v6 display hint Date: Mon, 15 Sep 2025 14:42:56 +0000 Message-ID: <20250915144301.725949-12-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250915144301.725949-1-ast@fiberby.net> References: <20250915144301.725949-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The attribute WGALLOWEDIP_A_IPADDR can contain either an IPv4 or an IPv6 address depending on WGALLOWEDIP_A_FAMILY, however in practice it is enough to look at the attribute length. This patch implements an ipv4-or-v6 display hint, that can deal with this kind of attribute. It only implements this display hint for genetlink-legacy, it can be added to other protocol variants if needed, but we don't want to encourage it's use. Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen Reviewed-by: Donald Hunter --- Documentation/netlink/genetlink-legacy.yaml | 2 +- tools/net/ynl/pyynl/lib/ynl.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/ne= tlink/genetlink-legacy.yaml index b29d62eefa16..66fb8653a344 100644 --- a/Documentation/netlink/genetlink-legacy.yaml +++ b/Documentation/netlink/genetlink-legacy.yaml @@ -154,7 +154,7 @@ properties: Optional format indicator that is intended only for choo= sing the right formatting mechanism when displaying values of= this type. - enum: [ hex, mac, fddi, ipv4, ipv6, uuid ] + enum: [ hex, mac, fddi, ipv4, ipv6, ipv4-or-v6, uuid ] struct: description: Name of the nested struct type. type: string diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py index 707753e371e2..62383c70ebb9 100644 --- a/tools/net/ynl/pyynl/lib/ynl.py +++ b/tools/net/ynl/pyynl/lib/ynl.py @@ -956,7 +956,7 @@ class YnlFamily(SpecFamily): formatted =3D hex(raw) else: formatted =3D bytes.hex(raw, ' ') - elif display_hint in [ 'ipv4', 'ipv6' ]: + elif display_hint in [ 'ipv4', 'ipv6', 'ipv4-or-v6' ]: formatted =3D format(ipaddress.ip_address(raw)) elif display_hint =3D=3D 'uuid': formatted =3D str(uuid.UUID(bytes=3Draw)) @@ -965,7 +965,7 @@ class YnlFamily(SpecFamily): return formatted =20 def _from_string(self, string, attr_spec): - if attr_spec.display_hint in ['ipv4', 'ipv6']: + if attr_spec.display_hint in ['ipv4', 'ipv6', 'ipv4-or-v6']: ip =3D ipaddress.ip_address(string) if attr_spec['type'] =3D=3D 'binary': raw =3D ip.packed --=20 2.51.0