woolen_common 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/README.md +31 -0
- data/ext/woolen_common/extconf.rb +26 -0
- data/ext/woolen_common/linux.h +3 -0
- data/ext/woolen_common/win.c +18 -0
- data/ext/woolen_common/win.h +4 -0
- data/ext/woolen_common/win/puts_color.c +139 -0
- data/ext/woolen_common/win/puts_color.h +5 -0
- data/ext/woolen_common/woolen_common.c +20 -0
- data/ext/woolen_common/woolen_common.h +7 -0
- data/lib/woolen_common.rb +39 -0
- data/lib/woolen_common/abstract_middleware/builder.rb +138 -0
- data/lib/woolen_common/abstract_middleware/map_cfg_manager.rb +52 -0
- data/lib/woolen_common/abstract_middleware/runner.rb +72 -0
- data/lib/woolen_common/action_pool_proxy.rb +28 -0
- data/lib/woolen_common/actionpool.rb +10 -0
- data/lib/woolen_common/actionpool/pool.rb +295 -0
- data/lib/woolen_common/actionpool/queue.rb +41 -0
- data/lib/woolen_common/actionpool/thread.rb +181 -0
- data/lib/woolen_common/addr_helper.rb +93 -0
- data/lib/woolen_common/cache.rb +305 -0
- data/lib/woolen_common/common_helper.rb +42 -0
- data/lib/woolen_common/config_manager.rb +36 -0
- data/lib/woolen_common/drb_helper.rb +125 -0
- data/lib/woolen_common/ffi/win32_kernel32.rb +86 -0
- data/lib/woolen_common/logger.rb +419 -0
- data/lib/woolen_common/pcap/mu/fixnum_ext.rb +8 -0
- data/lib/woolen_common/pcap/mu/pcap/ethernet.rb +164 -0
- data/lib/woolen_common/pcap/mu/pcap/header.rb +76 -0
- data/lib/woolen_common/pcap/mu/pcap/io_pair.rb +68 -0
- data/lib/woolen_common/pcap/mu/pcap/io_wrapper.rb +77 -0
- data/lib/woolen_common/pcap/mu/pcap/ip.rb +62 -0
- data/lib/woolen_common/pcap/mu/pcap/ipv4.rb +274 -0
- data/lib/woolen_common/pcap/mu/pcap/ipv6.rb +149 -0
- data/lib/woolen_common/pcap/mu/pcap/packet.rb +106 -0
- data/lib/woolen_common/pcap/mu/pcap/pkthdr.rb +162 -0
- data/lib/woolen_common/pcap/mu/pcap/reader.rb +62 -0
- data/lib/woolen_common/pcap/mu/pcap/reader/http_family.rb +175 -0
- data/lib/woolen_common/pcap/mu/pcap/sctp.rb +369 -0
- data/lib/woolen_common/pcap/mu/pcap/sctp/chunk.rb +124 -0
- data/lib/woolen_common/pcap/mu/pcap/sctp/chunk/data.rb +135 -0
- data/lib/woolen_common/pcap/mu/pcap/sctp/chunk/init.rb +101 -0
- data/lib/woolen_common/pcap/mu/pcap/sctp/chunk/init_ack.rb +69 -0
- data/lib/woolen_common/pcap/mu/pcap/sctp/parameter.rb +111 -0
- data/lib/woolen_common/pcap/mu/pcap/sctp/parameter/ip_address.rb +49 -0
- data/lib/woolen_common/pcap/mu/pcap/stream_packetizer.rb +74 -0
- data/lib/woolen_common/pcap/mu/pcap/tcp.rb +522 -0
- data/lib/woolen_common/pcap/mu/pcap/udp.rb +81 -0
- data/lib/woolen_common/pcap/mu/scenario/pcap.rb +175 -0
- data/lib/woolen_common/pcap/mu/scenario/pcap/fields.rb +51 -0
- data/lib/woolen_common/pcap/mu/scenario/pcap/rtp.rb +72 -0
- data/lib/woolen_common/pcap/pcap.rb +115 -0
- data/lib/woolen_common/pcap/readme.md +72 -0
- data/lib/woolen_common/ruby_ext/blank.rb +126 -0
- data/lib/woolen_common/ruby_ext/drb_ext.rb +7 -0
- data/lib/woolen_common/ruby_ext/string.rb +116 -0
- data/lib/woolen_common/ruby_ext/win32_ole.rb +4 -0
- data/lib/woolen_common/ruby_proxy.rb +5 -0
- data/lib/woolen_common/ruby_proxy/client.rb +305 -0
- data/lib/woolen_common/ruby_proxy/config.rb +44 -0
- data/lib/woolen_common/ruby_proxy/exceptions.rb +17 -0
- data/lib/woolen_common/ruby_proxy/proxy.rb +157 -0
- data/lib/woolen_common/ruby_proxy/proxy_global_set.rb +44 -0
- data/lib/woolen_common/ruby_proxy/proxy_load.rb +34 -0
- data/lib/woolen_common/ruby_proxy/server.rb +53 -0
- data/lib/woolen_common/splib.rb +36 -0
- data/lib/woolen_common/splib/Array.rb +33 -0
- data/lib/woolen_common/splib/CodeReloader.rb +59 -0
- data/lib/woolen_common/splib/Constants.rb +44 -0
- data/lib/woolen_common/splib/Conversions.rb +47 -0
- data/lib/woolen_common/splib/Exec.rb +132 -0
- data/lib/woolen_common/splib/Float.rb +13 -0
- data/lib/woolen_common/splib/HumanIdealRandomIterator.rb +40 -0
- data/lib/woolen_common/splib/Monitor.rb +214 -0
- data/lib/woolen_common/splib/PriorityQueue.rb +110 -0
- data/lib/woolen_common/splib/Sleep.rb +10 -0
- data/lib/woolen_common/splib/UrlShorteners.rb +48 -0
- data/lib/woolen_common/ssh_proxy.rb +146 -0
- data/lib/woolen_common/system_helper.rb +123 -0
- data/lib/woolen_common/system_monitor.rb +23 -0
- data/lib/woolen_common/system_monitor/linux_monitor.rb +250 -0
- data/lib/woolen_common/system_monitor/windows_monitor.rb +145 -0
- data/lib/woolen_common/type_helper.rb +42 -0
- data/lib/woolen_common/ver_ctrl_middle_ware.rb +92 -0
- data/lib/woolen_common/version.rb +3 -0
- metadata +210 -0
@@ -0,0 +1,124 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# http://www.mudynamics.com
|
3
|
+
# http://labs.mudynamics.com
|
4
|
+
# http://www.pcapr.net
|
5
|
+
|
6
|
+
module Mu
|
7
|
+
class Pcap
|
8
|
+
class SCTP
|
9
|
+
|
10
|
+
class Chunk < Packet
|
11
|
+
attr_accessor :type, :flags, :size
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super
|
15
|
+
|
16
|
+
@type = 0
|
17
|
+
@flags = 0
|
18
|
+
@size = 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.from_bytes bytes
|
22
|
+
# Basic validation
|
23
|
+
Pcap.assert(bytes.length >= 4,
|
24
|
+
"Truncated chunk header: 4 > #{bytes.length}")
|
25
|
+
|
26
|
+
# Read chunk header
|
27
|
+
type, flags, size = bytes.unpack('CCn')
|
28
|
+
|
29
|
+
# Validate chunk size
|
30
|
+
Pcap.assert(bytes.length >= size,
|
31
|
+
"Truncated chunk: #{size} set, #{bytes.length} available")
|
32
|
+
|
33
|
+
# Create chunk based on type
|
34
|
+
case type
|
35
|
+
when CHUNK_DATA
|
36
|
+
chunk = Data.from_bytes(flags, size, bytes[4..-1])
|
37
|
+
when CHUNK_INIT
|
38
|
+
chunk = Init.from_bytes(flags, size, bytes[4..-1])
|
39
|
+
when CHUNK_INIT_ACK
|
40
|
+
chunk = InitAck.from_bytes(flags, size, bytes[4..-1])
|
41
|
+
when CHUNK_SACK
|
42
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
43
|
+
when CHUNK_HEARTBEAT
|
44
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
45
|
+
when CHUNK_HEARTBEAT_ACK
|
46
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
47
|
+
when CHUNK_ABORT
|
48
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
49
|
+
when CHUNK_SHUTDOWN
|
50
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
51
|
+
when CHUNK_SHUTDOWN_ACK
|
52
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
53
|
+
when CHUNK_ERROR
|
54
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
55
|
+
when CHUNK_COOKIE_ECHO
|
56
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
57
|
+
when CHUNK_COOKIE_ACK
|
58
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
59
|
+
when CHUNK_ECNE
|
60
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
61
|
+
when CHUNK_CWR
|
62
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
63
|
+
when CHUNK_SHUTDOWN_COMPLETE
|
64
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
65
|
+
when CHUNK_AUTH
|
66
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
67
|
+
when CHUNK_ASCONF_ACK
|
68
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
69
|
+
when CHUNK_PADDING
|
70
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
71
|
+
when CHUNK_FORWARD_TSN
|
72
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
73
|
+
when CHUNK_ASCONF
|
74
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
75
|
+
else
|
76
|
+
chunk = dummy_chunk(type, flags, size, bytes)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Return the result
|
80
|
+
return chunk
|
81
|
+
end
|
82
|
+
|
83
|
+
def write io, ip
|
84
|
+
header = [@type, @flags, @size].pack('CCn')
|
85
|
+
|
86
|
+
# Write Chunk header followed by the payload
|
87
|
+
io.write(header)
|
88
|
+
io.write(@payload_raw)
|
89
|
+
end
|
90
|
+
|
91
|
+
def padded_size
|
92
|
+
if 0 == @size % 4
|
93
|
+
return @size
|
94
|
+
else
|
95
|
+
return (@size + 4 - (@size % 4))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def to_s
|
100
|
+
return "chunk(%d, %d, %d)" % [@type, @flags, @size]
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.dummy_chunk type, flags, size, bytes
|
104
|
+
# Create new dummy chunk
|
105
|
+
chunk = Chunk.new
|
106
|
+
chunk.type = type
|
107
|
+
chunk.flags = flags
|
108
|
+
chunk.size = size
|
109
|
+
|
110
|
+
# Save the payload
|
111
|
+
chunk.payload_raw = chunk.payload = bytes[4..chunk.padded_size]
|
112
|
+
|
113
|
+
# Return the result
|
114
|
+
return chunk
|
115
|
+
end
|
116
|
+
end # class Chunk
|
117
|
+
|
118
|
+
end # class SCTP
|
119
|
+
end # class Pcap
|
120
|
+
end # module Mu
|
121
|
+
|
122
|
+
require 'mu/pcap/sctp/chunk/data'
|
123
|
+
require 'mu/pcap/sctp/chunk/init'
|
124
|
+
require 'mu/pcap/sctp/chunk/init_ack'
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# http://www.mudynamics.com
|
3
|
+
# http://labs.mudynamics.com
|
4
|
+
# http://www.pcapr.net
|
5
|
+
|
6
|
+
module Mu
|
7
|
+
class Pcap
|
8
|
+
class SCTP
|
9
|
+
class Chunk
|
10
|
+
|
11
|
+
class Data < Chunk
|
12
|
+
FLAG_LAST_SEG = 0x01
|
13
|
+
FLAG_FIRST_SEG = 0x02
|
14
|
+
FLAG_UNORDERED = 0x04
|
15
|
+
|
16
|
+
attr_accessor :tsn, :sid, :ssn, :ppid
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
|
21
|
+
@type = CHUNK_DATA
|
22
|
+
@tsn = 0
|
23
|
+
@sid = 0
|
24
|
+
@ssn = 0
|
25
|
+
@ppid = 0
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.from_bytes flags, size, bytes
|
29
|
+
# Basic validation
|
30
|
+
Pcap.assert(bytes.length >= 12,
|
31
|
+
"Truncated data chunk header: 12 > #{bytes.length}")
|
32
|
+
|
33
|
+
# Read init chunk header
|
34
|
+
tsn, sid, ssn, ppid = bytes.unpack('NnnN')
|
35
|
+
|
36
|
+
# Create data chunk
|
37
|
+
data = Data.new
|
38
|
+
data.flags = flags
|
39
|
+
data.size = size
|
40
|
+
data.tsn = tsn
|
41
|
+
data.sid = sid
|
42
|
+
data.ssn = ssn
|
43
|
+
data.ppid = ppid
|
44
|
+
|
45
|
+
# Save the payload
|
46
|
+
data.payload_raw = data.payload = bytes[12..size - 5]
|
47
|
+
|
48
|
+
# Return the result
|
49
|
+
return data
|
50
|
+
end
|
51
|
+
|
52
|
+
def write io, ip
|
53
|
+
chunk_header = [@type, @flags, @size].pack('CCn')
|
54
|
+
data_header = [@tsn, @sid, @ssn, @ppid].pack('NnnN')
|
55
|
+
|
56
|
+
# Write Chunk header followed by the Data chunk header and payload
|
57
|
+
io.write(chunk_header)
|
58
|
+
io.write(data_header)
|
59
|
+
io.write(@payload_raw)
|
60
|
+
|
61
|
+
# Write padding, if necessary
|
62
|
+
if size < padded_size
|
63
|
+
(padded_size - size).times do
|
64
|
+
io.write("\x00")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def ordered?
|
70
|
+
if 0 == @flags[2]
|
71
|
+
return true
|
72
|
+
else
|
73
|
+
return false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def first_segment?
|
78
|
+
if 1 == @flags[1] and 0 == @flags[0]
|
79
|
+
return true
|
80
|
+
else
|
81
|
+
return false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def last_segment?
|
86
|
+
if 0 == @flags[1] and 1 == @flags[0]
|
87
|
+
return true
|
88
|
+
else
|
89
|
+
return false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def complete_segment?
|
94
|
+
if 1 == @flags[1] and 1 == @flags[0]
|
95
|
+
return true
|
96
|
+
else
|
97
|
+
return false
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def to_s
|
102
|
+
flags_s = '['
|
103
|
+
|
104
|
+
if ordered?
|
105
|
+
flags_s += 'ordered, '
|
106
|
+
else
|
107
|
+
flags_s += 'unordered, '
|
108
|
+
end
|
109
|
+
|
110
|
+
if complete_segment?
|
111
|
+
flags_s += 'complete segment'
|
112
|
+
elsif first_segment?
|
113
|
+
flags_s += 'first segment'
|
114
|
+
elsif last_segment?
|
115
|
+
flags_s += 'last segment'
|
116
|
+
else
|
117
|
+
flags_s += 'middle segment'
|
118
|
+
end
|
119
|
+
|
120
|
+
flags_s += ']'
|
121
|
+
|
122
|
+
return "data(%s, %d, %d, %d, %d, %d, %s)" % [flags_s,
|
123
|
+
@size,
|
124
|
+
@tsn,
|
125
|
+
@sid,
|
126
|
+
@ssn,
|
127
|
+
@ppid,
|
128
|
+
@payload.inspect]
|
129
|
+
end
|
130
|
+
end # class Data
|
131
|
+
|
132
|
+
end # class Chunk
|
133
|
+
end # class SCTP
|
134
|
+
end # class Pcap
|
135
|
+
end # module Mu
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# http://www.mudynamics.com
|
3
|
+
# http://labs.mudynamics.com
|
4
|
+
# http://www.pcapr.net
|
5
|
+
|
6
|
+
module Mu
|
7
|
+
class Pcap
|
8
|
+
class SCTP
|
9
|
+
class Chunk
|
10
|
+
|
11
|
+
class Init < Chunk
|
12
|
+
attr_accessor :init_tag, :a_rwnd, :o_streams, :i_streams, :init_tsn
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
super
|
16
|
+
|
17
|
+
@type = CHUNK_INIT
|
18
|
+
@init_tag = 0
|
19
|
+
@a_rwnd = 0
|
20
|
+
@o_streams = 0
|
21
|
+
@i_streams = 0
|
22
|
+
@init_tsn = 0
|
23
|
+
@payload = []
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.from_bytes flags, size, bytes
|
27
|
+
# Basic validation
|
28
|
+
Pcap.assert(bytes.length >= 16,
|
29
|
+
"Truncated init chunk header: 16 > #{bytes.length}")
|
30
|
+
|
31
|
+
# Read init chunk header
|
32
|
+
init_tag, a_rwnd, o_streams, i_streams, init_tsn = bytes.unpack('NNnnN')
|
33
|
+
|
34
|
+
# Create init chunk
|
35
|
+
init = Init.new
|
36
|
+
init.flags = flags
|
37
|
+
init.size = size
|
38
|
+
init.init_tag = init_tag
|
39
|
+
init.a_rwnd = a_rwnd
|
40
|
+
init.o_streams = o_streams
|
41
|
+
init.i_streams = i_streams
|
42
|
+
init.init_tsn = init_tsn
|
43
|
+
|
44
|
+
# Initialize the counter
|
45
|
+
length = 16
|
46
|
+
|
47
|
+
# Collect the chunks
|
48
|
+
while length < bytes.length
|
49
|
+
# Parse new parameter from the bytes
|
50
|
+
parameter = Parameter.from_bytes(bytes[length..-1])
|
51
|
+
|
52
|
+
# Get parameter size with padding
|
53
|
+
length += parameter.padded_size
|
54
|
+
|
55
|
+
# Add chunk to the list
|
56
|
+
init << parameter
|
57
|
+
end
|
58
|
+
|
59
|
+
# Return the result
|
60
|
+
return init
|
61
|
+
end
|
62
|
+
|
63
|
+
def write io, ip
|
64
|
+
chunk_header = [@type, @flags, @size].pack('CCn')
|
65
|
+
init_header = [@init_tag,
|
66
|
+
@a_rwnd,
|
67
|
+
@o_streams,
|
68
|
+
@i_streams,
|
69
|
+
@init_tsn].pack('NNnnN')
|
70
|
+
|
71
|
+
# Write Chunk header followed by the Init chunk header
|
72
|
+
io.write(chunk_header)
|
73
|
+
io.write(init_header)
|
74
|
+
|
75
|
+
# Write each parameter
|
76
|
+
@payload.each do |parameter|
|
77
|
+
parameter.write(io, ip)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def << parameter
|
82
|
+
@payload << parameter
|
83
|
+
end
|
84
|
+
|
85
|
+
def to_s
|
86
|
+
return "init(%d, %d, %d, %d, %d, %d, %s)" % [@size,
|
87
|
+
@init_tag,
|
88
|
+
@a_rwnd,
|
89
|
+
@o_streams,
|
90
|
+
@i_streams,
|
91
|
+
@init_tsn,
|
92
|
+
@payload.join(", ")]
|
93
|
+
end
|
94
|
+
end # class Init
|
95
|
+
|
96
|
+
end # class Chunk
|
97
|
+
end # class SCTP
|
98
|
+
end # class Pcap
|
99
|
+
end # module Mu
|
100
|
+
|
101
|
+
require 'mu/pcap/sctp/parameter'
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# http://www.mudynamics.com
|
3
|
+
# http://labs.mudynamics.com
|
4
|
+
# http://www.pcapr.net
|
5
|
+
|
6
|
+
module Mu
|
7
|
+
class Pcap
|
8
|
+
class SCTP
|
9
|
+
class Chunk
|
10
|
+
|
11
|
+
class InitAck < Init
|
12
|
+
def initialize
|
13
|
+
super
|
14
|
+
|
15
|
+
@type = CHUNK_INIT_ACK
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.from_bytes flags, size, bytes
|
19
|
+
# Basic validation
|
20
|
+
Pcap.assert(bytes.length >= 16,
|
21
|
+
"Truncated init_ack chunk header: 16 > #{bytes.length}")
|
22
|
+
|
23
|
+
# Read init_ack chunk header
|
24
|
+
init_tag, a_rwnd, o_streams, i_streams, init_tsn = bytes.unpack('NNnnN')
|
25
|
+
|
26
|
+
# Create init chunk
|
27
|
+
init_ack = InitAck.new
|
28
|
+
init_ack.flags = flags
|
29
|
+
init_ack.size = size
|
30
|
+
init_ack.init_tag = init_tag
|
31
|
+
init_ack.a_rwnd = a_rwnd
|
32
|
+
init_ack.o_streams = o_streams
|
33
|
+
init_ack.i_streams = i_streams
|
34
|
+
init_ack.init_tsn = init_tsn
|
35
|
+
|
36
|
+
# Initialize the counter
|
37
|
+
length = 16
|
38
|
+
|
39
|
+
# Collect the chunks
|
40
|
+
while length < bytes.length
|
41
|
+
# Parse new parameter from the bytes
|
42
|
+
parameter = Parameter.from_bytes(bytes[length..-1])
|
43
|
+
|
44
|
+
# Get parameter size with padding
|
45
|
+
length += parameter.padded_size
|
46
|
+
|
47
|
+
# Add chunk to the list
|
48
|
+
init_ack << parameter
|
49
|
+
end
|
50
|
+
|
51
|
+
# Return the result
|
52
|
+
return init_ack
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_s
|
56
|
+
return "init_ack(%d, %d, %d, %d, %d, %d, %s)" % [@size,
|
57
|
+
@init_tag,
|
58
|
+
@a_rwnd,
|
59
|
+
@o_streams,
|
60
|
+
@i_streams,
|
61
|
+
@init_tsn,
|
62
|
+
@payload.join(", ")]
|
63
|
+
end
|
64
|
+
end # class InitAck
|
65
|
+
|
66
|
+
end # class Chunk
|
67
|
+
end # class SCTP
|
68
|
+
end # class Pcap
|
69
|
+
end # module Mu
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# http://www.mudynamics.com
|
3
|
+
# http://labs.mudynamics.com
|
4
|
+
# http://www.pcapr.net
|
5
|
+
|
6
|
+
module Mu
|
7
|
+
class Pcap
|
8
|
+
class SCTP
|
9
|
+
|
10
|
+
class Parameter < Packet
|
11
|
+
attr_accessor :type, :size
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super
|
15
|
+
|
16
|
+
@type = 0
|
17
|
+
@size = 0
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.from_bytes bytes
|
21
|
+
# Basic validation
|
22
|
+
Pcap.assert(bytes.length >= 4,
|
23
|
+
"Truncated parameter header: 4 > #{bytes.length}")
|
24
|
+
|
25
|
+
# Read chunk header
|
26
|
+
type, size = bytes.unpack('nn')
|
27
|
+
|
28
|
+
# Validate chunk size
|
29
|
+
Pcap.assert(bytes.length >= size,
|
30
|
+
"Truncated parameter: #{size} set, #{bytes.length} available")
|
31
|
+
|
32
|
+
# Create chunk based on type
|
33
|
+
case type
|
34
|
+
when PARAM_IPV4
|
35
|
+
parameter = IpAddress.from_bytes(type, size, bytes[4..-1])
|
36
|
+
when PARAM_IPV6
|
37
|
+
parameter = IpAddress.from_bytes(type, size, bytes[4..-1])
|
38
|
+
when PARAM_STATE_COOKIE
|
39
|
+
parameter = dummy_parameter(type, size, bytes)
|
40
|
+
when PARAM_COOKIE_PRESERVATIVE
|
41
|
+
parameter = dummy_parameter(type, size, bytes)
|
42
|
+
when PARAM_HOST_NAME_ADDR
|
43
|
+
parameter = dummy_parameter(type, size, bytes)
|
44
|
+
when PARAM_SUPPORTED_ADDR_TYPES
|
45
|
+
parameter = dummy_parameter(type, size, bytes)
|
46
|
+
when PARAM_ECN
|
47
|
+
parameter = dummy_parameter(type, size, bytes)
|
48
|
+
when PARAM_RANDOM
|
49
|
+
parameter = dummy_parameter(type, size, bytes)
|
50
|
+
when PARAM_CHUNK_LIST
|
51
|
+
parameter = dummy_parameter(type, size, bytes)
|
52
|
+
when PARAM_HMAC_ALGORITHM
|
53
|
+
parameter = dummy_parameter(type, size, bytes)
|
54
|
+
when PARAM_PADDING
|
55
|
+
parameter = dummy_parameter(type, size, bytes)
|
56
|
+
when PARAM_SUPPORTED_EXTENSIONS
|
57
|
+
parameter = dummy_parameter(type, size, bytes)
|
58
|
+
when PARAM_FORWARD_TSN
|
59
|
+
parameter = dummy_parameter(type, size, bytes)
|
60
|
+
when PARAM_SET_PRIMARY_ADDR
|
61
|
+
parameter = dummy_parameter(type, size, bytes)
|
62
|
+
when PARAM_ADAPTATION_LAYER_INDICATION
|
63
|
+
parameter = dummy_parameter(type, size, bytes)
|
64
|
+
else
|
65
|
+
parameter = dummy_parameter(type, size, bytes)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Return the result
|
69
|
+
return parameter
|
70
|
+
end
|
71
|
+
|
72
|
+
def write io, ip
|
73
|
+
header = [@type, @size].pack('nn')
|
74
|
+
|
75
|
+
# Write Parameter header followed by the payload
|
76
|
+
io.write(header)
|
77
|
+
io.write(@payload_raw)
|
78
|
+
end
|
79
|
+
|
80
|
+
def padded_size
|
81
|
+
if 0 == @size % 4
|
82
|
+
return @size
|
83
|
+
else
|
84
|
+
return (@size + 4 - (@size % 4))
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def to_s
|
89
|
+
return "parameter(%d, %d)" % [@type, @size]
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.dummy_parameter type, size, bytes
|
93
|
+
# Create new dummy parameter
|
94
|
+
parameter = Parameter.new
|
95
|
+
parameter.type = type
|
96
|
+
parameter.size = size
|
97
|
+
|
98
|
+
# Save the payload
|
99
|
+
parameter.payload = bytes[4..parameter.padded_size - 1]
|
100
|
+
parameter.payload_raw = parameter.payload
|
101
|
+
|
102
|
+
# Return the result
|
103
|
+
return parameter
|
104
|
+
end
|
105
|
+
end # class Parameter
|
106
|
+
|
107
|
+
end # class SCTP
|
108
|
+
end # class Pcap
|
109
|
+
end # module Mu
|
110
|
+
|
111
|
+
require 'mu/pcap/sctp/parameter/ip_address'
|