def setUpClass(cls): super(TCPAcceptTest, cls).setUpClass() # Open a port so we can observe SYN+ACKs. Since it's a dual-stack socket it # will accept both IPv4 and IPv6 connections. We do this here instead of in # each test so we can use the same socket every time. That way, if a kernel # bug causes incoming packets to mark the listening socket instead of the # accepted socket, the test will fail as soon as the next address/interface # combination is tried. cls.listensocket = net_test.IPv6TCPSocket() cls.listenport = net_test.BindRandomPort(6, cls.listensocket)
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()