summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFadi Moukayed <smfadi@gmail.com>2015-08-28 12:55:56 +0200
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-30 14:17:30 +0900
commit9bca06c31c675f1064a45bb4ead16f73424fbaa7 (patch)
tree8c8a0bcbc4052e4459ff6fda0bba2097e69d66f1
parent7028704b3f72e394d353a3ca7e05665649db67d7 (diff)
packet/igmp: Python 3: truncate IGMP timer fields to integers before packing
This patch adds explicit integer conversions to the IGMP timer fields. This is necessary because Python 3's pack(...) does not automatically coerce floating-point values to integers (Python 3 actually throws a struct.error on struct.pack('B', 1.0)). This fixes IgmpQuerier._send_query and IgmpSnooper._do_query under Python 3, and possibly other functions that pass/assign floats to the `maxresp' attribute. Signed-off-by: Fadi Moukayed <smfadi@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/packet/igmp.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/ryu/lib/packet/igmp.py b/ryu/lib/packet/igmp.py
index f1d65b0d..cd8f59c7 100644
--- a/ryu/lib/packet/igmp.py
+++ b/ryu/lib/packet/igmp.py
@@ -119,6 +119,7 @@ where each Group Record has the following internal format:
import six
import struct
+from math import trunc
from ryu.lib import addrconv
from ryu.lib import stringify
@@ -209,7 +210,7 @@ class igmp(packet_base.PacketBase):
def serialize(self, payload, prev):
hdr = bytearray(struct.pack(self._PACK_STR, self.msgtype,
- self.maxresp, self.csum,
+ trunc(self.maxresp), self.csum,
addrconv.ipv4.text_to_bin(self.address)))
if self.csum == 0:
@@ -299,9 +300,9 @@ class igmpv3_query(igmp):
def serialize(self, payload, prev):
s_qrv = self.s_flg << 3 | self.qrv
buf = bytearray(struct.pack(self._PACK_STR, self.msgtype,
- self.maxresp, self.csum,
+ trunc(self.maxresp), self.csum,
addrconv.ipv4.text_to_bin(self.address),
- s_qrv, self.qqic, self.num))
+ s_qrv, trunc(self.qqic), self.num))
for src in self.srcs:
buf.extend(struct.pack('4s', addrconv.ipv4.text_to_bin(src)))
if 0 == self.num: