parent
db72dd16e0
commit
63e989f5e0
11
tc/q_delay.c
11
tc/q_delay.c
|
|
@ -64,6 +64,13 @@ static int delay_parse_opt(struct qdisc_util *qu, int argc, char **argv,
|
|||
return -1;
|
||||
}
|
||||
ok++;
|
||||
} else if (matches(*argv, "loss") == 0) {
|
||||
NEXT_ARG();
|
||||
if (get_percent(&opt.loss, *argv)) {
|
||||
explain1("loss");
|
||||
return -1;
|
||||
}
|
||||
ok++;
|
||||
} else if (matches(*argv, "rate") == 0) {
|
||||
NEXT_ARG();
|
||||
if (rate) {
|
||||
|
|
@ -125,11 +132,15 @@ static int delay_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
|
|||
|
||||
if (RTA_PAYLOAD(opt) < sizeof(*qopt))
|
||||
return -1;
|
||||
|
||||
qopt = RTA_DATA(opt);
|
||||
|
||||
fprintf(f, "delay limit %s latency %s ",
|
||||
sprint_size(qopt->limit, b1),
|
||||
sprint_usecs(qopt->latency, b2));
|
||||
if (qopt->loss)
|
||||
fprintf(f, "loss %s ",
|
||||
sprint_percent(qopt->loss, b1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
29
tc/tc_util.c
29
tc/tc_util.c
|
|
@ -314,6 +314,35 @@ char * sprint_size(__u32 size, char *buf)
|
|||
return buf;
|
||||
}
|
||||
|
||||
static double percent_scale = (double)(1ull << 32) / 100.;
|
||||
|
||||
int get_percent(__u32 *percent, const char *str)
|
||||
{
|
||||
char *p;
|
||||
double per = strtod(str, &p);
|
||||
|
||||
if (per > 100.)
|
||||
return -1;
|
||||
if (*p && strcmp(p, "%"))
|
||||
return -1;
|
||||
|
||||
*percent = per * percent_scale;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int print_percent(char *buf, int len, __u32 per)
|
||||
{
|
||||
snprintf(buf, len, "%g%%", (double) per / percent_scale);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char * sprint_percent(__u32 per, char *buf)
|
||||
{
|
||||
if (print_percent(buf, SPRINT_BSIZE-1, per))
|
||||
strcpy(buf, "???");
|
||||
return buf;
|
||||
}
|
||||
|
||||
int print_qdisc_handle(char *buf, int len, __u32 h)
|
||||
{
|
||||
snprintf(buf, len, "%x:", TC_H_MAJ(h)>>16);
|
||||
|
|
|
|||
|
|
@ -31,11 +31,13 @@ extern struct filter_util *get_filter_kind(const char *str);
|
|||
|
||||
extern int get_qdisc_handle(__u32 *h, const char *str);
|
||||
extern int get_rate(unsigned *rate, const char *str);
|
||||
extern int get_percent(unsigned *percent, const char *str);
|
||||
extern int get_size(unsigned *size, const char *str);
|
||||
extern int get_size_and_cell(unsigned *size, int *cell_log, char *str);
|
||||
extern int get_usecs(unsigned *usecs, const char *str);
|
||||
extern int print_rate(char *buf, int len, __u32 rate);
|
||||
extern int print_size(char *buf, int len, __u32 size);
|
||||
extern int print_percent(char *buf, int len, __u32 percent);
|
||||
extern int print_qdisc_handle(char *buf, int len, __u32 h);
|
||||
extern int print_usecs(char *buf, int len, __u32 usecs);
|
||||
extern char * sprint_rate(__u32 rate, char *buf);
|
||||
|
|
@ -43,6 +45,7 @@ extern char * sprint_size(__u32 size, char *buf);
|
|||
extern char * sprint_qdisc_handle(__u32 h, char *buf);
|
||||
extern char * sprint_tc_classid(__u32 h, char *buf);
|
||||
extern char * sprint_usecs(__u32 usecs, char *buf);
|
||||
extern char * sprint_percent(__u32 percent, char *buf);
|
||||
|
||||
extern void print_tcstats(FILE *fp, struct tc_stats *st);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue