]>
Commit | Line | Data |
---|---|---|
12e41d03 | 1 | /* |
896014f4 DL |
2 | * PIM for Quagga |
3 | * Copyright (C) 2008 Everton da Silva Marques | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; see the file COPYING; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | */ | |
12e41d03 DL |
19 | |
20 | #include <zebra.h> | |
21 | ||
22 | #include "log.h" | |
23 | #include "memory.h" | |
9df99407 | 24 | #include "if.h" |
dfe43e25 DW |
25 | #include "prefix.h" |
26 | #include "vty.h" | |
27 | #include "plist.h" | |
1bc98276 CS |
28 | #include "hash.h" |
29 | #include "jhash.h" | |
12e41d03 DL |
30 | |
31 | #include "pimd.h" | |
32 | #include "pim_cmd.h" | |
33 | #include "pim_iface.h" | |
34 | #include "pim_zebra.h" | |
35 | #include "pim_str.h" | |
36 | #include "pim_oil.h" | |
37 | #include "pim_pim.h" | |
38 | #include "pim_upstream.h" | |
12e41d03 DL |
39 | #include "pim_rpf.h" |
40 | #include "pim_ssmpingd.h" | |
6250610a | 41 | #include "pim_static.h" |
36d6bd7d | 42 | #include "pim_rp.h" |
15a5dafe | 43 | #include "pim_ssm.h" |
0b6817c5 | 44 | #include "pim_zlookup.h" |
1bc98276 | 45 | #include "pim_nht.h" |
12e41d03 DL |
46 | |
47 | const char *const PIM_ALL_SYSTEMS = MCAST_ALL_SYSTEMS; | |
48 | const char *const PIM_ALL_ROUTERS = MCAST_ALL_ROUTERS; | |
49 | const char *const PIM_ALL_PIM_ROUTERS = MCAST_ALL_PIM_ROUTERS; | |
50 | const char *const PIM_ALL_IGMP_ROUTERS = MCAST_ALL_IGMP_ROUTERS; | |
51 | ||
469351b3 | 52 | struct thread_master *master = NULL; |
12e41d03 DL |
53 | uint32_t qpim_debugs = 0; |
54 | int qpim_mroute_socket_fd = -1; | |
55 | int64_t qpim_mroute_socket_creation = 0; /* timestamp of creation */ | |
12e41d03 | 56 | int qpim_t_periodic = PIM_DEFAULT_T_PERIODIC; /* Period between Join/Prune Messages */ |
12e41d03 | 57 | struct pim_assert_metric qpim_infinite_assert_metric; |
deab75f7 | 58 | long qpim_rpf_cache_refresh_delay_msec = 50; |
59ba0ac3 | 59 | struct thread *qpim_rpf_cache_refresher = NULL; |
12e41d03 DL |
60 | int64_t qpim_rpf_cache_refresh_requests = 0; |
61 | int64_t qpim_rpf_cache_refresh_events = 0; | |
62 | int64_t qpim_rpf_cache_refresh_last = 0; | |
63 | struct in_addr qpim_inaddr_any; | |
59ba0ac3 | 64 | struct list *qpim_ssmpingd_list = NULL; |
12e41d03 DL |
65 | struct in_addr qpim_ssmpingd_group_addr; |
66 | int64_t qpim_scan_oil_events = 0; | |
67 | int64_t qpim_scan_oil_last = 0; | |
68 | int64_t qpim_mroute_add_events = 0; | |
69 | int64_t qpim_mroute_add_last = 0; | |
70 | int64_t qpim_mroute_del_events = 0; | |
71 | int64_t qpim_mroute_del_last = 0; | |
59ba0ac3 | 72 | struct list *qpim_static_route_list = NULL; |
4304f95c | 73 | unsigned int qpim_keep_alive_time = PIM_KEEPALIVE_PERIOD; |
01408ede | 74 | signed int qpim_rp_keep_alive_time = 0; |
284b4301 | 75 | int64_t qpim_nexthop_lookups = 0; |
8e4c9ef3 | 76 | int qpim_packet_process = PIM_DEFAULT_PACKET_PROCESS; |
cba44481 CS |
77 | uint8_t qpim_ecmp_enable = 0; |
78 | uint8_t qpim_ecmp_rebalance_enable = 0; | |
79 | struct pim_instance *pimg = NULL; | |
12e41d03 | 80 | |
4a4c4a07 DS |
81 | int32_t qpim_register_suppress_time = PIM_REGISTER_SUPPRESSION_TIME_DEFAULT; |
82 | int32_t qpim_register_probe_time = PIM_REGISTER_PROBE_TIME_DEFAULT; | |
83 | ||
1bc98276 CS |
84 | static struct pim_instance *pim_instance_init (vrf_id_t vrf_id, afi_t afi); |
85 | static void pim_instance_terminate (void); | |
86 | ||
87 | static int | |
88 | pim_vrf_new (struct vrf *vrf) | |
89 | { | |
90 | zlog_debug ("VRF Created: %s(%d)", vrf->name, vrf->vrf_id); | |
91 | return 0; | |
92 | } | |
93 | ||
94 | static int | |
95 | pim_vrf_delete (struct vrf *vrf) | |
96 | { | |
97 | zlog_debug ("VRF Deletion: %s(%d)", vrf->name, vrf->vrf_id); | |
98 | return 0; | |
99 | } | |
100 | ||
101 | static int | |
102 | pim_vrf_enable (struct vrf *vrf) | |
103 | { | |
104 | ||
105 | if (!vrf) // unexpected | |
106 | return -1; | |
107 | ||
108 | if (vrf->vrf_id == VRF_DEFAULT) | |
109 | { | |
110 | pimg = pim_instance_init (VRF_DEFAULT, AFI_IP); | |
111 | if (pimg == NULL) | |
6ca7dd90 DS |
112 | { |
113 | zlog_err ("%s %s: pim class init failure ", __FILE__, | |
114 | __PRETTY_FUNCTION__); | |
115 | /* | |
116 | * We will crash and burn otherwise | |
117 | */ | |
118 | exit(1); | |
09639810 DS |
119 | } |
120 | ||
121 | pimg->send_v6_secondary = 1; | |
71bbe73d | 122 | |
1bc98276 CS |
123 | } |
124 | return 0; | |
125 | } | |
126 | ||
127 | static int | |
128 | pim_vrf_disable (struct vrf *vrf) | |
129 | { | |
130 | if (vrf->vrf_id == VRF_DEFAULT) | |
131 | return 0; | |
132 | ||
133 | if (vrf->vrf_id == VRF_DEFAULT) | |
134 | pim_instance_terminate (); | |
135 | ||
136 | /* Note: This is a callback, the VRF will be deleted by the caller. */ | |
137 | return 0; | |
138 | } | |
139 | ||
140 | void | |
141 | pim_vrf_init (void) | |
142 | { | |
143 | vrf_add_hook (VRF_NEW_HOOK, pim_vrf_new); | |
144 | vrf_add_hook (VRF_ENABLE_HOOK, pim_vrf_enable); | |
145 | vrf_add_hook (VRF_DISABLE_HOOK, pim_vrf_disable); | |
146 | vrf_add_hook (VRF_DELETE_HOOK, pim_vrf_delete); | |
147 | ||
148 | vrf_init (); | |
149 | } | |
150 | ||
151 | static void | |
152 | pim_vrf_terminate (void) | |
153 | { | |
154 | vrf_add_hook (VRF_NEW_HOOK, NULL); | |
155 | vrf_add_hook (VRF_ENABLE_HOOK, NULL); | |
156 | vrf_add_hook (VRF_DISABLE_HOOK, NULL); | |
157 | vrf_add_hook (VRF_DELETE_HOOK, NULL); | |
158 | ||
159 | vrf_terminate (); | |
160 | } | |
161 | ||
162 | /* Key generate for pim->rpf_hash */ | |
163 | static unsigned int | |
164 | pim_rpf_hash_key (void *arg) | |
165 | { | |
166 | struct pim_nexthop_cache *r = (struct pim_nexthop_cache *) arg; | |
167 | ||
168 | return jhash_1word (r->rpf.rpf_addr.u.prefix4.s_addr, 0); | |
169 | } | |
170 | ||
171 | /* Compare pim->rpf_hash node data */ | |
172 | static int | |
173 | pim_rpf_equal (const void *arg1, const void *arg2) | |
174 | { | |
175 | const struct pim_nexthop_cache *r1 = | |
176 | (const struct pim_nexthop_cache *) arg1; | |
177 | const struct pim_nexthop_cache *r2 = | |
178 | (const struct pim_nexthop_cache *) arg2; | |
179 | ||
180 | return prefix_same (&r1->rpf.rpf_addr, &r2->rpf.rpf_addr); | |
181 | } | |
182 | ||
183 | /* Cleanup pim->rpf_hash each node data */ | |
184 | static void | |
185 | pim_rp_list_hash_clean (void *data) | |
186 | { | |
187 | struct pim_nexthop_cache *pnc; | |
188 | ||
189 | pnc = (struct pim_nexthop_cache *) data; | |
190 | if (pnc->rp_list->count) | |
191 | list_delete_all_node (pnc->rp_list); | |
192 | if (pnc->upstream_list->count) | |
193 | list_delete_all_node (pnc->upstream_list); | |
194 | } | |
195 | ||
15a5dafe | 196 | void |
197 | pim_prefix_list_update (struct prefix_list *plist) | |
198 | { | |
199 | pim_rp_prefix_list_update (plist); | |
200 | pim_ssm_prefix_list_update (plist); | |
df94f9a9 | 201 | pim_upstream_spt_prefix_list_update (plist); |
15a5dafe | 202 | } |
203 | ||
1bc98276 CS |
204 | static void |
205 | pim_instance_terminate (void) | |
206 | { | |
207 | /* Traverse and cleanup rpf_hash */ | |
6ca7dd90 | 208 | if (pimg->rpf_hash) |
1bc98276 CS |
209 | { |
210 | hash_clean (pimg->rpf_hash, (void *) pim_rp_list_hash_clean); | |
211 | hash_free (pimg->rpf_hash); | |
6ca7dd90 DS |
212 | pimg->rpf_hash = NULL; |
213 | } | |
214 | ||
215 | if (pimg->ssm_info) | |
216 | { | |
217 | pim_ssm_terminate (pimg->ssm_info); | |
218 | pimg->ssm_info = NULL; | |
1bc98276 CS |
219 | } |
220 | ||
221 | XFREE (MTYPE_PIM_PIM_INSTANCE, pimg); | |
222 | } | |
223 | ||
12e41d03 DL |
224 | static void pim_free() |
225 | { | |
226 | pim_ssmpingd_destroy(); | |
227 | ||
040d86ad | 228 | pim_oil_terminate (); |
12e41d03 | 229 | |
0f588989 | 230 | pim_upstream_terminate (); |
6250610a JAG |
231 | |
232 | if (qpim_static_route_list) | |
233 | list_free(qpim_static_route_list); | |
28b0c6b3 | 234 | |
ea4a71fc | 235 | pim_if_terminate (); |
36d6bd7d | 236 | pim_rp_free (); |
59d4564e | 237 | |
44a13ae3 | 238 | pim_route_map_terminate(); |
0b6817c5 DS |
239 | |
240 | zclient_lookup_free (); | |
241 | ||
242 | zprivs_terminate(&pimd_privs); | |
12e41d03 DL |
243 | } |
244 | ||
1bc98276 CS |
245 | static struct pim_instance * |
246 | pim_instance_init (vrf_id_t vrf_id, afi_t afi) | |
247 | { | |
248 | struct pim_instance *pim; | |
249 | ||
250 | pim = XCALLOC (MTYPE_PIM_PIM_INSTANCE, sizeof (struct pim_instance)); | |
251 | if (!pim) | |
252 | return NULL; | |
253 | ||
254 | pim->vrf_id = vrf_id; | |
255 | pim->afi = afi; | |
256 | ||
df94f9a9 DS |
257 | pim->spt.switchover = PIM_SPT_IMMEDIATE; |
258 | pim->spt.plist = NULL; | |
259 | ||
1bc98276 CS |
260 | pim->rpf_hash = hash_create_size (256, pim_rpf_hash_key, pim_rpf_equal); |
261 | ||
262 | if (PIM_DEBUG_ZEBRA) | |
263 | zlog_debug ("%s: NHT rpf hash init ", __PRETTY_FUNCTION__); | |
264 | ||
15a5dafe | 265 | pim->ssm_info = pim_ssm_init (vrf_id); |
266 | if (!pim->ssm_info) { | |
267 | pim_instance_terminate (); | |
268 | return NULL; | |
269 | } | |
1bc98276 CS |
270 | |
271 | return pim; | |
272 | } | |
273 | ||
12e41d03 DL |
274 | void pim_init() |
275 | { | |
01408ede DS |
276 | qpim_rp_keep_alive_time = PIM_RP_KEEPALIVE_PERIOD; |
277 | ||
36d6bd7d DS |
278 | pim_rp_init (); |
279 | ||
12e41d03 DL |
280 | if (!inet_aton(PIM_ALL_PIM_ROUTERS, &qpim_all_pim_routers_addr)) { |
281 | zlog_err("%s %s: could not solve %s to group address: errno=%d: %s", | |
282 | __FILE__, __PRETTY_FUNCTION__, | |
283 | PIM_ALL_PIM_ROUTERS, errno, safe_strerror(errno)); | |
284 | zassert(0); | |
285 | return; | |
286 | } | |
287 | ||
040d86ad | 288 | pim_oil_init (); |
12e41d03 | 289 | |
0f588989 | 290 | pim_upstream_init (); |
12e41d03 | 291 | |
6250610a JAG |
292 | qpim_static_route_list = list_new(); |
293 | if (!qpim_static_route_list) { | |
294 | zlog_err("%s %s: failure: static_route_list=list_new()", | |
295 | __FILE__, __PRETTY_FUNCTION__); | |
296 | return; | |
297 | } | |
298 | qpim_static_route_list->del = (void (*)(void *)) pim_static_route_free; | |
299 | ||
b8d16be2 | 300 | pim_mroute_socket_enable(); |
12e41d03 | 301 | |
12e41d03 DL |
302 | qpim_inaddr_any.s_addr = PIM_NET_INADDR_ANY; |
303 | ||
304 | /* | |
305 | RFC 4601: 4.6.3. Assert Metrics | |
306 | ||
307 | assert_metric | |
308 | infinite_assert_metric() { | |
309 | return {1,infinity,infinity,0} | |
310 | } | |
311 | */ | |
312 | qpim_infinite_assert_metric.rpt_bit_flag = 1; | |
313 | qpim_infinite_assert_metric.metric_preference = PIM_ASSERT_METRIC_PREFERENCE_MAX; | |
314 | qpim_infinite_assert_metric.route_metric = PIM_ASSERT_ROUTE_METRIC_MAX; | |
315 | qpim_infinite_assert_metric.ip_address = qpim_inaddr_any; | |
316 | ||
317 | pim_if_init(); | |
318 | pim_cmd_init(); | |
319 | pim_ssmpingd_init(); | |
320 | } | |
321 | ||
322 | void pim_terminate() | |
323 | { | |
324 | pim_free(); | |
1bc98276 CS |
325 | |
326 | /* reverse prefix_list_init */ | |
327 | prefix_list_add_hook (NULL); | |
328 | prefix_list_delete_hook (NULL); | |
329 | prefix_list_reset (); | |
330 | ||
331 | pim_vrf_terminate (); | |
12e41d03 | 332 | } |