/** * Print information about cache manager * @arg mngr Cache manager * @arg p Dumping parameters * * Prints information about the cache manager including all managed caches. * * @note This is a debugging function. */ void nl_cache_mngr_info(struct nl_cache_mngr *mngr, struct nl_dump_params *p) { char buf[128]; int i; nl_dump_line(p, "cache-manager <%p>\n", mngr); nl_dump_line(p, " .protocol = %s\n", nl_nlfamily2str(mngr->cm_protocol, buf, sizeof(buf))); nl_dump_line(p, " .flags = %#x\n", mngr->cm_flags); nl_dump_line(p, " .nassocs = %u\n", mngr->cm_nassocs); nl_dump_line(p, " .sock = <%p>\n", mngr->cm_sock); for (i = 0; i < mngr->cm_nassocs; i++) { struct nl_cache_assoc *assoc = &mngr->cm_assocs[i]; if (assoc->ca_cache) { nl_dump_line(p, " .cache[%d] = <%p> {\n", i, assoc->ca_cache); nl_dump_line(p, " .name = %s\n", assoc->ca_cache->c_ops->co_name); nl_dump_line(p, " .change_func = <%p>\n", assoc->ca_change); nl_dump_line(p, " .change_data = <%p>\n", assoc->ca_change_data); nl_dump_line(p, " .nitems = %u\n", nl_cache_nitems(assoc->ca_cache)); nl_dump_line(p, " .objects = {\n"); p->dp_prefix += 6; nl_cache_dump(assoc->ca_cache, p); p->dp_prefix -= 6; nl_dump_line(p, " }\n"); nl_dump_line(p, " }\n"); } } }
static void list_cls(int ifindex, uint32_t parent) { struct nl_cache *cls_cache; cls_cache = nl_cli_cls_alloc_cache(sock, ifindex, parent); params.dp_prefix += NUM_INDENT; nl_cache_dump(cls_cache, ¶ms); params.dp_prefix -= NUM_INDENT; nl_cache_free(cls_cache); }
void TNl::DumpCache(struct nl_cache *cache) const { if (!Verbose) return; static std::function<void(struct nl_dump_params *, char *)> handler; struct nl_dump_params dp = {}; dp.dp_cb = [](struct nl_dump_params *params, char *buf) { handler(params, buf); }; dp.dp_type = NL_DUMP_DETAILS; auto &str = L(); handler = [&](struct nl_dump_params *params, char *buf) { str << buf; }; str << "netlink cache: "; nl_cache_dump(cache, &dp); }
static void print_qdisc(struct nl_object *obj, void *arg) { struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) obj; struct nl_cache *cls_cache; uint32_t parent = rtnl_tc_get_handle((struct rtnl_tc *) qdisc); params.dp_prefix = (int)(long) arg; nl_object_dump(obj, ¶ms); print_tc_childs(TC_CAST(qdisc), arg + 2); if (rtnl_cls_alloc_cache(sock, ifindex, parent, &cls_cache) < 0) return; params.dp_prefix = (int)(long) arg + 2; nl_cache_dump(cls_cache, ¶ms); nl_cache_free(cls_cache); }
static void print_qdisc(struct nl_object *obj, void *arg) { struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) obj; struct nl_cache *cls_cache; uint32_t parent = rtnl_qdisc_get_handle(qdisc); dump_params.dp_prefix = (int) arg; nl_object_dump(obj, &dump_params); rtnl_qdisc_foreach_child(qdisc, class_cache, &print_class, arg + 2); cls_cache = rtnl_cls_alloc_cache(nl_handle, ifindex, parent); if (!cls_cache) return; dump_params.dp_prefix = (int) arg + 2; nl_cache_dump(cls_cache, &dump_params); nl_cache_free(cls_cache); }
void TNlLink::LogCache(struct nl_cache *cache) const { if (!debug) return; static std::function<void(struct nl_dump_params *, char *)> handler; struct nl_dump_params dp = {}; dp.dp_cb = [](struct nl_dump_params *params, char *buf) { handler(params, buf); }; dp.dp_type = NL_DUMP_DETAILS; auto &str = L(); handler = [&](struct nl_dump_params *params, char *buf) { str << buf; }; if (Link) str << "netlink " << rtnl_link_get_name(Link) << " cache: "; else str << "netlink cache: "; nl_cache_dump(cache, &dp); }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct nl_cache *neightbl_cache; struct nl_dump_params params = { .dp_type = NL_DUMP_LINE, .dp_fd = stdout, }; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); nl_cli_link_alloc_cache(sock); neightbl_cache = nl_cli_alloc_cache(sock, "neighbour table", rtnl_neightbl_alloc_cache); for (;;) { int c, optidx = 0; static struct option long_opts[] = { { "format", 1, 0, 'f' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "f:hv", long_opts, &optidx); if (c == -1) break; switch (c) { case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; } } nl_cache_dump(neightbl_cache, ¶ms); return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct nl_cache *cache; struct nl_dump_params params = { .dp_type = NL_DUMP_LINE, .dp_fd = stdout, }; if ((sock = nl_socket_alloc()) == 0) ERRX("Failed nl_socket_alloc"); if (genl_connect(sock)) ERRX("Failed genl_connect"); if (genl_ctrl_alloc_cache(sock, &cache)) ERRX("Failed genl_ctrl_alloc_cache"); nl_cache_dump(cache, ¶ms); return 0; }
static void print_class(struct nl_object *obj, void *arg) { struct rtnl_qdisc *leaf; struct rtnl_class *class = (struct rtnl_class *) obj; struct nl_cache *cls_cache; uint32_t parent = rtnl_tc_get_handle((struct rtnl_tc *) class); params.dp_prefix = (int)(long) arg; nl_object_dump(obj, ¶ms); leaf = rtnl_class_leaf_qdisc(class, qdisc_cache); if (leaf) print_qdisc((struct nl_object *) leaf, arg + 2); print_tc_childs(TC_CAST(class), arg + 2); if (rtnl_cls_alloc_cache(sock, ifindex, parent, &cls_cache) < 0) return; params.dp_prefix = (int)(long) arg + 2; nl_cache_dump(cls_cache, ¶ms); nl_cache_free(cls_cache); }
int main(int argc, char *argv[]) { struct nl_handle *nlh; struct nl_cache *link_cache, *route_cache; struct nl_addr *dst; struct nl_dump_params params = { .dp_fd = stdout, .dp_type = NL_DUMP_BRIEF }; int err = 1; if (argc < 2 || !strcmp(argv[1], "-h")) print_usage(); if (nltool_init(argc, argv) < 0) goto errout; nlh = nl_handle_alloc_nondefault(nltool_cbset); if (!nlh) goto errout; if (nltool_connect(nlh, NETLINK_ROUTE) < 0) goto errout_free_handle; link_cache = nltool_alloc_link_cache(nlh); if (!link_cache) goto errout_close; dst = nltool_addr_parse(argv[1]); if (!dst) goto errout_link_cache; route_cache = nltool_alloc_route_cache(nlh); if (!route_cache) goto errout_addr_put; { struct nl_msg *m; struct rtmsg rmsg = { .rtm_family = nl_addr_get_family(dst), .rtm_dst_len = nl_addr_get_prefixlen(dst), }; m = nlmsg_build_simple(RTM_GETROUTE, 0); nlmsg_append(m, &rmsg, sizeof(rmsg), 1); nla_put_addr(m, RTA_DST, dst); if ((err = nl_send_auto_complete(nlh, m)) < 0) { nlmsg_free(m); fprintf(stderr, "%s\n", nl_geterror()); goto errout_route_cache; } nlmsg_free(m); nl_cb_set(nl_handle_get_cb(nlh), NL_CB_VALID, NL_CB_CUSTOM, cb, route_cache); if (nl_recvmsgs_def(nlh) < 0) { fprintf(stderr, "%s\n", nl_geterror()); goto errout_route_cache; } } nl_cache_dump(route_cache, ¶ms); err = 0; errout_route_cache: nl_cache_free(route_cache); errout_addr_put: nl_addr_put(dst); errout_link_cache: nl_cache_free(link_cache); errout_close: nl_close(nlh); errout_free_handle: nl_handle_destroy(nlh); errout: return err; }