1. 01 Feb, 2023 15 commits
    • Jakub Kicinski's avatar
      Merge branch 'tools-ynl-more-docs-and-basic-ethtool-support' · 1b98ac0f
      Jakub Kicinski authored
      Jakub Kicinski says:
      
      ====================
      tools: ynl: more docs and basic ethtool support
      
      I got discouraged from supporting ethtool in specs, because
      generating the user space C code seems a little tricky.
      The messages are ID'ed in a "directional" way (to and from
      kernel are separate ID "spaces"). There is value, however,
      in having the spec and being able to for example use it
      in Python.
      
      After paying off some technical debt - add a partial
      ethtool spec. Partial because the header for ethtool is almost
      a 1000 LoC, so converting in one sitting is tough. But adding
      new commands should be trivial now.
      
      Last but not least I add more docs, I realized that I've been
      sending a similar "instructions" email to people working on
      new families. It's now intro-specs.rst.
      ====================
      
      Link: https://lore.kernel.org/r/20230131023354.1732677-1-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      1b98ac0f
    • Jakub Kicinski's avatar
      tools: net: use python3 explicitly · 981cbcb0
      Jakub Kicinski authored
      The scripts require Python 3 and some distros are dropping
      Python 2 support.
      Reported-by: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      981cbcb0
    • Jakub Kicinski's avatar
      docs: netlink: add a starting guide for working with specs · 01e47a37
      Jakub Kicinski authored
      We have a bit of documentation about the internals of Netlink
      and the specs, but really the goal is for most people to not
      worry about those. Add a practical guide for beginners who
      want to poke at the specs.
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      01e47a37
    • Jakub Kicinski's avatar
      netlink: specs: add partial specification for ethtool · b784db7a
      Jakub Kicinski authored
      Ethtool is one of the most actively developed families.
      With the changes to the CLI it should be possible to use
      the YNL based code for easy prototyping and development.
      Add a partial family definition. I've tested the string
      set and rings. I don't have any MAC Merge implementation
      to test with, but I added the definition for it, anyway,
      because it's last. New commands can simply be added at
      the end without having to worry about manually providing
      IDs / values.
      
      Set (with notification support - None is the response,
      the data is from the notification):
      
      $ sudo ./tools/net/ynl/cli.py \
          --spec Documentation/netlink/specs/ethtool.yaml \
          --do rings-set \
          --json '{"header":{"dev-name":"enp0s31f6"}, "rx":129}' \
          --subscribe monitor
      None
      [{'msg': {'header': {'dev-index': 2, 'dev-name': 'enp0s31f6'},
                'rx': 136,
                'rx-max': 4096,
                'tx': 256,
                'tx-max': 4096,
                'tx-push': 0},
        'name': 'rings-ntf'}]
      
      Do / dump (yes, the kernel requires that even for dump and even
      if empty - the "header" nest must be there):
      
      $ ./tools/net/ynl/cli.py \
          --spec Documentation/netlink/specs/ethtool.yaml \
          --do rings-get \
          --json '{"header":{"dev-index": 2}}'
      {'header': {'dev-index': 2, 'dev-name': 'enp0s31f6'},
       'rx': 136,
       'rx-max': 4096,
       'tx': 256,
       'tx-max': 4096,
       'tx-push': 0}
      
      $ ./tools/net/ynl/cli.py \
          --spec Documentation/netlink/specs/ethtool.yaml \
          --dump rings-get \
          --json '{"header":{}}'
      [{'header': {'dev-index': 2, 'dev-name': 'enp0s31f6'},
        'rx': 136,
        'rx-max': 4096,
        'tx': 256,
        'tx-max': 4096,
        'tx-push': 0},
       {'header': {'dev-index': 3, 'dev-name': 'wlp0s20f3'}, 'tx-push': 0},
       {'header': {'dev-index': 19, 'dev-name': 'enp58s0u1u1'},
        'rx': 100,
        'rx-max': 4096,
        'tx-push': 0}]
      
      And error reporting:
      
      $ ./tools/net/ynl/cli.py \
          --spec Documentation/netlink/specs/ethtool.yaml \
          --dump rings-get \
          --json '{"header":{"flags":5}}'
      Netlink error: Invalid argument
      nl_len = 68 (52) nl_flags = 0x300 nl_type = 2
      	error: -22	extack: {'msg': 'reserved bit set',
      	                         'bad-attr-offs': 24,
      				 'bad-attr': '.header.flags'}
      None
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      b784db7a
    • Jakub Kicinski's avatar
      netlink: specs: finish up operation enum-models · 8403bf04
      Jakub Kicinski authored
      I had a (bright?) idea of introducing the concept of enum-models
      to account for all the weird ways families enumerate their messages.
      I've never finished it because generating C code for each of them
      is pretty daunting. But for languages which can use ID values directly
      the support is simple enough, so clean this up a bit.
      
      "unified" model is what I recommend going forward.
      "directional" model is what ethtool uses.
      "notify-split" is used by the proposed DPLL code, but we can just
      make them use "unified", it hasn't been merged :)
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      8403bf04
    • Jakub Kicinski's avatar
      tools: ynl: load jsonschema on demand · 5c6674f6
      Jakub Kicinski authored
      The CLI script tries to validate jsonschema by default.
      It's seems better to validate too many times than too few.
      However, when copying the scripts to random servers having
      to install jsonschema is tedious. Load jsonschema via
      importlib, and let the user opt out.
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      5c6674f6
    • Jakub Kicinski's avatar
      tools: ynl: use operation names from spec on the CLI · 8dfec0a8
      Jakub Kicinski authored
      When I wrote the first version of the Python code I was quite
      excited that we can generate class methods directly from the
      spec. Unfortunately we need to use valid identifiers for method
      names (specifically no dashes are allowed). Don't reuse those
      names on the CLI, it's much more natural to use the operation
      names exactly as listed in the spec.
      
      Instead of:
        ./cli --do rings_get
      use:
        ./cli --do rings-get
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      8dfec0a8
    • Jakub Kicinski's avatar
      tools: ynl: support pretty printing bad attribute names · 4cd2796f
      Jakub Kicinski authored
      One of my favorite features of the Netlink specs is that they
      make decoding structured extack a ton easier.
      Implement pretty printing bad attribute names in YNL.
      
      For example it will now say:
      
        'bad-attr': '.header.flags'
      
      rather than the useless:
      
        'bad-attr-offs': 32
      
      Proof:
      
        $ ./cli.py --spec ethtool.yaml --do rings_get \
           --json '{"header":{"dev-index":1, "flags":4}}'
        Netlink error: Invalid argument
        nl_len = 68 (52) nl_flags = 0x300 nl_type = 2
      	error: -22	extack: {'msg': 'reserved bit set',
      				 'bad-attr': '.header.flags'}
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      4cd2796f
    • Jakub Kicinski's avatar
      tools: ynl: support multi-attr · 90256f3f
      Jakub Kicinski authored
      Ethtool uses mutli-attr, add the support to YNL.
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      90256f3f
    • Jakub Kicinski's avatar
      tools: ynl: support directional enum-model in CLI · fd0616d3
      Jakub Kicinski authored
      Support families which use different IDs for messages
      to and from the kernel.
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      fd0616d3
    • Jakub Kicinski's avatar
      tools: ynl: add support for types needed by ethtool · 19b64b48
      Jakub Kicinski authored
      Ethtool needs support for handful of extra types.
      It doesn't have the definitions section yet.
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      19b64b48
    • Jakub Kicinski's avatar
      tools: ynl: use the common YAML loading and validation code · 30a5c6c8
      Jakub Kicinski authored
      Adapt the common object hierarchy in code gen and CLI.
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      30a5c6c8
    • Jakub Kicinski's avatar
      tools: ynl: add an object hierarchy to represent parsed spec · 3aacf828
      Jakub Kicinski authored
      There's a lot of copy and pasting going on between the "cli"
      and code gen when it comes to representing the parsed spec.
      Create a library which both can use.
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      3aacf828
    • Jakub Kicinski's avatar
      tools: ynl: move the cli and netlink code around · 4e4480e8
      Jakub Kicinski authored
      Move the CLI code out of samples/ and the library part
      of it into tools/net/ynl/lib/. This way we can start
      sharing some code with the code gen.
      
      Initially I thought that code gen is too C-specific to
      share anything but basic stuff like calculating values
      for enums can easily be shared.
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      4e4480e8
    • Jakub Kicinski's avatar
      tools: ynl-gen: prevent do / dump reordering · eaf317e7
      Jakub Kicinski authored
      An earlier fix tried to address generated code jumping around
      one code-gen run to another. Turns out dict()s are already
      ordered since Python 3.7, the problem is that we iterate over
      operation modes using a set(). Sets are unordered in Python.
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      eaf317e7
  2. 31 Jan, 2023 22 commits
  3. 30 Jan, 2023 3 commits