Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bpf
24 changes: 21 additions & 3 deletions filter/net-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,27 +341,45 @@ bool NetFilter::load_rules(const char *rule_file)
char *line = NULL;
size_t len;
ssize_t read;
unsigned int first_key = key_cnt;

auto rollback_loaded_rules = [&]() {
for (unsigned int key = first_key; key < key_cnt; key++)
{
del_rule(key);
}
key_cnt = first_key;
};
while ((read = getline(&line, &len, fp)) != -1)
{
Rule rule;

if (line[0] == '#' || line[0] == '\n')
while (*line == ' ' || *line == '\t')
{
line++;
}
if (*line == '#' || *line == '\n' || *line == '\0')
{
continue;
}

if (!parse_rule(line, rule))
{
continue;
pr_error("syntax error in config file\n");
rollback_loaded_rules();
free(line);
fclose(fp);
return false;
}

int key;
key = add_rule(rule);

if (key < 0)
{
printf("syntax pr_error in config file\n");
pr_error("failed to add rule from config file\n");
rollback_loaded_rules();
free(line);
fclose(fp);
return false;
}
Expand Down
Loading