shadowsocks/shadowsocks-rust · error

`udp_redir` invalid

Error message

`udp_redir` invalid

What it means

Raised under the `local-redir` feature when the `udp_redir` string cannot be parsed into a `RedirType`. This is the UDP counterpart of the tcp_redir validation: the value must name a UDP redirect mechanism supported by the current platform and build.

Source

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

                        }

                        #[cfg(feature = "local-redir")]
                        if let Some(tcp_redir) = local.tcp_redir {
                            match tcp_redir.parse::<RedirType>() {
                                Ok(r) => local_config.tcp_redir = r,
                                Err(..) => {
                                    let err = Error::new(ErrorKind::Malformed, "`tcp_redir` invalid", None);
                                    return Err(err);
                                }
                            }
                        }

                        #[cfg(feature = "local-redir")]
                        if let Some(udp_redir) = local.udp_redir {
                            match udp_redir.parse::<RedirType>() {
                                Ok(r) => local_config.udp_redir = r,
                                Err(..) => {
                                    let err = Error::new(ErrorKind::Malformed, "`udp_redir` invalid", None);
                                    return Err(err);
                                }
                            }
                        }

                        #[cfg(feature = "local-dns")]
                        if let Some(local_dns_address) = local.local_dns_address {
                            match local_dns_address.parse::<IpAddr>() {
                                Ok(ip) => {
                                    local_config.local_dns_addr = Some(NameServerAddr::SocketAddr(SocketAddr::new(
                                        ip,
                                        local.local_dns_port.unwrap_or(53),
                                    )));
                                }
                                #[cfg(unix)]
                                Err(..) => {
                                    local_config.local_dns_addr =
                                        Some(NameServerAddr::UnixSocketAddr(PathBuf::from(local_dns_address)));

View on GitHub (pinned to 8eb0f0a65b)

Solutions

  1. Set `udp_redir` to a UDP-capable RedirType for your platform, e.g. "tproxy" on Linux.
  2. Remove `udp_redir` if UDP redirect is not needed.
  3. Confirm the local-redir feature and the required backend features (e.g. local-redir with tproxy support) are compiled in.

Example fix

// before
{ "udp_redir": "redirect" }
// after
{ "udp_redir": "tproxy" }
Defensive patterns

Strategy: validation

Validate before calling

fn validate_udp_redir(entry: &serde_json::Value, platform: &str) -> Result<(), String> {
    if let Some(r) = entry.get("udp_redir").and_then(|v| v.as_str()) {
        let ok = match platform {
            "linux" => r == "tproxy", // UDP redirect on Linux requires tproxy
            "macos" | "freebsd" | "openbsd" => r == "pf",
            _ => false,
        };
        if !ok {
            return Err(format!("udp_redir '{r}' not valid for {platform}"));
        }
    }
    Ok(())
}

Try / catch

#[cfg(feature = "local-redir")]
match LocalConfig::load_from(config_path) {
    Ok(cfg) => start(cfg),
    Err(e) if e.to_string().contains("udp_redir") => {
        eprintln!("Bad udp_redir (UDP usually needs tproxy on Linux): {e}");
        std::process::exit(1);
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: A config entry contains `udp_redir` set to an unrecognized string, e.g. `"redirect"` where UDP only supports "tproxy" on Linux, or any typo/wrong-case value.

Common situations: Users copying the TCP redir value into udp_redir (redirect is TCP-only on Linux; UDP needs tproxy); platform-mismatched configs; typos.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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