Re: [HACKERS] cidr

From: darcy(at)druid(dot)net (D'Arcy J(dot)M(dot) Cain)
To: maillist(at)candle(dot)pha(dot)pa(dot)us (Bruce Momjian)
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] cidr
Date: 1998-07-23 13:58:19
Message-ID: m0yzLsy-00006FC@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thus spake Bruce Momjian
> OK, let me explain what I think Paul was saying. cidr is used for
> networks. You can use it for hosts by specifying /32. It is not the
> same as a netmask. For example:
>
> host 192.24.45.32

Right but a netmask could be specified as 255.255.255.0/32. Better yet,
if all you want to store is a netmask in a field, use an int. Every
netmask can be specified in dotted notation or as a mask length.

> My idea is to internally store the new type as 8 bytes:
>
> ____ ____ ____ ____ ____ ___ ___ ____
> cidr addr x . x . x . x ip6 ip6
> bits len

Why bother with the addr len? Just expand it out with zeroes before
storing it.

Maybe we could make cidr bits equal to -1 if we are storing a host with
indeterminate netmask rather than setting it to 32. That allows us
to specify raw IP numbers without faking a netmask.

> Again, not sure we want to merge address and netmask for hosts in the
> same field.

Well, someone earlier suggested two different types, cidr for IPs with
network info and inet for IPs by themselves. The only argument against
that as I recall was that the cidr type would hold IPs alone as a special
case so why bother creating two different types?

To review, here, I think, are the types of data we want to store and how
I think we can handle them with the addition of a single cidr type.

IP alone can be entered as a dotted quad with no netmask. This would be
stored as if a /32 was appended (or /-1 if we want a special flag.)

IP and netmask can be entered as x.x.x.x/m or x.x.x.x:m.m.m.m. If the
former then store the IP and netmask. If the latter then convert the
dotted mask to masklen and store as the former. Raise an exception if
the dotted mask form is invalid such as 255.255.0.255.

Network alone can be stored the same as IP numbers. You need to specify
the mask length since networks can end in zeroes. Perhaps we can special
case inputs that don't have all 4 octets and apply the old class rules
but still store them like cidr addresses. There is no need to add a
flag to differentiate networks from addresses into the type since we
use the field for one or the other so we know what it is when we need
to display it. It's like using int to store both ID numbers and counts.
The database doesn't need to know the difference because we use any
particular field to store one or the other.

Netmasks alone can be stored in an int field.

--
D'Arcy J.M. Cain <darcy(at){druid|vex}.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 424 2871 (DoD#0082) (eNTP) | what's for dinner.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 1998-07-23 14:15:30 Re: [HACKERS] datetime ?#!!??@
Previous Message Davide Libenzi 1998-07-23 13:42:59 datetime ?#!!??@