packet/bmp: Correctly parse peer address with IPv4

Currently, Ryu expects that the IPv4 peer address format is
"4 bytes with IPv4 address, followed by 12 bytes padding".
However RFC 7854 says the format is
"12 bytes padding, followed by 4 bytes with IPv4 address".

This patch fixes it to correctly parse/serialize peer address.

Reported-by: Henk Smit <hhwsmit@xs4all.nl>
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Satoshi Fujimoto 2017-08-21 16:50:55 +09:00 committed by FUJITA Tomonori
parent f85ae78465
commit 98a838e487

View File

@ -208,7 +208,7 @@ class BMPPeerMessage(BMPMessage):
if peer_flags & (1 << 7):
peer_address = addrconv.ipv6.bin_to_text(peer_address)
else:
peer_address = addrconv.ipv4.bin_to_text(peer_address[:4])
peer_address = addrconv.ipv4.bin_to_text(peer_address[-4:])
peer_bgp_id = addrconv.ipv4.bin_to_text(peer_bgp_id)
@ -234,7 +234,8 @@ class BMPPeerMessage(BMPMessage):
flags |= (1 << 7)
peer_address = addrconv.ipv6.text_to_bin(self.peer_address)
else:
peer_address = addrconv.ipv4.text_to_bin(self.peer_address)
peer_address = struct.pack(
'!12x4s', addrconv.ipv4.text_to_bin(self.peer_address))
peer_bgp_id = addrconv.ipv4.text_to_bin(self.peer_bgp_id)
@ -562,7 +563,7 @@ class BMPPeerUpNotification(BMPPeerMessage):
remote_port) = struct.unpack_from(cls._PACK_STR, six.binary_type(rest))
if '.' in kwargs['peer_address']:
local_address = addrconv.ipv4.bin_to_text(local_address[:4])
local_address = addrconv.ipv4.bin_to_text(local_address[-4:])
elif ':' in kwargs['peer_address']:
local_address = addrconv.ipv6.bin_to_text(local_address)
else:
@ -586,7 +587,8 @@ class BMPPeerUpNotification(BMPPeerMessage):
msg = super(BMPPeerUpNotification, self).serialize_tail()
if '.' in self.local_address:
local_address = addrconv.ipv4.text_to_bin(self.local_address)
local_address = struct.pack(
'!12x4s', addrconv.ipv4.text_to_bin(self.local_address))
elif ':' in self.local_address:
local_address = addrconv.ipv6.text_to_bin(self.local_address)
else: