summaryrefslogtreecommitdiffstats
path: root/tools/net (follow)
Commit message (Collapse)AuthorAgeFilesLines
* tools: ynl: add display-hint support to ynlDonald Hunter2023-06-252-5/+39
| | | | | | | | | Add support to the ynl tool for rendering output based on display-hint properties. Signed-off-by: Donald Hunter <donald.hunter@gmail.com> Link: https://lore.kernel.org/r/20230623201928.14275-3-donald.hunter@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl: improve the direct-include header guard logicJakub Kicinski2023-06-231-14/+6
| | | | | | | | | | | | | | | | | | Przemek suggests that I shouldn't accuse GCC of witchcraft, there is a simpler explanation for why we need manual define. scripts/headers_install.sh modifies the guard, removing _UAPI. That's why including a kernel header from the tree and from /usr leads to duplicate definitions. This also solves the mystery of why I needed to include the header conditionally. I had the wrong guards for most cases but ethtool. Suggested-by: Przemek Kitszel <przemyslaw.kitszel@intel.com> Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com> Link: https://lore.kernel.org/r/20230621231719.2728928-1-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl: work around stale system headersJakub Kicinski2023-06-153-3/+35
| | | | | | | | | | | | | | | | | | | | | | | The inability to include the uAPI headers directly in tools/ is one of the bigger annoyances of compiling user space code. Most projects trade the pain for smaller inconvenience of having to copy the headers under tools/include. In case of netlink headers I think that we can avoid both. Netlink family headers are simple and should be self-contained. We can try to twiddle the Makefile a little to force-include just the family header, and use system headers for the rest. This works fairly well. There are two warts - for some reason if we specify -include $path/family.h as a compilation flag, the #ifdef header guard does not seem to work. So we need to throw the guard in on the command line as well. Seems like GCC detects that the header is different and tries to include both. Second problem is that make wants hash sign to be escaped or not depending on the version. Sigh. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
* tools: ynl-gen: inherit policy in multi-attrJakub Kicinski2023-06-131-18/+24
| | | | | | | | | | Instead of reimplementing policies in MutliAttr for every underlying type forward the calls to the base type. This will be needed for DPLL which uses a multi-attr nest, and currently gets an invalid NLA_NEST policy generated. Reviewed-by: Jacob Keller <Jacob.e.keller@intel.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: correct enum policiesJakub Kicinski2023-06-131-2/+13
| | | | | | | | Scalar range validation assumes enums start at 0. Teach it to properly calculate the value range. Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl: add sample for ethtoolJakub Kicinski2023-06-122-0/+66
| | | | | | | | | | | | | | | | | | | Configuring / reading ring sizes and counts is a fairly common operation for ethtool netlink. Present a sample doing that with YNL: $ ./ethtool Channels: enp1s0: combined 1 eni1np1: combined 1 eni2np1: combined 1 Rings: enp1s0: rx 256 tx 256 eni1np1: rx 0 tx 0 eni2np1: rx 0 tx 0 Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
* tools: ynl: generate code for the ethtool familyJakub Kicinski2023-06-123-3/+11890
| | | | | | | | | | | | Generate the protocol code for ethtool. Skip the stats for now, they are the only outlier in terms of complexity. Stats are a sort-of semi-polymorphic (attr space of a nest depends on value of another attr) or a type-value-scalar, depending on how one wants to look at it... A challenge for another time. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
* tools: ynl-gen: resolve enum vs struct name conflictsJakub Kicinski2023-06-121-5/+20
| | | | | | | | | | | | | Ethtool has an attribute set called stringset, from which we'll generate struct ethtool_stringset. Unfortunately, the old ethtool header declares enum ethtool_stringset (the same name), to which compilers object. This seems unavoidable. Check struct names against known constants and append an underscore if conflict is detected. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
* tools: ynl-gen: don't generate enum types if unnamedJakub Kicinski2023-06-121-2/+10
| | | | | | | | If attr set or enum has empty enum name we need to use u32 or int as function arguments and struct members. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
* netlink: specs: support setting prefix-name per attributeJakub Kicinski2023-06-121-2/+5
| | | | | | | | | | | | | | | | | | | | | | Ethtool's PSE PoDL has a attr nest with different prefixes: /* Power Sourcing Equipment */ enum { ETHTOOL_A_PSE_UNSPEC, ETHTOOL_A_PSE_HEADER, /* nest - _A_HEADER_* */ ETHTOOL_A_PODL_PSE_ADMIN_STATE, /* u32 */ ETHTOOL_A_PODL_PSE_ADMIN_CONTROL, /* u32 */ ETHTOOL_A_PODL_PSE_PW_D_STATUS, /* u32 */ Header has a prefix of ETHTOOL_A_PSE_ and other attrs prefix of ETHTOOL_A_PODL_PSE_ we can't cover them uniformly. If PODL was after PSE life would be easy. Now we either need to add prefixes to attr names which is yucky or support setting prefix name per attr. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
* tools: ynl-gen: record extra args for regenJakub Kicinski2023-06-122-1/+8
| | | | | | | | ynl-regen needs to know the arguments used to generate a file. Record excluded ops and, while at it, user headers. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
* tools: ynl-gen: support excluding tricky opsJakub Kicinski2023-06-122-5/+17
| | | | | | | | | The ethtool family has a small handful of quite tricky ops and a lot of simple very useful ops. Teach ynl-gen to skip ops so that we can bypass the tricky ones. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
* tools: ynl-gen: support / skip pads on the way to kernelJakub Kicinski2023-06-091-0/+6
| | | | | | | | Kernel does not have padding requirements for 64b attrs. We can ignore pad attrs. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: don't pass op_name to RenderInfoJakub Kicinski2023-06-091-19/+18
| | | | | | | | The op_name argument is barely used and identical to op.name in all cases. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: support code gen for eventsJakub Kicinski2023-06-092-6/+13
| | | | | | | | | | Netlink specs support both events and notifications (former can define their own message contents). Plug in missing code to generate types, parsers and include events into notification tables. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: sanitize notification trackingJakub Kicinski2023-06-092-43/+27
| | | | | | | | | Don't modify the raw dicts (as loaded from YAML) to pretend that the notify attributes also exist on the ops. This makes the code easier to follow. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl: regen: stop generating common notification handlersJakub Kicinski2023-06-094-98/+0
| | | | | | | Remove unused notification handlers. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: stop generating common notification handlersJakub Kicinski2023-06-091-73/+0
| | | | | | | | | | Common notification handler was supposed to be a way for the user to parse the notifications from a socket synchronously. I don't think we'll end up using it, ynl_ntf_check() works for all known use cases. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl: regen: regenerate the if laddersJakub Kicinski2023-06-094-74/+67
| | | | | | | | Renegate the code to combine } and else and use tmp variable to store type. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: get attr type outside of if()Jakub Kicinski2023-06-091-1/+3
| | | | | | | | | Reading attr type with mnl_attr_get_type() for each condition leads to most conditions being longer than 80 chars. Avoid this by reading the type to a variable on the stack. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: combine else with closing bracketJakub Kicinski2023-06-091-4/+19
| | | | | | | | | | | | | Code gen currently prints: } else if (... This is really ugly. Fix it by delaying printing of closing brackets in anticipation of else coming along. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: complete the C keyword listJakub Kicinski2023-06-091-1/+34
| | | | | | | | C keywords need to be avoided when naming things. Complete the list (ethtool has at least one thing called "auto"). Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl: regen: cleanup user space header includesJakub Kicinski2023-06-094-12/+4
| | | | | | | Remove unnecessary includes. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: cleanup user space header includesJakub Kicinski2023-06-091-4/+1
| | | | | | | | | | | | Bots started screaming that we're including stdlib.h twice. While at it move string.h into a common spot and drop stdio.h which we don't need. Reported-by: Abaci Robot <abaci@linux.alibaba.com> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=5464 Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=5466 Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=5467 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* Revert "tools: ynl: Remove duplicated include in handshake-user.c"Jakub Kicinski2023-06-091-0/+1
| | | | | | | | | | | | This reverts commit e7c5433c5aaab52ddd5448967a9a5db94a3939cc. Commit e7c5433c5aaa ("tools: ynl: Remove duplicated include in handshake-user.c") was applied too hastily. It changes an auto-generated file, and there's already a proper fix on the list. Link: https://lore.kernel.org/all/ZIMPLYi%2FxRih+DlC@nanopsycho/ Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl: Remove duplicated include in handshake-user.cYang Li2023-06-091-1/+0
| | | | | | | | | ./tools/net/ynl/generated/handshake-user.c: stdlib.h is included more than once. Reported-by: Abaci Robot <abaci@linux.alibaba.com> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=5464 Signed-off-by: Yang Li <yang.lee@linux.alibaba.com> Signed-off-by: David S. Miller <davem@davemloft.net>
* tools: ynl: add sample for devlinkJakub Kicinski2023-06-082-0/+61
| | | | | | | | | | | | | | | | | | | | Add a sample to show off how to issue basic devlink requests. For added testing issue get requests while walking a dump. $ ./devlink netdevsim/netdevsim1: driver: netdevsim running fw: fw.mgmt: 10.20.30 ... netdevsim/netdevsim2: driver: netdevsim running fw: fw.mgmt: 10.20.30 ... Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl: generate code for the devlink familyJakub Kicinski2023-06-083-1/+932
| | | | | | | | | | | Admittedly the devlink.yaml spec is fairly limitted, it only covers basic device get and info-get ops. That's sufficient to be useful (monitoring FW versions in the fleet). Plus it gives us a chance to exercise deep nesting and directional messaging in YNL. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: don't generate forward declarations for policies - regenJakub Kicinski2023-06-083-8/+0
| | | | | | | Renegerate code after dropping forward declarations for policies. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: don't generate forward declarations for policiesJakub Kicinski2023-06-081-9/+3
| | | | | | | | Now that all nested types have structs and are sorted topologically there should be no need to generate forward declarations for policies. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: walk nested types in depthJakub Kicinski2023-06-081-12/+29
| | | | | | | | | So far we had only created structures for nested types nested directly in messages (second level of attrs so to speak). Walk types in depth to support deeper nesting. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: inherit struct use infoJakub Kicinski2023-06-081-0/+8
| | | | | | | | | | We only render parse and netlink generation helpers as needed, to avoid generating dead code. Propagate the information from first- and second-layer attribute sets onto all children. Otherwise devlink won't work, it has a lot more levels of nesting. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: try to sort the types more intelligentlyJakub Kicinski2023-06-081-2/+24
| | | | | | | | | We need to sort the structures to avoid the need for forward declarations. While at it remove the sort of structs when rendering, it doesn't do anything. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: enable code gen for directional specsJakub Kicinski2023-06-082-6/+11
| | | | | | | | I think that user space code gen for directional specs works after recent changes. Let them through. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: refactor strmap helper generationJakub Kicinski2023-06-081-19/+17
| | | | | | | | Move generating strmap lookup function to a helper. No functional changes. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: use enum names in op strmap more carefullyJakub Kicinski2023-06-083-2/+9
| | | | | | | | | | In preparation for supporting families which use different msg ids to and from the kernel - make sure the ids in op strmap are correct. The map is expected to be used mostly for notifications, don't generate a separate map for the "to kernel" direction. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl: generate code for the handshake familyJakub Kicinski2023-06-073-1/+534
| | | | | | | Generate support for the handshake family. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: improve unwind on parsing errorsJakub Kicinski2023-06-071-5/+17
| | | | | | | | | | | | | | | | When parsing multi-attr we count the objects and then allocate an array to hold the parsed objects. If an attr space has multiple multi-attr objects, however, if parsing the first array fails we'll leave the object count for the second even tho the second array was never allocated. This may cause crashes when freeing objects on error. Count attributes to a variable on the stack and only set the count in the object once the memory was allocated. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: fill in support for MultiAttr scalarsJakub Kicinski2023-06-071-5/+42
| | | | | | | | | The handshake family needs support for MultiAttr scalars. Right now we only support code gen for MultiAttr nested types. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl: add sample for netdevJakub Kicinski2023-06-063-0/+137
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a sample application using the C library. My main goal is to make writing selftests easier but until I have some of those ready I think it's useful to show off the functionality and let people poke and tinker. Sample outputs - dump: $ ./netdev Select ifc ($ifindex; or 0 = dump; or -2 ntf check): 0 lo[1] 0: enp1s0[2] 23: basic redirect rx-sg Notifications (watching veth pair getting added and deleted): $ ./netdev Select ifc ($ifindex; or 0 = dump; or -2 ntf check): -2 [53] 0: (ntf: dev-add-ntf) [54] 0: (ntf: dev-add-ntf) [54] 23: basic redirect rx-sg (ntf: dev-change-ntf) [53] 23: basic redirect rx-sg (ntf: dev-change-ntf) [53] 23: basic redirect rx-sg (ntf: dev-del-ntf) [54] 23: basic redirect rx-sg (ntf: dev-del-ntf) Reviewed-by: Willem de Bruijn <willemb@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl: support fou and netdev in CJakub Kicinski2023-06-065-1/+1016
| | | | | | | | Generate the code for netdev and fou families. They are simple and already supported by the code gen. Reviewed-by: Willem de Bruijn <willemb@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl: user space helpersJakub Kicinski2023-06-066-1/+1231
| | | | | | | | | Add "fixed" part of the user space Netlink Spec-based library. This will get linked with the protocol implementations to form a full API. Acked-by: Willem de Bruijn <willemb@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: clean up stray new lines at the end of reply-less requestsJakub Kicinski2023-06-061-3/+4
| | | | | | | Do not print empty lines before closing brackets. Reviewed-by: Willem de Bruijn <willemb@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: generate static descriptions of notificationsJakub Kicinski2023-06-031-10/+42
| | | | | | | | | | Notifications may come in at any time. The family must be always ready to parse a random incoming notification. Generate notification table for parsing and tell YNL which request we're processing to distinguish responses from notifications. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: switch to family structJakub Kicinski2023-06-031-0/+15
| | | | | | | | | | | | | | We'll want to store static info about the family soon. Generate a struct. This changes creation from, e.g.: ys = ynl_sock_create("netdev", &yerr); to: ys = ynl_sock_create(&ynl_netdev_family, &yerr); on user's side. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: generate alloc and free helpers for reqJakub Kicinski2023-06-031-0/+17
| | | | | | | | | We expect user to allocate requests with calloc(), make things a bit more consistent and provide helpers. Generate free calls, too. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: move the response reading logic into YNLJakub Kicinski2023-06-031-36/+27
| | | | | | | | | We generate send() and recv() calls and all msg handling for each operation. It's a lot of repeated code and will only grow with notification handling. Call back to a helper YNL lib instead. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: generate enum-to-string helpersJakub Kicinski2023-06-031-0/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's sometimes useful to print the name of an enum value, flag or name of the op. Python can do it, add C helper code gen for getting names of things. Example: static const char * const netdev_xdp_act_strmap[] = { [0] = "basic", [1] = "redirect", [2] = "ndo-xmit", [3] = "xsk-zerocopy", [4] = "hw-offload", [5] = "rx-sg", [6] = "ndo-xmit-sg", }; const char *netdev_xdp_act_str(enum netdev_xdp_act value) { value = ffs(value) - 1; if (value < 0 || value >= (int)MNL_ARRAY_SIZE(netdev_xdp_act_strmap)) return NULL; return netdev_xdp_act_strmap[value]; } Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: add error checking for nested structsJakub Kicinski2023-06-031-1/+2
| | | | | | | | Parsing nested types may return an error, propagate it. Not marking as a fix, because nothing uses YNL upstream. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
* tools: ynl-gen: loosen type consistency check for eventsJakub Kicinski2023-06-031-7/+8
| | | | | | | | | Both event and notify types are always consistent. Rewrite the condition checking if we can reuse reply types to be less picky and let notify thru. Signed-off-by: Jakub Kicinski <kuba@kernel.org>