1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-01 08:27:59 +00:00

Fix some style(9) related issues after discussion with/education from bde:

- Add <sys/param.h> and <limits.h> where required (do not depend on other
   headers pulling it in).
 - __dead -> __dead2
 - #if defined() -> #ifdef
 - Remove ugly PRIu64 macros and use %llu w/ (unsigned long long) cast.

All changes looped back to OpenBSD (where applicable) for easier sync in the
future.

Requested by:	bde
Approved by:	bms(mentor)
This commit is contained in:
Max Laier 2004-03-15 13:41:17 +00:00
parent dce2454396
commit b83a49e9b9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=127024
12 changed files with 94 additions and 118 deletions

View File

@ -26,7 +26,7 @@
* SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@ -50,9 +50,6 @@
#include "pathnames.h"
#if defined(__FreeBSD__)
#define __dead __volatile
#endif
extern int symset(const char *, const char *, int);
static int read_config(FILE *);
@ -77,7 +74,11 @@ struct timeval Tstart, Tend; /* start and end times of session */
volatile sig_atomic_t want_death;
static void need_death(int signo);
#ifdef __FreeBSD__
static __dead2 void do_death(int);
#else
static __dead void do_death(int);
#endif
/*
* User shell for authenticating gateways. Sole purpose is to allow
@ -289,9 +290,8 @@ 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
/* NOTREACHED */
}
/*
@ -730,7 +730,11 @@ need_death(int signo)
/*
* function that removes our stuff when we go away.
*/
#ifdef __FreeBSD__
static __dead2 void
#else
static __dead void
#endif
do_death(int active)
{
int ret = 0;

View File

@ -69,7 +69,6 @@
*/
#include <sys/param.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>

View File

@ -49,6 +49,7 @@
#include <string.h>
#include <ctype.h>
#include <err.h>
#include <limits.h>
#include <pwd.h>
#include <grp.h>
#include <md5.h>
@ -56,7 +57,7 @@
#include "pfctl_parser.h"
#include "pfctl.h"
#if defined(__FreeBSD__)
#ifdef __FreeBSD__
#define HTONL(x) (x) = htonl((__uint32_t)(x))
#endif

View File

@ -37,12 +37,6 @@
#include <net/if.h>
#include <netinet/in.h>
#if defined(__FreeBSD__)
#include <inttypes.h>
#include <net/route.h>
#else
#define PRIu64 "llu"
#endif
#include <net/pfvar.h>
#include <arpa/inet.h>
#include <altq/altq.h>
@ -201,7 +195,7 @@ pfctl_enable(int dev, int opts)
if (ioctl(dev, DIOCSTART)) {
if (errno == EEXIST)
errx(1, "pf already enabled");
#if defined(__FreeBSD__)
#ifdef __FreeBSD__
else if (errno == ESRCH)
errx(1, "pfil registeration failed");
#endif
@ -554,10 +548,11 @@ 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: %-8"PRIu64" Packets: %-8"PRIu64" "
"Bytes: %-10"PRIu64" States: %-6u]\n",
rule->evaluations, rule->packets,
rule->bytes, rule->states);
printf(" [ Evaluations: %-8llu Packets: %-8llu "
"Bytes: %-10llu States: %-6u]\n",
(unsigned long long)rule->evaluations,
(unsigned long long)rule->packets,
(unsigned long long)rule->bytes, rule->states);
}
int
@ -619,9 +614,10 @@ pfctl_show_rules(int dev, int opts, int format, char *anchorname,
case 1:
if (pr.rule.label[0]) {
printf("%s ", pr.rule.label);
printf("%"PRIu64" %"PRIu64" %"PRIu64"\n",
pr.rule.evaluations, pr.rule.packets,
pr.rule.bytes);
printf("%llu %llu %llu\n",
(unsigned long long)pr.rule.evaluations,
(unsigned long long)pr.rule.packets,
(unsigned long long)pr.rule.bytes);
}
break;
default:
@ -651,9 +647,10 @@ pfctl_show_rules(int dev, int opts, int format, char *anchorname,
case 1:
if (pr.rule.label[0]) {
printf("%s ", pr.rule.label);
printf("%"PRIu64" %"PRIu64" %"PRIu64"\n",
pr.rule.evaluations, pr.rule.packets,
pr.rule.bytes);
printf("%llu %llu %llu\n",
(unsigned long long)pr.rule.evaluations,
(unsigned long long)pr.rule.packets,
(unsigned long long)pr.rule.bytes);
}
break;
default:

View File

@ -83,7 +83,7 @@ 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__)
#ifdef __FreeBSD__
extern int altqsupport;
#endif

View File

@ -19,12 +19,9 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#if !defined(__FreeBSD__)
#include <sys/limits.h>
#endif
#include <net/if.h>
#include <netinet/in.h>
@ -32,6 +29,7 @@
#include <err.h>
#include <errno.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@ -77,7 +75,7 @@ static int gsc_add_seg(struct gen_sc *, double, double, double,
double);
static double sc_x2y(struct service_curve *, double);
#if defined(__FreeBSD__)
#ifdef __FreeBSD__
u_int32_t getifspeed(int, char *);
#else
u_int32_t getifspeed(char *);
@ -246,7 +244,7 @@ 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__)
#ifdef __FreeBSD__
if ((rate = getifspeed(pf->dev, pa->ifname)) == 0) {
#else
if ((rate = getifspeed(pa->ifname)) == 0) {
@ -880,12 +878,7 @@ 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 <math.h> */
#else
#ifndef INFINITY
#define INFINITY HUGE_VAL /* positive infinity defined in <math.h> */
#endif
@ -1088,10 +1081,10 @@ rate2str(double rate)
return (buf);
}
#if defined(__FreeBSD__)
#ifdef __FreeBSD__
/*
* XXX
* FreeBSD do not have SIOCGIFDATA.
* FreeBSD does not have SIOCGIFDATA.
* To emulate this, DIOCGIFSPEED ioctl added to pf.
*/
u_int32_t

View File

@ -46,19 +46,13 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <netdb.h>
#include <stdarg.h>
#include <errno.h>
#include <err.h>
#include <ifaddrs.h>
#if defined(__FreeBSD__)
#include <inttypes.h>
#else
#define PRIu64 "llu"
#define PRId64 "lld"
#endif
#include "pfctl_parser.h"
#include "pfctl.h"
@ -511,30 +505,32 @@ 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 %14"PRIu64" %16"PRIu64"\n", "Bytes In",
s->bcounters[0][0], s->bcounters[1][0]);
printf(" %-25s %14"PRIu64" %16"PRIu64"\n", "Bytes Out",
s->bcounters[0][1], s->bcounters[1][1]);
printf(" %-25s %14llu %16llu\n", "Bytes In",
(unsigned long long)s->bcounters[0][0],
(unsigned long long)s->bcounters[1][0]);
printf(" %-25s %14llu %16llu\n", "Bytes Out",
(unsigned long long)s->bcounters[0][1],
(unsigned long long)s->bcounters[1][1]);
printf(" Packets In\n");
printf(" %-23s %14"PRIu64" %16"PRIu64"\n", "Passed",
s->pcounters[0][0][PF_PASS],
s->pcounters[1][0][PF_PASS]);
printf(" %-23s %14"PRIu64" %16"PRIu64"\n", "Blocked",
s->pcounters[0][0][PF_DROP],
s->pcounters[1][0][PF_DROP]);
printf(" %-23s %14llu %16llu\n", "Passed",
(unsigned long long)s->pcounters[0][0][PF_PASS],
(unsigned long long)s->pcounters[1][0][PF_PASS]);
printf(" %-23s %14llu %16llu\n", "Blocked",
(unsigned long long)s->pcounters[0][0][PF_DROP],
(unsigned long long)s->pcounters[1][0][PF_DROP]);
printf(" Packets Out\n");
printf(" %-23s %14"PRIu64" %16"PRIu64"\n", "Passed",
s->pcounters[0][1][PF_PASS],
s->pcounters[1][1][PF_PASS]);
printf(" %-23s %14"PRIu64" %16"PRIu64"\n\n", "Blocked",
s->pcounters[0][1][PF_DROP],
s->pcounters[1][1][PF_DROP]);
printf(" %-23s %14llu %16llu\n", "Passed",
(unsigned long long)s->pcounters[0][1][PF_PASS],
(unsigned long long)s->pcounters[1][1][PF_PASS]);
printf(" %-23s %14llu %16llu\n\n", "Blocked",
(unsigned long long)s->pcounters[0][1][PF_DROP],
(unsigned long long)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 %14"PRIu64" ", pf_fcounters[i],
s->fcounters[i]);
printf(" %-25s %14llu ", pf_fcounters[i],
(unsigned long long)s->fcounters[i]);
if (runtime > 0)
printf("%14.1f/s\n",
(double)s->fcounters[i] / (double)runtime);
@ -543,8 +539,8 @@ print_status(struct pf_status *s)
}
printf("Counters\n");
for (i = 0; i < PFRES_MAX; i++) {
printf(" %-25s %14"PRIu64" ", pf_reasons[i],
s->counters[i]);
printf(" %-25s %14llu ", pf_reasons[i],
(unsigned long long)s->counters[i]);
if (runtime > 0)
printf("%14.1f/s\n",
(double)s->counters[i] / (double)runtime);

View File

@ -135,7 +135,7 @@ struct node_queue_opt {
} data;
};
#if defined(__FreeBSD__)
#ifdef __FreeBSD__
/*
* XXX
* Absolutely this is not correct location to define this.

View File

@ -37,12 +37,6 @@
#include <altq/altq_priq.h>
#include <altq/altq_hfsc.h>
#if defined(__FreeBSD__)
#include <inttypes.h>
#else
#define PRIu64 "llu"
#endif
#include "pfctl.h"
#include "pfctl_parser.h"
@ -92,7 +86,7 @@ pfctl_show_altq(int dev, int opts, int verbose2)
{
struct pf_altq_node *root = NULL, *node;
#if defined(__FreeBSD__)
#ifdef __FreeBSD__
if (!altqsupport)
return (-1);
#endif
@ -286,12 +280,12 @@ pfctl_print_altq_nodestat(int dev, const struct pf_altq_node *a)
void
print_cbqstats(struct queue_stats cur)
{
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,
cur.data.cbq_stats.drop_cnt.bytes);
printf(" [ pkts: %10llu bytes: %10llu "
"dropped pkts: %6llu bytes: %6llu ]\n",
(unsigned long long)cur.data.cbq_stats.xmit_cnt.packets,
(unsigned long long)cur.data.cbq_stats.xmit_cnt.bytes,
(unsigned long long)cur.data.cbq_stats.drop_cnt.packets,
(unsigned long long)cur.data.cbq_stats.drop_cnt.bytes);
printf(" [ qlength: %3d/%3d borrows: %6u suspends: %6u ]\n",
cur.data.cbq_stats.qcnt, cur.data.cbq_stats.qmax,
cur.data.cbq_stats.borrows, cur.data.cbq_stats.delays);
@ -307,12 +301,12 @@ print_cbqstats(struct queue_stats cur)
void
print_priqstats(struct queue_stats cur)
{
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,
cur.data.priq_stats.dropcnt.bytes);
printf(" [ pkts: %10llu bytes: %10llu "
"dropped pkts: %6llu bytes: %6llu ]\n",
(unsigned long long)cur.data.priq_stats.xmitcnt.packets,
(unsigned long long)cur.data.priq_stats.xmitcnt.bytes,
(unsigned long long)cur.data.priq_stats.dropcnt.packets,
(unsigned long long)cur.data.priq_stats.dropcnt.bytes);
printf(" [ qlength: %3d/%3d ]\n",
cur.data.priq_stats.qlength, cur.data.priq_stats.qlimit);
@ -327,12 +321,12 @@ print_priqstats(struct queue_stats cur)
void
print_hfscstats(struct queue_stats cur)
{
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,
cur.data.hfsc_stats.drop_cnt.bytes);
printf(" [ pkts: %10llu bytes: %10llu "
"dropped pkts: %6llu bytes: %6llu ]\n",
(unsigned long long)cur.data.hfsc_stats.xmit_cnt.packets,
(unsigned long long)cur.data.hfsc_stats.xmit_cnt.bytes,
(unsigned long long)cur.data.hfsc_stats.drop_cnt.packets,
(unsigned long long)cur.data.hfsc_stats.drop_cnt.bytes);
printf(" [ qlength: %3d/%3d ]\n",
cur.data.hfsc_stats.qlength, cur.data.hfsc_stats.qlimit);

View File

@ -49,12 +49,6 @@
#include <string.h>
#include <time.h>
#if defined(__FreeBSD__)
#include <inttypes.h>
#else
#define PRIu64 "llu"
#endif
#include "pfctl_parser.h"
#include "pfctl.h"
@ -354,14 +348,15 @@ 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: %-18"PRIu64" Match: %-18"PRIu64" ]\n",
ts->pfrts_nomatch, ts->pfrts_match);
printf("\tEvaluations: [ NoMatch: %-18llu Match: %-18llu ]\n",
(unsigned long long)ts->pfrts_nomatch,
(unsigned long long)ts->pfrts_match);
for (dir = 0; dir < PFR_DIR_MAX; dir++)
for (op = 0; op < PFR_OP_TABLE_MAX; op++)
printf("\t%-12s [ Packets: %-18"PRIu64" Bytes: %-18"PRIu64" ]\n",
printf("\t%-12s [ Packets: %-18llu Bytes: %-18llu ]\n",
stats_text[dir][op],
ts->pfrts_packets[dir][op],
ts->pfrts_bytes[dir][op]);
(unsigned long long)ts->pfrts_packets[dir][op],
(unsigned long long)ts->pfrts_bytes[dir][op]);
}
int
@ -436,10 +431,10 @@ 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: %-18"PRIu64" Bytes: %-18"PRIu64" ]\n",
printf("\t%-12s [ Packets: %-18llu Bytes: %-18llu ]\n",
stats_text[dir][op],
as->pfras_packets[dir][op],
as->pfras_bytes[dir][op]);
(unsigned long long)as->pfras_packets[dir][op],
(unsigned long long)as->pfras_bytes[dir][op]);
}
void

View File

@ -45,16 +45,12 @@
#include <errno.h>
#include <stdarg.h>
#include <fcntl.h>
#if defined(__FreeBSD__)
#ifdef __FreeBSD__
#include "pidfile.h"
#else
#include <util.h>
#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) */
#define PCAP_NUM_PKTS 1000 /* max number of packets to process at each loop */
@ -88,11 +84,7 @@ 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 *
@ -135,7 +127,11 @@ logmsg(int pri, const char *message, ...)
va_end(ap);
}
#ifdef __FreeBSD__
__dead2 void
#else
__dead void
#endif
usage(void)
{
fprintf(stderr, "usage: pflogd [-D] [-d delay] [-f filename] ");

View File

@ -1,3 +1,4 @@
/* $FreeBSD$ */
/* $OpenBSD: pidfile.c,v 1.5 2002/05/26 09:29:02 deraadt Exp $ */
/* $NetBSD: pidfile.c,v 1.4 2001/02/19 22:43:42 cgd Exp $ */
@ -47,7 +48,7 @@ static const char rcsid[] = "$OpenBSD: pidfile.c,v 1.5 2002/05/26 09:29:02 deraa
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#if defined(__FreeBSD__)
#ifdef __FreeBSD__
#include "pidfile.h"
#else
#include <util.h>