packetgen 4.0.0 → 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.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/packetgen/deprecation.rb +7 -1
  4. data/lib/packetgen/header/arp.rb +6 -7
  5. data/lib/packetgen/header/asn1_base.rb +2 -1
  6. data/lib/packetgen/header/base.rb +27 -24
  7. data/lib/packetgen/header/bootp.rb +14 -14
  8. data/lib/packetgen/header/dhcp/option.rb +8 -8
  9. data/lib/packetgen/header/dhcp/options.rb +2 -2
  10. data/lib/packetgen/header/dhcp.rb +6 -7
  11. data/lib/packetgen/header/dhcpv6/duid.rb +1 -1
  12. data/lib/packetgen/header/dhcpv6/option.rb +37 -15
  13. data/lib/packetgen/header/dhcpv6/options.rb +3 -3
  14. data/lib/packetgen/header/dhcpv6/relay.rb +1 -0
  15. data/lib/packetgen/header/dhcpv6.rb +13 -14
  16. data/lib/packetgen/header/dns/name.rb +9 -8
  17. data/lib/packetgen/header/dns/opt.rb +3 -0
  18. data/lib/packetgen/header/dns/option.rb +7 -7
  19. data/lib/packetgen/header/dns/qdsection.rb +2 -2
  20. data/lib/packetgen/header/dns/question.rb +1 -0
  21. data/lib/packetgen/header/dns/rrsection.rb +2 -2
  22. data/lib/packetgen/header/dns.rb +76 -60
  23. data/lib/packetgen/header/dot11/control.rb +5 -5
  24. data/lib/packetgen/header/dot11/data.rb +11 -10
  25. data/lib/packetgen/header/dot11/element.rb +1 -1
  26. data/lib/packetgen/header/dot11/management.rb +18 -15
  27. data/lib/packetgen/header/dot11/sub_mngt.rb +22 -21
  28. data/lib/packetgen/header/dot11.rb +38 -38
  29. data/lib/packetgen/header/dot1q.rb +5 -4
  30. data/lib/packetgen/header/dot1x.rb +8 -8
  31. data/lib/packetgen/header/eap/fast.rb +3 -3
  32. data/lib/packetgen/header/eap/md5.rb +11 -3
  33. data/lib/packetgen/header/eap/tls.rb +9 -8
  34. data/lib/packetgen/header/eap/ttls.rb +13 -10
  35. data/lib/packetgen/header/eap.rb +58 -33
  36. data/lib/packetgen/header/eth.rb +26 -12
  37. data/lib/packetgen/header/gre.rb +26 -2
  38. data/lib/packetgen/header/http/headers.rb +6 -5
  39. data/lib/packetgen/header/http/request.rb +24 -16
  40. data/lib/packetgen/header/http/response.rb +22 -15
  41. data/lib/packetgen/header/icmp.rb +10 -10
  42. data/lib/packetgen/header/icmpv6.rb +10 -9
  43. data/lib/packetgen/header/igmp.rb +21 -10
  44. data/lib/packetgen/header/igmpv3/group_record.rb +7 -2
  45. data/lib/packetgen/header/igmpv3/mq.rb +1 -1
  46. data/lib/packetgen/header/igmpv3/mr.rb +1 -1
  47. data/lib/packetgen/header/igmpv3.rb +11 -10
  48. data/lib/packetgen/header/ip/addr.rb +6 -2
  49. data/lib/packetgen/header/ip/option.rb +18 -5
  50. data/lib/packetgen/header/ip.rb +52 -35
  51. data/lib/packetgen/header/ipv6/addr.rb +14 -13
  52. data/lib/packetgen/header/ipv6/extension.rb +9 -7
  53. data/lib/packetgen/header/ipv6/hop_by_hop.rb +26 -7
  54. data/lib/packetgen/header/ipv6.rb +31 -22
  55. data/lib/packetgen/header/llc.rb +20 -13
  56. data/lib/packetgen/header/mdns.rb +9 -2
  57. data/lib/packetgen/header/mld.rb +11 -9
  58. data/lib/packetgen/header/mldv2/mcast_address_record.rb +6 -1
  59. data/lib/packetgen/header/mldv2/mlq.rb +8 -8
  60. data/lib/packetgen/header/mldv2/mlr.rb +4 -4
  61. data/lib/packetgen/header/mldv2.rb +1 -1
  62. data/lib/packetgen/header/ospfv2/db_description.rb +10 -10
  63. data/lib/packetgen/header/ospfv2/hello.rb +11 -10
  64. data/lib/packetgen/header/ospfv2/ls_ack.rb +5 -6
  65. data/lib/packetgen/header/ospfv2/ls_request.rb +7 -6
  66. data/lib/packetgen/header/ospfv2/ls_update.rb +7 -7
  67. data/lib/packetgen/header/ospfv2/lsa.rb +33 -10
  68. data/lib/packetgen/header/ospfv2/lsa_header.rb +3 -2
  69. data/lib/packetgen/header/ospfv2.rb +31 -26
  70. data/lib/packetgen/header/ospfv3/db_description.rb +12 -13
  71. data/lib/packetgen/header/ospfv3/hello.rb +10 -9
  72. data/lib/packetgen/header/ospfv3/ipv6_prefix.rb +6 -2
  73. data/lib/packetgen/header/ospfv3/ls_ack.rb +5 -6
  74. data/lib/packetgen/header/ospfv3/ls_request.rb +10 -10
  75. data/lib/packetgen/header/ospfv3/ls_update.rb +7 -7
  76. data/lib/packetgen/header/ospfv3/lsa.rb +23 -9
  77. data/lib/packetgen/header/ospfv3/lsa_header.rb +3 -2
  78. data/lib/packetgen/header/ospfv3.rb +38 -34
  79. data/lib/packetgen/header/sctp/chunk.rb +38 -17
  80. data/lib/packetgen/header/sctp/error.rb +169 -197
  81. data/lib/packetgen/header/sctp/padded32.rb +3 -3
  82. data/lib/packetgen/header/sctp/parameter.rb +85 -132
  83. data/lib/packetgen/header/sctp.rb +14 -3
  84. data/lib/packetgen/header/snmp.rb +108 -7
  85. data/lib/packetgen/header/tcp/option.rb +7 -0
  86. data/lib/packetgen/header/tcp/options.rb +11 -3
  87. data/lib/packetgen/header/tcp.rb +33 -26
  88. data/lib/packetgen/header/tftp.rb +16 -10
  89. data/lib/packetgen/header/udp.rb +15 -13
  90. data/lib/packetgen/header.rb +19 -13
  91. data/lib/packetgen/headerable.rb +9 -3
  92. data/lib/packetgen/inspect.rb +2 -7
  93. data/lib/packetgen/packet.rb +94 -36
  94. data/lib/packetgen/pcapng/block.rb +2 -1
  95. data/lib/packetgen/pcapng/file.rb +41 -14
  96. data/lib/packetgen/pcapng/idb.rb +2 -1
  97. data/lib/packetgen/pcapng/shb.rb +2 -1
  98. data/lib/packetgen/pcapng/spb.rb +1 -1
  99. data/lib/packetgen/pcapng.rb +2 -0
  100. data/lib/packetgen/proto.rb +4 -0
  101. data/lib/packetgen/unknown_packet.rb +3 -3
  102. data/lib/packetgen/utils.rb +2 -1
  103. data/lib/packetgen/version.rb +1 -1
  104. data/lib/packetgen.rb +8 -2
  105. metadata +4 -4
@@ -57,23 +57,23 @@ module PacketGen
57
57
  # * *
58
58
  # | |
59
59
  # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60
- # +type+, +code+ and +checksum+ are attributes.from {ICMPv6} header.
60
+ # +type+, +code+ and +checksum+ are attributes from {ICMPv6} header.
61
61
  #
62
- # MLQ attributes.are:
63
- # * {#max_resp_code #max_resp_code} ({BinStruct::Int16}),
64
- # * {#reserved #reserved} ({BinStruct::Int16}),
62
+ # MLQ attributes are:
63
+ # * {#max_resp_code #max_resp_code} (+BinStruct::Int16+),
64
+ # * {#reserved #reserved} (+BinStruct::Int16+),
65
65
  # * {#mcast_addr #mcast_addr} ({IPv6::Addr}),
66
- # * {#flags} ({BinStruct::Int8}), with sub-fields:
66
+ # * {#flags} (+BinStruct::Int8+), with sub-fields:
67
67
  # * a 4-bit {#flag_resv} field,
68
68
  # * a 1-bit {#flag_s} boolean,
69
69
  # * a 3-bit {#flag_qrv} field,
70
- # * {#qqic} ({BinStruct::Int8}),
71
- # * {#number_of_sources} ({BinStruct::Int16}),
70
+ # * {#qqic} (+BinStruct::Int8+),
71
+ # * {#number_of_sources} (+BinStruct::Int16+),
72
72
  # * and {#source_addr}, a {IPv6::ArrayOfAddr}.
73
73
  #
74
74
  # == Max Resp Delay
75
75
  # Max Resp Delay is the real delay value. Max Resp Code is the encoded
76
- # delay. So {#max_resp_delay} and {#max_resp_code} attributes reflect this
76
+ # delay. So {#max_resp_delay} and {#max_resp_code #max_resp_code} attributes reflect this
77
77
  # difference.
78
78
  # @author Sylvain Daubert
79
79
  class MLQ < MLD
@@ -38,11 +38,11 @@ module PacketGen
38
38
  # . .
39
39
  # | |
40
40
  # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41
- # +type+, +code+ and +checksum+ are attributes.from {ICMPv6} header.
41
+ # +type+, +code+ and +checksum+ are attributes from {ICMPv6} header.
42
42
  #
43
- # MLR attributes.are:
44
- # * {#reserved} ({BinStruct::Int16}),
45
- # * {#number_of_mar} (number of mcast address records, {BinStruct::Int16}),
43
+ # MLR attributes are:
44
+ # * {#reserved} (+BinStruct::Int16+),
45
+ # * {#number_of_mar} (number of mcast address records, +BinStruct::Int16+),
46
46
  # * {#records} ({McastAddressRecords}).
47
47
  # @author Sylvain Daubert
48
48
  class MLR < Base
@@ -8,7 +8,7 @@
8
8
 
9
9
  module PacketGen
10
10
  module Header
11
- # This module contains all MLDv2 specific classes.
11
+ # This module contains all Multicast Listener Discovery Version 2 (MLDv2) specific classes.
12
12
  # @author Sylvain Daubert
13
13
  # @since 2.4.0
14
14
  module MLDv2
@@ -31,24 +31,26 @@ module PacketGen
31
31
  # | ... |
32
32
  #
33
33
  # A DB description payload is composed of:
34
- # * a 16-bit {#mtu} field ({BinStruct::Int16}),
35
- # * a 8-bit {#options} field ({BinStruct::Int8}),
36
- # * a 8-bit {#flags} field ({BinStruct::Int8}). Supported flags are:
34
+ # * a 16-bit {#mtu} field (+BinStruct::Int16+),
35
+ # * a 8-bit {#options} field (+BinStruct::Int8+),
36
+ # * a 8-bit {#flags} field (+BinStruct::Int8+). Supported flags are:
37
37
  # * {i_flag},
38
38
  # * {m_flag},
39
39
  # * {ms_flag},
40
- # * a 32-bit {#sequence_number} field ({BinStruct::Int32}),
40
+ # * a 32-bit {#sequence_number} field (+BinStruct::Int32+),
41
41
  # * and an array of {LSAHeader LSAHeaders} ({#lsas}, {ArrayOfLSA}).
42
42
  #
43
- # == Create a DbDescription payload
43
+ # @example Create a DbDescription payload
44
44
  # # standalone
45
45
  # dbd = PacketGen::Header::OSPFv2::DbDescription.new
46
46
  # # in a packet
47
- # pkt = PacketGen.gen('IP', src: source_ip).add('OSPFv2').add('OSPFv2::DbDescription')
47
+ # pkt = PacketGen.gen('IP').add('OSPFv2').add('OSPFv2::DbDescription')
48
+ # pkt.ospfize
48
49
  # # access to DbDescription payload
49
- # pkt.ospfv2_dbdescription # => PacketGen::Header::OSPFv2::DbDescription
50
+ # pkt.ospfv2_dbdescription.class # => PacketGen::Header::OSPFv2::DbDescription
50
51
  #
51
- # == DbDescription attributes
52
+ # @example DbDescription attributes
53
+ # dbd = PacketGen::Header::OSPFv2::DbDescription.new
52
54
  # dbd.mtu = 1500
53
55
  # # set options. Options may also be set one by one with {#mt_opt},
54
56
  # # {#e_opt}, {#mc_opt}, {#n_opt}, {#l_opt}, {#dc_opt}, {#o_opt} and {#dn_opt}
@@ -57,8 +59,6 @@ module PacketGen
57
59
  # dbd.seqnum = 0x800001
58
60
  # # add a LSA Router header
59
61
  # dbd.lsas << { type: 'Router', age: 40, link_state_id: '0.0.0.1', advertising_router: '1.1.1.1', sequence_number: 42, checksum: 0x1234, length: 56 }
60
- # # a header may also be set from an existing lsa
61
- # dbd.lsas << existing_lsa.to_lsa_header
62
62
  # @author Sylvain Daubert
63
63
  class DbDescription < Base
64
64
  # @!attribute mtu
@@ -29,25 +29,26 @@ module PacketGen
29
29
  # | ... |
30
30
  # A HELLO payload consists of:
31
31
  # * a {#network_mask} field ({IP::Addr}),
32
- # * a {#hello_interval} field ({BinStruct::Int16}),
33
- # * an {#options} field ({BinStruct::Int8}),
34
- # * a {#priority} field ({BinStruct::Int8}),
35
- # * a {#dead_interval} field ({BinStruct::Int32}),
32
+ # * a {#hello_interval} field (+BinStruct::Int16+),
33
+ # * an {#options} field (+BinStruct::Int8+),
34
+ # * a {#priority} field (+BinStruct::Int8+),
35
+ # * a {#dead_interval} field (+BinStruct::Int32+),
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}.
39
39
  #
40
- # == Create a HELLO payload
40
+ # @example Create a HELLO payload
41
41
  # # standalone
42
42
  # hello = PacketGen::Header::OSPFv2::Hello.new
43
43
  # # in a packet
44
- # pkt = PacketGen.gen('IP', src: source_ip).add('OSPFv2').add('OSPFv2::Hello')
44
+ # pkt = PacketGen.gen('IP').add('OSPFv2').add('OSPFv2::Hello')
45
45
  # # make IP header correct for OSPF
46
46
  # pkt.ospfize
47
47
  # # access to Hello payload
48
- # pkt.ospfv2_hello # => PacketGen::Header::OSPFv2::Hello
48
+ # pkt.ospfv2_hello.class # => PacketGen::Header::OSPFv2::Hello
49
49
  #
50
- # == HELLO attributes
50
+ # @example HELLO attributes
51
+ # hello = PacketGen::Header::OSPFv2::Hello.new
51
52
  # hello.network_mask = '255.255.255.0'
52
53
  # hello.hello_interval = 10
53
54
  # hello.options = 0
@@ -82,12 +83,12 @@ module PacketGen
82
83
  # @return [Integer]
83
84
  define_attr :dead_interval, BinStruct::Int32
84
85
  # @!attribute designated_router
85
- # The identity of the Designated Router for this network, in the
86
+ # The identity (as an IP address) of the Designated Router for this network, in the
86
87
  # view of the sending router.
87
88
  # @return [String]
88
89
  define_attr :designated_router, IP::Addr
89
90
  # @!attribute backup_designated_router
90
- # The identity of the Backup Designated Router for this network,
91
+ # The identity (as an IP address) of the Backup Designated Router for this network,
91
92
  # in the view of the sending router.
92
93
  # @return [String]
93
94
  define_attr :backup_designated_router, IP::Addr
@@ -28,18 +28,17 @@ module PacketGen
28
28
  # This paylod is implemented as a unique field: {#lsas}, which is an
29
29
  # {ArrayOfLSA} object.
30
30
  #
31
- # == Create a LSAck payload
31
+ # @example Create a LSAck payload
32
32
  # # standalone
33
33
  # lsack = PacketGen::Header::OSPFv2::LSAck.new
34
34
  # # in a packet
35
- # pkt = PacketGen.gen('IP', src: source_ip).add('OSPFv2').add('OSPFv2::LSAck')
35
+ # pkt = PacketGen.gen('IP').add('OSPFv2').add('OSPFv2::LSAck')
36
36
  # # access to LSAck payload
37
- # lasck = pkt.ospfv2_lsack # => PacketGen::Header::OSPFv2::LSAck
37
+ # lasck = pkt.ospfv2_lsack.class # => PacketGen::Header::OSPFv2::LSAck
38
38
  #
39
- # == Adding LSA headers to a LSAck payload
39
+ # @example Adding LSA headers to a LSAck payload
40
+ # lsack = PacketGen::Header::OSPFv2::LSAck.new
40
41
  # lsack.lsas << { type: 'Router', age: 40, link_state_id: '0.0.0.1', advertising_router: '1.1.1.1', sequence_number: 42, checksum: 0x1234, length: 56 }
41
- # # a header may also be set from an existing lsa
42
- # lasck.lsas << existing_lsa.to_lsa_header
43
42
  # @author Sylvain Daubert
44
43
  class LSAck < Base
45
44
  # @!attribute lsas
@@ -9,7 +9,7 @@
9
9
  module PacketGen
10
10
  module Header
11
11
  class OSPFv2
12
- # This class handle a LS request, which is composed 3 {BinStruct::Int32} fields:
12
+ # This class handle a LS request, which is composed 3 +BinStruct::Int32+ fields:
13
13
  # * {#type},
14
14
  # * {#link_state_id},
15
15
  # * and {#advertising_router}.
@@ -43,7 +43,7 @@ module PacketGen
43
43
  end
44
44
  end
45
45
 
46
- # This class defines a specialized {BinStruct::Array array} to handle series
46
+ # This class defines a specialized +BinStruct::Array+ to handle series
47
47
  # of {LSR LSRs}.
48
48
  # @author Sylvain Daubert
49
49
  class ArrayOfLSR < BinStruct::Array
@@ -65,17 +65,18 @@ module PacketGen
65
65
  # This paylod is implemented as a unique field: {#lsrs}, which is an
66
66
  # {ArrayOfLSR} object.
67
67
  #
68
- # == Create a LSRequest payload
68
+ # @example Create a LSRequest payload
69
69
  # # standalone
70
70
  # lsr = PacketGen::Header::OSPFv2::LSRequest.new
71
71
  # # in a packet
72
- # pkt = PacketGen.gen('IP', src: source_ip).add('OSPFv2').add('OSPFv2::LSRequest')
72
+ # pkt = PacketGen.gen('IP').add('OSPFv2').add('OSPFv2::LSRequest')
73
73
  # # make IP header correct for OSPF
74
74
  # pkt.ospfize
75
75
  # # access to LSRequest payload
76
- # pkt.ospfv2_lsrequest # => PacketGen::Header::OSPFv2::LSRequest
76
+ # pkt.ospfv2_lsrequest.class # => PacketGen::Header::OSPFv2::LSRequest
77
77
  #
78
- # == Add LSA requests to a LSRequest
78
+ # @example Add LSA requests to a LSRequest
79
+ # lsr = PacketGen::Header::OSPFv2::LSRequest.new
79
80
  # lsr.lsrs << { type: 'Router', link_state_id: '0.0.0.1', advertising_router: '1.1.1.1'}
80
81
  # @author Sylvain Daubert
81
82
  class LSRequest < Base
@@ -22,22 +22,22 @@ module PacketGen
22
22
  # +- +-+
23
23
  # | ... |
24
24
  # This paylod is implemented with two fields:
25
- # * {#lsas_count}, a {BinStruct::Int32} field,
25
+ # * {#lsas_count}, a +BinStruct::Int32+ field,
26
26
  # * and {#lsas}, an {ArrayOfLSA} object.
27
27
  #
28
- # == Create a LSUpdate payload
28
+ # @example Create a LSUpdate payload
29
29
  # # standalone
30
30
  # lsu = PacketGen::Header::OSPFv2::LSUpdate.new
31
31
  # # in a packet
32
- # pkt = PacketGen.gen('IP', src: source_ip).add('OSPFv2').add('OSPFv2::LSUpdate')
32
+ # pkt = PacketGen.gen('IP').add('OSPFv2').add('OSPFv2::LSUpdate')
33
33
  # # make IP header correct for OSPF
34
34
  # pkt.ospfize
35
35
  # # access to LSUpdate payload
36
- # lsu = pkt.ospfv2_lsupdate # => PacketGen::Header::OSPFv2::LSUpdate
36
+ # lsu = pkt.ospfv2_lsupdate.class # => PacketGen::Header::OSPFv2::LSUpdate
37
37
  #
38
- # == Add LSAs to a LSUpdate payload
39
- # Adding LSAs with {ArrayOfLSA#<< ArrayOfLSA#<<} automagically update
40
- # {#lsas_count}. To not update it, use {ArrayOfLSA#push ArrayOfLSA#push}.
38
+ # @example Add LSAs to a LSUpdate payload
39
+ # lsu = PacketGen::Header::OSPFv2::LSUpdate.new
40
+ # # Adding LSAs with #<< automagically update #lsas_count. To not update it, use #push.
41
41
  # lsu.lsas << { type: 'Router', age: 40, link_state_id: '0.0.0.1', advertising_router: '1.1.1.1', sequence_number: 42 }
42
42
  # lsu.lsas_count #=> 1
43
43
  # # add a link to Router LSA
@@ -45,7 +45,7 @@ module PacketGen
45
45
  end
46
46
  end
47
47
 
48
- # This class defines a specialized {BinStruct::Array array} to handle series
48
+ # This class defines a specialized +BinStruct::Array+ to handle series
49
49
  # of {TosMetric TOS metrics}.
50
50
  # @author Sylvain Daubert
51
51
  class ArrayOfTosMetric < BinStruct::Array
@@ -58,18 +58,27 @@ module PacketGen
58
58
  include BinStruct::Structable
59
59
 
60
60
  # @!attribute id
61
+ # Identify the link
61
62
  # @return [IP::Addr]
62
63
  define_attr :id, IP::Addr
63
64
  # @!attribute data
65
+ # Link data
64
66
  # @return [IP::Addr]
65
67
  define_attr :data, IP::Addr
66
68
  # @!attribute type
69
+ # Link type.
70
+ # * 1: Point-to-point connection to another router
71
+ # * 2: Connection to a transit network
72
+ # * 3: Connection to a stub network
73
+ # * 4: Virtual link
67
74
  # @return [Integer]
68
75
  define_attr :type, BinStruct::Int8
69
76
  # @!attribute tos_count
77
+ # Count of #{#tos TOS metrics}
70
78
  # @return [Integer]
71
79
  define_attr :tos_count, BinStruct::Int8
72
80
  # @!attribute metric
81
+ # The cost of using this router link
73
82
  # @return [Integer]
74
83
  define_attr :metric, BinStruct::Int16
75
84
  # @!attribute tos
@@ -77,13 +86,14 @@ module PacketGen
77
86
  # @return [ArrayOfTosMetric]
78
87
  define_attr :tos, ArrayOfTosMetric, builder: ->(h, t) { t.new(counter: h[:tos_count]) }
79
88
 
89
+ # Get human-readable description
80
90
  # @return [String]
81
91
  def to_human
82
92
  "<type:#{type},metric:#{metric},id:#{id},data:#{data}>"
83
93
  end
84
94
  end
85
95
 
86
- # This class defines a specialized {BinStruct::Array array} to handle series
96
+ # This class defines a specialized +BinStruct::Array+ to handle series
87
97
  # of {Link Links}.
88
98
  # @author Sylvain Daubert
89
99
  class ArrayOfLink < BinStruct::Array
@@ -94,8 +104,8 @@ module PacketGen
94
104
  #
95
105
  # A LSA router payload is composed of:
96
106
  # * a header (see methods inherited from {LSAHeader}),
97
- # * a 16-bit flag word {#u16} ({BinStruct::Int16}),
98
- # * a 16-bit {#link_count} field ({BinStruct::Int16}),
107
+ # * a 16-bit flag word {#u16} (+BinStruct::Int16+),
108
+ # * a 16-bit {#link_count} field (+BinStruct::Int16+),
99
109
  # * an array of {#links} ({ArrayOfLink}).
100
110
  # @author Sylvain Daubert
101
111
  class LSARouter < LSAHeader
@@ -103,10 +113,13 @@ module PacketGen
103
113
  # 16-bit flag word
104
114
  # @return [Integer]
105
115
  # @attribute v_flag
116
+ # Virtual link point flag
106
117
  # @return [Integer]
107
- # @attribute e_flag
118
+ # @attribute e_flag*
119
+ # AS boundary flag
108
120
  # @return [Integer]
109
121
  # @attribute b_flag
122
+ # Area border router flag
110
123
  # @return [Integer]
111
124
  define_bit_attr :u16, z: 5, v_flag: 1, e_flag: 1, b_flag: 1, zz: 8
112
125
  # @attribute link_count
@@ -114,6 +127,7 @@ module PacketGen
114
127
  # @return [Integer]
115
128
  define_attr :link_count, BinStruct::Int16
116
129
  # @attribute links
130
+ # Router links
117
131
  # @return [ArrayOfLink]
118
132
  define_attr :links, ArrayOfLink, builder: ->(h, t) { t.new(counter: h[:link_count]) }
119
133
  end
@@ -138,33 +152,42 @@ module PacketGen
138
152
 
139
153
  # This class handles external links in {LSAASExternal LSA AS-External payloads}.
140
154
  # @author Sylvain Daubert
155
+ # @author LemonTree55
141
156
  class External < BinStruct::Struct
142
157
  include BinStruct::Structable
143
158
 
144
159
  # @!attribute u8
160
+ # 1st byte containing {#e_flag} and #{tos}
145
161
  # @return [Integer]
146
162
  # @!attribute e_flag
163
+ # 1-bit type of external metric.
164
+ # If set, {#metric} is Type 2 external metric, else it is Type1.
147
165
  # @return [Integer]
148
166
  # @!attribute tos
167
+ # 7-bit TOS
149
168
  # @return [Integer]
150
169
  define_bit_attr :u8, e_flag: 1, tos: 7
151
170
  # @!attribute metric
171
+ # Cost of this route
152
172
  # @return [Integer]
153
173
  define_attr :metric, BinStruct::Int24
154
174
  # @!attribute forwarding_addr
175
+ # Forwarding address
155
176
  # @return [IP::Addr]
156
177
  define_attr :forwarding_addr, IP::Addr
157
178
  # @!attribute ext_route_tag
179
+ # 32-bit external route tag. Not used by OSPF protocol.
158
180
  # @return [Integer]
159
181
  define_attr :ext_route_tag, BinStruct::Int32
160
182
 
183
+ # Get human-readable string
161
184
  # @return [String]
162
185
  def to_human
163
186
  "<type:#{e_flag? ? 2 : 1},tos:#{tos},metric:#{metric},fwaddr:#{forwarding_addr},tag:#{ext_route_tag}>"
164
187
  end
165
188
  end
166
189
 
167
- # This class defines a specialized {BinStruct::Array array} to handle series
190
+ # This class defines a specialized +BinStruct::Array+ to handle series
168
191
  # of {External Externals}.
169
192
  # @author Sylvain Daubert
170
193
  class ArrayOfExternal < BinStruct::Array
@@ -189,18 +212,18 @@ module PacketGen
189
212
  builder: ->(h, t) { t.new(length_from: -> { h.length - 24 }) }
190
213
  end
191
214
 
192
- # This class defines a specialized {BinStruct::Array array} to handle series
215
+ # This class defines a specialized +BinStruct::Array+ to handle series
193
216
  # of {LSA LSAs}. It recognizes known LSA types and infers correct type.
194
217
  # @author Sylvain Daubert
195
218
  class ArrayOfLSA < BinStruct::Array
196
219
  set_of LSAHeader
197
220
 
198
221
  # @param [Hash] options
199
- # @option options [BinStruct::Int] counter Int object used as a counter for this set
200
- # @option options [Boolean] only_headers if +true+, only {LSAHeader LSAHeaders}
222
+ # @option options [BinStruct::Int] :counter +BinStruct::Int+ object used as a counter for this set
223
+ # @option options [Boolean] :only_headers if +true+, only {LSAHeader LSAHeaders}
201
224
  # will be added to this array.
202
225
  def initialize(options={})
203
- super()
226
+ super
204
227
  @only_headers = options[:only_headers] || false
205
228
  end
206
229
 
@@ -75,7 +75,7 @@ module PacketGen
75
75
  # @return [Integer]
76
76
  define_attr :length, BinStruct::Int16
77
77
 
78
- # Compute and set Fletcher-16 checksum on LSA
78
+ # Compute and set Fletcher-16 {#checksum} on LSA
79
79
  # @return [Integer]
80
80
  def calc_checksum
81
81
  c0 = c1 = 0
@@ -93,7 +93,7 @@ module PacketGen
93
93
  self.checksum = (x << 8) | y
94
94
  end
95
95
 
96
- # Compute length and set +length+ field
96
+ # Compute length and set {#length} field
97
97
  # @return [Integer]
98
98
  def calc_length
99
99
  self.length = Base.calculate_and_set_length(self)
@@ -105,6 +105,7 @@ module PacketGen
105
105
  self[:type].to_human
106
106
  end
107
107
 
108
+ # Get human-readable description
108
109
  # @return [String]
109
110
  def to_human
110
111
  "LSA<#{human_type},#{link_state_id},#{advertising_router}>"
@@ -9,7 +9,7 @@
9
9
  module PacketGen
10
10
  module Header
11
11
  # This class supports OSPFv2 (RFC 2328).
12
- # A OSPFv2 header has the following format:
12
+ # An OSPFv2 header has the following format:
13
13
  #
14
14
  # 0 1 2 3
15
15
  # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@@ -28,37 +28,38 @@ module PacketGen
28
28
  # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29
29
  #
30
30
  # An OSPFv2 header consists of:
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}).
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+ or {Headerable}).
40
40
  #
41
- # == Create an OSPFv2 header
41
+ # @example Create an OSPFv2 header
42
42
  # # standalone
43
43
  # ospf = PacketGen::Header::OSPFv2.new
44
44
  # # in a packet
45
- # pkt = PacketGen.gen('IP', src: source_ip).add('OSPFv2')
45
+ # pkt = PacketGen.gen('IP').add('OSPFv2')
46
46
  # # make IP header correct for OSPF
47
47
  # pkt.ospfize
48
48
  # # or make it correct with specific destination address
49
49
  # pkt.ospfize(dst: :all_spf_routers)
50
50
  # # access to OSPF header
51
- # pkt.ospfv2 # => PacketGen::Header::OSPFv2
51
+ # pkt.ospfv2.class # => PacketGen::Header::OSPFv2
52
52
  #
53
- # == OSPFv2 attributes
54
- # ospf.version # => 2
55
- # ospf.type = 'LS_ACK' # or 5
56
- # ospf.length = 154
57
- # ospf.router_id = 0xc0a80001
58
- # ospf.area_id = 1
59
- # ospf.checksum = 0xabcd
60
- # ospf.au_type = 'NO_AUTH' # or 0
61
- # ospf.authentication = 0
53
+ # @example OSPFv2 attributes
54
+ # ospf = PacketGen::Header::OSPFv2.new
55
+ # ospf.version # => 2
56
+ # ospf.type = 'LS_ACK' # or 5
57
+ # ospf.length = 154
58
+ # ospf.router_id = 0xc0a80001
59
+ # ospf.area_id = 1
60
+ # ospf.checksum = 0xabcd
61
+ # ospf.au_type = 'NO_AUTH' # or 0
62
+ # ospf.authentication = 0
62
63
  #
63
64
  # == OSPFv2 body
64
65
  # OSPFv2 {#body} should contain OSPF payload for given {#type}:
@@ -124,7 +125,8 @@ module PacketGen
124
125
  # @return [Integer]
125
126
  define_attr :authentication, BinStruct::Int64
126
127
  # @!attribute body
127
- # @return [String,Base]
128
+ # OSPF body
129
+ # @return [String,Headerable]
128
130
  define_attr :body, BinStruct::String
129
131
 
130
132
  # @api private
@@ -164,12 +166,15 @@ module PacketGen
164
166
  # @api private
165
167
  # @note This method is used internally by PacketGen and should not be
166
168
  # directly called
169
+ # @param [Packet] packet
170
+ # @return [void]
171
+ # Add +#ospfize+ method to +packet+. This method calls {#ospfize}.
167
172
  def added_to_packet(packet)
168
173
  ospf_idx = packet.headers.size
169
174
  packet.instance_eval "def ospfize(**kwargs) @headers[#{ospf_idx}].ospfize(**kwargs); end" # def ospfize(**kwargs) @headers[2].ospfize(**kwargs); end
170
175
  end
171
176
 
172
- # Compute checksum and set +checksum+ field
177
+ # Compute checksum and set {#checksum} attribute
173
178
  # @return [Integer]
174
179
  def calc_checksum
175
180
  # #authentication field is not used in checksum calculation,
@@ -198,7 +203,7 @@ module PacketGen
198
203
  self[:au_type].to_human
199
204
  end
200
205
 
201
- # Compute length and set +length+ field
206
+ # Compute length and set {#length} attribute
202
207
  # @return [Integer]
203
208
  def calc_length
204
209
  self[:length].value = Base.calculate_and_set_length(self)
@@ -213,7 +218,7 @@ module PacketGen
213
218
  # pkt.ospfv2.ospfize
214
219
  # # second way
215
220
  # pkt.ospfize
216
- # @param [String,Symbol,nil] dst destination address. May be a dotted IP
221
+ # @param [String,Symbolnil] dst destination address. May be a dotted IP
217
222
  # address (by example '224.0.0.5') or a Symbol (+:all_spf_routers+ or
218
223
  # +:all_d_routers+)
219
224
  # @return [void]
@@ -33,25 +33,26 @@ module PacketGen
33
33
  # | ... |
34
34
  #
35
35
  # A DB description payload is composed of:
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:
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 ({BinStruct::Int32}),
43
+ # * a 32-bit {#sequence_number} field (+BinStruct::Int32+),
44
44
  # * and an array of {LSAHeader LSAHeaders} ({#lsas}, {ArrayOfLSA}).
45
45
  #
46
- # == Create a DbDescription payload
46
+ # @example Create a DbDescription payload
47
47
  # # standalone
48
48
  # dbd = PacketGen::Header::OSPFv3::DbDescription.new
49
49
  # # in a packet
50
- # pkt = PacketGen.gen('IPv6', src: source_ip).add('OSPFv3').add('OSPFv3::DbDescription')
50
+ # pkt = PacketGen.gen('IPv6').add('OSPFv3').add('OSPFv3::DbDescription')
51
51
  # # access to DbDescription payload
52
- # pkt.ospfv3_dbdescription # => PacketGen::Header::OSPFv3::DbDescription
52
+ # pkt.ospfv3_dbdescription.class # => PacketGen::Header::OSPFv3::DbDescription
53
53
  #
54
- # == DbDescription attributes
54
+ # @example DbDescription attributes
55
+ # dbd = PacketGen::Header::OSPFv3::DbDescription.new
55
56
  # dbd.reserved = 0
56
57
  # # set options. Options may also be set one by one with #v6_opt, #e_opt,
57
58
  # # #n_opt, #r_opt and #dc_opt
@@ -61,8 +62,6 @@ module PacketGen
61
62
  # dbd.seqnum = 0x800001
62
63
  # # add a LSA Router header
63
64
  # dbd.lsas << { type: 'Router', age: 40, link_state_id: '0.0.0.1', advertising_router: '1.1.1.1', sequence_number: 42, checksum: 0x1234, length: 56 }
64
- # # a header may also be set from an existing lsa
65
- # dbd.lsas << existing_lsa.to_lsa_header
66
65
  # @author Sylvain Daubert
67
66
  class DbDescription < Base
68
67
  # @!attribute reserved
@@ -70,7 +69,7 @@ module PacketGen
70
69
  # @return [Integer]
71
70
  define_attr :reserved, BinStruct::Int8, default: 0
72
71
 
73
- # @!macro define_options
72
+ # @!macro define_ospfv3_options
74
73
  OSPFv3.define_options(self)
75
74
 
76
75
  # @!attribute mtu
@@ -101,7 +100,7 @@ module PacketGen
101
100
 
102
101
  # @!attribute lsas
103
102
  # Array of LSA headers
104
- # @return [ArrayOfLSAHeader]
103
+ # @return [ArrayOfLSA]
105
104
  define_attr :lsas, ArrayOfLSA, builder: ->(_h, t) { t.new(only_headers: true) }
106
105
  end
107
106
  end
@@ -28,26 +28,27 @@ module PacketGen
28
28
  # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29
29
  # | ... |
30
30
  # A HELLO payload consists of:
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}),
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}.
39
39
  #
40
- # == Create a HELLO payload
40
+ # @example Create a HELLO payload
41
41
  # # standalone
42
42
  # hello = PacketGen::Header::OSPFv3::Hello.new
43
43
  # # in a packet
44
- # pkt = PacketGen.gen('IPv6', src: source_ip).add('OSPFv3').add('OSPFv3::Hello')
44
+ # pkt = PacketGen.gen('IPv6').add('OSPFv3').add('OSPFv3::Hello')
45
45
  # # make IPv6 header correct for OSPF
46
46
  # pkt.ospfize
47
47
  # # access to Hello payload
48
- # pkt.ospfv3_hello # => PacketGen::Header::OSPFv3::Hello
48
+ # pkt.ospfv3_hello.class # => PacketGen::Header::OSPFv3::Hello
49
49
  #
50
- # == HELLO attributes
50
+ # @example HELLO attributes
51
+ # hello = PacketGen::Header::OSPFv3::Hello.new
51
52
  # hello.interface_id = 1
52
53
  # hello.priority = 1
53
54
  # # set options. Options may also be set one by one with #v6_opt, #e_opt,