summaryrefslogtreecommitdiffstats
path: root/tc
diff options
context:
space:
mode:
authorosdl.net!shemminger <osdl.net!shemminger>2004-06-25 20:59:28 +0000
committerosdl.net!shemminger <osdl.net!shemminger>2004-06-25 20:59:28 +0000
commit63e989f5e043a3a45857fe4ba083c49050eb3300 (patch)
treee8bb44caf67f10f334dc96b610edbbe9faa48dee /tc
parentdb72dd16e08f4a20b61f6b3d2fe18d52750dabf0 (diff)
add loss paramater.
(Logical change 1.31)
Diffstat (limited to 'tc')
-rw-r--r--tc/q_delay.c11
-rw-r--r--tc/tc_util.c29
-rw-r--r--tc/tc_util.h3
3 files changed, 43 insertions, 0 deletions
diff --git a/tc/q_delay.c b/tc/q_delay.c
index 8be83d0b..0dd528fc 100644
--- a/tc/q_delay.c
+++ b/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;
}
diff --git a/tc/tc_util.c b/tc/tc_util.c
index e4c78823..7b52ea15 100644
--- a/tc/tc_util.c
+++ b/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);
diff --git a/tc/tc_util.h b/tc/tc_util.h
index b3300f0f..208adbe1 100644
--- a/tc/tc_util.h
+++ b/tc/tc_util.h
@@ -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);