Skip to content

Commit

Permalink
tools: ynl: add ynl_dump_empty() helper
Browse files Browse the repository at this point in the history
Checking if dump is empty requires a couple of casts.
Add a convenient wrapper.

Add an example use in the netdev sample, loopback is always
present so an empty dump is an error.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: NipaLocal <nipa@local>
  • Loading branch information
kuba-moo authored and NipaLocal committed Mar 31, 2024
1 parent d92031a commit 95867b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tools/net/ynl/lib/ynl.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ void ynl_sock_destroy(struct ynl_sock *ys);
!ynl_dump_obj_is_last(iter); \
iter = ynl_dump_obj_next(iter))

/**
* ynl_dump_empty() - does the dump have no entries
* @dump: pointer to the dump list, as returned by a dump call
*
* Check if the dump is empty, i.e. contains no objects.
* Dump calls return NULL on error, and terminator element if empty.
*/
static inline bool ynl_dump_empty(void *dump)
{
return dump == (void *)YNL_LIST_END;
}

int ynl_subscribe(struct ynl_sock *ys, const char *grp_name);
int ynl_socket_get_fd(struct ynl_sock *ys);
int ynl_ntf_check(struct ynl_sock *ys);
Expand Down
2 changes: 2 additions & 0 deletions tools/net/ynl/samples/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ int main(int argc, char **argv)
if (!devs)
goto err_close;

if (ynl_dump_empty(devs))
fprintf(stderr, "Error: no devices reported\n");
ynl_dump_foreach(devs, d)
netdev_print_device(d, 0);
netdev_dev_get_list_free(devs);
Expand Down

0 comments on commit 95867b6

Please sign in to comment.