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