jdx/mise · error

firewall rule ' ' mixes IPv4 and IPv6 source/destination…

Error message

firewall rule '{name}' mixes IPv4 and IPv6 source/destination networks

What it means

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.

Solutions

  1. Make source and destination the same address family: change one CIDR to match the other (IPv4 with IPv4, IPv6 with IPv6).
  2. If you need to allow both families, define two separate rules, one per family, with distinct names.
  3. Remove the side you did not intend to constrain (e.g. drop `destination` if only source matters).

Example fix

// before
[[firewall.rules]]
name = "allow-nas"
source = "192.168.1.0/24"
destination = "fd00::10/128"
action = "allow"

// after (two rules, one per family)
[[firewall.rules]]
name = "allow-nas-v4"
source = "192.168.1.0/24"
destination = "192.168.1.10/32"
action = "allow"

[[firewall.rules]]
name = "allow-nas-v6"
source = "fd00::/64"
destination = "fd00::10/128"
action = "allow"
Defensive patterns

Strategy: validation

Validate before calling

fn families_match(rule: &FirewallRuleToml) -> bool {
    let f = |s: &Option<String>| s.as_ref().map(|n| n.contains(':'));
    match (f(&rule.source), f(&rule.destination)) {
        (Some(a), Some(b)) => a == b,
        _ => true,
    }
}

Type guard

fn is_consistent_family(src: Option<&IpNet>, dst: Option<&IpNet>) -> bool {
    match (src, dst) {
        (Some(s), Some(d)) => s.addr().is_ipv4() == d.addr().is_ipv4(),
        _ => true,
    }
}

Try / catch

match FirewallRequest::from_toml(cfg) {
    Err(e) if e.to_string().contains("mixes IPv4 and IPv6") => {
        eprintln!("split the rule into one per address family");
    }
    other => other?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/c4149a782a828bad. Report an issue: GitHub.

Appendix: source

Thrown at src/system/firewall.rs:422

                .interface
                .map(|interface| validate_interface(interface.trim()))
                .transpose()?;
            let source = rule
                .source
                .map(|source| source.parse::<IpNet>())
                .transpose()
                .wrap_err_with(|| format!("firewall rule '{name}' has an invalid source"))?;
            let destination = rule
                .destination
                .map(|destination| destination.parse::<IpNet>())
                .transpose()
                .wrap_err_with(|| format!("firewall rule '{name}' has an invalid destination"))?;
            if source.is_some_and(|source| {
                destination.is_some_and(|destination| {
                    source.addr().is_ipv4() != destination.addr().is_ipv4()
                })
            }) {
                bail!("firewall rule '{name}' mixes IPv4 and IPv6 source/destination networks");
            }
            let port = rule.port.map(FirewallPort::from_toml).transpose()?;
            if port.is_some() && rule.protocol.is_none() {
                bail!("firewall rule '{name}' sets port without protocol");
            }
            rules.push(FirewallRule {
                name,
                state: rule.state,
                direction: rule.direction,
                action: rule.action,
                port,
                protocol: rule.protocol,
                source,
                destination,
                interface,
            });
        }
        let ssh_connection = std::env::var("SSH_CONNECTION")

View on GitHub (pinned to 533346cc37)