int print_police(struct action_util *a, FILE *f, struct rtattr *arg) { SPRINT_BUF(b1); SPRINT_BUF(b2); struct tc_police *p; struct rtattr *tb[TCA_POLICE_MAX+1]; unsigned buffer; unsigned int linklayer; if (arg == NULL) return 0; parse_rtattr_nested(tb, TCA_POLICE_MAX, arg); if (tb[TCA_POLICE_TBF] == NULL) { fprintf(f, "[NULL police tbf]"); return 0; } #ifndef STOOPID_8BYTE if (RTA_PAYLOAD(tb[TCA_POLICE_TBF]) < sizeof(*p)) { fprintf(f, "[truncated police tbf]"); return -1; } #endif p = RTA_DATA(tb[TCA_POLICE_TBF]); fprintf(f, " police 0x%x ", p->index); fprintf(f, "rate %s ", sprint_rate(p->rate.rate, b1)); buffer = tc_calc_xmitsize(p->rate.rate, p->burst); fprintf(f, "burst %s ", sprint_size(buffer, b1)); fprintf(f, "mtu %s ", sprint_size(p->mtu, b1)); if (show_raw) fprintf(f, "[%08x] ", p->burst); if (p->peakrate.rate) fprintf(f, "peakrate %s ", sprint_rate(p->peakrate.rate, b1)); if (tb[TCA_POLICE_AVRATE]) fprintf(f, "avrate %s ", sprint_rate(rta_getattr_u32(tb[TCA_POLICE_AVRATE]), b1)); fprintf(f, "action %s", police_action_n2a(p->action, b1, sizeof(b1))); if (tb[TCA_POLICE_RESULT]) { fprintf(f, "/%s ", police_action_n2a(*(int*)RTA_DATA(tb[TCA_POLICE_RESULT]), b1, sizeof(b1))); } else fprintf(f, " "); fprintf(f, "overhead %ub ", p->rate.overhead); linklayer = (p->rate.linklayer & TC_LINKLAYER_MASK); if (linklayer > TC_LINKLAYER_ETHERNET || show_details) fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b2)); fprintf(f, "\nref %d bind %d\n",p->refcnt, p->bindcnt); return 0; }
void print_size_table(FILE *fp, const char *prefix, struct rtattr *rta) { struct rtattr *tb[TCA_STAB_MAX + 1]; SPRINT_BUF(b1); parse_rtattr_nested(tb, TCA_STAB_MAX, rta); if (tb[TCA_STAB_BASE]) { struct tc_sizespec s = {0}; memcpy(&s, RTA_DATA(tb[TCA_STAB_BASE]), MIN(RTA_PAYLOAD(tb[TCA_STAB_BASE]), sizeof(s))); fprintf(fp, "%s", prefix); if (s.linklayer) fprintf(fp, "linklayer %s ", sprint_linklayer(s.linklayer, b1)); if (s.overhead) fprintf(fp, "overhead %d ", s.overhead); if (s.mpu) fprintf(fp, "mpu %u ", s.mpu); if (s.mtu) fprintf(fp, "mtu %u ", s.mtu); if (s.tsize) fprintf(fp, "tsize %u ", s.tsize); } #if 0 if (tb[TCA_STAB_DATA]) { unsigned i, j, dlen; __u16 *data = RTA_DATA(tb[TCA_STAB_DATA]); dlen = RTA_PAYLOAD(tb[TCA_STAB_DATA]) / sizeof(__u16); fprintf(fp, "\n%sstab data:", prefix); for (i = 0; i < dlen/12; i++) { fprintf(fp, "\n%s %3u:", prefix, i * 12); for (j = 0; i * 12 + j < dlen; j++) fprintf(fp, " %05x", data[i * 12 + j]); } } #endif }