components/python/oslo.utils/patches/keepalive.patch
branchs11u3-sru
changeset 6035 c9748fcc32de
equal deleted inserted replaced
6016:a477397bba8b 6035:c9748fcc32de
       
     1 In-house patch to allow the TCP keepalive parameters to be used on Solaris.
       
     2 Patch has not yet been submitted upstream.
       
     3 
       
     4 --- oslo.utils-1.4.0/oslo_utils/netutils.py.orig	2015-10-21 10:11:23.275736933 -0600
       
     5 +++ oslo.utils-1.4.0/oslo_utils/netutils.py	2015-10-21 10:11:26.709349827 -0600
       
     6 @@ -20,6 +20,7 @@ Network-related utilities and helper fun
       
     7  import logging
       
     8  import os
       
     9  import socket
       
    10 +import sys
       
    11 
       
    12  import netaddr
       
    13  import netifaces
       
    14 @@ -317,26 +317,44 @@ def set_tcp_keepalive(sock, tcp_keepaliv
       
    15      if not tcp_keepalive:
       
    16          return
       
    17  
       
    18 -    # These options aren't available in the OS X version of eventlet,
       
    19 -    # Idle + Count * Interval effectively gives you the total timeout.
       
    20 -    if tcp_keepidle is not None:
       
    21 -        if hasattr(socket, 'TCP_KEEPIDLE'):
       
    22 -            sock.setsockopt(socket.IPPROTO_TCP,
       
    23 -                            socket.TCP_KEEPIDLE,
       
    24 -                            tcp_keepidle)
       
    25 -        else:
       
    26 -            LOG.warning(_LW('tcp_keepidle not available on your system'))
       
    27 -    if tcp_keepalive_interval is not None:
       
    28 -        if hasattr(socket, 'TCP_KEEPINTVL'):
       
    29 -            sock.setsockopt(socket.IPPROTO_TCP,
       
    30 -                            socket.TCP_KEEPINTVL,
       
    31 -                            tcp_keepalive_interval)
       
    32 -        else:
       
    33 -            LOG.warning(_LW('tcp_keepintvl not available on your system'))
       
    34 -    if tcp_keepalive_count is not None:
       
    35 -        if hasattr(socket, 'TCP_KEEPCNT'):
       
    36 -            sock.setsockopt(socket.IPPROTO_TCP,
       
    37 -                            socket.TCP_KEEPCNT,
       
    38 -                            tcp_keepalive_count)
       
    39 +    if sys.platform == 'sunos5':
       
    40 +        # Should match definitions in <netinet/tcp.h>
       
    41 +        TCP_KEEPALIVE_THRESHOLD = 0x16
       
    42 +        TCP_KEEPALIVE_ABORT_THRESHOLD = 0x17
       
    43 +
       
    44 +        if tcp_keepidle is not None:
       
    45 +            sock.setsockopt(socket.IPPROTO_TCP, TCP_KEEPALIVE_THRESHOLD,
       
    46 +                            tcp_keepidle * 1000)
       
    47 +        if tcp_keepalive_interval is None and tcp_keepalive_count is None:
       
    48 +            return
       
    49 +        if tcp_keepalive_interval is None or tcp_keepalive_count is None:
       
    50 +            LOG.warning(_LW('tcp_keepintvl and tcp_keepknt must be set '
       
    51 +                            'together'))
       
    52          else:
       
    53 -            LOG.warning(_LW('tcp_keepcnt not available on your system'))
       
    54 +            sock.setsockopt(
       
    55 +                socket.IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD,
       
    56 +                tcp_keepalive_interval * tcp_keepalive_count * 1000)
       
    57 +    else:
       
    58 +        # These options aren't available in the OS X version of eventlet,
       
    59 +        # Idle + Count * Interval effectively gives you the total timeout.
       
    60 +        if tcp_keepidle is not None:
       
    61 +            if hasattr(socket, 'TCP_KEEPIDLE'):
       
    62 +                sock.setsockopt(socket.IPPROTO_TCP,
       
    63 +                                socket.TCP_KEEPIDLE,
       
    64 +                                tcp_keepidle)
       
    65 +            else:
       
    66 +                LOG.warning(_LW('tcp_keepidle not available on your system'))
       
    67 +        if tcp_keepalive_interval is not None:
       
    68 +            if hasattr(socket, 'TCP_KEEPINTVL'):
       
    69 +                sock.setsockopt(socket.IPPROTO_TCP,
       
    70 +                                socket.TCP_KEEPINTVL,
       
    71 +                                tcp_keepalive_interval)
       
    72 +            else:
       
    73 +                LOG.warning(_LW('tcp_keepintvl not available on your system'))
       
    74 +        if tcp_keepalive_count is not None:
       
    75 +            if hasattr(socket, 'TCP_KEEPCNT'):
       
    76 +                sock.setsockopt(socket.IPPROTO_TCP,
       
    77 +                                socket.TCP_KEEPCNT,
       
    78 +                                tcp_keepalive_count)
       
    79 +            else:
       
    80 +                LOG.warning(_LW('tcp_keepcnt not available on your system'))