nfqws: comma separated values in --filter-tcp, --filter-udp

This commit is contained in:
bol-van
2024-10-29 17:41:59 +03:00
parent daac1d2127
commit 2452a529eb
7 changed files with 97 additions and 15 deletions

View File

@@ -448,3 +448,42 @@ bool ipset_collection_is_empty(const struct ipset_collection_head *head)
}
return true;
}
bool port_filter_add(struct port_filters_head *head, const port_filter *pf)
{
struct port_filter_item *entry = malloc(sizeof(struct port_filter_item));
if (entry)
{
entry->pf = *pf;
LIST_INSERT_HEAD(head, entry, next);
}
return entry;
}
void port_filters_destroy(struct port_filters_head *head)
{
struct port_filter_item *entry;
while ((entry = LIST_FIRST(head)))
{
LIST_REMOVE(entry, next);
free(entry);
}
}
bool port_filters_in_range(const struct port_filters_head *head, uint16_t port)
{
const struct port_filter_item *item;
if (!LIST_FIRST(head)) return true;
LIST_FOREACH(item, head, next)
{
if (pf_in_range(port, &item->pf))
return true;
}
return false;
}
bool port_filters_deny_if_empty(struct port_filters_head *head)
{
port_filter pf;
if (LIST_FIRST(head)) return true;
return pf_parse("0",&pf) && port_filter_add(head,&pf);
}