Skip to content
Open
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
4 changes: 4 additions & 0 deletions localization/strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3344,6 +3344,10 @@ On first run, creates the file with all settings commented out at their defaults
<data name="WSLCCLI_NetworkInternalArgDescription" xml:space="preserve">
<value>Restrict external access to the network</value>
</data>
<data name="WSLCCLI_NetworkIpv6ArgDescription" xml:space="preserve">
<value>Enable IPv6 networking</value>
<comment>{Locked="IPv6"}Command line arguments, file names and string inserts should not be translated</comment>
</data>
<data name="WSLCCLI_NetworkSubnetArgDescription" xml:space="preserve">
<value>Subnet in CIDR format that represents a network segment</value>
<comment>{Locked="CIDR"}Command line arguments, file names and string inserts should not be translated</comment>
Expand Down
6 changes: 4 additions & 2 deletions src/windows/inc/docker_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ struct CreateNetwork
std::string Name;
std::string Driver;
bool Internal{};
bool EnableIPv6{};
std::optional<IPAM> IPAM;
std::optional<std::map<std::string, std::string>> Options;
std::map<std::string, std::string> Labels;

NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(CreateNetwork, Name, Driver, Internal, IPAM, Options, Labels);
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(CreateNetwork, Name, Driver, Internal, EnableIPv6, IPAM, Options, Labels);
};

struct Network
Expand All @@ -160,11 +161,12 @@ struct Network
std::string Driver;
std::string Scope;
bool Internal{};
bool EnableIPv6{};
IPAM IPAM;
std::optional<std::map<std::string, std::string>> Options;
std::map<std::string, std::string> Labels;

NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Network, Id, Name, Driver, Scope, Internal, IPAM, Options, Labels);
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Network, Id, Name, Driver, Scope, Internal, EnableIPv6, IPAM, Options, Labels);
};

struct EndpointIPAMConfig
Expand Down
3 changes: 2 additions & 1 deletion src/windows/inc/wslc_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,12 @@ struct Network
std::string Driver;
std::string Scope;
bool Internal{};
bool EnableIPv6{};
IPAM IPAM;
std::optional<std::map<std::string, std::string>> Options;
std::map<std::string, std::string> Labels;

NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Network, Id, Name, Driver, Scope, Internal, IPAM, Options, Labels);
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Network, Id, Name, Driver, Scope, Internal, EnableIPv6, IPAM, Options, Labels);
};

} // namespace wsl::windows::common::wslc_schema
1 change: 1 addition & 0 deletions src/windows/service/inc/wslc.idl
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ typedef struct _WSLCNetworkOptions
[unique] LPCSTR Subnet;
[unique] LPCSTR Gateway;
[unique] LPCSTR IpRange;
BOOL EnableIPv6;
} WSLCNetworkOptions;

typedef char WSLCNetworkName[WSLC_MAX_NETWORK_NAME_LENGTH + 1];
Expand Down
1 change: 1 addition & 0 deletions src/windows/wslc/arguments/ArgumentDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ _(Input, "input", L"i", Kind::Value,
_(InspectFormat, "format", NO_ALIAS, Kind::Value, JsonIndent, Localization::WSLCCLI_InspectFormatArgDescription()) \
_(Interactive, "interactive", L"i", Kind::Flag, NoConversion, Localization::WSLCCLI_InteractiveArgDescription()) \
_(Internal, "internal", NO_ALIAS, Kind::Flag, NoConversion, Localization::WSLCCLI_NetworkInternalArgDescription()) \
_(Ipv6, "ipv6", NO_ALIAS, Kind::Flag, NoConversion, Localization::WSLCCLI_NetworkIpv6ArgDescription()) \
_(IpAddress, "ip", NO_ALIAS, Kind::Value, NoConversion, Localization::WSLCCLI_IpAddressArgDescription()) \
_(IpRange, "ip-range", NO_ALIAS, Kind::Value, NoConversion, Localization::WSLCCLI_NetworkIpRangeArgDescription()) \
_(Label, "label", L"l", Kind::Value, KeyValuePair, Localization::WSLCCLI_LabelArgDescription()) \
Expand Down
1 change: 1 addition & 0 deletions src/windows/wslc/commands/NetworkCreateCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ std::vector<Argument> NetworkCreateCommand::GetArguments() const
Argument::Create(ArgType::Label, false, Limit::Unlimited, Localization::WSLCCLI_NetworkLabelArgDescription()),
Argument::Create(ArgType::Gateway),
Argument::Create(ArgType::Internal),
Argument::Create(ArgType::Ipv6),
Argument::Create(ArgType::IpRange),
Argument::Create(ArgType::Subnet),
};
Expand Down
1 change: 1 addition & 0 deletions src/windows/wslc/services/NetworkModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct CreateNetworkOptions
std::vector<std::pair<std::string, std::string>> DriverOpts{};
std::vector<std::pair<std::string, std::string>> Labels{};
bool Internal{false};
bool EnableIPv6{false};
std::optional<std::string> Subnet;
std::optional<std::string> Gateway;
std::optional<std::string> IpRange;
Expand Down
1 change: 1 addition & 0 deletions src/windows/wslc/services/NetworkService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void NetworkService::Create(Terminal& terminal, models::Session& session, const
options.LabelsCount = static_cast<ULONG>(labels.size());

options.Internal = createOptions.Internal ? TRUE : FALSE;
options.EnableIPv6 = createOptions.EnableIPv6 ? TRUE : FALSE;
if (createOptions.Subnet.has_value())
{
options.Subnet = createOptions.Subnet->c_str();
Expand Down
1 change: 1 addition & 0 deletions src/windows/wslc/tasks/NetworkTasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void CreateNetwork(CLIExecutionContext& context)
}

options.Internal = context.Args.GetValue<ArgType::Internal>();
options.EnableIPv6 = context.Args.GetValue<ArgType::Ipv6>();

if (context.Args.Contains(ArgType::Subnet))
{
Expand Down
1 change: 1 addition & 0 deletions src/windows/wslcsession/WSLCNetworkMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct NetworkEntry
std::string Driver;
std::string Scope;
bool Internal{false};
bool EnableIPv6{false};
std::map<std::string, std::string> Labels;
std::map<std::string, std::string> Options;
NetworkIPAM IPAM;
Expand Down
4 changes: 4 additions & 0 deletions src/windows/wslcsession/WSLCSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2846,6 +2846,7 @@ try
request.Labels[WSLCNetworkManagedLabel] = "true";

request.Internal = static_cast<bool>(Options->Internal);
request.EnableIPv6 = static_cast<bool>(Options->EnableIPv6);

THROW_HR_WITH_USER_ERROR_IF(
E_INVALIDARG, Localization::MessageWslcGatewayRequiresSubnet(), Options->Gateway != nullptr && Options->Subnet == nullptr);
Expand Down Expand Up @@ -2915,6 +2916,7 @@ try
entry.Driver = full.Driver;
entry.Scope = full.Scope;
entry.Internal = full.Internal;
entry.EnableIPv6 = full.EnableIPv6;
entry.Labels = full.Labels;
if (full.Options)
{
Expand Down Expand Up @@ -3043,6 +3045,7 @@ try
result.Driver = entry.Driver;
result.Scope = entry.Scope;
result.Internal = entry.Internal;
result.EnableIPv6 = entry.EnableIPv6;
result.Labels = entry.Labels;
if (!entry.Options.empty())
{
Expand Down Expand Up @@ -3838,6 +3841,7 @@ void WSLCSession::RecoverExistingNetworks()
entry.Driver = network.Driver;
entry.Scope = network.Scope;
entry.Internal = network.Internal;
entry.EnableIPv6 = network.EnableIPv6;
entry.Labels = network.Labels;
if (network.Options)
{
Expand Down
18 changes: 18 additions & 0 deletions test/windows/wslc/e2e/WSLCE2ENetworkCreateTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class WSLCE2ENetworkCreateTests
VerifyNetworkIsListed(TestNetworkName);
auto inspect = InspectNetwork(TestNetworkName);
VERIFY_ARE_EQUAL("bridge", inspect.Driver);
VERIFY_IS_FALSE(inspect.EnableIPv6);
}

WSLC_TEST_METHOD(WSLCE2E_Network_Create_BridgeDriver_Success)
Expand Down Expand Up @@ -125,6 +126,23 @@ class WSLCE2ENetworkCreateTests
VERIFY_IS_TRUE(inspect.Internal);
}

WSLC_TEST_METHOD(WSLCE2E_Network_Create_Ipv6_Success)
{
const std::wstring subnet = L"fd00:172:53::/64";
auto result = RunWslc(std::format(L"network create --ipv6 --subnet {} {}", subnet, TestNetworkName));
result.Verify({.Stderr = L"", .ExitCode = 0});
VERIFY_ARE_EQUAL(TestNetworkName, result.GetStdoutOneLine());

VerifyNetworkIsListed(TestNetworkName);
auto inspect = InspectNetwork(TestNetworkName);
VERIFY_ARE_EQUAL("bridge", inspect.Driver);
VERIFY_IS_TRUE(inspect.EnableIPv6);
VERIFY_IS_TRUE(inspect.IPAM.Config.has_value());
VERIFY_IS_TRUE(std::ranges::any_of(*inspect.IPAM.Config, [&](const auto& config) {
return config.Subnet == wsl::shared::string::WideToMultiByte(subnet);
}));
}

WSLC_TEST_METHOD(WSLCE2E_Network_Create_Subnet_Success)
{
const std::wstring subnet = L"172.45.0.0/16";
Expand Down