Comment 4 for bug 2054203

Revision history for this message
Takashi Kajinami (kajinamit) wrote :

Please note this may affect wider patterns which were previously accepted.

For example with netaddr < 1.0.0, "10/8" is a valid representation of subnet and is translated to 10.0.0.0/8 .

Type "help", "copyright", "credits" or "license" for more information.
>>> import netaddr
>>> netaddr.IPNetwork('10/8')
IPNetwork('10.0.0.0/8')

However with netaddr >= 1.0.0, which uses INET_PTON, this is no longer accepted

>>> import netaddr
>>> netaddr.IPNetwork('10/8')
Traceback (most recent call last):
  File "/home/tkajinam/venv/lib/python3.11/site-packages/netaddr/strategy/ipv4.py", line 124, in str_to_int
    return _struct.unpack('>I', _inet_pton(AF_INET, addr))[0]
                                ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: illegal IP address string passed to inet_pton

Currently with netaddr < 1.0.0, neutron supports that INET_ATON compliant format.

```
[root@localhost ~]# openstack subnet create --debug --network testnetwork --subnet-range 10/8 testsubnet
...
REQ: curl -g -i -X POST http://127.0.0.1:9696/v2.0/subnets -H "Content-Type: application/json" -H "User-Agent: openstacksdk/2.1.0 keystoneauth1/5.5.0 python-requests/2.25.1 CPython/3.9.18" -H "X-Auth-Token: {SHA256}f5f8310eff9da291b1ed3a851365033bc771153d5f148ecd59b969d2d32ce32a" -d '{"subnet": {"name": "testsubnet", "network_id": "156e8829-3b7c-45b1-8678-c35d625e0af4", "ip_version": 4, "cidr": "10/8"}}'
http://127.0.0.1:9696 "POST /v2.0/subnets HTTP/1.1" 201 608
RESP: [201] Connection: keep-alive Content-Length: 608 Content-Type: application/json Date: Tue, 20 Feb 2024 15:10:06 GMT X-Openstack-Request-Id: req-455d7d7b-8de3-45ab-b75c-a6b9f505838d
RESP BODY: {"subnet":{"id":"3ba2fa27-5931-4acc-bba5-3383232cd112","name":"testsubnet","tenant_id":"2e1290f8bdc44d35bce981db68fb54a2","network_id":"156e8829-3b7c-45b1-8678-c35d625e0af4","ip_version":4,"subnetpool_id":null,"enable_dhcp":true,"ipv6_ra_mode":null,"ipv6_address_mode":null,"gateway_ip":"10.0.0.1","cidr":"10.0.0.0/8","allocation_pools":[{"start":"10.0.0.2","end":"10.255.255.254"}],"host_routes":[],"dns_nameservers":[],"description":"","service_types":[],"tags":[],"created_at":"2024-02-20T15:10:05Z","updated_at":"2024-02-20T15:10:05Z","revision_number":0,"project_id":"2e1290f8bdc44d35bce981db68fb54a2"}}
POST call to network for http://127.0.0.1:9696/v2.0/subnets used request id req-455d7d7b-8de3-45ab-b75c-a6b9f505838d
+----------------------+--------------------------------------+
| Field | Value |
+----------------------+--------------------------------------+
| allocation_pools | 10.0.0.2-10.255.255.254 |
| cidr | 10.0.0.0/8 |
| created_at | 2024-02-20T15:10:05Z |
| description | |
| dns_nameservers | |
| dns_publish_fixed_ip | None |
| enable_dhcp | True |
| gateway_ip | 10.0.0.1 |
| host_routes | |
| id | 3ba2fa27-5931-4acc-bba5-3383232cd112 |
| ip_version | 4 |
| ipv6_address_mode | None |
| ipv6_ra_mode | None |
| name | testsubnet |
| network_id | 156e8829-3b7c-45b1-8678-c35d625e0af4 |
| project_id | 2e1290f8bdc44d35bce981db68fb54a2 |
| revision_number | 0 |
| segment_id | None |
| service_types | |
| subnetpool_id | None |
| tags | |
| updated_at | 2024-02-20T15:10:05Z |
+----------------------+--------------------------------------+
```

But this is no longer accepted with netaddr 1.0.0 .