mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
general: fixed a bug which leads to panic when the specified interface not exists
This commit is contained in:
1 parent
72e57ab6e3
commit
7f85f664e3
11 files changed
+27
-39
No files matched your search
+3
-3
@@ -75,12 +75,12 @@ func ForwarderFromURL(s, intface string, dialTimeout, relayTimeout time.Duration
|
||||
}
|
||||
|
||||
// DirectForwarder returns a direct forwarder.
|
||||
func DirectForwarder(intface string, dialTimeout, relayTimeout time.Duration) *Forwarder {
|
||||
func DirectForwarder(intface string, dialTimeout, relayTimeout time.Duration) (*Forwarder, error) {
|
||||
d, err := proxy.NewDirect(intface, dialTimeout, relayTimeout)
|
||||
if err != nil {
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
return &Forwarder{Dialer: d, addr: d.Addr()}
|
||||
return &Forwarder{Dialer: d, addr: d.Addr()}, nil
|
||||
}
|
||||
|
||||
func (f *Forwarder) parseOption(option string) error {
|
||||
|
||||
+6
-2
@@ -48,8 +48,12 @@ func NewFwdrGroup(name string, s []string, c *Strategy) *FwdrGroup {
|
||||
|
||||
if len(fwdrs) == 0 {
|
||||
// direct forwarder
|
||||
fwdrs = append(fwdrs, DirectForwarder(c.IntFace,
|
||||
time.Duration(c.DialTimeout)*time.Second, time.Duration(c.RelayTimeout)*time.Second))
|
||||
direct, err := DirectForwarder(c.IntFace,
|
||||
time.Duration(c.DialTimeout)*time.Second, time.Duration(c.RelayTimeout)*time.Second)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fwdrs = append(fwdrs, direct)
|
||||
c.Strategy = "rr"
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -44,7 +44,8 @@ func NewProxy(mainForwarders []string, mainStrategy *Strategy, rules []*Config)
|
||||
if len(mainForwarders) > 0 {
|
||||
direct := NewFwdrGroup("", nil, mainStrategy)
|
||||
for _, f := range rd.main.fwdrs {
|
||||
host, _, _ := net.SplitHostPort(f.addr)
|
||||
addr := strings.Split(f.addr, ",")[0]
|
||||
host, _, _ := net.SplitHostPort(addr)
|
||||
if ip := net.ParseIP(host); ip == nil {
|
||||
rd.domainMap.Store(strings.ToLower(host), direct)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user