Class: Racket::L4::ICMPv6Generic

Inherits:
RacketPart
  • Object
show all
Defined in:
lib/racket/l4/icmpv6.rb

Overview

Generic ICMP class from which all ICMP variants spawn. This should never be used directly.

Constant Summary collapse

ICMPv6_TYPE_ECHO_REPLY =
129
ICMPv6_TYPE_DESTINATION_UNREACHABLE =
1
ICMPv6_TYPE_PACKET_TOO_BIG =
2
ICMPv6_TYPE_ECHO_REQUEST =
128
ICMPv6_TYPE_TIME_EXCEEDED =
3
ICMPv6_TYPE_PARAMETER_PROBLEM =
4
ICMPv6_TYPE_MLD_QUERY =
130
ICMPv6_TYPE_MLD_REPORT =
131
ICMPv6_TYPE_MLD_DONE =
132
ICMPv6_TYPE_ROUTER_SOLICITATION =
133
ICMPv6_TYPE_ROUTER_ADVERTISEMENT =
134
ICMPv6_TYPE_NEIGHBOR_SOLICITATION =
135
ICMPv6_TYPE_NEIGHBOR_ADVERTISEMENT =
136
ICMPv6_TYPE_REDIRECT =
137
ICMPv6_TYPE_INFORMATION_REQUEST =
139
ICMPv6_TYPE_INFORMATION_REPLY =
140

Instance Attribute Summary

Attributes inherited from RacketPart

#autofix

Instance Method Summary collapse

Methods inherited from RacketPart

#autofix?, #pretty

Constructor Details

#initialize(*args) ⇒ ICMPv6Generic

Returns a new instance of ICMPv6Generic.



66
67
68
69
# File 'lib/racket/l4/icmpv6.rb', line 66

def initialize(*args)
  super(*args)
  @autofix = false
end

Instance Method Details

#add_option(type, value) ⇒ Object

Add an ICMPv6 option. RFC claims that the value should be padded (with what?) to land on a 64-bit boundary, however that doesn’t always appear to be the case. so, yeah, try to pad on your own or pick strings that are multiples of 8 characters



74
75
76
77
78
79
80
81
# File 'lib/racket/l4/icmpv6.rb', line 74

def add_option(type, value)
  t = Racket::Misc::TLV.new(1,1)
  t.type = type
  t.length = (value.length + 2) / 8
  just = value.length + 2 + (8 - ((value.length + 2) % 8))
  t.value = (value.length + 2) % 8 == 0 ? value : value.ljust(just, "\x00")
  self.payload = t.encode + self.payload 
end

#checksum!(src_ip, dst_ip) ⇒ Object

compute and set the checksum for this ICMP packet



96
97
98
# File 'lib/racket/l4/icmpv6.rb', line 96

def checksum!(src_ip, dst_ip)
  self.checksum = compute_checksum(src_ip, dst_ip)
end

#checksum?Boolean

check the checksum for this ICMP packet

Returns:

  • (Boolean)


62
63
64
# File 'lib/racket/l4/icmpv6.rb', line 62

def checksum?
  self.checksum == compute_checksum
end

#fix!(src_ip, dst_ip) ⇒ Object

‘fix’ this ICMP packet up for sending. (really, just set the checksum)



102
103
104
# File 'lib/racket/l4/icmpv6.rb', line 102

def fix!(src_ip, dst_ip)
  self.checksum!(src_ip, dst_ip)
end

#get_optionsObject

ignorantly assume the first parts of the payload contain ICMPv6 options and find a return an array of Racket::Misc::TLV representing the options



85
86
87
88
89
90
91
92
93
# File 'lib/racket/l4/icmpv6.rb', line 85

def get_options
  p = self.payload
  options = []
  until ((o = Racket::Misc::TLV.new(1,1,8,true).decode(p)).nil?)
    options << o[0..2]
    p = o[3]
  end
  options
end

#sllaObject

get the source link layer address of this message, if found



107
108
109
110
111
112
113
114
115
116
# File 'lib/racket/l4/icmpv6.rb', line 107

def slla
  addr = nil
  self.get_options.each do |o|
    type, length, value, rest = o.flatten
    if (type == 1)
      addr = L2::Misc.string2mac(value)
    end
  end
  addr
end

#slla=(addr) ⇒ Object

set the source link layer address of this message. expects addr in de:ad:ba:dc:af:e0 form



120
121
122
# File 'lib/racket/l4/icmpv6.rb', line 120

def slla=(addr)
  self.add_option(1, L2::Misc.mac2string(addr))
end

#tllaObject

get the target link layer address of this message, if found



125
126
127
128
129
130
131
132
133
134
# File 'lib/racket/l4/icmpv6.rb', line 125

def tlla
  addr = nil
  self.get_options.each do |o|
    type, length, value, rest = o.flatten
    if (type == 2)
      addr = L2::Misc.string2mac(value)
    end
  end
  addr
end

#tlla=(addr) ⇒ Object

set the target link layer address of this message expects addr in de:ad:ba:dc:af:e0 form



138
139
140
# File 'lib/racket/l4/icmpv6.rb', line 138

def tlla=(addr)
  self.add_option(2, L2::Misc.mac2string(addr))
end