Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions localization/strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2324,9 +2324,9 @@ For privacy information about this product please visit https://aka.ms/privacy.<
<value>Network '{}' already exists.</value>
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
</data>
<data name="MessageWslcAdditionalNetworksRequirePrimary" xml:space="preserve">
<value>Additional networks are not allowed when the primary network mode is 'host' or 'none'.</value>
<comment>{Locked="host"}{Locked="none"}Command line arguments, file names and string inserts should not be translated</comment>
<data name="MessageWslcExclusiveNetworkMustBeAlone" xml:space="preserve">
<value>Network mode 'host', 'none', and 'container:&lt;name&gt;' cannot be combined with any other network.</value>
<comment>{Locked="host"}{Locked="none"}{Locked="container:&lt;name&gt;"}Command line arguments, file names and string inserts should not be translated</comment>
</data>
<data name="MessageWslcDuplicateNetwork" xml:space="preserve">
<value>Duplicate network: '{}'</value>
Expand Down
2 changes: 1 addition & 1 deletion src/windows/WslcSDK/WslcsdkPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ typedef struct WslcContainerOptionsInternal
const WslcContainerNamedVolume* namedVolumes;
uint32_t namedVolumesCount;
const WslcContainerProcessOptionsInternal* initProcessOptions;
WSLCContainerNetworkType networking;
std::string networking;
WslcContainerFlags containerFlags;

} WslcContainerOptionsInternal;
Expand Down
11 changes: 6 additions & 5 deletions src/windows/WslcSDK/wslcsdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ WSLCSignal Convert(WslcSignal signal)
}
}

WSLCContainerNetworkType Convert(WslcContainerNetworkingMode mode)
std::string Convert(WslcContainerNetworkingMode mode)
{
switch (mode)
{
case WSLC_CONTAINER_NETWORKING_MODE_NONE:
return WSLCContainerNetworkTypeNone;
return "none";
case WSLC_CONTAINER_NETWORKING_MODE_BRIDGED:
return WSLCContainerNetworkTypeBridged;
return "bridge";
default:
THROW_HR_MSG(E_INVALIDARG, "Invalid WslcContainerNetworkingMode: %i", mode);
}
Expand Down Expand Up @@ -643,7 +643,7 @@ try

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

return S_OK;
}
Expand Down Expand Up @@ -772,7 +772,8 @@ try
containerOptions.PortsCount = static_cast<ULONG>(internalContainerSettings->portsCount);
}

containerOptions.ContainerNetwork.ContainerNetworkType = internalContainerSettings->networking;
// SDK only exposes the network mode (no additional endpoints today).
containerOptions.ContainerNetwork.NetworkMode = internalContainerSettings->networking.c_str();

// TODO: No user access
// containerOptions.Labels;
Expand Down
29 changes: 10 additions & 19 deletions src/windows/common/WSLCContainerLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ WSLCContainerLauncher::WSLCContainerLauncher(
const std::string& Name,
const std::vector<std::string>& Arguments,
const std::vector<std::string>& Environment,
WSLCContainerNetworkType containerNetworkType,
std::string networkMode,
WSLCProcessFlags Flags) :
WSLCProcessLauncher({}, Arguments, Environment, Flags), m_image(Image), m_name(Name), m_containerNetworkType(containerNetworkType)
WSLCProcessLauncher({}, Arguments, Environment, Flags), m_image(Image), m_name(Name), m_networkMode(std::move(networkMode))
{
}

Expand Down Expand Up @@ -144,11 +144,6 @@ void WSLCContainerLauncher::SetContainerFlags(WSLCContainerFlags Flags)
m_containerFlags = Flags;
}

void WSLCContainerLauncher::SetContainerNetworkName(std::string&& Name)
{
m_containerNetworkName = std::move(Name);
}

void WSLCContainerLauncher::SetHostname(std::string&& Hostname)
{
m_hostname = std::move(Hostname);
Expand Down Expand Up @@ -287,7 +282,6 @@ std::pair<HRESULT, std::optional<RunningWSLCContainer>> WSLCContainerLauncher::C

auto [processOptions, commandLinePtrs, environmentPtrs] = CreateProcessOptions();
options.InitProcessOptions = processOptions;
options.ContainerNetwork.ContainerNetworkType = m_containerNetworkType;
options.Ports = m_ports.data();
options.PortsCount = static_cast<ULONG>(m_ports.size());
options.StopSignal = m_stopSignal;
Expand Down Expand Up @@ -359,21 +353,18 @@ std::pair<HRESULT, std::optional<RunningWSLCContainer>> WSLCContainerLauncher::C
options.TmpfsCount = static_cast<ULONG>(m_tmpfsMounts.size());
options.Tmpfs = m_tmpfsMounts.size() > 0 ? m_tmpfsMounts.data() : nullptr;

std::vector<WSLCNetworkAttachment> networkAttachments;
if (m_containerNetworkType == WSLCContainerNetworkTypeCustom)
{
networkAttachments.push_back({m_containerNetworkName.c_str(), nullptr});
}
options.ContainerNetwork.NetworkMode = m_networkMode.c_str();

// Each additional network becomes an entry in NetworkingConfig.EndpointsConfig.
std::vector<WSLCNetworkConnection> connections;
connections.reserve(m_additionalNetworks.size());
for (const auto& e : m_additionalNetworks)
{
networkAttachments.push_back({e.c_str(), nullptr});
connections.push_back({.NetworkName = e.c_str()});
}

if (!networkAttachments.empty())
{
options.ContainerNetwork.Networks = networkAttachments.data();
options.ContainerNetwork.NetworksCount = static_cast<ULONG>(networkAttachments.size());
}
options.ContainerNetwork.Networks = connections.empty() ? nullptr : connections.data();
options.ContainerNetwork.NetworksCount = static_cast<ULONG>(connections.size());

options.MemoryBytes = m_memoryBytes;
options.NanoCpus = m_nanoCpus;
Expand Down
6 changes: 2 additions & 4 deletions src/windows/common/WSLCContainerLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class WSLCContainerLauncher : private WSLCProcessLauncher
const std::string& Name = "",
const std::vector<std::string>& Arguments = {},
const std::vector<std::string>& Environment = {},
WSLCContainerNetworkType containerNetworkType = WSLCContainerNetworkTypeHost,
std::string networkMode = "host",
WSLCProcessFlags Flags = WSLCProcessFlagsNone);

void AddVolume(const std::wstring& HostPath, const std::string& ContainerPath, bool ReadOnly);
Expand All @@ -75,7 +75,6 @@ class WSLCContainerLauncher : private WSLCProcessLauncher
void SetDefaultStopSignal(WSLCSignal Signal);
void SetShmSize(int64_t ShmSize);
void SetContainerFlags(WSLCContainerFlags Flags);
void SetContainerNetworkName(std::string&& Name);
void SetHostname(std::string&& Hostname);
void SetDomainname(std::string&& Domainame);
void SetDnsServers(std::vector<std::string>&& DnsServers);
Expand All @@ -98,8 +97,7 @@ class WSLCContainerLauncher : private WSLCProcessLauncher
std::deque<std::wstring> m_hostPaths;
std::deque<std::string> m_volumeNames;
std::deque<std::string> m_containerPaths;
WSLCContainerNetworkType m_containerNetworkType;
std::string m_containerNetworkName;
std::string m_networkMode;
std::vector<std::string> m_entrypoint;
WSLCSignal m_stopSignal = WSLCSignalNone;
int64_t m_shmSize = 0;
Expand Down
21 changes: 8 additions & 13 deletions src/windows/service/inc/wslc.idl
Original file line number Diff line number Diff line change
Expand Up @@ -255,24 +255,19 @@ typedef struct _WSLCUlimit
LONGLONG Hard;
} WSLCUlimit;

typedef enum _WSLCContainerNetworkType
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;
Comment on lines +258 to 272

Expand Down
2 changes: 1 addition & 1 deletion src/windows/wslc/services/ContainerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static wsl::windows::common::RunningWSLCContainer CreateInternal(Session& sessio
WI_SetFlagIf(containerFlags, WSLCContainerFlagsGpu, options.Gpu);

wsl::windows::common::WSLCContainerLauncher containerLauncher(
image, options.Name, options.Arguments, options.EnvironmentVariables, WSLCContainerNetworkTypeBridged, processFlags);
image, options.Name, options.Arguments, options.EnvironmentVariables, "bridge", processFlags);

// Set port options if provided
for (const auto& port : options.Ports)
Expand Down
Loading
Loading