2 * PIM for FRR - PIM Instance
3 * Copyright (C) 2017 Cumulus Networks, Inc.
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.
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.
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,
25 #include "lib_errors.h"
28 #include "pim_instance.h"
32 #include "pim_mroute.h"
34 #include "pim_static.h"
35 #include "pim_ssmpingd.h"
41 static void pim_instance_terminate(struct pim_instance
*pim
)
46 pim_ssm_terminate(pim
->ssm_info
);
50 if (pim
->static_routes
)
51 list_delete(&pim
->static_routes
);
53 pim_instance_mlag_terminate(pim
);
55 pim_upstream_terminate(pim
);
59 pim_bsm_proc_free(pim
);
61 /* Traverse and cleanup rpf_hash */
63 hash_clean(pim
->rpf_hash
, (void *)pim_rp_list_hash_clean
);
64 hash_free(pim
->rpf_hash
);
68 pim_if_terminate(pim
);
70 pim_oil_terminate(pim
);
76 pim_mroute_socket_disable(pim
);
78 XFREE(MTYPE_PIM_PLIST_NAME
, pim
->spt
.plist
);
79 XFREE(MTYPE_PIM_PLIST_NAME
, pim
->register_plist
);
82 XFREE(MTYPE_PIM_PIM_INSTANCE
, pim
);
85 static struct pim_instance
*pim_instance_init(struct vrf
*vrf
)
87 struct pim_instance
*pim
;
90 pim
= XCALLOC(MTYPE_PIM_PIM_INSTANCE
, sizeof(struct pim_instance
));
94 pim
->mcast_if_count
= 0;
95 pim
->keep_alive_time
= PIM_KEEPALIVE_PERIOD
;
96 pim
->rp_keep_alive_time
= PIM_RP_KEEPALIVE_PERIOD
;
98 pim
->ecmp_enable
= false;
99 pim
->ecmp_rebalance_enable
= false;
103 pim
->spt
.switchover
= PIM_SPT_IMMEDIATE
;
104 pim
->spt
.plist
= NULL
;
106 pim_msdp_init(pim
, router
->master
);
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
,
114 zlog_debug("%s: NHT rpf hash init ", __func__
);
116 pim
->ssm_info
= pim_ssm_init();
118 pim
->static_routes
= list_new();
119 pim
->static_routes
->del
= (void (*)(void *))pim_static_route_free
;
121 pim
->send_v6_secondary
= 1;
127 pim_bsm_proc_init(pim
);
131 pim_upstream_init(pim
);
133 pim_instance_mlag_init(pim
);
135 pim
->last_route_change_time
= -1;
137 pim
->reg_sock
= pim_reg_sock();
138 if (pim
->reg_sock
< 0)
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
;
149 struct pim_instance
*pim_get_pim_instance(vrf_id_t vrf_id
)
151 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
159 static int pim_vrf_new(struct vrf
*vrf
)
161 struct pim_instance
*pim
= pim_instance_init(vrf
);
163 zlog_debug("VRF Created: %s(%u)", vrf
->name
, vrf
->vrf_id
);
165 vrf
->info
= (void *)pim
;
167 pim_ssmpingd_init(pim
);
171 static int pim_vrf_delete(struct vrf
*vrf
)
173 struct pim_instance
*pim
= vrf
->info
;
178 zlog_debug("VRF Deletion: %s(%u)", vrf
->name
, vrf
->vrf_id
);
180 pim_ssmpingd_destroy(pim
);
181 pim_instance_terminate(pim
);
189 * Code to turn on the pim instance that
190 * we have created with new
192 static int pim_vrf_enable(struct vrf
*vrf
)
194 struct pim_instance
*pim
= (struct pim_instance
*)vrf
->info
;
195 struct interface
*ifp
;
197 zlog_debug("%s: for %s %u", __func__
, vrf
->name
, vrf
->vrf_id
);
199 FOR_ALL_INTERFACES (vrf
, ifp
) {
203 pim_if_create_pimreg(pim
);
207 pim_mroute_socket_enable(pim
);
212 static int pim_vrf_disable(struct vrf
*vrf
)
214 /* Note: This is a callback, the VRF will be deleted by the caller. */
218 static int pim_vrf_config_write(struct vty
*vty
)
221 struct pim_instance
*pim
;
223 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
229 if (vrf
->vrf_id
!= VRF_DEFAULT
)
230 vty_frame(vty
, "vrf %s\n", vrf
->name
);
232 pim_global_config_write_worker(pim
, vty
);
234 if (vrf
->vrf_id
!= VRF_DEFAULT
)
235 vty_endframe(vty
, "exit-vrf\n!\n");
241 void pim_vrf_init(void)
243 vrf_init(pim_vrf_new
, pim_vrf_enable
, pim_vrf_disable
, pim_vrf_delete
);
245 vrf_cmd_init(pim_vrf_config_write
);
248 void pim_vrf_terminate(void)
252 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
253 struct pim_instance
*pim
;
259 pim_ssmpingd_destroy(pim
);
260 pim_instance_terminate(pim
);