All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Naab <jn@stusta.de>
To: netdev@vger.kernel.org
Subject: [PATCH] iproute2: tc netem rate: allow negative packet/cell overhead
Date: Wed, 23 Jan 2013 22:38:19 +0100	[thread overview]
Message-ID: <5100584B.6000108@stusta.de> (raw)

From: Johannes Naab <jn@stusta.de>

by fixing the parsing of command-line tokens

Signed-off-by: Johannes Naab <jn@stusta.de>
---

The packet or cell overhead used with the rate extension can be negative. The
man page tc-netem(8) documents this. However, iproute2 currently does not
detect negative numbers as valid token.

> $ tc qdisc add dev eth0 root netem rate 1024bps -14
> What is "-14"?
> Usage: ... netem [ limit PACKETS ]

I developed this patch while doing a student project at
http://www.nav.ei.tum.de/.


 tc/q_netem.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tc/q_netem.c b/tc/q_netem.c
index f8489e9..2583072 100644
--- a/tc/q_netem.c
+++ b/tc/q_netem.c
@@ -147,6 +147,8 @@ static int get_distribution(const char *type, __s16 *data, int maxdata)
 }
 
 #define NEXT_IS_NUMBER() (NEXT_ARG_OK() && isdigit(argv[1][0]))
+#define NEXT_IS_SIGNED_NUMBER() \
+	(NEXT_ARG_OK() && (isdigit(argv[1][0]) || argv[1][0] == '-'))
 
 /* Adjust for the fact that psched_ticks aren't always usecs
    (based on kernel PSCHED_CLOCK configuration */
@@ -393,7 +395,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 				explain1("rate");
 				return -1;
 			}
-			if (NEXT_IS_NUMBER()) {
+			if (NEXT_IS_SIGNED_NUMBER()) {
 				NEXT_ARG();
 				if (get_s32(&rate.packet_overhead, *argv, 0)) {
 					explain1("rate");
@@ -407,7 +409,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 					return -1;
 				}
 			}
-			if (NEXT_IS_NUMBER()) {
+			if (NEXT_IS_SIGNED_NUMBER()) {
 				NEXT_ARG();
 				if (get_s32(&rate.cell_overhead, *argv, 0)) {
 					explain1("rate");

                 reply	other threads:[~2013-01-23 21:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5100584B.6000108@stusta.de \
    --to=jn@stusta.de \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.