Skip to content

Commit

Permalink
Implement RFC 9072 (sender side)
Browse files Browse the repository at this point in the history
Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 committed Jul 18, 2024
1 parent c497a2b commit dfeaea0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/exabgp/bgp/message/open/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | BGP Identifier |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | Opt Parm Len |
# |Non-Ext OP Len.|Non-Ext OP Type| Extended Opt. Parm. Length |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | |
# | Optional Parameters (variable) |
Expand All @@ -40,11 +40,14 @@

# Optional Parameters:

# 0 1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
# | Parm. Type | Parm. Length | Parameter Value (variable)
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
# 0 1 2
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | Parm. Type | Parameter Length |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# ~ Parameter Value (variable) ~
# | |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+


@Message.register
Expand Down
14 changes: 14 additions & 0 deletions src/exabgp/bgp/message/open/capability/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from exabgp.bgp.message.notification import Notify

from struct import pack

# =================================================================== Parameter
#
Expand Down Expand Up @@ -183,6 +184,19 @@ def pack(self):
encoded = bytes([k, len(capability)]) + capability
parameters += bytes([2, len(encoded)]) + encoded

# If this is an extended optional parameters version, re-encode
# the OPEN message.
if len(parameters) >= 255:
parameters = b''
for k, capabilities in self.items():
for capability in capabilities.extract():
if len(capability) == 0:
continue
encoded = bytes([k, len(capability)]) + capability
parameters += pack('!BH', 2, len(encoded)) + encoded

return pack('!BBH', 255, 255, len(parameters)) + parameters

return bytes([len(parameters)]) + parameters

@staticmethod
Expand Down

0 comments on commit dfeaea0

Please sign in to comment.