]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
firewall-util: refuse IPv6 firewall rules when kernel does not support IPv6
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 23 Mar 2021 03:02:54 +0000 (12:02 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 23 Mar 2021 06:17:44 +0000 (15:17 +0900)
src/shared/firewall-util-nft.c

index 1c6a25c4c0c27e8092d1b6ef6facc8b3fd01e1b1..ecabc5fc4042b8a8e2084bd4ca1778f40ef623d3 100644 (file)
@@ -756,9 +756,11 @@ int fw_nftables_init(FirewallContext *ctx) {
         if (r < 0)
                 return r;
 
-        r = fw_nftables_init_family(nfnl, AF_INET6);
-        if (r < 0)
-                log_debug_errno(r, "Failed to init ipv6 NAT: %m");
+        if (socket_ipv6_is_supported()) {
+                r = fw_nftables_init_family(nfnl, AF_INET6);
+                if (r < 0)
+                        log_debug_errno(r, "Failed to init ipv6 NAT: %m");
+        }
 
         ctx->nfnl = TAKE_PTR(nfnl);
         return 0;
@@ -902,6 +904,9 @@ int fw_nftables_add_masquerade(
 
         int r;
 
+        if (!socket_ipv6_is_supported() && af == AF_INET6)
+                return -EOPNOTSUPP;
+
         r = fw_nftables_add_masquerade_internal(ctx, add, af, source, source_prefixlen);
         if (r != -ENOENT)
                 return r;
@@ -1048,6 +1053,9 @@ int fw_nftables_add_local_dnat(
 
         int r;
 
+        if (!socket_ipv6_is_supported() && af == AF_INET6)
+                return -EOPNOTSUPP;
+
         r = fw_nftables_add_local_dnat_internal(ctx, add, af, protocol, local_port, remote, remote_port, previous_remote);
         if (r != -ENOENT)
                 return r;