shadowsocks/shadowsocks-rust · error

invalid `fake_dns_ipv4_network`

Error message

invalid `fake_dns_ipv4_network`

What it means

Thrown while parsing a local (SIP008/JSON) config: `fake_dns_ipv4_network` could not be parsed as an Ipv4Net. Fake-DNS needs a valid IPv4 CIDR range; any other string is rejected with ErrorKind::Malformed.

Source

Thrown at crates/shadowsocks-service/src/config.rs:2058

                            local_config.socks5_auth = Socks5AuthConfig::load_from_file(&socks5_auth_config_path)?;
                        }

                        #[cfg(feature = "local-http")]
                        if let Some(http_auth_config_path) = local.http_auth_config_path {
                            local_config.http_auth = HttpAuthConfig::load_from_file(&http_auth_config_path)?;
                        }

                        #[cfg(feature = "local-fake-dns")]
                        {
                            if let Some(d) = local.fake_dns_record_expire_duration {
                                local_config.fake_dns_record_expire_duration = Some(Duration::from_secs(d));
                            }
                            if let Some(n) = local.fake_dns_ipv4_network {
                                match n.parse::<Ipv4Net>() {
                                    Ok(n) => local_config.fake_dns_ipv4_network = Some(n),
                                    Err(..) => {
                                        let err =
                                            Error::new(ErrorKind::Malformed, "invalid `fake_dns_ipv4_network`", None);
                                        return Err(err);
                                    }
                                }
                            }
                            if let Some(n) = local.fake_dns_ipv6_network {
                                match n.parse::<Ipv6Net>() {
                                    Ok(n) => local_config.fake_dns_ipv6_network = Some(n),
                                    Err(..) => {
                                        let err =
                                            Error::new(ErrorKind::Malformed, "invalid `fake_dns_ipv6_network`", None);
                                        return Err(err);
                                    }
                                }
                            }
                            if let Some(p) = local.fake_dns_database_path {
                                local_config.fake_dns_database_path = Some(p.into());
                            }
                        }

View on GitHub (pinned to 8eb0f0a65b)

Solutions

  1. Use a valid IPv4 CIDR, e.g. `"fake_dns_ipv4_network": "10.0.0.0/8"`
  2. Confirm the value contains no colons (IPv6) and prefix is 0-32
  3. Append a prefix length if only an address was given

Example fix

// before
{"fake_dns_ipv4_network": "198.18.0.1"}
// after
{"fake_dns_ipv4_network": "198.18.0.0/15"}
Defensive patterns

Strategy: validation

Validate before calling

fn valid_ipv4net(s: &str) -> bool { s.parse::<ipnet::Ipv4Net>().is_ok() }
// before load: assert config["fake_dns_ipv4_network"].as_str().map(valid_ipv4net).unwrap_or(true)

Type guard

fn is_ipv4net(s: &str) -> bool { s.parse::<ipnet::Ipv4Net>().is_ok() }

Try / catch

match Config::load_from_json(...) { Err(e) if format!("{e}").contains("fake_dns_ipv4_network") => fix_and_retry(), ... }

Prevention

When it happens

Trigger: Config parsing with `fake_dns_ipv4_network` set to a non-IPv4-CIDR value: an IPv6 network, a bare IP, an over-long prefix like `/33`, or malformed text.

Common situations: Configuring fake-dns ranges by hand; accidentally entering an IPv6 range in the IPv4 field; forgetting the prefix length.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of shadowsocks/shadowsocks-rust@8eb0f0a65b (2026-09-09). Data as JSON: /api/errors/2e3cca1ed932cb4c. Report an issue: GitHub.