]> git.proxmox.com Git - mirror_frr.git/blobdiff - sharpd/sharp_zebra.c
Merge pull request #3546 from opensourcerouting/ospf-show-neighbor-fix
[mirror_frr.git] / sharpd / sharp_zebra.c
index 8915397c7e7455cf01e3e248cc8d8084bea5bf8c..f752009eb8fc61312e35b08e0d13bbe44e26aabf 100644 (file)
@@ -176,7 +176,7 @@ void vrf_label_add(vrf_id_t vrf_id, afi_t afi, mpls_label_t label)
        zclient_send_vrf_label(zclient, vrf_id, afi, label, ZEBRA_LSP_SHARP);
 }
 
-void route_add(struct prefix *p, struct nexthop *nh)
+void route_add(struct prefix *p, uint8_t instance, struct nexthop *nh)
 {
        struct zapi_route api;
        struct zapi_nexthop *api_nh;
@@ -184,6 +184,7 @@ void route_add(struct prefix *p, struct nexthop *nh)
        memset(&api, 0, sizeof(api));
        api.vrf_id = VRF_DEFAULT;
        api.type = ZEBRA_ROUTE_SHARP;
+       api.instance = instance;
        api.safi = SAFI_UNICAST;
        memcpy(&api.prefix, p, sizeof(*p));
 
@@ -192,7 +193,7 @@ void route_add(struct prefix *p, struct nexthop *nh)
 
        api_nh = &api.nexthops[0];
        api_nh->vrf_id = VRF_DEFAULT;
-       api_nh->gate.ipv4 = nh->gate.ipv4;
+       api_nh->gate = nh->gate;
        api_nh->type = nh->type;
        api_nh->ifindex = nh->ifindex;
        api.nexthop_num = 1;
@@ -200,7 +201,7 @@ void route_add(struct prefix *p, struct nexthop *nh)
        zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
 }
 
-void route_delete(struct prefix *p)
+void route_delete(struct prefix *p, uint8_t instance)
 {
        struct zapi_route api;
 
@@ -208,19 +209,81 @@ void route_delete(struct prefix *p)
        api.vrf_id = VRF_DEFAULT;
        api.type = ZEBRA_ROUTE_SHARP;
        api.safi = SAFI_UNICAST;
+       api.instance = instance;
        memcpy(&api.prefix, p, sizeof(*p));
        zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
 
        return;
 }
 
+void sharp_zebra_nexthop_watch(struct prefix *p, bool watch)
+{
+       int command = ZEBRA_NEXTHOP_REGISTER;
+
+       if (!watch)
+               command = ZEBRA_NEXTHOP_UNREGISTER;
+
+       if (zclient_send_rnh(zclient, command, p, true, VRF_DEFAULT) < 0)
+               zlog_warn("%s: Failure to send nexthop to zebra",
+                         __PRETTY_FUNCTION__);
+}
+
+static int sharp_nexthop_update(int command, struct zclient *zclient,
+                               zebra_size_t length, vrf_id_t vrf_id)
+{
+       struct zapi_route nhr;
+       char buf[PREFIX_STRLEN];
+       int i;
+
+       if (!zapi_nexthop_update_decode(zclient->ibuf, &nhr)) {
+               zlog_warn("%s: Decode of update failed", __PRETTY_FUNCTION__);
+
+               return 0;
+       }
+
+       zlog_debug("Received update for %s",
+                  prefix2str(&nhr.prefix, buf, sizeof(buf)));
+       for (i = 0; i < nhr.nexthop_num; i++) {
+               struct zapi_nexthop *znh = &nhr.nexthops[i];
+
+               switch (znh->type) {
+               case NEXTHOP_TYPE_IPV4_IFINDEX:
+               case NEXTHOP_TYPE_IPV4:
+                       zlog_debug(
+                               "\tNexthop %s, type: %d, ifindex: %d, vrf: %d, label_num: %d",
+                               inet_ntop(AF_INET, &znh->gate.ipv4.s_addr, buf,
+                                         sizeof(buf)),
+                               znh->type, znh->ifindex, znh->vrf_id,
+                               znh->label_num);
+                       break;
+               case NEXTHOP_TYPE_IPV6_IFINDEX:
+               case NEXTHOP_TYPE_IPV6:
+                       zlog_debug(
+                               "\tNexthop %s, type: %d, ifindex: %d, vrf: %d, label_num: %d",
+                               inet_ntop(AF_INET6, &znh->gate.ipv6, buf,
+                                         sizeof(buf)),
+                               znh->type, znh->ifindex, znh->vrf_id,
+                               znh->label_num);
+                       break;
+               case NEXTHOP_TYPE_IFINDEX:
+                       zlog_debug("\tNexthop IFINDEX: %d, ifindex: %d",
+                                  znh->type, znh->ifindex);
+                       break;
+               case NEXTHOP_TYPE_BLACKHOLE:
+                       zlog_debug("\tNexthop blackhole");
+                       break;
+               }
+       }
+       return 0;
+}
+
 extern struct zebra_privs_t sharp_privs;
 
 void sharp_zebra_init(void)
 {
        struct zclient_options opt = {.receive_notify = true};
 
-       zclient = zclient_new_notify(master, &opt);
+       zclient = zclient_new(master, &opt);
 
        zclient_init(zclient, ZEBRA_ROUTE_SHARP, 0, &sharp_privs);
        zclient->zebra_connected = zebra_connected;
@@ -231,4 +294,5 @@ void sharp_zebra_init(void)
        zclient->interface_address_add = interface_address_add;
        zclient->interface_address_delete = interface_address_delete;
        zclient->route_notify_owner = route_notify_owner;
+       zclient->nexthop_update = sharp_nexthop_update;
 }