summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerkin <e.altunbas@vyos.io>2021-05-31 13:15:36 +0300
committererkin <e.altunbas@vyos.io>2021-06-06 17:14:50 +0300
commitdf8043dcbee22ec8d9d45b24d9e1fc07daeabf64 (patch)
tree5093802666d9177b90111304bfc8be14721f5e02
parent0856dd2f2584d2c41b8ddf70a5a2751ee446be5a (diff)
downloadvyos-1x-df8043dcbee22ec8d9d45b24d9e1fc07daeabf64.tar.gz
vyos-1x-df8043dcbee22ec8d9d45b24d9e1fc07daeabf64.zip
T3563: Add support for IPv6 source addresses in SSH connections
-rw-r--r--python/vyos/remote.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/python/vyos/remote.py b/python/vyos/remote.py
index 0bc2ee7f8..f1768aa4f 100644
--- a/python/vyos/remote.py
+++ b/python/vyos/remote.py
@@ -14,6 +14,7 @@
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
from ftplib import FTP
+import ipaddress
import math
import os
import shutil
@@ -28,7 +29,6 @@ from vyos.version import get_version
from paramiko import SSHClient, SSHException, MissingHostKeyPolicy
-
# This is a hardcoded path and no environment variable can change it.
KNOWN_HOSTS_FILE = os.path.expanduser('~/.ssh/known_hosts')
CHUNK_SIZE = 8192
@@ -42,7 +42,8 @@ class InteractivePolicy(MissingHostKeyPolicy):
print_error(f"Host '{hostname}' not found in known hosts.")
print_error('Fingerprint: ' + key.get_fingerprint().hex())
if ask_yes_no('Do you wish to continue?'):
- if client._host_keys_filename and ask_yes_no('Do you wish to permanently add this host/key pair to known hosts?'):
+ if client._host_keys_filename\
+ and ask_yes_no('Do you wish to permanently add this host/key pair to known hosts?'):
client._host_keys.add(hostname, key.get_name(), key)
client.save_host_keys(client._host_keys_filename)
else:
@@ -180,7 +181,14 @@ def transfer_sftp(mode, local_path, hostname, remote_path,\
source=None, progressbar=False):
sock = None
if source:
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ # Check if the given string is an IPv6 address.
+ try:
+ ipaddress.IPv6Address(source)
+ except ipaddress.AddressValueError:
+ address_family = socket.AF_INET
+ else:
+ address_family = socket.AF_INET6
+ sock = socket.socket(address_family, socket.SOCK_STREAM)
sock.bind((source, 0))
sock.connect((hostname, port))
callback = make_progressbar() if progressbar else None
@@ -284,7 +292,7 @@ def get_http_file_size(urlstring, username=None, password=None):
raise ValueError('Failed to receive file size from HTTP server.')
-# Dynamic dispatchers
+## Dynamic dispatchers
def download(local_path, urlstring, source=None, progressbar=False):
"""
Dispatch the appropriate download function for the given `urlstring` and save to `local_path`.
@@ -365,7 +373,6 @@ def get_remote_config(urlstring, source=None):
<interface>
<IP address>
"""
- url = urllib.parse.urlparse(urlstring)
temp = tempfile.NamedTemporaryFile(delete=False).name
try:
download(temp, urlstring, source)