From nobody Thu Oct 2 20:45:46 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 5D519314B69; Wed, 10 Sep 2025 23:09:03 +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=1757545745; cv=none; b=f3K8nfp5FQO2IL67Br+Ehe11k44FJGQTlWLE/Qz9A/1zOcy4pUIjHbtdZK2819ut6hVNz3ItKRa0KZJJY8T4OIAqWWzWrkAy8FZUXHwlWk2kv7xhBNf77/Tofr1nZSwtyOjqzsKG+wL2r99LuXBJdVE3nRaNskN1btR/QW+UBso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757545745; c=relaxed/simple; bh=BXBJfFZ+zTwLVHSQB68jOM4LzO0NIRI61RviYfjsvu0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fz9OHOu5hO7PCP2zn0MZzQtkid7iZjqtBk3zKUUjQvvsFl4uA4Fmb/mU69+G9No03eTo0ie/ZQYujnUTEj04hDFymA9BcbSw5uUsaTaIwLkKK43em9psxkh3deNWh3U5T/eeSCmddT1eul0ckQUVACNArJT78Y2afEbYLzQp8wI= 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=bBqxdVSi; 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="bBqxdVSi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757545730; bh=BXBJfFZ+zTwLVHSQB68jOM4LzO0NIRI61RviYfjsvu0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bBqxdVSi6kSZofaDl44lkOtbNg80c6YNbSYMuAf/AVwIgtPHOnlUkvjG6C+9f/qb/ n4eJh4JMpEt/CuHjB3UuvkMvSsAqrNZ8ZnrHKL5NM2IZJWygHJYezgIte5L5XJK4T+ sG7WJwx/nA9z27PkDE5BWAvytDssIibs9UkxXW3Ybq5b0K6pMxFEFy0SuNIGLSKA7g sBbv6SugbhobBsrALc3zjxhz54HVei8JvaGYG5GWxHN25rGr/hLr+wYd9Pj/xePqV7 fIbWxY/BL9W5L1KlIh3b2+ilAFSTMWwblORxPM4FQch3U/h9Nn9tguwN7/PpvpO+a+ ycqzJ+476TWZA== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id E947960140; Wed, 10 Sep 2025 23:08:50 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id C7C10201D12; Wed, 10 Sep 2025 23:08:42 +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 , Andrew Lunn , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 01/12] tools: ynl-gen: allow overriding name-prefix for constants Date: Wed, 10 Sep 2025 23:08:23 +0000 Message-ID: <20250910230841.384545-2-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250910230841.384545-1-ast@fiberby.net> References: <20250910230841.384545-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 fb7e03805a11..1543d4911bf5 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -3211,8 +3211,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 20:45:46 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 1AE5130FC06; Wed, 10 Sep 2025 23:08:58 +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=1757545742; cv=none; b=GVrYBVExY+0qKIsflHxB34iUZYSY6ObFAnp+UllOzavs0umgX7g0GFNxsNlg/a4qmU3w0L2CAEaq1Zp/zciYevWQ0e7i1J88NVLpgQeA/+sdUWCWv0WvYnBQQI/p5pn1HMD0NDPC22maEqViYIUbwbW+K+X8DGtoQ4QPRIVQ2ks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757545742; c=relaxed/simple; bh=KNcy1v4zfi/eZP7HpihPuqSy+gZFwWXsgS/ILoEcbXQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pz3NqMs9aLaVjcmnQyS8qR7IulYC/szmUYRUR2bH1BzJjj6MEjylBbh8HkDSncU9tnv+pwcC25ru/LCt5KB7D6i8/w50a2a639HH+oq9TWGi0sWklZ78zEskhMYHgBB0B8I6ZsKAebh0ViiIbjrIuhh9XNEu+chU2MS7g5o/Wm8= 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=aCrbd/pD; 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="aCrbd/pD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757545730; bh=KNcy1v4zfi/eZP7HpihPuqSy+gZFwWXsgS/ILoEcbXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aCrbd/pDy5sdCqEDbrrk8TrMRDl8uwg5JTucd5QYqK6209lFjYSKFJRv4zEe3CyAb EG6I46jSQEneIJdLDmzAaJd/zoQwViUkrV1v/TSZyHIm3WurPd8tc9GmaYLPFBSizB +fT0OSl5aQCmXo0QqB+Vu5LZhPJJ35JrYSUXr0FtaQqxe8KNCYxRG4Y34KAdRZLRCh CYP6cOrGh97EeYxz+4bBoFgUYWGV87F66Keue6JA2n7y/lstOwiH9xDxru6us8NTpV yHf4rA6caFdsMDJVvaxxr+LXKZP97GyGXbshVaj/d+C0YHv4ampJYTKMi4lRxcfxwe eTQ1kSxL/z2EA== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 4C921600C4; Wed, 10 Sep 2025 23:08:50 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id D36E8202A89; Wed, 10 Sep 2025 23:08:42 +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 , Andrew Lunn , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 02/12] tools: ynl-gen: generate nested array policies Date: Wed, 10 Sep 2025 23:08:24 +0000 Message-ID: <20250910230841.384545-3-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250910230841.384545-1-ast@fiberby.net> References: <20250910230841.384545-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 1543d4911bf5..b7de7f6b1fc7 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -816,6 +816,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 20:45:46 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 00FF93168E3; Wed, 10 Sep 2025 23:09:03 +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=1757545746; cv=none; b=mmEye7NTlG10VfhCuDtuvKVx0WLBu2EBpWfyjm36T+15fH0ZAF/KtT25K6Oe+DQc1b6yY+PpfZJVr+ljxOUjp8v3fPm20O/LSihX9upVNWcvs3zlMVrQqcOrIXQFnLldrY7Rd2/M0lKgAMdInTS305ray3flYBgaSi5rCNX5Hqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757545746; c=relaxed/simple; bh=6kMrPysvFhVYyAdolkuF1QheVD/lPJPn0VFB/qw9PH0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C3r1CDBe2QNrVgZJCbGz/UNGftC5I2HweAAxk7M8GPcfqABFXEdqTqsTEvYNz8PhvoLLjiKSxLdmTxYthRyRuKQeFMlOsd9FqkvBpj2lBmUw/6FJIbYgjqU+47q/Z/2X2r19wVVi058yNTgfd/sipaTmsit6IYfCKdr5SdFr0uU= 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=W86Ob1A4; 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="W86Ob1A4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757545731; bh=6kMrPysvFhVYyAdolkuF1QheVD/lPJPn0VFB/qw9PH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W86Ob1A4S+GbFW3JBjOBZKocDqdJi0q8nb59vp7FPIFlwiKL+bTnNulRC38BPS9h+ xFml9J0U48uhhxlhCa0VkNxxOBVZKOzcUSXs5zoH8SVgwRhtduKBKxa90t8HN6DGjM lPjvTesFXMxpgLgeG81uB/vzN5JaisB3LrJwJ0PN5PzpPxuQbjMnoqhTDRunl4K4TV hwXI5+eiQ+6HCtmnt0UTHldkTlcU5Esq/7wehIPAMJoovbjxpMN8H2OjPFuRVRlMIr 6iLEgf8FdPORbXqgPXRS47LBUSlhrhRLT2IlPy1SYEIFSBfrC+mcydYoIfXjZX5DWw iJ7DYumsPRpyQ== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id D3DEF6013D; Wed, 10 Sep 2025 23:08:50 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id E0D83202DF2; Wed, 10 Sep 2025 23:08:42 +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 , Andrew Lunn , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 03/12] tools: ynl-gen: add sub-type check Date: Wed, 10 Sep 2025 23:08:25 +0000 Message-ID: <20250910230841.384545-4-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250910230841.384545-1-ast@fiberby.net> References: <20250910230841.384545-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 b7de7f6b1fc7..04c26ed92ca3 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -826,8 +826,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 20:45:46 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 E0B223164CA; Wed, 10 Sep 2025 23:09:03 +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=1757545746; cv=none; b=sSpQtUAmwESnYDB0gEufQMGXiuW8zKPlULDNGsRcxXJ+reFQ6w2S5W+Nijho+ABCAN7RAso/6cMVdvZq0n3X6Req7xJ2+SGKVDYLqMddlKzMJ+elEhAwmC8k+16w5z2Pbzm/dBeramd5K4C/uHpksbP6rrbknFt6Um56vQgM2lY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757545746; c=relaxed/simple; bh=5iWNx54sGjcK9fIya6c+VTdunUg4fVj+MTblZK2rNog=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r7Aaeo6hmzKOf1qzGJ6qs4tu6Y05DuCQvT6GsVh8XpMJ5rOmlJ2PFWv0yMZdZiieeAXlEmqeubedYer04KytWEOCXYsfc3N2mf54a8BzuYUUagxvfzCfy3CCP8ULQBMSaKlnC038kXksb/4OQFiBY6rX7SEldDOJPAD5c7dTXkg= 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=v+HYsVyf; 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="v+HYsVyf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757545730; bh=5iWNx54sGjcK9fIya6c+VTdunUg4fVj+MTblZK2rNog=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v+HYsVyfHhzCBm7h8zMSS4thzij7x9TsWwDoNPhjnjHRt2S6YCTyyxwkqoYhs+CMT Z9AX4QK+TZbUT+ZIYcVZuZ9JXcShU+LdHJyNSQXJpY57c56CAY/KckNNWufc/39Qhh vl6pXyzdZTXLVXtsro69o1gWZsZMiwDkg4SoBl89ldMrgzORob2fb1ilS5nI4Qg5xz Z14xnXPsEfVQAuc1LAXuXtaVYMBwaf/CXoL2FvvoaVluyz/7Zs3/DjjW8ff3TB80be fASMwBfOsN0phj9ixmxlGCSPczmsG1Pu5z1u3a0IbedJx5aSGUFcWY30RYaE0e+twX ji85+5xg0GoOw== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id CB80F60139; Wed, 10 Sep 2025 23:08:50 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id E93582038ED; Wed, 10 Sep 2025 23:08:42 +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 , Andrew Lunn , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 04/12] tools: ynl-gen: refactor local vars for .attr_put() callers Date: Wed, 10 Sep 2025 23:08:26 +0000 Message-ID: <20250910230841.384545-5-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250910230841.384545-1-ast@fiberby.net> References: <20250910230841.384545-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 into the Type classes, and use the same helper in all places where .attr_put() is called. If any attributes requests identical local_vars, then they will be deduplicated, attributes are assumed to only use their local variables transiently. 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 --- tools/net/ynl/pyynl/ynl_gen_c.py | 37 +++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen= _c.py index 04c26ed92ca3..6441d5a31391 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -236,6 +236,12 @@ class Type(SpecAttr): line =3D f"ynl_attr_put_{put_type}(nlh, {self.enum_name}, {var}->{= self.c_name})" self._attr_put_line(ri, var, line) =20 + def attr_put_local_vars(self): + local_vars =3D [] + if self.presence_type() =3D=3D 'count': + local_vars.append('unsigned int i;') + return local_vars + def attr_put(self, ri, var): raise Exception(f"Put not implemented for class type {self.type}") =20 @@ -841,6 +847,10 @@ class TypeArrayNest(Type): '}'] return get_lines, None, local_vars =20 + def attr_put_local_vars(self): + local_vars =3D ['struct nlattr *array;'] + return local_vars + super().attr_put_local_vars() + def attr_put(self, ri, var): ri.cw.p(f'array =3D ynl_attr_nest_start(nlh, {self.enum_name});') if self.sub_type in scalars: @@ -2041,6 +2051,15 @@ 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 [] + for _, attr in struct.member_list(): + for local_var in attr.attr_put_local_vars(): + if local_var not in local_vars: + local_vars.append(local_var) + return local_vars + + def put_req_nested_prototype(ri, struct, suffix=3D';'): func_args =3D ['struct nlmsghdr *nlh', 'unsigned int attr_type', @@ -2063,15 +2082,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() @@ -2355,10 +2366,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() @@ -2425,6 +2433,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 20:45:46 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 78A8630FF36; Wed, 10 Sep 2025 23:08:59 +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=1757545741; cv=none; b=DMvAOOJTqAmgJrk5eaQYSrPR7gE+9CQK2WWcIdMWhXoT0MJx2OukyLPdVkNrH9lcniG7vDNkZ2a5DkaaBlitayU6THEfUcFqBonheao7Nf88DXIrsY0wZ9Q7MefJL3TcD8pYObKCE6Ojtp4ayQQeaw+xS+oDL5KyzreWfUvxbxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757545741; c=relaxed/simple; bh=nmFUdln7rWayXOvm+tCjXRJq0z3FgFYUv+rQXSS1YKI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PvOtya7ANAo9ZyMnn5btkaVWMAKuWDd+0kudNgHAA1M+NK5ytYsGYcb9FjVAra6hsX+NEf/eNnVfHORrjLymqEh23T2J7CsNqH767R9QiSKvmt6vjBDVsKAalmZMp+M9Z0ZzGXU8MBmmaErd53XcPnD82mf3Uz3CK6Ae0YPfzQI= 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=HltxTKhi; 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="HltxTKhi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757545730; bh=nmFUdln7rWayXOvm+tCjXRJq0z3FgFYUv+rQXSS1YKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HltxTKhiOHnCSUfdLrTG0iql13BAsPaDviXRRjJeOvWgY0+fo21zV1lKcSz2gEXNL L1FC5zrJ8EISxDPPjVrprNtiWuZaGH+2kl9PSTZt+vCj8QpgQiRX6QsVbRQ4iZA8KZ g6uI2QCbYkiOI3atxij7Wnul56VLVU6cGkmxReUsofKV4jy+CeR2gMaKLPoLekwKkK 5Vl3ihDFfXTiE+Lc/bhpFBTLcgl2orys1DvV0XVlPDmCOEOJxywPjSV/5+7w2i6ZGX KqFdn6b3y0ewBDHrc7XyDXsyhjGNLe6TNW0RO+TvLO5rAHp8hy+Pku72gThVtot2Ty lzZIp2a/SfYSQ== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 3DB566000C; Wed, 10 Sep 2025 23:08:49 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id F351E203A9B; Wed, 10 Sep 2025 23:08:42 +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 , Andrew Lunn , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 05/12] tools: ynl-gen: add CodeWriter.p_lines() helper Date: Wed, 10 Sep 2025 23:08:27 +0000 Message-ID: <20250910230841.384545-6-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250910230841.384545-1-ast@fiberby.net> References: <20250910230841.384545-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 helper for writing an array of lines, and convert all the existing loops doing that, to use the new helper. This is a trivial patch with no behavioural changes intended, there are no changes to the generated code. Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen --- tools/net/ynl/pyynl/ynl_gen_c.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen= _c.py index 6441d5a31391..18c6ed0044b9 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -181,8 +181,7 @@ class Type(SpecAttr): =20 def free(self, ri, var, ref): lines =3D self._free_lines(ri, var, ref) - for line in lines: - ri.cw.p(line) + ri.cw.p_lines(lines) =20 def arg_member(self, ri): member =3D self._complex_member_type(ri) @@ -268,13 +267,9 @@ class Type(SpecAttr): if self.presence_type() =3D=3D 'present': ri.cw.p(f"{var}->_present.{self.c_name} =3D 1;") =20 - if init_lines: - ri.cw.nl() - for line in init_lines: - ri.cw.p(line) + ri.cw.p_lines(init_lines, nl_before=3DTrue) =20 - for line in lines: - ri.cw.p(line) + ri.cw.p_lines(lines) ri.cw.block_end() return True =20 @@ -1789,8 +1784,7 @@ class CodeWriter: self.block_start() self.write_func_lvar(local_vars=3Dlocal_vars) =20 - for line in body: - self.p(line) + self.p_lines(body) self.block_end() =20 def writes_defines(self, defines): @@ -1831,6 +1825,12 @@ class CodeWriter: self.p('#ifdef ' + config_option) self._ifdef_block =3D config_option =20 + def p_lines(self, lines, nl_before=3DFalse): + if lines and nl_before: + self.nl() + for line in lines or []: + self.p(line) + =20 scalars =3D {'u8', 'u16', 'u32', 'u64', 's8', 's16', 's32', 's64', 'uint',= 'sint'} =20 @@ -2088,8 +2088,7 @@ def put_req_nested(ri, struct): ri.cw.block_start() ri.cw.write_func_lvar(local_vars) =20 - for line in init_lines: - ri.cw.p(line) + ri.cw.p_lines(init_lines) =20 for _, arg in struct.member_list(): arg.attr_put(ri, "obj") @@ -2150,8 +2149,7 @@ def _multi_parse(ri, struct, init_lines, local_vars): ri.cw.block_start() ri.cw.write_func_lvar(local_vars) =20 - for line in init_lines: - ri.cw.p(line) + ri.cw.p_lines(init_lines) ri.cw.nl() =20 for arg in struct.inherited: @@ -2280,10 +2278,8 @@ def parse_rsp_submsg(ri, struct): =20 ri.cw.block_start(line=3Df'{kw} (!strcmp(sel, "{name}"))') get_lines, init_lines, _ =3D arg._attr_get(ri, var) - for line in init_lines or []: - ri.cw.p(line) - for line in get_lines: - ri.cw.p(line) + ri.cw.p_lines(init_lines) + ri.cw.p_lines(get_lines) if arg.presence_type() =3D=3D 'present': ri.cw.p(f"{var}->_present.{arg.c_name} =3D 1;") ri.cw.block_end() --=20 2.51.0 From nobody Thu Oct 2 20:45:46 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 4313B317702; Wed, 10 Sep 2025 23:09:03 +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=1757545746; cv=none; b=GpH21UpaDXIzm3OitsByZxmhZ3ycb7WTatnGFbvwxdvRuX4VPKPH7SLd2WfykPNnO/P2gPtLx6PdGI3pZqfFXxViLk2mpB48aRiU/jfNNvjZFInrqjpco2nITexkSvzvDLCrQLEZqHdYq7THoXtjqWE/+IIIcL0FNu1+CeRVox0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757545746; c=relaxed/simple; bh=9YMEML/2cAF/dYFs5UWYG9j95tdvfBp0b58/5bdDpPo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sQ0FqRth3KwQi2xQLekO55CV6HT9KsX7mQks2aZrYvsOGcI5NahQ4/Hbks2nNQaPILhx9aw19kSnYgR6Dpukh2x3kFm0/HqO7R5+5SORHM/+iJ7oy63FewjOjyoit0uwfoymhmcHSezLijkrM20MDjTdwxbh4U+17fQsHDOyFSY= 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=LWCYqDZl; 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="LWCYqDZl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757545731; bh=9YMEML/2cAF/dYFs5UWYG9j95tdvfBp0b58/5bdDpPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LWCYqDZlxeZ1RYVDqKTrcp2TOseJUtrLdk/brH+iTTmlvJkr4ivvSNGy7r5A/22hA A6yJqVxBmaguVaHjY2LNXfpHkpawZWXUHes17bcT39zMU5Hl1VOcu6ourEVa7M8sxh nlL6OaABOOsufOkY6xf8YzFJYzjBM88eW+EyUK821kAg/JqikFVRuQZoK1N1wdVxpS LPb/Bm468DOCsu8Z4c3jwghh1gDXOXJVQIeAJQBEImss1OSt76vZ7xYFPsyDQgp9p2 FmY3SfVpqn4cLDYaOmvc2NdGMCX3IKlgGr0R6x8NiMokk1sQRojL9MDrizOWZpP91N bH7aqG2Fe/bkQ== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 40FA360078; Wed, 10 Sep 2025 23:08:50 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 09DAD2044FF; Wed, 10 Sep 2025 23:08:43 +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 , Andrew Lunn , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 06/12] tools: ynl-gen: deduplicate fixed_header handling Date: Wed, 10 Sep 2025 23:08:28 +0000 Message-ID: <20250910230841.384545-7-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250910230841.384545-1-ast@fiberby.net> References: <20250910230841.384545-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 Fixed headers are handled nearly identical in print_dump(), print_req() and put_req_nested(), generalize them and use a common function to generate them. This only causes cosmetic changes to tc_netem_attrs_put() in tc-user.c. Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen --- tools/net/ynl/pyynl/ynl_gen_c.py | 39 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen= _c.py index 18c6ed0044b9..f149c68ae84e 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -1829,7 +1829,10 @@ class CodeWriter: if lines and nl_before: self.nl() for line in lines or []: - self.p(line) + if line =3D=3D '': + self.nl() + else: + self.p(line) =20 =20 scalars =3D {'u8', 'u16', 'u32', 'u64', 's8', 's16', 's32', 's64', 'uint',= 'sint'} @@ -1922,6 +1925,15 @@ def type_name(ri, direction, deref=3DFalse): return f"struct {op_prefix(ri, direction, deref=3Dderef)}" =20 =20 +def prepare_fixed_header(var, local_vars, init_lines): + local_vars +=3D ['size_t hdr_len;', + 'void *hdr;'] + init_lines +=3D [f'hdr_len =3D sizeof({var}->_hdr);', + 'hdr =3D ynl_nlmsg_put_extra_header(nlh, hdr_len);', + f'memcpy(hdr, &{var}->_hdr, hdr_len);', + ''] + + def print_prototype(ri, direction, terminate=3DTrue, doc=3DNone): suffix =3D ';' if terminate else '' =20 @@ -2077,10 +2089,7 @@ def put_req_nested(ri, struct): local_vars.append('struct nlattr *nest;') init_lines.append("nest =3D ynl_attr_nest_start(nlh, attr_type);") if struct.fixed_header: - local_vars.append('void *hdr;') - struct_sz =3D f'sizeof({struct.fixed_header})' - 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});") + prepare_fixed_header('obj', local_vars, init_lines) =20 local_vars +=3D put_local_vars(struct) =20 @@ -2349,6 +2358,7 @@ def print_req(ri): ret_ok =3D '0' ret_err =3D '-1' direction =3D "request" + init_lines =3D [] local_vars =3D ['struct ynl_req_state yrs =3D { .yarg =3D { .ys =3D ys= , }, };', 'struct nlmsghdr *nlh;', 'int err;'] @@ -2359,8 +2369,7 @@ def print_req(ri): local_vars +=3D [f'{type_name(ri, rdir(direction))} *rsp;'] =20 if ri.struct["request"].fixed_header: - local_vars +=3D ['size_t hdr_len;', - 'void *hdr;'] + prepare_fixed_header('req', local_vars, init_lines) =20 local_vars +=3D put_local_vars(ri.struct["request"]) =20 @@ -2379,11 +2388,7 @@ def print_req(ri): ri.cw.p(f"yrs.yarg.rsp_policy =3D &{ri.struct['reply'].render_name= }_nest;") ri.cw.nl() =20 - if ri.struct['request'].fixed_header: - ri.cw.p("hdr_len =3D sizeof(req->_hdr);") - ri.cw.p("hdr =3D ynl_nlmsg_put_extra_header(nlh, hdr_len);") - ri.cw.p("memcpy(hdr, &req->_hdr, hdr_len);") - ri.cw.nl() + ri.cw.p_lines(init_lines) =20 for _, attr in ri.struct["request"].member_list(): attr.attr_put(ri, "req") @@ -2421,13 +2426,13 @@ def print_dump(ri): direction =3D "request" print_prototype(ri, direction, terminate=3DFalse) ri.cw.block_start() + init_lines =3D [] local_vars =3D ['struct ynl_dump_state yds =3D {};', 'struct nlmsghdr *nlh;', 'int err;'] =20 if ri.struct['request'].fixed_header: - local_vars +=3D ['size_t hdr_len;', - 'void *hdr;'] + prepare_fixed_header('req', local_vars, init_lines) =20 if "request" in ri.op[ri.op_mode]: local_vars +=3D put_local_vars(ri.struct["request"]) @@ -2449,11 +2454,7 @@ def print_dump(ri): else: ri.cw.p(f"nlh =3D ynl_gemsg_start_dump(ys, {ri.nl.get_family_id()}= , {ri.op.enum_name}, 1);") =20 - if ri.struct['request'].fixed_header: - ri.cw.p("hdr_len =3D sizeof(req->_hdr);") - ri.cw.p("hdr =3D ynl_nlmsg_put_extra_header(nlh, hdr_len);") - ri.cw.p("memcpy(hdr, &req->_hdr, hdr_len);") - ri.cw.nl() + ri.cw.p_lines(init_lines) =20 if "request" in ri.op[ri.op_mode]: ri.cw.p(f"ys->req_policy =3D &{ri.struct['request'].render_name}_n= est;") --=20 2.51.0 From nobody Thu Oct 2 20:45:46 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 125E230F959; Wed, 10 Sep 2025 23:09:05 +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=1757545747; cv=none; b=jtoUnJ+h7+La9u2pCX3RSawL+ZHWsnrAbgKxE7dkc3+xVZKVxT0Lg5zSJio3Tic6GGZyLHjDB9b2muHQyy5YuxEbdBf7pLgp3tT1Bi6UhhaOU7jj2Qy7C+GGHrvi8bup+wDHG1bTR8BakhqJv+OerBb/e+A5pEARKXfnbzk/azM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757545747; c=relaxed/simple; bh=Dv6vpp6X/AAuz1b30uuf1mx68WEBTMVd1Kg6gyPEzLY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nbuM/P/PoEqR4+9FMd5Awpm3Q2fpksquc7zSMjEg/eYW2cB8djuVxf3hdPWAcPLE/KhR6EJPyPuGCxPit0YDJzxj36jb28PKzG0pPtyu4SEKhQNwLhRjKSGeCAUazm9hXQeFhbhaQ4/5EVAbz9zAY3TDoabllLWnRyj7kZN/zJs= 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=E4j0kdv2; 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="E4j0kdv2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757545731; bh=Dv6vpp6X/AAuz1b30uuf1mx68WEBTMVd1Kg6gyPEzLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E4j0kdv2eni1WM/7CAHkGhsViAFNy7p0a4Mau5GfYuZ4ij+KAvQ6mB7Vmm2Jn0EoX BNYobMkHu4pIbHKdckHiTC8BP3jpcnqPtqIlXDL6ujjwIeqzXjZALDzeIrQsf1FfaM gKX/MWKkm2r/egCXmxDL1vTjWMths2fGYYF2iIqp0qJ3UTzk9kngd539US0vcH8ZeS pPrvQRWPcGcFgEAHGCzdZaZkn7aJuoP8fIN3m22JvosisoIKv6WiJl2j33gXlUpjhI QrAIHeTVPaXSmnTmW8sMnCh5s1RcecwK4gyI/9rpwC3G3taBlRM7ox9GzwmN/CNIgs wHLitHkBzqirQ== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id C4B6A60137; Wed, 10 Sep 2025 23:08:50 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 13C24204B0E; Wed, 10 Sep 2025 23:08:43 +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 , Andrew Lunn , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 07/12] tools: ynl-gen: only validate nested array payload Date: Wed, 10 Sep 2025 23:08:29 +0000 Message-ID: <20250910230841.384545-8-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250910230841.384545-1-ast@fiberby.net> References: <20250910230841.384545-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 adds a new helper, ynl_attr_validate_payload(), which we can use to validate the payload of the nested attribute, in the context of the parents attribute type, and it's policy, 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, }, Some other examples are NL80211_BAND_ATTR_FREQS (nest) and NL80211_ATTR_SUPPORTED_COMMANDS (u32). Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen --- tools/net/ynl/lib/ynl-priv.h | 2 ++ tools/net/ynl/lib/ynl.c | 17 ++++++++++++++--- tools/net/ynl/pyynl/ynl_gen_c.py | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tools/net/ynl/lib/ynl-priv.h b/tools/net/ynl/lib/ynl-priv.h index 824777d7e05e..70ea14c0a0e9 100644 --- a/tools/net/ynl/lib/ynl-priv.h +++ b/tools/net/ynl/lib/ynl-priv.h @@ -107,6 +107,8 @@ 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_attr_validate_payload(struct ynl_parse_arg *yarg, + const struct nlattr *attr, unsigned int type); int ynl_submsg_failed(struct ynl_parse_arg *yarg, const char *field_name, const char *sel_name); =20 diff --git a/tools/net/ynl/lib/ynl.c b/tools/net/ynl/lib/ynl.c index 2a169c3c0797..d52aa188401f 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"); @@ -450,6 +450,17 @@ int ynl_attr_validate(struct ynl_parse_arg *yarg, cons= t struct nlattr *attr) return 0; } =20 +int ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *att= r) +{ + return __ynl_attr_validate(yarg, attr, ynl_attr_type(attr)); +} + +int ynl_attr_validate_payload(struct ynl_parse_arg *yarg, + const struct nlattr *attr, unsigned int type) +{ + return __ynl_attr_validate(yarg, attr, type); +} + int ynl_submsg_failed(struct ynl_parse_arg *yarg, const char *field_name, const char *sel_name) { diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen= _c.py index f149c68ae84e..e93f5d724b42 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -836,7 +836,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_payload(yarg, attr2, type))', '\t\treturn YNL_PARSE_CB_ERROR;', f'\tn_{self.c_name}++;', '}'] --=20 2.51.0 From nobody Thu Oct 2 20:45:46 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 5FB31314B6A; Wed, 10 Sep 2025 23:09:03 +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=1757545745; cv=none; b=EAgwhvFjaPWrg+jnl6WIQd2JIH/+Gn1I6N45lMrsq8TSS9f21ey5Cplcb2xovXGl1a8qCBvCGpa67K+ciXGhlBBVm15dDQtxO0fjS4v7sdBx9Nh4JFU2Im/qKtuXTjXeG0mywd9pBTFyCkHrvUoV2BGgWpp6RIyN4ygH5aEEghw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757545745; c=relaxed/simple; bh=AJhXtkWuMzpABxvSR0d9FQM3KyK8VD9yoZ5MetyiYuU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=f0cMisi5r3A7uw3u5vsvhwAHR9yDtuzklilao06npQxWcKtcFsfv+YbNZXK76R4mUo5KcMXgxqydI0A+FSfES9MOB0hG/Zaf9h9Xphsc+FR1i58FTBMHoWa5kE70UE21PJBG/o+E/DLwJ9tC5mB7gxRoAL9I6Cg3QEtoqucHuxs= 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=EGexIctJ; 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="EGexIctJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757545730; bh=AJhXtkWuMzpABxvSR0d9FQM3KyK8VD9yoZ5MetyiYuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EGexIctJYnZrFmOZKzEMxSehii6fotVPm7gk9m/CLcRMi4P7IGNuLXyh66CtANQR3 ji0nCVE5RUX4HTyHTIGWzSYNfQxesLXuK4du+w+jI6zior+IbeSs/JEE46WY/HyZmp r7UwUVVmzqnRqG2qIFVfqSocXCmqynVcAGJxKK9pK0bzNt6mHY4XKsfUH7wuT9gwaR 6SMaq8cY0RHoDqfRm/t5MCbuA2USSe8rkz7JfJwKv1CPyK7Cf99oLlNlug+5+QfFKa ycdvyrpBpf4G6XsOHsROPrl86MG2Hi4Dg2dKwrzn9rrbPdjIJjN+SYU4S7RmeSjkjI arQQEmzV8Rk7g== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id C7B1160138; Wed, 10 Sep 2025 23:08:50 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 1DFF5204C9F; Wed, 10 Sep 2025 23:08:43 +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 , Andrew Lunn , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 08/12] tools: ynl-gen: rename TypeArrayNest to TypeIndexedArray Date: Wed, 10 Sep 2025 23:08:30 +0000 Message-ID: <20250910230841.384545-9-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250910230841.384545-1-ast@fiberby.net> References: <20250910230841.384545-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 --- tools/net/ynl/pyynl/ynl_gen_c.py | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen= _c.py index e93f5d724b42..574faa89b1f7 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -793,7 +793,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 @@ -830,7 +830,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;'] @@ -860,7 +860,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): @@ -1137,7 +1137,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': @@ -2127,33 +2127,33 @@ def _multi_parse(ri, struct, init_lines, local_vars= ): else: raise Exception(f"Per-op fixed header not supported, yet") =20 - array_nests =3D set() + indexed_arrays =3D set() multi_attrs =3D set() needs_parg =3D False 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: multi_attrs.add(arg) needs_parg |=3D 'nested-attributes' in aspec needs_parg |=3D 'sub-message' in aspec - 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) @@ -2172,8 +2172,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 @@ -2191,8 +2191,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}));") @@ -2217,8 +2217,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 20:45:46 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 78B0730FF39; Wed, 10 Sep 2025 23:08:59 +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=1757545742; cv=none; b=ZsjCJXS9+ZBKXpvnl/2CLMm8EZq4jXI70m4EufVnk+bOYnerJYO5mS1AX4ec2iWNPpTaen4LwG4wX6L5FVQhRoYF3Q8v7dndMBsSFkUBIWv/tEeodpqG96i1j1le6gyXSNnxgoxNQLAxhneYTNXBbI7IuJsUzkSSRQ1GkvLiFNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757545742; c=relaxed/simple; bh=Ns7Cgk5ZDdtF+Q6dyaF9mQHUhLgGBUAAJadXXI0Ry6M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VE5CF+UyLCADfhSzNOqTaZDotKvX751HNhyWbR7A5a0m4eVWJKR1fBKSZX/yAajTyWqzZ+Ui7ZInhkzfrnHlkTBnwjQLsWBNumezk0PMcHXa4/u2jxSi7Rfl5fjh4M7jaEMSxdULXGWnzY1n57RTGqp+yK12lysF9HLwxLqOn9I= 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=umbYFG1d; 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="umbYFG1d" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757545730; bh=Ns7Cgk5ZDdtF+Q6dyaF9mQHUhLgGBUAAJadXXI0Ry6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=umbYFG1d5Yak61rLgZzoGxrWRIqKSxbBUaFIbuDdfZU1mTzy6jhP0VGirnCNImw5z MySboBdfMvv+xHfYnjq2OiKHmbaodKvF6CCyAAdBlSIOtlTeIHxrAZoVDIDYZ/AAQU f8hPGt6GK7+xz0sf9jKTI67/B8H3ry8VlDJpxzB47LEhd0+sFqoTtR88EB6bMrz3Xr tNkqDER4VnB7JpFKB8un/pEp2TsXF8Nj6ZGSknA20gpJ0biBm2cOxrslEhgpfxDqr6 3kuga41VpSqcsIe6zGZn5RF6MB7rskNQ0+FbYqM3LFwUozTzKpR1SGeJJHlAjcuqZJ nFet1GbCbDnSQ== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id CFABB6013B; Wed, 10 Sep 2025 23:08:50 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 27688204E9E; Wed, 10 Sep 2025 23:08:43 +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 , Andrew Lunn , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 09/12] tools: ynl: move nest packing to a helper function Date: Wed, 10 Sep 2025 23:08:31 +0000 Message-ID: <20250910230841.384545-10-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250910230841.384545-1-ast@fiberby.net> References: <20250910230841.384545-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 8244a5f440b2..4928b41c636a 100644 --- a/tools/net/ynl/pyynl/lib/ynl.py +++ b/tools/net/ynl/pyynl/lib/ynl.py @@ -562,11 +562,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. @@ -623,6 +620,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 20:45:46 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 E85D2313E36; Wed, 10 Sep 2025 23:09:02 +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=1757545744; cv=none; b=Z++bQEMKERa5sBaJUTqhcAUHRUf3nto8Mnr52VMoqBrxpLTRWZUIuCGtpIdAVExLPx7fri7wbuVp/94zTHZ9I5ew+j0DfOPciIJNj2bH00SPL9GQb81GqQh58jkJaTmZmtVE2GANgTfr0+zmoqwYWf+Ht4J95b7z5tvSFi7LtMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757545744; c=relaxed/simple; bh=zYZnZi0XfZFGANAoH/LGTsc2D0gQ6Tox0actlKX6EnA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=d/JB7HIuRMQ2vk+npM6gl5nRlGooY1Bl4WutUmiB5GVbpHFXb9jnzVt5JYdtKawTWFgyBnqot3zzUiiqkov4tVir9JCz983DYLAnsc6PLZgZ0oTko+JSPfmNiFWUnqmleP8a9uqh7QGofCxd+G1a9O7DVp6Sm1aMMPpZVvDJkQQ= 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=a50bW58U; 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="a50bW58U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757545730; bh=zYZnZi0XfZFGANAoH/LGTsc2D0gQ6Tox0actlKX6EnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a50bW58UB2o8fhRf2PHclk9ZQ6uKZ9vysOFTgFmsgFgpfG1kO1S8GNZTm7ZUFaotw I+Sdu6PUVJNZpFlo42KXX/3fb2YJ9hrurHE+wdmJxghH4xd1BM1zU4mTBFV7WEz1Ae cmapCYKbmtMrpwuzqiURTAbU39p5ZV8Xk/WlCU6XdYy/vL4Xt6hRknMRTLupKh/aF+ 6fbe9FnrytcFy4JHls87nWDSWcLDt2w82kZBJXyujcxbeUock8Ln3x3+6PGjhFyfp1 VnCp8lTX8oCrwDPgnoppSXlYRRhIW67MLfjIrtsRQkUofsL2I6P4eN/S9O3frG3933 wpNBTEqNwGvWQ== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id E11C46013F; Wed, 10 Sep 2025 23:08:50 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 31239204EED; Wed, 10 Sep 2025 23:08:43 +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 , Andrew Lunn , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 10/12] tools: ynl: encode indexed-arrays Date: Wed, 10 Sep 2025 23:08:32 +0000 Message-ID: <20250910230841.384545-11-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250910230841.384545-1-ast@fiberby.net> References: <20250910230841.384545-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 --- 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 4928b41c636a..7ddf689a2a6e 100644 --- a/tools/net/ynl/pyynl/lib/ynl.py +++ b/tools/net/ynl/pyynl/lib/ynl.py @@ -564,6 +564,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. @@ -617,6 +622,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 @@ -628,6 +636,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 20:45:46 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 61CD9314B6B; Wed, 10 Sep 2025 23:09:02 +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=1757545745; cv=none; b=VUYoOoIlPoL+cZgNu3BwIEp4/wQY6A0235jj/szm78ieLq7CC+EZMpg1Ab24vOKM9bsfT/8TleFplW7AtGas0NO6agvi9e3bW7Da7WBv8dXYdsoI1SXnVMBL3sKJkF0/zMKctF8tlMEOcMHpB3HSo+858Lub1LPgh7LI60bIvCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757545745; c=relaxed/simple; bh=gPzW3wCV+qM3pD5q/z5sXTnTfFB9BV31CnXtVtDMhXI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QKsxoDBhEWOmwj7FcQTZrmIhm2l38SJxYIoIoghdivSCdnHpl4+GRazepEzJ09NVHdQ9meSry5gp2A047oFKmBuDygThtow3ZzjMMsPo6lH/0rFSveYVwbp535gPCH1Kz4PpL9BedKXCpR9GOs7o0U+xucoZ1IbBEQ2dUlAym/s= 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=hyH/WVOo; 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="hyH/WVOo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757545730; bh=gPzW3wCV+qM3pD5q/z5sXTnTfFB9BV31CnXtVtDMhXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hyH/WVOoCpQXnsmm/RhKX8w55PKl+c6IaIxkkHUJMtocIu6ROFzZaQLMEtFETOjbC T0+1wMFchb6H5DS+dk/blqGvnoEA1XU6E+bG7lxLLEEJ66uspRFdy5lrQcSsqqqIRw mePeC3azkYm3GXema0IW58Wb8ccnFg6Q4sovumUjHsyCMIs9s5gtZ36iaOBpJO45yt IBpyvFhUKiVSS+6xllPdq0x5iP2KdILcYSH8Zf7kyzpxBiR9ozbhB8rFVKPMcdzGkq 1VtMH02EGSFLmPC695ZI/uTyG8BW+FEXOx+h0C7Q4rQQJ3FK7ZHbaHxIepgg7sdikq 3gknIExnuyazA== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id D73AB6013E; Wed, 10 Sep 2025 23:08:50 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 3B22F20519B; Wed, 10 Sep 2025 23:08:43 +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 , Andrew Lunn , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 11/12] tools: ynl: decode hex input Date: Wed, 10 Sep 2025 23:08:33 +0000 Message-ID: <20250910230841.384545-12-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250910230841.384545-1-ast@fiberby.net> References: <20250910230841.384545-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 --- 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 7ddf689a2a6e..50f4889e721b 100644 --- a/tools/net/ynl/pyynl/lib/ynl.py +++ b/tools/net/ynl/pyynl/lib/ynl.py @@ -972,6 +972,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 20:45:46 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 78BC730FF3F; Wed, 10 Sep 2025 23:08:59 +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=1757545742; cv=none; b=ZPlihRRhY/v/DUrnBrv6SGbZ73UqvnSfm/dYVnEzul9intfIz8CzPYwzU8+tA8DUKiAm8aKKSGXfNHwoUpEdA0FyrCPSRMPrIraUQ8p8ToWCt77tJVK2LlNMAqjyc23lhfK/whBGYJaBY5LeJ0gCx1KtA45eSp+ka/oGDR/BONg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757545742; c=relaxed/simple; bh=mHCxHMaMTlUNc8yNdBlBwvuCNIWstdK/GS0nKVCzvbM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tIBsgJ/YXd3XTi8JXOrf68ogLjIrWrOsYV+PdJ6VdUtySqypfQ6T1s6ZNfv6+hR4N2bDNvkbNu/Ug+mOW9qsNj/l1tcWeI03ZYE+isJwK5acuIE9DhXskbzF8+kYSlBZp3FnbGjRgsaCHY+VdxdoX7a+IM1Oqqe6ME1gVu82iNs= 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=uidoNNm4; 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="uidoNNm4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757545730; bh=mHCxHMaMTlUNc8yNdBlBwvuCNIWstdK/GS0nKVCzvbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uidoNNm48j4rEEdkjJMfaKXIcU2W5eWc8JlPd1inHIZAEeBg9e33lXkR0p8KsI9gw YpIvfri0nB/UXDskxgy897Ao39UtgpKXvb2LuU6ruAtmyfEZpcejVXVQ3l9jryoSxl jWbV5FjHCzAXPL/ngfcdtlACoar+nChkt6kYYgVktCTbomNRdt1RyXcpZGrjTsv9RC HTmqp+H58yJO+PClPNBPvX+9FoqEJQg2hjn/1XDk8rj9twWhgmXPdoOm4WCaa7QiAA w4KNhZUPOxNMpjkRie75wkok/k/3wwt5XS4dqyLD+U7CfQzXq8nPazfKQcPjAVBA4n sz9VMGz9tTpQw== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 7E7746012E; Wed, 10 Sep 2025 23:08:50 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 44AB02051E5; Wed, 10 Sep 2025 23:08:43 +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 , Andrew Lunn , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 12/12] tools: ynl: add ipv4-or-v6 display hint Date: Wed, 10 Sep 2025 23:08:34 +0000 Message-ID: <20250910230841.384545-13-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250910230841.384545-1-ast@fiberby.net> References: <20250910230841.384545-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 50f4889e721b..4f2c8126d6e9 100644 --- a/tools/net/ynl/pyynl/lib/ynl.py +++ b/tools/net/ynl/pyynl/lib/ynl.py @@ -957,7 +957,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)) @@ -966,7 +966,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