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


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

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

Instance Attribute Details

#bodyTypes::String, Header::Base


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

define_field :body, Types::String

#cBoolean

Returns:

  • (Boolean)

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

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

#checksumInteger

Returns:

  • (Integer)

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

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

#kBoolean

Returns:

  • (Boolean)

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

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

#keyInteger

Returns:

  • (Integer)

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

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

#protocol_typeInteger

Returns:

  • (Integer)

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

define_field :protocol_type, Types::Int16

#reserved0Integer

Returns:

  • (Integer)

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

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

#reserved1Integer

Returns:

  • (Integer)

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

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

#sBoolean

Returns:

  • (Boolean)

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

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

#sequence_numberInteger Also known as: seqnum

Returns:

  • (Integer)

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

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

#verInteger

Returns:

  • (Integer)

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

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


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

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