"Fossies" - the Fresh Open Source Software Archive

Member "neutron-14.0.3/neutron/agent/l3/dvr_snat_ns.py" (22 Oct 2019, 2448 Bytes) of package /linux/misc/openstack/neutron-14.0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "dvr_snat_ns.py" see the Fossies "Dox" file reference documentation.

    1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    2 #    not use this file except in compliance with the License. You may obtain
    3 #    a copy of the License at
    4 #
    5 #         http://www.apache.org/licenses/LICENSE-2.0
    6 #
    7 #    Unless required by applicable law or agreed to in writing, software
    8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   10 #    License for the specific language governing permissions and limitations
   11 #    under the License.
   12 
   13 from neutron_lib import constants
   14 from oslo_log import log as logging
   15 
   16 from neutron.agent.l3 import namespaces
   17 from neutron.agent.linux import ip_lib
   18 
   19 LOG = logging.getLogger(__name__)
   20 SNAT_NS_PREFIX = 'snat-'
   21 
   22 
   23 class SnatNamespace(namespaces.Namespace):
   24 
   25     def __init__(self, router_id, agent_conf, driver, use_ipv6):
   26         self.router_id = router_id
   27         name = self.get_snat_ns_name(router_id)
   28         super(SnatNamespace, self).__init__(
   29             name, agent_conf, driver, use_ipv6)
   30 
   31     def create(self):
   32         super(SnatNamespace, self).create()
   33         # This might be an HA router namespaces and it should not have
   34         # ip_nonlocal_bind enabled
   35         ip_lib.set_ip_nonlocal_bind_for_namespace(self.name, 0)
   36         # Set nf_conntrack_tcp_loose to 0 to ensure mid-stream
   37         # TCP conversations aren't taken over by SNAT
   38         cmd = ['net.netfilter.nf_conntrack_tcp_loose=0']
   39         ip_lib.sysctl(cmd, namespace=self.name)
   40 
   41     @classmethod
   42     def get_snat_ns_name(cls, router_id):
   43         return namespaces.build_ns_name(SNAT_NS_PREFIX, router_id)
   44 
   45     @namespaces.check_ns_existence
   46     def delete(self):
   47         ns_ip = ip_lib.IPWrapper(namespace=self.name)
   48         for d in ns_ip.get_devices():
   49             if d.name.startswith(constants.SNAT_INT_DEV_PREFIX):
   50                 LOG.debug('Unplugging DVR device %s', d.name)
   51                 self.driver.unplug(d.name, namespace=self.name,
   52                                    prefix=constants.SNAT_INT_DEV_PREFIX)
   53             elif d.name.startswith(namespaces.EXTERNAL_DEV_PREFIX):
   54                 self.driver.unplug(
   55                     d.name,
   56                     namespace=self.name,
   57                     prefix=namespaces.EXTERNAL_DEV_PREFIX)
   58 
   59         # TODO(mrsmith): delete ext-gw-port
   60         LOG.debug('DVR: destroy snat ns: %s', self.name)
   61         super(SnatNamespace, self).delete()