diff options
author | Isaku Yamahata <yamahata@valinux.co.jp> | 2013-03-29 12:50:57 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-03-31 18:19:42 +0900 |
commit | d0c5c14ad8ad262c4be57b7fd845654b2dd281d8 (patch) | |
tree | 98b93145552da925ee66aeeb790e099594d1af23 | |
parent | 01798a7439e3f03da5f1a033296140bae59b3671 (diff) |
lib/packet/packet_utils: improve checksum padding
IP checksum needs padding.
Move padding logic into checksum from caller.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/packet/icmp.py | 2 | ||||
-rw-r--r-- | ryu/lib/packet/icmpv6.py | 2 | ||||
-rw-r--r-- | ryu/lib/packet/packet_utils.py | 3 | ||||
-rw-r--r-- | ryu/lib/packet/tcp.py | 2 | ||||
-rw-r--r-- | 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 a7d7656e..6fb7ebfa 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 f143662f..f0aef163 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 d9714f0d..6584caa3 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 bd3442d7..99182c39 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 c4fe5297..addf436b 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) |