Class: PacketGen::Header::DNS::OPT

Inherits:
RR show all
Defined in:
lib/packetgen/header/dns/opt.rb

Overview

OPT pseudo-RR. Used by Extended DNS (EDNS(0), cf. RFC 6891).

a OPT record may contain zero or more options in its RR#rdata.

Author:

  • Sylvain Daubert

Since:

Constant Summary

Constants inherited from Question

Question::CLASSES, Question::TYPES

Instance Attribute Summary collapse

Attributes inherited from RR

#rdata, #rdlength, #ttl

Attributes inherited from Question

#name, #rrclass, #type

Instance Method Summary collapse

Methods inherited from RR

#human_rdata, #human_rrclass

Methods inherited from Question

#human_rrclass, #human_type, #type?

Methods included from Types::Fieldable

#format_inspect, #read, #sz, #to_s, #type_name

Methods inherited from Types::Fields

#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

#initialize(dns, options = {}) ⇒ OPT

Returns a new instance of OPT.

Parameters:

  • dns (DNS)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :name (String)

    domain as a dotted string. Default to “.”

  • :type (Integer, String)

    see Question::TYPES. Default to ‘OPT’

  • :udp_size (Integer)

    UDP maximum size. Also :rrclass. Default to 512.

  • :ext_rcode (Integer)
  • :version (Integer)
  • :do (Boolean)

    DO bit

  • :ttl (Integer)

    set ext_rcode, version, do and z at once

  • :rdlength (Integer)

    if not provided, automatically set from :rdata length

  • :rdata (String)

Since:



39
40
41
42
43
44
45
46
47
# File 'lib/packetgen/header/dns/opt.rb', line 39

def initialize(dns, options={})
  opts = { name: '.', rrclass: 512, type: 41 }.merge!(options)
  super(dns, opts)

  self.udp_size = options[:udp_size] if options[:udp_size]
  self.ext_rcode = options[:ext_rcode] if options[:ext_rcode]
  self.version = options[:version] if options[:version]
  self.do = options[:do] unless options[:do].nil?
end

Instance Attribute Details

#optionsArrayOfOptions

Returns:



23
# File 'lib/packetgen/header/dns/opt.rb', line 23

define_field_after :rdata, :options, ArrayOfOptions

Instance Method Details

#do=(value) ⇒ Boolean #do?Boolean Also known as: do?

Overloads:

  • #do=(value) ⇒ Boolean

    Setter EDNS do

    Parameters:

    • value (Boolean)

    Returns:

    • (Boolean)
  • #do?Boolean

    Getter for EDNS do

    Returns:

    • (Boolean)

Returns:

  • (Boolean)

Since:



91
92
93
94
95
96
97
98
# File 'lib/packetgen/header/dns/opt.rb', line 91

def do=(value=nil)
  b = value ? 1 : 0
  unless value.nil?
    self[:ttl].value = self[:ttl].to_i & (0xffffffff & ~(1 << 15))
    self[:ttl].value |= (b & 1) << 15
  end
  ((self[:ttl].to_i >> 15) & 1) == 1
end

#ext_rcode=(value) ⇒ Integer #ext_rcodeInteger Also known as: ext_rcode

Overloads:

  • #ext_rcode=(value) ⇒ Integer

    Setter for upper 8 bits of extended 12-bit RCODE

    Parameters:

    • value (Integer)

    Returns:

    • (Integer)
  • #ext_rcodeInteger

    Getter for upper 8 bits of extended 12-bit RCODE

    Returns:

    • (Integer)

Returns:

  • (Integer)

Since:



57
58
59
60
61
62
63
# File 'lib/packetgen/header/dns/opt.rb', line 57

def ext_rcode=(value=nil)
  if value
    self[:ttl].value = self[:ttl].to_i & (0xffffffff & ~(0xff << 24))
    self[:ttl].value |= (value & 0xff) << 24
  end
  (self[:ttl].to_i >> 24) & 0xff
end

#human_flagsString

Returns:

  • (String)

Since:



122
123
124
# File 'lib/packetgen/header/dns/opt.rb', line 122

def human_flags
  do? ? 'do' : 'none'
end

#to_humanString

Returns:

  • (String)

Since:



127
128
129
130
131
# File 'lib/packetgen/header/dns/opt.rb', line 127

def to_human
  "#{name} #{human_type} UDPsize:#{udp_size} " \
    "extRCODE:#{ext_rcode} EDNSversion:#{version} flags:#{human_flags} " \
    "options:#{options.empty? ? 'none' : options.to_human}"
end

#version=(ver) ⇒ Integer #versionInteger Also known as: version

Overloads:

  • #version=(ver) ⇒ Integer

    Setter EDNS version

    Parameters:

    • ver (Integer)

    Returns:

    • (Integer)
  • #versionInteger

    Getter for EDNS version

    Returns:

    • (Integer)

Returns:

  • (Integer)

Since:



74
75
76
77
78
79
80
# File 'lib/packetgen/header/dns/opt.rb', line 74

def version=(ver=nil)
  if ver
    self[:ttl].value = self[:ttl].to_i & (0xffffffff & ~(0xff << 16))
    self[:ttl].value |= (ver & 0xff) << 16
  end
  (self[:ttl].to_i >> 16) & 0xff
end

#z=(value) ⇒ Integer #zInteger Also known as: z

Overloads:

  • #z=(value) ⇒ Integer

    Parameters:

    • value (Integer)

    Returns:

    • (Integer)
  • #zInteger

    Returns:

    • (Integer)

Returns:

  • (Integer)

Since:



107
108
109
110
111
112
113
# File 'lib/packetgen/header/dns/opt.rb', line 107

def z=(value=nil)
  if value
    self[:ttl].value = self[:ttl].to_i & (0xffffffff & ~0x7fff)
    self[:ttl].value |= value & 0x7fff
  end
  self[:ttl].to_i & 0x7fff
end