dropbox / nsot

Network Source of Truth is an open source IPAM and network inventory database
https://nsot.readthedocs.io
Other
399 stars 66 forks source link

Closest parent returns erroneous result #209

Closed dmar42 closed 8 years ago

dmar42 commented 8 years ago

The closest_parent function for a network resources doesn't seem to always work correctly. In the example below, using the network of 10.0.0.185/32 incorrectly returns 10.0.0.0/25. However, parent correctly returns 10.0.0.0/24.

This same behavior appears to apply to both assigned and unknown addresses.

Example nsot API call outputs:

GET /api/networks/10.0.0.185/32/closest_parent/?format=json
{
    "parent_id": 26690,
    "state": "allocated",
    "prefix_length": 25,
    "is_ip": false,
    "ip_version": "4",
    "network_address": "10.0.0.0",
    "attributes": {
    "comment": "foo",
    "usage": "fabric"
    },
    "site_id": 1,
    "id": 26691
}
GET /api/networks/10.0.0.185/32/parent/?format=json
{
    "parent_id": null,
    "state": "allocated",
    "prefix_length": 24,
    "is_ip": false,
    "ip_version": "4",
    "network_address": "10.0.0.0",
    "attributes": {
    "comment": "foo",
    "usage": "fabric"
    },
    "site_id": 1,
    "id": 26690
}
GET /api/networks/10.0.0.0/24/children/?format=json
[
    {
        "parent_id": 26690,
        "state": "allocated",
        "prefix_length": 25,
        "is_ip": false,
        "ip_version": "4",
        "network_address": "10.0.0.0",
        "attributes": {
        "comment": "foo",
        "usage": "fabric"
        },
        "site_id": 1,
        "id": 26691
    },
    {
        "parent_id": 26690,
        "state": "assigned",
        "prefix_length": 32,
        "is_ip": true,
        "ip_version": "4",
        "network_address": "10.0.0.185",
        "attributes": {},
        "site_id": 1,
        "id": 37407
    },
    {
        "parent_id": 26690,
        "state": "assigned",
        "prefix_length": 32,
        "is_ip": true,
        "ip_version": "4",
        "network_address": "10.0.0.189",
        "attributes": {},
        "site_id": 1,
        "id": 37416
    }
]
jathanism commented 8 years ago

Well this one is a doozy. Simple enough bug. Just need to make sure that we're considering prefix length for candidate ancestors.