]> git.proxmox.com Git - mirror_frr.git/blame - staticd/static_nht.c
bgpd: Keep the session down if maximum-prefix is reached
[mirror_frr.git] / staticd / static_nht.c
CommitLineData
7e24fdf3
DS
1/*
2 * Static NHT code.
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Donald Sharp
5 *
8d5cbee9
DS
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
7e24fdf3 10 *
8d5cbee9
DS
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
7e24fdf3
DS
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20#include <zebra.h>
21
22#include "prefix.h"
23#include "table.h"
24#include "vrf.h"
25#include "nexthop.h"
26
27#include "static_vrf.h"
28#include "static_routes.h"
29#include "static_zebra.h"
30#include "static_nht.h"
31
c45fb58d
DS
32static void static_nht_update_safi(struct prefix *p, uint32_t nh_num,
33 afi_t afi, safi_t safi, struct vrf *vrf,
34 vrf_id_t nh_vrf_id)
7e24fdf3
DS
35{
36 struct route_table *stable;
37 struct static_route *si;
38 struct static_vrf *svrf;
39 struct route_node *rn;
7e24fdf3
DS
40 bool orig;
41 bool reinstall;
42
c45fb58d
DS
43 svrf = vrf->info;
44 if (!svrf)
45 return;
7e24fdf3 46
c45fb58d
DS
47 stable = static_vrf_static_table(afi, safi, svrf);
48 if (!stable)
49 return;
7e24fdf3 50
c45fb58d
DS
51 for (rn = route_top(stable); rn; rn = route_next(rn)) {
52 reinstall = false;
53 for (si = rn->info; si; si = si->next) {
54 if (si->nh_vrf_id != nh_vrf_id)
24a4626c 55 continue;
7e24fdf3 56
c45fb58d
DS
57 if (si->type != STATIC_IPV4_GATEWAY
58 && si->type != STATIC_IPV4_GATEWAY_IFNAME
59 && si->type != STATIC_IPV6_GATEWAY
60 && si->type != STATIC_IPV6_GATEWAY_IFNAME)
24a4626c 61 continue;
7e24fdf3 62
c45fb58d
DS
63 orig = si->nh_valid;
64 if (p->family == AF_INET
65 && p->u.prefix4.s_addr == si->addr.ipv4.s_addr)
66 si->nh_valid = !!nh_num;
7e24fdf3 67
c45fb58d
DS
68 if (p->family == AF_INET6
69 && memcmp(&p->u.prefix6, &si->addr.ipv6, 16) == 0)
70 si->nh_valid = !!nh_num;
7e24fdf3 71
c45fb58d
DS
72 if (orig != si->nh_valid)
73 reinstall = true;
8bc8de2c 74
c45fb58d
DS
75 if (reinstall) {
76 static_zebra_route_add(rn, si, vrf->vrf_id,
77 safi, true);
78 reinstall = false;
8bc8de2c 79 }
7e24fdf3 80 }
7e24fdf3
DS
81 }
82}
c45fb58d
DS
83
84void static_nht_update(struct prefix *p, uint32_t nh_num, afi_t afi,
85 vrf_id_t nh_vrf_id)
86{
87
88 struct vrf *vrf;
89
90 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
91 static_nht_update_safi(p, nh_num, afi, SAFI_UNICAST,
92 vrf, nh_vrf_id);
93 static_nht_update_safi(p, nh_num, afi, SAFI_MULTICAST,
94 vrf, nh_vrf_id);
95 }
96}