From patchwork Fri Mar 24 19:18:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13187293 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 01BE3C76196 for ; Fri, 24 Mar 2023 19:19:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231504AbjCXTTY (ORCPT ); Fri, 24 Mar 2023 15:19:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231501AbjCXTTW (ORCPT ); Fri, 24 Mar 2023 15:19:22 -0400 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36B3646B6; Fri, 24 Mar 2023 12:19:21 -0700 (PDT) Received: by mail-qv1-xf2e.google.com with SMTP id o44so2331330qvo.4; Fri, 24 Mar 2023 12:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679685560; 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=Q0fJDaQeW5wvSe+fFziVQHt66kLEB3eUMJmm3rMpxvYPtNmTUpFRtbDQBO+5ElSARJ 64fTwS+OK0heENwMHAyUzSpu6FIWoiMfTZiZlre47MK5v3AIhHom1URq1/perGThaF66 TZLoFHS6TMuSYtjVb1qvPSrAIWaF/sQx4WxEDQljo0RzyvDDt34LuCise97NPXztNzks lhaDwnD4LIl4v87tJwZ21ArBH6sUnYbD75+hCQVwTC0UlacMED+Fpg05sOAj/nyR1Q9H sYPFGZBeAIFjelLl0BPWDufzPhJegiKmdvhEjHR/rTuodhCl3wbHyAYCbrsI68cKyBf/ JE1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679685560; 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=Yrq2no1x/YrTThFgdXgSb9MDYKc5LEPDJwt8X2qJrQfiZiYwfRswFQq6ebQpVWm4FA 6G0fMTVUqtGDc2Dk6OY4YF3KTpesn9lkSxfmqffRx19H1oeHn0ELRfySlFg0L0MJW5U9 GuqUOdYtdQglZtW3J2axz59lYCwjFkWB2+4JxUBjizOAfkVtZamzNLMBXYosBWOelG8c pu5TPRZbYmoZUZqqIgj7UD//4mBLMlXtLmhhRJco9bDKSPsGZbQyhyksMLOngnjUk8HC 76sobwR4epf2G++tu4swm9TJJmEiBDg8/6Q0Z7LdoGHzZhgDamUgHb9Ifp82JOmGlc/M hXTA== X-Gm-Message-State: AAQBX9cfl5jYu49/c2KoJ8IBj3K1vG/wTQd0mRZ0W2uJbt9EZkUMnxlE FRFfOX6Dtwx/4+mp2vurEtWL7jEawg0BsQ== X-Google-Smtp-Source: AKy350bo8Hgs7Rh3tiaqRdDPHiCMZq8VxVZ8Kf3j8Pp3qZloNsfj2g+PvtQtJ7HHiotz2aJVArznlQ== X-Received: by 2002:a05:6214:2604:b0:5ab:e259:b2a9 with SMTP id gu4-20020a056214260400b005abe259b2a9mr7661224qvb.14.1679685559848; Fri, 24 Mar 2023 12:19:19 -0700 (PDT) Received: from imac.redhat.com ([88.97.103.74]) by smtp.gmail.com with ESMTPSA id cn5-20020ad44a65000000b005dd8b9345e1sm900141qvb.121.2023.03.24.12.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 12:19:19 -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 v4 1/7] tools: ynl: Add struct parsing to nlspec Date: Fri, 24 Mar 2023 19:18:54 +0000 Message-Id: <20230324191900.21828-2-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324191900.21828-1-donald.hunter@gmail.com> References: <20230324191900.21828-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 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 19:18:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13187294 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 96237C6FD1C for ; Fri, 24 Mar 2023 19:19:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231263AbjCXTTZ (ORCPT ); Fri, 24 Mar 2023 15:19:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231194AbjCXTTX (ORCPT ); Fri, 24 Mar 2023 15:19:23 -0400 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9648F49EE; Fri, 24 Mar 2023 12:19:22 -0700 (PDT) Received: by mail-qv1-xf2e.google.com with SMTP id 59so2241227qva.11; Fri, 24 Mar 2023 12:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679685562; 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=qlsDeibRNspBbL1ZNhnut7pdMXrpf1TC9rqstiR62cY=; b=QeWSWZLy+ABbDTHhi7d6A1TOkmCB9fxqqp+/D9sGrV/olNZSJWoG3/fa++rx3KywY3 x7CI1ZAMkxALwtF9cjlu9443l1sLyopR+7JBj5WRO3xtYBvzdfTS4XXvr9tGjeEX4cAH pCcT0kntu9crF5tXz2bTgcGhMe1ORQ7FWoRq8JH7pvLOkOKCRIRnR/dY2sL+Yq3VDxxq vMDbDfKuhfcak+7s896ZSJbfL/4xLfaZJW7PoEagC95A1GvFf6M1mNmQlbB3qk8T4obZ nZw56arIPved2+vJ8PvG33OW9BvHmxTuoUElQvB2WZTW2Qq1WF/6NauYmEIFh07nL5TZ cgAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679685562; 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=qlsDeibRNspBbL1ZNhnut7pdMXrpf1TC9rqstiR62cY=; b=ldfvzs4zCrnJzwSqco5ysJcY81ji/SejxqFiR9RZeWTaogByEHmzbQUpWsafZFquJS qupKXEPTVOUpviDbP0ymZKtWIhU7zE6c8ptu8rtVxwNeFxF6/+rIzSOKimC3y/Qa489I jaxmXLGeodN15ojCp8GKl9LDJUkcRS2qFGcF6Wzxw6lgrr7cwHVgWz9aS50fwVpbpPCl sbkGQqlHvsj3iMjc9zeCV1Hf4XG6ttMwN61J6ugvMOWkaQl6bFio5yFeHWiohWZthife tcTm8e7D6Kkuy40zFkidxGAcqbBb59qAjv5dCIWDI9+nYaONFgfk950H7o//pPs5Siml Ro4w== X-Gm-Message-State: AAQBX9ebZSjeHng7+E1p+/15HVIjPfD+t06X57yK8P/DlHFg33G4g5l4 vbJlJh917aez1nGv1z+qcOvUrxktzzc39g== X-Google-Smtp-Source: AKy350ZphiSzn2tLykGsJZ5OnvGLX1c5/c+g55LVtHMdYHjBc7WBN+sVlRyIDqd5IwaPiumbtn2K9w== X-Received: by 2002:a05:6214:5299:b0:5b4:89b4:1af8 with SMTP id kj25-20020a056214529900b005b489b41af8mr6260209qvb.16.1679685561782; Fri, 24 Mar 2023 12:19:21 -0700 (PDT) Received: from imac.redhat.com ([88.97.103.74]) by smtp.gmail.com with ESMTPSA id cn5-20020ad44a65000000b005dd8b9345e1sm900141qvb.121.2023.03.24.12.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 12:19:21 -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 v4 2/7] tools: ynl: Add C array attribute decoding to ynl Date: Fri, 24 Mar 2023 19:18:55 +0000 Message-Id: <20230324191900.21828-3-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324191900.21828-1-donald.hunter@gmail.com> References: <20230324191900.21828-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/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 98ecfdb44a83..b635d147175c 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}" @@ -363,6 +372,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() @@ -380,7 +397,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 19:18:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13187295 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 819A5C76195 for ; Fri, 24 Mar 2023 19:19:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231665AbjCXTTc (ORCPT ); Fri, 24 Mar 2023 15:19:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231636AbjCXTT2 (ORCPT ); Fri, 24 Mar 2023 15:19:28 -0400 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00ECB49EE; Fri, 24 Mar 2023 12:19:24 -0700 (PDT) Received: by mail-qv1-xf2c.google.com with SMTP id l7so2315728qvh.5; Fri, 24 Mar 2023 12:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679685563; 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=bHqnuX3WU+YARDnObs3l+MTKnKtxe8++rZbFFZTLe6U=; b=HPvXhM8QR0gYIpFBflj4vQOC6paEHAoktF/xyautsfrGvNkYCtnxELpPrpsHqb/q39 XfhYFwVa5pms9ODtRvRh68xRLafmgQ6+/o7v3/QmO7223bfHOaYYCmFGGvawgJGPswac 3c/0LEzfRr9iqab4rRl1xKMSD77kScpanS6YNnhF3mqii0lyjgyurunPcl3ppDyzQNcF VfnbmErSqFXmHXGHhtYVKmR6KE/9Qp7B2FwHWRXbJkw8pXbTF+ea+2W6SxoMC91rL1zs dmQa4jqc+wI+/YRYZdWsGIka8DOiWrou3sl9hFlJdw+Ha607+XYdZ+73WeNSA5oMBJQ3 xq1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679685563; 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=bHqnuX3WU+YARDnObs3l+MTKnKtxe8++rZbFFZTLe6U=; b=cwVNKYBdBFOhsNL3aS8kkkMIVs58abu+UTsfNNVyZm9lgszpWZhYM/maQt7ZLnbS1x fqGQUuYqHe2pnsQwXkD++FEkZIrVqDzGUpnAWHI1KMPWPjzBqZo6A94DUMaLQm9Gzgme ComELhZPZrpSyyAV7nZGca6EUeDAW/eVoF8/OezLlSLMEJZUVBoZccmWhgb1DL+xomui JlOmoA0brDT5P3pzcCVSjvn1Tdi3BJYWiBxGNuvJsf+swCVA6eC3oZxp9qHDQpsgaOh5 fbkwgGbrBGf8k+FK36RrsfY5pGjiPYAax1h25NlApwm23JVSKd9AR/g5SurKYxIeaPIl PNow== X-Gm-Message-State: AAQBX9fNaI9PlJtGWnRQ+PjKhYDKXSFBhDkLzAwqYPsB5aJCHGJPDCWr 5U/xK8MWobL3rLnY6IyI4/Kw7QKEozOViA== X-Google-Smtp-Source: AKy350YcAW2LlVWi/AD4kREbhmf9I5m/Hf6wD2vyplr2p393yKhw8aHN1gsizxfI/9yTuAeSshUxow== X-Received: by 2002:a05:6214:2528:b0:537:6416:fc2b with SMTP id gg8-20020a056214252800b005376416fc2bmr6571553qvb.52.1679685563610; Fri, 24 Mar 2023 12:19:23 -0700 (PDT) Received: from imac.redhat.com ([88.97.103.74]) by smtp.gmail.com with ESMTPSA id cn5-20020ad44a65000000b005dd8b9345e1sm900141qvb.121.2023.03.24.12.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 12:19: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 v4 3/7] tools: ynl: Add struct attr decoding to ynl Date: Fri, 24 Mar 2023 19:18:56 +0000 Message-Id: <20230324191900.21828-4-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324191900.21828-1-donald.hunter@gmail.com> References: <20230324191900.21828-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 b635d147175c..af1d6d380035 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}" @@ -373,8 +383,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 19:18:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13187296 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 258DDC6FD1C for ; Fri, 24 Mar 2023 19:19:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231668AbjCXTTe (ORCPT ); Fri, 24 Mar 2023 15:19:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231194AbjCXTTb (ORCPT ); Fri, 24 Mar 2023 15:19:31 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D059ACC0E; Fri, 24 Mar 2023 12:19:27 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id x8so2266793qvr.9; Fri, 24 Mar 2023 12:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679685565; 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=zpYXcQJL1HWo7zltrRDmHHdajaouwLFByepqHsRLla8=; b=BiFGKTK9U/J+UBEvY9aSpicrxl3LcuKY3ePZJpctL6aclDuwk1Gb7Hm+/jhVi2fnAJ CXimbb81YZj+XcmKM2BrLhW8ShTRtyXd15rgmX2QpT7d48Dy02sQersSimbXS6guDURT RBUnKRETA1S2q67qQjArPOb8YM7NQ+w5DOtlE1TLu5Vr/cG8uXZAWgQw6MY/TnlfGcd/ O1roskjIeaH/Ww6VgHf69oqGVe7a+Ow0dWT1CeZQLiDJIeFMMChFY+dGzZYYWksS/1m9 4ozYE+Sx+AQR1c0Du+PPWQRcjrFL+ED1Y8hMpgIw/g+QBrhqtbcGaALB9tDrypQYc2me gz2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679685565; 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=zpYXcQJL1HWo7zltrRDmHHdajaouwLFByepqHsRLla8=; b=4GRZKGa3HAeg/XBytnw9DLf2y9JG781LPP2gJQi3Us8NiFp2carzk/TY3nPzBo95TH /8YBrjYFNklDXKV7xlfEufP6KjC4lZyCslMIrB00aA+O+Cqm/+a96QmqegKp8/wj4OcH EO+h2dplLCfq834bhmiz5fUNGmB1kdqvtZSTY5ALf2pAkO9WrwnNPAYxVnqlX1FWEYFd aYZ4Gq9uxs3zeyAWyl28QFNl6G/wvqL3ZBxbQa7JCYXpWFdEqqUgvHZ3f2mz5zI+ht6+ UCsVRDVf/5ne8iD3DtQORPwDVVmg8M2+W4oNzOYc9OIhncGjU975y8VWhtfhlIsEUdYw HO9w== X-Gm-Message-State: AAQBX9ff390r632RykOVG8i9VDMo2ktzSIS7gs6oty7YETaI6BKwmzMo 816/jh7GkywnuB+9spiZ6vuRWjjdjKNQUA== X-Google-Smtp-Source: AKy350aml5ATaTGHLm90L9vYhTuAwn8/hh1SWlzpyxoobhlNIFiMOij30soG1FGMon+BW4F2RsAV1w== X-Received: by 2002:a05:6214:d49:b0:5a8:d23e:9ab2 with SMTP id 9-20020a0562140d4900b005a8d23e9ab2mr7281999qvr.16.1679685565423; Fri, 24 Mar 2023 12:19:25 -0700 (PDT) Received: from imac.redhat.com ([88.97.103.74]) by smtp.gmail.com with ESMTPSA id cn5-20020ad44a65000000b005dd8b9345e1sm900141qvb.121.2023.03.24.12.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 12:19: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 v4 4/7] tools: ynl: Add fixed-header support to ynl Date: Fri, 24 Mar 2023 19:18:57 +0000 Message-Id: <20230324191900.21828-5-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324191900.21828-1-donald.hunter@gmail.com> References: <20230324191900.21828-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 af1d6d380035..4d206c46a087 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): @@ -504,6 +512,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) @@ -530,7 +545,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: @@ -540,7 +555,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 19:18:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13187297 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 6A657C76195 for ; Fri, 24 Mar 2023 19:19:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231687AbjCXTTg (ORCPT ); Fri, 24 Mar 2023 15:19:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231630AbjCXTTb (ORCPT ); Fri, 24 Mar 2023 15:19:31 -0400 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2410E5B91; Fri, 24 Mar 2023 12:19:27 -0700 (PDT) Received: by mail-qv1-xf2e.google.com with SMTP id o44so2331556qvo.4; Fri, 24 Mar 2023 12:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679685567; 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=PiI0ou8xBk2aJt3wwZQP79EL09Nrc2NFr/F9Zl44BxZCBhYhD2tVkQiNLKbjz7XPA4 yVcNkteeov7b0WNU6tjMX/YoowivDXcMlAJcbO0Xmj1tk4dUiAzB08A8hKFI/5fWa/R6 y6d67KseseGM/II9oMG4u+8tpmWRChxfb0j6EQGldW44MyuD2zhb120zPhp4/nBBNq2e FeTtee2Hg4iQr09/3U9f+Qqm4zwtmlYbqxZs7R2IK+svG+JEGsewpQMchiCYsbuGhePC uFUa+G/5Ei5YuHvda6QqBlQplk+cGPa43ll57R1IXFsrQY7Zwp3A9jI+qFcL+/f2e/0G TuUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679685567; 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=X9xz8gbK725tamkCIKiNVxTs6/yivFMbzw+Bj7Lvrs755BUPIR/3R0StHFIeLVGloM UensOaGHjWARaMzhjPyr+J3gAgtYpgWFgW9KVE+1aDYM0P17PbjBgh90bDGypknVJbKF NM2vU+fik4Ie4ABUTpqVh1XWezid98ZEB3DtFjUJnuwNY8icEtfM3mv5kys9pUQcaPv7 SkTFLMyw2+XzVe5P0z59WEt3KchN/EkyWudXCQZFzdoHYLqz0Nh5Ttv2qBKawfK5XcRE RSbYSjrsOgXZ7DxOU3MZv0hCWrQe7LrnIi2SVQRl9KfkekFiMrDZOtoYvHVUaxz25JxD EJKw== X-Gm-Message-State: AAQBX9eYQaycnkcfV62VrlfNPAyPnR57lCxJyXG+buhcuL12lBZb9poY ZZggwcWQVpvaqHjG3cNs9O89k/JXK3MwWg== X-Google-Smtp-Source: AKy350YGC5nbPO+QWcn8EDd51oowv0KOTjFNeDRhOVf5SjExifDqbsThn36q8RhoNeYfASp673ls7g== X-Received: by 2002:ad4:5f09:0:b0:5c5:95db:859e with SMTP id fo9-20020ad45f09000000b005c595db859emr7086370qvb.31.1679685567243; Fri, 24 Mar 2023 12:19:27 -0700 (PDT) Received: from imac.redhat.com ([88.97.103.74]) by smtp.gmail.com with ESMTPSA id cn5-20020ad44a65000000b005dd8b9345e1sm900141qvb.121.2023.03.24.12.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 12:19:26 -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 v4 5/7] netlink: specs: add partial specification for openvswitch Date: Fri, 24 Mar 2023 19:18:58 +0000 Message-Id: <20230324191900.21828-6-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324191900.21828-1-donald.hunter@gmail.com> References: <20230324191900.21828-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 19:18:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13187298 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 9A147C76196 for ; Fri, 24 Mar 2023 19:19:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231644AbjCXTTj (ORCPT ); Fri, 24 Mar 2023 15:19:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231667AbjCXTTd (ORCPT ); Fri, 24 Mar 2023 15:19:33 -0400 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AF987DB4; Fri, 24 Mar 2023 12:19:30 -0700 (PDT) Received: by mail-qv1-xf2e.google.com with SMTP id t13so2353119qvn.2; Fri, 24 Mar 2023 12:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679685569; 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=IdjRrV4huFStxRZVcAWPiu9Pb83m8hqa7lzJr3mNNmIi+I1aNSdpUIJFYE5Jt5f/nC 5VjcT7jJWlkw5MhmwuQl3jTQJ2vYFEFRMuK5s+ll2sY0YYLc8nVEoiGPgZ2ZVGTkmUGC 8EWyWBP9fWitUrODpIWTrx9ML1JVBHO05UtRJwbJaLd2QdFzHNg1JYgZLT8DL6TiXeZ5 Q3JFAsxtzYytsYN1ob/zsH7lo2AuFVo0Kb36ePKEB2WDItXwsDlnwVCkK0DeKPgJwQuY F2qXFa7PnSk94XcAVhnPItkVa9Rem2SlzG3Z7JnDniS5RDBOoJJogRXN713I4tbW+nl3 ikZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679685569; 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=rBHhvQAXcfrO90P+p6zdc2kSeifyVi1dpzWiTTFAAQh/X36ylM6qeEPFF61bwubkP6 Me9GREnsskwL/BP0bK2iBOhvU2S3Kvh4+N6ckUA9v16BTdrQjXGKEg8zknPssIxkabe3 syBnzvyGVzIfqa4c14c+RZ/xLGfK3YwtLhtaOZBf1OphfPKRQbey0JTpJ889t825WwJ8 EUETAWlUQUt/4dhFSedsIFOkzX7Jdbx98jtTo9TUvQJN0Uo8PJPfl8Qefpud34xwstoa Au6pvdHnhxsoPTQvO4SJh3r/IYAFHMFiEmIS2UR21FtIJ6ze235PLo+03V5zoJZYA0f3 HaHg== X-Gm-Message-State: AAQBX9ezxMNbUN0QEvqHOd6IlvEsiVcUkukE0d5vYm+WCKR55Bfs3F57 s7CDkuZo6p6aejLLfPL8iBHDqIeQPm4cCQ== X-Google-Smtp-Source: AKy350bjit81gVwWsxutHwcNnU2eP7zuLFpGQcRHmxKDZFZuV/LhRCIjPgwdYKMt5fFhL/JlEzSV/w== X-Received: by 2002:a05:6214:29e2:b0:5d8:ed66:3098 with SMTP id jv2-20020a05621429e200b005d8ed663098mr5676510qvb.42.1679685569087; Fri, 24 Mar 2023 12:19:29 -0700 (PDT) Received: from imac.redhat.com ([88.97.103.74]) by smtp.gmail.com with ESMTPSA id cn5-20020ad44a65000000b005dd8b9345e1sm900141qvb.121.2023.03.24.12.19.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 12:19: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 v4 6/7] docs: netlink: document struct support for genetlink-legacy Date: Fri, 24 Mar 2023 19:18:59 +0000 Message-Id: <20230324191900.21828-7-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324191900.21828-1-donald.hunter@gmail.com> References: <20230324191900.21828-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 19:19:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13187299 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 7A814C6FD1C for ; Fri, 24 Mar 2023 19:19:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231602AbjCXTTl (ORCPT ); Fri, 24 Mar 2023 15:19:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231508AbjCXTTh (ORCPT ); Fri, 24 Mar 2023 15:19:37 -0400 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15808469B; Fri, 24 Mar 2023 12:19:32 -0700 (PDT) Received: by mail-qv1-xf29.google.com with SMTP id cu4so2341289qvb.3; Fri, 24 Mar 2023 12:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679685571; 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=o/fCI8eCvJdWx6N61FxJQjh6ePqXk/lipAykGvNhEQD7vn8DnHKMB6rVMZhgrLjrPT NNRzBkLM0EWWZfz2DClbcVsr3E21OHiH4Sum/PP7Zgbv8XvNXLj4pEsO6/f1f0XxShqF GHgvR7xGHJOM6PCCWyDC1+oXKDBCuIujFTI4wmMKfTaBQs03uyOfdGOv4K482DxE5ZfF 2QQVBLSR8VW2Dl5j3NmYzGhASjrNyJYza62/zQszPxTOvszX63PcpenQ2kx5APMTcZwW VQs7IRrCovydbX+yhR4pIKRbSovJjDPiW5OBmc4Qj5FAcll5FWphpgb6mcYclJC8vqLa BKSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679685571; 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=AYRlV1X2hwCOPRe6SoTlPjveTv9aJNu4XdiG7N1SgSfD94MfUPr1SONE0ZaqaeHYAo 619ox+dJk6lJxqlrrL+joAWBwGpMFZ6k3WLaGLRRV2+TmDuIVcWL4MW8j9apEcb7fIUS DwTWToTUli6MY3CxFpDLcXWLmrv7i5M5DCCoHZagkHqEIL8OJzS+b9qqxefYfZ8TcGMg Oqf8+h0m/HAnPPW7L3+rPGdUY5GV0Idu/QhPGYl4jrr3OpI7Roe/ep0JYxCiYmedDJQT P8+kQNgjO3FOBx9zDFzLfjoWmUK2Pf/i1eeWaMBrGJP1/s9P8w22PTXNpCtnrJ6lKmZ6 I8KA== X-Gm-Message-State: AAQBX9eodTCySYEVjXmiGB4XRKr/VvHBFgXlPEDcUXY8zrH6DY90O6vV 704o0r3mQL3L0JUO3Siu9ztEpR/BLfUxIA== X-Google-Smtp-Source: AKy350agtxz524VV6sAsirgR2yGtrM/IlrRCFHyPR9Tne7xD8XWCTIyI/caAvhgeIAg34y5/Y0ye+g== X-Received: by 2002:a05:6214:d05:b0:56e:9c11:651e with SMTP id 5-20020a0562140d0500b0056e9c11651emr6501444qvh.27.1679685570861; Fri, 24 Mar 2023 12:19:30 -0700 (PDT) Received: from imac.redhat.com ([88.97.103.74]) by smtp.gmail.com with ESMTPSA id cn5-20020ad44a65000000b005dd8b9345e1sm900141qvb.121.2023.03.24.12.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 12:19: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 v4 7/7] docs: netlink: document the sub-type attribute property Date: Fri, 24 Mar 2023 19:19:00 +0000 Message-Id: <20230324191900.21828-8-donald.hunter@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230324191900.21828-1-donald.hunter@gmail.com> References: <20230324191900.21828-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 ----------