8#include <netlink/cli/utils.h>
10#include "nl-priv-dynamic-core/object-api.h"
11#include "nl-priv-dynamic-core/cache-api.h"
13static void print_usage(
void)
15 fprintf(stderr,
"Usage: nl-list-caches\n");
19static char *id_attr_list(
struct nl_object_ops *ops,
char *buf,
size_t len)
21 if (ops->oo_attrs2str != NULL)
22 return ops->oo_attrs2str(ops->oo_id_attrs, buf, len);
29static void print(
struct nl_cache_ops *ops,
void *arg)
34 " hdrsize: %d bytes\n" \
36 " request-update: %s\n" \
38 ops->co_name, ops->co_hdrsize,
39 nl_nlfamily2str(ops->co_protocol, buf,
sizeof(buf)),
40 ops->co_request_update ?
"yes" :
"no",
41 ops->co_msg_parser ?
"yes" :
"no");
43 if (ops->co_obj_ops) {
44 struct nl_object_ops *obj_ops = ops->co_obj_ops;
45 const char *dump_names[NL_DUMP_MAX+1] = {
52 printf(
" cacheable object:\n" \
54 " size: %zu bytes\n" \
55 " constructor: %s\n" \
59 " id attributes: %s\n" \
61 obj_ops->oo_name, obj_ops->oo_size,
62 obj_ops->oo_constructor ?
"yes" :
"no",
63 obj_ops->oo_free_data ?
"yes" :
"no",
64 obj_ops->oo_clone ?
"yes" :
"no",
65 obj_ops->oo_compare ?
"yes" :
"no",
66 id_attr_list(obj_ops, buf, sizeof(buf)));
68 for (i = 0; i <= NL_DUMP_MAX; i++)
69 if (obj_ops->oo_dump[i])
107int main(
int argc,
char *argv[])
109 if (argc > 1 && !strcasecmp(argv[1],
"-h"))
void nl_cache_ops_foreach(void(*cb)(struct nl_cache_ops *, void *), void *arg)
Call a function for each registered cache operation.
Definition of a Generic Netlink command.
struct nla_policy * c_attr_policy
Attribute validation policy, enforced before the callback is called.
int c_id
Numeric command identifier (required)
char * c_name
Human readable name (required)
int(* c_msg_parser)(struct nl_cache_ops *, struct genl_cmd *, struct genl_info *, void *)
Called whenever a message for this command is received.
int c_maxattr
Maximum attribute identifier that the command is prepared to handle.
Definition of a Generic Netlink family.
int o_ncmds
Number of elements in o_cmds array.
unsigned int o_hdrsize
Length of user header.
char * o_name
Human readable name, used by genl_ops_resolve() to resolve numeric id.
int o_id
Numeric identifier, automatically filled in by genl_ops_resolve()
struct genl_cmd * o_cmds
Optional array defining the available Generic Netlink commands.