IP Route: subnet's host_houtes attribute and router's routes accept the invalidate subnets.

Bug #1805991 reported by longqian.zhao
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Low
longqian.zhao

Bug Description

Bug Description

 Description:
 The type:hostroutes validator is not properly validating subnets that have non-zero values in the host portion of the network address (e.g., 1.2.3.1/24 rather than 1.2.3.0/24). This can cause issues for backends/drivers that assume that the data coming down from the server is valid.
 For example, using those values with the Linux command line utilities will result in an error:

 $ sudo ip route add 192.0.2.5/24 via 192.168.1.2
 RTNETLINK answers: Invalid argument

 But using the correct network address value results in a successful operation:
 $ sudo ip route add 192.0.2.0/24 via 192.168.1.2

 The issue can be reproduced on the latest devstack

 Version: openstack_latest in latest devstack

 scenario 1: subnet's host_routes
 Steps to reproduce:
 1. create network
  $ openstack network create TestNet

 2. create subnet
  $ openstack subnet create TestSubnet --host-route destination=10.10.10.1/24,gateway=10.10.10.1 --network=TestNet --subnet-range 10.10.10.0/24
  Expected output:'10.10.10.1/24' isn't a recognized IP subnet cidr, '10.10.10.0/24' is recommended.
  Actual output: success

 scenario 2: router's routes
 Steps to reproduce:
 1. create router
  $ openstack router create TestRouter

 2. add subnet to router
  $ openstack router add subnet TestRouter TestSubnet

 3. set the router
  $ openstack router set --route destination=10.10.10.1/24,gateway=10.10.10.17 TestRouter
  Expected output:'10.10.10.1/24' isn't a recognized IP subnet cidr, '10.10.10.0/24' is recommended.
  Actual output: success

longqian.zhao (longqian)
Changed in neutron:
assignee: nobody → longqian.zhao (longqian)
assignee: longqian.zhao (longqian) → nobody
longqian.zhao (longqian)
Changed in neutron:
assignee: nobody → longqian.zhao (longqian)
Changed in neutron:
status: New → Confirmed
importance: Undecided → Low
Revision history for this message
Bence Romsics (bence-romsics) wrote :

Thank you for your bug report.

I managed to reproduce the problem with:

neutron master @ dd14501c12243a8e5fb4086ba461482e54ac75bc and more importantly
neutron-lib master @ 1e6a07c5fc8275b11044091cfbd0b580d3a0ebd3.

This is the first error message I see in the l3-agent log.

# journalctl -u devstack@neutron-l3
dec 03 11:32:13 devstack0 neutron-l3-agent[24589]: DEBUG neutron.agent.linux.utils [-] Running command (rootwrap daemon): ['ip', 'netns', 'exec', 'qrouter-64e58dbe-21ed-4a5d-a9ac-32236b627f3a', 'ip', 'route', 'replace', 'to', '10.10.10.1/
24', 'via', '10.10.10.17'] {{(pid=24589) execute_rootwrap_daemon /opt/stack/neutron/neutron/agent/linux/utils.py:103}}
dec 03 11:32:13 devstack0 neutron-l3-agent[24589]: ERROR neutron.agent.linux.utils [-] Exit code: 2; Stdin: ; Stdout: ; Stderr: Error: Invalid prefix for given prefix length.

I'm setting the importance to 'low', because it looks like to me there's no regression introduced here.

Looking at the code (starting here https://github.com/openstack/neutron-lib/blob/master/neutron_lib/api/validators/__init__.py#L1086) I'm wondering if we should consider this bug to have its root cause in validate_subnet() instead of in validate_hostroutes() because that's what validate_hostroutes calls.

As a first attempt I'd suggest improving the subnet validation by rejecting subnet definitions in the format 'IP/prefix' instead of the conventional 'network address/prefix' format. Technically that seems easy with netaddr:

>>> import netaddr
>>> n = netaddr.IPNetwork('1.2.3.4/24')
>>> if n.ip != n.network:
>>> ... the expected error message

Then tests and reviewers could tell if narrowing what we consider valid subnet input works out or we have to think about an alternative. I'm assuming you're working on a patch since you assinged the bug to yourself.

Changed in neutron:
status: Confirmed → Triaged
Revision history for this message
longqian.zhao (longqian) wrote :

a new infomation:
    scenario 2: router's routes

    when I run the command " openstack router set --router destination=10.10.10.1/24,gateway=10.10.10.17 TestRouter ", the debug informations is: "Stderr: RTNETLINK answers: Invalid argument".

Revision history for this message
longqian.zhao (longqian) wrote :

Thanks, The solution we are going to commit is similar to yours.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron-lib (master)

Fix proposed to branch: master
Review: https://review.openstack.org/623415

Changed in neutron:
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to neutron (master)

Related fix proposed to branch: master
Review: https://review.openstack.org/623420

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron-lib (master)

Reviewed: https://review.openstack.org/623415
Committed: https://git.openstack.org/cgit/openstack/neutron-lib/commit/?id=7da36840989c29d27903283785fdc7b8723b5ecc
Submitter: Zuul
Branch: master

commit 7da36840989c29d27903283785fdc7b8723b5ecc
Author: longqianzhao <email address hidden>
Date: Sat Dec 8 00:23:37 2018 +0800

    Modify the judgment method of CIDR and Add utests

    The routing table could not add information, because
    the original method could not identify the invalid CIDR.
    This patch modify the judgement method. It will help
    the router working normally.

    Co-Authored-By: Allain Legacy <email address hidden>

    Change-Id: I4db2e35303492aeda7e14cf9d525cc9b4a54ac36
    Closes-Bug: #1805991
    Story: 2004567

Changed in neutron:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron-lib 1.22.0

This issue was fixed in the openstack/neutron-lib 1.22.0 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to neutron (master)

Reviewed: https://review.openstack.org/623420
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=4cbaa060316441b1d3dae58c6d0928789037213b
Submitter: Zuul
Branch: master

commit 4cbaa060316441b1d3dae58c6d0928789037213b
Author: longqianzhao <email address hidden>
Date: Fri Dec 7 23:18:36 2018 +0800

    Add test cases: invalidate CIDR

    Add the invalid CIDR for verifing the modified
    method is valid.

    Co-Authored-By: Allain Legacy <email address hidden>

    Depends-On: https://review.openstack.org/623415/
    Change-Id: I0f051130e4708682104bd935b23991b534fc99d2
    Related-Bug: #1805991
    Story: 2004567

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.