]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_instance.c
Merge pull request #5288 from SumitAgarwal123/bfd_docs
[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_ssm.h"
29 #include "pim_rpf.h"
30 #include "pim_rp.h"
31 #include "pim_mroute.h"
32 #include "pim_oil.h"
33 #include "pim_static.h"
34 #include "pim_ssmpingd.h"
35 #include "pim_vty.h"
36 #include "pim_bsm.h"
37 #include "pim_mlag.h"
38
39 static void pim_instance_terminate(struct pim_instance *pim)
40 {
41 pim_vxlan_exit(pim);
42
43 if (pim->ssm_info) {
44 pim_ssm_terminate(pim->ssm_info);
45 pim->ssm_info = NULL;
46 }
47
48 if (pim->static_routes)
49 list_delete(&pim->static_routes);
50
51 pim_instance_mlag_terminate(pim);
52
53 pim_upstream_terminate(pim);
54
55 pim_rp_free(pim);
56
57 pim_bsm_proc_free(pim);
58
59 /* Traverse and cleanup rpf_hash */
60 if (pim->rpf_hash) {
61 hash_clean(pim->rpf_hash, (void *)pim_rp_list_hash_clean);
62 hash_free(pim->rpf_hash);
63 pim->rpf_hash = NULL;
64 }
65
66 pim_if_terminate(pim);
67
68 pim_oil_terminate(pim);
69
70 pim_msdp_exit(pim);
71
72 XFREE(MTYPE_PIM_PIM_INSTANCE, pim);
73 }
74
75 static struct pim_instance *pim_instance_init(struct vrf *vrf)
76 {
77 struct pim_instance *pim;
78 char hash_name[64];
79
80 pim = XCALLOC(MTYPE_PIM_PIM_INSTANCE, sizeof(struct pim_instance));
81
82 pim_if_init(pim);
83
84 pim->keep_alive_time = PIM_KEEPALIVE_PERIOD;
85 pim->rp_keep_alive_time = PIM_RP_KEEPALIVE_PERIOD;
86
87 pim->ecmp_enable = false;
88 pim->ecmp_rebalance_enable = false;
89
90 pim->vrf_id = vrf->vrf_id;
91 pim->vrf = vrf;
92
93 pim->spt.switchover = PIM_SPT_IMMEDIATE;
94 pim->spt.plist = NULL;
95
96 pim_msdp_init(pim, router->master);
97 pim_vxlan_init(pim);
98
99 snprintf(hash_name, 64, "PIM %s RPF Hash", vrf->name);
100 pim->rpf_hash = hash_create_size(256, pim_rpf_hash_key, pim_rpf_equal,
101 hash_name);
102
103 if (PIM_DEBUG_ZEBRA)
104 zlog_debug("%s: NHT rpf hash init ", __PRETTY_FUNCTION__);
105
106 pim->ssm_info = pim_ssm_init();
107
108 pim->static_routes = list_new();
109 pim->static_routes->del = (void (*)(void *))pim_static_route_free;
110
111 pim->send_v6_secondary = 1;
112
113 pim_rp_init(pim);
114
115 pim_bsm_proc_init(pim);
116
117 pim_oil_init(pim);
118
119 pim_upstream_init(pim);
120
121 pim_instance_mlag_init(pim);
122
123 pim->last_route_change_time = -1;
124 return pim;
125 }
126
127 struct pim_instance *pim_get_pim_instance(vrf_id_t vrf_id)
128 {
129 struct vrf *vrf = vrf_lookup_by_id(vrf_id);
130
131 if (vrf)
132 return vrf->info;
133
134 return NULL;
135 }
136
137 static int pim_vrf_new(struct vrf *vrf)
138 {
139 struct pim_instance *pim = pim_instance_init(vrf);
140
141 zlog_debug("VRF Created: %s(%u)", vrf->name, vrf->vrf_id);
142
143 vrf->info = (void *)pim;
144
145 pim_ssmpingd_init(pim);
146 return 0;
147 }
148
149 static int pim_vrf_delete(struct vrf *vrf)
150 {
151 struct pim_instance *pim = vrf->info;
152
153 zlog_debug("VRF Deletion: %s(%u)", vrf->name, vrf->vrf_id);
154
155 pim_ssmpingd_destroy(pim);
156 pim_instance_terminate(pim);
157 return 0;
158 }
159
160 /*
161 * Code to turn on the pim instance that
162 * we have created with new
163 */
164 static int pim_vrf_enable(struct vrf *vrf)
165 {
166 struct pim_instance *pim = (struct pim_instance *)vrf->info;
167
168 zlog_debug("%s: for %s", __PRETTY_FUNCTION__, vrf->name);
169
170 pim_mroute_socket_enable(pim);
171
172 return 0;
173 }
174
175 static int pim_vrf_disable(struct vrf *vrf)
176 {
177 /* Note: This is a callback, the VRF will be deleted by the caller. */
178 return 0;
179 }
180
181 static int pim_vrf_config_write(struct vty *vty)
182 {
183 struct vrf *vrf;
184 struct pim_instance *pim;
185
186 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
187 pim = vrf->info;
188
189 if (!pim)
190 continue;
191
192 if (vrf->vrf_id != VRF_DEFAULT)
193 vty_frame(vty, "vrf %s\n", vrf->name);
194
195 pim_global_config_write_worker(pim, vty);
196
197 if (vrf->vrf_id != VRF_DEFAULT)
198 vty_endframe(vty, " exit-vrf\n!\n");
199 }
200
201 return 0;
202 }
203
204 void pim_vrf_init(void)
205 {
206 vrf_init(pim_vrf_new, pim_vrf_enable, pim_vrf_disable,
207 pim_vrf_delete, NULL);
208
209 vrf_cmd_init(pim_vrf_config_write, &pimd_privs);
210 }
211
212 void pim_vrf_terminate(void)
213 {
214 vrf_terminate();
215 }