Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
19b1c76f
Commit
19b1c76f
authored
19 years ago
by
Bruce Momjian
Browse files
Options
Downloads
Patches
Plain Diff
Use is_cidr in INET/CIDR structure, rather than the generic 'type'.
parent
726b42ab
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/backend/utils/adt/network.c
+24
-24
24 additions, 24 deletions
src/backend/utils/adt/network.c
src/include/utils/inet.h
+2
-2
2 additions, 2 deletions
src/include/utils/inet.h
with
26 additions
and
26 deletions
src/backend/utils/adt/network.c
+
24
−
24
View file @
19b1c76f
/*
* PostgreSQL type definitions for the INET and CIDR types.
*
* $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.5
8
2006/01/
11 08:43:12 neilc
Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.5
9
2006/01/
23 21:45:47 momjian
Exp $
*
* Jon Postel RIP 16 Oct 1998
*/
...
...
@@ -22,7 +22,7 @@
#include
"utils/inet.h"
static
Datum
text_network
(
text
*
src
,
int
type
);
static
Datum
text_network
(
text
*
src
,
int
is_cidr
);
static
int32
network_cmp_internal
(
inet
*
a1
,
inet
*
a2
);
static
int
bitncmp
(
void
*
l
,
void
*
r
,
int
n
);
static
bool
addressOK
(
unsigned
char
*
a
,
int
bits
,
int
family
);
...
...
@@ -38,8 +38,8 @@ static int ip_addrsize(inet *inetptr);
#define ip_bits(inetptr) \
(((inet_struct *)VARDATA(inetptr))->bits)
#define ip_
type
(inetptr) \
(((inet_struct *)VARDATA(inetptr))->
type
)
#define ip_
is_cidr
(inetptr) \
(((inet_struct *)VARDATA(inetptr))->
is_cidr
)
#define ip_addr(inetptr) \
(((inet_struct *)VARDATA(inetptr))->ipaddr)
...
...
@@ -66,7 +66,7 @@ ip_addrsize(inet *inetptr)
/* Common input routine */
static
inet
*
network_in
(
char
*
src
,
int
type
)
network_in
(
char
*
src
,
bool
is_cidr
)
{
int
bits
;
inet
*
dst
;
...
...
@@ -85,18 +85,18 @@ network_in(char *src, int type)
ip_family
(
dst
)
=
PGSQL_AF_INET
;
bits
=
inet_net_pton
(
ip_family
(
dst
),
src
,
ip_addr
(
dst
),
type
?
ip_addrsize
(
dst
)
:
-
1
);
is_cidr
?
ip_addrsize
(
dst
)
:
-
1
);
if
((
bits
<
0
)
||
(
bits
>
ip_maxbits
(
dst
)))
ereport
(
ERROR
,
(
errcode
(
ERRCODE_INVALID_TEXT_REPRESENTATION
),
/* translator: first %s is inet or cidr */
errmsg
(
"invalid input syntax for type %s:
\"
%s
\"
"
,
type
?
"cidr"
:
"inet"
,
src
)));
is_cidr
?
"cidr"
:
"inet"
,
src
)));
/*
* Error check: CIDR values must not have any bits set beyond the masklen.
*/
if
(
type
)
if
(
is_cidr
)
{
if
(
!
addressOK
(
ip_addr
(
dst
),
bits
,
ip_family
(
dst
)))
ereport
(
ERROR
,
...
...
@@ -109,7 +109,7 @@ network_in(char *src, int type)
+
((
char
*
)
ip_addr
(
dst
)
-
(
char
*
)
VARDATA
(
dst
))
+
ip_addrsize
(
dst
);
ip_bits
(
dst
)
=
bits
;
ip_
type
(
dst
)
=
type
;
ip_
is_cidr
(
dst
)
=
is_cidr
;
return
dst
;
}
...
...
@@ -152,7 +152,7 @@ inet_out(PG_FUNCTION_ARGS)
errmsg
(
"could not format inet value: %m"
)));
/* For CIDR, add /n if not present */
if
(
ip_
type
(
src
)
&&
strchr
(
tmp
,
'/'
)
==
NULL
)
if
(
ip_
is_cidr
(
src
)
&&
strchr
(
tmp
,
'/'
)
==
NULL
)
{
len
=
strlen
(
tmp
);
snprintf
(
tmp
+
len
,
sizeof
(
tmp
)
-
len
,
"/%u"
,
ip_bits
(
src
));
...
...
@@ -174,7 +174,7 @@ cidr_out(PG_FUNCTION_ARGS)
* inet_recv - converts external binary format to inet
*
* The external representation is (one byte apiece for)
* family, bits,
type
, address length, address in network byte order.
* family, bits,
is_cidr
, address length, address in network byte order.
*/
Datum
inet_recv
(
PG_FUNCTION_ARGS
)
...
...
@@ -201,8 +201,8 @@ inet_recv(PG_FUNCTION_ARGS)
(
errcode
(
ERRCODE_INVALID_BINARY_REPRESENTATION
),
errmsg
(
"invalid bits in external
\"
inet
\"
value"
)));
ip_bits
(
addr
)
=
bits
;
ip_
type
(
addr
)
=
pq_getmsgbyte
(
buf
);
if
(
ip_
type
(
addr
)
!=
0
&&
ip_
type
(
addr
)
!=
1
)
ip_
is_cidr
(
addr
)
=
pq_getmsgbyte
(
buf
);
if
(
ip_
is_cidr
(
addr
)
!=
false
&&
ip_
is_cidr
(
addr
)
!=
true
)
ereport
(
ERROR
,
(
errcode
(
ERRCODE_INVALID_BINARY_REPRESENTATION
),
errmsg
(
"invalid type in external
\"
inet
\"
value"
)));
...
...
@@ -222,7 +222,7 @@ inet_recv(PG_FUNCTION_ARGS)
/*
* Error check: CIDR values must not have any bits set beyond the masklen.
*/
if
(
ip_
type
(
addr
))
if
(
ip_
is_cidr
(
addr
))
{
if
(
!
addressOK
(
ip_addr
(
addr
),
bits
,
ip_family
(
addr
)))
ereport
(
ERROR
,
...
...
@@ -256,7 +256,7 @@ inet_send(PG_FUNCTION_ARGS)
pq_begintypsend
(
&
buf
);
pq_sendbyte
(
&
buf
,
ip_family
(
addr
));
pq_sendbyte
(
&
buf
,
ip_bits
(
addr
));
pq_sendbyte
(
&
buf
,
ip_
type
(
addr
));
pq_sendbyte
(
&
buf
,
ip_
is_cidr
(
addr
));
nb
=
ip_addrsize
(
addr
);
if
(
nb
<
0
)
nb
=
0
;
...
...
@@ -276,7 +276,7 @@ cidr_send(PG_FUNCTION_ARGS)
static
Datum
text_network
(
text
*
src
,
int
type
)
text_network
(
text
*
src
,
bool
is_cidr
)
{
int
len
=
VARSIZE
(
src
)
-
VARHDRSZ
;
...
...
@@ -285,7 +285,7 @@ text_network(text *src, int type)
memcpy
(
str
,
VARDATA
(
src
),
len
);
*
(
str
+
len
)
=
'\0'
;
PG_RETURN_INET_P
(
network_in
(
str
,
type
));
PG_RETURN_INET_P
(
network_in
(
str
,
is_cidr
));
}
...
...
@@ -425,8 +425,8 @@ network_ne(PG_FUNCTION_ARGS)
/*
* Support function for hash indexes on inet/cidr.
*
* Since network_cmp considers only ip_family, ip_bits, and ip_addr,
*
only
these fields may be used in the hash; in particular don't use
type
.
* Since network_cmp considers only ip_family, ip_bits, and ip_addr,
only
* these fields may be used in the hash; in particular don't use
is_cidr
.
*/
Datum
hashinet
(
PG_FUNCTION_ARGS
)
...
...
@@ -575,7 +575,7 @@ network_abbrev(PG_FUNCTION_ARGS)
int
len
;
char
tmp
[
sizeof
(
"xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128"
)];
if
(
ip_
type
(
ip
))
if
(
ip_
is_cidr
(
ip
))
dst
=
inet_cidr_ntop
(
ip_family
(
ip
),
ip_addr
(
ip
),
ip_bits
(
ip
),
tmp
,
sizeof
(
tmp
));
else
...
...
@@ -666,7 +666,7 @@ network_broadcast(PG_FUNCTION_ARGS)
ip_family
(
dst
)
=
ip_family
(
ip
);
ip_bits
(
dst
)
=
ip_bits
(
ip
);
ip_
type
(
dst
)
=
0
;
ip_
is_cidr
(
dst
)
=
false
;
VARATT_SIZEP
(
dst
)
=
VARHDRSZ
+
((
char
*
)
ip_addr
(
dst
)
-
(
char
*
)
VARDATA
(
dst
))
+
ip_addrsize
(
dst
);
...
...
@@ -712,7 +712,7 @@ network_network(PG_FUNCTION_ARGS)
ip_family
(
dst
)
=
ip_family
(
ip
);
ip_bits
(
dst
)
=
ip_bits
(
ip
);
ip_
type
(
dst
)
=
1
;
ip_
is_cidr
(
dst
)
=
true
;
VARATT_SIZEP
(
dst
)
=
VARHDRSZ
+
((
char
*
)
ip_addr
(
dst
)
-
(
char
*
)
VARDATA
(
dst
))
+
ip_addrsize
(
dst
);
...
...
@@ -756,7 +756,7 @@ network_netmask(PG_FUNCTION_ARGS)
ip_family
(
dst
)
=
ip_family
(
ip
);
ip_bits
(
dst
)
=
ip_maxbits
(
ip
);
ip_
type
(
dst
)
=
0
;
ip_
is_cidr
(
dst
)
=
false
;
VARATT_SIZEP
(
dst
)
=
VARHDRSZ
+
((
char
*
)
ip_addr
(
dst
)
-
(
char
*
)
VARDATA
(
dst
))
+
ip_addrsize
(
dst
);
...
...
@@ -806,7 +806,7 @@ network_hostmask(PG_FUNCTION_ARGS)
ip_family
(
dst
)
=
ip_family
(
ip
);
ip_bits
(
dst
)
=
ip_maxbits
(
ip
);
ip_
type
(
dst
)
=
0
;
ip_
is_cidr
(
dst
)
=
false
;
VARATT_SIZEP
(
dst
)
=
VARHDRSZ
+
((
char
*
)
ip_addr
(
dst
)
-
(
char
*
)
VARDATA
(
dst
))
+
ip_addrsize
(
dst
);
...
...
This diff is collapsed.
Click to expand it.
src/include/utils/inet.h
+
2
−
2
View file @
19b1c76f
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/utils/inet.h,v 1.2
0
200
4/12/31 22:03:46 pgsql
Exp $
* $PostgreSQL: pgsql/src/include/utils/inet.h,v 1.2
1
200
6/01/23 21:45:47 momjian
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -22,7 +22,7 @@ typedef struct
{
unsigned
char
family
;
/* PGSQL_AF_INET or PGSQL_AF_INET6 */
unsigned
char
bits
;
/* number of bits in netmask */
unsigned
char
type
;
/* 0 = inet, 1 =
cidr */
bool
is_cidr
;
/* is
cidr
?
*/
unsigned
char
ipaddr
[
16
];
/* up to 128 bits of address */
}
inet_struct
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment