]>
Commit | Line | Data |
---|---|---|
39236c6e A |
1 | |
2 | """ Please make sure you read the README COMPLETELY BEFORE reading anything below. | |
cb323159 | 3 | It is very critical that you read coding guidelines in Section E in README file. |
39236c6e | 4 | """ |
39236c6e A |
5 | from xnu import * |
6 | from utils import * | |
7 | from string import * | |
8 | from socket import * | |
cb323159 | 9 | import tempfile |
39236c6e A |
10 | |
11 | import xnudefines | |
12 | from netdefines import * | |
13 | from routedefines import * | |
14 | ||
cb323159 A |
15 | def GetDlilIfFlagsAsString(dlil_if_flags): |
16 | """ Return a formatted string description of the dlil interface flags | |
17 | """ | |
18 | out_string = "" | |
19 | flags = (unsigned)(dlil_if_flags & 0xffff) | |
20 | i = 0 | |
21 | num = 1 | |
22 | while num <= flags: | |
23 | if flags & num: | |
24 | out_string += dlil_if_flags_strings[i] + "," | |
25 | i += 1 | |
26 | num = num << 1 | |
27 | return rstrip(out_string, ",") | |
28 | ||
39236c6e A |
29 | def GetIfFlagsAsString(if_flags): |
30 | """ Return a formatted string description of the interface flags | |
31 | """ | |
32 | out_string = "" | |
33 | flags = (unsigned)(if_flags & 0xffff) | |
34 | i = 0 | |
35 | num = 1 | |
36 | while num <= flags: | |
37 | if flags & num: | |
cb323159 | 38 | out_string += if_flags_strings[i] + "," |
39236c6e A |
39 | i += 1 |
40 | num = num << 1 | |
41 | return rstrip(out_string, ",") | |
42 | ||
43 | ||
44 | def ShowIfConfiguration(ifnet): | |
45 | """ Display ifconfig-like output for the ifnet | |
46 | """ | |
47 | iface = Cast(ifnet, 'ifnet *') | |
cc8bc92a | 48 | dlifnet = Cast(ifnet, 'dlil_ifnet *') |
39236c6e A |
49 | out_string = "" |
50 | format_string = "{0: <s}: flags={1: <x} <{2: <s}> index {3: <d} mtu {4: <d}" | |
51 | if iface : | |
52 | out_string += format_string.format(iface.if_xname, (iface.if_flags & 0xffff), GetIfFlagsAsString(iface.if_flags), iface.if_index, iface.if_data.ifi_mtu) | |
cb323159 | 53 | out_string += "\n\tdlil flags=" + hex(dlifnet.dl_if_flags)+ " <" + GetDlilIfFlagsAsString(dlifnet.dl_if_flags) + ">" |
39236c6e | 54 | out_string += "\n\t(struct ifnet *)" + hex(ifnet) |
cc8bc92a A |
55 | if iface.if_snd.ifcq_len : |
56 | out_string += "\n\t" + str(iface.if_snd.ifcq_len) | |
f427ee49 A |
57 | if dlifnet.dl_if_inpstorage.dlth_pkts.qlen : |
58 | out_string += "\n\t" + str(dlifnet.dl_if_inpstorage.dlth_pkts.qlen) | |
39236c6e A |
59 | print out_string |
60 | ||
61 | def GetIfConfiguration(ifname): | |
62 | """ Return ifnet structure corresponding to the ifname passed in | |
63 | """ | |
64 | global kern | |
65 | ifnets = kern.globals.ifnet_head | |
66 | for ifnet in IterateTAILQ_HEAD(ifnets, "if_link") : | |
67 | if str(ifnet.if_xname) == ifname : | |
68 | return ifnet | |
69 | return None | |
70 | ||
cb323159 A |
71 | # Macro: net_get_always_on_pktap |
72 | @lldb_command('net_get_always_on_pktap') | |
73 | def NetGetAlwaysOnPktap(cmd_args=None): | |
74 | """ Dump the always-on packet capture to /tmp/dump.pktap | |
75 | """ | |
76 | for i in range(0, 10): | |
77 | ifnet = GetIfConfiguration("pktap"+str(i)) | |
78 | if not ifnet: | |
79 | continue | |
80 | if ifnet.if_bpf == 0: | |
81 | ifnet = None | |
82 | continue | |
83 | if ifnet.if_bpf.bif_dlist.bd_headdrop == 0: | |
84 | ifnet = None | |
85 | continue | |
86 | ||
87 | break | |
88 | ||
89 | if not ifnet: | |
90 | print "Could not find a pktap interface" | |
91 | return | |
92 | ||
93 | bpf_d = ifnet.if_bpf.bif_dlist | |
94 | ||
95 | f = tempfile.NamedTemporaryFile(prefix="dump-", suffix=".pktap", dir="/tmp/", mode="wb", delete=False) | |
96 | ||
97 | err = lldb.SBError() | |
98 | ||
99 | if bpf_d.bd_hbuf != 0: | |
100 | addr = bpf_d.bd_hbuf[0]._sbval19k84obscure747.AddressOf().GetValueAsUnsigned() | |
101 | buf = LazyTarget.GetProcess().ReadMemory(addr, unsigned(bpf_d.bd_hlen), err) | |
102 | if err.fail: | |
103 | print "Error, getting sbuf" | |
104 | f.write(buf) | |
105 | ||
106 | addr = bpf_d.bd_sbuf[0]._sbval19k84obscure747.AddressOf().GetValueAsUnsigned() | |
107 | buf = LazyTarget.GetProcess().ReadMemory(addr, unsigned(bpf_d.bd_slen), err) | |
108 | if err.fail: | |
109 | print "Error, getting sbuf" | |
110 | f.write(buf) | |
111 | ||
112 | print f.name | |
113 | f.close() | |
114 | # EndMacro: net_get_always_on_pktap | |
115 | ||
39236c6e A |
116 | # Macro: ifconfig |
117 | @lldb_command('ifconfig') | |
118 | def ShowIfconfig(cmd_args=None) : | |
119 | """ Display ifconfig-like output, and print the (struct ifnet *) pointers for further inspection | |
120 | """ | |
121 | if cmd_args != None and len(cmd_args) > 0: | |
122 | showall = 1 | |
123 | else: | |
124 | showall = 0 | |
125 | ||
126 | ifnets = kern.globals.ifnet_head | |
127 | for ifnet in IterateTAILQ_HEAD(ifnets, "if_link"): | |
128 | ShowIfConfiguration(ifnet) | |
129 | if (showall == 1): | |
130 | print GetIfaddrs(ifnet) | |
131 | # EndMacro: ifconfig | |
132 | ||
cb323159 A |
133 | #Macro: ifconfig_dlil |
134 | @lldb_command('ifconfig_dlil') | |
135 | def ShowIfconfigDlil(cmd_args=None) : | |
136 | """ Display ifconfig-like output for DLIL interface list, print (struct ifnet *) pointer and dlil info for further inspection | |
137 | """ | |
138 | dlil_ifnets = kern.globals.dlil_ifnet_head | |
139 | for dlil_ifnet in IterateTAILQ_HEAD(dlil_ifnets, "dl_if_link"): | |
140 | ShowIfConfiguration(dlil_ifnet) | |
141 | print GetIfaddrs(Cast(dlil_ifnet, 'ifnet *')) | |
142 | # EndMacro: ifconfig_dlil | |
143 | ||
39236c6e A |
144 | def GetAddressAsStringColonHex(addr, count): |
145 | out_string = "" | |
cb323159 | 146 | i = 0 |
39236c6e A |
147 | addr_format_string = "{0:02x}" |
148 | while (i < count): | |
149 | if (i == 0): | |
150 | out_string += addr_format_string.format(addr[i])[-2:] | |
151 | else: | |
152 | out_string += ":" + addr_format_string.format(addr[i])[-2:] | |
153 | i += 1 | |
154 | return out_string | |
155 | ||
156 | def GetSocketAddrAsStringUnspec(sockaddr): | |
157 | out_string = "" | |
158 | out_string += GetAddressAsStringColonHex(sockaddr.sa_data, sockaddr.sa_len - 2) | |
159 | return out_string | |
160 | ||
161 | def GetSocketAddrAsStringUnix(sockaddr): | |
162 | sock_unix = Cast(sockaddr, 'sockaddr_un *') | |
163 | if (sock_unix == 0): | |
164 | return "(null)" | |
165 | else: | |
cb323159 | 166 | if (len(str(sock_unix.sun_path)) > 0): |
39236c6e A |
167 | return str(sock_unix.sun_path) |
168 | else: | |
169 | return "\"\"" | |
170 | ||
171 | def GetInAddrAsString(ia): | |
172 | out_string = "" | |
173 | inaddr = Cast(ia, 'in_addr *') | |
cb323159 | 174 | |
39236c6e A |
175 | packed_value = struct.pack('I', unsigned(ia.s_addr)) |
176 | out_string = inet_ntoa(packed_value) | |
177 | return out_string | |
178 | ||
179 | def GetIn6AddrAsString(ia): | |
180 | out_string = "" | |
181 | addr = ia | |
182 | ||
183 | addr_format_string = "{0:02x}:{1:02x}:{2:02x}:{3:02x}{4:02x}:{5:02x}:{6:02x}:{7:02x}{8:02x}:{9:02x}:{10:02x}:{11:02x}{12:02x}:{13:02x}:{14:02x}:{15:02x}" | |
184 | out_string += addr_format_string.format(unsigned(addr[0]), unsigned(addr[1]), unsigned(addr[2]), unsigned(addr[3]), unsigned(addr[4]), unsigned(addr[5]), unsigned(addr[6]), unsigned(addr[7]), unsigned(addr[8]), unsigned(addr[9]), unsigned(addr[10]), unsigned(addr[11]), unsigned(addr[12]), unsigned(addr[13]), unsigned(addr[14]), unsigned(addr[15])) | |
185 | return out_string | |
186 | ||
187 | def GetSocketAddrAsStringInet(sockaddr): | |
188 | sock_in = Cast(sockaddr, 'sockaddr_in *') | |
cb323159 | 189 | return GetInAddrAsString(addressof(sock_in.sin_addr)) |
39236c6e A |
190 | |
191 | def GetSocketAddrAsStringInet6(sockaddr): | |
192 | sock_in6 = Cast(sockaddr, 'sockaddr_in6 *') | |
193 | return GetIn6AddrAsString(sock_in6.sin6_addr.__u6_addr.__u6_addr8) | |
194 | ||
195 | def GetSocketAddrAsStringLink(sockaddr): | |
196 | sock_link = Cast(sockaddr, 'sockaddr_dl *') | |
197 | if sock_link is None: | |
198 | return "(null)" | |
199 | else: | |
200 | out_string = "" | |
201 | if (sock_link.sdl_nlen == 0 and sock_link.sdl_alen == 0 and sock_link.sdl_slen == 0): | |
202 | out_string = "link#" + str(int(sock_link.sdl_index)) | |
203 | else: | |
204 | out_string += GetAddressAsStringColonHex(addressof(sock_link.sdl_data[sock_link.sdl_nlen]), sock_link.sdl_alen) | |
205 | return out_string | |
cb323159 | 206 | |
39236c6e A |
207 | def GetSocketAddrAsStringAT(sockaddr): |
208 | out_string = "" | |
209 | sock_addr = Cast(sockaddr, 'sockaddr *') | |
210 | out_string += GetAddressAsStringColonHex(sockaddr.sa_data, sockaddr.sa_len - 2) | |
211 | return out_string | |
212 | ||
213 | def GetSocketAddrAsString(sockaddr): | |
214 | if sockaddr is None : | |
215 | return "(null)" | |
216 | out_string = "" | |
217 | if (sockaddr.sa_family == 0): | |
218 | out_string += "UNSPC " | |
219 | GetSocketAddrAsStringUnspec(sockaddr) | |
220 | elif (sockaddr.sa_family == 1): | |
221 | out_string += "UNIX " | |
222 | out_string += GetSocketAddrAsStringUnix(sockaddr) | |
223 | elif (sockaddr.sa_family == 2): | |
224 | out_string += "INET " | |
225 | out_string += GetSocketAddrAsStringInet(sockaddr) | |
226 | elif (sockaddr.sa_family == 30): | |
227 | out_string += "INET6 " | |
228 | out_string += GetSocketAddrAsStringInet6(sockaddr) | |
229 | elif (sockaddr.sa_family == 18): | |
230 | out_string += "LINK " | |
231 | out_string += GetSocketAddrAsStringLink(sockaddr) | |
232 | elif (sockaddr.sa_family == 16): | |
233 | out_string += "ATLK " | |
234 | out_string += GetSocketAddrAsStringAT(sockaddr) | |
235 | else: | |
236 | out_string += "FAM " + str(sockaddr.sa_family) | |
237 | out_string += GetAddressAsStringColonHex(sockaddr.sa_data, sockaddr.sa_len) | |
238 | return out_string | |
239 | ||
240 | # Macro: showifaddrs | |
241 | @lldb_command('showifaddrs') | |
242 | def ShowIfaddrs(cmd_args=None): | |
243 | """ Show the (struct ifnet).if_addrhead list of addresses for the given ifp | |
244 | """ | |
245 | if cmd_args != None and len(cmd_args) > 0 : | |
246 | ifp = kern.GetValueFromAddress(cmd_args[0], 'ifnet *') | |
247 | if not ifp: | |
248 | print "Unknown value passed as argument." | |
249 | return | |
250 | i = 1 | |
251 | for ifaddr in IterateTAILQ_HEAD(ifp.if_addrhead, "ifa_link"): | |
252 | format_string = "\t{0: <d}: 0x{1: <x} {2: <s} [{3: <d}]" | |
253 | print format_string.format(i, ifaddr, GetSocketAddrAsString(ifaddr.ifa_addr), ifaddr.ifa_refcnt) | |
254 | i += 1 | |
255 | else : | |
256 | print "Missing argument 0 in user function." | |
257 | # EndMacro: showifaddrs | |
258 | ||
259 | def GetIfaddrs(ifp): | |
260 | out_string = "" | |
261 | if (ifp != 0): | |
262 | i = 1 | |
263 | for ifaddr in IterateTAILQ_HEAD(ifp.if_addrhead, "ifa_link"): | |
264 | format_string = "\t{0: <d}: 0x{1: <x} {2: <s} [{3: <d}]" | |
265 | out_string += format_string.format(i, ifaddr, GetSocketAddrAsString(ifaddr.ifa_addr), ifaddr.ifa_refcnt) + "\n" | |
266 | i += 1 | |
267 | else: | |
268 | out_string += "Missing argument 0 in user function." | |
269 | return out_string | |
270 | ||
271 | ||
272 | def GetCapabilitiesAsString(flags): | |
273 | """ Return a formatted string description of the interface flags | |
274 | """ | |
275 | out_string = "" | |
276 | i = 0 | |
277 | num = 1 | |
278 | while num <= flags: | |
279 | if flags & num: | |
cb323159 | 280 | out_string += if_capenable_strings[i] + "," |
39236c6e A |
281 | i += 1 |
282 | num = num << 1 | |
283 | return rstrip(out_string, ",") | |
284 | ||
285 | def GetIfEflagsAsString(if_eflags): | |
286 | """ Return a formatted string description of the interface flags | |
287 | """ | |
288 | out_string = "" | |
289 | flags = unsigned(if_eflags) | |
290 | i = 0 | |
291 | num = 1 | |
292 | while num <= flags: | |
293 | if flags & num: | |
294 | out_string += if_eflags_strings[i] + "," | |
295 | i += 1 | |
296 | num = num << 1 | |
297 | return rstrip(out_string, ",") | |
298 | ||
299 | def ShowDlilIfnetConfiguration(dlil_ifnet, show_all) : | |
300 | """ Formatted display of dlil_ifnet structures | |
301 | """ | |
302 | DLIF_INUSE = 0x1 | |
303 | DLIF_REUSE = 0x2 | |
304 | ||
305 | if dlil_ifnet is None : | |
306 | return | |
307 | ||
308 | dlil_iface = Cast(dlil_ifnet, 'dlil_ifnet *') | |
309 | iface = Cast(dlil_ifnet, 'ifnet *') | |
310 | out_string = "" | |
311 | if (dlil_iface.dl_if_flags & DLIF_REUSE) : | |
312 | out_string += "*" | |
313 | format_string = "{0: <s}: flags={1: <x} <{2: <s}> index {3: <d} mtu {4: <d}" | |
314 | extended_flags_format_string = "\n\teflags={0: <x} <{1: <s}>" | |
315 | capenabled_format_string = "\n\toptions={0: <x} <{1: <s}>" | |
316 | if (dlil_iface.dl_if_flags & DLIF_INUSE) : | |
317 | out_string += format_string.format(iface.if_xname, (iface.if_flags & 0xffff), GetIfFlagsAsString(iface.if_flags), iface.if_index, iface.if_data.ifi_mtu) | |
318 | else : | |
319 | out_string += format_string.format("[" + str(iface.if_name) + str(int(iface.if_unit)) + "]", (iface.if_flags & 0xffff), GetIfFlagsAsString(iface.if_flags), iface.if_index, iface.if_data.ifi_mtu) | |
320 | if (iface.if_eflags) : | |
321 | out_string += extended_flags_format_string.format(iface.if_eflags, GetIfEflagsAsString(iface.if_eflags)) | |
322 | if (iface.if_capenable) : | |
323 | out_string += capenabled_format_string.format(iface.if_capenable, GetCapabilitiesAsString(iface.if_capenable)) | |
324 | out_string += "\n\t(struct ifnet *)" + hex(dlil_ifnet) + "\n" | |
325 | if show_all : | |
326 | out_string += GetIfaddrs(iface) | |
327 | out_string += "\n" | |
f427ee49 | 328 | print out_string |
39236c6e A |
329 | |
330 | # Macro: showifnets | |
331 | @lldb_command('showifnets') | |
332 | def ShowIfnets(cmd_args=None) : | |
333 | """ Display ifconfig-like output for all attached and detached interfaces | |
cb323159 | 334 | """ |
39236c6e A |
335 | showall = 0 |
336 | if cmd_args != None and len(cmd_args) > 0 : | |
337 | showall = 1 | |
338 | dlil_ifnets = kern.globals.dlil_ifnet_head | |
339 | for dlil_ifnet in IterateTAILQ_HEAD(dlil_ifnets, "dl_if_link"): | |
340 | ShowDlilIfnetConfiguration(dlil_ifnet, showall) | |
341 | # EndMacro: showifnets | |
342 | ||
343 | # Macro: showifmultiaddrs | |
344 | @lldb_command('showifmultiaddrs') | |
345 | def ShowIfMultiAddrs(cmd_args=None) : | |
346 | """ Show the list of multicast addresses for the given ifp | |
347 | """ | |
348 | out_string = "" | |
349 | if cmd_args != None and len(cmd_args) > 0 : | |
350 | ifp = kern.GetValueFromAddress(cmd_args[0], 'ifnet *') | |
351 | if not ifp: | |
352 | print "Unknown value passed as argument." | |
353 | return | |
354 | ifmulti = cast(ifp.if_multiaddrs.lh_first, 'ifmultiaddr *') | |
355 | i = 0 | |
356 | while ifmulti != 0: | |
357 | ifma_format_string = "\t{0: <d}: 0x{1: <x} " | |
358 | out_string += (ifma_format_string.format(i + 1, ifmulti)) | |
359 | if (ifmulti.ifma_addr.sa_family == 2): | |
360 | if (ifmulti.ifma_ll != 0): | |
361 | out_string += GetSocketAddrAsStringLink(ifmulti.ifma_ll.ifma_addr) + " " | |
362 | out_string += GetSocketAddrAsStringInet(ifmulti.ifma_addr) | |
363 | if (ifmulti.ifma_addr.sa_family == 30): | |
364 | if (ifmulti.ifma_ll != 0): | |
365 | out_string += GetSocketAddrAsStringLink(ifmulti.ifma_ll.ifma_addr) + " " | |
366 | out_string += GetSocketAddrAsStringInet6(ifmulti.ifma_addr) + " " | |
367 | if (ifmulti.ifma_addr.sa_family == 18): | |
368 | out_string += GetSocketAddrAsStringLink(ifmulti.ifma_addr) + " " | |
369 | if (ifmulti.ifma_addr.sa_family == 0): | |
370 | out_string += GetSocketAddrAsStringUnspec(ifmulti.ifma_addr) + " " | |
371 | out_string += "[" + str(int(ifmulti.ifma_refcount)) + "]\n" | |
372 | ifmulti = cast(ifmulti.ifma_link.le_next, 'ifmultiaddr *') | |
373 | i += 1 | |
374 | print out_string | |
375 | else : | |
376 | print "Missing argument 0 in user function." | |
377 | # EndMacro: showifmultiaddrs | |
378 | ||
379 | # Macro: showinmultiaddrs | |
380 | @lldb_command('showinmultiaddrs') | |
381 | def ShowInMultiAddrs(cmd_args=None) : | |
382 | """ Show the contents of IPv4 multicast address records | |
383 | """ | |
384 | out_string = "" | |
385 | inmultihead = kern.globals.in_multihead | |
386 | inmulti = cast(inmultihead.lh_first, 'in_multi *') | |
387 | i = 0 | |
388 | while inmulti != 0: | |
389 | ifp = inmulti.inm_ifp | |
390 | inma_format_string = "\t{0: <d}: 0x{1: <x} " | |
391 | out_string += inma_format_string.format(i + 1, inmulti) + " " | |
392 | out_string += GetInAddrAsString(addressof(inmulti.inm_addr)) + " " | |
393 | ifma_format_string = "(ifp 0x{0: <x} [{1: <s}] ifma {2: <x})" | |
394 | out_string += ifma_format_string.format(ifp, ifp.if_xname, inmulti.inm_ifma) + "\n" | |
395 | inmulti = cast(inmulti.inm_link.le_next, 'in_multi *') | |
396 | i += 1 | |
397 | print out_string | |
398 | # EndMacro: showinmultiaddrs | |
399 | ||
400 | # Macro: showin6multiaddrs | |
401 | @lldb_command('showin6multiaddrs') | |
402 | def ShowIn6MultiAddrs(cmd_args=None) : | |
403 | """ Show the contents of IPv6 multicast address records | |
404 | """ | |
405 | out_string = "" | |
406 | in6multihead = kern.globals.in6_multihead | |
407 | in6multi = cast(in6multihead.lh_first, 'in6_multi *') | |
408 | i = 0 | |
409 | while in6multi != 0: | |
410 | ifp = in6multi.in6m_ifp | |
411 | inma_format_string = "\t{0: <d}: 0x{1: <x} " | |
412 | out_string += inma_format_string.format(i + 1, in6multi) + " " | |
413 | out_string += GetIn6AddrAsString((in6multi.in6m_addr.__u6_addr.__u6_addr8)) + " " | |
414 | ifma_format_string = "(ifp 0x{0: <x} [{1: <s}] ifma {2: <x})" | |
415 | out_string += ifma_format_string.format(ifp, ifp.if_xname, in6multi.in6m_ifma) + "\n" | |
416 | in6multi = cast(in6multi.in6m_entry.le_next, 'in6_multi *') | |
417 | i += 1 | |
418 | print out_string | |
419 | # EndMacro: showin6multiaddrs | |
420 | ||
421 | def GetTcpState(tcpcb): | |
422 | out_string = "" | |
423 | tp = Cast(tcpcb, 'tcpcb *') | |
424 | if (int(tp) != 0): | |
425 | if tp.t_state == 0: | |
426 | out_string += "CLOSED\t" | |
427 | if tp.t_state == 1: | |
428 | out_string += "LISTEN\t" | |
429 | if tp.t_state == 2: | |
430 | out_string += "SYN_SENT\t" | |
431 | if tp.t_state == 3: | |
432 | out_string += "SYN_RCVD\t" | |
433 | if tp.t_state == 4: | |
434 | out_string += "ESTABLISHED\t" | |
435 | if tp.t_state == 5: | |
436 | out_string += "CLOSE_WAIT\t" | |
437 | if tp.t_state == 6: | |
438 | out_string += "FIN_WAIT_1\t" | |
439 | if tp.t_state == 7: | |
440 | out_string += "CLOSING\t" | |
441 | if tp.t_state == 8: | |
442 | out_string += "LAST_ACK\t" | |
443 | if tp.t_state == 9: | |
444 | out_string += "FIN_WAIT_2\t" | |
445 | if tp.t_state == 10: | |
446 | out_string += "TIME_WAIT\t" | |
447 | return out_string | |
448 | ||
449 | def GetSocketProtocolAsString(sock): | |
450 | out_string = "" | |
451 | inpcb = Cast(sock.so_pcb, 'inpcb *') | |
452 | if sock.so_proto.pr_protocol == 6: | |
453 | out_string += " TCP " | |
454 | out_string += GetTcpState(inpcb.inp_ppcb) | |
455 | if sock.so_proto.pr_protocol == 17: | |
456 | out_string += " UDP " | |
457 | if sock.so_proto.pr_protocol == 1: | |
458 | out_string += " ICMP " | |
459 | if sock.so_proto.pr_protocol == 254: | |
460 | out_string += " DIVERT " | |
461 | if sock.so_proto.pr_protocol == 255: | |
462 | out_string += " RAW " | |
463 | return out_string | |
464 | ||
465 | def GetInAddr4to6AsString(inaddr): | |
466 | out_string = "" | |
467 | if (inaddr is not None): | |
cb323159 A |
468 | ia = Cast(inaddr, 'unsigned char *') |
469 | inaddr_format_string = "{0:d}:{1:d}:{2:d}:{3:d}" | |
470 | out_string += inaddr_format_string.format(unsigned(ia[0]), unsigned(ia[1]), unsigned(ia[2]), unsigned(ia[3])) | |
39236c6e A |
471 | return out_string |
472 | ||
473 | def GetInPortAsString(port): | |
474 | out_string = "" | |
475 | port_string = Cast(port, 'char *') | |
476 | port_unsigned = dereference(Cast(port, 'unsigned short *')) | |
477 | ||
478 | if ((((port_unsigned & 0xff00) >> 8) == port_string[0])) and (((port_unsigned & 0x00ff) == port_string[1])): | |
479 | out_string += ":" + str(int(port_unsigned)) | |
480 | else: | |
481 | out_string += ":" + str(int(((port_unsigned & 0xff00) >> 8) | ((port_unsigned & 0x00ff) << 8))) | |
482 | ||
483 | return out_string | |
484 | ||
485 | def GetIPv4SocketAsString(sock) : | |
486 | out_string = "" | |
487 | pcb = Cast(sock.so_pcb, 'inpcb *') | |
488 | if (pcb == 0): | |
489 | out_string += "inpcb: (null) " | |
490 | else: | |
491 | out_string += "inpcb: " + hex(pcb) | |
492 | out_string += GetSocketProtocolAsString(sock) | |
cb323159 A |
493 | |
494 | out_string += GetInAddr4to6AsString(addressof(pcb.inp_dependladdr.inp46_local.ia46_addr4)) | |
39236c6e A |
495 | out_string += GetInPortAsString(addressof(pcb.inp_lport)) |
496 | out_string += " -> " | |
cb323159 | 497 | out_string += GetInAddr4to6AsString(addressof(pcb.inp_dependfaddr.inp46_foreign.ia46_addr4)) |
39236c6e A |
498 | out_string += GetInPortAsString(addressof(pcb.inp_fport)) |
499 | return out_string | |
500 | ||
501 | def GetIPv6SocketAsString(sock) : | |
502 | out_string = "" | |
503 | pcb = Cast(sock.so_pcb, 'inpcb *') | |
504 | if (pcb == 0): | |
505 | out_string += "inpcb: (null) " | |
506 | else: | |
507 | out_string += "inpcb: " + hex(pcb) + " " | |
508 | out_string += GetSocketProtocolAsString(sock) | |
cb323159 | 509 | |
39236c6e A |
510 | out_string += GetIn6AddrAsString((pcb.inp_dependladdr.inp6_local.__u6_addr.__u6_addr8)) |
511 | out_string += GetInPortAsString(addressof(pcb.inp_lport)) | |
512 | out_string += " -> " | |
513 | out_string += GetIn6AddrAsString((pcb.inp_dependfaddr.inp6_foreign.__u6_addr.__u6_addr8)) | |
514 | out_string += GetInPortAsString(addressof(pcb.inp_fport)) | |
515 | return out_string | |
516 | ||
517 | def GetUnixDomainSocketAsString(sock) : | |
518 | out_string = "" | |
519 | pcb = Cast(sock.so_pcb, 'unpcb *') | |
520 | if (pcb == 0): | |
521 | out_string += "unpcb: (null) " | |
522 | else: | |
523 | out_string += "unpcb: " + hex(pcb) + " " | |
524 | out_string += "unp_vnode: " + hex(pcb.unp_vnode) + " " | |
525 | out_string += "unp_conn: " + hex(pcb.unp_conn) + " " | |
526 | out_string += "unp_addr: " + GetSocketAddrAsStringUnix(pcb.unp_addr) | |
527 | return out_string | |
528 | ||
f427ee49 A |
529 | def GetVsockSocketAsString(sock) : |
530 | out_string = "" | |
531 | pcb = Cast(sock.so_pcb, 'vsockpcb *') | |
532 | if (pcb == 0): | |
533 | out_string += "vsockpcb: (null) " | |
534 | else: | |
535 | out_string += "vsockpcb: " + hex(pcb) + " " | |
536 | out_string += str(pcb.local_address) + " " | |
537 | out_string += str(pcb.remote_address) | |
538 | return out_string | |
539 | ||
39236c6e A |
540 | def GetSocket(socket) : |
541 | """ Show the contents of a socket | |
542 | """ | |
543 | so = kern.GetValueFromAddress(unsigned(socket), 'socket *') | |
544 | if (so): | |
545 | out_string = "" | |
546 | sock_format_string = "so: 0x{0:<x}" | |
547 | out_string += sock_format_string.format(so) | |
548 | domain = so.so_proto.pr_domain | |
549 | domain_name_format_string = " {0:<s} " | |
550 | out_string += domain_name_format_string.format(domain.dom_name) | |
551 | if (domain.dom_family == 1): | |
552 | out_string += GetUnixDomainSocketAsString(so) | |
553 | if (domain.dom_family == 2): | |
554 | out_string += GetIPv4SocketAsString(so) | |
555 | if (domain.dom_family == 30): | |
556 | out_string += GetIPv6SocketAsString(so) | |
f427ee49 A |
557 | if (domain.dom_family == 40): |
558 | out_string += GetVsockSocketAsString(so) | |
cb323159 | 559 | out_string += " s=" + str(int(so.so_snd.sb_cc)) + " r=" + str(int(so.so_rcv.sb_cc)) + " usecnt=" + str(int(so.so_usecount)) + "] " |
39236c6e A |
560 | else: |
561 | out_string += "(null)" | |
562 | return out_string | |
563 | # EndMacro: showsocket | |
564 | ||
565 | ||
566 | # Macro: showsocket | |
567 | @lldb_command('showsocket') | |
568 | def ShowSocket(cmd_args=None) : | |
569 | """ Show the contents of a socket | |
570 | """ | |
571 | if (cmd_args == None or len(cmd_args) == 0): | |
572 | print "Missing argument 0 in user function." | |
573 | return | |
574 | so = kern.GetValueFromAddress(cmd_args[0], 'socket *') | |
575 | if (len(str(cmd_args[0])) > 0): | |
576 | out_string = "" | |
577 | sock_format_string = "so: 0x{0:<x}" | |
578 | out_string += sock_format_string.format(so) | |
579 | domain = so.so_proto.pr_domain | |
580 | domain_name_format_string = " {0:<s} " | |
581 | out_string += domain_name_format_string.format(domain.dom_name) | |
582 | if (domain.dom_family == 1): | |
583 | out_string += GetUnixDomainSocketAsString(so) | |
584 | if (domain.dom_family == 2): | |
585 | out_string += GetIPv4SocketAsString(so) | |
586 | if (domain.dom_family == 30): | |
587 | out_string += GetIPv6SocketAsString(so) | |
f427ee49 A |
588 | if (domain.dom_family == 40): |
589 | out_string += GetVsockSocketAsString(so) | |
39236c6e A |
590 | print out_string |
591 | else: | |
592 | print "Unknown value passed as argument." | |
593 | return | |
594 | # EndMacro: showsocket | |
595 | ||
cb323159 A |
596 | def GetProcSockets(proc, total_snd_cc, total_rcv_cc): |
597 | """ Given a proc_t pointer, display information about its sockets | |
598 | """ | |
599 | out_string = "" | |
600 | ||
601 | if proc is None: | |
602 | out_string += "Unknown value passed as argument." | |
603 | else: | |
604 | snd_cc = 0 | |
605 | rcv_cc = 0 | |
606 | sock_fd_seen = 0 | |
607 | count = 0 | |
608 | """struct filedesc *""" | |
609 | proc_filedesc = proc.p_fd | |
610 | """struct fileproc **""" | |
611 | proc_ofiles = proc_filedesc.fd_ofiles | |
612 | """ high-water mark of fd_ofiles """ | |
613 | proc_lastfile = unsigned(proc_filedesc.fd_lastfile) | |
614 | if proc_filedesc.fd_nfiles != 0: | |
615 | while count <= proc_lastfile: | |
f427ee49 A |
616 | if (unsigned(proc_ofiles[count]) != 0 and proc_ofiles[count].fp_glob != 0): |
617 | fg = proc_ofiles[count].fp_glob | |
cb323159 A |
618 | if (int(fg.fg_ops.fo_type) == 2): |
619 | if (proc_filedesc.fd_ofileflags[count] & 4): | |
620 | out_string += "U: " | |
621 | else: | |
622 | out_string += " " | |
623 | out_string += "fd = " + str(count) + " " | |
624 | if (fg.fg_data != 0): | |
625 | out_string += GetSocket(unsigned(fg.fg_data)) | |
626 | out_string += "\n" | |
627 | ||
628 | so = kern.GetValueFromAddress(unsigned(fg.fg_data), 'socket *') | |
629 | snd_cc += int(so.so_snd.sb_cc) | |
630 | total_snd_cc[0] += int(so.so_snd.sb_cc) | |
631 | rcv_cc += int(so.so_rcv.sb_cc) | |
632 | total_rcv_cc[0] += int(so.so_rcv.sb_cc) | |
633 | sock_fd_seen += 1 | |
634 | else: | |
635 | out_string += "" | |
636 | count += 1 | |
637 | out_string += "total sockets " + str(int(sock_fd_seen)) + " snd_cc " + str(int(snd_cc)) + " rcv_cc " + str(int(rcv_cc)) + "\n" | |
638 | return out_string | |
639 | ||
640 | ||
39236c6e A |
641 | # Macro: showprocsockets |
642 | @lldb_command('showprocsockets') | |
643 | def ShowProcSockets(cmd_args=None): | |
644 | """ Given a proc_t pointer, display information about its sockets | |
645 | """ | |
cb323159 A |
646 | total_snd_cc = [0] |
647 | total_rcv_cc = [0] | |
39236c6e | 648 | out_string = "" |
39236c6e A |
649 | if cmd_args != None and len(cmd_args) > 0 : |
650 | proc = kern.GetValueFromAddress(cmd_args[0], 'proc *') | |
39236c6e A |
651 | |
652 | if not proc: | |
653 | print "Unknown value passed as argument." | |
654 | return | |
655 | else: | |
cb323159 A |
656 | print GetProcInfo(proc) |
657 | print GetProcSockets(proc, total_snd_cc, total_rcv_cc) | |
39236c6e A |
658 | else: |
659 | print "Missing argument 0 in user function." | |
660 | # EndMacro: showprocsockets | |
661 | ||
39236c6e A |
662 | # Macro: showallprocsockets |
663 | @lldb_command('showallprocsockets') | |
664 | def ShowAllProcSockets(cmd_args=None): | |
665 | """Display information about the sockets of all the processes | |
666 | """ | |
cb323159 A |
667 | total_snd_cc = [0] |
668 | total_rcv_cc = [0] | |
39236c6e A |
669 | for proc in kern.procs: |
670 | print "================================================================================" | |
671 | print GetProcInfo(proc) | |
cb323159 A |
672 | print GetProcSockets(proc, total_snd_cc, total_rcv_cc) |
673 | print ("total_snd_cc: " + str(int(total_snd_cc[0])) + " total_rcv_cc: " + str(int(total_rcv_cc[0])) + "\n") | |
39236c6e A |
674 | # EndMacro: showallprocsockets |
675 | ||
676 | ||
677 | def GetRtEntryPrDetailsAsString(rte): | |
678 | out_string = "" | |
679 | rt = Cast(rte, 'rtentry *') | |
680 | dst = Cast(rt.rt_nodes[0].rn_u.rn_leaf.rn_Key, 'sockaddr *') | |
681 | isv6 = 0 | |
682 | dst_string_format = "{0:<18s}" | |
683 | if (dst.sa_family == AF_INET): | |
684 | out_string += dst_string_format.format(GetSocketAddrAsStringInet(dst)) + " " | |
cb323159 | 685 | else: |
39236c6e A |
686 | if (dst.sa_family == AF_INET6): |
687 | out_string += dst_string_format.format(GetSocketAddrAsStringInet6(dst)) + " " | |
688 | isv6 = 1 | |
689 | else: | |
690 | if (dst.sa_family == AF_LINK): | |
691 | out_string += dst_string_format.format(GetSocketAddrAsStringLink(dst)) | |
692 | if (isv6 == 1): | |
693 | out_string += " " | |
694 | else: | |
695 | out_string += " " | |
696 | else: | |
697 | out_string += dst_string_format.format(GetSocketAddrAsStringUnspec(dst)) + " " | |
698 | ||
699 | gw = Cast(rt.rt_gateway, 'sockaddr *') | |
700 | if (gw.sa_family == AF_INET): | |
701 | out_string += dst_string_format.format(GetSocketAddrAsStringInet(gw)) + " " | |
702 | else: | |
703 | if (gw.sa_family == 30): | |
704 | out_string += dst_string_format.format(GetSocketAddrAsStringInet6(gw)) + " " | |
705 | isv6 = 1 | |
706 | else: | |
707 | if (gw.sa_family == 18): | |
708 | out_string += dst_string_format.format(GetSocketAddrAsStringLink(gw)) + " " | |
709 | if (isv6 == 1): | |
710 | out_string += " " | |
711 | else: | |
712 | out_string += " " | |
713 | else: | |
714 | dst_string_format.format(GetSocketAddrAsStringUnspec(gw)) | |
715 | ||
716 | if (rt.rt_flags & RTF_WASCLONED): | |
717 | if (kern.ptrsize == 8): | |
718 | rt_flags_string_format = "0x{0:<16x}" | |
719 | out_string += rt_flags_string_format.format(rt.rt_parent) + " " | |
720 | else: | |
721 | rt_flags_string_format = "0x{0:<8x}" | |
722 | out_string += rt_flags_string_format.format(rt.rt_parent) + " " | |
723 | else: | |
724 | if (kern.ptrsize == 8): | |
725 | out_string += " " | |
726 | else: | |
727 | out_string += " " | |
728 | ||
729 | rt_refcnt_rmx_string_format = "{0:<d} {1:>10d} " | |
730 | out_string += rt_refcnt_rmx_string_format.format(rt.rt_refcnt, rt.rt_rmx.rmx_pksent) + " " | |
731 | ||
732 | rtf_string_format = "{0:>s}" | |
733 | if (rt.rt_flags & RTF_UP): | |
734 | out_string += rtf_string_format.format("U") | |
735 | if (rt.rt_flags & RTF_GATEWAY): | |
736 | out_string += rtf_string_format.format("G") | |
737 | if (rt.rt_flags & RTF_HOST): | |
738 | out_string += rtf_string_format.format("H") | |
739 | if (rt.rt_flags & RTF_REJECT): | |
740 | out_string += rtf_string_format.format("R") | |
741 | if (rt.rt_flags & RTF_DYNAMIC): | |
742 | out_string += rtf_string_format.format("D") | |
743 | if (rt.rt_flags & RTF_MODIFIED): | |
744 | out_string += rtf_string_format.format("M") | |
745 | if (rt.rt_flags & RTF_CLONING): | |
746 | out_string += rtf_string_format.format("C") | |
747 | if (rt.rt_flags & RTF_PRCLONING): | |
748 | out_string += rtf_string_format.format("c") | |
749 | if (rt.rt_flags & RTF_LLINFO): | |
750 | out_string += rtf_string_format.format("L") | |
751 | if (rt.rt_flags & RTF_STATIC): | |
752 | out_string += rtf_string_format.format("S") | |
753 | if (rt.rt_flags & RTF_PROTO1): | |
754 | out_string += rtf_string_format.format("1") | |
755 | if (rt.rt_flags & RTF_PROTO2): | |
756 | out_string += rtf_string_format.format("2") | |
757 | if (rt.rt_flags & RTF_PROTO3): | |
758 | out_string += rtf_string_format.format("3") | |
759 | if (rt.rt_flags & RTF_WASCLONED): | |
760 | out_string += rtf_string_format.format("W") | |
761 | if (rt.rt_flags & RTF_BROADCAST): | |
762 | out_string += rtf_string_format.format("b") | |
763 | if (rt.rt_flags & RTF_MULTICAST): | |
764 | out_string += rtf_string_format.format("m") | |
765 | if (rt.rt_flags & RTF_XRESOLVE): | |
766 | out_string += rtf_string_format.format("X") | |
767 | if (rt.rt_flags & RTF_BLACKHOLE): | |
768 | out_string += rtf_string_format.format("B") | |
769 | if (rt.rt_flags & RTF_IFSCOPE): | |
770 | out_string += rtf_string_format.format("I") | |
771 | if (rt.rt_flags & RTF_CONDEMNED): | |
772 | out_string += rtf_string_format.format("Z") | |
773 | if (rt.rt_flags & RTF_IFREF): | |
774 | out_string += rtf_string_format.format("i") | |
775 | if (rt.rt_flags & RTF_PROXY): | |
776 | out_string += rtf_string_format.format("Y") | |
777 | if (rt.rt_flags & RTF_ROUTER): | |
778 | out_string += rtf_string_format.format("r") | |
779 | ||
780 | out_string += "/" | |
781 | out_string += str(rt.rt_ifp.if_name) | |
782 | out_string += str(int(rt.rt_ifp.if_unit)) | |
783 | out_string += "\n" | |
784 | return out_string | |
cb323159 | 785 | |
39236c6e A |
786 | |
787 | RNF_ROOT = 2 | |
788 | def GetRtTableAsString(rt_tables): | |
789 | out_string = "" | |
790 | rn = Cast(rt_tables.rnh_treetop, 'radix_node *') | |
791 | rnh_cnt = rt_tables.rnh_cnt | |
792 | ||
793 | while (rn.rn_bit >= 0): | |
794 | rn = rn.rn_u.rn_node.rn_L | |
795 | ||
796 | while 1: | |
797 | base = Cast(rn, 'radix_node *') | |
798 | while ((rn.rn_parent.rn_u.rn_node.rn_R == rn) and (rn.rn_flags & RNF_ROOT == 0)): | |
799 | rn = rn.rn_parent | |
800 | rn = rn.rn_parent.rn_u.rn_node.rn_R | |
801 | while (rn.rn_bit >= 0): | |
802 | rn = rn.rn_u.rn_node.rn_L | |
803 | next_rn = rn | |
804 | while (base != 0): | |
805 | rn = base | |
806 | base = rn.rn_u.rn_leaf.rn_Dupedkey | |
807 | if ((rn.rn_flags & RNF_ROOT) == 0): | |
808 | rt = Cast(rn, 'rtentry *') | |
809 | if (kern.ptrsize == 8): | |
810 | rtentry_string_format = "0x{0:<18x}" | |
811 | out_string += rtentry_string_format.format(rt) + " " | |
812 | else: | |
813 | rtentry_string_format = "0x{0:<10x}" | |
814 | out_string += rtentry_string_format.format(rt) + " " | |
815 | out_string += GetRtEntryPrDetailsAsString(rt) + " " | |
816 | ||
817 | rn = next_rn | |
818 | if ((rn.rn_flags & RNF_ROOT) != 0): | |
819 | break | |
820 | return out_string | |
821 | ||
822 | def GetRtInetAsString(): | |
823 | rt_tables = kern.globals.rt_tables[2] | |
824 | if (kern.ptrsize == 8): | |
825 | rt_table_header_format_string = "{0:<18s} {1: <16s} {2:<20s} {3:<16s} {4:<8s} {5:<8s} {6:<8s}" | |
cb323159 | 826 | print rt_table_header_format_string.format("rtentry", " dst", "gw", "parent", "Refs", "Use", "flags/if") |
39236c6e A |
827 | print rt_table_header_format_string.format("-" * 18, "-" * 16, "-" * 16, "-" * 16, "-" * 8, "-" * 8, "-" * 8) |
828 | print GetRtTableAsString(rt_tables) | |
829 | else: | |
830 | rt_table_header_format_string = "{0:<8s} {1:<16s} {2:<18s} {3:<8s} {4:<8s} {5:<8s} {6:<8s}" | |
cb323159 A |
831 | print rt_table_header_format_string.format("rtentry", "dst", "gw", "parent", "Refs", "Use", "flags/if") |
832 | print rt_table_header_format_string.format("-" * 8, "-" * 16, "-" * 16, "-" * 8, "-" * 8, "-" * 8, "-" * 8) | |
39236c6e A |
833 | print GetRtTableAsString(rt_tables) |
834 | ||
835 | def GetRtInet6AsString(): | |
836 | rt_tables = kern.globals.rt_tables[30] | |
837 | if (kern.ptrsize == 8): | |
838 | rt_table_header_format_string = "{0:<18s} {1: <16s} {2:<20s} {3:<16s} {4:<8s} {5:<8s} {6:<8s}" | |
cb323159 | 839 | print rt_table_header_format_string.format("rtentry", " dst", "gw", "parent", "Refs", "Use", "flags/if") |
39236c6e A |
840 | print rt_table_header_format_string.format("-" * 18, "-" * 16, "-" * 16, "-" * 16, "-" * 8, "-" * 8, "-" * 8) |
841 | print GetRtTableAsString(rt_tables) | |
842 | else: | |
843 | rt_table_header_format_string = "{0:<8s} {1:<16s} {2:<18s} {3:<8s} {4:<8s} {5:<8s} {6:<8s}" | |
cb323159 A |
844 | print rt_table_header_format_string.format("rtentry", "dst", "gw", "parent", "Refs", "Use", "flags/if") |
845 | print rt_table_header_format_string.format("-" * 8, "-" * 16, "-" * 18, "-" * 8, "-" * 8, "-" * 8, "-" * 8) | |
39236c6e A |
846 | print GetRtTableAsString(rt_tables) |
847 | ||
848 | # Macro: show_rt_inet | |
849 | @lldb_command('show_rt_inet') | |
850 | def ShowRtInet(cmd_args=None): | |
851 | """ Display the IPv4 routing table | |
852 | """ | |
cb323159 | 853 | print GetRtInetAsString() |
39236c6e A |
854 | # EndMacro: show_rt_inet |
855 | ||
856 | # Macro: show_rt_inet6 | |
857 | @lldb_command('show_rt_inet6') | |
858 | def ShowRtInet6(cmd_args=None): | |
859 | """ Display the IPv6 routing table | |
860 | """ | |
861 | print GetRtInet6AsString() | |
862 | # EndMacro: show_rt_inet6 | |
863 | ||
864 | # Macro: rtentry_showdbg | |
865 | @lldb_command('rtentry_showdbg') | |
866 | def ShowRtEntryDebug(cmd_args=None): | |
867 | """ Print the debug information of a route entry | |
868 | """ | |
869 | if (cmd_args == None or len(cmd_args) == 0): | |
870 | print "Missing argument 0 in user function." | |
871 | return | |
872 | out_string = "" | |
873 | cnt = 0 | |
874 | rtd = kern.GetValueFromAddress(cmd_args[0], 'rtentry_dbg *') | |
875 | rtd_summary_format_string = "{0:s} {1:d}" | |
876 | out_string += rtd_summary_format_string.format("Total holds : ", rtd.rtd_refhold_cnt) + "\n" | |
877 | out_string += rtd_summary_format_string.format("Total releases : ", rtd.rtd_refrele_cnt) + "\n" | |
878 | ||
879 | ix = 0 | |
880 | while (ix < CTRACE_STACK_SIZE): | |
881 | kgm_pc = rtd.rtd_alloc.pc[ix] | |
882 | if (kgm_pc != 0): | |
883 | if (ix == 0): | |
884 | out_string += "\nAlloc: (thread " + hex(rtd.rtd_alloc.th) + "):\n" | |
885 | out_string += str(int(ix + 1)) + ": " | |
886 | out_string += GetSourceInformationForAddress(kgm_pc) | |
887 | out_string += "\n" | |
888 | ix += 1 | |
889 | ||
890 | ix = 0 | |
891 | while (ix < CTRACE_STACK_SIZE): | |
892 | kgm_pc = rtd.rtd_free.pc[ix] | |
893 | if (kgm_pc != 0): | |
894 | if (ix == 0): | |
895 | out_string += "\nFree: (thread " + hex(rtd.rtd_free.th) + "):\n" | |
896 | out_string += str(int(ix + 1)) + ": " | |
897 | out_string += GetSourceInformationForAddress(kgm_pc) | |
898 | out_string += "\n" | |
899 | ix += 1 | |
900 | ||
901 | while (cnt < RTD_TRACE_HIST_SIZE): | |
902 | ix = 0 | |
903 | while (ix < CTRACE_STACK_SIZE): | |
904 | kgm_pc = rtd.rtd_refhold[cnt].pc[ix] | |
905 | if (kgm_pc != 0): | |
906 | if (ix == 0): | |
907 | out_string += "\nHold [" + str(int(cnt)) + "] (thread " + hex(rtd.rtd_refhold[cnt].th) + "):\n" | |
908 | out_string += str(int(ix + 1)) + ": " | |
909 | out_string += GetSourceInformationForAddress(kgm_pc) | |
910 | out_string += "\n" | |
911 | ix += 1 | |
912 | cnt += 1 | |
cb323159 | 913 | |
39236c6e A |
914 | cnt = 0 |
915 | while (cnt < RTD_TRACE_HIST_SIZE): | |
916 | ix = 0 | |
917 | while (ix < CTRACE_STACK_SIZE): | |
918 | kgm_pc = rtd.rtd_refrele[cnt].pc[ix] | |
919 | if (kgm_pc != 0): | |
920 | if (ix == 0): | |
921 | out_string += "\nRelease [" + str(int(cnt)) + "] (thread " + hex(rtd.rtd_refrele[cnt].th) + "):\n" | |
922 | out_string += str(int(ix + 1)) + ": " | |
923 | out_string += GetSourceInformationForAddress(kgm_pc) | |
924 | out_string += "\n" | |
925 | ix += 1 | |
926 | cnt += 1 | |
cb323159 | 927 | |
39236c6e A |
928 | out_string += "\nTotal locks : " + str(int(rtd.rtd_lock_cnt)) |
929 | out_string += "\nTotal unlocks : " + str(int(rtd.rtd_unlock_cnt)) | |
930 | ||
931 | cnt = 0 | |
932 | while (cnt < RTD_TRACE_HIST_SIZE): | |
933 | ix = 0 | |
934 | while (ix < CTRACE_STACK_SIZE): | |
935 | kgm_pc = rtd.rtd_lock[cnt].pc[ix] | |
936 | if (kgm_pc != 0): | |
937 | if (ix == 0): | |
938 | out_string += "\nLock [" + str(int(cnt)) + "] (thread " + hex(rtd.rtd_lock[cnt].th) + "):\n" | |
939 | out_string += str(int(ix + 1)) + ": " | |
940 | out_string += GetSourceInformationForAddress(kgm_pc) | |
941 | out_string += "\n" | |
942 | ix += 1 | |
943 | cnt += 1 | |
cb323159 | 944 | |
39236c6e A |
945 | cnt = 0 |
946 | while (cnt < RTD_TRACE_HIST_SIZE): | |
947 | ix = 0 | |
948 | while (ix < CTRACE_STACK_SIZE): | |
949 | kgm_pc = rtd.rtd_unlock[cnt].pc[ix] | |
950 | if (kgm_pc != 0): | |
951 | if (ix == 0): | |
952 | out_string += "\nUnlock [" + str(int(cnt)) + "] (thread " + hex(rtd.rtd_unlock[cnt].th) + "):\n" | |
953 | out_string += str(int(ix + 1)) + ": " | |
954 | out_string += GetSourceInformationForAddress(kgm_pc) | |
955 | out_string += "\n" | |
956 | ix += 1 | |
957 | cnt += 1 | |
958 | ||
959 | print out_string | |
960 | # EndMacro: rtentry_showdbg | |
961 | ||
962 | # Macro: inifa_showdbg | |
963 | @lldb_command('inifa_showdbg') | |
964 | def InIfaShowDebug(cmd_args=None): | |
965 | """ Print the debug information of an IPv4 interface address | |
966 | """ | |
967 | if (cmd_args == None or len(cmd_args) == 0): | |
968 | print "Missing argument 0 in user function." | |
969 | return | |
970 | out_string = "" | |
971 | cnt = 0 | |
972 | inifa = kern.GetValueFromAddress(cmd_args[0], 'in_ifaddr_dbg *') | |
973 | in_ifaddr_summary_format_string = "{0:s} {1:d}" | |
974 | out_string += in_ifaddr_summary_format_string.format("Total holds : ", inifa.inifa_refhold_cnt) + "\n" | |
975 | out_string += in_ifaddr_summary_format_string.format("Total releases : ", inifa.inifa_refrele_cnt) + "\n" | |
976 | ||
977 | ix = 0 | |
978 | while (ix < CTRACE_STACK_SIZE): | |
979 | kgm_pc = inifa.inifa_alloc.pc[ix] | |
980 | if (kgm_pc != 0): | |
981 | if (ix == 0): | |
982 | out_string += "\nAlloc: (thread " + hex(inifa.inifa_alloc.th) + "):\n" | |
983 | out_string += str(int(ix + 1)) + ": " | |
984 | out_string += GetSourceInformationForAddress(kgm_pc) | |
985 | out_string += "\n" | |
986 | ix += 1 | |
987 | ||
988 | ix = 0 | |
989 | while (ix < CTRACE_STACK_SIZE): | |
990 | kgm_pc = inifa.inifa_free.pc[ix] | |
991 | if (kgm_pc != 0): | |
992 | if (ix == 0): | |
993 | out_string += "\nFree: (thread " + hex(inifa.inifa_free.th) + "):\n" | |
994 | out_string += str(int(ix + 1)) + ": " | |
995 | out_string += GetSourceInformationForAddress(kgm_pc) | |
996 | out_string += "\n" | |
997 | ix += 1 | |
998 | ||
999 | while (cnt < INIFA_TRACE_HIST_SIZE): | |
1000 | ix = 0 | |
1001 | while (ix < CTRACE_STACK_SIZE): | |
1002 | kgm_pc = inifa.inifa_refhold[cnt].pc[ix] | |
1003 | if (kgm_pc != 0): | |
1004 | if (ix == 0): | |
1005 | out_string += "\nHold [" + str(int(cnt)) + "] (thread " + hex(inifa.inifa_refhold[cnt].th) + "):\n" | |
1006 | out_string += str(int(ix + 1)) + ": " | |
1007 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1008 | out_string += "\n" | |
1009 | ix += 1 | |
1010 | cnt += 1 | |
1011 | cnt = 0 | |
1012 | ||
1013 | while (cnt < INIFA_TRACE_HIST_SIZE): | |
1014 | ix = 0 | |
1015 | while (ix < CTRACE_STACK_SIZE): | |
1016 | kgm_pc = inifa.inifa_refrele[cnt].pc[ix] | |
1017 | if (kgm_pc != 0): | |
1018 | if (ix == 0): | |
1019 | out_string += "\nRelease [" + str(int(cnt)) + "] (thread " + hex(inifa.inifa_refrele[cnt].th) + "):\n" | |
1020 | out_string += str(int(ix + 1)) + ": " | |
1021 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1022 | out_string += "\n" | |
1023 | ix += 1 | |
1024 | cnt += 1 | |
1025 | print out_string | |
1026 | # EndMacro: inifa_showdbg | |
1027 | ||
1028 | # Macro: in6ifa_showdbg | |
1029 | @lldb_command('in6ifa_showdbg') | |
1030 | def In6IfaShowDebug(cmd_args=None): | |
1031 | """ Print the debug information of an IPv6 interface address | |
1032 | """ | |
1033 | if (cmd_args == None or len(cmd_args) == 0): | |
1034 | print "Missing argument 0 in user function." | |
1035 | return | |
1036 | out_string = "" | |
1037 | cnt = 0 | |
1038 | in6ifa = kern.GetValueFromAddress(cmd_args[0], 'in6_ifaddr_dbg *') | |
1039 | in6_ifaddr_summary_format_string = "{0:s} {1:d}" | |
1040 | print in6_ifaddr_summary_format_string.format("Total holds : ", in6ifa.in6ifa_refhold_cnt) | |
1041 | print in6_ifaddr_summary_format_string.format("Total releases : ", in6ifa.in6ifa_refrele_cnt) | |
1042 | ||
1043 | ix = 0 | |
1044 | while (ix < CTRACE_STACK_SIZE): | |
1045 | kgm_pc = in6ifa.in6ifa_alloc.pc[ix] | |
1046 | if (kgm_pc != 0): | |
1047 | if (ix == 0): | |
1048 | out_string += "\nAlloc: (thread " + hex(in6ifa.in6ifa_alloc.th) + "):\n" | |
1049 | out_string += str(int(ix + 1)) + ": " | |
1050 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1051 | out_string += "\n" | |
1052 | ix += 1 | |
1053 | ||
1054 | ix = 0 | |
1055 | while (ix < CTRACE_STACK_SIZE): | |
1056 | kgm_pc = in6ifa.in6ifa_free.pc[ix] | |
1057 | if (kgm_pc != 0): | |
1058 | if (ix == 0): | |
1059 | out_string += "\nFree: (thread " + hex(in6ifa.in6ifa_free.th) + "):\n" | |
1060 | out_string += str(int(ix + 1)) + ": " | |
1061 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1062 | out_string += "\n" | |
1063 | ix += 1 | |
1064 | ||
1065 | while (cnt < IN6IFA_TRACE_HIST_SIZE): | |
1066 | ix = 0 | |
1067 | while (ix < CTRACE_STACK_SIZE): | |
1068 | kgm_pc = in6ifa.in6ifa_refhold[cnt].pc[ix] | |
1069 | if (kgm_pc != 0): | |
1070 | if (ix == 0): | |
1071 | out_string += "\nHold [" + str(int(cnt)) + "] (thread " + hex(in6ifa.in6ifa_refhold[cnt].th) + "):\n" | |
1072 | out_string += str(int(ix + 1)) + ": " | |
1073 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1074 | out_string += "\n" | |
1075 | ix += 1 | |
1076 | cnt += 1 | |
1077 | cnt = 0 | |
1078 | ||
1079 | while (cnt < IN6IFA_TRACE_HIST_SIZE): | |
1080 | ix = 0 | |
1081 | while (ix < CTRACE_STACK_SIZE): | |
1082 | kgm_pc = in6ifa.in6ifa_refrele[cnt].pc[ix] | |
1083 | if (kgm_pc != 0): | |
1084 | if (ix == 0): | |
1085 | out_string += "\nRelease [" + str(int(cnt)) + "] (thread " + hex(in6ifa.in6ifa_refrele[cnt].th) + "):\n" | |
1086 | out_string += str(int(ix + 1)) + ": " | |
1087 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1088 | out_string += "\n" | |
1089 | ix += 1 | |
1090 | cnt += 1 | |
1091 | print out_string | |
1092 | # EndMacro: in6ifa_showdbg | |
1093 | ||
1094 | # Macro: inm_showdbg | |
1095 | @lldb_command('inm_showdbg') | |
1096 | def InmShowDebug(cmd_args=None): | |
1097 | """ Print the debug information of an IPv4 multicast address | |
1098 | """ | |
1099 | if (cmd_args == None or len(cmd_args) == 0): | |
1100 | print "Missing argument 0 in user function." | |
1101 | return | |
1102 | out_string = "" | |
1103 | cnt = 0 | |
1104 | inm = kern.GetValueFromAddress(cmd_args[0], 'in_multi_dbg *') | |
1105 | in_multi_summary_format_string = "{0:s} {1:d}" | |
1106 | out_string += in_multi_summary_format_string.format("Total holds : ", inm.inm_refhold_cnt) | |
1107 | out_string += in_multi_summary_format_string.format("Total releases : ", inm.inm_refrele_cnt) | |
1108 | ||
1109 | while (cnt < INM_TRACE_HIST_SIZE): | |
1110 | ix = 0 | |
1111 | while (ix < CTRACE_STACK_SIZE): | |
1112 | kgm_pc = inm.inm_refhold[cnt].pc[ix] | |
1113 | if (kgm_pc != 0): | |
1114 | if (ix == 0): | |
1115 | out_string += "\nHold [" + str(int(cnt)) + "] (thread " + hex(inm.inm_refhold[cnt].th) + "):\n" | |
1116 | out_string += str(int(ix + 1)) + ": " | |
1117 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1118 | out_string += "\n" | |
1119 | ix += 1 | |
1120 | cnt += 1 | |
1121 | cnt = 0 | |
1122 | while (cnt < INM_TRACE_HIST_SIZE): | |
1123 | ix = 0 | |
1124 | while (ix < CTRACE_STACK_SIZE): | |
1125 | kgm_pc = inm.inm_refrele[cnt].pc[ix] | |
1126 | if (kgm_pc != 0): | |
1127 | if (ix == 0): | |
1128 | out_string += "\nRelease [" + str(int(cnt)) + "] (thread " + hex(inm.inm_refrele[cnt].th) + "):\n" | |
1129 | out_string += str(int(ix + 1)) + ": " | |
1130 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1131 | out_string += "\n" | |
1132 | ix += 1 | |
1133 | cnt += 1 | |
1134 | print out_string | |
1135 | # EndMacro: inm_showdbg | |
1136 | ||
1137 | # Macro: ifma_showdbg | |
1138 | @lldb_command('ifma_showdbg') | |
1139 | def IfmaShowDebug(cmd_args=None): | |
1140 | """ Print the debug information of a link multicast address | |
1141 | """ | |
1142 | if (cmd_args == None or len(cmd_args) == 0): | |
1143 | print "Missing argument 0 in user function." | |
1144 | return | |
1145 | out_string = "" | |
1146 | cnt = 0 | |
1147 | ifma = kern.GetValueFromAddress(cmd_args[0], 'ifmultiaddr_dbg *') | |
1148 | link_multi_summary_format_string = "{0:s} {1:d}" | |
1149 | out_string += link_multi_summary_format_string.format("Total holds : ", ifma.ifma_refhold_cnt) + "\n" | |
1150 | out_string += link_multi_summary_format_string.format("Total releases : ", ifma.ifma_refrele_cnt) + "\n" | |
1151 | ||
1152 | while (cnt < IFMA_TRACE_HIST_SIZE): | |
1153 | ix = 0 | |
1154 | while (ix < CTRACE_STACK_SIZE): | |
1155 | kgm_pc = ifma.ifma_refhold[cnt].pc[ix] | |
1156 | if (kgm_pc != 0): | |
1157 | if (ix == 0): | |
1158 | out_string += "\nHold [" + str(int(cnt)) + "] (thread " + hex(ifma.ifma_refhold[cnt].th) + "):\n" | |
1159 | out_string += str(int(ix + 1)) + ": " | |
1160 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1161 | out_string += "\n" | |
1162 | ix += 1 | |
1163 | cnt += 1 | |
1164 | cnt = 0 | |
1165 | while (cnt < IFMA_TRACE_HIST_SIZE): | |
1166 | ix = 0 | |
1167 | while (ix < CTRACE_STACK_SIZE): | |
1168 | kgm_pc = ifma.ifma_refrele[cnt].pc[ix] | |
1169 | if (kgm_pc != 0): | |
1170 | if (ix == 0): | |
1171 | out_string += "\nRelease [" + str(int(cnt)) + "] (thread " + hex(ifma.ifma_refrele[cnt].th) + "):\n" | |
1172 | out_string += str(int(ix + 1)) + ": " | |
1173 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1174 | out_string += "\n" | |
1175 | ix += 1 | |
1176 | cnt += 1 | |
1177 | print out_string | |
1178 | # EndMacro: ifma_showdbg | |
1179 | ||
1180 | # Macro: ifpref_showdbg | |
1181 | @lldb_command('ifpref_showdbg') | |
1182 | def IfpRefShowDebug(cmd_args=None): | |
1183 | """ Print the debug information of an interface ref count | |
1184 | """ | |
1185 | if (cmd_args == None or len(cmd_args) == 0): | |
1186 | print "Missing argument 0 in user function." | |
1187 | return | |
1188 | out_string = "" | |
1189 | cnt = 0 | |
1190 | dl_if = kern.GetValueFromAddress(cmd_args[0], 'dlil_ifnet_dbg *') | |
1191 | dl_if_summary_format_string = "{0:s} {1:d}" | |
1192 | out_string += dl_if_summary_format_string.format("Total holds : ", dl_if.dldbg_if_refhold_cnt) | |
1193 | out_string += dl_if_summary_format_string.format("Total releases : ", dl_if.dldbg_if_refrele_cnt) | |
1194 | ||
1195 | while (cnt < IF_REF_TRACE_HIST_SIZE): | |
1196 | ix = 0 | |
1197 | while (ix < CTRACE_STACK_SIZE): | |
1198 | kgm_pc = dl_if.dldbg_if_refhold[cnt].pc[ix] | |
1199 | if (kgm_pc != 0): | |
1200 | if (ix == 0): | |
1201 | out_string += "\nHold [" + str(int(cnt)) + "] (thread " + hex(dl_if.dldbg_if_refhold[cnt].th) + "):\n" | |
1202 | out_string += str(int(ix + 1)) + ": " | |
1203 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1204 | out_string += "\n" | |
1205 | ix += 1 | |
1206 | cnt += 1 | |
1207 | cnt = 0 | |
1208 | while (cnt < IF_REF_TRACE_HIST_SIZE): | |
1209 | ix = 0 | |
1210 | while (ix < CTRACE_STACK_SIZE): | |
1211 | kgm_pc = dl_if.dldbg_if_refrele[cnt].pc[ix] | |
1212 | if (kgm_pc != 0): | |
1213 | if (ix == 0): | |
1214 | out_string += "\nRelease [" + str(int(cnt)) + "] (thread " + hex(dl_if.dldbg_if_refrele[cnt].th) + "):\n" | |
1215 | out_string += str(int(ix + 1)) + ": " | |
1216 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1217 | out_string += "\n" | |
1218 | ix += 1 | |
1219 | cnt += 1 | |
1220 | print out_string | |
1221 | # EndMacro: ifpref_showdbg | |
1222 | ||
1223 | # Macro: ndpr_showdbg | |
1224 | @lldb_command('ndpr_showdbg') | |
1225 | def ndprShowDebug(cmd_args=None): | |
1226 | """ Print the debug information of a nd_prefix structure | |
1227 | """ | |
1228 | if (cmd_args == None or len(cmd_args) == 0): | |
1229 | print "Missing argument 0 in user function." | |
1230 | return | |
1231 | out_string = "" | |
1232 | cnt = 0 | |
1233 | ndpr = kern.GetValueFromAddress(cmd_args[0], 'nd_prefix_dbg *') | |
1234 | ndpr_summary_format_string = "{0:s} {1:d}" | |
1235 | out_string += ndpr_summary_format_string.format("Total holds : ", ndpr.ndpr_refhold_cnt) | |
1236 | out_string += ndpr_summary_format_string.format("Total releases : ", ndpr.ndpr_refrele_cnt) | |
1237 | ||
1238 | while (cnt < NDPR_TRACE_HIST_SIZE): | |
1239 | ix = 0 | |
1240 | while (ix < CTRACE_STACK_SIZE): | |
1241 | kgm_pc = ndpr.ndpr_refhold[cnt].pc[ix] | |
1242 | if (kgm_pc != 0): | |
1243 | if (ix == 0): | |
1244 | out_string += "\nHold [" + str(int(cnt)) + "] (thread " + hex(ndpr.ndpr_refhold[cnt].th) + "):\n" | |
1245 | out_string += str(int(ix + 1)) + ": " | |
1246 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1247 | out_string += "\n" | |
1248 | ix += 1 | |
1249 | cnt += 1 | |
1250 | cnt = 0 | |
1251 | while (cnt < NDPR_TRACE_HIST_SIZE): | |
1252 | ix = 0 | |
1253 | while (ix < CTRACE_STACK_SIZE): | |
1254 | kgm_pc = ndpr.ndpr_refrele[cnt].pc[ix] | |
1255 | if (kgm_pc != 0): | |
1256 | if (ix == 0): | |
1257 | out_string += "\nRelease [" + str(int(cnt)) + "] (thread " + hex(ndpr.ndpr_refrele[cnt].th) + "):\n" | |
1258 | out_string += str(int(ix + 1)) + ": " | |
1259 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1260 | out_string += "\n" | |
1261 | ix += 1 | |
1262 | cnt += 1 | |
1263 | print out_string | |
1264 | # EndMacro: ndpr_showdbg | |
1265 | ||
1266 | # Macro: nddr_showdbg | |
1267 | @lldb_command('nddr_showdbg') | |
1268 | def nddrShowDebug(cmd_args=None): | |
1269 | """ Print the debug information of a nd_defrouter structure | |
1270 | """ | |
1271 | if (cmd_args == None or len(cmd_args) == 0): | |
1272 | print "Missing argument 0 in user function." | |
1273 | return | |
1274 | out_string = "" | |
1275 | cnt = 0 | |
1276 | nddr = kern.GetValueFromAddress(cmd_args[0], 'nd_defrouter_dbg *') | |
1277 | nddr_summary_format_string = "{0:s} {1:d}" | |
1278 | out_string += nddr_summary_format_string.format("Total holds : ", nddr.nddr_refhold_cnt) | |
1279 | out_string += nddr_summary_format_string.format("Total releases : ", nddr.nddr_refrele_cnt) | |
1280 | ||
1281 | while (cnt < NDDR_TRACE_HIST_SIZE): | |
1282 | ix = 0 | |
1283 | while (ix < CTRACE_STACK_SIZE): | |
1284 | kgm_pc = nddr.nddr_refhold[cnt].pc[ix] | |
1285 | if (kgm_pc != 0): | |
1286 | if (ix == 0): | |
1287 | out_string += "\nHold [" + str(int(cnt)) + "] (thread " + hex(nddr.nddr_refhold[cnt].th) + "):\n" | |
1288 | out_string += str(int(ix + 1)) + ": " | |
1289 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1290 | out_string += "\n" | |
1291 | ix += 1 | |
1292 | cnt += 1 | |
1293 | cnt = 0 | |
1294 | while (cnt < NDDR_TRACE_HIST_SIZE): | |
1295 | ix = 0 | |
1296 | while (ix < CTRACE_STACK_SIZE): | |
1297 | kgm_pc = nddr.nddr_refrele[cnt].pc[ix] | |
1298 | if (kgm_pc != 0): | |
1299 | if (ix == 0): | |
1300 | out_string += "\nRelease [" + str(int(cnt)) + "] (thread " + hex(nddr.nddr_refrele[cnt].th) + "):\n" | |
1301 | out_string += str(int(ix + 1)) + ": " | |
1302 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1303 | out_string += "\n" | |
1304 | ix += 1 | |
1305 | cnt += 1 | |
1306 | print out_string | |
1307 | # EndMacro: nddr_showdbg | |
1308 | ||
1309 | # Macro: imo_showdbg | |
1310 | @lldb_command('imo_showdbg') | |
1311 | def IpmOptions(cmd_args=None): | |
1312 | """ Print the debug information of a ip_moptions structure | |
1313 | """ | |
1314 | if (cmd_args == None or len(cmd_args) == 0): | |
1315 | print "Missing argument 0 in user function." | |
1316 | return | |
1317 | out_string = "" | |
1318 | cnt = 0 | |
1319 | imo = kern.GetValueFromAddress(cmd_args[0], 'ip_moptions_dbg *') | |
1320 | imo_summary_format_string = "{0:s} {1:d}" | |
1321 | out_string += imo_summary_format_string.format("Total holds : ", imo.imo_refhold_cnt) | |
1322 | out_string += imo_summary_format_string.format("Total releases : ", imo.imo_refrele_cnt) | |
1323 | ||
1324 | while (cnt < IMO_TRACE_HIST_SIZE): | |
1325 | ix = 0 | |
1326 | while (ix < CTRACE_STACK_SIZE): | |
1327 | kgm_pc = imo.imo_refhold[cnt].pc[ix] | |
1328 | if (kgm_pc != 0): | |
1329 | if (ix == 0): | |
1330 | out_string += "\nHold [" + str(int(cnt)) + "] (thread " + hex(imo.imo_refhold[cnt].th) + "):\n" | |
1331 | out_string += str(int(ix + 1)) + ": " | |
1332 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1333 | out_string += "\n" | |
1334 | ix += 1 | |
1335 | cnt += 1 | |
1336 | cnt = 0 | |
1337 | while (cnt < IMO_TRACE_HIST_SIZE): | |
1338 | ix = 0 | |
1339 | while (ix < CTRACE_STACK_SIZE): | |
1340 | kgm_pc = imo.imo_refrele[cnt].pc[ix] | |
1341 | if (kgm_pc != 0): | |
1342 | if (ix == 0): | |
1343 | out_string += "\nRelease [" + str(int(cnt)) + "] (thread " + hex(imo.imo_refrele[cnt].th) + "):\n" | |
1344 | out_string += str(int(ix + 1)) + ": " | |
1345 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1346 | out_string += "\n" | |
1347 | ix += 1 | |
1348 | cnt += 1 | |
1349 | print out_string | |
1350 | # EndMacro: imo_showdbg | |
1351 | ||
1352 | # Macro: im6o_showdbg | |
1353 | @lldb_command('im6o_showdbg') | |
1354 | def IpmOptions(cmd_args=None): | |
1355 | """ Print the debug information of a ip6_moptions structure | |
1356 | """ | |
1357 | if (cmd_args == None or len(cmd_args) == 0): | |
1358 | print "Missing argument 0 in user function." | |
1359 | return | |
1360 | out_string = "" | |
1361 | cnt = 0 | |
1362 | im6o = kern.GetValueFromAddress(cmd_args[0], 'ip6_moptions_dbg *') | |
1363 | im6o_summary_format_string = "{0:s} {1:d}" | |
1364 | out_string += im6o_summary_format_string.format("Total holds : ", im6o.im6o_refhold_cnt) | |
1365 | out_string += im6o_summary_format_string.format("Total releases : ", im6o.im6o_refrele_cnt) | |
1366 | ||
1367 | while (cnt < IM6O_TRACE_HIST_SIZE): | |
1368 | ix = 0 | |
1369 | while (ix < CTRACE_STACK_SIZE): | |
1370 | kgm_pc = im6o.im6o_refhold[cnt].pc[ix] | |
1371 | if (kgm_pc != 0): | |
1372 | if (ix == 0): | |
1373 | out_string += "\nHold [" + str(int(cnt)) + "] (thread " + hex(im6o.im6o_refhold[cnt].th) + "):\n" | |
1374 | out_string += str(int(ix + 1)) + ": " | |
1375 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1376 | out_string += "\n" | |
1377 | ix += 1 | |
1378 | cnt += 1 | |
1379 | cnt = 0 | |
1380 | while (cnt < IM6O_TRACE_HIST_SIZE): | |
1381 | ix = 0 | |
1382 | while (ix < CTRACE_STACK_SIZE): | |
1383 | kgm_pc = im6o.im6o_refrele[cnt].pc[ix] | |
1384 | if (kgm_pc != 0): | |
1385 | if (ix == 0): | |
1386 | out_string += "\nRelease [" + str(int(cnt)) + "] (thread " + hex(im6o.im6o_refrele[cnt].th) + "):\n" | |
1387 | out_string += str(int(ix + 1)) + ": " | |
1388 | out_string += GetSourceInformationForAddress(kgm_pc) | |
1389 | out_string += "\n" | |
1390 | ix += 1 | |
1391 | cnt += 1 | |
1392 | print out_string | |
1393 | # EndMacro: im6o_showdbg | |
1394 | ||
1395 | # Macro: rtentry_trash | |
1396 | @lldb_command('rtentry_trash') | |
1397 | def RtEntryTrash(cmd_args=None): | |
1398 | """ Walk the list of trash route entries | |
1399 | """ | |
1400 | out_string = "" | |
1401 | rt_trash_head = kern.globals.rttrash_head | |
1402 | rtd = Cast(rt_trash_head.tqh_first, 'rtentry_dbg *') | |
1403 | rt_trash_format_string = "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}" | |
1404 | cnt = 0 | |
1405 | while (int(rtd) != 0): | |
1406 | if (cnt == 0): | |
1407 | if (kern.ptrsize == 8): | |
1408 | print " rtentry ref hold rele dst gw parent flags/if\n" | |
1409 | print " ----------------- --- ------ ------ --------------- ----- ------------------ -----------\n" | |
1410 | else: | |
1411 | print " rtentry ref hold rele dst gw parent flags/if\n" | |
1412 | print " --------- --- ------ ------ --------------- ----- ---------- -----------\n" | |
1413 | out_string += rt_trash_format_string.format(cnt, rtd, rtd.rtd_refhold_cnt - rtd.rtd_refrele_cnt, rtd.rtd_refhold_cnt, rtd.rtd_refrele_cnt) + " " | |
1414 | out_string += GetRtEntryPrDetailsAsString(rtd) + "\n" | |
1415 | rtd = rtd.rtd_trash_link.tqe_next | |
1416 | cnt += 1 | |
1417 | print out_string | |
1418 | # EndMacro: rtentry_trash | |
1419 | ||
3e170ce0 A |
1420 | # Macro: show_rtentry |
1421 | @lldb_command('show_rtentry') | |
1422 | def ShRtEntry(cmd_args=None): | |
1423 | """ Print rtentry. | |
1424 | """ | |
1425 | out_string = "" | |
1426 | rt = kern.GetValueFromAddress(cmd_args[0], 'rtentry *') | |
1427 | out_string += GetRtEntryPrDetailsAsString(rt) + "\n" | |
1428 | print out_string | |
1429 | # EndMacro: show_rtentry | |
1430 | ||
39236c6e A |
1431 | # Macro: inifa_trash |
1432 | @lldb_command('inifa_trash') | |
1433 | def InIfaTrash(cmd_args=None): | |
1434 | """ Walk the list of trash in_ifaddr entries | |
1435 | """ | |
1436 | out_string = "" | |
1437 | ifa_trash_head = kern.globals.inifa_trash_head | |
1438 | ifa = Cast(ifa_trash_head.tqh_first, 'in_ifaddr_dbg *') | |
1439 | inifa_trash_format_string = "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}" | |
1440 | cnt = 0 | |
1441 | while (int(ifa) != 0): | |
1442 | if (cnt == 0): | |
1443 | if (kern.ptrsize == 8): | |
1444 | print " in_ifa ref hold rele" | |
1445 | print " ------------------ --- ------ ----" | |
1446 | else: | |
1447 | print " in_ifa ref hold rele" | |
1448 | print " ---------- --- ----- ------" | |
1449 | out_string += inifa_trash_format_string.format(cnt + 1, ifa, ifa.inifa_refhold_cnt - ifa.inifa_refrele_cnt, ifa.inifa_refhold_cnt, ifa.inifa_refrele_cnt) + " " | |
1450 | out_string += GetSocketAddrAsStringInet(ifa.inifa.ia_ifa.ifa_addr) + "\n" | |
1451 | ifa = ifa.inifa_trash_link.tqe_next | |
1452 | cnt += 1 | |
1453 | print out_string | |
1454 | # EndMacro: inifa_trash | |
1455 | ||
1456 | # Macro: in6ifa_trash | |
1457 | @lldb_command('in6ifa_trash') | |
1458 | def In6IfaTrash(cmd_args=None): | |
1459 | """ Walk the list of trash in6_ifaddr entries | |
1460 | """ | |
1461 | out_string = "" | |
1462 | in6ifa_trash_head = kern.globals.in6ifa_trash_head | |
1463 | ifa = Cast(in6ifa_trash_head.tqh_first, 'in6_ifaddr_dbg *') | |
1464 | in6ifa_trash_format_string = "{0:4d}: 0x{1:x} {2:3d} {3:6d} {4:6d}" | |
1465 | cnt = 0 | |
1466 | while (int(ifa) != 0): | |
1467 | if (cnt == 0): | |
1468 | if (kern.ptrsize == 8): | |
1469 | print " in6_ifa ref hold rele" | |
1470 | print " ------------------ --- ------ ------" | |
1471 | else: | |
1472 | print " in6_ifa ref hold rele" | |
1473 | print " ---------- --- ------ ------" | |
1474 | out_string += in6ifa_trash_format_string.format(cnt + 1, ifa, ifa.in6ifa_refhold_cnt - ifa.in6ifa_refrele_cnt, ifa.in6ifa_refhold_cnt, ifa.in6ifa_refrele_cnt) + " " | |
1475 | out_string += GetSocketAddrAsStringInet6(ifa.in6ifa.ia_ifa.ifa_addr) + "\n" | |
1476 | ifa = ifa.in6ifa_trash_link.tqe_next | |
1477 | cnt += 1 | |
1478 | print out_string | |
1479 | # EndMacro: in6ifa_trash | |
1480 | ||
1481 | # Macro: inm_trash | |
1482 | @lldb_command('inm_trash') | |
1483 | def InmTrash(cmd_args=None): | |
1484 | """ Walk the list of trash in_multi entries | |
1485 | """ | |
1486 | out_string = "" | |
1487 | inm_trash_head = kern.globals.inm_trash_head | |
1488 | inm = Cast(inm_trash_head.tqh_first, 'in_multi_dbg *') | |
1489 | inm_trash_format_string = "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}" | |
1490 | cnt = 0 | |
1491 | while (int(inm) != 0): | |
1492 | if (cnt == 0): | |
1493 | if (kern.ptrsize == 8): | |
1494 | print " inm ref hold rele" | |
1495 | print " ------------------ --- ------ ------" | |
1496 | else: | |
1497 | print " inm ref hold rele" | |
1498 | print " ---------- --- ------ ------" | |
1499 | out_string += inm_trash_format_string.format(cnt + 1, inm, inm.inm_refhold_cnt - inm.inm_refrele_cnt, inm.inm_refhold_cnt, inm.inm_refrele_cnt) + " " | |
1500 | out_string += GetInAddrAsString(addressof(inm.inm.inm_addr)) + "\n" | |
1501 | inm = inm.inm_trash_link.tqe_next | |
1502 | cnt += 1 | |
1503 | print out_string | |
1504 | # EndMacro: inm_trash | |
1505 | ||
1506 | # Macro: in6m_trash | |
1507 | @lldb_command('in6m_trash') | |
1508 | def In6mTrash(cmd_args=None): | |
1509 | """ Walk the list of trash in6_multi entries | |
1510 | """ | |
1511 | out_string = "" | |
1512 | in6m_trash_head = kern.globals.in6m_trash_head | |
1513 | in6m = Cast(in6m_trash_head.tqh_first, 'in6_multi_dbg *') | |
1514 | in6m_trash_format_string = "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}" | |
1515 | cnt = 0 | |
1516 | while (int(in6m) != 0): | |
1517 | if (cnt == 0): | |
1518 | if (kern.ptrsize == 8): | |
1519 | print " in6m ref hold rele" | |
1520 | print " ------------------ --- ------ ------" | |
1521 | else: | |
1522 | print " in6m ref hold rele" | |
1523 | print " ---------- --- ------ ------" | |
1524 | out_string += in6m_trash_format_string.format(cnt + 1, in6m, in6m.in6m_refhold_cnt - in6m.in6m_refrele_cnt, in6m.in6m_refhold_cnt, in6m.in6m_refrele_cnt) + " " | |
1525 | out_string += GetIn6AddrAsString(addressof(in6m.in6m.in6m_addr)) + "\n" | |
1526 | in6m = in6m.in6m_trash_link.tqe_next | |
1527 | cnt += 1 | |
1528 | print out_string | |
1529 | # EndMacro: in6m_trash | |
1530 | ||
1531 | # Macro: ifma_trash | |
1532 | @lldb_command('ifma_trash') | |
1533 | def IfmaTrash(cmd_args=None): | |
1534 | """ Walk the list of trash ifmultiaddr entries | |
1535 | """ | |
1536 | out_string = "" | |
1537 | ifma_trash_head = kern.globals.ifma_trash_head | |
1538 | ifma = Cast(ifma_trash_head.tqh_first, 'ifmultiaddr_dbg *') | |
1539 | ifma_trash_format_string = "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}" | |
1540 | cnt = 0 | |
1541 | while (int(ifma) != 0): | |
1542 | if (cnt == 0): | |
1543 | if (kern.ptrsize == 8): | |
1544 | print " ifma ref hold rele" | |
1545 | print " ------------------ --- ------ ------" | |
1546 | else: | |
1547 | print " ifma ref hold rele" | |
1548 | print " ---------- --- ------ ------" | |
1549 | out_string += ifma_trash_format_string.format(cnt + 1, ifma, ifma.ifma_refhold_cnt - ifma.ifma_refrele_cnt, ifma.ifma_refhold_cnt, ifma.ifma_refrele_cnt) + " " | |
1550 | out_string += GetSocketAddrAsString(ifma.ifma.ifma_addr) + "\n" | |
1551 | out_string += " @ " + ifma.ifma.ifma_ifp.if_xname | |
1552 | ifma = ifma.ifma_trash_link.tqe_next | |
1553 | cnt += 1 | |
1554 | print out_string | |
1555 | # EndMacro: ifma_trash | |
1556 | ||
1557 | def GetInPcb(pcb, proto): | |
1558 | out_string = "" | |
1559 | out_string += hex(pcb) | |
1560 | ||
1561 | if (proto == IPPROTO_TCP): | |
1562 | out_string += " tcp" | |
cb323159 A |
1563 | elif (proto == IPPROTO_UDP): |
1564 | out_string += " udp" | |
1565 | elif (proto == IPPROTO_RAW): | |
1566 | out_string += " raw" | |
39236c6e | 1567 | else: |
cb323159 A |
1568 | out_string += str(proto) + "." |
1569 | ||
39236c6e A |
1570 | if (pcb.inp_vflag & INP_IPV4): |
1571 | out_string += "4 " | |
1572 | if (pcb.inp_vflag & INP_IPV6): | |
1573 | out_string += "6 " | |
1574 | ||
1575 | if (pcb.inp_vflag & INP_IPV4): | |
cb323159 | 1576 | out_string += " " |
39236c6e A |
1577 | out_string += GetInAddrAsString(addressof(pcb.inp_dependladdr.inp46_local.ia46_addr4)) |
1578 | else: | |
cb323159 | 1579 | out_string += " " |
39236c6e A |
1580 | out_string += GetIn6AddrAsString((pcb.inp_dependladdr.inp6_local.__u6_addr.__u6_addr8)) |
1581 | ||
1582 | out_string += " " | |
1583 | out_string += Getntohs(pcb.inp_lport) | |
1584 | out_string += " " | |
1585 | ||
1586 | if (pcb.inp_vflag & INP_IPV4): | |
cb323159 | 1587 | out_string += " " |
39236c6e A |
1588 | out_string += GetInAddrAsString(addressof(pcb.inp_dependfaddr.inp46_foreign.ia46_addr4)) |
1589 | else: | |
1590 | out_string += GetIn6AddrAsString((pcb.inp_dependfaddr.inp6_foreign.__u6_addr.__u6_addr8)) | |
1591 | ||
1592 | out_string += " " | |
1593 | out_string += Getntohs(pcb.inp_fport) | |
1594 | out_string += " " | |
1595 | ||
1596 | if (proto == IPPROTO_TCP): | |
1597 | out_string += GetTcpState(pcb.inp_ppcb) | |
1598 | ||
cb323159 | 1599 | out_string += "\n\t" |
39236c6e A |
1600 | if (pcb.inp_flags & INP_RECVOPTS): |
1601 | out_string += "recvopts " | |
1602 | if (pcb.inp_flags & INP_RECVRETOPTS): | |
1603 | out_string += "recvretopts " | |
1604 | if (pcb.inp_flags & INP_RECVDSTADDR): | |
1605 | out_string += "recvdstaddr " | |
1606 | if (pcb.inp_flags & INP_HDRINCL): | |
1607 | out_string += "hdrincl " | |
1608 | if (pcb.inp_flags & INP_HIGHPORT): | |
1609 | out_string += "highport " | |
1610 | if (pcb.inp_flags & INP_LOWPORT): | |
1611 | out_string += "lowport " | |
1612 | if (pcb.inp_flags & INP_ANONPORT): | |
1613 | out_string += "anonport " | |
1614 | if (pcb.inp_flags & INP_RECVIF): | |
1615 | out_string += "recvif " | |
1616 | if (pcb.inp_flags & INP_MTUDISC): | |
1617 | out_string += "mtudisc " | |
1618 | if (pcb.inp_flags & INP_STRIPHDR): | |
1619 | out_string += "striphdr " | |
1620 | if (pcb.inp_flags & INP_RECV_ANYIF): | |
1621 | out_string += "recv_anyif " | |
1622 | if (pcb.inp_flags & INP_INADDR_ANY): | |
1623 | out_string += "inaddr_any " | |
1624 | if (pcb.inp_flags & INP_RECVTTL): | |
1625 | out_string += "recvttl " | |
1626 | if (pcb.inp_flags & INP_UDP_NOCKSUM): | |
1627 | out_string += "nocksum " | |
1628 | if (pcb.inp_flags & INP_BOUND_IF): | |
1629 | out_string += "boundif " | |
1630 | if (pcb.inp_flags & IN6P_IPV6_V6ONLY): | |
1631 | out_string += "v6only " | |
1632 | if (pcb.inp_flags & IN6P_PKTINFO): | |
1633 | out_string += "pktinfo " | |
1634 | if (pcb.inp_flags & IN6P_HOPLIMIT): | |
1635 | out_string += "hoplimit " | |
1636 | if (pcb.inp_flags & IN6P_HOPOPTS): | |
1637 | out_string += "hopopts " | |
1638 | if (pcb.inp_flags & IN6P_DSTOPTS): | |
1639 | out_string += "dstopts " | |
1640 | if (pcb.inp_flags & IN6P_RTHDR): | |
1641 | out_string += "rthdr " | |
1642 | if (pcb.inp_flags & IN6P_RTHDRDSTOPTS): | |
1643 | out_string += "rthdrdstopts " | |
1644 | if (pcb.inp_flags & IN6P_TCLASS): | |
1645 | out_string += "rcv_tclass " | |
1646 | if (pcb.inp_flags & IN6P_AUTOFLOWLABEL): | |
1647 | out_string += "autoflowlabel " | |
1648 | if (pcb.inp_flags & IN6P_BINDV6ONLY): | |
1649 | out_string += "bindv6only " | |
1650 | if (pcb.inp_flags & IN6P_RFC2292): | |
1651 | out_string += "RFC2292 " | |
1652 | if (pcb.inp_flags & IN6P_MTU): | |
1653 | out_string += "rcv_pmtu " | |
1654 | if (pcb.inp_flags & INP_PKTINFO): | |
1655 | out_string += "pktinfo " | |
1656 | if (pcb.inp_flags & INP_FLOW_SUSPENDED): | |
1657 | out_string += "suspended " | |
1658 | if (pcb.inp_flags & INP_NO_IFT_CELLULAR): | |
1659 | out_string += "nocellular " | |
1660 | if (pcb.inp_flags & INP_FLOW_CONTROLLED): | |
1661 | out_string += "flowctld " | |
1662 | if (pcb.inp_flags & INP_FC_FEEDBACK): | |
1663 | out_string += "fcfeedback " | |
1664 | if (pcb.inp_flags2 & INP2_TIMEWAIT): | |
1665 | out_string += "timewait " | |
1666 | if (pcb.inp_flags2 & INP2_IN_FCTREE): | |
1667 | out_string += "in_fctree " | |
fe8ab488 A |
1668 | if (pcb.inp_flags2 & INP2_WANT_APP_POLICY): |
1669 | out_string += "want_app_policy " | |
cb323159 A |
1670 | |
1671 | out_string += "\n\t" | |
39236c6e A |
1672 | so = pcb.inp_socket |
1673 | if (so != 0): | |
2a1bd2d3 A |
1674 | out_string += "so=" + str(so) + " s=" + str(int(so.so_snd.sb_cc)) + " r=" + str(int(so.so_rcv.sb_cc)) |
1675 | if proto == IPPROTO_TCP : | |
1676 | tcpcb = cast(pcb.inp_ppcb, 'tcpcb *') | |
1677 | out_string += " reass=" + str(int(tcpcb.t_reassqlen)) | |
1678 | ||
1679 | out_string += " usecnt=" + str(int(so.so_usecount)) + ", " | |
39236c6e A |
1680 | |
1681 | if (pcb.inp_state == 0 or pcb.inp_state == INPCB_STATE_INUSE): | |
cb323159 | 1682 | out_string += "inuse" |
39236c6e A |
1683 | else: |
1684 | if (pcb.inp_state == INPCB_STATE_DEAD): | |
cb323159 | 1685 | out_string += "dead" |
39236c6e | 1686 | else: |
cb323159 | 1687 | out_string += "unknown (" + str(int(pcb.inp_state)) + ")" |
39236c6e A |
1688 | |
1689 | return out_string | |
1690 | ||
cb323159 A |
1691 | def CalcMbufInList(mpkt, pkt_cnt, buf_byte_cnt, mbuf_cnt, mbuf_cluster_cnt): |
1692 | while (mpkt != 0): | |
1693 | mp = mpkt | |
1694 | mpkt = mpkt.m_hdr.mh_nextpkt | |
1695 | pkt_cnt[0] +=1 | |
1696 | while (mp != 0): | |
1697 | mbuf_cnt[0] += 1 | |
1698 | buf_byte_cnt[int(mp.m_hdr.mh_type)] += 256 | |
1699 | buf_byte_cnt[Mbuf_Type.MT_LAST] += 256 | |
1700 | if (mp.m_hdr.mh_flags & 0x01): | |
1701 | mbuf_cluster_cnt[0] += 1 | |
1702 | buf_byte_cnt[int(mp.m_hdr.mh_type)] += mp.M_dat.MH.MH_dat.MH_ext.ext_size | |
1703 | buf_byte_cnt[Mbuf_Type.MT_LAST] += mp.M_dat.MH.MH_dat.MH_ext.ext_size | |
1704 | mp = mp.m_hdr.mh_next | |
1705 | ||
1706 | def CalcMbufInSB(so, snd_cc, snd_buf, rcv_cc, rcv_buf, snd_record_cnt, rcv_record_cnt, snd_mbuf_cnt, rcv_mbuf_cnt, snd_mbuf_cluster_cnt, rcv_mbuf_cluster_cnt): | |
1707 | snd_cc[0] += so.so_snd.sb_cc | |
1708 | mpkt = so.so_snd.sb_mb | |
1709 | CalcMbufInList(mpkt, snd_record_cnt, snd_buf, snd_mbuf_cnt, snd_mbuf_cluster_cnt) | |
1710 | rcv_cc[0] += so.so_rcv.sb_cc | |
1711 | mpkt = so.so_rcv.sb_mb | |
1712 | CalcMbufInList(mpkt, rcv_record_cnt, rcv_buf, rcv_mbuf_cnt, rcv_mbuf_cluster_cnt) | |
1713 | ||
39236c6e | 1714 | def GetPcbInfo(pcbi, proto): |
2a1bd2d3 A |
1715 | tcp_reassqlen = [0] |
1716 | tcp_reassq_bytes = 0 | |
1717 | mbuf_reassq_cnt = [0] | |
1718 | mbuf_reassq_bytes = [0] * (Mbuf_Type.MT_LAST + 1) | |
1719 | mbuf_reassq_cluster = [0] | |
39236c6e | 1720 | out_string = "" |
cb323159 A |
1721 | snd_mbuf_cnt = [0] |
1722 | snd_mbuf_cluster_cnt = [0] | |
1723 | snd_record_cnt = [0] | |
1724 | snd_cc = [0] | |
1725 | snd_buf = [0] * (Mbuf_Type.MT_LAST + 1) | |
1726 | rcv_mbuf_cnt = [0] | |
1727 | rcv_mbuf_cluster_cnt = [0] | |
1728 | rcv_record_cnt = [0] | |
1729 | rcv_cc = [0] | |
1730 | rcv_buf = [0] * (Mbuf_Type.MT_LAST + 1) | |
39236c6e A |
1731 | pcbseen = 0 |
1732 | out_string += "lastport " + str(int(pcbi.ipi_lastport)) + " lastlow " + str(int(pcbi.ipi_lastlow)) + " lasthi " + str(int(pcbi.ipi_lasthi)) + "\n" | |
1733 | out_string += "active pcb count is " + str(int(pcbi.ipi_count)) + "\n" | |
1734 | hashsize = pcbi.ipi_hashmask + 1 | |
1735 | out_string += "hash size is " + str(int(hashsize)) + "\n" | |
1736 | out_string += str(pcbi.ipi_hashbase) + " has the following inpcb(s):\n" | |
1737 | if (kern.ptrsize == 8): | |
cb323159 | 1738 | out_string += "pcb proto source port destination port\n" |
39236c6e A |
1739 | else: |
1740 | out_string += "pcb proto source address port destination address port\n\n" | |
1741 | ||
cb323159 A |
1742 | if proto == IPPROTO_RAW: |
1743 | head = cast(pcbi.ipi_listhead, 'inpcbhead *') | |
39236c6e A |
1744 | pcb = cast(head.lh_first, 'inpcb *') |
1745 | while pcb != 0: | |
1746 | pcbseen += 1 | |
1747 | out_string += GetInPcb(pcb, proto) + "\n" | |
1748 | so = pcb.inp_socket | |
1749 | if so != 0: | |
cb323159 A |
1750 | CalcMbufInSB(so, snd_cc, snd_buf, rcv_cc, rcv_buf, snd_record_cnt, rcv_record_cnt, snd_mbuf_cnt, rcv_mbuf_cnt, snd_mbuf_cluster_cnt, rcv_mbuf_cluster_cnt) |
1751 | pcb = cast(pcb.inp_list.le_next, 'inpcb *') | |
1752 | else: | |
1753 | i = 0 | |
1754 | hashbase = pcbi.ipi_hashbase | |
1755 | while (i < hashsize): | |
1756 | head = hashbase[i] | |
1757 | pcb = cast(head.lh_first, 'inpcb *') | |
1758 | while pcb != 0: | |
1759 | pcbseen += 1 | |
1760 | out_string += GetInPcb(pcb, proto) + "\n" | |
1761 | so = pcb.inp_socket | |
1762 | if so != 0: | |
1763 | CalcMbufInSB(so, snd_cc, snd_buf, rcv_cc, rcv_buf, snd_record_cnt, rcv_record_cnt, snd_mbuf_cnt, rcv_mbuf_cnt, snd_mbuf_cluster_cnt, rcv_mbuf_cluster_cnt) | |
1764 | if proto == IPPROTO_TCP and pcb.inp_ppcb: | |
1765 | tcpcb = cast(pcb.inp_ppcb, 'tcpcb *') | |
2a1bd2d3 A |
1766 | reass_entry = cast(tcpcb.t_segq.lh_first, 'tseg_qent *') |
1767 | curr_reass = 0 | |
1768 | while reass_entry != 0: | |
1769 | CalcMbufInList(reass_entry.tqe_m, tcp_reassqlen, mbuf_reassq_bytes, mbuf_reassq_cnt, mbuf_reassq_cluster) | |
1770 | tcp_reassq_bytes += reass_entry.tqe_len | |
1771 | curr_reass += reass_entry.tqe_len | |
1772 | ||
1773 | reass_entry = reass_entry.tqe_q.le_next | |
cb323159 A |
1774 | |
1775 | pcb = cast(pcb.inp_hash.le_next, 'inpcb *') | |
1776 | i += 1 | |
1777 | ||
1778 | out_string += "total pcbs seen: " + str(int(pcbseen)) + "\n" | |
1779 | out_string += "total send mbuf count: " + str(int(snd_mbuf_cnt[0])) + " receive mbuf count: " + str(int(rcv_mbuf_cnt[0])) + "\n" | |
1780 | out_string += "total send mbuf cluster count: " + str(int(snd_mbuf_cluster_cnt[0])) + " receive mbuf cluster count: " + str(int(rcv_mbuf_cluster_cnt[0])) + "\n" | |
1781 | out_string += "total send record count: " + str(int(snd_record_cnt[0])) + " receive record count: " + str(int(rcv_record_cnt[0])) + "\n" | |
1782 | out_string += "total snd_cc (total bytes in send buffers): " + str(int(snd_cc[0])) + " rcv_cc (total bytes in receive buffers): " + str(int(rcv_cc[0])) + "\n" | |
1783 | out_string += "total snd_buf bytes " + str(int(snd_buf[Mbuf_Type.MT_LAST])) + " rcv_buf bytes " + str(int(rcv_buf[Mbuf_Type.MT_LAST])) + "\n" | |
1784 | for x in range(Mbuf_Type.MT_LAST): | |
1785 | if (snd_buf[x] != 0 or rcv_buf[x] != 0): | |
1786 | out_string += "total snd_buf bytes of type " + Mbuf_Type.reverse_mapping[x] + " : " + str(int(snd_buf[x])) + " total recv_buf bytes of type " + Mbuf_Type.reverse_mapping[x] + " : " + str(int(rcv_buf[x])) + "\n" | |
1787 | out_string += "port hash base is " + hex(pcbi.ipi_porthashbase) + "\n" | |
1788 | if proto == IPPROTO_TCP: | |
2a1bd2d3 A |
1789 | out_string += "TCP reassembly queue length: " + str(tcp_reassqlen[0]) + " TCP-payload bytes: " + str(tcp_reassq_bytes) + "\n" |
1790 | ||
1791 | for x in range(Mbuf_Type.MT_LAST): | |
1792 | if mbuf_reassq_bytes[x] != 0: | |
1793 | out_string += "total reassq bytes of type " + Mbuf_Type.reverse_mapping[x] + " : " + str(mbuf_reassq_bytes[x]) + "\n" | |
cb323159 | 1794 | |
39236c6e A |
1795 | i = 0 |
1796 | hashbase = pcbi.ipi_porthashbase | |
1797 | while (i < hashsize): | |
1798 | head = hashbase[i] | |
1799 | pcb = cast(head.lh_first, 'inpcbport *') | |
1800 | while pcb != 0: | |
1801 | out_string += "\t" | |
1802 | out_string += GetInPcbPort(pcb) | |
1803 | out_string += "\n" | |
1804 | pcb = cast(pcb.phd_hash.le_next, 'inpcbport *') | |
1805 | i += 1 | |
1806 | ||
1807 | return out_string | |
1808 | ||
1809 | def GetInPcbPort(ppcb): | |
1810 | out_string = "" | |
1811 | out_string += hex(ppcb) + ": lport " | |
1812 | out_string += Getntohs(ppcb.phd_port) | |
1813 | return out_string | |
cb323159 | 1814 | |
39236c6e A |
1815 | |
1816 | def Getntohs(port): | |
1817 | out_string = "" | |
1818 | #p = unsigned(int(port) & 0x0000ffff) | |
1819 | p = ((port & 0x0000ff00) >> 8) | |
1820 | p |= ((port & 0x000000ff) << 8) | |
1821 | return str(p) | |
1822 | ||
f427ee49 A |
1823 | |
1824 | # Macro: mbuf_list_usage_summary | |
1825 | @lldb_command('mbuf_list_usage_summary') | |
1826 | def ShowMbufListUsageSummary(cmd_args=None): | |
1827 | """ Print mbuf list usage summary | |
1828 | """ | |
1829 | out_string = "" | |
1830 | pkt_cnt = [0] | |
1831 | buf_byte_cnt = [0] * (Mbuf_Type.MT_LAST + 1) | |
1832 | mbuf_cnt = [0] | |
1833 | mbuf_cluster_cnt = [0] | |
1834 | ||
1835 | mpkt = kern.GetValueFromAddress(cmd_args[0], 'struct mbuf *') | |
1836 | CalcMbufInList(mpkt, pkt_cnt, buf_byte_cnt, mbuf_cnt, mbuf_cluster_cnt) | |
1837 | ||
1838 | out_string += "Total packet count is " + str(int(pkt_cnt[0])) + "\n" | |
1839 | for x in range(Mbuf_Type.MT_LAST): | |
1840 | if (buf_byte_cnt[x] != 0): | |
1841 | out_string += "Total buf bytes of type " + Mbuf_Type.reverse_mapping[x] + " : " + str(int(buf_byte_cnt[x])) + "\n" | |
1842 | out_string += "Total mbuf count " + str(int(mbuf_cnt[0])) + "\n" | |
1843 | out_string += "Total mbuf cluster count " + str(int(mbuf_cluster_cnt[0])) + "\n" | |
1844 | print out_string | |
1845 | ||
39236c6e A |
1846 | # Macro: show_kern_event_pcbinfo |
1847 | def GetKernEventPcbInfo(kev_pcb_head): | |
1848 | out_string = "" | |
1849 | pcb = Cast(kev_pcb_head.lh_first, 'kern_event_pcb *') | |
1850 | if (kern.ptrsize == 8): | |
1851 | kev_pcb_format_string = "0x{0:<16x} {1:12d} {2:16d} {3:16d}" | |
1852 | out_string += " evp socket vendor code class filter subclass filter\n" | |
1853 | out_string += "-------------- ----------- ------------ ---------------\n" | |
1854 | else: | |
1855 | kev_pcb_format_string = "0x{0:<8x} {1:12d} {2:16d} {3:16d}" | |
1856 | out_string += "evp socket vendor code class filter subclass filter\n" | |
1857 | out_string += "---------- ----------- ------------ ---------------\n" | |
1858 | while (pcb != 0): | |
1859 | out_string += kev_pcb_format_string.format(pcb.evp_socket, pcb.evp_vendor_code_filter, pcb.evp_class_filter, pcb.evp_subclass_filter) | |
1860 | out_string += "\n" | |
1861 | pcb = pcb.evp_link.le_next | |
1862 | return out_string | |
1863 | ||
1864 | @lldb_command('show_kern_event_pcbinfo') | |
1865 | def ShowKernEventPcbInfo(cmd_args=None): | |
1866 | """ Display the list of Kernel Event protocol control block information | |
1867 | """ | |
1868 | print GetKernEventPcbInfo(addressof(kern.globals.kern_event_head)) | |
1869 | # EndMacro: show_kern_event_pcbinfo | |
1870 | ||
1871 | # Macro: show_kern_control_pcbinfo | |
1872 | def GetKernControlPcbInfo(ctl_head): | |
1873 | out_string = "" | |
1874 | kctl = Cast(ctl_head.tqh_first, 'kctl *') | |
cb323159 A |
1875 | if (kern.ptrsize == 8): |
1876 | kcb_format_string = "0x{0:<16x} {1:10d} {2:10d} {3:10d}\n" | |
39236c6e | 1877 | else: |
cb323159 | 1878 | kcb_format_string = "0x{0:<8x} {1:10d} {2:10d} {3:10d}\n" |
39236c6e A |
1879 | while unsigned(kctl) != 0: |
1880 | kctl_name = "controller: " + str(kctl.name) + "\n" | |
1881 | out_string += kctl_name | |
1882 | kcb = Cast(kctl.kcb_head.tqh_first, 'ctl_cb *') | |
1883 | if unsigned(kcb) != 0: | |
1884 | if (kern.ptrsize == 8): | |
cb323159 A |
1885 | out_string += "socket usecount snd_cc rcv_cc\n" |
1886 | out_string += "------ -------- ------ ------\n" | |
39236c6e | 1887 | else: |
cb323159 A |
1888 | out_string += "socket usecount snd_cc rcv_cc\n" |
1889 | out_string += "------ -------- ------ ------\n" | |
39236c6e | 1890 | while unsigned(kcb) != 0: |
cb323159 A |
1891 | so = Cast(kcb.so, 'socket *') |
1892 | snd_cc = so.so_snd.sb_cc | |
1893 | rcv_cc = so.so_rcv.sb_cc | |
1894 | out_string += kcb_format_string.format(kcb.so, kcb.usecount, snd_cc, rcv_cc) | |
39236c6e A |
1895 | kcb = kcb.next.tqe_next |
1896 | out_string += "\n" | |
1897 | kctl = kctl.next.tqe_next | |
1898 | return out_string | |
1899 | ||
1900 | @lldb_command('show_kern_control_pcbinfo') | |
1901 | def ShowKernControlPcbInfo(cmd_args=None): | |
1902 | """ Display the list of Kernel Control protocol control block information | |
1903 | """ | |
1904 | print GetKernControlPcbInfo(addressof(kern.globals.ctl_head)) | |
1905 | # EndMacro: show_kern_control_pcbinfo | |
1906 | ||
1907 | # Macro: show_tcp_pcbinfo | |
1908 | @lldb_command('show_tcp_pcbinfo') | |
1909 | def ShowTcpPcbInfo(cmd_args=None): | |
1910 | """ Display the list of TCP protocol control block information | |
1911 | """ | |
1912 | print GetPcbInfo(addressof(kern.globals.tcbinfo), IPPROTO_TCP) | |
1913 | # EndMacro: show_tcp_pcbinfo | |
1914 | ||
1915 | # Macro: show_udp_pcbinfo | |
1916 | @lldb_command('show_udp_pcbinfo') | |
1917 | def ShowUdpPcbInfo(cmd_args=None): | |
1918 | """ Display the list of UDP protocol control block information | |
1919 | """ | |
1920 | print GetPcbInfo(addressof(kern.globals.udbinfo), IPPROTO_UDP) | |
1921 | # EndMacro: show_udp_pcbinfo | |
1922 | ||
cb323159 A |
1923 | # Macro: show_rip_pcbinfo |
1924 | @lldb_command('show_rip_pcbinfo') | |
1925 | def ShowRipPcbInfo(cmd_args=None): | |
1926 | """ Display the list of Raw IP protocol control block information | |
1927 | """ | |
1928 | print GetPcbInfo(addressof(kern.globals.ripcbinfo), IPPROTO_RAW) | |
1929 | # EndMacro: show_rip_pcbinfo | |
1930 | ||
39236c6e A |
1931 | # Macro: show_tcp_timewaitslots |
1932 | @lldb_command('show_tcp_timewaitslots') | |
1933 | def ShowTcpTimeWaitSlots(cmd_args=None): | |
1934 | """ Display the list of the TCP protocol control blocks in TIMEWAIT | |
1935 | """ | |
1936 | out_string = "" | |
1937 | slot = -1 | |
1938 | _all = 0 | |
1939 | ||
1940 | if len(cmd_args) > 0: | |
1941 | if (int(cmd_args[0]) == -1): | |
1942 | _all = 1 | |
1943 | else: | |
1944 | slot = int(cmd_args[0]) | |
1945 | ||
1946 | out_string += "time wait slot size " + str(N_TIME_WAIT_SLOTS) + " cur_tw_slot " + str(int(kern.globals.cur_tw_slot)) + "\n" | |
1947 | i = 0 | |
1948 | ||
1949 | while (i < N_TIME_WAIT_SLOTS): | |
1950 | perslot = 0 | |
1951 | head = kern.globals.time_wait_slots[i] | |
1952 | if (i == slot or slot == -1): | |
1953 | pcb0 = cast(head.lh_first, 'inpcb *') | |
1954 | while (pcb0 != 0): | |
1955 | perslot += 1 | |
1956 | pcb0 = pcb0.inp_list.le_next | |
1957 | ||
1958 | out_string += " slot " + str(i) + " count " + str(perslot) + "\n" | |
1959 | ||
1960 | if (_all or i == slot): | |
1961 | pcb0 = cast(head.lh_first, 'inpcb *') | |
1962 | while (pcb0 != 0): | |
1963 | out_string += "\t" | |
1964 | out_string += GetInPcb(pcb0, IPPROTO_TCP) | |
1965 | out_string += "\n" | |
1966 | pcb0 = pcb0.inp_list.le_next | |
1967 | ||
1968 | i += 1 | |
1969 | print out_string | |
1970 | # EndMacro: show_tcp_timewaitslots | |
1971 | ||
1972 | # Macro: show_domains | |
1973 | @lldb_command('show_domains') | |
1974 | def ShowDomains(cmd_args=None): | |
1975 | """ Display the list of the domains | |
1976 | """ | |
1977 | out_string = "" | |
1978 | domains = kern.globals.domains | |
1979 | dp = Cast(domains.tqh_first, 'domain *') | |
1980 | ifma_trash_format_string = "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}" | |
1981 | cnt = 0 | |
1982 | while (dp != 0): | |
1983 | out_string += "\"" + str(dp.dom_name) + "\"" + "[" + str(int(dp.dom_refs)) + " refs] domain " + hex(dp) + "\n" | |
1984 | out_string += " family:\t" + str(int(dp.dom_family)) + "\n" | |
1985 | out_string += " flags:0x\t" + str(int(dp.dom_flags)) + "\n" | |
1986 | out_string += " rtparams:\toff=" + str(int(dp.dom_rtoffset)) + ", maxrtkey=" + str(int(dp.dom_maxrtkey)) + "\n" | |
1987 | ||
1988 | if (dp.dom_init): | |
1989 | out_string += " init:\t" | |
1990 | out_string += GetSourceInformationForAddress(dp.dom_init) + "\n" | |
1991 | if (dp.dom_externalize): | |
1992 | out_string += " externalize:\t" | |
1993 | out_string += GetSourceInformationForAddress(dp.dom_externalize) + "\n" | |
1994 | if (dp.dom_dispose): | |
1995 | out_string += " dispose:\t" | |
1996 | out_string += GetSourceInformationForAddress(dp.dom_dispose) + "\n" | |
1997 | if (dp.dom_rtattach): | |
1998 | out_string += " rtattach:\t" | |
1999 | out_string += GetSourceInformationForAddress(dp.dom_rtattach) + "\n" | |
2000 | if (dp.dom_old): | |
2001 | out_string += " old:\t" | |
2002 | out_string += GetSourceInformationForAddress(dp.dom_old) + "\n" | |
2003 | ||
2004 | pr = Cast(dp.dom_protosw.tqh_first, 'protosw *') | |
2005 | while pr != 0: | |
2006 | pru = pr.pr_usrreqs | |
2007 | out_string += "\ttype " + str(int(pr.pr_type)) + ", protocol " + str(int(pr.pr_protocol)) + ", protosw " + hex(pr) + "\n" | |
2008 | out_string += "\t flags:0x\t" + hex(pr.pr_flags) + "\n" | |
2009 | if (pr.pr_input): | |
2010 | out_string += "\t input:\t" | |
2011 | out_string += GetSourceInformationForAddress(pr.pr_input) + "\n" | |
2012 | if (pr.pr_output): | |
2013 | out_string += "\t output:\t" | |
2014 | out_string += GetSourceInformationForAddress(pr.pr_output) + "\n" | |
2015 | if (pr.pr_ctlinput): | |
2016 | out_string += "\t ctlinput:\t" | |
2017 | out_string += GetSourceInformationForAddress(pr.pr_ctlinput) + "\n" | |
2018 | if (pr.pr_ctloutput): | |
2019 | out_string += "\t ctloutput:\t" | |
2020 | out_string += GetSourceInformationForAddress(pr.pr_ctloutput) + "\n" | |
2021 | if (pr.pr_init): | |
2022 | out_string += "\t init:\t" | |
2023 | out_string += GetSourceInformationForAddress(pr.pr_init) + "\n" | |
2024 | if (pr.pr_drain): | |
2025 | out_string += "\t drain:\t" | |
2026 | out_string += GetSourceInformationForAddress(pr.pr_drain) + "\n" | |
2027 | if (pr.pr_sysctl): | |
2028 | out_string += "\t sysctl:\t" | |
2029 | out_string += GetSourceInformationForAddress(pr.pr_sysctl) + "\n" | |
2030 | if (pr.pr_lock): | |
2031 | out_string += "\t lock:\t" | |
2032 | out_string += GetSourceInformationForAddress(pr.pr_lock) + "\n" | |
2033 | if (pr.pr_unlock): | |
2034 | out_string += "\t unlock:\t" | |
2035 | out_string += GetSourceInformationForAddress(pr.pr_unlock) + "\n" | |
2036 | if (pr.pr_getlock): | |
2037 | out_string += "\t getlock:\t" | |
2038 | out_string += GetSourceInformationForAddress(pr.pr_getlock) + "\n" | |
2039 | if (pr.pr_old): | |
2040 | out_string += "\t old:\t" | |
2041 | out_string += GetSourceInformationForAddress(pr.pr_old) + "\n" | |
2042 | ||
2043 | out_string += "\t pru_flags:0x\t" + hex(pru.pru_flags) + "\n" | |
2044 | out_string += "\t abort:\t" | |
2045 | out_string += GetSourceInformationForAddress(pru.pru_abort) + "\n" | |
2046 | out_string += "\t accept:\t" | |
2047 | out_string += GetSourceInformationForAddress(pru.pru_accept) + "\n" | |
2048 | out_string += "\t attach:\t" | |
2049 | out_string += GetSourceInformationForAddress(pru.pru_attach) + "\n" | |
2050 | out_string += "\t bind:\t" | |
2051 | out_string += GetSourceInformationForAddress(pru.pru_bind) + "\n" | |
2052 | out_string += "\t connect:\t" | |
2053 | out_string += GetSourceInformationForAddress(pru.pru_connect) + "\n" | |
2054 | out_string += "\t connect2:\t" | |
2055 | out_string += GetSourceInformationForAddress(pru.pru_connect2) + "\n" | |
2056 | out_string += "\t connectx:\t" | |
2057 | out_string += GetSourceInformationForAddress(pru.pru_connectx) + "\n" | |
2058 | out_string += "\t control:\t" | |
2059 | out_string += GetSourceInformationForAddress(pru.pru_control) + "\n" | |
2060 | out_string += "\t detach:\t" | |
2061 | out_string += GetSourceInformationForAddress(pru.pru_detach) + "\n" | |
2062 | out_string += "\t disconnect:\t" | |
2063 | out_string += GetSourceInformationForAddress(pru.pru_disconnect) + "\n" | |
2064 | out_string += "\t listen:\t" | |
2065 | out_string += GetSourceInformationForAddress(pru.pru_listen) + "\n" | |
39236c6e A |
2066 | out_string += "\t peeraddr:\t" |
2067 | out_string += GetSourceInformationForAddress(pru.pru_peeraddr) + "\n" | |
2068 | out_string += "\t rcvd:\t" | |
2069 | out_string += GetSourceInformationForAddress(pru.pru_rcvd) + "\n" | |
2070 | out_string += "\t rcvoob:\t" | |
2071 | out_string += GetSourceInformationForAddress(pru.pru_rcvoob) + "\n" | |
2072 | out_string += "\t send:\t" | |
2073 | out_string += GetSourceInformationForAddress(pru.pru_send) + "\n" | |
2074 | out_string += "\t sense:\t" | |
2075 | out_string += GetSourceInformationForAddress(pru.pru_sense) + "\n" | |
2076 | out_string += "\t shutdown:\t" | |
2077 | out_string += GetSourceInformationForAddress(pru.pru_shutdown) + "\n" | |
2078 | out_string += "\t sockaddr:\t" | |
2079 | out_string += GetSourceInformationForAddress(pru.pru_sockaddr) + "\n" | |
2080 | out_string += "\t sopoll:\t" | |
2081 | out_string += GetSourceInformationForAddress(pru.pru_sopoll) + "\n" | |
2082 | out_string += "\t soreceive:\t" | |
2083 | out_string += GetSourceInformationForAddress(pru.pru_soreceive) + "\n" | |
2084 | out_string += "\t sosend:\t" | |
2085 | out_string += GetSourceInformationForAddress(pru.pru_sosend) + "\n" | |
2086 | pr = pr.pr_entry.tqe_next | |
2087 | dp = dp.dom_entry.tqe_next | |
2088 | ||
2089 | print out_string | |
2090 | # EndMacro: show_domains |