Ntttcp for linux - source interface ip address selection#91
Ntttcp for linux - source interface ip address selection#91lubaihua33 merged 16 commits intomicrosoft:masterfrom sagargadher-microsoft:ntttcp-for-linux-source-selection
Conversation
@microsoft-github-policy-service agree [company="{your company}"] |
@microsoft-github-policy-service agree |
|
@microsoft-github-policy-service agree |
|
Have tested all the testcases indicated in the PR description on most of the LINUX distributions! |
|
@lubaihua33 please help reviewing it. Thanks. |
|
@alid-msft - Could you please review this PR. |
There was a problem hiding this comment.
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. |
|
@simonxiaoss @lubaihua33 |
|
Hi @lubaihua33 I need one more approval to merge the change, |
There was a problem hiding this comment.
@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 Here is the gdb information. |
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. |
|
@sagargadher-microsoft Thank you for the confirmation. This is interesting. Let me reproduce this issue more times and figure out the reason. |


Description of the code change:
Introduced a new "-a" argument to the ntttcp CLI, allowing users to specify the network interface for binding.
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.
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.