summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortakahashi.minoru <takahashi.minoru7@gmail.com>2014-04-21 15:22:47 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-04-21 22:22:58 +0900
commitb47fa61dd307e180ed261a43ad85c7b73b982f84 (patch)
tree20a44422d85ad92641167dd1fa139110f71ba4d2
parent57166dc4853f64c4111e2240c9d5c6eaa64065f6 (diff)
packet lib: ipv6: Fix to calculate AH length
RFC2402 says: All IPv6 extension headers, as per RFC 1883, encode the "Hdr Ext Len" field by first subtracting 1 (64-bit word) from the header length (measured in 64-bit words). AH is an IPv6 extension header. However, since its length is measured in 32-bit words, the "Payload Length" is calculated by subtracting 2 (32 bit words). This patch fixes as follows: return (int(size) - 1) * 8 -> return (int(size) + 2) * 4 ^ ^ ^ And, this patch also fixes a default argument of length. Signed-off-by: TAKAHASHI Minoru <takahashi.minoru7@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/packet/ipv6.py4
-rw-r--r--ryu/tests/unit/packet/test_ipv6.py11
2 files changed, 11 insertions, 4 deletions
diff --git a/ryu/lib/packet/ipv6.py b/ryu/lib/packet/ipv6.py
index 960f1acb..b02ca51c 100644
--- a/ryu/lib/packet/ipv6.py
+++ b/ryu/lib/packet/ipv6.py
@@ -409,7 +409,7 @@ class auth(header):
_PACK_STR = '!BB2xII'
_MIN_LEN = struct.calcsize(_PACK_STR)
- def __init__(self, nxt=inet.IPPROTO_TCP, size=3, spi=0, seq=0,
+ def __init__(self, nxt=inet.IPPROTO_TCP, size=2, spi=0, seq=0,
data='\x00\x00\x00\x00'):
super(auth, self).__init__(nxt)
assert data is not None
@@ -420,7 +420,7 @@ class auth(header):
@classmethod
def _get_size(cls, size):
- return (int(size) - 1) * 8
+ return (int(size) + 2) * 4
@classmethod
def parser(cls, buf):
diff --git a/ryu/tests/unit/packet/test_ipv6.py b/ryu/tests/unit/packet/test_ipv6.py
index a2a13433..4229b18c 100644
--- a/ryu/tests/unit/packet/test_ipv6.py
+++ b/ryu/tests/unit/packet/test_ipv6.py
@@ -786,7 +786,14 @@ class Test_auth(unittest.TestCase):
eq_(self.data, res[4])
def test_len(self):
- eq_((4 - 1) * 8, len(self.auth))
+ eq_((4 + 2) * 4, len(self.auth))
+
+ def test_len_re(self):
+ size = 5
+ auth = ipv6.auth(
+ 0, size, 256, 1,
+ '\x21\xd3\xa9\x5c\x5f\xfd\x4d\x18\x46\x22\xb9\xf8\xf8\xf8\xf8\xf8')
+ eq_((size + 2) * 4, len(auth))
def test_default_args(self):
hdr = ipv6.auth()
@@ -796,7 +803,7 @@ class Test_auth(unittest.TestCase):
LOG.info(res)
eq_(res[0], 6)
- eq_(res[1], 3)
+ eq_(res[1], 2)
eq_(res[2], 0)
eq_(res[3], 0)
eq_(buf[ipv6.auth._MIN_LEN:], '\x00\x00\x00\x00')