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

libbpf-tools: fix local/remote address byte ordering in tcprtt #3726

Merged
merged 1 commit into from
Nov 30, 2021

Conversation

chendotjs
Copy link
Contributor

@chendotjs chendotjs commented Nov 29, 2021

Since inet_aton() converts IPv4 numbers-and-dots notation to binary in network byte order, there is no need to do htonl() again.

Signed-off-by: chendotjs [email protected]

Since inet_aton() converts IPv4 numbers-and-dots notation to binary in network byte order, there is
no need to do htonl() again.

Signed-off-by: chendotjs <[email protected]>
Comment on lines +133 to +140
env.laddr = addr.s_addr;
break;
case 'A':
if (inet_aton(arg, &addr) < 0) {
fprintf(stderr, "invalid remote address: %s\n", arg);
argp_usage(state);
}
env.raddr = htonl(addr.s_addr);
env.raddr = addr.s_addr;
Copy link
Collaborator

Choose a reason for hiding this comment

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

IIRC, this single htonl here is to avoid multiple bpf_ntohl in BPF program. This change here seems to be wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bcc/tools/tcprtt.py

Lines 161 to 175 in 2949f5a

# filter for local address
if args.laddr:
bpf_text = bpf_text.replace('LADDRFILTER',
"""if (saddr != %d)
return 0;""" % struct.unpack("=I", socket.inet_aton(args.laddr))[0])
else:
bpf_text = bpf_text.replace('LADDRFILTER', '')
# filter for remote address
if args.raddr:
bpf_text = bpf_text.replace('RADDRFILTER',
"""if (daddr != %d)
return 0;""" % struct.unpack("=I", socket.inet_aton(args.raddr))[0])
else:
bpf_text = bpf_text.replace('RADDRFILTER', '')

I suppose not. Doing htonl after inet_aton is duplicated and incorrect.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right.

inet_aton() converts the Internet host address cp from the IPv4 numbers-and-dots notation into binary form (in
network byte order) and stores it in the structure that inp points to.

Copy link
Collaborator

@chenhengqi chenhengqi left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ethercflow ethercflow left a comment

Choose a reason for hiding this comment

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

LGTM

@davemarchevsky davemarchevsky merged commit 3a05077 into iovisor:master Nov 30, 2021
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.

None yet

4 participants