]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_sr.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / ospfd / ospf_sr.c
index e4059d05c2cc459bbe8e8a4fed592d6a8ed715db..adb14ec6b1478ce9173e58dfe118c938fa77bcb5 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * This is an implementation of Segment Routing
  * as per RFC 8665 - OSPF Extensions for Segment Routing
@@ -9,20 +10,6 @@
  * Author: Anselme Sawadogo <anselmesawadogo@gmail.com>
  *
  * Copyright (C) 2016 - 2020 Orange Labs http://www.orange.com
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #ifdef HAVE_CONFIG_H
@@ -608,7 +595,7 @@ int ospf_sr_init(void)
 
        osr_debug("SR (%s): Initialize SR Data Base", __func__);
 
-       memset(&OspfSR, 0, sizeof(struct ospf_sr_db));
+       memset(&OspfSR, 0, sizeof(OspfSR));
        OspfSR.status = SR_OFF;
        /* Only AREA flooding is supported in this release */
        OspfSR.scope = OSPF_OPAQUE_AREA_LSA;
@@ -756,13 +743,14 @@ static struct ospf_neighbor *get_neighbor_by_addr(struct ospf *top,
        for (ALL_LIST_ELEMENTS_RO(top->oiflist, node, oi))
                for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
                        nbr = rn->info;
-                       if (nbr)
-                               if (IPV4_ADDR_SAME(&nbr->address.u.prefix4,
-                                                  &addr)
-                                   || IPV4_ADDR_SAME(&nbr->router_id, &addr)) {
-                                       route_unlock_node(rn);
-                                       return nbr;
-                               }
+                       if (!nbr)
+                               continue;
+
+                       if (IPV4_ADDR_SAME(&nbr->address.u.prefix4, &addr) ||
+                           IPV4_ADDR_SAME(&nbr->router_id, &addr)) {
+                               route_unlock_node(rn);
+                               return nbr;
+                       }
                }
        return NULL;
 }
@@ -1463,14 +1451,6 @@ void ospf_sr_ri_lsa_update(struct ospf_lsa *lsa)
                srn = (struct sr_node *)hash_get(OspfSR.neighbors,
                                                 &lsah->adv_router,
                                                 (void *)sr_node_new);
-               /* Sanity check */
-               if (srn == NULL) {
-                       flog_err(
-                               EC_OSPF_SR_NODE_CREATE,
-                               "SR (%s): Abort! can't create SR node in hash table",
-                               __func__);
-                       return;
-               }
                /* update LSA ID */
                srn->instance = ntohl(lsah->id.s_addr);
                /* Copy SRGB */
@@ -1582,14 +1562,6 @@ void ospf_sr_ext_link_lsa_update(struct ospf_lsa *lsa)
                                         (void *)&(lsah->adv_router),
                                         (void *)sr_node_new);
 
-       /* Sanity check */
-       if (srn == NULL) {
-               flog_err(EC_OSPF_SR_NODE_CREATE,
-                        "SR (%s): Abort! can't create SR node in hash table",
-                        __func__);
-               return;
-       }
-
        /* Initialize TLV browsing */
        length = lsa->size - OSPF_LSA_HEADER_SIZE;
        for (tlvh = TLV_HDR_TOP(lsah); length > 0 && tlvh;
@@ -1814,15 +1786,6 @@ void ospf_sr_ext_prefix_lsa_update(struct ospf_lsa *lsa)
        srn = (struct sr_node *)hash_get(OspfSR.neighbors,
                                         (void *)&(lsah->adv_router),
                                         (void *)sr_node_new);
-
-       /* Sanity check */
-       if (srn == NULL) {
-               flog_err(EC_OSPF_SR_NODE_CREATE,
-                        "SR (%s): Abort! can't create SR node in hash table",
-                        __func__);
-               return;
-       }
-
        /* Initialize TLV browsing */
        length = lsa->size - OSPF_LSA_HEADER_SIZE;
        for (tlvh = TLV_HDR_TOP(lsah); length > 0 && tlvh;
@@ -2023,7 +1986,7 @@ void ospf_sr_update_task(struct ospf *ospf)
 
 /*
  * --------------------------------------
- * Followings are vty command functions.
+ * Following are vty command functions.
  * --------------------------------------
  */
 
@@ -2053,11 +2016,15 @@ void ospf_sr_config_write_router(struct vty *vty)
                vty_out(vty, " segment-routing global-block %u %u",
                        OspfSR.srgb.start, upper);
 
-       if ((OspfSR.srlb.start != DEFAULT_SRLB_LABEL)
-           || (OspfSR.srlb.end != DEFAULT_SRLB_END))
+       if ((OspfSR.srlb.start != DEFAULT_SRLB_LABEL) ||
+           (OspfSR.srlb.end != DEFAULT_SRLB_END)) {
+               if ((OspfSR.srgb.start == DEFAULT_SRGB_LABEL) &&
+                   (OspfSR.srgb.size == DEFAULT_SRGB_SIZE))
+                       vty_out(vty, " segment-routing global-block %u %u",
+                               OspfSR.srgb.start, upper);
                vty_out(vty, " local-block %u %u\n", OspfSR.srlb.start,
                        OspfSR.srlb.end);
-       else
+       else
                vty_out(vty, "\n");
 
        if (OspfSR.msd != 0)
@@ -2323,84 +2290,6 @@ DEFUN(no_sr_global_label_range, no_sr_global_label_range_cmd,
                return CMD_SUCCESS;
 }
 
-#if CONFDATE > 20220528
-CPP_NOTICE(
-       "Use of the segment-routing local-block command is deprecated, use the combined global-block command instead")
-#endif
-
-DEFUN_HIDDEN(sr_local_label_range, sr_local_label_range_cmd,
-            "segment-routing local-block (16-1048575) (16-1048575)",
-            SR_STR
-            "Segment Routing Local Block label range\n"
-            "Lower-bound range in decimal (16-1048575)\n"
-            "Upper-bound range in decimal (16-1048575)\n")
-{
-       uint32_t upper;
-       uint32_t lower;
-       uint32_t srgb_upper;
-       int idx_low = 2;
-       int idx_up = 3;
-
-       /* Get lower and upper bound */
-       lower = strtoul(argv[idx_low]->arg, NULL, 10);
-       upper = strtoul(argv[idx_up]->arg, NULL, 10);
-
-       /* check correctness of SRLB */
-       if (!sr_range_is_valid(lower, upper, MIN_SRLB_SIZE)) {
-               vty_out(vty, "Invalid SRLB range\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       /* Check if values have changed */
-       if ((OspfSR.srlb.start == lower)
-           && (OspfSR.srlb.end == upper))
-               return CMD_SUCCESS;
-
-       /* Validate SRLB against SRGB */
-       srgb_upper = OspfSR.srgb.start + OspfSR.srgb.size - 1;
-
-       if (ranges_overlap(OspfSR.srgb.start, srgb_upper, lower, upper)) {
-               vty_out(vty,
-                       "New SR Local Block (%u/%u) conflicts with Global Block (%u/%u)\n",
-                       lower, upper, OspfSR.srgb.start, srgb_upper);
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       if (update_sr_blocks(OspfSR.srgb.start, srgb_upper, lower, upper) < 0)
-               return CMD_WARNING_CONFIG_FAILED;
-       else
-               return CMD_SUCCESS;
-}
-
-DEFUN_HIDDEN(no_sr_local_label_range, no_sr_local_label_range_cmd,
-            "no segment-routing local-block [(16-1048575) (16-1048575)]",
-            NO_STR SR_STR
-            "Segment Routing Local Block label range\n"
-            "Lower-bound range in decimal (16-1048575)\n"
-            "Upper-bound range in decimal (16-1048575)\n")
-{
-
-       uint32_t srgb_end;
-
-       /* Validate SRLB against SRGB */
-       srgb_end = OspfSR.srgb.start + OspfSR.srgb.size - 1;
-       if (ranges_overlap(OspfSR.srgb.start, srgb_end, DEFAULT_SRLB_LABEL,
-                          DEFAULT_SRLB_END)) {
-               vty_out(vty,
-                       "New SR Local Block (%u/%u) conflicts with Global Block (%u/%u)\n",
-                       DEFAULT_SRLB_LABEL, DEFAULT_SRLB_END, OspfSR.srgb.start,
-                       srgb_end);
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       if (update_sr_blocks(OspfSR.srgb.start, srgb_end, DEFAULT_SRLB_LABEL,
-                            DEFAULT_SRLB_END)
-           < 0)
-               return CMD_WARNING_CONFIG_FAILED;
-       else
-               return CMD_SUCCESS;
-}
-
 DEFUN (sr_node_msd,
        sr_node_msd_cmd,
        "segment-routing node-msd (1-16)",
@@ -2663,12 +2552,18 @@ DEFUN (no_sr_prefix_sid,
                return CMD_WARNING_CONFIG_FAILED;
        }
 
+       osr_debug("SR (%s): Remove Prefix %pFX with index %u", __func__,
+                 (struct prefix *)&srp->prefv4, srp->sid);
+
        /* Get Interface */
        ifp = if_lookup_by_index(srp->nhlfe.ifindex, VRF_DEFAULT);
        if (ifp == NULL) {
                vty_out(vty, "interface for prefix %s not found.\n",
                        argv[idx]->arg);
-               return CMD_WARNING_CONFIG_FAILED;
+               /* silently remove from list */
+               listnode_delete(OspfSR.self->ext_prefix, srp);
+               XFREE(MTYPE_OSPF_SR_PARAMS, srp);
+               return CMD_SUCCESS;
        }
 
        /* Update Extended Prefix LSA */
@@ -2677,9 +2572,6 @@ DEFUN (no_sr_prefix_sid,
                return CMD_WARNING;
        }
 
-       osr_debug("SR (%s): Remove Prefix %pFX with index %u", __func__,
-                 (struct prefix *)&srp->prefv4, srp->sid);
-
        /* Delete NHLFE if NO-PHP is set and EXPLICIT NULL not set */
        if (CHECK_FLAG(srp->flags, EXT_SUBTLV_PREFIX_SID_NPFLG)
            && !CHECK_FLAG(srp->flags, EXT_SUBTLV_PREFIX_SID_EFLG))
@@ -3065,8 +2957,6 @@ void ospf_sr_register_vty(void)
        install_element(OSPF_NODE, &no_ospf_sr_enable_cmd);
        install_element(OSPF_NODE, &sr_global_label_range_cmd);
        install_element(OSPF_NODE, &no_sr_global_label_range_cmd);
-       install_element(OSPF_NODE, &sr_local_label_range_cmd);
-       install_element(OSPF_NODE, &no_sr_local_label_range_cmd);
        install_element(OSPF_NODE, &sr_node_msd_cmd);
        install_element(OSPF_NODE, &no_sr_node_msd_cmd);
        install_element(OSPF_NODE, &sr_prefix_sid_cmd);