Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 92da1c3

Browse files
committed
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)
1 parent 5838918 commit 92da1c3

File tree

5 files changed

+628
-103
lines changed

5 files changed

+628
-103
lines changed

contrib/ip_and_mac/Makefile

+17-27
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
11
#
22
# PostgreSQL types for IP and MAC addresses
33
#
4-
# $Id: Makefile,v 1.3 1998/04/22 04:14:11 scrappy Exp $
4+
# $Id: Makefile,v 1.4 1998/06/16 04:34:29 momjian Exp $
55

6-
SRCDIR= ../../src
6+
all: ip.so mac.so
77

8-
include $(SRCDIR)/Makefile.global
8+
ip.so: ip.o
9+
ld -Bshareable -o ip.so ip.o
910

10-
CONTRIBDIR=$(LIBDIR)/modules
11+
ip.o: ip.c
12+
cc -g -O -fPIC -I/usr/local/pgsql/include -c ip.c
1113

12-
CFLAGS+= $(CFLAGS_SL) -I$(SRCDIR)/include
14+
mac.so: mac.o
15+
ld -Bshareable -o mac.so mac.o
1316

14-
ifdef REFINT_VERBOSE
15-
CFLAGS+= -DREFINT_VERBOSE
16-
endif
17+
mac.o: mac.c mac.h
18+
cc -g -O -fPIC -I/usr/local/pgsql/include -c mac.c
1719

18-
TARGETS= ip$(DLSUFFIX) ip.sql mac$(DLSUFFIX) mac.sql
20+
install: ip.so mac.so
21+
install -c ip.so mac.so /usr/local/pgsql/modules
1922

20-
CLEANFILES+= $(TARGETS)
21-
22-
all:: $(TARGETS)
23-
24-
install:: all $(CONTRIBDIR)
25-
for f in *$(DLSUFFIX); do $(INSTALL) -c $$f $(CONTRIBDIR)/$$f; done
26-
27-
$(CONTRIBDIR):
28-
mkdir -p $(CONTRIBDIR)
29-
30-
%.sql: %.sql.in
31-
rm -f $@; \
32-
C=`pwd`; \
33-
sed -e "s:_OBJWD_:$(CONTRIBDIR):g" \
34-
-e "s:_DLSUFFIX_:$(DLSUFFIX):g" < $< > $@
35-
36-
clean:
37-
rm -f $(TARGETS) *.o
23+
clean:
24+
rm -f *.o *.so *.b
25+
#
26+
# eof
27+
#

contrib/ip_and_mac/README

+43-56
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,43 @@
1-
PostgreSQL type extensions for IP and MAC addresses.
2-
---------------------------------------------------
3-
4-
$Id: README,v 1.2 1998/02/14 17:58:03 scrappy Exp $
5-
6-
I needed to record IP and MAC level ethernet addresses in a data
7-
base, and I really didn't want to store them as plain strings, with
8-
no enforced error checking, so I put together the accompanying code
9-
as my first experiment with adding a data type to PostgreSQL. I
10-
then thought that this might be useful to others, both directly and
11-
as a very simple example of how to do this sort of thing, so here
12-
it is, in the hope that it will be useful.
13-
14-
IP addresses are implemented as a 6 byte struct (this may be 1 byte
15-
more than is useful, but I figured that since it has to be at least 5,
16-
it might as well be an even number of bytes) that contains the four
17-
byte address and a mask width. The external representation of an IP
18-
address looks like '158.37.96.15/32' (or just '158.37.96.15', which is
19-
understood to mean the same thing). This address happens to be part
20-
of a subnet where I work; '158.37.96.0/24', which itself is a part of
21-
the larger subnet allocated to our site, which is '158.37.96.0/21',
22-
which again, if you go by the old book, is part of the class "B" net
23-
called '158.37.0.0/16'.
24-
25-
Input and output functions are supplied, along with the "normal" <,
26-
<=, =, >=, > and <> operators, which all do what you expect. In
27-
addition, there is a function to check whether a given address is a
28-
member of a given subnet: ipaddr_in_net(addr, net), and functions to
29-
return the netmask and the broadcast address of a given network:
30-
ipaddr_mask(net) and ipaddr_bcast(net).
31-
32-
MAC level ethernet addresses are implemented as a 6 byte struct that
33-
contains the address as unsigned chars. Several input forms are
34-
accepted; the following are all the same address: '08002b:010203',
35-
'08002b-010203', '0800.2b01.0203', '08-00-2b-01-02-03' and
36-
'08:00:2b:01:02:03'. Upper and lower case is accepted for the digits
37-
'a' through 'f'. Output is always in the latter of the given forms.
38-
39-
As with IP addresses, input and output functions are supplied as well
40-
as the "normal" operators, which do what you expect. As an extra
41-
feature, a function macaddr_manuf() is defined, which returns the name
42-
of the manufacturer as a string. This is currently held in a
43-
hard-coded struct internal to the C module -- it might be smarter to
44-
put this information into an actual data base table, and look up the
45-
manufacturer there. (Another TODO, for both new data types, is to
46-
interface them to indices. If anyone can explain this to me in a way
47-
that is easier to understand than the current documentation, I would
48-
be most grateful!)
49-
50-
I don't know what changes are needed to the Makefile for other systems
51-
than the one I'm running (NetBSD 1.3), but anyway: to install on a BSD
52-
system: fix the path names in the SQL files and the Makefile if you
53-
need to, then make, make install, slurp the SQL files into psql or
54-
whatever, and you're off. Enjoy!
55-
56-
Bergen, Norway, 1998-01-31, Tom Ivar Helbekkmo (tih@Hamartun.Priv.NO).
1+
2+
This directory contain 2 new classes - macaddr to store mac addresses
3+
written by (Bergen, Norway, 1998-01-31, Tom Ivar Helbekkmo
4+
(tih@Hamartun.Priv.NO)), and ipaddr type and ipaddr_ops operator class,
5+
rewritten by me (alex@relcom.EU.net, Aleksei Roudnev, Moscow, Russia,
6+
25.05.98) and written first by Bergen.
7+
8+
To see the description of macaddr type, read README.ORIG file.
9+
To see the description of ipaddr type, read ipaddr.html file.
10+
^^^^^^^^^^^
11+
12+
This ipaddr type differ slightly from the original one. First, if you
13+
input '193.124.23.0' it sets /24 prefix instead of /32 (this is in
14+
accordance to CISCO's notification and our internal data bases and
15+
records); if you input '0.0.0.0' it's '0.0.0.0/0' (default) but not NULL
16+
or NOADDR value.
17+
18+
Then, you can store ADDRESS/PREFIX pair, even if ADDRESS is not the
19+
subnet address (for example, you can store interface address and mask at
20+
the single attribute). This allow us to determine, for example, which
21+
interfaces/routers are accessible by connected network for our interface
22+
(select * from database where '193.124.23.4' @ interface_address);
23+
24+
Then, it have been written a few new functions and a few operators
25+
(addr1 @ addr - TRUE if addr1 is the part of subnet addr2);
26+
'ipaddr_print' function allow you to convert address to any form you
27+
want; and so on.
28+
29+
And then, I add ipi.sql setup script and test1.sql + test2.sql test
30+
scripts to allow and test indexing by this new class.
31+
32+
This ipaddr type/opclass are used for our internal IP ROUTING and
33+
ACCOUNTING data base, and I hope it shpuld be usefull for more people.
34+
35+
For those who like crazy tasks, I propose to realise 'RTREE' indexing
36+
method to allow effectively use '@' operation for the binding statistic
37+
records to the customers etc networks. Note 'ipaddr' type can be written
38+
as 'start,end' coordination pair and it's possible to define all '<<,
39+
&<, @@, etc graphical operators over this type.
40+
41+
42+
25.05.1998, Aleksei Roudnev, alex@relcom.EU.net, Relcom, Moscow, Russia. /+7-095-194-1995.
43+
==========================================================================================

contrib/ip_and_mac/README.ORIG

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
PostgreSQL type extensions for IP and MAC addresses.
2+
---------------------------------------------------
3+
4+
$Id: README.ORIG,v 1.1 1998/06/16 04:34:29 momjian Exp $
5+
6+
I needed to record IP and MAC level ethernet addresses in a data
7+
base, and I really didn't want to store them as plain strings, with
8+
no enforced error checking, so I put together the accompanying code
9+
as my first experiment with adding a data type to PostgreSQL. I
10+
then thought that this might be useful to others, both directly and
11+
as a very simple example of how to do this sort of thing, so here
12+
it is, in the hope that it will be useful.
13+
14+
IP addresses are implemented as a 6 byte struct (this may be 1 byte
15+
more than is useful, but I figured that since it has to be at least 5,
16+
it might as well be an even number of bytes) that contains the four
17+
byte address and a mask width. The external representation of an IP
18+
address looks like '158.37.96.15/32' (or just '158.37.96.15', which is
19+
understood to mean the same thing). This address happens to be part
20+
of a subnet where I work; '158.37.96.0/24', which itself is a part of
21+
the larger subnet allocated to our site, which is '158.37.96.0/21',
22+
which again, if you go by the old book, is part of the class "B" net
23+
called '158.37.0.0/16'.
24+
25+
Input and output functions are supplied, along with the "normal" <,
26+
<=, =, >=, > and <> operators, which all do what you expect. In
27+
addition, there is a function to check whether a given address is a
28+
member of a given subnet: ipaddr_in_net(addr, net), and functions to
29+
return the netmask and the broadcast address of a given network:
30+
ipaddr_mask(net) and ipaddr_bcast(net).
31+
32+
MAC level ethernet addresses are implemented as a 6 byte struct that
33+
contains the address as unsigned chars. Several input forms are
34+
accepted; the following are all the same address: '08002b:010203',
35+
'08002b-010203', '0800.2b01.0203', '08-00-2b-01-02-03' and
36+
'08:00:2b:01:02:03'. Upper and lower case is accepted for the digits
37+
'a' through 'f'. Output is always in the latter of the given forms.
38+
39+
As with IP addresses, input and output functions are supplied as well
40+
as the "normal" operators, which do what you expect. As an extra
41+
feature, a function macaddr_manuf() is defined, which returns the name
42+
of the manufacturer as a string. This is currently held in a
43+
hard-coded struct internal to the C module -- it might be smarter to
44+
put this information into an actual data base table, and look up the
45+
manufacturer there. (Another TODO, for both new data types, is to
46+
interface them to indices. If anyone can explain this to me in a way
47+
that is easier to understand than the current documentation, I would
48+
be most grateful!)
49+
50+
I don't know what changes are needed to the Makefile for other systems
51+
than the one I'm running (NetBSD 1.3), but anyway: to install on a BSD
52+
system: fix the path names in the SQL files and the Makefile if you
53+
need to, then make, make install, slurp the SQL files into psql or
54+
whatever, and you're off. Enjoy!
55+
56+
Bergen, Norway, 1998-01-31, Tom Ivar Helbekkmo (tih@Hamartun.Priv.NO).

0 commit comments

Comments
 (0)