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.



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

def initialize(options={})
  super
  self[:content].replace(options[:content]) if options[:content]
  calc_length unless options[:length]
end

Instance Attribute Details

#contentString

Payload content. Depends on payload. Variable length.

Returns:

  • (String)


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

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

#criticalBoolean

critical flag

Returns:

  • (Boolean)


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

define_bit_fields_on :flags, :critical, :hreserved, 7

#flagsInteger

8-bit flags

Returns:

  • (Integer)


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

define_field :flags, PacketGen::Types::Int8

#hreservedInteger

reserved part of #flags field

Returns:

  • (Integer)


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

define_bit_fields_on :flags, :critical, :hreserved, 7

#lengthInteger

16-bit payload total length, including generic payload Plugin

Returns:

  • (Integer)


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

define_field :length, PacketGen::Types::Int16

#nextInteger

8-bit next payload

Returns:

  • (Integer)


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

define_field :next, PacketGen::Types::Int8

Class Method Details

.protocol_nameString

Give protocol name

Returns:

  • (String)


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

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



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

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