Skip to content

Commit

Permalink
Merge pull request #1219 from ton31337/feature/enable_hostname_capabi…
Browse files Browse the repository at this point in the history
…lity

Enable hostname capability (fqdn)
  • Loading branch information
thomas-mangin authored Jul 9, 2024
2 parents d10d79a + f168635 commit 0746cbf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/exabgp/bgp/message/open/capability/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def new(self, neighbor, restarted):
self._refresh(neighbor)
self._operational(neighbor)
self._extended_message(neighbor)
# self._hostname(neighbor) # Cumulus draft - disabling until -01 is out
self._hostname(neighbor) # https://datatracker.ietf.org/doc/html/draft-walton-bgp-hostname-capability-02
self._session(neighbor) # MUST be the last key added, really !?! dict is not ordered !
return self

Expand Down
4 changes: 2 additions & 2 deletions src/exabgp/bgp/message/open/capability/capability.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class _CapabilityCode(int):
# 128-255 Reserved for Private Use [RFC5492]
MULTISESSION_CISCO = 0x83 # What Cisco really use for Multisession (yes this is a reserved range in prod !)

HOSTNAME = 0xB8 # ExaBGP only ...
HOSTNAME = 0x49 # https://datatracker.ietf.org/doc/html/draft-walton-bgp-hostname-capability-02
OPERATIONAL = 0xB9 # ExaBGP only ...

# Internal
Expand All @@ -60,7 +60,7 @@ class _CapabilityCode(int):
ROUTE_REFRESH_CISCO: 'cisco-route-refresh',
MULTISESSION_CISCO: 'cisco-multi-sesion',
AIGP: 'aigp',
HOSTNAME: 'exabgp-experimental-hostname',
HOSTNAME: 'hostname',
}

def __new__(cls, value):
Expand Down
13 changes: 11 additions & 2 deletions src/exabgp/bgp/message/open/capability/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
License: 3-clause BSD. (See the COPYRIGHT file)
"""

# https://tools.ietf.org/html/draft-walton-bgp-hostname-capability-02
# https://datatracker.ietf.org/doc/html/draft-walton-bgp-hostname-capability-02


from exabgp.bgp.message.open.capability.capability import Capability


class HostName(Capability):
ID = Capability.CODE.HOSTNAME
HOSTNAME_MAX_LEN = 64

def __init__(self, host_name, domain_name):
self.host_name = host_name
Expand All @@ -27,7 +28,15 @@ def json(self):
return '{ "host-name": "%s", "domain-name": "%s" }' % (self.host_name, self.domain_name)

def extract(self):
return [bytes([len(self.host_name)]) + self.host_name + bytes([len(self.domain_name)]) + self.domain_name]
hostname = self.host_name.encode('utf-8')
if len(hostname) > self.HOSTNAME_MAX_LEN:
hostname = hostname[:self.HOSTNAME_MAX_LEN]

domainname = self.domain_name.encode('utf-8')
if len(domainname) > self.HOSTNAME_MAX_LEN:
domainname = domainname[:self.HOSTNAME_MAX_LEN]

return [bytes([len(hostname)]) + hostname + bytes([len(domainname)]) + domainname]

@staticmethod
def unpack_capability(instance, data, capability=None): # pylint: disable=W0613
Expand Down

0 comments on commit 0746cbf

Please sign in to comment.