If -q flag is specified, do not complain when we are trying to delete

nonexistent NAT instance or nonexistent rule.

This allows execute batched `delete` commands and do not fail when
found nonexistent rule.

Obtained from:	Yandex LLC
MFC after:	2 weeks
Sponsored by:	Yandex LLC
This commit is contained in:
Andrey V. Elsukov 2018-08-09 12:46:30 +00:00
parent d1b1fe3a25
commit e327ad3377
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=337536

View File

@ -3271,9 +3271,11 @@ ipfw_delete(char *av[])
exitval = do_cmd(IP_FW_NAT_DEL, &i, sizeof i);
if (exitval) {
exitval = EX_UNAVAILABLE;
warn("rule %u not available", i);
if (co.do_quiet)
continue;
warn("nat %u not available", i);
}
} else if (co.do_pipe) {
} else if (co.do_pipe) {
exitval = ipfw_delete_pipe(co.do_pipe, i);
} else {
memset(&rt, 0, sizeof(rt));
@ -3295,10 +3297,14 @@ ipfw_delete(char *av[])
i = do_range_cmd(IP_FW_XDEL, &rt);
if (i != 0) {
exitval = EX_UNAVAILABLE;
if (co.do_quiet)
continue;
warn("rule %u: setsockopt(IP_FW_XDEL)",
rt.start_rule);
} else if (rt.new_set == 0 && do_set == 0) {
exitval = EX_UNAVAILABLE;
if (co.do_quiet)
continue;
if (rt.start_rule != rt.end_rule)
warnx("no rules rules in %u-%u range",
rt.start_rule, rt.end_rule);
@ -3308,7 +3314,7 @@ ipfw_delete(char *av[])
}
}
}
if (exitval != EX_OK)
if (exitval != EX_OK && co.do_quiet == 0)
exit(exitval);
}