Changeset View
Changeset View
Standalone View
Standalone View
sbin/pfctl/pfctl_altq.c
Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
static void gsc_add_sc(struct gen_sc *, struct service_curve *); | static void gsc_add_sc(struct gen_sc *, struct service_curve *); | ||||
static int is_gsc_under_sc(struct gen_sc *, | static int is_gsc_under_sc(struct gen_sc *, | ||||
struct service_curve *); | struct service_curve *); | ||||
static struct segment *gsc_getentry(struct gen_sc *, double); | static struct segment *gsc_getentry(struct gen_sc *, double); | ||||
static int gsc_add_seg(struct gen_sc *, double, double, double, | static int gsc_add_seg(struct gen_sc *, double, double, double, | ||||
double); | double); | ||||
static double sc_x2y(struct service_curve *, double); | static double sc_x2y(struct service_curve *, double); | ||||
#ifdef __FreeBSD__ | |||||
u_int64_t getifspeed(int, char *); | |||||
#else | |||||
u_int32_t getifspeed(char *); | u_int32_t getifspeed(char *); | ||||
#endif | |||||
u_long getifmtu(char *); | u_long getifmtu(char *); | ||||
int eval_queue_opts(struct pf_altq *, struct node_queue_opt *, | int eval_queue_opts(struct pf_altq *, struct node_queue_opt *, | ||||
u_int64_t); | u_int64_t); | ||||
u_int64_t eval_bwspec(struct node_queue_bw *, u_int64_t); | u_int64_t eval_bwspec(struct node_queue_bw *, u_int64_t); | ||||
void print_hfsc_sc(const char *, u_int, u_int, u_int, | void print_hfsc_sc(const char *, u_int, u_int, u_int, | ||||
const struct node_hfsc_sc *); | const struct node_hfsc_sc *); | ||||
void print_fairq_sc(const char *, u_int, u_int, u_int, | void print_fairq_sc(const char *, u_int, u_int, u_int, | ||||
const struct node_fairq_sc *); | const struct node_fairq_sc *); | ||||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | eval_pfaltq(struct pfctl *pf, struct pf_altq *pa, struct node_queue_bw *bw, | ||||
struct node_queue_opt *opts) | struct node_queue_opt *opts) | ||||
{ | { | ||||
u_int64_t rate; | u_int64_t rate; | ||||
u_int size, errors = 0; | u_int size, errors = 0; | ||||
if (bw->bw_absolute > 0) | if (bw->bw_absolute > 0) | ||||
pa->ifbandwidth = bw->bw_absolute; | pa->ifbandwidth = bw->bw_absolute; | ||||
else | else | ||||
#ifdef __FreeBSD__ | |||||
if ((rate = getifspeed(pf->dev, pa->ifname)) == 0) { | |||||
#else | |||||
if ((rate = getifspeed(pa->ifname)) == 0) { | if ((rate = getifspeed(pa->ifname)) == 0) { | ||||
#endif | |||||
fprintf(stderr, "interface %s does not know its bandwidth, " | fprintf(stderr, "interface %s does not know its bandwidth, " | ||||
"please specify an absolute bandwidth\n", | "please specify an absolute bandwidth\n", | ||||
pa->ifname); | pa->ifname); | ||||
errors++; | errors++; | ||||
} else if ((pa->ifbandwidth = eval_bwspec(bw, rate)) == 0) | } else if ((pa->ifbandwidth = eval_bwspec(bw, rate)) == 0) | ||||
pa->ifbandwidth = rate; | pa->ifbandwidth = rate; | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 916 Lines • ▼ Show 20 Lines | rate2str(double rate) | ||||
if ((int)(rate * 100) % 100) | if ((int)(rate * 100) % 100) | ||||
snprintf(buf, RATESTR_MAX, "%.2f%cb", rate, unit[i]); | snprintf(buf, RATESTR_MAX, "%.2f%cb", rate, unit[i]); | ||||
else | else | ||||
snprintf(buf, RATESTR_MAX, "%d%cb", (int)rate, unit[i]); | snprintf(buf, RATESTR_MAX, "%d%cb", (int)rate, unit[i]); | ||||
return (buf); | return (buf); | ||||
} | } | ||||
#ifdef __FreeBSD__ | |||||
/* | |||||
* XXX | |||||
* FreeBSD does not have SIOCGIFDATA. | |||||
* To emulate this, DIOCGIFSPEED ioctl added to pf. | |||||
*/ | |||||
u_int64_t | |||||
getifspeed(int pfdev, char *ifname) | |||||
{ | |||||
struct pf_ifspeed io; | |||||
bzero(&io, sizeof io); | |||||
if (strlcpy(io.ifname, ifname, IFNAMSIZ) >= | |||||
sizeof(io.ifname)) | |||||
errx(1, "getifspeed: strlcpy"); | |||||
if (ioctl(pfdev, DIOCGIFSPEED, &io) == -1) | |||||
err(1, "DIOCGIFSPEED"); | |||||
return (io.baudrate); | |||||
} | |||||
#else | |||||
u_int32_t | u_int32_t | ||||
getifspeed(char *ifname) | getifspeed(char *ifname) | ||||
{ | { | ||||
int s; | int s; | ||||
struct ifreq ifr; | struct ifreq ifr; | ||||
struct if_data ifrdat; | struct if_data ifrdat; | ||||
s = get_query_socket(); | s = get_query_socket(); | ||||
bzero(&ifr, sizeof(ifr)); | bzero(&ifr, sizeof(ifr)); | ||||
if (strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)) >= | if (strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)) >= | ||||
sizeof(ifr.ifr_name)) | sizeof(ifr.ifr_name)) | ||||
errx(1, "getifspeed: strlcpy"); | errx(1, "getifspeed: strlcpy"); | ||||
ifr.ifr_data = (caddr_t)&ifrdat; | ifr.ifr_data = (caddr_t)&ifrdat; | ||||
if (ioctl(s, SIOCGIFDATA, (caddr_t)&ifr) == -1) | if (ioctl(s, SIOCGIFDATA, (caddr_t)&ifr) == -1) | ||||
err(1, "SIOCGIFDATA"); | err(1, "SIOCGIFDATA"); | ||||
return ((u_int32_t)ifrdat.ifi_baudrate); | return ((u_int32_t)ifrdat.ifi_baudrate); | ||||
} | } | ||||
#endif | |||||
u_long | u_long | ||||
getifmtu(char *ifname) | getifmtu(char *ifname) | ||||
{ | { | ||||
int s; | int s; | ||||
struct ifreq ifr; | struct ifreq ifr; | ||||
s = get_query_socket(); | s = get_query_socket(); | ||||
▲ Show 20 Lines • Show All 165 Lines • Show Last 20 Lines |