Skip to content

Add IPv6 support to URN system endpoint parsing - #115

Merged
makr-code merged 4 commits into
mainfrom
copilot/check-ipv6-compatibility
Dec 20, 2025
Merged

makr-code merged 4 commits into
mainfrom
copilot/check-ipv6-compatibility

Conversation

Copilot AI commented Dec 19, 2025 •

Copy link
Copy Markdown
Contributor

The URN system's endpoint parser used find_last_of(':') to split host and port, breaking on IPv6 addresses with multiple colons (e.g., 2001:db8::1:8080 incorrectly parsed port as 8080 from within the address).

Changes

Core Implementation

  • MTLSClient::parseEndpoint(): RFC 3986 compliant parsing with bracket detection for IPv6
    • Detects [host]:port format and extracts correctly
    • Falls back to multiple-colon detection for bare IPv6 addresses
    • Preserves existing IPv4/hostname behavior
  • mtls_client.h: Made parseEndpoint() public with documented API

Testing

  • 20+ test cases covering IPv6 with/without brackets, with/without ports, protocol prefixes, edge cases
  • Verified backward compatibility with existing IPv4 and hostname tests

Documentation

  • docs/sharding/ipv6_support.md: Deployment guide with configuration examples
  • Updated sharding README to reflect IPv6 capability

Supported Formats

// IPv6
"[2001:db8::1]:8080"           → ("2001:db8::1", "8080")
"[::1]"                         → ("::1", "8080")
"2001:db8::1"                   → ("2001:db8::1", "8080")
"https://[2001:db8::1]:9090"   → ("2001:db8::1", "9090")

// IPv4/Hostname (unchanged)
"192.168.1.1:8080"             → ("192.168.1.1", "8080")
"shard-001.dc1.example.com"    → ("shard-001.dc1.example.com", "8080")

No breaking changes. Default port remains 8080 when unspecified.

Original prompt

ist unser URN System mit IPV6 kompatibel?


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Assess URN system compatibility with IPv6 Add IPv6 support to URN system endpoint parsing Dec 19, 2025
Copilot AI requested a review from makr-code December 19, 2025 07:49
@makr-code

Copy link
Copy Markdown
Owner

@copilot weiter

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive IPv6 support to ThemisDB's URN system endpoint parsing, enabling deployment in modern IPv6-only and dual-stack networks. The implementation is RFC 3986 compliant and maintains full backward compatibility with existing IPv4 and hostname-based endpoints.

Key Changes:

  • Enhanced MTLSClient::parseEndpoint() to detect and correctly parse IPv6 addresses with bracket notation
  • Added multi-colon detection for bare IPv6 addresses without ports
  • Made parseEndpoint() public API with comprehensive documentation

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/sharding/mtls_client.cpp Core IPv6 parsing logic with bracket detection and multi-colon handling
include/sharding/mtls_client.h Public API exposure with documented examples for IPv6, IPv4, and hostname formats
tests/test_mtls_client.cpp 20+ comprehensive test cases covering IPv6 with/without brackets, edge cases, and backward compatibility
docs/sharding/ipv6_support.md Complete deployment guide with configuration examples, best practices, and troubleshooting
docs/sharding/README.md Updated version to 1.2.0 and added IPv6 support highlights with quick reference
docs/sharding/IPv6_IMPLEMENTATION_SUMMARY.md Implementation summary documenting the problem, solution, and testing results

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

} else {
// Single colon - IPv4/hostname with port
host = url.substr(0, colon_pos);
port = url.substr(colon_pos + 1);

Copilot AI Dec 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function doesn't validate the extracted port string. Malformed input like "192.168.1.1:abc" or "example.com:99999" would be accepted without validation. Consider adding validation to ensure the port is a valid integer in the range 1-65535.

Copilot uses AI. Check for mistakes.
Comment on lines +96 to +216
// ===========================================================================
// IPv6 Endpoint Parsing Tests
// ===========================================================================

TEST(MTLSClientTest, ParseEndpoint_IPv4_WithPort) {
auto [host, port] = MTLSClient::parseEndpoint("192.168.1.1:8080");
EXPECT_EQ(host, "192.168.1.1");
EXPECT_EQ(port, "8080");
}

TEST(MTLSClientTest, ParseEndpoint_IPv4_WithoutPort) {
auto [host, port] = MTLSClient::parseEndpoint("192.168.1.1");
EXPECT_EQ(host, "192.168.1.1");
EXPECT_EQ(port, "8080"); // Default port
}

TEST(MTLSClientTest, ParseEndpoint_IPv4_WithProtocol) {
auto [host, port] = MTLSClient::parseEndpoint("https://192.168.1.1:9090");
EXPECT_EQ(host, "192.168.1.1");
EXPECT_EQ(port, "9090");
}

TEST(MTLSClientTest, ParseEndpoint_IPv6_WithBracketsAndPort) {
auto [host, port] = MTLSClient::parseEndpoint("[2001:db8::1]:8080");
EXPECT_EQ(host, "2001:db8::1");
EXPECT_EQ(port, "8080");
}

TEST(MTLSClientTest, ParseEndpoint_IPv6_WithBracketsWithoutPort) {
auto [host, port] = MTLSClient::parseEndpoint("[2001:db8::1]");
EXPECT_EQ(host, "2001:db8::1");
EXPECT_EQ(port, "8080"); // Default port
}

TEST(MTLSClientTest, ParseEndpoint_IPv6_WithoutBracketsWithoutPort) {
// IPv6 without brackets and without port (multiple colons)
auto [host, port] = MTLSClient::parseEndpoint("2001:db8::1");
EXPECT_EQ(host, "2001:db8::1");
EXPECT_EQ(port, "8080"); // Default port
}

TEST(MTLSClientTest, ParseEndpoint_IPv6_WithProtocolAndPort) {
auto [host, port] = MTLSClient::parseEndpoint("https://[2001:db8::1]:9090");
EXPECT_EQ(host, "2001:db8::1");
EXPECT_EQ(port, "9090");
}

TEST(MTLSClientTest, ParseEndpoint_IPv6_Localhost) {
auto [host, port] = MTLSClient::parseEndpoint("[::1]:8080");
EXPECT_EQ(host, "::1");
EXPECT_EQ(port, "8080");
}

TEST(MTLSClientTest, ParseEndpoint_IPv6_LocalhostWithoutPort) {
auto [host, port] = MTLSClient::parseEndpoint("::1");
EXPECT_EQ(host, "::1");
EXPECT_EQ(port, "8080"); // Default port
}

TEST(MTLSClientTest, ParseEndpoint_IPv6_FullAddress) {
auto [host, port] = MTLSClient::parseEndpoint("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:443");
EXPECT_EQ(host, "2001:0db8:85a3:0000:0000:8a2e:0370:7334");
EXPECT_EQ(port, "443");
}

TEST(MTLSClientTest, ParseEndpoint_IPv6_CompressedZeros) {
auto [host, port] = MTLSClient::parseEndpoint("[fe80::1]:8080");
EXPECT_EQ(host, "fe80::1");
EXPECT_EQ(port, "8080");
}

TEST(MTLSClientTest, ParseEndpoint_Hostname_WithPort) {
auto [host, port] = MTLSClient::parseEndpoint("shard-001.dc1.example.com:8080");
EXPECT_EQ(host, "shard-001.dc1.example.com");
EXPECT_EQ(port, "8080");
}

TEST(MTLSClientTest, ParseEndpoint_Hostname_WithoutPort) {
auto [host, port] = MTLSClient::parseEndpoint("shard-001.dc1.example.com");
EXPECT_EQ(host, "shard-001.dc1.example.com");
EXPECT_EQ(port, "8080"); // Default port
}

TEST(MTLSClientTest, ParseEndpoint_Hostname_WithProtocol) {
auto [host, port] = MTLSClient::parseEndpoint("https://shard-001.dc1.example.com:9090");
EXPECT_EQ(host, "shard-001.dc1.example.com");
EXPECT_EQ(port, "9090");
}

TEST(MTLSClientTest, ParseEndpoint_Localhost_WithPort) {
auto [host, port] = MTLSClient::parseEndpoint("localhost:8765");
EXPECT_EQ(host, "localhost");
EXPECT_EQ(port, "8765");
}

TEST(MTLSClientTest, ParseEndpoint_Localhost_WithoutPort) {
auto [host, port] = MTLSClient::parseEndpoint("localhost");
EXPECT_EQ(host, "localhost");
EXPECT_EQ(port, "8080"); // Default port
}

TEST(MTLSClientTest, ParseEndpoint_IPv6_MalformedBrackets) {
// Malformed: missing closing bracket
auto [host, port] = MTLSClient::parseEndpoint("[2001:db8::1");
// Should treat entire string as host
EXPECT_EQ(host, "[2001:db8::1");
EXPECT_EQ(port, "8080"); // Default port
}

TEST(MTLSClientTest, ParseEndpoint_IPv6_LinkLocal) {
auto [host, port] = MTLSClient::parseEndpoint("[fe80::a00:27ff:fe4e:66a1]:8080");
EXPECT_EQ(host, "fe80::a00:27ff:fe4e:66a1");
EXPECT_EQ(port, "8080");
}

TEST(MTLSClientTest, ParseEndpoint_IPv6_AllZeros) {
auto [host, port] = MTLSClient::parseEndpoint("[::]:8080");
EXPECT_EQ(host, "::");
EXPECT_EQ(port, "8080");
}

Copilot AI Dec 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage for edge cases including: empty port strings (e.g., "[::1]:", "192.168.1.1:"), invalid port values (e.g., "[::1]:abc", "host:99999"), and excessively long port numbers. These edge cases should be tested to ensure the parser handles malformed input gracefully.

Copilot uses AI. Check for mistakes.
size_t bracket_close = url.find(']');
if (bracket_close != std::string::npos) {
// Extract host (without brackets)
host = url.substr(1, bracket_close - 1);

Copilot AI Dec 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function doesn't validate that the extracted IPv6 host address is well-formed. Malformed addresses like "[not:valid:ipv6::::]" or "[::]:" would be accepted. Consider adding basic IPv6 address validation to catch obvious malformations early.

Copilot uses AI. Check for mistakes.
Comment on lines +291 to +292
port = url.substr(bracket_close + 2);
}

Copilot AI Dec 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function doesn't validate the extracted port string. Malformed input like "[::1]:abc" or "[::1]:99999" would be accepted without validation. Consider adding validation to ensure the port is a valid integer in the range 1-65535.

Copilot uses AI. Check for mistakes.
Comment on lines +290 to +292
if (bracket_close + 1 < url.size() && url[bracket_close + 1] == ':') {
port = url.substr(bracket_close + 2);
}

Copilot AI Dec 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function doesn't handle the case where the port string after the closing bracket is empty (e.g., "[::1]:"). This would result in an empty port string being returned instead of the default port "8080". Consider checking if the extracted port is empty and falling back to the default.

Copilot uses AI. Check for mistakes.
Comment on lines +309 to +310
host = url.substr(0, colon_pos);
port = url.substr(colon_pos + 1);

Copilot AI Dec 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function doesn't handle the case where the port string after the colon is empty (e.g., "192.168.1.1:" or "example.com:"). This would result in an empty port string being returned instead of the default port "8080". Consider checking if the extracted port is empty and falling back to the default.

Copilot uses AI. Check for mistakes.
@makr-code
makr-code marked this pull request as ready for review December 20, 2025 07:08
@makr-code
makr-code merged commit a88656a into main Dec 20, 2025
@makr-code makr-code added this to the v1.0.2 milestone Mar 11, 2026
@makr-code makr-code mentioned this pull request Mar 12, 2026
4 tasks
Copilot AI added a commit that referenced this pull request May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants