mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-06-05 10:45:49 +08:00
pfctl: Add const and move static variables.
Note: This should be upstreamed into BSD. Make everything constant that can be constant and move static variables out of their functions.
This commit is contained in:
parent
b6252fb806
commit
c70221cb64
@ -108,7 +108,11 @@ int pfctl_ruleset_trans(struct pfctl *, char *, struct pf_anchor *);
|
||||
int pfctl_load_ruleset(struct pfctl *, char *,
|
||||
struct pf_ruleset *, int, int);
|
||||
int pfctl_load_rule(struct pfctl *, char *, struct pf_rule *, int);
|
||||
#ifndef __rtems__
|
||||
const char *pfctl_lookup_option(char *, const char **);
|
||||
#else /* __rtems__ */
|
||||
const char *pfctl_lookup_option(char *, const char * const *);
|
||||
#endif /* __rtems__ */
|
||||
|
||||
struct pf_anchor_global pf_anchors;
|
||||
struct pf_anchor pf_main_anchor;
|
||||
@ -119,7 +123,11 @@ const char *showopt;
|
||||
const char *debugopt;
|
||||
char *anchoropt;
|
||||
const char *optiopt = NULL;
|
||||
#ifndef __rtems__
|
||||
char *pf_device = "/dev/pf";
|
||||
#else /* __rtems__ */
|
||||
const char *pf_device = "/dev/pf";
|
||||
#endif /* __rtems__ */
|
||||
char *ifaceopt;
|
||||
char *tableopt;
|
||||
const char *tblcmdopt;
|
||||
@ -212,29 +220,53 @@ static const struct {
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static const char *clearopt_list[] = {
|
||||
#else /* __rtems__ */
|
||||
static const char * const clearopt_list[] = {
|
||||
#endif /* __rtems__ */
|
||||
"nat", "queue", "rules", "Sources",
|
||||
"states", "info", "Tables", "osfp", "all", NULL
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static const char *showopt_list[] = {
|
||||
#else /* __rtems__ */
|
||||
static const char * const showopt_list[] = {
|
||||
#endif /* __rtems__ */
|
||||
"nat", "queue", "rules", "Anchors", "Sources", "states", "info",
|
||||
"Interfaces", "labels", "timeouts", "memory", "Tables", "osfp",
|
||||
"all", NULL
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static const char *tblcmdopt_list[] = {
|
||||
#else /* __rtems__ */
|
||||
static const char * const tblcmdopt_list[] = {
|
||||
#endif /* __rtems__ */
|
||||
"kill", "flush", "add", "delete", "load", "replace", "show",
|
||||
"test", "zero", "expire", NULL
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static const char *debugopt_list[] = {
|
||||
#else /* __rtems__ */
|
||||
static const char * const debugopt_list[] = {
|
||||
#endif /* __rtems__ */
|
||||
"none", "urgent", "misc", "loud", NULL
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static const char *optiopt_list[] = {
|
||||
#else /* __rtems__ */
|
||||
static const char * const optiopt_list[] = {
|
||||
#endif /* __rtems__ */
|
||||
"none", "basic", "profile", NULL
|
||||
};
|
||||
#ifdef __rtems__
|
||||
|
||||
static const int nattype[3] = { PF_NAT, PF_RDR, PF_BINAT };
|
||||
#endif /* __rtems__ */
|
||||
|
||||
void
|
||||
usage(void)
|
||||
@ -978,7 +1010,9 @@ pfctl_show_nat(int dev, int opts, char *anchorname)
|
||||
{
|
||||
struct pfioc_rule pr;
|
||||
u_int32_t mnr, nr;
|
||||
#ifndef __rtems__
|
||||
static int nattype[3] = { PF_NAT, PF_RDR, PF_BINAT };
|
||||
#endif /* __rtems__ */
|
||||
int i, dotitle = opts & PF_OPT_SHOWALL;
|
||||
|
||||
memset(&pr, 0, sizeof(pr));
|
||||
@ -2001,7 +2035,11 @@ pfctl_show_anchors(int dev, int opts, char *anchorname)
|
||||
}
|
||||
|
||||
const char *
|
||||
#ifndef __rtems__
|
||||
pfctl_lookup_option(char *cmd, const char **list)
|
||||
#else /* __rtems__ */
|
||||
pfctl_lookup_option(char *cmd, const char * const *list)
|
||||
#endif /* __rtems__ */
|
||||
{
|
||||
if (cmd != NULL && *cmd)
|
||||
for (; *list; list++)
|
||||
|
@ -1073,18 +1073,31 @@ sc_x2y(struct service_curve *sc, double x)
|
||||
#define R2S_BUFS 8
|
||||
#define RATESTR_MAX 16
|
||||
|
||||
#ifdef __rtems__
|
||||
static char r2sbuf[R2S_BUFS][RATESTR_MAX]; /* ring bufer */
|
||||
static int r2sidx = 0;
|
||||
|
||||
#endif /* __rtems__ */
|
||||
char *
|
||||
rate2str(double rate)
|
||||
{
|
||||
char *buf;
|
||||
#ifndef __rtems__
|
||||
static char r2sbuf[R2S_BUFS][RATESTR_MAX]; /* ring bufer */
|
||||
static int idx = 0;
|
||||
#endif /* __rtems__ */
|
||||
int i;
|
||||
static const char unit[] = " KMG";
|
||||
|
||||
#ifndef __rtems__
|
||||
buf = r2sbuf[idx++];
|
||||
if (idx == R2S_BUFS)
|
||||
idx = 0;
|
||||
#else /* __rtems__ */
|
||||
buf = r2sbuf[r2sidx++];
|
||||
if (r2sidx == R2S_BUFS)
|
||||
r2sidx = 0;
|
||||
#endif /* __rtems__ */
|
||||
|
||||
for (i = 0; rate >= 1000 && i <= 3; i++)
|
||||
rate /= 1000;
|
||||
|
@ -206,6 +206,10 @@ struct pf_rule_field {
|
||||
PF_RULE_FIELD(min_ttl, NEVER),
|
||||
PF_RULE_FIELD(set_tos, NEVER),
|
||||
};
|
||||
#ifdef __rtems__
|
||||
static int pf_opt_create_table_num;
|
||||
static int add_opt_table_num = 0;
|
||||
#endif /* __rtems__ */
|
||||
|
||||
|
||||
|
||||
@ -1228,7 +1232,9 @@ add_opt_table(struct pfctl *pf, struct pf_opt_tbl **tbl, sa_family_t af,
|
||||
#ifdef OPT_DEBUG
|
||||
char buf[128];
|
||||
#endif /* OPT_DEBUG */
|
||||
#ifndef __rtems__
|
||||
static int tablenum = 0;
|
||||
#endif /* __rtems__ */
|
||||
struct node_host node_host;
|
||||
|
||||
if (*tbl == NULL) {
|
||||
@ -1241,7 +1247,11 @@ add_opt_table(struct pfctl *pf, struct pf_opt_tbl **tbl, sa_family_t af,
|
||||
|
||||
/* This is just a temporary table name */
|
||||
snprintf((*tbl)->pt_name, sizeof((*tbl)->pt_name), "%s%d",
|
||||
#ifndef __rtems__
|
||||
PF_OPT_TABLE_PREFIX, tablenum++);
|
||||
#else /* __rtems__ */
|
||||
PF_OPT_TABLE_PREFIX, add_opt_table_num++);
|
||||
#endif /* __rtems__ */
|
||||
DEBUG("creating table <%s>", (*tbl)->pt_name);
|
||||
}
|
||||
|
||||
@ -1277,7 +1287,6 @@ add_opt_table(struct pfctl *pf, struct pf_opt_tbl **tbl, sa_family_t af,
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Do the dirty work of choosing an unused table name and creating it.
|
||||
* (be careful with the table name, it might already be used in another anchor)
|
||||
@ -1285,7 +1294,9 @@ add_opt_table(struct pfctl *pf, struct pf_opt_tbl **tbl, sa_family_t af,
|
||||
int
|
||||
pf_opt_create_table(struct pfctl *pf, struct pf_opt_tbl *tbl)
|
||||
{
|
||||
#ifndef __rtems__
|
||||
static int tablenum;
|
||||
#endif /* __rtems__ */
|
||||
struct pfr_table *t;
|
||||
|
||||
if (table_buffer.pfrb_type == 0) {
|
||||
@ -1308,9 +1319,17 @@ pf_opt_create_table(struct pfctl *pf, struct pf_opt_tbl *tbl)
|
||||
/* Now we have to pick a table name that isn't used */
|
||||
again:
|
||||
DEBUG("translating temporary table <%s> to <%s%x_%d>", tbl->pt_name,
|
||||
#ifndef __rtems__
|
||||
PF_OPT_TABLE_PREFIX, table_identifier, tablenum);
|
||||
#else /* __rtems__ */
|
||||
PF_OPT_TABLE_PREFIX, table_identifier, pf_opt_create_table_num);
|
||||
#endif /* __rtems__ */
|
||||
snprintf(tbl->pt_name, sizeof(tbl->pt_name), "%s%x_%d",
|
||||
#ifndef __rtems__
|
||||
PF_OPT_TABLE_PREFIX, table_identifier, tablenum);
|
||||
#else /* __rtems__ */
|
||||
PF_OPT_TABLE_PREFIX, table_identifier, pf_opt_create_table_num);
|
||||
#endif /* __rtems__ */
|
||||
PFRB_FOREACH(t, &table_buffer) {
|
||||
if (strcasecmp(t->pfrt_name, tbl->pt_name) == 0) {
|
||||
/* Collision. Try again */
|
||||
@ -1320,7 +1339,11 @@ again:
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
#ifndef __rtems__
|
||||
tablenum++;
|
||||
#else /* __rtems__ */
|
||||
pf_opt_create_table_num++;
|
||||
#endif /* __rtems__ */
|
||||
|
||||
|
||||
if (pfctl_define_table(tbl->pt_name, PFR_TFLAG_CONST, 1,
|
||||
|
@ -1010,7 +1010,18 @@ get_field(char **line, size_t *len, int *fieldlen)
|
||||
const char *
|
||||
print_ioctl(struct pf_osfp_ioctl *fp)
|
||||
{
|
||||
#ifndef __rtems__
|
||||
static char buf[1024];
|
||||
#else /* __rtems__ */
|
||||
/* Note on RTEMS port:
|
||||
* This buffer is static. So normally it would have to be initialized to
|
||||
* zero every time the program starts. But in this special case it is
|
||||
* set to zero inside the function. Therefore it is not necessary to
|
||||
* move it. If it would be moved out of the function, the name would
|
||||
* have to be changed. This would be a lot of change in this function!
|
||||
*/
|
||||
static char buf[1024];
|
||||
#endif /* __rtems__ */
|
||||
char tmp[32];
|
||||
int i, opt;
|
||||
|
||||
|
@ -78,7 +78,11 @@ struct node_host *host_v4(const char *, int);
|
||||
struct node_host *host_v6(const char *, int);
|
||||
struct node_host *host_dns(const char *, int, int);
|
||||
|
||||
#ifndef __rtems__
|
||||
const char *tcpflags = "FSRPAUEW";
|
||||
#else /* __rtems__ */
|
||||
const char * const tcpflags = "FSRPAUEW";
|
||||
#endif /* __rtems__ */
|
||||
|
||||
static const struct icmptypeent icmp_type[] = {
|
||||
{ "echoreq", ICMP_ECHO },
|
||||
@ -483,10 +487,17 @@ print_pool(struct pf_pool *pool, u_int16_t p1, u_int16_t p2,
|
||||
printf(" static-port");
|
||||
}
|
||||
|
||||
#ifndef __rtems__
|
||||
const char *pf_reasons[PFRES_MAX+1] = PFRES_NAMES;
|
||||
const char *pf_lcounters[LCNT_MAX+1] = LCNT_NAMES;
|
||||
const char *pf_fcounters[FCNT_MAX+1] = FCNT_NAMES;
|
||||
const char *pf_scounters[FCNT_MAX+1] = FCNT_NAMES;
|
||||
#else /* __rtems__ */
|
||||
const char * const pf_reasons[PFRES_MAX+1] = PFRES_NAMES;
|
||||
const char * const pf_lcounters[LCNT_MAX+1] = LCNT_NAMES;
|
||||
const char * const pf_fcounters[FCNT_MAX+1] = FCNT_NAMES;
|
||||
const char * const pf_scounters[FCNT_MAX+1] = FCNT_NAMES;
|
||||
#endif /* __rtems__ */
|
||||
|
||||
void
|
||||
print_status(struct pf_status *s, int opts)
|
||||
|
@ -69,6 +69,10 @@ struct pf_altq_node {
|
||||
struct queue_stats qstats;
|
||||
};
|
||||
|
||||
#ifdef __rtems__
|
||||
static u_int32_t last_ticket;
|
||||
|
||||
#endif /* __rtems__ */
|
||||
int pfctl_update_qstats(int, struct pf_altq_node **);
|
||||
void pfctl_insert_altq_node(struct pf_altq_node **,
|
||||
const struct pf_altq, const struct queue_stats);
|
||||
@ -139,7 +143,9 @@ pfctl_update_qstats(int dev, struct pf_altq_node **root)
|
||||
struct pfioc_qstats pq;
|
||||
u_int32_t mnr, nr;
|
||||
struct queue_stats qstats;
|
||||
#ifndef __rtems__
|
||||
static u_int32_t last_ticket;
|
||||
#endif /* __rtems__ */
|
||||
|
||||
memset(&pa, 0, sizeof(pa));
|
||||
memset(&pq, 0, sizeof(pq));
|
||||
|
@ -403,7 +403,11 @@ pfi_get_ifaces(const char *filter, struct pfi_kif *buf, int *size)
|
||||
|
||||
/* buffer management code */
|
||||
|
||||
#ifndef __rtems__
|
||||
size_t buf_esize[PFRB_MAX] = { 0,
|
||||
#else /* __rtems__ */
|
||||
const size_t buf_esize[PFRB_MAX] = { 0,
|
||||
#endif /* __rtems__ */
|
||||
sizeof(struct pfr_table), sizeof(struct pfr_tstats),
|
||||
sizeof(struct pfr_addr), sizeof(struct pfr_astats),
|
||||
sizeof(struct pfi_kif), sizeof(struct pfioc_trans_e)
|
||||
@ -536,10 +540,15 @@ pfr_buf_load(struct pfr_buffer *b, char *file, int nonetwork,
|
||||
return (rv);
|
||||
}
|
||||
|
||||
#ifdef __rtems__
|
||||
static char next_ch = ' ';
|
||||
#endif /* __rtems__ */
|
||||
int
|
||||
pfr_next_token(char buf[BUF_SIZE], FILE *fp)
|
||||
{
|
||||
#ifndef __rtems__
|
||||
static char next_ch = ' ';
|
||||
#endif /* __rtems__ */
|
||||
int i = 0;
|
||||
|
||||
for (;;) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user