-
Notifications
You must be signed in to change notification settings - Fork 197
crash: port net command #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Praveen Kumar Kannoju <[email protected]>
osandov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this. In addition to the inline comments, I have a few high-level comments:
netdev_ipv4s(),netdev_ipv6s(), andneigh_table_for_each_neighbor()all seem really useful and should be public helpers indrgn.helpers.linux.net. You can do that in a separate PR to merge before this or as separate commits in this PR, your choice.- The crash command appears to allow combining
-awith-sand-S, as well as multiple-sand-Soptions, and passing a task struct or the implicit current context to the-sand-Soptions. If we're going to support those options, we should allow that, too. That's a lot of complexity to support all at once, so maybe the initial version of this command can just support-aand the no option case, and then once that's landed we can add-s/-S. - The
--drgnoption is the main motivation for doing this porting work, so it'd be nice for the initial version of this command to support it.
Again, I appreciate your work on this!
| print_table(rows) | ||
|
|
||
| def print_net_devices(prog: Program) -> None: | ||
| rows = [["NET_DEVICE", "NAME", "IP ADDRESS(ES)"]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The NET_DEVICE header seems to be centered. You can use CellFormat for that (which might require a type annotation to make mypy happy):
| rows = [["NET_DEVICE", "NAME", "IP ADDRESS(ES)"]] | |
| rows: List[Sequence[Any]] = [[CellFormat("NET_DEVICE", "^"), "NAME", "IP ADDRESS(ES)"]] |
| rows = [["NET_DEVICE", "NAME", "IP ADDRESS(ES)"]] | ||
| net_namespaces = network.for_each_net(prog) | ||
|
|
||
| for net_namespace in net_namespaces: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crash doesn't appear to iterate over all network namespaces. It seems like it defaults to the initial network namespace (init_net), so let's do the same.
|
|
||
| for net_namespace in net_namespaces: | ||
| for name, dev in for_each_netdev(net_namespace): | ||
| net_device_ptr = hex(dev.dev.platform_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can tell, this can just use dev directly:
>>> dev.dev.platform_data == dev
True(But see the comment below for how to format this better.)
| ips = ", ".join(ip_list) | ||
| rows.append( | ||
| [ | ||
| net_device_ptr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crash doesn't include the 0x prefix, so use the x format directly:
| net_device_ptr, | |
| CellFormat(dev.value_(), "^x"), |
| rows.append( | ||
| [ | ||
| net_device_ptr, | ||
| net_device_name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just added the netdev_name() helper that you can use for this. You can use escape_ascii_string() to handle potentially bogus strings (whereas .decode() could potentially throw an exception):
| net_device_name, | |
| escape_ascii_string(netdev_name(dev), escape_backslash=True), |
| hw_type = str(hwtype_dict.get(int(neigh.dev.type))) | ||
| if int(neigh.dev.type) not in hwtype_dict.keys(): | ||
| hw_type = "ARPHRD_UNKNOWN" | ||
| hw_type = hw_type[7:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a simpler equivalent:
| hw_type = str(hwtype_dict.get(int(neigh.dev.type))) | |
| if int(neigh.dev.type) not in hwtype_dict.keys(): | |
| hw_type = "ARPHRD_UNKNOWN" | |
| hw_type = hw_type[7:] | |
| hw_type = hwtype_dict.get(int(neigh.dev.type), "ARPHRD_UNKNOWN")[7:] |
| dev_state, | ||
| ] | ||
| ) | ||
| neigh = neigh.next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be serving any purpose.
| neigh = neigh.next |
| print( | ||
| "PID: " | ||
| + str(pid) | ||
| + " TASK: " | ||
| + hex(task.value_())[2:] | ||
| + " CPU: " | ||
| + str(task_cpu(task)) | ||
| + " COMMAND: " | ||
| + task.comm.string_().decode("utf-8") | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use print_task_header() from drgn.commands.crash here.
| "FAMILY:TYPE", | ||
| "SOURCE-PORT", | ||
| "DESTINATION-PORT", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see these columns on my version of crash:
crash> net -S 1 | head
PID: 1 TASK: ffff95cb410d3080 CPU: 2 COMMAND: "systemd"
FD SOCKET SOCK
8 ffff95cb42caf1c0 ffff95cc20fc7400
struct socket {
state = SS_CONNECTED,
type = 1,
flags = 24,
file = 0xffff95cc479059c0,
sk = 0xffff95cc20fc7400,
Are they supposed to be there, or was this your addition?
| print( | ||
| "%-5s %-20s %-20s %-20s %-20s %-20s" | ||
| % ( | ||
| str(cnt), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this supposed to be the FD number, too?
crash: port net command.
Please review and let me know your comments.