fix(config): stop mutating shared config structs during parsing

Prevent data loss and nil panics across 5 parse functions:
- chain: nil-guard hop entries to avoid deref on empty YAML lists
- hop: build merged metadata map instead of writing inherited values
  into the original NodeConfig; swap+restore around ParseNode call
- node: use local connCfg/dialCfg instead of overwriting cfg.Connector
  and cfg.Dialer fields; only fill in Type when empty
- parser: preserve existing config file fields when env vars override
  Level/Addr (was replacing the entire struct)
- router: only update ipNet from dst CIDR if parse succeeds, keeping
  the route.Net fallback instead of overwriting with nil
This commit is contained in:
ginuerzh
2026-05-24 12:56:54 +08:00
parent 8390ccadab
commit 9febb23bc9
5 changed files with 60 additions and 54 deletions
+3 -1
View File
@@ -51,7 +51,9 @@ func ParseRouter(cfg *config.RouterConfig) router.Router {
_, ipNet, _ := net.ParseCIDR(route.Net)
dst := route.Dst
if dst != "" {
_, ipNet, _ = net.ParseCIDR(dst)
if _, parsed, _ := net.ParseCIDR(dst); parsed != nil {
ipNet = parsed
}
} else {
if ipNet != nil {
dst = ipNet.String()