1/* $FreeBSD: head/contrib/pf/pfctl/pfctl_altq.c 126355 2004-02-28 17:32:53Z mlaier $ */ |
2/* $OpenBSD: pfctl_altq.c,v 1.77 2003/08/22 21:50:34 david Exp $ */ 3 4/* 5 * Copyright (c) 2002 6 * Sony Computer Science Laboratories Inc. 7 * Copyright (c) 2002, 2003 Henning Brauer <henning@openbsd.org> 8 * 9 * Permission to use, copy, modify, and distribute this software for any --- 7 unchanged lines hidden (view full) --- 17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 */ 21 22#include <sys/types.h> 23#include <sys/ioctl.h> 24#include <sys/socket.h> |
25#if !defined(__FreeBSD__) |
26#include <sys/limits.h> |
27#endif |
28 29#include <net/if.h> 30#include <netinet/in.h> 31#include <net/pfvar.h> 32 33#include <err.h> 34#include <errno.h> 35#include <math.h> --- 36 unchanged lines hidden (view full) --- 72static int is_gsc_under_sc(struct gen_sc *, 73 struct service_curve *); 74static void gsc_destroy(struct gen_sc *); 75static struct segment *gsc_getentry(struct gen_sc *, double); 76static int gsc_add_seg(struct gen_sc *, double, double, double, 77 double); 78static double sc_x2y(struct service_curve *, double); 79 |
80#if defined(__FreeBSD__) 81u_int32_t getifspeed(int, char *); 82#else |
83u_int32_t getifspeed(char *); |
84#endif |
85u_long getifmtu(char *); 86int eval_queue_opts(struct pf_altq *, struct node_queue_opt *, 87 u_int32_t); 88u_int32_t eval_bwspec(struct node_queue_bw *, u_int32_t); 89void print_hfsc_sc(const char *, u_int, u_int, u_int, 90 const struct node_hfsc_sc *); 91 92static u_int32_t max_qid = 1; --- 148 unchanged lines hidden (view full) --- 241eval_pfaltq(struct pfctl *pf, struct pf_altq *pa, struct node_queue_bw *bw, 242 struct node_queue_opt *opts) 243{ 244 u_int rate, size, errors = 0; 245 246 if (bw->bw_absolute > 0) 247 pa->ifbandwidth = bw->bw_absolute; 248 else |
249#if defined(__FreeBSD__) 250 if ((rate = getifspeed(pf->dev, pa->ifname)) == 0) { 251#else |
252 if ((rate = getifspeed(pa->ifname)) == 0) { |
253#endif |
254 fprintf(stderr, "cannot determine interface bandwidth " 255 "for %s, specify an absolute bandwidth\n", 256 pa->ifname); 257 errors++; 258 } else if ((pa->ifbandwidth = eval_bwspec(bw, rate)) == 0) 259 pa->ifbandwidth = rate; 260 261 errors += eval_queue_opts(pa, opts, pa->ifbandwidth); --- 613 unchanged lines hidden (view full) --- 875 return (1); 876 } else 877 return (0); 878} 879 880/* 881 * admission control using generalized service curve 882 */ |
883#if defined(__FreeBSD__) 884#if defined(INFINITY) 885#undef INFINITY 886#endif |
887#define INFINITY HUGE_VAL /* positive infinity defined in <math.h> */ |
888#else 889#define INFINITY HUGE_VAL /* positive infinity defined in <math.h> */ 890#endif |
891 892/* add a new service curve to a generalized service curve */ 893static void 894gsc_add_sc(struct gen_sc *gsc, struct service_curve *sc) 895{ 896 if (is_sc_null(sc)) 897 return; 898 if (sc->d != 0) --- 184 unchanged lines hidden (view full) --- 1083 if ((int)(rate * 100) % 100) 1084 snprintf(buf, RATESTR_MAX, "%.2f%cb", rate, unit[i]); 1085 else 1086 snprintf(buf, RATESTR_MAX, "%d%cb", (int)rate, unit[i]); 1087 1088 return (buf); 1089} 1090 |
1091#if defined(__FreeBSD__) 1092/* 1093 * XXX 1094 * FreeBSD do not have SIOCGIFDATA. 1095 * To emulate this, DIOCGIFSPEED ioctl added to pf. 1096 */ |
1097u_int32_t |
1098getifspeed(int pfdev, char *ifname) 1099{ 1100 struct pf_ifspeed io; 1101 1102 bzero(&io, sizeof io); 1103 if (strlcpy(io.ifname, ifname, IFNAMSIZ) >= 1104 sizeof(io.ifname)) 1105 errx(1, "getifspeed: strlcpy"); 1106 if (ioctl(pfdev, DIOCGIFSPEED, &io) == -1) 1107 err(1, "DIOCGIFSPEED"); 1108 return ((u_int32_t)io.baudrate); 1109} 1110#else 1111u_int32_t |
1112getifspeed(char *ifname) 1113{ 1114 int s; 1115 struct ifreq ifr; 1116 struct if_data ifrdat; 1117 1118 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) 1119 err(1, "socket"); --- 4 unchanged lines hidden (view full) --- 1124 if (ioctl(s, SIOCGIFDATA, (caddr_t)&ifr) == -1) 1125 err(1, "SIOCGIFDATA"); 1126 if (shutdown(s, SHUT_RDWR) == -1) 1127 err(1, "shutdown"); 1128 if (close(s)) 1129 err(1, "close"); 1130 return ((u_int32_t)ifrdat.ifi_baudrate); 1131} |
1132#endif |
1133 1134u_long 1135getifmtu(char *ifname) 1136{ 1137 int s; 1138 struct ifreq ifr; 1139 1140 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) --- 109 unchanged lines hidden --- |