Skip to content
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

[config] Add more IP address validation checks #626

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

[config] Add more IP address validation checks #626

wants to merge 2 commits into from

Conversation

shikenghua
Copy link
Contributor

@shikenghua shikenghua commented Aug 30, 2019

- What I did
The below two cases will cause swss crash:

  1. Config /32(IPv4) or /128(IPv6) address on non-loopback interfaces
  2. Add the same IP subnet to two different interfaces

This is because duplicated route is added to SAI and it returns fail and cause swss raises exception.

Two checks are added when config IP on interface:

  1. /32(IPv4) and /128(IPv6) networks are only allowed on Loopback interfaces
  2. Newly added IP address shouldn't overlap with existing subnet

- How I did it
Perform validation checks in CLI configuration functions. Throw error if check fail.

- How to verify it
Use "config interface ip add/remove" commands to test. Config with invalid IP address should see error and vice versa.

- Previous command output (if the output of a command-line utility has changed)

  1. Config /32(IPv4) or /128(IPv6) address:
    admin@sonic:$sudo config interface ip add Ethernet0 1.1.1.1/32
    swss crash and error messages logged in /var/log/syslog:
    Nov 5 18:31:33.082312 sonic ERR swss#orchagent: :- addIp2MeRoute: Failed to create IP2me route ip:4.4.4.4, rv:-6
    Nov 5 18:31:33.082440 sonic INFO swss#supervisord: orchagent terminate called after throwing an instance of 'std::runtime_error'

  2. Config overlapped subnets:
    admin@sonic:$ sudo config interface ip add Ethernet0 10.1.1.1/24
    admin@sonic:$ sudo config interface ip add Ethernet1 10.1.1.2/24
    swss crash and error messages logged in /var/log/syslog:
    Nov 5 19:31:52.459171 sonic ERR swss#orchagent: :- addSubnetRoute: Failed to create subnet route to 10.1.1.2/24 from Ethernet4, rv:-6
    Nov 5 19:31:52.459855 sonic INFO swss#supervisord: orchagent terminate called after throwing an instance of 'std::runtime_error'

- New command output (if the output of a command-line utility has changed)

  1. Config /32(IPv4) or /128(IPv6) address:
    admin@sonic:$sudo config interface ip add Ethernet0 1.1.1.1/32
    Usage: config interface ip add [OPTIONS] <interface_name> <ip_addr>
    Error: Bad mask /32 for IP address 1.1.1.1/32
    admin@sonic:$sudo config interface ip add Ethernet0 2019::1/128
    Usage: config interface ip add [OPTIONS] <interface_name> <ip_addr>
    Error: Bad mask /128 for IP address 2019::1/128

  2. Config overlapped subnets:
    admin@sonic:$ sudo config interface ip add Ethernet0 10.1.1.1/24
    admin@sonic:$ sudo config interface ip add Ethernet1 10.1.1.2/24
    Usage: config interface ip add [OPTIONS] <interface_name> <ip_addr>
    Error: IP address 10.1.1.2/24 overlaps with existing subnet

-->

* /32(IPv4) and /128(IPv6) networks only allowed on Loopback interfaces
* Newly added IP address shouldn't overlap with existing subnet
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
@jleveque
Copy link
Contributor

jleveque commented Sep 9, 2019

Retest this please

@shikenghua shikenghua requested a review from jleveque September 19, 2019 07:46
@ITJamie
Copy link
Contributor

ITJamie commented Apr 19, 2022

Id like to see this added. its a nice safety check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants