diff options
author | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2017-05-09 16:09:53 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-05-12 09:47:48 +0900 |
commit | b327981534da9cfc311d702c55806747ec87cab2 (patch) | |
tree | 25687e4bd2eb005ddf1b1d706dd99027e6ae0c04 | |
parent | 9a4e8968ed731daec0b3f9289af85bbfbf39a336 (diff) |
packet/bgp: Properly calculate length for FlowSpec
RFC 5575 says the 'len' field in numeric or bitmask operators
represents that the length of the value field is [1 << 'len'].
But, in serializing FlowSpec messages, the packet library uses
the `len` field as the length of the value field itself.
This patch fixes it to serialize FlowSpec messages properly.
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/packet/bgp.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py index 29c5963f..adb66000 100644 --- a/ryu/lib/packet/bgp.py +++ b/ryu/lib/packet/bgp.py @@ -2661,11 +2661,12 @@ class _FlowSpecOperatorBase(_FlowSpecComponentBase): return cls(operator, value), rest def serialize_body(self): - length = (self.value.bit_length() + 7) // 8 or 1 - self.operator |= int(math.log(length, 2)) << 4 + byte_length = (self.value.bit_length() + 7) // 8 or 1 + length = int(math.ceil(math.log(byte_length, 2))) + self.operator |= length << 4 buf = struct.pack(self._OPE_PACK_STR, self.operator) - value_type = type_desc.IntDescr(length) - buf += struct.pack(self._VAL_PACK_STR % length, + value_type = type_desc.IntDescr(1 << length) + buf += struct.pack(self._VAL_PACK_STR % (1 << length), value_type.from_user(self.value)) return buf |