I investigated carefully POSTGRES data base (in idea to use it for
our internal IP routing data base, and because I have participated
in Ingres development here in Russia in RUBIN/DEMOS project -
through it was not freeware work - and it was very interesting for
me too see such good freeware data base as PostgreSQL), and I
modified 'ipaddr' data type library in accordance to our requests
and to allow SQL do indexing over ipaddr objects.
You can read description at 'http://relcom.EU.net/ipaddr.html' and
get sources at 'http://relcom.EU.net/ip_class.tar.gz'. It contains
sources, sql scripts for incorporating new data type into postgres
(including ipaddr_ops operator class incorporation) and 20,000
records based data test for the indexing.
I am not sure if it's proper mail list for this information, and
if it's interesting for anyone except me to get full-functional
ipaddress class. I am ready to make all modifications, bug fixing
and documentation for this data class if it's nessesary for it's
contribution to the Postgres data base.
Anyway, all my work was based at original 'ip&mac data type'
contribution, written by Tom Ivar Helbekkmo.
Be free to write me any questions or requests about this work.
==============================================================
Aleksei Roudnev, Network Operations Center, Relcom, Moscow (+7 095)
194-19-95 (Network Operations Center Hot Line),(+7 095) 239-10-10,
N 13729 (pager) (+7 095) 196-72-12 (Support), (+7 095) 194-33-28
(Fax)
1998-06-16 06:34:30 +02:00
|
|
|
PostgreSQL type extensions for IP and MAC addresses.
|
|
|
|
---------------------------------------------------
|
|
|
|
|
1998-06-16 07:35:12 +02:00
|
|
|
$Id: README.ORIG,v 1.2 1998/06/16 05:35:10 momjian Exp $
|
I investigated carefully POSTGRES data base (in idea to use it for
our internal IP routing data base, and because I have participated
in Ingres development here in Russia in RUBIN/DEMOS project -
through it was not freeware work - and it was very interesting for
me too see such good freeware data base as PostgreSQL), and I
modified 'ipaddr' data type library in accordance to our requests
and to allow SQL do indexing over ipaddr objects.
You can read description at 'http://relcom.EU.net/ipaddr.html' and
get sources at 'http://relcom.EU.net/ip_class.tar.gz'. It contains
sources, sql scripts for incorporating new data type into postgres
(including ipaddr_ops operator class incorporation) and 20,000
records based data test for the indexing.
I am not sure if it's proper mail list for this information, and
if it's interesting for anyone except me to get full-functional
ipaddress class. I am ready to make all modifications, bug fixing
and documentation for this data class if it's nessesary for it's
contribution to the Postgres data base.
Anyway, all my work was based at original 'ip&mac data type'
contribution, written by Tom Ivar Helbekkmo.
Be free to write me any questions or requests about this work.
==============================================================
Aleksei Roudnev, Network Operations Center, Relcom, Moscow (+7 095)
194-19-95 (Network Operations Center Hot Line),(+7 095) 239-10-10,
N 13729 (pager) (+7 095) 196-72-12 (Support), (+7 095) 194-33-28
(Fax)
1998-06-16 06:34:30 +02:00
|
|
|
|
|
|
|
I needed to record IP and MAC level ethernet addresses in a data
|
|
|
|
base, and I really didn't want to store them as plain strings, with
|
|
|
|
no enforced error checking, so I put together the accompanying code
|
|
|
|
as my first experiment with adding a data type to PostgreSQL. I
|
|
|
|
then thought that this might be useful to others, both directly and
|
|
|
|
as a very simple example of how to do this sort of thing, so here
|
|
|
|
it is, in the hope that it will be useful.
|
|
|
|
|
|
|
|
IP addresses are implemented as a 6 byte struct (this may be 1 byte
|
|
|
|
more than is useful, but I figured that since it has to be at least 5,
|
|
|
|
it might as well be an even number of bytes) that contains the four
|
|
|
|
byte address and a mask width. The external representation of an IP
|
|
|
|
address looks like '158.37.96.15/32' (or just '158.37.96.15', which is
|
|
|
|
understood to mean the same thing). This address happens to be part
|
|
|
|
of a subnet where I work; '158.37.96.0/24', which itself is a part of
|
|
|
|
the larger subnet allocated to our site, which is '158.37.96.0/21',
|
|
|
|
which again, if you go by the old book, is part of the class "B" net
|
|
|
|
called '158.37.0.0/16'.
|
|
|
|
|
|
|
|
Input and output functions are supplied, along with the "normal" <,
|
|
|
|
<=, =, >=, > and <> operators, which all do what you expect. In
|
|
|
|
addition, there is a function to check whether a given address is a
|
|
|
|
member of a given subnet: ipaddr_in_net(addr, net), and functions to
|
|
|
|
return the netmask and the broadcast address of a given network:
|
|
|
|
ipaddr_mask(net) and ipaddr_bcast(net).
|
|
|
|
|
|
|
|
MAC level ethernet addresses are implemented as a 6 byte struct that
|
|
|
|
contains the address as unsigned chars. Several input forms are
|
|
|
|
accepted; the following are all the same address: '08002b:010203',
|
|
|
|
'08002b-010203', '0800.2b01.0203', '08-00-2b-01-02-03' and
|
|
|
|
'08:00:2b:01:02:03'. Upper and lower case is accepted for the digits
|
|
|
|
'a' through 'f'. Output is always in the latter of the given forms.
|
|
|
|
|
|
|
|
As with IP addresses, input and output functions are supplied as well
|
|
|
|
as the "normal" operators, which do what you expect. As an extra
|
|
|
|
feature, a function macaddr_manuf() is defined, which returns the name
|
|
|
|
of the manufacturer as a string. This is currently held in a
|
|
|
|
hard-coded struct internal to the C module -- it might be smarter to
|
|
|
|
put this information into an actual data base table, and look up the
|
|
|
|
manufacturer there. (Another TODO, for both new data types, is to
|
|
|
|
interface them to indices. If anyone can explain this to me in a way
|
|
|
|
that is easier to understand than the current documentation, I would
|
|
|
|
be most grateful!)
|
|
|
|
|
|
|
|
I don't know what changes are needed to the Makefile for other systems
|
|
|
|
than the one I'm running (NetBSD 1.3), but anyway: to install on a BSD
|
|
|
|
system: fix the path names in the SQL files and the Makefile if you
|
|
|
|
need to, then make, make install, slurp the SQL files into psql or
|
|
|
|
whatever, and you're off. Enjoy!
|
|
|
|
|
|
|
|
Bergen, Norway, 1998-01-31, Tom Ivar Helbekkmo (tih@Hamartun.Priv.NO).
|