diff options
Diffstat (limited to 'src/shared/firewall-util-iptables.c')
-rw-r--r-- | src/shared/firewall-util-iptables.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/shared/firewall-util-iptables.c b/src/shared/firewall-util-iptables.c index 982c61d8fb..d53a394895 100644 --- a/src/shared/firewall-util-iptables.c +++ b/src/shared/firewall-util-iptables.c @@ -102,9 +102,9 @@ int fw_iptables_add_masquerade( if (!source || source_prefixlen == 0) return -EINVAL; - h = iptc_init("nat"); - if (!h) - return -errno; + r = fw_iptables_init_nat(&h); + if (r < 0) + return r; sz = XT_ALIGN(sizeof(struct ipt_entry)) + XT_ALIGN(sizeof(struct ipt_entry_target)) + @@ -192,9 +192,9 @@ int fw_iptables_add_local_dnat( if (remote_port <= 0) return -EINVAL; - h = iptc_init("nat"); - if (!h) - return -errno; + r = fw_iptables_init_nat(&h); + if (r < 0) + return r; sz = XT_ALIGN(sizeof(struct ipt_entry)) + XT_ALIGN(sizeof(struct ipt_entry_match)) + @@ -348,3 +348,16 @@ int fw_iptables_add_local_dnat( return 0; } + +int fw_iptables_init_nat(struct xtc_handle **ret) { + _cleanup_(iptc_freep) struct xtc_handle *h = NULL; + + h = iptc_init("nat"); + if (!h) + return log_debug_errno(errno, "Failed to init \"nat\" table: %s", iptc_strerror(errno)); + + if (ret) + *ret = TAKE_PTR(h); + + return 0; +} |