]>
Commit | Line | Data |
---|---|---|
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" | |
3613d898 | 25 | #include "lib_errors.h" |
c2cf4b02 DS |
26 | |
27 | #include "pimd.h" | |
28 | #include "pim_ssm.h" | |
29 | #include "pim_rpf.h" | |
30 | #include "pim_rp.h" | |
31 | #include "pim_mroute.h" | |
4e0bc0f0 DS |
32 | #include "pim_oil.h" |
33 | #include "pim_static.h" | |
71ad9915 | 34 | #include "pim_ssmpingd.h" |
9ecb7b77 | 35 | #include "pim_vty.h" |
c2cf4b02 DS |
36 | |
37 | static void pim_instance_terminate(struct pim_instance *pim) | |
38 | { | |
c2cf4b02 DS |
39 | if (pim->ssm_info) { |
40 | pim_ssm_terminate(pim->ssm_info); | |
41 | pim->ssm_info = NULL; | |
42 | } | |
43 | ||
4e0bc0f0 | 44 | if (pim->static_routes) |
affe9e99 | 45 | list_delete_and_null(&pim->static_routes); |
4e0bc0f0 | 46 | |
d9c9a9ee DS |
47 | pim_rp_free(pim); |
48 | ||
9b29ea95 DS |
49 | pim_upstream_terminate(pim); |
50 | ||
48d331e7 DS |
51 | /* Traverse and cleanup rpf_hash */ |
52 | if (pim->rpf_hash) { | |
53 | hash_clean(pim->rpf_hash, (void *)pim_rp_list_hash_clean); | |
54 | hash_free(pim->rpf_hash); | |
55 | pim->rpf_hash = NULL; | |
56 | } | |
57 | ||
f88df3a6 DS |
58 | pim_if_terminate(pim); |
59 | ||
e2c4bc88 DS |
60 | pim_oil_terminate(pim); |
61 | ||
2ad78035 DS |
62 | pim_msdp_exit(pim); |
63 | ||
7f1d002a | 64 | XFREE(MTYPE_PIM_PIM_INSTANCE, pim); |
c2cf4b02 DS |
65 | } |
66 | ||
67 | static struct pim_instance *pim_instance_init(struct vrf *vrf) | |
68 | { | |
69 | struct pim_instance *pim; | |
9fb302f4 | 70 | char hash_name[64]; |
c2cf4b02 DS |
71 | |
72 | pim = XCALLOC(MTYPE_PIM_PIM_INSTANCE, sizeof(struct pim_instance)); | |
c2cf4b02 | 73 | |
f88df3a6 DS |
74 | pim_if_init(pim); |
75 | ||
19b807ca DS |
76 | pim->keep_alive_time = PIM_KEEPALIVE_PERIOD; |
77 | pim->rp_keep_alive_time = PIM_RP_KEEPALIVE_PERIOD; | |
78 | ||
4795fff7 DS |
79 | pim->ecmp_enable = false; |
80 | pim->ecmp_rebalance_enable = false; | |
19b807ca | 81 | |
c2cf4b02 DS |
82 | pim->vrf_id = vrf->vrf_id; |
83 | pim->vrf = vrf; | |
84 | ||
85 | pim->spt.switchover = PIM_SPT_IMMEDIATE; | |
86 | pim->spt.plist = NULL; | |
87 | ||
64c86530 | 88 | pim_msdp_init(pim, master); |
2ad78035 | 89 | |
9fb302f4 | 90 | snprintf(hash_name, 64, "PIM %s RPF Hash", vrf->name); |
996c9314 LB |
91 | pim->rpf_hash = hash_create_size(256, pim_rpf_hash_key, pim_rpf_equal, |
92 | hash_name); | |
c2cf4b02 DS |
93 | |
94 | if (PIM_DEBUG_ZEBRA) | |
95 | zlog_debug("%s: NHT rpf hash init ", __PRETTY_FUNCTION__); | |
96 | ||
97 | pim->ssm_info = pim_ssm_init(); | |
c2cf4b02 | 98 | |
4e0bc0f0 | 99 | pim->static_routes = list_new(); |
4e0bc0f0 DS |
100 | pim->static_routes->del = (void (*)(void *))pim_static_route_free; |
101 | ||
c2cf4b02 DS |
102 | pim->send_v6_secondary = 1; |
103 | ||
104 | if (vrf->vrf_id == VRF_DEFAULT) | |
105 | pimg = pim; | |
106 | ||
d9c9a9ee DS |
107 | pim_rp_init(pim); |
108 | ||
611925dc DS |
109 | pim_oil_init(pim); |
110 | ||
9b29ea95 | 111 | pim_upstream_init(pim); |
d9c9a9ee | 112 | |
bfc92019 | 113 | pim->last_route_change_time = -1; |
c2cf4b02 DS |
114 | return pim; |
115 | } | |
116 | ||
117 | struct pim_instance *pim_get_pim_instance(vrf_id_t vrf_id) | |
118 | { | |
119 | struct vrf *vrf = vrf_lookup_by_id(vrf_id); | |
120 | ||
121 | if (vrf) | |
122 | return vrf->info; | |
123 | ||
124 | return NULL; | |
125 | } | |
126 | ||
127 | static int pim_vrf_new(struct vrf *vrf) | |
128 | { | |
6d3c1953 | 129 | struct pim_instance *pim = pim_instance_init(vrf); |
71ad9915 | 130 | |
87ad28f4 | 131 | zlog_debug("VRF Created: %s(%u)", vrf->name, vrf->vrf_id); |
6d3c1953 DS |
132 | |
133 | vrf->info = (void *)pim; | |
134 | ||
135 | if (vrf->vrf_id == VRF_DEFAULT) | |
136 | pimg = pim; | |
71ad9915 DS |
137 | |
138 | pim_ssmpingd_init(pim); | |
c2cf4b02 DS |
139 | return 0; |
140 | } | |
141 | ||
142 | static int pim_vrf_delete(struct vrf *vrf) | |
143 | { | |
71ad9915 DS |
144 | struct pim_instance *pim = vrf->info; |
145 | ||
87ad28f4 | 146 | zlog_debug("VRF Deletion: %s(%u)", vrf->name, vrf->vrf_id); |
71ad9915 DS |
147 | |
148 | pim_ssmpingd_destroy(pim); | |
7f1d002a | 149 | pim_instance_terminate(pim); |
c2cf4b02 DS |
150 | return 0; |
151 | } | |
152 | ||
b4575b3a DS |
153 | /* |
154 | * Code to turn on the pim instance that | |
155 | * we have created with new | |
156 | */ | |
c2cf4b02 DS |
157 | static int pim_vrf_enable(struct vrf *vrf) |
158 | { | |
b4575b3a | 159 | struct pim_instance *pim = (struct pim_instance *)vrf->info; |
c2cf4b02 DS |
160 | |
161 | zlog_debug("%s: for %s", __PRETTY_FUNCTION__, vrf->name); | |
c2cf4b02 | 162 | |
b4575b3a | 163 | pim_mroute_socket_enable(pim); |
c2cf4b02 DS |
164 | |
165 | return 0; | |
166 | } | |
167 | ||
168 | static int pim_vrf_disable(struct vrf *vrf) | |
169 | { | |
c2cf4b02 DS |
170 | /* Note: This is a callback, the VRF will be deleted by the caller. */ |
171 | return 0; | |
172 | } | |
173 | ||
a01538df DS |
174 | static int pim_vrf_config_write(struct vty *vty) |
175 | { | |
176 | struct vrf *vrf; | |
177 | struct pim_instance *pim; | |
178 | ||
a2addae8 | 179 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { |
a01538df | 180 | pim = vrf->info; |
e691f179 DS |
181 | |
182 | if (!pim) | |
183 | continue; | |
184 | ||
57dac17c DS |
185 | if (vrf->vrf_id != VRF_DEFAULT) |
186 | vty_frame(vty, "vrf %s\n", vrf->name); | |
e691f179 | 187 | |
e691f179 | 188 | pim_global_config_write_worker(pim, vty); |
57dac17c DS |
189 | |
190 | if (vrf->vrf_id != VRF_DEFAULT) | |
191 | vty_endframe(vty, "!\n"); | |
a01538df DS |
192 | } |
193 | ||
194 | return 0; | |
195 | } | |
196 | ||
c2cf4b02 DS |
197 | void pim_vrf_init(void) |
198 | { | |
199 | vrf_init(pim_vrf_new, pim_vrf_enable, pim_vrf_disable, pim_vrf_delete); | |
a01538df | 200 | |
3bc34908 | 201 | vrf_cmd_init(pim_vrf_config_write, &pimd_privs); |
c2cf4b02 DS |
202 | } |
203 | ||
204 | void pim_vrf_terminate(void) | |
205 | { | |
206 | vrf_terminate(); | |
207 | } |