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

Inherits:
BinStruct::Struct
  • 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

@options :type @options :protocol @options :length

Parameters:

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

    a customizable set of options

  • [Range] (Hash)

    a customizable set of options



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/packetgen/plugin/ike/ts.rb', line 70

def initialize(options={}) # rubocop:disable Metrics/AbcSize
  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_attr :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_attr :end_port, BinStruct::Int16, default: 65_535

#lengthInteger

16-bit Selector Length

Returns:

  • (Integer)


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

define_attr :length, BinStruct::Int16

#protocolInteger

8-bit protocol ID

Returns:

  • (Integer)


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

define_attr :protocol, BinStruct::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_attr :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_attr :start_port, BinStruct::Int16, default: 0

#typeInteger

8-bit TS type

Returns:

  • (Integer)


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

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


141
142
143
144
145
146
147
# File 'lib/packetgen/plugin/ike/ts.rb', line 141

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)


151
152
153
154
155
156
157
158
159
160
# File 'lib/packetgen/plugin/ike/ts.rb', line 151

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)


87
88
89
90
91
# File 'lib/packetgen/plugin/ike/ts.rb', line 87

def read(str)
  super
  select_addr_from_type type
  super
end

#to_humanString

Get a human readable string

Returns:

  • (String)


129
130
131
132
133
134
135
136
# File 'lib/packetgen/plugin/ike/ts.rb', line 129

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