Copilot commented on code in PR #3304:
URL: https://github.com/apache/brpc/pull/3304#discussion_r3709071177


##########
src/brpc/rdma/rdma_endpoint.cpp:
##########
@@ -1188,7 +1188,24 @@ int RdmaEndpoint::BringUpQp(const ParsedHello& remote, 
bool is_server) {
     }
 
     attr.qp_state = IBV_QPS_RTR;
-    attr.path_mtu = IBV_MTU_1024;  // TODO: support more mtu in future
+    // MTU negotiation: use the peer-advertised MTU if available, otherwise
+    // fall back to the legacy default (IBV_MTU_1024).
+    //   Server side: remote.path_mtu is the client's active MTU;
+    //     we compute min(local, client) here.
+    //   Client side: remote.path_mtu is already the server's negotiated
+    //     min(local, client) and we use it as-is.
+    uint32_t negotiated_mtu = IBV_MTU_1024;
+    if (remote.path_mtu.has_value()) {
+        if (is_server) {
+            uint32_t local_mtu = GetRdmaActiveMtu();
+            negotiated_mtu = std::min(local_mtu, *remote.path_mtu);
+            // Store the negotiated MTU for the server hello reply.
+            _outgoing_mtu = negotiated_mtu;
+        } else {
+            negotiated_mtu = *remote.path_mtu;
+        }
+    }
+    attr.path_mtu = static_cast<ibv_mtu>(negotiated_mtu);

Review Comment:
   remote.path_mtu comes from the peer and is used directly to configure 
attr.path_mtu via static_cast<ibv_mtu>(negotiated_mtu). If a peer sends an 
out-of-range value (including 0), this can select an invalid ibv_mtu and make 
IbvModifyQp fail (handshake DoS). Validate the MTU is one of 
IBV_MTU_{256,512,1024,2048,4096} before using it; otherwise ignore it and fall 
back to IBV_MTU_1024.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to