def HaveUdpDiag():
    """Checks if the current kernel has config CONFIG_INET_UDP_DIAG enabled.

  This config is required for device running 4.9 kernel that ship with P, In
  this case always assume the config is there and use the tests to check if the
  config is enabled as required.

  For all ther other kernel version, there is no way to tell whether a dump
  succeeded: if the appropriate handler wasn't found, __inet_diag_dump just
  returns an empty result instead of an error. So, just check to see if a UDP
  dump returns no sockets when we know it should return one. If not, some tests
  will be skipped.

  Returns:
    True if the kernel is 4.9 or above, or the CONFIG_INET_UDP_DIAG is enabled.
    False otherwise.
  """
    if HAVE_SO_COOKIE_SUPPORT:
        return True
    s = socket(AF_INET6, SOCK_DGRAM, 0)
    s.bind(("::", 0))
    s.connect((s.getsockname()))
    sd = sock_diag.SockDiag()
    have_udp_diag = len(sd.DumpAllInetSockets(IPPROTO_UDP, "")) > 0
    s.close()
    return have_udp_diag
Ejemplo n.º 2
0
def HaveUdpDiag():
    # There is no way to tell whether a dump succeeded: if the appropriate handler
    # wasn't found, __inet_diag_dump just returns an empty result instead of an
    # error. So, just check to see if a UDP dump returns no sockets when we know
    # it should return one.
    s = socket(AF_INET6, SOCK_DGRAM, 0)
    s.bind(("::", 0))
    s.connect((s.getsockname()))
    sd = sock_diag.SockDiag()
    have_udp_diag = len(sd.DumpAllInetSockets(IPPROTO_UDP, "")) > 0
    s.close()
    return have_udp_diag
 def setUp(self):
     super(SockDiagBaseTest, self).setUp()
     self.sock_diag = sock_diag.SockDiag()
     self.socketpairs = {}