]> git.proxmox.com Git - mirror_frr.git/blame - pimd/pim_upstream.c
Merge pull request #451 from opensourcerouting/ospfd-fix-cmdstr
[mirror_frr.git] / pimd / pim_upstream.c
CommitLineData
12e41d03
DL
1/*
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
16 along with this program; see the file COPYING; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
18 MA 02110-1301 USA
12e41d03
DL
19*/
20
21#include <zebra.h>
22
23#include "zebra/rib.h"
24
25#include "log.h"
26#include "zclient.h"
27#include "memory.h"
28#include "thread.h"
29#include "linklist.h"
dfe43e25
DW
30#include "vty.h"
31#include "plist.h"
0f588989
DS
32#include "hash.h"
33#include "jhash.h"
9c5e4d62 34#include "wheel.h"
12e41d03
DL
35
36#include "pimd.h"
37#include "pim_pim.h"
38#include "pim_str.h"
39#include "pim_time.h"
40#include "pim_iface.h"
41#include "pim_join.h"
42#include "pim_zlookup.h"
43#include "pim_upstream.h"
44#include "pim_ifchannel.h"
45#include "pim_neighbor.h"
46#include "pim_rpf.h"
47#include "pim_zebra.h"
48#include "pim_oil.h"
49#include "pim_macro.h"
8f5f5e91 50#include "pim_rp.h"
f14248dd 51#include "pim_br.h"
627ed2a3 52#include "pim_register.h"
3c72d654 53#include "pim_msdp.h"
982bff89 54#include "pim_jp_agg.h"
1bc98276 55#include "pim_nht.h"
15a5dafe 56#include "pim_ssm.h"
12e41d03 57
0f588989
DS
58struct hash *pim_upstream_hash = NULL;
59struct list *pim_upstream_list = NULL;
9c5e4d62 60struct timer_wheel *pim_upstream_sg_wheel = NULL;
0f588989 61
982bff89 62static void join_timer_stop(struct pim_upstream *up);
12e41d03
DL
63static void pim_upstream_update_assert_tracking_desired(struct pim_upstream *up);
64
cfa91a87
DS
65/*
66 * A (*,G) or a (*,*) is going away
67 * remove the parent pointer from
68 * those pointing at us
69 */
70static void
71pim_upstream_remove_children (struct pim_upstream *up)
72{
cfa91a87
DS
73 struct pim_upstream *child;
74
03417ccd 75 if (!up->sources)
cfa91a87
DS
76 return;
77
03417ccd 78 while (!list_isempty (up->sources))
cfa91a87 79 {
03417ccd
DS
80 child = listnode_head (up->sources);
81 child->parent = NULL;
82 listnode_delete (up->sources, child);
cfa91a87
DS
83 }
84}
85
86/*
87 * A (*,G) or a (*,*) is being created
88 * Find the children that would point
89 * at us.
90 */
91static void
92pim_upstream_find_new_children (struct pim_upstream *up)
93{
94 struct pim_upstream *child;
95 struct listnode *ch_node;
96
4ed0af70
DS
97 if ((up->sg.src.s_addr != INADDR_ANY) &&
98 (up->sg.grp.s_addr != INADDR_ANY))
cfa91a87
DS
99 return;
100
4ed0af70
DS
101 if ((up->sg.src.s_addr == INADDR_ANY) &&
102 (up->sg.grp.s_addr == INADDR_ANY))
cfa91a87
DS
103 return;
104
0f588989 105 for (ALL_LIST_ELEMENTS_RO (pim_upstream_list, ch_node, child))
cfa91a87 106 {
4ed0af70 107 if ((up->sg.grp.s_addr != INADDR_ANY) &&
0f588989 108 (child->sg.grp.s_addr == up->sg.grp.s_addr) &&
cfa91a87 109 (child != up))
03417ccd
DS
110 {
111 child->parent = up;
112 listnode_add_sort (up->sources, child);
113 }
cfa91a87
DS
114 }
115}
116
4d99418b
DS
117/*
118 * If we have a (*,*) || (S,*) there is no parent
119 * If we have a (S,G), find the (*,G)
120 * If we have a (*,G), find the (*,*)
121 */
122static struct pim_upstream *
03417ccd 123pim_upstream_find_parent (struct pim_upstream *child)
4d99418b 124{
03417ccd
DS
125 struct prefix_sg any = child->sg;
126 struct pim_upstream *up = NULL;
4d99418b
DS
127
128 // (S,G)
03417ccd
DS
129 if ((child->sg.src.s_addr != INADDR_ANY) &&
130 (child->sg.grp.s_addr != INADDR_ANY))
4d99418b 131 {
4ed0af70 132 any.src.s_addr = INADDR_ANY;
03417ccd
DS
133 up = pim_upstream_find (&any);
134
135 if (up)
136 listnode_add (up->sources, child);
137
138 return up;
4d99418b
DS
139 }
140
03417ccd 141 return NULL;
4d99418b
DS
142}
143
12e41d03
DL
144void pim_upstream_free(struct pim_upstream *up)
145{
146 XFREE(MTYPE_PIM_UPSTREAM, up);
1bc98276 147 up = NULL;
12e41d03
DL
148}
149
150static void upstream_channel_oil_detach(struct pim_upstream *up)
151{
152 if (up->channel_oil) {
153 pim_channel_oil_del(up->channel_oil);
25a335e0 154 up->channel_oil = NULL;
12e41d03
DL
155 }
156}
157
d0db90bf 158struct pim_upstream *
e5905a3b 159pim_upstream_del(struct pim_upstream *up, const char *name)
12e41d03 160{
7667c556 161 bool notify_msdp = false;
1bc98276 162 struct prefix nht_p;
7667c556 163
3197cb1e 164 if (PIM_DEBUG_TRACE)
7eb90689
DS
165 zlog_debug ("%s(%s): Delete %s ref count: %d, flags: %d (Pre decrement)",
166 __PRETTY_FUNCTION__, name, up->sg_str, up->ref_count, up->flags);
3197cb1e 167
e5905a3b
DS
168 --up->ref_count;
169
170 if (up->ref_count >= 1)
d0db90bf 171 return up;
e5905a3b 172
f14248dd 173 THREAD_OFF(up->t_ka_timer);
792f4d29 174 THREAD_OFF(up->t_rs_timer);
1bf16443 175 THREAD_OFF(up->t_msdp_reg_timer);
12e41d03 176
7667c556 177 if (up->join_state == PIM_UPSTREAM_JOINED) {
982bff89
DS
178 pim_jp_agg_single_upstream_send (&up->rpf, up, 0);
179
7667c556 180 if (up->sg.src.s_addr == INADDR_ANY) {
181 /* if a (*, G) entry in the joined state is being deleted we
182 * need to notify MSDP */
183 notify_msdp = true;
184 }
185 }
186
fc9d070d 187 join_timer_stop(up);
06e12762 188 pim_jp_agg_upstream_verification (up, false);
fc9d070d
DS
189 up->rpf.source_nexthop.interface = NULL;
190
36e466fe 191 if (up->sg.src.s_addr != INADDR_ANY) {
9c5e4d62 192 wheel_remove_item (pim_upstream_sg_wheel, up);
36e466fe 193 notify_msdp = true;
194 }
9c5e4d62 195
cfa91a87 196 pim_upstream_remove_children (up);
6a78764e 197 pim_mroute_del (up->channel_oil, __PRETTY_FUNCTION__);
12e41d03
DL
198 upstream_channel_oil_detach(up);
199
03417ccd 200 if (up->sources)
850a9f99
DS
201 {
202 struct listnode *node, *nnode;
203 struct pim_upstream *child;
204 for (ALL_LIST_ELEMENTS (up->sources, node, nnode, child))
205 {
206 if (PIM_UPSTREAM_FLAG_TEST_SRC_LHR(child->flags))
207 {
208 PIM_UPSTREAM_FLAG_UNSET_SRC_LHR(child->flags);
209 pim_upstream_del(child, __PRETTY_FUNCTION__);
210 }
211 }
212
213 list_delete (up->sources);
214 }
03417ccd
DS
215 up->sources = NULL;
216
2a28f7a0
DS
217 list_delete (up->ifchannels);
218
12e41d03
DL
219 /*
220 notice that listnode_delete() can't be moved
221 into pim_upstream_free() because the later is
222 called by list_delete_all_node()
223 */
03417ccd
DS
224 if (up->parent)
225 {
226 listnode_delete (up->parent->sources, up);
227 up->parent = NULL;
228 }
0f588989
DS
229 listnode_delete (pim_upstream_list, up);
230 hash_release (pim_upstream_hash, up);
12e41d03 231
1bc98276
CS
232 if (notify_msdp)
233 {
234 pim_msdp_up_del (&up->sg);
235 }
236
237 /* Deregister addr with Zebra NHT */
238 nht_p.family = AF_INET;
239 nht_p.prefixlen = IPV4_MAX_BITLEN;
240 nht_p.u.prefix4 = up->upstream_addr;
241 if (PIM_DEBUG_TRACE)
242 {
243 char buf[PREFIX2STR_BUFFER];
244 prefix2str (&nht_p, buf, sizeof (buf));
633988a7
CS
245 zlog_debug ("%s: Deregister upstream %s addr %s with Zebra",
246 __PRETTY_FUNCTION__, up->sg_str, buf);
1bc98276
CS
247 }
248 pim_delete_tracked_nexthop (&nht_p, up, NULL);
249
250 pim_upstream_free (up);
d0db90bf
DS
251
252 return NULL;
12e41d03
DL
253}
254
56638739
DS
255void
256pim_upstream_send_join (struct pim_upstream *up)
12e41d03 257{
3197cb1e 258 if (PIM_DEBUG_TRACE) {
eaa54bdb 259 char rpf_str[PREFIX_STRLEN];
63c59d0c 260 pim_addr_dump("<rpf?>", &up->rpf.rpf_addr, rpf_str, sizeof(rpf_str));
05e451f8 261 zlog_debug ("%s: RPF'%s=%s(%s) for Interface %s", __PRETTY_FUNCTION__,
8bfb8b67 262 up->sg_str, rpf_str, pim_upstream_state2str (up->join_state),
56638739 263 up->rpf.source_nexthop.interface->name);
63c59d0c 264 if (pim_rpf_addr_is_inaddr_any(&up->rpf)) {
05e451f8 265 zlog_debug("%s: can't send join upstream: RPF'%s=%s",
56638739 266 __PRETTY_FUNCTION__,
8bfb8b67 267 up->sg_str, rpf_str);
12e41d03
DL
268 /* warning only */
269 }
270 }
56638739 271
12e41d03 272 /* send Join(S,G) to the current upstream neighbor */
982bff89 273 pim_jp_agg_single_upstream_send(&up->rpf, up, 1 /* join */);
12e41d03
DL
274}
275
276static int on_join_timer(struct thread *t)
277{
278 struct pim_upstream *up;
279
12e41d03 280 up = THREAD_ARG(t);
12e41d03 281
bb6e291f
DS
282 up->t_join_timer = NULL;
283
284 /*
285 * In the case of a HFR we will not ahve anyone to send this to.
286 */
0bf27c5c 287 if (PIM_UPSTREAM_FLAG_TEST_FHR(up->flags))
bb6e291f
DS
288 return 0;
289
eb345962
DS
290 /*
291 * Don't send the join if the outgoing interface is a loopback
292 * But since this might change leave the join timer running
293 */
fc9d070d
DS
294 if (up->rpf.source_nexthop.interface &&
295 !if_is_loopback (up->rpf.source_nexthop.interface))
eb345962 296 pim_upstream_send_join (up);
12e41d03 297
12e41d03
DL
298 join_timer_start(up);
299
300 return 0;
301}
302
982bff89 303static void join_timer_stop(struct pim_upstream *up)
12e41d03 304{
982bff89
DS
305 struct pim_neighbor *nbr;
306
7eb90689
DS
307 THREAD_OFF (up->t_join_timer);
308
982bff89
DS
309 nbr = pim_neighbor_find (up->rpf.source_nexthop.interface,
310 up->rpf.rpf_addr.u.prefix4);
311
312 if (nbr)
313 pim_jp_agg_remove_group (nbr->upstream_jp_agg, up);
314
06e12762 315 pim_jp_agg_upstream_verification (up, false);
982bff89
DS
316}
317
318void
319join_timer_start(struct pim_upstream *up)
320{
fc9d070d 321 struct pim_neighbor *nbr = NULL;
982bff89 322
fc9d070d
DS
323 if (up->rpf.source_nexthop.interface)
324 {
325 nbr = pim_neighbor_find (up->rpf.source_nexthop.interface,
326 up->rpf.rpf_addr.u.prefix4);
327
328 if (PIM_DEBUG_PIM_EVENTS) {
329 zlog_debug("%s: starting %d sec timer for upstream (S,G)=%s",
330 __PRETTY_FUNCTION__,
331 qpim_t_periodic,
332 up->sg_str);
333 }
334 }
12e41d03 335
982bff89
DS
336 if (nbr)
337 pim_jp_agg_add_group (nbr->upstream_jp_agg, up, 1);
338 else
339 {
340 THREAD_OFF (up->t_join_timer);
341 THREAD_TIMER_ON(master, up->t_join_timer,
342 on_join_timer,
343 up, qpim_t_periodic);
344 }
06e12762 345 pim_jp_agg_upstream_verification (up, true);
12e41d03
DL
346}
347
982bff89
DS
348/*
349 * This is only called when we are switching the upstream
350 * J/P from one neighbor to another
351 *
352 * As such we need to remove from the old list and
353 * add to the new list.
354 */
355void pim_upstream_join_timer_restart(struct pim_upstream *up, struct pim_rpf *old)
12e41d03 356{
982bff89 357 //THREAD_OFF(up->t_join_timer);
12e41d03
DL
358 join_timer_start(up);
359}
360
361static void pim_upstream_join_timer_restart_msec(struct pim_upstream *up,
362 int interval_msec)
363{
364 if (PIM_DEBUG_PIM_EVENTS) {
05e451f8 365 zlog_debug("%s: restarting %d msec timer for upstream (S,G)=%s",
12e41d03
DL
366 __PRETTY_FUNCTION__,
367 interval_msec,
8bfb8b67 368 up->sg_str);
12e41d03
DL
369 }
370
371 THREAD_OFF(up->t_join_timer);
372 THREAD_TIMER_MSEC_ON(master, up->t_join_timer,
373 on_join_timer,
374 up, interval_msec);
375}
376
377void pim_upstream_join_suppress(struct pim_upstream *up,
378 struct in_addr rpf_addr,
379 int holdtime)
380{
381 long t_joinsuppress_msec;
382 long join_timer_remain_msec;
383
384 t_joinsuppress_msec = MIN(pim_if_t_suppressed_msec(up->rpf.source_nexthop.interface),
385 1000 * holdtime);
386
387 join_timer_remain_msec = pim_time_timer_remain_msec(up->t_join_timer);
388
3197cb1e 389 if (PIM_DEBUG_TRACE) {
eaa54bdb 390 char rpf_str[INET_ADDRSTRLEN];
12e41d03 391 pim_inet4_dump("<rpf?>", rpf_addr, rpf_str, sizeof(rpf_str));
05e451f8 392 zlog_debug("%s %s: detected Join%s to RPF'(S,G)=%s: join_timer=%ld msec t_joinsuppress=%ld msec",
12e41d03 393 __FILE__, __PRETTY_FUNCTION__,
8bfb8b67 394 up->sg_str,
12e41d03
DL
395 rpf_str,
396 join_timer_remain_msec, t_joinsuppress_msec);
397 }
398
399 if (join_timer_remain_msec < t_joinsuppress_msec) {
3197cb1e 400 if (PIM_DEBUG_TRACE) {
05e451f8 401 zlog_debug("%s %s: suppressing Join(S,G)=%s for %ld msec",
12e41d03 402 __FILE__, __PRETTY_FUNCTION__,
8bfb8b67 403 up->sg_str, t_joinsuppress_msec);
12e41d03
DL
404 }
405
406 pim_upstream_join_timer_restart_msec(up, t_joinsuppress_msec);
407 }
408}
409
410void pim_upstream_join_timer_decrease_to_t_override(const char *debug_label,
c48a612c 411 struct pim_upstream *up)
12e41d03
DL
412{
413 long join_timer_remain_msec;
414 int t_override_msec;
415
416 join_timer_remain_msec = pim_time_timer_remain_msec(up->t_join_timer);
417 t_override_msec = pim_if_t_override_msec(up->rpf.source_nexthop.interface);
418
3197cb1e 419 if (PIM_DEBUG_TRACE) {
eaa54bdb 420 char rpf_str[INET_ADDRSTRLEN];
c48a612c 421 pim_inet4_dump("<rpf?>", up->rpf.rpf_addr.u.prefix4, rpf_str, sizeof(rpf_str));
05e451f8 422 zlog_debug("%s: to RPF'%s=%s: join_timer=%ld msec t_override=%d msec",
12e41d03 423 debug_label,
8bfb8b67 424 up->sg_str, rpf_str,
12e41d03
DL
425 join_timer_remain_msec, t_override_msec);
426 }
427
428 if (join_timer_remain_msec > t_override_msec) {
3197cb1e 429 if (PIM_DEBUG_TRACE) {
05e451f8 430 zlog_debug("%s: decreasing (S,G)=%s join timer to t_override=%d msec",
12e41d03 431 debug_label,
8bfb8b67 432 up->sg_str,
12e41d03
DL
433 t_override_msec);
434 }
435
436 pim_upstream_join_timer_restart_msec(up, t_override_msec);
437 }
438}
439
440static void forward_on(struct pim_upstream *up)
441{
12e41d03
DL
442 struct listnode *chnode;
443 struct listnode *chnextnode;
b5e6281b 444 struct pim_ifchannel *ch = NULL;
12e41d03 445
ea4a71fc 446 /* scan (S,G) state */
b5e6281b 447 for (ALL_LIST_ELEMENTS(up->ifchannels, chnode, chnextnode, ch)) {
ea4a71fc
DS
448 if (pim_macro_chisin_oiflist(ch))
449 pim_forward_start(ch);
12e41d03 450
ea4a71fc 451 } /* scan iface channel list */
12e41d03
DL
452}
453
454static void forward_off(struct pim_upstream *up)
455{
12e41d03
DL
456 struct listnode *chnode;
457 struct listnode *chnextnode;
12e41d03
DL
458 struct pim_ifchannel *ch;
459
ea4a71fc 460 /* scan per-interface (S,G) state */
b5e6281b 461 for (ALL_LIST_ELEMENTS(up->ifchannels, chnode, chnextnode, ch)) {
12e41d03 462
ea4a71fc 463 pim_forward_stop(ch);
12e41d03 464
ea4a71fc 465 } /* scan iface channel list */
12e41d03
DL
466}
467
bb6e291f
DS
468static int
469pim_upstream_could_register (struct pim_upstream *up)
470{
1131c2eb
CS
471 struct pim_interface *pim_ifp = NULL;
472
473 if (up->rpf.source_nexthop.interface)
474 pim_ifp = up->rpf.source_nexthop.interface->info;
475 else
476 {
477 if (PIM_DEBUG_TRACE)
478 zlog_debug ("%s: up %s RPF is not present", __PRETTY_FUNCTION__, up->sg_str);
479 }
bb6e291f 480
35917570 481 if (pim_ifp && PIM_I_am_DR (pim_ifp) &&
bb6e291f
DS
482 pim_if_connected_to_source (up->rpf.source_nexthop.interface, up->sg.src))
483 return 1;
484
485 return 0;
486}
487
15a5dafe 488/* Source registration is supressed for SSM groups. When the SSM range changes
489 * we re-revaluate register setup for existing upstream entries */
490void
491pim_upstream_register_reevaluate (void)
492{
493 struct listnode *upnode;
494 struct pim_upstream *up;
495
496 for (ALL_LIST_ELEMENTS_RO (pim_upstream_list, upnode, up))
497 {
498 /* If FHR is set CouldRegister is True. Also check if the flow
499 * is actually active; if it is not kat setup will trigger source
500 * registration whenever the flow becomes active. */
501 if (!PIM_UPSTREAM_FLAG_TEST_FHR (up->flags) || !up->t_ka_timer)
502 continue;
503
504 if (pim_is_grp_ssm (up->sg.grp))
505 {
506 /* clear the register state for SSM groups */
507 if (up->reg_state != PIM_REG_NOINFO)
508 {
509 if (PIM_DEBUG_PIM_EVENTS)
510 zlog_debug ("Clear register for %s as G is now SSM",
511 up->sg_str);
512 /* remove regiface from the OIL if it is there*/
513 pim_channel_del_oif (up->channel_oil, pim_regiface,
514 PIM_OIF_FLAG_PROTO_PIM);
515 up->reg_state = PIM_REG_NOINFO;
516 }
517 }
518 else
519 {
520 /* register ASM sources with the RP */
521 if (up->reg_state == PIM_REG_NOINFO)
522 {
523 if (PIM_DEBUG_PIM_EVENTS)
524 zlog_debug ("Register %s as G is now ASM", up->sg_str);
525 pim_channel_add_oif (up->channel_oil, pim_regiface,
526 PIM_OIF_FLAG_PROTO_PIM);
527 up->reg_state = PIM_REG_JOIN;
528 }
529 }
530 }
531}
532
7fcdfb34
DS
533void
534pim_upstream_switch(struct pim_upstream *up,
535 enum pim_upstream_state new_state)
12e41d03
DL
536{
537 enum pim_upstream_state old_state = up->join_state;
538
12e41d03 539 if (PIM_DEBUG_PIM_EVENTS) {
c9802954 540 zlog_debug("%s: PIM_UPSTREAM_%s: (S,G) old: %s new: %s",
12e41d03 541 __PRETTY_FUNCTION__,
8bfb8b67 542 up->sg_str,
c9802954
DS
543 pim_upstream_state2str (up->join_state),
544 pim_upstream_state2str (new_state));
12e41d03
DL
545 }
546
b4786acd 547 up->join_state = new_state;
548 if (old_state != new_state)
549 up->state_transition = pim_time_monotonic_sec();
bb027ee8 550
12e41d03
DL
551 pim_upstream_update_assert_tracking_desired(up);
552
553 if (new_state == PIM_UPSTREAM_JOINED) {
81900c5a
DS
554 if (old_state != PIM_UPSTREAM_JOINED)
555 {
0bf27c5c 556 int old_fhr = PIM_UPSTREAM_FLAG_TEST_FHR(up->flags);
81900c5a 557 forward_on(up);
7667c556 558 pim_msdp_up_join_state_changed(up);
0bf27c5c 559 if (pim_upstream_could_register (up))
bb6e291f 560 {
0bf27c5c 561 PIM_UPSTREAM_FLAG_SET_FHR(up->flags);
a9b59879 562 if (!old_fhr && PIM_UPSTREAM_FLAG_TEST_SRC_STREAM(up->flags))
bb6e291f
DS
563 {
564 pim_upstream_keep_alive_timer_start (up, qpim_keep_alive_time);
15a5dafe 565 pim_register_join (up);
bb6e291f
DS
566 }
567 }
568 else
569 {
570 pim_upstream_send_join (up);
571 join_timer_start (up);
572 }
81900c5a
DS
573 }
574 else
575 {
576 forward_on (up);
577 }
12e41d03
DL
578 }
579 else {
982bff89 580
12e41d03 581 forward_off(up);
7667c556 582 if (old_state == PIM_UPSTREAM_JOINED)
583 pim_msdp_up_join_state_changed(up);
982bff89
DS
584
585 pim_jp_agg_single_upstream_send(&up->rpf, up, 0 /* prune */);
586 join_timer_stop(up);
12e41d03 587 }
12e41d03
DL
588}
589
1bc98276 590int
03417ccd
DS
591pim_upstream_compare (void *arg1, void *arg2)
592{
593 const struct pim_upstream *up1 = (const struct pim_upstream *)arg1;
594 const struct pim_upstream *up2 = (const struct pim_upstream *)arg2;
595
596 if (ntohl(up1->sg.grp.s_addr) < ntohl(up2->sg.grp.s_addr))
597 return -1;
598
599 if (ntohl(up1->sg.grp.s_addr) > ntohl(up2->sg.grp.s_addr))
600 return 1;
601
602 if (ntohl(up1->sg.src.s_addr) < ntohl(up2->sg.src.s_addr))
603 return -1;
604
605 if (ntohl(up1->sg.src.s_addr) > ntohl(up2->sg.src.s_addr))
606 return 1;
607
608 return 0;
609}
610
07335c8d
DS
611static struct pim_upstream *
612pim_upstream_new (struct prefix_sg *sg,
613 struct interface *incoming,
614 int flags)
12e41d03 615{
2f702571 616 enum pim_rpf_result rpf_result;
07335c8d
DS
617 struct pim_interface *pim_ifp;
618 struct pim_upstream *up;
12e41d03 619
36d9e7dc 620 up = XCALLOC(MTYPE_PIM_UPSTREAM, sizeof(*up));
1bc98276
CS
621 if (!up)
622 {
623 zlog_err("%s: PIM XCALLOC(%zu) failure",
12e41d03 624 __PRETTY_FUNCTION__, sizeof(*up));
1bc98276
CS
625 return NULL;
626 }
12e41d03 627
5074a423 628 up->sg = *sg;
8bfb8b67 629 pim_str_sg_set (sg, up->sg_str);
0f588989 630 up = hash_get (pim_upstream_hash, up, hash_alloc_intern);
36d6bd7d 631 if (!pim_rp_set_upstream_addr (&up->upstream_addr, sg->src, sg->grp))
8f5f5e91 632 {
3197cb1e 633 if (PIM_DEBUG_TRACE)
8f5f5e91
DS
634 zlog_debug("%s: Received a (*,G) with no RP configured", __PRETTY_FUNCTION__);
635
03417ccd 636 hash_release (pim_upstream_hash, up);
8f5f5e91
DS
637 XFREE (MTYPE_PIM_UPSTREAM, up);
638 return NULL;
639 }
640
03417ccd
DS
641 up->parent = pim_upstream_find_parent (up);
642 if (up->sg.src.s_addr == INADDR_ANY)
643 {
644 up->sources = list_new ();
645 up->sources->cmp = pim_upstream_compare;
646 }
647 else
648 up->sources = NULL;
649
cfa91a87 650 pim_upstream_find_new_children (up);
4a40c37a 651 up->flags = flags;
12e41d03 652 up->ref_count = 1;
4a4c4a07
DS
653 up->t_join_timer = NULL;
654 up->t_ka_timer = NULL;
792f4d29 655 up->t_rs_timer = NULL;
1bf16443 656 up->t_msdp_reg_timer = NULL;
b4786acd 657 up->join_state = PIM_UPSTREAM_NOTJOINED;
0c2ebf00 658 up->reg_state = PIM_REG_NOINFO;
12e41d03 659 up->state_transition = pim_time_monotonic_sec();
4a4c4a07 660 up->channel_oil = NULL;
f9e0ab5b 661 up->sptbit = PIM_UPSTREAM_SPTBIT_FALSE;
12e41d03 662
f24405b1 663 up->rpf.source_nexthop.interface = NULL;
63c59d0c
DS
664 up->rpf.source_nexthop.mrib_nexthop_addr.family = AF_INET;
665 up->rpf.source_nexthop.mrib_nexthop_addr.u.prefix4.s_addr = PIM_NET_INADDR_ANY;
12e41d03
DL
666 up->rpf.source_nexthop.mrib_metric_preference = qpim_infinite_assert_metric.metric_preference;
667 up->rpf.source_nexthop.mrib_route_metric = qpim_infinite_assert_metric.route_metric;
63c59d0c
DS
668 up->rpf.rpf_addr.family = AF_INET;
669 up->rpf.rpf_addr.u.prefix4.s_addr = PIM_NET_INADDR_ANY;
12e41d03 670
2a28f7a0
DS
671 up->ifchannels = list_new();
672 up->ifchannels->cmp = (int (*)(void *, void *))pim_ifchannel_compare;
673
9c5e4d62
DS
674 if (up->sg.src.s_addr != INADDR_ANY)
675 wheel_add_item (pim_upstream_sg_wheel, up);
676
1bc98276 677 rpf_result = pim_rpf_update(up, NULL, 1);
2f702571 678 if (rpf_result == PIM_RPF_FAILURE) {
ec97ac65
DS
679 struct prefix nht_p;
680
3197cb1e 681 if (PIM_DEBUG_TRACE)
4a40c37a 682 zlog_debug ("%s: Attempting to create upstream(%s), Unable to RPF for source", __PRETTY_FUNCTION__,
8bfb8b67 683 up->sg_str);
03417ccd 684
ec97ac65
DS
685 nht_p.family = AF_INET;
686 nht_p.prefixlen = IPV4_MAX_BITLEN;
687 nht_p.u.prefix4 = up->upstream_addr;
688 pim_delete_tracked_nexthop (&nht_p, up, NULL);
689
03417ccd
DS
690 if (up->parent)
691 {
692 listnode_delete (up->parent->sources, up);
693 up->parent = NULL;
694 }
9c5e4d62
DS
695
696 if (up->sg.src.s_addr != INADDR_ANY)
697 wheel_remove_item (pim_upstream_sg_wheel, up);
698
03417ccd
DS
699 pim_upstream_remove_children (up);
700 if (up->sources)
701 list_delete (up->sources);
702
703 hash_release (pim_upstream_hash, up);
2f702571
DS
704 XFREE(MTYPE_PIM_UPSTREAM, up);
705 return NULL;
706 }
12e41d03 707
633988a7
CS
708 if (up->rpf.source_nexthop.interface)
709 {
710 pim_ifp = up->rpf.source_nexthop.interface->info;
711 if (pim_ifp)
712 up->channel_oil = pim_channel_oil_add(&up->sg, pim_ifp->mroute_vif_index);
713 }
0f588989 714 listnode_add_sort(pim_upstream_list, up);
12e41d03 715
3197cb1e 716 if (PIM_DEBUG_TRACE)
1bc98276
CS
717 {
718 zlog_debug ("%s: Created Upstream %s upstream_addr %s",
719 __PRETTY_FUNCTION__, up->sg_str,
720 inet_ntoa (up->upstream_addr));
721 }
03417ccd 722
12e41d03
DL
723 return up;
724}
725
4ed0af70 726struct pim_upstream *pim_upstream_find(struct prefix_sg *sg)
12e41d03 727{
0f588989
DS
728 struct pim_upstream lookup;
729 struct pim_upstream *up = NULL;
12e41d03 730
0f588989
DS
731 lookup.sg = *sg;
732 up = hash_lookup (pim_upstream_hash, &lookup);
733 return up;
12e41d03
DL
734}
735
e711cd3c
DS
736struct pim_upstream *
737pim_upstream_find_or_add(struct prefix_sg *sg,
738 struct interface *incoming,
739 int flags, const char *name)
740{
741 struct pim_upstream *up;
742
743 up = pim_upstream_find(sg);
744
745 if (up)
746 {
747 if (!(up->flags & flags))
748 {
749 up->flags |= flags;
750 up->ref_count++;
751 }
752 }
753 else
754 up = pim_upstream_add (sg, incoming, flags, name);
755
756 return up;
757}
758
d0db90bf
DS
759void
760pim_upstream_ref(struct pim_upstream *up, int flags)
1bf16443 761{
762 up->flags |= flags;
763 ++up->ref_count;
764}
765
4ed0af70 766struct pim_upstream *pim_upstream_add(struct prefix_sg *sg,
4a40c37a 767 struct interface *incoming,
e5905a3b 768 int flags, const char *name)
12e41d03 769{
594a78cc 770 struct pim_upstream *up = NULL;
e5905a3b 771 int found = 0;
5074a423 772 up = pim_upstream_find(sg);
12e41d03 773 if (up) {
1bf16443 774 pim_upstream_ref(up, flags);
e5905a3b 775 found = 1;
12e41d03
DL
776 }
777 else {
4a40c37a 778 up = pim_upstream_new(sg, incoming, flags);
12e41d03
DL
779 }
780
e5905a3b 781 if (PIM_DEBUG_TRACE)
f4075cb4
DS
782 {
783 if (up)
633988a7
CS
784 {
785 char buf[PREFIX2STR_BUFFER];
786 prefix2str (&up->rpf.rpf_addr, buf, sizeof (buf));
787 zlog_debug("%s(%s): %s, iif %s found: %d: ref_count: %d",
f4075cb4 788 __PRETTY_FUNCTION__, name,
633988a7 789 up->sg_str, buf, found,
f4075cb4 790 up->ref_count);
633988a7 791 }
f4075cb4
DS
792 else
793 zlog_debug("%s(%s): (%s) failure to create",
794 __PRETTY_FUNCTION__, name,
795 pim_str_sg_dump (sg));
796 }
12e41d03 797
e5905a3b 798 return up;
12e41d03
DL
799}
800
c8fc07cb
DS
801/*
802 * Passed in up must be the upstream for ch. starch is NULL if no
803 * information
804 */
9f44d042 805int
7a3ddda5 806pim_upstream_evaluate_join_desired_interface (struct pim_upstream *up,
c8fc07cb
DS
807 struct pim_ifchannel *ch,
808 struct pim_ifchannel *starch)
7a3ddda5 809{
c8fc07cb 810 if (ch)
7a3ddda5 811 {
46c8aab8 812 if (PIM_IF_FLAG_TEST_S_G_RPT(ch->flags))
c8fc07cb 813 return 0;
d1e77284
DS
814
815 if (!pim_macro_ch_lost_assert(ch) && pim_macro_chisin_joins_or_include(ch))
c8fc07cb 816 return 1;
7a3ddda5 817 }
46c8aab8 818
7a3ddda5
DS
819 /*
820 * joins (*,G)
821 */
c8fc07cb 822 if (starch)
7a3ddda5 823 {
c8fc07cb
DS
824 if (PIM_IF_FLAG_TEST_S_G_RPT (starch->upstream->flags))
825 return 0;
826
827 if (!pim_macro_ch_lost_assert (starch) && pim_macro_chisin_joins_or_include (starch))
828 return 1;
7a3ddda5
DS
829 }
830
831 return 0;
832}
833
12e41d03
DL
834/*
835 Evaluate JoinDesired(S,G):
836
837 JoinDesired(S,G) is true if there is a downstream (S,G) interface I
838 in the set:
839
840 inherited_olist(S,G) =
841 joins(S,G) (+) pim_include(S,G) (-) lost_assert(S,G)
842
843 JoinDesired(S,G) may be affected by changes in the following:
844
845 pim_ifp->primary_address
846 pim_ifp->pim_dr_addr
847 ch->ifassert_winner_metric
848 ch->ifassert_winner
849 ch->local_ifmembership
850 ch->ifjoin_state
851 ch->upstream->rpf.source_nexthop.mrib_metric_preference
852 ch->upstream->rpf.source_nexthop.mrib_route_metric
853 ch->upstream->rpf.source_nexthop.interface
854
855 See also pim_upstream_update_join_desired() below.
856 */
857int pim_upstream_evaluate_join_desired(struct pim_upstream *up)
858{
c8fc07cb
DS
859 struct interface *ifp;
860 struct listnode *node;
861 struct pim_ifchannel *ch, *starch;
862 struct pim_upstream *starup = up->parent;
7a3ddda5 863 int ret = 0;
12e41d03 864
c8fc07cb 865 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
ea4a71fc 866 {
c8fc07cb
DS
867 if (!ifp->info)
868 continue;
869
870 ch = pim_ifchannel_find (ifp, &up->sg);
871
872 if (starup)
873 starch = pim_ifchannel_find (ifp, &starup->sg);
874 else
875 starch = NULL;
876
877 if (!ch && !starch)
878 continue;
12e41d03 879
c8fc07cb 880 ret += pim_upstream_evaluate_join_desired_interface (up, ch, starch);
ea4a71fc 881 } /* scan iface channel list */
12e41d03 882
7a3ddda5 883 return ret; /* false */
12e41d03
DL
884}
885
886/*
887 See also pim_upstream_evaluate_join_desired() above.
888*/
889void pim_upstream_update_join_desired(struct pim_upstream *up)
890{
891 int was_join_desired; /* boolean */
892 int is_join_desired; /* boolean */
893
894 was_join_desired = PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(up->flags);
895
896 is_join_desired = pim_upstream_evaluate_join_desired(up);
897 if (is_join_desired)
898 PIM_UPSTREAM_FLAG_SET_DR_JOIN_DESIRED(up->flags);
899 else
900 PIM_UPSTREAM_FLAG_UNSET_DR_JOIN_DESIRED(up->flags);
901
902 /* switched from false to true */
903 if (is_join_desired && !was_join_desired) {
12e41d03
DL
904 pim_upstream_switch(up, PIM_UPSTREAM_JOINED);
905 return;
906 }
907
908 /* switched from true to false */
909 if (!is_join_desired && was_join_desired) {
12e41d03
DL
910 pim_upstream_switch(up, PIM_UPSTREAM_NOTJOINED);
911 return;
912 }
913}
914
915/*
916 RFC 4601 4.5.7. Sending (S,G) Join/Prune Messages
917 Transitions from Joined State
918 RPF'(S,G) GenID changes
919
920 The upstream (S,G) state machine remains in Joined state. If the
921 Join Timer is set to expire in more than t_override seconds, reset
922 it so that it expires after t_override seconds.
923*/
924void pim_upstream_rpf_genid_changed(struct in_addr neigh_addr)
925{
926 struct listnode *up_node;
927 struct listnode *up_nextnode;
928 struct pim_upstream *up;
929
930 /*
0f588989
DS
931 * Scan all (S,G) upstreams searching for RPF'(S,G)=neigh_addr
932 */
933 for (ALL_LIST_ELEMENTS(pim_upstream_list, up_node, up_nextnode, up)) {
12e41d03 934
3197cb1e 935 if (PIM_DEBUG_TRACE) {
eaa54bdb
DW
936 char neigh_str[INET_ADDRSTRLEN];
937 char rpf_addr_str[PREFIX_STRLEN];
12e41d03 938 pim_inet4_dump("<neigh?>", neigh_addr, neigh_str, sizeof(neigh_str));
63c59d0c 939 pim_addr_dump("<rpf?>", &up->rpf.rpf_addr, rpf_addr_str, sizeof(rpf_addr_str));
05e451f8 940 zlog_debug("%s: matching neigh=%s against upstream (S,G)=%s joined=%d rpf_addr=%s",
12e41d03 941 __PRETTY_FUNCTION__,
8bfb8b67 942 neigh_str, up->sg_str,
12e41d03
DL
943 up->join_state == PIM_UPSTREAM_JOINED,
944 rpf_addr_str);
945 }
946
947 /* consider only (S,G) upstream in Joined state */
948 if (up->join_state != PIM_UPSTREAM_JOINED)
949 continue;
950
951 /* match RPF'(S,G)=neigh_addr */
63c59d0c 952 if (up->rpf.rpf_addr.u.prefix4.s_addr != neigh_addr.s_addr)
12e41d03
DL
953 continue;
954
955 pim_upstream_join_timer_decrease_to_t_override("RPF'(S,G) GenID change",
c48a612c 956 up);
12e41d03
DL
957 }
958}
959
960
961void pim_upstream_rpf_interface_changed(struct pim_upstream *up,
962 struct interface *old_rpf_ifp)
963{
ea4a71fc
DS
964 struct listnode *chnode;
965 struct listnode *chnextnode;
966 struct pim_ifchannel *ch;
ea4a71fc
DS
967
968 /* search all ifchannels */
b5e6281b 969 for (ALL_LIST_ELEMENTS(up->ifchannels, chnode, chnextnode, ch)) {
ea4a71fc
DS
970 if (ch->ifassert_state == PIM_IFASSERT_I_AM_LOSER) {
971 if (
972 /* RPF_interface(S) was NOT I */
973 (old_rpf_ifp == ch->interface)
974 &&
975 /* RPF_interface(S) stopped being I */
976 (ch->upstream->rpf.source_nexthop.interface != ch->interface)
977 ) {
978 assert_action_a5(ch);
979 }
980 } /* PIM_IFASSERT_I_AM_LOSER */
12e41d03 981
ea4a71fc 982 pim_ifchannel_update_assert_tracking_desired(ch);
12e41d03
DL
983 }
984}
985
986void pim_upstream_update_could_assert(struct pim_upstream *up)
987{
12e41d03
DL
988 struct listnode *chnode;
989 struct listnode *chnextnode;
12e41d03
DL
990 struct pim_ifchannel *ch;
991
ea4a71fc 992 /* scan per-interface (S,G) state */
b5e6281b 993 for (ALL_LIST_ELEMENTS(up->ifchannels, chnode, chnextnode, ch)) {
ea4a71fc
DS
994 pim_ifchannel_update_could_assert(ch);
995 } /* scan iface channel list */
12e41d03
DL
996}
997
998void pim_upstream_update_my_assert_metric(struct pim_upstream *up)
999{
12e41d03
DL
1000 struct listnode *chnode;
1001 struct listnode *chnextnode;
12e41d03
DL
1002 struct pim_ifchannel *ch;
1003
ea4a71fc 1004 /* scan per-interface (S,G) state */
b5e6281b 1005 for (ALL_LIST_ELEMENTS(up->ifchannels, chnode, chnextnode, ch)) {
ea4a71fc 1006 pim_ifchannel_update_my_assert_metric(ch);
12e41d03 1007
ea4a71fc 1008 } /* scan iface channel list */
12e41d03
DL
1009}
1010
1011static void pim_upstream_update_assert_tracking_desired(struct pim_upstream *up)
1012{
12e41d03
DL
1013 struct listnode *chnode;
1014 struct listnode *chnextnode;
12e41d03
DL
1015 struct pim_interface *pim_ifp;
1016 struct pim_ifchannel *ch;
1017
ea4a71fc 1018 /* scan per-interface (S,G) state */
b5e6281b 1019 for (ALL_LIST_ELEMENTS(up->ifchannels, chnode, chnextnode, ch)) {
ea4a71fc 1020 pim_ifp = ch->interface->info;
12e41d03
DL
1021 if (!pim_ifp)
1022 continue;
1023
ea4a71fc 1024 pim_ifchannel_update_assert_tracking_desired(ch);
12e41d03 1025
ea4a71fc 1026 } /* scan iface channel list */
12e41d03 1027}
f14248dd 1028
1bf16443 1029/* When kat is stopped CouldRegister goes to false so we need to
1030 * transition the (S, G) on FHR to NI state and remove reg tunnel
1031 * from the OIL */
1032static void pim_upstream_fhr_kat_expiry(struct pim_upstream *up)
1033{
1034 if (!PIM_UPSTREAM_FLAG_TEST_FHR(up->flags))
1035 return;
1036
1037 if (PIM_DEBUG_TRACE)
8bfb8b67
DS
1038 zlog_debug ("kat expired on %s; clear fhr reg state", up->sg_str);
1039
1bf16443 1040 /* stop reg-stop timer */
1041 THREAD_OFF(up->t_rs_timer);
1042 /* remove regiface from the OIL if it is there*/
1043 pim_channel_del_oif (up->channel_oil, pim_regiface, PIM_OIF_FLAG_PROTO_PIM);
0c2ebf00 1044 /* clear the register state */
1045 up->reg_state = PIM_REG_NOINFO;
1bf16443 1046 PIM_UPSTREAM_FLAG_UNSET_FHR(up->flags);
1047}
1048
1049/* When kat is started CouldRegister can go to true. And if it does we
1050 * need to transition the (S, G) on FHR to JOINED state and add reg tunnel
1051 * to the OIL */
1052static void pim_upstream_fhr_kat_start(struct pim_upstream *up)
1053{
1054 if (pim_upstream_could_register(up)) {
1055 if (PIM_DEBUG_TRACE)
8bfb8b67
DS
1056 zlog_debug ("kat started on %s; set fhr reg state to joined", up->sg_str);
1057
1bf16443 1058 PIM_UPSTREAM_FLAG_SET_FHR(up->flags);
15a5dafe 1059 if (up->reg_state == PIM_REG_NOINFO)
1060 pim_register_join (up);
1bf16443 1061 }
1062}
1063
f14248dd
DS
1064/*
1065 * On an RP, the PMBR value must be cleared when the
1066 * Keepalive Timer expires
1bf16443 1067 * KAT expiry indicates that flow is inactive. If the flow was created or
1068 * maintained by activity now is the time to deref it.
f14248dd
DS
1069 */
1070static int
1071pim_upstream_keep_alive_timer (struct thread *t)
1072{
1073 struct pim_upstream *up;
1074
1075 up = THREAD_ARG(t);
1bf16443 1076 up->t_ka_timer = NULL;
f14248dd 1077
4ed0af70 1078 if (I_am_RP (up->sg.grp))
850a9f99
DS
1079 {
1080 pim_br_clear_pmbr (&up->sg);
1081 /*
1082 * We need to do more here :)
1083 * But this is the start.
1084 */
1085 }
14315ea8 1086
1bf16443 1087 /* source is no longer active - pull the SA from MSDP's cache */
1088 pim_msdp_sa_local_del(&up->sg);
14315ea8 1089
1bf16443 1090 /* if entry was created because of activity we need to deref it */
1091 if (PIM_UPSTREAM_FLAG_TEST_SRC_STREAM(up->flags))
850a9f99
DS
1092 {
1093 pim_upstream_fhr_kat_expiry(up);
1094 if (PIM_DEBUG_TRACE)
1095 zlog_debug ("kat expired on %s; remove stream reference", up->sg_str);
1096 PIM_UPSTREAM_FLAG_UNSET_SRC_STREAM(up->flags);
1097 pim_upstream_del(up, __PRETTY_FUNCTION__);
1098 }
1099 else if (PIM_UPSTREAM_FLAG_TEST_SRC_LHR(up->flags))
1100 {
1101 PIM_UPSTREAM_FLAG_UNSET_SRC_LHR(up->flags);
1102 pim_upstream_del(up, __PRETTY_FUNCTION__);
1103 }
14315ea8 1104
1bf16443 1105 return 0;
f14248dd
DS
1106}
1107
f14248dd
DS
1108void
1109pim_upstream_keep_alive_timer_start (struct pim_upstream *up,
1110 uint32_t time)
1111{
1bf16443 1112 if (!PIM_UPSTREAM_FLAG_TEST_SRC_STREAM(up->flags)) {
1113 if (PIM_DEBUG_TRACE)
8bfb8b67 1114 zlog_debug ("kat start on %s with no stream reference", up->sg_str);
1bf16443 1115 }
00d2f9e4 1116 THREAD_OFF (up->t_ka_timer);
f14248dd
DS
1117 THREAD_TIMER_ON (master,
1118 up->t_ka_timer,
1119 pim_upstream_keep_alive_timer,
1120 up, time);
1bf16443 1121
1122 /* any time keepalive is started against a SG we will have to
1123 * re-evaluate our active source database */
1124 pim_msdp_sa_local_update(up);
1125}
1126
1127/* MSDP on RP needs to know if a source is registerable to this RP */
1128static int
1129pim_upstream_msdp_reg_timer(struct thread *t)
1130{
1131 struct pim_upstream *up;
1132
1133 up = THREAD_ARG(t);
1134 up->t_msdp_reg_timer = NULL;
1135
1136 /* source is no longer active - pull the SA from MSDP's cache */
1137 pim_msdp_sa_local_del(&up->sg);
1138 return 1;
1139}
1140void
1141pim_upstream_msdp_reg_timer_start(struct pim_upstream *up)
1142{
1143 THREAD_OFF(up->t_msdp_reg_timer);
1144 THREAD_TIMER_ON(master, up->t_msdp_reg_timer,
1145 pim_upstream_msdp_reg_timer, up, PIM_MSDP_REG_RXED_PERIOD);
1146
1147 pim_msdp_sa_local_update(up);
f14248dd 1148}
cb40b272
DS
1149
1150/*
1151 * 4.2.1 Last-Hop Switchover to the SPT
1152 *
1153 * In Sparse-Mode PIM, last-hop routers join the shared tree towards the
1154 * RP. Once traffic from sources to joined groups arrives at a last-hop
1155 * router, it has the option of switching to receive the traffic on a
1156 * shortest path tree (SPT).
1157 *
1158 * The decision for a router to switch to the SPT is controlled as
1159 * follows:
1160 *
1161 * void
1162 * CheckSwitchToSpt(S,G) {
1163 * if ( ( pim_include(*,G) (-) pim_exclude(S,G)
1164 * (+) pim_include(S,G) != NULL )
1165 * AND SwitchToSptDesired(S,G) ) {
1166 * # Note: Restarting the KAT will result in the SPT switch
1167 * set KeepaliveTimer(S,G) to Keepalive_Period
1168 * }
1169 * }
1170 *
1171 * SwitchToSptDesired(S,G) is a policy function that is implementation
1172 * defined. An "infinite threshold" policy can be implemented by making
1173 * SwitchToSptDesired(S,G) return false all the time. A "switch on
1174 * first packet" policy can be implemented by making
1175 * SwitchToSptDesired(S,G) return true once a single packet has been
1176 * received for the source and group.
1177 */
1178int
4ed0af70 1179pim_upstream_switch_to_spt_desired (struct prefix_sg *sg)
cb40b272 1180{
4ed0af70 1181 if (I_am_RP (sg->grp))
a3b58b4a
DS
1182 return 1;
1183
cb40b272
DS
1184 return 0;
1185}
d7259eac 1186
80d9c3a0
DS
1187int
1188pim_upstream_is_sg_rpt (struct pim_upstream *up)
1189{
f21597f0
DS
1190 struct listnode *chnode;
1191 struct pim_ifchannel *ch;
1192
b5e6281b 1193 for (ALL_LIST_ELEMENTS_RO(up->ifchannels, chnode, ch))
f21597f0 1194 {
b5e6281b
DS
1195 if (PIM_IF_FLAG_TEST_S_G_RPT(ch->flags))
1196 return 1;
f21597f0 1197 }
e43b8697 1198
80d9c3a0
DS
1199 return 0;
1200}
3a66b17b
DS
1201/*
1202 * After receiving a packet set SPTbit:
1203 * void
1204 * Update_SPTbit(S,G,iif) {
1205 * if ( iif == RPF_interface(S)
1206 * AND JoinDesired(S,G) == TRUE
1207 * AND ( DirectlyConnected(S) == TRUE
1208 * OR RPF_interface(S) != RPF_interface(RP(G))
1209 * OR inherited_olist(S,G,rpt) == NULL
1210 * OR ( ( RPF'(S,G) == RPF'(*,G) ) AND
1211 * ( RPF'(S,G) != NULL ) )
1212 * OR ( I_Am_Assert_Loser(S,G,iif) ) {
1213 * Set SPTbit(S,G) to TRUE
1214 * }
1215 * }
1216 */
1217void
1218pim_upstream_set_sptbit (struct pim_upstream *up, struct interface *incoming)
1219{
1220 struct pim_rpf *grpf = NULL;
1221
1222 // iif == RPF_interfvace(S)
1223 if (up->rpf.source_nexthop.interface != incoming)
1224 {
1225 if (PIM_DEBUG_TRACE)
1226 zlog_debug ("%s: Incoming Interface: %s is different than RPF_interface(S) %s",
1227 __PRETTY_FUNCTION__, incoming->name, up->rpf.source_nexthop.interface->name);
1228 return;
1229 }
1230
1231 // AND JoinDesired(S,G) == TRUE
1232 // FIXME
1233
1234 // DirectlyConnected(S) == TRUE
1235 if (pim_if_connected_to_source (up->rpf.source_nexthop.interface, up->sg.src))
1236 {
1237 if (PIM_DEBUG_TRACE)
1238 zlog_debug ("%s: %s is directly connected to the source", __PRETTY_FUNCTION__,
8bfb8b67 1239 up->sg_str);
3a66b17b
DS
1240 up->sptbit = PIM_UPSTREAM_SPTBIT_TRUE;
1241 return;
1242 }
1243
1244 // OR RPF_interface(S) != RPF_interface(RP(G))
1245 grpf = RP(up->sg.grp);
1246 if (!grpf || up->rpf.source_nexthop.interface != grpf->source_nexthop.interface)
1247 {
1248 if (PIM_DEBUG_TRACE)
1249 zlog_debug ("%s: %s RPF_interface(S) != RPF_interface(RP(G))",
8bfb8b67 1250 __PRETTY_FUNCTION__, up->sg_str);
3a66b17b
DS
1251 up->sptbit = PIM_UPSTREAM_SPTBIT_TRUE;
1252 return;
1253 }
1254
1255 // OR inherited_olist(S,G,rpt) == NULL
1256 if (pim_upstream_is_sg_rpt(up) && pim_upstream_empty_inherited_olist(up))
1257 {
1258 if (PIM_DEBUG_TRACE)
1259 zlog_debug ("%s: %s OR inherited_olist(S,G,rpt) == NULL", __PRETTY_FUNCTION__,
8bfb8b67 1260 up->sg_str);
3a66b17b
DS
1261 up->sptbit = PIM_UPSTREAM_SPTBIT_TRUE;
1262 return;
1263 }
1264
1265 // OR ( ( RPF'(S,G) == RPF'(*,G) ) AND
1266 // ( RPF'(S,G) != NULL ) )
1267 if (up->parent && pim_rpf_is_same (&up->rpf, &up->parent->rpf))
1268 {
1269 if (PIM_DEBUG_TRACE)
1270 zlog_debug ("%s: %s RPF'(S,G) is the same as RPF'(*,G)", __PRETTY_FUNCTION__,
8bfb8b67 1271 up->sg_str);
3a66b17b
DS
1272 up->sptbit = PIM_UPSTREAM_SPTBIT_TRUE;
1273 return;
1274 }
1275
1276 return;
1277}
80d9c3a0 1278
d7259eac 1279const char *
c9802954 1280pim_upstream_state2str (enum pim_upstream_state join_state)
d7259eac 1281{
c9802954 1282 switch (join_state)
d7259eac
DS
1283 {
1284 case PIM_UPSTREAM_NOTJOINED:
e775c0a4 1285 return "NotJoined";
d7259eac
DS
1286 break;
1287 case PIM_UPSTREAM_JOINED:
e775c0a4 1288 return "Joined";
d7259eac 1289 break;
d7259eac 1290 }
e775c0a4 1291 return "Unknown";
d7259eac 1292}
627ed2a3 1293
e0e127b0 1294const char *
0c2ebf00 1295pim_reg_state2str (enum pim_reg_state reg_state, char *state_str)
e0e127b0 1296{
0c2ebf00 1297 switch (reg_state)
e0e127b0 1298 {
0c2ebf00 1299 case PIM_REG_NOINFO:
1300 strcpy (state_str, "RegNoInfo");
e0e127b0 1301 break;
0c2ebf00 1302 case PIM_REG_JOIN:
1303 strcpy (state_str, "RegJoined");
e0e127b0 1304 break;
0c2ebf00 1305 case PIM_REG_JOIN_PENDING:
1306 strcpy (state_str, "RegJoinPend");
e0e127b0 1307 break;
0c2ebf00 1308 case PIM_REG_PRUNE:
1309 strcpy (state_str, "RegPrune");
e0e127b0 1310 break;
1311 default:
0c2ebf00 1312 strcpy (state_str, "RegUnknown");
e0e127b0 1313 }
1314 return state_str;
1315}
1316
627ed2a3
DS
1317static int
1318pim_upstream_register_stop_timer (struct thread *t)
1319{
4df01a4e 1320 struct pim_interface *pim_ifp;
627ed2a3
DS
1321 struct pim_upstream *up;
1322 struct pim_rpf *rpg;
1323 struct ip ip_hdr;
627ed2a3
DS
1324 up = THREAD_ARG (t);
1325
1326 up->t_rs_timer = NULL;
1327
1328 if (PIM_DEBUG_TRACE)
1329 {
0c2ebf00 1330 char state_str[PIM_REG_STATE_STR_LEN];
d5ed8a9c 1331 zlog_debug ("%s: (S,G)=%s upstream register stop timer %s",
8bfb8b67 1332 __PRETTY_FUNCTION__, up->sg_str,
0c2ebf00 1333 pim_reg_state2str(up->reg_state, state_str));
627ed2a3
DS
1334 }
1335
e0e127b0 1336 switch (up->reg_state)
627ed2a3 1337 {
0c2ebf00 1338 case PIM_REG_JOIN_PENDING:
1339 up->reg_state = PIM_REG_JOIN;
bb027ee8
DS
1340 pim_channel_add_oif (up->channel_oil, pim_regiface, PIM_OIF_FLAG_PROTO_PIM);
1341 break;
0c2ebf00 1342 case PIM_REG_JOIN:
627ed2a3 1343 break;
0c2ebf00 1344 case PIM_REG_PRUNE:
4df01a4e 1345 pim_ifp = up->rpf.source_nexthop.interface->info;
7ef66046
DS
1346 if (!pim_ifp)
1347 {
1348 if (PIM_DEBUG_TRACE)
1349 zlog_debug ("%s: Interface: %s is not configured for pim",
1350 __PRETTY_FUNCTION__, up->rpf.source_nexthop.interface->name);
1351 return 0;
1352 }
0c2ebf00 1353 up->reg_state = PIM_REG_JOIN_PENDING;
627ed2a3
DS
1354 pim_upstream_start_register_stop_timer (up, 1);
1355
70e7fda8
DS
1356 if (((up->channel_oil->cc.lastused/100) > PIM_KEEPALIVE_PERIOD) &&
1357 (I_am_RP (up->sg.grp)))
1358 {
1359 if (PIM_DEBUG_TRACE)
1360 zlog_debug ("%s: Stop sending the register, because I am the RP and we haven't seen a packet in a while", __PRETTY_FUNCTION__);
1361 return 0;
1362 }
4ed0af70 1363 rpg = RP (up->sg.grp);
627ed2a3
DS
1364 memset (&ip_hdr, 0, sizeof (struct ip));
1365 ip_hdr.ip_p = PIM_IP_PROTO_PIM;
1366 ip_hdr.ip_hl = 5;
1367 ip_hdr.ip_v = 4;
4ed0af70
DS
1368 ip_hdr.ip_src = up->sg.src;
1369 ip_hdr.ip_dst = up->sg.grp;
dc686f82 1370 ip_hdr.ip_len = htons (20);
627ed2a3 1371 // checksum is broken
4df01a4e 1372 pim_register_send ((uint8_t *)&ip_hdr, sizeof (struct ip),
0e3b3d5d 1373 pim_ifp->primary_address, rpg, 1, up);
627ed2a3
DS
1374 break;
1375 default:
1376 break;
1377 }
1378
1379 return 0;
1380}
1381
1382void
1383pim_upstream_start_register_stop_timer (struct pim_upstream *up, int null_register)
1384{
1385 uint32_t time;
1386
1387 if (up->t_rs_timer)
1388 {
1389 THREAD_TIMER_OFF (up->t_rs_timer);
1390 up->t_rs_timer = NULL;
1391 }
1392
1393 if (!null_register)
1394 {
1395 uint32_t lower = (0.5 * PIM_REGISTER_SUPPRESSION_PERIOD);
1396 uint32_t upper = (1.5 * PIM_REGISTER_SUPPRESSION_PERIOD);
1397 time = lower + (random () % (upper - lower + 1)) - PIM_REGISTER_PROBE_PERIOD;
1398 }
1399 else
1400 time = PIM_REGISTER_PROBE_PERIOD;
1401
1402 if (PIM_DEBUG_TRACE)
1403 {
05e451f8 1404 zlog_debug ("%s: (S,G)=%s Starting upstream register stop timer %d",
8bfb8b67 1405 __PRETTY_FUNCTION__, up->sg_str, time);
627ed2a3
DS
1406 }
1407 THREAD_TIMER_ON (master, up->t_rs_timer,
1408 pim_upstream_register_stop_timer,
1409 up, time);
1410}
4fdc8f36 1411
4fdc8f36 1412int
b5183fd1 1413pim_upstream_inherited_olist_decide (struct pim_upstream *up)
4fdc8f36 1414{
c8fc07cb 1415 struct interface *ifp;
1131c2eb 1416 struct pim_interface *pim_ifp = NULL;
c8fc07cb
DS
1417 struct pim_ifchannel *ch, *starch;
1418 struct listnode *node;
1419 struct pim_upstream *starup = up->parent;
219e0013
DS
1420 int output_intf = 0;
1421
1131c2eb
CS
1422 if (up->rpf.source_nexthop.interface)
1423 pim_ifp = up->rpf.source_nexthop.interface->info;
1424 else
1425 {
1426 if (PIM_DEBUG_TRACE)
1427 zlog_debug ("%s: up %s RPF is not present", __PRETTY_FUNCTION__, up->sg_str);
1428 }
da55afba 1429 if (pim_ifp && !up->channel_oil)
3667b0bc 1430 up->channel_oil = pim_channel_oil_add (&up->sg, pim_ifp->mroute_vif_index);
219e0013 1431
c8fc07cb 1432 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
219e0013 1433 {
c8fc07cb
DS
1434 if (!ifp->info)
1435 continue;
219e0013 1436
c8fc07cb
DS
1437 ch = pim_ifchannel_find (ifp, &up->sg);
1438
1439 if (starup)
1440 starch = pim_ifchannel_find (ifp, &starup->sg);
1441 else
1442 starch = NULL;
1443
1444 if (!ch && !starch)
1445 continue;
1446
1447 if (pim_upstream_evaluate_join_desired_interface (up, ch, starch))
1448 {
781a1745
DS
1449 int flag = PIM_OIF_FLAG_PROTO_PIM;
1450
c8fc07cb 1451 if (!ch)
781a1745 1452 flag = PIM_OIF_FLAG_PROTO_STAR;
c8fc07cb
DS
1453
1454 pim_channel_add_oif (up->channel_oil, ifp, flag);
1455 output_intf++;
1456 }
219e0013
DS
1457 }
1458
b5183fd1
DS
1459 return output_intf;
1460}
1461
1462/*
1463 * For a given upstream, determine the inherited_olist
1464 * and apply it.
1465 *
1466 * inherited_olist(S,G,rpt) =
1467 * ( joins(*,*,RP(G)) (+) joins(*,G) (-) prunes(S,G,rpt) )
1468 * (+) ( pim_include(*,G) (-) pim_exclude(S,G))
1469 * (-) ( lost_assert(*,G) (+) lost_assert(S,G,rpt) )
1470 *
1471 * inherited_olist(S,G) =
1472 * inherited_olist(S,G,rpt) (+)
1473 * joins(S,G) (+) pim_include(S,G) (-) lost_assert(S,G)
1474 *
1475 * return 1 if there are any output interfaces
1476 * return 0 if there are not any output interfaces
1477 */
1478int
1479pim_upstream_inherited_olist (struct pim_upstream *up)
1480{
1481 int output_intf = pim_upstream_inherited_olist_decide (up);
1482
483eef9d
DS
1483 /*
1484 * If we have output_intf switch state to Join and work like normal
1485 * If we don't have an output_intf that means we are probably a
1486 * switch on a stick so turn on forwarding to just accept the
1487 * incoming packets so we don't bother the other stuff!
1488 */
1489 if (output_intf)
1490 pim_upstream_switch (up, PIM_UPSTREAM_JOINED);
1491 else
1492 forward_on (up);
219e0013
DS
1493
1494 return output_intf;
4fdc8f36 1495}
d3dd1804 1496
80d9c3a0
DS
1497int
1498pim_upstream_empty_inherited_olist (struct pim_upstream *up)
1499{
ce0ddb4e 1500 return pim_channel_oil_empty (up->channel_oil);
80d9c3a0
DS
1501}
1502
d3dd1804
DS
1503/*
1504 * When we have a new neighbor,
1505 * find upstreams that don't have their rpf_addr
1506 * set and see if the new neighbor allows
1507 * the join to be sent
1508 */
1509void
1510pim_upstream_find_new_rpf (void)
1511{
1512 struct listnode *up_node;
1513 struct listnode *up_nextnode;
1514 struct pim_upstream *up;
1515
1516 /*
0f588989
DS
1517 * Scan all (S,G) upstreams searching for RPF'(S,G)=neigh_addr
1518 */
1519 for (ALL_LIST_ELEMENTS(pim_upstream_list, up_node, up_nextnode, up))
d3dd1804 1520 {
63c59d0c 1521 if (pim_rpf_addr_is_inaddr_any(&up->rpf))
d3dd1804 1522 {
3197cb1e 1523 if (PIM_DEBUG_TRACE)
d3dd1804 1524 zlog_debug ("Upstream %s without a path to send join, checking",
8bfb8b67 1525 up->sg_str);
1bc98276 1526 pim_rpf_update (up, NULL, 1);
d3dd1804
DS
1527 }
1528 }
1529}
0f588989 1530
0f588989
DS
1531static unsigned int
1532pim_upstream_hash_key (void *arg)
1533{
1534 struct pim_upstream *up = (struct pim_upstream *)arg;
1535
1536 return jhash_2words (up->sg.src.s_addr, up->sg.grp.s_addr, 0);
1537}
1538
1539void pim_upstream_terminate (void)
1540{
1541 if (pim_upstream_list)
693c9259 1542 list_delete (pim_upstream_list);
0f588989
DS
1543 pim_upstream_list = NULL;
1544
1545 if (pim_upstream_hash)
1546 hash_free (pim_upstream_hash);
693c9259 1547 pim_upstream_hash = NULL;
0f588989
DS
1548}
1549
1550static int
1551pim_upstream_equal (const void *arg1, const void *arg2)
1552{
1553 const struct pim_upstream *up1 = (const struct pim_upstream *)arg1;
1554 const struct pim_upstream *up2 = (const struct pim_upstream *)arg2;
1555
1556 if ((up1->sg.grp.s_addr == up2->sg.grp.s_addr) &&
1557 (up1->sg.src.s_addr == up2->sg.src.s_addr))
1558 return 1;
1559
1560 return 0;
1561}
1562
1bf16443 1563/* rfc4601:section-4.2:"Data Packet Forwarding Rules" defines
1564 * the cases where kat has to be restarted on rxing traffic -
1565 *
1566 * if( DirectlyConnected(S) == TRUE AND iif == RPF_interface(S) ) {
1567 * set KeepaliveTimer(S,G) to Keepalive_Period
1568 * # Note: a register state transition or UpstreamJPState(S,G)
1569 * # transition may happen as a result of restarting
1570 * # KeepaliveTimer, and must be dealt with here.
1571 * }
1572 * if( iif == RPF_interface(S) AND UpstreamJPState(S,G) == Joined AND
1573 * inherited_olist(S,G) != NULL ) {
1574 * set KeepaliveTimer(S,G) to Keepalive_Period
1575 * }
1576 */
1577static bool pim_upstream_kat_start_ok(struct pim_upstream *up)
1578{
1579 /* "iif == RPF_interface(S)" check has to be done by the kernel or hw
1580 * so we will skip that here */
1581 if (pim_if_connected_to_source(up->rpf.source_nexthop.interface,
1582 up->sg.src)) {
1583 return true;
1584 }
1585
1586 if ((up->join_state == PIM_UPSTREAM_JOINED) &&
1587 !pim_upstream_empty_inherited_olist(up)) {
1588 /* XXX: I have added this RP check just for 3.2 and it's a digression from
1589 * what rfc-4601 says. Till now we were only running KAT on FHR and RP and
1590 * there is some angst around making the change to run it all routers that
1591 * maintain the (S, G) state. This is tracked via CM-13601 and MUST be
1592 * removed to handle spt turn-arounds correctly in a 3-tier clos */
1593 if (I_am_RP (up->sg.grp))
1594 return true;
1595 }
1596
1597 return false;
1598}
1599
9c5e4d62
DS
1600/*
1601 * Code to check and see if we've received packets on a S,G mroute
1602 * and if so to set the SPT bit appropriately
1603 */
1604static void
1605pim_upstream_sg_running (void *arg)
1606{
1607 struct pim_upstream *up = (struct pim_upstream *)arg;
e43b8697
DS
1608
1609 // No packet can have arrived here if this is the case
1610 if (!up->channel_oil || !up->channel_oil->installed)
1611 {
1612 if (PIM_DEBUG_TRACE)
1613 zlog_debug ("%s: %s is not installed in mroute",
8bfb8b67 1614 __PRETTY_FUNCTION__, up->sg_str);
e43b8697
DS
1615 return;
1616 }
1617
bfdf4096
DS
1618 /*
1619 * This is a bit of a hack
1620 * We've noted that we should rescan but
1621 * we've missed the window for doing so in
1622 * pim_zebra.c for some reason. I am
1623 * only doing this at this point in time
1624 * to get us up and working for the moment
1625 */
1626 if (up->channel_oil->oil_inherited_rescan)
1627 {
1628 if (PIM_DEBUG_TRACE)
1629 zlog_debug ("%s: Handling unscanned inherited_olist for %s", __PRETTY_FUNCTION__, up->sg_str);
1630 pim_upstream_inherited_olist_decide (up);
1631 up->channel_oil->oil_inherited_rescan = 0;
1632 }
e43b8697
DS
1633 pim_mroute_update_counters (up->channel_oil);
1634
1635 // Have we seen packets?
1bf16443 1636 if ((up->channel_oil->cc.oldpktcnt >= up->channel_oil->cc.pktcnt) &&
e43b8697
DS
1637 (up->channel_oil->cc.lastused/100 > 30))
1638 {
1639 if (PIM_DEBUG_TRACE)
1640 {
eeedae06
DS
1641 zlog_debug ("%s: %s old packet count is equal or lastused is greater than 30, (%ld,%ld,%lld)",
1642 __PRETTY_FUNCTION__, up->sg_str,
1643 up->channel_oil->cc.oldpktcnt,
1644 up->channel_oil->cc.pktcnt,
1645 up->channel_oil->cc.lastused/100);
e43b8697
DS
1646 }
1647 return;
1648 }
1649
850a9f99 1650 if (pim_upstream_kat_start_ok(up))
1bf16443 1651 {
850a9f99
DS
1652 /* Add a source reference to the stream if
1653 * one doesn't already exist */
1654 if (!PIM_UPSTREAM_FLAG_TEST_SRC_STREAM(up->flags))
1655 {
1656 if (PIM_DEBUG_TRACE)
1657 zlog_debug ("source reference created on kat restart %s", up->sg_str);
8bfb8b67 1658
850a9f99
DS
1659 pim_upstream_ref(up, PIM_UPSTREAM_FLAG_MASK_SRC_STREAM);
1660 PIM_UPSTREAM_FLAG_SET_SRC_STREAM(up->flags);
1661 pim_upstream_fhr_kat_start(up);
1662 }
1663 pim_upstream_keep_alive_timer_start(up, qpim_keep_alive_time);
1bf16443 1664 }
850a9f99 1665 else if (PIM_UPSTREAM_FLAG_TEST_SRC_LHR(up->flags))
1bf16443 1666 pim_upstream_keep_alive_timer_start(up, qpim_keep_alive_time);
1bf16443 1667
1668 if (up->sptbit != PIM_UPSTREAM_SPTBIT_TRUE)
850a9f99
DS
1669 {
1670 pim_upstream_set_sptbit(up, up->rpf.source_nexthop.interface);
1671 }
e43b8697 1672 return;
9c5e4d62
DS
1673}
1674
a7b2b1e2
DS
1675void
1676pim_upstream_add_lhr_star_pimreg (void)
1677{
1678 struct pim_upstream *up;
1679 struct listnode *node;
1680
1681 for (ALL_LIST_ELEMENTS_RO (pim_upstream_list, node, up))
1682 {
1683 if (up->sg.src.s_addr != INADDR_ANY)
1684 continue;
1685
1686 if (!PIM_UPSTREAM_FLAG_TEST_SRC_IGMP (up->flags))
1687 continue;
1688
1689 pim_channel_add_oif (up->channel_oil, pim_regiface, PIM_OIF_FLAG_PROTO_IGMP);
1690 }
1691}
1692
1693void
df94f9a9
DS
1694pim_upstream_spt_prefix_list_update (struct prefix_list *pl)
1695{
1696 const char *pname = prefix_list_name (pl);
1697
1698 if (pimg->spt.plist && strcmp (pimg->spt.plist, pname) == 0)
1699 {
1700 pim_upstream_remove_lhr_star_pimreg (pname);
1701 }
1702}
1703
1704/*
1705 * nlist -> The new prefix list
1706 *
1707 * Per Group Application of pimreg to the OIL
1708 * If the prefix list tells us DENY then
1709 * we need to Switchover to SPT immediate
1710 * so add the pimreg.
1711 * If the prefix list tells us to ACCEPT than
1712 * we need to Never do the SPT so remove
1713 * the interface
1714 *
1715 */
1716void
1717pim_upstream_remove_lhr_star_pimreg (const char *nlist)
a7b2b1e2
DS
1718{
1719 struct pim_upstream *up;
1720 struct listnode *node;
df94f9a9
DS
1721 struct prefix_list *np;
1722 struct prefix g;
1723 enum prefix_list_type apply_new;
1724
1725 np = prefix_list_lookup (AFI_IP, nlist);
1726
1727 g.family = AF_INET;
1728 g.prefixlen = IPV4_MAX_PREFIXLEN;
a7b2b1e2
DS
1729
1730 for (ALL_LIST_ELEMENTS_RO (pim_upstream_list, node, up))
1731 {
1732 if (up->sg.src.s_addr != INADDR_ANY)
1733 continue;
1734
1735 if (!PIM_UPSTREAM_FLAG_TEST_SRC_IGMP (up->flags))
1736 continue;
1737
df94f9a9
DS
1738 if (!nlist)
1739 {
1740 pim_channel_del_oif (up->channel_oil, pim_regiface, PIM_OIF_FLAG_PROTO_IGMP);
1741 continue;
1742 }
1743 g.u.prefix4 = up->sg.grp;
1744 apply_new = prefix_list_apply (np, &g);
1745 if (apply_new == PREFIX_DENY)
1746 pim_channel_add_oif (up->channel_oil, pim_regiface, PIM_OIF_FLAG_PROTO_IGMP);
1747 else
1748 pim_channel_del_oif (up->channel_oil, pim_regiface, PIM_OIF_FLAG_PROTO_IGMP);
a7b2b1e2
DS
1749 }
1750}
1751
040d86ad
DS
1752void
1753pim_upstream_init (void)
0f588989 1754{
9c5e4d62
DS
1755 pim_upstream_sg_wheel = wheel_init (master, 31000, 100,
1756 pim_upstream_hash_key,
1757 pim_upstream_sg_running);
0f588989
DS
1758 pim_upstream_hash = hash_create_size (8192, pim_upstream_hash_key,
1759 pim_upstream_equal);
1760
1761 pim_upstream_list = list_new ();
1762 pim_upstream_list->del = (void (*)(void *)) pim_upstream_free;
03417ccd 1763 pim_upstream_list->cmp = pim_upstream_compare;
0f588989
DS
1764
1765}