Skip to content

[Utils] Add NetworkAddress abstraction for IPv6-safe address handling#20306

Merged
hnyls2002 merged 13 commits intomainfrom
lsyin/support-ipv6
Mar 11, 2026
Merged

[Utils] Add NetworkAddress abstraction for IPv6-safe address handling#20306
hnyls2002 merged 13 commits intomainfrom
lsyin/support-ipv6

Conversation

@hnyls2002
Copy link
Copy Markdown
Collaborator

@hnyls2002 hnyls2002 commented Mar 10, 2026

Motivation

Preparing for IPv6 support (#19981). The codebase has scattered IPv6 handling — configure_ipv6(), maybe_wrap_ipv6_address(), format_tcp_address(), manual .split(":") parsing, and is_valid_ipv6_address() checks at every call site. This PR introduces a single NetworkAddress dataclass to centralize all host:port operations, then migrates existing callers as a first step.

Modifications

New srt/utils/network.py

  • NetworkAddress(host, port) frozen dataclass with .to_url(), .to_tcp(), .to_host_port_str(), .to_bind_tuple(), .parse(), .from_parts()
  • .is_ipv6 / .family properties for automatic address family detection
  • wrap_ipv6() helper (internal use by get_zmq_socket_on_host)

Migrate existing callers

  • server_args.py: url() uses NetworkAddress.to_url(); PortArgs.init_new() replaces configure_ipv6() / .split(":") with NetworkAddress.parse() + .to_tcp()
  • data_parallel_controller.py: 3-branch endpoint construction → NetworkAddress.parse() + port offset
  • disaggregation/{common,mooncake,mori}/conn.py: replace is_valid_ipv6_address() + format_tcp_address() combos with NetworkAddress
  • shm_broadcast.py: same pattern — NetworkAddress for family detection + .to_tcp()
  • mooncake_transfer_engine.py: maybe_wrap_ipv6_address()NetworkAddress.to_host_port_str()
  • utils.py: _prebind_listening_socket uses NetworkAddress.family / .to_bind_tuple()
  • get_zmq_socket_on_host(): auto-wraps IPv6 + sets zmq.IPV6 flag internally

Cleanup

  • Delete configure_ipv6(), maybe_wrap_ipv6_address(), format_tcp_address() (zero remaining callers)
  • Remove is_valid_ipv6_address imports from all migrated files

Tests

  • Add test/registered/utils/test_network_address.py with full coverage: IPv4, IPv6, hostname, parse/roundtrip, error cases, from_parts, immutability
  • Move IPv6-related tests from test_server_args.pytest_network_address.py, update error message assertions

Checklist

  • Fully backward compatible — no default value changes, no behavior changes for IPv4 users
  • Unit tests for NetworkAddress (registered stage-a-cpu-only)
  • IPv6 tests for PortArgs.init_new() and ServerArgs.url() updated and passing
  • Format code according to pre-commit

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@hnyls2002 hnyls2002 changed the title Add ipv6 utils and wrapper. [Utils] Add \NetworkAddress\ abstraction for IPv6-safe address handling Mar 11, 2026
@hnyls2002 hnyls2002 changed the title [Utils] Add \NetworkAddress\ abstraction for IPv6-safe address handling [Utils] Add NetworkAddress abstraction for IPv6-safe address handling Mar 11, 2026
@hnyls2002 hnyls2002 mentioned this pull request Mar 11, 2026
5 tasks
psaab added a commit to psaab/sglang that referenced this pull request Mar 11, 2026
From PR sgl-project#20306 by hnyls2002. Introduces a frozen NetworkAddress dataclass
in srt/utils/network.py to centralize all host:port operations (to_url,
to_tcp, to_host_port_str, to_bind_tuple, parse, from_parts). Migrates
server_args, data_parallel_controller, disaggregation connectors,
shm_broadcast, mooncake_transfer_engine, and utils.py. Removes redundant
configure_ipv6, maybe_wrap_ipv6_address, and format_tcp_address helpers.
Adds comprehensive tests in test_network_address.py.
@hnyls2002 hnyls2002 merged commit 61cad15 into main Mar 11, 2026
105 of 119 checks passed
@hnyls2002 hnyls2002 deleted the lsyin/support-ipv6 branch March 11, 2026 07:07
psaab added a commit to psaab/sglang that referenced this pull request Mar 11, 2026
From PR sgl-project#20306 by hnyls2002. Introduces a frozen NetworkAddress dataclass
in srt/utils/network.py to centralize all host:port operations (to_url,
to_tcp, to_host_port_str, to_bind_tuple, parse, from_parts). Migrates
server_args, data_parallel_controller, disaggregation connectors,
shm_broadcast, mooncake_transfer_engine, and utils.py. Removes redundant
configure_ipv6, maybe_wrap_ipv6_address, and format_tcp_address helpers.
Adds comprehensive tests in test_network_address.py.
psaab added a commit to psaab/sglang that referenced this pull request Mar 13, 2026
From PR sgl-project#20306 by hnyls2002. Introduces a frozen NetworkAddress dataclass
in srt/utils/network.py to centralize all host:port operations (to_url,
to_tcp, to_host_port_str, to_bind_tuple, parse, from_parts). Migrates
server_args, data_parallel_controller, disaggregation connectors,
shm_broadcast, mooncake_transfer_engine, and utils.py. Removes redundant
configure_ipv6, maybe_wrap_ipv6_address, and format_tcp_address helpers.
Adds comprehensive tests in test_network_address.py.
liubiyongge pushed a commit to liubiyongge/sglang that referenced this pull request Mar 13, 2026
Wangzheee pushed a commit to Wangzheee/sglang that referenced this pull request Mar 21, 2026
JustinTong0323 pushed a commit to JustinTong0323/sglang that referenced this pull request Apr 7, 2026
yhyang201 pushed a commit to yhyang201/sglang that referenced this pull request Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant