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

API Proposal: IPNetwork to support CIDR notation #64033

Closed
alrz opened this issue Jan 20, 2022 · 6 comments
Closed

API Proposal: IPNetwork to support CIDR notation #64033

alrz opened this issue Jan 20, 2022 · 6 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Net
Milestone

Comments

@alrz
Copy link

alrz commented Jan 20, 2022

Background and motivation

An implementation is exposed through HttpOverrides middleware package at https://github.com/dotnet/aspnetcore/blob/main/src/Middleware/HttpOverrides/src/IPNetwork.cs

This proposal is to promote it under System.Net namespace for a built-in support.

API Proposal

namespace System.Net
{
    public struct IPNetwork
    {
        // eg: "192.168.0.0/16"
        public static IPNetwork Parse(string);
        public IPNetwork(IPAddress, IPAddress);
        public IPNetwork(IPAddress, int);
        public bool Contains(IPAddress);
        // ..
    }
}

API Usage

var range = IPNetwork.Parse(cidr);
bool result = range.Contains(address);

Alternative Designs

No response

Risks

No response

@alrz alrz added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jan 20, 2022
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Net untriaged New issue has not been triaged by the area owner labels Jan 20, 2022
@ghost
Copy link

ghost commented Jan 20, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and motivation

An implementation is exposed through HttpOverrides middleware package at https://github.com/dotnet/aspnetcore/blob/main/src/Middleware/HttpOverrides/src/IPNetwork.cs

This proposal is to promote it under System.Net namespace for a built-in support.

API Proposal

namespace System.Net
{
    public struct IPNetwork
    {
        // eg: "192.168.0.0/16"
        public static IPNetwork Parse(string);
        public IPNetwork(IPAddress, IPAddress);
        public IPNetwork(IPAddress, int);
        public bool Contains(IPAddress);
        // ..
    }
}

API Usage

var range = IPNetwork.Parse(cidr);
bool result = range.Contains(address);

Alternative Designs

No response

Risks

No response

Author: alrz
Assignees: -
Labels:

api-suggestion, area-System.Net, untriaged

Milestone: -

@alrz
Copy link
Author

alrz commented Jan 20, 2022

Relates to #42845

@pinkfloydx33
Copy link

Would this also include support for a built-in type converter (or similar) that would allow binding configuration containing such values?

At the moment we rely on a custom type converter to bind configuration containing such values (primarily for forwarded headers and ip whitelisting). We add the converters using TypeDescriptor.AddAttributes via a module Initializer in our shared library, but it's my understanding that it may not necessarily be safe to rely upon and only by chance has continued to work.

It would be nice to not need to do this and just have it work out of the box.

@scalablecory
Copy link
Contributor

We previously rejected a CIDR proposal due to lack of customer demand: #36428

@karelz
Copy link
Member

karelz commented Feb 15, 2022

Triage: Still not high enough demand. Other libraries exist that solve it. Not desperately needed in BCL.

@karelz
Copy link
Member

karelz commented Feb 15, 2022

Duplicate of #36428

@karelz karelz marked this as a duplicate of #36428 Feb 15, 2022
@karelz karelz closed this as completed Feb 15, 2022
@karelz karelz added this to the 7.0.0 milestone Feb 15, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Mar 17, 2022
@karelz karelz removed the untriaged New issue has not been triaged by the area owner label Oct 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Net
Projects
None yet
Development

No branches or pull requests

4 participants