diff options
author | Zuul <zuul@review.opendev.org> | 2019-09-17 20:32:23 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2019-09-17 20:32:23 +0000 |
commit | 8f989ac62c3dedb0bb706803f6cc105fa0140b8e (patch) | |
tree | 7a76251b7123e0416bea7365fa6922dc82e7db41 | |
parent | fe2b97c3f47b86ff5f822f5475e48de5c8d40865 (diff) | |
parent | 7a5ed4b688c7f69ce63ef600611947e08e14bcd0 (diff) | |
download | horizon-8f989ac62c3dedb0bb706803f6cc105fa0140b8e.tar.gz |
Merge "Allow creating ICMPV6 rules" into stable/rocky
-rw-r--r-- | openstack_dashboard/dashboards/project/security_groups/forms.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/openstack_dashboard/dashboards/project/security_groups/forms.py b/openstack_dashboard/dashboards/project/security_groups/forms.py index 58dd2dc4d..31678a335 100644 --- a/openstack_dashboard/dashboards/project/security_groups/forms.py +++ b/openstack_dashboard/dashboards/project/security_groups/forms.py @@ -397,6 +397,35 @@ class AddRule(forms.SelfHandlingForm): else: self._apply_rule_menu(cleaned_data, rule_menu) + def _adjust_ip_protocol_of_icmp(self, data): + # Note that this needs to be called after IPv4/IPv6 is determined. + try: + ip_protocol = int(data['ip_protocol']) + except ValueError: + # string representation of IP protocol + ip_protocol = data['ip_protocol'] + is_ipv6 = data['ethertype'] == 'IPv6' + + if isinstance(ip_protocol, int): + # When IP protocol number is specified, we assume a user + # knows more detail on IP protocol number, + # so a warning message on a mismatch between IP proto number + # and IP version is displayed. + if is_ipv6 and ip_protocol == 1: + msg = _('58 (ipv6-icmp) should be specified for IPv6 ' + 'instead of 1.') + self._errors['ip_protocol'] = self.error_class([msg]) + elif not is_ipv6 and ip_protocol == 58: + msg = _('1 (icmp) should be specified for IPv4 ' + 'instead of 58.') + self._errors['ip_protocol'] = self.error_class([msg]) + else: + # ICMPv6 uses different an IP protocol name and number. + # To allow 'icmp' for both IPv4 and IPv6 in the form, + # we need to replace 'icmp' with 'ipv6-icmp' based on IP version. + if is_ipv6 and ip_protocol == 'icmp': + data['ip_protocol'] = 'ipv6-icmp' + def clean(self): cleaned_data = super(AddRule, self).clean() @@ -431,6 +460,8 @@ class AddRule(forms.SelfHandlingForm): ip_ver = netaddr.IPNetwork(cidr).version cleaned_data['ethertype'] = 'IPv6' if ip_ver == 6 else 'IPv4' + self._adjust_ip_protocol_of_icmp(cleaned_data) + return cleaned_data def handle(self, request, data): |