Deleted Added
full compact
pfctl_altq.c (126354) pfctl_altq.c (126355)
1/* $FreeBSD: head/contrib/pf/pfctl/pfctl_altq.c 126355 2004-02-28 17:32:53Z mlaier $ */
1/* $OpenBSD: pfctl_altq.c,v 1.77 2003/08/22 21:50:34 david Exp $ */
2
3/*
4 * Copyright (c) 2002
5 * Sony Computer Science Laboratories Inc.
6 * Copyright (c) 2002, 2003 Henning Brauer <henning@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any

--- 7 unchanged lines hidden (view full) ---

16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21#include <sys/types.h>
22#include <sys/ioctl.h>
23#include <sys/socket.h>
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__)
24#include <sys/limits.h>
26#include <sys/limits.h>
27#endif
25
26#include <net/if.h>
27#include <netinet/in.h>
28#include <net/pfvar.h>
29
30#include <err.h>
31#include <errno.h>
32#include <math.h>

--- 36 unchanged lines hidden (view full) ---

69static int is_gsc_under_sc(struct gen_sc *,
70 struct service_curve *);
71static void gsc_destroy(struct gen_sc *);
72static struct segment *gsc_getentry(struct gen_sc *, double);
73static int gsc_add_seg(struct gen_sc *, double, double, double,
74 double);
75static double sc_x2y(struct service_curve *, double);
76
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
77u_int32_t getifspeed(char *);
83u_int32_t getifspeed(char *);
84#endif
78u_long getifmtu(char *);
79int eval_queue_opts(struct pf_altq *, struct node_queue_opt *,
80 u_int32_t);
81u_int32_t eval_bwspec(struct node_queue_bw *, u_int32_t);
82void print_hfsc_sc(const char *, u_int, u_int, u_int,
83 const struct node_hfsc_sc *);
84
85static u_int32_t max_qid = 1;

--- 148 unchanged lines hidden (view full) ---

234eval_pfaltq(struct pfctl *pf, struct pf_altq *pa, struct node_queue_bw *bw,
235 struct node_queue_opt *opts)
236{
237 u_int rate, size, errors = 0;
238
239 if (bw->bw_absolute > 0)
240 pa->ifbandwidth = bw->bw_absolute;
241 else
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
242 if ((rate = getifspeed(pa->ifname)) == 0) {
252 if ((rate = getifspeed(pa->ifname)) == 0) {
253#endif
243 fprintf(stderr, "cannot determine interface bandwidth "
244 "for %s, specify an absolute bandwidth\n",
245 pa->ifname);
246 errors++;
247 } else if ((pa->ifbandwidth = eval_bwspec(bw, rate)) == 0)
248 pa->ifbandwidth = rate;
249
250 errors += eval_queue_opts(pa, opts, pa->ifbandwidth);

--- 613 unchanged lines hidden (view full) ---

864 return (1);
865 } else
866 return (0);
867}
868
869/*
870 * admission control using generalized service curve
871 */
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
872#define INFINITY HUGE_VAL /* positive infinity defined in <math.h> */
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
873
874/* add a new service curve to a generalized service curve */
875static void
876gsc_add_sc(struct gen_sc *gsc, struct service_curve *sc)
877{
878 if (is_sc_null(sc))
879 return;
880 if (sc->d != 0)

--- 184 unchanged lines hidden (view full) ---

1065 if ((int)(rate * 100) % 100)
1066 snprintf(buf, RATESTR_MAX, "%.2f%cb", rate, unit[i]);
1067 else
1068 snprintf(buf, RATESTR_MAX, "%d%cb", (int)rate, unit[i]);
1069
1070 return (buf);
1071}
1072
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 */
1073u_int32_t
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
1074getifspeed(char *ifname)
1075{
1076 int s;
1077 struct ifreq ifr;
1078 struct if_data ifrdat;
1079
1080 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
1081 err(1, "socket");

--- 4 unchanged lines hidden (view full) ---

1086 if (ioctl(s, SIOCGIFDATA, (caddr_t)&ifr) == -1)
1087 err(1, "SIOCGIFDATA");
1088 if (shutdown(s, SHUT_RDWR) == -1)
1089 err(1, "shutdown");
1090 if (close(s))
1091 err(1, "close");
1092 return ((u_int32_t)ifrdat.ifi_baudrate);
1093}
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
1094
1095u_long
1096getifmtu(char *ifname)
1097{
1098 int s;
1099 struct ifreq ifr;
1100
1101 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)

--- 109 unchanged lines hidden ---
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 ---