v2rayA/v2rayA · error

undefined "%v" mode of transparent proxy

Error message

undefined "%v" mode of transparent proxy

What it means

The configured TransparentType value did not match any known mode (tproxy, redirect, system proxy, tinytun). This is a configuration-validation error indicating the setting file holds an out-of-range or corrupted value for the transparent proxy type.

Source

Thrown at service/kernel/v2ray/transparent.go:181

	case configure.TransparentTproxy:
		if err = iptables.Tproxy.GetSetupCommands().Run(true); err != nil {
			if strings.Contains(err.Error(), "TPROXY") && strings.Contains(err.Error(), "No chain") {
				err = fmt.Errorf("you does not compile xt_TPROXY in kernel")
			}
			return fmt.Errorf("not support \"tproxy\" mode of transparent proxy: %w", err)
		}
		iptables.SetWatcher(iptables.Tproxy)
	case configure.TransparentRedirect:
		if err = iptables.Redirect.GetSetupCommands().Run(true); err != nil {
			return fmt.Errorf("not support \"redirect\" mode of transparent proxy: %w", err)
		}
		iptables.SetWatcher(iptables.Redirect)
	case configure.TransparentSystemProxy:
		if err = iptables.SystemProxy.GetSetupCommands().Run(true); err != nil {
			return fmt.Errorf("not support \"system proxy\" mode of transparent proxy: %w", err)
		}
	default:
		return fmt.Errorf("undefined \"%v\" mode of transparent proxy", setting.TransparentType)
	}

	// 无论哪种透明代理模式,都用 nat 表的 REDIRECT 将 DNS 流量(:53)转到 DNS 模块(:52353)。
	// 同时拦截 OUTPUT(本地进程)和 PREROUTING(LAN 设备)的 DNS 查询。
	// TPROXY 模式对回环(loopback)流量的 TPROXY 拦截不可靠,而 REDIRECT 在 OUTPUT 链上稳定。
	//
	// IMPORTANT (fix): mark 0x80 豁免规则必须排在 REDIRECT 规则之前,否则 v2raya-core
	// 自己向上游转发的 DNS 查询(socket 带 SO_MARK=0x80)会被自己的 REDIRECT 规则劫持回
	// :52353,形成无限回环(内存雪崩直至 OOM)。iptables 按顺序匹配:
	//   - REDIRECT 用 -A(追加到链尾),确保在 mark 豁免之后
	//   - mark 豁免用 -I(插入到链首),确保最先匹配
	if ShouldLocalDnsListen() {
		dnsRedirect := `
iptables -w 2 -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to-port 52353
iptables -w 2 -t nat -A OUTPUT -p tcp --dport 53 -j REDIRECT --to-port 52353
iptables -w 2 -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-port 52353
iptables -w 2 -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-port 52353
iptables -w 2 -t nat -I OUTPUT -m mark --mark 0x80/0x80 -j RETURN

View on GitHub (pinned to 71e5442fc5)

Solutions

  1. Open v2rayA settings and re-select a valid transparent-proxy mode (tproxy / redirect / system proxy / tinytun).
  2. Or delete/reset the settings store so defaults are regenerated.
  3. Log the offending value (%v is interpolated) and fix the config file directly.
  4. If you wrote the config programmatically, validate the enum before persisting.

Example fix

// before (config)
"transparentType": "tun2socks"   // unknown value
// after
"transparentType": "redirect"
Defensive patterns

Strategy: validation

Validate before calling

valid := map[configure.TransparentType]bool{
	configure.TransparentTproxy: true, configure.TransparentRedirect: true,
	configure.TransparentSystemProxy: true, configure.TransparentTun: v2ray.IsTinyTunEnabled(),
}
if !valid[setting.TransparentType] { return fmt.Errorf("invalid transparent type: %v", setting.TransparentType) }

Prevention

When it happens

Trigger: writeTransparentProxyRules hits the default branch of its switch because setting.TransparentType contains an unknown/zero/legacy value — e.g. a hand-edited config, an older config version whose enum numeric value no longer maps, or a config written by a different fork.

Common situations: Manually editing the settings JSON with an invalid string; downgrading/upgrading v2rayA where enum representation changed; config sync from another tool writing raw values.

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 v2rayA/v2rayA@71e5442fc5 (2026-09-05). Data as JSON: /api/errors/c6e4d7347fc5404b. Report an issue: GitHub.