From ddaf00f0e71f481b237dd818e5ed60f5a9349d53 Mon Sep 17 00:00:00 2001 From: Konstantin Demin Date: Sun, 7 Jul 2024 15:22:17 +0300 Subject: [PATCH] minor code improvement --- dns-remap.go | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/dns-remap.go b/dns-remap.go index 669e956..8b6df37 100644 --- a/dns-remap.go +++ b/dns-remap.go @@ -173,36 +173,20 @@ func dnsRemap(qname string, qtype uint16, orig *dns.Msg) ([]PowerDnsAnswer, erro // perform nftables assignment if len(nft_ipv4) > 0 { - nftDoWithTable(cfgNftTable, cfgNftTableFamily, func(c *nft.Conn, t *nft.Table) error { - m, err := nftGetMapByName(c, t, cfgNftMapV4) - if err != nil { - return err - } + nftDoWithMap(cfgNftTable, cfgNftTableFamily, cfgNftMapV4, func(c *nft.Conn, t *nft.Table, m *nft.Set) error { _ = c.SetDeleteElements(m, nft_ipv4) return nil }) - nftDoWithTable(cfgNftTable, cfgNftTableFamily, func(c *nft.Conn, t *nft.Table) error { - m, err := nftGetMapByName(c, t, cfgNftMapV4) - if err != nil { - return err - } + nftDoWithMap(cfgNftTable, cfgNftTableFamily, cfgNftMapV4, func(c *nft.Conn, t *nft.Table, m *nft.Set) error { return c.SetAddElements(m, nft_ipv4) }) } if len(nft_ipv6) > 0 { - nftDoWithTable(cfgNftTable, cfgNftTableFamily, func(c *nft.Conn, t *nft.Table) error { - m, err := nftGetMapByName(c, t, cfgNftMapV6) - if err != nil { - return err - } + nftDoWithMap(cfgNftTable, cfgNftTableFamily, cfgNftMapV6, func(c *nft.Conn, t *nft.Table, m *nft.Set) error { _ = c.SetDeleteElements(m, nft_ipv6) return nil }) - nftDoWithTable(cfgNftTable, cfgNftTableFamily, func(c *nft.Conn, t *nft.Table) error { - m, err := nftGetMapByName(c, t, cfgNftMapV6) - if err != nil { - return err - } + nftDoWithMap(cfgNftTable, cfgNftTableFamily, cfgNftMapV6, func(c *nft.Conn, t *nft.Table, m *nft.Set) error { return c.SetAddElements(m, nft_ipv6) }) }