}
center->delete_file_event(cs.fd(), EVENT_WRITABLE);
+
+ update_socket_addr(target_addr.get_type());
+ lock.unlock();
+ async_msgr->learned_addr(socket_addr);
+ lock.lock();
ldout(async_msgr->cct, 10)
<< __func__ << " connect successfully, ready to send banner" << dendl;
state = STATE_CONNECTION_ESTABLISHED;
return protocol->is_connected();
}
+bool AsyncConnection::update_socket_addr(uint32_t type) {
+ sockaddr_storage ss;
+ socklen_t slen = sizeof(ss);
+ int r = getsockname(cs.fd(), (sockaddr *)&ss, &slen);
+ if (r == 0) {
+ entity_addr_t bind_addr;
+ bind_addr.set_type(type);
+ bind_addr.set_sockaddr((sockaddr*)&ss);
+ for (auto a : async_msgr->get_myaddrs().v) {
+ if (a.is_same_host(bind_addr) && a.get_port() == bind_addr.get_port()) {
+ socket_addr = a;
+ break;
+ }
+ }
+ if (socket_addr.is_blank_ip()) {
+ socket_addr = bind_addr;
+ }
+ return true;
+ }
+ return false;
+}
+
void AsyncConnection::connect(const entity_addrvec_t &addrs, int type,
entity_addr_t &target) {
ceph_assert(socket.fd() >= 0);
std::lock_guard<std::mutex> l(lock);
+
cs = std::move(socket);
- socket_addr = listen_addr;
+ if (!update_socket_addr(listen_addr.get_type())) {
+ socket_addr = listen_addr;
+ }
target_addr = peer_addr; // until we know better
+
state = STATE_ACCEPTING;
protocol->accept();
// rescheduler connection in order to avoid lock dep
peer_addr.set_port(port);
ldout(cct, 0) << __func__ << " accept peer addr is really " << peer_addr
- << " (socket is " << connection->socket_addr << ")" << dendl;
+ << " (socket is " << connection->target_addr << ")" << dendl;
}
connection->set_peer_addr(peer_addr); // so that connection_state gets set up
connection->target_addr = peer_addr;