Commit Graph

123 Commits

Author SHA1 Message Date
Adam Oswick c8c74f12e0 Load FIP information during initialize not init
DvrLocalRouter._load_used_fip_information() is called during the class
init however in some cases it tries to access a network namespace which
hasn't yet been created. This results in NetworkNamespaceNotFound.

This change ensures that we instead create any FIP priority rules after
the network namespace has been created by calling
_load_used_fip_information() from the initialize function rather than
in the class instantiation.

Closes-Bug: #2025129
Change-Id: I41ffffeca433faab2244ff3d1876ca078ce5ebfb
2023-06-29 20:59:27 +01: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
Brian Haley 81330921d8 Fix some pylint indentation warnings
Running with a stricter .pylintrc generates a lot of
C0330 warnings (hanging/continued indentation). Fix
the ones in neutron/agent and neutron/privileged/agent.

Trivialfix

Change-Id: Ib94257481e62b99b3d7648ae5137af5411b4867a
2022-12-01 16:22:24 +00:00
Rajesh Tailor 732c1dcbc2 Fix typos in error/log messages
This change fixes some typos in ERROR and LOG messages.

Change-Id: I4ec5b10cdd38bb8734b70d459b2afe99275cd8bd
2022-06-29 15:59:22 +05:30
Slawek Kaplonski 771fdc0b07 [DVR] Set arp entries only for IPs from the correct subnet
When dvr router is processing internal ports it is checking all
ports connected to the subnet and adding permanent arp entries for
all fixed IPs and allowed address pairs from those ports in the qrouter
namespace.
But port can have fixed IPs from different subnets, e.g. from IPv4 and
IPv6 subnet and until now Neutron wasn't checking subnet_id of the
fixed_ip address nor ip version of the allowed address pair's IP
address. That resulted in adding arp entries for all IPs through all
interfaces, e.g. IPv4 address was added as it's reachable through
interface connected to the IPv6 subnet.

This patch adds checking of the subnet_id for fixed_ips and ip version
for the allowed address pairs configured on the port to avoid that
problem.

Closes-Bug: #1936980
Change-Id: Id5afad7af74d69f8b4159163d23807a1cf032733
2021-09-24 09:51:30 +00:00
Zuul 6db2619628 Merge "[DVR] Set arp entries only for single IPs given as allowed addr pair" 2021-09-15 09:59:24 +00:00
Slawek Kaplonski 19375b3e78 [DVR] Set arp entries only for single IPs given as allowed addr pair
In allowed address pairs of the port there can be given not single IP
address but whole CIDR. In such case ARP entries for IPs from such
cidr will not be added in the DVR router namespace.

Closes-Bug: #1934912
Change-Id: I7bdefea943379125f93b116bb899446b874d9505
2021-08-26 19:08:56 +00:00
Zuul d1228f265b Merge "Populate self.floating_ips_dict using "ip rule" information" 2021-07-19 14:00:30 +00:00
Rodolfo Alonso Hernandez a03c240ef4 Populate self.floating_ips_dict using "ip rule" information
When the L3 agent starts, reads the floating IP rule priority from
a state file created by "FipRulePriorityAllocator". In case of not
having all floating IPs registers in this file, the method:
- Creates a new priority for this floating IP.
- Creates the "ip rule" in the namespace.
- Adds a new entry in "self.floating_ips_dict".

All "ip rules" present in the namespace that do not match the
registered fixed IP address ("from") and the priority assigned
are deleted.

Closes-Bug: #1891673
Closes-Bug: #1929821

Change-Id: Ia3fbde3304ab5f3c309dc62dbf58274afbcf4614
2021-07-08 15:40:08 +00:00
Hemanth Nakkina be7d0bb6ab Update arp entry of snat port on qrouter ns
In some cases, the arp entry of snat port is not updated
in qrouter namespace. l3-agent calls get_ports_by_subnet()
while setting arps for the subnet. And the snat port is
not returned if it is still unbound. One of the scenario
this is observed is when router is created, external
gateway set and internal subnet attached to router in
quick succession.

This patch retrieves snat port details from router info
as well and updates arp entry for snat port.

Closes-Bug: #1933092
Change-Id: I7ee797b4b930306cf6360922d855f8b24f1b813d
2021-07-02 17:06:43 +05:30
Rodolfo Alonso Hernandez 074c131b57 Disable pep8 import check for pyroute2 library
Since version 0.6.2, pyroute2 library dynamically imports the needed
modules when loaded. A static analysis will fail when checking the
import references.

Change-Id: I5aaf9494a2d5c2533199e6b92d4df8fe785f83a3
Closes-Bug: #1930750
2021-06-03 20:06:44 +00:00
Slawek Kaplonski 7b59b5069b [DVR] Send allowed address pairs info to the L3 agents
When new dvr router is going to be created on the node, L3 agent
asks server for list of ports plugged to the subnets, to populate
arp entries for all fixed IPs from those ports.
There was missing info about allowed address pairs there, so those
IPs were not populated in the qrouter namespace.
Now it's added and L3 agent can add those arp entries to the qrouter
namespaces too.

Closes-Bug: #1928466
Change-Id: I5d6c72c271ff450d9e43b3e33a99dd59d727882d
2021-05-18 12:58:23 +02:00
Rodolfo Alonso Hernandez 32193267f5 Replace "ip route" command in "dvr_local_router"
This is a leftover of the "ip route" command migration to Pyroute2.

A new paremeter, "proto", is added to the IP route add and list
commands. The default protocol used is "static".

Story: #2007686
Task: #41284
Related-Bug: #1492714

Change-Id: I319fd0611d3e8a3a09d6d4e077a17a622f74f51c
2021-03-15 16:05:28 +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
LIU Yulong 84d4fe177b [L3] Add missing address scope mark for IPv6 traffic
Any IPv6 traffic wants to go in/out directly on the DVR compute node
will be dropped by the mis-configured scope mark iptables rule. This
patch addresses this issue.

Closes-Bug: #1895401
Change-Id: Iee045e963e05f83d497e73bb39bb64c522f19543
2020-09-16 00:34:38 +00:00
Edward Hope-Morley 5eca44bfa8 Ensure fip ip rules deleted when fip removed
The information needed to delete ip rules associated
with fips is held in memory between add and remove so
a restart of the l3-agent results in any fips that
existed before the restart having their ip rules
persist after the fips are removed. This patch
enures that an agent restart reloads this information
so that ip rules associated with a fip are correctly
removed when the fip is removed.

Change-Id: If656a703c996ccc7719b1b09d793c5bbdfd6f3c1
Closes-Bug: #1891673
2020-08-18 20:39:10 +01:00
Brian Haley 4f10c3bd3f Remove usage of six.text_type and six.string_type
With python 3.x, six.text_type and six.string_type
are just str.

Also removed a six.integer_type since it was the only
one left in a file.

Another step in removing all of six usage from neutron.

Change-Id: I5208dc41bff1983ecd323286f427296b722da62a
2020-05-22 14:02:55 -04:00
LIU Yulong 5f2758bb80 Move arp device check out of loop
This could be time-consuming if there are lots of ports
under the router. So this patch moves the same device
check out of the loop.

Closes-Bug: #1856839
Change-Id: I2da856712aaafb77878628c52d19e0a5c7cdee0f
2020-01-04 15:48:11 +08:00
Brian Haley b79842f289 Start enforcing E125 flake8 directive
Removed E125 (continuation line does not distinguish itself
from next logical line) from the ignore list and fixed all
the indentation issues.  Didn't think it was going to be
close to 100 files when I started.

Change-Id: I0a6f5efec4b7d8d3632dd9dbb43e0ab58af9dff3
2019-07-19 23:39:41 -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
Swaminathan Vasudevan 30f35e08f9 Packets getting lost during SNAT with too many connections
We have a problem with SNAT with too many connections using the
same source and destination on the network nodes.

In addition we can see in the conntrack table that the who
"instert_failed" increases.

This might be a generic problem with conntrack and linux.
We suspect that we encounter the following "limitation / bug"
in the kernel.

There seems to be a workaround to alleviate this behavior by
setting the -random-fully flag in iptables for port consumption.

This patch fixes the problem by adding the --random-fully to
the SNAT rules.

Change-Id: I246c1f56df889bad9c7e140b56c3614124d80a19
Closes-Bug: #1814002
2019-04-12 10:12:04 -04:00
Boden R 9bbe9911c4 remove neutron.common.constants
All of the externally consumed variables from neutron.common.constants
now live in neutron-lib. This patch removes neutron.common.constants
and switches all uses over to lib.

NeutronLibImpact

Depends-On: https://review.openstack.org/#/c/647836/
Change-Id: I3c2f28ecd18996a1cee1ae3af399166defe9da87
2019-04-04 14:10:26 -06:00
Rodolfo Alonso Hernandez 0c6d76f210 Remove conntrack rule when FIP is deleted
Change-Id: Ia2bc8a7b5b27a5d4fbbfb7813cde7f022934bd22
Closes-Bug: #1818805
2019-03-28 14:45:56 +00:00
Zuul c21d922abd Merge "Fix pep8 E128 warnings in non-test code" 2019-03-15 11:37:27 +00:00
Brian Haley eaf990b2bc Fix pep8 E128 warnings in non-test code
Reduces E128 warnings by ~260 to just ~900,
no way we're getting rid of all of them at once (or ever).
Files under neutron/tests still have a ton of E128 warnings.

Change-Id: I9137150ccf129bf443e33428267cd4bc9c323b54
Co-Authored-By: Akihiro Motoki <amotoki@gmail.com>
2019-03-12 21:22:33 +00:00
Brian Haley 2ac0ee0b28 Fix pylint E1128 (assignment-from-no-return) in l3-agent
Changed migrate_centralized_floating_ip() to return a
status in DvrLocalRouter class.  Also changed the parent
method in RouterInfo class to return FLOATINGIP_STATUS_NOCHANGE,
which will cause the agent to not send an updated status for
the floating IP.

Also changed floating_ip_added_dist() to not use an
intermediate variable and just return directly.

Change-Id: I7dc4934308da95cf00a36b4ef1020aac7cef7d99
Closes-bug: #1816874
2019-03-12 13:43:58 +00:00
Doug Wiegley 7e208c3014 Bump pylint version to one that supports python3.7
The listed revision no longer supports python2, but afaik, we are
always running under python3 for those tests anyway.

Change-Id: Iba94d73eeb65fb21f5d098afe0fbe4348dbea850
2019-02-21 13:22:26 +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 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
Swaminathan Vasudevan cd0cc47a6a DVR: Centralized FloatingIPs are not cleared after migration.
With DVR routers, if a port is associated with a FloatingIP,
before it is used by a VM, the FloatingIP will be initially
started at the Network Node SNAT Namespace, since the port
is not bound to any host.

Then when the port is attached to a VM, the port gets its
host binding, and then the FloatingIP setup should be migrated
to the Compute host and the original FloatingIP in the Network
Node SNAT Namespace should be cleared.

But the original FloatingIP setup in SNAT Namespace was not
cleared by the agent.

This patch addresses the issue.

Change-Id: I55a16bcc0020087aa1abe76f5bc85cd64ccdaecd
Closes-Bug: #1796491
2018-11-13 16:25:04 -05:00
LIU Yulong ee7660f593 Install centralized floating IP nat rules to all ha nodes
For L3 DVR HA router, the centralized floating IP nat rules are not
installed in every HA node snat namespace. So, install the rules to
all the router snat-namespace on every scheduled HA router host.

Closes-Bug: #1793527
Change-Id: I08132510b3ed374a3f85146498f3624a103873d7
2018-10-06 02:40:52 +08:00
Zuul da396c3f47 Merge "DVR: Self recover from the loss of 'fg' ports in FIP Namespace" 2018-06-27 14:23:57 +00: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 5a7c12f245 DVR: Self recover from the loss of 'fg' ports in FIP Namespace
Sometimes we have seen the 'fg' ports within the fip-namespace
either goes down, not created in time or getting deleted due to
some race conditions.
When this happens, the code tries to recover itself after couple
of exceptions when there is a router_update message.
But after recovery we could see that the fip-namespace is
recreated and the 'fg-' port is plugged in and active, but the
'fpr' and the 'rfp' ports are missing which leads to the
FloatingIP failure.

This patch will fix this issue by checking for the missing devices
in all router_updates.

Change-Id: I78c7ea9f3b6a1cf5b208286eb372da05dc1ba379
Closes-Bug: #1776984
2018-06-15 14:25:42 -07: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
Brian Haley 7cfdf4aa81 Fix all pep8 E129 errors
Fixed all pep8 E129 errors and changed tox.ini to no longer
ignore them.

Change-Id: I0b06d99ce1d473b79a4cfdd173baa4f02e653847
2018-05-03 13:44:04 +09:00
Brian Haley c3b83a9ca6 Fix all pep8 E265 errors
Fixed all pep8 E265 errors and changed tox.ini to no longer
ignore them.  Also removed an N536 comment missed from a
previous change.

Change-Id: Ie6db8406c3b884c95b2a54a7598ea83476b8dba1
2018-04-30 16:35:52 -04:00
Zuul ffef5c0d01 Merge "DVR: Avoid address scope rules for dvr_no_external agents" 2018-04-09 21:30:07 +00:00
Swaminathan Vasudevan 7c4da6fb75 DVR: Avoid address scope rules for dvr_no_external agents
All FloatingIP for DVR_NO_EXTERNAL agents will be configured
in the SNAT Namespace. So there is no need to configure the
address scope related routes in the router namespace when the
agent is configured as DVR_NO_EXTERNAL.

Change-Id: I009dae9e7f485641f2f19dce8dd575da04bfb044
Related-Bug: #1753434
2018-04-05 08:37:08 -07: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
Swaminathan Vasudevan fbe308bdc1 DVR: Fix allowed_address_pair IP, ARP table update by neutron agent
Allowed_address_pair IP when associated with a network port will
inherit the services MAC.
Right now the ARP entry is updated with the last MAC that it is
associated with. But when allowed_address_pair IPs are used in
the context of VRRP the MAC keeps switching between the MASTER
and SLAVE. VRRP instance sends out GARP, but the ARP entry in the
router namespace is not getting updated based on the GARP.

This might cause the VRRP IP and the service using the IP to fail.

Since we having been adding the ARP entry with NUD state as
PERMANENT, the ARP entries are set for ever and does not adopt the
GARP sent out by the VRRP instance.

This will cause instances associated with DVR routers to have a
service interruption.

So the proposed patch will add the ARP entry for the Allowed address
pair with NUD for 'REACHABLE'.
This allows the Allowed_address_pair IP MAC to be updated on the
fly.

Change-Id: I43c3471f5d259e8c2ee1685398a06a4680c0bfcd
Closes-Bug: #1608400
2018-03-13 23:55:00 +00:00
Boden R f6de54fa4f use DVR constants from neutron-lib
The L3_AGENT_MODE_DVR_NO_EXTERNAL and DVR_SNAT_BOUND constants were
rehomed into neutron-lib with Ieb9374f5483a0ab2306592ab901686ca374db1c8
This patch consumes them by removing them from neutron and using the
constants from neutron-lib instead.

NeutronLibImpact

Change-Id: Ib63a523721a2fa3d1a978a729de28e6a2e560ef6
2018-02-23 09:17:02 -07:00
Daniel Russell af73882a9d Prevent LBaaS VRRP ports from populating DVR router ARP table
Prevents the MAC address of the VIP address of an LBaaS or
LBaaSv2 instance from populating in the DVR router ARP table

Change-Id: If49aaa48a5e95ccd0a236db984d3984a6e44c87c
Closes-Bug: 1733852
2017-12-08 08:30:45 +11:00
Jenkins 62b7881920 Merge "DVR: Fix unbound fip port migration to bound port" 2017-10-14 01:31:08 +00:00
Brian Haley 4f627b4e8d Change ip_lib network namespace code to use pyroute2
Change network namespace add/delete/list code to use
pyroute2 library instead of calling /sbin/ip.

Also changed all in-tree callers to use the new calls.

Closes-bug: #1717582
Related-bug: #1492714

Change-Id: Id802e77543177fbb95ff15c2c7361172e8824633
2017-10-04 21:09:28 +00:00
Swaminathan Vasudevan 27fcf86bcb DVR: Fix unbound fip port migration to bound port
With the current change in allowing the unbound fip
to be associated with the snat node, we are seeing
that all floating IPs that are associated with an
unbound port are created at the snat node.
This is also applicable for floating IPs that are
created just before associating the port to a VM.
We have seen such scenarios in the test cases.

This is the right behavior as per design. But when
the port is bound to a host, the floating IP should
be migrated to the respective host.

This patch fixes the issue by sending notification to
the respective node, when the port is bound and also
clear the fip from the snat node.

Closes-Bug: #1718788
Change-Id: I6b1f3ffc3c3336035632f6a82d3a87b3be57b403
2017-10-04 20:52:36 +00:00
Swaminathan Vasudevan afd1995d91 DVR: Fix agent to process only floatingips that have a host match
The agent is not currently checking for the host bound
before configuring the floatingip. That leads to
floatingips being configured on multiple hosts.

This is a partial fix on the agent side to prevent
configuring a floatingip ip that is not bound to
this host.

Related-Bug: #1712412
Related-Bug: #1713927

Change-Id: I1bc8c42425f97234f56412a2f109a996d9f896de
2017-08-31 15:22:27 -07:00
Jakub Libosvar 3270029261 dvr: Don't raise KeyError in _get_floatingips_bound_to_host
We thought _get_floatingips_bound_to_host is not needed but removing the
method caused sending garps for fip that doesn't belong to node during
the full-sync.

This patch just replaces dict lookup with get() method, so fips are
filtered based on presence on the host and if host is not set on fip, it
won't raise a KeyError.

Co-Authored-By: Swaminathan Vasudevan <SVasudevan@suse.com>

Related-bug: #1712412
Related-bug: #1713927

Change-Id: I0fbc772d757fb13b788f9df8d6d7d28d288d054a
2017-08-31 13:25:52 +00:00
Ihar Hrachyshka 7319c84455 Revert "DVR: _get_floatingips_bound_to_host throws KeyError"
This reverts commit 47fbc6157a.

Change-Id: I207b391fa9252e5639606b72d66234acb0ff9a4a
2017-08-30 20:34:14 +00:00