Class: PacketGen::Plugin::IKE::TrafficSelector

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

Overview

TrafficSelector substructure, as defined in RFC 7296, §3.13.1:

                     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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   TS Type     |IP Protocol ID*|       Selector Length         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Start Port*         |           End Port*           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                         Starting Address*                     ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                         Ending Address*                       ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Author:

  • Sylvain Daubert

Constant Summary collapse

TS_IPV4_ADDR_RANGE =

IPv4 traffic selector type

7
TS_IPV6_ADDR_RANGE =

IPv6 traffic selector type

8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TrafficSelector

Returns a new instance of TrafficSelector.

Parameters:

  • options (Hash) (defaults to: {})
  • [Range] (Hash)

    a customizable set of options

  • [Integer] (Hash)

    a customizable set of options



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/packetgen/plugin/ike/ts.rb', line 67

def initialize(options={})
  super
  select_addr options
  self[:start_addr].from_human(options[:start_addr]) if options[:start_addr]
  self[:end_addr].from_human(options[:end_addr]) if options[:end_addr]
  self.type = options[:type] if options[:type]
  self.protocol = options[:protocol] if options[:protocol]
  self[:length].value = sz unless options[:length]
  return unless options[:ports]

  self.start_port = options[:ports].begin
  self.end_port = options[:ports].end
end

Instance Attribute Details

#end_addrIP::Addr, IPv6::Addr

starting address

Returns:

  • (IP::Addr, IPv6::Addr)


61
# File 'lib/packetgen/plugin/ike/ts.rb', line 61

define_field :end_addr, PacketGen::Header::IP::Addr

#end_portInteger

16-bit End port

Returns:

  • (Integer)


53
# File 'lib/packetgen/plugin/ike/ts.rb', line 53

define_field :end_port, PacketGen::Types::Int16, default: 65_535

#lengthInteger

16-bit Selector Length

Returns:

  • (Integer)


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

define_field :length, PacketGen::Types::Int16

#protocolInteger

8-bit protocol ID

Returns:

  • (Integer)


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

define_field :protocol, PacketGen::Types::Int8, default: 0

#start_addrIP::Addr, IPv6::Addr

starting address

Returns:

  • (IP::Addr, IPv6::Addr)


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

define_field :start_addr, PacketGen::Header::IP::Addr

#start_portInteger

16-bit Start port

Returns:

  • (Integer)


49
# File 'lib/packetgen/plugin/ike/ts.rb', line 49

define_field :start_port, PacketGen::Types::Int16, default: 0

#typeInteger

8-bit TS type

Returns:

  • (Integer)


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

define_field :type, PacketGen::Types::Int8, default: 7

Instance Method Details

#human_protocolString

Get human readable protocol name. If protocol ID is 0, an empty string is returned.

Returns:

  • (String)


138
139
140
141
142
143
144
# File 'lib/packetgen/plugin/ike/ts.rb', line 138

def human_protocol
  if protocol.zero?
    ''
  else
    PacketGen::Proto.getprotobynumber(protocol) || protocol.to_s
  end
end

#human_typeString

Get human readable TS type

Returns:

  • (String)


148
149
150
151
152
153
154
155
156
157
# File 'lib/packetgen/plugin/ike/ts.rb', line 148

def human_type
  case type
  when TS_IPV4_ADDR_RANGE
    'IPv4'
  when TS_IPV6_ADDR_RANGE
    'IPv6'
  else
    "type #{type}"
  end
end

#read(str) ⇒ self

Populate object from a string

Parameters:

  • str (String)

Returns:

  • (self)


84
85
86
87
88
# File 'lib/packetgen/plugin/ike/ts.rb', line 84

def read(str)
  super
  select_addr_from_type type
  super
end

#to_humanString

Get a human readable string

Returns:

  • (String)


126
127
128
129
130
131
132
133
# File 'lib/packetgen/plugin/ike/ts.rb', line 126

def to_human
  h = start_addr << '-' << end_addr
  unless human_protocol.empty?
    h << "/#{human_protocol}"
    h << "[#{start_port}-#{end_port}]" if (start_port..end_port) != (0..65_535)
  end
  h
end