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
@@ -16,28 +16,28 @@ module PacketGen
|
|
16
16
|
# @!attribute body
|
17
17
|
# LSA body
|
18
18
|
# @return [String]
|
19
|
-
|
20
|
-
|
19
|
+
define_attr :body, BinStruct::String,
|
20
|
+
builder: ->(h, t) { t.new(length_from: -> { h.length - 20 }) }
|
21
21
|
end
|
22
22
|
|
23
23
|
# This class handles TOS metrics for {Link links} in a {LSARouter
|
24
24
|
# LSA router payload}.
|
25
25
|
# @author Sylvain Daubert
|
26
|
-
class TosMetric <
|
27
|
-
include
|
26
|
+
class TosMetric < BinStruct::Struct
|
27
|
+
include BinStruct::Structable
|
28
28
|
|
29
29
|
# @!attribute tos
|
30
30
|
# 8-bit IP Type of Service that this metric refers to.
|
31
31
|
# @return [Integer]
|
32
|
-
|
32
|
+
define_attr :tos, BinStruct::Int8
|
33
33
|
# @!attribute reserved
|
34
34
|
# 8-bit reserved field.
|
35
35
|
# @return [Integer]
|
36
|
-
|
36
|
+
define_attr :reserved, BinStruct::Int8, default: 0
|
37
37
|
# @!attribute tos_metric
|
38
38
|
# 16-bit TOS-specific metric information..
|
39
39
|
# @return [Integer]
|
40
|
-
|
40
|
+
define_attr :tos_metric, BinStruct::Int16
|
41
41
|
|
42
42
|
# @return [String]
|
43
43
|
def to_human
|
@@ -45,37 +45,37 @@ module PacketGen
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
# This class defines a specialized {
|
48
|
+
# This class defines a specialized {BinStruct::Array array} to handle series
|
49
49
|
# of {TosMetric TOS metrics}.
|
50
50
|
# @author Sylvain Daubert
|
51
|
-
class ArrayOfTosMetric <
|
51
|
+
class ArrayOfTosMetric < BinStruct::Array
|
52
52
|
set_of TosMetric
|
53
53
|
end
|
54
54
|
|
55
55
|
# This class handles links in a {LSARouter LSA router payload}.
|
56
56
|
# @author Sylvain Daubert
|
57
|
-
class Link <
|
58
|
-
include
|
57
|
+
class Link < BinStruct::Struct
|
58
|
+
include BinStruct::Structable
|
59
59
|
|
60
60
|
# @!attribute id
|
61
61
|
# @return [IP::Addr]
|
62
|
-
|
62
|
+
define_attr :id, IP::Addr
|
63
63
|
# @!attribute data
|
64
64
|
# @return [IP::Addr]
|
65
|
-
|
65
|
+
define_attr :data, IP::Addr
|
66
66
|
# @!attribute type
|
67
67
|
# @return [Integer]
|
68
|
-
|
68
|
+
define_attr :type, BinStruct::Int8
|
69
69
|
# @!attribute tos_count
|
70
70
|
# @return [Integer]
|
71
|
-
|
71
|
+
define_attr :tos_count, BinStruct::Int8
|
72
72
|
# @!attribute metric
|
73
73
|
# @return [Integer]
|
74
|
-
|
74
|
+
define_attr :metric, BinStruct::Int16
|
75
75
|
# @!attribute tos
|
76
76
|
# Additionnal TOS metrics
|
77
77
|
# @return [ArrayOfTosMetric]
|
78
|
-
|
78
|
+
define_attr :tos, ArrayOfTosMetric, builder: ->(h, t) { t.new(counter: h[:tos_count]) }
|
79
79
|
|
80
80
|
# @return [String]
|
81
81
|
def to_human
|
@@ -83,10 +83,10 @@ module PacketGen
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
# This class defines a specialized {
|
86
|
+
# This class defines a specialized {BinStruct::Array array} to handle series
|
87
87
|
# of {Link Links}.
|
88
88
|
# @author Sylvain Daubert
|
89
|
-
class ArrayOfLink <
|
89
|
+
class ArrayOfLink < BinStruct::Array
|
90
90
|
set_of Link
|
91
91
|
end
|
92
92
|
|
@@ -94,30 +94,28 @@ module PacketGen
|
|
94
94
|
#
|
95
95
|
# A LSA router payload is composed of:
|
96
96
|
# * a header (see methods inherited from {LSAHeader}),
|
97
|
-
# * a 16-bit flag word {#u16} ({
|
98
|
-
# * a 16-bit {#link_count} field ({
|
97
|
+
# * a 16-bit flag word {#u16} ({BinStruct::Int16}),
|
98
|
+
# * a 16-bit {#link_count} field ({BinStruct::Int16}),
|
99
99
|
# * an array of {#links} ({ArrayOfLink}).
|
100
100
|
# @author Sylvain Daubert
|
101
101
|
class LSARouter < LSAHeader
|
102
102
|
# @attribute u16
|
103
103
|
# 16-bit flag word
|
104
104
|
# @return [Integer]
|
105
|
-
|
105
|
+
# @attribute v_flag
|
106
|
+
# @return [Integer]
|
107
|
+
# @attribute e_flag
|
108
|
+
# @return [Integer]
|
109
|
+
# @attribute b_flag
|
110
|
+
# @return [Integer]
|
111
|
+
define_bit_attr :u16, z: 5, v_flag: 1, e_flag: 1, b_flag: 1, zz: 8
|
106
112
|
# @attribute link_count
|
107
113
|
# Number of links
|
108
114
|
# @return [Integer]
|
109
|
-
|
115
|
+
define_attr :link_count, BinStruct::Int16
|
110
116
|
# @attribute links
|
111
117
|
# @return [ArrayOfLink]
|
112
|
-
|
113
|
-
|
114
|
-
# @attribute v_flag
|
115
|
-
# @return [Boolean]
|
116
|
-
# @attribute e_flag
|
117
|
-
# @return [Boolean]
|
118
|
-
# @attribute b_flag
|
119
|
-
# @return [Boolean]
|
120
|
-
define_bit_fields_on :u16, :z, 5, :v_flag, :e_flag, :b_flag, :zz, 8
|
118
|
+
define_attr :links, ArrayOfLink, builder: ->(h, t) { t.new(counter: h[:link_count]) }
|
121
119
|
end
|
122
120
|
|
123
121
|
# This class handles LSA Network payloads.
|
@@ -130,37 +128,35 @@ module PacketGen
|
|
130
128
|
class LSANetwork < LSAHeader
|
131
129
|
# @!attribute netmask
|
132
130
|
# @return [IP::Addr]
|
133
|
-
|
131
|
+
define_attr :netmask, IP::Addr
|
134
132
|
# @!attribute routers
|
135
133
|
# List of routers in network
|
136
134
|
# @return [IP::ArrayOfAddr]
|
137
|
-
|
138
|
-
|
135
|
+
define_attr :routers, IP::ArrayOfAddr,
|
136
|
+
builder: ->(h, t) { t.new(length_from: -> { h.length - 24 }) }
|
139
137
|
end
|
140
138
|
|
141
139
|
# This class handles external links in {LSAASExternal LSA AS-External payloads}.
|
142
140
|
# @author Sylvain Daubert
|
143
|
-
class External <
|
144
|
-
include
|
141
|
+
class External < BinStruct::Struct
|
142
|
+
include BinStruct::Structable
|
145
143
|
|
146
144
|
# @!attribute u8
|
147
145
|
# @return [Integer]
|
148
|
-
|
146
|
+
# @!attribute e_flag
|
147
|
+
# @return [Integer]
|
148
|
+
# @!attribute tos
|
149
|
+
# @return [Integer]
|
150
|
+
define_bit_attr :u8, e_flag: 1, tos: 7
|
149
151
|
# @!attribute metric
|
150
152
|
# @return [Integer]
|
151
|
-
|
153
|
+
define_attr :metric, BinStruct::Int24
|
152
154
|
# @!attribute forwarding_addr
|
153
155
|
# @return [IP::Addr]
|
154
|
-
|
156
|
+
define_attr :forwarding_addr, IP::Addr
|
155
157
|
# @!attribute ext_route_tag
|
156
158
|
# @return [Integer]
|
157
|
-
|
158
|
-
|
159
|
-
# @!attribute e_flag
|
160
|
-
# @return [Boolean]
|
161
|
-
# @!attribute tos
|
162
|
-
# @return [Integer]
|
163
|
-
define_bit_fields_on :u8, :e_flag, :tos, 7
|
159
|
+
define_attr :ext_route_tag, BinStruct::Int32
|
164
160
|
|
165
161
|
# @return [String]
|
166
162
|
def to_human
|
@@ -168,10 +164,10 @@ module PacketGen
|
|
168
164
|
end
|
169
165
|
end
|
170
166
|
|
171
|
-
# This class defines a specialized {
|
167
|
+
# This class defines a specialized {BinStruct::Array array} to handle series
|
172
168
|
# of {External Externals}.
|
173
169
|
# @author Sylvain Daubert
|
174
|
-
class ArrayOfExternal <
|
170
|
+
class ArrayOfExternal < BinStruct::Array
|
175
171
|
set_of External
|
176
172
|
end
|
177
173
|
|
@@ -185,22 +181,22 @@ module PacketGen
|
|
185
181
|
class LSAASExternal < LSAHeader
|
186
182
|
# @!attribute netmask
|
187
183
|
# @return [IP::Addr]
|
188
|
-
|
184
|
+
define_attr :netmask, IP::Addr
|
189
185
|
# @!attribute externals
|
190
186
|
# List of external destinations
|
191
187
|
# @return [ArrayOfExternal]
|
192
|
-
|
193
|
-
|
188
|
+
define_attr :externals, ArrayOfExternal,
|
189
|
+
builder: ->(h, t) { t.new(length_from: -> { h.length - 24 }) }
|
194
190
|
end
|
195
191
|
|
196
|
-
# This class defines a specialized {
|
192
|
+
# This class defines a specialized {BinStruct::Array array} to handle series
|
197
193
|
# of {LSA LSAs}. It recognizes known LSA types and infers correct type.
|
198
194
|
# @author Sylvain Daubert
|
199
|
-
class ArrayOfLSA <
|
195
|
+
class ArrayOfLSA < BinStruct::Array
|
200
196
|
set_of LSAHeader
|
201
197
|
|
202
198
|
# @param [Hash] options
|
203
|
-
# @option options [
|
199
|
+
# @option options [BinStruct::Int] counter Int object used as a counter for this set
|
204
200
|
# @option options [Boolean] only_headers if +true+, only {LSAHeader LSAHeaders}
|
205
201
|
# will be added to this array.
|
206
202
|
def initialize(options={})
|
@@ -211,7 +207,7 @@ module PacketGen
|
|
211
207
|
private
|
212
208
|
|
213
209
|
def record_from_hash(hsh)
|
214
|
-
raise ArgumentError, 'hash should have :type key' unless hsh.key?
|
210
|
+
raise ArgumentError, 'hash should have :type key' unless hsh.key?(:type)
|
215
211
|
|
216
212
|
klass = if @only_headers
|
217
213
|
LSAHeader
|
@@ -231,8 +227,8 @@ module PacketGen
|
|
231
227
|
def get_lsa_class_by_human_type(htype)
|
232
228
|
klassname = "LSA#{htype.to_s.delete('-')}"
|
233
229
|
begin
|
234
|
-
if OSPFv2.const_defined?
|
235
|
-
OSPFv2.const_get
|
230
|
+
if OSPFv2.const_defined?(klassname)
|
231
|
+
OSPFv2.const_get(klassname)
|
236
232
|
else
|
237
233
|
LSA
|
238
234
|
end
|
@@ -29,8 +29,8 @@ module PacketGen
|
|
29
29
|
# LSA headers are used as-is in {DbDescription} payload. But this class
|
30
30
|
# 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 Types
|
36
36
|
TYPES = {
|
@@ -44,36 +44,36 @@ module PacketGen
|
|
44
44
|
# @!attribute age
|
45
45
|
# The time in seconds since the LSA was originated.
|
46
46
|
# @return [Integer]
|
47
|
-
|
47
|
+
define_attr :age, BinStruct::Int16
|
48
48
|
# @!macro define_options
|
49
49
|
OSPFv2.define_options(self)
|
50
50
|
# @!attribute type
|
51
51
|
# The type of the LSA.
|
52
52
|
# @return [Integer]
|
53
|
-
|
53
|
+
define_attr :type, BinStruct::Int8Enum, enum: TYPES
|
54
54
|
# @!attribute link_state_id
|
55
55
|
# This field identifies the portion of the internet environment
|
56
56
|
# that is being described by the LSA.
|
57
57
|
# @return [String]
|
58
|
-
|
58
|
+
define_attr :link_state_id, IP::Addr
|
59
59
|
# @!attribute advertising_router
|
60
60
|
# The Router ID of the router that originated the LSA.
|
61
61
|
# @return [String]
|
62
|
-
|
62
|
+
define_attr :advertising_router, IP::Addr
|
63
63
|
# @!attribute sequence_number
|
64
64
|
# @return [Integer]
|
65
|
-
|
65
|
+
define_attr :sequence_number, BinStruct::Int32
|
66
66
|
alias seqnum sequence_number
|
67
67
|
alias seqnum= sequence_number=
|
68
68
|
# @!attribute checksum
|
69
69
|
# The Fletcher checksum of the complete contents of the LSA,
|
70
70
|
# including the LSA header but excluding the LS age field.
|
71
71
|
# @return [Integer]
|
72
|
-
|
72
|
+
define_attr :checksum, BinStruct::Int16
|
73
73
|
# @!attribute length
|
74
74
|
# Length of the LSA, including the header.
|
75
75
|
# @return [Integer]
|
76
|
-
|
76
|
+
define_attr :length, BinStruct::Int16
|
77
77
|
|
78
78
|
# Compute and set Fletcher-16 checksum on LSA
|
79
79
|
# @return [Integer]
|
@@ -28,15 +28,15 @@ module PacketGen
|
|
28
28
|
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
29
29
|
#
|
30
30
|
# An OSPFv2 header consists of:
|
31
|
-
# * a {#version} field ({
|
32
|
-
# * a {#type} field ({
|
33
|
-
# * a {#length} field ({
|
34
|
-
# * a {#router_id} field ({
|
35
|
-
# * an {#area_id} field ({
|
36
|
-
# * a {#checksum} field ({
|
37
|
-
# * an {#au_type} field ({
|
38
|
-
# * an {#authentication} field ({
|
39
|
-
# * and a {#body} ({
|
31
|
+
# * a {#version} field ({BinStruct::Int8}),
|
32
|
+
# * a {#type} field ({BinStruct::Int8Enum}),
|
33
|
+
# * a {#length} field ({BinStruct::Int16}). The length includes the header,
|
34
|
+
# * a {#router_id} field ({BinStruct::Int32}),
|
35
|
+
# * an {#area_id} field ({BinStruct::Int32}),
|
36
|
+
# * a {#checksum} field ({BinStruct::Int16}),
|
37
|
+
# * an {#au_type} field ({BinStruct::Int16Enum}),
|
38
|
+
# * an {#authentication} field ({BinStruct::Int64}),
|
39
|
+
# * and a {#body} ({BinStruct::String}).
|
40
40
|
#
|
41
41
|
# == Create an OSPFv2 header
|
42
42
|
# # standalone
|
@@ -94,38 +94,38 @@ module PacketGen
|
|
94
94
|
# @!attribute version
|
95
95
|
# 8-bit OSPF version
|
96
96
|
# @return [Integer]
|
97
|
-
|
97
|
+
define_attr :version, BinStruct::Int8, default: 2
|
98
98
|
# @!attribute type
|
99
99
|
# 8-bit OSPF packet type. Types are defined in {TYPES}.
|
100
100
|
# @return [Integer]
|
101
|
-
|
101
|
+
define_attr :type, BinStruct::Int8Enum, enum: TYPES
|
102
102
|
# @!attribute length
|
103
103
|
# 16-bit OSPF packet length
|
104
104
|
# @return [Integer]
|
105
|
-
|
105
|
+
define_attr :length, BinStruct::Int16
|
106
106
|
# @!attribute router_id
|
107
107
|
# 32-bit router ID
|
108
108
|
# @return [Integer]
|
109
|
-
|
109
|
+
define_attr :router_id, BinStruct::Int32
|
110
110
|
# @!attribute area_id
|
111
111
|
# 32-bit area ID
|
112
112
|
# @return [Integer]
|
113
|
-
|
113
|
+
define_attr :area_id, BinStruct::Int32
|
114
114
|
# @!attribute checksum
|
115
115
|
# 16-bit OSPF packet checksum
|
116
116
|
# @return [Integer]
|
117
|
-
|
117
|
+
define_attr :checksum, BinStruct::Int16
|
118
118
|
# @!attribute au_type
|
119
119
|
# 16-bit authentication type. Types are defined in {AU_TYPES}.
|
120
120
|
# @return [Integer]
|
121
|
-
|
121
|
+
define_attr :au_type, BinStruct::Int16Enum, enum: AU_TYPES
|
122
122
|
# @!attribute authentication
|
123
123
|
# 64-bit authentication data
|
124
124
|
# @return [Integer]
|
125
|
-
|
125
|
+
define_attr :authentication, BinStruct::Int64
|
126
126
|
# @!attribute body
|
127
127
|
# @return [String,Base]
|
128
|
-
|
128
|
+
define_attr :body, BinStruct::String
|
129
129
|
|
130
130
|
# @api private
|
131
131
|
# Helper class method to define an OSPFv2 options field.
|
@@ -137,30 +137,28 @@ module PacketGen
|
|
137
137
|
# {#n_opt}, {#l_opt}, {#dc_opt}, {#o_opt} and {#dn_opt}.
|
138
138
|
# @return [Integer]
|
139
139
|
# @!attribute dn_opt
|
140
|
-
# @return [
|
140
|
+
# @return [Integer]
|
141
141
|
# @!attribute o_opt
|
142
|
-
# @return [
|
142
|
+
# @return [Integer]
|
143
143
|
# @!attribute dc_opt
|
144
144
|
# This bit describes the router's handling of demand circuits.
|
145
|
-
# @return [
|
145
|
+
# @return [Integer]
|
146
146
|
# @!attribute l_opt
|
147
147
|
# This specifies if a LLS Data block is present.
|
148
|
-
# @return [
|
148
|
+
# @return [Integer]
|
149
149
|
# @!attribute n_opt
|
150
150
|
# This bit specifies if NSSA is supported.
|
151
|
-
# @return [
|
151
|
+
# @return [Integer]
|
152
152
|
# @!attribute mc_opt
|
153
153
|
# This bit describes whether IP multicast datagrams are forwarded.
|
154
|
-
# @return [
|
154
|
+
# @return [Integer]
|
155
155
|
# @!attribute e_opt
|
156
156
|
# This bit describes the way AS-external-LSAs are flooded.
|
157
|
-
# @return [
|
157
|
+
# @return [Integer]
|
158
158
|
# @!attribute mt_opt
|
159
|
-
# @return [
|
159
|
+
# @return [Integer]
|
160
160
|
def self.define_options(hdr)
|
161
|
-
hdr.
|
162
|
-
hdr.define_bit_fields_on :options, :dn_opt, :o_opt, :dc_opt, :l_opt,
|
163
|
-
:n_opt, :mc_opt, :e_opt, :mt_opt
|
161
|
+
hdr.define_bit_attr :options, dn_opt: 1, o_opt: 1, dc_opt: 1, l_opt: 1, n_opt: 1, mc_opt: 1, e_opt: 1, mt_opt: 1
|
164
162
|
end
|
165
163
|
|
166
164
|
# @api private
|
@@ -33,14 +33,14 @@ module PacketGen
|
|
33
33
|
# | ... |
|
34
34
|
#
|
35
35
|
# A DB description payload is composed of:
|
36
|
-
# * a 8-bit {#reserved} field ({
|
37
|
-
# * a 24-bit {#options} field ({
|
38
|
-
# * a 16-bit {#mtu} field ({
|
39
|
-
# * a 16-bit {#flags} field ({
|
36
|
+
# * a 8-bit {#reserved} field ({BinStruct::Int8}),
|
37
|
+
# * a 24-bit {#options} field ({BinStruct::Int24}),
|
38
|
+
# * a 16-bit {#mtu} field ({BinStruct::Int16}),
|
39
|
+
# * a 16-bit {#flags} field ({BinStruct::Int16}). Supported flags are:
|
40
40
|
# * {i_flag},
|
41
41
|
# * {m_flag},
|
42
42
|
# * {ms_flag},
|
43
|
-
# * a 32-bit {#sequence_number} field ({
|
43
|
+
# * a 32-bit {#sequence_number} field ({BinStruct::Int32}),
|
44
44
|
# * and an array of {LSAHeader LSAHeaders} ({#lsas}, {ArrayOfLSA}).
|
45
45
|
#
|
46
46
|
# == Create a DbDescription payload
|
@@ -68,7 +68,7 @@ module PacketGen
|
|
68
68
|
# @!attribute reserved
|
69
69
|
# 8-bit zero field before {#options} one
|
70
70
|
# @return [Integer]
|
71
|
-
|
71
|
+
define_attr :reserved, BinStruct::Int8, default: 0
|
72
72
|
|
73
73
|
# @!macro define_options
|
74
74
|
OSPFv3.define_options(self)
|
@@ -76,34 +76,33 @@ module PacketGen
|
|
76
76
|
# @!attribute mtu
|
77
77
|
# 16-bit interface MTU
|
78
78
|
# @return [Integer]
|
79
|
-
|
79
|
+
define_attr :mtu, BinStruct::Int16
|
80
80
|
# @!attribute flags
|
81
81
|
# 16-bit interface flags ({#i_flag}, {#m_flag} and {#ms_flag})
|
82
82
|
# @return [Integer]
|
83
|
-
define_field :flags, Types::Int16
|
84
83
|
# @!attribute i_flag
|
85
84
|
# Init bit from {#flags} field
|
86
|
-
# @return [
|
85
|
+
# @return [Integer]
|
87
86
|
# @!attribute m_flag
|
88
87
|
# More bit from {#flags} field
|
89
|
-
# @return [
|
88
|
+
# @return [Integer]
|
90
89
|
# @!attribute ms_flag
|
91
90
|
# Master/Slave bit from {#flags} field
|
92
|
-
# @return [
|
93
|
-
|
91
|
+
# @return [Integer]
|
92
|
+
define_bit_attr :flags, zz: 13, i_flag: 1, m_flag: 1, ms_flag: 1
|
94
93
|
|
95
94
|
# @!attribute sequence_number
|
96
95
|
# 32-bit DD sequence number, used to sequence the collection of Database
|
97
96
|
# Description Packets.
|
98
97
|
# @return [Integer]
|
99
|
-
|
98
|
+
define_attr :sequence_number, BinStruct::Int32
|
100
99
|
alias seqnum sequence_number
|
101
100
|
alias seqnum= sequence_number=
|
102
101
|
|
103
102
|
# @!attribute lsas
|
104
103
|
# Array of LSA headers
|
105
104
|
# @return [ArrayOfLSAHeader]
|
106
|
-
|
105
|
+
define_attr :lsas, ArrayOfLSA, builder: ->(_h, t) { t.new(only_headers: true) }
|
107
106
|
end
|
108
107
|
end
|
109
108
|
|
@@ -28,11 +28,11 @@ module PacketGen
|
|
28
28
|
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
29
29
|
# | ... |
|
30
30
|
# A HELLO payload consists of:
|
31
|
-
# * a {#interface_id} field ({
|
32
|
-
# * a {#priority} field ({
|
33
|
-
# * an {#options} field ({
|
34
|
-
# * a {#hello_interval} field ({
|
35
|
-
# * a {#dead_interval} field ({
|
31
|
+
# * a {#interface_id} field ({BinStruct::Int32}),
|
32
|
+
# * a {#priority} field ({BinStruct::Int8}),
|
33
|
+
# * an {#options} field ({BinStruct::Int24}),
|
34
|
+
# * a {#hello_interval} field ({BinStruct::Int16}),
|
35
|
+
# * a {#dead_interval} field ({BinStruct::Int16}),
|
36
36
|
# * a {#designated_router} field ({IP::Addr}),
|
37
37
|
# * a {#backup_designated_router} field ({IP::Addr}),
|
38
38
|
# * a {#neighbors} array containing neighbors as {IP::Addr}.
|
@@ -65,36 +65,36 @@ module PacketGen
|
|
65
65
|
# @!attribute interface_id
|
66
66
|
# The network mask associated with this interface.
|
67
67
|
# @return [String]
|
68
|
-
|
68
|
+
define_attr :interface_id, BinStruct::Int32
|
69
69
|
# @!attribute priority
|
70
70
|
# This router's Router Priority. Used in (Backup) Designated
|
71
71
|
# Router election.
|
72
72
|
# @return [Integer]
|
73
|
-
|
73
|
+
define_attr :priority, BinStruct::Int8
|
74
74
|
# @!macro define_ospfv3_options
|
75
75
|
OSPFv3.define_options(self)
|
76
76
|
# @!attribute hello_interval
|
77
77
|
# The number of seconds between this router's Hello packets.
|
78
78
|
# @return [Integer]
|
79
|
-
|
79
|
+
define_attr :hello_interval, BinStruct::Int16
|
80
80
|
# @!attribute dead_interval
|
81
81
|
# The number of seconds before declaring a silent router down.
|
82
82
|
# @return [Integer]
|
83
|
-
|
83
|
+
define_attr :dead_interval, BinStruct::Int16
|
84
84
|
# @!attribute designated_router
|
85
85
|
# The identity of the Designated Router for this network, in the
|
86
86
|
# view of the sending router.
|
87
87
|
# @return [String]
|
88
|
-
|
88
|
+
define_attr :designated_router, IP::Addr
|
89
89
|
# @!attribute backup_designated_router
|
90
90
|
# The identity of the Backup Designated Router for this network,
|
91
91
|
# in the view of the sending router.
|
92
92
|
# @return [String]
|
93
|
-
|
93
|
+
define_attr :backup_designated_router, IP::Addr
|
94
94
|
# @!attribute neighbors
|
95
95
|
# Array of neighbors
|
96
96
|
# @return [IP::ArrayOfAddr]
|
97
|
-
|
97
|
+
define_attr :neighbors, IP::ArrayOfAddr
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -17,44 +17,42 @@ module PacketGen
|
|
17
17
|
# * and an array of 32-bit words to encode prefix itself ({#prefix}). This
|
18
18
|
# array consumes ((PrefixLength + 31) / 32) 32-bit words.
|
19
19
|
# @author Sylvain Daubert
|
20
|
-
class IPv6Prefix <
|
21
|
-
include
|
20
|
+
class IPv6Prefix < BinStruct::Struct
|
21
|
+
include BinStruct::Structable
|
22
22
|
|
23
23
|
# @!attribute length
|
24
24
|
# Prefix length, in bits
|
25
25
|
# @return [Integer]
|
26
|
-
|
26
|
+
define_attr :length, BinStruct::Int8
|
27
27
|
# @!attribute options
|
28
28
|
# Prefix capabilities. See also capability bits: {#dn_opt}, {#p_opt},
|
29
29
|
# {#la_opt} and {#nu_opt}.
|
30
30
|
# @return [Options]
|
31
|
-
define_field :options, Types::Int8
|
32
|
-
# @!attribute reserved
|
33
|
-
# Reserved field in most of LSA types.
|
34
|
-
# @return [Integer]
|
35
|
-
define_field :reserved, Types::Int16
|
36
|
-
# @!attribute prefix
|
37
|
-
# IPv6 Prefix as an array of 32-bit words
|
38
|
-
# @return [Prefix]
|
39
|
-
define_field :prefix, Types::ArrayOfInt32, builder: ->(h, t) { t.new(length_from: -> { h.length / 8 }) }
|
40
|
-
|
41
31
|
# @!attribute dn_opt
|
42
32
|
# This bit controls an inter-area-prefix-LSAs or AS-external-LSAs
|
43
33
|
# re-advertisement in a VPN environment.
|
44
|
-
# @return [
|
34
|
+
# @return [Integer]
|
45
35
|
# @!attribute p_opt
|
46
36
|
# The "propagate" bit. Set on NSSA area prefixes that should be
|
47
37
|
# readvertised by the translating NSSA area border.
|
48
|
-
# @return [
|
38
|
+
# @return [Integer]
|
49
39
|
# @!attribute la_opt
|
50
40
|
# The "local address" capability bit. If set, the prefix is
|
51
41
|
# actually an IPv6 interface address of the Advertising Router.
|
52
|
-
# @return [
|
42
|
+
# @return [Integer]
|
53
43
|
# @!attribute nu_opt
|
54
44
|
# The "no unicast" capability bit. If set, the prefix should be
|
55
45
|
# excluded from IPv6 unicast calculations.
|
56
|
-
# @return [
|
57
|
-
|
46
|
+
# @return [Integer]
|
47
|
+
define_bit_attr :options, zz: 3, dn_opt: 1, p_opt: 1, z: 1, la_opt: 1, nu_opt: 1
|
48
|
+
# @!attribute reserved
|
49
|
+
# Reserved field in most of LSA types.
|
50
|
+
# @return [Integer]
|
51
|
+
define_attr :reserved, BinStruct::Int16
|
52
|
+
# @!attribute prefix
|
53
|
+
# IPv6 Prefix as an array of 32-bit words
|
54
|
+
# @return [Prefix]
|
55
|
+
define_attr :prefix, BinStruct::ArrayOfInt32, builder: ->(h, t) { t.new(length_from: -> { h.length / 8 }) }
|
58
56
|
|
59
57
|
# Get human-readable prefix
|
60
58
|
# @return [String]
|
@@ -100,7 +98,7 @@ module PacketGen
|
|
100
98
|
|
101
99
|
# Array of {IPv6Prefix}
|
102
100
|
# @author Sylvain Daubert
|
103
|
-
class ArrayOfIPv6Prefix <
|
101
|
+
class ArrayOfIPv6Prefix < BinStruct::Array
|
104
102
|
set_of IPv6Prefix
|
105
103
|
end
|
106
104
|
end
|
@@ -40,8 +40,8 @@ module PacketGen
|
|
40
40
|
# @!attribute lsas
|
41
41
|
# Array of {LSA LSAs}
|
42
42
|
# @return [ArrayOfLSA]
|
43
|
-
|
44
|
-
|
43
|
+
define_attr :lsas, ArrayOfLSA,
|
44
|
+
builder: ->(_h, t) { t.new(only_headers: true) }
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|