Class: Dnsruby::RR::OPT

Inherits:
Dnsruby::RR show all
Defined in:
lib/Dnsruby/resource/OPT.rb

Overview

Class for EDNS pseudo resource record OPT. This class is effectively internal to Dnsruby See RFC 2671, RFC 2435 Section 3 @TODO@ Extended labels RFC2671 section 3

Defined Under Namespace

Classes: Option

Constant Summary collapse

ClassValue =

:nodoc: all

nil
TypeValue =

:nodoc: all

Types::OPT
DO_BIT =

:nodoc: all

0x8000

Constants inherited from Dnsruby::RR

ClassInsensitiveTypes

Instance Attribute Summary

Attributes inherited from Dnsruby::RR

#klass, #name, #rdata, #ttl, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Dnsruby::RR

#<=>, #==, #clone, create, #eql?, find_class, #from_hash, get_class, get_num, #hash, implemented_rrs, #init_defaults, new_from_data, new_from_hash, new_from_string, #rdata_to_string, #rdlength, #sameRRset

Constructor Details

#initialize(*args) ⇒ OPT

Can be called with up to 3 arguments, none of which must be present

  • OPT.new()

  • OPT.new(size)

  • OPT.new(size,flags)

  • OPT.new(size,flags,options)



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/Dnsruby/resource/OPT.rb', line 34

def initialize(*args)
  @type = Types.new('OPT')
  @ttl = nil
  
  @options=nil
  if (args.length > 0)
    self.payloadsize=(args[0])
    if (args.length > 1)
      self.flags=(args[1])
      if (args.length > 2) 
        self.options=(args[2])
      else
        self.options=nil
      end
    else
      self.flags=0
    end
  else
    self.payloadsize=0
  end
end

Class Method Details

.decode_rdata(msg) ⇒ Object

:nodoc: all



191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/Dnsruby/resource/OPT.rb', line 191

def self.decode_rdata(msg)#:nodoc: all
  if (msg.has_remaining)
    options = []
    while (msg.has_remaining) do
      code  = msg.get_unpack('n')[0]
      len = msg.get_unpack('n')[0]
      data = msg.get_bytes(len)
      options.push(Option.new(code, data))
    end
  end
  return self.new([options])
end

Instance Method Details

#dnssec_okObject



123
124
125
# File 'lib/Dnsruby/resource/OPT.rb', line 123

def dnssec_ok
  return ((flags() & DO_BIT) == DO_BIT)
end

#dnssec_ok=(on) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/Dnsruby/resource/OPT.rb', line 127

def dnssec_ok=(on)
  if (on)
    set_flags(flags() | DO_BIT)
  else
    set_flags(flags() & (~DO_BIT))
  end
end

#encode_rdata(msg, canonical = false) ⇒ Object



181
182
183
184
185
186
187
188
189
# File 'lib/Dnsruby/resource/OPT.rb', line 181

def encode_rdata(msg, canonical=false)
  if (@options)
    @options.each do |opt|
      msg.put_pack('n', opt.code)
      msg.put_pack('n', opt.data.length)
      msg.put_bytes(opt.data)
    end
  end
end

#flagsObject



111
112
113
# File 'lib/Dnsruby/resource/OPT.rb', line 111

def flags
  return flags_from_ttl[2, 2].unpack("n")[0]
end

#flags=(code) ⇒ Object



115
116
117
# File 'lib/Dnsruby/resource/OPT.rb', line 115

def flags=(code)
  set_flags(code)
end

#flags_from_ttlObject

4.6. The extended RCODE and flags (which OPT stores in the RR TTL field) are structured as follows:

              +0 (MSB)                            +1 (LSB)
   +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0: |         EXTENDED-RCODE        |            VERSION            |
   +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
2: |                               Z                               |
   +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

EXTENDED-RCODE  Forms upper 8 bits of extended 12-bit RCODE.  Note
                that EXTENDED-RCODE value "0" indicates that an
                unextended RCODE is in use (values "0" through "15").

VERSION         Indicates the implementation level of whoever sets
                it.  Full conformance with this specification is
                indicated by version "0."


86
87
88
89
90
91
92
# File 'lib/Dnsruby/resource/OPT.rb', line 86

def flags_from_ttl
  if (@ttl)
    return [@ttl].pack("N")
  else
    return [0].pack("N")
  end
end

#from_data(data) ⇒ Object



162
163
164
# File 'lib/Dnsruby/resource/OPT.rb', line 162

def from_data(data)
  @options = data
end

#from_string(input) ⇒ Object

Raises:

  • (NotImplementedError)


166
167
168
# File 'lib/Dnsruby/resource/OPT.rb', line 166

def from_string(input)
  raise NotImplementedError
end

#options(args) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/Dnsruby/resource/OPT.rb', line 143

def options(args)
  if (args==nil)
    return @options
  elsif args.kind_of?Fixnum
    # return list of options with that code
    ret = []
    @options.each do |option|
      if (option.code == args)
        ret.push(option)
      end
    end
    return ret
  end
end

#options=(options) ⇒ Object



158
159
160
# File 'lib/Dnsruby/resource/OPT.rb', line 158

def options=(options)
  @options = options
end

#payloadsizeObject



135
136
137
# File 'lib/Dnsruby/resource/OPT.rb', line 135

def payloadsize
  return @klass.code
end

#payloadsize=(size) ⇒ Object



139
140
141
# File 'lib/Dnsruby/resource/OPT.rb', line 139

def payloadsize=(size)
  self.klass=size
end

#set_flags(code) ⇒ Object

Should always be zero



119
120
121
# File 'lib/Dnsruby/resource/OPT.rb', line 119

def set_flags(code) # Should always be zero
  @ttl = (xrcode().code << 24) + (version() << 16) + code
end

#to_sObject



170
171
172
173
174
175
176
177
178
179
# File 'lib/Dnsruby/resource/OPT.rb', line 170

def to_s
  ret = "OPT pseudo-record : payloadsize #{payloadsize}, xrcode #{xrcode.code}, version #{version}, flags #{flags}"
  if @options
    @options.each do |opt|
      ret = ret + " " + opt.to_s
    end
  end
  ret = ret + "\n"
  return ret
end

#versionObject



103
104
105
# File 'lib/Dnsruby/resource/OPT.rb', line 103

def version
  return flags_from_ttl[1, 1].unpack("C")[0]
end

#version=(code) ⇒ Object



107
108
109
# File 'lib/Dnsruby/resource/OPT.rb', line 107

def version=(code)
  @ttl = (xrcode().code << 24) + (code << 16) + flags()
end

#xrcodeObject



94
95
96
# File 'lib/Dnsruby/resource/OPT.rb', line 94

def xrcode
  return ExtendedRCode.new(flags_from_ttl[0, 1].unpack("C")[0])
end

#xrcode=(c) ⇒ Object



98
99
100
101
# File 'lib/Dnsruby/resource/OPT.rb', line 98

def xrcode=(c)
  code = ExtendedRCode.new(c)
  @ttl = (code.code << 24) + (version() << 16) + flags()
end