]> git.proxmox.com Git - mirror_frr.git/blame - pimd/pim_instance.c
pimd: Fix c_oil->pim set spot
[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"
25
26#include "pimd.h"
27#include "pim_ssm.h"
28#include "pim_rpf.h"
29#include "pim_rp.h"
30#include "pim_mroute.h"
31
32static void pim_instance_terminate(struct pim_instance *pim)
33{
34 /* Traverse and cleanup rpf_hash */
35 if (pim->rpf_hash) {
36 hash_clean(pim->rpf_hash, (void *)pim_rp_list_hash_clean);
37 hash_free(pim->rpf_hash);
38 pim->rpf_hash = NULL;
39 }
40
41 if (pim->ssm_info) {
42 pim_ssm_terminate(pim->ssm_info);
43 pim->ssm_info = NULL;
44 }
45
46 XFREE(MTYPE_PIM_PIM_INSTANCE, pimg);
47}
48
49static struct pim_instance *pim_instance_init(struct vrf *vrf)
50{
51 struct pim_instance *pim;
52
53 pim = XCALLOC(MTYPE_PIM_PIM_INSTANCE, sizeof(struct pim_instance));
54 if (!pim)
55 return NULL;
56
57 pim->vrf_id = vrf->vrf_id;
58 pim->vrf = vrf;
59
60 pim->spt.switchover = PIM_SPT_IMMEDIATE;
61 pim->spt.plist = NULL;
62
63 pim->rpf_hash =
64 hash_create_size(256, pim_rpf_hash_key, pim_rpf_equal, NULL);
65
66 if (PIM_DEBUG_ZEBRA)
67 zlog_debug("%s: NHT rpf hash init ", __PRETTY_FUNCTION__);
68
69 pim->ssm_info = pim_ssm_init();
70 if (!pim->ssm_info) {
71 pim_instance_terminate(pim);
72 return NULL;
73 }
74
75 pim->send_v6_secondary = 1;
76
77 if (vrf->vrf_id == VRF_DEFAULT)
78 pimg = pim;
79
80 pim_mroute_socket_enable(pim);
81
82 return pim;
83}
84
85struct pim_instance *pim_get_pim_instance(vrf_id_t vrf_id)
86{
87 struct vrf *vrf = vrf_lookup_by_id(vrf_id);
88
89 if (vrf)
90 return vrf->info;
91
92 return NULL;
93}
94
95static int pim_vrf_new(struct vrf *vrf)
96{
97 zlog_debug("VRF Created: %s(%d)", vrf->name, vrf->vrf_id);
98 return 0;
99}
100
101static int pim_vrf_delete(struct vrf *vrf)
102{
103 zlog_debug("VRF Deletion: %s(%d)", vrf->name, vrf->vrf_id);
104 return 0;
105}
106
107static int pim_vrf_enable(struct vrf *vrf)
108{
109 struct pim_instance *pim;
110
111 zlog_debug("%s: for %s", __PRETTY_FUNCTION__, vrf->name);
112 pim = pim_instance_init(vrf);
113 if (pim == NULL) {
114 zlog_err("%s %s: pim class init failure ", __FILE__,
115 __PRETTY_FUNCTION__);
116 /*
117 * We will crash and burn otherwise
118 */
119 exit(1);
120 }
121
122 vrf->info = (void *)pim;
123
124 if (vrf->vrf_id == VRF_DEFAULT)
125 pimg = pim;
126
127 return 0;
128}
129
130static int pim_vrf_disable(struct vrf *vrf)
131{
132 pim_instance_terminate((struct pim_instance *)vrf->info);
133
134 /* Note: This is a callback, the VRF will be deleted by the caller. */
135 return 0;
136}
137
138void pim_vrf_init(void)
139{
140 vrf_init(pim_vrf_new, pim_vrf_enable, pim_vrf_disable, pim_vrf_delete);
141}
142
143void pim_vrf_terminate(void)
144{
145 vrf_terminate();
146}