Class: PacketGen::Header::GRE

Inherits:
Base show all
Defined in:
lib/packetgen/header/gre.rb

Overview

Generic Routing Encapsulation (RFC 2784 and 2890)

                     1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|C| |K|S| Reserved0       | Ver |         Protocol Type         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      Checksum (optional)      |       Reserved1 (Optional)    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Key (optional)                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                 Sequence Number (Optional)                    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Author:

  • Sylvain Daubert

Since:

  • 2.1.0

Constant Summary collapse

IP_PROTOCOL =

IP protocol number for GRE

Since:

  • 2.1.0

47

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

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

Methods included from PacketGen::Headerable

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

Methods inherited from Types::Fields

#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

#initialize(options = {}) ⇒ GRE

Returns a new instance of GRE.

Since:

  • 2.1.0



65
66
67
68
# File 'lib/packetgen/header/gre.rb', line 65

def initialize(options={})
  opts = { r: false, reserved0: 0, version: 0 }.merge(options)
  super(opts)
end

Instance Attribute Details

#bodyTypes::String, Header::Base



60
# File 'lib/packetgen/header/gre.rb', line 60

define_field :body, Types::String

#cBoolean

Returns:

  • (Boolean)


41
# File 'lib/packetgen/header/gre.rb', line 41

define_bit_fields_on :u16, :c, :r, :k, :s, :reserved0, 9, :ver, 3

#checksumInteger

Returns:

  • (Integer)


48
# File 'lib/packetgen/header/gre.rb', line 48

define_field :checksum, Types::Int16, default: 0, optional: ->(gre) { gre.c? }

#kBoolean

Returns:

  • (Boolean)


41
# File 'lib/packetgen/header/gre.rb', line 41

define_bit_fields_on :u16, :c, :r, :k, :s, :reserved0, 9, :ver, 3

#keyInteger

Returns:

  • (Integer)


54
# File 'lib/packetgen/header/gre.rb', line 54

define_field :key, Types::Int32, optional: ->(gre) { gre.k? }

#protocol_typeInteger

Returns:

  • (Integer)


45
# File 'lib/packetgen/header/gre.rb', line 45

define_field :protocol_type, Types::Int16

#reserved0Integer

Returns:

  • (Integer)


41
# File 'lib/packetgen/header/gre.rb', line 41

define_bit_fields_on :u16, :c, :r, :k, :s, :reserved0, 9, :ver, 3

#reserved1Integer

Returns:

  • (Integer)


51
# File 'lib/packetgen/header/gre.rb', line 51

define_field :reserved1, Types::Int16, default: 0, optional: ->(gre) { gre.c? }

#sBoolean

Returns:

  • (Boolean)


41
# File 'lib/packetgen/header/gre.rb', line 41

define_bit_fields_on :u16, :c, :r, :k, :s, :reserved0, 9, :ver, 3

#sequence_numberInteger Also known as: seqnum

Returns:

  • (Integer)


57
# File 'lib/packetgen/header/gre.rb', line 57

define_field :sequence_number, Types::Int32, optional: ->(gre) { gre.s? }

#verInteger

Returns:

  • (Integer)


41
# File 'lib/packetgen/header/gre.rb', line 41

define_bit_fields_on :u16, :c, :r, :k, :s, :reserved0, 9, :ver, 3

Instance Method Details

#calc_checksumInteger

Compute checksum and set checksum field

Returns:

  • (Integer)

Since:

  • 2.1.0



72
73
74
75
# File 'lib/packetgen/header/gre.rb', line 72

def calc_checksum
  sum = IP.sum16(self)
  self.checksum = IP.reduce_checksum(sum)
end