packetgen 3.3.3 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -21
  3. data/lib/packetgen/capture.rb +2 -2
  4. data/lib/packetgen/config.rb +0 -1
  5. data/lib/packetgen/deprecation.rb +7 -7
  6. data/lib/packetgen/header/arp.rb +13 -13
  7. data/lib/packetgen/header/asn1_base.rb +1 -1
  8. data/lib/packetgen/header/base.rb +17 -18
  9. data/lib/packetgen/header/bootp.rb +32 -34
  10. data/lib/packetgen/header/dhcp/option.rb +19 -19
  11. data/lib/packetgen/header/dhcp/options.rb +1 -1
  12. data/lib/packetgen/header/dhcp.rb +3 -3
  13. data/lib/packetgen/header/dhcpv6/duid.rb +16 -16
  14. data/lib/packetgen/header/dhcpv6/option.rb +53 -53
  15. data/lib/packetgen/header/dhcpv6/options.rb +1 -1
  16. data/lib/packetgen/header/dhcpv6/relay.rb +5 -5
  17. data/lib/packetgen/header/dhcpv6.rb +6 -6
  18. data/lib/packetgen/header/dns/name.rb +14 -10
  19. data/lib/packetgen/header/dns/opt.rb +2 -2
  20. data/lib/packetgen/header/dns/option.rb +11 -11
  21. data/lib/packetgen/header/dns/qdsection.rb +1 -1
  22. data/lib/packetgen/header/dns/question.rb +6 -8
  23. data/lib/packetgen/header/dns/rr.rb +56 -43
  24. data/lib/packetgen/header/dns/rrsection.rb +4 -4
  25. data/lib/packetgen/header/dns.rb +27 -30
  26. data/lib/packetgen/header/dot11/control.rb +11 -11
  27. data/lib/packetgen/header/dot11/data.rb +20 -20
  28. data/lib/packetgen/header/dot11/element.rb +4 -4
  29. data/lib/packetgen/header/dot11/management.rb +8 -8
  30. data/lib/packetgen/header/dot11/sub_mngt.rb +39 -53
  31. data/lib/packetgen/header/dot11.rb +88 -93
  32. data/lib/packetgen/header/dot1q.rb +10 -12
  33. data/lib/packetgen/header/dot1x.rb +9 -9
  34. data/lib/packetgen/header/eap/fast.rb +4 -4
  35. data/lib/packetgen/header/eap/md5.rb +6 -6
  36. data/lib/packetgen/header/eap/tls.rb +13 -15
  37. data/lib/packetgen/header/eap/ttls.rb +13 -15
  38. data/lib/packetgen/header/eap.rb +22 -22
  39. data/lib/packetgen/header/eth.rb +18 -18
  40. data/lib/packetgen/header/gre.rb +8 -10
  41. data/lib/packetgen/header/http/headers.rb +2 -2
  42. data/lib/packetgen/header/http/request.rb +17 -16
  43. data/lib/packetgen/header/http/response.rb +18 -17
  44. data/lib/packetgen/header/http/verbs.rb +1 -3
  45. data/lib/packetgen/header/icmp.rb +8 -8
  46. data/lib/packetgen/header/icmpv6.rb +3 -3
  47. data/lib/packetgen/header/igmp.rb +8 -8
  48. data/lib/packetgen/header/igmpv3/group_record.rb +12 -12
  49. data/lib/packetgen/header/igmpv3/mq.rb +16 -18
  50. data/lib/packetgen/header/igmpv3/mr.rb +4 -4
  51. data/lib/packetgen/header/igmpv3.rb +7 -7
  52. data/lib/packetgen/header/ip/addr.rb +13 -13
  53. data/lib/packetgen/header/ip/option.rb +31 -33
  54. data/lib/packetgen/header/ip/options.rb +1 -1
  55. data/lib/packetgen/header/ip.rb +37 -72
  56. data/lib/packetgen/header/ipv6/addr.rb +14 -14
  57. data/lib/packetgen/header/ipv6/extension.rb +8 -8
  58. data/lib/packetgen/header/ipv6/hop_by_hop.rb +9 -9
  59. data/lib/packetgen/header/ipv6.rb +20 -22
  60. data/lib/packetgen/header/llc.rb +17 -17
  61. data/lib/packetgen/header/mdns.rb +1 -1
  62. data/lib/packetgen/header/mld.rb +6 -6
  63. data/lib/packetgen/header/mldv2/mcast_address_record.rb +11 -11
  64. data/lib/packetgen/header/mldv2/mlq.rb +21 -23
  65. data/lib/packetgen/header/mldv2/mlr.rb +8 -8
  66. data/lib/packetgen/header/ospfv2/db_description.rb +11 -12
  67. data/lib/packetgen/header/ospfv2/hello.rb +11 -11
  68. data/lib/packetgen/header/ospfv2/ls_ack.rb +1 -1
  69. data/lib/packetgen/header/ospfv2/ls_request.rb +9 -9
  70. data/lib/packetgen/header/ospfv2/ls_update.rb +3 -3
  71. data/lib/packetgen/header/ospfv2/lsa.rb +54 -58
  72. data/lib/packetgen/header/ospfv2/lsa_header.rb +9 -9
  73. data/lib/packetgen/header/ospfv2.rb +27 -29
  74. data/lib/packetgen/header/ospfv3/db_description.rb +13 -14
  75. data/lib/packetgen/header/ospfv3/hello.rb +12 -12
  76. data/lib/packetgen/header/ospfv3/ipv6_prefix.rb +17 -19
  77. data/lib/packetgen/header/ospfv3/ls_ack.rb +2 -2
  78. data/lib/packetgen/header/ospfv3/ls_request.rb +9 -9
  79. data/lib/packetgen/header/ospfv3/ls_update.rb +4 -4
  80. data/lib/packetgen/header/ospfv3/lsa.rb +48 -51
  81. data/lib/packetgen/header/ospfv3/lsa_header.rb +9 -9
  82. data/lib/packetgen/header/ospfv3.rb +25 -27
  83. data/lib/packetgen/header/sctp/chunk.rb +44 -41
  84. data/lib/packetgen/header/sctp/error.rb +52 -52
  85. data/lib/packetgen/header/sctp/parameter.rb +38 -38
  86. data/lib/packetgen/header/sctp.rb +5 -5
  87. data/lib/packetgen/header/snmp.rb +2 -2
  88. data/lib/packetgen/header/tcp/option.rb +45 -39
  89. data/lib/packetgen/header/tcp/options.rb +2 -2
  90. data/lib/packetgen/header/tcp.rb +55 -44
  91. data/lib/packetgen/header/tftp.rb +16 -16
  92. data/lib/packetgen/header/udp.rb +8 -8
  93. data/lib/packetgen/header.rb +9 -10
  94. data/lib/packetgen/headerable.rb +13 -3
  95. data/lib/packetgen/inspect.rb +2 -2
  96. data/lib/packetgen/packet.rb +54 -37
  97. data/lib/packetgen/pcap.rb +15 -4
  98. data/lib/packetgen/pcapng/block.rb +18 -17
  99. data/lib/packetgen/pcapng/epb.rb +13 -15
  100. data/lib/packetgen/pcapng/file.rb +3 -97
  101. data/lib/packetgen/pcapng/idb.rb +9 -11
  102. data/lib/packetgen/pcapng/shb.rb +13 -15
  103. data/lib/packetgen/pcapng/spb.rb +8 -10
  104. data/lib/packetgen/pcapng/unknown_block.rb +6 -17
  105. data/lib/packetgen/pcapng.rb +4 -4
  106. data/lib/packetgen/pcaprub_wrapper.rb +17 -1
  107. data/lib/packetgen/proto.rb +1 -1
  108. data/lib/packetgen/unknown_packet.rb +2 -2
  109. data/lib/packetgen/utils/arp_spoofer.rb +18 -19
  110. data/lib/packetgen/utils.rb +2 -2
  111. data/lib/packetgen/version.rb +1 -1
  112. data/lib/packetgen.rb +4 -3
  113. metadata +29 -38
  114. data/lib/packetgen/types/abstract_tlv.rb +0 -278
  115. data/lib/packetgen/types/array.rb +0 -287
  116. data/lib/packetgen/types/cstring.rb +0 -109
  117. data/lib/packetgen/types/enum.rb +0 -171
  118. data/lib/packetgen/types/fieldable.rb +0 -66
  119. data/lib/packetgen/types/fields.rb +0 -622
  120. data/lib/packetgen/types/int.rb +0 -473
  121. data/lib/packetgen/types/int_string.rb +0 -102
  122. data/lib/packetgen/types/length_from.rb +0 -54
  123. data/lib/packetgen/types/oui.rb +0 -52
  124. data/lib/packetgen/types/string.rb +0 -97
  125. data/lib/packetgen/types/tlv.rb +0 -161
  126. 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 < Types::Fields
31
- include Types::Fieldable
30
+ class LSR < BinStruct::Struct
31
+ include BinStruct::Structable
32
32
 
33
33
  # @!attribute reserved
34
34
  # reserved field.
35
35
  # @return [Integer]
36
- define_field :reserved, Types::Int16, default: 0
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
- define_field :type, Types::Int16Enum, enum: LSAHeader::TYPES
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
- define_field :link_state_id, IP::Addr
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
- define_field :advertising_router, IP::Addr
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 {Types::Array array} to handle series
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 < Types::Array
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
- define_field :lsrs, ArrayOfLSR
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 {Types::Int32} field,
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
- define_field :lsas_count, Types::Int32
51
+ define_attr :lsas_count, BinStruct::Int32
52
52
  # @!attribute lsas
53
53
  # Array of {LSA LSAs}
54
54
  # @return [ArrayOfLSA]
55
- define_field :lsas, ArrayOfLSA,
56
- builder: ->(h, t) { t.new(counter: h[:lsas_count]) }
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 < Types::Fields
15
- include Types::Fieldable
14
+ class Link < BinStruct::Struct
15
+ include BinStruct::Structable
16
16
 
17
17
  # @!attribute type
18
18
  # @return [Integer]
19
- define_field :type, Types::Int8
19
+ define_attr :type, BinStruct::Int8
20
20
  # @!attribute reserved
21
21
  # @return [Integer]
22
- define_field :reserved, Types::Int8, default: 0
22
+ define_attr :reserved, BinStruct::Int8, default: 0
23
23
  # @!attribute metric
24
24
  # @return [Integer]
25
- define_field :metric, Types::Int16
25
+ define_attr :metric, BinStruct::Int16
26
26
  # @!attribute interface_id
27
27
  # @return [Integer]
28
- define_field :interface_id, Types::Int32
28
+ define_attr :interface_id, BinStruct::Int32
29
29
  # @!attribute neighbor_interface_id
30
30
  # @return [Integer]
31
- define_field :neighbor_interface_id, Types::Int32
31
+ define_attr :neighbor_interface_id, BinStruct::Int32
32
32
  # @!attribute neighbor_router_id
33
33
  # @return [String]
34
- define_field :neighbor_router_id, IP::Addr
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 {Types::Array array} to handle series
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 < Types::Array
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
- define_field :body, Types::String,
58
- builder: ->(h, t) { t.new(length_from: -> { h.length - 20 }) }
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} ({Types::Int8}),
66
- # * a 24-bit {#options} field ({Types::Int24}),
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 [Boolean]
74
+ # @return [Integer]
82
75
  # @!attribute v_flag
83
- # @return [Boolean]
76
+ # @return [Integer]
84
77
  # @!attribute e_flag
85
- # @return [Boolean]
78
+ # @return [Integer]
86
79
  # @!attribute b_flag
87
- # @return [Boolean]
88
- define_bit_fields_on :flags, :zz, 3, :nt_flag, :x_flag, :v_flag, :e_flag,
89
- :b_flag
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
- define_field :reserved, Types::Int8
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
- define_field :routers, IP::ArrayOfAddr, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:routers) }) }
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 ({Types::Int16}),
116
- # * a 16-bit {#ref_ls_type} field ({Types::Int16Enum}),
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
- define_field :prefix_count, Types::Int16
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
- define_field :ref_ls_type, Types::Int16Enum, enum: TYPES
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
- define_field :ref_link_state_id, IP::Addr
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
- define_field :ref_advertising_router, IP::Addr
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
- define_field :prefixes, ArrayOfIPv6Prefix,
150
- builder: ->(h, t) { t.new(counter: h[:prefix_count]) }
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 ({Types::Int8}),
157
- # * a 24-bit {#options} field ({Types::Int24}),
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 ({Types::Int32}),
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
- define_field :router_priority, Types::Int8
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
- define_field :interface_addr, IPv6::Addr
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
- define_field :prefix_count, Types::Int32
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
- define_field :prefixes, ArrayOfIPv6Prefix, builder: ->(h, t) { t.new(counter: h[:prefix_count]) }
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 {Types::Array array} to handle series
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 < Types::Array
185
+ class ArrayOfLSA < BinStruct::Array
189
186
  set_of LSAHeader
190
187
 
191
188
  # @param [Hash] options
192
- # @option options [Types::Int] counter Int object used as a counter for this set
193
- # @option options [Boolean] only_headers if +true+, only {LSAHeader LSAHeaders}
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? :type
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? klassname
224
- OSPFv3.const_get klassname
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 < Types::Fields
33
- include Types::Fieldable
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
- define_field :age, Types::Int16
50
+ define_attr :age, BinStruct::Int16
51
51
  # @!attribute type
52
52
  # The type of the LSA.
53
53
  # @return [Integer]
54
- define_field :type, Types::Int16Enum, enum: TYPES
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
- define_field :link_state_id, IP::Addr
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
- define_field :advertising_router, IP::Addr
63
+ define_attr :advertising_router, IP::Addr
64
64
  # @!attribute sequence_number
65
65
  # @return [Integer]
66
- define_field :sequence_number, Types::Int32
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
- define_field :checksum, Types::Int16
73
+ define_attr :checksum, BinStruct::Int16
74
74
  # @!attribute length
75
75
  # Length of the LSA, including the header.
76
76
  # @return [Integer]
77
- define_field :length, Types::Int16
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 ({Types::Int8}),
28
- # * a {#type} field ({Types::Int8Enum}),
29
- # * a {#length} field ({Types::Int16}). The length includes the header,
30
- # * a {#router_id} field ({Types::Int32}),
31
- # * an {#area_id} field ({Types::Int32}),
32
- # * a {#checksum} field ({Types::Int16}),
33
- # * an {#instance_id} field ({Types::Int8}),
34
- # * a {#reserved} field ({Types::Int8}),
35
- # * and a {#body} ({Types::String}).
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
- define_field :version, Types::Int8, default: 3
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
- define_field :type, Types::Int8Enum, enum: TYPES
81
+ define_attr :type, BinStruct::Int8Enum, enum: TYPES
82
82
  # @!attribute length
83
83
  # 16-bit OSPF packet length
84
84
  # @return [Integer]
85
- define_field :length, Types::Int16
85
+ define_attr :length, BinStruct::Int16
86
86
  # @!attribute router_id
87
87
  # 32-bit router ID
88
88
  # @return [Integer]
89
- define_field :router_id, Types::Int32
89
+ define_attr :router_id, BinStruct::Int32
90
90
  # @!attribute area_id
91
91
  # 32-bit area ID
92
92
  # @return [Integer]
93
- define_field :area_id, Types::Int32
93
+ define_attr :area_id, BinStruct::Int32
94
94
  # @!attribute checksum
95
95
  # 16-bit OSPF packet checksum
96
96
  # @return [Integer]
97
- define_field :checksum, Types::Int16
97
+ define_attr :checksum, BinStruct::Int16
98
98
  # @!attribute instance_id
99
99
  # 8-bit instance ID.
100
100
  # @return [Integer]
101
- define_field :instance_id, Types::Int8
101
+ define_attr :instance_id, BinStruct::Int8
102
102
  # @!attribute reserved
103
103
  # 8-bit reserved field.
104
104
  # @return [Integer]
105
- define_field :reserved, Types::Int8, default: 0
105
+ define_attr :reserved, BinStruct::Int8, default: 0
106
106
  # @!attribute body
107
107
  # @return [String,Base]
108
- define_field :body, Types::String
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 [Boolean]
121
+ # @return [Integer]
122
122
  # @!attribute r_opt
123
123
  # This bit indicates whether the originator is an active router.
124
- # @return [Boolean]
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 [Boolean]
127
+ # @return [Integer]
128
128
  # @!attribute x_opt
129
129
  # This bit should be set to 0, and ignored when received.
130
- # @return [Boolean]
130
+ # @return [Integer]
131
131
  # @!attribute e_opt
132
132
  # This bit describes the way AS-external-LSAs are flooded.
133
- # @return [Boolean]
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 [Boolean]
137
+ # @return [Integer]
138
138
  def self.define_options(hdr)
139
- hdr.define_field :options, Types::Int24
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