support SO_BINDTODEVICE and bind client_host#3179
Conversation
2571ebd to
2578b05
Compare
|
The unit test is broken, please fix. |
There was a problem hiding this comment.
Pull request overview
This PR adds support for binding client sockets to a specific IP address or hostname before connecting to a server, addressing issue #3157. The feature allows users to control which local network interface is used for outgoing connections.
- Adds
client_hostfield toChannelOptionsfor user configuration - Propagates client endpoint information through
SocketOptions,GetNamingServiceThreadOptions, and channel signature computation - Implements socket binding in
Socket::Connect()to bind the client socket to the specified IP before connecting
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| src/brpc/channel.h | Adds client_host string field to ChannelOptions for specifying client IP/hostname |
| src/brpc/channel.cpp | Implements parsing of client_host to EndPoint and includes it in channel signature; handles both InitSingle and Init paths |
| src/brpc/socket.h | Adds local_side field to SocketOptions to store the client endpoint |
| src/brpc/socket.cpp | Implements bind() call in Connect() to bind socket to client IP; initializes local_side from options |
| src/brpc/socket_map.h | Updates function signatures to accept client_end_point parameter |
| src/brpc/socket_map.cpp | Passes client_end_point through to SocketOptions when creating sockets |
| src/brpc/details/naming_service_thread.h | Adds client_end_point field to GetNamingServiceThreadOptions |
| src/brpc/details/naming_service_thread.cpp | Passes client_end_point to SocketMapInsert when adding servers |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
11468f5 to
8bd8610
Compare
8bd8610 to
4aac92d
Compare
|
Please add some unit tests for this feature. |
8a2dc92 to
1bff8cb
Compare
@chenBright done |
|
LGTM |
6cb6396 to
c1c6e1a
Compare
c1c6e1a to
8650f00
Compare
| // We need to do async connect (to manage the timeout by ourselves). | ||
| CHECK_EQ(0, butil::make_non_blocking(sockfd)); | ||
|
|
||
| if (!_device_name.empty()) { |
There was a problem hiding this comment.
不是很确定 #3157 需要的是指定source IP,还是指定网络设备。如果只需要指定source IP, 之前的bind可以满足需求。这里要不要把之前的那个client_host选项一并加进来?
There was a problem hiding this comment.
确实可以加进来,让网络配置更精细化,我有空合并一下
@wwbmmm 大佬,可以合并了吗? |
6d77bb9 to
ec6d269
Compare
ec6d269 to
46b8adf
Compare
What problem does this PR solve?
Issue Number: #3157, #3178
Problem Summary:
What is changed and the side effects?
Changed:
1.在ChannelOptions中添加client_host和device_name,让用户设置client的ip或hostname和网卡名称
2.在SocketOptions 中添加butil::EndPoint local_side,由 client_host:0 -> local_side
3.在GetNamingServiceThreadOptions添加butil::EndPoint client_end_point,由 client_host:0 -> client_end_point
4.在ComputeChannelSignature中append "clih=client_host", 进行hash
5.在系统调用socket创建socket后,调用bind绑定ip以及绑定网卡
Side effects:
Performance effects:
Breaking backward compatibility:
Check List: