From dce51fd6d75e9e1fe9ac23e2b80c5406629ec727 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 18 Sep 2016 23:19:15 +0530 Subject: [PATCH] networks: Support configuring IPv6 networks - Very similar to configuration of IPv4 networks. - Supports 'auto', 'dhcp', 'manual' and 'ignored' modes as supported by network manager. 'shared' mode is not yet implemented by network manager. --- plinth/modules/networks/forms.py | 67 ++++++++++++++++++- plinth/modules/networks/networks.py | 18 +++++ .../networks/templates/connections_edit.html | 50 +++++++++----- plinth/network.py | 31 +++++++++ plinth/tests/test_network.py | 66 +++++++++++++++++- 5 files changed, 214 insertions(+), 18 deletions(-) diff --git a/plinth/modules/networks/forms.py b/plinth/modules/networks/forms.py index 6921249a7..690026dcf 100644 --- a/plinth/modules/networks/forms.py +++ b/plinth/modules/networks/forms.py @@ -89,6 +89,46 @@ available over this interfaces. Select Internal only for trusted networks.'), 'provided by a DHCP server will be ignored.'), validators=[validators.validate_ipv4_address], required=False) + ipv6_method = forms.ChoiceField( + label=_('IPv6 Addressing Method'), + help_text=format_lazy( + ugettext_lazy( + '"Automatic" methods will make {box_name} acquire ' + 'configuration from this network making it a client.'), + box_name=ugettext_lazy(cfg.box_name)), + choices=[('auto', _('Automatic')), + ('dhcp', _('Automatic, DHCP only')), + ('manual', _('Manual')), + ('ignore', _('Ignore'))]) + ipv6_address = forms.CharField( + label=_('Address'), + validators=[validators.validate_ipv6_address], + required=False) + ipv6_prefix = forms.IntegerField( + label=_('Prefix'), + help_text=_('Value between 1 and 128.'), + min_value=1, + max_value=128, + required=False) + ipv6_gateway = forms.CharField( + label=_('Gateway'), + help_text=_('Optional value.'), + validators=[validators.validate_ipv6_address], + required=False) + ipv6_dns = forms.CharField( + label=_('DNS Server'), + help_text=_('Optional value. If this value is given and IPv6 ' + 'addressing method is "Automatic", the DNS Servers ' + 'provided by a DHCP server will be ignored.'), + validators=[validators.validate_ipv6_address], + required=False) + ipv6_second_dns = forms.CharField( + label=_('Second DNS Server'), + help_text=_('Optional value. If this value is given and IPv6 ' + 'Addressing Method is "Automatic", the DNS Servers ' + 'provided by a DHCP server will be ignored.'), + validators=[validators.validate_ipv6_address], + required=False) @staticmethod def _get_interface_choices(device_type): @@ -111,6 +151,7 @@ available over this interfaces. Select Internal only for trusted networks.'), 'zone': self.cleaned_data['zone'], } settings['ipv4'] = self.get_ipv4_settings() + settings['ipv6'] = self.get_ipv6_settings() return settings def get_ipv4_settings(self): @@ -125,6 +166,18 @@ available over this interfaces. Select Internal only for trusted networks.'), } return ipv4 + def get_ipv6_settings(self): + """Return IPv6 dict from cleaned data.""" + ipv6 = { + 'method': self.cleaned_data['ipv6_method'], + 'address': self.cleaned_data['ipv6_address'], + 'prefix': self.cleaned_data['ipv6_prefix'], + 'gateway': self.cleaned_data['ipv6_gateway'], + 'dns': self.cleaned_data['ipv6_dns'], + 'second_dns': self.cleaned_data['ipv6_second_dns'], + } + return ipv6 + class GenericForm(ConnectionForm): """Form to create/edit a generic connection.""" @@ -164,6 +217,12 @@ class PPPoEForm(EthernetForm): ipv4_gateway = None ipv4_dns = None ipv4_second_dns = None + ipv6_method = None + ipv6_address = None + ipv6_prefix = None + ipv6_gateway = None + ipv6_dns = None + ipv6_second_dns = None username = forms.CharField(label=_('Username')) password = forms.CharField(label=_('Password'), @@ -185,13 +244,19 @@ class PPPoEForm(EthernetForm): """Return IPv4 settings from cleaned data.""" return None + def get_ipv6_settings(self): + """Return IPv6 settings from cleaned data.""" + return None + class WifiForm(ConnectionForm): """Form to create/edit a Wi-Fi connection.""" field_order = ['name', 'interface', 'zone', 'ssid', 'mode', 'band', 'channel', 'bssid', 'auth_mode', 'passphrase', 'ipv4_method', 'ipv4_address', 'ipv4_netmask', - 'ipv4_gateway', 'ipv4_dns', 'ipv4_second_dns'] + 'ipv4_gateway', 'ipv4_dns', 'ipv4_second_dns', + 'ipv6_method', 'ipv6_address', 'ipv6_prefix', + 'ipv6_gateway', 'ipv6_dns', 'ipv6_second_dns'] ssid = forms.CharField( label=_('SSID'), diff --git a/plinth/modules/networks/networks.py b/plinth/modules/networks/networks.py index bad776c38..8dfd63f31 100644 --- a/plinth/modules/networks/networks.py +++ b/plinth/modules/networks/networks.py @@ -160,6 +160,24 @@ def edit(request, uuid): if number_of_dns > 1: form_data['ipv4_second_dns'] = settings_ipv4.get_dns(1) + settings_ipv6 = connection.get_setting_ip6_config() + form_data['ipv6_method'] = settings_ipv6.get_method() + if settings_ipv6.get_num_addresses(): + address = settings_ipv6.get_address(0) + form_data['ipv6_address'] = address.get_address() + form_data['ipv6_prefix'] = address.get_prefix() + + gateway = settings_ipv6.get_gateway() + if gateway: + form_data['ipv6_gateway'] = gateway + + number_of_dns = settings_ipv6.get_num_dns() + if number_of_dns: + form_data['ipv6_dns'] = settings_ipv6.get_dns(0) + + if number_of_dns > 1: + form_data['ipv6_second_dns'] = settings_ipv6.get_dns(1) + if settings_connection.get_connection_type() == 'generic': form = GenericForm(form_data) elif settings_connection.get_connection_type() == '802-11-wireless': diff --git a/plinth/modules/networks/templates/connections_edit.html b/plinth/modules/networks/templates/connections_edit.html index 193f67cbb..7bfbba800 100644 --- a/plinth/modules/networks/templates/connections_edit.html +++ b/plinth/modules/networks/templates/connections_edit.html @@ -39,43 +39,61 @@