if (s < 0)
err(EX_UNAVAILABLE, "socket");
- if (optname == IP_FW_GET || optname == IP_DUMMYNET_GET ||
+ if (optname == IP_FW_GET || optname == IP_FW_DYN_GET ||
+ optname == IP_DUMMYNET_GET ||
optname == IP_FW_ADD || optname == IP_FW_TABLE_LIST ||
optname == IP_FW_TABLE_GETSIZE ||
optname == IP_FW_NAT_GET_CONFIG ||
ipfw_list(int ac, char *av[], int show_counters)
{
struct ip_fw *r;
- ipfw_dyn_rule *dynrules, *d;
+ ipfw_dyn_rule *dynrules = NULL;
+ ipfw_dyn_rule *d;
#define NEXT(r) ((struct ip_fw *)((char *)r + RULESIZE(r)))
char *lim;
void *data = NULL;
- int bcwidth, n, nbytes, nstat, ndyn, pcwidth, width;
+ int bcwidth, n, nbytes, pcwidth, width, nstat;
+ int ndyn = 0;
int exitval = EX_OK;
int lac;
char **lav;
char *endptr;
int seen = 0;
uint8_t set;
+ int ocmd = IP_FW_GET;
+
+ if (co.do_pipe)
+ ocmd = IP_DUMMYNET_GET;
+ else if (co.do_dynamic)
+ ocmd = IP_FW_DYN_GET;
- const int ocmd = co.do_pipe ? IP_DUMMYNET_GET : IP_FW_GET;
int nalloc = 1024; /* start somewhere... */
last = 0;
* Count static rules. They have variable size so we
* need to scan the list to count them.
*/
+ nstat = 0;
+ r = data;
+
+ if (!co.do_dynamic) {
for (nstat = 1, r = data, lim = (char *)data + nbytes;
r->rulenum < IPFW_DEFAULT_RULE && (char *)r < lim;
++nstat, r = NEXT(r) )
; /* nothing */
+ }
/*
* Count dynamic rules. This is easier as they have
* fixed size.
*/
- r = NEXT(r);
- dynrules = (ipfw_dyn_rule *)r ;
- n = (char *)r - (char *)data;
- ndyn = (nbytes - n) / sizeof *dynrules;
+ if (co.do_dynamic) {
+ dynrules = (ipfw_dyn_rule *)r ;
+ n = (char *)r - (char *)data;
+ ndyn = (nbytes - n) / sizeof *dynrules;
+ }
/* if showing stats, figure out column widths ahead of time */
bcwidth = pcwidth = 0;
bcwidth = width;
}
}
+
if (co.do_dynamic && ndyn) {
for (n = 0, d = dynrules; n < ndyn; n++, d++) {
if (co.use_set) {
bcwidth = width;
}
}
+
/* if no rule numbers were specified, list all rules */
if (ac == 0) {
for (n = 0, r = data; n < nstat; n++, r = NEXT(r)) {
/* display specific rules requested on command line */
+ if (!co.do_dynamic) {
for (lac = ac, lav = av; lac != 0; lac--) {
/* convert command line rule # */
last = rnum = strtoul(*lav++, &endptr, 10);
warnx("rule %lu does not exist", rnum);
}
}
+ }
if (co.do_dynamic && ndyn) {
printf("## Dynamic rules:\n");