[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Clean up the traceroute test



commit 6ec4d27e8fe304492e3394029c73412dae1d0edc
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Fri Feb 28 17:31:13 2014 +0100

    Clean up the traceroute test
    
    Match UDP and TCP based on destination and source port instead of IP ID
---
 ooni/nettests/manipulation/traceroute.py |    5 +----
 ooni/templates/scapyt.py                 |    2 +-
 ooni/utils/txscapy.py                    |   23 ++++++++++++++---------
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/ooni/nettests/manipulation/traceroute.py b/ooni/nettests/manipulation/traceroute.py
index 0fb715c..6c5ca2a 100644
--- a/ooni/nettests/manipulation/traceroute.py
+++ b/ooni/nettests/manipulation/traceroute.py
@@ -1,7 +1,4 @@
 # -*- encoding: utf-8 -*-
-#
-# :authors: Arturo Filastò
-# :licence: see LICENSE
 
 from twisted.python import usage
 from twisted.internet import defer, reactor
@@ -38,7 +35,7 @@ class TracerouteTest(scapyt.BaseScapyTest):
         if self.localOptions['maxttl']:
             self.st.ttl_max = int(self.localOptions['maxttl'])
         if self.localOptions['dstport']:
-            self.st.dst_ports = int(self.localOptions['dstport'])
+            self.st.dst_ports = [int(self.localOptions['dstport'])]
         if self.localOptions['interval']:
             self.st.interval = float(self.localOptions['interval'])
 
diff --git a/ooni/templates/scapyt.py b/ooni/templates/scapyt.py
index a4d66c2..8194925 100644
--- a/ooni/templates/scapyt.py
+++ b/ooni/templates/scapyt.py
@@ -41,7 +41,7 @@ class BaseScapyTest(NetTestCase):
         super(BaseScapyTest, self)._setUp()
 
         if not config.scapyFactory:
-            log.debug("Scapy factoring not set, registering it.")
+            log.debug("Scapy factory not set, registering it.")
             config.scapyFactory = ScapyFactory(config.advanced.interface)
 
         self.report['answer_flags'] = []
diff --git a/ooni/utils/txscapy.py b/ooni/utils/txscapy.py
index 3e4e1b4..16d8e7e 100644
--- a/ooni/utils/txscapy.py
+++ b/ooni/utils/txscapy.py
@@ -451,10 +451,10 @@ class MPTraceroute(ScapyProtocol):
 
             # Initialize or append to the lists of packets
             # with the same key
-            if k in self.received_packets:
+            if key in self.received_packets:
                 self.received_packets[key].append(packet)
             else:
-                self.received_packets[key] = [pcket]
+                self.received_packets[key] = [packet]
 
         def matchResponse(k, p):
             if k in self.received_packets:
@@ -473,12 +473,12 @@ class MPTraceroute(ScapyProtocol):
                 pid = l.id
                 l = p.getlayer(3)
                 if isinstance(l, ICMPerror):
-                    addToReceivedPackets(('icmp', pid), p)
+                    addToReceivedPackets(('icmp', l.id), p)
                 elif isinstance(l, TCPerror):
-                    addToReceivedPackets(('tcp', pid), p)
+                    addToReceivedPackets(('tcp', l.dport, l.sport), p)
                 elif isinstance(l, UDPerror):
-                    addToReceivedPackets(('udp', pid), p)
-            elif p.src in self.hosts:
+                    addToReceivedPackets(('udp', l.dport, l.sport), p)
+            elif hasattr(p, 'src') and p.src in self.hosts:
                 l = p.getlayer(1)
                 if isinstance(l, ICMP):
                     addToReceivedPackets(('icmp', l.id), p)
@@ -496,10 +496,10 @@ class MPTraceroute(ScapyProtocol):
                 i += matchResponse(('icmp', p.id), p) # match by ipid
                 i += matchResponse(('icmp', l.id), p) # match by icmpid
             if isinstance(l, TCP):
-                i += matchResponse(('tcp', p.id), p) # match by ipid
+                i += matchResponse(('tcp', l.dport, l.sport), p) # match by s|dport 
                 i += matchResponse(('tcp', l.seq, l.sport, l.dport), p)
             if isinstance(l, UDP):
-                i += matchResponse(('udp', p.id), p)
+                i += matchResponse(('udp', l.dport, l.sport), p)
                 i += matchResponse(('udp', l.sport, l.dport), p)
             if i == 0:
                 log.debug("No response for packet %s" % [p])
@@ -507,7 +507,12 @@ class MPTraceroute(ScapyProtocol):
         del self._recvbuf
 
     def packetReceived(self, packet):
-        self._recvbuf.append(packet)
+        l = packet.getlayer(1)
+        if not l:
+            return
+        elif (isinstance(l, ICMP) or isinstance(l, UDP) or
+                isinstance(l, TCP)):
+            self._recvbuf.append(packet)
 
     def stopListening(self):
         self.factory.unRegisterProtocol(self)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits