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) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Constant Summary
collapse
- IP_PROTOCOL =
IP protocol number for GRE
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
#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read
#[], #[]=, #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.
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
60
|
# File 'lib/packetgen/header/gre.rb', line 60
define_field :body, Types::String
|
#c ⇒ Boolean
41
|
# File 'lib/packetgen/header/gre.rb', line 41
define_bit_fields_on :u16, :c, :r, :k, :s, :reserved0, 9, :ver, 3
|
#checksum ⇒ Integer
48
|
# File 'lib/packetgen/header/gre.rb', line 48
define_field :checksum, Types::Int16, default: 0, optional: ->(gre) { gre.c? }
|
#k ⇒ Boolean
41
|
# File 'lib/packetgen/header/gre.rb', line 41
define_bit_fields_on :u16, :c, :r, :k, :s, :reserved0, 9, :ver, 3
|
#key ⇒ Integer
54
|
# File 'lib/packetgen/header/gre.rb', line 54
define_field :key, Types::Int32, optional: ->(gre) { gre.k? }
|
#protocol_type ⇒ Integer
45
|
# File 'lib/packetgen/header/gre.rb', line 45
define_field :protocol_type, Types::Int16
|
#reserved0 ⇒ Integer
41
|
# File 'lib/packetgen/header/gre.rb', line 41
define_bit_fields_on :u16, :c, :r, :k, :s, :reserved0, 9, :ver, 3
|
#reserved1 ⇒ Integer
51
|
# File 'lib/packetgen/header/gre.rb', line 51
define_field :reserved1, Types::Int16, default: 0, optional: ->(gre) { gre.c? }
|
#s ⇒ Boolean
41
|
# File 'lib/packetgen/header/gre.rb', line 41
define_bit_fields_on :u16, :c, :r, :k, :s, :reserved0, 9, :ver, 3
|
#sequence_number ⇒ Integer
Also known as:
seqnum
57
|
# File 'lib/packetgen/header/gre.rb', line 57
define_field :sequence_number, Types::Int32, optional: ->(gre) { gre.s? }
|
#ver ⇒ 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_checksum ⇒ Integer
Compute checksum and set checksum
field
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
|