blob: df3a70bad60a6ba52d44a3de12b54039772558e4 [file] [log] [blame]
Holger Hans Peter Freyther7220ca92010-10-20 16:56:46 +02001-- Split trace based on SCCP Source
2do
3 local function init_listener()
4 print("CREATED LISTENER")
Holger Hans Peter Freythere512e3f2010-10-20 18:57:17 +02005 local tap = Listener.new("ip", "sccp && (ip.src == 172.16.1.81 || ip.dst == 172.16.1.81)")
Holger Hans Peter Freyther7220ca92010-10-20 16:56:46 +02006 local sccp_type_field = Field.new("sccp.message_type")
7 local sccp_src_field = Field.new("sccp.slr")
8 local sccp_dst_field = Field.new("sccp.dlr")
9 local msg_type_field = Field.new("gsm_a.dtap_msg_mm_type")
10 local lu_rej_field = Field.new("gsm_a.dtap.rej_cause")
11 local ip_src_field = Field.new("ip.src")
12 local ip_dst_field = Field.new("ip.dst")
13
Holger Hans Peter Freyther721c4572010-10-20 18:58:12 +020014 --
15 local bssmap_msgtype_field = Field.new("gsm_a.bssmap_msgtype")
16 -- assignment failure 0x03
17 --
18
19 --
20 local dtap_cause_field = Field.new("gsm_a_dtap.cause")
21 local dtap_cc_field = Field.new("gsm_a.dtap_msg_cc_type")
22
Holger Hans Peter Freyther7220ca92010-10-20 16:56:46 +020023 local connections = {}
24
25 function check_failure(con)
Holger Hans Peter Freyther721c4572010-10-20 18:58:12 +020026 check_lu_reject(con)
27 check_disconnect(con)
28 end
29
30 -- check if a DISCONNECT is normal
31 function check_disconnect(con)
32 local msg_type = dtap_cc_field()
33 if not msg_type then
34 return
35 end
36
37 if tonumber(msg_type) ~= 0x25 then
38 return
39 end
40
41 local cause = dtap_cause_field()
42 if not cause then
43 return
44 end
45
46 cause = tonumber(cause)
47 if cause ~= 0x10 then
48 print("DISCONNECT != Normal")
49 con[4] = true
50 end
51 end
52
53 -- check if we have a LU Reject
54 function check_lu_reject(con)
Holger Hans Peter Freyther7220ca92010-10-20 16:56:46 +020055 local msg_type = msg_type_field()
56 if not msg_type then
57 return
58 end
59
60 msg_type = tonumber(tostring(msg_type))
61 if msg_type == 0x04 then
62 print("LU REJECT with " .. tostring(lu_rej_field()))
63 con[4] = true
64 end
65 end
66
67 function tap.packet(pinfo,tvb,ip)
68 local ip_src = tostring(ip_src_field())
69 local ip_dst = tostring(ip_dst_field())
70 local sccp_type = tonumber(tostring(sccp_type_field()))
71 local sccp_src = sccp_src_field()
72 local sccp_dst = sccp_dst_field()
73
74 local con
75
76 if sccp_type == 0x01 then
77 elseif sccp_type == 0x2 then
78 local src = string.format("%s-%s", ip_src, tostring(sccp_src))
79 local dst = string.format("%s-%s", ip_dst, tostring(sccp_dst))
80 local datestring = os.date("%Y%m%d%H%M%S")
81 local pcap_name = string.format("alink_trace_%s-%s_%s.pcap", src, dst, datestring)
82 local dumper = Dumper.new_for_current(pcap_name)
83
84 local con = { ip_src, tostring(sccp_src), tostring(sccp_dst), false, dumper, pcap_name }
85
86 dumper:dump_current()
87 connections[src] = con
88 connections[dst] = con
89 elseif sccp_type == 0x4 then
90 -- close a connection... remove it from the list
91 local src = string.format("%s-%s", ip_src, tostring(sccp_src))
92 local dst = string.format("%s-%s", ip_dst, tostring(sccp_dst))
93
94 local con = connections[src]
95 if not con then
96 return
97 end
98
99 con[5]:dump_current()
100 con[5]:flush()
101
102 -- this causes a crash on unpacted wireshark
103 con[5]:close()
104
105 -- the connection had a failure
106 if con[4] == true then
107 local datestring = os.date("%Y%m%d%H%M%S")
108 local new_name = string.format("alink_failure_%s_%s-%s.pcap", datestring, con[2], con[3])
109 os.rename(con[6], new_name)
110 else
111 os.remove(con[6])
112 end
113
114
115 -- clear the old connection
116 connections[src] = nil
117 connections[dst] = nil
118
119 elseif sccp_type == 0x5 then
120 -- not handled yet... we should verify stuff here...
121 local dst = string.format("%s-%s", ip_dst, tostring(sccp_dst))
122 local con = connections[dst]
123 if not con then
124 return
125 end
126 con[5]:dump_current()
127 elseif sccp_type == 0x6 then
128 local dst = string.format("%s-%s", ip_dst, tostring(sccp_dst))
129 local con = connections[dst]
130 if not con then
131 print("DON'T KNOW THIS CONNECTION for " .. ip_dst)
132 return
133 end
134 con[5]:dump_current()
135 check_failure(con)
136 end
137
138 end
139 function tap.draw()
140 print("DRAW")
141 end
142 function tap.reset()
143 print("RESET")
144 end
145 end
146
147 init_listener()
148end