]> git.puffer.fish Git - matthieu/frr.git/commitdiff
yang, bgpd: Fix "aggregator-asn" to support asdot
authoranlan_cs <vic.lan@pica8.com>
Thu, 9 Mar 2023 01:34:07 +0000 (09:34 +0800)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Thu, 16 Mar 2023 06:00:53 +0000 (07:00 +0100)
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 <vic.lan@pica8.com>
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
bgpd/bgp_routemap_nb_config.c
yang/frr-bgp-route-map.yang

index 142bded6c536895664502969966d306f7f11a5a6..4db8dba2ccf346ec665cf400c824d0d435fa5104 100644 (file)
@@ -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:
index 8e288194eceddafc06aec513867525bcf986f537..90163f125e26437b2625d173f0f23e2fb4828129 100644 (file)
@@ -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";