Class: PacketGen::Plugin::IKE::Payload

Inherits:
Header::Base
  • Object
show all
Defined in:
lib/packetgen/plugin/ike/payload.rb

Overview

PacketGen::Header::Base class for IKE payloads. This class may also be used for unknown payloads.

This class handles generic IKE payload Plugin:

                     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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload  |C|  RESERVED   |         Payload Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

to which a #content field is added to handle content of unknown payload types.

Author:

  • Sylvain Daubert

Direct Known Subclasses

Auth, Cert, IDi, KE, Nonce, Notify, SA, SK, TSi, VendorID

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Payload

Returns a new instance of Payload.



58
59
60
61
62
63
64
65
# File 'lib/packetgen/plugin/ike/payload.rb', line 58

def initialize(options={})
  super
  if options[:content]
    self[:content] = PacketGen::Types::String.new
    self[:content].read options[:content]
  end
  calc_length unless options[:length]
end

Instance Attribute Details

#contentString

Payload content. Depends on payload. Variable length.

Returns:

  • (String)


45
# File 'lib/packetgen/plugin/ike/payload.rb', line 45

define_field :content, PacketGen::Types::String, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:content) }) }

#criticalBoolean

critical flag

Returns:

  • (Boolean)


56
# File 'lib/packetgen/plugin/ike/payload.rb', line 56

define_bit_fields_on :flags, :critical, :hreserved, 7

#flagsInteger

8-bit flags

Returns:

  • (Integer)


37
# File 'lib/packetgen/plugin/ike/payload.rb', line 37

define_field :flags, PacketGen::Types::Int8

#hreservedInteger

reserved part of #flags field

Returns:

  • (Integer)


56
# File 'lib/packetgen/plugin/ike/payload.rb', line 56

define_bit_fields_on :flags, :critical, :hreserved, 7

#lengthInteger

16-bit payload total length, including generic payload Plugin

Returns:

  • (Integer)


41
# File 'lib/packetgen/plugin/ike/payload.rb', line 41

define_field :length, PacketGen::Types::Int16

#nextInteger

8-bit next payload

Returns:

  • (Integer)


33
# File 'lib/packetgen/plugin/ike/payload.rb', line 33

define_field :next, PacketGen::Types::Int8

Class Method Details

.protocol_nameString

Give protocol name

Returns:

  • (String)


23
24
25
26
27
28
# File 'lib/packetgen/plugin/ike/payload.rb', line 23

def self.protocol_name
  return @protocol_name if defined? @protocol_name

  basename = to_s.sub(/.*::/, '')
  @protocol_name = "IKE::#{basename}"
end

Instance Method Details

#calc_lengthInteger

Compute length and set #length field

Returns:

  • (Integer)

    new length



69
70
71
72
73
# File 'lib/packetgen/plugin/ike/payload.rb', line 69

def calc_length
  # Here, #body is next payload, so body size should not be taken in
  # account (payload's real body is #content).
  self.length = sz - self[:body].sz
end