def CheckSockStatFile(self, name, srcaddr, srcport, dstaddr, dstport, state, txmem=0, rxmem=0): expected = [ "%s:%04X" % (net_test.FormatSockStatAddress(srcaddr), srcport), "%s:%04X" % (net_test.FormatSockStatAddress(dstaddr), dstport), "%02X" % state, "%08X:%08X" % (txmem, rxmem), str(os.getuid()), "2", "0" ] for actual in self.ReadProcNetSocket(name): # Check that rxmem and txmem don't differ too much from each other. actual_txmem, actual_rxmem = expected[3].split(":") if self.IsAlmostEqual(txmem, int(actual_txmem, 16), txmem / 4): return if self.IsAlmostEqual(rxmem, int(actual_rxmem, 16), rxmem / 4): return # Check all the parameters except rxmem and txmem. expected[3] = actual[3] if expected == actual: return self.fail("Cound not find socket matching %s" % expected)
def CheckSockStatFile(self, name, srcaddr, srcport, dstaddr, dstport, state, txmem=0, rxmem=0): expected = ["%s:%04X" % (net_test.FormatSockStatAddress(srcaddr), srcport), "%s:%04X" % (net_test.FormatSockStatAddress(dstaddr), dstport), "%02X" % state, "%08X:%08X" % (txmem, rxmem), str(os.getuid()), "2", "0"] actual = self.ReadProcNetSocket(name)[-1] self.assertListEqual(expected, actual)
def CheckForwardingCrash(self, netid, iface1, iface2): listenport = packets.RandomPort() listensocket = net_test.IPv6TCPSocket() listensocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) listensocket.bind(("::", listenport)) listensocket.listen(100) self.SetSocketMark(listensocket, netid) version = 6 remoteaddr = self.GetRemoteAddress(version) myaddr = self.MyAddress(version, netid) desc, syn = packets.SYN(listenport, version, remoteaddr, myaddr) synack_desc, synack = packets.SYNACK(version, myaddr, remoteaddr, syn) msg = "Sent %s, expected %s" % (desc, synack_desc) reply = self._ReceiveAndExpectResponse(netid, syn, synack, msg) establishing_ack = packets.ACK(version, remoteaddr, myaddr, reply)[1] self.ReceivePacketOn(netid, establishing_ack) accepted, peer = listensocket.accept() remoteport = accepted.getpeername()[1] accepted.close() desc, fin = packets.FIN(version, myaddr, remoteaddr, establishing_ack) self.ExpectPacketOn(netid, msg + ": expecting %s after close" % desc, fin) desc, finack = packets.FIN(version, remoteaddr, myaddr, fin) self.ReceivePacketOn(netid, finack) # Check our socket is now in TIME_WAIT. sockets = self.ReadProcNetSocket("tcp6") mysrc = "%s:%04X" % (net_test.FormatSockStatAddress(myaddr), listenport) mydst = "%s:%04X" % (net_test.FormatSockStatAddress(remoteaddr), remoteport) state = None sockets = [s for s in sockets if s[0] == mysrc and s[1] == mydst] self.assertEquals(1, len(sockets)) self.assertEquals("%02X" % self.TCP_TIME_WAIT, sockets[0][2]) # Remove our IP address. try: self.iproute.DelAddress(myaddr, 64, self.ifindices[netid]) self.ReceivePacketOn(iface1, finack) self.ReceivePacketOn(iface1, establishing_ack) self.ReceivePacketOn(iface1, establishing_ack) # No crashes? Good. finally: # Put back our IP address. self.SendRA(netid) listensocket.close()