Skip to content
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

drgn.helpers.linux.net: add some room helpers #353

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mina
Copy link

@mina mina commented Sep 4, 2023

They were useful in my debugging of an issue. I thought I'd contribute them.

Useful in debugging net issues that are often about skbs.

Signed-off-by: Mina Almasry <[email protected]>
Copy link
Owner

@osandov osandov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these! A few comments here, and a couple of more generic requests in line with CONTRIBUTING.rst:

  • Could you please add docstrings to these helpers?
  • Could you please add test cases? The test I added for skb_shinfo() in 470b2e0 might be good inspiration. At the very least we should call them from a test case without looking at the result to make sure they don't blow up, but bonus points if you can craft SKBs to meaningfully test these.

Comment on lines +279 to +280
def skb_is_nonlinear(skb: Object) -> Object:
return skb.data_len
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make more sense for this one to return bool:

Suggested change
def skb_is_nonlinear(skb: Object) -> Object:
return skb.data_len
def skb_is_nonlinear(skb: Object) -> bool:
return bool(skb.data_len)



def skb_headroom(skb: Object) -> Object:
return skb.data - skb.head
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the kernel, skb_headroom() returns unsigned int, but this returns ptrdiff_t. If we want to be extra accurate, we should cast this here:

Suggested change
return skb.data - skb.head
return cast("unsigned int", skb.data - skb.head)

Comment on lines +283 to +286
def skb_tailroom(skb: Object) -> IntegerLike:
if skb_is_nonlinear(skb):
return 0
return skb.end - skb.tail
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this one is int in the kernel, so it could be:

Suggested change
def skb_tailroom(skb: Object) -> IntegerLike:
if skb_is_nonlinear(skb):
return 0
return skb.end - skb.tail
def skb_tailroom(skb: Object) -> Object:
if skb_is_nonlinear(skb):
return Object(prog, "int", 0)
return cast("int", skb.end - skb.tail)

There doesn't seem to be much logic in how the return types were picked in the kernel, but we might as well copy those choices for the rest, too.

"shinfo(txflags=%u nr_frags=%u gso(size=%hu type=%u segs=%hu))\n"
"csum(0x%x ip_summed=%u complete_sw=%u valid=%u level=%u)\n"
"hash(0x%x sw=%u l4=%u) proto=0x%04x pkttype=%u iif=%d\n"
% (
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer an f-string or at least str.format() over % formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants