]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
7e24fdf3 DS |
2 | /* |
3 | * STATICd - vrf code | |
4 | * Copyright (C) 2018 Cumulus Networks, Inc. | |
5 | * Donald Sharp | |
7e24fdf3 DS |
6 | */ |
7 | #include <zebra.h> | |
8 | ||
9 | #include "vrf.h" | |
10 | #include "nexthop.h" | |
11 | #include "table.h" | |
12 | #include "srcdest_table.h" | |
6cc73dad | 13 | #include "northbound_cli.h" |
7e24fdf3 | 14 | |
7e24fdf3 DS |
15 | #include "static_vrf.h" |
16 | #include "static_routes.h" | |
fceb6174 | 17 | #include "static_zebra.h" |
7e24fdf3 | 18 | |
88fa5104 | 19 | DEFINE_MTYPE_STATIC(STATIC, STATIC_RTABLE_INFO, "Static Route Table Info"); |
20 | ||
7e24fdf3 DS |
21 | static struct static_vrf *static_vrf_alloc(void) |
22 | { | |
23 | struct route_table *table; | |
24 | struct static_vrf *svrf; | |
88fa5104 | 25 | struct stable_info *info; |
7e24fdf3 DS |
26 | safi_t safi; |
27 | afi_t afi; | |
28 | ||
88fa5104 | 29 | svrf = XCALLOC(MTYPE_STATIC_RTABLE_INFO, sizeof(struct static_vrf)); |
7e24fdf3 DS |
30 | |
31 | for (afi = AFI_IP; afi <= AFI_IP6; afi++) { | |
32 | for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++) { | |
33 | if (afi == AFI_IP6) | |
34 | table = srcdest_table_init(); | |
35 | else | |
36 | table = route_table_init(); | |
88fa5104 | 37 | |
38 | info = XCALLOC(MTYPE_STATIC_RTABLE_INFO, | |
39 | sizeof(struct stable_info)); | |
40 | info->svrf = svrf; | |
41 | info->afi = afi; | |
42 | info->safi = safi; | |
43 | route_table_set_info(table, info); | |
44 | ||
7e24fdf3 DS |
45 | table->cleanup = zebra_stable_node_cleanup; |
46 | svrf->stable[afi][safi] = table; | |
47 | } | |
48 | } | |
49 | return svrf; | |
50 | } | |
51 | ||
52 | static int static_vrf_new(struct vrf *vrf) | |
53 | { | |
54 | struct static_vrf *svrf; | |
55 | ||
56 | svrf = static_vrf_alloc(); | |
57 | vrf->info = svrf; | |
58 | svrf->vrf = vrf; | |
59 | ||
60 | return 0; | |
61 | } | |
62 | ||
63 | static int static_vrf_enable(struct vrf *vrf) | |
64 | { | |
fceb6174 PG |
65 | static_zebra_vrf_register(vrf); |
66 | ||
7e24fdf3 DS |
67 | static_fixup_vrf_ids(vrf->info); |
68 | ||
7e24fdf3 DS |
69 | return 0; |
70 | } | |
71 | ||
72 | static int static_vrf_disable(struct vrf *vrf) | |
73 | { | |
fceb6174 | 74 | static_zebra_vrf_unregister(vrf); |
7e24fdf3 DS |
75 | return 0; |
76 | } | |
77 | ||
78 | static int static_vrf_delete(struct vrf *vrf) | |
79 | { | |
80 | struct route_table *table; | |
81 | struct static_vrf *svrf; | |
82 | safi_t safi; | |
83 | afi_t afi; | |
88fa5104 | 84 | void *info; |
7e24fdf3 DS |
85 | |
86 | svrf = vrf->info; | |
87 | for (afi = AFI_IP; afi <= AFI_IP6; afi++) { | |
88 | for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++) { | |
89 | table = svrf->stable[afi][safi]; | |
88fa5104 | 90 | info = route_table_get_info(table); |
7e24fdf3 | 91 | route_table_finish(table); |
88fa5104 | 92 | XFREE(MTYPE_STATIC_RTABLE_INFO, info); |
7e24fdf3 DS |
93 | svrf->stable[afi][safi] = NULL; |
94 | } | |
95 | } | |
88fa5104 | 96 | XFREE(MTYPE_STATIC_RTABLE_INFO, svrf); |
7e24fdf3 DS |
97 | return 0; |
98 | } | |
99 | ||
100 | /* Lookup the static routing table in a VRF. */ | |
101 | struct route_table *static_vrf_static_table(afi_t afi, safi_t safi, | |
102 | struct static_vrf *svrf) | |
103 | { | |
104 | if (!svrf) | |
105 | return NULL; | |
106 | ||
107 | if (afi >= AFI_MAX || safi >= SAFI_MAX) | |
108 | return NULL; | |
109 | ||
110 | return svrf->stable[afi][safi]; | |
111 | } | |
112 | ||
7e24fdf3 DS |
113 | struct static_vrf *static_vrf_lookup_by_name(const char *name) |
114 | { | |
115 | struct vrf *vrf; | |
116 | ||
117 | if (!name) | |
118 | name = VRF_DEFAULT_NAME; | |
119 | ||
120 | vrf = vrf_lookup_by_name(name); | |
121 | if (vrf) | |
122 | return ((struct static_vrf *)vrf->info); | |
123 | ||
124 | return NULL; | |
125 | } | |
126 | ||
127 | static int static_vrf_config_write(struct vty *vty) | |
128 | { | |
6cc73dad IR |
129 | struct lyd_node *dnode; |
130 | int written = 0; | |
0e20f68b | 131 | |
6cc73dad IR |
132 | dnode = yang_dnode_get(running_config->dnode, "/frr-routing:routing"); |
133 | if (dnode) { | |
134 | nb_cli_show_dnode_cmds(vty, dnode, false); | |
135 | written = 1; | |
7e24fdf3 DS |
136 | } |
137 | ||
6cc73dad | 138 | return written; |
7e24fdf3 DS |
139 | } |
140 | ||
7e24fdf3 DS |
141 | void static_vrf_init(void) |
142 | { | |
ac2cb9bf IR |
143 | vrf_init(static_vrf_new, static_vrf_enable, static_vrf_disable, |
144 | static_vrf_delete); | |
7e24fdf3 | 145 | |
cfc369c4 | 146 | vrf_cmd_init(static_vrf_config_write); |
7e24fdf3 | 147 | } |
a4155a1b | 148 | |
149 | void static_vrf_terminate(void) | |
150 | { | |
151 | vrf_terminate(); | |
152 | } |