diff --git a/interface-definitions/policy.xml.in b/interface-definitions/policy.xml.in index eb907cb9e40..ec9932e18e9 100644 --- a/interface-definitions/policy.xml.in +++ b/interface-definitions/policy.xml.in @@ -202,11 +202,11 @@ Regular expression to match against a community-list - local-AS no-advertise no-export internet additive + local-AS no-advertise no-export internet graceful-shutdown accept-own-nexthop accept-own route-filter-translated-v4 route-filter-v4 route-filter-translated-v6 route-filter-v6 llgr-stale no-llgr blackhole no-peer additive <aa:nn> - Community number in AA:NN format + Community number in AA:NN format where AA and NN are (0-65535) local-AS @@ -224,10 +224,58 @@ internet Well-known communities value 0 + + graceful-shutdown + Well-known communities value GRACEFUL_SHUTDOWN 0xFFFF0000 + + + accept-own-nexthop + Well-known communities value ACCEPT_OWN_NEXTHOP 0xFFFF0008 + + + accept-own + Well-known communities value ACCEPT_OWN 0xFFFF0001 65535:1 + + + route-filter-translated-v4 + Well-known communities value ROUTE_FILTER_TRANSLATED_v4 0xFFFF0002 65535:2 + + + route-filter-v4 + Well-known communities value ROUTE_FILTER_v4 0xFFFF0003 65535:3 + + + route-filter-translated-v6 + Well-known communities value ROUTE_FILTER_TRANSLATED_v6 0xFFFF0004 65535:4 + + + route-filter-v6 + Well-known communities value ROUTE_FILTER_v6 0xFFFF0005 65535:5 + + + llgr-stale + Well-known communities value LLGR_STALE 0xFFFF0006 65535:6 + + + no-llgr + Well-known communities value NO_LLGR 0xFFFF0007 65535:7 + + + blackhole + Well-known communities value BLACKHOLE 0xFFFF029A 65535:666 + + + no-peer + Well-known communities value NOPEER 0xFFFFFF04 65535:65284 + additive New value is appended to the existing value + + (local-AS|no-advertise|no-export|internet|graceful-shutdown|accept-own-nexthop|accept-own|route-filter-translated-v4|route-filter-v4|route-filter-translated-v6|route-filter-v6|llgr-stale|no-llgr|blackhole|no-peer|additive) + + diff --git a/src/validators/bgp-community-list b/src/validators/bgp-community-list new file mode 100755 index 00000000000..24619d132eb --- /dev/null +++ b/src/validators/bgp-community-list @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +# Copyright 2024 VyOS maintainers and contributors +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see . + +from argparse import ArgumentParser +from sys import exit + +from vyos.template import is_ipv4 + +COMM_MAX_2_OCTET: int = 65535 + +if __name__ == '__main__': + # add an argument with community + parser: ArgumentParser = ArgumentParser() + parser.add_argument('community', type=str) + args = parser.parse_args() + + for community in args.community.split(): + if community.count(':') != 1: + print("Invalid community format") + exit(1) + try: + # try to extract community parts from an argument + comm_left: str = community.split(':')[0] + comm_right: int = int(community.split(':')[1]) + + # check if left part is an IPv4 address + if is_ipv4(comm_left) and 0 <= comm_right <= COMM_MAX_2_OCTET: + continue + # check if a left part is a number + if 0 <= int(comm_left) <= COMM_MAX_2_OCTET \ + and 0 <= comm_right <= COMM_MAX_2_OCTET: + continue + + raise Exception() + + except Exception: + # fail if something was wrong + print("Invalid community format") + exit(1)