Allow specifying 0 for PortRangeMin/PortRangeMax in security group rule · Issue #3644 · gophercloud/gophercloud · GitHub
Skip to content

Allow specifying 0 for PortRangeMin/PortRangeMax in security group rule #3644

Description

@arasHi87

What is missing?

Description

Fixes the inability to explicitly set an ICMP Type of 0 in Security Group Rules.

Root Cause

Currently, the PortRangeMin and PortRangeMax fields use the omitempty JSON tag. In Go, setting an integer to 0 triggers this tag, causing the JSON marshaler to completely omit the field from the API payload.

When creating a security group rule for the icmp protocol, OpenStack Neutron uses port_range_min to define the ICMP Type and port_range_max to define the ICMP Code. Because 0 is a valid ICMP Type (e.g., Echo Reply), the omitempty tag prevents the user from successfully sending {"port_range_min": 0} to the API. Consequently, Neutron receives a request with an ICMP Code but a missing ICMP Type, resulting in a `400 Bad Request.

failed to create security group rule in openstack: Expected HTTP response code [201 202] when accessing [POST http://10.32.50.10:9696/v2.0/security-group-rules], but got 400 instead: {\"NeutronError\": {\"type\": \"SecurityGroupMissingIcmpType\", \"message\": \"ICMP code (port-range-max) 255 is provided but ICMP type (port-range-min) is missing.\", \"detail\": \"\"}}

Solution

By changing the struct fields to *int pointers, we can distinguish 0 from nil. This allows 0 to be safely marshaled without the omitempty tag dropping it.

I noticed this issue has been open since 2019, so I would love to help get it resolved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions