packetgen 3.1.3 → 3.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/bin/pgconsole +1 -0
- data/lib/packetgen.rb +33 -4
- data/lib/packetgen/capture.rb +51 -28
- data/lib/packetgen/config.rb +17 -11
- data/lib/packetgen/deprecation.rb +33 -7
- data/lib/packetgen/header.rb +2 -9
- data/lib/packetgen/header/arp.rb +2 -2
- data/lib/packetgen/header/asn1_base.rb +2 -2
- data/lib/packetgen/header/base.rb +70 -74
- data/lib/packetgen/header/bootp.rb +3 -3
- data/lib/packetgen/header/dhcp.rb +2 -2
- data/lib/packetgen/header/dhcp/option.rb +2 -2
- data/lib/packetgen/header/dhcp/options.rb +2 -2
- data/lib/packetgen/header/dhcpv6.rb +12 -12
- data/lib/packetgen/header/dhcpv6/duid.rb +11 -5
- data/lib/packetgen/header/dhcpv6/option.rb +8 -16
- data/lib/packetgen/header/dhcpv6/options.rb +2 -2
- data/lib/packetgen/header/dhcpv6/relay.rb +2 -2
- data/lib/packetgen/header/dns.rb +9 -9
- data/lib/packetgen/header/dns/name.rb +20 -9
- data/lib/packetgen/header/dns/opt.rb +2 -2
- data/lib/packetgen/header/dns/option.rb +2 -2
- data/lib/packetgen/header/dns/qdsection.rb +3 -3
- data/lib/packetgen/header/dns/question.rb +37 -35
- data/lib/packetgen/header/dns/rr.rb +3 -3
- data/lib/packetgen/header/dns/rrsection.rb +2 -2
- data/lib/packetgen/header/dot11.rb +30 -51
- data/lib/packetgen/header/dot11/control.rb +5 -5
- data/lib/packetgen/header/dot11/data.rb +11 -7
- data/lib/packetgen/header/dot11/element.rb +16 -16
- data/lib/packetgen/header/dot11/management.rb +2 -2
- data/lib/packetgen/header/dot11/sub_mngt.rb +2 -12
- data/lib/packetgen/header/dot1q.rb +2 -2
- data/lib/packetgen/header/dot1x.rb +7 -20
- data/lib/packetgen/header/eap.rb +30 -33
- data/lib/packetgen/header/eap/fast.rb +2 -2
- data/lib/packetgen/header/eap/md5.rb +2 -2
- data/lib/packetgen/header/eap/tls.rb +2 -2
- data/lib/packetgen/header/eap/ttls.rb +2 -2
- data/lib/packetgen/header/eth.rb +13 -11
- data/lib/packetgen/header/gre.rb +2 -2
- data/lib/packetgen/header/http.rb +2 -0
- data/lib/packetgen/header/http/headers.rb +6 -4
- data/lib/packetgen/header/http/request.rb +36 -21
- data/lib/packetgen/header/http/response.rb +7 -7
- data/lib/packetgen/header/http/verbs.rb +3 -3
- data/lib/packetgen/header/icmp.rb +2 -2
- data/lib/packetgen/header/icmpv6.rb +2 -2
- data/lib/packetgen/header/igmp.rb +4 -4
- data/lib/packetgen/header/igmpv3.rb +3 -3
- data/lib/packetgen/header/igmpv3/group_record.rb +8 -6
- data/lib/packetgen/header/igmpv3/mq.rb +2 -2
- data/lib/packetgen/header/igmpv3/mr.rb +2 -2
- data/lib/packetgen/header/ip.rb +30 -31
- data/lib/packetgen/header/ip/addr.rb +10 -3
- data/lib/packetgen/header/ip/option.rb +8 -10
- data/lib/packetgen/header/ip/options.rb +3 -5
- data/lib/packetgen/header/ipv6.rb +2 -2
- data/lib/packetgen/header/ipv6/addr.rb +9 -2
- data/lib/packetgen/header/ipv6/extension.rb +2 -2
- data/lib/packetgen/header/ipv6/hop_by_hop.rb +3 -3
- data/lib/packetgen/header/llc.rb +2 -2
- data/lib/packetgen/header/mdns.rb +2 -2
- data/lib/packetgen/header/mld.rb +2 -2
- data/lib/packetgen/header/mldv2.rb +2 -2
- data/lib/packetgen/header/mldv2/mcast_address_record.rb +4 -2
- data/lib/packetgen/header/mldv2/mlq.rb +2 -2
- data/lib/packetgen/header/mldv2/mlr.rb +2 -2
- data/lib/packetgen/header/ospfv2.rb +9 -9
- data/lib/packetgen/header/ospfv2/db_description.rb +2 -2
- data/lib/packetgen/header/ospfv2/hello.rb +2 -2
- data/lib/packetgen/header/ospfv2/ls_ack.rb +2 -2
- data/lib/packetgen/header/ospfv2/ls_request.rb +4 -2
- data/lib/packetgen/header/ospfv2/ls_update.rb +2 -2
- data/lib/packetgen/header/ospfv2/lsa.rb +9 -5
- data/lib/packetgen/header/ospfv2/lsa_header.rb +8 -7
- data/lib/packetgen/header/ospfv3.rb +2 -2
- data/lib/packetgen/header/ospfv3/db_description.rb +2 -2
- data/lib/packetgen/header/ospfv3/hello.rb +2 -2
- data/lib/packetgen/header/ospfv3/ipv6_prefix.rb +4 -2
- data/lib/packetgen/header/ospfv3/ls_ack.rb +2 -2
- data/lib/packetgen/header/ospfv3/ls_request.rb +4 -2
- data/lib/packetgen/header/ospfv3/ls_update.rb +2 -2
- data/lib/packetgen/header/ospfv3/lsa.rb +5 -5
- data/lib/packetgen/header/ospfv3/lsa_header.rb +9 -8
- data/lib/packetgen/header/snmp.rb +33 -29
- data/lib/packetgen/header/tcp.rb +4 -23
- data/lib/packetgen/header/tcp/option.rb +11 -11
- data/lib/packetgen/header/tcp/options.rb +2 -2
- data/lib/packetgen/header/tftp.rb +6 -6
- data/lib/packetgen/header/udp.rb +3 -3
- data/lib/packetgen/headerable.rb +5 -4
- data/lib/packetgen/inject.rb +23 -0
- data/lib/packetgen/inspect.rb +23 -20
- data/lib/packetgen/packet.rb +82 -53
- data/lib/packetgen/pcap.rb +29 -0
- data/lib/packetgen/pcapng.rb +13 -13
- data/lib/packetgen/pcapng/block.rb +26 -13
- data/lib/packetgen/pcapng/epb.rb +25 -22
- data/lib/packetgen/pcapng/file.rb +260 -138
- data/lib/packetgen/pcapng/idb.rb +36 -38
- data/lib/packetgen/pcapng/shb.rb +51 -53
- data/lib/packetgen/pcapng/spb.rb +19 -19
- data/lib/packetgen/pcapng/unknown_block.rb +5 -13
- data/lib/packetgen/pcaprub_wrapper.rb +81 -0
- data/lib/packetgen/proto.rb +2 -2
- data/lib/packetgen/types.rb +3 -0
- data/lib/packetgen/types/abstract_tlv.rb +27 -7
- data/lib/packetgen/types/array.rb +22 -15
- data/lib/packetgen/types/cstring.rb +57 -20
- data/lib/packetgen/types/enum.rb +7 -2
- data/lib/packetgen/types/fieldable.rb +65 -0
- data/lib/packetgen/types/fields.rb +182 -117
- data/lib/packetgen/types/int.rb +18 -6
- data/lib/packetgen/types/int_string.rb +10 -2
- data/lib/packetgen/types/length_from.rb +20 -12
- data/lib/packetgen/types/oui.rb +4 -2
- data/lib/packetgen/types/string.rb +59 -8
- data/lib/packetgen/types/tlv.rb +4 -2
- data/lib/packetgen/utils.rb +4 -4
- data/lib/packetgen/utils/arp_spoofer.rb +2 -2
- data/lib/packetgen/version.rb +3 -3
- metadata +39 -61
- data/.gitignore +0 -13
- data/.rubocop.yml +0 -30
- data/.travis.yml +0 -19
- data/Gemfile +0 -4
- data/Rakefile +0 -21
- data/packetgen.gemspec +0 -36
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv2
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv2
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv2
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv2
|
@@ -14,6 +14,8 @@ module PacketGen
|
|
14
14
|
# * and {#advertising_router}.
|
15
15
|
# @author Sylvain Daubert
|
16
16
|
class LSR < Types::Fields
|
17
|
+
include Types::Fieldable
|
18
|
+
|
17
19
|
# @!attribute type
|
18
20
|
# The type of the LSA to request.
|
19
21
|
# @return [Integer]
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv2
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv2
|
@@ -23,6 +23,8 @@ module PacketGen
|
|
23
23
|
# LSA router payload}.
|
24
24
|
# @author Sylvain Daubert
|
25
25
|
class TosMetric < Types::Fields
|
26
|
+
include Types::Fieldable
|
27
|
+
|
26
28
|
# @!attribute tos
|
27
29
|
# 8-bit IP Type of Service that this metric refers to.
|
28
30
|
# @return [Integer]
|
@@ -52,6 +54,8 @@ module PacketGen
|
|
52
54
|
# This class handles links in a {LSARouter LSA router payload}.
|
53
55
|
# @author Sylvain Daubert
|
54
56
|
class Link < Types::Fields
|
57
|
+
include Types::Fieldable
|
58
|
+
|
55
59
|
# @!attribute id
|
56
60
|
# @return [IP::Addr]
|
57
61
|
define_field :id, IP::Addr
|
@@ -136,6 +140,8 @@ module PacketGen
|
|
136
140
|
# This class handles external links in {LSAASExternal LSA AS-External payloads}.
|
137
141
|
# @author Sylvain Daubert
|
138
142
|
class External < Types::Fields
|
143
|
+
include Types::Fieldable
|
144
|
+
|
139
145
|
# @!attribute u8
|
140
146
|
# @return [Integer]
|
141
147
|
define_field :u8, Types::Int8
|
@@ -204,9 +210,7 @@ module PacketGen
|
|
204
210
|
private
|
205
211
|
|
206
212
|
def record_from_hash(hsh)
|
207
|
-
unless hsh.key? :type
|
208
|
-
raise ArgumentError, 'hash should have :type key'
|
209
|
-
end
|
213
|
+
raise ArgumentError, 'hash should have :type key' unless hsh.key? :type
|
210
214
|
|
211
215
|
klass = if @only_headers
|
212
216
|
LSAHeader
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv2
|
@@ -29,13 +29,15 @@ module PacketGen
|
|
29
29
|
# is also a base class for different LSA class, as {LSARouter}.
|
30
30
|
# @author Sylvain Daubert
|
31
31
|
class LSAHeader < Types::Fields
|
32
|
+
include Types::Fieldable
|
33
|
+
|
32
34
|
# LSA Types
|
33
35
|
TYPES = {
|
34
|
-
'Router'
|
35
|
-
'Network'
|
36
|
-
'Summary-IP'
|
36
|
+
'Router' => 1,
|
37
|
+
'Network' => 2,
|
38
|
+
'Summary-IP' => 3,
|
37
39
|
'Summary-ABSR' => 4,
|
38
|
-
'AS-External'
|
40
|
+
'AS-External' => 5
|
39
41
|
}.freeze
|
40
42
|
|
41
43
|
# @!attribute age
|
@@ -75,7 +77,6 @@ module PacketGen
|
|
75
77
|
# Compute and set Fletcher-16 checksum on LSA
|
76
78
|
# @return [Integer]
|
77
79
|
def calc_checksum
|
78
|
-
self.checksum = 0
|
79
80
|
bytes = to_s[2..-1].unpack('C*')
|
80
81
|
|
81
82
|
c0 = c1 = 0
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
# This class supports OSPFv3 (RFC 5340).
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv3
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv3
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv3
|
@@ -17,6 +17,8 @@ module PacketGen
|
|
17
17
|
# array consumes ((PrefixLength + 31) / 32) 32-bit words.
|
18
18
|
# @author Sylvain Daubert
|
19
19
|
class IPv6Prefix < Types::Fields
|
20
|
+
include Types::Fieldable
|
21
|
+
|
20
22
|
# @!attribute length
|
21
23
|
# Prefix length, in bits
|
22
24
|
# @return [Integer]
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv3
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv3
|
@@ -27,6 +27,8 @@ module PacketGen
|
|
27
27
|
# * and a 32-bit {#advertising_router} field.
|
28
28
|
# @author Sylvain Daubert
|
29
29
|
class LSR < Types::Fields
|
30
|
+
include Types::Fieldable
|
31
|
+
|
30
32
|
# @!attribute reserved
|
31
33
|
# reserved field.
|
32
34
|
# @return [Integer]
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv3
|
@@ -1,16 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv3
|
11
11
|
# This class handles links in a {LSARouter OSPFv3 LSA router payload}.
|
12
12
|
# @author Sylvain Daubert
|
13
13
|
class Link < Types::Fields
|
14
|
+
include Types::Fieldable
|
15
|
+
|
14
16
|
# @!attribute type
|
15
17
|
# @return [Integer]
|
16
18
|
define_field :type, Types::Int8
|
@@ -197,9 +199,7 @@ module PacketGen
|
|
197
199
|
private
|
198
200
|
|
199
201
|
def record_from_hash(hsh)
|
200
|
-
unless hsh.key? :type
|
201
|
-
raise ArgumentError, 'hash should have :type key'
|
202
|
-
end
|
202
|
+
raise ArgumentError, 'hash should have :type key' unless hsh.key? :type
|
203
203
|
|
204
204
|
klass = if @only_headers
|
205
205
|
LSAHeader
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is part of PacketGen
|
2
4
|
# See https://github.com/sdaubert/packetgen for more informations
|
3
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
6
|
# This program is published under MIT license.
|
5
7
|
|
6
|
-
# frozen_string_literal: true
|
7
|
-
|
8
8
|
module PacketGen
|
9
9
|
module Header
|
10
10
|
class OSPFv3
|
@@ -29,15 +29,17 @@ module PacketGen
|
|
29
29
|
# But this class is also a base class for different LSA class, as {LSARouter}.
|
30
30
|
# @author Sylvain Daubert
|
31
31
|
class LSAHeader < Types::Fields
|
32
|
+
include Types::Fieldable
|
33
|
+
|
32
34
|
# LSA known types
|
33
35
|
TYPES = {
|
34
|
-
'Router'
|
35
|
-
'Network'
|
36
|
+
'Router' => 0x2001,
|
37
|
+
'Network' => 0x2002,
|
36
38
|
'Inter-Area-Prefix' => 0x2003,
|
37
39
|
'Inter-Area-Router' => 0x2004,
|
38
|
-
'AS-External'
|
39
|
-
'NSSA'
|
40
|
-
'Link'
|
40
|
+
'AS-External' => 0x4005,
|
41
|
+
'NSSA' => 0x2007,
|
42
|
+
'Link' => 0x0008,
|
41
43
|
'Intra-Area-Prefix' => 0x2009
|
42
44
|
}.freeze
|
43
45
|
|
@@ -76,7 +78,6 @@ module PacketGen
|
|
76
78
|
# Compute and set Fletcher-16 checksum on LSA
|
77
79
|
# @return [Integer]
|
78
80
|
def calc_checksum
|
79
|
-
self.checksum = 0
|
80
81
|
bytes = to_s[2..-1].unpack('C*')
|
81
82
|
|
82
83
|
c0 = c1 = 0
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
# This file is part of PacketGen
|
3
5
|
# See https://github.com/sdaubert/packetgen for more informations
|
4
6
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
5
7
|
# This program is published under MIT license.
|
6
8
|
|
7
|
-
# frozen_string_literal: true
|
8
|
-
|
9
9
|
module PacketGen
|
10
10
|
module Header
|
11
11
|
# Dissect error
|
@@ -22,6 +22,8 @@ module PacketGen
|
|
22
22
|
# Configuration sinks listen to this port
|
23
23
|
UDP_PORT2 = 162
|
24
24
|
|
25
|
+
# rubocop:disable Naming/ConstantName
|
26
|
+
|
25
27
|
PDU_GET = 0
|
26
28
|
PDU_NEXT = 1
|
27
29
|
PDU_RESPONSE = 2
|
@@ -31,27 +33,28 @@ module PacketGen
|
|
31
33
|
PDU_INFORM = 6
|
32
34
|
PDU_TRAPv2 = 7
|
33
35
|
PDU_REPORT = 8
|
36
|
+
# rubocop:enable Naming/ConstantName
|
34
37
|
|
35
38
|
ERRORS = {
|
36
|
-
'no_error'
|
37
|
-
'too_big'
|
38
|
-
'no_such_name'
|
39
|
-
'bad_value'
|
40
|
-
'read_only'
|
41
|
-
'generic_error'
|
42
|
-
'no_access'
|
43
|
-
'wrong_type'
|
44
|
-
'wrong_length'
|
45
|
-
'wrong_encoding'
|
46
|
-
'wrong_value'
|
47
|
-
'no_creation'
|
48
|
-
'inconsistent_value'
|
39
|
+
'no_error' => 0,
|
40
|
+
'too_big' => 1,
|
41
|
+
'no_such_name' => 2,
|
42
|
+
'bad_value' => 3,
|
43
|
+
'read_only' => 4,
|
44
|
+
'generic_error' => 5,
|
45
|
+
'no_access' => 6,
|
46
|
+
'wrong_type' => 7,
|
47
|
+
'wrong_length' => 8,
|
48
|
+
'wrong_encoding' => 9,
|
49
|
+
'wrong_value' => 10,
|
50
|
+
'no_creation' => 11,
|
51
|
+
'inconsistent_value' => 12,
|
49
52
|
'ressource_unavailable' => 13,
|
50
|
-
'commit_failed'
|
51
|
-
'undo_failed'
|
52
|
-
'authorization_error'
|
53
|
-
'not_writable'
|
54
|
-
'inconsistent_name'
|
53
|
+
'commit_failed' => 14,
|
54
|
+
'undo_failed' => 15,
|
55
|
+
'authorization_error' => 16,
|
56
|
+
'not_writable' => 17,
|
57
|
+
'inconsistent_name' => 18
|
55
58
|
}.freeze
|
56
59
|
|
57
60
|
# Class to handle SNMP VarBind
|
@@ -162,13 +165,13 @@ module PacketGen
|
|
162
165
|
implicit: SNMP::PDU_TRAPv1, constructed: true,
|
163
166
|
content: [objectid(:enterprise),
|
164
167
|
octet_string(:agent_addr),
|
165
|
-
integer(:generic_trap, enum: { 'cold_start'
|
166
|
-
'warm_start'
|
167
|
-
'link_down'
|
168
|
-
'link_up'
|
169
|
-
'auth_failure'
|
168
|
+
integer(:generic_trap, enum: { 'cold_start' => 0,
|
169
|
+
'warm_start' => 1,
|
170
|
+
'link_down' => 2,
|
171
|
+
'link_up' => 3,
|
172
|
+
'auth_failure' => 4,
|
170
173
|
'egp_neighbor_loss' => 5,
|
171
|
-
'specific'
|
174
|
+
'specific' => 6 }),
|
172
175
|
integer(:specific_trap),
|
173
176
|
integer(:timestamp),
|
174
177
|
model(:varbindlist, VariableBindings)]
|
@@ -243,7 +246,8 @@ module PacketGen
|
|
243
246
|
end
|
244
247
|
|
245
248
|
sequence :message,
|
246
|
-
content: [integer(:version,
|
249
|
+
content: [integer(:version,
|
250
|
+
value: 'v2c',
|
247
251
|
enum: { 'v1' => 0, 'v2c' => 1, 'v2' => 2, 'v3' => 3 }),
|
248
252
|
octet_string(:community, value: 'public'),
|
249
253
|
model(:data, PDUs)]
|
@@ -291,8 +295,8 @@ module PacketGen
|
|
291
295
|
str << data.chosen_value.inspect(1)
|
292
296
|
begin
|
293
297
|
str << Inspect.inspect_body(self[:message].to_der, 'ASN.1 DER')
|
294
|
-
rescue StandardError =>
|
295
|
-
raise unless
|
298
|
+
rescue StandardError => e
|
299
|
+
raise unless e.message.match?(/TAG.*not handled/)
|
296
300
|
end
|
297
301
|
str
|
298
302
|
end
|