]> git.proxmox.com Git - mirror_frr.git/blame - sharpd/sharp_nht.c
Merge pull request #5224 from manuhalo/fix_frr_reload_paths
[mirror_frr.git] / sharpd / sharp_nht.c
CommitLineData
86da53ab
DS
1/*
2 * SHARP - code to track nexthops
3 * Copyright (C) Cumulus Networks, Inc.
4 * Donald Sharp
5 *
6 * This file is part of FRR.
7 *
8 * FRR is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * FRR is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22#include <zebra.h>
23
24#include "memory.h"
25#include "nexthop.h"
26#include "nexthop_group.h"
27#include "vty.h"
28
29#include "sharp_nht.h"
30#include "sharp_globals.h"
31
32DEFINE_MTYPE_STATIC(SHARPD, NH_TRACKER, "Nexthop Tracker")
33
34struct sharp_nh_tracker *sharp_nh_tracker_get(struct prefix *p)
35{
36 struct listnode *node;
37 struct sharp_nh_tracker *nht;
38
39 for (ALL_LIST_ELEMENTS_RO(sg.nhs, node, nht)) {
40 if (prefix_same(&nht->p, p))
41 break;
42 }
43
44 if (nht)
45 return nht;
46
47 nht = XCALLOC(MTYPE_NH_TRACKER, sizeof(*nht));
48 prefix_copy(&nht->p, p);
49
50 listnode_add(sg.nhs, nht);
51 return nht;
52}
53
54void sharp_nh_tracker_dump(struct vty *vty)
55{
56 struct listnode *node;
57 struct sharp_nh_tracker *nht;
58
59 for (ALL_LIST_ELEMENTS_RO(sg.nhs, node, nht)) {
60 char buf[PREFIX_STRLEN];
61
62 vty_out(vty, "%s: Nexthops: %u Updates: %u\n",
63 prefix2str(&nht->p, buf, sizeof(buf)),
64 nht->nhop_num,
65 nht->updates);
66 }
67}