-
Notifications
You must be signed in to change notification settings - Fork 1.8k
caclmgrd: correct IP2ME address logic #9826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/sonic-host-services/tests/caclmgrd/caclmgrd_ip2me_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| from swsscommon import swsscommon | ||
| from parameterized import parameterized | ||
| from sonic_py_common.general import load_module_from_source | ||
| from unittest import TestCase, mock | ||
| from pyfakefs.fake_filesystem_unittest import patchfs | ||
|
|
||
| from .test_ip2me_vectors import CACLMGRD_IP2ME_TEST_VECTOR | ||
| from tests.common.mock_configdb import MockConfigDb | ||
|
|
||
|
|
||
| DBCONFIG_PATH = '/var/run/redis/sonic-db/database_config.json' | ||
|
|
||
|
|
||
| class TestCaclmgrdIP2Me(TestCase): | ||
| """ | ||
| Test caclmgrd IP2Me | ||
| """ | ||
| def setUp(self): | ||
| swsscommon.ConfigDBConnector = MockConfigDb | ||
| test_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
| modules_path = os.path.dirname(test_path) | ||
| scripts_path = os.path.join(modules_path, "scripts") | ||
| sys.path.insert(0, modules_path) | ||
| caclmgrd_path = os.path.join(scripts_path, 'caclmgrd') | ||
| self.caclmgrd = load_module_from_source('caclmgrd', caclmgrd_path) | ||
| self.maxDiff = None | ||
|
|
||
| @parameterized.expand(CACLMGRD_IP2ME_TEST_VECTOR) | ||
| @patchfs | ||
| def test_caclmgrd_ip2me(self, test_name, test_data, fs): | ||
| if not os.path.exists(DBCONFIG_PATH): | ||
| fs.create_file(DBCONFIG_PATH) # fake database_config.json | ||
|
|
||
| MockConfigDb.set_config_db(test_data["config_db"]) | ||
| self.caclmgrd.ControlPlaneAclManager.get_namespace_mgmt_ip = mock.MagicMock() | ||
| self.caclmgrd.ControlPlaneAclManager.get_namespace_mgmt_ipv6 = mock.MagicMock() | ||
| caclmgrd_daemon = self.caclmgrd.ControlPlaneAclManager("caclmgrd") | ||
| ret = caclmgrd_daemon.generate_block_ip2me_traffic_iptables_commands('') | ||
| self.assertListEqual(test_data["return"], ret) |
159 changes: 159 additions & 0 deletions
159
src/sonic-host-services/tests/caclmgrd/test_ip2me_vectors.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| from unittest.mock import call | ||
|
|
||
| """ | ||
| caclmgrd ip2me block test vector | ||
| """ | ||
| CACLMGRD_IP2ME_TEST_VECTOR = [ | ||
| [ | ||
| "Only MGMT interface, no block", | ||
| { | ||
| "config_db": { | ||
| "MGMT_INTERFACE": { | ||
| "eth0|172.18.0.100/24": { | ||
| "gwaddr": "172.18.0.1" | ||
| } | ||
| }, | ||
| "LOOPBACK_INTERFACE": {}, | ||
| "VLAN_INTERFACE": {}, | ||
| "PORTCHANNEL_INTERFACE": {}, | ||
| "INTERFACE": {}, | ||
| "DEVICE_METADATA": { | ||
| "localhost": { | ||
| } | ||
| }, | ||
| }, | ||
| "return": [ | ||
| ], | ||
| }, | ||
| ], | ||
| [ | ||
| "One interface of each type, /32 - block all interfaces but MGMT", | ||
| { | ||
| "config_db": { | ||
| "LOOPBACK_INTERFACE": { | ||
| "Loopback0|10.10.10.10/32": {}, | ||
| }, | ||
| "VLAN_INTERFACE": { | ||
| "Vlan110|10.10.11.10/32": {}, | ||
| }, | ||
| "PORTCHANNEL_INTERFACE": { | ||
| "PortChannel0001|10.10.12.10/32": {}, | ||
| }, | ||
| "INTERFACE": { | ||
| "Ethernet0|10.10.13.10/32": {} | ||
| }, | ||
| "MGMT_INTERFACE": { | ||
| "eth0|172.18.0.100/24": { | ||
| "gwaddr": "172.18.0.1" | ||
| } | ||
| }, | ||
| "DEVICE_METADATA": { | ||
| "localhost": { | ||
| } | ||
| }, | ||
| }, | ||
| "return": [ | ||
| "iptables -A INPUT -d 10.10.10.10 -j DROP -m comment --comment 'Block IP2ME on interface Loopback0'", | ||
| "iptables -A INPUT -d 10.10.11.10 -j DROP -m comment --comment 'Block IP2ME on interface Vlan110'", | ||
| "iptables -A INPUT -d 10.10.12.10 -j DROP -m comment --comment 'Block IP2ME on interface PortChannel0001'", | ||
| "iptables -A INPUT -d 10.10.13.10 -j DROP -m comment --comment 'Block IP2ME on interface Ethernet0'" | ||
| ], | ||
| }, | ||
| ], | ||
| [ | ||
| "One interface of each type, /25 - block all interfaces but MGMT", | ||
| { | ||
| "config_db": { | ||
| "LOOPBACK_INTERFACE": { | ||
| "Loopback0|10.10.10.150/25": {}, | ||
| }, | ||
| "VLAN_INTERFACE": { | ||
| "Vlan110|10.10.11.100/25": {}, | ||
| }, | ||
| "PORTCHANNEL_INTERFACE": { | ||
| "PortChannel0001|10.10.12.100/25": {}, | ||
| }, | ||
| "INTERFACE": { | ||
| "Ethernet0|10.10.13.1/25": {} | ||
| }, | ||
| "MGMT_INTERFACE": { | ||
| "eth0|172.18.0.100/24": { | ||
| "gwaddr": "172.18.0.1" | ||
| } | ||
| }, | ||
| "DEVICE_METADATA": { | ||
| "localhost": { | ||
| } | ||
| }, | ||
| }, | ||
| "return": [ | ||
| "iptables -A INPUT -d 10.10.10.150 -j DROP -m comment --comment 'Block IP2ME on interface Loopback0'", | ||
| "iptables -A INPUT -d 10.10.11.100 -j DROP -m comment --comment 'Block IP2ME on interface Vlan110'", | ||
| "iptables -A INPUT -d 10.10.11.1 -j DROP -m comment --comment 'Block IP2ME (first IP) on interface Vlan110'", | ||
| "iptables -A INPUT -d 10.10.12.100 -j DROP -m comment --comment 'Block IP2ME on interface PortChannel0001'", | ||
| "iptables -A INPUT -d 10.10.13.1 -j DROP -m comment --comment 'Block IP2ME on interface Ethernet0'" | ||
| ], | ||
| }, | ||
| ], | ||
| [ | ||
| "One VLAN interface, /24, we are .1 -- regression testing to ensure compatibility with old behavior", | ||
| { | ||
| "config_db": { | ||
| "MGMT_INTERFACE": { | ||
| "eth0|172.18.0.100/24": { | ||
| "gwaddr": "172.18.0.1" | ||
| } | ||
| }, | ||
| "LOOPBACK_INTERFACE": {}, | ||
| "VLAN_INTERFACE": { | ||
| "Vlan110|10.10.11.1/24": {}, | ||
| }, | ||
| "PORTCHANNEL_INTERFACE": {}, | ||
| "INTERFACE": {}, | ||
| "DEVICE_METADATA": { | ||
| "localhost": { | ||
| } | ||
| }, | ||
| }, | ||
| "return": [ | ||
| "iptables -A INPUT -d 10.10.11.1 -j DROP -m comment --comment 'Block IP2ME on interface Vlan110'", | ||
| ], | ||
| }, | ||
| ], | ||
| [ | ||
| "One interface of each type, IPv6, /64 - block all interfaces but MGMT", | ||
| { | ||
| "config_db": { | ||
| "LOOPBACK_INTERFACE": { | ||
| "Loopback0|2001:db8:10::/64": {}, | ||
| }, | ||
| "VLAN_INTERFACE": { | ||
| "Vlan110|2001:db8:11::/64": {}, | ||
| }, | ||
| "PORTCHANNEL_INTERFACE": { | ||
| "PortChannel0001|2001:db8:12::/64": {}, | ||
| }, | ||
| "INTERFACE": { | ||
| "Ethernet0|2001:db8:13::/64": {} | ||
| }, | ||
| "MGMT_INTERFACE": { | ||
| "eth0|2001:db8:200::200/64": { | ||
| "gwaddr": "2001:db8:200::100" | ||
| } | ||
| }, | ||
| "DEVICE_METADATA": { | ||
| "localhost": { | ||
| } | ||
| }, | ||
| }, | ||
| "return": [ | ||
| "ip6tables -A INPUT -d 2001:db8:10:: -j DROP -m comment --comment 'Block IP2ME on interface Loopback0'", | ||
| "ip6tables -A INPUT -d 2001:db8:11:: -j DROP -m comment --comment 'Block IP2ME on interface Vlan110'", | ||
| "ip6tables -A INPUT -d 2001:db8:11::1 -j DROP -m comment --comment 'Block IP2ME (first IP) on interface Vlan110'", | ||
| "ip6tables -A INPUT -d 2001:db8:12:: -j DROP -m comment --comment 'Block IP2ME on interface PortChannel0001'", | ||
| "ip6tables -A INPUT -d 2001:db8:13:: -j DROP -m comment --comment 'Block IP2ME on interface Ethernet0'" | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.