@@ -18,6 +18,7 @@ import (
18
18
"github.com/celzero/firestack/intra/ipn"
19
19
"github.com/celzero/firestack/intra/log"
20
20
"github.com/celzero/firestack/intra/protect"
21
+ "github.com/celzero/firestack/intra/xdns"
21
22
)
22
23
23
24
const (
@@ -43,8 +44,8 @@ type bootstrap struct {
43
44
proxies ipn.Proxies // never nil if underlying transport is set
44
45
bridge Bridge // never nil if underlying transport is set
45
46
typ string // DOH or DNS53
46
- ipports string // never empty
47
- url string // never empty
47
+ ipports string // never empty for DNS53
48
+ url string // never empty for DOH
48
49
hostname string // never empty
49
50
}
50
51
@@ -76,35 +77,40 @@ func newDefaultTransport(ipcsv string, p ipn.Proxies, g Bridge) (dnsx.Transport,
76
77
return nil , errCannotStart
77
78
}
78
79
79
- func (b * bootstrap ) reinit (trtype , u , ipcsv string ) error {
80
- if len (ipcsv ) <= 0 {
81
- log .E ("dns: default: reinit: empty url %s / ips %s" , u , ipcsv )
82
- return dnsx .ErrNotDefaultTransport
83
- }
84
- if trtype != dnsx .DOH && trtype != dnsx .DNS53 {
85
- log .E ("dns: default: reinit: unknown type %s" , trtype )
86
- return dnsx .ErrNotDefaultTransport
87
- }
88
- if len (u ) <= 0 {
89
- u = protect .UidSelf
90
- }
91
- b .url = u // may be localhost or protect.UidSelf; see: ipmap.LookupNetIP
92
- b .typ = trtype
93
- b .ipports = ipcsv
94
- ips := strings .Split (ipcsv , "," )
95
- if len (ips ) <= 0 {
96
- log .E ("dns: default: reinit: zero valid ipports in %s (url? %s)" , ipcsv , b .url )
80
+ func (b * bootstrap ) reinit (trtype , ippOrUrl , ipcsv string ) error {
81
+ if len (ippOrUrl ) <= 0 {
82
+ log .E ("dns: default: reinit: empty url %s! ips? %s" , ippOrUrl , ipcsv )
97
83
return dnsx .ErrNotDefaultTransport
98
84
}
99
85
100
- b .hostname = b .url // may be a special name like protect.UidSelf
101
- if parsed , err := url .Parse (b .url ); err == nil {
86
+ if parsed , err := url .Parse (ippOrUrl ); err == nil { // ippOrUrl is a url?
87
+ if trtype != dnsx .DOH {
88
+ log .E ("dns: default: reinit: url %s for %s" , ippOrUrl , trtype )
89
+ return dnsx .ErrNotDefaultTransport
90
+ }
91
+ b .url = ippOrUrl
102
92
b .hostname = parsed .Hostname ()
93
+ b .ipports = ipcsv // may be empty
94
+ b .typ = dnsx .DOH
95
+ } else { // ippOrUrl is an ipport?
96
+ if trtype != dnsx .DNS53 {
97
+ log .E ("dns: default: reinit: ipport %s for %s" , ippOrUrl , trtype )
98
+ return dnsx .ErrNotDefaultTransport
99
+ }
100
+ if ipport , err := xdns .DnsIPPort (ippOrUrl ); err == nil {
101
+ b .url = ""
102
+ b .hostname = protect .UidSelf
103
+ b .ipports = ipport .String ()
104
+ b .typ = dnsx .DNS53
105
+ } else {
106
+ return err
107
+ }
103
108
}
109
+
104
110
// hydrate ipmap with the new ips against incoming hostname
105
- ok := dialers .Renew (b .hostname , ips )
111
+ ok := dialers .Renew (b .hostname , strings . Split ( ipcsv , "," ) )
106
112
107
- log .I ("dns: default: %s reinit %s %s w/ %s; resolved? %t" , trtype , b .url , b .hostname , ips , ok )
113
+ log .I ("dns: default: %s reinit %s %s w/ %s; resolved? %t" , trtype , b .url , b .hostname , ipcsv , ok )
108
114
109
115
// if proxies and bridges are set, restart to create new transport
110
116
if b .proxies != nil && b .bridge != nil {
0 commit comments