]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/simple: use my addr when setting sock priority
authorKefu Chai <kchai@redhat.com>
Sat, 29 Apr 2017 05:27:49 +0000 (13:27 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 29 Apr 2017 05:38:56 +0000 (13:38 +0800)
actually we always fails to set ToS of listening
socket. 6f1037e22c2a304795895498cdc955e0ef80f8e3 reveals this issue.

Fixes: http://tracker.ceph.com/issues/19801
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/msg/simple/Pipe.cc

index 7783d4e4a877bfda70e3e344f57de096b59f9922..771c920790391539585146e46927fe9ff4ccf21d 100644 (file)
@@ -923,25 +923,29 @@ void Pipe::set_socket_options()
     int r = -1;
 #ifdef IPTOS_CLASS_CS6
     int iptos = IPTOS_CLASS_CS6;
-
-    if (peer_addr.get_family() == AF_INET) {
+    int addr_family = 0;
+    if (!peer_addr.is_blank_ip()) {
+      addr_family = peer_addr.get_family();
+    } else {
+      addr_family = msgr->get_myaddr().get_family();
+    }
+    switch (addr_family) {
+    case AF_INET:
       r = ::setsockopt(sd, IPPROTO_IP, IP_TOS, &iptos, sizeof(iptos));
-      if (r < 0) {
-        r = -errno;
-        ldout(msgr->cct,0) << "couldn't set IP_TOS to " << iptos
-                           << ": " << cpp_strerror(r) << dendl;
-      }
-    } else if (peer_addr.get_family() == AF_INET6) {
+      break;
+    case AF_INET6:
       r = ::setsockopt(sd, IPPROTO_IPV6, IPV6_TCLASS, &iptos, sizeof(iptos));
-      if (r < 0) {
-        r = -errno;
-        ldout(msgr->cct,0) << "couldn't set IPV6_TCLASS to " << iptos
-                           << ": " << cpp_strerror(r) << dendl;
-      }
-    } else {
+      break;
+    default:
       lderr(msgr->cct) << "couldn't set ToS of unknown family ("
-                      << peer_addr.get_family() << ")"
+                      << addr_family << ")"
                       << " to " << iptos << dendl;
+      return;
+    }
+    if (r < 0) {
+      r = -errno;
+      ldout(msgr->cct,0) << "couldn't set TOS to " << iptos
+                        << ": " << cpp_strerror(r) << dendl;
     }
 #endif
     // setsockopt(IPTOS_CLASS_CS6) sets the priority of the socket as 0.