MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ipfw_zero

Function ipfw_zero

tools/ipfw/ipfw2.c:5404–5462  ·  view source on GitHub ↗

* clear the counters or the log counters. * optname has the following values: * 0 (zero both counters and logging) * 1 (zero logging only) */

Source from the content-addressed store, hash-verified

5402 * 1 (zero logging only)
5403 */
5404void
5405ipfw_zero(int ac, char *av[], int optname)
5406{
5407 ipfw_range_tlv rt;
5408 char const *errstr;
5409 char const *name = optname ? "RESETLOG" : "ZERO";
5410 uint32_t arg;
5411 int failed = EX_OK;
5412
5413 optname = optname ? IP_FW_XRESETLOG : IP_FW_XZERO;
5414 av++; ac--;
5415
5416 if (ac == 0) {
5417 /* clear all entries */
5418 memset(&rt, 0, sizeof(rt));
5419 rt.flags = IPFW_RCFLAG_ALL;
5420 if (do_range_cmd(optname, &rt) < 0)
5421 err(EX_UNAVAILABLE, "setsockopt(IP_FW_X%s)", name);
5422 if (!g_co.do_quiet)
5423 printf("%s.\n", optname == IP_FW_XZERO ?
5424 "Accounting cleared":"Logging counts reset");
5425
5426 return;
5427 }
5428
5429 while (ac) {
5430 /* Rule number */
5431 if (isdigit(**av)) {
5432 arg = strtonum(*av, 0, 0xffff, &errstr);
5433 if (errstr)
5434 errx(EX_DATAERR,
5435 "invalid rule number %s\n", *av);
5436 memset(&rt, 0, sizeof(rt));
5437 rt.start_rule = arg;
5438 rt.end_rule = arg;
5439 rt.flags |= IPFW_RCFLAG_RANGE;
5440 if (g_co.use_set != 0) {
5441 rt.set = g_co.use_set - 1;
5442 rt.flags |= IPFW_RCFLAG_SET;
5443 }
5444 if (do_range_cmd(optname, &rt) != 0) {
5445 warn("rule %u: setsockopt(IP_FW_X%s)",
5446 arg, name);
5447 failed = EX_UNAVAILABLE;
5448 } else if (rt.new_set == 0) {
5449 printf("Entry %d not found\n", arg);
5450 failed = EX_UNAVAILABLE;
5451 } else if (!g_co.do_quiet)
5452 printf("Entry %d %s.\n", arg,
5453 optname == IP_FW_XZERO ?
5454 "cleared" : "logging count reset");
5455 } else {
5456 errx(EX_USAGE, "invalid rule number ``%s''", *av);
5457 }
5458 av++; ac--;
5459 }
5460 if (failed != EX_OK)
5461 exit(failed);

Callers 1

main.cFile · 0.85

Calls 5

memsetFunction · 0.85
do_range_cmdFunction · 0.85
isdigitFunction · 0.85
strtonumFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected