From patchwork Mon Mar 27 08:31: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: 13188783 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 6B9D9C7619A for ; Mon, 27 Mar 2023 08:37:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233179AbjC0Ihp (ORCPT ); Mon, 27 Mar 2023 04:37:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233215AbjC0Ih0 (ORCPT ); Mon, 27 Mar 2023 04:37:26 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43B5876A7; Mon, 27 Mar 2023 01:32:00 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id l27so7783096wrb.2; Mon, 27 Mar 2023 01:32:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679905916; 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=pBxJwdkasfll4c1P/Ox5qD5BWll0iXc1I1GXZEfyI9I=; b=GOTkOo+ieYYB1QkraE93x4xAoMU9d02Ccz7dVFswTesltBL6iaXkfLOf3wO9UkGuws j2o+SxFwkRdi+SVB+X2L81edCWB8/QLc+Lldp5Qs6fJ0abgL/QsMWGP9BKw2dPIUZamK wH772q3I/23bEv7oYIoSu96NpGFbVsX9ndXeTyMyHiBTuS0SYb9rsujvy82olOoipHf4 Ga38vECMi7sMvR4iqUCOFGRpDcLdt2PcyjtBP+NeuCtx12T5BnCKq8PHVKVlHdNAcd6b CDw3V6IAnuUTY8bGxsg8LGbTF/4koYdNHaF3NKnVzC/iP6wKRe9EGEPaTnPhwJlEyRUc YRFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679905916; 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=pBxJwdkasfll4c1P/Ox5qD5BWll0iXc1I1GXZEfyI9I=; b=eqtEiJfoF1hq8OyXcCb9IahIPijsh1N+qsA0wI5iRtgYv+oQPMz/KxdSIojqu3Mk3I eok4GPjykUUky7Ak++0C/nEizg7iXjR3pTvJ+TtTdCAyEV27N0VRz1804zOvWJ+Dx7/a xdGvlD/lyb+caP+2fvm1clx4SFvjPXfXsBGamtOJNNXhocokLlKKcRhxZVfUKTIVabS5 Mk7+7LQzlQi5PcFEj35qW9Lh21H2a/DUk0jaQ1oWlEl3l+OgPuJcnvXlpQMx9VHcBwBs K6VCCQ2W6SufqoARB2LA5IFUnVlaVL76GM32NslgXpC/LAZM3xWxIpUTXY6Xy3HCTM2y Qk8Q== X-Gm-Message-State: AAQBX9dAXlLegMFe3xYUcqp4veWYYELfEGpn+kW570MAt1PrTHot0Y9b /DnGLnpRybHkPhAtZWCD7nGLXCCgp/07ZA== X-Google-Smtp-Source: AKy350bozmdtmug+/7uxDp5TT41mbwZGBZLM+3Xq8dROJoL9V6HxhJ9POKQ9ZJcBNlUAI8r/odjyHQ== X-Received: by 2002:adf:decf:0:b0:2cf:f30f:cc04 with SMTP id i15-20020adfdecf000000b002cff30fcc04mr7705518wrn.27.1679905915648; Mon, 27 Mar 2023 01:31:55 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:7887:5530:69a2:a11f]) by smtp.gmail.com with ESMTPSA id z6-20020a056000110600b002c557f82e27sm24353249wrw.99.2023.03.27.01.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 01:31:55 -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 v5 1/7] tools: ynl: Add struct parsing to nlspec Date: Mon, 27 Mar 2023 09:31:32 +0100 Message-Id: <20230327083138.96044-2-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230327083138.96044-1-donald.hunter@gmail.com> References: <20230327083138.96044-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 Reviewed-by: Jakub Kicinski --- 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 dba70100124a..83de2a1a3cc6 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 Mon Mar 27 08:31: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: 13188784 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 693D2C761A6 for ; Mon, 27 Mar 2023 08:37:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232923AbjC0Ihr (ORCPT ); Mon, 27 Mar 2023 04:37:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233234AbjC0Ih1 (ORCPT ); Mon, 27 Mar 2023 04:37:27 -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 E1411A27D; Mon, 27 Mar 2023 01:32:01 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id h17so7758932wrt.8; Mon, 27 Mar 2023 01:32:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679905917; 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=wRmswFiWTDHAdnFgsbs9MdujlDQuLrbap9qquN6025Y=; b=HzhRrIeo1C/+XxOhhHieZpFfxfXRpYE0MHWP2Or9LR5tN1X1F6e+Pps07YhADgfk/1 kYU4fI8d6U0OfGsIf2kIpcxsb8vFnUWqRvcr+D+rFTy/rKuBpGc8qwnzjgdOb0Yg83ch RQEy6QDuriwEwEa7LbHYmGhX+jai2hrniIIlNLkD82LwtMIt99ayTAW4FhGLvs72lF1O IZGrxIGlVZUf4CMrQjAaQWOfO5VccqbCSdAkleLRAjCO3WZmQcrfPXMakM4mcF/JzAha rv8kgREkWEZ88jmn/NlAsTrsm6crD0ZdDKTQwyJOOYtfaiUVzZhVryKaPEPQvrgwa+Xl PBQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679905917; 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=wRmswFiWTDHAdnFgsbs9MdujlDQuLrbap9qquN6025Y=; b=boyz75mGzx3XI6lBlC9W0o1VTE8AoJ5t/M06JByIQebyAIa8QbB/f1fvLzyLF8D+Xb p9cbwbvlO4uFVZ7lls+eHW8BINaAWhl6E2yPj0cvvyGzZG7/LSmdaz2NKLijoX9gVwVb qgvDe1ezOsQK3UixKUCP0t1I2OGcms/WKqATHrtMvIiBwJ9Wbvd37xWtRYmEeCeHB5l1 w3PECipVrytwYD3rqS972LG7JZCm0SuM9fYMxoYIARssR3dybVWsPwCAaA0ncLvMAB+F xSG05PgXuLtwpVSkO0EewzRdwl1aRhn0Exruvp3vCrqOUttN/rfHFrmP3+2fL+Svgu5A EX1w== X-Gm-Message-State: AAQBX9d1Yt240jdz2w4XmAHG1QlrLo2mlVEYtvwafPY9U/Muo0oHZ3zM mPgLkdtLLzI0NqHTyzmvnXz8FU4aerdRVA== X-Google-Smtp-Source: AKy350YODumRf9/l2kzuzNxsvYnUVwcWTCGQrhGp5HD53dYdwXUDCs5xpF4jd9WXMPoIU5cEV9XEqg== X-Received: by 2002:a5d:4b44:0:b0:2d8:47c7:7b50 with SMTP id w4-20020a5d4b44000000b002d847c77b50mr8991866wrs.1.1679905916810; Mon, 27 Mar 2023 01:31:56 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:7887:5530:69a2:a11f]) by smtp.gmail.com with ESMTPSA id z6-20020a056000110600b002c557f82e27sm24353249wrw.99.2023.03.27.01.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 01:31:56 -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 v5 2/7] tools: ynl: Add C array attribute decoding to ynl Date: Mon, 27 Mar 2023 09:31:33 +0100 Message-Id: <20230327083138.96044-3-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230327083138.96044-1-donald.hunter@gmail.com> References: <20230327083138.96044-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 Reviewed-by: Jakub Kicinski --- tools/net/ynl/lib/nlspec.py | 7 +++++-- tools/net/ynl/lib/ynl.py | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py index 83de2a1a3cc6..6cc9b7646ae8 100644 --- a/tools/net/ynl/lib/nlspec.py +++ b/tools/net/ynl/lib/nlspec.py @@ -149,8 +149,10 @@ class SpecAttr(SpecElement): Represents a single attribute type within an attr space. Attributes: - value numerical ID when serialized - attr_set Attribute Set containing this attr + value numerical ID when serialized + attr_set Attribute Set containing this attr + is_multi bool, attr may repeat multiple times + sub_type string, name of sub type """ def __init__(self, family, attr_set, yaml, value): super().__init__(family, yaml) @@ -158,6 +160,7 @@ class SpecAttr(SpecElement): self.value = value self.attr_set = attr_set self.is_multi = yaml.get('multi-attr', False) + self.sub_type = yaml.get('sub-type') class SpecAttrSet(SpecElement): diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 7eaf066b115e..eada229402fa 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}" @@ -367,6 +376,13 @@ class YnlFamily(SpecFamily): value = enum.entries_by_val[raw - i].name rsp[attr_spec['name']] = value + def _decode_binary(self, attr, attr_spec): + if attr_spec.sub_type: + decoded = attr.as_c_array(attr_spec.sub_type) + else: + decoded = attr.as_bin() + return decoded + def _decode(self, attrs, space): attr_space = self.attr_sets[space] rsp = dict() @@ -386,7 +402,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 Mon Mar 27 08:31: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: 13188785 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 DC209C761AF for ; Mon, 27 Mar 2023 08:37:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233050AbjC0Iht (ORCPT ); Mon, 27 Mar 2023 04:37:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232802AbjC0Ih3 (ORCPT ); Mon, 27 Mar 2023 04:37:29 -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 60DE0A5D0; Mon, 27 Mar 2023 01:32:02 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id l12so7748482wrm.10; Mon, 27 Mar 2023 01:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679905918; 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=0IgR10FE6V1U4aJROuVTnUv5RQNS8iilsZvadRjruEI=; b=JZHw7DhT7u8gIH0Smm2TUiwFfNVOgRymnTFuntx9+v5kRedthdsF+9oRASwUthWgS9 TBJZm4MErtdCmrMASYYI8scWmA0n/rgCQvuU3sabPrKAJpgjMWCbptxwzRoPjEMq/0dZ cEgyBuBx0+rdAu48b4MqnfTST7L9oG5dWO0jCvrEoSYkA+wMXf3HI4Wo/TERbcGmhUzU 9qUClW8e5dg2fwxxrzZ5R3tnTUxaNLuq66+/Z/KYevD7sja9PgfzcicVMq4H9BmduCZt tamx+N9MpOQWfiq+j4ogYgZDvidRU+IsHkVo6LZ2hy+jriMv3YmFT+rC7w+s10zaAQ2R ytXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679905918; 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=0IgR10FE6V1U4aJROuVTnUv5RQNS8iilsZvadRjruEI=; b=ymZe5dIiPn6JM6Id2DDMBwdbJHPJJOpv/KNB9slnS3PT76Vybn26KG/xXo0MM1+uXK aZY5B/5HL+rCoLrwCsX9UIqm3ACkVeP+g/UF2T2qwh67FMgedCmyXng9C8umsUT9H/GU SUVVMq4+2aH7rWwFDdz1dh9TvU06glGiRAZ/a8JKny6a5JPUAG1koWgrOBEXkt/gYBCN WKtY9lNc9FcUnjmVrLSLU12knMDOaZCKxH/gO07q0WHepx2bsG53c+F+AbMW8L0303DF Tiv//9KgQOMH953GyJM3yKogwancPDC+gOL8ZK1QvsEztRNEX1T4ug46AsDZzPzDxFjX mfkQ== X-Gm-Message-State: AAQBX9dJJh5ozwCJh3I5ZAQ+3CHhMIrIffex2o1LyNmv+GUB4ly5VTVn nXsBSbszi93W1XruAIJ9+Hcrrk5pnbbgkw== X-Google-Smtp-Source: AKy350ZuXvN7xjarwrJag1Vlz0PDcM9x6DyHUanDlKuZ0dRUp12SN3JS8lvPgQ1WXq+j0KMK3I1JDg== X-Received: by 2002:adf:dc43:0:b0:2d4:e666:cab4 with SMTP id m3-20020adfdc43000000b002d4e666cab4mr9434614wrj.30.1679905918006; Mon, 27 Mar 2023 01:31:58 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:7887:5530:69a2:a11f]) by smtp.gmail.com with ESMTPSA id z6-20020a056000110600b002c557f82e27sm24353249wrw.99.2023.03.27.01.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 01:31:57 -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 v5 3/7] tools: ynl: Add struct attr decoding to ynl Date: Mon, 27 Mar 2023 09:31:34 +0100 Message-Id: <20230327083138.96044-4-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230327083138.96044-1-donald.hunter@gmail.com> References: <20230327083138.96044-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/nlspec.py | 2 ++ tools/net/ynl/lib/ynl.py | 15 ++++++++++++++- 3 files changed, 21 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/nlspec.py b/tools/net/ynl/lib/nlspec.py index 6cc9b7646ae8..d1e5f60af580 100644 --- a/tools/net/ynl/lib/nlspec.py +++ b/tools/net/ynl/lib/nlspec.py @@ -152,6 +152,7 @@ class SpecAttr(SpecElement): value numerical ID when serialized attr_set Attribute Set containing this attr is_multi bool, attr may repeat multiple times + struct_name string, name of struct definition sub_type string, name of sub type """ def __init__(self, family, attr_set, yaml, value): @@ -160,6 +161,7 @@ class SpecAttr(SpecElement): self.value = value self.attr_set = attr_set self.is_multi = yaml.get('multi-attr', False) + self.struct_name = yaml.get('struct') self.sub_type = yaml.get('sub-type') diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index eada229402fa..63af3bd9787d 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -102,6 +102,17 @@ 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: + # TODO: handle non-scalar 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}" @@ -377,7 +388,9 @@ class YnlFamily(SpecFamily): rsp[attr_spec['name']] = value def _decode_binary(self, attr, attr_spec): - if attr_spec.sub_type: + if attr_spec.struct_name: + decoded = attr.as_struct(self.consts[attr_spec.struct_name]) + elif attr_spec.sub_type: decoded = attr.as_c_array(attr_spec.sub_type) else: decoded = attr.as_bin() From patchwork Mon Mar 27 08:31:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13188789 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 9EBE2C76195 for ; Mon, 27 Mar 2023 08:38:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233216AbjC0IiE (ORCPT ); Mon, 27 Mar 2023 04:38:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233037AbjC0Ihb (ORCPT ); Mon, 27 Mar 2023 04:37:31 -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 09D74BDE7; Mon, 27 Mar 2023 01:32:03 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id r11so7756253wrr.12; Mon, 27 Mar 2023 01:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679905919; 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=VsN1qM/iNlNKJZHZAqCBrKK2RA/zU2Iy4nTTO5WUc/g=; b=RY5nhqKcRUkWtzfIdOvJ3IFZQjZq54zGARvWoCO/DpfrSNQ2v3+7uVtPx/yyylIo9G pcUQ/QEYSf9G1fYn8ruseqjqOckMab1j7p4kAuqudoPmNJgsV3lB18o64VqFxf2HTVq8 FHqESLvZ+4HTTwlEdSiGjvuFXwuGbzajGC8NOW+T/y4a6fVrtWZC4IT0bzxjzj0RtToX G1d29NqvDcO8z6GOOVxONPqjpA6cIXQyDWUbUFWynAMZZJC6rCr4bAmLI8aqBxOYC49f ZbMUNxN2CZWZbgYHwk7TDqvxM8d0bpIP0LXwivge2q4rY/oWhlrFUVINI7GdQ37k6eQm yzrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679905919; 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=VsN1qM/iNlNKJZHZAqCBrKK2RA/zU2Iy4nTTO5WUc/g=; b=Btan0MMlJRK5ZzK4zmf7Evv0q2We8XM/+T4wn8C4u7kZQQB7nufWR6vgpnLLHyxPe5 eo7rvbaDaRMZqYN/XmZq8wIqrDVoC5wVxjWg6lt8pWap2lcx9ecCoCyWFqa1pn9LNeqA jQEu2qG1q6EH9xqTZ378mF90lDN5Ggfpubk1L/1jNYdolJq+e4qzEx/m/XE89LjJrVe6 CNbBYgjC0iVcihLBELu2j1B3400M27mE49Yfbe/L4/P2QkrzgMfmleqf/kBqWHGlr+6h zGzkllWSvhQO+kP+9P661FuURG7sZbO28h1+xTtxVeoTe3oJA44zvYGP1yroA1q27VK2 XLVg== X-Gm-Message-State: AAQBX9dAWCo2ziXQy3lqf1pJuH+jc/wQuslQf4Mf8/Zpf3jsY5/Nz+Zz MdoRkIYVu9he3TfPHLznRl3NjC+IQ8wWnw== X-Google-Smtp-Source: AKy350Zu5lg5ZzPmlUJq1f7rCFctfxaQ+eRxcBwd2ar8bodr3zszXYHcOCMoD71aDctrVvvwRjjK/w== X-Received: by 2002:a05:6000:114b:b0:2ce:abea:3de with SMTP id d11-20020a056000114b00b002ceabea03demr8494268wrx.45.1679905919350; Mon, 27 Mar 2023 01:31:59 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:7887:5530:69a2:a11f]) by smtp.gmail.com with ESMTPSA id z6-20020a056000110600b002c557f82e27sm24353249wrw.99.2023.03.27.01.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 01:31:58 -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 v5 4/7] tools: ynl: Add fixed-header support to ynl Date: Mon, 27 Mar 2023 09:31:35 +0100 Message-Id: <20230327083138.96044-5-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230327083138.96044-1-donald.hunter@gmail.com> References: <20230327083138.96044-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 | 11 ++++++++++ tools/net/ynl/lib/nlspec.py | 21 +++++++++++------- tools/net/ynl/lib/ynl.py | 24 +++++++++++++++++---- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml index d50c78b9f42d..b33541a51d6b 100644 --- a/Documentation/netlink/genetlink-legacy.yaml +++ b/Documentation/netlink/genetlink-legacy.yaml @@ -261,6 +261,14 @@ 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 defining 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 +301,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 d1e5f60af580..06a906d74f0e 100644 --- a/tools/net/ynl/lib/nlspec.py +++ b/tools/net/ynl/lib/nlspec.py @@ -263,16 +263,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) @@ -284,6 +285,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 @@ -324,6 +326,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: @@ -397,6 +400,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: @@ -408,6 +412,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 63af3bd9787d..ec40918152e1 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -278,14 +278,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): @@ -509,6 +517,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) @@ -535,7 +550,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: @@ -545,7 +560,8 @@ 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 Mon Mar 27 08:31:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13188788 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 8BE84C761A6 for ; Mon, 27 Mar 2023 08:38:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233030AbjC0IiA (ORCPT ); Mon, 27 Mar 2023 04:38:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233029AbjC0Iha (ORCPT ); Mon, 27 Mar 2023 04:37:30 -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 93617A247; Mon, 27 Mar 2023 01:32:03 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id l12so7748626wrm.10; Mon, 27 Mar 2023 01:32:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679905920; 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=YtQgmvrLx05oF7czPID/aIMRXHg4M3b3SCDAKauuwd7AQhSEnAkNVDUAw6lknTbbOa S5zHpg4wSdLaMljnUEq5os+BTLyc+Z4cLfOlI15gtIiGgGJeGsowlpmTRHDrruHoDwSG 70efjXBcJPEhXFkzisdQREVMXf36rkBhmrViCE3AdKLYe59kRdE4C9MzsOXIBqZrCCoc Y1eTgWSg4Jv4vPqmBEUvWAaJozR98cIqmudrMzwzqNfiQPhKiUzC/i3Ro4U/DbMSya1s bbx/Vy00Gw7RZQvuiK5refBM6UzHeHF1/N1t9B7ki0QFU1gaEVJTMFUhr2mI9oGgmuWX x5Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679905920; 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=XMhOA2gYEq6MjOXRhzBW0xbLa7P+CNuqFko5dqEc+D2eA8iSCYR+0wfCPOjzaF2gqQ acUw3zDXeR84kusR5BZYRDoFXsXZpum9RSas4p2y59Z7pQUoPDt7YT5lQ8rys7PAwwHo 4Ke/sZi9NbPIqxs4ADA6/QWe1iE1N5e005HbYts1tPAo6pD7hj3QAMehSobMvZtjsL8Z GlsSpZavbGbpfRom06XenhLEc+mp2ZmBkwZ+bK+pi4FpzCaZR9WrYObZ2jpXDxAsifXc T4l4fhQRWMhPKe4VsuXI0GhsUC08dnY8pCWefrAjPp5I++GQAcoP+pVkScFzcL3YGHvZ cuQg== X-Gm-Message-State: AAQBX9dXBunWwWBVfWSLF9JI42X5aRgt6ZpyKTQpVzNtK3dmoxxwYNf6 1/e1NyAd4YpMTT2O11F1n1MNSFRCYyjHjQ== X-Google-Smtp-Source: AKy350ZyYBwmEVI8F/eXSkK603ntFgHYL63twRuf8Rm9ECXWG4nA2bRkSX1B36vkuCG/4WTpiR+76g== X-Received: by 2002:a5d:6845:0:b0:2d0:3584:27f with SMTP id o5-20020a5d6845000000b002d03584027fmr9008483wrw.68.1679905920465; Mon, 27 Mar 2023 01:32:00 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:7887:5530:69a2:a11f]) by smtp.gmail.com with ESMTPSA id z6-20020a056000110600b002c557f82e27sm24353249wrw.99.2023.03.27.01.31.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 01:31:59 -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 v5 5/7] netlink: specs: add partial specification for openvswitch Date: Mon, 27 Mar 2023 09:31:36 +0100 Message-Id: <20230327083138.96044-6-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230327083138.96044-1-donald.hunter@gmail.com> References: <20230327083138.96044-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 Mon Mar 27 08:31:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13188787 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 518E1C77B6D for ; Mon, 27 Mar 2023 08:38:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233072AbjC0IiC (ORCPT ); Mon, 27 Mar 2023 04:38:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233035AbjC0Iha (ORCPT ); Mon, 27 Mar 2023 04:37:30 -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 B2D05A24B; Mon, 27 Mar 2023 01:32:03 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id l27so7783434wrb.2; Mon, 27 Mar 2023 01:32:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679905922; 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=71KoEvNw1a5K58EQ9MffE/8r5VSXHU8fzu2wgupbboU=; b=J4RsoRpBnwN1MqbboCHaHWoIINzGdRVo7e+jhZ+2JH7+YVu8z/mUJO5beVgJZmmx5y O3EArjWy5A7cubyHbMv5vYaMLQs67VBGcKnT8jJGrdSAhENwCQzvndRIWkFt0ZT4wQN0 PV48JFRZiYwKl+OYU68DnCUyphLMngKVp6Afu6U+aykBAOd5y2OMThul+JrmmpyD79yL +WuGb1YBKG5Se3RtW6vLB4kkMl7YUr4OdflJFaDr8fCtoqJNyB5ZfKXEnLJMgbBWSe2d sy2/MFmGJzYZcvRxdO2AmQzwX44/pcTirBe4a6iGMIlAPW9QqOcf943M97m/xEZGE1G1 7G8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679905922; 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=71KoEvNw1a5K58EQ9MffE/8r5VSXHU8fzu2wgupbboU=; b=xnd2FCzGrZDNNsIDK8gXlOZIAjGOIdDV+bVn7BTG2FPgpmT9GxzXU1eugNCFk8wfoN ilILH1HvMRXSgtByUimzh4z1X9zKtZSbjv+bsfce0Y7V4hymIt6AekkTvyItwuzrSFa7 DKpbuHARzPExta4ZBAbXOSHYYY/idbt6HGiP3acRRVL9e7wVwOVz5m+4/haFAzsCfO0z jEE5PSFtUdHgYd0yRiKgCEInDusXih6yban3Xwv9qhCvNcAiZ/RrkCoWHv5zbGl4H5i3 P4rOaIXX/uDV0rWILRmZCGB6TWDoJcYOiIkQHs+Jf/W2yOSQfq+xmBgs/Sz+Syw97Zpz Sf5g== X-Gm-Message-State: AAQBX9eE+zP91xlG/qk0YXt1Wz2eMW5E05PqekHCx/sXJDWHYebD20QP us0qLOfYDjo5oxUSzgcdwotLtCmwJPmyLg== X-Google-Smtp-Source: AKy350aM6lYL21FU3RM1r+IrDmd1X4g5iCKGkf8lGXaX/M48js6Bgm8kyAD4RinWQiSktmBRSQh2vA== X-Received: by 2002:a5d:5343:0:b0:2ce:ada5:325d with SMTP id t3-20020a5d5343000000b002ceada5325dmr9156319wrv.37.1679905921856; Mon, 27 Mar 2023 01:32:01 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:7887:5530:69a2:a11f]) by smtp.gmail.com with ESMTPSA id z6-20020a056000110600b002c557f82e27sm24353249wrw.99.2023.03.27.01.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 01:32:01 -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 v5 6/7] docs: netlink: document struct support for genetlink-legacy Date: Mon, 27 Mar 2023 09:31:37 +0100 Message-Id: <20230327083138.96044-7-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230327083138.96044-1-donald.hunter@gmail.com> References: <20230327083138.96044-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 Reviewed-by: Bagas Sanjaya --- .../netlink/genetlink-legacy.rst | 74 ++++++++++++++++++- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/Documentation/userspace-api/netlink/genetlink-legacy.rst b/Documentation/userspace-api/netlink/genetlink-legacy.rst index 3bf0bcdf21d8..b8fdcf7f6615 100644 --- a/Documentation/userspace-api/netlink/genetlink-legacy.rst +++ b/Documentation/userspace-api/netlink/genetlink-legacy.rst @@ -162,9 +162,77 @@ Other quirks (todo) 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. +Legacy families can define C structures both to be used as the contents of +an attribute and as a fixed message header. Structures are defined in +``definitions`` and referenced in operations or attributes. Note that +structures defined in YAML are implicitly packed according to C +conventions. For example, the following struct is 4 bytes, not 6 bytes: + +.. code-block:: c + + struct { + u8 a; + u16 b; + u8 c; + } + +Any padding must be explicitly added and C-like languages should infer the +need for explicit padding from whether the members are naturally aligned. + +Here is the struct definition from above, declared in YAML: + +.. code-block:: yaml + + definitions: + - + name: message-header + type: struct + members: + - + name: a + type: u8 + - + name: b + type: u16 + - + name: c + type: u8 + +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 Mon Mar 27 08:31:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13188790 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 328CCC76195 for ; Mon, 27 Mar 2023 08:38:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232917AbjC0IiH (ORCPT ); Mon, 27 Mar 2023 04:38:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233254AbjC0Ihc (ORCPT ); Mon, 27 Mar 2023 04:37:32 -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 501C25279; Mon, 27 Mar 2023 01:32:05 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id l12so7748766wrm.10; Mon, 27 Mar 2023 01:32:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679905923; 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=W3Pnhk6WXCTvMYshsQQxsvUwuf8HT7xMnse1nDPGhPo=; b=qacayhcU8j7TjHpxJKF4fFiwSBWH52U1tTZBx/KPUwncWUUqrrFGQMkFuA5Hk3Uqm7 mFfUzbbEetwcvaFCOeY+7jfynuUBn6PdLE0mny2ODwdpJgLy66XIydwt53hiHmGXec+J jZm7gYy5OYlTyfndam8Pg8p9DVVeLoGdqXI7SXVNcgzjLU5xoNaJ2t+5nXqflkhWDjbl GokbCOO2dpT8bxo7rQCszJftp4KCqULc1DffKMpOveo6BDWg7NVGu1Z8eVZZDhgBxjAh KESM+RlJjyiCNwm+LM8e5rU5T/os4lTPWHnFuFnok3MByxnFZZUUJ3rKAraZLCU40mqj ECNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679905923; 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=W3Pnhk6WXCTvMYshsQQxsvUwuf8HT7xMnse1nDPGhPo=; b=zvnM8730el/i3J2SovR2EXlxhtRHPfyrGZOpohdHThzIEQWMe8I1AsWpjhIh/Ux9j9 N4qb4Uj4LDpTfTmmqQWOV6EuRu8Sbb7YXDXv6T8oXW3KSW4xyTUcKveETnqsD+ow2MSu wDOo+sWFNxAqRiEbby3KOv9KF0kRt4vHSktdsOYl7+whcdzXmQtsNY+nQmXEcRfo+4xg heP2rzob7y2EzbR2JO+ovdLj2Q7NoIyPeCBpEJihN+xg5inksJEz+SkVo5tdSAdUur/n 8B9/hFsOMRj3MHTefkLIAjNiM0CN7wXdQD2FMnW3H+X+pAA2MY6zeZahHaDyiR4HLVvS Zg/w== X-Gm-Message-State: AAQBX9eFAPOAjp3qJNUkrRwjqT7tDF3ODub61mGTJZwWW2DlncmFdQYK 79GiFiwS5kO+JcVAZd8NcVAURJdWqMK4Cg== X-Google-Smtp-Source: AKy350ZHmJPagplwUBfqVwiTe6cpM9txTphF28audlh2ksHNQLFtkVRLoXCntUyVg96Tigwx4+FMAw== X-Received: by 2002:adf:ef83:0:b0:2d4:b9fc:90c1 with SMTP id d3-20020adfef83000000b002d4b9fc90c1mr9282039wro.42.1679905923043; Mon, 27 Mar 2023 01:32:03 -0700 (PDT) Received: from imac.fritz.box ([2a02:8010:60a0:0:7887:5530:69a2:a11f]) by smtp.gmail.com with ESMTPSA id z6-20020a056000110600b002c557f82e27sm24353249wrw.99.2023.03.27.01.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 01:32:02 -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 v5 7/7] docs: netlink: document the sub-type attribute property Date: Mon, 27 Mar 2023 09:31:38 +0100 Message-Id: <20230327083138.96044-8-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230327083138.96044-1-donald.hunter@gmail.com> References: <20230327083138.96044-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 Reviewed-by: Bagas Sanjaya --- .../userspace-api/netlink/genetlink-legacy.rst | 14 ++++++++++++++ Documentation/userspace-api/netlink/specs.rst | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/Documentation/userspace-api/netlink/genetlink-legacy.rst b/Documentation/userspace-api/netlink/genetlink-legacy.rst index b8fdcf7f6615..802875a37a27 100644 --- a/Documentation/userspace-api/netlink/genetlink-legacy.rst +++ b/Documentation/userspace-api/netlink/genetlink-legacy.rst @@ -234,6 +234,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..2e4acde890b7 100644 --- a/Documentation/userspace-api/netlink/specs.rst +++ b/Documentation/userspace-api/netlink/specs.rst @@ -254,6 +254,16 @@ 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 +~~~~~~~~ + +Legacy families have special ways of expressing arrays. ``sub-type`` can be +used to define the type of array members in case array members are not +fully defined as attributes (in a bona fide attribute space). For instance +a C array of u32 values can be specified with ``type: binary`` and +``sub-type: u32``. Binary types and legacy array formats are described in +more detail in :doc:`genetlink-legacy`. + operations ----------