Sha256: 7567510d5fae264b69fc700a7d08ad9aa536b4051cb38b5a1ca24ed9a922ec4b

Contents?: true

Size: 1.89 KB

Versions: 13

Compression:

Stored size: 1.89 KB

Contents

require 'pio/options'
require 'pio/dhcp/common_options'
require 'pio/dhcp/dhcp_tlv_options'

module Pio
  class Dhcp
    # Options for creating a DHCP message.
    class BootReplyOptions < Pio::Options
      include CommonOptions
      include DhcpTlvOptions

      mandatory_option :source_mac
      mandatory_option :destination_mac
      mandatory_option :ip_source_address
      mandatory_option :ip_destination_address
      mandatory_option :type
      option :subnet_mask
      option :renewal_time_value
      option :rebinding_time_value
      option :ip_address_lease_time
      option :server_identifier
      option :transaction_id

      def initialize(options)
        @options = options
      end

      def to_hash
        {
          destination_mac: destination_mac,
          source_mac: source_mac,
          ip_destination_address: ip_destination_address,
          ip_source_address: ip_source_address,
          udp_src_port: BOOTPS,
          udp_dst_port: BOOTPC,
          dhcp: dhcp_data
        }
      end

      private

      def dhcp_field_values
        {
          message_type: BootReply::MESSAGE_TYPE,
          transaction_id: transaction_id,
          client_ip_address: QUAD_ZERO_IP_ADDRESS,
          your_ip_address: ip_destination_address,
          next_server_ip_address: QUAD_ZERO_IP_ADDRESS,
          relay_agent_ip_address: QUAD_ZERO_IP_ADDRESS,
          client_mac_address: source_mac,
          optional_tlvs: options_for_optional_tlv
        }
      end

      def options_for_optional_tlv
        [
          message_type_hash,
          renewal_time_value_hash,
          rebinding_time_value_hash,
          ip_address_lease_time_hash,
          dhcp_server_identifier_hash,
          subnet_mask_hash
        ].compact
      end

      def server_identifier
        IPv4Address.new(
          @options[:server_identifier] || ip_source_address
        )
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
pio-0.15.2 lib/pio/dhcp/boot_reply_options.rb
pio-0.15.1 lib/pio/dhcp/boot_reply_options.rb
pio-0.15.0 lib/pio/dhcp/boot_reply_options.rb
pio-0.14.0 lib/pio/dhcp/boot_reply_options.rb
pio-0.13.0 lib/pio/dhcp/boot_reply_options.rb
pio-0.12.0 lib/pio/dhcp/boot_reply_options.rb
pio-0.11.2 lib/pio/dhcp/boot_reply_options.rb
pio-0.11.1 lib/pio/dhcp/boot_reply_options.rb
pio-0.11.0 lib/pio/dhcp/boot_reply_options.rb
pio-0.10.1 lib/pio/dhcp/boot_reply_options.rb
pio-0.10.0 lib/pio/dhcp/boot_reply_options.rb
pio-0.9.0 lib/pio/dhcp/boot_reply_options.rb
pio-0.8.2 lib/pio/dhcp/boot_reply_options.rb