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

Function pfr_ina_define

freebsd/netpfil/pf/pf_table.c:1462–1561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1460}
1461
1462int
1463pfr_ina_define(struct pfr_table *tbl, struct pfr_addr *addr, int size,
1464 int *nadd, int *naddr, u_int32_t ticket, int flags)
1465{
1466 struct pfr_ktableworkq tableq;
1467 struct pfr_kentryworkq addrq;
1468 struct pfr_ktable *kt, *rt, *shadow, key;
1469 struct pfr_kentry *p;
1470 struct pfr_addr *ad;
1471 struct pf_kruleset *rs;
1472 int i, rv, xadd = 0, xaddr = 0;
1473
1474 PF_RULES_WASSERT();
1475
1476 ACCEPT_FLAGS(flags, PFR_FLAG_DUMMY | PFR_FLAG_ADDRSTOO);
1477 if (size && !(flags & PFR_FLAG_ADDRSTOO))
1478 return (EINVAL);
1479 if (pfr_validate_table(tbl, PFR_TFLAG_USRMASK,
1480 flags & PFR_FLAG_USERIOCTL))
1481 return (EINVAL);
1482 rs = pf_find_kruleset(tbl->pfrt_anchor);
1483 if (rs == NULL || !rs->topen || ticket != rs->tticket)
1484 return (EBUSY);
1485 tbl->pfrt_flags |= PFR_TFLAG_INACTIVE;
1486 SLIST_INIT(&tableq);
1487 kt = RB_FIND(pfr_ktablehead, &V_pfr_ktables, (struct pfr_ktable *)tbl);
1488 if (kt == NULL) {
1489 kt = pfr_create_ktable(tbl, 0, 1);
1490 if (kt == NULL)
1491 return (ENOMEM);
1492 SLIST_INSERT_HEAD(&tableq, kt, pfrkt_workq);
1493 xadd++;
1494 if (!tbl->pfrt_anchor[0])
1495 goto _skip;
1496
1497 /* find or create root table */
1498 bzero(&key, sizeof(key));
1499 strlcpy(key.pfrkt_name, tbl->pfrt_name, sizeof(key.pfrkt_name));
1500 rt = RB_FIND(pfr_ktablehead, &V_pfr_ktables, &key);
1501 if (rt != NULL) {
1502 kt->pfrkt_root = rt;
1503 goto _skip;
1504 }
1505 rt = pfr_create_ktable(&key.pfrkt_t, 0, 1);
1506 if (rt == NULL) {
1507 pfr_destroy_ktables(&tableq, 0);
1508 return (ENOMEM);
1509 }
1510 SLIST_INSERT_HEAD(&tableq, rt, pfrkt_workq);
1511 kt->pfrkt_root = rt;
1512 } else if (!(kt->pfrkt_flags & PFR_TFLAG_INACTIVE))
1513 xadd++;
1514_skip:
1515 shadow = pfr_create_ktable(tbl, 0, 0);
1516 if (shadow == NULL) {
1517 pfr_destroy_ktables(&tableq, 0);
1518 return (ENOMEM);
1519 }

Callers 1

pfioctlFunction · 0.85

Calls 15

pfr_validate_tableFunction · 0.85
pf_find_krulesetFunction · 0.85
pfr_create_ktableFunction · 0.85
bzeroFunction · 0.85
pfr_destroy_ktablesFunction · 0.85
pfr_validate_addrFunction · 0.85
pfr_lookup_addrFunction · 0.85
pfr_create_kentryFunction · 0.85
pfr_route_kentryFunction · 0.85
pfr_destroy_kentryFunction · 0.85
pfr_destroy_ktableFunction · 0.85
pfr_insert_ktablesFunction · 0.85

Tested by

no test coverage detected