3 * Copyright (C) 2018 Cumulus Networks, Inc.
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)
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
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
27 #include "static_vrf.h"
28 #include "static_routes.h"
29 #include "static_zebra.h"
30 #include "static_nht.h"
32 static void static_nht_update_safi(struct prefix
*p
, uint32_t nh_num
,
33 afi_t afi
, safi_t safi
, struct vrf
*vrf
,
36 struct route_table
*stable
;
37 struct static_route
*si
;
38 struct static_vrf
*svrf
;
39 struct route_node
*rn
;
45 stable
= static_vrf_static_table(afi
, safi
, svrf
);
49 for (rn
= route_top(stable
); rn
; rn
= route_next(rn
)) {
50 for (si
= rn
->info
; si
; si
= si
->next
) {
51 if (si
->nh_vrf_id
!= nh_vrf_id
)
54 if (si
->type
!= STATIC_IPV4_GATEWAY
55 && si
->type
!= STATIC_IPV4_GATEWAY_IFNAME
56 && si
->type
!= STATIC_IPV6_GATEWAY
57 && si
->type
!= STATIC_IPV6_GATEWAY_IFNAME
)
60 if (p
->family
== AF_INET
61 && p
->u
.prefix4
.s_addr
== si
->addr
.ipv4
.s_addr
)
62 si
->nh_valid
= !!nh_num
;
64 if (p
->family
== AF_INET6
65 && memcmp(&p
->u
.prefix6
, &si
->addr
.ipv6
, 16) == 0)
66 si
->nh_valid
= !!nh_num
;
68 static_zebra_route_add(rn
, si
, vrf
->vrf_id
, safi
, true);
73 void static_nht_update(struct prefix
*p
, uint32_t nh_num
, afi_t afi
,
79 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
80 static_nht_update_safi(p
, nh_num
, afi
, SAFI_UNICAST
,
82 static_nht_update_safi(p
, nh_num
, afi
, SAFI_MULTICAST
,