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