diff --git a/pkg/networkmanager/ip-settings.jsx b/pkg/networkmanager/ip-settings.jsx index c11bad66c922..b7f7b2fe8219 100644 --- a/pkg/networkmanager/ip-settings.jsx +++ b/pkg/networkmanager/ip-settings.jsx @@ -36,25 +36,35 @@ import { useDialogs } from "dialogs.jsx"; const _ = cockpit.gettext; -export const ipv4_method_choices = - [ - { choice: 'auto', title: _("Automatic (DHCP)") }, - { choice: 'link-local', title: _("Link local") }, - { choice: 'manual', title: _("Manual") }, - { choice: 'shared', title: _("Shared") }, - { choice: 'disabled', title: _("Disabled") } - ]; +const ip_method_choices = [ + { choice: 'auto', title: _("Automatic") }, + { choice: 'dhcp', title: _("Automatic (DHCP only)") }, + { choice: 'link-local', title: _("Link local") }, + { choice: 'manual', title: _("Manual") }, + { choice: 'ignore', title: _("Ignore") }, + { choice: 'shared', title: _("Shared") }, + { choice: 'disabled', title: _("Disabled") } +]; -export const ipv6_method_choices = - [ - { choice: 'auto', title: _("Automatic") }, - { choice: 'dhcp', title: _("Automatic (DHCP only)") }, - { choice: 'link-local', title: _("Link local") }, - { choice: 'manual', title: _("Manual") }, - { choice: 'ignore', title: _("Ignore") }, - { choice: 'shared', title: _("Shared") }, - { choice: 'disabled', title: _("Disabled") } - ]; +const supported_ipv4_methods = ['auto', 'link-local', 'manual', 'shared', 'disabled']; +// NM only supports a subset of IPv4 and IPv6 methods for wireguard +// See: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/1.42.8/src/libnm-core-impl/nm-setting-wireguard.c#L1723 +const wg_supported_ipv4_methods = ['manual', 'disabled']; +const wg_supported_ipv6_methods = ['link-local', 'manual', 'ignored', 'disabled']; + +export function get_ip_method_choices(topic, device_type) { + if (topic === 'ipv4') { + if (device_type === 'wireguard') + return ip_method_choices.filter(item => wg_supported_ipv4_methods.includes(item.choice)); + return ip_method_choices.filter(item => supported_ipv4_methods.includes(item.choice)); + } + + if (device_type === 'wireguard') + return ip_method_choices.filter(item => wg_supported_ipv6_methods.includes(item.choice)); + + // IPv6 supports all the choices + return ip_method_choices; +} export const IpSettingsDialog = ({ topic, connection, dev, settings }) => { const Dialogs = useDialogs(); @@ -164,7 +174,7 @@ export const IpSettingsDialog = ({ topic, connection, dev, settings }) => { aria-label={_("Select method")} onChange={(_, val) => setMethod(val)} value={method}> - {(topic == "ipv4" ? ipv4_method_choices : ipv6_method_choices).map(choice => )} + {get_ip_method_choices(topic, dev.DeviceType).map(choice => )}