According to RFC 792, the Destination Unreachable and Time Exceeded ICMP types 
should have the following as data:

"Internet Header + 64 bits of Original Data Datagram”

We do not validate this, but we *should* ensure that:
1) The data_len passed in fits into a single octet
2) The length of the data passed in matches the data_len

Whether or not passing data_len is redundant (given that condition 2 ensures 
that they must be the same), is a topic for later debate. ;)

Signed-off-by: Victor J. Orlikowski <[email protected]>

diff --git a/ryu/lib/packet/icmp.py b/ryu/lib/packet/icmp.py
index 57b153c..68e5724 100644
--- a/ryu/lib/packet/icmp.py
+++ b/ryu/lib/packet/icmp.py
@@ -214,8 +214,20 @@ class dest_unreach(stringify.StringifyMixin):
 
     def __init__(self, data_len=0, mtu=0, data=None):
         super(dest_unreach, self).__init__()
-        self.data_len = data_len
+
+        if ((data_len >= 0) and (data_len <= 255)):
+            self.data_len = data_len
+        else:
+            raise ValueError('Specified data length (%d) is invalid.' % 
data_len)
+
         self.mtu = mtu
+
+        passed_data_len = 0
+        if data:
+            passed_data_len = len(data)
+        if (passed_data_len != data_len):
+            raise ValueError('Length of data (%d) does not match data_len 
(%d).' %
+                             (passed_data_len, data_len))
         self.data = data
 
     @classmethod
@@ -273,7 +285,19 @@ class TimeExceeded(stringify.StringifyMixin):
     _MIN_LEN = struct.calcsize(_PACK_STR)
 
     def __init__(self, data_len=0, data=None):
-        self.data_len = data_len
+        if ((data_len >= 0) and (data_len <= 255)):
+            self.data_len = data_len
+        else:
+            raise ValueError('Specified data length (%d) is invalid.' % 
data_len)
+
+        self.mtu = mtu
+
+        passed_data_len = 0
+        if data:
+            passed_data_len = len(data)
+        if (passed_data_len != data_len):
+            raise ValueError('Length of data (%d) does not match data_len 
(%d).' %
+                             (passed_data_len, data_len))
         self.data = data
 
     @classmethod


Best,
Victor
--
Victor J. Orlikowski <> vjo@[cs.]duke.edu

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to