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

Function ipfw_sets_handler

tools/ipfw/ipfw2.c:2385–2495  ·  view source on GitHub ↗

* This one handles all set-related commands * ipfw set { show | enable | disable } * ipfw set swap X Y * ipfw set move X to Y * ipfw set move rule X to Y */

Source from the content-addressed store, hash-verified

2383 * ipfw set move rule X to Y
2384 */
2385void
2386ipfw_sets_handler(char *av[])
2387{
2388 ipfw_range_tlv rt;
2389 const char *msg;
2390 size_t size;
2391 uint32_t masks[2];
2392 int i;
2393 uint16_t rulenum;
2394 uint8_t cmd;
2395
2396 av++;
2397 memset(&rt, 0, sizeof(rt));
2398
2399 if (av[0] == NULL)
2400 errx(EX_USAGE, "set needs command");
2401 if (_substrcmp(*av, "show") == 0) {
2402 struct format_opts fo;
2403 ipfw_cfg_lheader *cfg;
2404
2405 memset(&fo, 0, sizeof(fo));
2406 if (ipfw_get_config(&g_co, &fo, &cfg, &size) != 0)
2407 err(EX_OSERR, "requesting config failed");
2408
2409 for (i = 0, msg = "disable"; i < RESVD_SET; i++)
2410 if ((cfg->set_mask & (1<<i)) == 0) {
2411 printf("%s %d", msg, i);
2412 msg = "";
2413 }
2414 msg = (cfg->set_mask != (uint32_t)-1) ? " enable" : "enable";
2415 for (i = 0; i < RESVD_SET; i++)
2416 if ((cfg->set_mask & (1<<i)) != 0) {
2417 printf("%s %d", msg, i);
2418 msg = "";
2419 }
2420 printf("\n");
2421 free(cfg);
2422 } else if (_substrcmp(*av, "swap") == 0) {
2423 av++;
2424 if ( av[0] == NULL || av[1] == NULL )
2425 errx(EX_USAGE, "set swap needs 2 set numbers\n");
2426 rt.set = atoi(av[0]);
2427 rt.new_set = atoi(av[1]);
2428 if (!isdigit(*(av[0])) || rt.set > RESVD_SET)
2429 errx(EX_DATAERR, "invalid set number %s\n", av[0]);
2430 if (!isdigit(*(av[1])) || rt.new_set > RESVD_SET)
2431 errx(EX_DATAERR, "invalid set number %s\n", av[1]);
2432 i = do_range_cmd(IP_FW_SET_SWAP, &rt);
2433 } else if (_substrcmp(*av, "move") == 0) {
2434 av++;
2435 if (av[0] && _substrcmp(*av, "rule") == 0) {
2436 rt.flags = IPFW_RCFLAG_RANGE; /* move rules to new set */
2437 cmd = IP_FW_XMOVE;
2438 av++;
2439 } else
2440 cmd = IP_FW_SET_MOVE; /* Move set to new one */
2441 if (av[0] == NULL || av[1] == NULL || av[2] == NULL ||
2442 av[3] != NULL || _substrcmp(av[1], "to") != 0)

Callers 1

main.cFile · 0.85

Calls 7

memsetFunction · 0.85
_substrcmpFunction · 0.85
ipfw_get_configFunction · 0.85
isdigitFunction · 0.85
do_range_cmdFunction · 0.85
printfFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected