Class: Net::DNS::RR::OPT
- Inherits:
-
Net::DNS::RR
- Object
- Net::DNS::RR
- Net::DNS::RR::OPT
- Defined in:
- lib/Net/DNS/RR/OPT.rb
Overview
NAME
Net::DNS::RR::OPT - DNS OPT
DESCRIPTION
Class for EDNS pseudo resource record OPT.
Construction
This object should only be used inside the Net::DNS classes itself.
Since “OPT” is a pseudo record and should not be stored in masterfiles; Therefore we have not implemented a method to create this RR from string.
One may create the object from a hash. See RFC 2671 for details for the meaning of the hash keys.
rr= Net::DNS::RR.new_from_hash(
'name' => "", # Ignored and set to ""
'type' => "OPT",
'class' => 1024, # sets UDP payload size
:extendedrcode => 0x00, # sets the extended RCODE 1 octets
:ednsflags => 0x0000, # sets the ednsflags (2octets)
:optioncode => 0x0 # 2 octets
:optiondata => 0x0 # optionlength octets
)
The ednsversion is set to 0 for now. The ttl value is determined from the extendedrcode, the ednsversion and the ednsflag. The rdata is constructed from the optioncode and optiondata see section 4.4 of RFC 2671
If optioncode is left undefined then we do not expect any RDATA.
The defaults are no rdata.
TODO
-
This class is tailored to use with dnssec.
-
Do some range checking on the input.
-
This class probably needs subclasses once OPTION codes start to be defined.
-
look at use of extended labels
COPYRIGHT
Copyright © 2001, 2002 RIPE NCC. Author Olaf M. Kolkman
Ruby version Copyright © 2006 AlexD (Nominet UK)
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.
THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Based on, and contains, code by Copyright © 1997-2002 Michael Fuhr.
SEE ALSO
Net::DNS, Net::DNS::Resolver, Net::DNS::Packet, Net::DNS::Header, Net::DNS::Question, Net::DNS::RR, RFC 2435 Section 3
Constant Summary collapse
- @@EDNSVERSION =
0- @@extendedrcodesbyname =
{ "ONLY_RDATA" => 0, # No name specified see 4.6 of 2671 "UNDEF1" => 1, "UNDEF2" => 2, "UNDEF3" => 3, "UNDEF4" => 4, "UNDEF5" => 5, "UNDEF6" => 6, "UNDEF7" => 7, "UNDEF8" => 8, "UNDEF9" => 9, "UNDEF10" => 10, "UNDEF11" => 11, "UNDEF12" => 12, "UNDEF13" => 13, "UNDEF14" => 14, "UNDEF15" => 15, "BADVERS" => 16, # RFC 2671 }
- @@extendedrcodesbyval =
RFC 2671
@@extendedrcodesbyname.invert
Constants inherited from Net::DNS::RR
Instance Attribute Summary collapse
-
#ednsflags ⇒ Object
Returns the value of attribute ednsflags.
-
#ednsversion ⇒ Object
Returns the value of attribute ednsversion.
-
#extendedrcode ⇒ Object
Returns the value of attribute extendedrcode.
-
#optioncode ⇒ Object
Returns the value of attribute optioncode.
-
#optiondata ⇒ Object
Returns the value of attribute optiondata.
-
#optionlength ⇒ Object
Returns the value of attribute optionlength.
Attributes inherited from Net::DNS::RR
#name, #rdata, #rdlength, #rrclass, #ttl, #type
Instance Method Summary collapse
-
#clear_do_flag ⇒ Object
Clears the do flag.
-
#do_flag ⇒ Object
Reads the do flag.
- #inpsect ⇒ Object
- #new_from_data(data, offset) ⇒ Object
- #new_from_hash(values) ⇒ Object
- #new_from_string(*args) ⇒ Object
- #rdatastr ⇒ Object
- #rr_rdata(*args) ⇒ Object
-
#set_do_flag ⇒ Object
Sets the do flag.
-
#size ⇒ Object
Get the packet size.
-
#size=(s) ⇒ Object
Set the packet size.
Methods inherited from Net::DNS::RR
#_canonicalRdata, #_canonicaldata, _get_subclass, _name2wire, #_name2wire, build_regex, create, #create_rrsort_func, #data, #get_rrsort_func, #init, #init_rrsort_func, #inspect, new_from_data, new_from_hash, new_from_string, #set_rrsort_func
Instance Attribute Details
#ednsflags ⇒ Object
Returns the value of attribute ednsflags.
100 101 102 |
# File 'lib/Net/DNS/RR/OPT.rb', line 100 def ednsflags @ednsflags end |
#ednsversion ⇒ Object
Returns the value of attribute ednsversion.
100 101 102 |
# File 'lib/Net/DNS/RR/OPT.rb', line 100 def ednsversion @ednsversion end |
#extendedrcode ⇒ Object
Returns the value of attribute extendedrcode.
100 101 102 |
# File 'lib/Net/DNS/RR/OPT.rb', line 100 def extendedrcode @extendedrcode end |
#optioncode ⇒ Object
Returns the value of attribute optioncode.
100 101 102 |
# File 'lib/Net/DNS/RR/OPT.rb', line 100 def optioncode @optioncode end |
#optiondata ⇒ Object
Returns the value of attribute optiondata.
100 101 102 |
# File 'lib/Net/DNS/RR/OPT.rb', line 100 def optiondata @optiondata end |
#optionlength ⇒ Object
Returns the value of attribute optionlength.
100 101 102 |
# File 'lib/Net/DNS/RR/OPT.rb', line 100 def optionlength @optionlength end |
Instance Method Details
#clear_do_flag ⇒ Object
Clears the do flag. (first bit in the ednssflags);
227 228 229 |
# File 'lib/Net/DNS/RR/OPT.rb', line 227 def clear_do_flag return @ednsflags = ( ~0x8000 & @ednsflags ); end |
#do_flag ⇒ Object
Reads the do flag. (first bit in the ednssflags);
217 218 219 |
# File 'lib/Net/DNS/RR/OPT.rb', line 217 def do_flag return ( 0x8000 & @ednsflags ); end |
#inpsect ⇒ Object
193 194 195 196 197 198 |
# File 'lib/Net/DNS/RR/OPT.rb', line 193 def inpsect return "; EDNS Version " + @ednsversion + \ "\t UDP Packetsize: " + @class + "\n; EDNS-RCODE:\t" + @extendedrcode + \ " (" + @@extendedrcodesbyval[@extendedrcode] + ")" + \ "\n; EDNS-FLAGS:\t" + sprintf("0x%04x", @ednsflags) + "\n"; end |
#new_from_data(data, offset) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/Net/DNS/RR/OPT.rb', line 126 def new_from_data(data, offset) @name = "" ; # should allway be "root" if (@rdlength > 0) @optioncode = data[offset, 2].unpack("n")[0]; @optionlength = data[offset+2, 2].unpack("n")[0]; @optiondata = data[offset+4, @optionlength].unpack("n"); end @_rcode_flags = [ttl].pack("N"); @extendedrcode = @_rcode_flags[0, 1].unpack("C")[0]; @ednsversion = @_rcode_flags[1, 1].unpack("C")[0]; @ednsflags = @_rcode_flags[2, 2].unpack("n")[0]; end |
#new_from_hash(values) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/Net/DNS/RR/OPT.rb', line 154 def new_from_hash(values) @name = "" ; # should allway be "root" # Setting the MTU smaller then 512 does not make sense # should we test for a maximum here? if (@rrclass == "IN" || @rrclass.to_s.to_i < 512) @rrclass = 512; # Default value... end @extendedrcode = 0 if values.has_key?:extendedrcode @extendedrcode = values[:extendedrcode] end @ednsflags = 0; if values.has_key?:ednsflags @ednsflags = values[:ednsflags] end @ednsversion = @@EDNSVERSION; if values.has_key?:ednsversion @ednsversion = values[:ednsversion] end @ttl= ([@extendedrcode].pack("C") + [@ednsversion].pack("C") + [@ednsflags].pack("n")).unpack("N")[0] if (values.has_key?:optioncode) @optiondata = "" if values.has_key(:optiondata) @optiondata= values[:optiondata] end @optionlength = @optiondata.length end end |
#new_from_string(*args) ⇒ Object
146 147 148 149 150 |
# File 'lib/Net/DNS/RR/OPT.rb', line 146 def new_from_string(*args) # There is no such thing as an OPT RR in a ZONE file. # Not implemented! raise RuntimeError, "You should not try to create a OPT RR from a string\nNot implemented"; end |
#rdatastr ⇒ Object
201 202 203 |
# File 'lib/Net/DNS/RR/OPT.rb', line 201 def rdatastr return '; Parsing of OPT rdata is not yet implemented'; end |
#rr_rdata(*args) ⇒ Object
205 206 207 208 209 210 211 212 213 214 |
# File 'lib/Net/DNS/RR/OPT.rb', line 205 def rr_rdata(*args) rdata=""; if (defined?@optioncode) rdata = pack("n", @optioncode); rdata += pack("n", @optionlength); rdata += @optiondata end return rdata; end |
#set_do_flag ⇒ Object
Sets the do flag. (first bit in the ednssflags);
222 223 224 |
# File 'lib/Net/DNS/RR/OPT.rb', line 222 def set_do_flag return @ednsflags = ( 0x8000 | @ednsflags ); end |
#size ⇒ Object
Get the packet size.
print "Packet size:". opt.size
245 246 247 |
# File 'lib/Net/DNS/RR/OPT.rb', line 245 def size return @rrclass end |
#size=(s) ⇒ Object
Set the packet size.
opt.size(1498)
234 235 236 237 238 239 |
# File 'lib/Net/DNS/RR/OPT.rb', line 234 def size=(s) if (s != nil) @rrclass=s; end return @rrclass; end |