'Adds or removes rules and routes for SNAT redirection.'

def _snat_redirect_modify(self, gateway, sn_port, sn_int, is_add):

    cmd = [('net.ipv4.conf.%s.send_redirects=0' % sn_int)]
    try:
        ns_ipr = ip_lib.IPRule(namespace=self.ns_name)
        ns_ipd = ip_lib.IPDevice(sn_int, namespace=self.ns_name)
        for port_fixed_ip in sn_port['fixed_ips']:
            port_ip_addr = port_fixed_ip['ip_address']
            port_ip_vers = netaddr.IPAddress(port_ip_addr).version
            for gw_fixed_ip in gateway['fixed_ips']:
                gw_ip_addr = gw_fixed_ip['ip_address']
                if (netaddr.IPAddress(gw_ip_addr).version == port_ip_vers):
                    sn_port_cidr = common_utils.ip_to_cidr(port_ip_addr, port_fixed_ip['prefixlen'])
                    snat_idx = self._get_snat_idx(sn_port_cidr)
                    if is_add:
                        ns_ipd.route.add_gateway(gw_ip_addr, table=snat_idx)
                        ns_ipr.rule.add(ip=sn_port_cidr, table=snat_idx, priority=snat_idx)
                        ip_lib.sysctl(cmd, namespace=self.ns_name)
                    else:
                        self._delete_gateway_device_if_exists(ns_ipd, gw_ip_addr, snat_idx)
                        ns_ipr.rule.delete(ip=sn_port_cidr, table=snat_idx, priority=snat_idx)
    except Exception:
        if is_add:
            exc = _LE('DVR:    error    adding    redirection    logic')
        else:
            exc = _LE('DVR:    snat    remove    failed    to    clear    the    rule    and    device')
        LOG.exception(exc)
