Merge pull request #7063 from idryzhov/yang-leafref

yang: use leafref instead of string
This commit is contained in:
Renato Westphal 2020-09-26 15:12:13 -03:00 committed by GitHub
commit e4d09f608d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 90 additions and 77 deletions

View File

@ -2179,7 +2179,7 @@ void bfd_session_update_vrf_name(struct bfd_session *bs, struct vrf *vrf)
"[interface='%s']", bs->key.ifname); "[interface='%s']", bs->key.ifname);
else else
slen += snprintf(xpath + slen, sizeof(xpath) - slen, slen += snprintf(xpath + slen, sizeof(xpath) - slen,
"[interface='']"); "[interface='*']");
snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']/vrf", snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']/vrf",
bs->key.vrfname); bs->key.vrfname);

View File

@ -21,6 +21,8 @@
#include <zebra.h> #include <zebra.h>
#include "filter.h" #include "filter.h"
#include "if.h"
#include "vrf.h"
#include "bfd.h" #include "bfd.h"
#include "bfdd_nb.h" #include "bfdd_nb.h"

View File

@ -127,7 +127,7 @@ DEFPY_YANG_NOSH(
"[interface='%s']", ifname); "[interface='%s']", ifname);
else else
slen += snprintf(xpath + slen, sizeof(xpath) - slen, slen += snprintf(xpath + slen, sizeof(xpath) - slen,
"[interface='']"); "[interface='*']");
if (vrf) if (vrf)
snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf); snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf);
else else
@ -185,7 +185,7 @@ DEFPY_YANG(
"[interface='%s']", ifname); "[interface='%s']", ifname);
else else
slen += snprintf(xpath + slen, sizeof(xpath) - slen, slen += snprintf(xpath + slen, sizeof(xpath) - slen,
"[interface='']"); "[interface='*']");
if (vrf) if (vrf)
snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf); snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf);
else else
@ -218,7 +218,7 @@ static void _bfd_cli_show_peer(struct vty *vty, struct lyd_node *dnode,
if (strcmp(vrf, VRF_DEFAULT_NAME)) if (strcmp(vrf, VRF_DEFAULT_NAME))
vty_out(vty, " vrf %s", vrf); vty_out(vty, " vrf %s", vrf);
if (ifname[0]) if (strcmp(ifname, "*"))
vty_out(vty, " interface %s", ifname); vty_out(vty, " interface %s", ifname);
vty_out(vty, "\n"); vty_out(vty, "\n");

View File

@ -45,11 +45,11 @@ static void bfd_session_get_key(bool mhop, const struct lyd_node *dnode,
if (yang_dnode_exists(dnode, "./source-addr")) if (yang_dnode_exists(dnode, "./source-addr"))
strtosa(yang_dnode_get_string(dnode, "./source-addr"), &lsa); strtosa(yang_dnode_get_string(dnode, "./source-addr"), &lsa);
/* Get optional interface and vrf names. */ ifname = yang_dnode_get_string(dnode, "./interface");
if (yang_dnode_exists(dnode, "./interface")) vrfname = yang_dnode_get_string(dnode, "./vrf");
ifname = yang_dnode_get_string(dnode, "./interface");
if (yang_dnode_exists(dnode, "./vrf")) if (strcmp(ifname, "*") == 0)
vrfname = yang_dnode_get_string(dnode, "./vrf"); ifname = NULL;
/* Generate the corresponding key. */ /* Generate the corresponding key. */
gen_bfd_key(bk, &psa, &lsa, mhop, ifname, vrfname); gen_bfd_key(bk, &psa, &lsa, mhop, ifname, vrfname);
@ -72,18 +72,10 @@ static int bfd_session_create(enum nb_event event, const struct lyd_node *dnode,
*/ */
yang_dnode_get_prefix(&p, dnode, "./dest-addr"); yang_dnode_get_prefix(&p, dnode, "./dest-addr");
/* ifname = yang_dnode_get_string(dnode, "./interface");
* To support old FRR versions we must allow empty
* interface to be specified, however that should
* change in the future.
*/
if (yang_dnode_exists(dnode, "./interface"))
ifname = yang_dnode_get_string(dnode, "./interface");
else
ifname = "";
if (p.family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6) if (p.family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)
&& strlen(ifname) == 0) { && strcmp(ifname, "*") == 0) {
zlog_warn( zlog_warn(
"%s: when using link-local you must specify an interface.", "%s: when using link-local you must specify an interface.",
__func__); __func__);

View File

@ -12,6 +12,9 @@ module frr-bfdd {
import frr-interface { import frr-interface {
prefix frr-interface; prefix frr-interface;
} }
import frr-vrf {
prefix frr-vrf;
}
import frr-route-types { import frr-route-types {
prefix frr-route-types; prefix frr-route-types;
} }
@ -396,14 +399,12 @@ module frr-bfdd {
} }
leaf interface { leaf interface {
type string { type frr-interface:interface-ref;
length "0..16";
}
description "Interface to use to contact peer"; description "Interface to use to contact peer";
} }
leaf vrf { leaf vrf {
type string; type frr-vrf:vrf-ref;
description "Virtual Routing Domain name"; description "Virtual Routing Domain name";
} }
@ -441,14 +442,12 @@ module frr-bfdd {
} }
leaf interface { leaf interface {
type string { type frr-interface:interface-ref;
length "0..16";
}
description "Interface to use to contact peer"; description "Interface to use to contact peer";
} }
leaf vrf { leaf vrf {
type string; type frr-vrf:vrf-ref;
description "Virtual Routing Domain name"; description "Virtual Routing Domain name";
} }

View File

@ -9,6 +9,10 @@ submodule frr-bgp-common-structure {
prefix inet; prefix inet;
} }
import frr-route-map {
prefix frr-route-map;
}
import frr-interface { import frr-interface {
prefix frr-interface; prefix frr-interface;
} }
@ -371,7 +375,7 @@ submodule frr-bgp-common-structure {
} }
leaf rmap-policy-export { leaf rmap-policy-export {
type frr-bt:rmap-ref; type frr-route-map:route-map-ref;
description description
"Route-map to specify criteria to originate default."; "Route-map to specify criteria to originate default.";
} }

View File

@ -17,6 +17,10 @@ submodule frr-bgp-common {
prefix frr-bt; prefix frr-bt;
} }
import frr-route-map {
prefix frr-route-map;
}
import frr-route-types { import frr-route-types {
prefix frr-rt-type; prefix frr-rt-type;
} }
@ -73,25 +77,25 @@ submodule frr-bgp-common {
grouping rmap-policy-import { grouping rmap-policy-import {
leaf rmap-import { leaf rmap-import {
type frr-bt:rmap-ref; type frr-route-map:route-map-ref;
} }
} }
grouping rmap-policy-export { grouping rmap-policy-export {
leaf rmap-export { leaf rmap-export {
type frr-bt:rmap-ref; type frr-route-map:route-map-ref;
} }
} }
grouping unsupress-map-policy-import { grouping unsupress-map-policy-import {
leaf unsupress-map-import { leaf unsupress-map-import {
type frr-bt:rmap-ref; type frr-route-map:route-map-ref;
} }
} }
grouping unsupress-map-policy-export { grouping unsupress-map-policy-export {
leaf unsupress-map-export { leaf unsupress-map-export {
type frr-bt:rmap-ref; type frr-route-map:route-map-ref;
} }
} }
@ -728,7 +732,7 @@ submodule frr-bgp-common {
} }
leaf rmap-policy-import { leaf rmap-policy-import {
type frr-bt:rmap-ref; type frr-route-map:route-map-ref;
description description
"Route-map to be applied for redistributed routes into the bgp."; "Route-map to be applied for redistributed routes into the bgp.";
} }
@ -743,7 +747,7 @@ submodule frr-bgp-common {
} }
leaf rmap-policy-export { leaf rmap-policy-export {
type frr-bt:rmap-ref; type frr-route-map:route-map-ref;
description description
"Route-map to modify the attributes for Routes going out "Route-map to modify the attributes for Routes going out
via BGP updates."; via BGP updates.";
@ -771,7 +775,7 @@ submodule frr-bgp-common {
} }
leaf rmap-policy-export { leaf rmap-policy-export {
type frr-bt:rmap-ref; type frr-route-map:route-map-ref;
description description
"Apply route map to aggregate network."; "Apply route map to aggregate network.";
} }
@ -1097,7 +1101,7 @@ submodule frr-bgp-common {
} }
leaf rmap-policy-export { leaf rmap-policy-export {
type frr-bt:rmap-ref; type frr-route-map:route-map-ref;
description description
"Route-map to modify the attributes for Routes going out "Route-map to modify the attributes for Routes going out
via BGP updates."; via BGP updates.";

View File

@ -41,10 +41,6 @@ module frr-bgp-types {
"Initial revision."; "Initial revision.";
} }
typedef rmap-ref {
type string;
}
typedef plist-ref { typedef plist-ref {
type string; type string;
} }

View File

@ -12,6 +12,12 @@ module frr-eigrpd {
import frr-interface { import frr-interface {
prefix frr-interface; prefix frr-interface;
} }
import frr-vrf {
prefix frr-vrf;
}
import frr-route-map {
prefix frr-route-map;
}
import frr-route-types { import frr-route-types {
prefix frr-route-types; prefix frr-route-types;
} }
@ -109,9 +115,7 @@ module frr-eigrpd {
leaf vrf { leaf vrf {
description "Virtual Routing Domain name"; description "Virtual Routing Domain name";
type string { type frr-vrf:vrf-ref;
length "0..16";
}
} }
/* /*
@ -235,9 +239,7 @@ module frr-eigrpd {
"Applies the conditions of the specified route-map to "Applies the conditions of the specified route-map to
routes that are redistributed into the EIGRP routing routes that are redistributed into the EIGRP routing
instance"; instance";
type string { type frr-route-map:route-map-ref;
length "1..max";
}
} }
container metrics { container metrics {

View File

@ -15,6 +15,14 @@ module frr-isisd {
prefix frr-interface; prefix frr-interface;
} }
import frr-vrf {
prefix frr-vrf;
}
import frr-route-map {
prefix frr-route-map;
}
import frr-route-types { import frr-route-types {
prefix frr-route-types; prefix frr-route-types;
} }
@ -240,9 +248,7 @@ module frr-isisd {
description description
"Common optional attributes of any redistribute entry."; "Common optional attributes of any redistribute entry.";
leaf route-map { leaf route-map {
type string { type frr-route-map:route-map-ref;
length "1..max";
}
description description
"Applies the conditions of the specified route-map to routes that "Applies the conditions of the specified route-map to routes that
are redistributed into this routing instance."; are redistributed into this routing instance.";
@ -341,7 +347,7 @@ module frr-isisd {
} }
leaf vrf { leaf vrf {
type string; type frr-vrf:vrf-ref;
default "default"; default "default";
description description
"VRF NAME."; "VRF NAME.";
@ -830,7 +836,7 @@ module frr-isisd {
} }
leaf vrf { leaf vrf {
type string; type frr-vrf:vrf-ref;
description description
"VRF NAME."; "VRF NAME.";
} }

View File

@ -156,7 +156,7 @@ module frr-nexthop {
} }
leaf vrf { leaf vrf {
type string; type frr-vrf:vrf-ref;
description description
"The nexthop vrf name, if different from the route."; "The nexthop vrf name, if different from the route.";
} }
@ -167,7 +167,7 @@ module frr-nexthop {
} }
leaf interface { leaf interface {
type string; type frr-interface:interface-ref;
description description
"The nexthop egress interface."; "The nexthop egress interface.";
} }
@ -275,7 +275,7 @@ module frr-nexthop {
description description
"List of nexthop groups, each contains group of nexthops"; "List of nexthop groups, each contains group of nexthops";
leaf name { leaf name {
type string; type nexthop-group-ref;
description description
"The nexthop-group name."; "The nexthop-group name.";
} }

View File

@ -15,6 +15,10 @@ module frr-ospfd {
prefix frr-interface; prefix frr-interface;
} }
import frr-route-map {
prefix frr-route-map;
}
import frr-route-types { import frr-route-types {
prefix frr-route-types; prefix frr-route-types;
} }
@ -41,10 +45,6 @@ module frr-ospfd {
} }
/* Policy types to be removed later, once policy Yang finalized */ /* Policy types to be removed later, once policy Yang finalized */
typedef rmap-ref {
type string;
}
typedef plist-ref { typedef plist-ref {
type string; type string;
} }
@ -425,7 +425,7 @@ module frr-ospfd {
} }
leaf route-map { leaf route-map {
type rmap-ref; type frr-route-map:route-map-ref;
description description
"Route map reference."; "Route map reference.";
} }

View File

@ -12,6 +12,12 @@ module frr-ripd {
import frr-interface { import frr-interface {
prefix frr-interface; prefix frr-interface;
} }
import frr-vrf {
prefix frr-vrf;
}
import frr-route-map {
prefix frr-route-map;
}
import frr-route-types { import frr-route-types {
prefix frr-route-types; prefix frr-route-types;
} }
@ -72,7 +78,7 @@ module frr-ripd {
"RIP routing instance."; "RIP routing instance.";
leaf vrf { leaf vrf {
type string; type frr-vrf:vrf-ref;
description description
"VRF name."; "VRF name.";
} }
@ -227,9 +233,7 @@ module frr-ripd {
must '. != "rip"'; must '. != "rip"';
} }
leaf route-map { leaf route-map {
type string { type frr-route-map:route-map-ref;
length "1..max";
}
description description
"Applies the conditions of the specified route-map to "Applies the conditions of the specified route-map to
routes that are redistributed into the RIP routing routes that are redistributed into the RIP routing
@ -396,7 +400,7 @@ module frr-ripd {
"Next hop IPv4 address."; "Next hop IPv4 address.";
} }
leaf interface { leaf interface {
type string; type frr-interface:interface-ref;
description description
"The interface that the route uses."; "The interface that the route uses.";
} }
@ -587,7 +591,7 @@ module frr-ripd {
input { input {
leaf vrf { leaf vrf {
type string; type frr-vrf:vrf-ref;
description description
"VRF name identifying a specific RIP instance. "VRF name identifying a specific RIP instance.
This leaf is optional for the rpc. This leaf is optional for the rpc.
@ -608,7 +612,7 @@ module frr-ripd {
receives a PDU with the wrong authentication type receives a PDU with the wrong authentication type
field."; field.";
leaf interface-name { leaf interface-name {
type string; type frr-interface:interface-ref;
description description
"Describes the name of the RIP interface."; "Describes the name of the RIP interface.";
} }
@ -624,7 +628,7 @@ module frr-ripd {
receives a PDU with the wrong authentication receives a PDU with the wrong authentication
information."; information.";
leaf interface-name { leaf interface-name {
type string; type frr-interface:interface-ref;
description description
"Describes the name of the RIP interface."; "Describes the name of the RIP interface.";
} }

View File

@ -12,6 +12,12 @@ module frr-ripngd {
import frr-interface { import frr-interface {
prefix frr-interface; prefix frr-interface;
} }
import frr-vrf {
prefix frr-vrf;
}
import frr-route-map {
prefix frr-route-map;
}
import frr-route-types { import frr-route-types {
prefix frr-route-types; prefix frr-route-types;
} }
@ -71,7 +77,7 @@ module frr-ripngd {
"RIPng routing instance."; "RIPng routing instance.";
leaf vrf { leaf vrf {
type string; type frr-vrf:vrf-ref;
description description
"VRF name."; "VRF name.";
} }
@ -170,9 +176,7 @@ module frr-ripngd {
must '. != "ripng"'; must '. != "ripng"';
} }
leaf route-map { leaf route-map {
type string { type frr-route-map:route-map-ref;
length "1..max";
}
description description
"Applies the conditions of the specified route-map to "Applies the conditions of the specified route-map to
routes that are redistributed into the RIPng routing routes that are redistributed into the RIPng routing
@ -298,7 +302,7 @@ module frr-ripngd {
"Next hop IPv6 address."; "Next hop IPv6 address.";
} }
leaf interface { leaf interface {
type string; type frr-interface:interface-ref;
description description
"The interface that the route uses."; "The interface that the route uses.";
} }
@ -359,7 +363,7 @@ module frr-ripngd {
input { input {
leaf vrf { leaf vrf {
type string; type frr-vrf:vrf-ref;
description description
"VRF name identifying a specific RIPng instance. "VRF name identifying a specific RIPng instance.
This leaf is optional for the rpc. This leaf is optional for the rpc.

View File

@ -249,7 +249,7 @@ module frr-routing {
instance."; instance.";
} }
leaf vrf { leaf vrf {
type string; type frr-vrf:vrf-ref;
description description
"vrf for control-plane protocol"; "vrf for control-plane protocol";
} }

View File

@ -57,7 +57,7 @@ module frr-test-module {
} }
container interfaces { container interfaces {
leaf-list interface { leaf-list interface {
type string; type frr-interface:interface-ref;
} }
} }
container routes { container routes {
@ -69,7 +69,7 @@ module frr-test-module {
type inet:ipv4-address; type inet:ipv4-address;
} }
leaf interface { leaf interface {
type string; type frr-interface:interface-ref;
} }
leaf metric { leaf metric {
type uint8; type uint8;

View File

@ -2137,7 +2137,7 @@ module frr-zebra {
"The admin distance to use for imported routes."; "The admin distance to use for imported routes.";
} }
leaf route-map { leaf route-map {
type string; type frr-route-map:route-map-ref;
description description
"A route-map to filter imported routes."; "A route-map to filter imported routes.";
} }