static int atm_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) { struct rtattr *tb[TCA_ATM_MAX+1]; char buffer[MAX_ATM_ADDR_LEN+1]; if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_ATM_MAX, opt); if (tb[TCA_ATM_ADDR]) { if (RTA_PAYLOAD(tb[TCA_ATM_ADDR]) < sizeof(struct sockaddr_atmpvc)) fprintf(stderr,"ATM: address too short\n"); else { if (atm2text(buffer,MAX_ATM_ADDR_LEN, RTA_DATA(tb[TCA_ATM_ADDR]),A2T_PRETTY | A2T_NAME) < 0) fprintf(stderr,"atm2text error\n"); fprintf(f,"pvc %s ",buffer); } } if (tb[TCA_ATM_HDR]) { int i; const __u8 *hdr = RTA_DATA(tb[TCA_ATM_HDR]); fprintf(f,"hdr"); for (i = 0; i < RTA_PAYLOAD(tb[TCA_ATM_HDR]); i++) fprintf(f,"%c%02x", i ? '.' : ' ', hdr[i]); if (!i) fprintf(f," ."); fprintf(f," "); } if (tb[TCA_ATM_EXCESS]) { __u32 excess; if (RTA_PAYLOAD(tb[TCA_ATM_EXCESS]) < sizeof(excess)) fprintf(stderr,"ATM: excess class ID too short\n"); else { excess = rta_getattr_u32(tb[TCA_ATM_EXCESS]); if (!excess) fprintf(f,"excess clp "); else { char buf[64]; print_tc_classid(buf,sizeof(buf),excess); fprintf(f,"excess %s ",buf); } } } if (tb[TCA_ATM_STATE]) { static const char *map[] = { ATM_VS2TXT_MAP }; int state; if (RTA_PAYLOAD(tb[TCA_ATM_STATE]) < sizeof(state)) fprintf(stderr,"ATM: state field too short\n"); else { state = *(int *) RTA_DATA(tb[TCA_ATM_STATE]); fprintf(f,"%s ",map[state]); } } return 0; }
int print_qdisc(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct tcmsg *t = NLMSG_DATA(n); int len = n->nlmsg_len; struct rtattr * tb[TCA_MAX+1]; struct qdisc_util *q; char abuf[256]; if (n->nlmsg_type != RTM_NEWQDISC && n->nlmsg_type != RTM_DELQDISC) { fprintf(stderr, "Not a qdisc\n"); return 0; } len -= NLMSG_LENGTH(sizeof(*t)); if (len < 0) { fprintf(stderr, "Wrong len %d\n", len); return -1; } if (filter_ifindex && filter_ifindex != t->tcm_ifindex) return 0; memset(tb, 0, sizeof(tb)); parse_rtattr(tb, TCA_MAX, TCA_RTA(t), len); if (tb[TCA_KIND] == NULL) { fprintf(stderr, "print_qdisc: NULL kind\n"); return -1; } if (n->nlmsg_type == RTM_DELQDISC) fprintf(fp, "deleted "); fprintf(fp, "qdisc %s %x: ", (char*)RTA_DATA(tb[TCA_KIND]), t->tcm_handle>>16); if (filter_ifindex == 0) fprintf(fp, "dev %s ", ll_index_to_name(t->tcm_ifindex)); if (t->tcm_parent == TC_H_ROOT) fprintf(fp, "root "); else if (t->tcm_parent) { print_tc_classid(abuf, sizeof(abuf), t->tcm_parent); fprintf(fp, "parent %s ", abuf); } if (t->tcm_info != 1) { fprintf(fp, "refcnt %d ", t->tcm_info); } /* pfifo_fast is generic enough to warrant the hardcoding --JHS */ if (0 == strcmp("pfifo_fast", RTA_DATA(tb[TCA_KIND]))) q = get_qdisc_kind("prio"); else q = get_qdisc_kind(RTA_DATA(tb[TCA_KIND])); if (tb[TCA_OPTIONS]) { if (q) q->print_qopt(q, fp, tb[TCA_OPTIONS]); else fprintf(fp, "[cannot parse qdisc parameters]"); } fprintf(fp, "\n"); if (show_stats) { struct rtattr *xstats = NULL; if (tb[TCA_STATS] || tb[TCA_STATS2] || tb[TCA_XSTATS]) { print_tcstats_attr(fp, tb, " ", &xstats); fprintf(fp, "\n"); } if (q && xstats && q->print_xstats) { q->print_xstats(q, fp, xstats); fprintf(fp, "\n"); } } fflush(fp); return 0; }
int print_qdisc(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct tcmsg *t = NLMSG_DATA(n); int len = n->nlmsg_len; struct rtattr * tb[TCA_MAX+1]; struct qdisc_util *q; char abuf[256]; if (n->nlmsg_type != RTM_NEWQDISC && n->nlmsg_type != RTM_DELQDISC) { fprintf(stderr, "Not a qdisc\n"); return 0; } len -= NLMSG_LENGTH(sizeof(*t)); if (len < 0) { fprintf(stderr, "Wrong len %d\n", len); return -1; } if (filter_ifindex && filter_ifindex != t->tcm_ifindex) return 0; memset(tb, 0, sizeof(tb)); parse_rtattr(tb, TCA_MAX, TCA_RTA(t), len); if (tb[TCA_KIND] == NULL) { fprintf(stderr, "NULL kind\n"); return -1; } if (n->nlmsg_type == RTM_DELQDISC) fprintf(fp, "deleted "); fprintf(fp, "qdisc %s %x: ", (char*)RTA_DATA(tb[TCA_KIND]), t->tcm_handle>>16); if (filter_ifindex == 0) fprintf(fp, "dev %s ", ll_index_to_name(t->tcm_ifindex)); if (t->tcm_parent == TC_H_ROOT) fprintf(fp, "root "); else if (t->tcm_parent) { print_tc_classid(abuf, sizeof(abuf), t->tcm_parent); fprintf(fp, "parent %s ", abuf); } if (t->tcm_info != 1) { fprintf(fp, "refcnt %d ", t->tcm_info); } if ((q = get_qdisc_kind(RTA_DATA(tb[TCA_KIND]))) != NULL) q->print_qopt(q, fp, tb[TCA_OPTIONS]); else fprintf(fp, "[UNKNOWN]"); fprintf(fp, "\n"); if (show_stats) { if (tb[TCA_STATS]) { if (RTA_PAYLOAD(tb[TCA_STATS]) < sizeof(struct tc_stats)) fprintf(fp, "statistics truncated"); else { struct tc_stats st; memcpy(&st, RTA_DATA(tb[TCA_STATS]), sizeof(st)); print_tcstats(fp, &st); fprintf(fp, "\n"); } } if (q && tb[TCA_XSTATS]) { q->print_xstats(q, fp, tb[TCA_XSTATS]); fprintf(fp, "\n"); } fprintf(fp, "\n "); } fflush(fp); return 0; }