From c7a9fa399d557c6366222e90b35db31e45d25678 Mon Sep 17 00:00:00 2001 From: Stephen Frost Date: Wed, 15 Mar 2017 11:16:25 -0400 Subject: Add support for EUI-64 MAC addresses as macaddr8 This adds in support for EUI-64 MAC addresses by adding a new data type called 'macaddr8' (using our usual convention of indicating the number of bytes stored). This was largely a copy-and-paste from the macaddr data type, with appropriate adjustments for having 8 bytes instead of 6 and adding support for converting a provided EUI-48 (6 byte format) to the EUI-64 format. Conversion from EUI-48 to EUI-64 inserts FFFE as the 4th and 5th bytes but does not perform the IPv6 modified EUI-64 action of flipping the 7th bit, but we add a function to perform that specific action for the user as it may be commonly done by users who wish to calculate their IPv6 address based on their network prefix and 48-bit MAC address. Author: Haribabu Kommi, with a good bit of rework of macaddr8_in by me. Reviewed by: Vitaly Burovoy, Kuntal Ghosh Discussion: https://postgr.es/m/CAJrrPGcUi8ZH+KkK+=TctNQ+EfkeCEHtMU_yo1mvX8hsk_ghNQ@mail.gmail.com --- doc/src/sgml/brin.sgml | 11 ++++++ doc/src/sgml/btree-gin.sgml | 3 +- doc/src/sgml/btree-gist.sgml | 4 +-- doc/src/sgml/datatype.sgml | 83 ++++++++++++++++++++++++++++++++++++++++++++ doc/src/sgml/func.sgml | 56 ++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 3 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/brin.sgml b/doc/src/sgml/brin.sgml index 6448b18e465..5bf11dc2d15 100644 --- a/doc/src/sgml/brin.sgml +++ b/doc/src/sgml/brin.sgml @@ -281,6 +281,17 @@ > + + macaddr8_minmax_ops + macaddr8 + + < + <= + = + >= + > + + name_minmax_ops name diff --git a/doc/src/sgml/btree-gin.sgml b/doc/src/sgml/btree-gin.sgml index 2b081db9d5a..0de8eb5c309 100644 --- a/doc/src/sgml/btree-gin.sgml +++ b/doc/src/sgml/btree-gin.sgml @@ -16,7 +16,8 @@ time without time zone, date, interval, oid, money, "char", varchar, text, bytea, bit, - varbit, macaddr, inet, and cidr. + varbit, macaddr, macaddr8, inet, + and cidr. diff --git a/doc/src/sgml/btree-gist.sgml b/doc/src/sgml/btree-gist.sgml index d08647ce05a..cfdd5be84af 100644 --- a/doc/src/sgml/btree-gist.sgml +++ b/doc/src/sgml/btree-gist.sgml @@ -16,8 +16,8 @@ time without time zone, date, interval, oid, money, char, varchar, text, bytea, bit, - varbit, macaddr, inet, cidr, - and uuid. + varbit, macaddr, macaddr8, inet, + cidr and uuid. diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index 35610307d9a..e2f8dee7b66 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -166,6 +166,12 @@ MAC (Media Access Control) address + + macaddr8 + + MAC (Media Access Control) address (EUI-64 format) + + money @@ -3428,6 +3434,12 @@ SELECT person.name, holidays.num_weeks FROM person, holidays MAC addresses + + macaddr8 + 8 bytes + MAC addresses (EUI-64 format) + + @@ -3668,6 +3680,77 @@ SELECT person.name, holidays.num_weeks FROM person, holidays + + <type>macaddr8</type> + + + macaddr8 (data type) + + + + MAC address (EUI-64 format) + macaddr + + + + The macaddr8 type stores MAC addresses in EUI-64 + format, known for example from Ethernet card hardware addresses + (although MAC addresses are used for other purposes as well). + This type can accept both 6 and 8 byte length MAC addresses + and stores them in 8 byte length format. MAC addresses given + in 6 byte format will be stored in 8 byte length format with the + 4th and 5th bytes set to FF and FE, respectively. + + Note that IPv6 uses a modified EUI-64 format where the 7th bit + should be set to one after the conversion from EUI-48. The + function macaddr8_set7bit is provided to make this + change. + + Generally speaking, any input which is comprised of pairs of hex + digits (on byte boundaries), optionally separated consistently by + one of ':', '-' or '.', is + accepted. The number of hex digits must be either 16 (8 bytes) or + 12 (6 bytes). Leading and trailing whitespace is ignored. + + The following are examples of input formats that are accepted: + + + '08:00:2b:01:02:03:04:05' + '08-00-2b-01-02-03-04-05' + '08002b:0102030405' + '08002b-0102030405' + '0800.2b01.0203.0405' + '0800-2b01-0203-0405' + '08002b01:02030405' + '08002b0102030405' + + + These examples would all specify the same address. Upper and + lower case is accepted for the digits + a through f. Output is always in the + first of the forms shown. + + The last six input formats that are mentioned above are not part + of any standard. + + To convert a traditional 48 bit MAC address in EUI-48 format to + modified EUI-64 format to be included as the host portion of an + IPv6 address, use macaddr8_set7bit as shown: + + +SELECT macaddr8_set7bit('08:00:2b:01:02:03'); + + macaddr8_set7bit +------------------------- + 0a:00:2b:ff:fe:01:02:03 +(1 row) + + + + + + + diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 583b3b241ab..a521912317b 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -9228,6 +9228,62 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple for NOT, AND and OR. + + shows the functions + available for use with the macaddr8 type. The function + trunc(macaddr8) returns a MAC + address with the last 5 bytes set to zero. This can be used to + associate the remaining prefix with a manufacturer. + + + + <type>macaddr8</type> Functions + + + + Function + Return Type + Description + Example + Result + + + + + + + trunc + + trunc(macaddr8) + + macaddr8 + set last 5 bytes to zero + trunc(macaddr8 '12:34:56:78:90:ab:cd:ef') + 12:34:56:00:00:00:00:00 + + + + + macaddr8_set7bit + + macaddr8_set7bit(macaddr8) + + macaddr8 + set 7th bit to one, also known as modified EUI-64, for inclusion in an IPv6 address + macaddr8_set7bit(macaddr8 '00:34:56:ab:cd:ef') + 02:34:56:ff:fe:ab:cd:ef + + + +
+ + + The macaddr8 type also supports the standard relational + operators (>, <=, etc.) for + ordering, and the bitwise arithmetic operators (~, + & and |) for NOT, AND and OR. + +
-- cgit v1.2.3