From 174b857658b07529e543f19f7a31e8962865e724 Mon Sep 17 00:00:00 2001 From: TargetLocked <32962687+TargetLocked@users.noreply.github.com> Date: Wed, 26 Feb 2025 07:28:42 +0800 Subject: [PATCH] Fix parsing legacy DNS options --- option/dns.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/option/dns.go b/option/dns.go index f4418468..c4186240 100644 --- a/option/dns.go +++ b/option/dns.go @@ -87,7 +87,7 @@ func (o *NewDNSServerOptions) UnmarshalJSONContext(ctx context.Context, content } registry := service.FromContext[DNSTransportOptionsRegistry](ctx) if registry == nil { - return E.New("missing outbound options registry in context") + return E.New("missing DNS transport options registry in context") } var options any switch o.Type { @@ -102,7 +102,7 @@ func (o *NewDNSServerOptions) UnmarshalJSONContext(ctx context.Context, content return E.New("unknown transport type: ", o.Type) } } - err = badjson.UnmarshallExcludedContext(ctx, content, (*_Outbound)(o), options) + err = badjson.UnmarshallExcludedContext(ctx, content, (*_NewDNSServerOptions)(o), options) if err != nil { return err } @@ -178,12 +178,10 @@ func (o *NewDNSServerOptions) Upgrade(ctx context.Context) error { if !serverAddr.IsValid() { return E.New("invalid server address") } - remoteOptions.Server = serverAddr.Addr.String() + remoteOptions.Server = serverAddr.AddrString() if serverAddr.Port != 0 && serverAddr.Port != 53 { remoteOptions.ServerPort = serverAddr.Port } - remoteOptions.Server = serverAddr.AddrString() - remoteOptions.ServerPort = serverAddr.Port case C.DNSTypeTCP: o.Type = C.DNSTypeTCP o.Options = &remoteOptions @@ -191,19 +189,17 @@ func (o *NewDNSServerOptions) Upgrade(ctx context.Context) error { if !serverAddr.IsValid() { return E.New("invalid server address") } - remoteOptions.Server = serverAddr.Addr.String() + remoteOptions.Server = serverAddr.AddrString() if serverAddr.Port != 0 && serverAddr.Port != 53 { remoteOptions.ServerPort = serverAddr.Port } - remoteOptions.Server = serverAddr.AddrString() - remoteOptions.ServerPort = serverAddr.Port case C.DNSTypeTLS, C.DNSTypeQUIC: o.Type = serverType serverAddr := M.ParseSocksaddr(serverURL.Host) if !serverAddr.IsValid() { return E.New("invalid server address") } - remoteOptions.Server = serverAddr.Addr.String() + remoteOptions.Server = serverAddr.AddrString() if serverAddr.Port != 0 && serverAddr.Port != 853 { remoteOptions.ServerPort = serverAddr.Port } @@ -222,7 +218,7 @@ func (o *NewDNSServerOptions) Upgrade(ctx context.Context) error { if !serverAddr.IsValid() { return E.New("invalid server address") } - httpsOptions.Server = serverAddr.Addr.String() + httpsOptions.Server = serverAddr.AddrString() if serverAddr.Port != 0 && serverAddr.Port != 443 { httpsOptions.ServerPort = serverAddr.Port }