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