#  -*- text -*-
#  Copyright (C) 2019 Network RADIUS SARL (legal@networkradius.com)
#  This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0
#
#  Version $Id: 8b140af6dcd46478d6376f0cee8735ce4b443133 $
#

proto dhcpv6
proto-dictionary dhcpv6
fuzzer-out dhcpv6

#
#  Encoding an option header:
#
#   0                   1                   2                   3
#   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |        OPTION_CLIENTID        |          option-len           |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#

#  From RFC 3315
#
#  9.2. DUID Based on Link-layer Address Plus Time [DUID-LLT]
#
#  The following diagram illustrates the format of a DUID-LLT:
#
#   0                   1                   2                   3
#   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |               1               |    hardware type (16 bits)    |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |                        time (32 bits)                         |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  .                                                               .
#  .             link-layer address (variable length)              .
#  .                                                               .
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#

#
#  Client Identifier
#

#  Define the DUID-LLT + DUID
encode-pair Client-ID.DUID = LLT, Client-ID.DUID.LLT.Hardware-Type = 1, Client-ID.DUID.LLT.Time = "Jan  1 2000 12:00:00 UTC", Client-ID.DUID.LLT.Hardware-Type.Ethernet.Address = aa:bb:cc:dd:ee:ff
match 00 01 00 0e 00 01 00 01 00 00 a8 c0 aa bb cc dd ee ff

decode-pair -
match Client-ID = { DUID = ::LLT, DUID.LLT = { Hardware-Type = ::Ethernet, Time = "2000-01-01T12:00:00Z", Hardware-Type.Ethernet = { Address = aa:bb:cc:dd:ee:ff } } }

#
#  Server Identifier
#

#  Define the DUID-LLT + DUID
encode-pair Server-ID.DUID = LLT, Server-ID.DUID.LLT.Hardware-Type = Ethernet, Server-ID.DUID.LLT.Time = "Jan  1 2000 12:00:00 UTC", Server-ID.DUID.LLT.Hardware-Type.Ethernet.Address = c0:ff:ee:c0:ff:ee
match 00 02 00 0e 00 01 00 01 00 00 a8 c0 c0 ff ee c0 ff ee

decode-pair -
match Server-ID = { DUID = ::LLT, DUID.LLT = { Hardware-Type = ::Ethernet, Time = "2000-01-01T12:00:00Z", Hardware-Type.Ethernet = { Address = c0:ff:ee:c0:ff:ee } } }

#
#  9.3. DUID Assigned by Vendor Based on Enterprise Number [DUID-EN]
#
#   0                   1                   2                   3
#   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |               2               |       enterprise-number       |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |   enterprise-number (contd)   |                               |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               |
#  .                           identifier                          .
#  .                       (variable length)                       .
#  .                                                               .
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#

#
#  Client Identifier
#

#  Define the DUID-EN + DUID
encode-pair Client-ID.DUID = EN, Client-ID.DUID.EN.Enterprise-Number = 11344, Client-ID.DUID.EN.Identifier = 0xaabbccddeeff
match 00 01 00 0c 00 02 00 00 2c 50 aa bb cc dd ee ff

decode-pair -
match Client-ID = { DUID = ::EN, DUID.EN = { Enterprise-Number = 11344, Identifier = 0xaabbccddeeff } }

#
#  Server Identifier
#

#  Define the DUID-EN + DUID
encode-pair Server-ID.DUID = EN, Server-ID.DUID.EN.Enterprise-Number = 11344, Server-ID.DUID.EN.Identifier = 0xc0ffeec0ffee
match 00 02 00 0c 00 02 00 00 2c 50 c0 ff ee c0 ff ee

decode-pair -
match Server-ID = { DUID = ::EN, DUID.EN = { Enterprise-Number = 11344, Identifier = 0xc0ffeec0ffee } }

#
#  9.4. DUID Based on Link-layer Address [DUID-LL]
#
#   0                   1                   2                   3
#   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |               3               |    hardware type (16 bits)    |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  .                                                               .
#  .             link-layer address (variable length)              .
#  .                                                               .
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#

#
#  Client Identifier
#

#  Define the DUID-LL + DUID
encode-pair Client-ID.DUID = LL, Client-ID.DUID.LL.Hardware-Type = Ethernet, Client-ID.DUID.LL.Hardware-Type.Ethernet.Address = aa:bb:cc:dd:ee:ff
match 00 01 00 0a 00 03 00 01 aa bb cc dd ee ff

decode-pair -
match Client-ID = { DUID = ::LL, DUID.LL = { Hardware-Type = ::Ethernet, Hardware-Type.Ethernet = { Address = aa:bb:cc:dd:ee:ff } } }

#
#  Server Identifier
#

#  Define the DUID-LL + DUID
encode-pair Server-ID.DUID = LL, Server-ID.DUID.LL.Hardware-Type = Ethernet, Server-ID.DUID.LL.Hardware-Type.Ethernet.Address = d3:4d:00:c0:ff:ee
match 00 02 00 0a 00 03 00 01 d3 4d 00 c0 ff ee

decode-pair -
match Server-ID = { DUID = ::LL, DUID.LL = { Hardware-Type = ::Ethernet, Hardware-Type.Ethernet = { Address = d3:4d:00:c0:ff:ee } } }

#
#  And unknown hardware types: hardware type 255 is unassigned
#
#  The hardware type is decoded as an unknown attribute.
#
#  @todo - this should really be decoded as an option with a generic name.
#  this will likely be easier to do once we have real nested TLVs / groups
#
decode-pair 00 02 00 0a 00 03 00 ff d3 4d 00 c0 ff ee
match Server-ID = { DUID = ::LL, DUID.LL = { Hardware-Type = 255, raw.Hardware-Type.0 = 0xd34d00c0ffee } }

count
match 29
