Commit Graph

99 Commits

Author SHA1 Message Date
Dr. Jens Harbott 2ed9834047 Fix invalid IP address representation in unit test
An IP address may not have a leading zero in any of its octets, this is
getting enforced by the latest netaddr library.

Partial-Bug: 2054203
Change-Id: I15cd049de1511a9b52e8e28bccec87060c2f1411
2024-02-19 10:16:49 +00:00
Takashi Kajinami 656028f311 Remove logic for old LBaaS(v2)
There are some logic left which checks device owner values set by
LBaaS v1 or v2, but LBaaS was already retired in favor of Octavia.

Change-Id: Ieca7a29a45f0686babe68619ff9da133edd89dec
2023-11-28 11:27:02 +00:00
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
Takashi Natsume 76cf6b4a9e Fix deprecation warnings in pkg_resources
Fix the following deprecation warnings.

  PkgResourcesDeprecationWarning:
  <MagicMock name='execute().split().__getitem__().__getitem__()'
  id='140417024565696'> is an invalid version and will not be
  supported in a future release

  DeprecationWarning: Creating a LegacyVersion has been
  deprecated and will be removed in the next major release

Change-Id: I23540114120f6ea52754116cfaaeac35e09543b4
Closes-Bug: 1986428
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
2022-08-13 22:53:21 +09:00
Edward Hope-Morley 36bf1df46d Partially revert "Do not link up HA router gateway in backup node"
This partially reverts commit c52029c39a.

We revert everything except one minor addition to
neutron/agent/l3/ha_router.py which ensures that ha_confs path is
created when the keepalived manager is initialised.

Closes-Bug: #1965297
Change-Id: I14ad015c4344b32f7210c924902dac4e6ad1ae88
2022-05-24 11:24:30 +00:00
labedz f430cd0072 Don't set HA ports down while L3 agent restart.
Because of the fix for bug[1] and issue with linux_utils
get_process_count_by_name() L3 agent puts all it's HA ports down
during initialization phase. Unfortunately such operation can break
already working L3 communication. Rewiring ha-* port from down state to
up can takes few seconds and some VRRP packages could be lost then.
That triggers keepalived on other node so router HA state change
may be triggered.

This change prevents putting HA ports down when during initialization
phase L3 agent finds already configured own net namespaces. Existance
of such net namespace is a good proof that there is a network
configuration existing so host wasn't rebooted so most probably it is
just agent restart.

[1] https://bugs.launchpad.net/neutron/+bug/1597461

Closes-Bug: #1959151
Change-Id: Id9c906b2d141c3bedd80fb5f868190f8a4b66f54
2022-03-01 14:27:42 +00:00
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 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
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
Slawek Kaplonski 0d8ae15767 Remove update_initial_state() method from the HA router
This method was intended to check state of the HA router on the
node and update it in the neutron server.
Patch [1] added check of the initial status to the
neutron_keepalived_state_change_monitor process.
It also could cause some race conditions and event which is setting
correct state of the router will be not processed thus router may endup
with two nodes with "primary" state in the Neutron's DB.

Neutron_keepalived_state_change_monitor was notifying agent about
router's initial state only if this state was 'primary'.
Now it will notify agent always to let agent set router's state as
'backup' if needed (that was previously done by this removed
update_initial_state() method).

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

Change-Id: I2cc58c30cf844ee0ecf0611ecdec430086464790
Closes-Bug: #1916022
2021-02-23 14:58:29 +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
Zuul bdee7b0c58 Merge "Ensure fip ip rules deleted when fip removed" 2020-09-08 10:17:55 +00:00
Brian Haley 055036ba2b Improve terminology in the Neutron tree
There is no real reason we should be using some of the
terms we do, they're outdated, and we're behind other
open-source projects in this respect. Let's switch to
using more inclusive terms in all possible places.

Change-Id: I99913107e803384b34cbd5ca588451b1cf64d594
2020-08-19 16:47:53 -04: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 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
LIU Yulong c52029c39a Do not link up HA router gateway in backup node
L3 router will set its devices link up by default.
For HA routers, the gateway device will be pluged
in all scheduled hosts. When the gateway deivce is
up in backup node, it will send out IPv6 related
packets (MLDv2) according to some kernal config.
This will cause the physical fabric think that the
gateway MAC is now working in the backup node. And
finally the master node L3 traffic will be broken.

This patch sets the backup gateway device link down
by default. When the VRRP sets the master state in
one host, the L3 agent state change procedure will
do link up action for the gateway device.

Closes-Bug: #1859832
Change-Id: I8dca2c1a2f8cb467cfb44420f0eea54ca0932b05
2020-03-25 16:09:42 +08: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
LIU Yulong 7a9d6d2641 Do not initialize snat-ns twice
If the DVR+HA router has external gateway, the snat-namespace will be
initialized twice during agent restart. And that ns initialization
function will run many external resource processing actions which will
definitely increase the starting time of L3 agent. This patch addresses
this issue.

Change-Id: I7719491275fa1ebfa7e881366e5cb066e3d4185c
Closes-Bug: #1850779
2019-11-07 06:42:08 +00: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
Sławek Kapłoński b09b44608b Remove deprecated 'external_network_bridge' option
This option is deprecated and marked to be deleted in Ocata. So
as we are now in Stein development cycle I think that it's good time
to remove it.

Change-Id: I07474713206c218710544ad98c08caaa37dbf53a
2019-03-09 22:07:38 +00:00
Doug Wiegley 8914f8247f Update neutron files for new over-indentation hacking rule (E117)
Change-Id: I594e2d1238f6ffa3c1039624e3b3ed6569485837
2019-01-29 15:36:20 -05: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
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
LIU Yulong 656a8f8729 Do not install centralized FIP if HA port is down
The issue scenario happens when we disassociate a floating IP
while the 'master' router host is restarted or powered-off.

When the L3 agent is powered-on again, the HA router state config
still remains 'master', but the ha port is down. And the message
queue still has one 'router_update' message (floating IP
disassociate message), so the L3 agent will sync this router info
at least twice during the restart, one is the router_update, the
other is the L3 agent full-sync.

The first one will add the centralized FIP to the qg-device, because
the router state is 'master'. So for DVR HA routers, only add the
centralized floating IP to the qg-device in the snat-namespace when
the HA port is up. For the restart procedure, if the HA port is up,
but the router is set to 'backup', do not add the floating IP.

Closes-Bug: #1794305
Change-Id: Ib39fe7dcd437a867c69852885c461a594167f6a1
2018-09-28 13:15:34 +00: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
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
zhsun 2200b1c369 Add/rm centralized fips for DVR+HA from standby node
For DVR+HA:
When adding/removing a centralized fip, just add/remove it to/from
keepalived instance and do not check if it is a master router.

When adding a centralized fip, it is still needed to invoke method
of supperclass to configure nat rules on master node.

When removing a centralized fip, it is still needed to invoke method
of supperclass to clean contrack on master node.

Change-Id: I202db59acb7fb0b7924748cf7def2879a748e56a
Closes-Bug: #1736068
2018-02-05 17:28:23 +08:00
Zuul 4b609f9206 Merge "Add missing iptable rule in snat ns for centralized fips." 2018-01-12 05:56:16 +00:00
zhsun 0f08b2c625 Add missing iptable rule in snat ns for centralized fips.
The following iptable rule should be added to snat ns:
"-A neutron-l3-agent-snat -j neutron-l3-agent-float-snat",
or the snat rule will take effect instead of centralized fips
when accessing to the outside for vms.
Closes-Bug: #1735866

Change-Id: I286283bfb4dbf935a34c5919ee0af5225e75fac9
2018-01-09 22:44:18 +00: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 1077184d8d Merge "Refactoring agent linux&ovsdb config" 2017-09-13 00:33:56 +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
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
sindhu devale 51ca683797 Refactoring agent linux&ovsdb config
Refactoring neutron agent linux and ovsdb config opts
to be in neutron/conf/agent so that all the config options
reside in a centralized location. This simplifies the
process of looking up the config opts and provides an easy
way to import.

NeutronLibImpact

Change-Id: Ib1e0e63dec2985c417412d1ecc68e2a74ef87182
Partial-Bug: #1563069
2017-08-25 10:41:39 -04:00
Swaminathan Vasudevan 47fbc6157a DVR: _get_floatingips_bound_to_host throws KeyError
_get_floatingips_bound_to_host function was introduced
recently in dvr_local_router to retrieve the external
interface name for centralizing the floatingip.

This function was throwing a 'KeyError' on fip['host'] and
not required for centralized floatingips anymore.

The get_external_device_interface_name in dvr_local_router
will try to get the 'fg' interface that is required for
the bound floating-ips to clear up some of the rules.
In the case of the centralized unbound floating-ips, the
'qg' external interface is retreived from
get_snat_external_device_interface_name that is defined
in 'dvr_edge_router' and based on the namespace.

So _get_floatingips_bound_to_host can be removed from
get_external_device_inteface_name.

Closes-Bug: 1712412

Change-Id: I94c0a071df32f572745a2c29942956c3da9f309b
2017-08-24 16:03:27 -07:00
Swaminathan Vasudevan 8b4bb9c0b0 DVR: Configure centralized floatingips to snat_namespace.
This patch is the agent side patch that takes care of configuring
the centralized floatingips for the unbound ports in the snat_namespace.

Change-Id: I595ce4d6520adfd57bacbdf20ed03ffefd0b190a
Closes-Bug: #1583694
2017-08-08 10:44:45 -07:00
Tong Liu cf3b963618 Fix some pep8 errors under l3 unit tests
TrivialFix

Change-Id: Ibd64ea7f70937caf83ceb4efc2ad52d00a66487c
2017-07-31 13:27:07 +00:00
Swaminathan Vasudevan dba107be0e DVR: Add forwarding routes based on address_scopes
When we create agent gateway port on all the nodes irrespective
of the floatingips we can basically use that agent gateway port to
forward traffic in and out of the nodes if the address_scopes match,
since we don't need SNAT functionality if address scopes match.

If a gateway is configured and if it has internal ports that belong
to the same address_scopes then no need to add the redirect rules.
At the same we should also add a static route in the fip namespace
for every interface that is connected to the router that belongs to
the same address scope.

Change-Id: I617e2fc5a70852c6f2e925ac7244f2a205d60de4
Closes-Bug: #1577488
2017-06-15 10:28:13 -07:00
Ihar Hrachyshka 0fecc04d7a Revert "DVR: Add forwarding routes based on address_scopes"
This reverts commit fb2093c365.

This patch started spamming logstash like crazy with ERRORs.

Closes-Bug: #1693539
Change-Id: I81627f1bac1b981f930b66c126abd8285653bf49
2017-05-25 15:52:02 +00:00
Swaminathan Vasudevan fb2093c365 DVR: Add forwarding routes based on address_scopes
When we create agent gateway port on all the nodes irrespective
of the floatingips we can basically use that agent gateway port to
forward traffic in and out of the nodes if the address_scopes match,
since we don't need SNAT functionality if address scopes match.

If a gateway is configured and if it has internal ports that belong
to the same address_scopes then no need to add the redirect rules.
At the same we should also add a static route in the fip namespace
for every interface that is connected to the router that belongs to
the same address scope.

Change-Id: Iaf6d3b38b1fb45772cf0b88706586c057ddb0230
Closes-Bug: #1577488
2017-04-27 11:56:51 -07:00