packetgen 3.3.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -21
- data/lib/packetgen/capture.rb +2 -2
- data/lib/packetgen/config.rb +0 -1
- data/lib/packetgen/deprecation.rb +7 -7
- data/lib/packetgen/header/arp.rb +13 -13
- data/lib/packetgen/header/asn1_base.rb +1 -1
- data/lib/packetgen/header/base.rb +17 -18
- data/lib/packetgen/header/bootp.rb +32 -34
- data/lib/packetgen/header/dhcp/option.rb +19 -19
- data/lib/packetgen/header/dhcp/options.rb +1 -1
- data/lib/packetgen/header/dhcp.rb +3 -3
- data/lib/packetgen/header/dhcpv6/duid.rb +16 -16
- data/lib/packetgen/header/dhcpv6/option.rb +53 -53
- data/lib/packetgen/header/dhcpv6/options.rb +1 -1
- data/lib/packetgen/header/dhcpv6/relay.rb +5 -5
- data/lib/packetgen/header/dhcpv6.rb +6 -6
- data/lib/packetgen/header/dns/name.rb +14 -10
- data/lib/packetgen/header/dns/opt.rb +2 -2
- data/lib/packetgen/header/dns/option.rb +11 -11
- data/lib/packetgen/header/dns/qdsection.rb +1 -1
- data/lib/packetgen/header/dns/question.rb +6 -8
- data/lib/packetgen/header/dns/rr.rb +56 -43
- data/lib/packetgen/header/dns/rrsection.rb +4 -4
- data/lib/packetgen/header/dns.rb +27 -30
- data/lib/packetgen/header/dot11/control.rb +11 -11
- data/lib/packetgen/header/dot11/data.rb +20 -20
- data/lib/packetgen/header/dot11/element.rb +4 -4
- data/lib/packetgen/header/dot11/management.rb +8 -8
- data/lib/packetgen/header/dot11/sub_mngt.rb +39 -53
- data/lib/packetgen/header/dot11.rb +88 -93
- data/lib/packetgen/header/dot1q.rb +10 -12
- data/lib/packetgen/header/dot1x.rb +9 -9
- data/lib/packetgen/header/eap/fast.rb +4 -4
- data/lib/packetgen/header/eap/md5.rb +6 -6
- data/lib/packetgen/header/eap/tls.rb +13 -15
- data/lib/packetgen/header/eap/ttls.rb +13 -15
- data/lib/packetgen/header/eap.rb +22 -22
- data/lib/packetgen/header/eth.rb +18 -18
- data/lib/packetgen/header/gre.rb +8 -10
- data/lib/packetgen/header/http/headers.rb +2 -2
- data/lib/packetgen/header/http/request.rb +17 -16
- data/lib/packetgen/header/http/response.rb +18 -17
- data/lib/packetgen/header/http/verbs.rb +1 -3
- data/lib/packetgen/header/icmp.rb +8 -8
- data/lib/packetgen/header/icmpv6.rb +3 -3
- data/lib/packetgen/header/igmp.rb +8 -8
- data/lib/packetgen/header/igmpv3/group_record.rb +12 -12
- data/lib/packetgen/header/igmpv3/mq.rb +16 -18
- data/lib/packetgen/header/igmpv3/mr.rb +4 -4
- data/lib/packetgen/header/igmpv3.rb +7 -7
- data/lib/packetgen/header/ip/addr.rb +13 -13
- data/lib/packetgen/header/ip/option.rb +31 -33
- data/lib/packetgen/header/ip/options.rb +1 -1
- data/lib/packetgen/header/ip.rb +37 -72
- data/lib/packetgen/header/ipv6/addr.rb +14 -14
- data/lib/packetgen/header/ipv6/extension.rb +8 -8
- data/lib/packetgen/header/ipv6/hop_by_hop.rb +9 -9
- data/lib/packetgen/header/ipv6.rb +20 -22
- data/lib/packetgen/header/llc.rb +17 -17
- data/lib/packetgen/header/mdns.rb +1 -1
- data/lib/packetgen/header/mld.rb +6 -6
- data/lib/packetgen/header/mldv2/mcast_address_record.rb +11 -11
- data/lib/packetgen/header/mldv2/mlq.rb +21 -23
- data/lib/packetgen/header/mldv2/mlr.rb +8 -8
- data/lib/packetgen/header/ospfv2/db_description.rb +11 -12
- data/lib/packetgen/header/ospfv2/hello.rb +11 -11
- data/lib/packetgen/header/ospfv2/ls_ack.rb +1 -1
- data/lib/packetgen/header/ospfv2/ls_request.rb +9 -9
- data/lib/packetgen/header/ospfv2/ls_update.rb +3 -3
- data/lib/packetgen/header/ospfv2/lsa.rb +54 -58
- data/lib/packetgen/header/ospfv2/lsa_header.rb +9 -9
- data/lib/packetgen/header/ospfv2.rb +27 -29
- data/lib/packetgen/header/ospfv3/db_description.rb +13 -14
- data/lib/packetgen/header/ospfv3/hello.rb +12 -12
- data/lib/packetgen/header/ospfv3/ipv6_prefix.rb +17 -19
- data/lib/packetgen/header/ospfv3/ls_ack.rb +2 -2
- data/lib/packetgen/header/ospfv3/ls_request.rb +9 -9
- data/lib/packetgen/header/ospfv3/ls_update.rb +4 -4
- data/lib/packetgen/header/ospfv3/lsa.rb +48 -51
- data/lib/packetgen/header/ospfv3/lsa_header.rb +9 -9
- data/lib/packetgen/header/ospfv3.rb +25 -27
- data/lib/packetgen/header/sctp/chunk.rb +44 -41
- data/lib/packetgen/header/sctp/error.rb +52 -52
- data/lib/packetgen/header/sctp/parameter.rb +38 -38
- data/lib/packetgen/header/sctp.rb +5 -5
- data/lib/packetgen/header/snmp.rb +2 -2
- data/lib/packetgen/header/tcp/option.rb +45 -39
- data/lib/packetgen/header/tcp/options.rb +2 -2
- data/lib/packetgen/header/tcp.rb +55 -44
- data/lib/packetgen/header/tftp.rb +16 -16
- data/lib/packetgen/header/udp.rb +8 -8
- data/lib/packetgen/header.rb +9 -10
- data/lib/packetgen/headerable.rb +13 -3
- data/lib/packetgen/inspect.rb +2 -2
- data/lib/packetgen/packet.rb +54 -37
- data/lib/packetgen/pcap.rb +15 -4
- data/lib/packetgen/pcapng/block.rb +18 -17
- data/lib/packetgen/pcapng/epb.rb +13 -15
- data/lib/packetgen/pcapng/file.rb +3 -97
- data/lib/packetgen/pcapng/idb.rb +9 -11
- data/lib/packetgen/pcapng/shb.rb +13 -15
- data/lib/packetgen/pcapng/spb.rb +8 -10
- data/lib/packetgen/pcapng/unknown_block.rb +6 -17
- data/lib/packetgen/pcapng.rb +4 -4
- data/lib/packetgen/pcaprub_wrapper.rb +17 -1
- data/lib/packetgen/proto.rb +1 -1
- data/lib/packetgen/unknown_packet.rb +2 -2
- data/lib/packetgen/utils/arp_spoofer.rb +18 -19
- data/lib/packetgen/utils.rb +2 -2
- data/lib/packetgen/version.rb +1 -1
- data/lib/packetgen.rb +4 -3
- metadata +34 -29
- 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
@@ -27,26 +27,26 @@ module PacketGen
|
|
27
27
|
# * a 32-bit {#link_state_id} field,
|
28
28
|
# * and a 32-bit {#advertising_router} field.
|
29
29
|
# @author Sylvain Daubert
|
30
|
-
class LSR <
|
31
|
-
include
|
30
|
+
class LSR < BinStruct::Struct
|
31
|
+
include BinStruct::Structable
|
32
32
|
|
33
33
|
# @!attribute reserved
|
34
34
|
# reserved field.
|
35
35
|
# @return [Integer]
|
36
|
-
|
36
|
+
define_attr :reserved, BinStruct::Int16, default: 0
|
37
37
|
# @!attribute type
|
38
38
|
# The type of the LSA to request.
|
39
39
|
# @return [Integer]
|
40
|
-
|
40
|
+
define_attr :type, BinStruct::Int16Enum, enum: LSAHeader::TYPES
|
41
41
|
# @!attribute link_state_id
|
42
42
|
# This field identifies the portion of the internet environment
|
43
43
|
# that is being described by the LSA to request.
|
44
44
|
# @return [String]
|
45
|
-
|
45
|
+
define_attr :link_state_id, IP::Addr
|
46
46
|
# @!attribute advertising_router
|
47
47
|
# The Router ID of the requested LSA.
|
48
48
|
# @return [String]
|
49
|
-
|
49
|
+
define_attr :advertising_router, IP::Addr
|
50
50
|
|
51
51
|
# Get human-readable type
|
52
52
|
# @return [String]
|
@@ -60,10 +60,10 @@ module PacketGen
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
# This class defines a specialized {
|
63
|
+
# This class defines a specialized {BinStruct::Array array} to handle series
|
64
64
|
# of {LSR LSRs}.
|
65
65
|
# @author Sylvain Daubert
|
66
|
-
class ArrayOfLSR <
|
66
|
+
class ArrayOfLSR < BinStruct::Array
|
67
67
|
set_of LSR
|
68
68
|
end
|
69
69
|
|
@@ -100,7 +100,7 @@ module PacketGen
|
|
100
100
|
# @!attribute lsrs
|
101
101
|
# Array of {LSR}
|
102
102
|
# @return [ArrayOfLSR]
|
103
|
-
|
103
|
+
define_attr :lsrs, ArrayOfLSR
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
@@ -23,7 +23,7 @@ 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
|
# == Create a LSUpdate payload
|
@@ -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,27 +11,27 @@ 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
18
|
# @return [Integer]
|
19
|
-
|
19
|
+
define_attr :type, BinStruct::Int8
|
20
20
|
# @!attribute reserved
|
21
21
|
# @return [Integer]
|
22
|
-
|
22
|
+
define_attr :reserved, BinStruct::Int8, default: 0
|
23
23
|
# @!attribute metric
|
24
24
|
# @return [Integer]
|
25
|
-
|
25
|
+
define_attr :metric, BinStruct::Int16
|
26
26
|
# @!attribute interface_id
|
27
27
|
# @return [Integer]
|
28
|
-
|
28
|
+
define_attr :interface_id, BinStruct::Int32
|
29
29
|
# @!attribute neighbor_interface_id
|
30
30
|
# @return [Integer]
|
31
|
-
|
31
|
+
define_attr :neighbor_interface_id, BinStruct::Int32
|
32
32
|
# @!attribute neighbor_router_id
|
33
33
|
# @return [String]
|
34
|
-
|
34
|
+
define_attr :neighbor_router_id, IP::Addr
|
35
35
|
|
36
36
|
# @return [String]
|
37
37
|
def to_human
|
@@ -40,10 +40,10 @@ module PacketGen
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
# This class defines a specialized {
|
43
|
+
# This class defines a specialized {BinStruct::Array array} to handle series
|
44
44
|
# of {Link Links}.
|
45
45
|
# @author Sylvain Daubert
|
46
|
-
class ArrayOfLink <
|
46
|
+
class ArrayOfLink < BinStruct::Array
|
47
47
|
set_of Link
|
48
48
|
end
|
49
49
|
|
@@ -54,39 +54,36 @@ module PacketGen
|
|
54
54
|
# @!attribute body
|
55
55
|
# LSA body
|
56
56
|
# @return [String]
|
57
|
-
|
58
|
-
|
57
|
+
define_attr :body, BinStruct::String,
|
58
|
+
builder: ->(h, t) { t.new(length_from: -> { h.length - 20 }) }
|
59
59
|
end
|
60
60
|
|
61
61
|
# This class handles OSPFv3 LSA Router payloads.
|
62
62
|
#
|
63
63
|
# A LSA router payload is composed of:
|
64
64
|
# * a header (see methods inherited from {LSAHeader}),
|
65
|
-
# * a 8-bit flag word {#flags} ({
|
66
|
-
# * a 24-bit {#options} field ({
|
65
|
+
# * a 8-bit flag word {#flags} ({BinStruct::Int8}),
|
66
|
+
# * a 24-bit {#options} field ({BinStruct::Int24}),
|
67
67
|
# * and an array of {#links} ({ArrayOfLink}).
|
68
68
|
# @author Sylvain Daubert
|
69
69
|
class LSARouter < LSAHeader
|
70
70
|
# @attribute flags
|
71
71
|
# 8-bit flag word
|
72
72
|
# @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
73
|
# @!attribute nt_flag
|
81
|
-
# @return [
|
74
|
+
# @return [Integer]
|
82
75
|
# @!attribute v_flag
|
83
|
-
# @return [
|
76
|
+
# @return [Integer]
|
84
77
|
# @!attribute e_flag
|
85
|
-
# @return [
|
78
|
+
# @return [Integer]
|
86
79
|
# @!attribute b_flag
|
87
|
-
# @return [
|
88
|
-
|
89
|
-
|
80
|
+
# @return [Integer]
|
81
|
+
define_bit_attr :flags, zz: 3, nt_flag: 1, x_flag: 1, v_flag: 1, e_flag: 1, b_flag: 1
|
82
|
+
# @!macro define_ospfv3_options
|
83
|
+
OSPFv3.define_options(self)
|
84
|
+
# @attribute links
|
85
|
+
# @return [ArrayOfLink]
|
86
|
+
define_attr :links, ArrayOfLink, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:links) }) }
|
90
87
|
end
|
91
88
|
|
92
89
|
# This class handles OSPFv3 LSA Network payloads.
|
@@ -100,20 +97,20 @@ module PacketGen
|
|
100
97
|
class LSANetwork < LSAHeader
|
101
98
|
# @!attribute reserved
|
102
99
|
# @return [Integer]
|
103
|
-
|
100
|
+
define_attr :reserved, BinStruct::Int8
|
104
101
|
# @!macro define_ospfv3_options
|
105
102
|
OSPFv3.define_options(self)
|
106
103
|
# @!attribute routers
|
107
104
|
# List of routers attached to the link.
|
108
105
|
# @return [IP::ArrayOfAddr]
|
109
|
-
|
106
|
+
define_attr :routers, IP::ArrayOfAddr, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:routers) }) }
|
110
107
|
end
|
111
108
|
|
112
109
|
# This class handles OSPFv3 LSA Intra-Area-Prefix payloads.
|
113
110
|
#
|
114
111
|
# An Intra-Area-Prefix payloads is composed of:
|
115
|
-
# * a 16-bit {#prefix_count} field ({
|
116
|
-
# * a 16-bit {#ref_ls_type} field ({
|
112
|
+
# * a 16-bit {#prefix_count} field ({BinStruct::Int16}),
|
113
|
+
# * a 16-bit {#ref_ls_type} field ({BinStruct::Int16Enum}),
|
117
114
|
# * a 32-bit {#ref_link_state_id} ({IP::Addr}),
|
118
115
|
# * a 32-bit {#ref_advertising_router} ({IP::Addr}),
|
119
116
|
# * and an array of {IPv6Prefix} ({#prefixes}, {ArrayOfIPv6Prefix}). In
|
@@ -123,40 +120,40 @@ module PacketGen
|
|
123
120
|
# @!attribute prefix_count
|
124
121
|
# The number of IPv6 address prefixes contained in the LSA.
|
125
122
|
# @return [Integer]
|
126
|
-
|
123
|
+
define_attr :prefix_count, BinStruct::Int16
|
127
124
|
# @!attribute ref_ls_type
|
128
125
|
# Used to identify the router-LSA or network-LSA with which the IPv6
|
129
126
|
# address prefixes should be associated, in association with
|
130
127
|
# {#ref_link_state_id} and {#ref_advertising_router}.
|
131
128
|
# @return [Integer]
|
132
|
-
|
129
|
+
define_attr :ref_ls_type, BinStruct::Int16Enum, enum: TYPES
|
133
130
|
# @!attribute ref_link_state_id
|
134
131
|
# Used to identify the router-LSA or network-LSA with which the IPv6
|
135
132
|
# address prefixes should be associated, in association with
|
136
133
|
# {#ref_ls_type} and {#ref_advertising_router}.
|
137
134
|
# @return [String]
|
138
|
-
|
135
|
+
define_attr :ref_link_state_id, IP::Addr
|
139
136
|
# @!attribute ref_advertising_router
|
140
137
|
# Used to identify the router-LSA or network-LSA with which the IPv6
|
141
138
|
# address prefixes should be associated, in association with
|
142
139
|
# {#ref_link_state_id} and {#ref_ls_type}.
|
143
140
|
# @return [String]
|
144
|
-
|
141
|
+
define_attr :ref_advertising_router, IP::Addr
|
145
142
|
# @!attribute prefixes
|
146
143
|
# Array of {IPv6Prefix}. Note for this LSA, {IPv6Prefix#reserved} is
|
147
144
|
# used as +metric+ value.
|
148
145
|
# @return [ArrayOfIPv6Prefix]
|
149
|
-
|
150
|
-
|
146
|
+
define_attr :prefixes, ArrayOfIPv6Prefix,
|
147
|
+
builder: ->(h, t) { t.new(counter: h[:prefix_count]) }
|
151
148
|
end
|
152
149
|
|
153
150
|
# This class handles OSPFv3 LSA Link payloads.
|
154
151
|
#
|
155
152
|
# A Link payloads is composed of:
|
156
|
-
# * a 8-bit {#router_priority} field ({
|
157
|
-
# * a 24-bit {#options} field ({
|
153
|
+
# * a 8-bit {#router_priority} field ({BinStruct::Int8}),
|
154
|
+
# * a 24-bit {#options} field ({BinStruct::Int24}),
|
158
155
|
# * a 128-bit IPv6 {#interface_addr} ({IPv6::Addr}),
|
159
|
-
# * a 32-bit {#prefix_count} field ({
|
156
|
+
# * a 32-bit {#prefix_count} field ({BinStruct::Int32}),
|
160
157
|
# * and an array of {IPv6Prefix} ({#prefixes}, {ArrayOfIPv6Prefix}).
|
161
158
|
# @author Sylvain Daubert
|
162
159
|
class LSALink < LSAHeader
|
@@ -164,33 +161,33 @@ module PacketGen
|
|
164
161
|
# The Router Priority of the interface attaching the originating
|
165
162
|
# router to the link.
|
166
163
|
# @return [Integer]
|
167
|
-
|
164
|
+
define_attr :router_priority, BinStruct::Int8
|
168
165
|
# @!macro define_ospfv3_options
|
169
166
|
OSPFv3.define_options(self)
|
170
167
|
# @!attribute interface_addr
|
171
168
|
# The originating router's link-local interface address on the link.
|
172
169
|
# @return [String]
|
173
|
-
|
170
|
+
define_attr :interface_addr, IPv6::Addr
|
174
171
|
# @!attribute prefix_count
|
175
172
|
# The number of IPv6 address prefixes contained in the LSA.
|
176
173
|
# @return [Integer]
|
177
|
-
|
174
|
+
define_attr :prefix_count, BinStruct::Int32
|
178
175
|
# @!attribute prefixes
|
179
176
|
# List of IPv6 prefixes to be associated with the link.
|
180
177
|
# @return [ArrayOfIPv6Prefix]
|
181
|
-
|
178
|
+
define_attr :prefixes, ArrayOfIPv6Prefix, builder: ->(h, t) { t.new(counter: h[:prefix_count]) }
|
182
179
|
end
|
183
180
|
|
184
|
-
# This class defines a specialized {
|
181
|
+
# This class defines a specialized {BinStruct::Array array} to handle series
|
185
182
|
# of {LSA LSAs} or {LSAHeader LSAHeaders}. It recognizes known LSA types
|
186
183
|
# and infers correct type.
|
187
184
|
# @author Sylvain Daubert
|
188
|
-
class ArrayOfLSA <
|
185
|
+
class ArrayOfLSA < BinStruct::Array
|
189
186
|
set_of LSAHeader
|
190
187
|
|
191
188
|
# @param [Hash] options
|
192
|
-
# @option options [
|
193
|
-
# @option options [
|
189
|
+
# @option options [BinStruct::Int] counter Int object used as a counter for this set
|
190
|
+
# @option options [Integer] only_headers if +true+, only {LSAHeader LSAHeaders}
|
194
191
|
# will be added to this array.
|
195
192
|
def initialize(options={})
|
196
193
|
super
|
@@ -200,7 +197,7 @@ module PacketGen
|
|
200
197
|
private
|
201
198
|
|
202
199
|
def record_from_hash(hsh)
|
203
|
-
raise ArgumentError, 'hash should have :type key' unless hsh.key?
|
200
|
+
raise ArgumentError, 'hash should have :type key' unless hsh.key?(:type)
|
204
201
|
|
205
202
|
klass = if @only_headers
|
206
203
|
LSAHeader
|
@@ -220,8 +217,8 @@ module PacketGen
|
|
220
217
|
def get_lsa_class_by_human_type(htype)
|
221
218
|
klassname = "LSA#{htype.to_s.delete('-')}"
|
222
219
|
begin
|
223
|
-
if OSPFv3.const_defined?
|
224
|
-
OSPFv3.const_get
|
220
|
+
if OSPFv3.const_defined?(klassname)
|
221
|
+
OSPFv3.const_get(klassname)
|
225
222
|
else
|
226
223
|
LSA
|
227
224
|
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,34 +47,34 @@ 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
79
|
# Compute and set Fletcher-16 checksum on LSA
|
80
80
|
# @return [Integer]
|
@@ -24,15 +24,15 @@ 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}).
|
36
36
|
#
|
37
37
|
# == Create an OSPFv3 header
|
38
38
|
# # standalone
|
@@ -74,38 +74,38 @@ module PacketGen
|
|
74
74
|
# @!attribute version
|
75
75
|
# 8-bit OSPF version
|
76
76
|
# @return [Integer]
|
77
|
-
|
77
|
+
define_attr :version, BinStruct::Int8, default: 3
|
78
78
|
# @!attribute type
|
79
79
|
# 8-bit OSPF packet type. Types are defined in {TYPES}.
|
80
80
|
# @return [Integer]
|
81
|
-
|
81
|
+
define_attr :type, BinStruct::Int8Enum, enum: TYPES
|
82
82
|
# @!attribute length
|
83
83
|
# 16-bit OSPF packet length
|
84
84
|
# @return [Integer]
|
85
|
-
|
85
|
+
define_attr :length, BinStruct::Int16
|
86
86
|
# @!attribute router_id
|
87
87
|
# 32-bit router ID
|
88
88
|
# @return [Integer]
|
89
|
-
|
89
|
+
define_attr :router_id, BinStruct::Int32
|
90
90
|
# @!attribute area_id
|
91
91
|
# 32-bit area ID
|
92
92
|
# @return [Integer]
|
93
|
-
|
93
|
+
define_attr :area_id, BinStruct::Int32
|
94
94
|
# @!attribute checksum
|
95
95
|
# 16-bit OSPF packet checksum
|
96
96
|
# @return [Integer]
|
97
|
-
|
97
|
+
define_attr :checksum, BinStruct::Int16
|
98
98
|
# @!attribute instance_id
|
99
99
|
# 8-bit instance ID.
|
100
100
|
# @return [Integer]
|
101
|
-
|
101
|
+
define_attr :instance_id, BinStruct::Int8
|
102
102
|
# @!attribute reserved
|
103
103
|
# 8-bit reserved field.
|
104
104
|
# @return [Integer]
|
105
|
-
|
105
|
+
define_attr :reserved, BinStruct::Int8, default: 0
|
106
106
|
# @!attribute body
|
107
107
|
# @return [String,Base]
|
108
|
-
|
108
|
+
define_attr :body, BinStruct::String
|
109
109
|
|
110
110
|
# @api private
|
111
111
|
# Helper class method to define an OSPFv3 options field.
|
@@ -118,27 +118,25 @@ module PacketGen
|
|
118
118
|
# @return [Integer]
|
119
119
|
# @!attribute dc_opt
|
120
120
|
# This bit describes the router's handling of demand circuits.
|
121
|
-
# @return [
|
121
|
+
# @return [Integer]
|
122
122
|
# @!attribute r_opt
|
123
123
|
# This bit indicates whether the originator is an active router.
|
124
|
-
# @return [
|
124
|
+
# @return [Integer]
|
125
125
|
# @!attribute n_opt
|
126
126
|
# This bit indicates whether or not the router is attached to an NSSA.
|
127
|
-
# @return [
|
127
|
+
# @return [Integer]
|
128
128
|
# @!attribute x_opt
|
129
129
|
# This bit should be set to 0, and ignored when received.
|
130
|
-
# @return [
|
130
|
+
# @return [Integer]
|
131
131
|
# @!attribute e_opt
|
132
132
|
# This bit describes the way AS-external-LSAs are flooded.
|
133
|
-
# @return [
|
133
|
+
# @return [Integer]
|
134
134
|
# @!attribute v6_opt
|
135
135
|
# If this bit is clear, the router/link should be excluded from IPv6
|
136
136
|
# routing calculations.
|
137
|
-
# @return [
|
137
|
+
# @return [Integer]
|
138
138
|
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
|
139
|
+
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
140
|
end
|
143
141
|
|
144
142
|
# @api private
|