From 5b498ae7ecc58ff6e9afa74bbf3715aee1332d52 Mon Sep 17 00:00:00 2001 From: anlan_cs Date: Thu, 9 Mar 2023 09:34:07 +0800 Subject: [PATCH] yang, bgpd: Fix "aggregator-asn" to support asdot The following command is not working: > (routemap) set aggregator as ASNUM A.B.C.D Since "aggregator-asn" has already supported asdot, fixed it with new yang type. Extra ASN validation (leading zeroes for instance) are done in the validate hook of the yang leaf. Signed-off-by: anlan_cs Signed-off-by: Philippe Guibert --- bgpd/bgp_routemap_nb_config.c | 10 ++++++++++ yang/frr-bgp-route-map.yang | 27 ++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/bgpd/bgp_routemap_nb_config.c b/bgpd/bgp_routemap_nb_config.c index 142bded6c5..4db8dba2cc 100644 --- a/bgpd/bgp_routemap_nb_config.c +++ b/bgpd/bgp_routemap_nb_config.c @@ -2628,8 +2628,18 @@ int lib_route_map_entry_set_action_rmap_set_action_aggregator_aggregator_asn_modify( struct nb_cb_modify_args *args) { + const char *asn; + enum match_type match; + switch (args->event) { case NB_EV_VALIDATE: + asn = yang_dnode_get_string(args->dnode, NULL); + if (!asn) + return NB_ERR_VALIDATION; + match = asn_str2asn_match(asn); + if (match == exact_match) + return NB_OK; + return NB_ERR_VALIDATION; case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: diff --git a/yang/frr-bgp-route-map.yang b/yang/frr-bgp-route-map.yang index 8e288194ec..90163f125e 100644 --- a/yang/frr-bgp-route-map.yang +++ b/yang/frr-bgp-route-map.yang @@ -474,6 +474,27 @@ module frr-bgp-route-map { "ext-community link bandwidth types."; } + typedef asn-type { + type union { + type uint32 { + range "1..4294967295"; + } + type string { + pattern '(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|' + + '6[0-4][0-9]{3}|65[0-4][0-9]{2}|' + + '655[0-2][0-9]|6553[0-5])\.' + + '(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|' + + '65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])' { + error-message "AS dot should be in the form [0..65535].[0..65535]."; + } + pattern '^0\.0$' { + modifier "invert-match"; + error-message "AS dot can't be equal to 0.0."; + } + } + } + } + augment "/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:match-condition/frr-route-map:rmap-match-condition/frr-route-map:match-condition" { case local-preference { when "derived-from-or-self(/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:match-condition/frr-route-map:condition, 'frr-bgp-route-map:match-local-preference')"; @@ -1004,16 +1025,12 @@ module frr-bgp-route-map { when "derived-from-or-self(/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:set-action/frr-route-map:action, 'frr-bgp-route-map:aggregator')"; container aggregator { leaf aggregator-asn { - type uint32 { - range "1..4294967295"; - } + type asn-type; description "ASN of the aggregator"; } leaf aggregator-address { - when "../aggregator-asn > 0 or " - + "../aggregator-asn <= 4294967295"; type inet:ipv4-address; description "IPv4 address of the aggregator"; -- 2.39.5