1 /*
2 * nl-list-caches.c List registered cache types
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
7 * of the License.
8 *
9 * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
10 */
11
12 #include <netlink-private/netlink.h>
13 #include <netlink/cli/utils.h>
14
print_usage(void)15 static void print_usage(void)
16 {
17 fprintf(stderr, "Usage: nl-list-caches\n");
18 exit(1);
19 }
20
id_attr_list(struct nl_object_ops * ops,char * buf,size_t len)21 static char *id_attr_list(struct nl_object_ops *ops, char *buf, size_t len)
22 {
23 if (ops->oo_attrs2str != NULL)
24 return ops->oo_attrs2str(ops->oo_id_attrs, buf, len);
25 else {
26 memset(buf, 0, len);
27 return buf;
28 }
29 }
30
print(struct nl_cache_ops * ops,void * arg)31 static void print(struct nl_cache_ops *ops, void *arg)
32 {
33 char buf[64];
34
35 printf("%s:\n" \
36 " hdrsize: %d bytes\n" \
37 " protocol: %s\n" \
38 " request-update: %s\n" \
39 " msg-parser: %s\n",
40 ops->co_name, ops->co_hdrsize,
41 nl_nlfamily2str(ops->co_protocol, buf, sizeof(buf)),
42 ops->co_request_update ? "yes" : "no",
43 ops->co_msg_parser ? "yes" : "no");
44
45 if (ops->co_obj_ops) {
46 struct nl_object_ops *obj_ops = ops->co_obj_ops;
47 const char *dump_names[NL_DUMP_MAX+1] = {
48 "brief",
49 "detailed",
50 "stats",
51 };
52 int i;
53
54 printf(" cacheable object:\n" \
55 " name: %s:\n" \
56 " size: %zu bytes\n" \
57 " constructor: %s\n" \
58 " free-data: %s\n" \
59 " clone: %s\n" \
60 " compare: %s\n" \
61 " id attributes: %s\n" \
62 " dump: ",
63 obj_ops->oo_name, obj_ops->oo_size,
64 obj_ops->oo_constructor ? "yes" : "no",
65 obj_ops->oo_free_data ? "yes" : "no",
66 obj_ops->oo_clone ? "yes" : "no",
67 obj_ops->oo_compare ? "yes" : "no",
68 id_attr_list(obj_ops, buf, sizeof(buf)));
69
70 for (i = 0; i <= NL_DUMP_MAX; i++)
71 if (obj_ops->oo_dump[i])
72 printf("%s%s",
73 i == 0 ? "" : ", ",
74 dump_names[i]);
75
76 printf("\n");
77 }
78
79 if (ops->co_genl) {
80 struct genl_ops *genl_ops = ops->co_genl;
81
82 printf(" genl:\n" \
83 " name: %s\n" \
84 " user-hdr: %d\n" \
85 " id: %d\n",
86 genl_ops->o_name, genl_ops->o_hdrsize, genl_ops->o_id);
87
88 if (genl_ops->o_ncmds) {
89 int i;
90
91 printf(" cmds:\n");
92
93 for (i = 0; i < genl_ops->o_ncmds; i++) {
94 struct genl_cmd *cmd = &genl_ops->o_cmds[i];
95
96 printf(" %s:\n"
97 " id: %d\n" \
98 " maxattr: %d\n" \
99 " msg-parser: %s\n" \
100 " attr-policy: %s\n",
101 cmd->c_name, cmd->c_id, cmd->c_maxattr,
102 cmd->c_msg_parser ? "yes" : "no",
103 cmd->c_attr_policy ? "yes" : "no");
104 }
105 }
106 }
107 }
108
main(int argc,char * argv[])109 int main(int argc, char *argv[])
110 {
111 if (argc > 1 && !strcasecmp(argv[1], "-h"))
112 print_usage();
113
114 nl_cache_ops_foreach(print, NULL);
115
116 return 0;
117 }
118