]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_instance.c
pimd: Convert channel_oil_hash and list into 'struct pim_instance *'
[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
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 #include "pim_oil.h"
32 #include "pim_static.h"
33
34 static void pim_instance_terminate(struct pim_instance *pim)
35 {
36 /* Traverse and cleanup rpf_hash */
37 if (pim->rpf_hash) {
38 hash_clean(pim->rpf_hash, (void *)pim_rp_list_hash_clean);
39 hash_free(pim->rpf_hash);
40 pim->rpf_hash = NULL;
41 }
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_free(pim->static_routes);
50
51 pim_rp_free(pim);
52
53 pim_upstream_terminate(pim);
54
55 pim_oil_terminate(pim);
56
57 pim_if_terminate(pim);
58
59 XFREE(MTYPE_PIM_PIM_INSTANCE, pimg);
60 }
61
62 static struct pim_instance *pim_instance_init(struct vrf *vrf)
63 {
64 struct pim_instance *pim;
65
66 pim = XCALLOC(MTYPE_PIM_PIM_INSTANCE, sizeof(struct pim_instance));
67 if (!pim)
68 return NULL;
69
70 pim_if_init(pim);
71
72 pim->vrf_id = vrf->vrf_id;
73 pim->vrf = vrf;
74
75 pim->spt.switchover = PIM_SPT_IMMEDIATE;
76 pim->spt.plist = NULL;
77
78 pim->rpf_hash =
79 hash_create_size(256, pim_rpf_hash_key, pim_rpf_equal, NULL);
80
81 if (PIM_DEBUG_ZEBRA)
82 zlog_debug("%s: NHT rpf hash init ", __PRETTY_FUNCTION__);
83
84 pim->ssm_info = pim_ssm_init();
85 if (!pim->ssm_info) {
86 pim_instance_terminate(pim);
87 return NULL;
88 }
89
90 pim->static_routes = list_new();
91 if (!pim->static_routes) {
92 zlog_err("%s %s: failure: static_routes=list_new()", __FILE__,
93 __PRETTY_FUNCTION__);
94 pim_instance_terminate(pim);
95 return NULL;
96 }
97 pim->static_routes->del = (void (*)(void *))pim_static_route_free;
98
99 pim->send_v6_secondary = 1;
100
101 if (vrf->vrf_id == VRF_DEFAULT)
102 pimg = pim;
103
104 pim_mroute_socket_enable(pim);
105
106 pim_rp_init(pim);
107
108 pim_oil_init(pim);
109
110 pim_upstream_init(pim);
111
112 return pim;
113 }
114
115 struct pim_instance *pim_get_pim_instance(vrf_id_t vrf_id)
116 {
117 struct vrf *vrf = vrf_lookup_by_id(vrf_id);
118
119 if (vrf)
120 return vrf->info;
121
122 return NULL;
123 }
124
125 static int pim_vrf_new(struct vrf *vrf)
126 {
127 zlog_debug("VRF Created: %s(%d)", vrf->name, vrf->vrf_id);
128 return 0;
129 }
130
131 static int pim_vrf_delete(struct vrf *vrf)
132 {
133 zlog_debug("VRF Deletion: %s(%d)", vrf->name, vrf->vrf_id);
134 return 0;
135 }
136
137 static int pim_vrf_enable(struct vrf *vrf)
138 {
139 struct pim_instance *pim;
140
141 zlog_debug("%s: for %s", __PRETTY_FUNCTION__, vrf->name);
142 pim = pim_instance_init(vrf);
143 if (pim == NULL) {
144 zlog_err("%s %s: pim class init failure ", __FILE__,
145 __PRETTY_FUNCTION__);
146 /*
147 * We will crash and burn otherwise
148 */
149 exit(1);
150 }
151
152 vrf->info = (void *)pim;
153
154 if (vrf->vrf_id == VRF_DEFAULT)
155 pimg = pim;
156
157 return 0;
158 }
159
160 static int pim_vrf_disable(struct vrf *vrf)
161 {
162 pim_instance_terminate((struct pim_instance *)vrf->info);
163
164 /* Note: This is a callback, the VRF will be deleted by the caller. */
165 return 0;
166 }
167
168 void pim_vrf_init(void)
169 {
170 vrf_init(pim_vrf_new, pim_vrf_enable, pim_vrf_disable, pim_vrf_delete);
171 }
172
173 void pim_vrf_terminate(void)
174 {
175 vrf_terminate();
176 }