Skip to content

Ntttcp for linux - source interface ip address selection#91

Merged
lubaihua33 merged 16 commits intomicrosoft:masterfrom
sagargadher-microsoft:ntttcp-for-linux-source-selection
May 30, 2025
Merged

Ntttcp for linux - source interface ip address selection#91
lubaihua33 merged 16 commits intomicrosoft:masterfrom
sagargadher-microsoft:ntttcp-for-linux-source-selection

Conversation

@sagargadher-microsoft
Copy link
Copy Markdown
Contributor

@sagargadher-microsoft sagargadher-microsoft commented May 6, 2025

Description of the code change:

  1. Introduced a new "-a" argument to the ntttcp CLI, allowing users to specify the network interface for binding.

  2. Using the bind() socket system call with just the interface address helps with source IP selection, but it does not guarantee selection of the correct outgoing interface, which still depends on the destination IP.

  3. Added a setsockopt() call with SO_BINDTODEVICE to explicitly bind the socket to a specific interface, overriding the default route and ensuring the intended interface is used for outgoing traffic.

List of Test cases tested:

Use the -S option with the IP address assigned to eth0.

Use the -S option with the IP address assigned to eth1.

Use the -S option with an invalid or non-existent interface IP address.

Run the command without specifying the -S option.

Use the -S option with 0.0.0.0 as the interface IP address.

Use the -S option with an IPv6 address assigned to a valid interface.

Use the -S option with a loopback address (127.0.0.1).

Use the -S option with an address from a down or disconnected interface.

Use the -S option with a valid IP address that is not assigned to any interface on the host.

Comment thread src/ntttcp.c Outdated
Comment thread src/parameter.c Outdated
Comment thread src/parameter.c Outdated
Comment thread src/parameter.c Outdated
Comment thread src/parameter.c Outdated
Comment thread src/tcpstream.c Outdated
Comment thread src/tcpstream.c Outdated
Comment thread src/udpstream.c Outdated
Comment thread src/tcpstream.c Outdated
Comment thread src/tcpstream.c Outdated
Comment thread src/ntttcp.h Outdated
@sagargadher-microsoft
Copy link
Copy Markdown
Contributor Author

@sagargadher-microsoft please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree [company="{your company}"]

@sagargadher-microsoft
Copy link
Copy Markdown
Contributor Author

@sagargadher-microsoft the command you issued was incorrect. Please try again.

Examples are:

@microsoft-github-policy-service agree

and

@microsoft-github-policy-service agree company="your company"

@microsoft-github-policy-service agree

@sagargadher-microsoft
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Comment thread src/ntttcp.c Outdated
Comment thread src/tcpstream.c Outdated
Comment thread src/tcpstream.c Outdated
Comment thread src/udpstream.c Outdated
Comment thread src/udpstream.c Outdated
simonxiaoss
simonxiaoss previously approved these changes May 12, 2025
@sagargadher-microsoft
Copy link
Copy Markdown
Contributor Author

Have tested all the testcases indicated in the PR description on most of the LINUX distributions!

@squirrelsc
Copy link
Copy Markdown

@lubaihua33 please help reviewing it. Thanks.

@sagargadher-microsoft
Copy link
Copy Markdown
Contributor Author

@alid-msft - Could you please review this PR.

@squirrelsc squirrelsc requested a review from lubaihua33 May 14, 2025 17:57
Comment thread src/util.c Outdated
Comment thread src/util.c
Comment thread src/util.c Outdated
Comment thread src/util.c Outdated
Comment thread src/util.c Outdated
Comment thread src/util.c Outdated
Comment thread src/endpointsync.c Outdated
Comment thread src/endpointsync.c Outdated
Comment thread src/endpointsync.c Outdated
Comment thread src/util.c Outdated
Comment thread src/util.c Outdated
Comment thread src/util.c Outdated
Comment thread src/util.c
Comment thread src/util.c Outdated
Comment thread src/util.c Outdated
Comment thread src/util.c Outdated
Comment thread src/util.c Outdated
Comment thread src/util.c Outdated
Comment thread src/util.c Outdated
Comment thread src/util.c Outdated
Comment thread src/endpointsync.c Outdated
Comment thread src/endpointsync.c Outdated
Comment thread src/endpointsync.c Outdated
Comment thread src/endpointsync.c Outdated
Comment thread src/util.c Outdated
Comment thread src/parameter.c Outdated
@LiliDeng LiliDeng requested a review from Copilot May 20, 2025 11:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a new "-a" command-line option that enables users (senders or clients) to explicitly specify the network interface IP address for socket binding. Key changes include adding new parameters (client_address and use_client_address), updating argument parsing and usage messages, and introducing helper functions to resolve the interface name and bind sockets using SO_BINDTODEVICE.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/util.h Added declarations and the inclusion of <net/if.h> to support interface binding.
src/util.c Added implementations for validating IP addresses, retrieving interface names, and binding sockets.
src/udpstream.c Updated UDP stream sender to resolve interface names and bind sockets using the new client_address parameter.
src/tcpstream.c Updated TCP stream sender to use client IP address info for binding and interface selection.
src/parameter.c Modified argument parsing and usage output to add support for the new -a option.
src/ntttcp.h Updated structure definitions with the new client_address and use_client_address members.
src/ntttcp.c Updated default settings to include client_address initialization.
src/endpointsync.c Updated sync socket creation to incorporate client IP address binding and retrieve the corresponding interface name.

Comment thread src/util.c Outdated
Comment thread src/parameter.c Outdated
Comment thread src/parameter.c Outdated
Comment thread src/parameter.c Outdated
Comment thread src/parameter.c Outdated
Comment thread src/parameter.c Outdated
Comment thread src/parameter.c Outdated
Comment thread src/util.c Outdated
Comment thread src/util.c Outdated
Comment thread src/tcpstream.c Outdated
Comment thread src/udpstream.c Outdated
@sagargadher-microsoft
Copy link
Copy Markdown
Contributor Author

@simonxiaoss @lubaihua33
Could you please approve the review?

@sagargadher-microsoft
Copy link
Copy Markdown
Contributor Author

Hi @lubaihua33

I need one more approval to merge the change,
Could you please review and approve these changes?

Copy link
Copy Markdown
Collaborator

@lubaihua33 lubaihua33 left a comment

Choose a reason for hiding this comment

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

@sagargadher-microsoft please double check the changes, the server end has Segmentation fault:

root@lisa--720-e0-n1:/# ntttcp  -P 1 -t 10
NTTTCP for Linux 1.4.1
---------------------------------------------------------
13:37:56 INFO: no role specified. use receiver role
13:37:56 INFO: 2 threads created
13:38:20 INFO: Network activity progressing...
Segmentation fault (core dumped)

@sagargadher-microsoft
Copy link
Copy Markdown
Contributor Author

sagargadher-microsoft commented May 28, 2025

@sagargadher-microsoft please double check the changes, the server end has Segmentation fault:

root@lisa--720-e0-n1:/# ntttcp  -P 1 -t 10
NTTTCP for Linux 1.4.1
---------------------------------------------------------
13:37:56 INFO: no role specified. use receiver role
13:37:56 INFO: 2 threads created
13:38:20 INFO: Network activity progressing...
Segmentation fault (core dumped)

Could you please share the client and server commands? Let me reproduce it on my local setup.

@lubaihua33
Copy link
Copy Markdown
Collaborator

lubaihua33 commented May 29, 2025

@sagargadher-microsoft please double check the changes, the server end has Segmentation fault:

root@lisa--720-e0-n1:/# ntttcp  -P 1 -t 10
NTTTCP for Linux 1.4.1
---------------------------------------------------------
13:37:56 INFO: no role specified. use receiver role
13:37:56 INFO: 2 threads created
13:38:20 INFO: Network activity progressing...
Segmentation fault (core dumped)

Could you please share the client and server commands? Let me reproduce it on my local setup.

I used "canonical 0001-com-ubuntu-server-jammy 22_04-lts-gen2 latest" to create a VM and run this test.

Client command: ntttcp -s10.0.0.5 -P 1 -n 1 -t 10
Server command: ntttcp -P 1 -t 10

Here is the gdb information.

Core was generated by `ntttcp -P 1 -t 10'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x000062a450a23fce in get_single_value_from_os_file ()
[Current thread is 1 (Thread 0x79324ac39740 (LWP 20199))]
(gdb) bt
#0  0x000062a450a23fce in get_single_value_from_os_file ()
#1  0x000062a450a285e7 in run_ntttcp_throughput_management ()
#2  0x000062a450a2e02a in run_ntttcp_receiver ()
#3  0x000062a450a22d25 in main ()

@sagargadher-microsoft
Copy link
Copy Markdown
Contributor Author

@sagargadher-microsoft please double check the changes, the server end has Segmentation fault:

root@lisa--720-e0-n1:/# ntttcp  -P 1 -t 10
NTTTCP for Linux 1.4.1
---------------------------------------------------------
13:37:56 INFO: no role specified. use receiver role
13:37:56 INFO: 2 threads created
13:38:20 INFO: Network activity progressing...
Segmentation fault (core dumped)

Could you please share the client and server commands? Let me reproduce it on my local setup.

I used "canonical 0001-com-ubuntu-server-jammy 22_04-lts-gen2 latest" to create a VM and run this test.

Client command: ntttcp -s10.0.0.5 -P 1 -n 1 -t 10 Server command: ntttcp -P 1 -t 10

Here is the gdb information.

Core was generated by `ntttcp -P 1 -t 10'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x000062a450a23fce in get_single_value_from_os_file ()
[Current thread is 1 (Thread 0x79324ac39740 (LWP 20199))]
(gdb) bt
#0  0x000062a450a23fce in get_single_value_from_os_file ()
#1  0x000062a450a285e7 in run_ntttcp_throughput_management ()
#2  0x000062a450a2e02a in run_ntttcp_receiver ()
#3  0x000062a450a22d25 in main ()

This backtrace is pointing to the function or path where I did not do any code change.

I tried same commands and could see its running good.

image

image

@lubaihua33
Copy link
Copy Markdown
Collaborator

@sagargadher-microsoft Thank you for the confirmation. This is interesting. Let me reproduce this issue more times and figure out the reason.

@lubaihua33 lubaihua33 closed this May 29, 2025
@lubaihua33 lubaihua33 reopened this May 29, 2025
@lubaihua33 lubaihua33 self-requested a review May 29, 2025 09:28
@lubaihua33 lubaihua33 merged commit c048cef into microsoft:master May 30, 2025
4 of 6 checks passed
@sagargadher-microsoft sagargadher-microsoft deleted the ntttcp-for-linux-source-selection branch May 30, 2025 08:53
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.

7 participants