• Jakub Kicinski's avatar
    netlink: support extack in dump ->start() · 5ab8c41c
    Jakub Kicinski authored
    Commit 4a19edb6 ("netlink: Pass extack to dump handlers")
    added extack support to netlink dumps. It was focused on rtnl
    and since rtnl does not use ->start(), ->done() callbacks
    it ignored those. Genetlink on the other hand uses ->start()
    extensively, for parsing and input validation.
    
    Pass the extact in via struct netlink_dump_control and link
    it to cb for the time of ->start(). Both struct netlink_dump_control
    and extack itself live on the stack so we can't keep the same
    extack for the duration of the dump. This means that the extack
    visible in ->start() and each ->dump() callbacks will be different.
    Corner cases like reporting a warning message in DONE across dump
    calls are still not supported.
    
    We could put the extack (for dumps) in the socket struct,
    but layering makes it slightly awkward (extack pointer is decided
    before the DO / DUMP split).
    
    The genetlink dump error extacks are now surfaced:
    
      $ cli.py --spec netlink/specs/ethtool.yaml --dump channels-get
      lib.ynl.NlError: Netlink error: Invalid argument
      nl_len = 64 (48) nl_flags = 0x300 nl_type = 2
    	error: -22	extack: {'msg': 'request header missing'}
    
    Previously extack was missing:
    
      $ cli.py --spec netlink/specs/ethtool.yaml --dump channels-get
      lib.ynl.NlError: Netlink error: Invalid argument
      nl_len = 36 (20) nl_flags = 0x100 nl_type = 2
    	error: -22
    Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    5ab8c41c
genetlink.c 41.1 KB