IP checksum needs padding.
Move padding logic into checksum from caller.

Signed-off-by: Isaku Yamahata <[email protected]>
---
 ryu/lib/packet/icmp.py         |    2 --
 ryu/lib/packet/icmpv6.py       |    2 --
 ryu/lib/packet/packet_utils.py |    3 +++
 ryu/lib/packet/tcp.py          |    2 --
 ryu/lib/packet/udp.py          |    2 --
 5 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/ryu/lib/packet/icmp.py b/ryu/lib/packet/icmp.py
index a7d7656..6fb7ebf 100644
--- a/ryu/lib/packet/icmp.py
+++ b/ryu/lib/packet/icmp.py
@@ -72,8 +72,6 @@ class icmp(packet_base.PacketBase):
                 hdr += self.data
 
         if self.csum == 0:
-            if len(hdr) % 2:
-                hdr += '\0'
             self.csum = socket.htons(packet_utils.checksum(hdr))
             struct.pack_into('!H', hdr, 2, self.csum)
 
diff --git a/ryu/lib/packet/icmpv6.py b/ryu/lib/packet/icmpv6.py
index f143662..f0aef16 100644
--- a/ryu/lib/packet/icmpv6.py
+++ b/ryu/lib/packet/icmpv6.py
@@ -107,8 +107,6 @@ class icmpv6(packet_base.PacketBase):
             ph = struct.pack('!16s16sBBH', prev.src, prev.dst, 0, prev.nxt,
                              length)
             f = ph + hdr + payload
-            if len(f) % 2:
-                f += '\x00'
             self.csum = socket.htons(packet_utils.checksum(f))
             struct.pack_into('!H', hdr, 2, self.csum)
 
diff --git a/ryu/lib/packet/packet_utils.py b/ryu/lib/packet/packet_utils.py
index d9714f0..6584caa 100644
--- a/ryu/lib/packet/packet_utils.py
+++ b/ryu/lib/packet/packet_utils.py
@@ -20,6 +20,9 @@ def carry_around_add(a, b):
 
 
 def checksum(data):
+    if len(data) % 2:
+        data += '\x00'
+
     s = 0
     for i in range(0, len(data), 2):
         w = data[i] + (data[i + 1] << 8)
diff --git a/ryu/lib/packet/tcp.py b/ryu/lib/packet/tcp.py
index bd3442d..99182c3 100644
--- a/ryu/lib/packet/tcp.py
+++ b/ryu/lib/packet/tcp.py
@@ -72,8 +72,6 @@ class tcp(packet_base.PacketBase):
                 ph = struct.pack('!16s16sBBH', prev.src, prev.dst, 0, 6,
                                  length)
             f = ph + h + payload
-            if len(f) % 2:
-                f += '\x00'
             self.csum = socket.htons(packet_utils.checksum(f))
             struct.pack_into('!H', h, 16, self.csum)
         return h
diff --git a/ryu/lib/packet/udp.py b/ryu/lib/packet/udp.py
index c4fe529..addf436 100644
--- a/ryu/lib/packet/udp.py
+++ b/ryu/lib/packet/udp.py
@@ -48,8 +48,6 @@ class udp(packet_base.PacketBase):
             ph = struct.pack('!IIBBH', prev.src, prev.dst, 0, 17,
                              self.total_length)
             f = ph + h + payload
-            if len(f) % 2:
-                f += '\x00'
             self.csum = socket.htons(packet_utils.checksum(f))
             h = struct.pack(udp._PACK_STR, self.src_port, self.dst_port,
                             self.total_length, self.csum)
-- 
1.7.10.4


------------------------------------------------------------------------------
Own the Future-Intel(R) Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest. Compete 
for recognition, cash, and the chance to get your game on Steam. 
$5K grand prize plus 10 genre and skill prizes. Submit your demo 
by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to