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.



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

def initialize(options={})
  super
  if options[:content]
    self[:content] = BinStruct::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)


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

define_attr :content, BinStruct::String, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:content) }) }

#criticalBoolean

critical flag

Returns:

  • (Boolean)


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

define_bit_attr :flags, critical: 1, hreserved: 7

#flagsInteger

8-bit flags

Returns:

  • (Integer)


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

define_bit_attr :flags, critical: 1, hreserved: 7

#hreservedInteger

reserved part of #flags field

Returns:

  • (Integer)


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

define_bit_attr :flags, critical: 1, hreserved: 7

#lengthInteger

16-bit payload total length, including generic payload Plugin

Returns:

  • (Integer)


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

define_attr :length, BinStruct::Int16

#nextInteger

8-bit next payload

Returns:

  • (Integer)


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

define_attr :next, BinStruct::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



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