# frozen_string_literal: true

# This file is part of PacketGen
# See https://github.com/lemontree55/packetgen for more informations
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
# This program is published under MIT license.

module PacketGen
  module Header
    class DHCPv6
      # DHCPv6 Relay agent / server header
      # @author Sylvain Daubert
      class Relay < Base
        # DHCPv6 Relay message types
        MESSAGE_TYPES = {
          'RELAY-FORW' => 12,
          'RELAY-REPL' => 13
        }.freeze

        # @!attribute msg_type
        #   8-bit message type
        #   @return [Integer]
        define_attr :msg_type, BinStruct::Int8Enum, enum: MESSAGE_TYPES
        # @!attribute hop_count
        #   8-bit hop count (number of relay agents that have relayed
        #   this message)
        #   @return [Integer]
        define_attr :hop_count, BinStruct::Int8
        # @!attribute link
        #   Link address: address that will be used by the server to identify
        #   the link on which the client is located
        #   @return [IPv6::Addr]
        define_attr :link, IPv6::Addr
        # @!attribute peer
        #   Peer address: the address of the client or relay agent from which
        #   the message to be relayed was received
        #   @return [IPv6::Addr]
        define_attr :peer, IPv6::Addr
        # @!attribute options
        #   Set of {Option}s
        #   @return [DHCPv6::Options]
        define_attr :options, DHCPv6::Options
      end
    end

    UDP.bind DHCPv6::Relay, sport: DHCPv6::UDP_CLIENT_PORT
    UDP.bind DHCPv6::Relay, dport: DHCPv6::UDP_SERVER_PORT
    UDP.bind DHCPv6::Relay, sport: DHCPv6::UDP_SERVER_PORT
    UDP.bind DHCPv6::Relay, dport: DHCPv6::UDP_CLIENT_PORT
  end
end
