From nobody Thu Oct 2 19:28:28 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 039191DBB13; Thu, 11 Sep 2025 20:05:30 +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=1757621133; cv=none; b=MUplM2dN4YwXAHaYgCX/Bedd/ntY9KcqdtxvbrUVJFv83TzGM2XEqG9uYqsVp8bZlblsEKWeL8rIt406fy6LF9wTuva/4ZxOvFJAr3rlnIWzyWQxt51lDXCmIJkquqCT3YUV0+6yWWnfs0CdvfUWZAjmkuW+ykq0dZoNvhJFjio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757621133; c=relaxed/simple; bh=pnz1Z9RsFEA/w79qMxEPA9j3gcVp4d2qUkVblwMqsWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KqA5aVBHDLuIBXLjqoJFl/CrqfSXztDu1vSSBobXCDklkmlBq2Srat5JYvvK2aDfroncvMXVcsJCWVdjYhHTF/8L55geecRuUie+5hvpJKkFuurxBlCQDSarMcoTQok92BOe7ZtYKWwdq2gFrlnml9OTahwSQKMZ1tJqcpx3IOc= 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=rR6tl7ON; 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="rR6tl7ON" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757621127; bh=pnz1Z9RsFEA/w79qMxEPA9j3gcVp4d2qUkVblwMqsWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rR6tl7ON3KGjavAVSATs4mNIhcvrOV+Pox69ZgQCXF5PJmFZMrLRJBKHyfSaBjN7G +/FyJSwlHeDeQkp2eO7zztFZUoOJCPpNpmpLW3EM6MfuPyW9VvASCl7wwrNNfLXuO0 fDUTrlX1jgFA/I5/qA+VuLGzueY3WZjaH1e+8Oj1NoBJrE2vBAbJkB7WnKNcag0XTR JfOVw/OuNGpqU4O3aXqVgbNN2lOfjXDVTy1Z5i0oKTokHoWyIVK08i/xsyFsBOyMQI eNJkCfkRFAMXo944xdNKq7GCVt66ZJYcrqm6U/9tfxORTRSC1gCRbrG1pvKTbgtQg+ kXh861lb2dmJQ== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 885EC6000C; Thu, 11 Sep 2025 20:05:26 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id D7098202A89; Thu, 11 Sep 2025 20:05:20 +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 v3 01/13] tools: ynl-gen: allow overriding name-prefix for constants Date: Thu, 11 Sep 2025 20:04:54 +0000 Message-ID: <20250911200508.79341-2-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250911200508.79341-1-ast@fiberby.net> References: <20250911200508.79341-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 19:28:28 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 4C3A3274B5A; Thu, 11 Sep 2025 20:05:34 +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=1757621137; cv=none; b=kFC7WAtML1D1lMGEFWUK+yzAr86ovBqJNSZ+zG9DsVB+VLzrPhRadJ26xGhStX47enpr8c2c7RrWfXqGjM3R3MNZfGJGlMF6G0VRMyac+ZRMNCI7FohRWG8otcsXfP2H8NVNQMz6SN1g0aVb3usvbkeJcugjeLdHVTXOIRqXsE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757621137; c=relaxed/simple; bh=B0xFRM28DmWIgrG1Q+a6XZkJNRKEo5x4SQ82oQgZwfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gySwPrJaVaFdVpJuVELLEbgVNZQceaqE2xC09jk361qYkuOWhpdwHabRkFmBM9Q+qn4sEISl14R0s/Vlg+TeZ/v2FRXqvjck82y5IWE66Pw4mn4IFOD1v12U4tvy+6prUq4cgOHkvoa4JMlztdYL6aUrLGXdt50qVTtVpZKlWLw= 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=NJVWSvkt; 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="NJVWSvkt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757621127; bh=B0xFRM28DmWIgrG1Q+a6XZkJNRKEo5x4SQ82oQgZwfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NJVWSvktbBPJ4GVMV4hCwrMnoeJ0HehiBFmmPCyj7OR4+NS45L5wdp1OTWcgfbo6J MQxqF49AA+Yb+MQ9Y3jDeE/EuNkN2MlA+SGtxSr/AdS5D145VXt2q30iJirSuBx7jm SMYCqCnD8Ki/NaplmZutVlRSc3JI6wrePf0kWROSGNlpgSQfvlYJEyRexPeR5EV2bD 9BX7biFn8C1PqBiO0S/bdFu8iraU15EI661XondqvaP3+PWC8pxcBqzYqdxMl0P6Dx kHvmdQOYGrv+ajmoYwjV+aJVZ7VvIFF/lqFw98rEiJ1ydcfAMIMk6A4nFHUcCyaCDJ fIwbJBfQ0/zlw== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 423646013E; Thu, 11 Sep 2025 20:05:27 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id E2394202FBF; Thu, 11 Sep 2025 20:05:20 +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 v3 02/13] tools: ynl-gen: generate nested array policies Date: Thu, 11 Sep 2025 20:04:55 +0000 Message-ID: <20250911200508.79341-3-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250911200508.79341-1-ast@fiberby.net> References: <20250911200508.79341-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 19:28:28 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 6B8DD27280F; Thu, 11 Sep 2025 20:05:34 +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=1757621136; cv=none; b=DMdaDrkHvd5TvgkLFuE9/yIccMXE9DGNyT3AjnHNILAlHhj6jJPsZ2olJZdKBngOVrdBzvLsBspN3ZEMaBmOHmYGPVZ3N93+CFWMr2G/xaTsdQxUkQ5rMnW1PpwVWPhDfaFgFVOuWdzgXBY4ZJnUZ5GqZsboILnpNWiwkNlNTNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757621136; 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=rvvba3tiFlUA6Qf2PlSYG2qqJ3gn7iGa0hDvvH2R9PYnIcixILbe944NRXrjdags/5+61oBb6s/ZYZGZmrr/w5fZMqrddYkbRKO0o89WeWWT3DKDCpwKIRWy+OZDHp2u1gTd0ftNBAeYKHtTx5PDAAfc1HWC/bckwFQI2FnLws0= 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=Y28AXAcW; 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="Y28AXAcW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757621127; bh=EZJrSC8HKLIZeYkZ/ou7/O3NW58W1W8t+y2LSY8Uu94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y28AXAcWOK0yjBdzFPOBC50xh4n1r+wrb2/oJAXRZwyuOi59jSS7LdMEuYu1E/83I 5AfGet3+UyfSYN/irQKNueBNfChybd+gtEMsNMDekxOk56bbL2IKxe74mPJ9c2eUVK +vbCZcMKLeWUsKJ55M9Kt7FKH3CyOJumBP83HoLcS6F6gq8PzrgXZDYAg7D5y2gfP9 l4YcWN8v9jruY+AZQd+4AZDlpM60rO1AFXMtrPkO2nF9gVNHVocY+aG3H+y14ffM69 KPNEcTG9ODF6UwZZVYC/IXT0qvJeDt1HJoVkj3gsRl6J2fBGK5sv6AN01ClNKl5d6Q JEJlVz7qV9X/w== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 2D5FD60139; Thu, 11 Sep 2025 20:05:27 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id EC9E920393F; Thu, 11 Sep 2025 20:05:20 +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 v3 03/13] tools: ynl-gen: add sub-type check Date: Thu, 11 Sep 2025 20:04:56 +0000 Message-ID: <20250911200508.79341-4-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250911200508.79341-1-ast@fiberby.net> References: <20250911200508.79341-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 19:28:28 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 4E98C1E3DD7; Thu, 11 Sep 2025 20:05:31 +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=1757621133; cv=none; b=M8L126zsKylFvqb0esseDC0AQXg1kaO3It/hqu3sJauh+1PcOsTPoNYL0NSY2Fd7XeaPW10MBWfzESzQkeFeqlhtiAkbDEVW4UimPvyQsZ1ftm2BkKjKi9wKOe9LnnMpy5pnKPlh3xsSzoL1HhvHSN+vbXnlZBi/P4JW48baZRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757621133; c=relaxed/simple; bh=XXjcTNKslt1b6PY8TquSYL6KbSfUAvUwDGK7Xz4t9us=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r6OFIieBhdC/pajkJu7Ixan89q8U46l9q7KkDivBKjtLkaEhROwzzY7379GsWko3+ZokGUNpJT/BD4tVZSZAUNbwsEtjl3PFJBctunyAv1dYpuGnBXPJuBafQeas+5OUb24oEKfVvcZ9/dlnsHF0gQBdE8MOc/hoqi+eFP/+5Nk= 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=Ycdp3kZq; 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="Ycdp3kZq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757621127; bh=XXjcTNKslt1b6PY8TquSYL6KbSfUAvUwDGK7Xz4t9us=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ycdp3kZqhwXL2kf+4Twbc5x3QcYvB1DuXLbqmZIEiKRMQNByXEoRrOYLqg2vhATjN 1txvhfIMfWGiCLcruCG0ha5YVTOr1LSczv8deqIawWbCur0XT2cYfzvQ4wVqtIXbsh D3Aviwj5cD6CYWHrQnGl7nxWcPUhXM9nQUIN+lJpqw0AN6sdmQlVfR4XZvZ00hgsLJ FKcKmkqjJTzutsU3Cysdqq4qcAKlD/6N1ARX17p0rcvKC0jlEitvcRuulp/BnqwMaO eOwt0jTdlY8i5Qh23BhxOkZPrxAu34tl1v0G46VD6v1lM8OswiyEMY+K0SQyfzAq2S BDvpRn+lWjyiQ== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 8B1E460078; Thu, 11 Sep 2025 20:05:26 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 02C7C203CF3; Thu, 11 Sep 2025 20:05:21 +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 v3 04/13] tools: ynl-gen: refactor local vars for .attr_put() callers Date: Thu, 11 Sep 2025 20:04:57 +0000 Message-ID: <20250911200508.79341-5-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250911200508.79341-1-ast@fiberby.net> References: <20250911200508.79341-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 Reviewed-by: Donald Hunter --- tools/net/ynl/pyynl/ynl_gen_c.py | 35 ++++++++++++++++++++------------ 1 file changed, 22 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..e4cb8c95632c 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -235,6 +235,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 @@ -840,6 +846,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: @@ -2040,6 +2050,13 @@ 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 set() + for _, attr in struct.member_list(): + local_vars |=3D set(attr.attr_put_local_vars()) + return list(local_vars) + + def put_req_nested_prototype(ri, struct, suffix=3D';'): func_args =3D ['struct nlmsghdr *nlh', 'unsigned int attr_type', @@ -2062,15 +2079,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 +2363,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 +2430,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 19:28:28 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 6EAAC27281D; Thu, 11 Sep 2025 20:05:34 +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=1757621136; cv=none; b=nYI1WRnAKDzBUv8QvslpjMI8aTUBgfByJ9VMkAssN8p9riEgVHVMtTtgiHwgE/a367paHHKe1K2xjYvKNw9LTiEa7hF3EMIhM6gzG0ESlzLrvcijHlgriAwEE7QeaKBtQCrA2g4jzNA91KnzArME4+UgoF61VuaXe136xgJcQYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757621136; c=relaxed/simple; bh=BQC1Dyawkb1Zu4qHJO8XzZ7e0+gVs8UpteFavlIpea0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=En6Xsbe4FkoZAk94Zgc+Cng2S2JuJ98xUuMTadLtXkhr7BPXW4hvIeVKFB08UmAeDEcXWEMe0P9imPqcKlTqskfPaEoX9IWjdTRI1fQacADBNeSicO5gKH9Jw3iiRYmrdcZpNY3RmywXmU0twOOEc7ljPXQS0LauXz83IfWBfoY= 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=YhFg3m8m; 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="YhFg3m8m" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757621127; bh=BQC1Dyawkb1Zu4qHJO8XzZ7e0+gVs8UpteFavlIpea0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YhFg3m8mEc3vLKlbqULWgOnI9myrPsQ9F+e4kyCfm7ZfNE8b5R7Y5S7g9Jd+QQy1R q2B/3Uz2mYplB8lWyeOnex7J/x8ChWA2QNLNXQMx736/02NVnedEwBI+ulWIr7tXVh Pzz3W+ncc/Blwub/tffxUGx2XTNmRQwxpiF8j5F/mO7yUQEjKARxxJX0Q2mKcCKCH1 cbfc6mlycr73/j5YtHBYgD6AtG6Ebymq0udsInXTj0AXNRRd0fLezIE6LLE8aBC1O2 nT0KMhRGh3euayOfYFRc8vX9cqKiKkr5+7EeVRyVyHakhGab/noBuSr9CP8J96UmHu lAtpesUcFaJfA== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id C4C3B60128; Thu, 11 Sep 2025 20:05:26 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 0CC8C204AFE; Thu, 11 Sep 2025 20:05:21 +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 v3 05/13] tools: ynl-gen: add CodeWriter.p_lines() helper Date: Thu, 11 Sep 2025 20:04:58 +0000 Message-ID: <20250911200508.79341-6-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250911200508.79341-1-ast@fiberby.net> References: <20250911200508.79341-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 Reviewed-by: Donald Hunter --- 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 e4cb8c95632c..7a2e49a84735 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -180,8 +180,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) @@ -267,13 +266,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 @@ -1788,8 +1783,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): @@ -1830,6 +1824,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 @@ -2085,8 +2085,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") @@ -2147,8 +2146,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: @@ -2277,10 +2275,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 19:28:28 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 D743E27467D; Thu, 11 Sep 2025 20:05:34 +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=1757621137; cv=none; b=Vs4tW6CXVOf+Ccp7dlK7kl92DYQLQPTAMpuR2gGJTmdn2gcT0px1yLu4XIDoLKF4nBUvMoJaIQ2nTMQ/Kqiri+1H6Srqxlx2Z3jWb0yghJdWZCe+qnILvTkKOyrPOaxU+HXqkCRx/uuZWA4BMTKTqImh4JouhYgXgv8LNjffdXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757621137; c=relaxed/simple; bh=nRP5kSsL1NhUO522TR+BNYCRG7vfbgQCQLsZarTM8HM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CcOZZ60zrxfTGy0rSI/ETmWBe0fDvCOdrsPiMk6SqqOh2Cbl700ftoV3gFQwA3RCTLxwW0x9jfxihwbdrtkyuq0vP9mUWVOpbiqed/5y+PWqZAaavy+kSFtido3gywhqLYvwVVPMASvYY4APUhIvru6AkVM6Sd1uVQ2wSaztXsQ= 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=WAstVTba; 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="WAstVTba" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757621127; bh=nRP5kSsL1NhUO522TR+BNYCRG7vfbgQCQLsZarTM8HM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WAstVTbavWlOpORLtQzsZb8QQoo0KzpoUYqwExXkes5k+cuHAR1XOQ/4mkxG7cWwQ s36rgOJ5lfzAEdeiF9YYw6Ecpxgz/OX6aZKss/FQyJSwpE1u+0Y5GB/wY/Ij7er2FD gGMnVp9VL8r+u7jy56M9u3r+ZGXhGW6rol0nCx8WIzM6EoT7wY4gHutlTtfoQ/szZj jrpz6VpdIaHDedINmtKMJkBJn3R1/Cf0BT902mEf6ErBOQVm8YJ8ZPtaPh6PCz4RnC IMmSkEGc5uody4NT/A3duYL0QviQTSpLz4TOnVTk4/gjazFfG8Wq/jmAPIv2R59V+t cJ4jyaZBVPT8w== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 2C3E960138; Thu, 11 Sep 2025 20:05:27 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 16890204C71; Thu, 11 Sep 2025 20:05:21 +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 v3 06/13] tools: ynl-gen: deduplicate fixed_header handling Date: Thu, 11 Sep 2025 20:04:59 +0000 Message-ID: <20250911200508.79341-7-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250911200508.79341-1-ast@fiberby.net> References: <20250911200508.79341-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 Reviewed-by: Donald Hunter --- 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 7a2e49a84735..b3ce0901a19b 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -1828,7 +1828,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'} @@ -1921,6 +1924,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 @@ -2074,10 +2086,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 @@ -2346,6 +2355,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;'] @@ -2356,8 +2366,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 @@ -2376,11 +2385,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") @@ -2418,13 +2423,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"]) @@ -2446,11 +2451,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 19:28:28 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 6D06C272814; Thu, 11 Sep 2025 20:05:34 +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=1757621137; cv=none; b=UCbJUjWVRY+9UI/Uk3DfvSOsUKBexl3BpDz7zmuY92s9cfdmN2c847A4a84xv4fs44chYcu5zntpRd60SUFe3tfUXBakuPOJO3AA8+0w7u0ZTXTXfDuWvdvRVg44j4h0vnCa/ZWpgh2CxeFwgbGpReFoYXFFj1wVat7Fslrjz68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757621137; c=relaxed/simple; bh=lcInuRuB+vNuJa4fGRHJlvJD9iDvGJACqmazL3h49mo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MHvVTUvh4Rmkgv4YC7Kne2OuCSirs5E3mwIN9WMH36YS6Vx1zSNjrRhVzHg6RId/f9j4ZUnFsa3Vd9AB7+KSbqb6OSCCOiaU4mwTfza8ftr4jEekUQy1vx7xeqjAV/ySKPSJB7phcYhpU5lOMLMECRlRsnrhtv1NwyRm87ttSh4= 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=KTps+Ak3; 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="KTps+Ak3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757621127; bh=lcInuRuB+vNuJa4fGRHJlvJD9iDvGJACqmazL3h49mo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KTps+Ak3z9B88aI2xES6gW/itFyEksAj2Na5VSiHTFw496zhNGJYX75h/HwL4u6Yi zhLSI75/6qifk21s3i+vDBYCe44U3iVHaDscqq/tIuX9qV5swoIdgtib92Iw5zMl4Y G6MCd63pj4T84dTcJskwwpIRY5aGMYjBnlGaJSALslf1HWrO4EzJUd1gm1gw+40FXi 4SywbKNn86VDw6I8xRGLE4Qo0kfnrx084mFu4CIOk76S095+VqzlRNqTNbSvsKdsNj wInScr1wtH4WUzXGdl2GAmSVmKI0zeWMcLAFyfzRcY9RJZc/wtSIvUjFzjXu6RCK3J TH1xTKvzl/Ylw== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 2C1D460137; Thu, 11 Sep 2025 20:05:27 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 20275204CAF; Thu, 11 Sep 2025 20:05:21 +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 v3 07/13] tools: ynl-gen: avoid repetitive variables definitions Date: Thu, 11 Sep 2025 20:05:00 +0000 Message-ID: <20250911200508.79341-8-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250911200508.79341-1-ast@fiberby.net> References: <20250911200508.79341-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: Donald Hunter --- 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 b3ce0901a19b..d63b63ac0b8e 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -247,7 +247,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: @@ -255,10 +255,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))") @@ -2124,6 +2120,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 @@ -2141,6 +2138,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 19:28:28 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 8EB80273D7B; Thu, 11 Sep 2025 20:05:34 +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=1757621136; cv=none; b=lHABEVFm2Ppj+QOcIDeLJ1ymdKUqI1YiWaSdk/xptuUKrXnfYUbYrCwMvUVzgMnvXTBStnpRNZU+uJJoB/GqYFptQSHSF8EE8/iKJfAs54j1dJZnzb8a9R+/8qVeo3e+X/V1JnFxoTCrNCf5JAxu+qh3NxGYW0NwH2S5UGePgqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757621136; c=relaxed/simple; bh=C+VTgsHCYZdF8SYNjY6frnXzohQkWdBkQ4hBxELYtjs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BVLK6r0XSR1PMLb5LqeOd2pFjQsasPrRXHyEOBwut4tuU7L5TgaYp1p1y7cig7gajzAYw76wWaXxn6WqLLNLjw9+GieuXPCpuMl7yS4/es6WFxNQS0O70nWYD1+eUK8tshjRKpxd4AhnLODbz1GJ4kv9SpVgm2bpRqkTYAXT+EI= 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=X+AnvfYJ; 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="X+AnvfYJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757621127; bh=C+VTgsHCYZdF8SYNjY6frnXzohQkWdBkQ4hBxELYtjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X+AnvfYJoONEm+GMLbkvkrS9OCuzC2hCB28mkKDJGqcK6WHSxzfpImZoAu9Q1ix07 5T+pg8HT7j4sv1tbeqkyazcF087xWSAL1qkAa1aROiOTigbVzZuvr+/2jErnwsfqKx XEd0U4hgTMRNTfQfhHFsPB8oCS3IZtk82JlQ/ke96asU47fkTabpFgmYInKVt60qcv rBi8vVS1s+mE6Qy2BIoOKNU3ymh3JTZQZQcqIigQMjhxvLhYYmMRRRIq2yk6Xqmyeo tWGtT72vlxf/wdWtw67Q+AL/3k+eTZv+2UsWrERX8Fm0fMUnPvV4nWn3eC/OeT+1zu dSDVsQ/ro62tA== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 38E3B6013D; Thu, 11 Sep 2025 20:05:27 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 29F9F204EE2; Thu, 11 Sep 2025 20:05:21 +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 v3 08/13] tools: ynl-gen: only validate nested array payload Date: Thu, 11 Sep 2025 20:05:01 +0000 Message-ID: <20250911200508.79341-9-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250911200508.79341-1-ast@fiberby.net> References: <20250911200508.79341-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..0daf39229587 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) +static int __ynl_attr_validate(struct ynl_parse_arg *yarg, + const struct nlattr *attr, 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 d63b63ac0b8e..ab5b8d98cbda 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -831,7 +831,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 19:28:28 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 D7388274670; Thu, 11 Sep 2025 20:05:34 +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=1757621137; cv=none; b=LfjnC0Z7hYHEfA0to7hX0XbHoRQYSGaHQihwFnIwTmq+tKyscumQXsVzLQ8N1loNU5hqWC3EOmkW4cLJ3QHEEBVGKRBsJtjKyBSDPLuSmliOu/owRmRweupeWQaaYclJjywo7vCwSB5/S3uf26RIba0uCNw602CkB+9AModeIto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757621137; c=relaxed/simple; bh=JXLnIORMG1oj7UEnKhu1WJfE+dEgFaaB5hGxhVbbsrE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QLzEajtQjiyzQ15YyCP7ZlrNGaVJUP5EIkTjz/OoQMsJAh2quyA1QxpQFm979oMOll1UgYJFYRZ0hbJ++PLowEwKemC+yOCJJ5fdRyc9aVPrFvTMXj+x5bZyyx9NNJsZsP2ZHNLD3p8+H4GdoPb5fOdIt2YeKIfcIQZQ/F3UUnU= 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=PdXDTPxT; 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="PdXDTPxT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757621127; bh=JXLnIORMG1oj7UEnKhu1WJfE+dEgFaaB5hGxhVbbsrE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PdXDTPxTb7H0iDyGXYjYKodzCI9BzoHTM7tYLCslc+rSxuJTLB+NNZNPqQxu7kIl8 /6Yn/hLfwo+TpaRAn+i2y/vaDUYV1FYlZrX4+/rFERNO1Z7x/OCRMAz3nMUbfoxUoV iw3125jD4vwV47zBKTv0lcteGC/SAAaNCSyg09quXpJpGpzhAur6SVZAkwqKPLZs9D LKICsC8VtU4f/TxAJmQ6aOosTU3gfRUFngF0WJ2FK/avcVcVWjaEgDK/CPeMyvuOmr xZSTCeBulB5Cr4N6aQGfN3RHusiA35snv0yzNVtYQa3PJlRYflfioR+ch1l4YYlQO+ tqa5zC2Knn/HQ== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 4C69B6013F; Thu, 11 Sep 2025 20:05:27 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 33809204FB3; Thu, 11 Sep 2025 20:05:21 +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 v3 09/13] tools: ynl-gen: rename TypeArrayNest to TypeIndexedArray Date: Thu, 11 Sep 2025 20:05:02 +0000 Message-ID: <20250911200508.79341-10-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250911200508.79341-1-ast@fiberby.net> References: <20250911200508.79341-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 --- 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 ab5b8d98cbda..2c5787b518f0 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -788,7 +788,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 @@ -825,7 +825,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;'] @@ -855,7 +855,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): @@ -1132,7 +1132,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': @@ -2120,18 +2120,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: @@ -2145,16 +2145,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) @@ -2173,8 +2173,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 @@ -2192,8 +2192,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}));") @@ -2218,8 +2218,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 19:28:28 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 05A39274B2E; Thu, 11 Sep 2025 20:05:34 +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=1757621136; cv=none; b=AOteA0MsnujZkDUP46drCb0cEOq+8m1T4QvXb6apW0vh7NUOJ7JE+p1roP2S8haTyuQuFXecJ4PS/WxsZKTNLQuDPgEgivc1PuvphsV7awtDYEQU3evw5vvn844zEob780FnlVoQhK1tUyZIRZW6sFh6vs7hhkfFA8YMvNyEI2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757621136; c=relaxed/simple; bh=HqyIhwC1Ng9W9Rs+TyJnvWCNwSRIXH4apSsRMl21lQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DibYRyK0qxmL/JJJU8Bn/Ia4e4qXMOqwbWcvOmkerqvjErtNcN1Nt8LkpvTmWfTzRP+9x2O7E+qKJph15cQkttgGKUPfKGP4Qe7Rf8SFt+Sd4Rx/T0T78cR9GmEwuzyfyrVmW81fgD9b5CdbnALduhUEeKTXUDjj0MeK+sPkxYg= 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=R1eIAfT4; 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="R1eIAfT4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757621127; bh=HqyIhwC1Ng9W9Rs+TyJnvWCNwSRIXH4apSsRMl21lQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R1eIAfT4gNvjKWImBI6ECcJxub9SVJj0y/ul+m0dloFG4jGE7pLAGoMs8W5BVqbtH 1jUHdAgrQzNF2lQC68Yw252tvzRLU39DUkLDM1IiYjQtcXGlzCpVRVruAdMb2iAuR0 FvcD9iJrHOVBT4sxJBlF75uBe3hHxqDCStyJ7b3bYDNIS2eX/fcL2CTuwbGv6qL3Le AM8tCDqIu05g+eNFUAB61+xqgZr9jyBqUritWs8PALMwT4aYjEAzPeK5RBorzc+4kx /k59qfBf7un1ESRO6vBc24dOux4PQkyQ3r8OGQAn8HDr+FWBPEoWTb87iUFfh6bh+V AmfAeSCZN69vg== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 96B42601BA; Thu, 11 Sep 2025 20:05:27 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 3D2662051A8; Thu, 11 Sep 2025 20:05:21 +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 v3 10/13] tools: ynl: move nest packing to a helper function Date: Thu, 11 Sep 2025 20:05:03 +0000 Message-ID: <20250911200508.79341-11-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250911200508.79341-1-ast@fiberby.net> References: <20250911200508.79341-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 19:28:28 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 038B32DC784; Thu, 11 Sep 2025 20:05:30 +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=1757621132; cv=none; b=gclZt+G520TMf9LLH42zZDVAmg5ADcUqIoCZi8VxsNSakSAeuU71F+lHfgTryXxBTlE+RINguB53LYJRgWygOvaTz2avd3KkImCVEVhKRwNXxZhoM6MHBehPMXHWNukItpA936+Jz+PvDv0dlqnQrlsASFBTmzSJyyTYsgM/+u0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757621132; c=relaxed/simple; bh=cBJ8N3+usDyC0kts12vANVIdZbJUEHQHgUg3Ehv0XcY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t03y6KSiSQ3pqXV3WjOHsk5S6m4yPJWHO9IX4++mzIs2Ty3/bQfS8G2DgCnxRRuNV+gNGnL0fL3fBkPAOLDb6615w/SdnpZRdj2Tnhq0nSCi8Wqj9hRaPWSjadzXNerpYK/ZZw9Ybc9FLk1vQ1h4vO7NSMh3WObmmb4XLV+MAlA= 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=p954Zw0D; 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="p954Zw0D" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757621127; bh=cBJ8N3+usDyC0kts12vANVIdZbJUEHQHgUg3Ehv0XcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p954Zw0DXV1nCLEnrXMHUbaYWpXk6FPwoHeSN8IJ2aGGThLLjS0F79TIjgvs+v2Af siMe/sDs+zpTlU9xPE2sPnC+CflXGs3Tdg6YZ1Ae3rdEVIa1vc9/9WbDEjKW3bjNe5 WSPsVDnzMWtOlI1Ed5zDZQ8daypp79UcicpFhfqBod3m9KsrJm5xrE51/4uQ9+WOVu 5OCLFQwMx9kRh8COcEkVqdV3HvLWjdumVIdpqI6AtSyB6ML5KDZf0B8cgoCMCb8XKF lP77tJgd8+3iZcLyym/Z5wHSSGhwaceWgtmh2efqqRPxLEAB7kj3f0t0HnNYf6iDJF QJSAo9v+lD+gw== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 8DFED600C4; Thu, 11 Sep 2025 20:05:26 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 46FA62054AD; Thu, 11 Sep 2025 20:05:21 +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 v3 11/13] tools: ynl: encode indexed-arrays Date: Thu, 11 Sep 2025 20:05:04 +0000 Message-ID: <20250911200508.79341-12-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250911200508.79341-1-ast@fiberby.net> References: <20250911200508.79341-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 19:28:28 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 1A45D1E32B7; Thu, 11 Sep 2025 20:05:30 +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=1757621133; cv=none; b=BLekaBobpsK0AnRqbzuFrrHn3JkuckpZMG/gaUgtPTq4diDoQWSFfVPxE3Tv5LcGTimCxrMZtEmpAd8c8SpsBtX6DXifA2JixGlaPaBd9QkFyw0KRVlryGO8RrPXwmKUz/DQfYe6tvKno4UZ3BVh2R3VAzGKSoBCE+H6fKSbils= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757621133; c=relaxed/simple; bh=S0gMc72oPdc0g0sj6y+NzdUsQ1houqygFTU/3OS/3SU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YZrBhzT/vrnOrlZJfE4RhUKsU5F5d+7glJyN420/u1GhI8RNXotqFdnDfGNrmLlaMx/ZxzmwTIkrgiJFS39zCVJkMV/a8P/TV/2uCWx259rrgxfxBuZcM+mLGJg7EUo1RwoEZIS6Hf8v/svNgCibS8AVFLq6pmLDKK7aHfRFEx0= 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=frqESVFN; 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="frqESVFN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757621127; bh=S0gMc72oPdc0g0sj6y+NzdUsQ1houqygFTU/3OS/3SU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=frqESVFNCJwluZln0HPUxGZ80dbNhFim/N+up5JtWOkk+G2eOjy6rzkB7wavmOv9x NB3jBmKxS2T3kQdE7hOCSZUfkZ60p8EuFmLmlsv9BLj1siRUgQ5+dhuXhzF0Weldhl pRxvmvUcU6ZrcO6g86acDlCP6pA+y9rverAgrjAoGz9DtvaW6eUGnBdOiilXu5Q91G PVeJJNa8Q0YqPlG/hyNL3HLUID5A670hyEcP8KGfl/jeHIPEU0ZCi8FYVk7pQFPEE8 xnWKniptFyLUx+iBS+iek8mEXWeppqXLMT723Usqvr/41PJnGcXlghIzEt+g+M3Q56 6zEBzN3lBgk5A== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 32D7C6013B; Thu, 11 Sep 2025 20:05:27 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 4FAD22054BC; Thu, 11 Sep 2025 20:05:21 +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 v3 12/13] tools: ynl: decode hex input Date: Thu, 11 Sep 2025 20:05:05 +0000 Message-ID: <20250911200508.79341-13-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250911200508.79341-1-ast@fiberby.net> References: <20250911200508.79341-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 19:28:28 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 E75B927602A; Thu, 11 Sep 2025 20:05:35 +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=1757621137; cv=none; b=ZQRVSOn2tkHB48hm8QQMTmIYr8AeY/7y9GZnURN6tjIzTdz53/LYvV4tPvN555R8FqcxnhHr0ngR3fD2yM23QPWYaky6mruJU8wYVBnLrT4gh+6Eg38CpG3MHUYk2jvgrH0cBdhTP2kyC3RBO5S53+Bh1GDgSfx8+QBLBmykl3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757621137; c=relaxed/simple; bh=M8RZw0PcAr23td7B4SWZsTm8GfTk/HQcBuK2/+z1TOk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jHTrDvhxQrmnn/ZtoeW91vu2eGQ/t4ouQHF1dBqmw7DRYbj8t+iukIFI0Ykj0kQ5yB2Rw3xYeGDMDtPOLLhht1OIhsKtFPo0N8hSh3tUtYiOm3aL9R+SGqTfVyMklgr/WgEDE7x20AKgolk+QlnVojRjOcWqqKsOs0wpG/dgQac= 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=Ckqf8y3/; 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="Ckqf8y3/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757621127; bh=M8RZw0PcAr23td7B4SWZsTm8GfTk/HQcBuK2/+z1TOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ckqf8y3/AzjVvxnZC2k9ly4RI51ZQ712aXjBCfSJ1VWDwgQ6rwgd/eYNnJFOKinFf 4kzX0y7z5ebvlRob3JLsiSN4EB9s/YIYoa7rAcH8yZtYxpZ7W2EZbcsyBR7kHR5ar4 R01PXD+xvbgd0pAhIIPCSTPk0vZMchw95XuL9HUU9lXYJtSy9aOxrzFIt0i4I5EB6g i+vM068jPRcJbP1Q8XaYbNY43x7LFUxC85WmJixa7oLMvnbvIeYMz8uWZA01Lf5ey3 mGMC69ouOTPYidd/N/e2G0KOK0gsjHZ3ZAGo63kyNjaCM0u9m/F6OOaQ0QvKGoyQfP 89APPZycwQAFw== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 96AED601B9; Thu, 11 Sep 2025 20:05:27 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 5964120573E; Thu, 11 Sep 2025 20:05:21 +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 v3 13/13] tools: ynl: add ipv4-or-v6 display hint Date: Thu, 11 Sep 2025 20:05:06 +0000 Message-ID: <20250911200508.79341-14-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250911200508.79341-1-ast@fiberby.net> References: <20250911200508.79341-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