Class: PacketGen::Plugin::IKE::Attribute

Inherits:
Types::Fields
  • Object
show all
Defined in:
lib/packetgen/plugin/ike/sa.rb

Overview

Transform attribute.

                     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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|A|       Attribute Type        |    AF=0  Attribute Length     |
|F|                             |    AF=1  Attribute Value      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                   AF=0  Attribute Value                       |
|                   AF=1  Not Transmitted                       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Such an attribute may have a TLV (Type/length/value) format if AF=0, or a TV format (AF=1).

Author:

  • Sylvain Daubert

Constant Summary collapse

TYPE_KEY_LENGTH =

KeyLength attribute type

14

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Attribute

Returns a new instance of Attribute.



41
42
43
44
45
46
47
48
# File 'lib/packetgen/plugin/ike/sa.rb', line 41

def initialize(options={})
  super
  if tv_format?
    self[:length].value = (options[:value] & 0xffff)
  else
    self[:length].value = 8 unless options[:length]
  end
end

Instance Attribute Details

#lengthInteger

Returns:

  • (Integer)


35
# File 'lib/packetgen/plugin/ike/sa.rb', line 35

define_field :length, PacketGen::Types::Int16

#typeInteger

attribute type

Returns:

  • (Integer)


31
# File 'lib/packetgen/plugin/ike/sa.rb', line 31

define_field :type, PacketGen::Types::Int16

#valueInteger

Returns:

  • (Integer)


39
# File 'lib/packetgen/plugin/ike/sa.rb', line 39

define_field :value, PacketGen::Types::Int32, optional: ->(h) { !h.tv_format? }

Instance Method Details

#to_humanString

Get a human readable string

Returns:

  • (String)


64
65
66
67
68
69
# File 'lib/packetgen/plugin/ike/sa.rb', line 64

def to_human
  name = self.class.constants.grep(/TYPE_/)
             .detect { |c| self.class.const_get(c) == (type & 0x7fff) } || "attr[#{type & 0x7fff}]"
  name = name.to_s.sub(/TYPE_/, '')
  "#{name}=#{value}"
end

#tv_format?Boolean

Say if attribute use TV format (true) or TLV one (false)

Returns:

  • (Boolean)


73
74
75
# File 'lib/packetgen/plugin/ike/sa.rb', line 73

def tv_format?
  type & 0x8000 == 0x8000
end