Class: PacketGen::Header::DHCPv6

Inherits:
Base show all
Defined in:
lib/packetgen/header/dhcpv6.rb,
lib/packetgen/header/dhcpv6.rb,
lib/packetgen/header/dhcpv6/duid.rb,
lib/packetgen/header/dhcpv6/relay.rb,
lib/packetgen/header/dhcpv6/option.rb,
lib/packetgen/header/dhcpv6/options.rb

Overview

Dynamic Host Configuration Protocol for IPv6, RFC 3315

 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    msg-type   |               transaction-id                  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                            options                            .
.                           (variable)                          .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

A DHCPv6 header is made of:

Create a DHCPv6 header

 # standalone
dhcpv6 = PacketGen::Header::DHCPv6.new(msg_type: 'SOLLICIT')
# in a packet
pkt = PacketGen.gen('IPv6').add('DHCPv6', msg_type: 'SOLLICIT')
# access to DHCPv6 header from packet
pkt.dhcpv6    #=> PacketGen::Header::DHCPv6

Add options

DHCPv6 options are defined by subclasses of Option.

Options may be added by pushing a hash to #options:

dhcpv6 = PacketGen::Header::DHCPv6.new(msg_type: 'SOLLICIT')
dhcpv6.options << { type: 'Preference', value: 1 }

Author:

  • Sylvain Daubert

Since:

  • 2.5.0

Defined Under Namespace

Classes: ClientID, DUID, DUID_EN, DUID_LL, DUID_LLT, ElapsedTime, IAAddr, IANA, IATA, ORO, Option, Options, Preference, RapidCommit, Relay, RelayMessage, RequestedOptions, ServerID, ServerUnicast, StatusCode

Constant Summary collapse

UDP_CLIENT_PORT =

DHCPv6 UDP client port

Since:

  • 2.5.0

546
UDP_SERVER_PORT =

DHCPv6 UDP client port

Since:

  • 2.5.0

547
MESSAGE_TYPES =

DHCPv6 message types

Since:

  • 2.5.0

{
  'SOLLICIT' => 1,
  'ADVERTISE' => 2,
  'REQUEST' => 3,
  'CONFIRM' => 4,
  'RENEW' => 5,
  'REBIND' => 6,
  'REPLY' => 7,
  'RELEASE' => 8,
  'DECLINE' => 9,
  'RECONFIGURE' => 10,
  'INFORMATION-REQUEST' => 11
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

bind, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, #ll_header

Methods included from PacketGen::Headerable

#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name

Methods inherited from Types::Fields

#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #initialize, #inspect, #offset_of, #optional?, #optional_fields, #present?, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

This class inherits a constructor from PacketGen::Header::Base

Instance Attribute Details

#msg_typeInteger

8-bit message type

Returns:

  • (Integer)


75
# File 'lib/packetgen/header/dhcpv6.rb', line 75

define_field :msg_type, Types::Int8Enum, enum: MESSAGE_TYPES

#optionsDHCPv6::Options

Returns:



82
# File 'lib/packetgen/header/dhcpv6.rb', line 82

define_field :options, DHCPv6::Options

#transaction_idObject

24-bit transaction ID



79
# File 'lib/packetgen/header/dhcpv6.rb', line 79

define_field :transaction_id, Types::Int24

Instance Method Details

#human_msg_typeString

Get human readable message type

Returns:

  • (String)

Since:

  • 2.5.0



100
101
102
# File 'lib/packetgen/header/dhcpv6.rb', line 100

def human_msg_type
  self[:msg_type].to_human
end

#read(str) ⇒ DHCPv6, DHCPv6::Relay

Populate object from string

Parameters:

  • str (String)

Returns:

Since:

  • 2.5.0



87
88
89
90
91
92
93
94
95
96
# File 'lib/packetgen/header/dhcpv6.rb', line 87

def read(str)
  msg_type = Types::Int8.new.read(str)

  case msg_type
  when 12, 13
    DHCPv6::Relay.new.read(str)
  else
    super
  end
end