1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * PIM for FRR - PIM Instance
4 * Copyright (C) 2017 Cumulus Networks, Inc.
11 #include "lib_errors.h"
14 #include "pim_instance.h"
18 #include "pim_mroute.h"
20 #include "pim_static.h"
21 #include "pim_ssmpingd.h"
27 static void pim_instance_terminate(struct pim_instance
*pim
)
32 pim_ssm_terminate(pim
->ssm_info
);
36 if (pim
->static_routes
)
37 list_delete(&pim
->static_routes
);
39 pim_instance_mlag_terminate(pim
);
41 pim_upstream_terminate(pim
);
45 pim_bsm_proc_free(pim
);
47 /* Traverse and cleanup rpf_hash */
48 hash_clean_and_free(&pim
->rpf_hash
, (void *)pim_rp_list_hash_clean
);
50 pim_if_terminate(pim
);
52 pim_oil_terminate(pim
);
58 pim_mroute_socket_disable(pim
);
60 XFREE(MTYPE_PIM_PLIST_NAME
, pim
->spt
.plist
);
61 XFREE(MTYPE_PIM_PLIST_NAME
, pim
->register_plist
);
64 XFREE(MTYPE_PIM_PIM_INSTANCE
, pim
);
67 static struct pim_instance
*pim_instance_init(struct vrf
*vrf
)
69 struct pim_instance
*pim
;
72 pim
= XCALLOC(MTYPE_PIM_PIM_INSTANCE
, sizeof(struct pim_instance
));
76 pim
->mcast_if_count
= 0;
77 pim
->keep_alive_time
= PIM_KEEPALIVE_PERIOD
;
78 pim
->rp_keep_alive_time
= PIM_RP_KEEPALIVE_PERIOD
;
80 pim
->ecmp_enable
= false;
81 pim
->ecmp_rebalance_enable
= false;
85 pim
->spt
.switchover
= PIM_SPT_IMMEDIATE
;
86 pim
->spt
.plist
= NULL
;
88 pim_msdp_init(pim
, router
->master
);
91 snprintf(hash_name
, sizeof(hash_name
), "PIM %s RPF Hash", vrf
->name
);
92 pim
->rpf_hash
= hash_create_size(256, pim_rpf_hash_key
, pim_rpf_equal
,
96 zlog_debug("%s: NHT rpf hash init ", __func__
);
98 pim
->ssm_info
= pim_ssm_init();
100 pim
->static_routes
= list_new();
101 pim
->static_routes
->del
= (void (*)(void *))pim_static_route_free
;
103 pim
->send_v6_secondary
= 1;
109 pim_bsm_proc_init(pim
);
113 pim_upstream_init(pim
);
115 pim_instance_mlag_init(pim
);
117 pim
->last_route_change_time
= -1;
119 pim
->reg_sock
= pim_reg_sock();
120 if (pim
->reg_sock
< 0)
123 /* MSDP global timer defaults. */
124 pim
->msdp
.hold_time
= PIM_MSDP_PEER_HOLD_TIME
;
125 pim
->msdp
.keep_alive
= PIM_MSDP_PEER_KA_TIME
;
126 pim
->msdp
.connection_retry
= PIM_MSDP_PEER_CONNECT_RETRY_TIME
;
131 struct pim_instance
*pim_get_pim_instance(vrf_id_t vrf_id
)
133 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
141 static int pim_vrf_new(struct vrf
*vrf
)
143 struct pim_instance
*pim
= pim_instance_init(vrf
);
145 zlog_debug("VRF Created: %s(%u)", vrf
->name
, vrf
->vrf_id
);
147 vrf
->info
= (void *)pim
;
149 pim_ssmpingd_init(pim
);
153 static int pim_vrf_delete(struct vrf
*vrf
)
155 struct pim_instance
*pim
= vrf
->info
;
160 zlog_debug("VRF Deletion: %s(%u)", vrf
->name
, vrf
->vrf_id
);
162 pim_ssmpingd_destroy(pim
);
163 pim_instance_terminate(pim
);
171 * Code to turn on the pim instance that
172 * we have created with new
174 static int pim_vrf_enable(struct vrf
*vrf
)
176 struct pim_instance
*pim
= (struct pim_instance
*)vrf
->info
;
177 struct interface
*ifp
;
179 zlog_debug("%s: for %s %u", __func__
, vrf
->name
, vrf
->vrf_id
);
181 FOR_ALL_INTERFACES (vrf
, ifp
) {
185 pim_if_create_pimreg(pim
);
189 pim_mroute_socket_enable(pim
);
194 static int pim_vrf_disable(struct vrf
*vrf
)
196 /* Note: This is a callback, the VRF will be deleted by the caller. */
200 static int pim_vrf_config_write(struct vty
*vty
)
203 struct pim_instance
*pim
;
205 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
211 if (vrf
->vrf_id
!= VRF_DEFAULT
)
212 vty_frame(vty
, "vrf %s\n", vrf
->name
);
214 pim_global_config_write_worker(pim
, vty
);
216 if (vrf
->vrf_id
!= VRF_DEFAULT
)
217 vty_endframe(vty
, "exit-vrf\n!\n");
223 void pim_vrf_init(void)
225 vrf_init(pim_vrf_new
, pim_vrf_enable
, pim_vrf_disable
, pim_vrf_delete
);
227 vrf_cmd_init(pim_vrf_config_write
);
230 void pim_vrf_terminate(void)
234 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
235 struct pim_instance
*pim
;
241 pim_ssmpingd_destroy(pim
);
242 pim_instance_terminate(pim
);