gitlab-net-dns 0.9.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/demo/check_soa.rb +1 -1
- data/gitlab-net-dns.gemspec +2 -1
- data/lib/net/dns/header.rb +14 -14
- data/lib/net/dns/question.rb +2 -0
- data/lib/net/dns/resolver/socks.rb +1 -1
- data/lib/net/dns/resolver.rb +554 -8
- data/lib/net/dns/rr/soa.rb +1 -1
- data/lib/net/dns/rr/types.rb +70 -48
- data/lib/net/dns/rr.rb +8 -1
- data/lib/net/dns/version.rb +1 -1
- data/test/unit/question_test.rb +10 -1
- data/test/unit/rr/a_test.rb +1 -1
- data/test/unit/rr/aaaa_test.rb +2 -2
- data/test/unit/rr/cname_test.rb +2 -2
- data/test/unit/rr/hinfo_test.rb +1 -1
- data/test/unit/rr/mx_test.rb +2 -2
- data/test/unit/rr/ns_test.rb +2 -2
- data/test/unit/rr/types_test.rb +4 -4
- data/test/unit/rr_test.rb +33 -0
- metadata +18 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6894aeca8ca5a877a50f79dd5960888cf153cbf33ae1f367681185ab72eeed25
|
4
|
+
data.tar.gz: 6db68fc71b24701ebe82fb84e13f2a5a131a6aecba929af968b528d2e40650dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d3aae8c3e2868244e5cd5f4da8a89191901f440ca0a999280ee8b1f7b083f57aa10fc1aabe8fe38b13de99579bcfec4805a4ed4eb2c6c35c61d9003c5ea4076
|
7
|
+
data.tar.gz: e4d8e5f5dca3b4b9c704d0c4ff8c695b86f4620b48ccfa9ca505cbc0a5ac784517f045b6257ac2e76d15f3e4ad277385814e56905167ec044bed77f543cf645e
|
data/.gitlab-ci.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Release 0.10.0
|
4
|
+
|
5
|
+
- CHANGED: Update list of supported types (https://gitlab.com/gitlab-org/ruby/gems/gitlab-net-dns/-/merge_requests/7)
|
6
|
+
|
3
7
|
## Release 0.9.2
|
4
8
|
|
5
9
|
- FIXED: Fixed TimeoutError deprecation warning (https://gitlab.com/gitlab-org/ruby/gems/gitlab-net-dns/-/merge_requests/4)
|
data/demo/check_soa.rb
CHANGED
@@ -18,7 +18,7 @@ domain = ARGV[0]
|
|
18
18
|
res = Net::DNS::Resolver.new(defname: false, retry: 2)
|
19
19
|
|
20
20
|
ns_req = res.query(domain, Net::DNS::NS)
|
21
|
-
unless ns_req &&
|
21
|
+
unless ns_req && ns_req.header.anCount.positive?
|
22
22
|
raise ArgumentError, "No nameservers found for domain: #{res.errorstring}"
|
23
23
|
end
|
24
24
|
|
data/gitlab-net-dns.gemspec
CHANGED
@@ -11,12 +11,13 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.description = "Net::DNS is a pure Ruby DNS library, with a clean OO interface and an extensible API."
|
12
12
|
s.licenses = ["Ruby"]
|
13
13
|
|
14
|
-
s.required_ruby_version = ">=
|
14
|
+
s.required_ruby_version = ">= 3.0"
|
15
15
|
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.files = `git ls-files`.split("\n")
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.extra_rdoc_files = %w[LICENSE.txt]
|
20
|
+
s.add_dependency "logger"
|
20
21
|
|
21
22
|
s.add_development_dependency "mocha"
|
22
23
|
s.add_development_dependency "rake"
|
data/lib/net/dns/header.rb
CHANGED
@@ -674,20 +674,20 @@ module Net
|
|
674
674
|
end
|
675
675
|
|
676
676
|
arr = str.unpack("n C2 n4")
|
677
|
-
@id
|
678
|
-
@qr
|
679
|
-
@opCode
|
680
|
-
@aa
|
681
|
-
@tc
|
682
|
-
@rd
|
683
|
-
@ra
|
684
|
-
@ad
|
685
|
-
@cd
|
686
|
-
@rCode
|
687
|
-
@qdCount
|
688
|
-
@anCount
|
689
|
-
@nsCount
|
690
|
-
@arCount
|
677
|
+
@id = arr[0]
|
678
|
+
@qr = (arr[1] >> 7) & 0x01
|
679
|
+
@opCode = (arr[1] >> 3) & 0x0F
|
680
|
+
@aa = (arr[1] >> 2) & 0x01
|
681
|
+
@tc = (arr[1] >> 1) & 0x01
|
682
|
+
@rd = arr[1] & 0x1
|
683
|
+
@ra = (arr[2] >> 7) & 0x01
|
684
|
+
@ad = (arr[2] >> 5) & 0x01
|
685
|
+
@cd = (arr[2] >> 4) & 0x01
|
686
|
+
@rCode = RCode.new(arr[2] & 0xf)
|
687
|
+
@qdCount = arr[3]
|
688
|
+
@anCount = arr[4]
|
689
|
+
@nsCount = arr[5]
|
690
|
+
@arCount = arr[6]
|
691
691
|
end
|
692
692
|
|
693
693
|
def new_from_hash(hash)
|
data/lib/net/dns/question.rb
CHANGED
data/lib/net/dns/resolver.rb
CHANGED
@@ -1074,14 +1074,560 @@ module Net
|
|
1074
1074
|
if ENV['LOCALDOMAIN']
|
1075
1075
|
self.domain = ENV['LOCALDOMAIN']
|
1076
1076
|
end
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1077
|
+
# Resolver helper method.
|
1078
|
+
#
|
1079
|
+
# Calling the resolver directly:
|
1080
|
+
#
|
1081
|
+
# puts Resolver("www.google.com").answer.size
|
1082
|
+
# # => 5
|
1083
|
+
#
|
1084
|
+
# An optional block can be passed yielding the Net::DNS::Packet object.
|
1085
|
+
#
|
1086
|
+
# Resolver("www.google.com") { |packet| puts packet.size + " bytes" }
|
1087
|
+
# # => 484 bytes
|
1088
|
+
#
|
1089
|
+
# = Net::DNS::Resolver - DNS resolver class
|
1090
|
+
#
|
1091
|
+
# The Net::DNS::Resolver class implements a complete DNS resolver written
|
1092
|
+
# in pure Ruby, without a single C line of code. It has all of the
|
1093
|
+
# tipical properties of an evoluted resolver, and a bit of OO which
|
1094
|
+
# comes from having used Ruby.
|
1095
|
+
#
|
1096
|
+
# This project started as a porting of the Net::DNS Perl module,
|
1097
|
+
# written by Martin Fuhr, but turned out (in the last months) to be
|
1098
|
+
# an almost complete rewriting. Well, maybe some of the features of
|
1099
|
+
# the Perl version are still missing, but guys, at least this is
|
1100
|
+
# readable code!
|
1101
|
+
#
|
1102
|
+
# == Environment
|
1103
|
+
#
|
1104
|
+
# The Following Environment variables can also be used to configure
|
1105
|
+
# the resolver:
|
1106
|
+
#
|
1107
|
+
# * +RES_NAMESERVERS+: A space-separated list of nameservers to query.
|
1108
|
+
#
|
1109
|
+
# # Bourne Shell
|
1110
|
+
# $ RES_NAMESERVERS="192.168.1.1 192.168.2.2 192.168.3.3"
|
1111
|
+
# $ export RES_NAMESERVERS
|
1112
|
+
#
|
1113
|
+
# # C Shell
|
1114
|
+
# % setenv RES_NAMESERVERS "192.168.1.1 192.168.2.2 192.168.3.3"
|
1115
|
+
#
|
1116
|
+
# * +RES_SEARCHLIST+: A space-separated list of domains to put in the
|
1117
|
+
# search list.
|
1118
|
+
#
|
1119
|
+
# # Bourne Shell
|
1120
|
+
# $ RES_SEARCHLIST="example.com sub1.example.com sub2.example.com"
|
1121
|
+
# $ export RES_SEARCHLIST
|
1122
|
+
#
|
1123
|
+
# # C Shell
|
1124
|
+
# % setenv RES_SEARCHLIST "example.com sub1.example.com sub2.example.com"
|
1125
|
+
#
|
1126
|
+
# * +LOCALDOMAIN+: The default domain.
|
1127
|
+
#
|
1128
|
+
# # Bourne Shell
|
1129
|
+
# $ LOCALDOMAIN=example.com
|
1130
|
+
# $ export LOCALDOMAIN
|
1131
|
+
#
|
1132
|
+
# # C Shell
|
1133
|
+
# % setenv LOCALDOMAIN example.com
|
1134
|
+
#
|
1135
|
+
# * +RES_OPTIONS+: A space-separated list of resolver options to set.
|
1136
|
+
# Options that take values are specified as option:value.
|
1137
|
+
#
|
1138
|
+
# # Bourne Shell
|
1139
|
+
# $ RES_OPTIONS="retrans:3 retry:2 debug"
|
1140
|
+
# $ export RES_OPTIONS
|
1141
|
+
#
|
1142
|
+
# # C Shell
|
1143
|
+
# % setenv RES_OPTIONS "retrans:3 retry:2 debug"
|
1144
|
+
#
|
1145
|
+
# An hash with the defaults values of almost all the
|
1146
|
+
# configuration parameters of a resolver object. See
|
1147
|
+
# the description for each parameter to have an
|
1148
|
+
# explanation of its usage.
|
1149
|
+
# Quick resolver method. Bypass the configuration using
|
1150
|
+
# the defaults.
|
1151
|
+
#
|
1152
|
+
# Net::DNS::Resolver.start "www.google.com"
|
1153
|
+
#
|
1154
|
+
# Returns true if running on a Windows platform.
|
1155
|
+
#
|
1156
|
+
# Note. This method doesn't rely on the RUBY_PLATFORM constant
|
1157
|
+
# because the comparison will fail when running on JRuby.
|
1158
|
+
# On JRuby RUBY_PLATFORM == 'java'.
|
1159
|
+
# Creates a new resolver object.
|
1160
|
+
#
|
1161
|
+
# Argument +config+ can either be empty or be an hash with
|
1162
|
+
# some configuration parameters. To know what each parameter
|
1163
|
+
# do, look at the description of each.
|
1164
|
+
# Some example:
|
1165
|
+
#
|
1166
|
+
# # Use the sistem defaults
|
1167
|
+
# res = Net::DNS::Resolver.new
|
1168
|
+
#
|
1169
|
+
# # Specify a configuration file
|
1170
|
+
# res = Net::DNS::Resolver.new(:config_file => '/my/dns.conf')
|
1171
|
+
#
|
1172
|
+
# # Set some option
|
1173
|
+
# res = Net::DNS::Resolver.new(:nameservers => "172.16.1.1",
|
1174
|
+
# :recursive => false,
|
1175
|
+
# :retry => 10)
|
1176
|
+
#
|
1177
|
+
# == Config file
|
1178
|
+
#
|
1179
|
+
# Net::DNS::Resolver uses a config file to read the usual
|
1180
|
+
# values a resolver needs, such as nameserver list and
|
1181
|
+
# domain names. On UNIX systems the defaults are read from the
|
1182
|
+
# following files, in the order indicated:
|
1183
|
+
#
|
1184
|
+
# * /etc/resolv.conf
|
1185
|
+
# * $HOME/.resolv.conf
|
1186
|
+
# * ./.resolv.conf
|
1187
|
+
#
|
1188
|
+
# The following keywords are recognized in resolver configuration files:
|
1189
|
+
#
|
1190
|
+
# * domain: the default domain.
|
1191
|
+
# * search: a space-separated list of domains to put in the search list.
|
1192
|
+
# * nameserver: a space-separated list of nameservers to query.
|
1193
|
+
#
|
1194
|
+
# Files except for /etc/resolv.conf must be owned by the effective userid
|
1195
|
+
# running the program or they won't be read. In addition, several environment
|
1196
|
+
# variables can also contain configuration information; see Environment
|
1197
|
+
# in the main description for Resolver class.
|
1198
|
+
#
|
1199
|
+
# On Windows Systems, an attempt is made to determine the system defaults
|
1200
|
+
# using the registry. This is still a work in progress; systems with many
|
1201
|
+
# dynamically configured network interfaces may confuse Net::DNS.
|
1202
|
+
#
|
1203
|
+
# You can include a configuration file of your own when creating a resolver
|
1204
|
+
# object:
|
1205
|
+
#
|
1206
|
+
# # Use my own configuration file
|
1207
|
+
# my $res = Net::DNS::Resolver->new(config_file => '/my/dns.conf');
|
1208
|
+
#
|
1209
|
+
# This is supported on both UNIX and Windows. Values pulled from a custom
|
1210
|
+
# configuration file override the the system's defaults, but can still be
|
1211
|
+
# overridden by the other arguments to Resolver::new.
|
1212
|
+
#
|
1213
|
+
# Explicit arguments to Resolver::new override both the system's defaults
|
1214
|
+
# and the values of the custom configuration file, if any.
|
1215
|
+
#
|
1216
|
+
# == Parameters
|
1217
|
+
#
|
1218
|
+
# The following arguments to Resolver::new are supported:
|
1219
|
+
#
|
1220
|
+
# * nameservers: an array reference of nameservers to query.
|
1221
|
+
# * searchlist: an array reference of domains.
|
1222
|
+
# * recurse
|
1223
|
+
# * debug
|
1224
|
+
# * domain
|
1225
|
+
# * port
|
1226
|
+
# * srcaddr
|
1227
|
+
# * srcport
|
1228
|
+
# * tcp_timeout
|
1229
|
+
# * udp_timeout
|
1230
|
+
# * retrans
|
1231
|
+
# * retry
|
1232
|
+
# * usevc
|
1233
|
+
# * stayopen
|
1234
|
+
# * igntc
|
1235
|
+
# * defnames
|
1236
|
+
# * dnsrch
|
1237
|
+
# * persistent_tcp
|
1238
|
+
# * persistent_udp
|
1239
|
+
# * dnssec
|
1240
|
+
#
|
1241
|
+
# For more information on any of these options, please consult the
|
1242
|
+
# method of the same name.
|
1243
|
+
#
|
1244
|
+
# == Disclaimer
|
1245
|
+
#
|
1246
|
+
# Part of the above documentation is taken from the one in the
|
1247
|
+
# Net::DNS::Resolver Perl module.
|
1248
|
+
#
|
1249
|
+
# New logger facility
|
1250
|
+
#------------------------------------------------------------
|
1251
|
+
# Resolver configuration will be set in order from:
|
1252
|
+
# 1) initialize arguments
|
1253
|
+
# 2) ENV variables
|
1254
|
+
# 3) config file
|
1255
|
+
# 4) defaults (and /etc/resolv.conf for config)
|
1256
|
+
#------------------------------------------------------------
|
1257
|
+
#------------------------------------------------------------
|
1258
|
+
# Parsing config file
|
1259
|
+
#------------------------------------------------------------
|
1260
|
+
#------------------------------------------------------------
|
1261
|
+
# Parsing ENV variables
|
1262
|
+
#------------------------------------------------------------
|
1263
|
+
#------------------------------------------------------------
|
1264
|
+
# Parsing arguments
|
1265
|
+
#------------------------------------------------------------
|
1266
|
+
# Get the resolver search list, returned as an array of entries.
|
1267
|
+
#
|
1268
|
+
# res.searchlist
|
1269
|
+
# #=> ["example.com","a.example.com","b.example.com"]
|
1270
|
+
#
|
1271
|
+
# Set the resolver searchlist.
|
1272
|
+
# +arg+ can be a single string or an array of strings.
|
1273
|
+
#
|
1274
|
+
# res.searchstring = "example.com"
|
1275
|
+
# res.searchstring = ["example.com","a.example.com","b.example.com"]
|
1276
|
+
#
|
1277
|
+
# Note that you can also append a new name to the searchlist.
|
1278
|
+
#
|
1279
|
+
# res.searchlist << "c.example.com"
|
1280
|
+
# res.searchlist
|
1281
|
+
# #=> ["example.com","a.example.com","b.example.com","c.example.com"]
|
1282
|
+
#
|
1283
|
+
# The default is an empty array.
|
1284
|
+
#
|
1285
|
+
# Get the list of resolver nameservers, in a dotted decimal format-
|
1286
|
+
#
|
1287
|
+
# res.nameservers
|
1288
|
+
# #=> ["192.168.0.1","192.168.0.2"]
|
1289
|
+
#
|
1290
|
+
# Set the list of resolver nameservers.
|
1291
|
+
# +arg+ can be a single ip address or an array of addresses.
|
1292
|
+
#
|
1293
|
+
# res.nameservers = "192.168.0.1"
|
1294
|
+
# res.nameservers = ["192.168.0.1","192.168.0.2"]
|
1295
|
+
#
|
1296
|
+
# If you want you can specify the addresses as IPAddr instances.
|
1297
|
+
#
|
1298
|
+
# ip = IPAddr.new("192.168.0.3")
|
1299
|
+
# res.nameservers << ip
|
1300
|
+
# #=> ["192.168.0.1","192.168.0.2","192.168.0.3"]
|
1301
|
+
#
|
1302
|
+
# The default is 127.0.0.1 (localhost)
|
1303
|
+
#
|
1304
|
+
# arg is in the name form, not IP
|
1305
|
+
# Return a string with the default domain.
|
1306
|
+
# Set the domain for the query.
|
1307
|
+
# Return the defined size of the packet.
|
1308
|
+
# Get the port number to which the resolver sends queries.
|
1309
|
+
#
|
1310
|
+
# puts "Sending queries to port #{res.port}"
|
1311
|
+
#
|
1312
|
+
# Set the port number to which the resolver sends queries. This can be useful
|
1313
|
+
# for testing a nameserver running on a non-standard port.
|
1314
|
+
#
|
1315
|
+
# res.port = 10053
|
1316
|
+
#
|
1317
|
+
# The default is port 53.
|
1318
|
+
#
|
1319
|
+
# Get the value of the source port number.
|
1320
|
+
#
|
1321
|
+
# puts "Sending queries using port #{res.source_port}"
|
1322
|
+
#
|
1323
|
+
# Set the local source port from which the resolver sends its queries.
|
1324
|
+
#
|
1325
|
+
# res.source_port = 40000
|
1326
|
+
#
|
1327
|
+
# Note that if you want to set a port you need root priviledges, as
|
1328
|
+
# raw sockets will be used to generate packets. The class will then
|
1329
|
+
# generate the exception ResolverPermissionError if you're not root.
|
1330
|
+
#
|
1331
|
+
# The default is 0, which means that the port will be chosen by the
|
1332
|
+
# underlaying layers.
|
1333
|
+
#
|
1334
|
+
# Get the local address from which the resolver sends queries
|
1335
|
+
#
|
1336
|
+
# puts "Sending queries using source address #{res.source_address}"
|
1337
|
+
#
|
1338
|
+
# Get the local ipv6 address from which the resolver sends queries
|
1339
|
+
#
|
1340
|
+
# Set the local source address from which the resolver sends its queries.
|
1341
|
+
#
|
1342
|
+
# res.source_address = "172.16.100.1"
|
1343
|
+
# res.source_address = IPAddr.new("172.16.100.1")
|
1344
|
+
#
|
1345
|
+
# You can specify +arg+ as either a string containing the ip address
|
1346
|
+
# or an instance of IPAddr class.
|
1347
|
+
#
|
1348
|
+
# Normally this can be used to force queries out a specific interface
|
1349
|
+
# on a multi-homed host. In this case, you should of course need to
|
1350
|
+
# know the addresses of the interfaces.
|
1351
|
+
#
|
1352
|
+
# Another way to use this option is for some kind of spoofing attacks
|
1353
|
+
# towards weak nameservers, to probe the security of your network.
|
1354
|
+
# This includes specifing ranged attacks such as DoS and others. For
|
1355
|
+
# a paper on DNS security, checks http://www.marcoceresa.com/security/
|
1356
|
+
#
|
1357
|
+
# Note that if you want to set a non-binded source address you need
|
1358
|
+
# root priviledges, as raw sockets will be used to generate packets.
|
1359
|
+
# The class will then generate an exception if you're not root.
|
1360
|
+
#
|
1361
|
+
# The default is 0.0.0.0, meaning any local address (chosen on routing needs).
|
1362
|
+
#
|
1363
|
+
# Port already in use!
|
1364
|
+
# Address is not valid: raw socket
|
1365
|
+
# Return the retrasmission interval (in seconds) the resolvers has
|
1366
|
+
# been set on.
|
1367
|
+
# Set the retrasmission interval in seconds. Default 5 seconds.
|
1368
|
+
# The number of times the resolver will try a query.
|
1369
|
+
#
|
1370
|
+
# puts "Will try a max of #{res.retry_number} queries"
|
1371
|
+
#
|
1372
|
+
# Set the number of times the resolver will try a query.
|
1373
|
+
# Default 4 times.
|
1374
|
+
# This method will return true if the resolver is configured to
|
1375
|
+
# perform recursive queries.
|
1376
|
+
#
|
1377
|
+
# print "The resolver will perform a "
|
1378
|
+
# print res.recursive? ? "" : "not "
|
1379
|
+
# puts "recursive query"
|
1380
|
+
#
|
1381
|
+
# Sets whether or not the resolver should perform recursive
|
1382
|
+
# queries. Default is true.
|
1383
|
+
#
|
1384
|
+
# res.recursive = false # perform non-recursive query
|
1385
|
+
#
|
1386
|
+
# Return a string representing the resolver state, suitable
|
1387
|
+
# for printing on the screen.
|
1388
|
+
#
|
1389
|
+
# puts "Resolver state:"
|
1390
|
+
# puts res.state
|
1391
|
+
#
|
1392
|
+
# Checks whether the +defname+ flag has been activate.
|
1393
|
+
# Set the flag +defname+ in a boolean state. if +defname+ is true,
|
1394
|
+
# calls to Resolver#query will append the default domain to names
|
1395
|
+
# that contain no dots.
|
1396
|
+
# Example:
|
1397
|
+
#
|
1398
|
+
# # Domain example.com
|
1399
|
+
# res.defname = true
|
1400
|
+
# res.query("machine1")
|
1401
|
+
# #=> This will perform a query for machine1.example.com
|
1402
|
+
#
|
1403
|
+
# Default is true.
|
1404
|
+
#
|
1405
|
+
# Get the state of the dns_search flag.
|
1406
|
+
# Set the flag +dns_search+ in a boolean state. If +dns_search+
|
1407
|
+
# is true, when using the Resolver#search method will be applied
|
1408
|
+
# the search list. Default is true.
|
1409
|
+
# Get the state of the use_tcp flag.
|
1410
|
+
#
|
1411
|
+
# If +use_tcp+ is true, the resolver will perform all queries
|
1412
|
+
# using TCP virtual circuits instead of UDP datagrams, which
|
1413
|
+
# is the default for the DNS protocol.
|
1414
|
+
#
|
1415
|
+
# res.use_tcp = true
|
1416
|
+
# res.query "host.example.com"
|
1417
|
+
# #=> Sending TCP segments...
|
1418
|
+
#
|
1419
|
+
# Default is false.
|
1420
|
+
#
|
1421
|
+
# Return an object representing the value of the stored TCP
|
1422
|
+
# timeout the resolver will use in is queries. This object
|
1423
|
+
# is an instance of the class +TcpTimeout+, and two methods
|
1424
|
+
# are available for printing informations: TcpTimeout#to_s
|
1425
|
+
# and TcpTimeout#pretty_to_s.
|
1426
|
+
#
|
1427
|
+
# Here's some example:
|
1428
|
+
#
|
1429
|
+
# puts "Timeout of #{res.tcp_timeout} seconds" # implicit to_s
|
1430
|
+
# #=> Timeout of 150 seconds
|
1431
|
+
#
|
1432
|
+
# puts "You set a timeout of " + res.tcp_timeout.pretty_to_s
|
1433
|
+
# #=> You set a timeout of 2 minutes and 30 seconds
|
1434
|
+
#
|
1435
|
+
# If the timeout is infinite, a string "infinite" will be returned.
|
1436
|
+
#
|
1437
|
+
# Set the value of TCP timeout for resolver queries that
|
1438
|
+
# will be performed using TCP. A value of 0 means that
|
1439
|
+
# the timeout will be infinite.
|
1440
|
+
# The value is stored internally as a +TcpTimeout+ object, see
|
1441
|
+
# the description for Resolver#tcp_timeout
|
1442
|
+
#
|
1443
|
+
# Default is 5 seconds.
|
1444
|
+
#
|
1445
|
+
# Return an object representing the value of the stored UDP
|
1446
|
+
# timeout the resolver will use in is queries. This object
|
1447
|
+
# is an instance of the class +UdpTimeout+, and two methods
|
1448
|
+
# are available for printing information: UdpTimeout#to_s
|
1449
|
+
# and UdpTimeout#pretty_to_s.
|
1450
|
+
#
|
1451
|
+
# Here's some example:
|
1452
|
+
#
|
1453
|
+
# puts "Timeout of #{res.udp_timeout} seconds" # implicit to_s
|
1454
|
+
# #=> Timeout of 150 seconds
|
1455
|
+
#
|
1456
|
+
# puts "You set a timeout of " + res.udp_timeout.pretty_to_s
|
1457
|
+
# #=> You set a timeout of 2 minutes and 30 seconds
|
1458
|
+
#
|
1459
|
+
# If the timeout is zero, a string "not defined" will
|
1460
|
+
# be returned.
|
1461
|
+
#
|
1462
|
+
# Set the value of UDP timeout for resolver queries that
|
1463
|
+
# will be performed using UDP. A value of 0 means that
|
1464
|
+
# the timeout will not be used, and the resolver will use
|
1465
|
+
# only +retry_number+ and +retry_interval+ parameters.
|
1466
|
+
#
|
1467
|
+
# Default is 5 seconds.
|
1468
|
+
#
|
1469
|
+
# The value is stored internally as a +UdpTimeout+ object, see
|
1470
|
+
# the description for Resolver#udp_timeout.
|
1471
|
+
#
|
1472
|
+
# Set a new log file for the logger facility of the resolver
|
1473
|
+
# class. Could be a file descriptor too:
|
1474
|
+
#
|
1475
|
+
# res.log_file = $stderr
|
1476
|
+
#
|
1477
|
+
# Note that a new logging facility will be create, destroing
|
1478
|
+
# the old one, which will then be impossibile to recover.
|
1479
|
+
#
|
1480
|
+
# This one permits to have a personal logger facility to handle
|
1481
|
+
# resolver messages, instead of new built-in one, which is set up
|
1482
|
+
# for a +$stdout+ (or +$stderr+) use.
|
1483
|
+
#
|
1484
|
+
# If you want your own logging facility you can create a new instance
|
1485
|
+
# of the +Logger+ class:
|
1486
|
+
#
|
1487
|
+
# log = Logger.new("/tmp/resolver.log","weekly",2*1024*1024)
|
1488
|
+
# log.level = Logger::DEBUG
|
1489
|
+
# log.progname = "ruby_resolver"
|
1490
|
+
#
|
1491
|
+
# and then pass it to the resolver:
|
1492
|
+
#
|
1493
|
+
# res.logger = log
|
1494
|
+
#
|
1495
|
+
# Note that this will destroy the precedent logger.
|
1496
|
+
#
|
1497
|
+
# Set the log level for the built-in logging facility.
|
1498
|
+
#
|
1499
|
+
# The log level can be one of the following:
|
1500
|
+
#
|
1501
|
+
# - +Net::DNS::DEBUG+
|
1502
|
+
# - +Net::DNS::INFO+
|
1503
|
+
# - +Net::DNS::WARN+
|
1504
|
+
# - +Net::DNS::ERROR+
|
1505
|
+
# - +Net::DNS::FATAL+
|
1506
|
+
#
|
1507
|
+
# Note that if the global variable $DEBUG is set (like when the
|
1508
|
+
# -d switch is used at the command line) the logger level is
|
1509
|
+
# automatically set at DEGUB.
|
1510
|
+
#
|
1511
|
+
# For further informations, see Logger documentation in the
|
1512
|
+
# Ruby standard library.
|
1513
|
+
#
|
1514
|
+
# Performs a DNS query for the given name, applying the searchlist if
|
1515
|
+
# appropriate. The search algorithm is as follows:
|
1516
|
+
#
|
1517
|
+
# 1. If the name contains at least one dot, try it as is.
|
1518
|
+
# 2. If the name doesn't end in a dot then append each item in the search
|
1519
|
+
# list to the name. This is only done if +dns_search+ is true.
|
1520
|
+
# 3. If the name doesn't contain any dots, try it as is.
|
1521
|
+
#
|
1522
|
+
# The record type and class can be omitted; they default to +A+ and +IN+.
|
1523
|
+
#
|
1524
|
+
# packet = res.search('mailhost')
|
1525
|
+
# packet = res.search('mailhost.example.com')
|
1526
|
+
# packet = res.search('example.com', Net::DNS::MX)
|
1527
|
+
# packet = res.search('user.passwd.example.com', Net::DNS::TXT, Net::DNS::HS)
|
1528
|
+
#
|
1529
|
+
# If the name is an IP address (Ipv4 or IPv6), in the form of a string
|
1530
|
+
# or a +IPAddr+ object, then an appropriate PTR query will be performed:
|
1531
|
+
#
|
1532
|
+
# ip = IPAddr.new("172.16.100.2")
|
1533
|
+
# packet = res.search(ip)
|
1534
|
+
# packet = res.search("192.168.10.254")
|
1535
|
+
#
|
1536
|
+
# Returns a Net::DNS::Packet object. If you need to examine the response packet
|
1537
|
+
# whether it contains any answers or not, use the Resolver#query method instead.
|
1538
|
+
#
|
1539
|
+
# If the name contains at least one dot then try it as is first.
|
1540
|
+
# If the name doesn't end in a dot then apply the search list.
|
1541
|
+
# Finally, if the name has no dots then try it as is.
|
1542
|
+
# Performs a DNS query for the given name; the search list
|
1543
|
+
# is not applied. If the name doesn't contain any dots and
|
1544
|
+
# +defname+ is true then the default domain will be appended.
|
1545
|
+
#
|
1546
|
+
# The record type and class can be omitted; they default to +A+
|
1547
|
+
# and +IN+. If the name looks like an IP address (IPv4 or IPv6),
|
1548
|
+
# then an appropriate PTR query will be performed.
|
1549
|
+
#
|
1550
|
+
# packet = res.query('mailhost')
|
1551
|
+
# packet = res.query('mailhost.example.com')
|
1552
|
+
# packet = res.query('example.com', Net::DNS::MX)
|
1553
|
+
# packet = res.query('user.passwd.example.com', Net::DNS::TXT, Net::DNS::HS)
|
1554
|
+
#
|
1555
|
+
# If the name is an IP address (Ipv4 or IPv6), in the form of a string
|
1556
|
+
# or a +IPAddr+ object, then an appropriate PTR query will be performed:
|
1557
|
+
#
|
1558
|
+
# ip = IPAddr.new("172.16.100.2")
|
1559
|
+
# packet = res.query(ip)
|
1560
|
+
# packet = res.query("192.168.10.254")
|
1561
|
+
#
|
1562
|
+
# Returns a Net::DNS::Packet object. If you need to examine the response
|
1563
|
+
# packet whether it contains any answers or not, use the Resolver#query
|
1564
|
+
# method instead.
|
1565
|
+
#
|
1566
|
+
# If the name doesn't contain any dots then append the default domain.
|
1567
|
+
# Performs a DNS query for the given name. Neither the
|
1568
|
+
# searchlist nor the default domain will be appended.
|
1569
|
+
#
|
1570
|
+
# The argument list can be either a Net::DNS::Packet object
|
1571
|
+
# or a name string plus optional type and class, which if
|
1572
|
+
# omitted default to +A+ and +IN+.
|
1573
|
+
#
|
1574
|
+
# Returns a Net::DNS::Packet object.
|
1575
|
+
#
|
1576
|
+
# # Executes the query with a +Packet+ object
|
1577
|
+
# send_packet = Net::DNS::Packet.new("host.example.com", Net::DNS::NS, Net::DNS::HS)
|
1578
|
+
# packet = res.query(send_packet)
|
1579
|
+
#
|
1580
|
+
# # Executes the query with a host, type and cls
|
1581
|
+
# packet = res.query("host.example.com")
|
1582
|
+
# packet = res.query("host.example.com", Net::DNS::NS)
|
1583
|
+
# packet = res.query("host.example.com", Net::DNS::NS, Net::DNS::HS)
|
1584
|
+
#
|
1585
|
+
# If the name is an IP address (Ipv4 or IPv6), in the form of a string
|
1586
|
+
# or a IPAddr object, then an appropriate PTR query will be performed:
|
1587
|
+
#
|
1588
|
+
# ip = IPAddr.new("172.16.100.2")
|
1589
|
+
# packet = res.query(ip)
|
1590
|
+
#
|
1591
|
+
# packet = res.query("172.16.100.2")
|
1592
|
+
#
|
1593
|
+
# Use +packet.header.ancount+ or +packet.answer+ to find out if there
|
1594
|
+
# were any records in the answer section.
|
1595
|
+
#
|
1596
|
+
# Store packet_data for performance improvements,
|
1597
|
+
# so methods don't keep on calling Packet#data
|
1598
|
+
# Choose whether use TCP, UDP or RAW
|
1599
|
+
# Must use TCP, either plain or raw
|
1600
|
+
# Use raw sockets?
|
1601
|
+
# Packet size is inside the boundaries
|
1602
|
+
# Use raw sockets?
|
1603
|
+
# User requested TCP
|
1604
|
+
# Finally use UDP
|
1605
|
+
# Performs a zone transfer for the zone passed as a parameter.
|
1606
|
+
#
|
1607
|
+
# It is actually only a wrapper to a send with type set as Net::DNS::AXFR,
|
1608
|
+
# since it is using the same infrastucture.
|
1609
|
+
#
|
1610
|
+
# Performs an MX query for the domain name passed as parameter.
|
1611
|
+
#
|
1612
|
+
# It actually uses the same methods a normal Resolver query would
|
1613
|
+
# use, but automatically sort the results based on preferences
|
1614
|
+
# and returns an ordered array.
|
1615
|
+
#
|
1616
|
+
# res = Net::DNS::Resolver.new
|
1617
|
+
# res.mx("google.com")
|
1618
|
+
#
|
1619
|
+
# Parses a configuration file specified as the argument.
|
1620
|
+
# Parses environment variables.
|
1621
|
+
# Contains a number, try to see if it's an IP or IPv6 address
|
1622
|
+
# Create the packet
|
1623
|
+
# DNSSEC and TSIG stuff to be inserted here
|
1624
|
+
# FIXME: a ? method should never raise.
|
1625
|
+
ENV['RES_OPTIONS']&.split(" ")&.each do |opt|
|
1626
|
+
name, val = opt.split(":")
|
1627
|
+
begin
|
1628
|
+
eval("self.#{name} = #{val}")
|
1629
|
+
rescue NoMethodError
|
1630
|
+
raise ArgumentError, "Invalid ENV option #{name}"
|
1085
1631
|
end
|
1086
1632
|
end
|
1087
1633
|
end
|
data/lib/net/dns/rr/soa.rb
CHANGED
data/lib/net/dns/rr/types.rb
CHANGED
@@ -6,65 +6,87 @@ module Net # :nodoc:
|
|
6
6
|
TYPES = {
|
7
7
|
'SIGZERO' => 0, # RFC2931 consider this a pseudo type
|
8
8
|
'A' => 1, # RFC 1035, Section 3.4.1
|
9
|
-
'NS' => 2,
|
10
|
-
'MD' => 3,
|
11
|
-
'MF' => 4,
|
9
|
+
'NS' => 2, # RFC 1035, Section 3.3.11
|
10
|
+
'MD' => 3, # RFC 1035, Section 3.3.4 (obsolete)
|
11
|
+
'MF' => 4, # RFC 1035, Section 3.3.5 (obsolete)
|
12
12
|
'CNAME' => 5, # RFC 1035, Section 3.3.1
|
13
13
|
'SOA' => 6, # RFC 1035, Section 3.3.13
|
14
|
-
'MB' => 7,
|
15
|
-
'MG' => 8,
|
16
|
-
'MR' => 9,
|
17
|
-
'NULL' => 10, # RFC 1035, Section 3.3.10
|
18
|
-
'WKS' => 11,
|
19
|
-
'PTR' => 12,
|
20
|
-
'HINFO' => 13,
|
21
|
-
'MINFO' => 14,
|
14
|
+
'MB' => 7, # RFC 1035, Section 3.3.3 (obsolete)
|
15
|
+
'MG' => 8, # RFC 1035, Section 3.3.6 (obsolete)
|
16
|
+
'MR' => 9, # RFC 1035, Section 3.3.8 (obsolete)
|
17
|
+
'NULL' => 10, # RFC 1035, Section 3.3.10 (obsolete)
|
18
|
+
'WKS' => 11, # RFC 1035, Section 3.4.2 (obsolete)
|
19
|
+
'PTR' => 12, # RFC 1035, Section 3.3.12
|
20
|
+
'HINFO' => 13, # RFC 1035, Section 3.3.2
|
21
|
+
'MINFO' => 14, # RFC 1035, Section 3.3.7 (obsolete)
|
22
22
|
'MX' => 15, # RFC 1035, Section 3.3.9
|
23
23
|
'TXT' => 16, # RFC 1035, Section 3.3.14
|
24
|
-
'RP' => 17, # RFC 1183, Section 2.2
|
24
|
+
'RP' => 17, # RFC 1183, Section 2.2 (obsolete)
|
25
25
|
'AFSDB' => 18, # RFC 1183, Section 1
|
26
|
-
'X25' => 19, # RFC 1183, Section 3.1
|
27
|
-
'ISDN' => 20, # RFC 1183, Section 3.2
|
28
|
-
'RT' => 21, # RFC 1183, Section 3.3
|
29
|
-
'NSAP' => 22, # RFC 1706, Section 5
|
30
|
-
'NSAP_PTR' => 23, # RFC 1348 (obsolete)
|
26
|
+
'X25' => 19, # RFC 1183, Section 3.1 (obsolete)
|
27
|
+
'ISDN' => 20, # RFC 1183, Section 3.2 (obsolete)
|
28
|
+
'RT' => 21, # RFC 1183, Section 3.3 (obsolete)
|
29
|
+
'NSAP' => 22, # RFC 1706, Section 5 (obsolete)
|
30
|
+
'NSAP_PTR' => 23, # RFC 1348 (obsolete) (obsolete)
|
31
31
|
# The following 2 RRs are impemented in Net::DNS::SEC, TODO
|
32
|
-
'SIG' => 24,
|
33
|
-
'KEY' => 25,
|
34
|
-
'PX' => 26, # RFC 2163,
|
35
|
-
'GPOS' => 27,
|
36
|
-
'AAAA' => 28,
|
32
|
+
'SIG' => 24, # RFC 2535, Section 4.1 (obsolete)
|
33
|
+
'KEY' => 25, # RFC 2535, Section 3.1 (obsolete)
|
34
|
+
'PX' => 26, # RFC 2163, (obsolete)
|
35
|
+
'GPOS' => 27, # RFC 1712 (obsolete)
|
36
|
+
'AAAA' => 28, # RFC 1886, Section 2.1
|
37
37
|
'LOC' => 29, # RFC 1876
|
38
38
|
# The following RR is implemented in Net::DNS::SEC, TODO
|
39
|
-
'NXT' => 30,
|
40
|
-
'EID' => 31,
|
41
|
-
'NIMLOC' => 32, # draft-ietf-nimrod-dns-xx.txt
|
39
|
+
'NXT' => 30, # RFC 2535, Section 5.2 (obsolete)
|
40
|
+
'EID' => 31, # draft-ietf-nimrod-dns-xx.txt (obsolete)
|
41
|
+
'NIMLOC' => 32, # draft-ietf-nimrod-dns-xx.txt (obsolete)
|
42
42
|
'SRV' => 33, # RFC 2052
|
43
|
-
'ATMA' => 34, # ???
|
43
|
+
'ATMA' => 34, # ??? (obsolete)
|
44
44
|
'NAPTR' => 35, # RFC 2168
|
45
45
|
'KX' => 36, # RFC 2230
|
46
46
|
'CERT' => 37, # RFC 2538
|
47
47
|
'DNAME' => 39, # RFC 2672
|
48
48
|
'OPT' => 41, # RFC 2671
|
49
|
+
'APL' => 42, # RFC 3123 (obsolete)
|
49
50
|
# The following 4 RRs are implemented in Net::DNS::SEC TODO
|
50
|
-
'DS' => 43, #
|
51
|
-
'SSHFP' => 44,
|
52
|
-
'
|
53
|
-
'
|
54
|
-
'
|
55
|
-
'
|
56
|
-
'
|
57
|
-
'
|
58
|
-
'
|
59
|
-
'
|
60
|
-
'
|
61
|
-
'
|
62
|
-
'
|
63
|
-
'
|
64
|
-
'
|
51
|
+
'DS' => 43, # RFC 4034
|
52
|
+
'SSHFP' => 44, # RFC 4255
|
53
|
+
'IPSECKEY' => 45, # RFC 4025
|
54
|
+
'RRSIG' => 46, # RFC 4034
|
55
|
+
'NSEC' => 47, # RFC 4034
|
56
|
+
'DNSKEY' => 48, # RFC 4034
|
57
|
+
'DHCID' => 49, # RFC 4701
|
58
|
+
'NSEC3' => 50, # RFC 5155
|
59
|
+
'NSEC3PARAM' => 51, # RFC 5155
|
60
|
+
'TLSA' => 52, # RFC 6698
|
61
|
+
'SMIMEA' => 53, # RFC 8162
|
62
|
+
'HIP' => 55, # RFC 8005
|
63
|
+
'CDS' => 59, # RFC 7344
|
64
|
+
'CDNSKEY' => 60, # RFC 7344
|
65
|
+
'OPENPGPKEY' => 61, # RFC 7929
|
66
|
+
'CSYNC' => 62, # RFC 7477
|
67
|
+
'ZONEMD' => 63, # RFC 8976
|
68
|
+
'SVCB' => 64, # RFC 9460
|
69
|
+
'HTTPS' => 65, # RFC 9460
|
70
|
+
'UINFO' => 100, # non-standard (obsolete)
|
71
|
+
'UID' => 101, # non-standard (obsolete)
|
72
|
+
'GID' => 102, # non-standard (obsolete)
|
73
|
+
'UNSPEC' => 103, # non-standard (obsolete)
|
74
|
+
'EUI48' => 108, # RFC 7043
|
75
|
+
'EUI64' => 109, # RFC 7043
|
76
|
+
'TKEY' => 249, # RFC 2930
|
77
|
+
'TSIG' => 250, # RFC 2931
|
78
|
+
'IXFR' => 251, # RFC 1995
|
79
|
+
'AXFR' => 252, # RFC 1035
|
80
|
+
'MAILB' => 253, # RFC 1035 (MB, MG, MR) (obsolete)
|
81
|
+
'MAILA' => 254, # RFC 1035 (obsolete - see MX)
|
65
82
|
'ANY' => 255, # RFC 1035
|
83
|
+
'URI' => 256, # RFC 7553
|
84
|
+
'CAA' => 257, # RFC 6844
|
66
85
|
}.freeze
|
67
86
|
|
87
|
+
# Pre-initialize the inverted hash to avoid runtime inversion
|
88
|
+
TYPES_BY_NUMBER = TYPES.invert.freeze
|
89
|
+
|
68
90
|
# The default value when type is nil in Resource Records
|
69
91
|
@@default = TYPES["A"]
|
70
92
|
|
@@ -88,7 +110,7 @@ module Net # :nodoc:
|
|
88
110
|
when String
|
89
111
|
TYPES.key?(type)
|
90
112
|
when Integer
|
91
|
-
|
113
|
+
TYPES_BY_NUMBER.key?(type)
|
92
114
|
else
|
93
115
|
raise ArgumentError, "Wrong type class: #{type.class}"
|
94
116
|
end
|
@@ -99,8 +121,8 @@ module Net # :nodoc:
|
|
99
121
|
def self.to_str(type)
|
100
122
|
case type
|
101
123
|
when Integer
|
102
|
-
if
|
103
|
-
|
124
|
+
if TYPES_BY_NUMBER.key? type
|
125
|
+
TYPES_BY_NUMBER[type]
|
104
126
|
else
|
105
127
|
raise ArgumentError, "Unknown type number #{type}"
|
106
128
|
end
|
@@ -129,7 +151,7 @@ module Net # :nodoc:
|
|
129
151
|
new_from_num(type)
|
130
152
|
when nil
|
131
153
|
# default type, control with Types.default=
|
132
|
-
@str =
|
154
|
+
@str = TYPES_BY_NUMBER[@@default]
|
133
155
|
@num = @@default
|
134
156
|
else
|
135
157
|
raise ArgumentError, "Wrong type class: #{type.class}"
|
@@ -178,11 +200,11 @@ module Net # :nodoc:
|
|
178
200
|
|
179
201
|
# Contructor for numeric data type.
|
180
202
|
def new_from_num(type)
|
181
|
-
if
|
203
|
+
if TYPES_BY_NUMBER.key? type
|
182
204
|
@num = type
|
183
|
-
@str =
|
205
|
+
@str = TYPES_BY_NUMBER[type]
|
184
206
|
else
|
185
|
-
raise ArgumentError, "
|
207
|
+
raise ArgumentError, "Unknown type number #{type}"
|
186
208
|
end
|
187
209
|
end
|
188
210
|
end
|
data/lib/net/dns/rr.rb
CHANGED
@@ -298,7 +298,14 @@ module Net
|
|
298
298
|
if self.class == Net::DNS::RR
|
299
299
|
temp = dn_expand(data, offset)[1]
|
300
300
|
type = Net::DNS::RR::Types.new data.unpack("@#{temp} n")[0]
|
301
|
-
|
301
|
+
rr_class = Net::DNS::RR.const_get(type.to_s) rescue nil
|
302
|
+
|
303
|
+
if rr_class && rr_class.respond_to?(:parse_packet)
|
304
|
+
rr_class.parse_packet(data, offset)
|
305
|
+
else
|
306
|
+
# This shouldn't happen because Net::DNS::RR::Types.new already raises an error on invalid types
|
307
|
+
raise "Unknown or unsupported RR type: #{type}"
|
308
|
+
end
|
302
309
|
else
|
303
310
|
@name, offset = dn_expand(data, offset)
|
304
311
|
rrtype, cls, @ttl, @rdlength = data.unpack("@#{offset} n2 N n")
|
data/lib/net/dns/version.rb
CHANGED
data/test/unit/question_test.rb
CHANGED
@@ -5,7 +5,7 @@ class QuestionTest < Minitest::Test
|
|
5
5
|
def setup
|
6
6
|
@domain = 'example.com.'
|
7
7
|
@type = 'MX'
|
8
|
-
@cls
|
8
|
+
@cls = 'HS'
|
9
9
|
@data = "\006google\003com\000\000\001\000\001"
|
10
10
|
|
11
11
|
@default = Net::DNS::Question.new(@domain)
|
@@ -42,6 +42,15 @@ class QuestionTest < Minitest::Test
|
|
42
42
|
assert_raises(ArgumentError) do
|
43
43
|
Net::DNS::Question.parse([])
|
44
44
|
end
|
45
|
+
assert_raises(ArgumentError) do
|
46
|
+
Net::DNS::Question.parse("[]")
|
47
|
+
end
|
48
|
+
assert_raises(ArgumentError) do
|
49
|
+
Net::DNS::Question.parse("12344")
|
50
|
+
end
|
51
|
+
assert_raises(ArgumentError) do
|
52
|
+
Net::DNS::Question.parse("12345")
|
53
|
+
end
|
45
54
|
assert_raises(ArgumentError) do
|
46
55
|
Net::DNS::Question.parse("test")
|
47
56
|
end
|
data/test/unit/rr/a_test.rb
CHANGED
@@ -10,7 +10,7 @@ class RRATest < Minitest::Test
|
|
10
10
|
@rr_value = "64.233.187.99"
|
11
11
|
@rr_address = IPAddr.new(@rr_value)
|
12
12
|
|
13
|
-
@rr_output
|
13
|
+
@rr_output = "google.com. 10000 IN A 64.233.187.99"
|
14
14
|
|
15
15
|
@rr = Net::DNS::RR::A.new(name: @rr_name, address: @rr_address, ttl: @rr_ttl)
|
16
16
|
end
|
data/test/unit/rr/aaaa_test.rb
CHANGED
@@ -10,9 +10,9 @@ class RRAAAATest < Minitest::Test
|
|
10
10
|
@rr_value = "2a00:d40:1:1::239"
|
11
11
|
@rr_address = IPAddr.new(@rr_value)
|
12
12
|
|
13
|
-
@rr_output
|
13
|
+
@rr_output = "www.nic.it. 60 IN AAAA 2a00:d40:1:1::239"
|
14
14
|
|
15
|
-
@rr
|
15
|
+
@rr = Net::DNS::RR::AAAA.new(name: @rr_name, address: @rr_address, ttl: @rr_ttl)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_initialize_from_hash
|
data/test/unit/rr/cname_test.rb
CHANGED
@@ -10,9 +10,9 @@ class RRCNAMETest < Minitest::Test
|
|
10
10
|
@rr_value = "www.l.google.com."
|
11
11
|
@rr_cname = @rr_value
|
12
12
|
|
13
|
-
@rr_output
|
13
|
+
@rr_output = "www.google.com. 550317 IN CNAME www.l.google.com."
|
14
14
|
|
15
|
-
@rr
|
15
|
+
@rr = Net::DNS::RR::CNAME.new(name: @rr_name, cname: @rr_cname, ttl: @rr_ttl)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_initialize_from_hash
|
data/test/unit/rr/hinfo_test.rb
CHANGED
@@ -14,7 +14,7 @@ class RRHINFOTest < Minitest::Test
|
|
14
14
|
@rr_cpu = "PC-Intel-700mhz"
|
15
15
|
@rr_os = "Redhat Linux 7.1"
|
16
16
|
|
17
|
-
@rr
|
17
|
+
@rr = Net::DNS::RR::HINFO.new(name: @rr_name, cpu: @rr_cpu, os: @rr_os)
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_initialize_from_hash
|
data/test/unit/rr/mx_test.rb
CHANGED
@@ -11,9 +11,9 @@ class RRMXTest < Minitest::Test
|
|
11
11
|
@rr_exchange = "mail.example.com."
|
12
12
|
@rr_value = "#{@rr_preference} #{@rr_exchange}"
|
13
13
|
|
14
|
-
@rr_output
|
14
|
+
@rr_output = "example.com. 10000 IN MX 10 mail.example.com."
|
15
15
|
|
16
|
-
@rr
|
16
|
+
@rr = Net::DNS::RR::MX.new(name: "example.com.", preference: 10, exchange: "mail.example.com.", ttl: 10_000)
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_initialize_from_hash
|
data/test/unit/rr/ns_test.rb
CHANGED
@@ -9,9 +9,9 @@ class RRNSTest < Minitest::Test
|
|
9
9
|
@rr_ttl = 10_800
|
10
10
|
@rr_nsdname = "ns1.google.com."
|
11
11
|
|
12
|
-
@rr_output
|
12
|
+
@rr_output = "google.com. 10800 IN NS ns1.google.com."
|
13
13
|
|
14
|
-
@rr
|
14
|
+
@rr = Net::DNS::RR::NS.new(name: "google.com.", nsdname: "ns1.google.com.", ttl: @rr_ttl)
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_initialize_from_hash
|
data/test/unit/rr/types_test.rb
CHANGED
@@ -50,10 +50,10 @@ class RRTypesTest < Minitest::Test
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_valid?
|
53
|
-
assert_equal(true,
|
54
|
-
assert_equal(true,
|
53
|
+
assert_equal(true, Net::DNS::RR::Types.valid?("A"))
|
54
|
+
assert_equal(true, Net::DNS::RR::Types.valid?(1))
|
55
55
|
assert_equal(false, Net::DNS::RR::Types.valid?("Q"))
|
56
|
-
assert_equal(false, Net::DNS::RR::Types.valid?(
|
56
|
+
assert_equal(false, Net::DNS::RR::Types.valid?(12345))
|
57
57
|
assert_raises(ArgumentError) do
|
58
58
|
Net::DNS::RR::Types.valid?({})
|
59
59
|
end
|
@@ -62,7 +62,7 @@ class RRTypesTest < Minitest::Test
|
|
62
62
|
def test_to_str
|
63
63
|
assert_equal("A", Net::DNS::RR::Types.to_str(1))
|
64
64
|
assert_raises(ArgumentError) do
|
65
|
-
Net::DNS::RR::Types.to_str(
|
65
|
+
Net::DNS::RR::Types.to_str(12345)
|
66
66
|
end
|
67
67
|
assert_raises(ArgumentError) do
|
68
68
|
Net::DNS::RR::Types.to_str("string")
|
data/test/unit/rr_test.rb
CHANGED
@@ -124,4 +124,37 @@ class RRTest < Minitest::Test
|
|
124
124
|
Net::DNS::RR.new("google.com. 10800 IM A")
|
125
125
|
end
|
126
126
|
end
|
127
|
+
|
128
|
+
def test_bad_type
|
129
|
+
assert_raises(ArgumentError) do
|
130
|
+
Net::DNS::RR.new(name: @rr_name,
|
131
|
+
ttl: @ttl,
|
132
|
+
cls: @cls,
|
133
|
+
type: "BOGUS",
|
134
|
+
address: @rdata)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_parse_packet_with_unsupported_type
|
139
|
+
# Create a mock binary packet with an unsupported RR type
|
140
|
+
|
141
|
+
# Start with a normal A record to get valid binary data
|
142
|
+
record = Net::DNS::RR.new("example.com. 3600 IN A 192.168.1.1")
|
143
|
+
binary_data = record.data
|
144
|
+
|
145
|
+
# Find where the name ends by looking for a null byte
|
146
|
+
name_end = binary_data.index("\x00") + 1
|
147
|
+
|
148
|
+
# Replace the type value (2 bytes) with 0xFACE (an undefined type)
|
149
|
+
modified_data = binary_data.dup
|
150
|
+
modified_data[name_end, 2] = [0xFACE].pack("n")
|
151
|
+
|
152
|
+
# The parse_packet should raise an error for unknown types
|
153
|
+
error = assert_raises(ArgumentError) do
|
154
|
+
Net::DNS::RR.parse(modified_data)
|
155
|
+
end
|
156
|
+
|
157
|
+
# Verify the error message mentions the unknown type
|
158
|
+
assert_match(/Unknown type number/, error.message)
|
159
|
+
end
|
127
160
|
end
|
metadata
CHANGED
@@ -1,16 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-net-dns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marco Ceresa
|
8
8
|
- Simone Carletti
|
9
|
-
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2025-04-28 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logger
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
14
27
|
- !ruby/object:Gem::Dependency
|
15
28
|
name: mocha
|
16
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,7 +142,6 @@ homepage: https://gitlab.com/gitlab-org/gitlab-net-dns
|
|
129
142
|
licenses:
|
130
143
|
- Ruby
|
131
144
|
metadata: {}
|
132
|
-
post_install_message:
|
133
145
|
rdoc_options: []
|
134
146
|
require_paths:
|
135
147
|
- lib
|
@@ -137,15 +149,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
149
|
requirements:
|
138
150
|
- - ">="
|
139
151
|
- !ruby/object:Gem::Version
|
140
|
-
version: '
|
152
|
+
version: '3.0'
|
141
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
154
|
requirements:
|
143
155
|
- - ">="
|
144
156
|
- !ruby/object:Gem::Version
|
145
157
|
version: '0'
|
146
158
|
requirements: []
|
147
|
-
rubygems_version: 3.
|
148
|
-
signing_key:
|
159
|
+
rubygems_version: 3.6.2
|
149
160
|
specification_version: 4
|
150
161
|
summary: Pure Ruby DNS library.
|
151
162
|
test_files:
|