]>
Commit | Line | Data |
---|---|---|
c2cf4b02 DS |
1 | /* |
2 | * PIM for FRR - PIM Instance | |
3 | * Copyright (C) 2017 Cumulus Networks, Inc. | |
4 | * Donald Sharp | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program 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 | |
17 | * along with this program; see the file COPYING; if not, write to the | |
18 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, | |
19 | * MA 02110-1301 USA | |
20 | */ | |
21 | #include <zebra.h> | |
22 | ||
23 | #include "hash.h" | |
24 | #include "vrf.h" | |
25 | ||
26 | #include "pimd.h" | |
27 | #include "pim_ssm.h" | |
28 | #include "pim_rpf.h" | |
29 | #include "pim_rp.h" | |
30 | #include "pim_mroute.h" | |
4e0bc0f0 DS |
31 | #include "pim_oil.h" |
32 | #include "pim_static.h" | |
71ad9915 | 33 | #include "pim_ssmpingd.h" |
9ecb7b77 | 34 | #include "pim_vty.h" |
c2cf4b02 DS |
35 | |
36 | static void pim_instance_terminate(struct pim_instance *pim) | |
37 | { | |
38 | /* Traverse and cleanup rpf_hash */ | |
39 | if (pim->rpf_hash) { | |
40 | hash_clean(pim->rpf_hash, (void *)pim_rp_list_hash_clean); | |
41 | hash_free(pim->rpf_hash); | |
42 | pim->rpf_hash = NULL; | |
43 | } | |
44 | ||
45 | if (pim->ssm_info) { | |
46 | pim_ssm_terminate(pim->ssm_info); | |
47 | pim->ssm_info = NULL; | |
48 | } | |
49 | ||
4e0bc0f0 | 50 | if (pim->static_routes) |
affe9e99 | 51 | list_delete_and_null(&pim->static_routes); |
4e0bc0f0 | 52 | |
d9c9a9ee DS |
53 | pim_rp_free(pim); |
54 | ||
9b29ea95 DS |
55 | pim_upstream_terminate(pim); |
56 | ||
611925dc DS |
57 | pim_oil_terminate(pim); |
58 | ||
f88df3a6 DS |
59 | pim_if_terminate(pim); |
60 | ||
2ad78035 DS |
61 | pim_msdp_exit(pim); |
62 | ||
7f1d002a | 63 | XFREE(MTYPE_PIM_PIM_INSTANCE, pim); |
c2cf4b02 DS |
64 | } |
65 | ||
66 | static struct pim_instance *pim_instance_init(struct vrf *vrf) | |
67 | { | |
68 | struct pim_instance *pim; | |
9fb302f4 | 69 | char hash_name[64]; |
c2cf4b02 DS |
70 | |
71 | pim = XCALLOC(MTYPE_PIM_PIM_INSTANCE, sizeof(struct pim_instance)); | |
72 | if (!pim) | |
73 | return NULL; | |
74 | ||
f88df3a6 DS |
75 | pim_if_init(pim); |
76 | ||
19b807ca DS |
77 | pim->keep_alive_time = PIM_KEEPALIVE_PERIOD; |
78 | pim->rp_keep_alive_time = PIM_RP_KEEPALIVE_PERIOD; | |
79 | ||
80 | ||
c2cf4b02 DS |
81 | pim->vrf_id = vrf->vrf_id; |
82 | pim->vrf = vrf; | |
83 | ||
84 | pim->spt.switchover = PIM_SPT_IMMEDIATE; | |
85 | pim->spt.plist = NULL; | |
86 | ||
64c86530 | 87 | pim_msdp_init(pim, master); |
2ad78035 | 88 | |
9fb302f4 DS |
89 | snprintf(hash_name, 64, "PIM %s RPF Hash", vrf->name); |
90 | pim->rpf_hash = hash_create_size(256, pim_rpf_hash_key, | |
91 | pim_rpf_equal, hash_name); | |
c2cf4b02 DS |
92 | |
93 | if (PIM_DEBUG_ZEBRA) | |
94 | zlog_debug("%s: NHT rpf hash init ", __PRETTY_FUNCTION__); | |
95 | ||
96 | pim->ssm_info = pim_ssm_init(); | |
97 | if (!pim->ssm_info) { | |
98 | pim_instance_terminate(pim); | |
99 | return NULL; | |
100 | } | |
101 | ||
4e0bc0f0 DS |
102 | pim->static_routes = list_new(); |
103 | if (!pim->static_routes) { | |
104 | zlog_err("%s %s: failure: static_routes=list_new()", __FILE__, | |
105 | __PRETTY_FUNCTION__); | |
106 | pim_instance_terminate(pim); | |
107 | return NULL; | |
108 | } | |
109 | pim->static_routes->del = (void (*)(void *))pim_static_route_free; | |
110 | ||
c2cf4b02 DS |
111 | pim->send_v6_secondary = 1; |
112 | ||
113 | if (vrf->vrf_id == VRF_DEFAULT) | |
114 | pimg = pim; | |
115 | ||
d9c9a9ee DS |
116 | pim_rp_init(pim); |
117 | ||
611925dc DS |
118 | pim_oil_init(pim); |
119 | ||
9b29ea95 | 120 | pim_upstream_init(pim); |
d9c9a9ee | 121 | |
c2cf4b02 DS |
122 | return pim; |
123 | } | |
124 | ||
125 | struct pim_instance *pim_get_pim_instance(vrf_id_t vrf_id) | |
126 | { | |
127 | struct vrf *vrf = vrf_lookup_by_id(vrf_id); | |
128 | ||
129 | if (vrf) | |
130 | return vrf->info; | |
131 | ||
132 | return NULL; | |
133 | } | |
134 | ||
135 | static int pim_vrf_new(struct vrf *vrf) | |
136 | { | |
6d3c1953 | 137 | struct pim_instance *pim = pim_instance_init(vrf); |
71ad9915 | 138 | |
c2cf4b02 | 139 | zlog_debug("VRF Created: %s(%d)", vrf->name, vrf->vrf_id); |
6d3c1953 DS |
140 | if (pim == NULL) { |
141 | zlog_err("%s %s: pim class init failure ", __FILE__, | |
142 | __PRETTY_FUNCTION__); | |
143 | /* | |
144 | * We will crash and burn otherwise | |
145 | */ | |
146 | exit(1); | |
147 | } | |
148 | ||
149 | vrf->info = (void *)pim; | |
150 | ||
151 | if (vrf->vrf_id == VRF_DEFAULT) | |
152 | pimg = pim; | |
71ad9915 DS |
153 | |
154 | pim_ssmpingd_init(pim); | |
c2cf4b02 DS |
155 | return 0; |
156 | } | |
157 | ||
158 | static int pim_vrf_delete(struct vrf *vrf) | |
159 | { | |
71ad9915 DS |
160 | struct pim_instance *pim = vrf->info; |
161 | ||
c2cf4b02 | 162 | zlog_debug("VRF Deletion: %s(%d)", vrf->name, vrf->vrf_id); |
71ad9915 DS |
163 | |
164 | pim_ssmpingd_destroy(pim); | |
7f1d002a | 165 | pim_instance_terminate(pim); |
c2cf4b02 DS |
166 | return 0; |
167 | } | |
168 | ||
b4575b3a DS |
169 | /* |
170 | * Code to turn on the pim instance that | |
171 | * we have created with new | |
172 | */ | |
c2cf4b02 DS |
173 | static int pim_vrf_enable(struct vrf *vrf) |
174 | { | |
b4575b3a | 175 | struct pim_instance *pim = (struct pim_instance *)vrf->info; |
c2cf4b02 DS |
176 | |
177 | zlog_debug("%s: for %s", __PRETTY_FUNCTION__, vrf->name); | |
c2cf4b02 | 178 | |
b4575b3a | 179 | pim_mroute_socket_enable(pim); |
c2cf4b02 DS |
180 | |
181 | return 0; | |
182 | } | |
183 | ||
184 | static int pim_vrf_disable(struct vrf *vrf) | |
185 | { | |
c2cf4b02 DS |
186 | /* Note: This is a callback, the VRF will be deleted by the caller. */ |
187 | return 0; | |
188 | } | |
189 | ||
a01538df DS |
190 | static int pim_vrf_config_write(struct vty *vty) |
191 | { | |
192 | struct vrf *vrf; | |
193 | struct pim_instance *pim; | |
194 | ||
a2addae8 | 195 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { |
a01538df | 196 | pim = vrf->info; |
e691f179 DS |
197 | |
198 | if (!pim) | |
199 | continue; | |
200 | ||
201 | if (vrf->vrf_id == VRF_DEFAULT) | |
202 | continue; | |
203 | ||
76260b35 | 204 | vty_frame(vty, "vrf %s\n", vrf->name); |
e691f179 | 205 | pim_global_config_write_worker(pim, vty); |
76260b35 | 206 | vty_endframe(vty, "!\n"); |
a01538df DS |
207 | } |
208 | ||
209 | return 0; | |
210 | } | |
211 | ||
c2cf4b02 DS |
212 | void pim_vrf_init(void) |
213 | { | |
214 | vrf_init(pim_vrf_new, pim_vrf_enable, pim_vrf_disable, pim_vrf_delete); | |
a01538df DS |
215 | |
216 | vrf_cmd_init(pim_vrf_config_write); | |
c2cf4b02 DS |
217 | } |
218 | ||
219 | void pim_vrf_terminate(void) | |
220 | { | |
221 | vrf_terminate(); | |
222 | } |