From patchwork Sun Mar 19 19:37:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13180558 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78E86C6FD1F for ; Sun, 19 Mar 2023 19:38:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229776AbjCSTig (ORCPT ); Sun, 19 Mar 2023 15:38:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjCSTi3 (ORCPT ); Sun, 19 Mar 2023 15:38:29 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FA8C6EAC for ; Sun, 19 Mar 2023 12:38:27 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id j2so8532893wrh.9 for ; Sun, 19 Mar 2023 12:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679254705; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6BVGpxdql44gS2WLVUDyHPvm/nXsusxFRbvvN5WJp24=; b=nBhfBInPHRzumJEwoI9z6FlkzLx7ojKaS6YSMUC1C0uls3m8sXVEGzeYzQem+jMKFi XsW1uQL2nX2WaszqslwnTFkuOzYDUbemz6tJKbqpacZl1OIXH4NZY5bsFTIc+//ENxLk UJr2tcLOsyItu+N9sM7KPJweKo/DkNcB+XDXAAWqy8L03ZCCDeIMarAhcoME4OGW+G23 +KL8LPNcCGQiPDr77LbZmzkvO8DmOpQ1yGl5UsufhTvusJahbeZJj03wmheXChLJ7Sm+ 0ksdgXrV0nYJxVzHYZoJqQVeJbpv9frASq58pSkvobqHnvD8cvGTPJef2yoYlwvquUie 7O+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679254705; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6BVGpxdql44gS2WLVUDyHPvm/nXsusxFRbvvN5WJp24=; b=j4GFpGW0QI1EfZVvtlpT2xGVBp6fbxE+hRZDszX2xlJ2NM0hhdWxnaj5P+UZQQ/H67 nO+3GVuYqZv615x3493Hdp3ya4tJzYFnzHQaAQL2al0uOURy65w26m2adTIczsgbTAo8 YsPK7rGNsJN8R5uuptCI97b7rx9CK88TG1aMT6b7kMsJaU3+gMJussfl4z7XAWJn2oxR ucSLWnaL7tXXwTIIt4GtDUp1WfQTbm2I7Y0FjjZoiaRYopOx9W+QD9p1b90stIGuNk24 +kiBbpBneXCZRX3hIh4nzqqzp55SU9uHjUiJQm9W2Bm1TOuCUf1ANazlqBCQ35Nb5iho Avug== X-Gm-Message-State: AO0yUKU+CnX8/V/ALVwk6hdbInoRsevwu6dcP/EnTS7PWzQkIQviD7j7 TQKEG4KtZTBWIPafhzA7j/EfVhyJntsPog== X-Google-Smtp-Source: AK7set/xnWbPh6l14D97o8P6vUpCG8nEzFGgtS/Bq2+IkEKoJYXYJspf0lLQZGjXbA7XVkeQ52LJzw== X-Received: by 2002:adf:fc52:0:b0:2cf:ed48:2ea7 with SMTP id e18-20020adffc52000000b002cfed482ea7mr11066479wrs.4.1679254705295; Sun, 19 Mar 2023 12:38:25 -0700 (PDT) Received: from imac.redhat.com ([88.97.103.74]) by smtp.gmail.com with ESMTPSA id d5-20020adfef85000000b002cfed482e9asm7204190wro.61.2023.03.19.12.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 12:38:24 -0700 (PDT) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v2 1/6] tools: ynl: Fix genlmsg header encoding formats Date: Sun, 19 Mar 2023 19:37:58 +0000 Message-Id: <20230319193803.97453-2-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230319193803.97453-1-donald.hunter@gmail.com> References: <20230319193803.97453-1-donald.hunter@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The pack strings use 'b' signed char for cmd and version but struct genlmsghdr defines them as unsigned char. Use 'B' instead. Fixes: 4e4480e89c47 ("tools: ynl: move the cli and netlink code around") Signed-off-by: Donald Hunter --- tools/net/ynl/lib/ynl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 90764a83c646..32536e1f9064 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -200,7 +200,7 @@ def _genl_msg(nl_type, nl_flags, genl_cmd, genl_version, seq=None): if seq is None: seq = random.randint(1, 1024) nlmsg = struct.pack("HHII", nl_type, nl_flags, seq, 0) - genlmsg = struct.pack("bbH", genl_cmd, genl_version, 0) + genlmsg = struct.pack("BBH", genl_cmd, genl_version, 0) return nlmsg + genlmsg @@ -264,7 +264,7 @@ class GenlMsg: self.hdr = nl_msg.raw[0:4] self.raw = nl_msg.raw[4:] - self.genl_cmd, self.genl_version, _ = struct.unpack("bbH", self.hdr) + self.genl_cmd, self.genl_version, _ = struct.unpack("BBH", self.hdr) self.raw_attrs = NlAttrs(self.raw) @@ -358,7 +358,7 @@ class YnlFamily(SpecFamily): raw >>= 1 i += 1 else: - value = enum['entries'][raw - i] + value = enum.entries_by_val[raw - i].name rsp[attr_spec['name']] = value def _decode(self, attrs, space): From patchwork Sun Mar 19 19:37:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13180559 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 532D0C76195 for ; Sun, 19 Mar 2023 19:38:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229622AbjCSTih (ORCPT ); Sun, 19 Mar 2023 15:38:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229700AbjCSTi3 (ORCPT ); Sun, 19 Mar 2023 15:38:29 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D6FC7ABA for ; Sun, 19 Mar 2023 12:38:28 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id d17so114959wrb.11 for ; Sun, 19 Mar 2023 12:38:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679254706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MGoMP5Ydt29FPyCV4lBeSQAeOKjlwuxeDmPc4dpRBBA=; b=VGW60GsonB3Hpvq7tgxzfjNk0zeymJKQxMuZ0BtFD7XSO6pKp9lKwtwqpm71grA3IR Wis1dRYjz8N0cIvIgWr5u7L81tSgtIgTmHaoY6wN7nUM5W1CwaHUaUUmHydFF/9Z+DwV L2PH/u86/cwasJg7CHx/p9c97Ah+rV1Ddt6OjkKp7F9uuL0yNvFdB0MaGIPvOIylddfv ZzWVd9P4c6Gq1RkzobGM+6BTZP3SoQBmlNjmh/nRSqDciRVFtqFK7cOcTeR5OYV1x0L8 KvBJDuDOevJfEMSxw32PayCHalKu89pCdOuEIzUOuIBQvfGr6ju9ekNafG/Mto1G9Mcj tnRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679254706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MGoMP5Ydt29FPyCV4lBeSQAeOKjlwuxeDmPc4dpRBBA=; b=f//iAkAtOUqP/uZyZMm6HrfR6A7E8F3PKBNfZ2LFM55K2MAD2JpKUEq4FaEX+lin5t KlRVXXz22FuALdY4UrbWrahK5xCol5dPhKmcYmejvGG7EtGSDp8EJ01T0/FIct3Sl1su uoIJKtDbQDKjPWe7+WDBm+FDcmbaAkP4mzP4zVwTY8p91jtHACZblbGtgeUBPW1UCAuQ szJiNAt0oUVyQmkkr94RMhLX245lFj+txS0uYrk9RhlLP773O068ehLC6HS/WWNj4FH7 R+zVzw+WLhnw4i57LWosh3P3//CqvBeMlPdYzOo9HPxVvdg0aQvHVIzVM+c17ZUUhsd6 TT3A== X-Gm-Message-State: AO0yUKX+Q1Gfzx86BfdbDfU801NjrW/HlZyMVNV6WwUuYalr/KvfjZm9 jLYunkpMNV5/JuUZRy3qf7Vnl1cr6j9wZA== X-Google-Smtp-Source: AK7set/jd3yfVnDgfkm+kxGZmR2hKhTsoXryJVmGH83HlhVRurwcF/IkGjNkSh+YvCZGRdwB0xO2VQ== X-Received: by 2002:a5d:5142:0:b0:2d1:53f5:900c with SMTP id u2-20020a5d5142000000b002d153f5900cmr7747300wrt.20.1679254706379; Sun, 19 Mar 2023 12:38:26 -0700 (PDT) Received: from imac.redhat.com ([88.97.103.74]) by smtp.gmail.com with ESMTPSA id d5-20020adfef85000000b002cfed482e9asm7204190wro.61.2023.03.19.12.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 12:38:25 -0700 (PDT) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v2 2/6] tools: ynl: Add struct parsing to nlspec Date: Sun, 19 Mar 2023 19:37:59 +0000 Message-Id: <20230319193803.97453-3-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230319193803.97453-1-donald.hunter@gmail.com> References: <20230319193803.97453-1-donald.hunter@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add python classes for struct definitions to nlspec Signed-off-by: Donald Hunter --- tools/net/ynl/lib/nlspec.py | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py index d04450c2a44a..5ac2dfd415c5 100644 --- a/tools/net/ynl/lib/nlspec.py +++ b/tools/net/ynl/lib/nlspec.py @@ -214,6 +214,43 @@ class SpecAttrSet(SpecElement): return self.attrs.items() +class SpecStructMember(SpecElement): + """Struct member attribute + + Represents a single struct member attribute. + + Attributes: + type string, kernel type of the member attribute + """ + def __init__(self, family, yaml): + super().__init__(family, yaml) + self.type = yaml['type'] + +class SpecStruct(SpecElement): + """Netlink struct type + + Represents a C struct definition. + + Attributes: + members ordered list of struct members + """ + def __init__(self, family, yaml): + super().__init__(family, yaml) + + self.members = [] + for member in yaml.get('members', []): + self.members.append(self.new_member(family, member)) + + def new_member(self, family, elem): + return SpecStructMember(family, elem) + + def __iter__(self): + yield from self.members + + def items(self): + return self.members.items() + + class SpecOperation(SpecElement): """Netlink Operation @@ -344,6 +381,9 @@ class SpecFamily(SpecElement): def new_attr_set(self, elem): return SpecAttrSet(self, elem) + def new_struct(self, elem): + return SpecStruct(self, elem) + def new_operation(self, elem, req_val, rsp_val): return SpecOperation(self, elem, req_val, rsp_val) @@ -399,6 +439,8 @@ class SpecFamily(SpecElement): for elem in definitions: if elem['type'] == 'enum' or elem['type'] == 'flags': self.consts[elem['name']] = self.new_enum(elem) + elif elem['type'] == 'struct': + self.consts[elem['name']] = self.new_struct(elem) else: self.consts[elem['name']] = elem From patchwork Sun Mar 19 19:38:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13180560 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3F6CC7618A for ; Sun, 19 Mar 2023 19:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229779AbjCSTij (ORCPT ); Sun, 19 Mar 2023 15:38:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbjCSTia (ORCPT ); Sun, 19 Mar 2023 15:38:30 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76526BDCD for ; Sun, 19 Mar 2023 12:38:29 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id v1so2441392wrv.1 for ; Sun, 19 Mar 2023 12:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679254707; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oPkE8wIr05geZ5cnisxHcZNbN3HQvV0w+URKtwTfy6g=; b=BD4qm3I0VHFpJvJ8tL+T0bO6RXyD5xg4cifcIEEHF1083Ibk/y1QCK7i8arT7DvHIP njXE/8BfAvFE3O3Rf4D0nLMp2vNZkzV7pW/Ns30CZE6jFOk5lU4Q3tjU0UEay29+GLrG xLKH7tggKcZq/FADIkhVvaQKc+0W2sCeHEsKuMKjk0R2hfL4fFvuTa5mp6mhbEjn8JYO MpxWqPllx9d1egomgLwYUHaoOY3lpbgZ4tL7Y9dBv9YNwUEZ5DPqi1iW08zIzxKnjYCk aOFgcSk+DtnwgnsjcvVoG5tgoz4i4vQRb5bYWUsDkepdcm/2+RPuzKwdDMaIV/zQcPPa bPyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679254707; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oPkE8wIr05geZ5cnisxHcZNbN3HQvV0w+URKtwTfy6g=; b=fxo29xpA/1WZW/KzLQ5Ytc+YWPoF4zoJSahp1JZKdkGv/oVe3pOmi9sPPOw/Xx1cHF rjhOSLz7+pmfXvRrLvUAjTGt/EXv4PhBHTAJTCzMAhdxFnl0ycF5Pb/qoWxkLMCn9DNR z0NWCPHJj9Qd9sMGyfiG13foJI6lLTskBj7oLZoVDLc+3syEP+auz47Th2Wxv+m+IJ4b WhH390vYyXKUA0FHF6z74nr3lJY8TIA4uDtro4Vzgz5XVHwsobec31wYsmQbNvaaeL6j ogxe8PookJzy35xGEUCeJ3/lUe1BciLf/8JbqML7AqgIvd8vi5jTk0l7v0SRB/+vmm04 rvHQ== X-Gm-Message-State: AO0yUKW5uZ/YCBcSohfaeRqFf0si2S+OWUwHMMRHAdffm7ddv31MtXyz gWvaTjUqJr+wmIXi2PYwRUYxxyjw9wC2og== X-Google-Smtp-Source: AK7set9tFJu4aOII/oC+qsB8eyf3addFyRA5Xoe4x75yhlqSh8sC0/uEEuTkV8WCIoS+KbVA247zTA== X-Received: by 2002:a5d:6848:0:b0:2cf:e496:93d9 with SMTP id o8-20020a5d6848000000b002cfe49693d9mr11393421wrw.52.1679254707454; Sun, 19 Mar 2023 12:38:27 -0700 (PDT) Received: from imac.redhat.com ([88.97.103.74]) by smtp.gmail.com with ESMTPSA id d5-20020adfef85000000b002cfed482e9asm7204190wro.61.2023.03.19.12.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 12:38:26 -0700 (PDT) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v2 3/6] tools: ynl: Add array-nest attr decoding to ynl Date: Sun, 19 Mar 2023 19:38:00 +0000 Message-Id: <20230319193803.97453-4-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230319193803.97453-1-donald.hunter@gmail.com> References: <20230319193803.97453-1-donald.hunter@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add support for decoding nested arrays of scalars in netlink messages. Signed-off-by: Donald Hunter --- tools/net/ynl/lib/ynl.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 32536e1f9064..077ba9e8dc98 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -93,6 +93,10 @@ class NlAttr: def as_bin(self): return self.raw + def as_array(self, type): + format, _ = self.type_formats[type] + return list({ x[0] for x in struct.iter_unpack(format, self.raw) }) + def __repr__(self): return f"[type:{self.type} len:{self._len}] {self.raw}" @@ -381,6 +385,8 @@ class YnlFamily(SpecFamily): decoded = attr.as_bin() elif attr_spec["type"] == 'flag': decoded = True + elif attr_spec["type"] == 'array-nest': + decoded = attr.as_array(attr_spec["sub-type"]) else: raise Exception(f'Unknown {attr.type} {attr_spec["name"]} {attr_spec["type"]}') From patchwork Sun Mar 19 19:38:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13180561 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43344C7618A for ; Sun, 19 Mar 2023 19:38:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229805AbjCSTik (ORCPT ); Sun, 19 Mar 2023 15:38:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229754AbjCSTib (ORCPT ); Sun, 19 Mar 2023 15:38:31 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D17BD306 for ; Sun, 19 Mar 2023 12:38:30 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id o7so8552442wrg.5 for ; Sun, 19 Mar 2023 12:38:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679254708; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=458WZKE7Wv1WdZP9AIvsjyYap+pFspsLQh0MCtVsk8M=; b=aGaJiGtkVy9LIA24cvbq5itc/SasiUSWRaVLBIyIZ5zikZQI8CU1Vsi4d4Fck+/oQE YRcCEl2JQ81Z1YlAHlRxYeQDzKHy541XrfolkVFGQXNff3dT2+R/3ONmH6uFj6dv2Mpm wlES+WsY12BuE5z4XZsBUnBLwfZGBV4caVS/gCYoXxikMtEJf0VYPJzMqaDgwni9I48h TWR5YKp3X5u8h+nj41SFekdMXPCzT3J6FWRI0cxnD+k7xb1KSCS6gIseoJLLA2dWV7Cj 4Tzfa5M9oNn28OCOWsNGurtCJ2MaT7bsWZ02eIGOyG3GyIDBMp+0UzQoYaz8gsLX5J8e IJsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679254708; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=458WZKE7Wv1WdZP9AIvsjyYap+pFspsLQh0MCtVsk8M=; b=MKUHXTMS7RNJTnbk4i7hHrRH3/QTR+JAKDVw55LnIblAwrK7ny4VUc/ve9D/suYYfe uI5i05SlKfDNq3jqtJ8M5ZzcmzxkuNp8qKHo5G7SIWRGdMx5tSekL1i4BM7oihM7TW8c DcpAdu4wLnindpCQ0zp/dX/Dg3commUYX1rJxvZpdU63+l/1zx1jMN1cBW1Jcq86PbMq i4DRSGNUg0ADwD4yhOV8nRKg0xVh6KMZ/vDIWw7KRnASfdJGf1mc9f+sirBcXYGZSaqa K/sHg9Jhi8WZEq9fMuCHmAE7NxPsQ6yAfHj4mLpcLyrFLgllhpY9uM3POP4SP9uqKSN3 m2RQ== X-Gm-Message-State: AO0yUKW9fuSMWPihsEM6YefOle4rAkCkl2rPgMN1WcpM4FJDtCFFyKRF PDog0z0U0arMTKODQ9a+LB1GiMqRrZ0Vqg== X-Google-Smtp-Source: AK7set/i+CtBcnibwTgiRHt91Lk15RGls96Bns45sg/kdQXZq3y19bof1WuIyMgyTGxZbmNKICLipg== X-Received: by 2002:adf:eb0e:0:b0:2d7:1ec1:9e46 with SMTP id s14-20020adfeb0e000000b002d71ec19e46mr572703wrn.47.1679254708467; Sun, 19 Mar 2023 12:38:28 -0700 (PDT) Received: from imac.redhat.com ([88.97.103.74]) by smtp.gmail.com with ESMTPSA id d5-20020adfef85000000b002cfed482e9asm7204190wro.61.2023.03.19.12.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 12:38:27 -0700 (PDT) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v2 4/6] tools: ynl: Add struct attr decoding to ynl Date: Sun, 19 Mar 2023 19:38:01 +0000 Message-Id: <20230319193803.97453-5-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230319193803.97453-1-donald.hunter@gmail.com> References: <20230319193803.97453-1-donald.hunter@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add support for decoding attributes that contain C structs. Signed-off-by: Donald Hunter --- Documentation/netlink/genetlink-legacy.yaml | 7 ++++++- tools/net/ynl/lib/ynl.py | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml index 5dc6f1c07a97..654f40b26beb 100644 --- a/Documentation/netlink/genetlink-legacy.yaml +++ b/Documentation/netlink/genetlink-legacy.yaml @@ -172,7 +172,7 @@ properties: type: string type: &attr-type enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64, - string, nest, array-nest, nest-type-value ] + string, nest, array-nest, nest-type-value, struct ] doc: description: Documentation of the attribute. type: string @@ -218,6 +218,11 @@ properties: description: Max length for a string or a binary attribute. $ref: '#/$defs/len-or-define' sub-type: *attr-type + # Start genetlink-legacy + struct: + description: Name of the struct type used for the attribute. + type: string + # End genetlink-legacy # Make sure name-prefix does not appear in subsets (subsets inherit naming) dependencies: diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 077ba9e8dc98..24f8af3c2b38 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -68,6 +68,11 @@ class Netlink: class NlAttr: + type_formats = { 'u8' : ('B', 1), + 'u16': ('H', 2), + 'u32': ('I', 4), + 'u64': ('Q', 8) } + def __init__(self, raw, offset): self._len, self._type = struct.unpack("HH", raw[offset:offset + 4]) self.type = self._type & ~Netlink.NLA_TYPE_MASK @@ -97,6 +102,16 @@ class NlAttr: format, _ = self.type_formats[type] return list({ x[0] for x in struct.iter_unpack(format, self.raw) }) + def as_struct(self, members): + value = dict() + offset = 0 + for m in members: + format, size = self.type_formats[m.type] + decoded = struct.unpack_from(format, self.raw, offset) + offset += size + value[m.name] = decoded[0] + return value + def __repr__(self): return f"[type:{self.type} len:{self._len}] {self.raw}" @@ -385,6 +400,9 @@ class YnlFamily(SpecFamily): decoded = attr.as_bin() elif attr_spec["type"] == 'flag': decoded = True + elif attr_spec["type"] == 'struct': + s = attr_spec['struct'] + decoded = attr.as_struct(self.consts[s]) elif attr_spec["type"] == 'array-nest': decoded = attr.as_array(attr_spec["sub-type"]) else: From patchwork Sun Mar 19 19:38:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13180563 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47F45C76195 for ; Sun, 19 Mar 2023 19:38:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229795AbjCSTip (ORCPT ); Sun, 19 Mar 2023 15:38:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbjCSTif (ORCPT ); Sun, 19 Mar 2023 15:38:35 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F9FD7DA9 for ; Sun, 19 Mar 2023 12:38:31 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id l27so224374wrb.2 for ; Sun, 19 Mar 2023 12:38:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679254709; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z5iBtY8KDPyw7Vjzd2GhmY5pBsVMT2mvsTw3P8c+LMM=; b=mI4wf8jmRoFDyhkf8cXxGsR8fdIjH8vldcCNH7ZvrGzFCqw273wdRlG273IkSoW4sX yO1MiLksWwjCFjMNS13HA3800m96du9dKaPiqVQqpkxjPWEFf9a76NOk9wM8R3SZzNNQ 1UkP76CuX3iHw2eEjY7amME56E8JESKFZc/PQrHbx++jbPVVE5AVeVKIIGt4lrFeQPFr m1L+bfQ11jWix8UySl4WVnlrdQvuB+aVw0w9HCicXyh8jadeAG6Z2JzIwJLB7PH4qHkA pA54AIPNsqD3ahRhFNQYEuz86S5L8of4Q0aP/woLOYnNrNEe+kQ75niqrcxJNXk0E+Km wXhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679254709; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z5iBtY8KDPyw7Vjzd2GhmY5pBsVMT2mvsTw3P8c+LMM=; b=Qtuo6dJmYU3aJq721ZzzJGShzuRCB/GqJ7kvTx1672ql+ZisMfOXwTT06LpoD0Il+z w6Trbghd0ZxJ5ef3aKTne7GvyUkVgHkAfitI38PdiUiDyql826qbgnljlwJhekHHmXE5 kRmIAB9fID/oXJAScnAM0xISiyNTk3AV5soNSUvRO/bHtIf9GTfVYsFxdgGZt0KbGV+Z HpoqH44pRasNq/TO0SaS/kUXOk7tWVjcIOu77l0BUYNAVaF0sF483tS64lAehpxSIyR7 6MC/9CZmZHwN8LqqDLvaiVBEDTfo7NVWDg2SyFiJ/K5xuJjcp7ODVUplLY1i4oonGH6p Aqsg== X-Gm-Message-State: AO0yUKWup+qHUp+SlWxBoTQYJ9Rqzb5t3A+zOug9Z4O25Sw8VJA9olsj o8hBLBJtB2pucczmP4dlqDZd+CFwDCbczg== X-Google-Smtp-Source: AK7set/JVq4y1ylySMw/Y6xMK26KaeiL2ifRt/2yJz5P57Rw8pmtz4dQztBUxnskKWkCtJL6cNhRKw== X-Received: by 2002:adf:ffc5:0:b0:2ce:a8ee:173a with SMTP id x5-20020adfffc5000000b002cea8ee173amr12139886wrs.68.1679254709444; Sun, 19 Mar 2023 12:38:29 -0700 (PDT) Received: from imac.redhat.com ([88.97.103.74]) by smtp.gmail.com with ESMTPSA id d5-20020adfef85000000b002cfed482e9asm7204190wro.61.2023.03.19.12.38.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 12:38:28 -0700 (PDT) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v2 5/6] tools: ynl: Add fixed-header support to ynl Date: Sun, 19 Mar 2023 19:38:02 +0000 Message-Id: <20230319193803.97453-6-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230319193803.97453-1-donald.hunter@gmail.com> References: <20230319193803.97453-1-donald.hunter@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add support for netlink families that add an optional fixed header structure after the genetlink header and before any attributes. The fixed-header can be specified on a per op basis, or once for all operations. Signed-off-by: Donald Hunter --- Documentation/netlink/genetlink-legacy.yaml | 10 +++++++ tools/net/ynl/lib/nlspec.py | 30 ++++++++++++--------- tools/net/ynl/lib/ynl.py | 23 +++++++++++++--- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml index 654f40b26beb..30a8051c1d8f 100644 --- a/Documentation/netlink/genetlink-legacy.yaml +++ b/Documentation/netlink/genetlink-legacy.yaml @@ -261,6 +261,13 @@ properties: async-enum: description: Name for the enum type with notifications/events. type: string + # Start genetlink-legacy + fixed-header: &fixed-header + description: | + Name of the structure defininig the optional fixed-length protocol header. This header is + placed in a message after the netlink and genetlink headers and before any attributes. + type: string + # End genetlink-legacy list: description: List of commands type: array @@ -293,6 +300,9 @@ properties: type: array items: enum: [ strict, dump ] + # Start genetlink-legacy + fixed-header: *fixed-header + # End genetlink-legacy do: &subop-type description: Main command handler. type: object diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py index 5ac2dfd415c5..69ee9f940e0e 100644 --- a/tools/net/ynl/lib/nlspec.py +++ b/tools/net/ynl/lib/nlspec.py @@ -257,18 +257,19 @@ class SpecOperation(SpecElement): Information about a single Netlink operation. Attributes: - value numerical ID when serialized, None if req/rsp values differ + value numerical ID when serialized, None if req/rsp values differ - req_value numerical ID when serialized, user -> kernel - rsp_value numerical ID when serialized, user <- kernel - is_call bool, whether the operation is a call - is_async bool, whether the operation is a notification - is_resv bool, whether the operation does not exist (it's just a reserved ID) - attr_set attribute set name + req_value numerical ID when serialized, user -> kernel + rsp_value numerical ID when serialized, user <- kernel + is_call bool, whether the operation is a call + is_async bool, whether the operation is a notification + is_resv bool, whether the operation does not exist (it's just a reserved ID) + attr_set attribute set name + fixed_header string, optional fixed header structure name - yaml raw spec as loaded from the spec file + yaml raw spec as loaded from the spec file """ - def __init__(self, family, yaml, req_value, rsp_value): + def __init__(self, family, yaml, req_value, rsp_value, default_fixed_header): super().__init__(family, yaml) self.value = req_value if req_value == rsp_value else None @@ -278,6 +279,7 @@ class SpecOperation(SpecElement): self.is_call = 'do' in yaml or 'dump' in yaml self.is_async = 'notify' in yaml or 'event' in yaml self.is_resv = not self.is_async and not self.is_call + self.fixed_header = self.yaml.get('fixed-header', default_fixed_header) # Added by resolve: self.attr_set = None @@ -384,24 +386,26 @@ class SpecFamily(SpecElement): def new_struct(self, elem): return SpecStruct(self, elem) - def new_operation(self, elem, req_val, rsp_val): - return SpecOperation(self, elem, req_val, rsp_val) + def new_operation(self, elem, req_val, rsp_val, default_fixed_header): + return SpecOperation(self, elem, req_val, rsp_val, default_fixed_header) def add_unresolved(self, elem): self._resolution_list.append(elem) def _dictify_ops_unified(self): + default_fixed_header = self.yaml['operations'].get('fixed-header') val = 1 for elem in self.yaml['operations']['list']: if 'value' in elem: val = elem['value'] - op = self.new_operation(elem, val, val) + op = self.new_operation(elem, val, val, default_fixed_header) val += 1 self.msgs[op.name] = op def _dictify_ops_directional(self): + default_fixed_header = self.yaml['operations'].get('fixed-header') req_val = rsp_val = 1 for elem in self.yaml['operations']['list']: if 'notify' in elem: @@ -426,7 +430,7 @@ class SpecFamily(SpecElement): else: raise Exception("Can't parse directional ops") - op = self.new_operation(elem, req_val, rsp_val) + op = self.new_operation(elem, req_val, rsp_val, default_fixed_header) req_val = req_val_next rsp_val = rsp_val_next diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 24f8af3c2b38..736a637ecb2b 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -277,14 +277,22 @@ def _genl_load_families(): class GenlMsg: - def __init__(self, nl_msg): + def __init__(self, nl_msg, fixed_header_members = []): self.nl = nl_msg self.hdr = nl_msg.raw[0:4] - self.raw = nl_msg.raw[4:] + offset = 4 self.genl_cmd, self.genl_version, _ = struct.unpack("BBH", self.hdr) + self.fixed_header_attrs = dict() + for m in fixed_header_members: + format, size = NlAttr.type_formats[m.type] + decoded = struct.unpack_from(format, nl_msg.raw, offset) + offset += size + self.fixed_header_attrs[m.name] = decoded[0] + + self.raw = nl_msg.raw[offset:] self.raw_attrs = NlAttrs(self.raw) def __repr__(self): @@ -496,6 +504,13 @@ class YnlFamily(SpecFamily): req_seq = random.randint(1024, 65535) msg = _genl_msg(self.family.family_id, nl_flags, op.req_value, 1, req_seq) + fixed_header_members = [] + if op.fixed_header: + fixed_header_members = self.consts[op.fixed_header].members + for m in fixed_header_members: + value = vals.pop(m.name) + format, _ = NlAttr.type_formats[m.type] + msg += struct.pack(format, value) for name, value in vals.items(): msg += self._add_attr(op.attr_set.name, name, value) msg = _genl_msg_finalize(msg) @@ -522,7 +537,7 @@ class YnlFamily(SpecFamily): done = True break - gm = GenlMsg(nl_msg) + gm = GenlMsg(nl_msg, fixed_header_members) # Check if this is a reply to our request if nl_msg.nl_seq != req_seq or gm.genl_cmd != op.rsp_value: if gm.genl_cmd in self.async_msg_ids: @@ -532,7 +547,7 @@ class YnlFamily(SpecFamily): print('Unexpected message: ' + repr(gm)) continue - rsp.append(self._decode(gm.raw_attrs, op.attr_set.name)) + rsp.append(self._decode(gm.raw_attrs, op.attr_set.name) | gm.fixed_header_attrs) if not rsp: return None From patchwork Sun Mar 19 19:38:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13180562 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8947EC6FD1F for ; Sun, 19 Mar 2023 19:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229700AbjCSTin (ORCPT ); Sun, 19 Mar 2023 15:38:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbjCSTif (ORCPT ); Sun, 19 Mar 2023 15:38:35 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E896C4223 for ; Sun, 19 Mar 2023 12:38:32 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id l27so224404wrb.2 for ; Sun, 19 Mar 2023 12:38:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679254710; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3ygo9cP42ENNj3ilA9aApLzpVUDVAgd/awYBFmOYHlo=; b=EYGQFcREkgSEeSA/WEFcMHanCqlK34lcrtlxo7lOqZzZnj97xB+xXZjWBCbIqOqmG0 SDtuQq1dNqVpJ/m9MsmhYBFEQfLXBQHwyd2hJp30nd8/VXmckrw8+05loqcG7b1yeZC9 uWgkubRmhyMAJ5CxO0nJkh3QjKl+E61wLtDUoaadn2+MPd4IY4csfK4BvCx2qchXgcEI F3tv3U1zppF0c60dZBoAXKU3RUjjKeiLMczWlGfANe6arvlsnb+XAU9zGY/J8LzZhjTY nAUI1Nu90bo8F8HAKW6Q7nDW9dIdzuwkUQSKRyji+JbJkWbSHASLIsUlhb3OYG/7xRY7 njjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679254710; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3ygo9cP42ENNj3ilA9aApLzpVUDVAgd/awYBFmOYHlo=; b=gbKmPdzucixDNXzxvnMxQ+XdsrHlQdG32xj0Cf4Za5i8WxG4Zd2WKyjQ1AdciVd088 gA1JIOPufy3V+w4oJQEHaSBIAkZXUS78EZllTB3rGGiEMMPwZZObcWiarelGj4Fs4FQ8 k8jS2IVk0ZCdJNrQ7TZAq4sYc+qeBL6h++tBI/vhqrIiG3ytSh6CAcS7RNw/JX543/DU XvnPD8gERIgwnHkXHIFKRsoz2Mm23QSHuAno9ryCZr4VfGKPUtIvVYGzg5gkgT1YbHc6 R1qH26eXE1Dj2+nq9CGn2ZsJyZu+YqRiCw3v7FFOcLayMcYL6It5Gq/l6isufAzgR0v4 wkrQ== X-Gm-Message-State: AO0yUKXv+gPCfNm+YMhCm6VA5uV+4G/cHk//qFq0DZUckTsaG4V0dnGl aqhXUwB9Aw8XRlYOHkQ4cJUGqY5dEQ40TQ== X-Google-Smtp-Source: AK7set9CfWKu5ocR867bR0plro61Bkifv+N2cf9JG1mBbdWUw7+Bgor9eacBFvn9sOgd9qeginee9Q== X-Received: by 2002:a05:6000:100b:b0:2d5:5610:e7b4 with SMTP id a11-20020a056000100b00b002d55610e7b4mr3285698wrx.64.1679254710634; Sun, 19 Mar 2023 12:38:30 -0700 (PDT) Received: from imac.redhat.com ([88.97.103.74]) by smtp.gmail.com with ESMTPSA id d5-20020adfef85000000b002cfed482e9asm7204190wro.61.2023.03.19.12.38.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 12:38:30 -0700 (PDT) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v2 6/6] netlink: specs: add partial specification for openvswitch Date: Sun, 19 Mar 2023 19:38:03 +0000 Message-Id: <20230319193803.97453-7-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230319193803.97453-1-donald.hunter@gmail.com> References: <20230319193803.97453-1-donald.hunter@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The openvswitch family has a fixed header, uses struct attrs and has array values. This partial spec demonstrates these features in the YNL CLI. These specs are sufficient to create, delete and dump datapaths and to dump vports: $ ./tools/net/ynl/cli.py \ --schema Documentation/netlink/genetlink-legacy.yaml \ --spec Documentation/netlink/specs/ovs_datapath.yaml \ --do dp-new --json '{ "dp-ifindex": 0, "name": "demo", "upcall-pid": 0}' None ./tools/net/ynl/cli.py \ --schema Documentation/netlink/genetlink-legacy.yaml \ --spec Documentation/netlink/specs/ovs_datapath.yaml \ --dump dp-get --json '{ "dp-ifindex": 0 }' [{'dp-ifindex': 3, 'masks-cache-size': 256, 'megaflow-stats': {'cache-hits': 0, 'mask-hit': 0, 'masks': 0, 'pad1': 0, 'padding': 0}, 'name': 'test', 'stats': {'flows': 0, 'hit': 0, 'lost': 0, 'missed': 0}, 'user-features': {'dispatch-upcall-per-cpu', 'tc-recirc-sharing', 'unaligned'}}, {'dp-ifindex': 48, 'masks-cache-size': 256, 'megaflow-stats': {'cache-hits': 0, 'mask-hit': 0, 'masks': 0, 'pad1': 0, 'padding': 0}, 'name': 'demo', 'stats': {'flows': 0, 'hit': 0, 'lost': 0, 'missed': 0}, 'user-features': set()}] $ ./tools/net/ynl/cli.py \ --schema Documentation/netlink/genetlink-legacy.yaml \ --spec Documentation/netlink/specs/ovs_datapath.yaml \ --do dp-del --json '{ "dp-ifindex": 0, "name": "demo"}' None $ ./tools/net/ynl/cli.py \ --schema Documentation/netlink/genetlink-legacy.yaml \ --spec Documentation/netlink/specs/ovs_vport.yaml \ --dump vport-get --json '{ "dp-ifindex": 3 }' [{'dp-ifindex': 3, 'ifindex': 3, 'name': 'test', 'port-no': 0, 'stats': {'rx-bytes': 0, 'rx-dropped': 0, 'rx-errors': 0, 'rx-packets': 0, 'tx-bytes': 0, 'tx-dropped': 0, 'tx-errors': 0, 'tx-packets': 0}, 'type': 'internal', 'upcall-pid': [0], 'upcall-stats': {'fail': 0, 'success': 0}}] Signed-off-by: Donald Hunter --- Documentation/netlink/specs/ovs_datapath.yaml | 153 ++++++++++++++++++ Documentation/netlink/specs/ovs_vport.yaml | 139 ++++++++++++++++ 2 files changed, 292 insertions(+) create mode 100644 Documentation/netlink/specs/ovs_datapath.yaml create mode 100644 Documentation/netlink/specs/ovs_vport.yaml diff --git a/Documentation/netlink/specs/ovs_datapath.yaml b/Documentation/netlink/specs/ovs_datapath.yaml new file mode 100644 index 000000000000..2eefdf9d8cd7 --- /dev/null +++ b/Documentation/netlink/specs/ovs_datapath.yaml @@ -0,0 +1,153 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) + +name: ovs_datapath +version: 2 +protocol: genetlink-legacy + +doc: + OVS datapath configuration over generic netlink. + +definitions: + - + name: ovs-header + type: struct + members: + - + name: dp-ifindex + type: u32 + - + name: user-features + type: flags + entries: + - + name: unaligned + doc: Allow last Netlink attribute to be unaligned + - + name: vport-pids + doc: Allow datapath to associate multiple Netlink PIDs to each vport + - + name: tc-recirc-sharing + doc: Allow tc offload recirc sharing + - + name: dispatch-upcall-per-cpu + doc: Allow per-cpu dispatch of upcalls + - + name: datapath-stats + type: struct + members: + - + name: hit + type: u64 + - + name: missed + type: u64 + - + name: lost + type: u64 + - + name: flows + type: u64 + - + name: megaflow-stats + type: struct + members: + - + name: mask-hit + type: u64 + - + name: masks + type: u32 + - + name: padding + type: u32 + - + name: cache-hits + type: u64 + - + name: pad1 + type: u64 + +attribute-sets: + - + name: datapath + attributes: + - + name: name + type: string + - + name: upcall-pid + doc: upcall pid + type: u32 + - + name: stats + type: struct + struct: datapath-stats + - + name: megaflow-stats + type: struct + struct: megaflow-stats + - + name: user-features + type: u32 + enum: user-features + enum-as-flags: true + - + name: pad + type: unused + - + name: masks-cache-size + type: u32 + - + name: per-cpu-pids + type: array-nest + sub-type: u32 + +operations: + fixed-header: ovs-header + list: + - + name: dp-get + doc: Get / dump OVS data path configuration and state + value: 3 + attribute-set: datapath + do: &dp-get-op + request: + attributes: + - name + reply: + attributes: + - name + - upcall-pid + - stats + - megaflow-stats + - user-features + - masks-cache-size + - per-cpu-pids + dump: *dp-get-op + - + name: dp-new + doc: Create new OVS data path + value: 1 + attribute-set: datapath + do: + request: + attributes: + - dp-ifindex + - name + - upcall-pid + - user-features + - + name: dp-del + doc: Delete existing OVS data path + value: 2 + attribute-set: datapath + do: + request: + attributes: + - dp-ifindex + - name + +mcast-groups: + list: + - + name: ovs_datapath diff --git a/Documentation/netlink/specs/ovs_vport.yaml b/Documentation/netlink/specs/ovs_vport.yaml new file mode 100644 index 000000000000..a0d01adcb435 --- /dev/null +++ b/Documentation/netlink/specs/ovs_vport.yaml @@ -0,0 +1,139 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) + +name: ovs_vport +version: 2 +protocol: genetlink-legacy + +doc: + OVS vport configuration over generic netlink. + +definitions: + - + name: ovs-header + type: struct + members: + - + name: dp-ifindex + type: u32 + - + name: vport-type + type: enum + entries: [ unspec, netdev, internal, gre, vxlan, geneve ] + - + name: vport-stats + type: struct + members: + - + name: rx-packets + type: u64 + - + name: tx-packets + type: u64 + - + name: rx-bytes + type: u64 + - + name: tx-bytes + type: u64 + - + name: rx-errors + type: u64 + - + name: tx-errors + type: u64 + - + name: rx-dropped + type: u64 + - + name: tx-dropped + type: u64 + +attribute-sets: + - + name: vport-options + attributes: + - + name: dst-port + type: u32 + - + name: extension + type: u32 + - + name: upcall-stats + attributes: + - + name: success + type: u64 + value: 0 + - + name: fail + type: u64 + - + name: vport + attributes: + - + name: port-no + type: u32 + - + name: type + type: u32 + enum: vport-type + - + name: name + type: string + - + name: options + type: nest + nested-attributes: vport-options + - + name: upcall-pid + type: array-nest + sub-type: u32 + - + name: stats + type: struct + struct: vport-stats + - + name: pad + type: unused + - + name: ifindex + type: u32 + - + name: netnsid + type: u32 + - + name: upcall-stats + type: nest + nested-attributes: upcall-stats + +operations: + list: + - + name: vport-get + doc: Get / dump OVS vport configuration and state + value: 3 + attribute-set: vport + fixed-header: ovs-header + do: &vport-get-op + request: + attributes: + - dp-ifindex + - name + reply: &dev-all + attributes: + - dp-ifindex + - port-no + - type + - name + - upcall-pid + - stats + - ifindex + - netnsid + - upcall-stats + dump: *vport-get-op + +mcast-groups: + list: + - + name: ovs_vport