Skip to content

Commit 0e15095

Browse files
Allow direct download templates from IPv6 host address. (apache#5900)
* Allow templates & ISOs from IPv6 host address. * fix checkstyle issue * Allow only direct download templates from IPv6 address Co-authored-by: gabriel <gabriel@apache.org>
1 parent 6fa8538 commit 0e15095

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public TemplateProfile prepare(GetUploadParamsForIsoCmd cmd) throws ResourceAllo
216216
public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException {
217217
TemplateProfile profile = super.prepare(cmd);
218218
String url = profile.getUrl();
219-
UriUtils.validateUrl(cmd.getFormat(), url);
219+
UriUtils.validateUrl(cmd.getFormat(), url, cmd.isDirectDownload());
220220
if (cmd.isDirectDownload()) {
221221
DigestHelper.validateChecksumString(cmd.getChecksum());
222222
Long templateSize = performDirectDownloadUrlValidation(cmd.getFormat(), url, cmd.getZoneIds());

utils/src/main/java/com/cloud/utils/UriUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ public static Pair<String, Integer> validateUrl(String url) throws IllegalArgume
263263
}
264264

265265
public static Pair<String, Integer> validateUrl(String format, String url) throws IllegalArgumentException {
266+
return validateUrl(format, url, false);
267+
}
268+
269+
public static Pair<String, Integer> validateUrl(String format, String url, boolean skipIpv6Check) throws IllegalArgumentException {
266270
try {
267271
URI uri = new URI(url);
268272
if ((uri.getScheme() == null) ||
@@ -283,7 +287,7 @@ public static Pair<String, Integer> validateUrl(String format, String url) throw
283287
if (hostAddr.isAnyLocalAddress() || hostAddr.isLinkLocalAddress() || hostAddr.isLoopbackAddress() || hostAddr.isMulticastAddress()) {
284288
throw new IllegalArgumentException("Illegal host specified in url");
285289
}
286-
if (hostAddr instanceof Inet6Address) {
290+
if (!skipIpv6Check && hostAddr instanceof Inet6Address) {
287291
throw new IllegalArgumentException("IPV6 addresses not supported (" + hostAddr.getHostAddress() + ")");
288292
}
289293
} catch (UnknownHostException uhe) {

0 commit comments

Comments
 (0)