Fix stack wireguard device returning non-nil interface containing nil pointer

This commit is contained in:
wwqgtxx 2023-03-13 13:24:42 +08:00 committed by 世界
parent 657b05fd96
commit b004b9ec81
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -109,9 +109,17 @@ func (w *StackDevice) DialContext(ctx context.Context, network string, destinati
} }
switch N.NetworkName(network) { switch N.NetworkName(network) {
case N.NetworkTCP: case N.NetworkTCP:
return gonet.DialTCPWithBind(ctx, w.stack, bind, addr, networkProtocol) tcpConn, err := gonet.DialTCPWithBind(ctx, w.stack, bind, addr, networkProtocol)
if err != nil {
return nil, err
}
return tcpConn, nil
case N.NetworkUDP: case N.NetworkUDP:
return gonet.DialUDP(w.stack, &bind, &addr, networkProtocol) udpConn, err := gonet.DialUDP(w.stack, &bind, &addr, networkProtocol)
if err != nil {
return nil, err
}
return udpConn, nil
default: default:
return nil, E.Extend(N.ErrUnknownNetwork, network) return nil, E.Extend(N.ErrUnknownNetwork, network)
} }
@ -129,7 +137,11 @@ func (w *StackDevice) ListenPacket(ctx context.Context, destination M.Socksaddr)
networkProtocol = header.IPv6ProtocolNumber networkProtocol = header.IPv6ProtocolNumber
bind.Addr = w.addr6 bind.Addr = w.addr6
} }
return gonet.DialUDP(w.stack, &bind, nil, networkProtocol) udpConn, err := gonet.DialUDP(w.stack, &bind, nil, networkProtocol)
if err != nil {
return nil, err
}
return udpConn, nil
} }
func (w *StackDevice) Start() error { func (w *StackDevice) Start() error {