Re: [HACKERS] cidr - Mailing list pgsql-hackers
From | darcy@druid.net (D'Arcy J.M. Cain) |
---|---|
Subject | Re: [HACKERS] cidr |
Date | |
Msg-id | m0yzLsy-00006FC@druid.net Whole thread Raw |
In response to | Re: [HACKERS] cidr (Bruce Momjian <maillist@candle.pha.pa.us>) |
Responses |
Re: [HACKERS] cidr
|
List | 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@{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.
pgsql-hackers by date: