I stumbled upon a piece of code on GitHub: https://github.com/adeverteuil/bash-ula-generator/blob/master/gen-ula.sh
# Generate an EUI64 from the MAC address
# as described in RFC 3513
# https://tools.ietf.org/html/rfc3513
first=`echo $mac | cut -c1-1`
second=`echo $mac | cut -c2-2`
macu=`echo $mac | cut -c3-6`
macl=`echo $mac | cut -c7-12`
# reversing u/l bit
case $second in
[13579bdf])
die "MAC-address \"${mac}\" is a group MAC address"
;;
0)
second_rev=2
;;
2)
second_rev=0
;;
4)
second_rev=6;
;;
6)
second_rev=4;
;;
8)
second_rev=a;
;;
a)
second_rev=8;
;;
c)
second_rev=e;
;;
e)
second_rev=c;
;;
*)
#impossible
die "MAC address \"${mac}\" is registered to the IEEE database, "\
"but the first octet (${first}${second}) is regarded as invalid. "\
"(probably a bug in this script...)"
esac
eui64="${first}${second_rev}${macu}fffe${macl}"
TLDR: While reversing the 7th bit of the MAC OUI to create an EUI-64, the author assumes that the 8th bit is always binary 0. I immediately check more than 100 clients on my DHCP server and strangely enough, none ends with an odd number on the first octet — they are always something like:
- dc:0c:5c:c9:53:36
- 40:9f:38:4b:69:08
- 18:d7:17:55:61:d1
- 34:c3:d2:70:ad:be
- (and so on…)
Why it always end with a binary 0?
Best Answer
You may notice that two least-significant bits of the most-significant byte of a 48-bit MAC address are usually set to
0
(as in all your examples). There are two flags in the most-significant byte of the OUI (Organizationally Unique Identifier, which are the most-significant 24-bits) part of the MAC address:Actually, that is creating a Modified EUI-64. You would never assign a group address (I/G flag set) to an interface or unicast address, and you do set the U/L flag to show that it is a locally administered address. The Modified EUI-64 from 48-bit MAC algorithm (and others) is explained in RFC 4291, IP Version 6 Addressing Architecture, Appendix A: Creating Modified EUI-64 Format Interface Identifiers, which obsoleted RFC 3513, IP Version 6 Addressing Architecture to which your code example refers. Basically, you split the 48-bit MAC address in half, insert
fffe
in the middle, and set the U/L flag to indicate a locally administered address (see my highlights below, including the note at the end):