]> git.proxmox.com Git - mirror_frr.git/blob - staticd/static_nht.c
staticd: Fix static_nht_update to actually know route we are installing
[mirror_frr.git] / staticd / static_nht.c
1 /*
2 * Static NHT code.
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Donald Sharp
5 *
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.
10 *
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.
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 #include "srcdest_table.h"
27
28 #include "static_vrf.h"
29 #include "static_routes.h"
30 #include "static_zebra.h"
31 #include "static_nht.h"
32
33 static void static_nht_update_rn(struct route_node *rn,
34 struct prefix *nhp, uint32_t nh_num,
35 vrf_id_t nh_vrf_id, struct vrf *vrf,
36 safi_t safi)
37 {
38 struct static_route *si;
39
40 for (si = rn->info; si; si = si->next) {
41 if (si->nh_vrf_id != nh_vrf_id)
42 continue;
43
44 if (si->type != STATIC_IPV4_GATEWAY
45 && si->type != STATIC_IPV4_GATEWAY_IFNAME
46 && si->type != STATIC_IPV6_GATEWAY
47 && si->type != STATIC_IPV6_GATEWAY_IFNAME)
48 continue;
49
50 if (nhp->family == AF_INET
51 && nhp->u.prefix4.s_addr == si->addr.ipv4.s_addr)
52 si->nh_valid = !!nh_num;
53
54 if (nhp->family == AF_INET6
55 && memcmp(&nhp->u.prefix6, &si->addr.ipv6, 16) == 0)
56 si->nh_valid = !!nh_num;
57
58 static_zebra_route_add(rn, si, vrf->vrf_id, safi, true);
59 }
60 }
61
62 static void static_nht_update_safi(struct prefix *sp, struct prefix *nhp,
63 uint32_t nh_num, afi_t afi, safi_t safi,
64 struct vrf *vrf, vrf_id_t nh_vrf_id)
65 {
66 struct route_table *stable;
67 struct static_vrf *svrf;
68 struct route_node *rn;
69
70 svrf = vrf->info;
71 if (!svrf)
72 return;
73
74 stable = static_vrf_static_table(afi, safi, svrf);
75 if (!stable)
76 return;
77
78 if (sp) {
79 rn = srcdest_rnode_lookup(stable, sp, NULL);
80 if (rn) {
81 static_nht_update_rn(rn, nhp, nh_num, nh_vrf_id,
82 vrf, safi);
83 route_unlock_node(rn);
84 }
85 return;
86 }
87
88 for (rn = route_top(stable); rn; rn = route_next(rn))
89 static_nht_update_rn(rn, nhp, nh_num, nh_vrf_id, vrf, safi);
90
91 }
92
93 void static_nht_update(struct prefix *sp, struct prefix *nhp,
94 uint32_t nh_num, afi_t afi, vrf_id_t nh_vrf_id)
95 {
96
97 struct vrf *vrf;
98
99 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
100 static_nht_update_safi(sp, nhp, nh_num, afi, SAFI_UNICAST,
101 vrf, nh_vrf_id);
102 static_nht_update_safi(sp, nhp, nh_num, afi, SAFI_MULTICAST,
103 vrf, nh_vrf_id);
104 }
105 }