]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_instance.c
pim6d: fix "show ipv6 mld interface" command
[mirror_frr.git] / pimd / pim_instance.c
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 #include "lib_errors.h"
26
27 #include "pimd.h"
28 #include "pim_instance.h"
29 #include "pim_ssm.h"
30 #include "pim_rpf.h"
31 #include "pim_rp.h"
32 #include "pim_mroute.h"
33 #include "pim_oil.h"
34 #include "pim_static.h"
35 #include "pim_ssmpingd.h"
36 #include "pim_vty.h"
37 #include "pim_bsm.h"
38 #include "pim_mlag.h"
39 #include "pim_sock.h"
40
41 static void pim_instance_terminate(struct pim_instance *pim)
42 {
43 pim_vxlan_exit(pim);
44
45 if (pim->ssm_info) {
46 pim_ssm_terminate(pim->ssm_info);
47 pim->ssm_info = NULL;
48 }
49
50 if (pim->static_routes)
51 list_delete(&pim->static_routes);
52
53 pim_instance_mlag_terminate(pim);
54
55 pim_upstream_terminate(pim);
56
57 pim_rp_free(pim);
58
59 pim_bsm_proc_free(pim);
60
61 /* Traverse and cleanup rpf_hash */
62 if (pim->rpf_hash) {
63 hash_clean(pim->rpf_hash, (void *)pim_rp_list_hash_clean);
64 hash_free(pim->rpf_hash);
65 pim->rpf_hash = NULL;
66 }
67
68 pim_if_terminate(pim);
69
70 pim_oil_terminate(pim);
71
72 pim_msdp_exit(pim);
73
74 close(pim->reg_sock);
75
76 pim_mroute_socket_disable(pim);
77
78 XFREE(MTYPE_PIM_PLIST_NAME, pim->spt.plist);
79 XFREE(MTYPE_PIM_PLIST_NAME, pim->register_plist);
80
81 pim->vrf = NULL;
82 XFREE(MTYPE_PIM_PIM_INSTANCE, pim);
83 }
84
85 static struct pim_instance *pim_instance_init(struct vrf *vrf)
86 {
87 struct pim_instance *pim;
88 char hash_name[64];
89
90 pim = XCALLOC(MTYPE_PIM_PIM_INSTANCE, sizeof(struct pim_instance));
91
92 pim_if_init(pim);
93
94 pim->mcast_if_count = 0;
95 pim->keep_alive_time = PIM_KEEPALIVE_PERIOD;
96 pim->rp_keep_alive_time = PIM_RP_KEEPALIVE_PERIOD;
97
98 pim->ecmp_enable = false;
99 pim->ecmp_rebalance_enable = false;
100
101 pim->vrf = vrf;
102
103 pim->spt.switchover = PIM_SPT_IMMEDIATE;
104 pim->spt.plist = NULL;
105
106 pim_msdp_init(pim, router->master);
107 pim_vxlan_init(pim);
108
109 snprintf(hash_name, sizeof(hash_name), "PIM %s RPF Hash", vrf->name);
110 pim->rpf_hash = hash_create_size(256, pim_rpf_hash_key, pim_rpf_equal,
111 hash_name);
112
113 if (PIM_DEBUG_ZEBRA)
114 zlog_debug("%s: NHT rpf hash init ", __func__);
115
116 pim->ssm_info = pim_ssm_init();
117
118 pim->static_routes = list_new();
119 pim->static_routes->del = (void (*)(void *))pim_static_route_free;
120
121 pim->send_v6_secondary = 1;
122
123 pim->gm_socket = -1;
124
125 pim_rp_init(pim);
126
127 pim_bsm_proc_init(pim);
128
129 pim_oil_init(pim);
130
131 pim_upstream_init(pim);
132
133 pim_instance_mlag_init(pim);
134
135 pim->last_route_change_time = -1;
136
137 pim->reg_sock = pim_reg_sock();
138 if (pim->reg_sock < 0)
139 assert(0);
140
141 /* MSDP global timer defaults. */
142 pim->msdp.hold_time = PIM_MSDP_PEER_HOLD_TIME;
143 pim->msdp.keep_alive = PIM_MSDP_PEER_KA_TIME;
144 pim->msdp.connection_retry = PIM_MSDP_PEER_CONNECT_RETRY_TIME;
145
146 return pim;
147 }
148
149 struct pim_instance *pim_get_pim_instance(vrf_id_t vrf_id)
150 {
151 struct vrf *vrf = vrf_lookup_by_id(vrf_id);
152
153 if (vrf)
154 return vrf->info;
155
156 return NULL;
157 }
158
159 static int pim_vrf_new(struct vrf *vrf)
160 {
161 struct pim_instance *pim = pim_instance_init(vrf);
162
163 zlog_debug("VRF Created: %s(%u)", vrf->name, vrf->vrf_id);
164
165 vrf->info = (void *)pim;
166
167 pim_ssmpingd_init(pim);
168 return 0;
169 }
170
171 static int pim_vrf_delete(struct vrf *vrf)
172 {
173 struct pim_instance *pim = vrf->info;
174
175 if (!pim)
176 return 0;
177
178 zlog_debug("VRF Deletion: %s(%u)", vrf->name, vrf->vrf_id);
179
180 pim_ssmpingd_destroy(pim);
181 pim_instance_terminate(pim);
182
183 vrf->info = NULL;
184
185 return 0;
186 }
187
188 /*
189 * Code to turn on the pim instance that
190 * we have created with new
191 */
192 static int pim_vrf_enable(struct vrf *vrf)
193 {
194 struct pim_instance *pim = (struct pim_instance *)vrf->info;
195 struct interface *ifp;
196
197 zlog_debug("%s: for %s %u", __func__, vrf->name, vrf->vrf_id);
198
199 FOR_ALL_INTERFACES (vrf, ifp) {
200 if (!ifp->info)
201 continue;
202
203 pim_if_create_pimreg(pim);
204 break;
205 }
206
207 pim_mroute_socket_enable(pim);
208
209 return 0;
210 }
211
212 static int pim_vrf_disable(struct vrf *vrf)
213 {
214 /* Note: This is a callback, the VRF will be deleted by the caller. */
215 return 0;
216 }
217
218 static int pim_vrf_config_write(struct vty *vty)
219 {
220 struct vrf *vrf;
221 struct pim_instance *pim;
222
223 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
224 pim = vrf->info;
225
226 if (!pim)
227 continue;
228
229 if (vrf->vrf_id != VRF_DEFAULT)
230 vty_frame(vty, "vrf %s\n", vrf->name);
231
232 pim_global_config_write_worker(pim, vty);
233
234 if (vrf->vrf_id != VRF_DEFAULT)
235 vty_endframe(vty, "exit-vrf\n!\n");
236 }
237
238 return 0;
239 }
240
241 void pim_vrf_init(void)
242 {
243 vrf_init(pim_vrf_new, pim_vrf_enable, pim_vrf_disable, pim_vrf_delete);
244
245 vrf_cmd_init(pim_vrf_config_write);
246 }
247
248 void pim_vrf_terminate(void)
249 {
250 struct vrf *vrf;
251
252 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
253 struct pim_instance *pim;
254
255 pim = vrf->info;
256 if (!pim)
257 continue;
258
259 pim_ssmpingd_destroy(pim);
260 pim_instance_terminate(pim);
261
262 vrf->info = NULL;
263 }
264
265 vrf_terminate();
266 }