lib-dhcp 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 903661e700f93534c6a5901ec965da48261e5e97d399f812bff7aa8b9d990b9d
4
- data.tar.gz: d2f9fb68a1171aa5812bfe5b7da0e9c4316ced431f24b33271d0704d61fda7d4
2
+ SHA1:
3
+ metadata.gz: 53121146f58779b496d7c7c9e77e958c63acc29c
4
+ data.tar.gz: 52f05fc29b2759d0436b4585d96c5c9c96bccc23
5
5
  SHA512:
6
- metadata.gz: 88a40896ce795cd16bea2836b2f9e3f8db1fd332b86c2a21ac34e72c0f2380cca86a112d6d369f9fd1b6e7ffdef50e0f64ce288289444a9691f39dda82e67582
7
- data.tar.gz: ed34b5fdfd7f36dd3286765fcf10f89facedb02e5531fba4d15f26efffc1fbf4ed96a01d504c341a63f34656529f03ba713c855ca7bbdd40fb998a19e2dc3784
6
+ metadata.gz: 44aa6bc04389a95fd3ef79ca190bf6fa8bc383dc6dc8179792f7af91e3de0d8bf1c9be8744003323a8e227404f9e8d295b84aba9914dea57b1e4265ab8e0852c
7
+ data.tar.gz: '091386845addca0b7380db9aaed49921c23e9406ae77252f7e597ea719e05cc62addc15798b4beefc33ec27de8926831d8ee871e11dc19b86afe5ad60ae4f086'
data/.gitignore CHANGED
@@ -7,4 +7,6 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  .idea/
10
- Gemfile.lock
10
+ Gemfile.lock
11
+ .DS_store
12
+ *.gem
@@ -34,6 +34,7 @@ module Lib
34
34
  raise TypeError, "Can't convert #{options.class.name} to Lib::DHCP::Option"
35
35
  end
36
36
  self.options.add Lib::DHCP::Option53.new(LEASE_QUERY)
37
+
37
38
  end
38
39
 
39
40
  def pack
@@ -50,13 +51,42 @@ module Lib
50
51
  res
51
52
  end
52
53
 
54
+ def query_by_ip?
55
+ (ciaddr != 0) ? true : false
56
+ end
57
+
58
+ def query_by_mac?
59
+ (htype != 0 and hlen != 0 and chaddr != 0) ? true : false
60
+ end
61
+
62
+ def query_by_client_id?
63
+ option61.nil? ? false : true
64
+ end
65
+
53
66
  protected :op=
54
67
  # noinspection RubyResolve
55
68
  protected :option53=
56
69
 
57
70
  protected
58
71
  def sanity_check
59
- #TODO LeaseQuery Sanity Check
72
+ if query_by_ip?
73
+ raise Lib::DHCP::SanityCheck::LeaseQuery, 'The values of htype, hlen, and chaddr MUST be set to zero '+
74
+ 'in the query by IP' unless self.htype == 0 and self.hlen == 0 and self.chaddr == 0
75
+ raise Lib::DHCP::SanityCheck::LeaseQuery, 'The Client-identifier option (option 61) MUST NOT appear in the ' +
76
+ 'query by IP' unless self.option61.nil?
77
+ elsif query_by_mac?
78
+ raise Lib::DHCP::SanityCheck::LeaseQuery, 'The "ciaddr" field MUST be set to zero in the query ' +
79
+ 'by MAC address' unless self.ciaddr == 0
80
+ raise Lib::DHCP::SanityCheck::LeaseQuery, 'The Client-identifier option (option 61) MUST NOT appear in the ' +
81
+ 'query by MAC' if self.option61
82
+ elsif query_by_client_id?
83
+ raise Lib::DHCP::SanityCheck::LeaseQuery, 'The "ciaddr" field MUST be set to zero in the query ' +
84
+ 'by Client identifier' unless self.ciaddr == 0
85
+ raise Lib::DHCP::SanityCheck::LeaseQuery, 'The values of htype, hlen, and chaddr MUST be set to zero in ' +
86
+ 'the query by Client identifier' unless self.htype == 0 or self.hlen == 0 and self.chaddr != 0
87
+ else
88
+ raise Lib::DHCP::SanityCheck::LeaseQuery, 'Unknown query type'
89
+ end
60
90
  end
61
91
  end
62
92
  end
@@ -140,6 +140,8 @@ module Lib
140
140
  STREET_TALK_DIRECTORY_SERVER= 0x4c
141
141
  USER_CLASS= 0x4d
142
142
  RELAY_AGENT = 0x52
143
+ CLIENT_LAST_TRANSACTION_TIME= 0x5b
144
+ ASSOCIATED_IP = 0x5c
143
145
  PRIVATE= 0xaf
144
146
  END_OPTION = 0xff
145
147
 
@@ -235,8 +237,8 @@ module Lib
235
237
  88 => 'BCMCS Controller Domain Name list',
236
238
  89 => 'BCMCS Controller IPv4 address list.',
237
239
  90 => 'Authentication',
238
- 91 => 'client-last-transaction-time',
239
- 92 => 'associated-ip',
240
+ 91 => 'Client last transaction time',
241
+ 92 => 'Associated IP',
240
242
  93 => 'Client System Architecture Type',
241
243
  119 => 'Domain Search',
242
244
  121 => 'Classless Static Route Option',
@@ -10,8 +10,44 @@ require_relative 'type/raw'
10
10
  module Lib
11
11
  module DHCP
12
12
  class Option91 < Option
13
- #TODO Option91
14
- include Lib::DHCP::Option::Type::Raw
13
+ # This option allows the receiver to determine the time of the
14
+ # most recent access of the client. It is particularly useful
15
+ # when DHCPLEASEACTIVE messages from two different DHCP servers
16
+ # need to be compared, although it can be useful in other
17
+ # situations. The value is a duration in seconds from the
18
+ # current time into the past when this IP address was most
19
+ # recently the subject of communication between the client and
20
+ # the DHCP server.
21
+ # The code for the this option is 91. The length of the this option is 4 octets.
22
+
23
+ def_delegators :@payload, :to_s
24
+
25
+ def initialize(time)
26
+ super CLIENT_LAST_TRANSACTION_TIME, time.to_i
27
+ end
28
+
29
+ def payload=(time)
30
+ @payload = time.to_i
31
+ end
32
+
33
+ def pack
34
+ [@oid, 4, @payload].pack('C2N')
35
+ end
36
+
37
+ def len
38
+ 4
39
+ end
40
+
41
+ alias_method :time, :payload
42
+ alias_method :time=, :payload=
43
+
44
+ private
45
+
46
+ def self.unpack(oid, len, payload)
47
+ raise ArgumentError, "OID Mismatch for #{NAME[oid]} - #{oid}" unless oid.to_i == CLIENT_LAST_TRANSACTION_TIME
48
+ raise ArgumentError, "Wrong #{NAME[oid]} length - #{len}" unless len == 4
49
+ self.new payload.unpack('N').first.to_i
50
+ end
15
51
  end
16
52
  end
17
53
  end
@@ -5,13 +5,21 @@
5
5
 
6
6
 
7
7
  require_relative 'option'
8
- require_relative 'type/raw'
8
+ require 'lib/dhcp/options/type/ip_array'
9
9
 
10
10
  module Lib
11
11
  module DHCP
12
12
  class Option92 < Option
13
- #TODO Option92
14
- include Lib::DHCP::Option::Type::Raw
13
+
14
+ # This option is used to return all of the IP addresses
15
+ # associated with the DHCP client specified in a particular DHCPLEASEQUERY message.
16
+ # The code for this option is 92. The minimum length for this option is 4 octets,
17
+ # and the length MUST always be a multiple of 4.
18
+
19
+ include Type::IPArray
20
+
21
+ alias_method :associated_ip, :payload
22
+ alias_method :associated_ip=, :payload=
15
23
  end
16
24
  end
17
25
  end
@@ -1,5 +1,5 @@
1
1
  module Lib
2
2
  module DHCP
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lib-dhcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Wojcieszonek
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-13 00:00:00.000000000 Z
11
+ date: 2018-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -402,7 +402,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
402
402
  version: '0'
403
403
  requirements: []
404
404
  rubyforge_project:
405
- rubygems_version: 2.7.5
405
+ rubygems_version: 2.6.14
406
406
  signing_key:
407
407
  specification_version: 4
408
408
  summary: DHCP protocol library.