summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMinoru TAKAHASHI <takahashi.minoru7@gmail.com>2015-02-20 13:43:38 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-02-20 21:15:18 +0900
commitd1ff39ebab5660945403113d0a50fa3bdd774d3c (patch)
treebd24ca72d360c4a0e2c5bb66fc990a9d521cb956
parente330e439b81572251a5c2c2882c172940430bc66 (diff)
packet lib: dhcp: Fix to calculate Hardware address length
Reported-by: Sam Russell <sam.h.russell@gmail.com> Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/packet/dhcp.py2
-rw-r--r--ryu/tests/unit/packet/test_dhcp.py53
2 files changed, 54 insertions, 1 deletions
diff --git a/ryu/lib/packet/dhcp.py b/ryu/lib/packet/dhcp.py
index 5320079a..a172e790 100644
--- a/ryu/lib/packet/dhcp.py
+++ b/ryu/lib/packet/dhcp.py
@@ -154,7 +154,7 @@ class dhcp(packet_base.PacketBase):
self.op = op
self.htype = htype
if hlen == 0:
- self.hlen = len(chaddr)
+ self.hlen = len(addrconv.mac.text_to_bin(chaddr))
else:
self.hlen = hlen
self.hops = hops
diff --git a/ryu/tests/unit/packet/test_dhcp.py b/ryu/tests/unit/packet/test_dhcp.py
index 44a10c50..cd4e8c40 100644
--- a/ryu/tests/unit/packet/test_dhcp.py
+++ b/ryu/tests/unit/packet/test_dhcp.py
@@ -205,3 +205,56 @@ class Test_dhcp_offer(unittest.TestCase):
jsondict = self.dh.to_jsondict()
dh = dhcp.dhcp.from_jsondict(jsondict['dhcp'])
eq_(str(self.dh), str(dh))
+
+
+class Test_dhcp_offer_with_hlen_zero(unittest.TestCase):
+
+ op = dhcp.DHCP_BOOT_REPLY
+ chaddr = 'aa:aa:aa:aa:aa:aa'
+ htype = 1
+ hlen = 6
+ hops = 0
+ xid = 1
+ secs = 0
+ flags = 1
+ ciaddr = '192.168.10.10'
+ yiaddr = '192.168.20.20'
+ siaddr = '192.168.30.30'
+ giaddr = '192.168.40.40'
+ sname = 'abc'
+ boot_file = ''
+
+ option_list = [
+ dhcp.option(dhcp.DHCP_MESSAGE_TYPE_OPT, '\x02', 1),
+ dhcp.option(dhcp.DHCP_SUBNET_MASK_OPT, '\xff\xff\xff\x00', 4),
+ dhcp.option(dhcp.DHCP_GATEWAY_ADDR_OPT, '\xc0\xa8\x0a\x09', 4),
+ dhcp.option(dhcp.DHCP_DNS_SERVER_ADDR_OPT, '\xc0\xa8\x0a\x09', 4),
+ dhcp.option(dhcp.DHCP_IP_ADDR_LEASE_TIME_OPT, '\x00\x03\xf4\x80', 4),
+ dhcp.option(dhcp.DHCP_RENEWAL_TIME_OPT, '\x00\x01\xfa\x40', 4),
+ dhcp.option(dhcp.DHCP_REBINDING_TIME_OPT, '\x00\x03\x75\xf0', 4),
+ dhcp.option(dhcp.DHCP_SERVER_IDENTIFIER_OPT, '\xc0\xa8\x0a\x09', 4)]
+ magic_cookie = '99.130.83.99'
+ options = dhcp.options(option_list=option_list, options_len=50,
+ magic_cookie=magic_cookie)
+
+ dh = dhcp.dhcp(op, chaddr, options, htype=htype, hlen=0,
+ hops=hops, xid=xid, secs=secs, flags=flags,
+ ciaddr=ciaddr, yiaddr=yiaddr, siaddr=siaddr,
+ giaddr=giaddr, sname=sname, boot_file=boot_file)
+
+ def test_init(self):
+ eq_(self.op, self.dh.op)
+ eq_(self.htype, self.dh.htype)
+ eq_(self.hlen, self.dh.hlen)
+ eq_(self.hops, self.dh.hops)
+ eq_(self.xid, self.dh.xid)
+ eq_(self.secs, self.dh.secs)
+ eq_(self.flags, self.dh.flags)
+ eq_(self.ciaddr, self.dh.ciaddr)
+ eq_(self.yiaddr, self.dh.yiaddr)
+ eq_(self.siaddr, self.dh.siaddr)
+ eq_(self.giaddr, self.dh.giaddr)
+ eq_(self.chaddr, self.dh.chaddr)
+ eq_(self.sname, self.dh.sname)
+ eq_(self.boot_file, self.dh.boot_file)
+ eq_(str(self.options), str(self.dh.options))