mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-05-09 22:36:10 +02:00
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>
This commit is contained in:
parent
01798a7439
commit
d0c5c14ad8
@ -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)
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user