firewall: introduce helper function for add/flush/delete nft table command

(cherry picked from commit e796a67d6c)
This commit is contained in:
Thomas Haller 2022-09-27 18:15:31 +02:00
parent d7bc25b3bd
commit 56a503c879
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -619,6 +619,14 @@ _fw_nft_call_sync(GBytes *stdin_buf, GError **error)
#define _append(p_strbuf, fmt, ...) nm_str_buf_append_printf((p_strbuf), "" fmt "\n", ##__VA_ARGS__)
static void
_fw_nft_append_cmd_table(NMStrBuf *strbuf, const char *family, const char *table_name, gboolean up)
{
/* Either delete the table, or create/flush it. */
_append(strbuf, "add table %s %s", family, table_name);
_append(strbuf, "%s table %s %s", up ? "flush" : "delete", family, table_name);
}
static GBytes *
_fw_nft_set_shared_construct(gboolean up, const char *ip_iface, in_addr_t addr, guint8 plen)
{
@ -630,8 +638,7 @@ _fw_nft_set_shared_construct(gboolean up, const char *ip_iface, in_addr_t addr,
_share_iptables_subnet_to_str(str_subnet, addr, plen);
_append(&strbuf, "add table ip %s", table_name);
_append(&strbuf, "%s table ip %s", up ? "flush" : "delete", table_name);
_fw_nft_append_cmd_table(&strbuf, "ip", table_name, up);
if (up) {
_append(&strbuf,