]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_sr.c
Merge pull request #5549 from donaldsharp/automated
[mirror_frr.git] / ospfd / ospf_sr.c
index 33ec09b9f3a329e51b248ec7063ee70c373f546a..ff2039bec84984a977671afe36627bd66be4cf99 100644 (file)
@@ -86,7 +86,7 @@ static inline void del_sid_nhlfe(struct sr_nhlfe nhlfe);
  */
 
 /* Hash function for Segment Routing entry */
-static unsigned int sr_hash(void *p)
+static unsigned int sr_hash(const void *p)
 {
        const struct in_addr *rid = p;
 
@@ -94,7 +94,7 @@ static unsigned int sr_hash(void *p)
 }
 
 /* Compare 2 Router ID hash entries based on SR Node */
-static int sr_cmp(const void *p1, const void *p2)
+static bool sr_cmp(const void *p1, const void *p2)
 {
        const struct sr_node *srn = p1;
        const struct in_addr *rid = p2;
@@ -165,10 +165,10 @@ static void sr_node_del(struct sr_node *srn)
                return;
 
        /* Clean Extended Link */
-       list_delete_and_null(&srn->ext_link);
+       list_delete(&srn->ext_link);
 
        /* Clean Prefix List */
-       list_delete_and_null(&srn->ext_prefix);
+       list_delete(&srn->ext_prefix);
 
        XFREE(MTYPE_OSPF_SR_PARAMS, srn);
 }
@@ -283,7 +283,7 @@ static void ospf_sr_stop(void)
 
        /*
         * Remove all SR Nodes from the Hash table. Prefix and Link SID will
-        * be remove though list_delete_and_null() call. See sr_node_del()
+        * be remove though list_delete() call. See sr_node_del()
         */
        hash_clean(OspfSR.neighbors, (void *)sr_node_del);
 }
@@ -608,26 +608,8 @@ static int compute_prefix_nhlfe(struct sr_prefix *srp)
 /* Send MPLS Label entry to Zebra for installation or deletion */
 static int ospf_zebra_send_mpls_labels(int cmd, struct sr_nhlfe nhlfe)
 {
-       struct stream *s;
-
-       /* Reset stream. */
-       s = zclient->obuf;
-       stream_reset(s);
-
-       zclient_create_header(s, cmd, VRF_DEFAULT);
-       stream_putc(s, ZEBRA_LSP_SR);
-       /* OSPF Segment Routing currently support only IPv4 */
-       stream_putl(s, nhlfe.prefv4.family);
-       stream_put_in_addr(s, &nhlfe.prefv4.prefix);
-       stream_putc(s, nhlfe.prefv4.prefixlen);
-       stream_put_in_addr(s, &nhlfe.nexthop);
-       stream_putl(s, nhlfe.ifindex);
-       stream_putc(s, OSPF_SR_PRIORITY_DEFAULT);
-       stream_putl(s, nhlfe.label_in);
-       stream_putl(s, nhlfe.label_out);
-
-       /* Put length at the first point of the stream. */
-       stream_putw_at(s, 0, stream_get_endp(s));
+       struct zapi_labels zl = {};
+       struct zapi_nexthop_label *znh;
 
        if (IS_DEBUG_OSPF_SR)
                zlog_debug("    |-  %s LSP %u/%u for %s/%u via %u",
@@ -636,70 +618,39 @@ static int ospf_zebra_send_mpls_labels(int cmd, struct sr_nhlfe nhlfe)
                           inet_ntoa(nhlfe.prefv4.prefix),
                           nhlfe.prefv4.prefixlen, nhlfe.ifindex);
 
-       return zclient_send_message(zclient);
-}
-
-/* Request zebra to install/remove FEC in FIB */
-static int ospf_zebra_send_mpls_ftn(int cmd, struct sr_nhlfe nhlfe)
-{
-       struct zapi_route api;
-       struct zapi_nexthop *api_nh;
-
-       /* Support only IPv4 */
-       if (nhlfe.prefv4.family != AF_INET)
-               return -1;
-
-       memset(&api, 0, sizeof(api));
-       api.vrf_id = VRF_DEFAULT;
-       api.type = ZEBRA_ROUTE_OSPF;
-       api.safi = SAFI_UNICAST;
-       memcpy(&api.prefix, &nhlfe.prefv4, sizeof(struct prefix_ipv4));
-
-       if (cmd == ZEBRA_ROUTE_ADD) {
-               /* Metric value. */
-               SET_FLAG(api.message, ZAPI_MESSAGE_METRIC);
-               api.metric = OSPF_SR_DEFAULT_METRIC;
-               /* Nexthop */
-               SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
-               api_nh = &api.nexthops[0];
-               IPV4_ADDR_COPY(&api_nh->gate.ipv4, &nhlfe.nexthop);
-               api_nh->type = NEXTHOP_TYPE_IPV4_IFINDEX;
-               api_nh->ifindex = nhlfe.ifindex;
-               /* MPLS labels */
-               SET_FLAG(api.message, ZAPI_MESSAGE_LABEL);
-               api_nh->labels[0] = nhlfe.label_out;
-               api_nh->label_num = 1;
-               api_nh->vrf_id = VRF_DEFAULT;
-               api.nexthop_num = 1;
-       }
-
-       if (IS_DEBUG_OSPF_SR)
-               zlog_debug("    |-  %s FEC %u for %s/%u via %u",
-                          cmd == ZEBRA_ROUTE_ADD ? "Add" : "Delete",
-                          nhlfe.label_out, inet_ntoa(nhlfe.prefv4.prefix),
-                          nhlfe.prefv4.prefixlen, nhlfe.ifindex);
-
-       return zclient_route_send(cmd, zclient, &api);
+       zl.type = ZEBRA_LSP_OSPF_SR;
+       zl.local_label = nhlfe.label_in;
+
+       SET_FLAG(zl.message, ZAPI_LABELS_FTN);
+       zl.route.prefix.family = nhlfe.prefv4.family;
+       zl.route.prefix.prefixlen = nhlfe.prefv4.prefixlen;
+       zl.route.prefix.u.prefix4 = nhlfe.prefv4.prefix;
+       zl.route.type = ZEBRA_ROUTE_OSPF;
+       zl.route.instance = 0;
+
+       zl.nexthop_num = 1;
+       znh = &zl.nexthops[0];
+       znh->type = NEXTHOP_TYPE_IPV4_IFINDEX;
+       znh->family = AF_INET;
+       znh->address.ipv4 = nhlfe.nexthop;
+       znh->ifindex = nhlfe.ifindex;
+       znh->label = nhlfe.label_out;
+
+       return zebra_send_mpls_labels(zclient, cmd, &zl);
 }
 
 /* Add new NHLFE entry for SID */
 static inline void add_sid_nhlfe(struct sr_nhlfe nhlfe)
 {
-       if ((nhlfe.label_in != 0) && (nhlfe.label_out != 0)) {
+       if ((nhlfe.label_in != 0) && (nhlfe.label_out != 0))
                ospf_zebra_send_mpls_labels(ZEBRA_MPLS_LABELS_ADD, nhlfe);
-               if (nhlfe.label_out != MPLS_LABEL_IMPLICIT_NULL)
-                       ospf_zebra_send_mpls_ftn(ZEBRA_ROUTE_ADD, nhlfe);
-       }
 }
 
 /* Remove NHLFE entry for SID */
 static inline void del_sid_nhlfe(struct sr_nhlfe nhlfe)
 {
-       if ((nhlfe.label_in != 0) && (nhlfe.label_out != 0)) {
+       if ((nhlfe.label_in != 0) && (nhlfe.label_out != 0))
                ospf_zebra_send_mpls_labels(ZEBRA_MPLS_LABELS_DELETE, nhlfe);
-               if (nhlfe.label_out != MPLS_LABEL_IMPLICIT_NULL)
-                       ospf_zebra_send_mpls_ftn(ZEBRA_ROUTE_DELETE, nhlfe);
-       }
 }
 
 /* Update NHLFE entry for SID */
@@ -1020,10 +971,10 @@ static void update_ext_prefix_sid(struct sr_node *srn, struct sr_prefix *srp)
  * When change the FRR Self SRGB, update the NHLFE Input Label
  * for all Extended Prefix with SID index through hash_iterate()
  */
-static void update_in_nhlfe(struct hash_backet *backet, void *args)
+static void update_in_nhlfe(struct hash_bucket *bucket, void *args)
 {
        struct listnode *node;
-       struct sr_node *srn = (struct sr_node *)backet->data;
+       struct sr_node *srn = (struct sr_node *)bucket->data;
        struct sr_prefix *srp;
        struct sr_nhlfe new;
 
@@ -1052,10 +1003,10 @@ static void update_in_nhlfe(struct hash_backet *backet, void *args)
  * When SRGB has changed, update NHLFE Output Label for all Extended Prefix
  * with SID index which use the given SR-Node as nexthop though hash_iterate()
  */
-static void update_out_nhlfe(struct hash_backet *backet, void *args)
+static void update_out_nhlfe(struct hash_bucket *bucket, void *args)
 {
        struct listnode *node;
-       struct sr_node *srn = (struct sr_node *)backet->data;
+       struct sr_node *srn = (struct sr_node *)bucket->data;
        struct sr_node *srnext = (struct sr_node *)args;
        struct sr_prefix *srp;
        struct sr_nhlfe new;
@@ -1192,7 +1143,7 @@ void ospf_sr_ri_lsa_update(struct ospf_lsa *lsa)
                /* Update NHLFE if it is a neighbor SR node */
                if (srn->neighbor == OspfSR.self)
                        hash_iterate(OspfSR.neighbors,
-                                    (void (*)(struct hash_backet *,
+                                    (void (*)(struct hash_bucket *,
                                               void *))update_out_nhlfe,
                                     (void *)srn);
        }
@@ -1531,10 +1482,10 @@ void ospf_sr_update_prefix(struct interface *ifp, struct prefix *p)
  * Following functions are used to update MPLS LFIB after a SPF run
  */
 
-static void ospf_sr_nhlfe_update(struct hash_backet *backet, void *args)
+static void ospf_sr_nhlfe_update(struct hash_bucket *bucket, void *args)
 {
 
-       struct sr_node *srn = (struct sr_node *)backet->data;
+       struct sr_node *srn = (struct sr_node *)bucket->data;
        struct listnode *node;
        struct sr_prefix *srp;
        struct sr_nhlfe old;
@@ -1593,14 +1544,14 @@ static int ospf_sr_update_schedule(struct thread *t)
        if (IS_DEBUG_OSPF_SR)
                zlog_debug("SR (%s): Start SPF update", __func__);
 
-       hash_iterate(OspfSR.neighbors, (void (*)(struct hash_backet *,
+       hash_iterate(OspfSR.neighbors, (void (*)(struct hash_bucket *,
                                                 void *))ospf_sr_nhlfe_update,
                     NULL);
 
        monotime(&stop_time);
 
        if (IS_DEBUG_OSPF_SR)
-               zlog_debug("SR (%s): SPF Processing Time(usecs): %lld\n",
+               zlog_debug("SR (%s): SPF Processing Time(usecs): %lld",
                           __func__,
                           (stop_time.tv_sec - start_time.tv_sec) * 1000000LL
                                   + (stop_time.tv_usec - start_time.tv_usec));
@@ -1818,7 +1769,7 @@ DEFUN (sr_sid_label_range,
 
        /* Update NHLFE entries */
        hash_iterate(OspfSR.neighbors,
-                    (void (*)(struct hash_backet *, void *))update_in_nhlfe,
+                    (void (*)(struct hash_bucket *, void *))update_in_nhlfe,
                     NULL);
 
        return CMD_SUCCESS;
@@ -1850,7 +1801,7 @@ DEFUN (no_sr_sid_label_range,
 
        /* Update NHLFE entries */
        hash_iterate(OspfSR.neighbors,
-                    (void (*)(struct hash_backet *, void *))update_in_nhlfe,
+                    (void (*)(struct hash_bucket *, void *))update_in_nhlfe,
                     NULL);
 
        return CMD_SUCCESS;
@@ -2053,6 +2004,9 @@ DEFUN (no_sr_prefix_sid,
        bool found = false;
        int rc;
 
+       if (!ospf_sr_enabled(vty))
+               return CMD_WARNING_CONFIG_FAILED;
+
        /* Get network prefix */
        argv_find(argv, argc, "A.B.C.D/M", &idx);
        rc = str2prefix(argv[idx]->arg, &p);
@@ -2278,18 +2232,18 @@ static void show_sr_node(struct vty *vty, struct json_object *json,
                vty_out(vty, "\n");
 }
 
-static void show_vty_srdb(struct hash_backet *backet, void *args)
+static void show_vty_srdb(struct hash_bucket *bucket, void *args)
 {
        struct vty *vty = (struct vty *)args;
-       struct sr_node *srn = (struct sr_node *)backet->data;
+       struct sr_node *srn = (struct sr_node *)bucket->data;
 
        show_sr_node(vty, NULL, srn);
 }
 
-static void show_json_srdb(struct hash_backet *backet, void *args)
+static void show_json_srdb(struct hash_bucket *bucket, void *args)
 {
        struct json_object *json = (struct json_object *)args;
-       struct sr_node *srn = (struct sr_node *)backet->data;
+       struct sr_node *srn = (struct sr_node *)bucket->data;
 
        show_sr_node(NULL, json, srn);
 }
@@ -2363,14 +2317,14 @@ DEFUN (show_ip_opsf_srdb,
 
        /* No parameters have been provided, Iterate through all the SRDB */
        if (uj) {
-               hash_iterate(OspfSR.neighbors, (void (*)(struct hash_backet *,
+               hash_iterate(OspfSR.neighbors, (void (*)(struct hash_bucket *,
                                                         void *))show_json_srdb,
                             (void *)json_node_array);
                vty_out(vty, "%s\n", json_object_to_json_string_ext(
                                             json, JSON_C_TO_STRING_PRETTY));
                json_object_free(json);
        } else {
-               hash_iterate(OspfSR.neighbors, (void (*)(struct hash_backet *,
+               hash_iterate(OspfSR.neighbors, (void (*)(struct hash_bucket *,
                                                         void *))show_vty_srdb,
                             (void *)vty);
        }