Skip to content

Commit

Permalink
work on #1183
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-mangin committed Oct 31, 2023
1 parent 2946f34 commit f320ac9
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions src/exabgp/configuration/flow/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,32 @@ def rate_limit(tokeniser):
def redirect(tokeniser):
data = tokeniser()
count = data.count(':')

# the redirect is an IPv4
if count == 0:
return IP.create(data), ExtendedCommunities().add(TrafficNextHopSimpson(False))
if count == 1:

# the redirect is an IPv6
if data.startswith('[') and data.endswith(']'):
return IP.create(data[1:-1]), ExtendedCommunities().add(TrafficNextHopSimpson(False))

# the redirect is an ipv6:asn using []: notation
if count > 1:
if ']:' not in data:
raise ValueError('it looks like you tried to use an IPv6 but did not enclose it in []')

ip, asn = data.split(']:')
ip = ip.replace('[', '', 1)

# FIXME: should this be 2^16 ??
if asn >= pow(2, 32):
raise ValueError('asn is a 32 bits number, value too large %s' % asn)
return IP.create(ip), ExtendedCommunities().add(TrafficRedirectIPv6(ip, asn))

# the redirect is an ASN:RT
if True: # count == 1:
prefix, suffix = data.split(':', 1)

if prefix.count('.'):
raise ValueError(
'this format has been deprecated as it does not make sense and it is not supported by other vendors'
Expand All @@ -289,30 +311,17 @@ def redirect(tokeniser):

if asn >= pow(2, 32):
raise ValueError('asn is a 32 bits number, value too large %s' % asn)

if asn >= pow(2, 16):
if route_target >= pow(2, 16):
raise ValueError('asn is a 32 bits number, route target can only be 16 bit %s' % route_target)
return NoNextHop, ExtendedCommunities().add(TrafficRedirectASN4(asn, route_target))
if route_target >= pow(2, 32):
raise ValueError('route target is a 32 bits number, value too large %s' % route_target)
return NoNextHop, ExtendedCommunities().add(TrafficRedirect(asn, route_target))
else:
explicit_v6 = ']:' in data

# ipv4
if not explicit_v6 and data.count(':') == 1:
return IP.create(data), ExtendedCommunities().add(TrafficNextHopSimpson(False))

# ipv6 using []: notation
if explicit_v6:
ip, asn = data.split(']:')
ip = ip.replace('[', '', 1)
# FIXME: should this be 2^16 ??
if asn >= pow(2, 32):
raise ValueError('asn is a 32 bits number, value too large %s' % asn)
return IP.create(ip), ExtendedCommunities().add(TrafficRedirectIPv6(ip, asn))

raise ValueError('it looks like you tried to use an IPv6 but did not enclose it in []')
else:
if route_target >= pow(2, 32):
raise ValueError('route target is a 32 bits number, value too large %s' % route_target)
return NoNextHop, ExtendedCommunities().add(TrafficRedirect(asn, route_target))

raise ValueError('it looks like you tried to use an IPv6 but did not enclose it in []')


def redirect_next_hop(tokeniser):
Expand Down

0 comments on commit f320ac9

Please sign in to comment.