]> git.proxmox.com Git - mirror_frr.git/blobdiff - sharpd/sharp_nht.c
Merge pull request #13162 from donaldsharp/pass_by_value_no_no_no
[mirror_frr.git] / sharpd / sharp_nht.c
index 7484dd3b068837f29ebeaf83b9007a7be709f6b0..fa7880572d9df308d1fadb1b90fb01408ab9cd5f 100644 (file)
@@ -1,23 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * SHARP - code to track nexthops
  * Copyright (C) Cumulus Networks, Inc.
  *               Donald Sharp
- *
- * This file is part of FRR.
- *
- * FRR 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, or (at your option) any
- * later version.
- *
- * FRR 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
  */
 #include <zebra.h>
 
@@ -32,8 +17,8 @@
 #include "sharp_globals.h"
 #include "sharp_zebra.h"
 
-DEFINE_MTYPE_STATIC(SHARPD, NH_TRACKER, "Nexthop Tracker")
-DEFINE_MTYPE_STATIC(SHARPD, NHG, "Nexthop Group")
+DEFINE_MTYPE_STATIC(SHARPD, NH_TRACKER, "Nexthop Tracker");
+DEFINE_MTYPE_STATIC(SHARPD, NHG, "Nexthop Group");
 
 struct sharp_nh_tracker *sharp_nh_tracker_get(struct prefix *p)
 {
@@ -60,14 +45,9 @@ void sharp_nh_tracker_dump(struct vty *vty)
        struct listnode *node;
        struct sharp_nh_tracker *nht;
 
-       for (ALL_LIST_ELEMENTS_RO(sg.nhs, node, nht)) {
-               char buf[PREFIX_STRLEN];
-
-               vty_out(vty, "%s: Nexthops: %u Updates: %u\n",
-                       prefix2str(&nht->p, buf, sizeof(buf)),
-                       nht->nhop_num,
-                       nht->updates);
-       }
+       for (ALL_LIST_ELEMENTS_RO(sg.nhs, node, nht))
+               vty_out(vty, "%pFX: Nexthops: %u Updates: %u\n", &nht->p,
+                       nht->nhop_num, nht->updates);
 }
 
 PREDECL_RBTREE_UNIQ(sharp_nhg_rb);
@@ -77,7 +57,8 @@ struct sharp_nhg {
 
        uint32_t id;
 
-       char name[256];
+#define NHG_NAME_LEN 256
+       char name[NHG_NAME_LEN];
 
        bool installed;
 };
@@ -95,7 +76,7 @@ struct sharp_nhg_rb_head nhg_head;
 static int sharp_nhg_compare_func(const struct sharp_nhg *a,
                                  const struct sharp_nhg *b)
 {
-       return strncmp(a->name, b->name, strlen(a->name));
+       return strncmp(a->name, b->name, NHG_NAME_LEN);
 }
 
 DECLARE_RBTREE_UNIQ(sharp_nhg_rb, struct sharp_nhg, mylistitem,
@@ -128,6 +109,24 @@ static void sharp_nhgroup_add_cb(const char *name)
        sharp_nhg_rb_add(&nhg_head, snhg);
 }
 
+static void sharp_nhgroup_modify_cb(const struct nexthop_group_cmd *nhgc)
+{
+       struct sharp_nhg lookup;
+       struct sharp_nhg *snhg;
+       struct nexthop_group_cmd *bnhgc = NULL;
+
+       strlcpy(lookup.name, nhgc->name, sizeof(lookup.name));
+       snhg = sharp_nhg_rb_find(&nhg_head, &lookup);
+
+       if (!nhgc->nhg.nexthop)
+               return;
+
+       if (nhgc->backup_list_name[0])
+               bnhgc = nhgc_find(nhgc->backup_list_name);
+
+       nhg_add(snhg->id, &nhgc->nhg, (bnhgc ? &bnhgc->nhg : NULL));
+}
+
 static void sharp_nhgroup_add_nexthop_cb(const struct nexthop_group_cmd *nhgc,
                                         const struct nexthop *nhop)
 {
@@ -219,7 +218,8 @@ void sharp_nhgroup_init(void)
        sharp_nhg_rb_init(&nhg_head);
        nhg_id = zclient_get_nhg_start(ZEBRA_ROUTE_SHARP);
 
-       nexthop_group_init(sharp_nhgroup_add_cb, sharp_nhgroup_add_nexthop_cb,
+       nexthop_group_init(sharp_nhgroup_add_cb, sharp_nhgroup_modify_cb,
+                          sharp_nhgroup_add_nexthop_cb,
                           sharp_nhgroup_del_nexthop_cb,
                           sharp_nhgroup_delete_cb);
 }