From patchwork Fri Mar 24 11:37:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13186678 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 BA939C76196 for ; Fri, 24 Mar 2023 11:38:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231464AbjCXLi1 (ORCPT ); Fri, 24 Mar 2023 07:38:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjCXLiZ (ORCPT ); Fri, 24 Mar 2023 07:38:25 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97AE41D931; Fri, 24 Mar 2023 04:38:24 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id y14so1486714wrq.4; Fri, 24 Mar 2023 04:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679657902; 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=3QaKKaAV5uskNotm4xfaVm8rl+bvQRGyp7RvzE6EVzE=; b=M7ZD+jbhHHlBY7CNybvO9TRZe6Q7640MqfVOOATyKqFyc86/nvTJ0ZWX8l1Ih3lHhH cK689vY14xDcnJkp+3ACFmJkF27K5G1nPum5CR/7YkezN60VRLSX3zwXCJCqGtsC7ct2 bw5SUGsFM2jInNHv95RZIlGsLWMC9ctF+gCCKWkjM2kTO1jfFGIVmMesylBMI92r74Kn RzwR3dh5RsAi/LUKNqK6F2LygFW4O0BVT/34gB5wotKygzAktJCSLXUzh1ZAUByaPk// AjeDgJDi+ibTUPfQCv/N8VbXBhCwlENYF57mOelBmTQUqwpB8wbuzLWjnKQHqp+bbNVR XifQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679657902; 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=3QaKKaAV5uskNotm4xfaVm8rl+bvQRGyp7RvzE6EVzE=; b=f4hIm9Ix3I/xhpPkzR2zsv3YKDlH9vaVEikWWrjhNs58A0D1QEZkKNQf4XsaYTFoaQ Yo/uZ04h3m0Z/fGG0UigGDzxylaGEcrM8IHfoO1PnXRkjJzRdxhi+k9fDRhkhbaxJBUt qkJ+KHQrRNx3XNIWUSKXmpYf6QzyVF2whO2JEG6vidizBvjsA1z/uvPMUZLyqVP9ZuOP 08Yiw30/d+EF9zIRqe9ZH0TqzInsERX3DUAZqkSsL8F8Y8v8u3zu6b8mGhqgR+bF2cBb AQz9fZHAL9NCw36BL8Ys21e0FIpxiv5DYoKzwRXPrAAhr9oyU63jLqm+oLyNcoa9zHDm 1bqQ== X-Gm-Message-State: AAQBX9cyLfM85ZWLqc6J8eNXtFt8CcX/g7BnKSTspBfPpuSFeQEEMDbn CHWjqLR1pqQR9WM0jnWhskKL+0mLx/O3lQ== X-Google-Smtp-Source: AKy350a9Ky3sT70E9GhO1ppy3WVijz2YPeV3jqBVf/FOuOjmbckYUQmT9s0N2ZlvrGoqULvK+c9Hgg== X-Received: by 2002:a5d:428c:0:b0:2d3:3cda:b3c6 with SMTP id k12-20020a5d428c000000b002d33cdab3c6mr1892991wrq.40.1679657902449; Fri, 24 Mar 2023 04:38:22 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:cd72:bbb4:8d1:483a]) by smtp.gmail.com with ESMTPSA id t6-20020adff606000000b002d828a9f9ddsm10150954wrp.115.2023.03.24.04.38.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 04:38:22 -0700 (PDT) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Jonathan Corbet , linux-doc@vger.kernel.org Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v3 1/7] tools: ynl: Add struct parsing to nlspec Date: Fri, 24 Mar 2023 11:37:28 +0000 Message-Id: <20230324113734.1473-2-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324113734.1473-1-donald.hunter@gmail.com> References: <20230324113734.1473-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 | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py index d04450c2a44a..a08f6dda5b79 100644 --- a/tools/net/ynl/lib/nlspec.py +++ b/tools/net/ynl/lib/nlspec.py @@ -214,6 +214,44 @@ class SpecAttrSet(SpecElement): return self.attrs.items() +class SpecStructMember(SpecElement): + """Struct member attribute + + Represents a single struct member attribute. + + Attributes: + type string, 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 +382,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 +440,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 Fri Mar 24 11:37:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13186679 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 77ECFC76196 for ; Fri, 24 Mar 2023 11:38:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231511AbjCXLi3 (ORCPT ); Fri, 24 Mar 2023 07:38:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjCXLi2 (ORCPT ); Fri, 24 Mar 2023 07:38:28 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE0AD1E1C0; Fri, 24 Mar 2023 04:38:26 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id o7so1484580wrg.5; Fri, 24 Mar 2023 04:38:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679657904; 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=58IwQQkEAhYQMjB39CTS4lZbJRfFOqasTG2I1XON7Dk=; b=qp/OhoQhSO48Iq3e+YBN0KILticoZfWqSqhdVlHVQvc5Hw4T3t32FV7YvpotLluF1P ZG+cpCB2cQmshJTWzqOPZ/5T0/IHmU16/uKc8JVDckiP+layf8GUGURhx2o6ZWGOSImY dmqMKpYHD6QmKvC9yLRMeV1B4P7HM4yHu+3CHdh79LBj1BKHlkzLMotDf9mAPeqIiG29 1uQicCLS7SqIfeUWHlWqddICQVm8+pjHhuUqNaOa/hhO1BsHSNmBjUKN/rTXQsK43GGv Oq77dWGCSx0u9UI/R+l0GVZRDxX4lPSBJlmkf2uM3f6Hse/TE3kk5yZPiz0Zf59Hjlxa GXMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679657904; 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=58IwQQkEAhYQMjB39CTS4lZbJRfFOqasTG2I1XON7Dk=; b=O587a/VZpBuAc45kfMPyHNvsnUgJ8IXc67UU1gSkWYtTlJHpgXbC3sdUVzNXroKFWx Tbg5ghaWjQrob/WBbr1mkDdybGdVsWEyeBRvkQ2sl6ElH3gGVv8x7lFglRgMCVU4K0Xv HC6oVroGr5jjQfda9tHuKguh26Nc82/NFcWtQz7HFrQMW2i8HxrdosULNleAK3p21gcb ox2pITuyESxdzy4Y9zvMoZyQ2yJRnQ1P8LtSuMwtQz1boaMEX49xQzW20r519TKtqb7P v1KT9D4C2XU/lEcn5ZNIvaaSr/0vcL463h4/UzAGXJjJhDxCXPcg0nj+hpk/9fNfYFrX 1P/w== X-Gm-Message-State: AAQBX9d4A1G15wljfRI0IvSKOvfI+d4DuOV84hCmIBFTTIQlh+5LLBNs cx0XAlejoedVS4/6xINn0k11dCcg9ZVszQ== X-Google-Smtp-Source: AKy350Z8QawNVmrN8u3LAyPsai9oDGPxND5vWfS4TV0PhfvMxErB230PGttC7atVstzfk5UIy1bHVA== X-Received: by 2002:a05:6000:1a47:b0:2d8:4f02:66b6 with SMTP id t7-20020a0560001a4700b002d84f0266b6mr2134647wry.9.1679657904388; Fri, 24 Mar 2023 04:38:24 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:cd72:bbb4:8d1:483a]) by smtp.gmail.com with ESMTPSA id t6-20020adff606000000b002d828a9f9ddsm10150954wrp.115.2023.03.24.04.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 04:38:23 -0700 (PDT) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Jonathan Corbet , linux-doc@vger.kernel.org Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v3 2/7] tools: ynl: Add C array attribute decoding to ynl Date: Fri, 24 Mar 2023 11:37:29 +0000 Message-Id: <20230324113734.1473-3-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324113734.1473-1-donald.hunter@gmail.com> References: <20230324113734.1473-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 C arrays from binay blobs in genetlink-legacy messages. Signed-off-by: Donald Hunter --- tools/net/ynl/lib/ynl.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 32536e1f9064..fbcaca67d571 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), 's8' : ('b', 1), + 'u16': ('H', 2), 's16': ('h', 2), + 'u32': ('I', 4), 's32': ('i', 4), + 'u64': ('Q', 8), 's64': ('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 @@ -93,6 +98,10 @@ class NlAttr: def as_bin(self): return self.raw + def as_c_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}" @@ -361,6 +370,14 @@ class YnlFamily(SpecFamily): value = enum.entries_by_val[raw - i].name rsp[attr_spec['name']] = value + def _decode_binary(self, attr, attr_spec): + sub_type = attr_spec.get('sub-type') + if sub_type: + decoded = attr.as_c_array(sub_type) + else: + decoded = attr.as_bin() + return decoded + def _decode(self, attrs, space): attr_space = self.attr_sets[space] rsp = dict() @@ -378,7 +395,7 @@ class YnlFamily(SpecFamily): elif attr_spec["type"] == 'string': decoded = attr.as_strz() elif attr_spec["type"] == 'binary': - decoded = attr.as_bin() + decoded = self._decode_binary(attr, attr_spec) elif attr_spec["type"] == 'flag': decoded = True else: From patchwork Fri Mar 24 11:37:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13186680 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 5CE3EC6FD20 for ; Fri, 24 Mar 2023 11:38:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231527AbjCXLic (ORCPT ); Fri, 24 Mar 2023 07:38:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231475AbjCXLi3 (ORCPT ); Fri, 24 Mar 2023 07:38:29 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0250D1D92E; Fri, 24 Mar 2023 04:38:27 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id r11so1463120wrr.12; Fri, 24 Mar 2023 04:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679657906; 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=UknnM/LyXPl7qqTNocHtWRPHH99DiTOzTPEQbzahRG4=; b=Y/a954F+6g6Wx9HSw8yb0eDc5g8uemxWS4+NHlL2SiIKAGZW2s55VUqFVvDV3MICZz t83sqgursXuxIRBioA3QwzePsOoPbUI4uY0N6CEAKSq/s945tBA0q4U1ytVcOFyJFR8S CXxT+xe4HXxbTnZegXhraQejIwlI3m0uLXKmUx7G7eEo5QUBkpcOmLjfjNSsatb3TENi uOAFQ2NbP9jsuwzYPCPDO4rXQXjLjY/GTgFXHWPpqQhdg8NgVzaP9UbJTl/KhhKjtVFD HPckdyA4DoZvLa3Fyc0AxPZCvj4TvpQpCyzCh1Wmc8298PYQ+25XrKgXEEoKJtBEznik fxgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679657906; 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=UknnM/LyXPl7qqTNocHtWRPHH99DiTOzTPEQbzahRG4=; b=rE9Gv2uqtA8w+3MF1O5MG/kDsdpUKCJBX7wQ5dvN2IfhWnglln/rIw79xoU9mQij4O sNZ5S0d5GrPE856dL7B+FIwktbBgWg9s9ebetmSkl+ckQgoqd0pD8j8ed2rsNH7nG0+O xTU/PtLofuNh8B5lt+fsWJJ9EYqYdHaEK7yNUcmU37Z5aTvd79rzc1G9R2+/kkCawE3j EzMbAw0DbxDwGCs/riBrh2+jD0p/tIe3pRtlrtPxJyzlEcT9+lNQFC6Bx1Z2pTMYwgRo j8nDmQfGq6r0JDpELU78XrfotZ42KJsjoyotKxnQZ9KvystKMgW7WQz94ETWF+lf8Dyh /Hrg== X-Gm-Message-State: AAQBX9d+aW61cEWlkzs04hLsapLiDIgaHiyMssdmls8OD3xSLKNixixG SJwtx/POKdd1da8+/jwCLMgK0MGvvHpRKw== X-Google-Smtp-Source: AKy350a5dCLtvzt+u0sl0mZrAsMDKTsUTzCsWaeiqODw5LXYgHBrw1XJVDAJmLwWDLN1Czo2+1bp+w== X-Received: by 2002:adf:f4c7:0:b0:2ce:ac70:5113 with SMTP id h7-20020adff4c7000000b002ceac705113mr2006147wrp.41.1679657906035; Fri, 24 Mar 2023 04:38:26 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:cd72:bbb4:8d1:483a]) by smtp.gmail.com with ESMTPSA id t6-20020adff606000000b002d828a9f9ddsm10150954wrp.115.2023.03.24.04.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 04:38:25 -0700 (PDT) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Jonathan Corbet , linux-doc@vger.kernel.org Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v3 3/7] tools: ynl: Add struct attr decoding to ynl Date: Fri, 24 Mar 2023 11:37:30 +0000 Message-Id: <20230324113734.1473-4-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324113734.1473-1-donald.hunter@gmail.com> References: <20230324113734.1473-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 | 5 +++++ tools/net/ynl/lib/ynl.py | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml index 5dc6f1c07a97..d50c78b9f42d 100644 --- a/Documentation/netlink/genetlink-legacy.yaml +++ b/Documentation/netlink/genetlink-legacy.yaml @@ -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 fbcaca67d571..b2845a63f6af 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -102,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}" @@ -371,8 +381,11 @@ class YnlFamily(SpecFamily): rsp[attr_spec['name']] = value def _decode_binary(self, attr, attr_spec): + struct_name = attr_spec.get('struct') sub_type = attr_spec.get('sub-type') - if sub_type: + if struct_name: + decoded = attr.as_struct(self.consts[struct_name]) + elif sub_type: decoded = attr.as_c_array(sub_type) else: decoded = attr.as_bin() From patchwork Fri Mar 24 11:37:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13186681 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 7E8F4C6FD1C for ; Fri, 24 Mar 2023 11:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231637AbjCXLij (ORCPT ); Fri, 24 Mar 2023 07:38:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231491AbjCXLic (ORCPT ); Fri, 24 Mar 2023 07:38:32 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D8AE1E1DF; Fri, 24 Mar 2023 04:38:29 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id l27so1492973wrb.2; Fri, 24 Mar 2023 04:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679657907; 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=fz33cl1Em+iCEUOiB+c8bhu29hBoUMGh0ZsVhdcIWf0=; b=YotdmO//d6dCF6trw9eN6gwtU071nfpffOfim2PfSbwu97ONGS/8uhE9Psi48LThoA rQn329mGz3XkVFcNhueaK+7AByXcqkzmoweV2y7DDCLQPaGTEstHCBkPC7cevo+zy5s5 IlQpvztNlUtN7rBB+qzjX92/kWjsIEVvSCD5R0CuPKXWcr3TzRCQyZbwoyFKE7sfcxlf 8JMgTxT/zpEZYjZdJvoO2K5AELpa1gBPMyOSkeYJUIGyZr19YkfZLFKUxXFl9CD5X8Ak 8hgByrTstsDb5DVjNQ+YdNVFhgmvCDISKyXbpGBNgidKOkI8zkmSNgYadtS2czI0PxwZ /awQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679657907; 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=fz33cl1Em+iCEUOiB+c8bhu29hBoUMGh0ZsVhdcIWf0=; b=OgivpWSOUwTzZTm04+baQQQvurJ8B7+8KBLBAx5dBkXQ/LFdOtC64WQIligoVS7kZk eklJRz9IWkZJ9WmpMPaGawO+hxZgmPRZo6dx0YZZFlp+fdB2FwBfPrZkCyuBoYjJNQIt renzJvDkLFngBF1iNx0ZTFsQyrjFemzIctHGY2Md/I6huXjpJxR3R4HotpEQ5gjloIZA hpsyvIwQeIhjTwRCAsduzkAKxIMFIMwI4BI/3fH5+g4vMq+anfhV/YWmh+NzfxK4eHcn ZtD2JORbvEWlcPRSILB13Lc3vgKrIVTOUwTunfYFtcV9s5X9RI/itKHLOtA+AMYjRo7W fF/Q== X-Gm-Message-State: AAQBX9eGi/V86rXcIDL/f1tmJDkkb1KekvHhe1eBZ+NS8vZYfAmDCQt0 kGxdDDNjt7Mm2TY5B1BGBMcJC1s9q5Knuw== X-Google-Smtp-Source: AKy350b0u7S9+b2L7MdWO5XMOQe8stiDFPKup0ngyCE7NHB1A0IjMPfEy/ooYipXJuuM+3ViPZxnqQ== X-Received: by 2002:a05:6000:c:b0:2c7:ae57:5acc with SMTP id h12-20020a056000000c00b002c7ae575accmr2003665wrx.26.1679657907689; Fri, 24 Mar 2023 04:38:27 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:cd72:bbb4:8d1:483a]) by smtp.gmail.com with ESMTPSA id t6-20020adff606000000b002d828a9f9ddsm10150954wrp.115.2023.03.24.04.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 04:38:27 -0700 (PDT) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Jonathan Corbet , linux-doc@vger.kernel.org Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v3 4/7] tools: ynl: Add fixed-header support to ynl Date: Fri, 24 Mar 2023 11:37:31 +0000 Message-Id: <20230324113734.1473-5-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324113734.1473-1-donald.hunter@gmail.com> References: <20230324113734.1473-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, which serves as a default value that can be overridden. Signed-off-by: Donald Hunter --- Documentation/netlink/genetlink-legacy.yaml | 10 +++++++++ tools/net/ynl/lib/nlspec.py | 21 ++++++++++++------- tools/net/ynl/lib/ynl.py | 23 +++++++++++++++++---- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml index d50c78b9f42d..3b8984122383 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 a08f6dda5b79..09dbb6c51ee9 100644 --- a/tools/net/ynl/lib/nlspec.py +++ b/tools/net/ynl/lib/nlspec.py @@ -258,16 +258,17 @@ 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 name of fixed header struct - 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): super().__init__(family, yaml) @@ -279,6 +280,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', family.fixed_header) # Added by resolve: self.attr_set = None @@ -319,6 +321,7 @@ class SpecFamily(SpecElement): msgs_by_value dict of all messages (indexed by name) ops dict of all valid requests / responses consts dict of all constants/enums + fixed_header string, optional name of family default fixed header struct """ def __init__(self, spec_path, schema_path=None): with open(spec_path, "r") as stream: @@ -392,6 +395,7 @@ class SpecFamily(SpecElement): self._resolution_list.append(elem) def _dictify_ops_unified(self): + self.fixed_header = self.yaml['operations'].get('fixed-header') val = 1 for elem in self.yaml['operations']['list']: if 'value' in elem: @@ -403,6 +407,7 @@ class SpecFamily(SpecElement): self.msgs[op.name] = op def _dictify_ops_directional(self): + self.fixed_header = self.yaml['operations'].get('fixed-header') req_val = rsp_val = 1 for elem in self.yaml['operations']['list']: if 'notify' in elem: diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index b2845a63f6af..5bf024022cfa 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): @@ -502,6 +510,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) @@ -528,7 +543,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: @@ -538,7 +553,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 Fri Mar 24 11:37:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13186682 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 1F116C6FD1C for ; Fri, 24 Mar 2023 11:38:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231589AbjCXLil (ORCPT ); Fri, 24 Mar 2023 07:38:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231625AbjCXLii (ORCPT ); Fri, 24 Mar 2023 07:38:38 -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 708F81DB87; Fri, 24 Mar 2023 04:38:31 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id r29so1458763wra.13; Fri, 24 Mar 2023 04:38:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679657909; 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=baO/JoV/iXYEzhQwMlu7mnvyc24+QpS7jNnl+nSC1E8=; b=R2cXobDHGNb6xe0rxUhk9nEpqCjJj84VR1JJDR5l0g51zDRPG6B7Foe0c2FilWQOCF kuTmUBxdszHMgCaghMa9S3viPLL1hNIdei/0TKb58UNyDgKx6lKfQha4+/P0cOWZXzIY 6EuiXPxocmsJwTW+HmOfn/oAD6tWwEB4qX9RzYupf3vRhV5McWGUhY7LE9XpvRj9hf46 AyJEJl7fDyloDhjguyCy2okj4z3IOfN3jrSQFVA7CTeWWzNFsmVlOZzudCtYFRRVb/ke YakixInGQ4J5+1vugFAd1YY1pXDTKrtSFD5abTM7DjiVVhgTZHEsnZ2+SGhgjc48AyaU IqvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679657909; 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=baO/JoV/iXYEzhQwMlu7mnvyc24+QpS7jNnl+nSC1E8=; b=D0TJNY2ruMc6wiFmFjsPj/dz7T+1RnAkO/G+mIJsTuz4AfJwa9FhdbVEUlWYB0lt9F TgJ3i0g2xgMRRFB32MwcKcVzz2cnxAPCzqLZeyepU8rNTlx8nLjkFlZDglz1GAABan79 6Wdy56yRG6w4J7Y92n0xQZ+iZWzuxNcKO2QZXCz1thukR3kbZticzPQP0LqNJUMl+RM5 E5qkcQrHJGUYCpFITZgHADN7eWEssOU65l5Fbk2etzCO01Fr+67/yEtKJvcK4lN09B86 tb6PE2icYbzkmIRrHPy/ctD7KsYIXdLL1h/tbTOQRIKRR/gK8haz0nXWkpgnNToZ5CD/ xsng== X-Gm-Message-State: AAQBX9crLOt+3D7K9U3UMM+NEKrPDkwfn0gaYqLl5CU11loFR+iNBG3r 5qEmwLNy4JYwWBC4UT7SSyjByhu07miDrg== X-Google-Smtp-Source: AKy350YJb3GyghCATyGiFlKvkQnzfth+opxFp8vdD3nIV63bXkorDGgo8z3Jw5p7Lk9XRNnJAVaVrQ== X-Received: by 2002:adf:f80c:0:b0:2ce:a8d5:4a89 with SMTP id s12-20020adff80c000000b002cea8d54a89mr1951339wrp.37.1679657909398; Fri, 24 Mar 2023 04:38:29 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:cd72:bbb4:8d1:483a]) by smtp.gmail.com with ESMTPSA id t6-20020adff606000000b002d828a9f9ddsm10150954wrp.115.2023.03.24.04.38.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 04:38:28 -0700 (PDT) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Jonathan Corbet , linux-doc@vger.kernel.org Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v3 5/7] netlink: specs: add partial specification for openvswitch Date: Fri, 24 Mar 2023 11:37:32 +0000 Message-Id: <20230324113734.1473-6-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324113734.1473-1-donald.hunter@gmail.com> References: <20230324113734.1473-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 \ --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 \ --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 \ --spec Documentation/netlink/specs/ovs_datapath.yaml \ --do dp-del --json '{ "dp-ifindex": 0, "name": "demo"}' None $ ./tools/net/ynl/cli.py \ --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..6d71db8c4416 --- /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: binary + struct: datapath-stats + - + name: megaflow-stats + type: binary + 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: binary + 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..8e55622ddf11 --- /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: binary + sub-type: u32 + - + name: stats + type: binary + 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 From patchwork Fri Mar 24 11:37:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13186683 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 2528FC6FD20 for ; Fri, 24 Mar 2023 11:38:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231724AbjCXLin (ORCPT ); Fri, 24 Mar 2023 07:38:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231631AbjCXLij (ORCPT ); Fri, 24 Mar 2023 07:38:39 -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 1191F1DB88; Fri, 24 Mar 2023 04:38:33 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id e18so1471065wra.9; Fri, 24 Mar 2023 04:38:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679657911; 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=LCkEokrsCzjIkMKxFdvX1hlK9J/wGQW+qxp7NgekMCc=; b=O5N+yaWDPZJ/teIwRzgmImfUqBlW/UYf3DzpmpmzyqND/4lLN8sX1FOJf7Qe8JXICK FctjckiNWkqXZrhwtv1eS2zBk4BD/P/B/GG0kJWQvOiofIP69tVrKnmtD6oVgZHdZSn6 cj+mq/lFci7FBTAU5sA/8cxWf7UPBhuk+Vk2doTNPFi7526kHx4aOeOqARINfk+JIkr1 YgfXYFR6fshKeaYAeH2JKFtglX8RXzqUvj6aZRAJU/2cIUw73FN6ylsVUWek7BcIzwsN lsvneZJPpl28hXkLQDQyPc3yAqgYJWeKN+7bLfcdBNRQLRDrxqejPV7QLnZCx2m0wTeW YEaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679657911; 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=LCkEokrsCzjIkMKxFdvX1hlK9J/wGQW+qxp7NgekMCc=; b=lQW0iQayGDECautxh6iTPoAUGTPECtntruOEL1/NjzHDW9OIQL+YHT+xkeuHbhhguw ghLddm4Uy6mLgByfVXWsDdiYFTgfKDVr9n0P4GrB83ZYGNT4dUPdw5GID+BIPJpA0VfM gCaAMbXYXzG4JmYncaZk9AjlV+YmqfhDQEZVLHKnVRv8fqJLJlBjihuhpRJIA3PzCsRK rWk5Fixb6nts12qdkzQno9qLvJfwgN5TnftEew1kUwPzn7+1ATcXoBF6HjnIFweDI/1g J6Oa9d2QfF+pD9o1SAYVVv1oBko2w8RlhQahWIi8/6U1Fm1y3VWEF6vKmhn2T94ZT5T6 MjyA== X-Gm-Message-State: AAQBX9d31wTdfvMzFYh1r/xQy0/KU6gvDa60JYuCQ46eIFrvnlT53Pv2 qXJz2NacuNOLni3BzI95Zcf4RKw7oI+x3w== X-Google-Smtp-Source: AKy350aLL4oUxZocKs58TZu0oNwOYK/HJjw3NvU7ScUBc8b74WcMwn4n0cn9JVZHIfEgcMPhma8VpA== X-Received: by 2002:adf:ffc9:0:b0:2d3:b49c:23d5 with SMTP id x9-20020adfffc9000000b002d3b49c23d5mr1783302wrs.29.1679657911031; Fri, 24 Mar 2023 04:38:31 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:cd72:bbb4:8d1:483a]) by smtp.gmail.com with ESMTPSA id t6-20020adff606000000b002d828a9f9ddsm10150954wrp.115.2023.03.24.04.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 04:38:30 -0700 (PDT) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Jonathan Corbet , linux-doc@vger.kernel.org Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v3 6/7] docs: netlink: document struct support for genetlink-legacy Date: Fri, 24 Mar 2023 11:37:33 +0000 Message-Id: <20230324113734.1473-7-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324113734.1473-1-donald.hunter@gmail.com> References: <20230324113734.1473-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 Describe the genetlink-legacy support for using struct definitions for fixed headers and for binary attributes. Signed-off-by: Donald Hunter --- .../netlink/genetlink-legacy.rst | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/Documentation/userspace-api/netlink/genetlink-legacy.rst b/Documentation/userspace-api/netlink/genetlink-legacy.rst index 3bf0bcdf21d8..6b385a9e6d0b 100644 --- a/Documentation/userspace-api/netlink/genetlink-legacy.rst +++ b/Documentation/userspace-api/netlink/genetlink-legacy.rst @@ -163,8 +163,58 @@ Structures ---------- Legacy families can define C structures both to be used as the contents -of an attribute and as a fixed message header. The plan is to define -the structs in ``definitions`` and link the appropriate attrs. +of an attribute and as a fixed message header. Structs are defined +in ``definitions`` and referenced in operations or attributes. + +.. code-block:: yaml + + definitions: + - + name: message-header + type: struct + members: + - + name: a + type: u32 + - + name: b + type: string + +Fixed Headers +~~~~~~~~~~~~~ + +Fixed message headers can be added to operations using ``fixed-header``. +The default ``fixed-header`` can be set in ``operations`` and it can be set +or overridden for each operation. + +.. code-block:: yaml + + operations: + fixed-header: message-header + list: + - + name: get + fixed-header: custom-header + attribute-set: message-attrs + +Attributes +~~~~~~~~~~ + +A ``binary`` attribute can be interpreted as a C structure using a +``struct`` property with the name of the structure definition. The +``struct`` property implies ``sub-type: struct`` so it is not necessary to +specify a sub-type. + +.. code-block:: yaml + + attribute-sets: + - + name: stats-attrs + attributes: + - + name: stats + type: binary + struct: vport-stats Multi-message DO ---------------- From patchwork Fri Mar 24 11:37:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13186684 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 737B7C76196 for ; Fri, 24 Mar 2023 11:38:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231528AbjCXLiy (ORCPT ); Fri, 24 Mar 2023 07:38:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231473AbjCXLij (ORCPT ); Fri, 24 Mar 2023 07:38:39 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9B571E5C1; Fri, 24 Mar 2023 04:38:34 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id p34so968703wms.3; Fri, 24 Mar 2023 04:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679657912; 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=lIMBsyNwngYJxJCZuFxAXyNmrXqE9/jxWeXYfc5T+pA=; b=RKnSMcBaLdEWl7IWKSkMboMI7waawAjExOiht+HZkb5Tj9TuhS5LNmaTdIEBGT2mYF gkxJ0Y7u1JUzPhJWlFFH6WolZg5e46dmHAji/ToyCceygPbLC7wIRQM445fd0mOmlSvm K2m3CB/4caUz1ouVn7MiKqo0qUtFvoDk8IhLai+iLo8u7i3IVRVmnuNwvB/4VjXnGRiK wzgnwL/+yNFVA2H1xuIZuDO2WSMBsz9OF149JeX92YdY9iZCMZ6FLS8lx4TGNJxQPcQE 0k/nnBI603ubwYcZqqHXWIQgv/Vii+XSGzY4ccH8eHKrdDaSwBKGGonU/20FRWFv63y6 CkbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679657912; 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=lIMBsyNwngYJxJCZuFxAXyNmrXqE9/jxWeXYfc5T+pA=; b=fefALNbIoon8p2aEF1KncqsVvaVrKb1y+YeBN7BV6XWhLhsdbrBbsr0o8RJKMQ9o7D gOWYy4e6lu/FzZkcoIuvOLWrUjP+G91+hCLfJAM3HntpDnshufKs3YW02jdbuQr+eJP1 y/rVf7xUG0R6dA82wC5IFbMIwvhB0r2GtCYugOHTBWg//tSePeZ9iZVAFGzm670hVAzM 3FCo9oXcVxY6YLS7LDJ9VHpPJgzCKaUyX9A18YOnlji02dUsXLFXgm51nSfsXlpc9Dwr C2ASwOeHWWT4qJ0lPE+ZQEGp1KRkuJDXPrNWM+wERlH6DN/kSwrQwOGLm69ioCqQgJYA wTZw== X-Gm-Message-State: AO0yUKWfB3aNRW3eyD1WIlx5woHJ43jsCKRDWyr343rK3/VmVlaJ6NLt YC2PY3TCtnU2AGfVnz1in47QMUPcmcBhgg== X-Google-Smtp-Source: AK7set/+Rk5azK5TjcPok3nXqckyj55OghOyXrBUSn94BGFncUB56B3KRodyVm1+TgvDxW3n5K6fKg== X-Received: by 2002:a7b:c398:0:b0:3ed:da87:3349 with SMTP id s24-20020a7bc398000000b003edda873349mr2119748wmj.1.1679657912712; Fri, 24 Mar 2023 04:38:32 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:cd72:bbb4:8d1:483a]) by smtp.gmail.com with ESMTPSA id t6-20020adff606000000b002d828a9f9ddsm10150954wrp.115.2023.03.24.04.38.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 04:38:32 -0700 (PDT) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Jonathan Corbet , linux-doc@vger.kernel.org Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v3 7/7] docs: netlink: document the sub-type attribute property Date: Fri, 24 Mar 2023 11:37:34 +0000 Message-Id: <20230324113734.1473-8-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324113734.1473-1-donald.hunter@gmail.com> References: <20230324113734.1473-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 a definition for sub-type to the protocol spec doc and a description of its usage for C arrays in genetlink-legacy. Signed-off-by: Donald Hunter --- .../userspace-api/netlink/genetlink-legacy.rst | 14 ++++++++++++++ Documentation/userspace-api/netlink/specs.rst | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/Documentation/userspace-api/netlink/genetlink-legacy.rst b/Documentation/userspace-api/netlink/genetlink-legacy.rst index 6b385a9e6d0b..afd9c4947a1c 100644 --- a/Documentation/userspace-api/netlink/genetlink-legacy.rst +++ b/Documentation/userspace-api/netlink/genetlink-legacy.rst @@ -216,6 +216,20 @@ specify a sub-type. type: binary struct: vport-stats +C Arrays +-------- + +Legacy families also use ``binary`` attributes to encapsulate C arrays. The +``sub-type`` is used to identify the type of scalar to extract. + +.. code-block:: yaml + + attributes: + - + name: ports + type: binary + sub-type: u32 + Multi-message DO ---------------- diff --git a/Documentation/userspace-api/netlink/specs.rst b/Documentation/userspace-api/netlink/specs.rst index a22442ba1d30..7931322d3238 100644 --- a/Documentation/userspace-api/netlink/specs.rst +++ b/Documentation/userspace-api/netlink/specs.rst @@ -254,6 +254,15 @@ rather than depend on what is specified in the spec file. The validation policy in the kernel is formed by combining the type definition (``type`` and ``nested-attributes``) and the ``checks``. +sub-type +~~~~~~~~ + +Attributes can have a ``sub-type`` that is interpreted in a ``type`` +specific way. For example, an attribute with ``type: binary`` can have +``sub-type: u32`` which says to interpret the binary blob as an array of +``u32``. Binary types are described in more detail in +:doc:`genetlink-legacy`. + operations ----------