Changeset View
Changeset View
Standalone View
Standalone View
sbin/ipfw/dummynet.c
Show All 17 Lines | |||||
* This software is provided ``AS IS'' without any warranties of any kind. | * This software is provided ``AS IS'' without any warranties of any kind. | ||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
* | * | ||||
* dummynet support | * dummynet support | ||||
*/ | */ | ||||
#define NEW_AQM | #define NEW_AQM | ||||
#include <sys/limits.h> | |||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
/* XXX there are several sysctl leftover here */ | /* XXX there are several sysctl leftover here */ | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include "ipfw2.h" | #include "ipfw2.h" | ||||
#ifdef NEW_AQM | #ifdef NEW_AQM | ||||
▲ Show 20 Lines • Show All 755 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/* | /* | ||||
* Take as input a string describing a bandwidth value | * Take as input a string describing a bandwidth value | ||||
* and return the numeric bandwidth value. | * and return the numeric bandwidth value. | ||||
* set clocking interface or bandwidth value | * set clocking interface or bandwidth value | ||||
*/ | */ | ||||
static void | static void | ||||
read_bandwidth(char *arg, int *bandwidth, char *if_name, int namelen) | read_bandwidth(char *arg, uint32_t *bandwidth, char *if_name, int namelen) | ||||
{ | { | ||||
if (*bandwidth != -1) | if (*bandwidth != (uint32_t)-1) | ||||
warnx("duplicate token, override bandwidth value!"); | warnx("duplicate token, override bandwidth value!"); | ||||
if (arg[0] >= 'a' && arg[0] <= 'z') { | if (arg[0] >= 'a' && arg[0] <= 'z') { | ||||
if (!if_name) { | if (!if_name) { | ||||
errx(1, "no if support"); | errx(1, "no if support"); | ||||
} | } | ||||
if (namelen >= IFNAMSIZ) | if (namelen >= IFNAMSIZ) | ||||
warn("interface name truncated"); | warn("interface name truncated"); | ||||
namelen--; | namelen--; | ||||
/* interface name */ | /* interface name */ | ||||
strlcpy(if_name, arg, namelen); | strlcpy(if_name, arg, namelen); | ||||
*bandwidth = 0; | *bandwidth = 0; | ||||
} else { /* read bandwidth value */ | } else { /* read bandwidth value */ | ||||
int bw; | uint64_t bw; | ||||
char *end = NULL; | char *end = NULL; | ||||
bw = strtoul(arg, &end, 0); | bw = strtoul(arg, &end, 0); | ||||
if (*end == 'K' || *end == 'k') { | if (*end == 'K' || *end == 'k') { | ||||
end++; | end++; | ||||
bw *= 1000; | bw *= 1000; | ||||
} else if (*end == 'M' || *end == 'm') { | } else if (*end == 'M' || *end == 'm') { | ||||
end++; | end++; | ||||
bw *= 1000000; | bw *= 1000000; | ||||
} else if (*end == 'G' || *end == 'g') { | } else if (*end == 'G' || *end == 'g') { | ||||
end++; | end++; | ||||
bw *= 1000000000; | bw *= 1000000000; | ||||
} | } | ||||
if ((*end == 'B' && | if ((*end == 'B' && | ||||
_substrcmp2(end, "Bi", "Bit/s") != 0) || | _substrcmp2(end, "Bi", "Bit/s") != 0) || | ||||
_substrcmp2(end, "by", "bytes") == 0) | _substrcmp2(end, "by", "bytes") == 0) | ||||
bw *= 8; | bw *= 8; | ||||
if (bw < 0) | if (bw > UINT_MAX) | ||||
errx(EX_DATAERR, "bandwidth too large"); | errx(EX_DATAERR, "bandwidth too large"); | ||||
*bandwidth = bw; | *bandwidth = (uint32_t)bw; | ||||
if (if_name) | if (if_name) | ||||
if_name[0] = '\0'; | if_name[0] = '\0'; | ||||
} | } | ||||
} | } | ||||
struct point { | struct point { | ||||
double prob; | double prob; | ||||
double delay; | double delay; | ||||
▲ Show 20 Lines • Show All 888 Lines • ▼ Show 20 Lines | default: | ||||
errx(EX_DATAERR, "unrecognised option ``%s''", av[-1]); | errx(EX_DATAERR, "unrecognised option ``%s''", av[-1]); | ||||
} | } | ||||
} | } | ||||
/* check validity of parameters */ | /* check validity of parameters */ | ||||
if (p) { | if (p) { | ||||
if (p->delay > 10000) | if (p->delay > 10000) | ||||
errx(EX_DATAERR, "delay must be < 10000"); | errx(EX_DATAERR, "delay must be < 10000"); | ||||
if (p->bandwidth == -1) | if (p->bandwidth == (uint32_t)-1) | ||||
p->bandwidth = 0; | p->bandwidth = 0; | ||||
} | } | ||||
if (fs) { | if (fs) { | ||||
/* XXX accept a 0 scheduler to keep the default */ | /* XXX accept a 0 scheduler to keep the default */ | ||||
if (fs->flags & DN_QSIZE_BYTES) { | if (fs->flags & DN_QSIZE_BYTES) { | ||||
size_t len; | size_t len; | ||||
long limit; | long limit; | ||||
▲ Show 20 Lines • Show All 247 Lines • Show Last 20 Lines |