Browse Source

Merge "Allow creating ICMPV6 rules" into stable/stein

changes/54/680454/1
Zuul 2 weeks ago
parent
commit
6a6f64860c
1 changed files with 31 additions and 0 deletions
  1. 31
    0
      openstack_dashboard/dashboards/project/security_groups/forms.py

+ 31
- 0
openstack_dashboard/dashboards/project/security_groups/forms.py View File

@@ -397,6 +397,35 @@ class AddRule(forms.SelfHandlingForm):
397 397
         else:
398 398
             self._apply_rule_menu(cleaned_data, rule_menu)
399 399
 
400
+    def _adjust_ip_protocol_of_icmp(self, data):
401
+        # Note that this needs to be called after IPv4/IPv6 is determined.
402
+        try:
403
+            ip_protocol = int(data['ip_protocol'])
404
+        except ValueError:
405
+            # string representation of IP protocol
406
+            ip_protocol = data['ip_protocol']
407
+        is_ipv6 = data['ethertype'] == 'IPv6'
408
+
409
+        if isinstance(ip_protocol, int):
410
+            # When IP protocol number is specified, we assume a user
411
+            # knows more detail on IP protocol number,
412
+            # so a warning message on a mismatch between IP proto number
413
+            # and IP version is displayed.
414
+            if is_ipv6 and ip_protocol == 1:
415
+                msg = _('58 (ipv6-icmp) should be specified for IPv6 '
416
+                        'instead of 1.')
417
+                self._errors['ip_protocol'] = self.error_class([msg])
418
+            elif not is_ipv6 and ip_protocol == 58:
419
+                msg = _('1 (icmp) should be specified for IPv4 '
420
+                        'instead of 58.')
421
+                self._errors['ip_protocol'] = self.error_class([msg])
422
+        else:
423
+            # ICMPv6 uses different an IP protocol name and number.
424
+            # To allow 'icmp' for both IPv4 and IPv6 in the form,
425
+            # we need to replace 'icmp' with 'ipv6-icmp' based on IP version.
426
+            if is_ipv6 and ip_protocol == 'icmp':
427
+                data['ip_protocol'] = 'ipv6-icmp'
428
+
400 429
     def clean(self):
401 430
         cleaned_data = super(AddRule, self).clean()
402 431
 
@@ -431,6 +460,8 @@ class AddRule(forms.SelfHandlingForm):
431 460
                 ip_ver = netaddr.IPNetwork(cidr).version
432 461
                 cleaned_data['ethertype'] = 'IPv6' if ip_ver == 6 else 'IPv4'
433 462
 
463
+        self._adjust_ip_protocol_of_icmp(cleaned_data)
464
+
434 465
         return cleaned_data
435 466
 
436 467
     def handle(self, request, data):

Loading…
Cancel
Save