3 * Copyright (C) 2008 Everton da Silva Marques
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.
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.
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
33 #include "pim_iface.h"
34 #include "pim_ifchannel.h"
35 #include "pim_zebra.h"
41 #include "pim_macro.h"
43 #include "pim_upstream.h"
47 RB_GENERATE(pim_ifchannel_rb
, pim_ifchannel
, pim_ifp_rb
, pim_ifchannel_compare
);
49 int pim_ifchannel_compare(const struct pim_ifchannel
*ch1
,
50 const struct pim_ifchannel
*ch2
)
52 struct pim_interface
*pim_ifp1
;
53 struct pim_interface
*pim_ifp2
;
55 pim_ifp1
= ch1
->interface
->info
;
56 pim_ifp2
= ch2
->interface
->info
;
58 if (pim_ifp1
->mroute_vif_index
< pim_ifp2
->mroute_vif_index
)
61 if (pim_ifp1
->mroute_vif_index
> pim_ifp2
->mroute_vif_index
)
64 if (ntohl(ch1
->sg
.grp
.s_addr
) < ntohl(ch2
->sg
.grp
.s_addr
))
67 if (ntohl(ch1
->sg
.grp
.s_addr
) > ntohl(ch2
->sg
.grp
.s_addr
))
70 if (ntohl(ch1
->sg
.src
.s_addr
) < ntohl(ch2
->sg
.src
.s_addr
))
73 if (ntohl(ch1
->sg
.src
.s_addr
) > ntohl(ch2
->sg
.src
.s_addr
))
80 * A (*,G) or a (*,*) is going away
81 * remove the parent pointer from
82 * those pointing at us
84 static void pim_ifchannel_remove_children(struct pim_ifchannel
*ch
)
86 struct pim_ifchannel
*child
;
91 while (!list_isempty(ch
->sources
)) {
92 child
= listnode_head(ch
->sources
);
94 listnode_delete(ch
->sources
, child
);
99 * A (*,G) or a (*,*) is being created
100 * find all the children that would point
103 static void pim_ifchannel_find_new_children(struct pim_ifchannel
*ch
)
105 struct pim_interface
*pim_ifp
= ch
->interface
->info
;
106 struct pim_ifchannel
*child
;
108 // Basic Sanity that we are not being silly
109 if ((ch
->sg
.src
.s_addr
!= INADDR_ANY
)
110 && (ch
->sg
.grp
.s_addr
!= INADDR_ANY
))
113 if ((ch
->sg
.src
.s_addr
== INADDR_ANY
)
114 && (ch
->sg
.grp
.s_addr
== INADDR_ANY
))
117 RB_FOREACH (child
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
118 if ((ch
->sg
.grp
.s_addr
!= INADDR_ANY
)
119 && (child
->sg
.grp
.s_addr
== ch
->sg
.grp
.s_addr
)
122 listnode_add_sort(ch
->sources
, child
);
127 void pim_ifchannel_delete(struct pim_ifchannel
*ch
)
129 struct pim_interface
*pim_ifp
;
131 pim_ifp
= ch
->interface
->info
;
133 if (ch
->upstream
->channel_oil
) {
134 uint32_t mask
= PIM_OIF_FLAG_PROTO_PIM
;
135 if (ch
->upstream
->flags
& PIM_UPSTREAM_FLAG_MASK_SRC_IGMP
)
136 mask
= PIM_OIF_FLAG_PROTO_IGMP
;
138 /* SGRpt entry could have empty oil */
139 if (ch
->upstream
->channel_oil
)
140 pim_channel_del_oif(ch
->upstream
->channel_oil
,
141 ch
->interface
, mask
);
143 * Do we have any S,G's that are inheriting?
144 * Nuke from on high too.
146 if (ch
->upstream
->sources
) {
147 struct pim_upstream
*child
;
148 struct listnode
*up_node
;
150 for (ALL_LIST_ELEMENTS_RO(ch
->upstream
->sources
,
152 pim_channel_del_oif(child
->channel_oil
,
154 PIM_OIF_FLAG_PROTO_STAR
);
159 * When this channel is removed
160 * we need to find all our children
161 * and make sure our pointers are fixed
163 pim_ifchannel_remove_children(ch
);
166 list_delete_and_null(&ch
->sources
);
168 listnode_delete(ch
->upstream
->ifchannels
, ch
);
170 if (ch
->ifjoin_state
!= PIM_IFJOIN_NOINFO
) {
171 pim_upstream_update_join_desired(pim_ifp
->pim
, ch
->upstream
);
174 /* upstream is common across ifchannels, check if upstream's
175 ifchannel list is empty before deleting upstream_del
176 ref count will take care of it.
178 pim_upstream_del(pim_ifp
->pim
, ch
->upstream
, __PRETTY_FUNCTION__
);
181 THREAD_OFF(ch
->t_ifjoin_expiry_timer
);
182 THREAD_OFF(ch
->t_ifjoin_prune_pending_timer
);
183 THREAD_OFF(ch
->t_ifassert_timer
);
186 listnode_delete(ch
->parent
->sources
, ch
);
190 RB_REMOVE(pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
, ch
);
192 if (PIM_DEBUG_PIM_TRACE
)
193 zlog_debug("%s: ifchannel entry %s is deleted ",
194 __PRETTY_FUNCTION__
, ch
->sg_str
);
196 XFREE(MTYPE_PIM_IFCHANNEL
, ch
);
199 void pim_ifchannel_delete_all(struct interface
*ifp
)
201 struct pim_interface
*pim_ifp
;
202 struct pim_ifchannel
*ch
;
208 while (!RB_EMPTY(pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
)) {
209 ch
= RB_ROOT(pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
);
211 pim_ifchannel_delete(ch
);
215 static void delete_on_noinfo(struct pim_ifchannel
*ch
)
217 if (ch
->local_ifmembership
== PIM_IFMEMBERSHIP_NOINFO
218 && ch
->ifjoin_state
== PIM_IFJOIN_NOINFO
219 && ch
->t_ifjoin_expiry_timer
== NULL
)
220 pim_ifchannel_delete(ch
);
223 void pim_ifchannel_ifjoin_switch(const char *caller
, struct pim_ifchannel
*ch
,
224 enum pim_ifjoin_state new_state
)
226 enum pim_ifjoin_state old_state
= ch
->ifjoin_state
;
227 struct pim_interface
*pim_ifp
= ch
->interface
->info
;
229 if (PIM_DEBUG_PIM_EVENTS
)
231 "PIM_IFCHANNEL(%s): %s is switching from %s to %s",
232 ch
->interface
->name
, ch
->sg_str
,
233 pim_ifchannel_ifjoin_name(ch
->ifjoin_state
, ch
->flags
),
234 pim_ifchannel_ifjoin_name(new_state
, 0));
237 if (old_state
== new_state
) {
238 if (PIM_DEBUG_PIM_EVENTS
) {
240 "%s calledby %s: non-transition on state %d (%s)",
241 __PRETTY_FUNCTION__
, caller
, new_state
,
242 pim_ifchannel_ifjoin_name(new_state
, 0));
247 ch
->ifjoin_state
= new_state
;
249 if (ch
->sg
.src
.s_addr
== INADDR_ANY
) {
250 struct pim_upstream
*up
= ch
->upstream
;
251 struct pim_upstream
*child
;
252 struct listnode
*up_node
;
255 if (ch
->ifjoin_state
== PIM_IFJOIN_NOINFO
) {
256 for (ALL_LIST_ELEMENTS_RO(up
->sources
, up_node
,
258 struct channel_oil
*c_oil
=
261 if (PIM_DEBUG_PIM_TRACE
)
263 "%s %s: Prune(S,G)=%s from %s",
271 if (!pim_upstream_evaluate_join_desired(
272 pim_ifp
->pim
, child
)) {
274 c_oil
, ch
->interface
,
275 PIM_OIF_FLAG_PROTO_STAR
);
276 pim_upstream_update_join_desired(
277 pim_ifp
->pim
, child
);
281 * If the S,G has no if channel and the
283 * has output here then the *,G was
284 * supplying the implied
285 * if channel. So remove it.
286 * I think this is dead code now. is it?
288 if (c_oil
->oil
.mfcc_ttls
289 [pim_ifp
->mroute_vif_index
])
291 c_oil
, ch
->interface
,
292 PIM_OIF_FLAG_PROTO_STAR
);
295 if (ch
->ifjoin_state
== PIM_IFJOIN_JOIN
) {
296 for (ALL_LIST_ELEMENTS_RO(up
->sources
, up_node
,
298 if (PIM_DEBUG_PIM_TRACE
)
300 "%s %s: Join(S,G)=%s from %s",
306 if (pim_upstream_evaluate_join_desired(
307 pim_ifp
->pim
, child
)) {
311 PIM_OIF_FLAG_PROTO_STAR
);
312 pim_upstream_update_join_desired(
313 pim_ifp
->pim
, child
);
319 /* Transition to/from NOINFO ? */
320 if ((old_state
== PIM_IFJOIN_NOINFO
)
321 || (new_state
== PIM_IFJOIN_NOINFO
)) {
323 if (PIM_DEBUG_PIM_EVENTS
) {
324 zlog_debug("PIM_IFCHANNEL_%s: (S,G)=%s on interface %s",
325 ((new_state
== PIM_IFJOIN_NOINFO
) ? "DOWN"
327 ch
->sg_str
, ch
->interface
->name
);
331 Record uptime of state transition to/from NOINFO
333 ch
->ifjoin_creation
= pim_time_monotonic_sec();
335 pim_upstream_update_join_desired(pim_ifp
->pim
, ch
->upstream
);
336 pim_ifchannel_update_could_assert(ch
);
337 pim_ifchannel_update_assert_tracking_desired(ch
);
341 const char *pim_ifchannel_ifjoin_name(enum pim_ifjoin_state ifjoin_state
,
344 switch (ifjoin_state
) {
345 case PIM_IFJOIN_NOINFO
:
346 if (PIM_IF_FLAG_TEST_S_G_RPT(flags
))
351 case PIM_IFJOIN_JOIN
:
354 case PIM_IFJOIN_PRUNE
:
355 if (PIM_IF_FLAG_TEST_S_G_RPT(flags
))
360 case PIM_IFJOIN_PRUNE_PENDING
:
361 if (PIM_IF_FLAG_TEST_S_G_RPT(flags
))
366 case PIM_IFJOIN_PRUNE_TMP
:
367 if (PIM_IF_FLAG_TEST_S_G_RPT(flags
))
372 case PIM_IFJOIN_PRUNE_PENDING_TMP
:
373 if (PIM_IF_FLAG_TEST_S_G_RPT(flags
))
380 return "ifjoin_bad_state";
383 const char *pim_ifchannel_ifassert_name(enum pim_ifassert_state ifassert_state
)
385 switch (ifassert_state
) {
386 case PIM_IFASSERT_NOINFO
:
388 case PIM_IFASSERT_I_AM_WINNER
:
390 case PIM_IFASSERT_I_AM_LOSER
:
394 return "ifassert_bad_state";
398 RFC 4601: 4.6.5. Assert State Macros
400 AssertWinner(S,G,I) defaults to NULL and AssertWinnerMetric(S,G,I)
401 defaults to Infinity when in the NoInfo state.
403 void reset_ifassert_state(struct pim_ifchannel
*ch
)
405 struct in_addr any
= {.s_addr
= INADDR_ANY
};
407 THREAD_OFF(ch
->t_ifassert_timer
);
409 pim_ifassert_winner_set(ch
, PIM_IFASSERT_NOINFO
, any
,
410 qpim_infinite_assert_metric
);
413 struct pim_ifchannel
*pim_ifchannel_find(struct interface
*ifp
,
414 struct prefix_sg
*sg
)
416 struct pim_interface
*pim_ifp
;
417 struct pim_ifchannel
*ch
;
418 struct pim_ifchannel lookup
;
423 zlog_warn("%s: (S,G)=%s: multicast not enabled on interface %s",
424 __PRETTY_FUNCTION__
, pim_str_sg_dump(sg
), ifp
->name
);
429 lookup
.interface
= ifp
;
430 ch
= RB_FIND(pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
, &lookup
);
435 static void ifmembership_set(struct pim_ifchannel
*ch
,
436 enum pim_ifmembership membership
)
438 struct pim_interface
*pim_ifp
= ch
->interface
->info
;
440 if (ch
->local_ifmembership
== membership
)
443 if (PIM_DEBUG_PIM_EVENTS
) {
444 zlog_debug("%s: (S,G)=%s membership now is %s on interface %s",
445 __PRETTY_FUNCTION__
, ch
->sg_str
,
446 membership
== PIM_IFMEMBERSHIP_INCLUDE
? "INCLUDE"
448 ch
->interface
->name
);
451 ch
->local_ifmembership
= membership
;
453 pim_upstream_update_join_desired(pim_ifp
->pim
, ch
->upstream
);
454 pim_ifchannel_update_could_assert(ch
);
455 pim_ifchannel_update_assert_tracking_desired(ch
);
459 void pim_ifchannel_membership_clear(struct interface
*ifp
)
461 struct pim_interface
*pim_ifp
;
462 struct pim_ifchannel
*ch
;
467 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
)
468 ifmembership_set(ch
, PIM_IFMEMBERSHIP_NOINFO
);
471 void pim_ifchannel_delete_on_noinfo(struct interface
*ifp
)
473 struct pim_interface
*pim_ifp
;
474 struct pim_ifchannel
*ch
, *ch_tmp
;
479 RB_FOREACH_SAFE (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
, ch_tmp
)
480 delete_on_noinfo(ch
);
484 * For a given Interface, if we are given a S,G
485 * Find the *,G (If we have it).
486 * If we are passed a *,G, find the *,* ifchannel
489 static struct pim_ifchannel
*pim_ifchannel_find_parent(struct pim_ifchannel
*ch
)
491 struct prefix_sg parent_sg
= ch
->sg
;
492 struct pim_ifchannel
*parent
= NULL
;
495 if ((parent_sg
.src
.s_addr
!= INADDR_ANY
)
496 && (parent_sg
.grp
.s_addr
!= INADDR_ANY
)) {
497 parent_sg
.src
.s_addr
= INADDR_ANY
;
498 parent
= pim_ifchannel_find(ch
->interface
, &parent_sg
);
501 listnode_add(parent
->sources
, ch
);
508 struct pim_ifchannel
*pim_ifchannel_add(struct interface
*ifp
,
509 struct prefix_sg
*sg
,
510 uint8_t source_flags
, int up_flags
)
512 struct pim_interface
*pim_ifp
;
513 struct pim_ifchannel
*ch
;
514 struct pim_upstream
*up
;
516 ch
= pim_ifchannel_find(ifp
, sg
);
522 ch
= XCALLOC(MTYPE_PIM_IFCHANNEL
, sizeof(*ch
));
525 "%s: pim_ifchannel_new() failure for (S,G)=%s on interface %s",
526 __PRETTY_FUNCTION__
, pim_str_sg_dump(sg
), ifp
->name
);
531 if ((source_flags
& PIM_ENCODE_RPT_BIT
)
532 && !(source_flags
& PIM_ENCODE_WC_BIT
))
533 PIM_IF_FLAG_SET_S_G_RPT(ch
->flags
);
537 pim_str_sg_set(sg
, ch
->sg_str
);
538 ch
->parent
= pim_ifchannel_find_parent(ch
);
539 if (ch
->sg
.src
.s_addr
== INADDR_ANY
) {
540 ch
->sources
= list_new();
542 (int (*)(void *, void *))pim_ifchannel_compare
;
546 pim_ifchannel_find_new_children(ch
);
547 ch
->local_ifmembership
= PIM_IFMEMBERSHIP_NOINFO
;
549 ch
->ifjoin_state
= PIM_IFJOIN_NOINFO
;
550 ch
->t_ifjoin_expiry_timer
= NULL
;
551 ch
->t_ifjoin_prune_pending_timer
= NULL
;
552 ch
->ifjoin_creation
= 0;
554 RB_INSERT(pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
, ch
);
556 up
= pim_upstream_add(pim_ifp
->pim
, sg
, NULL
, up_flags
,
557 __PRETTY_FUNCTION__
, ch
);
561 "%s: could not attach upstream (S,G)=%s on interface %s",
562 __PRETTY_FUNCTION__
, pim_str_sg_dump(sg
), ifp
->name
);
565 listnode_delete(ch
->parent
->sources
, ch
);
567 pim_ifchannel_remove_children(ch
);
569 list_delete_and_null(&ch
->sources
);
571 THREAD_OFF(ch
->t_ifjoin_expiry_timer
);
572 THREAD_OFF(ch
->t_ifjoin_prune_pending_timer
);
573 THREAD_OFF(ch
->t_ifassert_timer
);
575 RB_REMOVE(pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
, ch
);
576 XFREE(MTYPE_PIM_IFCHANNEL
, ch
);
581 listnode_add_sort(up
->ifchannels
, ch
);
583 ch
->ifassert_my_metric
= pim_macro_ch_my_assert_metric_eval(ch
);
584 ch
->ifassert_winner_metric
= pim_macro_ch_my_assert_metric_eval(ch
);
586 ch
->ifassert_winner
.s_addr
= 0;
589 ch
->t_ifassert_timer
= NULL
;
590 ch
->ifassert_state
= PIM_IFASSERT_NOINFO
;
591 reset_ifassert_state(ch
);
592 if (pim_macro_ch_could_assert_eval(ch
))
593 PIM_IF_FLAG_SET_COULD_ASSERT(ch
->flags
);
595 PIM_IF_FLAG_UNSET_COULD_ASSERT(ch
->flags
);
597 if (pim_macro_assert_tracking_desired_eval(ch
))
598 PIM_IF_FLAG_SET_ASSERT_TRACKING_DESIRED(ch
->flags
);
600 PIM_IF_FLAG_UNSET_ASSERT_TRACKING_DESIRED(ch
->flags
);
602 if (PIM_DEBUG_PIM_TRACE
)
603 zlog_debug("%s: ifchannel %s is created ", __PRETTY_FUNCTION__
,
609 static void ifjoin_to_noinfo(struct pim_ifchannel
*ch
, bool ch_del
)
611 pim_forward_stop(ch
, !ch_del
);
612 pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__
, ch
, PIM_IFJOIN_NOINFO
);
614 delete_on_noinfo(ch
);
617 static int on_ifjoin_expiry_timer(struct thread
*t
)
619 struct pim_ifchannel
*ch
;
623 ifjoin_to_noinfo(ch
, true);
624 /* ch may have been deleted */
629 static int on_ifjoin_prune_pending_timer(struct thread
*t
)
631 struct pim_ifchannel
*ch
;
632 int send_prune_echo
; /* boolean */
633 struct interface
*ifp
;
634 struct pim_interface
*pim_ifp
;
640 "%s: IFCHANNEL%s %s Prune Pending Timer Popped",
641 __PRETTY_FUNCTION__
, pim_str_sg_dump(&ch
->sg
),
642 pim_ifchannel_ifjoin_name(ch
->ifjoin_state
, ch
->flags
));
644 if (ch
->ifjoin_state
== PIM_IFJOIN_PRUNE_PENDING
) {
647 if (!PIM_IF_FLAG_TEST_S_G_RPT(ch
->flags
)) {
648 /* Send PruneEcho(S,G) ? */
650 (listcount(pim_ifp
->pim_neighbor_list
) > 1);
652 if (send_prune_echo
) {
655 rpf
.source_nexthop
.interface
= ifp
;
656 rpf
.rpf_addr
.u
.prefix4
=
657 pim_ifp
->primary_address
;
658 pim_jp_agg_single_upstream_send(
659 &rpf
, ch
->upstream
, 0);
662 ifjoin_to_noinfo(ch
, true);
664 /* If SGRpt flag is set on ifchannel, Trigger SGRpt
665 * message on RP path upon prune timer expiry.
667 ch
->ifjoin_state
= PIM_IFJOIN_PRUNE
;
669 struct pim_upstream
*parent
=
670 ch
->upstream
->parent
;
672 pim_upstream_update_join_desired(pim_ifp
->pim
,
675 pim_jp_agg_single_upstream_send(&parent
->rpf
,
679 /* from here ch may have been deleted */
685 static void check_recv_upstream(int is_join
, struct interface
*recv_ifp
,
686 struct in_addr upstream
, struct prefix_sg
*sg
,
687 uint8_t source_flags
, int holdtime
)
689 struct pim_upstream
*up
;
690 struct pim_interface
*pim_ifp
= recv_ifp
->info
;
692 /* Upstream (S,G) in Joined state ? */
693 up
= pim_upstream_find(pim_ifp
->pim
, sg
);
696 if (up
->join_state
!= PIM_UPSTREAM_JOINED
)
699 /* Upstream (S,G) in Joined state */
701 if (pim_rpf_addr_is_inaddr_any(&up
->rpf
)) {
702 /* RPF'(S,G) not found */
703 zlog_warn("%s %s: RPF'%s not found", __FILE__
,
704 __PRETTY_FUNCTION__
, up
->sg_str
);
708 /* upstream directed to RPF'(S,G) ? */
709 if (upstream
.s_addr
!= up
->rpf
.rpf_addr
.u
.prefix4
.s_addr
) {
710 char up_str
[INET_ADDRSTRLEN
];
711 char rpf_str
[PREFIX_STRLEN
];
712 pim_inet4_dump("<up?>", upstream
, up_str
, sizeof(up_str
));
713 pim_addr_dump("<rpf?>", &up
->rpf
.rpf_addr
, rpf_str
,
716 "%s %s: (S,G)=%s upstream=%s not directed to RPF'(S,G)=%s on interface %s",
717 __FILE__
, __PRETTY_FUNCTION__
, up
->sg_str
, up_str
,
718 rpf_str
, recv_ifp
->name
);
721 /* upstream directed to RPF'(S,G) */
724 /* Join(S,G) to RPF'(S,G) */
725 pim_upstream_join_suppress(up
, up
->rpf
.rpf_addr
.u
.prefix4
,
730 /* Prune to RPF'(S,G) */
732 if (source_flags
& PIM_RPT_BIT_MASK
) {
733 if (source_flags
& PIM_WILDCARD_BIT_MASK
) {
734 /* Prune(*,G) to RPF'(S,G) */
735 pim_upstream_join_timer_decrease_to_t_override(
740 /* Prune(S,G,rpt) to RPF'(S,G) */
741 pim_upstream_join_timer_decrease_to_t_override("Prune(S,G,rpt)",
746 /* Prune(S,G) to RPF'(S,G) */
747 pim_upstream_join_timer_decrease_to_t_override("Prune(S,G)", up
);
750 static int nonlocal_upstream(int is_join
, struct interface
*recv_ifp
,
751 struct in_addr upstream
, struct prefix_sg
*sg
,
752 uint8_t source_flags
, uint16_t holdtime
)
754 struct pim_interface
*recv_pim_ifp
;
755 int is_local
; /* boolean */
757 recv_pim_ifp
= recv_ifp
->info
;
758 zassert(recv_pim_ifp
);
760 is_local
= (upstream
.s_addr
== recv_pim_ifp
->primary_address
.s_addr
);
765 if (PIM_DEBUG_PIM_TRACE_DETAIL
) {
766 char up_str
[INET_ADDRSTRLEN
];
767 pim_inet4_dump("<upstream?>", upstream
, up_str
, sizeof(up_str
));
768 zlog_warn("%s: recv %s (S,G)=%s to non-local upstream=%s on %s",
769 __PRETTY_FUNCTION__
, is_join
? "join" : "prune",
770 pim_str_sg_dump(sg
), up_str
, recv_ifp
->name
);
774 * Since recv upstream addr was not directed to our primary
775 * address, check if we should react to it in any way.
777 check_recv_upstream(is_join
, recv_ifp
, upstream
, sg
, source_flags
,
780 return 1; /* non-local */
783 void pim_ifchannel_join_add(struct interface
*ifp
, struct in_addr neigh_addr
,
784 struct in_addr upstream
, struct prefix_sg
*sg
,
785 uint8_t source_flags
, uint16_t holdtime
)
787 struct pim_interface
*pim_ifp
;
788 struct pim_ifchannel
*ch
;
790 if (nonlocal_upstream(1 /* join */, ifp
, upstream
, sg
, source_flags
,
795 ch
= pim_ifchannel_add(ifp
, sg
, source_flags
,
796 PIM_UPSTREAM_FLAG_MASK_SRC_PIM
);
801 RFC 4601: 4.6.1. (S,G) Assert Message State Machine
803 Transitions from "I am Assert Loser" State
805 Receive Join(S,G) on Interface I
807 We receive a Join(S,G) that has the Upstream Neighbor Address
808 field set to my primary IP address on interface I. The action is
809 to transition to NoInfo state, delete this (S,G) assert state
810 (Actions A5 below), and allow the normal PIM Join/Prune mechanisms
813 Notice: The nonlocal_upstream() test above ensures the upstream
814 address of the join message is our primary address.
816 if (ch
->ifassert_state
== PIM_IFASSERT_I_AM_LOSER
) {
817 char neigh_str
[INET_ADDRSTRLEN
];
818 pim_inet4_dump("<neigh?>", neigh_addr
, neigh_str
,
820 zlog_warn("%s: Assert Loser recv Join%s from %s on %s",
821 __PRETTY_FUNCTION__
, ch
->sg_str
, neigh_str
,
824 assert_action_a5(ch
);
830 switch (ch
->ifjoin_state
) {
831 case PIM_IFJOIN_NOINFO
:
832 pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__
, ch
,
834 if (pim_macro_chisin_oiflist(ch
)) {
835 pim_upstream_inherited_olist(pim_ifp
->pim
,
837 pim_forward_start(ch
);
840 * If we are going to be a LHR, we need to note it
842 if (ch
->upstream
->parent
&& (ch
->upstream
->parent
->flags
843 & PIM_UPSTREAM_FLAG_MASK_SRC_IGMP
)
844 && !(ch
->upstream
->flags
845 & PIM_UPSTREAM_FLAG_MASK_SRC_LHR
)) {
846 pim_upstream_ref(ch
->upstream
,
847 PIM_UPSTREAM_FLAG_MASK_SRC_LHR
,
848 __PRETTY_FUNCTION__
);
849 pim_upstream_keep_alive_timer_start(
850 ch
->upstream
, pim_ifp
->pim
->keep_alive_time
);
853 case PIM_IFJOIN_JOIN
:
854 zassert(!ch
->t_ifjoin_prune_pending_timer
);
857 In the JOIN state ch->t_ifjoin_expiry_timer may be NULL due to
859 previously received join message with holdtime=0xFFFF.
861 if (ch
->t_ifjoin_expiry_timer
) {
862 unsigned long remain
= thread_timer_remain_second(
863 ch
->t_ifjoin_expiry_timer
);
864 if (remain
> holdtime
) {
866 RFC 4601: 4.5.3. Receiving (S,G) Join/Prune
869 Transitions from Join State
871 The (S,G) downstream state machine on
872 interface I remains in
873 Join state, and the Expiry Timer (ET) is
875 maximum of its current value and the HoldTime
877 triggering Join/Prune message.
879 Conclusion: Do not change the ET if the
881 higher than the received join holdtime.
886 THREAD_OFF(ch
->t_ifjoin_expiry_timer
);
888 case PIM_IFJOIN_PRUNE
:
889 if (source_flags
& PIM_ENCODE_RPT_BIT
)
890 pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__
, ch
,
893 case PIM_IFJOIN_PRUNE_PENDING
:
894 THREAD_OFF(ch
->t_ifjoin_prune_pending_timer
);
895 if (source_flags
& PIM_ENCODE_RPT_BIT
) {
896 THREAD_OFF(ch
->t_ifjoin_expiry_timer
);
897 pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__
, ch
,
900 pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__
, ch
,
903 case PIM_IFJOIN_PRUNE_TMP
:
905 case PIM_IFJOIN_PRUNE_PENDING_TMP
:
909 if (holdtime
!= 0xFFFF) {
910 thread_add_timer(master
, on_ifjoin_expiry_timer
, ch
, holdtime
,
911 &ch
->t_ifjoin_expiry_timer
);
915 void pim_ifchannel_prune(struct interface
*ifp
, struct in_addr upstream
,
916 struct prefix_sg
*sg
, uint8_t source_flags
,
919 struct pim_ifchannel
*ch
;
920 struct pim_interface
*pim_ifp
;
921 int jp_override_interval_msec
;
923 if (nonlocal_upstream(0 /* prune */, ifp
, upstream
, sg
, source_flags
,
928 ch
= pim_ifchannel_find(ifp
, sg
);
929 if (!ch
&& !(source_flags
& PIM_ENCODE_RPT_BIT
)) {
932 "%s: Received prune with no relevant ifchannel %s(%s) state: %d",
933 __PRETTY_FUNCTION__
, ifp
->name
,
934 pim_str_sg_dump(sg
), source_flags
);
938 ch
= pim_ifchannel_add(ifp
, sg
, source_flags
,
939 PIM_UPSTREAM_FLAG_MASK_SRC_PIM
);
945 switch (ch
->ifjoin_state
) {
946 case PIM_IFJOIN_NOINFO
:
947 if (source_flags
& PIM_ENCODE_RPT_BIT
) {
948 if (!(source_flags
& PIM_ENCODE_WC_BIT
))
949 PIM_IF_FLAG_SET_S_G_RPT(ch
->flags
);
951 ch
->ifjoin_state
= PIM_IFJOIN_PRUNE_PENDING
;
952 if (listcount(pim_ifp
->pim_neighbor_list
) > 1)
953 jp_override_interval_msec
=
954 pim_if_jp_override_interval_msec(ifp
);
956 jp_override_interval_msec
=
957 0; /* schedule to expire immediately */
958 /* If we called ifjoin_prune() directly instead, care
960 be taken not to use "ch" afterwards since it would be
963 THREAD_OFF(ch
->t_ifjoin_prune_pending_timer
);
964 THREAD_OFF(ch
->t_ifjoin_expiry_timer
);
965 thread_add_timer_msec(
966 master
, on_ifjoin_prune_pending_timer
, ch
,
967 jp_override_interval_msec
,
968 &ch
->t_ifjoin_prune_pending_timer
);
969 thread_add_timer(master
, on_ifjoin_expiry_timer
, ch
,
970 holdtime
, &ch
->t_ifjoin_expiry_timer
);
971 pim_upstream_update_join_desired(pim_ifp
->pim
,
975 case PIM_IFJOIN_PRUNE_PENDING
:
978 case PIM_IFJOIN_JOIN
:
979 THREAD_OFF(ch
->t_ifjoin_expiry_timer
);
981 pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__
, ch
,
982 PIM_IFJOIN_PRUNE_PENDING
);
984 if (listcount(pim_ifp
->pim_neighbor_list
) > 1)
985 jp_override_interval_msec
=
986 pim_if_jp_override_interval_msec(ifp
);
988 jp_override_interval_msec
=
989 0; /* schedule to expire immediately */
990 /* If we called ifjoin_prune() directly instead, care should
991 be taken not to use "ch" afterwards since it would be
993 THREAD_OFF(ch
->t_ifjoin_prune_pending_timer
);
994 thread_add_timer_msec(master
, on_ifjoin_prune_pending_timer
, ch
,
995 jp_override_interval_msec
,
996 &ch
->t_ifjoin_prune_pending_timer
);
998 case PIM_IFJOIN_PRUNE
:
999 if (source_flags
& PIM_ENCODE_RPT_BIT
) {
1000 THREAD_OFF(ch
->t_ifjoin_prune_pending_timer
);
1001 thread_add_timer(master
, on_ifjoin_expiry_timer
, ch
,
1002 holdtime
, &ch
->t_ifjoin_expiry_timer
);
1005 case PIM_IFJOIN_PRUNE_TMP
:
1006 if (source_flags
& PIM_ENCODE_RPT_BIT
) {
1007 ch
->ifjoin_state
= PIM_IFJOIN_PRUNE
;
1008 THREAD_OFF(ch
->t_ifjoin_expiry_timer
);
1009 thread_add_timer(master
, on_ifjoin_expiry_timer
, ch
,
1010 holdtime
, &ch
->t_ifjoin_expiry_timer
);
1013 case PIM_IFJOIN_PRUNE_PENDING_TMP
:
1014 if (source_flags
& PIM_ENCODE_RPT_BIT
) {
1015 ch
->ifjoin_state
= PIM_IFJOIN_PRUNE_PENDING
;
1016 THREAD_OFF(ch
->t_ifjoin_expiry_timer
);
1017 thread_add_timer(master
, on_ifjoin_expiry_timer
, ch
,
1018 holdtime
, &ch
->t_ifjoin_expiry_timer
);
1024 int pim_ifchannel_local_membership_add(struct interface
*ifp
,
1025 struct prefix_sg
*sg
)
1027 struct pim_ifchannel
*ch
, *starch
;
1028 struct pim_interface
*pim_ifp
;
1029 struct pim_instance
*pim
;
1031 /* PIM enabled on interface? */
1032 pim_ifp
= ifp
->info
;
1035 if (!PIM_IF_TEST_PIM(pim_ifp
->options
))
1040 /* skip (*,G) ch creation if G is of type SSM */
1041 if (sg
->src
.s_addr
== INADDR_ANY
) {
1042 if (pim_is_grp_ssm(pim
, sg
->grp
)) {
1043 if (PIM_DEBUG_PIM_EVENTS
)
1045 "%s: local membership (S,G)=%s ignored as group is SSM",
1046 __PRETTY_FUNCTION__
,
1047 pim_str_sg_dump(sg
));
1052 ch
= pim_ifchannel_add(ifp
, sg
, 0, PIM_UPSTREAM_FLAG_MASK_SRC_IGMP
);
1057 ifmembership_set(ch
, PIM_IFMEMBERSHIP_INCLUDE
);
1059 if (sg
->src
.s_addr
== INADDR_ANY
) {
1060 struct pim_upstream
*up
= pim_upstream_find(pim
, sg
);
1061 struct pim_upstream
*child
;
1062 struct listnode
*up_node
;
1066 for (ALL_LIST_ELEMENTS_RO(up
->sources
, up_node
, child
)) {
1067 if (PIM_DEBUG_EVENTS
)
1068 zlog_debug("%s %s: IGMP (S,G)=%s(%s) from %s",
1069 __FILE__
, __PRETTY_FUNCTION__
,
1070 child
->sg_str
, ifp
->name
,
1073 ch
= pim_ifchannel_find(ifp
, &child
->sg
);
1074 if (pim_upstream_evaluate_join_desired_interface(
1075 child
, ch
, starch
)) {
1076 pim_channel_add_oif(child
->channel_oil
, ifp
,
1077 PIM_OIF_FLAG_PROTO_STAR
);
1078 pim_upstream_switch(pim
, child
,
1079 PIM_UPSTREAM_JOINED
);
1083 if (pim
->spt
.switchover
== PIM_SPT_INFINITY
) {
1084 if (pim
->spt
.plist
) {
1085 struct prefix_list
*plist
= prefix_list_lookup(
1086 AFI_IP
, pim
->spt
.plist
);
1089 g
.prefixlen
= IPV4_MAX_PREFIXLEN
;
1090 g
.u
.prefix4
= up
->sg
.grp
;
1092 if (prefix_list_apply(plist
, &g
)
1094 pim_channel_add_oif(
1095 up
->channel_oil
, pim
->regiface
,
1096 PIM_OIF_FLAG_PROTO_IGMP
);
1100 pim_channel_add_oif(up
->channel_oil
, pim
->regiface
,
1101 PIM_OIF_FLAG_PROTO_IGMP
);
1107 void pim_ifchannel_local_membership_del(struct interface
*ifp
,
1108 struct prefix_sg
*sg
)
1110 struct pim_ifchannel
*starch
, *ch
, *orig
;
1111 struct pim_interface
*pim_ifp
;
1113 /* PIM enabled on interface? */
1114 pim_ifp
= ifp
->info
;
1117 if (!PIM_IF_TEST_PIM(pim_ifp
->options
))
1120 orig
= ch
= pim_ifchannel_find(ifp
, sg
);
1123 ifmembership_set(ch
, PIM_IFMEMBERSHIP_NOINFO
);
1125 if (sg
->src
.s_addr
== INADDR_ANY
) {
1126 struct pim_upstream
*up
= pim_upstream_find(pim_ifp
->pim
, sg
);
1127 struct pim_upstream
*child
;
1128 struct listnode
*up_node
, *up_nnode
;
1132 for (ALL_LIST_ELEMENTS(up
->sources
, up_node
, up_nnode
, child
)) {
1133 struct channel_oil
*c_oil
= child
->channel_oil
;
1134 struct pim_ifchannel
*chchannel
=
1135 pim_ifchannel_find(ifp
, &child
->sg
);
1136 struct pim_interface
*pim_ifp
= ifp
->info
;
1138 if (PIM_DEBUG_EVENTS
)
1139 zlog_debug("%s %s: Prune(S,G)=%s(%s) from %s",
1140 __FILE__
, __PRETTY_FUNCTION__
,
1141 up
->sg_str
, ifp
->name
,
1144 ch
= pim_ifchannel_find(ifp
, &child
->sg
);
1146 && !pim_upstream_evaluate_join_desired_interface(
1148 pim_channel_del_oif(c_oil
, ifp
,
1149 PIM_OIF_FLAG_PROTO_STAR
);
1152 * If the S,G has no if channel and the c_oil still
1153 * has output here then the *,G was supplying the
1155 * if channel. So remove it.
1157 if (!chchannel
&& c_oil
1158 && c_oil
->oil
.mfcc_ttls
[pim_ifp
->mroute_vif_index
])
1159 pim_channel_del_oif(c_oil
, ifp
,
1160 PIM_OIF_FLAG_PROTO_STAR
);
1162 /* Child node removal/ref count-- will happen as part of
1163 * parent' delete_no_info */
1166 delete_on_noinfo(orig
);
1169 void pim_ifchannel_update_could_assert(struct pim_ifchannel
*ch
)
1171 int old_couldassert
=
1172 PIM_FORCE_BOOLEAN(PIM_IF_FLAG_TEST_COULD_ASSERT(ch
->flags
));
1173 int new_couldassert
=
1174 PIM_FORCE_BOOLEAN(pim_macro_ch_could_assert_eval(ch
));
1176 if (new_couldassert
== old_couldassert
)
1179 if (PIM_DEBUG_PIM_EVENTS
) {
1180 char src_str
[INET_ADDRSTRLEN
];
1181 char grp_str
[INET_ADDRSTRLEN
];
1182 pim_inet4_dump("<src?>", ch
->sg
.src
, src_str
, sizeof(src_str
));
1183 pim_inet4_dump("<grp?>", ch
->sg
.grp
, grp_str
, sizeof(grp_str
));
1184 zlog_debug("%s: CouldAssert(%s,%s,%s) changed from %d to %d",
1185 __PRETTY_FUNCTION__
, src_str
, grp_str
,
1186 ch
->interface
->name
, old_couldassert
,
1190 if (new_couldassert
) {
1191 /* CouldAssert(S,G,I) switched from FALSE to TRUE */
1192 PIM_IF_FLAG_SET_COULD_ASSERT(ch
->flags
);
1194 /* CouldAssert(S,G,I) switched from TRUE to FALSE */
1195 PIM_IF_FLAG_UNSET_COULD_ASSERT(ch
->flags
);
1197 if (ch
->ifassert_state
== PIM_IFASSERT_I_AM_WINNER
) {
1198 assert_action_a4(ch
);
1202 pim_ifchannel_update_my_assert_metric(ch
);
1206 my_assert_metric may be affected by:
1209 pim_ifp->primary_address
1210 rpf->source_nexthop.mrib_metric_preference;
1211 rpf->source_nexthop.mrib_route_metric;
1213 void pim_ifchannel_update_my_assert_metric(struct pim_ifchannel
*ch
)
1215 struct pim_assert_metric my_metric_new
=
1216 pim_macro_ch_my_assert_metric_eval(ch
);
1218 if (pim_assert_metric_match(&my_metric_new
, &ch
->ifassert_my_metric
))
1221 if (PIM_DEBUG_PIM_EVENTS
) {
1222 char src_str
[INET_ADDRSTRLEN
];
1223 char grp_str
[INET_ADDRSTRLEN
];
1224 char old_addr_str
[INET_ADDRSTRLEN
];
1225 char new_addr_str
[INET_ADDRSTRLEN
];
1226 pim_inet4_dump("<src?>", ch
->sg
.src
, src_str
, sizeof(src_str
));
1227 pim_inet4_dump("<grp?>", ch
->sg
.grp
, grp_str
, sizeof(grp_str
));
1228 pim_inet4_dump("<old_addr?>", ch
->ifassert_my_metric
.ip_address
,
1229 old_addr_str
, sizeof(old_addr_str
));
1230 pim_inet4_dump("<new_addr?>", my_metric_new
.ip_address
,
1231 new_addr_str
, sizeof(new_addr_str
));
1233 "%s: my_assert_metric(%s,%s,%s) changed from %u,%u,%u,%s to %u,%u,%u,%s",
1234 __PRETTY_FUNCTION__
, src_str
, grp_str
,
1235 ch
->interface
->name
,
1236 ch
->ifassert_my_metric
.rpt_bit_flag
,
1237 ch
->ifassert_my_metric
.metric_preference
,
1238 ch
->ifassert_my_metric
.route_metric
, old_addr_str
,
1239 my_metric_new
.rpt_bit_flag
,
1240 my_metric_new
.metric_preference
,
1241 my_metric_new
.route_metric
, new_addr_str
);
1244 ch
->ifassert_my_metric
= my_metric_new
;
1246 if (pim_assert_metric_better(&ch
->ifassert_my_metric
,
1247 &ch
->ifassert_winner_metric
)) {
1248 assert_action_a5(ch
);
1252 void pim_ifchannel_update_assert_tracking_desired(struct pim_ifchannel
*ch
)
1254 int old_atd
= PIM_FORCE_BOOLEAN(
1255 PIM_IF_FLAG_TEST_ASSERT_TRACKING_DESIRED(ch
->flags
));
1257 PIM_FORCE_BOOLEAN(pim_macro_assert_tracking_desired_eval(ch
));
1259 if (new_atd
== old_atd
)
1262 if (PIM_DEBUG_PIM_EVENTS
) {
1263 char src_str
[INET_ADDRSTRLEN
];
1264 char grp_str
[INET_ADDRSTRLEN
];
1265 pim_inet4_dump("<src?>", ch
->sg
.src
, src_str
, sizeof(src_str
));
1266 pim_inet4_dump("<grp?>", ch
->sg
.grp
, grp_str
, sizeof(grp_str
));
1268 "%s: AssertTrackingDesired(%s,%s,%s) changed from %d to %d",
1269 __PRETTY_FUNCTION__
, src_str
, grp_str
,
1270 ch
->interface
->name
, old_atd
, new_atd
);
1274 /* AssertTrackingDesired(S,G,I) switched from FALSE to TRUE */
1275 PIM_IF_FLAG_SET_ASSERT_TRACKING_DESIRED(ch
->flags
);
1277 /* AssertTrackingDesired(S,G,I) switched from TRUE to FALSE */
1278 PIM_IF_FLAG_UNSET_ASSERT_TRACKING_DESIRED(ch
->flags
);
1280 if (ch
->ifassert_state
== PIM_IFASSERT_I_AM_LOSER
) {
1281 assert_action_a5(ch
);
1287 * If we have a new pim interface, check to
1288 * see if any of the pre-existing channels have
1289 * their upstream out that way and turn on forwarding
1290 * for that ifchannel then.
1292 void pim_ifchannel_scan_forward_start(struct interface
*new_ifp
)
1294 struct pim_interface
*new_pim_ifp
= new_ifp
->info
;
1295 struct pim_instance
*pim
= new_pim_ifp
->pim
;
1296 struct interface
*ifp
;
1298 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1299 struct pim_interface
*loop_pim_ifp
= ifp
->info
;
1300 struct pim_ifchannel
*ch
;
1305 if (new_pim_ifp
== loop_pim_ifp
)
1308 RB_FOREACH (ch
, pim_ifchannel_rb
, &loop_pim_ifp
->ifchannel_rb
) {
1309 if (ch
->ifjoin_state
== PIM_IFJOIN_JOIN
) {
1310 struct pim_upstream
*up
= ch
->upstream
;
1311 if ((!up
->channel_oil
)
1312 && (up
->rpf
.source_nexthop
1313 .interface
== new_ifp
))
1314 pim_forward_start(ch
);
1321 * Downstream per-interface (S,G,rpt) state machine
1322 * states that we need to move (S,G,rpt) items
1323 * into different states at the start of the
1324 * reception of a *,G join as well, when
1325 * we get End of Message
1327 void pim_ifchannel_set_star_g_join_state(struct pim_ifchannel
*ch
, int eom
,
1330 struct pim_ifchannel
*child
;
1331 struct listnode
*ch_node
, *nch_node
;
1332 struct pim_instance
*pim
=
1333 ((struct pim_interface
*)ch
->interface
->info
)->pim
;
1335 if (PIM_DEBUG_PIM_TRACE
)
1337 "%s: %s %s eom: %d join %u", __PRETTY_FUNCTION__
,
1338 pim_ifchannel_ifjoin_name(ch
->ifjoin_state
, ch
->flags
),
1339 ch
->sg_str
, eom
, join
);
1343 for (ALL_LIST_ELEMENTS(ch
->sources
, ch_node
, nch_node
, child
)) {
1344 if (!PIM_IF_FLAG_TEST_S_G_RPT(child
->flags
))
1347 switch (child
->ifjoin_state
) {
1348 case PIM_IFJOIN_NOINFO
:
1349 case PIM_IFJOIN_JOIN
:
1351 case PIM_IFJOIN_PRUNE
:
1353 child
->ifjoin_state
= PIM_IFJOIN_PRUNE_TMP
;
1355 case PIM_IFJOIN_PRUNE_PENDING
:
1357 child
->ifjoin_state
=
1358 PIM_IFJOIN_PRUNE_PENDING_TMP
;
1360 case PIM_IFJOIN_PRUNE_TMP
:
1361 case PIM_IFJOIN_PRUNE_PENDING_TMP
:
1365 if (child
->ifjoin_state
== PIM_IFJOIN_PRUNE_PENDING_TMP
)
1366 THREAD_OFF(child
->t_ifjoin_prune_pending_timer
);
1367 THREAD_OFF(child
->t_ifjoin_expiry_timer
);
1368 struct pim_upstream
*parent
= child
->upstream
->parent
;
1370 PIM_IF_FLAG_UNSET_S_G_RPT(child
->flags
);
1371 child
->ifjoin_state
= PIM_IFJOIN_NOINFO
;
1373 if (I_am_RP(pim
, child
->sg
.grp
)) {
1374 pim_channel_add_oif(
1375 child
->upstream
->channel_oil
,
1376 ch
->interface
, PIM_OIF_FLAG_PROTO_STAR
);
1377 pim_upstream_switch(pim
, child
->upstream
,
1378 PIM_UPSTREAM_JOINED
);
1379 pim_jp_agg_single_upstream_send(
1380 &child
->upstream
->rpf
, child
->upstream
,
1384 pim_jp_agg_single_upstream_send(&parent
->rpf
,
1387 delete_on_noinfo(child
);
1393 unsigned int pim_ifchannel_hash_key(void *arg
)
1395 struct pim_ifchannel
*ch
= (struct pim_ifchannel
*)arg
;
1397 return jhash_2words(ch
->sg
.src
.s_addr
, ch
->sg
.grp
.s_addr
, 0);