Skip to content

Commit a4fd7f5

Browse files
Allow IPv6 Addresses
The REST and gRPC servers support IPv6. Unhobble the config test to allow them through.
1 parent 3cf3436 commit a4fd7f5

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

Dockerfile.redhat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ RUN bazel build --jobs=$JOBS ${debug_bazel_flags} ${minitrace_flags} //src:ovms
295295
COPY ci/check_coverage.bat /ovms/
296296
ARG CHECK_COVERAGE=0
297297
ARG RUN_TESTS=0
298-
COPY run_unit_tests.sh prepare_llm_models.sh prepare_gpu_models.sh /ovms/
299-
RUN if [ "$RUN_TESTS" == "1" ] ; then ./prepare_llm_models.sh /ovms/src/test/llm_testing docker && ./run_unit_tests.sh ; fi
298+
COPY run_unit_tests.sh prepare_llm_models.sh prepare_gpu_models.sh demos/common/export_models/export_model.py /ovms/
299+
RUN if [ "$RUN_TESTS" == "1" ] ; then mkdir -p demos/common/export_models/ && mv export_model.py demos/common/export_models/ && ./prepare_llm_models.sh /ovms/src/test/llm_testing docker && ./run_unit_tests.sh ; fi
300300

301301
ARG ovms_metadata_file
302302

Dockerfile.ubuntu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ WORKDIR /ovms
280280
# Test Coverage
281281
COPY ci/check_coverage.bat /ovms/
282282
ARG CHECK_COVERAGE=0
283-
COPY run_unit_tests.sh prepare_llm_models.sh install_va.sh /ovms/
283+
COPY run_unit_tests.sh prepare_llm_models.sh install_va.sh demos/common/export_models/export_model.py /ovms/
284284

285285
ARG FUZZER_BUILD=0
286286
# Custom Nodes
@@ -295,7 +295,7 @@ ARG OPTIMIZE_BUILDING_TESTS=0
295295
RUN if [ "$FUZZER_BUILD" == "0" ]; then bazel build --jobs=$JOBS ${debug_bazel_flags} ${minitrace_flags} //src:ovms $(if [ "${OPTIMIZE_BUILDING_TESTS}" == "1" ] ; then echo -n //src:ovms_test; fi); fi;
296296

297297
ARG RUN_TESTS=0
298-
RUN if [ "$RUN_TESTS" == "1" ] ; then ./prepare_llm_models.sh /ovms/src/test/llm_testing docker && ./run_unit_tests.sh ; fi
298+
RUN if [ "$RUN_TESTS" == "1" ] ; then mkdir -p demos/common/export_models/ && mv export_model.py demos/common/export_models/ && ./prepare_llm_models.sh /ovms/src/test/llm_testing docker && ./run_unit_tests.sh ; fi
299299

300300
RUN if [ "$FUZZER_BUILD" == "0" ]; then /ovms/bazel-bin/src/ovms --version && /ovms/bazel-bin/src/ovms; fi;
301301

src/config.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,18 @@ bool Config::check_hostname_or_ip(const std::string& input) {
7676
}
7777
bool all_numeric = true;
7878
for (char c : input) {
79-
if (c == '.') {
79+
if (c == '.' || c == ':') {
8080
continue;
8181
}
82-
if (!::isdigit(c)) {
82+
if (!::isxdigit(c)) {
8383
all_numeric = false;
8484
}
8585
}
8686
if (all_numeric) {
87-
std::regex valid_ip_regex("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$");
88-
return std::regex_match(input, valid_ip_regex);
87+
static const std::regex valid_ipv4_regex("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$");
88+
static const std::regex valid_ipv6_regex(R"(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))");
89+
return std::regex_match(input, valid_ipv4_regex) ||
90+
std::regex_match(input, valid_ipv6_regex);
8991
} else {
9092
std::regex valid_hostname_regex("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$");
9193
return std::regex_match(input, valid_hostname_regex);

src/test/ovmsconfig_test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,25 @@ TEST_F(OvmsParamsTest, hostname_ip_regex) {
335335
EXPECT_EQ(ovms::Config::check_hostname_or_ip("(%$#*F"), false);
336336
std::string too_long(256, 'a');
337337
EXPECT_EQ(ovms::Config::check_hostname_or_ip(too_long), false);
338+
// Uncompressed IPv6 address
339+
EXPECT_EQ(ovms::Config::check_hostname_or_ip(
340+
"fe80:0000:0000:0000:0202:b3ff:fe1e:8329", true);
341+
// Zero compressed IPv6 address
342+
EXPECT_EQ(ovms::Config::check_hostname_or_ip(
343+
"2001:db8:85a3::8a2e:370:7334", true);
344+
EXPECT_EQ(ovms::Config::check_hostname_or_ip("::1", true);
345+
EXPECT_EQ(ovms::Config::check_hostname_or_ip("::", true);
346+
// Link-local IPv6 with zone index (RFC 4007 § 11) - unsupported
347+
EXPECT_EQ(ovms::Config::check_hostname_or_ip("fe80::1234%eth0", false);
348+
EXPECT_EQ(ovms::Config::check_hostname_or_ip("fe80::1234%1", false);
349+
// IPv4-Embedded IPv6 addresses
350+
EXPECT_EQ(ovms::Config::check_hostname_or_ip("64:ff9b::192.0.2.33", true);
351+
EXPECT_EQ(ovms::Config::check_hostname_or_ip(
352+
"2001:db8:122:344::192.0.2.33", true);
353+
// IPv4-mapped IPv6 addresses
354+
EXPECT_EQ(ovms::Config::check_hostname_or_ip("::ffff:192.0.2.128", true);
355+
// IPv4-translated IPv6 addresses
356+
EXPECT_EQ(ovms::Config::check_hostname_or_ip("::ffff:0:192.0.2.128", true);
338357
}
339358

340359
TEST(OvmsConfigTest, positiveMulti) {

0 commit comments

Comments
 (0)