While preparing for my final exams I stumbled across some question:
Please calculate the IPv6 link-local Address from the following MAC Address…
Good question.
Well, it’s pretty easy if you know how to do it.
Let’s say you have the following (hypothetical) MAC Address:
5f:4e:3d:2c:1b:0a
First thing, you have to add some ff:fe
in the middle:
5f:4e:3d:ff:fe:2c:1b:0a
Now for the tricky part - the calculation.
Look at the first part, in this case 5f
. Convert it from HEX to BIN
(see table below if you need help):
5 f (HEX)
0 1 0 1 1 1 1 1 (BIN)
The second to last bit needs to be flipped. Or more technically speaking
the result needs to be XORed with 0 0 0 0 0 0 1 0
.
0 1 0 1 1 1 1 1
0 0 0 0 0 0 1 0 (XOR)
0 1 0 1 1 1 0 1
Lastly, convert it back to HEX:
0 1 0 1 1 1 0 1 (BIN)
5 d (HEX)
Now we get the following:
5d:4e:3d:ff:fe:2c:1b:0a
As a final step add the prefix fe80
, fill it with zeros and format
it like a proper IPv6 Address:
fe80::5d4e:3dff:fe2c:1b0a
As I told you - pretty easy.
HEX | BIN | — | HEX | BIN |
---|---|---|---|---|
0 | 0 0 0 0 | 8 | 1 0 0 0 | |
1 | 0 0 0 1 | 9 | 1 0 0 1 | |
2 | 0 0 1 0 | a | 1 0 1 0 | |
3 | 0 0 1 1 | b | 1 0 1 1 | |
4 | 0 1 0 0 | c | 1 1 0 0 | |
5 | 0 1 0 1 | d | 1 1 0 1 | |
6 | 0 1 1 0 | e | 1 1 1 0 | |
7 | 0 1 1 1 | f | 1 1 1 1 |
A | B | XOR |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
The other way around is similar – chomp both fe80::
and ff:fe
, then
use the same XOR operation as above.
If you know all this above, you can easily spot generated link-local addresses,
when they contain some ff:fe
.
There are some operation systems around that use randomly generated ones - so don’t be confused if your machine does not generate one like above. I don’t know if this is compliant with the spec…
So long!
Update:
Just fixed some mistake – the final address was incorrect, I forgot to add leading zeros:
Changed: fe80:
→ fe80::
Further – If you want to know more, take a look at those RFCs:
4291 IP Version 6 Addressing Architecture – Section 2.5.6 Link-Local IPv6 Unicast Addresses
4862 IPv6 Stateless Address Autoconfiguration – Section 5.3 Creation of Link-Local Addresses
7721 Security and Privacy Considerations for IPv6 Address Generation Mechanisms
4941 Privacy Extensions for Stateless Address Autoconfiguration in IPv6
So, yes, using randomly generated link-local addresses is compliant with the spec…