Class: PacketGen::Header::IKE::TSi

Inherits:
Payload show all
Defined in:
lib/packetgen/header/ike/ts.rb

Overview

This class handles Traffic Selector - Initiator payloads, denoted TSi.

A TSi payload consists of the IKE generic payload header (see Payload) and some specific fields:

                     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        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Number of TSs |                 RESERVED                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                       <Traffic Selectors>                     ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

These specific fields are:

Create a TSi payload

# Create a IKE packet with a TSi payload
pkt = PacketGen.gen('IP').add('UDP').add('IKE').add('IKE::TSi')
# add a traffic selector to this payload
pkt.ike_tsi.traffic_selectors << { protocol: 'tcp', ports: 1..1024, start_addr: '20.0.0.1', end_addr: '21.255.255.254' }
# add another traffic selector (IPv6, all protocols)
pkt.ike_tsi.traffic_selectors << { start_addr: '2001::1', end_addr: '200a:ffff:ffff:ffff:ffff:ffff:ffff:ffff' }

Author:

  • Sylvain Daubert

Since:

  • 2.0.0

Direct Known Subclasses

TSr

Constant Summary collapse

PAYLOAD_TYPE =

Payload type number

Since:

  • 2.0.0

44

Instance Attribute Summary collapse

Attributes inherited from Payload

#content, #critical, #flags, #hreserved, #length, #next

Attributes inherited from Base

#packet

Instance Method Summary collapse

Methods inherited from Payload

#base_read, #initialize

Methods inherited from Base

#added_to_packet, bind, bind_header, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, known_headers, #ll_header, #method_name, #parse?, #protocol_name, protocol_name

Methods inherited from Types::Fields

#[], #[]=, #bits_on, #body=, define_bit_fields_on, define_field, define_field_after, define_field_before, delete_field, #fields, fields, #force_binary, inherited, #initialize, #inspect, #is_optional?, #is_present?, #offset_of, #optional?, #optional_fields, #present?, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

This class inherits a constructor from PacketGen::Header::IKE::Payload

Instance Attribute Details

#num_tsInteger

8-bit Number of TSs

Returns:

  • (Integer)


228
# File 'lib/packetgen/header/ike/ts.rb', line 228

define_field_before :body, :num_ts, Types::Int8

#rsvInteger

24-bit RESERVED field

Returns:

  • (Integer)


232
# File 'lib/packetgen/header/ike/ts.rb', line 232

define_field_before :body, :rsv, Types::Int24

#traffic_selectorsTrafficSelectors Also known as: selectors

Returns:



237
238
# File 'lib/packetgen/header/ike/ts.rb', line 237

define_field_before :body, :traffic_selectors, TrafficSelectors,
builder: ->(h, t) { t.new(counter: h[:num_ts]) }

Instance Method Details

#calc_lengthInteger

Compute length and set Payload#length field

Returns:

  • (Integer)

    new length

Since:

  • 2.0.0



255
256
257
258
# File 'lib/packetgen/header/ike/ts.rb', line 255

def calc_length
  selectors.each(&:calc_length)
  super
end

#read(str) ⇒ self

Populate object from a string

Parameters:

  • str (String)

Returns:

  • (self)

Since:

  • 2.0.0



244
245
246
247
248
249
250
251
# File 'lib/packetgen/header/ike/ts.rb', line 244

def read(str)
  super(str[0, 8])
  hlen = self.class.new.sz
  tslen = length - hlen
  selectors.read str[hlen, tslen]
  body.read str[hlen + tslen..-1]
  self
end