]> git.proxmox.com Git - mirror_frr.git/blame - pimd/pim_instance.c
Merge pull request #7669 from ranjanyash54/2370
[mirror_frr.git] / pimd / pim_instance.c
CommitLineData
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"
3613d898 25#include "lib_errors.h"
c2cf4b02
DS
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"
4e0bc0f0
DS
32#include "pim_oil.h"
33#include "pim_static.h"
71ad9915 34#include "pim_ssmpingd.h"
9ecb7b77 35#include "pim_vty.h"
361b5843 36#include "pim_bsm.h"
36b5b98f 37#include "pim_mlag.h"
c2cf4b02
DS
38
39static void pim_instance_terminate(struct pim_instance *pim)
40{
b21e0c93
AK
41 pim_vxlan_exit(pim);
42
c2cf4b02
DS
43 if (pim->ssm_info) {
44 pim_ssm_terminate(pim->ssm_info);
45 pim->ssm_info = NULL;
46 }
47
4e0bc0f0 48 if (pim->static_routes)
6a154c88 49 list_delete(&pim->static_routes);
4e0bc0f0 50
36b5b98f
SK
51 pim_instance_mlag_terminate(pim);
52
9b29ea95
DS
53 pim_upstream_terminate(pim);
54
1d483838
DS
55 pim_rp_free(pim);
56
361b5843 57 pim_bsm_proc_free(pim);
58
48d331e7
DS
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
f88df3a6
DS
66 pim_if_terminate(pim);
67
e2c4bc88
DS
68 pim_oil_terminate(pim);
69
2ad78035
DS
70 pim_msdp_exit(pim);
71
1c4e26bc 72 XFREE(MTYPE_PIM_PLIST_NAME, pim->spt.plist);
f4e74bd0 73 XFREE(MTYPE_PIM_PLIST_NAME, pim->register_plist);
7f1d002a 74 XFREE(MTYPE_PIM_PIM_INSTANCE, pim);
c2cf4b02
DS
75}
76
77static struct pim_instance *pim_instance_init(struct vrf *vrf)
78{
79 struct pim_instance *pim;
9fb302f4 80 char hash_name[64];
c2cf4b02
DS
81
82 pim = XCALLOC(MTYPE_PIM_PIM_INSTANCE, sizeof(struct pim_instance));
c2cf4b02 83
f88df3a6
DS
84 pim_if_init(pim);
85
ccf696e8 86 pim->mcast_if_count = 0;
19b807ca
DS
87 pim->keep_alive_time = PIM_KEEPALIVE_PERIOD;
88 pim->rp_keep_alive_time = PIM_RP_KEEPALIVE_PERIOD;
89
4795fff7
DS
90 pim->ecmp_enable = false;
91 pim->ecmp_rebalance_enable = false;
19b807ca 92
c2cf4b02
DS
93 pim->vrf_id = vrf->vrf_id;
94 pim->vrf = vrf;
95
96 pim->spt.switchover = PIM_SPT_IMMEDIATE;
97 pim->spt.plist = NULL;
98
36417fcc 99 pim_msdp_init(pim, router->master);
b583b035 100 pim_vxlan_init(pim);
2ad78035 101
772270f3 102 snprintf(hash_name, sizeof(hash_name), "PIM %s RPF Hash", vrf->name);
996c9314
LB
103 pim->rpf_hash = hash_create_size(256, pim_rpf_hash_key, pim_rpf_equal,
104 hash_name);
c2cf4b02
DS
105
106 if (PIM_DEBUG_ZEBRA)
15569c58 107 zlog_debug("%s: NHT rpf hash init ", __func__);
c2cf4b02
DS
108
109 pim->ssm_info = pim_ssm_init();
c2cf4b02 110
4e0bc0f0 111 pim->static_routes = list_new();
4e0bc0f0
DS
112 pim->static_routes->del = (void (*)(void *))pim_static_route_free;
113
c2cf4b02
DS
114 pim->send_v6_secondary = 1;
115
d9c9a9ee
DS
116 pim_rp_init(pim);
117
361b5843 118 pim_bsm_proc_init(pim);
119
611925dc
DS
120 pim_oil_init(pim);
121
9b29ea95 122 pim_upstream_init(pim);
d9c9a9ee 123
36b5b98f
SK
124 pim_instance_mlag_init(pim);
125
bfc92019 126 pim->last_route_change_time = -1;
c2cf4b02
DS
127 return pim;
128}
129
130struct pim_instance *pim_get_pim_instance(vrf_id_t vrf_id)
131{
132 struct vrf *vrf = vrf_lookup_by_id(vrf_id);
133
134 if (vrf)
135 return vrf->info;
136
137 return NULL;
138}
139
140static int pim_vrf_new(struct vrf *vrf)
141{
6d3c1953 142 struct pim_instance *pim = pim_instance_init(vrf);
71ad9915 143
87ad28f4 144 zlog_debug("VRF Created: %s(%u)", vrf->name, vrf->vrf_id);
6d3c1953
DS
145
146 vrf->info = (void *)pim;
147
71ad9915 148 pim_ssmpingd_init(pim);
c2cf4b02
DS
149 return 0;
150}
151
152static int pim_vrf_delete(struct vrf *vrf)
153{
71ad9915
DS
154 struct pim_instance *pim = vrf->info;
155
87ad28f4 156 zlog_debug("VRF Deletion: %s(%u)", vrf->name, vrf->vrf_id);
71ad9915
DS
157
158 pim_ssmpingd_destroy(pim);
7f1d002a 159 pim_instance_terminate(pim);
c2cf4b02
DS
160 return 0;
161}
162
b4575b3a
DS
163/*
164 * Code to turn on the pim instance that
165 * we have created with new
166 */
c2cf4b02
DS
167static int pim_vrf_enable(struct vrf *vrf)
168{
b4575b3a 169 struct pim_instance *pim = (struct pim_instance *)vrf->info;
c2cf4b02 170
15569c58 171 zlog_debug("%s: for %s", __func__, vrf->name);
c2cf4b02 172
b4575b3a 173 pim_mroute_socket_enable(pim);
c2cf4b02
DS
174
175 return 0;
176}
177
178static int pim_vrf_disable(struct vrf *vrf)
179{
c2cf4b02
DS
180 /* Note: This is a callback, the VRF will be deleted by the caller. */
181 return 0;
182}
183
a01538df
DS
184static int pim_vrf_config_write(struct vty *vty)
185{
186 struct vrf *vrf;
187 struct pim_instance *pim;
188
a2addae8 189 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
a01538df 190 pim = vrf->info;
e691f179
DS
191
192 if (!pim)
193 continue;
194
57dac17c
DS
195 if (vrf->vrf_id != VRF_DEFAULT)
196 vty_frame(vty, "vrf %s\n", vrf->name);
e691f179 197
e691f179 198 pim_global_config_write_worker(pim, vty);
57dac17c
DS
199
200 if (vrf->vrf_id != VRF_DEFAULT)
e8be380a 201 vty_endframe(vty, " exit-vrf\n!\n");
a01538df
DS
202 }
203
204 return 0;
205}
206
c2cf4b02
DS
207void pim_vrf_init(void)
208{
ecbc5a37
PG
209 vrf_init(pim_vrf_new, pim_vrf_enable, pim_vrf_disable,
210 pim_vrf_delete, NULL);
a01538df 211
3bc34908 212 vrf_cmd_init(pim_vrf_config_write, &pimd_privs);
c2cf4b02
DS
213}
214
215void pim_vrf_terminate(void)
216{
217 vrf_terminate();
218}