From patchwork Mon Jun 3 15:19:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 248313 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 0B09C2C00A0 for ; Tue, 4 Jun 2013 01:19:51 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758049Ab3FCPTs (ORCPT ); Mon, 3 Jun 2013 11:19:48 -0400 Received: from mail-pb0-f44.google.com ([209.85.160.44]:64386 "EHLO mail-pb0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755880Ab3FCPTq (ORCPT ); Mon, 3 Jun 2013 11:19:46 -0400 Received: by mail-pb0-f44.google.com with SMTP id wz12so5855698pbc.31 for ; Mon, 03 Jun 2013 08:19:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :content-type:x-mailer:content-transfer-encoding:mime-version; bh=GhxOpPc7u3Wd1MVfw+IIrjgQ8oqJJEjMpuDQRDWRkkM=; b=cH1NwcJ3L62yQIf3bSp3QbUXkDVsKyY0NIMfbg5oSHvuZvauyhe3wptMyd2ekHxFy5 RyYRTrUI0v0msH8Ri8BWqpLNXfxYUR4t9Iokz8ZOE6gm+zSsqn8ug/7PIdafwdS6rCXD pesbJxgkleSvZgjsUFsl6NoKOm+xE3wU7l0lW5o+l24aAgAZm3eqN/69iOUtMF/RLqa9 fDDLavhuF4zmlpfB7Q7+xD7vsV3EL9Zxr7GiFUvmU4D2iX/yOA3VJzKD/6kipvenIIc3 /LBwJcn8sGnYZAIsogYl6aaC3vw/WVslh2+furZdYcQORJu3Zo3BpNEgKNcDCOB0QWP8 enWQ== X-Received: by 10.68.201.163 with SMTP id kb3mr9406804pbc.191.1370272786110; Mon, 03 Jun 2013 08:19:46 -0700 (PDT) Received: from [172.26.50.3] ([172.26.50.3]) by mx.google.com with ESMTPSA id xd2sm19648012pac.15.2013.06.03.08.19.44 for (version=SSLv3 cipher=RC4-SHA bits=128/128); Mon, 03 Jun 2013 08:19:45 -0700 (PDT) Message-ID: <1370272783.24311.148.camel@edumazet-glaptop> Subject: Re: [PATCH v2 iproute2] get_rate: detect 32bit overflows From: Eric Dumazet To: Ben Hutchings Cc: Stephen Hemminger , netdev Date: Mon, 03 Jun 2013 08:19:43 -0700 In-Reply-To: <1370270231.1918.10.camel@bwh-desktop.uk.level5networks.com> References: <1370199083.24311.43.camel@edumazet-glaptop> <1370209008.24311.91.camel@edumazet-glaptop> <1370270231.1918.10.camel@bwh-desktop.uk.level5networks.com> X-Mailer: Evolution 3.2.3-0ubuntu6 Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Mon, 2013-06-03 at 15:37 +0100, Ben Hutchings wrote: > This would be more understandable without a goto. I think this ordering > would work: Yeah you're right, thanks ! [PATCH v3] get_rate: detect 32bit overflows Current rate limit is 34.359.738.360 bit per second, and unfortunately 40Gbps links are above it. overflows in get_rate() are currently not detected, and some users are confused. Let's detect this and complain. Note that some qdisc are ready to get extended range, but this will need additional attributes and new iproute2 Signed-off-by: Eric Dumazet --- tc/tc_util.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/tc/tc_util.c b/tc/tc_util.c index 8e62a01..912216c 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -146,25 +146,29 @@ static const struct rate_suffix { int get_rate(unsigned *rate, const char *str) { char *p; - double bps = strtod(str, &p); + long long bps = strtoll(str, &p, 0); const struct rate_suffix *s; if (p == str) return -1; - if (*p == '\0') { - *rate = bps / 8.; /* assume bits/sec */ - return 0; - } - for (s = suffixes; s->name; ++s) { if (strcasecmp(s->name, p) == 0) { - *rate = (bps * s->scale) / 8.; - return 0; + bps *= s->scale; + p += strlen(p); + break; } } - return -1; + if (*p) + return -1; /* unknown suffix */ + + bps /= 8; /* -> bytes per second */ + *rate = bps; + /* detect if an overflow happened */ + if (*rate != bps) + return -1; + return 0; } void print_rate(char *buf, int len, __u32 rate)