]>
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 | ||
12e41d03 DL |
22 | #include "if.h" |
23 | #include "log.h" | |
24 | #include "prefix.h" | |
25 | #include "zclient.h" | |
26 | #include "stream.h" | |
27 | #include "network.h" | |
dfe43e25 DW |
28 | #include "vty.h" |
29 | #include "plist.h" | |
ba4eb1bc | 30 | #include "lib/bfd.h" |
12e41d03 DL |
31 | |
32 | #include "pimd.h" | |
33 | #include "pim_pim.h" | |
34 | #include "pim_zebra.h" | |
35 | #include "pim_iface.h" | |
36 | #include "pim_str.h" | |
37 | #include "pim_oil.h" | |
38 | #include "pim_rpf.h" | |
39 | #include "pim_time.h" | |
40 | #include "pim_join.h" | |
41 | #include "pim_zlookup.h" | |
42 | #include "pim_ifchannel.h" | |
8f5f5e91 | 43 | #include "pim_rp.h" |
2560106c | 44 | #include "pim_igmpv3.h" |
982bff89 | 45 | #include "pim_jp_agg.h" |
1bc98276 | 46 | #include "pim_nht.h" |
15a5dafe | 47 | #include "pim_ssm.h" |
af7b561b | 48 | #include "pim_vxlan.h" |
46c2687c | 49 | #include "pim_mlag.h" |
12e41d03 DL |
50 | |
51 | #undef PIM_DEBUG_IFADDR_DUMP | |
52 | #define PIM_DEBUG_IFADDR_DUMP | |
53 | ||
36b5b98f | 54 | struct zclient *zclient; |
38f4935a | 55 | |
12e41d03 | 56 | |
12e41d03 | 57 | /* Router-id update message from zebra. */ |
121f9dee | 58 | static int pim_router_id_update_zebra(ZAPI_CALLBACK_ARGS) |
12e41d03 | 59 | { |
d62a17ae | 60 | struct prefix router_id; |
12e41d03 | 61 | |
d62a17ae | 62 | zebra_router_id_update_read(zclient->ibuf, &router_id); |
12e41d03 | 63 | |
d62a17ae | 64 | return 0; |
12e41d03 DL |
65 | } |
66 | ||
121f9dee | 67 | static int pim_zebra_interface_vrf_update(ZAPI_CALLBACK_ARGS) |
ee568318 DS |
68 | { |
69 | struct interface *ifp; | |
70 | vrf_id_t new_vrf_id; | |
71 | ||
72 | ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id, | |
73 | &new_vrf_id); | |
74 | if (!ifp) | |
75 | return 0; | |
76 | ||
77 | if (PIM_DEBUG_ZEBRA) | |
78 | zlog_debug("%s: %s updating from %u to %u", | |
79 | __PRETTY_FUNCTION__, | |
80 | ifp->name, vrf_id, new_vrf_id); | |
81 | ||
a36898e7 | 82 | if_update_to_new_vrf(ifp, new_vrf_id); |
ee568318 DS |
83 | |
84 | return 0; | |
85 | } | |
86 | ||
12e41d03 DL |
87 | #ifdef PIM_DEBUG_IFADDR_DUMP |
88 | static void dump_if_address(struct interface *ifp) | |
89 | { | |
d62a17ae | 90 | struct connected *ifc; |
91 | struct listnode *node; | |
92 | ||
93 | zlog_debug("%s %s: interface %s addresses:", __FILE__, | |
94 | __PRETTY_FUNCTION__, ifp->name); | |
95 | ||
96 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { | |
97 | struct prefix *p = ifc->address; | |
98 | ||
99 | if (p->family != AF_INET) | |
100 | continue; | |
101 | ||
102 | zlog_debug("%s %s: interface %s address %s %s", __FILE__, | |
103 | __PRETTY_FUNCTION__, ifp->name, | |
104 | inet_ntoa(p->u.prefix4), | |
105 | CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY) | |
106 | ? "secondary" | |
107 | : "primary"); | |
108 | } | |
12e41d03 DL |
109 | } |
110 | #endif | |
111 | ||
121f9dee | 112 | static int pim_zebra_if_address_add(ZAPI_CALLBACK_ARGS) |
12e41d03 | 113 | { |
d62a17ae | 114 | struct connected *c; |
115 | struct prefix *p; | |
116 | struct pim_interface *pim_ifp; | |
26bb1fd5 | 117 | struct pim_instance *pim; |
d62a17ae | 118 | |
119 | /* | |
120 | zebra api notifies address adds/dels events by using the same call | |
121 | interface_add_read below, see comments in lib/zclient.c | |
122 | ||
123 | zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD, ...) | |
124 | will add address to interface list by calling | |
125 | connected_add_by_prefix() | |
126 | */ | |
121f9dee | 127 | c = zebra_interface_address_read(cmd, zclient->ibuf, vrf_id); |
d62a17ae | 128 | if (!c) |
129 | return 0; | |
130 | ||
131 | pim_ifp = c->ifp->info; | |
132 | p = c->address; | |
133 | ||
134 | if (PIM_DEBUG_ZEBRA) { | |
135 | char buf[BUFSIZ]; | |
136 | prefix2str(p, buf, BUFSIZ); | |
87ad28f4 | 137 | zlog_debug("%s: %s(%u) connected IP address %s flags %u %s", |
e0ae31b8 | 138 | __PRETTY_FUNCTION__, c->ifp->name, vrf_id, buf, |
996c9314 LB |
139 | c->flags, |
140 | CHECK_FLAG(c->flags, ZEBRA_IFA_SECONDARY) | |
141 | ? "secondary" | |
142 | : "primary"); | |
d62a17ae | 143 | |
12e41d03 | 144 | #ifdef PIM_DEBUG_IFADDR_DUMP |
d62a17ae | 145 | dump_if_address(c->ifp); |
12e41d03 | 146 | #endif |
d62a17ae | 147 | } |
12e41d03 | 148 | |
d62a17ae | 149 | if (!CHECK_FLAG(c->flags, ZEBRA_IFA_SECONDARY)) { |
150 | /* trying to add primary address */ | |
12e41d03 | 151 | |
d62a17ae | 152 | struct in_addr primary_addr = pim_find_primary_addr(c->ifp); |
153 | if (p->family != AF_INET | |
154 | || primary_addr.s_addr != p->u.prefix4.s_addr) { | |
155 | if (PIM_DEBUG_ZEBRA) { | |
156 | /* but we had a primary address already */ | |
12e41d03 | 157 | |
d62a17ae | 158 | char buf[BUFSIZ]; |
12e41d03 | 159 | |
d62a17ae | 160 | prefix2str(p, buf, BUFSIZ); |
12e41d03 | 161 | |
d62a17ae | 162 | zlog_warn( |
163 | "%s: %s : forcing secondary flag on %s", | |
164 | __PRETTY_FUNCTION__, c->ifp->name, buf); | |
165 | } | |
166 | SET_FLAG(c->flags, ZEBRA_IFA_SECONDARY); | |
167 | } | |
168 | } | |
12e41d03 | 169 | |
d62a17ae | 170 | pim_if_addr_add(c); |
26bb1fd5 DS |
171 | if (pim_ifp) { |
172 | pim = pim_get_pim_instance(vrf_id); | |
173 | pim_ifp->pim = pim; | |
174 | ||
d62a17ae | 175 | pim_rp_check_on_if_add(pim_ifp); |
26bb1fd5 | 176 | } |
12e41d03 | 177 | |
d62a17ae | 178 | if (if_is_loopback(c->ifp)) { |
f4e14fdb | 179 | struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); |
d62a17ae | 180 | struct interface *ifp; |
d8424057 | 181 | |
451fda4f | 182 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 183 | if (!if_is_loopback(ifp) && if_is_operative(ifp)) |
184 | pim_if_addr_add_all(ifp); | |
185 | } | |
186 | } | |
d8424057 | 187 | |
d62a17ae | 188 | return 0; |
12e41d03 DL |
189 | } |
190 | ||
121f9dee | 191 | static int pim_zebra_if_address_del(ZAPI_CALLBACK_ARGS) |
12e41d03 | 192 | { |
d62a17ae | 193 | struct connected *c; |
194 | struct prefix *p; | |
fec883d9 | 195 | struct vrf *vrf = vrf_lookup_by_id(vrf_id); |
819f099b DS |
196 | struct pim_instance *pim; |
197 | ||
198 | if (!vrf) | |
199 | return 0; | |
200 | pim = vrf->info; | |
d62a17ae | 201 | |
202 | /* | |
203 | zebra api notifies address adds/dels events by using the same call | |
204 | interface_add_read below, see comments in lib/zclient.c | |
205 | ||
206 | zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE, ...) | |
207 | will remove address from interface list by calling | |
208 | connected_delete_by_prefix() | |
209 | */ | |
121f9dee | 210 | c = zebra_interface_address_read(cmd, zclient->ibuf, vrf_id); |
d62a17ae | 211 | if (!c) |
212 | return 0; | |
213 | ||
214 | p = c->address; | |
215 | if (p->family == AF_INET) { | |
216 | if (PIM_DEBUG_ZEBRA) { | |
217 | char buf[BUFSIZ]; | |
218 | prefix2str(p, buf, BUFSIZ); | |
219 | zlog_debug( | |
87ad28f4 | 220 | "%s: %s(%u) disconnected IP address %s flags %u %s", |
e0ae31b8 | 221 | __PRETTY_FUNCTION__, c->ifp->name, vrf_id, buf, |
d62a17ae | 222 | c->flags, |
223 | CHECK_FLAG(c->flags, ZEBRA_IFA_SECONDARY) | |
224 | ? "secondary" | |
225 | : "primary"); | |
6233f087 | 226 | |
12e41d03 | 227 | #ifdef PIM_DEBUG_IFADDR_DUMP |
d62a17ae | 228 | dump_if_address(c->ifp); |
12e41d03 | 229 | #endif |
d62a17ae | 230 | } |
12e41d03 | 231 | |
d62a17ae | 232 | pim_if_addr_del(c, 0); |
fec883d9 DS |
233 | pim_rp_setup(pim); |
234 | pim_i_am_rp_re_evaluate(pim); | |
d62a17ae | 235 | } |
6233f087 | 236 | |
721c0857 | 237 | connected_free(&c); |
d62a17ae | 238 | return 0; |
12e41d03 DL |
239 | } |
240 | ||
74389231 DS |
241 | void pim_zebra_update_all_interfaces(struct pim_instance *pim) |
242 | { | |
243 | struct interface *ifp; | |
244 | ||
245 | FOR_ALL_INTERFACES (pim->vrf, ifp) { | |
246 | struct pim_interface *pim_ifp = ifp->info; | |
247 | struct pim_iface_upstream_switch *us; | |
248 | struct listnode *node; | |
249 | ||
250 | if (!pim_ifp) | |
251 | continue; | |
252 | ||
253 | for (ALL_LIST_ELEMENTS_RO(pim_ifp->upstream_switch_list, node, | |
254 | us)) { | |
255 | struct pim_rpf rpf; | |
256 | ||
257 | rpf.source_nexthop.interface = ifp; | |
258 | rpf.rpf_addr.u.prefix4 = us->address; | |
259 | pim_joinprune_send(&rpf, us->us); | |
260 | pim_jp_agg_clear_group(us->us); | |
261 | } | |
262 | } | |
263 | } | |
264 | ||
cc67ccf9 DS |
265 | void pim_zebra_upstream_rpf_changed(struct pim_instance *pim, |
266 | struct pim_upstream *up, | |
267 | struct pim_rpf *old) | |
268 | { | |
1250cb5d SP |
269 | if (old->source_nexthop.interface) { |
270 | struct pim_neighbor *nbr; | |
cc67ccf9 | 271 | |
1250cb5d SP |
272 | nbr = pim_neighbor_find(old->source_nexthop.interface, |
273 | old->rpf_addr.u.prefix4); | |
274 | if (nbr) | |
c5cdf069 | 275 | pim_jp_agg_remove_group(nbr->upstream_jp_agg, up, nbr); |
cc67ccf9 | 276 | |
cc67ccf9 | 277 | /* |
1250cb5d SP |
278 | * We have detected a case where we might need |
279 | * to rescan the inherited o_list so do it. | |
cc67ccf9 | 280 | */ |
1250cb5d SP |
281 | if (up->channel_oil->oil_inherited_rescan) { |
282 | pim_upstream_inherited_olist_decide(pim, up); | |
283 | up->channel_oil->oil_inherited_rescan = 0; | |
284 | } | |
cc67ccf9 | 285 | |
1250cb5d SP |
286 | if (up->join_state == PIM_UPSTREAM_JOINED) { |
287 | /* | |
288 | * If we come up real fast we can be here | |
289 | * where the mroute has not been installed | |
290 | * so install it. | |
291 | */ | |
292 | if (!up->channel_oil->installed) | |
69e3538c | 293 | pim_upstream_mroute_add(up->channel_oil, |
1250cb5d SP |
294 | __PRETTY_FUNCTION__); |
295 | ||
296 | /* | |
297 | * RFC 4601: 4.5.7. Sending (S,G) | |
298 | * Join/Prune Messages | |
299 | * | |
300 | * Transitions from Joined State | |
301 | * | |
302 | * RPF'(S,G) changes not due to an Assert | |
303 | * | |
304 | * The upstream (S,G) state machine remains | |
305 | * in Joined state. Send Join(S,G) to the new | |
306 | * upstream neighbor, which is the new value | |
307 | * of RPF'(S,G). Send Prune(S,G) to the old | |
308 | * upstream neighbor, which is the old value | |
309 | * of RPF'(S,G). Set the Join Timer (JT) to | |
310 | * expire after t_periodic seconds. | |
311 | */ | |
312 | pim_jp_agg_switch_interface(old, &up->rpf, up); | |
313 | ||
314 | pim_upstream_join_timer_restart(up, old); | |
315 | } /* up->join_state == PIM_UPSTREAM_JOINED */ | |
316 | } | |
317 | ||
318 | else { | |
cc67ccf9 | 319 | /* |
1250cb5d SP |
320 | * We have detected a case where we might need |
321 | * to rescan the inherited o_list so do it. | |
cc67ccf9 | 322 | */ |
1250cb5d SP |
323 | if (up->channel_oil->oil_inherited_rescan) { |
324 | pim_upstream_inherited_olist_decide(pim, up); | |
325 | up->channel_oil->oil_inherited_rescan = 0; | |
326 | } | |
cc67ccf9 | 327 | |
db431af2 AK |
328 | if (up->join_state == PIM_UPSTREAM_JOINED) |
329 | pim_jp_agg_switch_interface(old, &up->rpf, up); | |
330 | ||
1250cb5d | 331 | if (!up->channel_oil->installed) |
69e3538c AK |
332 | pim_upstream_mroute_add(up->channel_oil, |
333 | __PRETTY_FUNCTION__); | |
1250cb5d | 334 | } |
cc67ccf9 | 335 | |
1250cb5d SP |
336 | /* FIXME can join_desired actually be changed by pim_rpf_update() |
337 | * returning PIM_RPF_CHANGED ? | |
338 | */ | |
cc67ccf9 DS |
339 | pim_upstream_update_join_desired(pim, up); |
340 | } | |
341 | ||
121f9dee | 342 | static int pim_zebra_vxlan_sg_proc(ZAPI_CALLBACK_ARGS) |
af7b561b AK |
343 | { |
344 | struct stream *s; | |
345 | struct pim_instance *pim; | |
346 | struct prefix_sg sg; | |
347 | ||
348 | pim = pim_get_pim_instance(vrf_id); | |
349 | if (!pim) | |
350 | return 0; | |
351 | ||
352 | s = zclient->ibuf; | |
353 | ||
354 | sg.family = AF_INET; | |
355 | sg.prefixlen = stream_getl(s); | |
356 | stream_get(&sg.src.s_addr, s, sg.prefixlen); | |
357 | stream_get(&sg.grp.s_addr, s, sg.prefixlen); | |
358 | ||
359 | if (PIM_DEBUG_ZEBRA) { | |
360 | char sg_str[PIM_SG_LEN]; | |
361 | ||
362 | pim_str_sg_set(&sg, sg_str); | |
363 | zlog_debug("%u:recv SG %s %s", vrf_id, | |
121f9dee | 364 | (cmd == ZEBRA_VXLAN_SG_ADD)?"add":"del", |
af7b561b AK |
365 | sg_str); |
366 | } | |
367 | ||
121f9dee | 368 | if (cmd == ZEBRA_VXLAN_SG_ADD) |
af7b561b AK |
369 | pim_vxlan_sg_add(pim, &sg); |
370 | else | |
371 | pim_vxlan_sg_del(pim, &sg); | |
372 | ||
373 | return 0; | |
374 | } | |
375 | ||
ecbbc3a7 AK |
376 | static void pim_zebra_vxlan_replay(void) |
377 | { | |
378 | struct stream *s = NULL; | |
379 | ||
380 | /* Check socket. */ | |
381 | if (!zclient || zclient->sock < 0) | |
382 | return; | |
383 | ||
384 | s = zclient->obuf; | |
385 | stream_reset(s); | |
386 | ||
387 | zclient_create_header(s, ZEBRA_VXLAN_SG_REPLAY, VRF_DEFAULT); | |
388 | stream_putw_at(s, 0, stream_get_endp(s)); | |
389 | ||
390 | zclient_send_message(zclient); | |
391 | } | |
392 | ||
da11e325 | 393 | void pim_scan_oil(struct pim_instance *pim) |
8a67a996 | 394 | { |
d62a17ae | 395 | struct channel_oil *c_oil; |
d62a17ae | 396 | |
bfc92019 DS |
397 | pim->scan_oil_last = pim_time_monotonic_sec(); |
398 | ++pim->scan_oil_events; | |
d62a17ae | 399 | |
7315ecda | 400 | frr_each (rb_pim_oil, &pim->channel_oil_head, c_oil) |
7984af18 | 401 | pim_upstream_mroute_iif_update(c_oil, __func__); |
12e41d03 DL |
402 | } |
403 | ||
404 | static int on_rpf_cache_refresh(struct thread *t) | |
405 | { | |
da11e325 DS |
406 | struct pim_instance *pim = THREAD_ARG(t); |
407 | ||
d62a17ae | 408 | /* update kernel multicast forwarding cache (MFC) */ |
da11e325 | 409 | pim_scan_oil(pim); |
12e41d03 | 410 | |
bfc92019 DS |
411 | pim->rpf_cache_refresh_last = pim_time_monotonic_sec(); |
412 | ++pim->rpf_cache_refresh_events; | |
12e41d03 | 413 | |
d62a17ae | 414 | // It is called as part of pim_neighbor_add |
415 | // pim_rp_setup (); | |
416 | return 0; | |
12e41d03 DL |
417 | } |
418 | ||
da11e325 | 419 | void sched_rpf_cache_refresh(struct pim_instance *pim) |
12e41d03 | 420 | { |
bfc92019 | 421 | ++pim->rpf_cache_refresh_requests; |
12e41d03 | 422 | |
bfc92019 | 423 | pim_rpf_set_refresh_time(pim); |
e71bf8f7 | 424 | |
da11e325 | 425 | if (pim->rpf_cache_refresher) { |
d62a17ae | 426 | /* Refresh timer is already running */ |
427 | return; | |
428 | } | |
12e41d03 | 429 | |
d62a17ae | 430 | /* Start refresh timer */ |
12e41d03 | 431 | |
d62a17ae | 432 | if (PIM_DEBUG_ZEBRA) { |
433 | zlog_debug("%s: triggering %ld msec timer", __PRETTY_FUNCTION__, | |
da03883e | 434 | router->rpf_cache_refresh_delay_msec); |
d62a17ae | 435 | } |
12e41d03 | 436 | |
36417fcc | 437 | thread_add_timer_msec(router->master, on_rpf_cache_refresh, pim, |
da03883e | 438 | router->rpf_cache_refresh_delay_msec, |
da11e325 | 439 | &pim->rpf_cache_refresher); |
12e41d03 DL |
440 | } |
441 | ||
d62a17ae | 442 | static void pim_zebra_connected(struct zclient *zclient) |
48e8451b | 443 | { |
d62a17ae | 444 | /* Send the client registration */ |
0945d5ed | 445 | bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER, router->vrf_id); |
ba4eb1bc | 446 | |
4dfe9ad2 | 447 | zclient_send_reg_requests(zclient, router->vrf_id); |
ecbbc3a7 AK |
448 | |
449 | /* request for VxLAN BUM group addresses */ | |
450 | pim_zebra_vxlan_replay(); | |
48e8451b | 451 | } |
8711a53d | 452 | |
ac567a6f DS |
453 | static void pim_zebra_capabilities(struct zclient_capabilities *cap) |
454 | { | |
d6749d74 | 455 | router->role = cap->role; |
ac567a6f DS |
456 | } |
457 | ||
eb05883f | 458 | void pim_zebra_init(void) |
12e41d03 | 459 | { |
d62a17ae | 460 | /* Socket for receiving updates from Zebra daemon */ |
36417fcc | 461 | zclient = zclient_new(router->master, &zclient_options_default); |
d62a17ae | 462 | |
ac567a6f | 463 | zclient->zebra_capabilities = pim_zebra_capabilities; |
d62a17ae | 464 | zclient->zebra_connected = pim_zebra_connected; |
465 | zclient->router_id_update = pim_router_id_update_zebra; | |
d62a17ae | 466 | zclient->interface_address_add = pim_zebra_if_address_add; |
467 | zclient->interface_address_delete = pim_zebra_if_address_del; | |
ee568318 | 468 | zclient->interface_vrf_update = pim_zebra_interface_vrf_update; |
d62a17ae | 469 | zclient->nexthop_update = pim_parse_nexthop_update; |
af7b561b AK |
470 | zclient->vxlan_sg_add = pim_zebra_vxlan_sg_proc; |
471 | zclient->vxlan_sg_del = pim_zebra_vxlan_sg_proc; | |
46c2687c SK |
472 | zclient->mlag_process_up = pim_zebra_mlag_process_up; |
473 | zclient->mlag_process_down = pim_zebra_mlag_process_down; | |
474 | zclient->mlag_handle_msg = pim_zebra_mlag_handle_msg; | |
d62a17ae | 475 | |
342213ea | 476 | zclient_init(zclient, ZEBRA_ROUTE_PIM, 0, &pimd_privs); |
d62a17ae | 477 | if (PIM_DEBUG_PIM_TRACE) { |
87270023 | 478 | zlog_notice("%s: zclient socket initialized", |
d62a17ae | 479 | __PRETTY_FUNCTION__); |
480 | } | |
481 | ||
482 | zclient_lookup_new(); | |
12e41d03 DL |
483 | } |
484 | ||
6f932b0c DS |
485 | void igmp_anysource_forward_start(struct pim_instance *pim, |
486 | struct igmp_group *group) | |
12e41d03 | 487 | { |
d62a17ae | 488 | struct igmp_source *source; |
489 | struct in_addr src_addr = {.s_addr = 0}; | |
490 | /* Any source (*,G) is forwarded only if mode is EXCLUDE {empty} */ | |
491 | zassert(group->group_filtermode_isexcl); | |
492 | zassert(listcount(group->group_source_list) < 1); | |
493 | ||
494 | source = source_new(group, src_addr); | |
495 | if (!source) { | |
496 | zlog_warn("%s: Failure to create * source", | |
497 | __PRETTY_FUNCTION__); | |
498 | return; | |
499 | } | |
500 | ||
6f932b0c | 501 | igmp_source_forward_start(pim, source); |
12e41d03 DL |
502 | } |
503 | ||
504 | void igmp_anysource_forward_stop(struct igmp_group *group) | |
505 | { | |
d62a17ae | 506 | struct igmp_source *source; |
507 | struct in_addr star = {.s_addr = 0}; | |
12e41d03 | 508 | |
d62a17ae | 509 | source = igmp_find_source_by_addr(group, star); |
510 | if (source) | |
511 | igmp_source_forward_stop(source); | |
12e41d03 DL |
512 | } |
513 | ||
6f439a70 DS |
514 | static void igmp_source_forward_reevaluate_one(struct pim_instance *pim, |
515 | struct igmp_source *source) | |
15a5dafe | 516 | { |
d62a17ae | 517 | struct prefix_sg sg; |
518 | struct igmp_group *group = source->source_group; | |
519 | struct pim_ifchannel *ch; | |
520 | ||
521 | if ((source->source_addr.s_addr != INADDR_ANY) | |
522 | || !IGMP_SOURCE_TEST_FORWARDING(source->source_flags)) | |
523 | return; | |
524 | ||
525 | memset(&sg, 0, sizeof(struct prefix_sg)); | |
526 | sg.src = source->source_addr; | |
527 | sg.grp = group->group_addr; | |
528 | ||
529 | ch = pim_ifchannel_find(group->group_igmp_sock->interface, &sg); | |
6f439a70 | 530 | if (pim_is_grp_ssm(pim, group->group_addr)) { |
d62a17ae | 531 | /* If SSM group withdraw local membership */ |
532 | if (ch | |
533 | && (ch->local_ifmembership == PIM_IFMEMBERSHIP_INCLUDE)) { | |
534 | if (PIM_DEBUG_PIM_EVENTS) | |
535 | zlog_debug( | |
536 | "local membership del for %s as G is now SSM", | |
537 | pim_str_sg_dump(&sg)); | |
538 | pim_ifchannel_local_membership_del( | |
539 | group->group_igmp_sock->interface, &sg); | |
540 | } | |
541 | } else { | |
542 | /* If ASM group add local membership */ | |
543 | if (!ch | |
544 | || (ch->local_ifmembership == PIM_IFMEMBERSHIP_NOINFO)) { | |
545 | if (PIM_DEBUG_PIM_EVENTS) | |
546 | zlog_debug( | |
547 | "local membership add for %s as G is now ASM", | |
548 | pim_str_sg_dump(&sg)); | |
549 | pim_ifchannel_local_membership_add( | |
550 | group->group_igmp_sock->interface, &sg); | |
551 | } | |
552 | } | |
15a5dafe | 553 | } |
554 | ||
5d59e408 | 555 | void igmp_source_forward_reevaluate_all(struct pim_instance *pim) |
15a5dafe | 556 | { |
d62a17ae | 557 | struct interface *ifp; |
558 | ||
5d59e408 DS |
559 | FOR_ALL_INTERFACES (pim->vrf, ifp) { |
560 | struct pim_interface *pim_ifp = ifp->info; | |
561 | struct listnode *sock_node; | |
562 | struct igmp_sock *igmp; | |
563 | ||
564 | if (!pim_ifp) | |
d62a17ae | 565 | continue; |
566 | ||
5d59e408 DS |
567 | /* scan igmp sockets */ |
568 | for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, | |
569 | igmp)) { | |
570 | struct listnode *grpnode; | |
571 | struct igmp_group *grp; | |
572 | ||
573 | /* scan igmp groups */ | |
574 | for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, | |
575 | grpnode, grp)) { | |
576 | struct listnode *srcnode; | |
577 | struct igmp_source *src; | |
578 | ||
579 | /* scan group sources */ | |
580 | for (ALL_LIST_ELEMENTS_RO( | |
581 | grp->group_source_list, srcnode, | |
582 | src)) { | |
583 | igmp_source_forward_reevaluate_one(pim, | |
584 | src); | |
585 | } /* scan group sources */ | |
586 | } /* scan igmp groups */ | |
587 | } /* scan igmp sockets */ | |
588 | } /* scan interfaces */ | |
15a5dafe | 589 | } |
590 | ||
6f932b0c DS |
591 | void igmp_source_forward_start(struct pim_instance *pim, |
592 | struct igmp_source *source) | |
12e41d03 | 593 | { |
75c61a18 | 594 | struct pim_interface *pim_oif; |
d62a17ae | 595 | struct igmp_group *group; |
596 | struct prefix_sg sg; | |
597 | int result; | |
598 | int input_iface_vif_index = 0; | |
599 | ||
600 | memset(&sg, 0, sizeof(struct prefix_sg)); | |
601 | sg.src = source->source_addr; | |
602 | sg.grp = source->source_group->group_addr; | |
603 | ||
604 | if (PIM_DEBUG_IGMP_TRACE) { | |
605 | zlog_debug( | |
606 | "%s: (S,G)=%s igmp_sock=%d oif=%s fwd=%d", | |
607 | __PRETTY_FUNCTION__, pim_str_sg_dump(&sg), | |
608 | source->source_group->group_igmp_sock->fd, | |
609 | source->source_group->group_igmp_sock->interface->name, | |
610 | IGMP_SOURCE_TEST_FORWARDING(source->source_flags)); | |
611 | } | |
612 | ||
613 | /* Prevent IGMP interface from installing multicast route multiple | |
614 | times */ | |
615 | if (IGMP_SOURCE_TEST_FORWARDING(source->source_flags)) { | |
616 | return; | |
8711a53d | 617 | } |
d62a17ae | 618 | |
619 | group = source->source_group; | |
75c61a18 DS |
620 | pim_oif = group->group_igmp_sock->interface->info; |
621 | if (!pim_oif) { | |
622 | if (PIM_DEBUG_IGMP_TRACE) { | |
623 | zlog_debug( | |
624 | "%s: multicast not enabled on oif=%s ?", | |
625 | __PRETTY_FUNCTION__, | |
626 | source->source_group->group_igmp_sock | |
627 | ->interface->name); | |
628 | } | |
629 | return; | |
630 | } | |
d62a17ae | 631 | |
632 | if (!source->source_channel_oil) { | |
633 | struct in_addr vif_source; | |
d1a1b09c | 634 | struct prefix src, grp; |
d62a17ae | 635 | struct pim_nexthop nexthop; |
636 | struct pim_upstream *up = NULL; | |
637 | ||
6f932b0c | 638 | if (!pim_rp_set_upstream_addr(pim, &vif_source, |
732c209c SP |
639 | source->source_addr, sg.grp)) { |
640 | /*Create a dummy channel oil */ | |
8a3e7e9e | 641 | source->source_channel_oil = pim_channel_oil_add( |
7984af18 | 642 | pim, &sg, __PRETTY_FUNCTION__); |
732c209c | 643 | } |
d62a17ae | 644 | |
732c209c | 645 | else { |
732c209c SP |
646 | src.family = AF_INET; |
647 | src.prefixlen = IPV4_MAX_BITLEN; | |
648 | src.u.prefix4 = vif_source; // RP or Src address | |
649 | grp.family = AF_INET; | |
650 | grp.prefixlen = IPV4_MAX_BITLEN; | |
651 | grp.u.prefix4 = sg.grp; | |
652 | ||
43763b11 DS |
653 | up = pim_upstream_find(pim, &sg); |
654 | if (up) { | |
655 | memcpy(&nexthop, &up->rpf.source_nexthop, | |
656 | sizeof(struct pim_nexthop)); | |
657 | pim_ecmp_nexthop_lookup(pim, &nexthop, &src, | |
658 | &grp, 0); | |
659 | if (nexthop.interface) | |
660 | input_iface_vif_index = | |
d62a17ae | 661 | pim_if_find_vifindex_by_ifindex( |
43763b11 DS |
662 | pim, |
663 | nexthop.interface->ifindex); | |
732c209c SP |
664 | } else |
665 | input_iface_vif_index = | |
43763b11 DS |
666 | pim_ecmp_fib_lookup_if_vif_index( |
667 | pim, &src, &grp); | |
d62a17ae | 668 | |
732c209c SP |
669 | if (PIM_DEBUG_ZEBRA) { |
670 | char buf2[INET_ADDRSTRLEN]; | |
d62a17ae | 671 | |
732c209c SP |
672 | pim_inet4_dump("<source?>", vif_source, buf2, |
673 | sizeof(buf2)); | |
674 | zlog_debug("%s: NHT %s vif_source %s vif_index:%d ", | |
d62a17ae | 675 | __PRETTY_FUNCTION__, |
676 | pim_str_sg_dump(&sg), | |
732c209c | 677 | buf2, input_iface_vif_index); |
d62a17ae | 678 | } |
d62a17ae | 679 | |
732c209c SP |
680 | if (input_iface_vif_index < 1) { |
681 | if (PIM_DEBUG_IGMP_TRACE) { | |
682 | char source_str[INET_ADDRSTRLEN]; | |
683 | pim_inet4_dump("<source?>", | |
684 | source->source_addr, | |
685 | source_str, sizeof(source_str)); | |
686 | zlog_debug( | |
687 | "%s %s: could not find input interface for source %s", | |
688 | __FILE__, __PRETTY_FUNCTION__, | |
689 | source_str); | |
690 | } | |
691 | source->source_channel_oil = | |
8a3e7e9e | 692 | pim_channel_oil_add( |
7984af18 | 693 | pim, &sg, |
8a3e7e9e | 694 | __PRETTY_FUNCTION__); |
732c209c SP |
695 | } |
696 | ||
697 | else { | |
698 | /* | |
699 | * Protect IGMP against adding looped MFC | |
700 | * entries created by both source and receiver | |
701 | * attached to the same interface. See TODO | |
50d06d9e | 702 | * T22. Block only when the intf is non DR |
703 | * DR must create upstream. | |
732c209c | 704 | */ |
50d06d9e | 705 | if ((input_iface_vif_index == |
706 | pim_oif->mroute_vif_index) && | |
707 | !(PIM_I_am_DR(pim_oif))) { | |
732c209c SP |
708 | /* ignore request for looped MFC entry |
709 | */ | |
710 | if (PIM_DEBUG_IGMP_TRACE) { | |
711 | zlog_debug( | |
712 | "%s: ignoring request for looped MFC entry (S,G)=%s: igmp_sock=%d oif=%s vif_index=%d", | |
713 | __PRETTY_FUNCTION__, | |
714 | pim_str_sg_dump(&sg), | |
715 | source->source_group | |
716 | ->group_igmp_sock->fd, | |
717 | source->source_group | |
718 | ->group_igmp_sock | |
719 | ->interface->name, | |
720 | input_iface_vif_index); | |
721 | } | |
722 | return; | |
723 | } | |
724 | ||
725 | source->source_channel_oil = | |
8a3e7e9e | 726 | pim_channel_oil_add( |
7984af18 | 727 | pim, &sg, |
8a3e7e9e | 728 | __PRETTY_FUNCTION__); |
732c209c SP |
729 | if (!source->source_channel_oil) { |
730 | if (PIM_DEBUG_IGMP_TRACE) { | |
731 | zlog_debug( | |
732 | "%s %s: could not create OIL for channel (S,G)=%s", | |
733 | __FILE__, | |
734 | __PRETTY_FUNCTION__, | |
735 | pim_str_sg_dump(&sg)); | |
736 | } | |
737 | return; | |
738 | } | |
d62a17ae | 739 | } |
d62a17ae | 740 | } |
8711a53d | 741 | } |
d62a17ae | 742 | |
8e389ea9 DS |
743 | if (PIM_I_am_DR(pim_oif)) { |
744 | result = pim_channel_add_oif(source->source_channel_oil, | |
745 | group->group_igmp_sock->interface, | |
1b249e70 | 746 | PIM_OIF_FLAG_PROTO_IGMP, __func__); |
8e389ea9 DS |
747 | if (result) { |
748 | if (PIM_DEBUG_MROUTE) { | |
749 | zlog_warn("%s: add_oif() failed with return=%d", | |
750 | __func__, result); | |
751 | } | |
752 | return; | |
d62a17ae | 753 | } |
8e389ea9 | 754 | } else { |
90a084e4 DS |
755 | if (PIM_DEBUG_IGMP_TRACE) |
756 | zlog_debug("%s: %s was received on %s interface but we are not DR for that interface", | |
757 | __PRETTY_FUNCTION__, | |
758 | pim_str_sg_dump(&sg), | |
759 | group->group_igmp_sock->interface->name); | |
b96892db | 760 | |
75c61a18 | 761 | return; |
90a084e4 | 762 | } |
d62a17ae | 763 | /* |
764 | Feed IGMPv3-gathered local membership information into PIM | |
765 | per-interface (S,G) state. | |
766 | */ | |
767 | if (!pim_ifchannel_local_membership_add( | |
75c61a18 | 768 | group->group_igmp_sock->interface, &sg)) { |
d62a17ae | 769 | if (PIM_DEBUG_MROUTE) |
770 | zlog_warn("%s: Failure to add local membership for %s", | |
771 | __PRETTY_FUNCTION__, pim_str_sg_dump(&sg)); | |
b96892db DS |
772 | |
773 | pim_channel_del_oif(source->source_channel_oil, | |
774 | group->group_igmp_sock->interface, | |
1b249e70 | 775 | PIM_OIF_FLAG_PROTO_IGMP, __func__); |
d62a17ae | 776 | return; |
777 | } | |
778 | ||
779 | IGMP_SOURCE_DO_FORWARDING(source->source_flags); | |
12e41d03 DL |
780 | } |
781 | ||
782 | /* | |
783 | igmp_source_forward_stop: stop fowarding, but keep the source | |
784 | igmp_source_delete: stop fowarding, and delete the source | |
785 | */ | |
786 | void igmp_source_forward_stop(struct igmp_source *source) | |
787 | { | |
d62a17ae | 788 | struct igmp_group *group; |
789 | struct prefix_sg sg; | |
790 | int result; | |
791 | ||
792 | memset(&sg, 0, sizeof(struct prefix_sg)); | |
793 | sg.src = source->source_addr; | |
794 | sg.grp = source->source_group->group_addr; | |
795 | ||
796 | if (PIM_DEBUG_IGMP_TRACE) { | |
797 | zlog_debug( | |
798 | "%s: (S,G)=%s igmp_sock=%d oif=%s fwd=%d", | |
799 | __PRETTY_FUNCTION__, pim_str_sg_dump(&sg), | |
800 | source->source_group->group_igmp_sock->fd, | |
801 | source->source_group->group_igmp_sock->interface->name, | |
802 | IGMP_SOURCE_TEST_FORWARDING(source->source_flags)); | |
803 | } | |
804 | ||
805 | /* Prevent IGMP interface from removing multicast route multiple | |
806 | times */ | |
807 | if (!IGMP_SOURCE_TEST_FORWARDING(source->source_flags)) { | |
808 | return; | |
809 | } | |
810 | ||
811 | group = source->source_group; | |
812 | ||
813 | /* | |
814 | It appears that in certain circumstances that | |
815 | igmp_source_forward_stop is called when IGMP forwarding | |
816 | was not enabled in oif_flags for this outgoing interface. | |
817 | Possibly because of multiple calls. When that happens, we | |
818 | enter the below if statement and this function returns early | |
819 | which in turn triggers the calling function to assert. | |
820 | Making the call to pim_channel_del_oif and ignoring the return code | |
821 | fixes the issue without ill effect, similar to | |
822 | pim_forward_stop below. | |
823 | */ | |
824 | result = pim_channel_del_oif(source->source_channel_oil, | |
825 | group->group_igmp_sock->interface, | |
1b249e70 AK |
826 | PIM_OIF_FLAG_PROTO_IGMP, |
827 | __func__); | |
d62a17ae | 828 | if (result) { |
829 | if (PIM_DEBUG_IGMP_TRACE) | |
830 | zlog_debug( | |
831 | "%s: pim_channel_del_oif() failed with return=%d", | |
832 | __func__, result); | |
833 | return; | |
834 | } | |
835 | ||
836 | /* | |
837 | Feed IGMPv3-gathered local membership information into PIM | |
838 | per-interface (S,G) state. | |
839 | */ | |
840 | pim_ifchannel_local_membership_del(group->group_igmp_sock->interface, | |
841 | &sg); | |
842 | ||
843 | IGMP_SOURCE_DONT_FORWARDING(source->source_flags); | |
12e41d03 DL |
844 | } |
845 | ||
846 | void pim_forward_start(struct pim_ifchannel *ch) | |
847 | { | |
d62a17ae | 848 | struct pim_upstream *up = ch->upstream; |
849 | uint32_t mask = PIM_OIF_FLAG_PROTO_PIM; | |
d62a17ae | 850 | |
851 | if (PIM_DEBUG_PIM_TRACE) { | |
852 | char source_str[INET_ADDRSTRLEN]; | |
853 | char group_str[INET_ADDRSTRLEN]; | |
854 | char upstream_str[INET_ADDRSTRLEN]; | |
855 | ||
856 | pim_inet4_dump("<source?>", ch->sg.src, source_str, | |
857 | sizeof(source_str)); | |
858 | pim_inet4_dump("<group?>", ch->sg.grp, group_str, | |
859 | sizeof(group_str)); | |
860 | pim_inet4_dump("<upstream?>", up->upstream_addr, upstream_str, | |
861 | sizeof(upstream_str)); | |
862 | zlog_debug("%s: (S,G)=(%s,%s) oif=%s (%s)", __PRETTY_FUNCTION__, | |
863 | source_str, group_str, ch->interface->name, | |
732c209c | 864 | inet_ntoa(up->upstream_addr)); |
d62a17ae | 865 | } |
866 | ||
d62a17ae | 867 | if (up->flags & PIM_UPSTREAM_FLAG_MASK_SRC_IGMP) |
868 | mask = PIM_OIF_FLAG_PROTO_IGMP; | |
869 | ||
1b249e70 AK |
870 | pim_channel_add_oif(up->channel_oil, ch->interface, |
871 | mask, __func__); | |
12e41d03 DL |
872 | } |
873 | ||
aabb9a2f | 874 | void pim_forward_stop(struct pim_ifchannel *ch, bool install_it) |
12e41d03 | 875 | { |
d62a17ae | 876 | struct pim_upstream *up = ch->upstream; |
12e41d03 | 877 | |
d62a17ae | 878 | if (PIM_DEBUG_PIM_TRACE) { |
aabb9a2f DS |
879 | zlog_debug("%s: (S,G)=%s oif=%s install_it: %d installed: %d", |
880 | __PRETTY_FUNCTION__, ch->sg_str, ch->interface->name, | |
881 | install_it, up->channel_oil->installed); | |
d62a17ae | 882 | } |
12e41d03 | 883 | |
2164ed5d DS |
884 | /* |
885 | * If a channel is being removed, check to see if we still need | |
886 | * to inherit the interface. If so make sure it is added in | |
887 | */ | |
888 | if (pim_upstream_evaluate_join_desired_interface(up, ch, ch->parent)) | |
889 | pim_channel_add_oif(up->channel_oil, ch->interface, | |
1b249e70 | 890 | PIM_OIF_FLAG_PROTO_PIM, __func__); |
2164ed5d DS |
891 | else |
892 | pim_channel_del_oif(up->channel_oil, ch->interface, | |
1b249e70 | 893 | PIM_OIF_FLAG_PROTO_PIM, __func__); |
aabb9a2f DS |
894 | |
895 | if (install_it && !up->channel_oil->installed) | |
69e3538c | 896 | pim_upstream_mroute_add(up->channel_oil, __PRETTY_FUNCTION__); |
12e41d03 | 897 | } |
8799b66b | 898 | |
d62a17ae | 899 | void pim_zebra_zclient_update(struct vty *vty) |
8799b66b | 900 | { |
d62a17ae | 901 | vty_out(vty, "Zclient update socket: "); |
902 | ||
903 | if (zclient) { | |
904 | vty_out(vty, "%d failures=%d\n", zclient->sock, zclient->fail); | |
905 | } else { | |
906 | vty_out(vty, "<null zclient>\n"); | |
907 | } | |
8799b66b | 908 | } |
1bc98276 | 909 | |
d62a17ae | 910 | struct zclient *pim_zebra_zclient_get(void) |
1bc98276 | 911 | { |
d62a17ae | 912 | if (zclient) |
913 | return zclient; | |
914 | else | |
915 | return NULL; | |
1bc98276 | 916 | } |
ddbf3e60 DS |
917 | |
918 | void pim_zebra_interface_set_master(struct interface *vrf, | |
919 | struct interface *ifp) | |
920 | { | |
921 | zclient_interface_set_master(zclient, vrf, ifp); | |
922 | } |