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
Conversation
`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>
/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); |
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.
@@ -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); |
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.
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 guess it's a good candidate for backports. I'm wondering what kind of bug this could have made.
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". |
local_port
instruct bpf_sock_ops
andstruct sk_msg_md
is stored in host byte order. The use ofbpf_ntohl
is kind of misleading.Please ensure your pull request adheres to the following guidelines:
description and a
Fixes: #XXX
line if the commit addresses a particularGitHub issue.
Fixes: <commit-id>
tag, thenplease add the commit author[s] as reviewer[s] to this issue.