Commit Graph

138 Commits

Author SHA1 Message Date
Rodolfo Alonso Hernandez ebb7ec1eed ``IpLinkCommand.set_netns`` "is_ovs_port" parameter no longer needed
The input parameter "is_ovs_port" is no longer needed in the method
``IpLinkCommand.set_netns`` since [1].

[1]https://review.opendev.org/c/openstack/neutron/+/905836

Trivial-Fix

Change-Id: I0e36cf8afe76904997e14eca415a0e978f05c55a
2024-02-21 07:48:01 +00:00
Felix Huettner 566fea3fed fix netns deletion of broken namespaces
normal network namespaces are bind-mounted to files under
/var/run/netns. If a process deleting a network namespace gets killed
during that operation there is the chance that the bind mount to the
netns has been removed, but the file under /var/run/netns still exists.

When the neutron-ovn-metadata-agent tries to clean up such network
namespaces it first tires to validate that the network namespace is
empty. For the cases described above this fails, as this network
namespace no longer really exists, but is just a stray file laying
around.

To fix this we treat network namespaces where we get an `OSError` with
errno 22 (Invalid Argument) as empty. The calls to pyroute2 to delete
the namespace will then clean up the file.

Additionally we add a guard to teardown_datapath to continue even if
this fails. failing to remove a datapath is not critical and leaves in
the worst case a process and a network namespace running, however
previously it would have also prevented the creation of new datapaths
which is critical for VM startup.

Closes-Bug: #2037102
Change-Id: I7c43812fed5903f98a2e491076c24a8d926a59b4
2024-01-08 07:51:33 +01:00
Bence Romsics 2aee961ab6 Suppress IPv6 metadata DAD failure and delete address
IPv4 DAD is non-existent in Linux or its failure is silent, so we
never needed to catch and ignore it. On the other hand IPv6 DAD
failure is explicit, hence comes this change.

This of course leaves the metadata service dead on hosts where
duplicate address detection failed. But if we catch the
DADFailed exception and delete the address, at least other
functions of the dhcp-agent should not be affected.

With this the IPv6 isolated metadata service is not redundant, which
is the best we can do without a redesign.

Also document the promised service level of isolated metadata.

Added additional tests for the metadata driver as well.

Change-Id: I6b544c5528cb22e5e8846fc47dfb8b05f70f975c
Partial-Bug: #1953165
2023-04-04 09:39:19 -04:00
Slawek Kaplonski 2af5fd889b Add sleep before checking if ovs port is in the namespace
When network device which is ovs internal port is moved to the namespace
it may happend sometimes that it will have "shy port syndrome" [1].
Even though there is wait for device to be in namespace in the set_netns
method it may happend that device is in namespace during this check but
it dissapears for short time later and that causes failures e.g. in
functional tests like described in [2].
To avoid that, this patch proposed simple (and ugly) sleep for 1 second
before checking if port really exists in the namespace. If it will be
"shy" port it should already flap during that 1 second.

[1] https://bugs.launchpad.net/neutron/+bug/1618987
[2] https://bugs.launchpad.net/neutron/+bug/1961740

Related-Bug: #1961740
Related-Bug: #1998337
Change-Id: I442587e7ef55917f4ea873e190bf8afbc0e911e1
2023-03-01 09:26:42 +01:00
Zuul f7743f4a98 Merge "Change flag check order in wait_until_address_ready()" 2023-01-26 13:31:21 +00:00
Brian Haley 1d22cfa99a Change flag check order in wait_until_address_ready()
When DAD fails on an IPv6 address, both the 'dadfailed'
and 'tentative' flags will be set. So change the code
to check for 'dadfailed' first, just to be explicit.

Added better unit testing to cover more cases as well.

Trivialfix

Change-Id: I2dddc296826e5ab5e057c32a554e353577cc36e8
2023-01-24 09:45:41 -05:00
Rodolfo Alonso Hernandez 1d84aaf877 Bump the minimum pyroute2 version to 0.7.3
This patch also removes the pylint disablement message control
statements and imports NetNS and IPRoute from the new locations
in pyroute2.

Trivial-Fix

Change-Id: I298a7da767473c236ddf03c5702a2904d4870284
2023-01-18 04:43:09 +01:00
Dr. Jens Harbott fe4fa55642 Fix tests involving pyroute2.netns module
pyroute2 0.6.11 did some further refactoring of their module imports,
adapt some mocks to that the tests work with both the older and the new
versions.

Change-Id: I00c1b1e81c33cf93372dec21f4a9f409d784a160
2022-06-08 22:07:02 +02:00
Tamas Gergely Peter a47e9494c1 Check whether vxlan group and local addresses are IPv4 or IPv6
Check if group and/or local addresses passed to ip_lib / add_vxlan()
are IPv4 or IPv6. In case of IPv4 fill 'vxlan_group' and 'vxlan_local'
arguments and in case of IPv6 fill 'vxlan_group6' and 'vxlan_local6'
arguments to be passed down to privileged create_interface() method.
In case of an invalid address format raise an AddrFormatError exception.

Closes-Bug: #1952897
Change-Id: I2e3b0c1635627edb2c86c6120b0410ab3c4678b2
2022-01-10 13:11:37 +00:00
Rodolfo Alonso Hernandez 16a793af19 When creating a VXLAN interface, a device is mandatory
"IPWrapper.add_vxlan" method must have "dev" parameter as possitional
argument. A VXLAN interface must be always created on top of an existing
network device:
  https://www.kernel.org/doc/Documentation/networking/vxlan.txt

Closes-Bug: #1954316
Change-Id: Ia082f8531ffcc1599206124774599dcdb500274a
2021-12-10 12:15:18 +00:00
Rodolfo Alonso Hernandez ebc4766990 Check interface presence in new namespace
When an interface is moved to a new namespace, specially with OVS
internal ports, the interface first dissapears from any network
namespace and then is added again. ovs-vswitchd service detects
this interface change as reported in [1]. This delay is the cause
of the related bug, where some interfaces are not present when
the L3 agent needs to manipulate them.

[1]https://bugs.launchpad.net/neutron/+bug/1948832/comments/3

Closes-Bug: #1948832
Change-Id: I3af4d0afa784899689ccb595ce6ba64495431eb9
2021-11-15 08:58:11 +00:00
Rodolfo Alonso Hernandez 8127221479 Check a namespace existence by checking only its own directory
To check the existance of a namespace, instead of listing the
namespaces directory (by default "/var/run/netns"), this patch
directly checks the existence of the namespace directory, using
"os.path.exists".

This check is faster than listing the whole directory and avoids
timeout problems as reported in the related bug.

Closes-Bug: #1947974
Change-Id: I558d50d28378beb3710d98a2113ff9549c82ae17
2021-10-25 09:59:32 +00:00
Rodolfo Alonso Hernandez c511964d70 Replace "get_routing_table" with "list_ip_routes"
"get_routing_table" uses "pyroute2.IPDB" that has been deprecated.
"list_ip_routes" has been improved to be able to read multipath
routes.

Closes-Bug: #1926476

Change-Id: I0299fa11a7afefbd2999f81cd4ed3beed572009c
2021-05-01 17:39:42 +00:00
Zuul 1aef2a6498 Merge "Remove "IpCommandBase" base class" 2021-03-02 13:10:22 +00:00
Rodolfo Alonso Hernandez 0a4dcb18bb Remove "IpCommandBase" base class
"IpCommandBase" class was implemented to provide a common interface
for all "ip" command subclasses. This base class provided a COMMAND
class variable, to define the "ip" shell command subparameter and
a two execution methods, "_run" and "_as_root".

Now all "ip" command classes have been migrated to Pyroute2, this
basic interface is not needed anymore.

Story: #2007686
Task: #41558

Change-Id: Ib7d30b954bef3bc3551f1ca206873df354d1ab23
2021-03-01 12:15:40 +00:00
Rodolfo Alonso Hernandez a6cdf273c0 Improve "get_devices_with_ip" performance
As reported in LP#1896734, there is a limit in the size of information
that can be transmitted in one single message between an application
and the privsep daemon. The read socket buffer is limited in size;
a message exceeding this size will generate an exception.

In order to limit the amount of information to be sent, this patch
improves the performance of "get_devices_with_ip". In the previous
implementation, the whole list of network devices from a namespace
was retrieved. In some environments, the list of devices could be
so big that the list returned by "privileged.get_link_devices" can
exceed the read buffer size (as reported in the LP bug when the
OVS agent tries to retrieve the list of IP addresses in the system).

Now the function calls "privileged.get_ip_addresses", that returns
a much smaller list. This patch is also reducing the number of system
calls to just one; the previous implementation was retrieving first
the devices link information list (that method was returning a much
bigger blob) and then, per device, retrieving the IP address
information.

Change-Id: I97ada62484023b9833ed12afd68eb4c8d337fd1f
Related-Bug: #1896734
2021-02-27 10:07:03 +00:00
Rodolfo Alonso Hernandez 591715b86e Implement "ip neigh flush" with Pyroute2
Story: #2007686
Task: #41558

Change-Id: I00c676e234fd9f771d716def7e4388bf33004118
2021-02-19 14:17:34 +00:00
Rodolfo Alonso Hernandez 5a419cbc84 Remove rootwrap execution (5)
Replace rootwrap execution with privsep context execution.
This series of patches will progressively replace any
rootwrap call.

This patch migrates some missing execution methods present in
the code and removes unneeded rootwrap filters.

Story: #2007686
Task: #41558

Change-Id: I1542dc4cf98658fc9a40018192498c7a5cd1c3fe
2021-02-19 08:47:17 +00:00
Rodolfo Alonso Hernandez c89c1f53db Remove rootwrap execution (1)
Replace rootwrap execution with privsep context execution.
This series of patches will progressively replace any
rootwrap call.

This patch replaces some "IpNetnsCommand" command execution
methods.

Change-Id: Ic5fdf221a2a2cd0951539b0e040d2a941feee287
Story: #2007686
Task: #41558
2021-02-06 16:22:43 +00:00
Rodolfo Alonso Hernandez 0705699e60 "scope" conversion only just before pyroute2 method call
In "IpAddrCommand.list" method, the "scope" parameter is a string
("link", "site", "global" or "host"). This method will retrieve all
devices with an IP address calling "ip_lib.get_devices_with_ip".

Since [1], "ip_lib.get_devices_with_ip" makes the conversion of
"scope" string parameter to pyroute2 format (see
"pyroute2.netlink.rtnl.rtscopes"). The list command should skip then
the previous conversion.

Closes-Bug: #1899141

[1]https://review.opendev.org/#/c/747406/

Change-Id: I55a0f4341b328af52ea3bd758a72f633fbe3abcb
2020-10-15 15:49:05 +00:00
Brian Haley 7594bb0627 Remove the dependency on the "mock" package
Now that we are python3 only, we should move to using the built
in version of mock that supports all of our testing needs and
remove the dependency on the "mock" package.

This patch moves all references to "import mock" to
"from unittest import mock". It also cleans up some new line
inconsistency.

Fixed an inconsistency in the OVSBridge.deferred() definition
as it needs to also have an *args argument.

Fixed an issue where an l3-agent test was mocking
functools.partial, causing a python3.8 failure.

Unit tests only, removing from tests/base.py affects
functional tests which need additional work.

Change-Id: I40e8a8410840c3774c72ae1a8054574445d66ece
2020-04-28 18:05:37 -04:00
Rodolfo Alonso Hernandez 8cc2765b5f Avoid raising NetworkInterfaceNotFound exception in DHCP agent logs
In "ip_lib.ensure_device_is_ready", before retrieving the interface
attributes, a check is done to know if the interface exists. In case
it does not exist, the exception "NetworkInterfaceNotFound" will not
be raised and written in the logs.

Change-Id: I4b9fd0885d850601717274a5058e042871211bbb
Closes-Bug: #1854723
2019-12-06 10:28:24 +00:00
Brian Haley 555238da69 Start using oslo_utils.netutils.is_ipv6_enabled()
Seems that is_enabled_and_bind_by_default() from
neutron.common.ipv6_utils was copied directly into
oslo_utils.netutils, so start using it instead.

Trivialfix

Change-Id: I00fa441e7a20fcd1115485bb8ab75750e6a8cf07
2019-10-16 21:44:56 -04:00
Rodolfo Alonso Hernandez 429c77c574 Implement "ip route delete" command using Pyroute2
Change-Id: I960455d6a9bc1b633d485c42a26b3a254731558e
Related-Bug: #1492714
2019-07-01 10:37:19 +00:00
Rodolfo Alonso Hernandez 0699713609 Implement "ip route" commands using Pyroute2
Commands implemented:
* Add route
* List routes

Related-Bug: #1492714

Change-Id: I5e5e9f6981024317773979d9d2d77db3f5e7ec98
2019-06-27 10:07:52 +00:00
Rodolfo Alonso Hernandez a477c31a23 Add ip_monitor command implemented using Pyroute2
This method allows to track any IP address change in a
namespace. In future patches, this method will replace
the current IP monitor used in the keepalived_state_change
daemon. The current implementation relays in a spawned shell,
executed in root mode, and the output of this shell,
conveniently parsed.

If the passed namespace is not None, this new method must
be executed in privileged mode (root user), but cannot use
privsep because is a blocking function and can exhaust the
number of working threads.

This function should be executed in a parallel thread, returning
the data using the eventlet queue. Pyroute does not implement yet
a non blocking method to retrieve the command output or to know if
the buffer has data. This method, spawned in a greenthread, must be
stopped by killing this thread.

An example of how to use it can be found in the functional tests
implemented in this patch.

Change-Id: I86e4487035d60e1b52e951dd3cd50d6bb54f388b
Related-Bug: #1680183
2019-06-05 17:22:44 +00:00
Rodolfo Alonso Hernandez 05644f79ad Retrieve devices with link not present
In ip_lib.get_devices_info(), privileged.get_link_devices() can return
devices with links not present in this namespace or not listed. In this
situation, get_devices_info() will always try to find the device to set
the parameter "parent_name", what will trigger an exception.

This patch solves this issue avoiding the population of "parent_name"
if the link device is not present in the devices list.

Change-Id: Ic5c7d9008a11da5c406dc383cfdae2892a3118d8
Closes-Bug: #1815758
2019-02-17 20:41:58 +00:00
Zuul 46dc30991a Merge "Switch isolated metadata proxy to bind to 169.254.169.254" 2019-02-05 13:51:37 +00:00
Zuul b86fa161ed Merge "remove neutron.common.exceptions" 2019-02-03 17:07:02 +00:00
Boden R 68fd13af40 remove neutron.common.exceptions
Today the neutron common exceptions already live in neutron-lib and are
shimmed from neutron. This patch removes the neutron.common.exceptions
module and changes neutron's imports over to use their respective
neutron-lib exception module instead.

NeutronLibImpact

Change-Id: I9704f20eb21da85d2cf024d83338b3d94593671e
2019-02-01 14:35:00 -07:00
Rodolfo Alonso Hernandez aa71530aaa Add VLAN and VXLAN link information in get_devices_info
Added VLAN parent device name and index and VXLAN link device
name and index.

Change-Id: Ib44a63c0648a7b5b07b1021b10e8994002031ce8
Related-Bug: #1804274
2019-01-30 18:31:39 +00:00
Bernard Cafarelli 6124f60297 Switch isolated metadata proxy to bind to 169.254.169.254
Currently the metadata proxy binds to default 0.0.0.0, which does not
add any advantage (metadata requests are not sent to random IP
addresses), and may allow access to cloud information from
third parties.

This changes the generated configuration to bind to METADATA_DEFAULT_IP
address instead.

This is not enabled in other metadata proxy configuration (in the L3
agent), as this would require net.ipv4.ip_nonlocal_bind everywhere
(currently only enabled for DVR) or transparent mode in haproxy (which
requires net.ipv4.ip_nonlocal_bind anyway)

Changed set_ip_nonlocal_bind_for_namespace() to support setting the
value in both the given and root namespace correctly, since it was
only used from inside the neutron codebase according to codesearch.

Change-Id: I388391cf697dade1a163d15ab568b33134f7b2d9
Co-Authored-By: Andrey Arapov <andrey.arapov@nixaid.com>
Closes-Bug: #1745618
2019-01-30 14:17:43 +00:00
Rodolfo Alonso Hernandez e7a2b6d179 Add IPWrapper.get_devices_info using PyRoute2
This function returns the attributes of a list of devices.

Change-Id: I322fc7db9c71e7c21fd03d616937d172da856428
Related-Bug: #1804274
2019-01-25 17:50:24 +00:00
Rodolfo Alonso Hernandez 05a54e8004 Implement IpAddrCommand.get_devices_with_ip using pyroute2
Related-Bug: #1492714

Change-Id: If7292c33dd0716a0a412bf60658123d2e688dfdb
2018-12-17 13:11:49 +00:00
Rodolfo Alonso Hernandez 489dd18530 Implement IpRuleCommand.delete() using pyroute2
Related-Bug: #1492714

Change-Id: Ia9f192541f7b9994c3dae93f3f3ae96f1a4fba0c
2018-12-14 19:27:41 +00:00
Rodolfo Alonso Hernandez 89ba2416f2 Table name in "add_ip_rule" can be a string
In neutron.agent.linux.ip_lib.add_ip_rule, the "table" argument can be
an integer or a string ("default", "main", "local").

This parameter is incorrectly treated in "_make_pyroute2_args".

Change-Id: I0a50af5fe9b1550700e607eb680bb16e5044e8ef
Closes-Bug: #1807128
2018-12-13 09:22:27 +00:00
Rodolfo Alonso Hernandez 87926fddc0 Implement IpRuleCommand.add() using pyroute2
Change-Id: I0cc6b24a91794eeba46462fac2bfdeda2ba2ab9e
Related-Bug: #1492714
2018-12-04 19:54:18 +00:00
Rodolfo Alonso Hernandez c68ebd661b Implement IpRuleCommand.list_rules() using pyroute2
Change-Id: I55d5dd756940e5a92f472c9309d49f427e907928
Related-Bug: #1492714
2018-11-27 09:23:25 +00:00
Zuul 70c5c5f249 Merge "Change to use iproute2 instead of brctl" 2018-11-21 23:26:24 +00:00
Brian Haley 2572c158f5 Change to use iproute2 instead of brctl
brctl is being deprecated in some Linux distros, so
change neutron to start using iproute2 commands or
the pyroute2 library where possible.

Added create() to IpLinkCommand class to allow usage
of pyroute2 for bridge creation.

Change-Id: If679e79fa3242ee1cd8610b5525deca35b41c87e
Closes-bug: #1801919
2018-11-14 12:46:37 -05:00
Rodolfo Alonso Hernandez aa19fa1c3f Implement ip_lib get_devices using pyroute2
IPWrapper.get_devices() now uses pyroute2 and priv_sep.

Related-Bug: #1492714
Change-Id: Idb847bf16fe8898735266d93d39430da1f5410f9
2018-11-14 09:27:26 +00:00
Daniel Alvarez 8e60531d11 Exclude fallback tunnel devices from netns cleanup
When a namespace gets created, if the fb_tunnels_only_for_init_net
sysctl configuration is set to 0, the fallback tunnels will be
automatically created if the corresponding tunnel is present
in the initial network namespace. Source [0].

This is being observed in some systems where namespaces are not
getting cleaned up due to the presence of such devices as
ip_lib.namespace_is_empty() is returning False.

This patch is adding such devices as per the kernel documentation
to the list of excluded devices by default.

[0] https://www.kernel.org/doc/Documentation/sysctl/net.txt

Closes-Bug: #1797084
Change-Id: I94415a0da5367e2d98d792a5eb4ba3919b838326
Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>
2018-10-10 15:01:49 +02:00
Brian Haley 00de8f9a9e Do not fail deleting namespace if it does not exist
Note: this is a squash of two changes since they are
dependent on each other, and are currently blocking
the gate queue.

Sometimes cleanup methods are failing in the check and
gate queues trying to delete non-existing namespaces.
Since they could have been deleted asynchronously, don't
raise if the failure is "No such file or directory" since
the system is in the intended state.

Cleaned-up the DHCP agent to longer check for existence
first, and the tests to longer mock-out the namespace
exists check.

Fix test_legacy_router_lifecycle failures

Multi-path routes returned via the pyroute2 library have
their outgoing interfaces in the 'multipath' dictionary
element, not in the route dictionary.  In that case return
all the multipath routes correctly.

Change-Id: I5415cb3a88ff2640a19598a1fcb2278388815343
Closes-bug: #1795482
Closes-bug: #1795548
2018-10-02 09:52:22 -04:00
Hongbin Lu 12bb26fd0e Use constant IP_VERSION_4/6 in unit tests
Change-Id: I54bec2c06940b0b1362fecacef7860361d081601
2018-08-27 21:45:39 +00:00
Slawek Kaplonski 99567388ac Create veth pair devices using pyroute2
Create of veth devices now uses pyroute2 and priv_sep.

Change-Id: I8d0346dd1859010aba864ea908c7dcb118aa5412
Related-Bug: #1492714
2018-08-10 10:33:14 +02:00
ZhaoBo de9b39ed2c [agent side] L3 agent side Floating IP port forwarding
This patch contains the l3 agent extension and agent part code.
This patch introduce a new l3 agent extension named "port_forwarding",
to process the binding of the port forwarding resources, manage its own
floatingip configuration on router interface and floatingip status.
Currrently, we support all Neutron Router reference implementations.

This extension uses the period router sync task and PortForwarding OVO
rpc.

* The main idea about this new extension is using the generic router sync
  rpc to maintain the host port forwarding resources,
* For a single port forwarding create/update/delete, process it one by one
  in smaller scope for forbidding refresh the iptables with a larger
  scope frequently.

Partially-Implements: blueprint port-forwarding
Partial-Bug: #1491317
Change-Id: Ic56e67d428f6177099c285a9d1bccabc1e710f2b
2018-07-27 18:25:47 +08:00
Zuul abbd534fdf Merge "Revert "DVR: Fix allowed_address_pair IP, ARP table update by neutron agent"" 2018-06-18 21:56:10 +00:00
Swaminathan Vasudevan f98f239a15 Revert "DVR: Fix allowed_address_pair IP, ARP table update by neutron agent"
This reverts commit fbe308bdc1.

This does not help the ARP update for the unbound Allowed-address-pair
IP, since the temporary ARP update (NUD: reachable) goes to incomplete
state when the router tries to re-ARP for the IP, before it responds to
a VM, since DVR routers does not allow the ARP requests to flow through
the br-tun.

Closes-bug: #1773999

Change-Id: I9977c8cbbbc1e68565249e7f80c59319fe967300
2018-06-07 15:32:20 +00:00
Miguel Lavalle be8a7a2795 Fix handling of dstport option for VXLANs
When specifying a value for the 'dstport' option in the [vxlan] section
of the Linux bridge agent, the agent crashes upon start. This is
because the value specified in 'dstport' is incorrectly converted to
a string before being passed to pyroute2 when creating a VXLAN tunnel.
pyroute2 expects an integer value. This patch fixes this bug.

Change-Id: I83131f3bb32253cbc4acec3a1f38bf225223ff8b
Closes-Bug: #1764867
2018-04-17 16:10:34 -05:00
Dmitrii Shcherbakov 81db328b2d Use cidr during tenant network rule deletion
If a distributed router has interfaces on multiple tenant networks, with
'fast exit' functionality policy based rules are created in qrouter
namespace for every tenant network subnet and 'from <cidr>' is included
into an 'ip rule' command invocation.

When a port on a tenant network is deleted 'from <cidr>' part is not
included and a first rule matching specified parameters gets deleted.

For example with the following layout

ip netns exec qrouter-4f9ca9ef-303b-4082-abbc-e50782d9b800 ip rule
0:      from all lookup local
32766:  from all lookup main
32767:  from all lookup default
80000:  from 192.168.100.0/24 lookup 16
80000:  from 192.168.200.0/24 lookup 16

and neutron l3 agent will use this command

ip netns exec qrouter-4f9ca9ef-303b-4082-abbc-e50782d9b800 ip -4 rule\
del priority 80000 table 16 type unicast

and 192.168.100.0/24 rule will get deleted even if you actually removed
a port on 192.168.200.0.

This results in an extra rule present and not cleaned up and the right
rule removed. It is only recreated if a router is disabled and enabled
again.

additional changes:

1) Floating IP rules are identified by priority only as implemented
currently - for this reason this change adds fixed_ip to the rule
removal code. Rule priorities are 32-bit values in iproute2 so,
in theory, those should be not be used to cover IPv6.

2) IP protocol information for 'from all' rules is currently
derived from link-local address IP version. The same approach
is preserved by using version-specific /0 addresses without
changing the API provided by ip_lib.

Change-Id: I0ea6dddd26e17771be223a1fbdf21792c90f3e9c
Closes-Bug: #1759956
2018-04-03 19:17:03 -04:00