Date: Thu, 8 Oct 2009 22:42:07 +0000 (UTC) From: Ermal Luçi <eri@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r197886 - user/eri/pf45/head/contrib/pf/pfctl Message-ID: <200910082242.n98Mg7Uo035952@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: eri Date: Thu Oct 8 22:42:07 2009 New Revision: 197886 URL: http://svn.freebsd.org/changeset/base/197886 Log: Make pfctl compile as well. This allows pf(4) 4.5 to be tested. Modified: user/eri/pf45/head/contrib/pf/pfctl/pf_print_state.c user/eri/pf45/head/contrib/pf/pfctl/pfctl.c user/eri/pf45/head/contrib/pf/pfctl/pfctl.h user/eri/pf45/head/contrib/pf/pfctl/pfctl_altq.c user/eri/pf45/head/contrib/pf/pfctl/pfctl_optimize.c user/eri/pf45/head/contrib/pf/pfctl/pfctl_parser.c user/eri/pf45/head/contrib/pf/pfctl/pfctl_parser.h user/eri/pf45/head/contrib/pf/pfctl/pfctl_qstats.c user/eri/pf45/head/contrib/pf/pfctl/pfctl_radix.c Modified: user/eri/pf45/head/contrib/pf/pfctl/pf_print_state.c ============================================================================== --- user/eri/pf45/head/contrib/pf/pfctl/pf_print_state.c Thu Oct 8 22:38:46 2009 (r197885) +++ user/eri/pf45/head/contrib/pf/pfctl/pf_print_state.c Thu Oct 8 22:42:07 2009 (r197886) @@ -30,6 +30,9 @@ * */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #include <sys/types.h> #include <sys/socket.h> #include <net/if.h> Modified: user/eri/pf45/head/contrib/pf/pfctl/pfctl.c ============================================================================== --- user/eri/pf45/head/contrib/pf/pfctl/pfctl.c Thu Oct 8 22:38:46 2009 (r197885) +++ user/eri/pf45/head/contrib/pf/pfctl/pfctl.c Thu Oct 8 22:42:07 2009 (r197886) @@ -31,6 +31,9 @@ * */ + #include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h> @@ -56,6 +59,10 @@ #include "pfctl_parser.h" #include "pfctl.h" + #ifdef __FreeBSD__ + #define HTONL(x) (x) = htonl((__uint32_t)(x)) + #endif + void usage(void); int pfctl_enable(int, int); int pfctl_disable(int, int); @@ -244,6 +251,10 @@ pfctl_enable(int dev, int opts) if (ioctl(dev, DIOCSTART)) { if (errno == EEXIST) errx(1, "pf already enabled"); + #ifdef __FreeBSD__ + else if (errno == ESRCH) + errx(1, "pfil registeration failed"); + #endif else err(1, "DIOCSTART"); } @@ -2182,7 +2193,11 @@ main(int argc, char *argv[]) /* turn off options */ opts &= ~ (PF_OPT_DISABLE | PF_OPT_ENABLE); clearopt = showopt = debugopt = NULL; + #if defined(__FreeBSD__) && !defined(ENABLE_ALTQ) + altqsupport = 0; + #else altqsupport = 1; +#endif } if (opts & PF_OPT_DISABLE) Modified: user/eri/pf45/head/contrib/pf/pfctl/pfctl.h ============================================================================== --- user/eri/pf45/head/contrib/pf/pfctl/pfctl.h Thu Oct 8 22:38:46 2009 (r197885) +++ user/eri/pf45/head/contrib/pf/pfctl/pfctl.h Thu Oct 8 22:42:07 2009 (r197886) @@ -85,6 +85,11 @@ void warn_namespace_collision(const cha int pfctl_show_ifaces(const char *, int); FILE *pfctl_fopen(const char *, const char *); +#ifdef __FreeBSD__ +extern int altqsupport; +extern int dummynetsupport; +#endif + #ifndef DEFAULT_PRIORITY #define DEFAULT_PRIORITY 1 #endif Modified: user/eri/pf45/head/contrib/pf/pfctl/pfctl_altq.c ============================================================================== --- user/eri/pf45/head/contrib/pf/pfctl/pfctl_altq.c Thu Oct 8 22:38:46 2009 (r197885) +++ user/eri/pf45/head/contrib/pf/pfctl/pfctl_altq.c Thu Oct 8 22:42:07 2009 (r197886) @@ -18,6 +18,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h> @@ -74,7 +77,11 @@ static int gsc_add_seg(struct gen_sc * double); static double sc_x2y(struct service_curve *, double); +#ifdef __FreeBSD__ +u_int32_t getifspeed(int, char *); +#else u_int32_t getifspeed(char *); +#endif u_long getifmtu(char *); int eval_queue_opts(struct pf_altq *, struct node_queue_opt *, u_int32_t); @@ -146,6 +153,11 @@ print_altq(const struct pf_altq *a, unsi return; } +#ifdef __FreeBSD__ + if (a->local_flags & PFALTQ_FLAG_IF_REMOVED) + printf("INACTIVE "); +#endif + printf("altq on %s ", a->ifname); switch (a->scheduler) { @@ -181,6 +193,10 @@ print_queue(const struct pf_altq *a, uns { unsigned int i; +#ifdef __FreeBSD__ + if (a->local_flags & PFALTQ_FLAG_IF_REMOVED) + printf("INACTIVE "); +#endif printf("queue "); for (i = 0; i < level; ++i) printf(" "); @@ -223,7 +239,11 @@ eval_pfaltq(struct pfctl *pf, struct pf_ if (bw->bw_absolute > 0) pa->ifbandwidth = bw->bw_absolute; else +#ifdef __FreeBSD__ + if ((rate = getifspeed(pf->dev, pa->ifname)) == 0) { +#else if ((rate = getifspeed(pa->ifname)) == 0) { +#endif fprintf(stderr, "interface %s does not know its bandwidth, " "please specify an absolute bandwidth\n", pa->ifname); @@ -1075,6 +1095,26 @@ rate2str(double rate) return (buf); } +-#ifdef __FreeBSD__ +-/* +- * XXX +- * FreeBSD does not have SIOCGIFDATA. +- * To emulate this, DIOCGIFSPEED ioctl added to pf. +- */ +u_int32_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 ((u_int32_t)io.baudrate); +} +#else u_int32_t getifspeed(char *ifname) { @@ -1095,6 +1135,7 @@ getifspeed(char *ifname) err(1, "close"); return ((u_int32_t)ifrdat.ifi_baudrate); } +#endif u_long getifmtu(char *ifname) @@ -1109,7 +1150,11 @@ getifmtu(char *ifname) sizeof(ifr.ifr_name)) errx(1, "getifmtu: strlcpy"); if (ioctl(s, SIOCGIFMTU, (caddr_t)&ifr) == -1) +#ifdef __FreeBSD__ + ifr.ifr_mtu = 1500; +#else err(1, "SIOCGIFMTU"); +#endif if (close(s)) err(1, "close"); if (ifr.ifr_mtu > 0) Modified: user/eri/pf45/head/contrib/pf/pfctl/pfctl_optimize.c ============================================================================== --- user/eri/pf45/head/contrib/pf/pfctl/pfctl_optimize.c Thu Oct 8 22:38:46 2009 (r197885) +++ user/eri/pf45/head/contrib/pf/pfctl/pfctl_optimize.c Thu Oct 8 22:42:07 2009 (r197886) @@ -16,6 +16,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h> @@ -859,7 +862,11 @@ block_feedback(struct pfctl *pf, struct break; } } +#ifdef __FreeBSD__ + if (por2 == NULL) +#else if (por2 == TAILQ_END(&block->sb_rules)) +#endif TAILQ_INSERT_TAIL(&block->sb_rules, por1, por_entry); } Modified: user/eri/pf45/head/contrib/pf/pfctl/pfctl_parser.c ============================================================================== --- user/eri/pf45/head/contrib/pf/pfctl/pfctl_parser.c Thu Oct 8 22:38:46 2009 (r197885) +++ user/eri/pf45/head/contrib/pf/pfctl/pfctl_parser.c Thu Oct 8 22:42:07 2009 (r197886) @@ -31,6 +31,9 @@ * */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h> @@ -594,7 +597,11 @@ print_status(struct pf_status *s, int op printf("Limit Counters\n"); for (i = 0; i < LCNT_MAX; i++) { printf(" %-25s %14lld ", pf_lcounters[i], +#ifdef __FreeBSD__ + (unsigned long long)s->lcounters[i]); +#else s->lcounters[i]); +#endif if (runtime > 0) printf("%14.1f/s\n", (double)s->lcounters[i] / (double)runtime); @@ -639,8 +646,13 @@ print_src_node(struct pf_src_node *sn, i sn->expire, min, sec); } printf(", %llu pkts, %llu bytes", +#ifdef __FreeBSD__ + (unsigned long long)(sn->packets[0] + sn->packets[1]), + (unsigned long long)(sn->bytes[0] + sn->bytes[1])); +#else sn->packets[0] + sn->packets[1], sn->bytes[0] + sn->bytes[1]); +#endif switch (sn->ruletype) { case PF_NAT: if (sn->rule.nr != -1) Modified: user/eri/pf45/head/contrib/pf/pfctl/pfctl_parser.h ============================================================================== --- user/eri/pf45/head/contrib/pf/pfctl/pfctl_parser.h Thu Oct 8 22:38:46 2009 (r197885) +++ user/eri/pf45/head/contrib/pf/pfctl/pfctl_parser.h Thu Oct 8 22:42:07 2009 (r197886) @@ -157,6 +157,30 @@ struct node_queue_opt { } data; }; +#ifdef __FreeBSD__ +/* + * XXX + * Absolutely this is not correct location to define this. + * Should we use an another sperate header file? + */ +#define SIMPLEQ_HEAD STAILQ_HEAD +#define SIMPLEQ_HEAD_INITIALIZER STAILQ_HEAD_INITIALIZER +#define SIMPLEQ_ENTRY STAILQ_ENTRY +#define SIMPLEQ_FIRST STAILQ_FIRST +#define SIMPLEQ_END(head) NULL +#define SIMPLEQ_EMPTY STAILQ_EMPTY +#define SIMPLEQ_NEXT STAILQ_NEXT +/*#define SIMPLEQ_FOREACH STAILQ_FOREACH*/ +#define SIMPLEQ_FOREACH(var, head, field) \ + for((var) = SIMPLEQ_FIRST(head); \ + (var) != SIMPLEQ_END(head); \ + (var) = SIMPLEQ_NEXT(var, field)) +#define SIMPLEQ_INIT STAILQ_INIT +#define SIMPLEQ_INSERT_HEAD STAILQ_INSERT_HEAD +#define SIMPLEQ_INSERT_TAIL STAILQ_INSERT_TAIL +#define SIMPLEQ_INSERT_AFTER STAILQ_INSERT_AFTER +#define SIMPLEQ_REMOVE_HEAD STAILQ_REMOVE_HEAD +#endif SIMPLEQ_HEAD(node_tinithead, node_tinit); struct node_tinit { /* table initializer */ SIMPLEQ_ENTRY(node_tinit) entries; Modified: user/eri/pf45/head/contrib/pf/pfctl/pfctl_qstats.c ============================================================================== --- user/eri/pf45/head/contrib/pf/pfctl/pfctl_qstats.c Thu Oct 8 22:38:46 2009 (r197885) +++ user/eri/pf45/head/contrib/pf/pfctl/pfctl_qstats.c Thu Oct 8 22:42:07 2009 (r197886) @@ -16,6 +16,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h> @@ -86,6 +89,10 @@ pfctl_show_altq(int dev, const char *ifa struct pf_altq_node *root = NULL, *node; int nodes, dotitle = (opts & PF_OPT_SHOWALL); +#ifdef __FreeBSD__ + if (!altqsupport) + return (-1); +#endif if ((nodes = pfctl_update_qstats(dev, &root)) < 0) return (-1); @@ -111,6 +118,10 @@ pfctl_show_altq(int dev, const char *ifa for (node = root; node != NULL; node = node->next) { if (iface != NULL && strcmp(node->altq.ifname, iface)) continue; +#ifdef __FreeBSD__ + if (node->altq.local_flags & PFALTQ_FLAG_IF_REMOVED) + continue; +#endif pfctl_print_altq_node(dev, node, 0, opts); } } @@ -150,7 +161,12 @@ pfctl_update_qstats(int dev, struct pf_a warn("DIOCGETALTQ"); return (-1); } +#ifdef __FreeBSD__ + if (pa.altq.qid > 0 && + !(pa.altq.local_flags & PFALTQ_FLAG_IF_REMOVED)) { +#else if (pa.altq.qid > 0) { +#endif pq.nr = nr; pq.ticket = pa.ticket; pq.buf = &qstats.data; @@ -168,6 +184,19 @@ pfctl_update_qstats(int dev, struct pf_a pfctl_insert_altq_node(root, pa.altq, qstats); } } +#ifdef __FreeBSD__ + else if (pa.altq.local_flags & PFALTQ_FLAG_IF_REMOVED) { + memset(&qstats.data, 0, sizeof(qstats.data)); + if ((node = pfctl_find_altq_node(*root, pa.altq.qname, + pa.altq.ifname)) != NULL) { + memcpy(&node->qstats.data, &qstats.data, + sizeof(qstats.data)); + update_avg(node); + } else { + pfctl_insert_altq_node(root, pa.altq, qstats); + } + } +#endif } return (mnr); } @@ -274,6 +303,10 @@ pfctl_print_altq_nodestat(int dev, const if (a->altq.qid == 0) return; +#ifdef __FreeBSD__ + if (a->altq.local_flags & PFALTQ_FLAG_IF_REMOVED) + return; +#endif switch (a->altq.scheduler) { case ALTQT_CBQ: print_cbqstats(a->qstats); Modified: user/eri/pf45/head/contrib/pf/pfctl/pfctl_radix.c ============================================================================== --- user/eri/pf45/head/contrib/pf/pfctl/pfctl_radix.c Thu Oct 8 22:38:46 2009 (r197885) +++ user/eri/pf45/head/contrib/pf/pfctl/pfctl_radix.c Thu Oct 8 22:42:07 2009 (r197886) @@ -30,6 +30,9 @@ * */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200910082242.n98Mg7Uo035952>