{"record":{"id":"76bf86b1fff9c53a","repo":"shadowsocks/shadowsocks-rust","slug":"tcp-redir-invalid","errorCode":null,"errorMessage":"`tcp_redir` invalid","messagePattern":"`tcp_redir` invalid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/shadowsocks-service/src/config.rs","lineNumber":1952,"sourceCode":"                                    let err =\n                                        Error::new(ErrorKind::Malformed, \"`forward_port` cannot be missing or 0\", None);\n                                    return Err(err);\n                                }\n                                Some(p) => p,\n                            };\n\n                            local_config.forward_addr = Some(match forward_address.parse::<IpAddr>() {\n                                Ok(ip) => Address::from(SocketAddr::new(ip, forward_port)),\n                                Err(..) => Address::from((forward_address, forward_port)),\n                            });\n                        }\n\n                        #[cfg(feature = \"local-redir\")]\n                        if let Some(tcp_redir) = local.tcp_redir {\n                            match tcp_redir.parse::<RedirType>() {\n                                Ok(r) => local_config.tcp_redir = r,\n                                Err(..) => {\n                                    let err = Error::new(ErrorKind::Malformed, \"`tcp_redir` invalid\", None);\n                                    return Err(err);\n                                }\n                            }\n                        }\n\n                        #[cfg(feature = \"local-redir\")]\n                        if let Some(udp_redir) = local.udp_redir {\n                            match udp_redir.parse::<RedirType>() {\n                                Ok(r) => local_config.udp_redir = r,\n                                Err(..) => {\n                                    let err = Error::new(ErrorKind::Malformed, \"`udp_redir` invalid\", None);\n                                    return Err(err);\n                                }\n                            }\n                        }\n\n                        #[cfg(feature = \"local-dns\")]\n                        if let Some(local_dns_address) = local.local_dns_address {","sourceCodeStart":1934,"sourceCodeEnd":1970,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/crates/shadowsocks-service/src/config.rs#L1934-L1970","documentation":"Raised under the `local-redir` feature when the `tcp_redir` string in a local entry cannot be parsed into a `RedirType`. RedirType names the platform TCP redirect mechanism (e.g. iptables/redirect on Linux, pf on BSD/macOS); an unknown value is rejected as Malformed.","triggerScenarios":"A config entry contains `tcp_redir` set to a string not recognized by RedirType::from_str — e.g. `\"nftables\"` on a version that doesn't support it, `\"iptables\"` on a macOS build, or a typo.","commonSituations":"Cross-platform configs reused on an OS whose RedirType variants differ; feature builds compiled without the redir backend matching the config; typos like \"REDIRECT\" or \"pf\" vs \"pf\"-style names.","solutions":["Use a RedirType value valid for your platform and build (e.g. \"redirect\" or \"tproxy\" on Linux with the matching feature enabled; \"pf\" on macOS/BSD).","Remove `tcp_redir` to use the platform default.","Check shadowsocks-rust docs for RedirType variants per OS and enabled cargo features."],"exampleFix":"// before\n{ \"tcp_redir\": \"nftables\" }\n// after\n{ \"tcp_redir\": \"tproxy\" }","handlingStrategy":"validation","validationCode":"fn validate_tcp_redir(entry: &serde_json::Value, platform: &str) -> Result<(), String> {\n    if let Some(r) = entry.get(\"tcp_redir\").and_then(|v| v.as_str()) {\n        let ok = match platform {\n            \"linux\" => matches!(r, \"redirect\" | \"tproxy\"),\n            \"macos\" | \"freebsd\" | \"openbsd\" => r == \"pf\",\n            _ => false,\n        };\n        if !ok {\n            return Err(format!(\"tcp_redir '{r}' not valid for {platform}\"));\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"#[cfg(feature = \"local-redir\")]\nmatch LocalConfig::load_from(config_path) {\n    Ok(cfg) => start(cfg),\n    Err(e) if e.to_string().contains(\"tcp_redir\") => {\n        eprintln!(\"Bad tcp_redir for this platform/build: {e}\");\n        std::process::exit(1);\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Keep platform-specific redir values in separate per-OS config files.","Verify the redir backend feature is compiled into your binary before referencing it.","Use the platform default by omitting tcp_redir unless you need a specific mechanism."],"tags":["config","redir","platform","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"8eb0f0a65b1d976ab6bed5787327ef86529b0435","analyzedAt":"2026-09-09T12:20:43.168Z","contentChangedAt":"2026-09-09T12:20:43.168Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}