summaryrefslogtreecommitdiff
path: root/sharpd/sharp_zebra.c
diff options
context:
space:
mode:
Diffstat (limited to 'sharpd/sharp_zebra.c')
-rw-r--r--sharpd/sharp_zebra.c77
1 files changed, 43 insertions, 34 deletions
diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c
index c9f333e34b..4682dbc73a 100644
--- a/sharpd/sharp_zebra.c
+++ b/sharpd/sharp_zebra.c
@@ -36,6 +36,8 @@
#include "nexthop.h"
#include "nexthop_group.h"
+#include "sharp_globals.h"
+#include "sharp_nht.h"
#include "sharp_zebra.h"
/* Zebra structure to hold current status. */
@@ -129,16 +131,6 @@ static int interface_state_down(int command, struct zclient *zclient,
return 0;
}
-static struct timeval t_start;
-static struct timeval t_end;
-extern uint32_t total_routes;
-extern uint32_t installed_routes;
-extern uint32_t removed_routes;
-extern int32_t repeat;
-extern struct prefix orig_prefix;
-extern struct nexthop_group nhop_group;
-extern uint8_t inst;
-
void sharp_install_routes_helper(struct prefix *p, uint8_t instance,
struct nexthop_group *nhg,
uint32_t routes)
@@ -154,7 +146,7 @@ void sharp_install_routes_helper(struct prefix *p, uint8_t instance,
} else
temp = ntohl(p->u.val32[3]);
- monotime(&t_start);
+ monotime(&sg.r.t_start);
for (i = 0; i < routes; i++) {
route_add(p, (uint8_t)instance, nhg);
if (v4)
@@ -178,7 +170,7 @@ void sharp_remove_routes_helper(struct prefix *p, uint8_t instance,
} else
temp = ntohl(p->u.val32[3]);
- monotime(&t_start);
+ monotime(&sg.r.t_start);
for (i = 0; i < routes; i++) {
route_delete(p, (uint8_t)instance);
if (v4)
@@ -190,21 +182,21 @@ void sharp_remove_routes_helper(struct prefix *p, uint8_t instance,
static void handle_repeated(bool installed)
{
- struct prefix p = orig_prefix;
- repeat--;
+ struct prefix p = sg.r.orig_prefix;
+ sg.r.repeat--;
- if (repeat <= 0)
+ if (sg.r.repeat <= 0)
return;
if (installed) {
- removed_routes = 0;
- sharp_remove_routes_helper(&p, inst, total_routes);
+ sg.r.removed_routes = 0;
+ sharp_remove_routes_helper(&p, sg.r.inst, sg.r.total_routes);
}
- if (!installed) {
- installed_routes = 0;
- sharp_install_routes_helper(&p, inst, &nhop_group,
- total_routes);
+ if (installed) {
+ sg.r.installed_routes = 0;
+ sharp_install_routes_helper(&p, sg.r.inst, &sg.r.nhop_group,
+ sg.r.total_routes);
}
}
@@ -221,10 +213,10 @@ static int route_notify_owner(int command, struct zclient *zclient,
switch (note) {
case ZAPI_ROUTE_INSTALLED:
- installed_routes++;
- if (total_routes == installed_routes) {
- monotime(&t_end);
- timersub(&t_end, &t_start, &r);
+ sg.r.installed_routes++;
+ if (sg.r.total_routes == sg.r.installed_routes) {
+ monotime(&sg.r.t_end);
+ timersub(&sg.r.t_end, &sg.r.t_start, &r);
zlog_debug("Installed All Items %ld.%ld", r.tv_sec,
r.tv_usec);
handle_repeated(true);
@@ -237,10 +229,10 @@ static int route_notify_owner(int command, struct zclient *zclient,
zlog_debug("Better Admin Distance won over us");
break;
case ZAPI_ROUTE_REMOVED:
- removed_routes++;
- if (total_routes == removed_routes) {
- monotime(&t_end);
- timersub(&t_end, &t_start, &r);
+ sg.r.removed_routes++;
+ if (sg.r.total_routes == sg.r.removed_routes) {
+ monotime(&sg.r.t_end);
+ timersub(&sg.r.t_end, &sg.r.t_start, &r);
zlog_debug("Removed all Items %ld.%ld", r.tv_sec,
r.tv_usec);
handle_repeated(false);
@@ -328,14 +320,24 @@ void route_delete(struct prefix *p, uint8_t instance)
return;
}
-void sharp_zebra_nexthop_watch(struct prefix *p, bool watch)
+void sharp_zebra_nexthop_watch(struct prefix *p, bool import,
+ bool watch, bool connected)
{
- int command = ZEBRA_NEXTHOP_REGISTER;
+ int command;
- if (!watch)
- command = ZEBRA_NEXTHOP_UNREGISTER;
+ if (!import) {
+ command = ZEBRA_NEXTHOP_REGISTER;
- if (zclient_send_rnh(zclient, command, p, true, VRF_DEFAULT) < 0)
+ if (!watch)
+ command = ZEBRA_NEXTHOP_UNREGISTER;
+ } else {
+ command = ZEBRA_IMPORT_ROUTE_REGISTER;
+
+ if (!watch)
+ command = ZEBRA_IMPORT_ROUTE_UNREGISTER;
+ }
+
+ if (zclient_send_rnh(zclient, command, p, connected, VRF_DEFAULT) < 0)
zlog_warn("%s: Failure to send nexthop to zebra",
__PRETTY_FUNCTION__);
}
@@ -343,6 +345,7 @@ void sharp_zebra_nexthop_watch(struct prefix *p, bool watch)
static int sharp_nexthop_update(int command, struct zclient *zclient,
zebra_size_t length, vrf_id_t vrf_id)
{
+ struct sharp_nh_tracker *nht;
struct zapi_route nhr;
char buf[PREFIX_STRLEN];
int i;
@@ -355,6 +358,11 @@ static int sharp_nexthop_update(int command, struct zclient *zclient,
zlog_debug("Received update for %s",
prefix2str(&nhr.prefix, buf, sizeof(buf)));
+
+ nht = sharp_nh_tracker_get(&nhr.prefix);
+ nht->nhop_num = nhr.nexthop_num;
+ nht->updates++;
+
for (i = 0; i < nhr.nexthop_num; i++) {
struct zapi_nexthop *znh = &nhr.nexthops[i];
@@ -407,4 +415,5 @@ void sharp_zebra_init(void)
zclient->interface_address_delete = interface_address_delete;
zclient->route_notify_owner = route_notify_owner;
zclient->nexthop_update = sharp_nexthop_update;
+ zclient->import_check_update = sharp_nexthop_update;
}