Class: PacketGen::Header::IPv6::Extension Abstract

Inherits:
Base
  • Object
show all
Defined in:
lib/packetgen/header/ipv6/extension.rb

Overview

This class is abstract.

You should not use this class but its subclasses.

Base class to handle IPv6 extensions. A IPv6 extension header has the following format:

 0                   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 Header  |  Hdr Ext Len  |                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
|                                                               |
.                                                               .
.                            Options                            .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Such a header consists of:

  • a #next header field (BinStruct::Int8),

  • a #length field (BinStruct::Int8),

  • an #options field (BinStruct::String),

  • and a #body, containing next header.

Author:

  • Sylvain Daubert

Since:

  • 2.4.0

Direct Known Subclasses

HopByHop

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

bind, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, #ll_header

Methods included from PacketGen::Headerable

#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read, #to_s

Constructor Details

This class inherits a constructor from PacketGen::Header::Base

Instance Attribute Details

#bodyString, Headerable

Next header in IPv6 packet

Returns:



52
# File 'lib/packetgen/header/ipv6/extension.rb', line 52

define_attr :body, BinStruct::String

#lengthInteger

8-bit extension length, in 8-octets units, not including the first 8 octets.

Returns:

  • (Integer)


43
# File 'lib/packetgen/header/ipv6/extension.rb', line 43

define_attr :length, BinStruct::Int8

#nextInteger

8-bit Next header field

Returns:

  • (Integer)


38
# File 'lib/packetgen/header/ipv6/extension.rb', line 38

define_attr :next, BinStruct::Int8

#optionsString

Specific options of extension header

Returns:

  • (String)


47
48
# File 'lib/packetgen/header/ipv6/extension.rb', line 47

define_attr :options, BinStruct::String,
builder: ->(h, t) { t.new(length_from: -> { h.real_length - 2}) }

Instance Method Details

#calc_lengthInteger

Compute length and set #length+ attribute

Returns:

  • (Integer)

Since:

  • 2.4.0



62
63
64
# File 'lib/packetgen/header/ipv6/extension.rb', line 62

def calc_length
  self.length = (options.sz + 2) / 8 - 1
end

#real_lengthInteger

Get real extension header length

Returns:

  • (Integer)

Since:

  • 2.4.0



56
57
58
# File 'lib/packetgen/header/ipv6/extension.rb', line 56

def real_length
  (length + 1) * 8
end