Class: PacketGen::Header::MLD

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

Overview

This class supports MLDv1 (RFC 2710).

From RFC 2710, a MLD 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    Maximum Response delay     |           Reserved            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                       Multicast Address                       +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

A MLD header consists of:

Create a MLD header

# standalone
mld = PacketGen::Header::MLD.new
# in a packet
pkt = PacketGen.gen('IPv6').add('ICMPv6').add('MLD')
# access to MLD header
pkt.mld    # => PacketGen::Header::MLD

MLD attributes

pkt.icmpv6.type = 130       # ICMPv6 type 130 is MLD Multicast Listener Query
pkt.mld.max_resp_delay = 20
pkt.mld.group_addr = '::'

Author:

  • Sylvain Daubert

Since:

  • 2.4.0

Direct Known Subclasses

PacketGen::Header::MLDv2::MLQ

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

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, #initialize, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

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

Instance Attribute Details

#bodyString, Base

Returns:


64
# File 'lib/packetgen/header/mld.rb', line 64

define_field :body, Types::String

#max_resp_delayInteger Also known as: max_resp_code

16-bit MLD Max Response Delay

Returns:

  • (Integer)

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

define_field :max_resp_delay, Types::Int16

#mcast_addrIPv6::Addr

IPv6 Multicast address

Returns:


61
# File 'lib/packetgen/header/mld.rb', line 61

define_field :mcast_addr, IPv6::Addr, default: '::'

#reservedInteger

16-bit Reserved field

Returns:

  • (Integer)

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

define_field :reserved, Types::Int16

Instance Method Details

#added_to_packet(packet) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

This method is used internally by PacketGen and should not be directly called

Since:

  • 2.4.0


69
70
71
72
# File 'lib/packetgen/header/mld.rb', line 69

def added_to_packet(packet)
  mld_idx = packet.headers.size
  packet.instance_eval "def mldize() @headers[#{mld_idx}].mldize; end" # def mldize() @headers[3].mldize; end
end

#mldizevoid

This method returns an undefined value.

Fixup IP header according to RFC 2710:

  • set Hop limit to 1,

  • add Router Alert option,

  • recalculate checksum and length.

This method may be called as:

# first method
pkt.mld.mldize
# second method
pkt.mldize

Since:

  • 2.4.0


84
85
86
87
88
89
90
91
# File 'lib/packetgen/header/mld.rb', line 84

def mldize
  ipv6 = ip_header(self)
  ipv6.hop = 1
  ipv6.next = 0
  packet.insert(ipv6, 'IPv6::HopByHop', next: ICMPv6::IP_PROTOCOL)
  packet.ipv6_hopbyhop.options << { type: 'router_alert', value: [0].pack('n') }
  packet.calc
end