{"record":{"id":"c4149a782a828bad","repo":"jdx/mise","slug":"firewall-rule-name-mixes-ipv4-and-ipv6-source","errorCode":null,"errorMessage":"firewall rule '{name}' mixes IPv4 and IPv6 source/destination networks","messagePattern":"firewall rule '(.+?)' mixes IPv4 and IPv6 source/destination networks","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/firewall.rs","lineNumber":422,"sourceCode":"                .interface\n                .map(|interface| validate_interface(interface.trim()))\n                .transpose()?;\n            let source = rule\n                .source\n                .map(|source| source.parse::<IpNet>())\n                .transpose()\n                .wrap_err_with(|| format!(\"firewall rule '{name}' has an invalid source\"))?;\n            let destination = rule\n                .destination\n                .map(|destination| destination.parse::<IpNet>())\n                .transpose()\n                .wrap_err_with(|| format!(\"firewall rule '{name}' has an invalid destination\"))?;\n            if source.is_some_and(|source| {\n                destination.is_some_and(|destination| {\n                    source.addr().is_ipv4() != destination.addr().is_ipv4()\n                })\n            }) {\n                bail!(\"firewall rule '{name}' mixes IPv4 and IPv6 source/destination networks\");\n            }\n            let port = rule.port.map(FirewallPort::from_toml).transpose()?;\n            if port.is_some() && rule.protocol.is_none() {\n                bail!(\"firewall rule '{name}' sets port without protocol\");\n            }\n            rules.push(FirewallRule {\n                name,\n                state: rule.state,\n                direction: rule.direction,\n                action: rule.action,\n                port,\n                protocol: rule.protocol,\n                source,\n                destination,\n                interface,\n            });\n        }\n        let ssh_connection = std::env::var(\"SSH_CONNECTION\")","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/firewall.rs#L404-L440","documentation":"A firewall rule in `[firewall]` TOML config specifies both `source` and `destination` CIDR networks, but one is IPv4 and the other IPv6. Such a rule can never match a packet, and nftables/ufw/firewalld either reject it or silently drop it, so mise validates consistency while parsing the rule into FirewallRule.","triggerScenarios":"Defining a rule like source = \"192.168.1.0/24\" with destination = \"fd00::/8\" (or vice versa) and running any firewall bootstrap command that builds FirewallRequest::from_toml. Only fires when both source and destination are present and their address families differ.","commonSituations":"Mixing an IPv4-only LAN prefix with an IPv6 ULA/global destination; editing a rule to switch one side to IPv6 for a dual-stack host while forgetting the other side; copy-pasting CIDRs from different machine docs.","solutions":["Make source and destination the same address family: change one CIDR to match the other (IPv4 with IPv4, IPv6 with IPv6).","If you need to allow both families, define two separate rules, one per family, with distinct names.","Remove the side you did not intend to constrain (e.g. drop `destination` if only source matters)."],"exampleFix":"// before\n[[firewall.rules]]\nname = \"allow-nas\"\nsource = \"192.168.1.0/24\"\ndestination = \"fd00::10/128\"\naction = \"allow\"\n\n// after (two rules, one per family)\n[[firewall.rules]]\nname = \"allow-nas-v4\"\nsource = \"192.168.1.0/24\"\ndestination = \"192.168.1.10/32\"\naction = \"allow\"\n\n[[firewall.rules]]\nname = \"allow-nas-v6\"\nsource = \"fd00::/64\"\ndestination = \"fd00::10/128\"\naction = \"allow\"","handlingStrategy":"validation","validationCode":"fn families_match(rule: &FirewallRuleToml) -> bool {\n    let f = |s: &Option<String>| s.as_ref().map(|n| n.contains(':'));\n    match (f(&rule.source), f(&rule.destination)) {\n        (Some(a), Some(b)) => a == b,\n        _ => true,\n    }\n}","typeGuard":"fn is_consistent_family(src: Option<&IpNet>, dst: Option<&IpNet>) -> bool {\n    match (src, dst) {\n        (Some(s), Some(d)) => s.addr().is_ipv4() == d.addr().is_ipv4(),\n        _ => true,\n    }\n}","tryCatchPattern":"match FirewallRequest::from_toml(cfg) {\n    Err(e) if e.to_string().contains(\"mixes IPv4 and IPv6\") => {\n        eprintln!(\"split the rule into one per address family\");\n    }\n    other => other?,\n}","preventionTips":["Decide per host whether a rule is v4 or v6 and suffix the rule name accordingly.","Use CIDR literals that are visually distinct in review (dots vs colons).","Add a config test that asserts source/destination family equality for each rule."],"tags":["firewall","ipv6","config-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}