Skip to content

Commit

Permalink
bootstrap: overwrite existing transport on reinit
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Nov 24, 2023
1 parent 4d5696a commit 4068d9b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions intra/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ func (b *bootstrap) reinit(trtype, ippOrUrl, ipcsv string) error {
return dnsx.ErrNotDefaultTransport
}

// note: plain ip4 address is a valid url; ex: 1.2.3.4
if parsed, err := url.Parse(ippOrUrl); err == nil { // ippOrUrl is a url?
if trtype != dnsx.DOH {
log.E("dns: default: reinit: url %s for %s", ippOrUrl, trtype)
log.E("dns: default: reinit: url %s; %s != %s", ippOrUrl, trtype, dnsx.DOH)
return dnsx.ErrNotDefaultTransport
}
b.url = ippOrUrl
Expand All @@ -94,7 +95,7 @@ func (b *bootstrap) reinit(trtype, ippOrUrl, ipcsv string) error {
b.typ = dnsx.DOH
} else { // ippOrUrl is an ipport?
if trtype != dnsx.DNS53 {
log.E("dns: default: reinit: ipport %s for %s", ippOrUrl, trtype)
log.E("dns: default: reinit: ipport %s; %s != %s", ippOrUrl, trtype, dnsx.DNS53)
return dnsx.ErrNotDefaultTransport
}
ips := strings.Split(ippOrUrl, ",")
Expand Down Expand Up @@ -130,9 +131,6 @@ func (t *bootstrap) recreate() error {
}

func (t *bootstrap) kickstart(px ipn.Proxies, g Bridge) error {
if t.Transport != nil {
return errAlreadyStarted
}
if px == nil || g == nil {
return errCannotStart
}
Expand All @@ -150,7 +148,12 @@ func (t *bootstrap) kickstart(px ipn.Proxies, g Bridge) error {
err = errDefaultTransportType
}

t.Transport = tr // override previous transport; may be nil
if t.Transport != nil {
log.I("dns: default: removing %s %s[%s]", t.typ, t.GetAddr())
}

// always override previous transport with (new) tr; even if nil
t.Transport = tr
if err != nil {
log.E("dns: default: start; err %v", err)
return err
Expand Down

0 comments on commit 4068d9b

Please sign in to comment.