Skip to content

Changes to networking cidr/inet mapping #5136

@roji

Description

@roji

Npgsql currently PG cidr to .NET ValueTuple<IPAddress, int> by default, and also allows mapping inet to it. There's also an obsolete NpgsqlInet mutable struct. For 8.0, we'll do the following changes:

  • We'll un-obsolete NpgsqlInet, make it an immutable struct and clean it up.
    • IPAddress will remain the default mapping for inet, as that's what most users use it for.
    • Note that as before, reading an inet with a non-full netmask silently truncates the value. This seems reasonable as the primary usage of inet is to store simple host IPs (i.e. IPAddress). If the netmask component is significant, NpgsqlInet mapping can be used instead.
  • We'll also introduce a similar immutable NpgsqlCidr struct, and remove the value tuple mapping.
  • NpgsqlCidr will be the default mapping for cidr, as that type is used to represent networks, where both the IP and netmask components are important.
  • The ValueTuple mapping will be removed.

Some notes on why it makes sense to have separate NpgsqlInet and NpgsqlCidr types for PG inet and cidr:

  • inet can represent a single IP Address, and so should be constructible/castable from one; that's not the case for cidr.
  • inet ToString doesn't output the netmask if it has all bits (32 for IPv4/128 for IPv6). This doesn't really make sense for cidr.
  • Having a separate CLR type for cidr would allow mapping it by default without requiring explicit specification of NpgsqlDbType/DataTypeName.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions