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

#==, create, #eql?, #from_hash, get_class, #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)



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

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



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

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

Instance Method Details

#d_oObject



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

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

#d_o=(on) ⇒ Object



124
125
126
127
128
129
130
# File 'lib/Dnsruby/resource/OPT.rb', line 124

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

#encode_rdata(msg) ⇒ Object



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

def encode_rdata(msg)
  if (@options)
    @options.each do |opt|
      msg.pack('n', opt.code)
      msg.pack('n', opt.data.length)
      msg.put_bytes(opt.data)
    end
    msg.put_array(@options)
  end
end

#flagsObject



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

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

#flags=(code) ⇒ Object



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

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."


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

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

#from_data(data) ⇒ Object



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

def from_data(data)
  @options = data
end

#from_string(input) ⇒ Object



163
164
165
166
167
# File 'lib/Dnsruby/resource/OPT.rb', line 163

def from_string(input)
  if input
    @options = input.split(" ")
  end
end

#options(args) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/Dnsruby/resource/OPT.rb', line 140

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



155
156
157
# File 'lib/Dnsruby/resource/OPT.rb', line 155

def options=(options)
  @options = options
end

#payloadsizeObject



132
133
134
# File 'lib/Dnsruby/resource/OPT.rb', line 132

def payloadsize
  return @klass
end

#payloadsize=(size) ⇒ Object



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

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

#set_flags(code) ⇒ Object

Should always be zero



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

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

#to_sObject



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

def to_s
  ret = "OPT pseudo-record : #{klass.code} max UDP packet size, "
  ret = ""
  if @options
    @options.each do |opt|
      ret = ret + opt.to_s + " "
    end
    ret.chomp!
  end
  return ret
end

#versionObject



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

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

#version=(code) ⇒ Object



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

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

#xrcodeObject



92
93
94
# File 'lib/Dnsruby/resource/OPT.rb', line 92

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

#xrcode=(code) ⇒ Object



96
97
98
# File 'lib/Dnsruby/resource/OPT.rb', line 96

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