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>
This commit is contained in:
takahashi.minoru 2014-04-21 15:22:47 +09:00 committed by FUJITA Tomonori
parent 57166dc485
commit b47fa61dd3
2 changed files with 11 additions and 4 deletions

View File

@ -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):

View File

@ -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')