macaddr 64 bit (EUI-64) datatype support

Started by Haribabu Kommiover 9 years ago73 messageshackers
Jump to latest
#1Haribabu Kommi
kommi.haribabu@gmail.com

There was bug that is raised in [1]/messages/by-id/20161010162001.1413.12486@wrigleys.postgresql.org related to storing EUI-64 mac address
in PostgreSQL MAC address datatype.

As the current macaddr datatype stores only 48 bit MAC address only, and
now a days
people are adopting to EUI-64 format of MAC address. So it better to add
the support
in PostgreSQL.

Here I attached a POC patch that adds the support for EUI-64 MAC address
storage with a
new datatype macaddr64. Currently this type takes only EUI-64 datatype, not
accepts 48
bit MAC address.

Before continuing and adding more details for macaddr64 datatype, it is not
possible to
add the support for current macaddr datatype as it is a fixed size datatype
that is stored
in the disk. So any enhancements to change it from 48 to 64 bit will give
problems to
pg_upgrade.

As we are moving to PostgreSQL 10, so are there any plans of backward
compatiblity
breakage, so the existing macaddr datatype itself can be changed to support
both
48 and 64 bit MAC addresses. If not, I will try update the POC patch with
more details
similar like macaddr datatype.

[1]: /messages/by-id/20161010162001.1413.12486@wrigleys.postgresql.org
/messages/by-id/20161010162001.1413.12486@wrigleys.postgresql.org

Regards,
Hari Babu
Fujitsu Australia

Attachments:

macaddr64_poc.patchapplication/octet-stream; name=macaddr64_poc.patchDownload+425-1
#2Michael Paquier
michael@paquier.xyz
In reply to: Haribabu Kommi (#1)
Re: macaddr 64 bit (EUI-64) datatype support

On Wed, Oct 12, 2016 at 3:30 PM, Haribabu Kommi
<kommi.haribabu@gmail.com> wrote:

As we are moving to PostgreSQL 10, so are there any plans of backward
compatiblity
breakage, so the existing macaddr datatype itself can be changed to support
both
48 and 64 bit MAC addresses.

Er, I had thought that we should not use Postgres 10 as a reason for
backward-incompatible breakages, at least not to increase them into a
such amount that upgrading would be a pain.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Craig Ringer
craig@2ndquadrant.com
In reply to: Haribabu Kommi (#1)
Re: macaddr 64 bit (EUI-64) datatype support

On 12 October 2016 at 14:30, Haribabu Kommi <kommi.haribabu@gmail.com> wrote:

As we are moving to PostgreSQL 10, so are there any plans of backward
compatiblity
breakage, so the existing macaddr datatype itself can be changed to support
both
48 and 64 bit MAC addresses. If not, I will try update the POC patch with
more details
similar like macaddr datatype.

There's been some minor BC breaking, but breaking on-disk format for
pg_upgrade is a much bigger deal. I'm really not a fan of that idea.

Just use macaddr64 if you want wide MACs.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Julien Rouhaud
rjuju123@gmail.com
In reply to: Craig Ringer (#3)
Re: macaddr 64 bit (EUI-64) datatype support

On 12/10/2016 09:32, Craig Ringer wrote:

On 12 October 2016 at 14:30, Haribabu Kommi <kommi.haribabu@gmail.com> wrote:

As we are moving to PostgreSQL 10, so are there any plans of backward
compatiblity
breakage, so the existing macaddr datatype itself can be changed to support
both
48 and 64 bit MAC addresses. If not, I will try update the POC patch with
more details
similar like macaddr datatype.

There's been some minor BC breaking, but breaking on-disk format for
pg_upgrade is a much bigger deal. I'm really not a fan of that idea.

Just use macaddr64 if you want wide MACs.

+1

and you can instead make macaddr64 support both format, and provide a
macaddr::macaddr64 cast

--
Julien Rouhaud
http://dalibo.com - http://dalibo.org

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Julien Rouhaud (#4)
Re: macaddr 64 bit (EUI-64) datatype support

Julien Rouhaud wrote:

and you can instead make macaddr64 support both format, and provide a
macaddr::macaddr64 cast

Having macaddr64 support both formats sounds nice, but how does it work?
Will we have to reserve one additional bit to select the representation?
That would make the type be 65 bits which is a clear loser IMO.

Is it allowed to just leave 16 bits as zeroes which would indicate that
the address is EUI48? I wouldn't think so ...

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Haribabu Kommi (#1)
Re: macaddr 64 bit (EUI-64) datatype support

Haribabu Kommi <kommi.haribabu@gmail.com> writes:

Here I attached a POC patch that adds the support for EUI-64 MAC address
storage with a new datatype macaddr64. Currently this type takes only
EUI-64 datatype, not accepts 48 bit MAC address.

Our other data types that have sizes in the names measure the sizes in
bytes (float4, int8, etc). Should this be called macaddr8?

As we are moving to PostgreSQL 10, so are there any plans of backward
compatiblity breakage, so the existing macaddr datatype itself can be
changed to support both 48 and 64 bit MAC addresses.

As others have noted, there is no likelihood that we'd take a disk-format-
compatibility-breaking patch for v10. Even if we wanted to do that, the
above proposal would also break send/recv (binary COPY) compatibility for
macaddr.

I think that probably the best bet here is to have two types and put some
thought into making them interoperate where appropriate, as the various
sizes of int do. It's kind of a shame that this won't look like the
approach used for inet addresses, but we're stuck.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Julien Rouhaud
rjuju123@gmail.com
In reply to: Alvaro Herrera (#5)
Re: macaddr 64 bit (EUI-64) datatype support

On 12/10/2016 14:32, Alvaro Herrera wrote:

Julien Rouhaud wrote:

and you can instead make macaddr64 support both format, and provide a
macaddr::macaddr64 cast

Having macaddr64 support both formats sounds nice, but how does it work?
Will we have to reserve one additional bit to select the representation?
That would make the type be 65 bits which is a clear loser IMO.

Is it allowed to just leave 16 bits as zeroes which would indicate that
the address is EUI48? I wouldn't think so ...

From what I read, you can indicate it's an EUI-48 address by storing
FF:FF (or FF:FE for MAC-48) in 4th and 5th bytes of the EUI-64 address.

--
Julien Rouhaud
http://dalibo.com - http://dalibo.org

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#8Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Julien Rouhaud (#7)
Re: macaddr 64 bit (EUI-64) datatype support

Julien Rouhaud wrote:

On 12/10/2016 14:32, Alvaro Herrera wrote:

Julien Rouhaud wrote:

and you can instead make macaddr64 support both format, and provide a
macaddr::macaddr64 cast

Having macaddr64 support both formats sounds nice, but how does it work?
Will we have to reserve one additional bit to select the representation?
That would make the type be 65 bits which is a clear loser IMO.

Is it allowed to just leave 16 bits as zeroes which would indicate that
the address is EUI48? I wouldn't think so ...

From what I read, you can indicate it's an EUI-48 address by storing
FF:FF (or FF:FE for MAC-48) in 4th and 5th bytes of the EUI-64 address.

That seems reasonable at first glance; so the new type would be able to
store both 48-bit and 64-bit values, and there would be assignment casts
in both directions and a suite of operators to enable interoperability
of 48-bit values in macaddr8 with values in type macaddr. Right?

(The cast function from macaddr8 to macaddr would raise error if the
4th and 5th bytes are not either FF:FF or FF:FE -- I don't think we can
in practice distinguish EUI-48 from MAC-48 in this context. The cast in
the other direction would have no restriction and should probably always
use FF:FE).

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#9Vitaly Burovoy
vitaly.burovoy@gmail.com
In reply to: Alvaro Herrera (#8)
Re: macaddr 64 bit (EUI-64) datatype support

On 10/12/16, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

Julien Rouhaud wrote:

On 12/10/2016 14:32, Alvaro Herrera wrote:

Julien Rouhaud wrote:

and you can instead make macaddr64 support both format, and provide a
macaddr::macaddr64 cast

Having macaddr64 support both formats sounds nice, but how does it
work?
Will we have to reserve one additional bit to select the
representation?
That would make the type be 65 bits which is a clear loser IMO.

Is it allowed to just leave 16 bits as zeroes which would indicate that
the address is EUI48? I wouldn't think so ...

From what I read, you can indicate it's an EUI-48 address by storing
FF:FF (or FF:FE for MAC-48) in 4th and 5th bytes of the EUI-64 address.

That seems reasonable at first glance; so the new type would be able to
store both 48-bit and 64-bit values, and there would be assignment casts
in both directions

I think either "macaddr" should be renamed to "macaddr6" (saved its
oid), a new type "macaddr8" is added with introducing a new alias
"macaddr" or the current "macaddr" should accept both versions as the
"inet" type does.

The function "macaddr_recv" can distinguish them by the
StringInfoData.len member, "macaddr_in" - by number of parts split by
":".
The "macaddr_out" and "macaddr_send" can out 6 octets if the stored
value is mapped to MAC-48.
Storing can be done always as 8 bytes using the rule above.

In the other case there is hard from user's PoV to detect at the
design stage when it is necessary to define column as macaddr and when
to macaddr8.
If users need to update a column type (a new hardware appears with
EUI-64 address), they should keep in mind that all things are changed
for the new column type - stored procedure's parameters, application
code interacting with the DB etc.).
I don't agree with Tom's proposal to introduce a new type, it would be
inconvenient for users.

We have types "int2", "int4", "int8" and an alias "int" for a type
"int4", at least psql does not show it:
postgres=# \dT+ int
List of data types
Schema | Name | Internal name | Size | Elements | Owner | Access
privileges | Description
--------+------+---------------+------+----------+-------+-------------------+-------------
(0 rows)

It is understandable to have 3 types for integers because most space
of the DB occupied by them and in the real life we just don't use big
numbers, but cases for "inet" and "macaddr" are different.

and a suite of operators to enable interoperability
of 48-bit values in macaddr8 with values in type macaddr. Right?

(The cast function from macaddr8 to macaddr would raise error if the
4th and 5th bytes are not either FF:FF or FF:FE -- I don't think we can
in practice distinguish EUI-48 from MAC-48 in this context.

The wikipedia says[1]https://en.wikipedia.org/wiki/Organizationally_unique_identifier#48-bit_Media_Access_Control_Identifier_.28MAC-48.29 -- Best regards, Vitaly Burovoy they are the same things but MAC-48 is an
obsolete term for a special case, so there is no necessary to
distinguish them.

The cast in the other direction would have no restriction and should
probably always use FF:FE).

[1]: https://en.wikipedia.org/wiki/Organizationally_unique_identifier#48-bit_Media_Access_Control_Identifier_.28MAC-48.29 -- Best regards, Vitaly Burovoy
--
Best regards,
Vitaly Burovoy

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#10Vitaly Burovoy
vitaly.burovoy@gmail.com
In reply to: Vitaly Burovoy (#9)
Re: macaddr 64 bit (EUI-64) datatype support

On 10/12/16, Vitaly Burovoy <vitaly.burovoy@gmail.com> wrote:

On 10/12/16, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

Julien Rouhaud wrote:

On 12/10/2016 14:32, Alvaro Herrera wrote:

Julien Rouhaud wrote:

and you can instead make macaddr64 support both format, and provide a
macaddr::macaddr64 cast

Having macaddr64 support both formats sounds nice, but how does it
work?
Will we have to reserve one additional bit to select the
representation?
That would make the type be 65 bits which is a clear loser IMO.

Is it allowed to just leave 16 bits as zeroes which would indicate
that
the address is EUI48? I wouldn't think so ...

From what I read, you can indicate it's an EUI-48 address by storing
FF:FF (or FF:FE for MAC-48) in 4th and 5th bytes of the EUI-64 address.

That seems reasonable at first glance; so the new type would be able to
store both 48-bit and 64-bit values, and there would be assignment casts
in both directions

I think either "macaddr" should be renamed to "macaddr6" (saved its
oid), a new type "macaddr8" is added with introducing a new alias
"macaddr" or the current "macaddr" should accept both versions as the
"inet" type does.

The function "macaddr_recv" can distinguish them by the
StringInfoData.len member, "macaddr_in" - by number of parts split by
":".
The "macaddr_out" and "macaddr_send" can out 6 octets if the stored
value is mapped to MAC-48.
Storing can be done always as 8 bytes using the rule above.

In the other case there is hard from user's PoV to detect at the
design stage when it is necessary to define column as macaddr and when
to macaddr8.
If users need to update a column type (a new hardware appears with
EUI-64 address), they should keep in mind that all things are changed
for the new column type - stored procedure's parameters, application
code interacting with the DB etc.).
I don't agree with Tom's proposal to introduce a new type, it would be
inconvenient for users.

We have types "int2", "int4", "int8" and an alias "int" for a type
"int4", at least psql does not show it:
postgres=# \dT+ int
List of data types
Schema | Name | Internal name | Size | Elements | Owner | Access
privileges | Description
--------+------+---------------+------+----------+-------+-------------------+-------------
(0 rows)

It is understandable to have 3 types for integers because most space
of the DB occupied by them and in the real life we just don't use big
numbers, but cases for "inet" and "macaddr" are different.

and a suite of operators to enable interoperability
of 48-bit values in macaddr8 with values in type macaddr. Right?

(The cast function from macaddr8 to macaddr would raise error if the
4th and 5th bytes are not either FF:FF or FF:FE -- I don't think we can
in practice distinguish EUI-48 from MAC-48 in this context.

The wikipedia says[1] they are the same things but MAC-48 is an
obsolete term for a special case, so there is no necessary to
distinguish them.

The cast in the other direction would have no restriction and should
probably always use FF:FE).

[1]
https://en.wikipedia.org/wiki/Organizationally_unique_identifier#48-bit_Media_Access_Control_Identifier_.28MAC-48.29

Haribabu Kommi, why have you read enough about EUI-64?
Your function "macaddr64_trunc" sets 4 lower bytes as 0 whereas
(according to the Wikipedia, but I can look for a standard) 3 bytes
are still define an OUI (organizationally unique identifier), so
truncation should be done for 5, not 4 lower octets.

The macros "hibits" should be 3 octets long, not 4; "lobits" --- 5 bytes, not 4.
In the other case your comparisons fail.

What document have you used to write the patch? Are short form formats
correct in macaddr64_in?

P.S.: I still think it is a good idea to change storage format,
macaddr_{in,out,send,recv}, fill 4th and 5th bytes if necessary;
change "lobits" macros and add new fields to bit operation functions.
It avoids a new type, casting, comparison functions between macaddr6
and macaddr8 etc. Proposed patch is mostly copy-paste of mac.c

--
Best regards,
Vitaly Burovoy

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#11Vitaly Burovoy
vitaly.burovoy@gmail.com
In reply to: Vitaly Burovoy (#10)
Re: macaddr 64 bit (EUI-64) datatype support

I'm sorry for the offtopic, but does anyone know a reason why a
condition in mac.c

if ((a < 0) || (a > 255) || (b < 0) || (b > 255) ||
(c < 0) || (c > 255) || (d < 0) || (d > 255) ||
(e < 0) || (e > 255) || (f < 0) || (f > 255))

can not be rewritten as:

if (((a | b | c | d | e | f) < 0) ||
((a | b | c | d | e | f) > 255))

It seems more compact and a compiler can optimize it to keep a result
of a binary OR for the comparison with 255...

--
Best regards,
Vitaly Burovoy

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#12Tom Lane
tgl@sss.pgh.pa.us
In reply to: Vitaly Burovoy (#10)
Re: macaddr 64 bit (EUI-64) datatype support

Vitaly Burovoy <vitaly.burovoy@gmail.com> writes:

P.S.: I still think it is a good idea to change storage format,

I'm not sure which part of "no" you didn't understand, but we're
not breaking on-disk compatibility of existing macaddr columns.
Breaking the on-the-wire binary I/O representation seems like a
nonstarter as well.

If you can think of a way to have one type do it all without breaking
that, then fine; but that seems like a pretty hard problem.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#13Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Tom Lane (#12)
Re: macaddr 64 bit (EUI-64) datatype support

Tom Lane wrote:

Vitaly Burovoy <vitaly.burovoy@gmail.com> writes:

P.S.: I still think it is a good idea to change storage format,

I'm not sure which part of "no" you didn't understand, but we're
not breaking on-disk compatibility of existing macaddr columns.
Breaking the on-the-wire binary I/O representation seems like a
nonstarter as well.

I think the suggestion was to rename macaddr to macaddr6 or similar,
keeping the existing behavior and the current OID. So existing columns
would continue to work fine and maintain on-disk compatibility, but any
newly created columns would become the 8-byte variant.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#14Tom Lane
tgl@sss.pgh.pa.us
In reply to: Vitaly Burovoy (#11)
Re: macaddr 64 bit (EUI-64) datatype support

Vitaly Burovoy <vitaly.burovoy@gmail.com> writes:

I'm sorry for the offtopic, but does anyone know a reason why a
condition in mac.c

if ((a < 0) || (a > 255) || (b < 0) || (b > 255) ||
(c < 0) || (c > 255) || (d < 0) || (d > 255) ||
(e < 0) || (e > 255) || (f < 0) || (f > 255))

can not be rewritten as:

if (((a | b | c | d | e | f) < 0) ||
((a | b | c | d | e | f) > 255))

Well, it's ugly and it adds a bunch of assumptions about arithmetic
behavior that we don't particularly need to make. If this were some
amazingly hot hot-spot then maybe it would be worth making the code
unreadable to save a few nanoseconds, but I doubt that it is.
(Anyway, you've not shown that there actually is any benefit ...)

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#15Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#13)
Re: macaddr 64 bit (EUI-64) datatype support

Alvaro Herrera <alvherre@2ndquadrant.com> writes:

Tom Lane wrote:

Vitaly Burovoy <vitaly.burovoy@gmail.com> writes:

P.S.: I still think it is a good idea to change storage format,

I'm not sure which part of "no" you didn't understand, but we're
not breaking on-disk compatibility of existing macaddr columns.
Breaking the on-the-wire binary I/O representation seems like a
nonstarter as well.

I think the suggestion was to rename macaddr to macaddr6 or similar,
keeping the existing behavior and the current OID. So existing columns
would continue to work fine and maintain on-disk compatibility, but any
newly created columns would become the 8-byte variant.

... and would have different I/O behavior from before, possibly breaking
applications that expect "macaddr" to mean what it used to. I'm still
dubious that that's a good idea.

The larger picture here is that we got very little thanks when we squeezed
IPv6 into the pre-existing inet datatype; there's a large number of people
who just said "no thanks" and started using the add-on ip4r type instead.
So I'm not sure why we want to complicate our lives in order to make
macaddr follow the same path.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#16Vitaly Burovoy
vitaly.burovoy@gmail.com
In reply to: Tom Lane (#14)
Re: macaddr 64 bit (EUI-64) datatype support

On 10/12/16, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Vitaly Burovoy <vitaly.burovoy@gmail.com> writes:

I'm sorry for the offtopic, but does anyone know a reason why a
condition in mac.c

if ((a < 0) || (a > 255) || (b < 0) || (b > 255) ||
(c < 0) || (c > 255) || (d < 0) || (d > 255) ||
(e < 0) || (e > 255) || (f < 0) || (f > 255))

can not be rewritten as:

if (((a | b | c | d | e | f) < 0) ||
((a | b | c | d | e | f) > 255))

Well, it's ugly and

it adds a bunch of assumptions about arithmetic
behavior that we don't particularly need to make.

It explains the reason, thank you. I'm just not familiar with other
architectures where it is not the same as in X86/X86-64.

If this were some
amazingly hot hot-spot then maybe it would be worth making the code
unreadable to save a few nanoseconds, but I doubt that it is.

(Anyway, you've not shown that there actually is any benefit ...)

I don't think it has a speed benefit, especially comparing with the sscanf call.
But personally for me the second variant does not seem ugly, just "no
one bit in all variables is out of a byte" (looks better with
comparison with "0xff" as sscanf operates with "%2x").
Sorry for my bad taste and for a noise.

--
Best regards,
Vitaly Burovoy

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#17Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Vitaly Burovoy (#10)
Re: macaddr 64 bit (EUI-64) datatype support

On Thu, Oct 13, 2016 at 7:31 AM, Vitaly Burovoy <vitaly.burovoy@gmail.com>
wrote:

Haribabu Kommi, why have you read enough about EUI-64?
Your function "macaddr64_trunc" sets 4 lower bytes as 0 whereas
(according to the Wikipedia, but I can look for a standard) 3 bytes
are still define an OUI (organizationally unique identifier), so
truncation should be done for 5, not 4 lower octets.

The macros "hibits" should be 3 octets long, not 4; "lobits" --- 5 bytes,
not 4.
In the other case your comparisons fail.

What document have you used to write the patch? Are short form formats
correct in macaddr64_in?

Yes, OUI is 24 bits. I just created prototype patch to check community
opinion on it.
I checked the following links [1]http://standards.ieee.org/develop/regauth/tut/eui64.pdf, [2]https://en.wikipedia.org/wiki/MAC_address for the development of macaddr8. But
the patch is
not correct for all the cases, it is just a prototype to see whether it
accepts 8 byte
MAC address or not?

[1]: http://standards.ieee.org/develop/regauth/tut/eui64.pdf
[2]: https://en.wikipedia.org/wiki/MAC_address

Regards,
Hari Babu
Fujitsu Australia

#18Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Tom Lane (#15)
Re: macaddr 64 bit (EUI-64) datatype support

On Thu, Oct 13, 2016 at 7:59 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Alvaro Herrera <alvherre@2ndquadrant.com> writes:

Tom Lane wrote:

Vitaly Burovoy <vitaly.burovoy@gmail.com> writes:

P.S.: I still think it is a good idea to change storage format,

I'm not sure which part of "no" you didn't understand, but we're
not breaking on-disk compatibility of existing macaddr columns.
Breaking the on-the-wire binary I/O representation seems like a
nonstarter as well.

I think the suggestion was to rename macaddr to macaddr6 or similar,
keeping the existing behavior and the current OID. So existing columns
would continue to work fine and maintain on-disk compatibility, but any
newly created columns would become the 8-byte variant.

... and would have different I/O behavior from before, possibly breaking
applications that expect "macaddr" to mean what it used to. I'm still
dubious that that's a good idea.

The larger picture here is that we got very little thanks when we squeezed
IPv6 into the pre-existing inet datatype; there's a large number of people
who just said "no thanks" and started using the add-on ip4r type instead.
So I'm not sure why we want to complicate our lives in order to make
macaddr follow the same path.

Thanks for all your opinions regarding the addition of new datatype to
support
EUI-64 Mac address, I will work on it and come up with a patch.

Regards,
Hari Babu
Fujitsu Australia

#19Vitaly Burovoy
vitaly.burovoy@gmail.com
In reply to: Tom Lane (#15)
Re: macaddr 64 bit (EUI-64) datatype support

On 10/12/16, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Alvaro Herrera <alvherre@2ndquadrant.com> writes:

Tom Lane wrote:

Vitaly Burovoy <vitaly.burovoy@gmail.com> writes:

P.S.: I still think it is a good idea to change storage format,

I'm not sure which part of "no" you didn't understand,

I just paid attention to the words "likelihood" (mixed up with
"likeliness"), "we wanted" and "probably".
Also there was a note about "would also break send/recv" which
behavior can be saved.
And after your letter Julien Rouhaud wrote about mapping from MAC-48
to EUI-64 which leads absence of a bit indicated version of a stored
value. Which can be considered as a new information.

but we're
not breaking on-disk compatibility of existing macaddr columns.

Can I ask why? It will not be a varlen (typstorage will not be
changed), it just changes typlen to 8 and typalign to 'd'.
For every major release 9.0, 9.1, 9.2 .. 9.6 the docs says "A
dump/restore using pg_dumpall, or use of pg_upgrade, is required".
Both handle changes in a storage format. Do they?

Breaking the on-the-wire binary I/O representation seems like a
nonstarter as well.

I wrote that for the EUI-48 (MAC-48) values the binary I/O
representation can be saved.
The binary format (in DataRow message) has a length of the column
value which is reflected in PGresAttValue.len in libpq.
If the client works with the binary format it must consult with the
length of the data.
But until the client works with (and columns have) MAC-48 nothing
hurts it and PGresAttValue.len is "6" as now.

I think the suggestion was to rename macaddr to macaddr6 or similar,
keeping the existing behavior and the current OID. So existing columns
would continue to work fine and maintain on-disk compatibility, but any
newly created columns would become the 8-byte variant.

... and would have different I/O behavior from before, possibly breaking
applications that expect "macaddr" to mean what it used to. I'm still
dubious that that's a good idea.

Only if a new type will send xx:xx:xx:FF:FF:xx:xx:xx instead of usual
(expected) 6 octets long.
Again, that case in my offer is similar (by I/O behavior) to "just
change 'macaddr' to keep and accept both MAC-48 and MAC-64", but
allows to use "-k" key for pg_upgrade to prevent rewriting possibly
huge (for instance, 'log') tables (but users unexpectedly get
"macaddr6" after upgrade in their columns and function names which
looks strange enough).

The larger picture here is that we got very little thanks when we squeezed
IPv6 into the pre-existing inet datatype;

Without a sarcasm, I thank a lot all people involved in it because it
does not hurt me (and many other people) from distinguishing ipv4 and
ipv6 at app-level.
I write apps and just save remote address of clients to an "inet"
column named "remote_ip" without thinking "what if we start serving
clients via ipv6?"; or have a column named "allowed_ip" with IPs or
subnets and just save client's IPv4 or IPv6 as a white list (and use
"allowed_ip >>= $1"). It just works.

there's a large number of people
who just said "no thanks" and started using the add-on ip4r type instead.

I found a repository[1]https://github.com/petere/ip4r-cvs at github. From the description it is
understandable why people used ip4r those days (2005 year). The reason
"Furthermore, they are variable length types (to support ipv6) with
non-trivial overheads" is mentioned as the last in its README.
When you deal with IPv4 in 99.999%, storing it in TOAST tables leads
to a big penalty, but the new version of macaddr is not so wide, so it
does not lead to similar speed decrease (it will be stored inplace).

So I'm not sure why we want to complicate our lives in order to make
macaddr follow the same path.

Because according to the Wiki[3]https://en.wikipedia.org/wiki/MAC_address MAC addresses now "are formed
according to the rules of one of three numbering name spaces ...:
MAC-48, EUI-48, and EUI-64.", so IEEE extended range of allowed values
from 48 to 64 bits and since Postgres claims supporting of "mac
addresses", I (as a developer who still uses PG as a primary database)
expect supporting of any kind of mac address, not a limited one. I
expect it is just works.

I reject to imagine what I have to do if I have a column of a type
"macaddr" and unexpectedly I have to deal with an input of EUI-64
type. Add a new column or change columns's type?

In the first case what to do with stored procedures? Duplicate input
parameter to pass the new column of macaddr8 (if macaddr was passed
before)? Duplicate stored procedure?
Also I have to support two columns at the application level. Why? I
just want to store it in the DB, work with it there and get it back!

In the second case (if output will not be mapped to MAC-48 when it is
possible) I have the same troubles as you wrote (oid, I/O and text
representation at least for output, may be also for input).
Moreover I still have to rewrite tables but not when I'm ready for it
(at a migration stage from one major version to another), but when the
task appears.

===
I see no type (besides integers, floats and related with them: their
ranges and arrays ) where numbers appears indicating their capacity:

postgres=# select typname from pg_type where typname ~ '[0-9]' and
typname not like 'pg_toast_%';
typname
-------------
int8
int2
int2vector
int4
float4
float8
_int2
_int2vector
_int4
_int8
_float4
_float8
int4range
_int4range
int8range
_int8range
(16 rows)

So why should we have the name "macaddr" without capacity number and
(unexpectedly) macaddr8 (when a different number appears in the
official name "EAI-64")?

===
I offer a change when the current behavior is not changed for MAC-48
values at all (for textual and binary I/O), internal representation is
always 64bit long, and input and output are mapped from (and when it
is possible to) MAC-48 to seamless usage of a "mac address" concept.

P.S.: Note that the current version[2]https://github.com/RhodiumToad/ip4r of ip4r has the "ipaddress"
type for both IPv4 and IPv6 like the "inet" has. We'll end up having a
single type for both MAC-48 and MAC-64. Why don't do it immediately
(without intermediate types)?
While time passes more and more hardware have EUI-64; the same as more
and more clients have IPv6.

P.P.S.: I played around a length of a value in the binary format (in a
client and in the "macaddr_recv"). It is possible to distinguish
MAC-48 to EUI-64 inputs in "macaddr_recv", so there is no changes
necessary at the client side while it works with the MAC-48 format
only.

[1]: https://github.com/petere/ip4r-cvs
[2]: https://github.com/RhodiumToad/ip4r
[3]: https://en.wikipedia.org/wiki/MAC_address

--
Best regards,
Vitaly Burovoy

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#20Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Vitaly Burovoy (#19)
Re: macaddr 64 bit (EUI-64) datatype support

On Thu, Oct 13, 2016 at 4:10 PM, Vitaly Burovoy <vitaly.burovoy@gmail.com>
wrote:

On 10/12/16, Tom Lane <tgl@sss.pgh.pa.us> wrote:

but we're
not breaking on-disk compatibility of existing macaddr columns.

Can I ask why? It will not be a varlen (typstorage will not be
changed), it just changes typlen to 8 and typalign to 'd'.
For every major release 9.0, 9.1, 9.2 .. 9.6 the docs says "A
dump/restore using pg_dumpall, or use of pg_upgrade, is required".
Both handle changes in a storage format. Do they?

macaddr is not a varlena datatype, all the varlena datatypes stores the
length of the data in the header byte because of variable length data
they can hold.

As the macaddr datatype is not that type, so changing the storage size
from 6 to 8 will break the on-disk compatibility, thus it can cause users
to use only pg_dump to upgrade to version 10. pg_upgrade doesn't
handle the changes in storage format.

Just because of a single datatype, loosing the option of using pg_upgrade
is huge and it is not worth as I feel.

Breaking the on-the-wire binary I/O representation seems like a
nonstarter as well.

I wrote that for the EUI-48 (MAC-48) values the binary I/O
representation can be saved.
The binary format (in DataRow message) has a length of the column
value which is reflected in PGresAttValue.len in libpq.
If the client works with the binary format it must consult with the
length of the data.
But until the client works with (and columns have) MAC-48 nothing
hurts it and PGresAttValue.len is "6" as now.

By taking some steps, yes, it is possible to accept both 48-bit and 64-bit
address into a single macaddr datatype.

But I feel this should be done with a new datatype and eventually drop
the old datatype after some time.

===
I see no type (besides integers, floats and related with them: their
ranges and arrays ) where numbers appears indicating their capacity:

postgres=# select typname from pg_type where typname ~ '[0-9]' and
typname not like 'pg_toast_%';
typname
-------------
int8
int2
int2vector
int4
float4
float8
_int2
_int2vector
_int4
_int8
_float4
_float8
int4range
_int4range
int8range
_int8range
(16 rows)

So why should we have the name "macaddr" without capacity number and
(unexpectedly) macaddr8 (when a different number appears in the
official name "EAI-64")?

===
I offer a change when the current behavior is not changed for MAC-48
values at all (for textual and binary I/O), internal representation is
always 64bit long, and input and output are mapped from (and when it
is possible to) MAC-48 to seamless usage of a "mac address" concept.

I agree that adding new datatype whenever the standards are changed to
store the MAC address, instead the new datatype that we are going to add
now can changed as an varlena datatype, so it can handle any length mac
addresses.

The current macaddr datatype needs to be kept for some time by renaming
it without changing OID and use the newer one for further usage.

Regards,
Hari Babu
Fujitsu Australia

#21Shay Rojansky
roji@roji.org
In reply to: Haribabu Kommi (#20)
#22Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#15)
#23Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#6)
#24Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Shay Rojansky (#21)
#25Peter Eisentraut
peter_e@gmx.net
In reply to: Haribabu Kommi (#24)
#26Robert Haas
robertmhaas@gmail.com
In reply to: Bruce Momjian (#23)
#27Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Peter Eisentraut (#25)
#28Shay Rojansky
roji@roji.org
In reply to: Haribabu Kommi (#27)
#29Peter Eisentraut
peter_e@gmx.net
In reply to: Shay Rojansky (#28)
#30Shay Rojansky
roji@roji.org
In reply to: Peter Eisentraut (#29)
#31Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Shay Rojansky (#30)
#32Shay Rojansky
roji@roji.org
In reply to: Haribabu Kommi (#31)
#33Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Haribabu Kommi (#27)
#34Stephen Frost
sfrost@snowman.net
In reply to: Shay Rojansky (#32)
#35Tom Lane
tgl@sss.pgh.pa.us
In reply to: Stephen Frost (#34)
#36Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#35)
#37Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Robert Haas (#36)
#38Tom Lane
tgl@sss.pgh.pa.us
In reply to: Haribabu Kommi (#37)
#39Jon Nelson
jnelson+pgsql@jamponi.net
In reply to: Tom Lane (#38)
#40Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Tom Lane (#38)
#41Tom Lane
tgl@sss.pgh.pa.us
In reply to: Haribabu Kommi (#40)
#42Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Tom Lane (#41)
#43Tom Lane
tgl@sss.pgh.pa.us
In reply to: Haribabu Kommi (#42)
#44Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Tom Lane (#43)
#45Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Haribabu Kommi (#44)
#46Vitaly Burovoy
vitaly.burovoy@gmail.com
In reply to: Haribabu Kommi (#45)
#47Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Vitaly Burovoy (#46)
#48Kuntal Ghosh
kuntalghosh.2007@gmail.com
In reply to: Haribabu Kommi (#47)
#49Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Kuntal Ghosh (#48)
#50Kuntal Ghosh
kuntalghosh.2007@gmail.com
In reply to: Haribabu Kommi (#49)
#51Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Kuntal Ghosh (#50)
#52Vitaly Burovoy
vitaly.burovoy@gmail.com
In reply to: Haribabu Kommi (#51)
#53Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Vitaly Burovoy (#52)
#54Vitaly Burovoy
vitaly.burovoy@gmail.com
In reply to: Haribabu Kommi (#53)
#55Kuntal Ghosh
kuntalghosh.2007@gmail.com
In reply to: Haribabu Kommi (#53)
#56Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Vitaly Burovoy (#54)
#57Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Kuntal Ghosh (#55)
#58Vitaly Burovoy
vitaly.burovoy@gmail.com
In reply to: Haribabu Kommi (#57)
#59Michael Paquier
michael@paquier.xyz
In reply to: Vitaly Burovoy (#58)
#60Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Vitaly Burovoy (#58)
#61Vitaly Burovoy
vitaly.burovoy@gmail.com
In reply to: Haribabu Kommi (#60)
#62Kuntal Ghosh
kuntalghosh.2007@gmail.com
In reply to: Vitaly Burovoy (#61)
#63Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Vitaly Burovoy (#61)
#64Stephen Frost
sfrost@snowman.net
In reply to: Haribabu Kommi (#63)
#65Stephen Frost
sfrost@snowman.net
In reply to: Stephen Frost (#64)
#66Stephen Frost
sfrost@snowman.net
In reply to: Stephen Frost (#65)
#67Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Stephen Frost (#65)
#68Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Stephen Frost (#66)
#69Stephen Frost
sfrost@snowman.net
In reply to: Haribabu Kommi (#68)
#70Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Stephen Frost (#69)
#71Andres Freund
andres@anarazel.de
In reply to: Stephen Frost (#69)
#72Stephen Frost
sfrost@snowman.net
In reply to: Andres Freund (#71)
#73Stephen Frost
sfrost@snowman.net
In reply to: Andres Freund (#71)