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

Fix misleading use of bpf_ntohl #24483

Merged
merged 1 commit into from Mar 22, 2023
Merged

Conversation

lazybetrayer
Copy link
Contributor

@lazybetrayer lazybetrayer commented Mar 21, 2023

local_port in struct bpf_sock_ops and struct sk_msg_md is stored in host byte order. The use of bpf_ntohl is kind of misleading.

Please ensure your pull request adheres to the following guidelines:

  • For first time contributors, read Submitting a pull request
  • All code is covered by unit and/or runtime tests where feasible.
  • All commits contain a well written commit description including a title,
    description and a Fixes: #XXX line if the commit addresses a particular
    GitHub issue.
  • If your commit description contains a Fixes: <commit-id> tag, then
    please add the commit author[s] as reviewer[s] to this issue.
  • All commits are signed off. See the section Developer’s Certificate of Origin
  • Provide a title or release-note blurb suitable for the release notes.
  • Are you a user of Cilium? Please add yourself to the Users doc
  • Thanks for contributing!

`local_port` in `struct bpf_sock_ops` and `struct sk_msg_md` is stored in
host byte order. The use of `bpf_ntohl` is kind of misleading.

Signed-off-by: Wang Zhen <lazybetrayer@gmail.com>
@lazybetrayer lazybetrayer requested a review from a team as a code owner March 21, 2023 03:34
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Mar 21, 2023
@github-actions github-actions bot added the kind/community-contribution This was a contribution made by a community member. label Mar 21, 2023
@joestringer joestringer added the release-note/misc This PR makes changes that have no direct user impact. label Mar 22, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Mar 22, 2023
@joestringer
Copy link
Member

/test

@@ -29,7 +29,7 @@ static __always_inline void sk_msg_extract4_key(const struct sk_msg_md *msg,
key->sip4 = msg->local_ip4;
key->family = ENDPOINT_KEY_IPV4;

key->sport = (bpf_ntohl(msg->local_port) >> 16);
key->sport = (bpf_htonl(msg->local_port) >> 16);
Copy link
Member

Choose a reason for hiding this comment

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

@@ -30,7 +30,7 @@ static __always_inline void sk_extract4_key(const struct bpf_sock_ops *ops,
key->sip4 = ops->local_ip4;
key->family = ENDPOINT_KEY_IPV4;

key->sport = (bpf_ntohl(ops->local_port) >> 16);
key->sport = (bpf_htonl(ops->local_port) >> 16);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@sahid sahid left a comment

Choose a reason for hiding this comment

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

I guess it's a good candidate for backports. I'm wondering what kind of bug this could have made.

@joestringer
Copy link
Member

I don't think this has any practical impact, the implementations would equally either byteswap or do nothing depending on the underlying architecture. However I agree that it's confusing to take a HBO field and "convert from network to host".

@joestringer joestringer merged commit 522004b into cilium:master Mar 22, 2023
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/community-contribution This was a contribution made by a community member. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants