diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/ifconfig/interface.py | 4 | ||||
| -rw-r--r-- | python/vyos/nat.py | 33 | ||||
| -rw-r--r-- | python/vyos/qos/base.py | 21 | 
3 files changed, 57 insertions, 1 deletions
| diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index 8ed5cb114..75c5f27a9 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -1275,7 +1275,6 @@ class Interface(Control):              # running, but it should be running (e.g. on system startup)              if 'dhcp_options_changed' in self.config or not is_systemd_service_active(systemd_service):                  return self._cmd(f'systemctl restart {systemd_service}') -            return None          else:              if is_systemd_service_active(systemd_service):                  self._cmd(f'systemctl stop {systemd_service}') @@ -1284,6 +1283,7 @@ class Interface(Control):                  if os.path.isfile(file):                      os.remove(file) +        return None      def set_dhcpv6(self, enable):          """ @@ -1317,6 +1317,8 @@ class Interface(Control):              if os.path.isfile(config_file):                  os.remove(config_file) +        return None +      def set_mirror_redirect(self):          # Please refer to the document for details          #   - https://man7.org/linux/man-pages/man8/tc.8.html diff --git a/python/vyos/nat.py b/python/vyos/nat.py index 603fedb9b..418efe649 100644 --- a/python/vyos/nat.py +++ b/python/vyos/nat.py @@ -94,6 +94,39 @@ def parse_nat_rule(rule_conf, rule_id, nat_type, ipv6=False):          if options:              translation_str += f' {",".join(options)}' +        if 'backend' in rule_conf['load_balance']: +            hash_input_items = [] +            current_prob = 0 +            nat_map = [] + +            for trans_addr, addr in rule_conf['load_balance']['backend'].items(): +                item_prob = int(addr['weight']) +                upper_limit = current_prob + item_prob - 1 +                hash_val = str(current_prob) + '-' + str(upper_limit) +                element = hash_val + " : " + trans_addr +                nat_map.append(element) +                current_prob = current_prob + item_prob + +            elements = ' , '.join(nat_map) + +            if 'hash' in rule_conf['load_balance'] and 'random' in rule_conf['load_balance']['hash']: +                translation_str += ' numgen random mod 100 map ' + '{ ' + f'{elements}' + ' }' +            else: +                for input_param in rule_conf['load_balance']['hash']: +                    if input_param == 'source-address': +                        param = 'ip saddr' +                    elif input_param == 'destination-address': +                        param = 'ip daddr' +                    elif input_param == 'source-port': +                        prot = rule_conf['protocol'] +                        param = f'{prot} sport' +                    elif input_param == 'destination-port': +                        prot = rule_conf['protocol'] +                        param = f'{prot} dport' +                    hash_input_items.append(param) +                hash_input = ' . '.join(hash_input_items) +                translation_str += f' jhash ' + f'{hash_input}' + ' mod 100 map ' + '{ ' + f'{elements}' + ' }' +      for target in ['source', 'destination']:          if target not in rule_conf:              continue diff --git a/python/vyos/qos/base.py b/python/vyos/qos/base.py index 1eac0d1ee..d8bbfe970 100644 --- a/python/vyos/qos/base.py +++ b/python/vyos/qos/base.py @@ -298,6 +298,27 @@ class QoSBase:                                  filter_cmd += f' flowid {self._parent:x}:{cls:x}'                                  self._cmd(filter_cmd) +                    if any(tmp in ['exceed', 'bandwidth', 'burst'] for tmp in cls_config): +                        filter_cmd += f' action police' + +                        if 'exceed' in cls_config: +                            action = cls_config['exceed'] +                            filter_cmd += f' conform-exceed {action}' +                        if 'not_exceed' in cls_config: +                            action = cls_config['not_exceed'] +                            filter_cmd += f'/{action}' + +                        if 'bandwidth' in cls_config: +                            rate = self._rate_convert(cls_config['bandwidth']) +                            filter_cmd += f' rate {rate}' + +                        if 'burst' in cls_config: +                            burst = cls_config['burst'] +                            filter_cmd += f' burst {burst}' +                        cls = int(cls) +                        filter_cmd += f' flowid {self._parent:x}:{cls:x}' +                        self._cmd(filter_cmd) +                  else:                      filter_cmd += ' basic' | 
