Bug#815166: preseed/url: correctly handle IPv6 addresses
Package: preseed
Version: 1.70
Severity: normal
Tags: d-i patch
Dear maintainer,
trying to fetch a preseed URL using an IPv6 address fails. For example,
consider the preseed/url setting:
http://[fd00:9:152:48:1822:ffff:162:199]/dir/preseed.cfg
which becomes
http://[fd00.example.org:9:152:48:1822:ffff:162:199]/dir/preseed.cfg
The problem is that "fd00" is treated as hostname without domain and, thus,
the domain name is appended resulting in "fd00.example.org". Of course,
this is no longer a valid IPv6 address.
To solve this problem, I added a patch that enhances the auto-install.sh
to detect IPv6 addresses. I also added few more unit test cases to cover
different URLs with IPv6 addresses with user, password, and port variations:
[...]
ok 11 - ftp with user/password, IPv4, and domain
ok 12 - ftp with user/password, IPv4, and domain and port
ok 13 - http with short IPv6 and domain
ok 14 - http with simple IPv6 and domain
ok 15 - http with IPv6 and domain
ok 16 - http with IPv6, port, and domain
ok 17 - http with user/password, IPv6 and domain
ok 18 - http with user/password, IPv6, port, and domain
Thanks and kind regards,
Hendrik
>From dbc8bc790c781530954d2b58b0050472bbaef354 Mon Sep 17 00:00:00 2001
From: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Date: Fri, 19 Feb 2016 11:23:50 +0100
Subject: [PATCH] auto-install: correctly handle IPv6 addresses
The auto-install does not properly detect IPv6 address when they
are specified in an URL. Typically, the first IPv6 address part
is to be considered as the hostname and, if specified, a domain
name is appended. For example,
http://[fd00:9:152:48:1822:ffff:162:199]/dir/preseed.cfg
becomes
http://[fd00.example.org:9:152:48:1822:ffff:162:199]/dir/preseed.cfg
which is no longer a valid IPv6 address. To solve this problem,
enhance auto-install.sh and test for IPv6 addresses in URLs.
Also added few IPv6 unit test cases.
Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
---
auto-install.sh | 5 +++-
t/01-auto-install.t | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 1 deletions(-)
diff --git a/auto-install.sh b/auto-install.sh
index a1551a1..e38ecf5 100755
--- a/auto-install.sh
+++ b/auto-install.sh
@@ -34,7 +34,10 @@ else
db_get auto-install/defaultroot && dir="$RET"
fi
-if expr $host_port : [^.]*$ >/dev/null; then
+if expr "$host_port" : '^.*\[[:a-fA-F0-9]*\]' > /dev/null; then
+ # IPv6 address with or without port
+ :
+elif expr $host_port : [^.]*$ >/dev/null; then
db_get netcfg/get_domain && domain="$RET"
if [ -n "$domain" ] && [ "$domain" != "unassigned-domain" ] && [ "$domain" != "unnassigned-domain" ]; then
diff --git a/t/01-auto-install.t b/t/01-auto-install.t
index 10e6945..4822536 100755
--- a/t/01-auto-install.t
+++ b/t/01-auto-install.t
@@ -122,6 +122,61 @@ is(run_test('preseed/url'=>'ftp://foo/preseed.cfg',
'ftp:// is kept'
);
+is(run_test('preseed/url'=>'ftp://user:pass@10.11.12.13/foo/preseed.cfg',
+ 'netcfg/get_domain' => 'example.org',
+ ),
+ 'preseed/url=ftp://user:pass@10.11.12.13/foo/preseed.cfg',
+ 'ftp with user/password, IPv4, and domain'
+ );
+
+is(run_test('preseed/url'=>'ftp://user:pass@10.11.12.13:8080/foo/preseed.cfg',
+ 'netcfg/get_domain' => 'example.org',
+ ),
+ 'preseed/url=ftp://user:pass@10.11.12.13:8080/foo/preseed.cfg',
+ 'ftp with user/password, IPv4, and domain and port'
+ );
+
+is(run_test('preseed/url'=>'http://[fe80::5054:ff:fe23:8018]/foo/preseed.cfg',
+ 'netcfg/get_domain' => 'example.org',
+ ),
+ 'preseed/url=http://[fe80::5054:ff:fe23:8018]/foo/preseed.cfg',
+ 'http with short IPv6 and domain'
+ );
+
+is(run_test('preseed/url'=>'http://[::1]/foo/preseed.cfg',
+ 'netcfg/get_domain' => 'example.org',
+ ),
+ 'preseed/url=http://[::1]/foo/preseed.cfg',
+ 'http with simple IPv6 and domain'
+ );
+is(run_test('preseed/url'=>'http://[fd00:9:152:48:1822:ffff:162:199]/foo/preseed.cfg',
+ 'netcfg/get_domain' => 'example.org',
+ ),
+ 'preseed/url=http://[fd00:9:152:48:1822:ffff:162:199]/foo/preseed.cfg',
+ 'http with IPv6 and domain'
+ );
+
+is(run_test('preseed/url'=>'http://[fd00:9:152:48:1822:ffff:162:199]:8080/foo/preseed.cfg',
+ 'netcfg/get_domain' => 'example.org',
+ ),
+ 'preseed/url=http://[fd00:9:152:48:1822:ffff:162:199]:8080/foo/preseed.cfg',
+ 'http with IPv6, port, and domain'
+ );
+
+is(run_test('preseed/url'=>'http://user:pass@[fd00:9:152:48:1822:ffff:162:199]/foo/preseed.cfg',
+ 'netcfg/get_domain' => 'example.org',
+ ),
+ 'preseed/url=http://user:pass@[fd00:9:152:48:1822:ffff:162:199]/foo/preseed.cfg',
+ 'http with user/password, IPv6 and domain'
+ );
+
+is(run_test('preseed/url'=>'http://user:pass@[fd00:9:152:48:1822:ffff:162:199]:8080/foo/preseed.cfg',
+ 'netcfg/get_domain' => 'example.org',
+ ),
+ 'preseed/url=http://user:pass@[fd00:9:152:48:1822:ffff:162:199]:8080/foo/preseed.cfg',
+ 'http with user/password, IPv6, port, and domain'
+ );
+
# XXX: Write some tests for auto-install/defaultroot
# Clean-up:
--
1.7.1
Reply to: