lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Wed, 15 Nov 2017 09:58:56 -0800
From:   Stephen Hemminger <stephen@...workplumber.org>
To:     Nishanth Devarajan <ndev2021@...il.com>
Cc:     netdev@...r.kernel.org, doucette@...edu, michel.machado@...il.com
Subject: Re: [PATCH iproute2/net-next v2]tc: B.W limits can now be specified
 in %.

On Wed, 15 Nov 2017 07:06:21 +0530
Nishanth Devarajan <ndev2021@...il.com> wrote:

> int parse_percent_rate(char *rate, const char *str, char *dev)
You aren't modifyin dev so it should be const char *
> +{
> +	long max_rate_bits;
> +	int ret, saved_errno;
> +	double perc, rate_bits;
> +	char *str_perc, *p;
> +
> +	if (!dev[0]) {
> +		fprintf(stderr, "No device specified; specify device to rate limit by percentage\n");
> +		return -1;
> +	}
> +
> +	if (read_prop(dev, "speed", &max_rate_bits))
> +		return -1;

If speed is unknown, then many will devices will return -1.
You need to handle that.

Since speed reported by kernel is in mbits per second, it
would make sense to rename max_rate_bits to mbit.

> +
> +	ret = sscanf(str, "%m[0-9.%]", &str_perc);
> +	if (ret != 1)
> +		goto malf;
> +
> +	/* Make sure there's only one percent sign and it's at the end */
> +	perc = strtod(str_perc, &p);
> +	if (*p != '%' || *(p++) != '\0')
> +		goto malf;

There already is parse_percent in tc/q_netem.c.
Please move that to util and use that instead of coding here.

> +
> +	saved_errno = errno;
> +	free(str_perc);
> +
> +	if (perc > 100.0 || perc < 0.0 || saved_errno == ERANGE) {
> +		fprintf(stderr, "Invalid rate specified; should be between [0,100]%% but is %s\n", str);
> +		return -1;
> +	}
> +
> +	rate_bits = (perc * max_rate_bits) / 100.0;
> +
> +	ret = snprintf(rate, 20, "%lf", rate_bits);
> +	if (ret <= 0 || ret >= 20) {
> +		fprintf(stderr, "Unable to parse calculated rate\n");
> +		return -1;
> +	}
> +
> +	return 0;
> +
> +malf:
> +	fprintf(stderr, "Specified rate value could not be read or is malformed\n");
> +	return -1;
> +}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ