diff --git a/contrib/pf/authpf/authpf.c b/contrib/pf/authpf/authpf.c index 8828ffc2f37e..09d0ac3b733c 100644 --- a/contrib/pf/authpf/authpf.c +++ b/contrib/pf/authpf/authpf.c @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* $OpenBSD: authpf.c,v 1.68 2003/08/21 19:13:23 frantzen Exp $ */ /* @@ -49,6 +50,9 @@ #include "pathnames.h" +#if defined(__FreeBSD__) +#define __dead __volatile +#endif extern int symset(const char *, const char *, int); static int read_config(FILE *); @@ -285,6 +289,9 @@ main(int argc, char *argv[]) sleep(180); /* them lusers read reaaaaal slow */ die: do_death(0); +#if defined(__FreeBSD__) + return 0; /* gcc hack to prevent warning */ +#endif } /* diff --git a/contrib/pf/ftp-proxy/ftp-proxy.c b/contrib/pf/ftp-proxy/ftp-proxy.c index 88b6fd16b867..2c44431f9aa2 100644 --- a/contrib/pf/ftp-proxy/ftp-proxy.c +++ b/contrib/pf/ftp-proxy/ftp-proxy.c @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* $OpenBSD: ftp-proxy.c,v 1.33 2003/08/22 21:50:34 david Exp $ */ /* @@ -67,6 +68,7 @@ * - per-user rules perhaps. */ +#include #include #include #include diff --git a/contrib/pf/pfctl/pfctl.c b/contrib/pf/pfctl/pfctl.c index 0e52476aaddd..9a8fed8e0a25 100644 --- a/contrib/pf/pfctl/pfctl.c +++ b/contrib/pf/pfctl/pfctl.c @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* $OpenBSD: pfctl.c,v 1.188 2003/08/29 21:47:36 cedric Exp $ */ /* @@ -36,6 +37,12 @@ #include #include +#if defined(__FreeBSD__) +#include +#include +#else +#define PRIu64 "llu" +#endif #include #include #include @@ -194,6 +201,10 @@ pfctl_enable(int dev, int opts) if (ioctl(dev, DIOCSTART)) { if (errno == EEXIST) errx(1, "pf already enabled"); +#if defined(__FreeBSD__) + else if (errno == ESRCH) + errx(1, "pfil registeration failed"); +#endif else err(1, "DIOCSTART"); } @@ -543,8 +554,8 @@ pfctl_print_rule_counters(struct pf_rule *rule, int opts) rule->qname, rule->qid, rule->pqname, rule->pqid); } if (opts & PF_OPT_VERBOSE) - printf(" [ Evaluations: %-8llu Packets: %-8llu " - "Bytes: %-10llu States: %-6u]\n", + printf(" [ Evaluations: %-8"PRIu64" Packets: %-8"PRIu64" " + "Bytes: %-10"PRIu64" States: %-6u]\n", rule->evaluations, rule->packets, rule->bytes, rule->states); } @@ -608,7 +619,7 @@ pfctl_show_rules(int dev, int opts, int format, char *anchorname, case 1: if (pr.rule.label[0]) { printf("%s ", pr.rule.label); - printf("%llu %llu %llu\n", + printf("%"PRIu64" %"PRIu64" %"PRIu64"\n", pr.rule.evaluations, pr.rule.packets, pr.rule.bytes); } @@ -640,7 +651,7 @@ pfctl_show_rules(int dev, int opts, int format, char *anchorname, case 1: if (pr.rule.label[0]) { printf("%s ", pr.rule.label); - printf("%llu %llu %llu\n", + printf("%"PRIu64" %"PRIu64" %"PRIu64"\n", pr.rule.evaluations, pr.rule.packets, pr.rule.bytes); } @@ -1222,6 +1233,9 @@ pfctl_clear_rule_counters(int dev, int opts) int pfctl_test_altqsupport(int dev, int opts) { +#if defined(__FreeBSD__) && !defined(ENABLE_ALTQ) + return (0); +#else struct pfioc_altq pa; if (ioctl(dev, DIOCGETALTQS, &pa)) { @@ -1234,6 +1248,7 @@ pfctl_test_altqsupport(int dev, int opts) err(1, "DIOCGETALTQS"); } return (1); +#endif } int @@ -1476,7 +1491,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) diff --git a/contrib/pf/pfctl/pfctl.h b/contrib/pf/pfctl/pfctl.h index 2149ac14f965..8b439b4936ca 100644 --- a/contrib/pf/pfctl/pfctl.h +++ b/contrib/pf/pfctl/pfctl.h @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* $OpenBSD: pfctl.h,v 1.25 2003/08/29 21:47:36 cedric Exp $ */ /* @@ -82,6 +83,10 @@ int pfctl_command_tables(int, char *[], char *, const char *, char *, int pfctl_show_altq(int, int, int); void warn_namespace_collision(const char *); +#if defined(__FreeBSD__) +extern int altqsupport; +#endif + #ifndef DEFAULT_PRIORITY #define DEFAULT_PRIORITY 1 #endif diff --git a/contrib/pf/pfctl/pfctl_altq.c b/contrib/pf/pfctl/pfctl_altq.c index efe92ab9965b..807ecb5c0cdd 100644 --- a/contrib/pf/pfctl/pfctl_altq.c +++ b/contrib/pf/pfctl/pfctl_altq.c @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* $OpenBSD: pfctl_altq.c,v 1.77 2003/08/22 21:50:34 david Exp $ */ /* @@ -21,7 +22,9 @@ #include #include #include +#if !defined(__FreeBSD__) #include +#endif #include #include @@ -74,7 +77,11 @@ static int gsc_add_seg(struct gen_sc *, double, double, double, double); static double sc_x2y(struct service_curve *, double); +#if defined(__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); @@ -239,7 +246,11 @@ eval_pfaltq(struct pfctl *pf, struct pf_altq *pa, struct node_queue_bw *bw, if (bw->bw_absolute > 0) pa->ifbandwidth = bw->bw_absolute; else +#if defined(__FreeBSD__) + if ((rate = getifspeed(pf->dev, pa->ifname)) == 0) { +#else if ((rate = getifspeed(pa->ifname)) == 0) { +#endif fprintf(stderr, "cannot determine interface bandwidth " "for %s, specify an absolute bandwidth\n", pa->ifname); @@ -869,7 +880,14 @@ print_hfsc_opts(const struct pf_altq *a, const struct node_queue_opt *qopts) /* * admission control using generalized service curve */ +#if defined(__FreeBSD__) +#if defined(INFINITY) +#undef INFINITY +#endif #define INFINITY HUGE_VAL /* positive infinity defined in */ +#else +#define INFINITY HUGE_VAL /* positive infinity defined in */ +#endif /* add a new service curve to a generalized service curve */ static void @@ -1070,6 +1088,26 @@ rate2str(double rate) return (buf); } +#if defined(__FreeBSD__) +/* + * XXX + * FreeBSD do 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) { @@ -1091,6 +1129,7 @@ getifspeed(char *ifname) err(1, "close"); return ((u_int32_t)ifrdat.ifi_baudrate); } +#endif u_long getifmtu(char *ifname) diff --git a/contrib/pf/pfctl/pfctl_parser.c b/contrib/pf/pfctl/pfctl_parser.c index 7c051ac4bd48..de76cc74b7e2 100644 --- a/contrib/pf/pfctl/pfctl_parser.c +++ b/contrib/pf/pfctl/pfctl_parser.c @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* $OpenBSD: pfctl_parser.c,v 1.175 2003/09/18 20:27:58 cedric Exp $ */ /* @@ -51,6 +52,13 @@ #include #include +#if defined(__FreeBSD__) +#include +#else +#define PRIu64 "llu" +#define PRId64 "lld" +#endif + #include "pfctl_parser.h" #include "pfctl.h" @@ -503,30 +511,30 @@ print_status(struct pf_status *s) if (s->ifname[0] != 0) { printf("Interface Stats for %-16s %5s %16s\n", s->ifname, "IPv4", "IPv6"); - printf(" %-25s %14llu %16llu\n", "Bytes In", + printf(" %-25s %14"PRIu64" %16"PRIu64"\n", "Bytes In", s->bcounters[0][0], s->bcounters[1][0]); - printf(" %-25s %14llu %16llu\n", "Bytes Out", + printf(" %-25s %14"PRIu64" %16"PRIu64"\n", "Bytes Out", s->bcounters[0][1], s->bcounters[1][1]); printf(" Packets In\n"); - printf(" %-23s %14llu %16llu\n", "Passed", + printf(" %-23s %14"PRIu64" %16"PRIu64"\n", "Passed", s->pcounters[0][0][PF_PASS], s->pcounters[1][0][PF_PASS]); - printf(" %-23s %14llu %16llu\n", "Blocked", + printf(" %-23s %14"PRIu64" %16"PRIu64"\n", "Blocked", s->pcounters[0][0][PF_DROP], s->pcounters[1][0][PF_DROP]); printf(" Packets Out\n"); - printf(" %-23s %14llu %16llu\n", "Passed", + printf(" %-23s %14"PRIu64" %16"PRIu64"\n", "Passed", s->pcounters[0][1][PF_PASS], s->pcounters[1][1][PF_PASS]); - printf(" %-23s %14llu %16llu\n\n", "Blocked", + printf(" %-23s %14"PRIu64" %16"PRIu64"\n\n", "Blocked", s->pcounters[0][1][PF_DROP], s->pcounters[1][1][PF_DROP]); } printf("%-27s %14s %16s\n", "State Table", "Total", "Rate"); printf(" %-25s %14u %14s\n", "current entries", s->states, ""); for (i = 0; i < FCNT_MAX; i++) { - printf(" %-25s %14llu", pf_fcounters[i], - (unsigned long long)s->fcounters[i]); + printf(" %-25s %14"PRIu64" ", pf_fcounters[i], + s->fcounters[i]); if (runtime > 0) printf("%14.1f/s\n", (double)s->fcounters[i] / (double)runtime); @@ -535,8 +543,8 @@ print_status(struct pf_status *s) } printf("Counters\n"); for (i = 0; i < PFRES_MAX; i++) { - printf(" %-25s %14llu ", pf_reasons[i], - (unsigned long long)s->counters[i]); + printf(" %-25s %14"PRIu64" ", pf_reasons[i], + s->counters[i]); if (runtime > 0) printf("%14.1f/s\n", (double)s->counters[i] / (double)runtime); @@ -1124,6 +1132,12 @@ host_v4(const char *s, int mask) h->ifname = NULL; h->af = AF_INET; h->addr.v.a.addr.addr32[0] = ina.s_addr; +#if defined(__FreeBSD__) && (__FreeBSD_version <= 501106) + /* inet_net_pton acts strange w/ multicast addresses, RFC1112 */ + if (mask == -1 && h->addr.v.a.addr.addr8[0] >= 224 && + h->addr.v.a.addr.addr8[0] < 240) + bits = 32; +#endif set_ipmask(h, bits); h->next = NULL; h->tail = h; diff --git a/contrib/pf/pfctl/pfctl_parser.h b/contrib/pf/pfctl/pfctl_parser.h index 88047e597324..e866bd868c3f 100644 --- a/contrib/pf/pfctl/pfctl_parser.h +++ b/contrib/pf/pfctl/pfctl_parser.h @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* $OpenBSD: pfctl_parser.h,v 1.67 2003/08/21 19:12:09 frantzen Exp $ */ /* @@ -134,6 +135,30 @@ struct node_queue_opt { } data; }; +#if defined(__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; diff --git a/contrib/pf/pfctl/pfctl_qstats.c b/contrib/pf/pfctl/pfctl_qstats.c index 23c431ea1fd9..ea4b6f58426d 100644 --- a/contrib/pf/pfctl/pfctl_qstats.c +++ b/contrib/pf/pfctl/pfctl_qstats.c @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* $OpenBSD: pfctl_qstats.c,v 1.24 2003/07/31 09:46:08 kjc Exp $ */ /* @@ -36,6 +37,12 @@ #include #include +#if defined(__FreeBSD__) +#include +#else +#define PRIu64 "llu" +#endif + #include "pfctl.h" #include "pfctl_parser.h" @@ -85,6 +92,10 @@ pfctl_show_altq(int dev, int opts, int verbose2) { struct pf_altq_node *root = NULL, *node; +#if defined(__FreeBSD__) + if (!altqsupport) + return (-1); +#endif if (pfctl_update_qstats(dev, &root)) return (-1); @@ -275,8 +286,8 @@ pfctl_print_altq_nodestat(int dev, const struct pf_altq_node *a) void print_cbqstats(struct queue_stats cur) { - printf(" [ pkts: %10llu bytes: %10llu " - "dropped pkts: %6llu bytes: %6llu ]\n", + printf(" [ pkts: %10"PRIu64" bytes: %10"PRIu64" " + "dropped pkts: %6"PRIu64" bytes: %6"PRIu64" ]\n", cur.data.cbq_stats.xmit_cnt.packets, cur.data.cbq_stats.xmit_cnt.bytes, cur.data.cbq_stats.drop_cnt.packets, @@ -296,8 +307,8 @@ print_cbqstats(struct queue_stats cur) void print_priqstats(struct queue_stats cur) { - printf(" [ pkts: %10llu bytes: %10llu " - "dropped pkts: %6llu bytes: %6llu ]\n", + printf(" [ pkts: %10"PRIu64" bytes: %10"PRIu64" " + "dropped pkts: %6"PRIu64" bytes: %6"PRIu64" ]\n", cur.data.priq_stats.xmitcnt.packets, cur.data.priq_stats.xmitcnt.bytes, cur.data.priq_stats.dropcnt.packets, @@ -316,8 +327,8 @@ print_priqstats(struct queue_stats cur) void print_hfscstats(struct queue_stats cur) { - printf(" [ pkts: %10llu bytes: %10llu " - "dropped pkts: %6llu bytes: %6llu ]\n", + printf(" [ pkts: %10"PRIu64" bytes: %10"PRIu64" " + "dropped pkts: %6"PRIu64" bytes: %6"PRIu64" ]\n", cur.data.hfsc_stats.xmit_cnt.packets, cur.data.hfsc_stats.xmit_cnt.bytes, cur.data.hfsc_stats.drop_cnt.packets, diff --git a/contrib/pf/pfctl/pfctl_table.c b/contrib/pf/pfctl/pfctl_table.c index 57bdf19c6da5..1764750334d9 100644 --- a/contrib/pf/pfctl/pfctl_table.c +++ b/contrib/pf/pfctl/pfctl_table.c @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* $OpenBSD: pfctl_table.c,v 1.50 2003/08/29 21:47:36 cedric Exp $ */ /* @@ -48,6 +49,12 @@ #include #include +#if defined(__FreeBSD__) +#include +#else +#define PRIu64 "llu" +#endif + #include "pfctl_parser.h" #include "pfctl.h" @@ -347,11 +354,11 @@ print_tstats(struct pfr_tstats *ts, int debug) printf("\tReferences: [ Anchors: %-18d Rules: %-18d ]\n", ts->pfrts_refcnt[PFR_REFCNT_ANCHOR], ts->pfrts_refcnt[PFR_REFCNT_RULE]); - printf("\tEvaluations: [ NoMatch: %-18llu Match: %-18llu ]\n", + printf("\tEvaluations: [ NoMatch: %-18"PRIu64" Match: %-18"PRIu64" ]\n", ts->pfrts_nomatch, ts->pfrts_match); for (dir = 0; dir < PFR_DIR_MAX; dir++) for (op = 0; op < PFR_OP_TABLE_MAX; op++) - printf("\t%-12s [ Packets: %-18llu Bytes: %-18llu ]\n", + printf("\t%-12s [ Packets: %-18"PRIu64" Bytes: %-18"PRIu64" ]\n", stats_text[dir][op], ts->pfrts_packets[dir][op], ts->pfrts_bytes[dir][op]); @@ -429,7 +436,7 @@ print_astats(struct pfr_astats *as, int dns) printf("\tCleared: %s", ctime(&time)); for (dir = 0; dir < PFR_DIR_MAX; dir++) for (op = 0; op < PFR_OP_ADDR_MAX; op++) - printf("\t%-12s [ Packets: %-18llu Bytes: %-18llu ]\n", + printf("\t%-12s [ Packets: %-18"PRIu64" Bytes: %-18"PRIu64" ]\n", stats_text[dir][op], as->pfras_packets[dir][op], as->pfras_bytes[dir][op]); diff --git a/contrib/pf/pflogd/pflogd.c b/contrib/pf/pflogd/pflogd.c index 9777f151627f..10d8816fabbe 100644 --- a/contrib/pf/pflogd/pflogd.c +++ b/contrib/pf/pflogd/pflogd.c @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* $OpenBSD: pflogd.c,v 1.21 2003/08/22 21:50:34 david Exp $ */ /* @@ -44,7 +45,15 @@ #include #include #include +#if defined(__FreeBSD__) +#include "pidfile.h" +#else #include +#endif + +#if defined(__FreeBSD__) +#define __dead __volatile +#endif #define DEF_SNAPLEN 116 /* default plus allow for larger header of pflog */ #define PCAP_TO_MS 500 /* pcap read timeout (ms) */ @@ -79,7 +88,11 @@ int reset_dump(void); void sig_alrm(int); void sig_close(int); void sig_hup(int); +#if defined(__FreeBSD__) +__volatile void usage(void); +#else void usage(void); +#endif char *