static void print_link(struct nl_object *obj, void *arg) { struct rtnl_link *link = (struct rtnl_link *) obj; struct rtnl_qdisc *qdisc; ifindex = rtnl_link_get_ifindex(link); dump_params.dp_prefix = 0; nl_object_dump(obj, &dump_params); class_cache = rtnl_class_alloc_cache(nl_handle, ifindex); if (!class_cache) return; qdisc = rtnl_qdisc_get_by_parent(qdisc_cache, ifindex, TC_H_ROOT); if (qdisc) { print_qdisc((struct nl_object *) qdisc, (void *) 2); rtnl_qdisc_put(qdisc); } qdisc = rtnl_qdisc_get_by_parent(qdisc_cache, ifindex, 0); if (qdisc) { print_qdisc((struct nl_object *) qdisc, (void *) 2); rtnl_qdisc_put(qdisc); } qdisc = rtnl_qdisc_get_by_parent(qdisc_cache, ifindex, TC_H_INGRESS); if (qdisc) { print_qdisc((struct nl_object *) qdisc, (void *) 2); rtnl_qdisc_put(qdisc); } nl_cache_free(class_cache); }
int accept_tcmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; if (n->nlmsg_type == RTM_NEWTFILTER || n->nlmsg_type == RTM_DELTFILTER) { print_filter(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWTCLASS || n->nlmsg_type == RTM_DELTCLASS) { print_class(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWQDISC || n->nlmsg_type == RTM_DELQDISC) { print_qdisc(who, n, arg); return 0; } if (n->nlmsg_type == RTM_GETACTION || n->nlmsg_type == RTM_NEWACTION || n->nlmsg_type == RTM_DELACTION) { print_action(who, n, arg); return 0; } if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP && n->nlmsg_type != NLMSG_DONE) { fprintf(fp, "Unknown message: length %08d type %08x flags %08x\n", n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); } 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); }
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_class_get_handle(class); dump_params.dp_prefix = (int) arg; nl_object_dump(obj, &dump_params); leaf = rtnl_class_leaf_qdisc(class, qdisc_cache); if (leaf) print_qdisc((struct nl_object *) leaf, arg + 2); rtnl_class_foreach_child(class, 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); }