packetgen 3.3.3 → 4.1.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/README.md +38 -22
- data/lib/packetgen/capture.rb +2 -2
- data/lib/packetgen/config.rb +0 -1
- data/lib/packetgen/deprecation.rb +14 -8
- data/lib/packetgen/header/arp.rb +17 -18
- data/lib/packetgen/header/asn1_base.rb +2 -1
- data/lib/packetgen/header/base.rb +42 -40
- data/lib/packetgen/header/bootp.rb +35 -37
- data/lib/packetgen/header/dhcp/option.rb +21 -21
- data/lib/packetgen/header/dhcp/options.rb +3 -3
- data/lib/packetgen/header/dhcp.rb +8 -9
- data/lib/packetgen/header/dhcpv6/duid.rb +16 -16
- data/lib/packetgen/header/dhcpv6/option.rb +83 -61
- data/lib/packetgen/header/dhcpv6/options.rb +4 -4
- data/lib/packetgen/header/dhcpv6/relay.rb +6 -5
- data/lib/packetgen/header/dhcpv6.rb +17 -18
- data/lib/packetgen/header/dns/name.rb +21 -16
- data/lib/packetgen/header/dns/opt.rb +5 -2
- data/lib/packetgen/header/dns/option.rb +14 -14
- data/lib/packetgen/header/dns/qdsection.rb +3 -3
- data/lib/packetgen/header/dns/question.rb +7 -8
- data/lib/packetgen/header/dns/rr.rb +56 -43
- data/lib/packetgen/header/dns/rrsection.rb +6 -6
- data/lib/packetgen/header/dns.rb +103 -90
- data/lib/packetgen/header/dot11/control.rb +12 -12
- data/lib/packetgen/header/dot11/data.rb +25 -24
- data/lib/packetgen/header/dot11/element.rb +4 -4
- data/lib/packetgen/header/dot11/management.rb +21 -18
- data/lib/packetgen/header/dot11/sub_mngt.rb +40 -53
- data/lib/packetgen/header/dot11.rb +117 -122
- data/lib/packetgen/header/dot1q.rb +12 -13
- data/lib/packetgen/header/dot1x.rb +13 -13
- data/lib/packetgen/header/eap/fast.rb +4 -4
- data/lib/packetgen/header/eap/md5.rb +16 -8
- data/lib/packetgen/header/eap/tls.rb +18 -19
- data/lib/packetgen/header/eap/ttls.rb +22 -21
- data/lib/packetgen/header/eap.rb +73 -48
- data/lib/packetgen/header/eth.rb +41 -27
- data/lib/packetgen/header/gre.rb +33 -11
- data/lib/packetgen/header/http/headers.rb +7 -6
- data/lib/packetgen/header/http/request.rb +38 -29
- data/lib/packetgen/header/http/response.rb +35 -27
- data/lib/packetgen/header/http/verbs.rb +1 -3
- data/lib/packetgen/header/icmp.rb +14 -14
- data/lib/packetgen/header/icmpv6.rb +10 -9
- data/lib/packetgen/header/igmp.rb +26 -15
- data/lib/packetgen/header/igmpv3/group_record.rb +18 -13
- data/lib/packetgen/header/igmpv3/mq.rb +16 -18
- data/lib/packetgen/header/igmpv3/mr.rb +5 -5
- data/lib/packetgen/header/igmpv3.rb +12 -11
- data/lib/packetgen/header/ip/addr.rb +19 -15
- data/lib/packetgen/header/ip/option.rb +47 -36
- data/lib/packetgen/header/ip/options.rb +1 -1
- data/lib/packetgen/header/ip.rb +77 -95
- data/lib/packetgen/header/ipv6/addr.rb +28 -27
- data/lib/packetgen/header/ipv6/extension.rb +13 -11
- data/lib/packetgen/header/ipv6/hop_by_hop.rb +32 -13
- data/lib/packetgen/header/ipv6.rb +42 -35
- data/lib/packetgen/header/llc.rb +28 -21
- data/lib/packetgen/header/mdns.rb +10 -3
- data/lib/packetgen/header/mld.rb +15 -13
- data/lib/packetgen/header/mldv2/mcast_address_record.rb +17 -12
- data/lib/packetgen/header/mldv2/mlq.rb +22 -24
- data/lib/packetgen/header/mldv2/mlr.rb +8 -8
- data/lib/packetgen/header/mldv2.rb +1 -1
- data/lib/packetgen/header/ospfv2/db_description.rb +17 -18
- data/lib/packetgen/header/ospfv2/hello.rb +18 -17
- data/lib/packetgen/header/ospfv2/ls_ack.rb +6 -7
- data/lib/packetgen/header/ospfv2/ls_request.rb +14 -13
- data/lib/packetgen/header/ospfv2/ls_update.rb +9 -9
- data/lib/packetgen/header/ospfv2/lsa.rb +79 -60
- data/lib/packetgen/header/ospfv2/lsa_header.rb +12 -11
- data/lib/packetgen/header/ospfv2.rb +49 -46
- data/lib/packetgen/header/ospfv3/db_description.rb +20 -22
- data/lib/packetgen/header/ospfv3/hello.rb +17 -16
- data/lib/packetgen/header/ospfv3/ipv6_prefix.rb +22 -20
- data/lib/packetgen/header/ospfv3/ls_ack.rb +7 -8
- data/lib/packetgen/header/ospfv3/ls_request.rb +18 -18
- data/lib/packetgen/header/ospfv3/ls_update.rb +10 -10
- data/lib/packetgen/header/ospfv3/lsa.rb +62 -51
- data/lib/packetgen/header/ospfv3/lsa_header.rb +12 -11
- data/lib/packetgen/header/ospfv3.rb +54 -52
- data/lib/packetgen/header/sctp/chunk.rb +80 -56
- data/lib/packetgen/header/sctp/error.rb +174 -202
- data/lib/packetgen/header/sctp/padded32.rb +3 -3
- data/lib/packetgen/header/sctp/parameter.rb +89 -136
- data/lib/packetgen/header/sctp.rb +19 -8
- data/lib/packetgen/header/snmp.rb +108 -7
- data/lib/packetgen/header/tcp/option.rb +52 -39
- data/lib/packetgen/header/tcp/options.rb +13 -5
- data/lib/packetgen/header/tcp.rb +83 -65
- data/lib/packetgen/header/tftp.rb +31 -25
- data/lib/packetgen/header/udp.rb +21 -19
- data/lib/packetgen/header.rb +23 -18
- data/lib/packetgen/headerable.rb +21 -5
- data/lib/packetgen/inspect.rb +3 -8
- data/lib/packetgen/packet.rb +146 -71
- data/lib/packetgen/pcap.rb +15 -4
- data/lib/packetgen/pcapng/block.rb +20 -18
- data/lib/packetgen/pcapng/epb.rb +13 -15
- data/lib/packetgen/pcapng/file.rb +44 -111
- data/lib/packetgen/pcapng/idb.rb +11 -12
- data/lib/packetgen/pcapng/shb.rb +15 -16
- data/lib/packetgen/pcapng/spb.rb +9 -11
- data/lib/packetgen/pcapng/unknown_block.rb +6 -17
- data/lib/packetgen/pcapng.rb +6 -4
- data/lib/packetgen/pcaprub_wrapper.rb +17 -1
- data/lib/packetgen/proto.rb +5 -1
- data/lib/packetgen/unknown_packet.rb +5 -5
- data/lib/packetgen/utils/arp_spoofer.rb +18 -19
- data/lib/packetgen/utils.rb +4 -3
- data/lib/packetgen/version.rb +1 -1
- data/lib/packetgen.rb +12 -5
- metadata +29 -38
- data/lib/packetgen/types/abstract_tlv.rb +0 -278
- data/lib/packetgen/types/array.rb +0 -287
- data/lib/packetgen/types/cstring.rb +0 -109
- data/lib/packetgen/types/enum.rb +0 -171
- data/lib/packetgen/types/fieldable.rb +0 -66
- data/lib/packetgen/types/fields.rb +0 -622
- data/lib/packetgen/types/int.rb +0 -473
- data/lib/packetgen/types/int_string.rb +0 -102
- data/lib/packetgen/types/length_from.rb +0 -54
- data/lib/packetgen/types/oui.rb +0 -52
- data/lib/packetgen/types/string.rb +0 -97
- data/lib/packetgen/types/tlv.rb +0 -161
- data/lib/packetgen/types.rb +0 -26
@@ -23,22 +23,22 @@ module PacketGen
|
|
23
23
|
# | ... |
|
24
24
|
#
|
25
25
|
# This paylod is implemented with two fields:
|
26
|
-
# * {#lsas_count}, a
|
26
|
+
# * {#lsas_count}, a +BinStruct::Int32+ field,
|
27
27
|
# * and {#lsas}, an {ArrayOfLSA} object.
|
28
28
|
#
|
29
|
-
#
|
29
|
+
# @example Create a LSUpdate payload
|
30
30
|
# # standalone
|
31
31
|
# lsu = PacketGen::Header::OSPFv3::LSUpdate.new
|
32
32
|
# # in a packet
|
33
|
-
# pkt = PacketGen.gen('IPv6'
|
33
|
+
# pkt = PacketGen.gen('IPv6').add('OSPFv3').add('OSPFv3::LSUpdate')
|
34
34
|
# # make IPv6 header correct for OSPF
|
35
35
|
# pkt.ospfize
|
36
36
|
# # access to LSUpdate payload
|
37
|
-
# lsu = pkt.ospfv3_lsupdate # => PacketGen::Header::OSPFv3::LSUpdate
|
37
|
+
# lsu = pkt.ospfv3_lsupdate.class # => PacketGen::Header::OSPFv3::LSUpdate
|
38
38
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
39
|
+
# @example Add LSAs to a LSUpdate payload
|
40
|
+
# lsu = PacketGen::Header::OSPFv3::LSUpdate.new
|
41
|
+
# # Adding LSAs with #<< automagically update #lsas_count. To not update it, use #push.
|
42
42
|
# lsu.lsas << { type: 'Router', age: 40, link_state_id: '0.0.0.1', advertising_router: '1.1.1.1', sequence_number: 42 }
|
43
43
|
# lsu.lsas_count #=> 1
|
44
44
|
# # add a link to Router LSA
|
@@ -48,12 +48,12 @@ module PacketGen
|
|
48
48
|
# @!attribute lsas_count
|
49
49
|
# Count of LSAs included in this update
|
50
50
|
# @return [Integer]
|
51
|
-
|
51
|
+
define_attr :lsas_count, BinStruct::Int32
|
52
52
|
# @!attribute lsas
|
53
53
|
# Array of {LSA LSAs}
|
54
54
|
# @return [ArrayOfLSA]
|
55
|
-
|
56
|
-
|
55
|
+
define_attr :lsas, ArrayOfLSA,
|
56
|
+
builder: ->(h, t) { t.new(counter: h[:lsas_count]) }
|
57
57
|
|
58
58
|
# Calculate checksums of all LSAs
|
59
59
|
# @return [void]
|
@@ -11,28 +11,37 @@ module PacketGen
|
|
11
11
|
class OSPFv3
|
12
12
|
# This class handles links in a {LSARouter OSPFv3 LSA router payload}.
|
13
13
|
# @author Sylvain Daubert
|
14
|
-
class Link <
|
15
|
-
include
|
14
|
+
class Link < BinStruct::Struct
|
15
|
+
include BinStruct::Structable
|
16
16
|
|
17
17
|
# @!attribute type
|
18
|
+
# Kind of interface being described. One of the following:
|
19
|
+
# * 1: Point-to-point connection to another router
|
20
|
+
# * 2: Connection to a transit network
|
21
|
+
# * 4: Virtual link
|
18
22
|
# @return [Integer]
|
19
|
-
|
23
|
+
define_attr :type, BinStruct::Int8
|
20
24
|
# @!attribute reserved
|
21
25
|
# @return [Integer]
|
22
|
-
|
26
|
+
define_attr :reserved, BinStruct::Int8, default: 0
|
23
27
|
# @!attribute metric
|
28
|
+
# Cost of using this router interface.
|
24
29
|
# @return [Integer]
|
25
|
-
|
30
|
+
define_attr :metric, BinStruct::Int16
|
26
31
|
# @!attribute interface_id
|
32
|
+
# ID for the interface being described.
|
27
33
|
# @return [Integer]
|
28
|
-
|
34
|
+
define_attr :interface_id, BinStruct::Int32
|
29
35
|
# @!attribute neighbor_interface_id
|
36
|
+
# Interface ID the neighbor router has associated with this link.
|
30
37
|
# @return [Integer]
|
31
|
-
|
38
|
+
define_attr :neighbor_interface_id, BinStruct::Int32
|
32
39
|
# @!attribute neighbor_router_id
|
40
|
+
# Router ID of the neighbor router.
|
33
41
|
# @return [String]
|
34
|
-
|
42
|
+
define_attr :neighbor_router_id, IP::Addr
|
35
43
|
|
44
|
+
# Human-readable description
|
36
45
|
# @return [String]
|
37
46
|
def to_human
|
38
47
|
"Link<type:#{type},metric:#{metric},id:#{interface_id}," \
|
@@ -40,10 +49,10 @@ module PacketGen
|
|
40
49
|
end
|
41
50
|
end
|
42
51
|
|
43
|
-
# This class defines a specialized
|
52
|
+
# This class defines a specialized +BinStruct::Array+ to handle series
|
44
53
|
# of {Link Links}.
|
45
54
|
# @author Sylvain Daubert
|
46
|
-
class ArrayOfLink <
|
55
|
+
class ArrayOfLink < BinStruct::Array
|
47
56
|
set_of Link
|
48
57
|
end
|
49
58
|
|
@@ -54,39 +63,41 @@ module PacketGen
|
|
54
63
|
# @!attribute body
|
55
64
|
# LSA body
|
56
65
|
# @return [String]
|
57
|
-
|
58
|
-
|
66
|
+
define_attr :body, BinStruct::String,
|
67
|
+
builder: ->(h, t) { t.new(length_from: -> { h.length - 20 }) }
|
59
68
|
end
|
60
69
|
|
61
70
|
# This class handles OSPFv3 LSA Router payloads.
|
62
71
|
#
|
63
72
|
# A LSA router payload is composed of:
|
64
73
|
# * a header (see methods inherited from {LSAHeader}),
|
65
|
-
# * a 8-bit flag word {#flags} (
|
66
|
-
# * a 24-bit {#options} field (
|
74
|
+
# * a 8-bit flag word {#flags} (+BinStruct::Int8+),
|
75
|
+
# * a 24-bit {#options} field (+BinStruct::Int24+),
|
67
76
|
# * and an array of {#links} ({ArrayOfLink}).
|
68
77
|
# @author Sylvain Daubert
|
69
78
|
class LSARouter < LSAHeader
|
70
79
|
# @attribute flags
|
71
80
|
# 8-bit flag word
|
72
81
|
# @return [Integer]
|
73
|
-
define_field :flags, Types::Int8
|
74
|
-
# @!macro define_ospfv3_options
|
75
|
-
OSPFv3.define_options(self)
|
76
|
-
# @attribute links
|
77
|
-
# @return [ArrayOfLink]
|
78
|
-
define_field :links, ArrayOfLink, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:links) }) }
|
79
|
-
|
80
82
|
# @!attribute nt_flag
|
81
|
-
#
|
83
|
+
# If set, the router is an NSSA border router that is translating NSSA-LSAs into AS-external-LSAs.
|
84
|
+
# @return [Integer]
|
82
85
|
# @!attribute v_flag
|
83
|
-
#
|
86
|
+
# If set, router is an endpoint or one or many fully adjacent virtual links.
|
87
|
+
# @return [Integer]
|
84
88
|
# @!attribute e_flag
|
85
|
-
#
|
89
|
+
# If set, router is an AS boundary router.
|
90
|
+
# @return [Integer]
|
86
91
|
# @!attribute b_flag
|
87
|
-
#
|
88
|
-
|
89
|
-
|
92
|
+
# If set, router is an area border router.
|
93
|
+
# @return [Integer]
|
94
|
+
define_bit_attr :flags, zz: 3, nt_flag: 1, x_flag: 1, v_flag: 1, e_flag: 1, b_flag: 1
|
95
|
+
# @!macro define_ospfv3_options
|
96
|
+
OSPFv3.define_options(self)
|
97
|
+
# @attribute links
|
98
|
+
# Router interfaces, as a list of {Link} objects.
|
99
|
+
# @return [ArrayOfLink]
|
100
|
+
define_attr :links, ArrayOfLink, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:links) }) }
|
90
101
|
end
|
91
102
|
|
92
103
|
# This class handles OSPFv3 LSA Network payloads.
|
@@ -100,20 +111,20 @@ module PacketGen
|
|
100
111
|
class LSANetwork < LSAHeader
|
101
112
|
# @!attribute reserved
|
102
113
|
# @return [Integer]
|
103
|
-
|
114
|
+
define_attr :reserved, BinStruct::Int8
|
104
115
|
# @!macro define_ospfv3_options
|
105
116
|
OSPFv3.define_options(self)
|
106
117
|
# @!attribute routers
|
107
118
|
# List of routers attached to the link.
|
108
119
|
# @return [IP::ArrayOfAddr]
|
109
|
-
|
120
|
+
define_attr :routers, IP::ArrayOfAddr, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:routers) }) }
|
110
121
|
end
|
111
122
|
|
112
123
|
# This class handles OSPFv3 LSA Intra-Area-Prefix payloads.
|
113
124
|
#
|
114
125
|
# An Intra-Area-Prefix payloads is composed of:
|
115
|
-
# * a 16-bit {#prefix_count} field (
|
116
|
-
# * a 16-bit {#ref_ls_type} field (
|
126
|
+
# * a 16-bit {#prefix_count} field (+BinStruct::Int16+),
|
127
|
+
# * a 16-bit {#ref_ls_type} field (+BinStruct::Int16Enum+),
|
117
128
|
# * a 32-bit {#ref_link_state_id} ({IP::Addr}),
|
118
129
|
# * a 32-bit {#ref_advertising_router} ({IP::Addr}),
|
119
130
|
# * and an array of {IPv6Prefix} ({#prefixes}, {ArrayOfIPv6Prefix}). In
|
@@ -123,40 +134,40 @@ module PacketGen
|
|
123
134
|
# @!attribute prefix_count
|
124
135
|
# The number of IPv6 address prefixes contained in the LSA.
|
125
136
|
# @return [Integer]
|
126
|
-
|
137
|
+
define_attr :prefix_count, BinStruct::Int16
|
127
138
|
# @!attribute ref_ls_type
|
128
139
|
# Used to identify the router-LSA or network-LSA with which the IPv6
|
129
140
|
# address prefixes should be associated, in association with
|
130
141
|
# {#ref_link_state_id} and {#ref_advertising_router}.
|
131
142
|
# @return [Integer]
|
132
|
-
|
143
|
+
define_attr :ref_ls_type, BinStruct::Int16Enum, enum: TYPES
|
133
144
|
# @!attribute ref_link_state_id
|
134
145
|
# Used to identify the router-LSA or network-LSA with which the IPv6
|
135
146
|
# address prefixes should be associated, in association with
|
136
147
|
# {#ref_ls_type} and {#ref_advertising_router}.
|
137
148
|
# @return [String]
|
138
|
-
|
149
|
+
define_attr :ref_link_state_id, IP::Addr
|
139
150
|
# @!attribute ref_advertising_router
|
140
151
|
# Used to identify the router-LSA or network-LSA with which the IPv6
|
141
152
|
# address prefixes should be associated, in association with
|
142
153
|
# {#ref_link_state_id} and {#ref_ls_type}.
|
143
154
|
# @return [String]
|
144
|
-
|
155
|
+
define_attr :ref_advertising_router, IP::Addr
|
145
156
|
# @!attribute prefixes
|
146
157
|
# Array of {IPv6Prefix}. Note for this LSA, {IPv6Prefix#reserved} is
|
147
158
|
# used as +metric+ value.
|
148
159
|
# @return [ArrayOfIPv6Prefix]
|
149
|
-
|
150
|
-
|
160
|
+
define_attr :prefixes, ArrayOfIPv6Prefix,
|
161
|
+
builder: ->(h, t) { t.new(counter: h[:prefix_count]) }
|
151
162
|
end
|
152
163
|
|
153
164
|
# This class handles OSPFv3 LSA Link payloads.
|
154
165
|
#
|
155
166
|
# A Link payloads is composed of:
|
156
|
-
# * a 8-bit {#router_priority} field (
|
157
|
-
# * a 24-bit {#options} field (
|
167
|
+
# * a 8-bit {#router_priority} field (+BinStruct::Int8+),
|
168
|
+
# * a 24-bit {#options} field (+BinStruct::Int24+),
|
158
169
|
# * a 128-bit IPv6 {#interface_addr} ({IPv6::Addr}),
|
159
|
-
# * a 32-bit {#prefix_count} field (
|
170
|
+
# * a 32-bit {#prefix_count} field (+BinStruct::Int32+),
|
160
171
|
# * and an array of {IPv6Prefix} ({#prefixes}, {ArrayOfIPv6Prefix}).
|
161
172
|
# @author Sylvain Daubert
|
162
173
|
class LSALink < LSAHeader
|
@@ -164,33 +175,33 @@ module PacketGen
|
|
164
175
|
# The Router Priority of the interface attaching the originating
|
165
176
|
# router to the link.
|
166
177
|
# @return [Integer]
|
167
|
-
|
178
|
+
define_attr :router_priority, BinStruct::Int8
|
168
179
|
# @!macro define_ospfv3_options
|
169
180
|
OSPFv3.define_options(self)
|
170
181
|
# @!attribute interface_addr
|
171
182
|
# The originating router's link-local interface address on the link.
|
172
183
|
# @return [String]
|
173
|
-
|
184
|
+
define_attr :interface_addr, IPv6::Addr
|
174
185
|
# @!attribute prefix_count
|
175
186
|
# The number of IPv6 address prefixes contained in the LSA.
|
176
187
|
# @return [Integer]
|
177
|
-
|
188
|
+
define_attr :prefix_count, BinStruct::Int32
|
178
189
|
# @!attribute prefixes
|
179
190
|
# List of IPv6 prefixes to be associated with the link.
|
180
191
|
# @return [ArrayOfIPv6Prefix]
|
181
|
-
|
192
|
+
define_attr :prefixes, ArrayOfIPv6Prefix, builder: ->(h, t) { t.new(counter: h[:prefix_count]) }
|
182
193
|
end
|
183
194
|
|
184
|
-
# This class defines a specialized
|
195
|
+
# This class defines a specialized +BinStruct::Array+ to handle series
|
185
196
|
# of {LSA LSAs} or {LSAHeader LSAHeaders}. It recognizes known LSA types
|
186
197
|
# and infers correct type.
|
187
198
|
# @author Sylvain Daubert
|
188
|
-
class ArrayOfLSA <
|
199
|
+
class ArrayOfLSA < BinStruct::Array
|
189
200
|
set_of LSAHeader
|
190
201
|
|
191
202
|
# @param [Hash] options
|
192
|
-
# @option options [
|
193
|
-
# @option options [
|
203
|
+
# @option options [BinStruct::Int] counter Int object used as a counter for this set
|
204
|
+
# @option options [Integer] only_headers if +true+, only {LSAHeader LSAHeaders}
|
194
205
|
# will be added to this array.
|
195
206
|
def initialize(options={})
|
196
207
|
super
|
@@ -200,7 +211,7 @@ module PacketGen
|
|
200
211
|
private
|
201
212
|
|
202
213
|
def record_from_hash(hsh)
|
203
|
-
raise ArgumentError, 'hash should have :type key' unless hsh.key?
|
214
|
+
raise ArgumentError, 'hash should have :type key' unless hsh.key?(:type)
|
204
215
|
|
205
216
|
klass = if @only_headers
|
206
217
|
LSAHeader
|
@@ -220,8 +231,8 @@ module PacketGen
|
|
220
231
|
def get_lsa_class_by_human_type(htype)
|
221
232
|
klassname = "LSA#{htype.to_s.delete('-')}"
|
222
233
|
begin
|
223
|
-
if OSPFv3.const_defined?
|
224
|
-
OSPFv3.const_get
|
234
|
+
if OSPFv3.const_defined?(klassname)
|
235
|
+
OSPFv3.const_get(klassname)
|
225
236
|
else
|
226
237
|
LSA
|
227
238
|
end
|
@@ -29,8 +29,8 @@ module PacketGen
|
|
29
29
|
# LSA headers are used as-is in {DbDescription} and {LSAck} payloads.
|
30
30
|
# But this class is also a base class for different LSA class, as {LSARouter}.
|
31
31
|
# @author Sylvain Daubert
|
32
|
-
class LSAHeader <
|
33
|
-
include
|
32
|
+
class LSAHeader < BinStruct::Struct
|
33
|
+
include BinStruct::Structable
|
34
34
|
|
35
35
|
# LSA known types
|
36
36
|
TYPES = {
|
@@ -47,36 +47,36 @@ module PacketGen
|
|
47
47
|
# @!attribute age
|
48
48
|
# The time in seconds since the LSA was originated.
|
49
49
|
# @return [Integer]
|
50
|
-
|
50
|
+
define_attr :age, BinStruct::Int16
|
51
51
|
# @!attribute type
|
52
52
|
# The type of the LSA.
|
53
53
|
# @return [Integer]
|
54
|
-
|
54
|
+
define_attr :type, BinStruct::Int16Enum, enum: TYPES
|
55
55
|
# @!attribute link_state_id
|
56
56
|
# This field identifies the portion of the internet environment
|
57
57
|
# that is being described by the LSA.
|
58
58
|
# @return [String]
|
59
|
-
|
59
|
+
define_attr :link_state_id, IP::Addr
|
60
60
|
# @!attribute advertising_router
|
61
61
|
# The Router ID of the router that originated the LSA.
|
62
62
|
# @return [String]
|
63
|
-
|
63
|
+
define_attr :advertising_router, IP::Addr
|
64
64
|
# @!attribute sequence_number
|
65
65
|
# @return [Integer]
|
66
|
-
|
66
|
+
define_attr :sequence_number, BinStruct::Int32
|
67
67
|
alias seqnum sequence_number
|
68
68
|
alias seqnum= sequence_number=
|
69
69
|
# @!attribute checksum
|
70
70
|
# The Fletcher checksum of the complete contents of the LSA,
|
71
71
|
# including the LSA header but excluding the LS age field.
|
72
72
|
# @return [Integer]
|
73
|
-
|
73
|
+
define_attr :checksum, BinStruct::Int16
|
74
74
|
# @!attribute length
|
75
75
|
# Length of the LSA, including the header.
|
76
76
|
# @return [Integer]
|
77
|
-
|
77
|
+
define_attr :length, BinStruct::Int16
|
78
78
|
|
79
|
-
# Compute and set Fletcher-16 checksum on LSA
|
79
|
+
# Compute and set Fletcher-16 {#checksum} on LSA
|
80
80
|
# @return [Integer]
|
81
81
|
def calc_checksum
|
82
82
|
c0 = c1 = 0
|
@@ -94,7 +94,7 @@ module PacketGen
|
|
94
94
|
self.checksum = (x << 8) | y
|
95
95
|
end
|
96
96
|
|
97
|
-
# Compute length and set
|
97
|
+
# Compute length and set {#length} field
|
98
98
|
# @return [Integer]
|
99
99
|
def calc_length
|
100
100
|
self.length = Base.calculate_and_set_length(self)
|
@@ -106,6 +106,7 @@ module PacketGen
|
|
106
106
|
self[:type].to_human
|
107
107
|
end
|
108
108
|
|
109
|
+
# Get human-readable description
|
109
110
|
# @return [String]
|
110
111
|
def to_human
|
111
112
|
"LSA<#{human_type},#{link_state_id},#{advertising_router}>"
|
@@ -24,45 +24,47 @@ module PacketGen
|
|
24
24
|
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
25
25
|
#
|
26
26
|
# An OSPFv3 header consists of:
|
27
|
-
# * a {#version} field (
|
28
|
-
# * a {#type} field (
|
29
|
-
# * a {#length} field (
|
30
|
-
# * a {#router_id} field (
|
31
|
-
# * an {#area_id} field (
|
32
|
-
# * a {#checksum} field (
|
33
|
-
# * an {#instance_id} field (
|
34
|
-
# * a {#reserved} field (
|
35
|
-
# * and a {#body} (
|
27
|
+
# * a {#version} field (+BinStruct::Int8+),
|
28
|
+
# * a {#type} field (+BinStruct::Int8Enum+),
|
29
|
+
# * a {#length} field (+BinStruct::Int16+). The length includes the header,
|
30
|
+
# * a {#router_id} field (+BinStruct::Int32+),
|
31
|
+
# * an {#area_id} field (+BinStruct::Int32+),
|
32
|
+
# * a {#checksum} field (+BinStruct::Int16+),
|
33
|
+
# * an {#instance_id} field (+BinStruct::Int8+),
|
34
|
+
# * a {#reserved} field (+BinStruct::Int8+),
|
35
|
+
# * and a {#body} (+BinStruct::String+ or {Headerable}).
|
36
36
|
#
|
37
|
-
# ==
|
37
|
+
# == OSPFv3 body
|
38
|
+
# OSPFv3 {#body} should contain OSPF payload for given {#type}:
|
39
|
+
# * {OSPFv3::Hello},
|
40
|
+
# * {OSPFv3::DbDescription},
|
41
|
+
# * {OSPFv3::LSRequest},
|
42
|
+
# * {OSPFv3::LSUpdate},
|
43
|
+
# * or {OSPFv3::LSAck}.
|
44
|
+
#
|
45
|
+
# @example Create an OSPFv3 header
|
38
46
|
# # standalone
|
39
47
|
# ospf = PacketGen::Header::OSPFv3.new
|
40
48
|
# # in a packet
|
41
|
-
# pkt = PacketGen.gen('IPv6'
|
49
|
+
# pkt = PacketGen.gen('IPv6').add('OSPFv3')
|
42
50
|
# # make IPv6 header correct for OSPF
|
43
51
|
# pkt.ospfize
|
44
52
|
# # or make it correct with specific destination address
|
45
53
|
# pkt.ospfize(dst: :all_spf_routers)
|
46
54
|
# # access to OSPF header
|
47
|
-
# pkt.ospfv3 # => PacketGen::Header::OSPFv3
|
48
|
-
#
|
49
|
-
# == OSPFv3 attributes
|
50
|
-
# ospf.version # => 3
|
51
|
-
# ospf.type = 'LS_ACK' # or 5
|
52
|
-
# ospf.length = 154
|
53
|
-
# ospf.router_id = 0xc0a80001
|
54
|
-
# ospf.area_id = 1
|
55
|
-
# ospf.checksum = 0xabcd
|
56
|
-
# ospf.instance_id = 0
|
55
|
+
# pkt.ospfv3.class # => PacketGen::Header::OSPFv3
|
57
56
|
#
|
58
|
-
#
|
59
|
-
# OSPFv3
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
57
|
+
# @example OSPFv3 attributes
|
58
|
+
# ospf = PacketGen::Header::OSPFv3.new
|
59
|
+
# ospf.version # => 3
|
60
|
+
# ospf.type = 'LS_ACK' # or 5
|
61
|
+
# ospf.length = 154
|
62
|
+
# ospf.router_id = 0xc0a80001
|
63
|
+
# ospf.area_id = 1
|
64
|
+
# ospf.checksum = 0xabcd
|
65
|
+
# ospf.instance_id = 0
|
65
66
|
# @author Sylvain Daubert
|
67
|
+
# @author LemonTree55
|
66
68
|
# @since 2.5.0
|
67
69
|
class OSPFv3 < Base
|
68
70
|
# IP protocol number for OSPF
|
@@ -74,38 +76,39 @@ module PacketGen
|
|
74
76
|
# @!attribute version
|
75
77
|
# 8-bit OSPF version
|
76
78
|
# @return [Integer]
|
77
|
-
|
79
|
+
define_attr :version, BinStruct::Int8, default: 3
|
78
80
|
# @!attribute type
|
79
81
|
# 8-bit OSPF packet type. Types are defined in {TYPES}.
|
80
82
|
# @return [Integer]
|
81
|
-
|
83
|
+
define_attr :type, BinStruct::Int8Enum, enum: TYPES
|
82
84
|
# @!attribute length
|
83
|
-
# 16-bit OSPF packet length
|
85
|
+
# 16-bit OSPF packet length. Header is included in length
|
84
86
|
# @return [Integer]
|
85
|
-
|
87
|
+
define_attr :length, BinStruct::Int16
|
86
88
|
# @!attribute router_id
|
87
89
|
# 32-bit router ID
|
88
90
|
# @return [Integer]
|
89
|
-
|
91
|
+
define_attr :router_id, BinStruct::Int32
|
90
92
|
# @!attribute area_id
|
91
93
|
# 32-bit area ID
|
92
94
|
# @return [Integer]
|
93
|
-
|
95
|
+
define_attr :area_id, BinStruct::Int32
|
94
96
|
# @!attribute checksum
|
95
97
|
# 16-bit OSPF packet checksum
|
96
98
|
# @return [Integer]
|
97
|
-
|
99
|
+
define_attr :checksum, BinStruct::Int16
|
98
100
|
# @!attribute instance_id
|
99
101
|
# 8-bit instance ID.
|
100
102
|
# @return [Integer]
|
101
|
-
|
103
|
+
define_attr :instance_id, BinStruct::Int8
|
102
104
|
# @!attribute reserved
|
103
105
|
# 8-bit reserved field.
|
104
106
|
# @return [Integer]
|
105
|
-
|
107
|
+
define_attr :reserved, BinStruct::Int8, default: 0
|
106
108
|
# @!attribute body
|
107
|
-
#
|
108
|
-
|
109
|
+
# OSPFv3 body
|
110
|
+
# @return [String,Headerable]
|
111
|
+
define_attr :body, BinStruct::String
|
109
112
|
|
110
113
|
# @api private
|
111
114
|
# Helper class method to define an OSPFv3 options field.
|
@@ -118,38 +121,37 @@ module PacketGen
|
|
118
121
|
# @return [Integer]
|
119
122
|
# @!attribute dc_opt
|
120
123
|
# This bit describes the router's handling of demand circuits.
|
121
|
-
# @return [
|
124
|
+
# @return [Integer]
|
122
125
|
# @!attribute r_opt
|
123
126
|
# This bit indicates whether the originator is an active router.
|
124
|
-
# @return [
|
127
|
+
# @return [Integer]
|
125
128
|
# @!attribute n_opt
|
126
129
|
# This bit indicates whether or not the router is attached to an NSSA.
|
127
|
-
# @return [
|
130
|
+
# @return [Integer]
|
128
131
|
# @!attribute x_opt
|
129
132
|
# This bit should be set to 0, and ignored when received.
|
130
|
-
# @return [
|
133
|
+
# @return [Integer]
|
131
134
|
# @!attribute e_opt
|
132
135
|
# This bit describes the way AS-external-LSAs are flooded.
|
133
|
-
# @return [
|
136
|
+
# @return [Integer]
|
134
137
|
# @!attribute v6_opt
|
135
138
|
# If this bit is clear, the router/link should be excluded from IPv6
|
136
139
|
# routing calculations.
|
137
|
-
# @return [
|
140
|
+
# @return [Integer]
|
138
141
|
def self.define_options(hdr)
|
139
|
-
hdr.
|
140
|
-
hdr.define_bit_fields_on :options, :z, 18, :dc_opt, :r_opt,
|
141
|
-
:n_opt, :x_opt, :e_opt, :v6_opt
|
142
|
+
hdr.define_bit_attr :options, z: 18, dc_opt: 1, r_opt: 1, n_opt: 1, x_opt: 1, e_opt: 1, v6_opt: 1
|
142
143
|
end
|
143
144
|
|
144
145
|
# @api private
|
145
146
|
# @note This method is used internally by PacketGen and should not be
|
146
147
|
# directly called
|
148
|
+
# Add +#ospfize+ method to +packet+. This method calls {#ospfize}.
|
147
149
|
def added_to_packet(packet)
|
148
150
|
ospf_idx = packet.headers.size
|
149
151
|
packet.instance_eval "def ospfize(**kwargs) @headers[#{ospf_idx}].ospfize(**kwargs); end" # def ospfize(**kwargs) @headers[2].ospfize(**kwargs); end
|
150
152
|
end
|
151
153
|
|
152
|
-
# Compute checksum and set
|
154
|
+
# Compute checksum and set {#checksum} attribute
|
153
155
|
# @return [Integer]
|
154
156
|
def calc_checksum
|
155
157
|
ipv6 = ip_header(self)
|
@@ -166,7 +168,7 @@ module PacketGen
|
|
166
168
|
self[:type].to_human
|
167
169
|
end
|
168
170
|
|
169
|
-
# Compute length and set
|
171
|
+
# Compute length and set {#length} attribute
|
170
172
|
# @return [Integer]
|
171
173
|
def calc_length
|
172
174
|
self[:length].value = Base.calculate_and_set_length(self)
|
@@ -181,8 +183,8 @@ module PacketGen
|
|
181
183
|
# pkt.ospfv3.ospfize
|
182
184
|
# # second way
|
183
185
|
# pkt.ospfize
|
184
|
-
# @param [String,Symbol,nil] dst destination address. May be a
|
185
|
-
# address (by example
|
186
|
+
# @param [String,Symbol,nil] dst destination address. May be a coloned IP
|
187
|
+
# address (by example +1::1234:5+) or a Symbol (+:all_spf_routers+ or
|
186
188
|
# +:all_d_routers+)
|
187
189
|
# @return [void]
|
188
190
|
def ospfize(dst: nil)
|