]> git.proxmox.com Git - mirror_frr.git/blob - staticd/static_nht.c
staticd: Start the addition of a staticd
[mirror_frr.git] / staticd / static_nht.c
1 /*
2 * Static NHT code.
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Donald Sharp
5 *
6 * FRR 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
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * FRR is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
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
32 void static_nht_update(struct prefix *p, uint32_t nh_num,
33 afi_t afi, vrf_id_t vrf_id)
34 {
35 struct route_table *stable;
36 struct static_route *si;
37 struct static_vrf *svrf;
38 struct route_node *rn;
39 struct vrf *vrf;
40 bool orig;
41 bool reinstall;
42
43 vrf = vrf_lookup_by_id(vrf_id);
44
45 if (!vrf->info)
46 return;
47
48 svrf = vrf->info;
49 stable = static_vrf_static_table(afi, SAFI_UNICAST, svrf);
50 if (!stable)
51 return;
52
53 for (rn = route_top(stable); rn; rn = route_next(rn)) {
54 reinstall = false;
55 for (si = rn->info; si; si = si->next) {
56 if (si->type != STATIC_IPV4_GATEWAY &&
57 si->type != STATIC_IPV6_GATEWAY)
58 continue;
59
60 orig = si->nh_valid;
61 if (p->family == AF_INET &&
62 p->u.prefix4.s_addr == si->addr.ipv4.s_addr)
63 si->nh_valid = !!nh_num;
64
65 if (p->family == AF_INET6 &&
66 memcmp(&p->u.prefix6, &si->addr.ipv6, 16) == 0)
67 si->nh_valid = !!nh_num;
68
69 if (orig != si->nh_valid)
70 reinstall = true;
71 }
72 if (reinstall)
73 static_zebra_route_add(rn, vrf_id, SAFI_UNICAST, true);
74 }
75 }