]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/commitdiff
Handle new/old API and new additions to tc_stats.
authorosdl.net!shemminger <osdl.net!shemminger>
Tue, 31 Aug 2004 17:45:21 +0000 (17:45 +0000)
committerosdl.net!shemminger <osdl.net!shemminger>
Tue, 31 Aug 2004 17:45:21 +0000 (17:45 +0000)
2004/08/29 10:20:25-07:00 net[shemminger]!shemminger
Import patch reqs-patch-iproute2-2.6.8

(Logical change 1.77)

tc/tc_qdisc.c

index eb451a47119327b4feed44dc62d43bf990d61c41..8f324895307bcabcd5dd2887a5f3bac77af26bcc 100644 (file)
@@ -167,34 +167,44 @@ int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
        return 0;
 }
 
-void print_tcstats(FILE *fp, struct tc_stats *st)
+
+void print_tcstats_attr(FILE *fp, const struct rtattr *rta)
 {
+       struct tc_stats st;
        SPRINT_BUF(b1);
 
-       fprintf(fp, " Sent %llu bytes %u pkts (dropped %u, overlimits %u ) ",
-               (unsigned long long)st->bytes, st->packets, st->drops, st->overlimits);
-       if (st->bps || st->pps || st->qlen || st->backlog) {
+       /* handle case where kernel returns more/less than we know about */
+       memset(&st, 0, sizeof(st));
+       memcpy(&st, RTA_DATA(rta), MIN(RTA_PAYLOAD(rta), sizeof(st)));
+
+       fprintf(fp, " Sent %llu bytes %u pkts (dropped %u, overlimits %u requeus%u ) ",
+               (unsigned long long)st.bytes, st.packets, st.drops, 
+               st.overlimits, st.reqs);
+
+       if (st.bps || st.pps || st.qlen || st.backlog) {
                fprintf(fp, "\n ");
-               if (st->bps || st->pps) {
+               if (st.bps || st.pps) {
                        fprintf(fp, "rate ");
-                       if (st->bps)
-                               fprintf(fp, "%s ", sprint_rate(st->bps, b1));
-                       if (st->pps)
-                               fprintf(fp, "%upps ", st->pps);
+                       if (st.bps)
+                               fprintf(fp, "%s ", sprint_rate(st.bps, b1));
+                       if (st.pps)
+                               fprintf(fp, "%upps ", st.pps);
                }
-               if (st->qlen || st->backlog) {
+               if (st.qlen || st.backlog) {
                        fprintf(fp, "backlog ");
-                       if (st->backlog)
-                               fprintf(fp, "%s ", sprint_size(st->backlog, b1));
-                       if (st->qlen)
-                               fprintf(fp, "%up ", st->qlen);
+                       if (st.backlog)
+                               fprintf(fp, "%s ", sprint_size(st.backlog, b1));
+                       if (st.qlen)
+                               fprintf(fp, "%up ", st.qlen);
                }
        }
 }
 
 static int filter_ifindex;
 
-int print_qdisc(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
+static int print_qdisc(const struct sockaddr_nl *who, 
+                      const struct nlmsghdr *n, 
+                      void *arg)
 {
        FILE *fp = (FILE*)arg;
        struct tcmsg *t = NLMSG_DATA(n);
@@ -255,16 +265,11 @@ int print_qdisc(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        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");
-                       }
+                       print_tcstats_attr(fp, tb[TCA_STATS]);
+                       fprintf(fp, "\n");
                }
-               if (q && tb[TCA_XSTATS]) {
+
+               if (q && tb[TCA_XSTATS] && q->print_xstats) {
                        q->print_xstats(q, fp, tb[TCA_XSTATS]);
                        fprintf(fp, "\n");
                }