summaryrefslogtreecommitdiff
path: root/ospf6d/ospf6_zebra.c
diff options
context:
space:
mode:
Diffstat (limited to 'ospf6d/ospf6_zebra.c')
-rw-r--r--ospf6d/ospf6_zebra.c144
1 files changed, 111 insertions, 33 deletions
diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c
index c5c8ca27b9..f21e940a77 100644
--- a/ospf6d/ospf6_zebra.c
+++ b/ospf6d/ospf6_zebra.c
@@ -39,6 +39,8 @@
#include "ospf6_asbr.h"
#include "ospf6_zebra.h"
#include "ospf6d.h"
+#include "ospf6_area.h"
+#include "lib/json.h"
DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_DISTANCE, "OSPF6 distance")
@@ -47,16 +49,49 @@ unsigned char conf_debug_ospf6_zebra = 0;
/* information about zebra. */
struct zclient *zclient = NULL;
+void ospf6_zebra_vrf_register(struct ospf6 *ospf6)
+{
+ if (!zclient || zclient->sock < 0 || !ospf6)
+ return;
+
+ if (ospf6->vrf_id != VRF_UNKNOWN) {
+ if (IS_OSPF6_DEBUG_ZEBRA(RECV)) {
+ zlog_debug("%s: Register VRF %s id %u", __func__,
+ ospf6_vrf_id_to_name(ospf6->vrf_id),
+ ospf6->vrf_id);
+ }
+ zclient_send_reg_requests(zclient, ospf6->vrf_id);
+ }
+}
+
+void ospf6_zebra_vrf_deregister(struct ospf6 *ospf6)
+{
+ if (!zclient || zclient->sock < 0 || !ospf6)
+ return;
+
+ if (ospf6->vrf_id != VRF_DEFAULT && ospf6->vrf_id != VRF_UNKNOWN) {
+ if (IS_OSPF6_DEBUG_ZEBRA(RECV)) {
+ zlog_debug("%s: De-Register VRF %s id %u to Zebra.",
+ __func__,
+ ospf6_vrf_id_to_name(ospf6->vrf_id),
+ ospf6->vrf_id);
+ }
+ /* Deregister for router-id, interfaces,
+ * redistributed routes. */
+ zclient_send_dereg_requests(zclient, ospf6->vrf_id);
+ }
+}
+
/* Router-id update message from zebra. */
static int ospf6_router_id_update_zebra(ZAPI_CALLBACK_ARGS)
{
struct prefix router_id;
- struct ospf6 *o = ospf6;
+ struct ospf6 *o;
zebra_router_id_update_read(zclient->ibuf, &router_id);
om6->zebra_router_id = router_id.u.prefix4.s_addr;
-
+ o = ospf6_lookup_by_vrf_id(vrf_id);
if (o == NULL)
return 0;
@@ -69,7 +104,7 @@ static int ospf6_router_id_update_zebra(ZAPI_CALLBACK_ARGS)
INET_ADDRSTRLEN));
}
- ospf6_router_id_update();
+ ospf6_router_id_update(o);
return 0;
}
@@ -146,6 +181,9 @@ static int ospf6_zebra_read_route(ZAPI_CALLBACK_ARGS)
struct zapi_route api;
unsigned long ifindex;
struct in6_addr *nexthop;
+ struct ospf6 *ospf6;
+
+ ospf6 = ospf6_lookup_by_vrf_id(vrf_id);
if (ospf6 == NULL)
return 0;
@@ -173,44 +211,80 @@ static int ospf6_zebra_read_route(ZAPI_CALLBACK_ARGS)
if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD)
ospf6_asbr_redistribute_add(api.type, ifindex, &api.prefix,
- api.nexthop_num, nexthop, api.tag);
+ api.nexthop_num, nexthop, api.tag,
+ ospf6);
else
- ospf6_asbr_redistribute_remove(api.type, ifindex, &api.prefix);
+ ospf6_asbr_redistribute_remove(api.type, ifindex, &api.prefix,
+ ospf6);
return 0;
}
-DEFUN (show_zebra,
- show_ospf6_zebra_cmd,
- "show ipv6 ospf6 zebra",
- SHOW_STR
- IPV6_STR
- OSPF6_STR
- ZEBRA_STR)
+DEFUN(show_zebra,
+ show_ospf6_zebra_cmd,
+ "show ipv6 ospf6 zebra [json]",
+ SHOW_STR
+ IPV6_STR
+ OSPF6_STR
+ ZEBRA_STR
+ JSON_STR)
{
int i;
+ bool uj = use_json(argc, argv);
+ json_object *json;
+ json_object *json_zebra;
+ json_object *json_array;
+
if (zclient == NULL) {
vty_out(vty, "Not connected to zebra\n");
return CMD_SUCCESS;
}
- vty_out(vty, "Zebra Information\n");
- vty_out(vty, " fail: %d\n", zclient->fail);
- vty_out(vty, " redistribute default: %d\n",
- vrf_bitmap_check(zclient->default_information[AFI_IP6],
- VRF_DEFAULT));
- vty_out(vty, " redistribute:");
- for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
- if (vrf_bitmap_check(zclient->redist[AFI_IP6][i], VRF_DEFAULT))
- vty_out(vty, " %s", zebra_route_string(i));
+ if (uj) {
+ json = json_object_new_object();
+ json_zebra = json_object_new_object();
+ json_array = json_object_new_array();
+
+ json_object_int_add(json_zebra, "fail", zclient->fail);
+ json_object_int_add(
+ json_zebra, "redistributeDefault",
+ vrf_bitmap_check(zclient->default_information[AFI_IP6],
+ VRF_DEFAULT));
+ for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
+ if (vrf_bitmap_check(zclient->redist[AFI_IP6][i],
+ VRF_DEFAULT))
+ json_object_array_add(
+ json_array,
+ json_object_new_string(
+ zebra_route_string(i)));
+ }
+ json_object_object_add(json_zebra, "redistribute", json_array);
+ json_object_object_add(json, "zebraInformation", json_zebra);
+
+ vty_out(vty, "%s\n",
+ json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
+ } else {
+ vty_out(vty, "Zebra Infomation\n");
+ vty_out(vty, " fail: %d\n", zclient->fail);
+ vty_out(vty, " redistribute default: %d\n",
+ vrf_bitmap_check(zclient->default_information[AFI_IP6],
+ VRF_DEFAULT));
+ vty_out(vty, " redistribute:");
+ for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
+ if (vrf_bitmap_check(zclient->redist[AFI_IP6][i],
+ VRF_DEFAULT))
+ vty_out(vty, " %s", zebra_route_string(i));
+ }
+ vty_out(vty, "\n");
}
- vty_out(vty, "\n");
return CMD_SUCCESS;
}
#define ADD 0
#define REM 1
-static void ospf6_zebra_route_update(int type, struct ospf6_route *request)
+static void ospf6_zebra_route_update(int type, struct ospf6_route *request,
+ struct ospf6 *ospf6)
{
struct zapi_route api;
int nhcount;
@@ -280,15 +354,15 @@ static void ospf6_zebra_route_update(int type, struct ospf6_route *request)
}
SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);
- api.distance =
- ospf6_distance_apply((struct prefix_ipv6 *)dest, request);
+ api.distance = ospf6_distance_apply((struct prefix_ipv6 *)dest, request,
+ ospf6);
if (type == REM)
ret = zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
else
ret = zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
- if (ret < 0)
+ if (ret == ZCLIENT_SEND_FAILURE)
flog_err(EC_LIB_ZAPI_SOCKET,
"zclient_route_send() %s failed: %s",
(type == REM ? "delete" : "add"),
@@ -297,17 +371,19 @@ static void ospf6_zebra_route_update(int type, struct ospf6_route *request)
return;
}
-void ospf6_zebra_route_update_add(struct ospf6_route *request)
+void ospf6_zebra_route_update_add(struct ospf6_route *request,
+ struct ospf6 *ospf6)
{
- ospf6_zebra_route_update(ADD, request);
+ ospf6_zebra_route_update(ADD, request, ospf6);
}
-void ospf6_zebra_route_update_remove(struct ospf6_route *request)
+void ospf6_zebra_route_update_remove(struct ospf6_route *request,
+ struct ospf6 *ospf6)
{
- ospf6_zebra_route_update(REM, request);
+ ospf6_zebra_route_update(REM, request, ospf6);
}
-void ospf6_zebra_add_discard(struct ospf6_route *request)
+void ospf6_zebra_add_discard(struct ospf6_route *request, struct ospf6 *ospf6)
{
struct zapi_route api;
struct prefix *dest = &request->prefix;
@@ -334,7 +410,8 @@ void ospf6_zebra_add_discard(struct ospf6_route *request)
}
}
-void ospf6_zebra_delete_discard(struct ospf6_route *request)
+void ospf6_zebra_delete_discard(struct ospf6_route *request,
+ struct ospf6 *ospf6)
{
struct zapi_route api;
struct prefix *dest = &request->prefix;
@@ -462,7 +539,8 @@ void ospf6_distance_reset(struct ospf6 *o)
}
}
-uint8_t ospf6_distance_apply(struct prefix_ipv6 *p, struct ospf6_route * or)
+uint8_t ospf6_distance_apply(struct prefix_ipv6 *p, struct ospf6_route * or,
+ struct ospf6 *ospf6)
{
struct ospf6 *o;