class PacketGen::Header::MLD

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

Public Instance Methods

added_to_packet(packet) click to toggle source

@api private @note This method is used internally by PacketGen and should not be

directly called
# 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"
end
mldize() click to toggle source

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

@return [void]

# 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