X-Git-Url: http://git.onelab.eu/?p=ipfw.git;a=blobdiff_plain;f=ipfw%2Fipfw2.c;fp=ipfw%2Fipfw2.c;h=bf3a9b1ab52716650d1c48585436b8a8c6fb94b2;hp=6cb826b91fb76e5249922f5cfd1c8d47fa9972ca;hb=28a7fe9d930667786b902af6697c01eb87694173;hpb=2a8b6c544cf5ea3c84f763144c7ecfa79daea969 diff --git a/ipfw/ipfw2.c b/ipfw/ipfw2.c index 6cb826b..bf3a9b1 100644 --- a/ipfw/ipfw2.c +++ b/ipfw/ipfw2.c @@ -17,7 +17,7 @@ * * NEW command line interface for IP firewall facility * - * $FreeBSD: user/luigi/ipfw3-head/sbin/ipfw/ipfw2.c 203369 2010-02-02 07:39:56Z luigi $ + * $FreeBSD: head/sbin/ipfw/ipfw2.c 206843 2010-04-19 15:11:45Z luigi $ */ #include @@ -321,22 +321,29 @@ static struct _s_x rule_options[] = { { NULL, 0 } /* terminator */ }; -/* - * The following is used to generate a printable argument for - * 64-bit numbers, irrespective of platform alignment and bit size. - * Because all the printf in this program use %llu as a format, - * we just return an unsigned long long, which is larger than - * we need in certain cases, but saves the hassle of using - * PRIu64 as a format specifier. - * We don't care about inlining, this is not performance critical code. +/* + * Helper routine to print a possibly unaligned uint64_t on + * various platform. If width > 0, print the value with + * the desired width, followed by a space; + * otherwise, return the required width. */ -unsigned long long -align_uint64(const uint64_t *pll) +int +pr_u64(uint64_t *pd, int width) { - uint64_t ret; - - bcopy (pll, &ret, sizeof(ret)); - return ret; +#ifdef TCC +#define U64_FMT "I64" +#else +#define U64_FMT "llu" +#endif + uint64_t u; + unsigned long long d; + + bcopy (pd, &u, sizeof(u)); + d = u; + return (width > 0) ? + printf("%*" U64_FMT " ", width, d) : + snprintf(NULL, 0, "%" U64_FMT, d) ; +#undef U64_FMT } void * @@ -980,18 +987,11 @@ show_ipfw(struct ip_fw *rule, int pcwidth, int bcwidth) } printf("%05u ", rule->rulenum); - if (pcwidth>0 || bcwidth>0) + if (pcwidth > 0 || bcwidth > 0) { + pr_u64(&rule->pcnt, pcwidth); + pr_u64(&rule->bcnt, bcwidth); + } - /* Tcc relies on msvcrt.dll for printf, and - * it does not support ANSI %llu syntax - */ -#ifndef TCC - printf("%*llu %*llu ", pcwidth, align_uint64(&rule->pcnt), - bcwidth, align_uint64(&rule->bcnt)); -#else - printf("%*I64u %*I64u ", pcwidth, align_uint64(&rule->pcnt), - bcwidth, align_uint64(&rule->bcnt)); -#endif if (co.do_time == 2) printf("%10u ", rule->timestamp); else if (co.do_time == 1) { @@ -1592,25 +1592,12 @@ show_dyn_ipfw(ipfw_dyn_rule *d, int pcwidth, int bcwidth) } bcopy(&d->rule, &rulenum, sizeof(rulenum)); printf("%05d", rulenum); - if (pcwidth>0 || bcwidth>0) - - /* Tcc relies on msvcrt.dll for printf, and - * it does not support ANSI %llu syntax - */ -#ifndef TCC - printf(" %*llu %*llu (%ds)", pcwidth, - align_uint64(&d->pcnt), bcwidth, - align_uint64(&d->bcnt), d->expire); -#else - /*printf(" %*I64u %*I64u (%ds)", pcwidth, - align_uint64(&d->pcnt), bcwidth, - align_uint64(&d->bcnt), d->expire);*/ - - //XXX workaround here, for multiple I64 on the same printf - printf(" %*I64u",pcwidth,align_uint64(&d->pcnt)); - printf(" %*I64u",bcwidth,align_uint64(&d->bcnt)); - printf(" (%ds)",d->expire); -#endif + if (pcwidth > 0 || bcwidth > 0) { + printf(" "); + pr_u64(&d->pcnt, pcwidth); + pr_u64(&d->bcnt, bcwidth); + printf("(%ds)", d->expire); + } switch (d->dyn_type) { case O_LIMIT_PARENT: printf(" PARENT %d", d->count); @@ -1770,6 +1757,8 @@ ipfw_sysctl_handler(char *av[], int which) } else if (_substrcmp(*av, "firewall") == 0) { sysctlbyname("net.inet.ip.fw.enable", NULL, 0, &which, sizeof(which)); + sysctlbyname("net.inet6.ip6.fw.enable", NULL, 0, + &which, sizeof(which)); } else if (_substrcmp(*av, "one_pass") == 0) { sysctlbyname("net.inet.ip.fw.one_pass", NULL, 0, &which, sizeof(which)); @@ -1865,24 +1854,12 @@ ipfw_list(int ac, char *av[], int show_counters) continue; /* packet counter */ - - /* Tcc relies on msvcrt.dll for printf, and - * it does not support ANSI %llu syntax - */ -#ifndef TCC - width = snprintf(NULL, 0, "%llu", align_uint64(&r->pcnt)); -#else - width = snprintf(NULL, 0, "%I64u", align_uint64(&r->pcnt)); -#endif + width = pr_u64(&r->pcnt, 0); if (width > pcwidth) pcwidth = width; /* byte counter */ -#ifndef TCC - width = snprintf(NULL, 0, "%llu",align_uint64(&r->bcnt)); -#else - width = snprintf(NULL, 0, "%I64u",align_uint64(&r->bcnt)); -#endif + width = pr_u64(&r->bcnt, 0); if (width > bcwidth) bcwidth = width; } @@ -1896,23 +1873,11 @@ ipfw_list(int ac, char *av[], int show_counters) if (set != co.use_set - 1) continue; } - - /* Tcc relies on msvcrt.dll for printf, and - * it does not support ANSI %llu syntax - */ -#ifndef TCC - width = snprintf(NULL, 0, "%llu",align_uint64(&d->pcnt)); -#else - width = snprintf(NULL, 0, "%I64u",align_uint64(&d->pcnt)); -#endif + width = pr_u64(&d->pcnt, 0); if (width > pcwidth) pcwidth = width; -#ifndef TCC - width = snprintf(NULL, 0, "%llu",align_uint64(&d->bcnt)); -#else - width = snprintf(NULL, 0, "%I64u",align_uint64(&d->bcnt)); -#endif + width = pr_u64(&d->bcnt, 0); if (width > bcwidth) bcwidth = width; }