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

Function pf_commit_rules

freebsd/netpfil/pf/pf_ioctl.c:1030–1085  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1028}
1029
1030static int
1031pf_commit_rules(u_int32_t ticket, int rs_num, char *anchor)
1032{
1033 struct pf_kruleset *rs;
1034 struct pf_krule *rule, **old_array;
1035 struct pf_krulequeue *old_rules;
1036 int error;
1037 u_int32_t old_rcount;
1038
1039 PF_RULES_WASSERT();
1040
1041 if (rs_num < 0 || rs_num >= PF_RULESET_MAX)
1042 return (EINVAL);
1043 rs = pf_find_kruleset(anchor);
1044 if (rs == NULL || !rs->rules[rs_num].inactive.open ||
1045 ticket != rs->rules[rs_num].inactive.ticket)
1046 return (EBUSY);
1047
1048 /* Calculate checksum for the main ruleset */
1049 if (rs == &pf_main_ruleset) {
1050 error = pf_setup_pfsync_matching(rs);
1051 if (error != 0)
1052 return (error);
1053 }
1054
1055 /* Swap rules, keep the old. */
1056 old_rules = rs->rules[rs_num].active.ptr;
1057 old_rcount = rs->rules[rs_num].active.rcount;
1058 old_array = rs->rules[rs_num].active.ptr_array;
1059
1060 rs->rules[rs_num].active.ptr =
1061 rs->rules[rs_num].inactive.ptr;
1062 rs->rules[rs_num].active.ptr_array =
1063 rs->rules[rs_num].inactive.ptr_array;
1064 rs->rules[rs_num].active.rcount =
1065 rs->rules[rs_num].inactive.rcount;
1066 rs->rules[rs_num].inactive.ptr = old_rules;
1067 rs->rules[rs_num].inactive.ptr_array = old_array;
1068 rs->rules[rs_num].inactive.rcount = old_rcount;
1069
1070 rs->rules[rs_num].active.ticket =
1071 rs->rules[rs_num].inactive.ticket;
1072 pf_calc_skip_steps(rs->rules[rs_num].active.ptr);
1073
1074 /* Purge the old rule list. */
1075 while ((rule = TAILQ_FIRST(old_rules)) != NULL)
1076 pf_unlink_rule(old_rules, rule);
1077 if (rs->rules[rs_num].inactive.ptr_array)
1078 free(rs->rules[rs_num].inactive.ptr_array, M_TEMP);
1079 rs->rules[rs_num].inactive.ptr_array = NULL;
1080 rs->rules[rs_num].inactive.rcount = 0;
1081 rs->rules[rs_num].inactive.open = 0;
1082 pf_remove_if_empty_kruleset(rs);
1083
1084 return (0);
1085}
1086
1087static int

Callers 2

pfioctlFunction · 0.85
shutdown_pfFunction · 0.85

Calls 6

pf_find_krulesetFunction · 0.85
pf_setup_pfsync_matchingFunction · 0.85
pf_calc_skip_stepsFunction · 0.85
pf_unlink_ruleFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected