]>
Commit | Line | Data |
---|---|---|
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 | ||
f591b309 DS |
32 | void static_nht_update(struct prefix *p, uint32_t nh_num, afi_t afi, |
33 | vrf_id_t nh_vrf_id) | |
7e24fdf3 DS |
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 | ||
f591b309 DS |
43 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { |
44 | svrf = vrf->info; | |
45 | if (!svrf) | |
46 | continue; | |
7e24fdf3 | 47 | |
f591b309 DS |
48 | stable = static_vrf_static_table(afi, SAFI_UNICAST, svrf); |
49 | if (!stable) | |
50 | continue; | |
7e24fdf3 | 51 | |
f591b309 DS |
52 | for (rn = route_top(stable); rn; rn = route_next(rn)) { |
53 | reinstall = false; | |
54 | for (si = rn->info; si; si = si->next) { | |
55 | if (si->nh_vrf_id != nh_vrf_id) | |
56 | continue; | |
7e24fdf3 | 57 | |
f591b309 DS |
58 | if (si->type != STATIC_IPV4_GATEWAY |
59 | && si->type != STATIC_IPV4_GATEWAY_IFNAME | |
60 | && si->type != STATIC_IPV6_GATEWAY | |
61 | && si->type != STATIC_IPV6_GATEWAY_IFNAME) | |
62 | continue; | |
7e24fdf3 | 63 | |
f591b309 DS |
64 | orig = si->nh_valid; |
65 | if (p->family == AF_INET | |
66 | && p->u.prefix4.s_addr | |
67 | == si->addr.ipv4.s_addr) | |
68 | si->nh_valid = !!nh_num; | |
7e24fdf3 | 69 | |
f591b309 DS |
70 | if (p->family == AF_INET6 |
71 | && memcmp(&p->u.prefix6, &si->addr.ipv6, 16) | |
72 | == 0) | |
73 | si->nh_valid = !!nh_num; | |
7e24fdf3 | 74 | |
f591b309 DS |
75 | if (orig != si->nh_valid) |
76 | reinstall = true; | |
8bc8de2c | 77 | |
f591b309 DS |
78 | if (reinstall) { |
79 | static_zebra_route_add( | |
80 | rn, si, vrf->vrf_id, | |
81 | SAFI_UNICAST, true); | |
82 | reinstall = false; | |
83 | } | |
8bc8de2c | 84 | } |
7e24fdf3 | 85 | } |
7e24fdf3 DS |
86 | } |
87 | } |