From 9c1b97ba6224e9deb8a1dcb66af1894728fdc9ea Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 28 Oct 2024 18:20:13 +0100 Subject: [PATCH] topotests: fix bmp_collector handling of empty as-path When configuring the bgp_bmp test with an additional peer that sends empty AS-PATH, the bmp collector is stopping: > [2024-10-28 17:41:51] Finished dissecting data from ('192.0.2.1', 33922) > [2024-10-28 17:41:52] Data received from ('192.0.2.1', 33922): length 195 > [2024-10-28 17:41:52] Got message type: > [2024-10-28 17:41:52] unpack_from requires a buffer of at least 2 bytes for unpacking 2 bytes at offset 0 (actual buffer size is 0) > [2024-10-28 17:41:52] TCP session closed with ('192.0.2.1', 33922) > [2024-10-28 17:41:52] Server shutting down on 192.0.2.10:1789 The parser attempts to read an empty AS-path and considers the length value as a length in bytes, whereas RFC mentions this value as definining the number of AS-PAths. Fix this in the parser. Signed-off-by: Philippe Guibert --- .../lib/bmp_collector/bgp/update/path_attributes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/topotests/lib/bmp_collector/bgp/update/path_attributes.py b/tests/topotests/lib/bmp_collector/bgp/update/path_attributes.py index 3694cb4fe3df..ca49c405d147 100644 --- a/tests/topotests/lib/bmp_collector/bgp/update/path_attributes.py +++ b/tests/topotests/lib/bmp_collector/bgp/update/path_attributes.py @@ -72,6 +72,12 @@ def dissect(cls, data): if path_attr_cls == cls.UNKNOWN_ATTR: return data[offset + attr_len :], None + # RFC1771, 4.3 UPDATE Message Format + # The path segment length is a 1-octet long field containing + # the number of ASs in the path segment value field. + if type_code == PATH_ATTR_TYPE_AS_PATH and attr_len == 0: + return data[offset:], path_attr_cls.dissect(data[offset : offset + 2]) + return data[offset + attr_len :], path_attr_cls.dissect( data[offset : offset + attr_len] )