Skip to content

[DO NOT MERGE] Network refactor#40628

Closed
kvega005 wants to merge 3 commits into
microsoft:masterfrom
kvega005:networkRefactor
Closed

[DO NOT MERGE] Network refactor#40628
kvega005 wants to merge 3 commits into
microsoft:masterfrom
kvega005:networkRefactor

Conversation

@kvega005

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copilot AI review requested due to automatic review settings May 22, 2026 18:23
@kvega005 kvega005 changed the title Network refactor [DO NOT MERGE] Network refactor May 22, 2026

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 refactors WSLC container networking from an enum-based model to a string-based NetworkMode model (e.g., "bridge", "host", "none", "container:<name>") and introduces a new WSLCNetworkConnection struct for representing additional network connections/endpoints.

Changes:

  • Replace WSLCContainerNetworkType usage with NetworkMode strings across container creation, launcher helpers, and tests.
  • Rework container creation networking logic to resolve network modes, validate endpoint combinations, and build endpoint configs/port mappings accordingly.
  • Update SDK and service call sites to pass the new network mode representation, plus update a user-facing localization string.

Reviewed changes

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

Show a summary per file
File Description
test/windows/WSLCTests.cpp Updates test coverage to use network mode strings and new network/error behavior.
src/windows/wslcsession/WSLCContainer.h Updates container implementation state to store network mode as a string.
src/windows/wslcsession/WSLCContainer.cpp Implements network-mode resolution, endpoint validation, and updated port-mapping behavior.
src/windows/WslcSDK/WslcsdkPrivate.h Changes SDK internal container settings representation for networking.
src/windows/WslcSDK/wslcsdk.cpp Updates SDK conversions/defaults and maps SDK settings into runtime WSLCContainerOptions.
src/windows/wslc/services/ContainerService.cpp Updates service container creation to pass "bridge" as the default network mode string.
src/windows/service/inc/wslc.idl Replaces the container network enum/attachment model with NetworkMode + WSLCNetworkConnection[].
src/windows/common/WSLCContainerLauncher.h Updates launcher API/storage to take and store network mode as a string.
src/windows/common/WSLCContainerLauncher.cpp Marshals network mode and additional network connections into WSLCContainerOptions.
localization/strings/en-US/Resources.resw Replaces an error string with a new “exclusive network must be alone” message.

Comment on lines 6043 to 6049
WSLCContainerOptions options{};
options.Image = "debian:latest";
options.Name = "test-custom-network-empty";
options.InitProcessOptions.CommandLine = {.Values = args, .Count = ARRAYSIZE(args)};
options.ContainerNetwork.ContainerNetworkType = WSLCContainerNetworkTypeCustom;
WSLCNetworkAttachment emptyNet{};
emptyNet.NetworkName = "";
options.ContainerNetwork.Networks = &emptyNet;
options.ContainerNetwork.Networks = &emptyName;
options.ContainerNetwork.NetworksCount = 1;

uint32_t namedVolumesCount;
const WslcContainerProcessOptionsInternal* initProcessOptions;
WSLCContainerNetworkType networking;
std::string networking;
Comment on lines 636 to 647
STDAPI WslcInitContainerSettings(_In_ PCSTR imageName, _Out_ WslcContainerSettings* containerSettings)
try
{
auto internalType = CheckAndGetInternalType(containerSettings);
RETURN_HR_IF_NULL(E_POINTER, imageName);

*internalType = {};

internalType->image = imageName;
// Default network configuration to WSLC SDK `0`, which is NONE.
internalType->networking = WSLCContainerNetworkTypeNone;
internalType->networking = "none";

Comment on lines +258 to 272
typedef struct _WSLCNetworkConnection
{
WSLCContainerNetworkTypeNone = 0,
WSLCContainerNetworkTypeHost = 1,
WSLCContainerNetworkTypeBridged = 2,
WSLCContainerNetworkTypeCustom = 3
} WSLCContainerNetworkType;
[string] LPCSTR NetworkName;

typedef struct _WSLCNetworkAttachment
{
[unique] LPCSTR NetworkName;
[unique] LPCSTR ContainerIpAddress; // Reserved for future --ip support; must be NULL today.
} WSLCNetworkAttachment;
[unique, size_is(SettingsCount)] const KeyValuePair* Settings;
ULONG SettingsCount;
} WSLCNetworkConnection;

typedef struct _WSLCContainerNetwork
{
WSLCContainerNetworkType ContainerNetworkType;
[unique, size_is(NetworksCount)] const WSLCNetworkAttachment* Networks;
[unique, string] LPCSTR NetworkMode;

[unique, size_is(NetworksCount)] const WSLCNetworkConnection* Networks;
ULONG NetworksCount;
} WSLCContainerNetwork;
@kvega005 kvega005 closed this May 27, 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