#  -*- 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: 101b30bb3d1228b5509b2bb93403118a1b40b414 $
#

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           |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#

#
#  4.  DUID-UUID Format
#
#  The DUID-UUID is carried within Client Identifier or Server
#  Identifier options.  It has the following format:
#
#  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
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |          DUID-Type (4)        |    UUID (128 bits)            |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               |
#  |                                                               |
#  |                                                               |
#  |                                -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |                                |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#
#  Figure 1: DUID-UUID Format
#
#  DUID-Type -  DUID-UUID (4) - (16 bits)
#  UUID -  An [RFC4122] UUID (128 bits)
#

#
#  Client Identifier
#

#  Define the DUID-LLT + DUID
encode-pair Client-ID.DUID = UUID
match 00 01 00 02 00 04

decode-pair -
match Client-ID = { DUID = ::UUID }

#  Encode a 16-octet UUID
encode-pair Client-ID.DUID = UUID, Client-ID.DUID.UUID.Value = 0x000102030405060708090a0b0c0d0e0f
match 00 01 00 12 00 04 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f

decode-pair -
match Client-ID = { DUID = ::UUID, DUID.UUID = { Value = 0x000102030405060708090a0b0c0d0e0f } }

#  UUID-Value field is 16 octets.  So we truncate if if it's too long, and pad it with zeros if it's too short.
encode-pair Client-ID.DUID = UUID, Client-ID.DUID.UUID.Value = 0x000102030405060708090a0b0c0d0e0f1112
match 00 01 00 12 00 04 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f

#  But if we decode something that's too long, we ignore the extra data
decode-pair -
match Client-ID = { DUID = ::UUID, DUID.UUID = { Value = 0x000102030405060708090a0b0c0d0e0f } }

#  Or we pad the UUID to 16 octets if it's too short
encode-pair Client-ID.DUID = UUID, Client-ID.DUID.UUID.Value = 0x000102030405060708090a0b0c0d
match 00 01 00 12 00 04 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 00 00

#  And if we see something that's too short, we get a bad attribute.
decode-pair 00 01 00 10 00 04 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d
match Client-ID = { DUID = ::UUID, raw.DUID.UUID = 0x000102030405060708090a0b0c0d }

#
#  Server Identifier
#

#  Define the DUID-LLT + DUID
encode-pair Server-ID.DUID = UUID
match 00 02 00 02 00 04

decode-pair -
match Server-ID = { DUID = ::UUID }

#  Encode a 16-octet UUID
encode-pair Server-ID.DUID = UUID, Server-ID.DUID.UUID.Value = 0x000102030405060708090a0b0c0d0e0f
match 00 02 00 12 00 04 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f

decode-pair -
match Server-ID = { DUID = ::UUID, DUID.UUID = { Value = 0x000102030405060708090a0b0c0d0e0f } }

#  UUID-Value field is 16 octets.  So we truncate if if it's too long, and pad it with zeros if it's too short.
encode-pair Server-ID.DUID = UUID, Server-ID.DUID.UUID.Value = 0x000102030405060708090a0b0c0d0e0f1112
match 00 02 00 12 00 04 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f

#  But if we decode something that's too long, we ignore the extra data
decode-pair -
match Server-ID = { DUID = ::UUID, DUID.UUID = { Value = 0x000102030405060708090a0b0c0d0e0f } }

#  Or we pad the UUID to 16 octets if it's too short
encode-pair Server-ID.DUID = UUID, Server-ID.DUID.UUID.Value = 0x000102030405060708090a0b0c0d
match 00 02 00 12 00 04 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 00 00

decode-pair -
match Server-ID = { DUID = ::UUID, DUID.UUID = { Value = 0x000102030405060708090a0b0c0d0000 } }

#  And if we see something that's too short, we get a bad attribute.
decode-pair 00 02 00 10 00 04 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d
match Server-ID = { DUID = ::UUID, raw.DUID.UUID = 0x000102030405060708090a0b0c0d }

count
match 37
