ripd: make YANG operational-data VRF aware too

Move the "state" container into the "instance" list and adapt the code
accordingly.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2019-01-04 19:08:10 -02:00
parent ae7b826a23
commit 32600a9807
3 changed files with 175 additions and 152 deletions

View File

@ -99,6 +99,38 @@ static int ripd_instance_delete(enum nb_event event,
return NB_OK; return NB_OK;
} }
static const void *ripd_instance_get_next(const void *parent_list_entry,
const void *list_entry)
{
const struct rip *rip = list_entry;
if (list_entry == NULL)
rip = RB_MIN(rip_instance_head, &rip_instances);
else
rip = RB_NEXT(rip_instance_head, (struct rip *)rip);
return rip;
}
static int ripd_instance_get_keys(const void *list_entry,
struct yang_list_keys *keys)
{
const struct rip *rip = list_entry;
keys->num = 1;
strlcpy(keys->key[0], rip->vrf_name, sizeof(keys->key[0]));
return NB_OK;
}
static const void *ripd_instance_lookup_entry(const void *parent_list_entry,
const struct yang_list_keys *keys)
{
const char *vrf_name = keys->key[0];
return rip_lookup_by_vrf_name(vrf_name);
}
/* /*
* XPath: /frr-ripd:ripd/instance/allow-ecmp * XPath: /frr-ripd:ripd/instance/allow-ecmp
*/ */
@ -1099,19 +1131,15 @@ lib_interface_rip_authentication_key_chain_delete(enum nb_event event,
} }
/* /*
* XPath: /frr-ripd:ripd/state/neighbors/neighbor * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor
*/ */
static const void * static const void *
ripd_state_neighbors_neighbor_get_next(const void *parent_list_entry, ripd_instance_state_neighbors_neighbor_get_next(const void *parent_list_entry,
const void *list_entry) const void *list_entry)
{ {
struct rip *rip; const struct rip *rip = parent_list_entry;
struct listnode *node; struct listnode *node;
rip = rip_lookup_by_vrf_id(VRF_DEFAULT);
if (rip == NULL)
return NULL;
if (list_entry == NULL) if (list_entry == NULL)
node = listhead(rip->peer_list); node = listhead(rip->peer_list);
else else
@ -1120,8 +1148,9 @@ ripd_state_neighbors_neighbor_get_next(const void *parent_list_entry,
return node; return node;
} }
static int ripd_state_neighbors_neighbor_get_keys(const void *list_entry, static int
struct yang_list_keys *keys) ripd_instance_state_neighbors_neighbor_get_keys(const void *list_entry,
struct yang_list_keys *keys)
{ {
const struct listnode *node = list_entry; const struct listnode *node = list_entry;
const struct rip_peer *peer = listgetdata(node); const struct rip_peer *peer = listgetdata(node);
@ -1133,21 +1162,16 @@ static int ripd_state_neighbors_neighbor_get_keys(const void *list_entry,
return NB_OK; return NB_OK;
} }
static const void * static const void *ripd_instance_state_neighbors_neighbor_lookup_entry(
ripd_state_neighbors_neighbor_lookup_entry(const void *parent_list_entry, const void *parent_list_entry, const struct yang_list_keys *keys)
const struct yang_list_keys *keys)
{ {
struct rip *rip; const struct rip *rip = parent_list_entry;
struct in_addr address; struct in_addr address;
struct rip_peer *peer; struct rip_peer *peer;
struct listnode *node; struct listnode *node;
yang_str2ipv4(keys->key[0], &address); yang_str2ipv4(keys->key[0], &address);
rip = rip_lookup_by_vrf_id(VRF_DEFAULT);
if (rip == NULL)
return NULL;
for (ALL_LIST_ELEMENTS_RO(rip->peer_list, node, peer)) { for (ALL_LIST_ELEMENTS_RO(rip->peer_list, node, peer)) {
if (IPV4_ADDR_SAME(&peer->addr, &address)) if (IPV4_ADDR_SAME(&peer->addr, &address))
return node; return node;
@ -1157,11 +1181,11 @@ ripd_state_neighbors_neighbor_lookup_entry(const void *parent_list_entry,
} }
/* /*
* XPath: /frr-ripd:ripd/state/neighbors/neighbor/address * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor/address
*/ */
static struct yang_data * static struct yang_data *
ripd_state_neighbors_neighbor_address_get_elem(const char *xpath, ripd_instance_state_neighbors_neighbor_address_get_elem(const char *xpath,
const void *list_entry) const void *list_entry)
{ {
const struct listnode *node = list_entry; const struct listnode *node = list_entry;
const struct rip_peer *peer = listgetdata(node); const struct rip_peer *peer = listgetdata(node);
@ -1170,22 +1194,22 @@ ripd_state_neighbors_neighbor_address_get_elem(const char *xpath,
} }
/* /*
* XPath: /frr-ripd:ripd/state/neighbors/neighbor/last-update * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor/last-update
*/ */
static struct yang_data * static struct yang_data *
ripd_state_neighbors_neighbor_last_update_get_elem(const char *xpath, ripd_instance_state_neighbors_neighbor_last_update_get_elem(
const void *list_entry) const char *xpath, const void *list_entry)
{ {
/* TODO: yang:date-and-time is tricky */ /* TODO: yang:date-and-time is tricky */
return NULL; return NULL;
} }
/* /*
* XPath: /frr-ripd:ripd/state/neighbors/neighbor/bad-packets-rcvd * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor/bad-packets-rcvd
*/ */
static struct yang_data * static struct yang_data *
ripd_state_neighbors_neighbor_bad_packets_rcvd_get_elem(const char *xpath, ripd_instance_state_neighbors_neighbor_bad_packets_rcvd_get_elem(
const void *list_entry) const char *xpath, const void *list_entry)
{ {
const struct listnode *node = list_entry; const struct listnode *node = list_entry;
const struct rip_peer *peer = listgetdata(node); const struct rip_peer *peer = listgetdata(node);
@ -1194,11 +1218,11 @@ ripd_state_neighbors_neighbor_bad_packets_rcvd_get_elem(const char *xpath,
} }
/* /*
* XPath: /frr-ripd:ripd/state/neighbors/neighbor/bad-routes-rcvd * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor/bad-routes-rcvd
*/ */
static struct yang_data * static struct yang_data *
ripd_state_neighbors_neighbor_bad_routes_rcvd_get_elem(const char *xpath, ripd_instance_state_neighbors_neighbor_bad_routes_rcvd_get_elem(
const void *list_entry) const char *xpath, const void *list_entry)
{ {
const struct listnode *node = list_entry; const struct listnode *node = list_entry;
const struct rip_peer *peer = listgetdata(node); const struct rip_peer *peer = listgetdata(node);
@ -1207,19 +1231,15 @@ ripd_state_neighbors_neighbor_bad_routes_rcvd_get_elem(const char *xpath,
} }
/* /*
* XPath: /frr-ripd:ripd/state/routes/route * XPath: /frr-ripd:ripd/instance/state/routes/route
*/ */
static const void * static const void *
ripd_state_routes_route_get_next(const void *parent_list_entry, ripd_instance_state_routes_route_get_next(const void *parent_list_entry,
const void *list_entry) const void *list_entry)
{ {
struct rip *rip; const struct rip *rip = parent_list_entry;
struct route_node *rn; struct route_node *rn;
rip = rip_lookup_by_vrf_id(VRF_DEFAULT);
if (rip == NULL)
return NULL;
if (list_entry == NULL) if (list_entry == NULL)
rn = route_top(rip->table); rn = route_top(rip->table);
else else
@ -1230,8 +1250,9 @@ ripd_state_routes_route_get_next(const void *parent_list_entry,
return rn; return rn;
} }
static int ripd_state_routes_route_get_keys(const void *list_entry, static int
struct yang_list_keys *keys) ripd_instance_state_routes_route_get_keys(const void *list_entry,
struct yang_list_keys *keys)
{ {
const struct route_node *rn = list_entry; const struct route_node *rn = list_entry;
@ -1242,19 +1263,15 @@ static int ripd_state_routes_route_get_keys(const void *list_entry,
} }
static const void * static const void *
ripd_state_routes_route_lookup_entry(const void *parent_list_entry, ripd_instance_state_routes_route_lookup_entry(const void *parent_list_entry,
const struct yang_list_keys *keys) const struct yang_list_keys *keys)
{ {
struct rip *rip; const struct rip *rip = parent_list_entry;
struct prefix prefix; struct prefix prefix;
struct route_node *rn; struct route_node *rn;
yang_str2ipv4p(keys->key[0], &prefix); yang_str2ipv4p(keys->key[0], &prefix);
rip = rip_lookup_by_vrf_id(VRF_DEFAULT);
if (rip == NULL)
return NULL;
rn = route_node_lookup(rip->table, &prefix); rn = route_node_lookup(rip->table, &prefix);
if (!rn || !rn->info) if (!rn || !rn->info)
return NULL; return NULL;
@ -1265,11 +1282,11 @@ ripd_state_routes_route_lookup_entry(const void *parent_list_entry,
} }
/* /*
* XPath: /frr-ripd:ripd/state/routes/route/prefix * XPath: /frr-ripd:ripd/instance/state/routes/route/prefix
*/ */
static struct yang_data * static struct yang_data *
ripd_state_routes_route_prefix_get_elem(const char *xpath, ripd_instance_state_routes_route_prefix_get_elem(const char *xpath,
const void *list_entry) const void *list_entry)
{ {
const struct route_node *rn = list_entry; const struct route_node *rn = list_entry;
const struct rip_info *rinfo = listnode_head(rn->info); const struct rip_info *rinfo = listnode_head(rn->info);
@ -1278,11 +1295,11 @@ ripd_state_routes_route_prefix_get_elem(const char *xpath,
} }
/* /*
* XPath: /frr-ripd:ripd/state/routes/route/next-hop * XPath: /frr-ripd:ripd/instance/state/routes/route/next-hop
*/ */
static struct yang_data * static struct yang_data *
ripd_state_routes_route_next_hop_get_elem(const char *xpath, ripd_instance_state_routes_route_next_hop_get_elem(const char *xpath,
const void *list_entry) const void *list_entry)
{ {
const struct route_node *rn = list_entry; const struct route_node *rn = list_entry;
const struct rip_info *rinfo = listnode_head(rn->info); const struct rip_info *rinfo = listnode_head(rn->info);
@ -1297,31 +1314,33 @@ ripd_state_routes_route_next_hop_get_elem(const char *xpath,
} }
/* /*
* XPath: /frr-ripd:ripd/state/routes/route/interface * XPath: /frr-ripd:ripd/instance/state/routes/route/interface
*/ */
static struct yang_data * static struct yang_data *
ripd_state_routes_route_interface_get_elem(const char *xpath, ripd_instance_state_routes_route_interface_get_elem(const char *xpath,
const void *list_entry) const void *list_entry)
{ {
const struct route_node *rn = list_entry; const struct route_node *rn = list_entry;
const struct rip_info *rinfo = listnode_head(rn->info); const struct rip_info *rinfo = listnode_head(rn->info);
const struct rip *rip = rip_info_get_instance(rinfo);
switch (rinfo->nh.type) { switch (rinfo->nh.type) {
case NEXTHOP_TYPE_IFINDEX: case NEXTHOP_TYPE_IFINDEX:
case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4_IFINDEX:
return yang_data_new_string( return yang_data_new_string(
xpath, ifindex2ifname(rinfo->nh.ifindex, VRF_DEFAULT)); xpath,
ifindex2ifname(rinfo->nh.ifindex, rip->vrf->vrf_id));
default: default:
return NULL; return NULL;
} }
} }
/* /*
* XPath: /frr-ripd:ripd/state/routes/route/metric * XPath: /frr-ripd:ripd/instance/state/routes/route/metric
*/ */
static struct yang_data * static struct yang_data *
ripd_state_routes_route_metric_get_elem(const char *xpath, ripd_instance_state_routes_route_metric_get_elem(const char *xpath,
const void *list_entry) const void *list_entry)
{ {
const struct route_node *rn = list_entry; const struct route_node *rn = list_entry;
const struct rip_info *rinfo = listnode_head(rn->info); const struct rip_info *rinfo = listnode_head(rn->info);
@ -1423,6 +1442,9 @@ const struct frr_yang_module_info frr_ripd_info = {
.xpath = "/frr-ripd:ripd/instance", .xpath = "/frr-ripd:ripd/instance",
.cbs.create = ripd_instance_create, .cbs.create = ripd_instance_create,
.cbs.delete = ripd_instance_delete, .cbs.delete = ripd_instance_delete,
.cbs.get_next = ripd_instance_get_next,
.cbs.get_keys = ripd_instance_get_keys,
.cbs.lookup_entry = ripd_instance_lookup_entry,
.cbs.cli_show = cli_show_router_rip, .cbs.cli_show = cli_show_router_rip,
}, },
{ {
@ -1607,48 +1629,48 @@ const struct frr_yang_module_info frr_ripd_info = {
.cbs.cli_show = cli_show_ip_rip_authentication_key_chain, .cbs.cli_show = cli_show_ip_rip_authentication_key_chain,
}, },
{ {
.xpath = "/frr-ripd:ripd/state/neighbors/neighbor", .xpath = "/frr-ripd:ripd/instance/state/neighbors/neighbor",
.cbs.get_next = ripd_state_neighbors_neighbor_get_next, .cbs.get_next = ripd_instance_state_neighbors_neighbor_get_next,
.cbs.get_keys = ripd_state_neighbors_neighbor_get_keys, .cbs.get_keys = ripd_instance_state_neighbors_neighbor_get_keys,
.cbs.lookup_entry = ripd_state_neighbors_neighbor_lookup_entry, .cbs.lookup_entry = ripd_instance_state_neighbors_neighbor_lookup_entry,
}, },
{ {
.xpath = "/frr-ripd:ripd/state/neighbors/neighbor/address", .xpath = "/frr-ripd:ripd/instance/state/neighbors/neighbor/address",
.cbs.get_elem = ripd_state_neighbors_neighbor_address_get_elem, .cbs.get_elem = ripd_instance_state_neighbors_neighbor_address_get_elem,
}, },
{ {
.xpath = "/frr-ripd:ripd/state/neighbors/neighbor/last-update", .xpath = "/frr-ripd:ripd/instance/state/neighbors/neighbor/last-update",
.cbs.get_elem = ripd_state_neighbors_neighbor_last_update_get_elem, .cbs.get_elem = ripd_instance_state_neighbors_neighbor_last_update_get_elem,
}, },
{ {
.xpath = "/frr-ripd:ripd/state/neighbors/neighbor/bad-packets-rcvd", .xpath = "/frr-ripd:ripd/instance/state/neighbors/neighbor/bad-packets-rcvd",
.cbs.get_elem = ripd_state_neighbors_neighbor_bad_packets_rcvd_get_elem, .cbs.get_elem = ripd_instance_state_neighbors_neighbor_bad_packets_rcvd_get_elem,
}, },
{ {
.xpath = "/frr-ripd:ripd/state/neighbors/neighbor/bad-routes-rcvd", .xpath = "/frr-ripd:ripd/instance/state/neighbors/neighbor/bad-routes-rcvd",
.cbs.get_elem = ripd_state_neighbors_neighbor_bad_routes_rcvd_get_elem, .cbs.get_elem = ripd_instance_state_neighbors_neighbor_bad_routes_rcvd_get_elem,
}, },
{ {
.xpath = "/frr-ripd:ripd/state/routes/route", .xpath = "/frr-ripd:ripd/instance/state/routes/route",
.cbs.get_next = ripd_state_routes_route_get_next, .cbs.get_next = ripd_instance_state_routes_route_get_next,
.cbs.get_keys = ripd_state_routes_route_get_keys, .cbs.get_keys = ripd_instance_state_routes_route_get_keys,
.cbs.lookup_entry = ripd_state_routes_route_lookup_entry, .cbs.lookup_entry = ripd_instance_state_routes_route_lookup_entry,
}, },
{ {
.xpath = "/frr-ripd:ripd/state/routes/route/prefix", .xpath = "/frr-ripd:ripd/instance/state/routes/route/prefix",
.cbs.get_elem = ripd_state_routes_route_prefix_get_elem, .cbs.get_elem = ripd_instance_state_routes_route_prefix_get_elem,
}, },
{ {
.xpath = "/frr-ripd:ripd/state/routes/route/next-hop", .xpath = "/frr-ripd:ripd/instance/state/routes/route/next-hop",
.cbs.get_elem = ripd_state_routes_route_next_hop_get_elem, .cbs.get_elem = ripd_instance_state_routes_route_next_hop_get_elem,
}, },
{ {
.xpath = "/frr-ripd:ripd/state/routes/route/interface", .xpath = "/frr-ripd:ripd/instance/state/routes/route/interface",
.cbs.get_elem = ripd_state_routes_route_interface_get_elem, .cbs.get_elem = ripd_instance_state_routes_route_interface_get_elem,
}, },
{ {
.xpath = "/frr-ripd:ripd/state/routes/route/metric", .xpath = "/frr-ripd:ripd/instance/state/routes/route/metric",
.cbs.get_elem = ripd_state_routes_route_metric_get_elem, .cbs.get_elem = ripd_instance_state_routes_route_metric_get_elem,
}, },
{ {
.xpath = "/frr-ripd:clear-rip-route", .xpath = "/frr-ripd:clear-rip-route",

View File

@ -517,6 +517,7 @@ extern void ripd_notif_send_auth_type_failure(const char *ifname);
extern void ripd_notif_send_auth_failure(const char *ifname); extern void ripd_notif_send_auth_failure(const char *ifname);
extern struct zebra_privs_t ripd_privs; extern struct zebra_privs_t ripd_privs;
extern struct rip_instance_head rip_instances;
/* Master thread strucutre. */ /* Master thread strucutre. */
extern struct thread_master *master; extern struct thread_master *master;

View File

@ -298,83 +298,83 @@ module frr-ripd {
'(./receive = "2" and ./send = "2") or ' + '(./receive = "2" and ./send = "2") or ' +
'(./receive = "1-2" and ./send = "2")'; '(./receive = "1-2" and ./send = "2")';
} }
}
/* /*
* Operational data. * Operational data.
*/ */
container state { container state {
config false; config false;
description
"Operational data.";
container neighbors {
description description
"Neighbor information."; "Operational data.";
list neighbor {
key "address"; container neighbors {
description description
"A RIP neighbor."; "Neighbor information.";
leaf address { list neighbor {
type inet:ipv4-address; key "address";
description description
"IP address that a RIP neighbor is using as its "A RIP neighbor.";
source address."; leaf address {
} type inet:ipv4-address;
leaf last-update { description
type yang:date-and-time; "IP address that a RIP neighbor is using as its
description source address.";
"The time when the most recent RIP update was }
received from this neighbor."; leaf last-update {
} type yang:date-and-time;
leaf bad-packets-rcvd { description
type yang:counter32; "The time when the most recent RIP update was
description received from this neighbor.";
"The number of RIP invalid packets received from }
this neighbor which were subsequently discarded leaf bad-packets-rcvd {
for any reason (e.g. a version 0 packet, or an type yang:counter32;
unknown command type)."; description
} "The number of RIP invalid packets received from
leaf bad-routes-rcvd { this neighbor which were subsequently discarded
type yang:counter32; for any reason (e.g. a version 0 packet, or an
description unknown command type).";
"The number of routes received from this neighbor, }
in valid RIP packets, which were ignored for any leaf bad-routes-rcvd {
reason (e.g. unknown address family, or invalid type yang:counter32;
metric)."; description
"The number of routes received from this neighbor,
in valid RIP packets, which were ignored for any
reason (e.g. unknown address family, or invalid
metric).";
}
} }
} }
} container routes {
container routes {
description
"Route information.";
list route {
key "prefix";
description description
"A RIP IPv4 route."; "Route information.";
leaf prefix { list route {
type inet:ipv4-prefix; key "prefix";
description description
"IP address (in the form A.B.C.D) and prefix length, "A RIP IPv4 route.";
separated by the slash (/) character. The range of leaf prefix {
values for the prefix-length is 0 to 32."; type inet:ipv4-prefix;
} description
leaf next-hop { "IP address (in the form A.B.C.D) and prefix length,
type inet:ipv4-address; separated by the slash (/) character. The range of
description values for the prefix-length is 0 to 32.";
"Next hop IPv4 address."; }
} leaf next-hop {
leaf interface { type inet:ipv4-address;
type string; description
description "Next hop IPv4 address.";
"The interface that the route uses."; }
} leaf interface {
leaf metric { type string;
type uint8 { description
range "0..16"; "The interface that the route uses.";
}
leaf metric {
type uint8 {
range "0..16";
}
description
"Route metric.";
} }
description
"Route metric.";
} }
} }
} }