1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2008 Everton da Silva Marques
22 #include "pim_instance.h"
23 #include "pim_zebra.h"
24 #include "pim_iface.h"
26 #include "pim_mroute.h"
30 #include "pim_neighbor.h"
31 #include "pim_ifchannel.h"
34 #include "pim_ssmpingd.h"
37 #include "pim_jp_agg.h"
38 #include "pim_igmp_join.h"
39 #include "pim_vxlan.h"
44 static void pim_if_igmp_join_del_all(struct interface
*ifp
);
45 static int igmp_join_sock(const char *ifname
, ifindex_t ifindex
,
46 struct in_addr group_addr
, struct in_addr source_addr
,
47 struct pim_interface
*pim_ifp
);
50 void pim_if_init(struct pim_instance
*pim
)
54 for (i
= 0; i
< MAXVIFS
; i
++)
55 pim
->iface_vif_index
[i
] = 0;
58 void pim_if_terminate(struct pim_instance
*pim
)
60 struct interface
*ifp
;
62 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
63 struct pim_interface
*pim_ifp
= ifp
->info
;
73 static void pim_sec_addr_free(struct pim_secondary_addr
*sec_addr
)
75 XFREE(MTYPE_PIM_SEC_ADDR
, sec_addr
);
78 __attribute__((unused
))
79 static int pim_sec_addr_comp(const void *p1
, const void *p2
)
81 const struct pim_secondary_addr
*sec1
= p1
;
82 const struct pim_secondary_addr
*sec2
= p2
;
84 if (sec1
->addr
.family
== AF_INET
&& sec2
->addr
.family
== AF_INET6
)
87 if (sec1
->addr
.family
== AF_INET6
&& sec2
->addr
.family
== AF_INET
)
90 if (sec1
->addr
.family
== AF_INET
) {
91 if (ntohl(sec1
->addr
.u
.prefix4
.s_addr
)
92 < ntohl(sec2
->addr
.u
.prefix4
.s_addr
))
95 if (ntohl(sec1
->addr
.u
.prefix4
.s_addr
)
96 > ntohl(sec2
->addr
.u
.prefix4
.s_addr
))
99 return memcmp(&sec1
->addr
.u
.prefix6
, &sec2
->addr
.u
.prefix6
,
100 sizeof(struct in6_addr
));
106 struct pim_interface
*pim_if_new(struct interface
*ifp
, bool gm
, bool pim
,
107 bool ispimreg
, bool is_vxlan_term
)
109 struct pim_interface
*pim_ifp
;
114 pim_ifp
= XCALLOC(MTYPE_PIM_INTERFACE
, sizeof(*pim_ifp
));
116 pim_ifp
->pim
= ifp
->vrf
->info
;
117 pim_ifp
->mroute_vif_index
= -1;
119 pim_ifp
->igmp_version
= IGMP_DEFAULT_VERSION
;
120 pim_ifp
->mld_version
= MLD_DEFAULT_VERSION
;
121 pim_ifp
->gm_default_robustness_variable
=
122 GM_DEFAULT_ROBUSTNESS_VARIABLE
;
123 pim_ifp
->gm_default_query_interval
= GM_GENERAL_QUERY_INTERVAL
;
124 pim_ifp
->gm_query_max_response_time_dsec
=
125 GM_QUERY_MAX_RESPONSE_TIME_DSEC
;
126 pim_ifp
->gm_specific_query_max_response_time_dsec
=
127 GM_SPECIFIC_QUERY_MAX_RESPONSE_TIME_DSEC
;
128 pim_ifp
->gm_last_member_query_count
= GM_DEFAULT_ROBUSTNESS_VARIABLE
;
130 /* BSM config on interface: true by default */
131 pim_ifp
->bsm_enable
= true;
132 pim_ifp
->ucast_bsm_accept
= true;
133 pim_ifp
->am_i_dr
= false;
136 RFC 3376: 8.3. Query Response Interval
137 The number of seconds represented by the [Query Response Interval]
138 must be less than the [Query Interval].
140 assert(pim_ifp
->gm_query_max_response_time_dsec
<
141 pim_ifp
->gm_default_query_interval
);
143 pim_ifp
->pim_enable
= pim
;
144 pim_ifp
->pim_passive_enable
= false;
145 pim_ifp
->gm_enable
= gm
;
147 pim_ifp
->gm_join_list
= NULL
;
148 pim_ifp
->pim_neighbor_list
= NULL
;
149 pim_ifp
->upstream_switch_list
= NULL
;
150 pim_ifp
->pim_generation_id
= 0;
152 /* list of struct gm_sock */
153 pim_igmp_if_init(pim_ifp
, ifp
);
155 /* list of struct pim_neighbor */
156 pim_ifp
->pim_neighbor_list
= list_new();
157 pim_ifp
->pim_neighbor_list
->del
= (void (*)(void *))pim_neighbor_free
;
159 pim_ifp
->upstream_switch_list
= list_new();
160 pim_ifp
->upstream_switch_list
->del
=
161 (void (*)(void *))pim_jp_agg_group_list_free
;
162 pim_ifp
->upstream_switch_list
->cmp
= pim_jp_agg_group_list_cmp
;
164 pim_ifp
->sec_addr_list
= list_new();
165 pim_ifp
->sec_addr_list
->del
= (void (*)(void *))pim_sec_addr_free
;
166 pim_ifp
->sec_addr_list
->cmp
=
167 (int (*)(void *, void *))pim_sec_addr_comp
;
169 pim_ifp
->activeactive
= false;
171 RB_INIT(pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
);
177 pim_if_add_vif(ifp
, ispimreg
, is_vxlan_term
);
178 pim_ifp
->pim
->mcast_if_count
++;
183 void pim_if_delete(struct interface
*ifp
)
185 struct pim_interface
*pim_ifp
;
191 pim_ifp
->pim
->mcast_if_count
--;
193 if (pim_ifp
->gm_join_list
) {
194 pim_if_igmp_join_del_all(ifp
);
198 pim_ifchannel_delete_all(ifp
);
200 igmp_sock_delete_all(ifp
);
202 if (pim_ifp
->pim_sock_fd
>= 0)
203 pim_sock_delete(ifp
, "Interface removed from configuration");
207 pim_igmp_if_fini(pim_ifp
);
209 list_delete(&pim_ifp
->pim_neighbor_list
);
210 list_delete(&pim_ifp
->upstream_switch_list
);
211 list_delete(&pim_ifp
->sec_addr_list
);
213 if (pim_ifp
->bfd_config
.profile
)
214 XFREE(MTYPE_TMP
, pim_ifp
->bfd_config
.profile
);
216 XFREE(MTYPE_PIM_INTERFACE
, pim_ifp
->boundary_oil_plist
);
217 XFREE(MTYPE_PIM_INTERFACE
, pim_ifp
);
222 void pim_if_update_could_assert(struct interface
*ifp
)
224 struct pim_interface
*pim_ifp
;
225 struct pim_ifchannel
*ch
;
230 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
231 pim_ifchannel_update_could_assert(ch
);
235 static void pim_if_update_my_assert_metric(struct interface
*ifp
)
237 struct pim_interface
*pim_ifp
;
238 struct pim_ifchannel
*ch
;
243 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
244 pim_ifchannel_update_my_assert_metric(ch
);
248 static void pim_addr_change(struct interface
*ifp
)
250 struct pim_interface
*pim_ifp
;
255 pim_if_dr_election(ifp
); /* router's own DR Priority (addr) changes --
257 pim_if_update_join_desired(pim_ifp
); /* depends on DR */
258 pim_if_update_could_assert(ifp
); /* depends on DR */
259 pim_if_update_my_assert_metric(ifp
); /* depends on could_assert */
260 pim_if_update_assert_tracking_desired(
261 ifp
); /* depends on DR, join_desired */
264 RFC 4601: 4.3.1. Sending Hello Messages
266 1) Before an interface goes down or changes primary IP address, a
267 Hello message with a zero HoldTime should be sent immediately
268 (with the old IP address if the IP address changed).
269 -- Done at the caller of the function as new ip already updated here
271 2) After an interface has changed its IP address, it MUST send a
272 Hello message with its new IP address.
275 3) If an interface changes one of its secondary IP addresses, a
276 Hello message with an updated Address_List option and a non-zero
277 HoldTime should be sent immediately.
278 -- FIXME See TODO T31
280 PIM_IF_FLAG_UNSET_HELLO_SENT(pim_ifp
->flags
);
281 if (pim_ifp
->pim_sock_fd
< 0)
283 pim_hello_restart_now(ifp
); /* send hello and restart timer */
286 static int detect_primary_address_change(struct interface
*ifp
,
287 int force_prim_as_any
,
290 struct pim_interface
*pim_ifp
= ifp
->info
;
291 pim_addr new_prim_addr
;
294 if (force_prim_as_any
)
295 new_prim_addr
= PIMADDR_ANY
;
297 new_prim_addr
= pim_find_primary_addr(ifp
);
299 changed
= pim_addr_cmp(new_prim_addr
, pim_ifp
->primary_address
);
302 zlog_debug("%s: old=%pPA new=%pPA on interface %s: %s",
303 __func__
, &pim_ifp
->primary_address
, &new_prim_addr
,
304 ifp
->name
, changed
? "changed" : "unchanged");
307 /* Before updating pim_ifp send Hello time with 0 hold time */
308 if (pim_ifp
->pim_enable
) {
309 pim_hello_send(ifp
, 0 /* zero-sec holdtime */);
311 pim_ifp
->primary_address
= new_prim_addr
;
317 static struct pim_secondary_addr
*
318 pim_sec_addr_find(struct pim_interface
*pim_ifp
, struct prefix
*addr
)
320 struct pim_secondary_addr
*sec_addr
;
321 struct listnode
*node
;
323 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->sec_addr_list
, node
, sec_addr
)) {
324 if (prefix_cmp(&sec_addr
->addr
, addr
) == 0) {
332 static void pim_sec_addr_del(struct pim_interface
*pim_ifp
,
333 struct pim_secondary_addr
*sec_addr
)
335 listnode_delete(pim_ifp
->sec_addr_list
, sec_addr
);
336 pim_sec_addr_free(sec_addr
);
339 static int pim_sec_addr_add(struct pim_interface
*pim_ifp
, struct prefix
*addr
)
342 struct pim_secondary_addr
*sec_addr
;
344 sec_addr
= pim_sec_addr_find(pim_ifp
, addr
);
346 sec_addr
->flags
&= ~PIM_SEC_ADDRF_STALE
;
350 sec_addr
= XCALLOC(MTYPE_PIM_SEC_ADDR
, sizeof(*sec_addr
));
353 sec_addr
->addr
= *addr
;
354 listnode_add_sort(pim_ifp
->sec_addr_list
, sec_addr
);
359 static int pim_sec_addr_del_all(struct pim_interface
*pim_ifp
)
363 if (!list_isempty(pim_ifp
->sec_addr_list
)) {
365 /* remove all nodes and free up the list itself */
366 list_delete_all_node(pim_ifp
->sec_addr_list
);
372 static int pim_sec_addr_update(struct interface
*ifp
)
374 struct pim_interface
*pim_ifp
= ifp
->info
;
375 struct connected
*ifc
;
376 struct listnode
*node
;
377 struct listnode
*nextnode
;
378 struct pim_secondary_addr
*sec_addr
;
381 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->sec_addr_list
, node
, sec_addr
)) {
382 sec_addr
->flags
|= PIM_SEC_ADDRF_STALE
;
385 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, ifc
)) {
386 pim_addr addr
= pim_addr_from_prefix(ifc
->address
);
388 if (pim_addr_is_any(addr
))
391 if (!pim_addr_cmp(addr
, pim_ifp
->primary_address
)) {
392 /* don't add the primary address into the secondary
397 if (pim_sec_addr_add(pim_ifp
, ifc
->address
)) {
402 /* Drop stale entries */
403 for (ALL_LIST_ELEMENTS(pim_ifp
->sec_addr_list
, node
, nextnode
,
405 if (sec_addr
->flags
& PIM_SEC_ADDRF_STALE
) {
406 pim_sec_addr_del(pim_ifp
, sec_addr
);
414 static int detect_secondary_address_change(struct interface
*ifp
,
415 int force_prim_as_any
,
418 struct pim_interface
*pim_ifp
= ifp
->info
;
421 if (force_prim_as_any
) {
422 /* if primary address is being forced to zero just flush the
423 * secondary address list */
424 changed
= pim_sec_addr_del_all(pim_ifp
);
426 /* re-evaluate the secondary address list */
427 changed
= pim_sec_addr_update(ifp
);
433 static void detect_address_change(struct interface
*ifp
, int force_prim_as_any
,
437 struct pim_interface
*pim_ifp
;
443 if (detect_primary_address_change(ifp
, force_prim_as_any
, caller
)) {
447 if (detect_secondary_address_change(ifp
, force_prim_as_any
, caller
)) {
453 if (!pim_ifp
->pim_enable
) {
457 pim_addr_change(ifp
);
460 /* XXX: if we have unnumbered interfaces we need to run detect address
461 * address change on all of them when the lo address changes */
464 int pim_update_source_set(struct interface
*ifp
, pim_addr source
)
466 struct pim_interface
*pim_ifp
= ifp
->info
;
469 return PIM_IFACE_NOT_FOUND
;
472 if (!pim_addr_cmp(pim_ifp
->update_source
, source
)) {
473 return PIM_UPDATE_SOURCE_DUP
;
476 pim_ifp
->update_source
= source
;
477 detect_address_change(ifp
, 0 /* force_prim_as_any */, __func__
);
482 void pim_if_addr_add(struct connected
*ifc
)
484 struct pim_interface
*pim_ifp
;
485 struct interface
*ifp
;
496 if (!if_is_operative(ifp
))
500 zlog_debug("%s: %s ifindex=%d connected IP address %pFX %s",
501 __func__
, ifp
->name
, ifp
->ifindex
, ifc
->address
,
502 CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
)
506 if (IN6_IS_ADDR_LINKLOCAL(&ifc
->address
->u
.prefix6
) ||
507 IN6_IS_ADDR_LOOPBACK(&ifc
->address
->u
.prefix6
)) {
508 if (IN6_IS_ADDR_UNSPECIFIED(&pim_ifp
->ll_lowest
))
509 pim_ifp
->ll_lowest
= ifc
->address
->u
.prefix6
;
510 else if (IPV6_ADDR_CMP(&ifc
->address
->u
.prefix6
,
511 &pim_ifp
->ll_lowest
) < 0)
512 pim_ifp
->ll_lowest
= ifc
->address
->u
.prefix6
;
514 if (IPV6_ADDR_CMP(&ifc
->address
->u
.prefix6
,
515 &pim_ifp
->ll_highest
) > 0)
516 pim_ifp
->ll_highest
= ifc
->address
->u
.prefix6
;
520 "%s: new link-local %pI6, lowest now %pI6, highest %pI6",
521 ifc
->ifp
->name
, &ifc
->address
->u
.prefix6
,
522 &pim_ifp
->ll_lowest
, &pim_ifp
->ll_highest
);
526 detect_address_change(ifp
, 0, __func__
);
528 // if (ifc->address->family != AF_INET)
532 struct in_addr ifaddr
= ifc
->address
->u
.prefix4
;
534 if (pim_ifp
->gm_enable
) {
535 struct gm_sock
*igmp
;
537 /* lookup IGMP socket */
538 igmp
= pim_igmp_sock_lookup_ifaddr(pim_ifp
->gm_socket_list
,
541 /* if addr new, add IGMP socket */
542 if (ifc
->address
->family
== AF_INET
)
543 pim_igmp_sock_add(pim_ifp
->gm_socket_list
,
545 } else if (igmp
->mtrace_only
) {
546 igmp_sock_delete(igmp
);
547 pim_igmp_sock_add(pim_ifp
->gm_socket_list
, ifaddr
, ifp
,
551 /* Replay Static IGMP groups */
552 if (pim_ifp
->gm_join_list
) {
553 struct listnode
*node
;
554 struct listnode
*nextnode
;
558 for (ALL_LIST_ELEMENTS(pim_ifp
->gm_join_list
, node
,
560 /* Close socket and reopen with Source and Group
563 join_fd
= igmp_join_sock(
564 ifp
->name
, ifp
->ifindex
, ij
->group_addr
,
565 ij
->source_addr
, pim_ifp
);
567 char group_str
[INET_ADDRSTRLEN
];
568 char source_str
[INET_ADDRSTRLEN
];
569 pim_inet4_dump("<grp?>", ij
->group_addr
,
573 "<src?>", ij
->source_addr
,
574 source_str
, sizeof(source_str
));
576 "%s: igmp_join_sock() failure for IGMP group %s source %s on interface %s",
577 __func__
, group_str
, source_str
,
581 ij
->sock_fd
= join_fd
;
586 struct gm_sock
*igmp
;
588 /* lookup IGMP socket */
589 igmp
= pim_igmp_sock_lookup_ifaddr(pim_ifp
->gm_socket_list
,
591 if (ifc
->address
->family
== AF_INET
) {
593 igmp_sock_delete(igmp
);
594 /* if addr new, add IGMP socket */
595 pim_igmp_sock_add(pim_ifp
->gm_socket_list
, ifaddr
, ifp
,
598 } /* igmp mtrace only */
601 if (pim_ifp
->pim_enable
) {
603 if (!pim_addr_is_any(pim_ifp
->primary_address
)) {
605 /* Interface has a valid socket ? */
606 if (pim_ifp
->pim_sock_fd
< 0) {
607 if (pim_sock_add(ifp
)) {
609 "Failure creating PIM socket for interface %s",
613 struct pim_nexthop_cache
*pnc
= NULL
;
615 struct zclient
*zclient
= NULL
;
617 zclient
= pim_zebra_zclient_get();
618 /* RP config might come prior to (local RP's interface)
620 In this case, pnc would not have pim enabled
622 Once Interface is UP and pim info is available,
624 with RNH address to receive update and add the
625 interface as nexthop. */
626 memset(&rpf
, 0, sizeof(struct pim_rpf
));
627 rpf
.rpf_addr
= pim_addr_from_prefix(ifc
->address
);
628 pnc
= pim_nexthop_cache_find(pim_ifp
->pim
, &rpf
);
630 pim_sendmsg_zebra_rnh(pim_ifp
->pim
, zclient
,
632 ZEBRA_NEXTHOP_REGISTER
);
637 PIM or IGMP is enabled on interface, and there is at least one
638 address assigned, then try to create a vif_index.
640 if (pim_ifp
->mroute_vif_index
< 0) {
641 vxlan_term
= pim_vxlan_is_term_dev_cfg(pim_ifp
->pim
, ifp
);
642 pim_if_add_vif(ifp
, false, vxlan_term
);
645 pim_ifchannel_scan_forward_start(ifp
);
648 static void pim_if_addr_del_igmp(struct connected
*ifc
)
651 struct pim_interface
*pim_ifp
= ifc
->ifp
->info
;
652 struct gm_sock
*igmp
;
653 struct in_addr ifaddr
;
655 if (ifc
->address
->family
!= AF_INET
) {
656 /* non-IPv4 address */
661 /* IGMP not enabled on interface */
665 ifaddr
= ifc
->address
->u
.prefix4
;
667 /* lookup IGMP socket */
668 igmp
= pim_igmp_sock_lookup_ifaddr(pim_ifp
->gm_socket_list
, ifaddr
);
670 /* if addr found, del IGMP socket */
671 igmp_sock_delete(igmp
);
676 static void pim_if_addr_del_pim(struct connected
*ifc
)
678 struct pim_interface
*pim_ifp
= ifc
->ifp
->info
;
680 if (ifc
->address
->family
!= PIM_AF
) {
681 /* non-IPv4 address */
686 /* PIM not enabled on interface */
690 if (!pim_addr_is_any(pim_ifp
->primary_address
)) {
691 /* Interface keeps a valid primary address */
695 if (pim_ifp
->pim_sock_fd
< 0) {
696 /* Interface does not hold a valid socket any longer */
701 pim_sock_delete() closes the socket, stops read and timer threads,
702 and kills all neighbors.
704 pim_sock_delete(ifc
->ifp
,
705 "last address has been removed from interface");
708 void pim_if_addr_del(struct connected
*ifc
, int force_prim_as_any
)
710 struct interface
*ifp
;
717 zlog_debug("%s: %s ifindex=%d disconnected IP address %pFX %s",
718 __func__
, ifp
->name
, ifp
->ifindex
, ifc
->address
,
719 CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
)
724 struct pim_interface
*pim_ifp
= ifc
->ifp
->info
;
727 (!IPV6_ADDR_CMP(&ifc
->address
->u
.prefix6
, &pim_ifp
->ll_lowest
) ||
728 !IPV6_ADDR_CMP(&ifc
->address
->u
.prefix6
, &pim_ifp
->ll_highest
))) {
729 struct listnode
*cnode
;
730 struct connected
*cc
;
732 memset(&pim_ifp
->ll_lowest
, 0xff, sizeof(pim_ifp
->ll_lowest
));
733 memset(&pim_ifp
->ll_highest
, 0, sizeof(pim_ifp
->ll_highest
));
735 for (ALL_LIST_ELEMENTS_RO(ifc
->ifp
->connected
, cnode
, cc
)) {
736 if (!IN6_IS_ADDR_LINKLOCAL(&cc
->address
->u
.prefix6
) &&
737 !IN6_IS_ADDR_LOOPBACK(&cc
->address
->u
.prefix6
))
740 if (IPV6_ADDR_CMP(&cc
->address
->u
.prefix6
,
741 &pim_ifp
->ll_lowest
) < 0)
742 pim_ifp
->ll_lowest
= cc
->address
->u
.prefix6
;
743 if (IPV6_ADDR_CMP(&cc
->address
->u
.prefix6
,
744 &pim_ifp
->ll_highest
) > 0)
745 pim_ifp
->ll_highest
= cc
->address
->u
.prefix6
;
748 if (pim_ifp
->ll_lowest
.s6_addr
[0] == 0xff)
749 memset(&pim_ifp
->ll_lowest
, 0,
750 sizeof(pim_ifp
->ll_lowest
));
754 "%s: removed link-local %pI6, lowest now %pI6, highest %pI6",
755 ifc
->ifp
->name
, &ifc
->address
->u
.prefix6
,
756 &pim_ifp
->ll_lowest
, &pim_ifp
->ll_highest
);
762 detect_address_change(ifp
, force_prim_as_any
, __func__
);
764 pim_if_addr_del_igmp(ifc
);
765 pim_if_addr_del_pim(ifc
);
768 void pim_if_addr_add_all(struct interface
*ifp
)
770 struct connected
*ifc
;
771 struct listnode
*node
;
772 struct listnode
*nextnode
;
775 struct pim_interface
*pim_ifp
= ifp
->info
;
779 /* PIM/IGMP enabled ? */
783 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nextnode
, ifc
)) {
784 struct prefix
*p
= ifc
->address
;
786 if (p
->family
!= AF_INET
)
790 pim_if_addr_add(ifc
);
793 if (!v4_addrs
&& v6_addrs
&& !if_is_loopback(ifp
) &&
794 pim_ifp
->pim_enable
&& !pim_addr_is_any(pim_ifp
->primary_address
) &&
795 pim_ifp
->pim_sock_fd
< 0 && pim_sock_add(ifp
)) {
796 /* Interface has a valid primary address ? */
797 /* Interface has a valid socket ? */
798 zlog_warn("Failure creating PIM socket for interface %s",
802 * PIM or IGMP/MLD is enabled on interface, and there is at least one
803 * address assigned, then try to create a vif_index.
805 if (pim_ifp
->mroute_vif_index
< 0) {
806 vxlan_term
= pim_vxlan_is_term_dev_cfg(pim_ifp
->pim
, ifp
);
807 pim_if_add_vif(ifp
, false, vxlan_term
);
810 pim_ifchannel_scan_forward_start(ifp
);
812 pim_rp_setup(pim_ifp
->pim
);
813 pim_rp_check_on_if_add(pim_ifp
);
816 void pim_if_addr_del_all(struct interface
*ifp
)
818 struct connected
*ifc
;
819 struct listnode
*node
;
820 struct listnode
*nextnode
;
821 struct pim_instance
*pim
;
823 pim
= ifp
->vrf
->info
;
827 /* PIM/IGMP enabled ? */
831 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nextnode
, ifc
)) {
832 struct prefix
*p
= ifc
->address
;
834 if (p
->family
!= PIM_AF
)
837 pim_if_addr_del(ifc
, 1 /* force_prim_as_any=true */);
841 pim_i_am_rp_re_evaluate(pim
);
844 void pim_if_addr_del_all_igmp(struct interface
*ifp
)
846 struct connected
*ifc
;
847 struct listnode
*node
;
848 struct listnode
*nextnode
;
850 /* PIM/IGMP enabled ? */
854 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nextnode
, ifc
)) {
855 struct prefix
*p
= ifc
->address
;
857 if (p
->family
!= AF_INET
)
860 pim_if_addr_del_igmp(ifc
);
864 pim_addr
pim_find_primary_addr(struct interface
*ifp
)
866 struct connected
*ifc
;
867 struct listnode
*node
;
868 struct pim_interface
*pim_ifp
= ifp
->info
;
870 if (pim_ifp
&& !pim_addr_is_any(pim_ifp
->update_source
))
871 return pim_ifp
->update_source
;
874 if (pim_ifp
&& !pim_addr_is_any(pim_ifp
->ll_highest
))
875 return pim_ifp
->ll_highest
;
877 pim_addr best_addr
= PIMADDR_ANY
;
879 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, ifc
)) {
882 if (ifc
->address
->family
!= AF_INET6
)
885 addr
= pim_addr_from_prefix(ifc
->address
);
886 if (!IN6_IS_ADDR_LINKLOCAL(&addr
))
888 if (pim_addr_cmp(addr
, best_addr
) > 0)
897 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, ifc
)) {
898 switch (ifc
->address
->family
) {
909 if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
))
912 if (ifc
->address
->family
!= PIM_AF
)
915 return pim_addr_from_prefix(ifc
->address
);
919 * If we have no v4_addrs and v6 is configured
920 * We probably are using unnumbered
921 * So let's grab the loopbacks v4 address
922 * and use that as the primary address
924 if (!v4_addrs
&& v6_addrs
) {
925 struct interface
*lo_ifp
;
927 // DBS - Come back and check here
928 if (ifp
->vrf
->vrf_id
== VRF_DEFAULT
)
929 lo_ifp
= if_lookup_by_name("lo", ifp
->vrf
->vrf_id
);
931 lo_ifp
= if_lookup_by_name(ifp
->vrf
->name
,
934 if (lo_ifp
&& (lo_ifp
!= ifp
))
935 return pim_find_primary_addr(lo_ifp
);
941 static int pim_iface_next_vif_index(struct interface
*ifp
)
943 struct pim_interface
*pim_ifp
= ifp
->info
;
944 struct pim_instance
*pim
= pim_ifp
->pim
;
948 * The pimreg vif is always going to be in index 0
951 if (ifp
->ifindex
== PIM_OIF_PIM_REGISTER_VIF
)
954 for (i
= 1; i
< MAXVIFS
; i
++) {
955 if (pim
->iface_vif_index
[i
] == 0)
962 pim_if_add_vif() uses ifindex as vif_index
964 see also pim_if_find_vifindex_by_ifindex()
966 int pim_if_add_vif(struct interface
*ifp
, bool ispimreg
, bool is_vxlan_term
)
968 struct pim_interface
*pim_ifp
= ifp
->info
;
970 unsigned char flags
= 0;
974 if (pim_ifp
->mroute_vif_index
> 0) {
975 zlog_warn("%s: vif_index=%d > 0 on interface %s ifindex=%d",
976 __func__
, pim_ifp
->mroute_vif_index
, ifp
->name
,
981 if (ifp
->ifindex
< 0) {
982 zlog_warn("%s: ifindex=%d < 1 on interface %s", __func__
,
983 ifp
->ifindex
, ifp
->name
);
987 ifaddr
= pim_ifp
->primary_address
;
989 /* IPv6 API is always by interface index */
990 if (!ispimreg
&& !is_vxlan_term
&& pim_addr_is_any(ifaddr
)) {
992 "%s: could not get address for interface %s ifindex=%d",
993 __func__
, ifp
->name
, ifp
->ifindex
);
998 pim_ifp
->mroute_vif_index
= pim_iface_next_vif_index(ifp
);
1000 if (pim_ifp
->mroute_vif_index
>= MAXVIFS
) {
1002 "%s: Attempting to configure more than MAXVIFS=%d on pim enabled interface %s",
1003 __func__
, MAXVIFS
, ifp
->name
);
1007 if (ifp
->ifindex
== PIM_OIF_PIM_REGISTER_VIF
)
1008 flags
= VIFF_REGISTER
;
1009 #ifdef VIFF_USE_IFINDEX
1011 flags
= VIFF_USE_IFINDEX
;
1014 if (pim_mroute_add_vif(ifp
, ifaddr
, flags
)) {
1015 /* pim_mroute_add_vif reported error */
1019 pim_ifp
->pim
->iface_vif_index
[pim_ifp
->mroute_vif_index
] = 1;
1024 /* if the device qualifies as pim_vxlan iif/oif update vxlan entries */
1025 pim_vxlan_add_vif(ifp
);
1029 int pim_if_del_vif(struct interface
*ifp
)
1031 struct pim_interface
*pim_ifp
= ifp
->info
;
1033 if (pim_ifp
->mroute_vif_index
< 1) {
1034 zlog_warn("%s: vif_index=%d < 1 on interface %s ifindex=%d",
1035 __func__
, pim_ifp
->mroute_vif_index
, ifp
->name
,
1040 /* if the device was a pim_vxlan iif/oif update vxlan mroute entries */
1041 pim_vxlan_del_vif(ifp
);
1043 gm_ifp_teardown(ifp
);
1045 pim_mroute_del_vif(ifp
);
1050 pim_ifp
->pim
->iface_vif_index
[pim_ifp
->mroute_vif_index
] = 0;
1052 pim_ifp
->mroute_vif_index
= -1;
1057 struct interface
*pim_if_find_by_vif_index(struct pim_instance
*pim
,
1058 ifindex_t vif_index
)
1060 struct interface
*ifp
;
1062 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1064 struct pim_interface
*pim_ifp
;
1065 pim_ifp
= ifp
->info
;
1067 if (vif_index
== pim_ifp
->mroute_vif_index
)
1076 pim_if_add_vif() uses ifindex as vif_index
1078 int pim_if_find_vifindex_by_ifindex(struct pim_instance
*pim
, ifindex_t ifindex
)
1080 struct pim_interface
*pim_ifp
;
1081 struct interface
*ifp
;
1083 ifp
= if_lookup_by_index(ifindex
, pim
->vrf
->vrf_id
);
1084 if (!ifp
|| !ifp
->info
)
1086 pim_ifp
= ifp
->info
;
1088 return pim_ifp
->mroute_vif_index
;
1091 int pim_if_lan_delay_enabled(struct interface
*ifp
)
1093 struct pim_interface
*pim_ifp
;
1095 pim_ifp
= ifp
->info
;
1097 assert(pim_ifp
->pim_number_of_nonlandelay_neighbors
>= 0);
1099 return pim_ifp
->pim_number_of_nonlandelay_neighbors
== 0;
1102 uint16_t pim_if_effective_propagation_delay_msec(struct interface
*ifp
)
1104 if (pim_if_lan_delay_enabled(ifp
)) {
1105 struct pim_interface
*pim_ifp
;
1106 pim_ifp
= ifp
->info
;
1107 return pim_ifp
->pim_neighbors_highest_propagation_delay_msec
;
1109 return PIM_DEFAULT_PROPAGATION_DELAY_MSEC
;
1113 uint16_t pim_if_effective_override_interval_msec(struct interface
*ifp
)
1115 if (pim_if_lan_delay_enabled(ifp
)) {
1116 struct pim_interface
*pim_ifp
;
1117 pim_ifp
= ifp
->info
;
1118 return pim_ifp
->pim_neighbors_highest_override_interval_msec
;
1120 return PIM_DEFAULT_OVERRIDE_INTERVAL_MSEC
;
1124 int pim_if_t_override_msec(struct interface
*ifp
)
1126 int effective_override_interval_msec
;
1127 int t_override_msec
;
1129 effective_override_interval_msec
=
1130 pim_if_effective_override_interval_msec(ifp
);
1133 frr_weak_random() % (effective_override_interval_msec
+ 1);
1135 return t_override_msec
;
1138 uint16_t pim_if_jp_override_interval_msec(struct interface
*ifp
)
1140 return pim_if_effective_propagation_delay_msec(ifp
)
1141 + pim_if_effective_override_interval_msec(ifp
);
1145 RFC 4601: 4.1.6. State Summarization Macros
1147 The function NBR( I, A ) uses information gathered through PIM Hello
1148 messages to map the IP address A of a directly connected PIM
1149 neighbor router on interface I to the primary IP address of the same
1150 router (Section 4.3.4). The primary IP address of a neighbor is the
1151 address that it uses as the source of its PIM Hello messages.
1153 struct pim_neighbor
*pim_if_find_neighbor(struct interface
*ifp
, pim_addr addr
)
1155 struct listnode
*neighnode
;
1156 struct pim_neighbor
*neigh
;
1157 struct pim_interface
*pim_ifp
;
1162 pim_ifp
= ifp
->info
;
1164 zlog_warn("%s: multicast not enabled on interface %s", __func__
,
1169 pim_addr_to_prefix(&p
, addr
);
1171 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
, neighnode
,
1174 /* primary address ? */
1175 if (!pim_addr_cmp(neigh
->source_addr
, addr
))
1178 /* secondary address ? */
1179 if (pim_neighbor_find_secondary(neigh
, &p
))
1183 if (PIM_DEBUG_PIM_TRACE
)
1185 "%s: neighbor not found for address %pPA on interface %s",
1186 __func__
, &addr
, ifp
->name
);
1191 long pim_if_t_suppressed_msec(struct interface
*ifp
)
1193 struct pim_interface
*pim_ifp
;
1194 long t_suppressed_msec
;
1195 uint32_t ramount
= 0;
1197 pim_ifp
= ifp
->info
;
1200 /* join suppression disabled ? */
1201 if (pim_ifp
->pim_can_disable_join_suppression
)
1204 /* t_suppressed = t_periodic * rand(1.1, 1.4) */
1205 ramount
= 1100 + (frr_weak_random() % (1400 - 1100 + 1));
1206 t_suppressed_msec
= router
->t_periodic
* ramount
;
1208 return t_suppressed_msec
;
1212 static void igmp_join_free(struct gm_join
*ij
)
1214 XFREE(MTYPE_PIM_IGMP_JOIN
, ij
);
1217 static struct gm_join
*igmp_join_find(struct list
*join_list
,
1218 struct in_addr group_addr
,
1219 struct in_addr source_addr
)
1221 struct listnode
*node
;
1226 for (ALL_LIST_ELEMENTS_RO(join_list
, node
, ij
)) {
1227 if ((group_addr
.s_addr
== ij
->group_addr
.s_addr
)
1228 && (source_addr
.s_addr
== ij
->source_addr
.s_addr
))
1235 static int igmp_join_sock(const char *ifname
, ifindex_t ifindex
,
1236 struct in_addr group_addr
, struct in_addr source_addr
,
1237 struct pim_interface
*pim_ifp
)
1241 pim_ifp
->igmp_ifstat_joins_sent
++;
1243 join_fd
= pim_socket_raw(IPPROTO_IGMP
);
1245 pim_ifp
->igmp_ifstat_joins_failed
++;
1249 if (pim_igmp_join_source(join_fd
, ifindex
, group_addr
, source_addr
)) {
1250 char group_str
[INET_ADDRSTRLEN
];
1251 char source_str
[INET_ADDRSTRLEN
];
1252 pim_inet4_dump("<grp?>", group_addr
, group_str
,
1254 pim_inet4_dump("<src?>", source_addr
, source_str
,
1255 sizeof(source_str
));
1257 "%s: setsockopt(fd=%d) failure for IGMP group %s source %s ifindex %d on interface %s: errno=%d: %s",
1258 __func__
, join_fd
, group_str
, source_str
, ifindex
,
1259 ifname
, errno
, safe_strerror(errno
));
1261 pim_ifp
->igmp_ifstat_joins_failed
++;
1271 static struct gm_join
*igmp_join_new(struct interface
*ifp
,
1272 struct in_addr group_addr
,
1273 struct in_addr source_addr
)
1275 struct pim_interface
*pim_ifp
;
1279 pim_ifp
= ifp
->info
;
1282 join_fd
= igmp_join_sock(ifp
->name
, ifp
->ifindex
, group_addr
,
1283 source_addr
, pim_ifp
);
1285 char group_str
[INET_ADDRSTRLEN
];
1286 char source_str
[INET_ADDRSTRLEN
];
1288 pim_inet4_dump("<grp?>", group_addr
, group_str
,
1290 pim_inet4_dump("<src?>", source_addr
, source_str
,
1291 sizeof(source_str
));
1293 "%s: igmp_join_sock() failure for IGMP group %s source %s on interface %s",
1294 __func__
, group_str
, source_str
, ifp
->name
);
1298 ij
= XCALLOC(MTYPE_PIM_IGMP_JOIN
, sizeof(*ij
));
1300 ij
->sock_fd
= join_fd
;
1301 ij
->group_addr
= group_addr
;
1302 ij
->source_addr
= source_addr
;
1303 ij
->sock_creation
= pim_time_monotonic_sec();
1305 listnode_add(pim_ifp
->gm_join_list
, ij
);
1309 #endif /* PIM_IPV == 4 */
1312 ferr_r
pim_if_igmp_join_add(struct interface
*ifp
, struct in_addr group_addr
,
1313 struct in_addr source_addr
)
1315 struct pim_interface
*pim_ifp
;
1318 pim_ifp
= ifp
->info
;
1320 return ferr_cfg_invalid("multicast not enabled on interface %s",
1324 if (!pim_ifp
->gm_join_list
) {
1325 pim_ifp
->gm_join_list
= list_new();
1326 pim_ifp
->gm_join_list
->del
= (void (*)(void *))igmp_join_free
;
1329 ij
= igmp_join_find(pim_ifp
->gm_join_list
, group_addr
, source_addr
);
1331 /* This interface has already been configured to join this IGMP group
1337 (void)igmp_join_new(ifp
, group_addr
, source_addr
);
1339 if (PIM_DEBUG_GM_EVENTS
) {
1340 char group_str
[INET_ADDRSTRLEN
];
1341 char source_str
[INET_ADDRSTRLEN
];
1342 pim_inet4_dump("<grp?>", group_addr
, group_str
,
1344 pim_inet4_dump("<src?>", source_addr
, source_str
,
1345 sizeof(source_str
));
1347 "%s: issued static igmp join for channel (S,G)=(%s,%s) on interface %s",
1348 __func__
, source_str
, group_str
, ifp
->name
);
1353 #endif /* PIM_IPV == 4 */
1355 int pim_if_igmp_join_del(struct interface
*ifp
, struct in_addr group_addr
,
1356 struct in_addr source_addr
)
1358 struct pim_interface
*pim_ifp
;
1361 pim_ifp
= ifp
->info
;
1363 zlog_warn("%s: multicast not enabled on interface %s", __func__
,
1368 if (!pim_ifp
->gm_join_list
) {
1369 zlog_warn("%s: no IGMP join on interface %s", __func__
,
1374 ij
= igmp_join_find(pim_ifp
->gm_join_list
, group_addr
, source_addr
);
1376 char group_str
[INET_ADDRSTRLEN
];
1377 char source_str
[INET_ADDRSTRLEN
];
1378 pim_inet4_dump("<grp?>", group_addr
, group_str
,
1380 pim_inet4_dump("<src?>", source_addr
, source_str
,
1381 sizeof(source_str
));
1383 "%s: could not find IGMP group %s source %s on interface %s",
1384 __func__
, group_str
, source_str
, ifp
->name
);
1388 if (close(ij
->sock_fd
)) {
1389 char group_str
[INET_ADDRSTRLEN
];
1390 char source_str
[INET_ADDRSTRLEN
];
1391 pim_inet4_dump("<grp?>", group_addr
, group_str
,
1393 pim_inet4_dump("<src?>", source_addr
, source_str
,
1394 sizeof(source_str
));
1396 "%s: failure closing sock_fd=%d for IGMP group %s source %s on interface %s: errno=%d: %s",
1397 __func__
, ij
->sock_fd
, group_str
, source_str
, ifp
->name
,
1398 errno
, safe_strerror(errno
));
1401 listnode_delete(pim_ifp
->gm_join_list
, ij
);
1403 if (listcount(pim_ifp
->gm_join_list
) < 1) {
1404 list_delete(&pim_ifp
->gm_join_list
);
1405 pim_ifp
->gm_join_list
= 0;
1411 __attribute__((unused
))
1412 static void pim_if_igmp_join_del_all(struct interface
*ifp
)
1414 struct pim_interface
*pim_ifp
;
1415 struct listnode
*node
;
1416 struct listnode
*nextnode
;
1419 pim_ifp
= ifp
->info
;
1421 zlog_warn("%s: multicast not enabled on interface %s", __func__
,
1426 if (!pim_ifp
->gm_join_list
)
1429 for (ALL_LIST_ELEMENTS(pim_ifp
->gm_join_list
, node
, nextnode
, ij
))
1430 pim_if_igmp_join_del(ifp
, ij
->group_addr
, ij
->source_addr
);
1432 #else /* PIM_IPV != 4 */
1433 ferr_r
pim_if_igmp_join_add(struct interface
*ifp
, struct in_addr group_addr
,
1434 struct in_addr source_addr
)
1439 int pim_if_igmp_join_del(struct interface
*ifp
, struct in_addr group_addr
,
1440 struct in_addr source_addr
)
1444 #endif /* PIM_IPV != 4 */
1449 Transitions from "I am Assert Loser" State
1451 Current Winner's GenID Changes or NLT Expires
1453 The Neighbor Liveness Timer associated with the current winner
1454 expires or we receive a Hello message from the current winner
1455 reporting a different GenID from the one it previously reported.
1456 This indicates that the current winner's interface or router has
1457 gone down (and may have come back up), and so we must assume it no
1458 longer knows it was the winner.
1460 void pim_if_assert_on_neighbor_down(struct interface
*ifp
, pim_addr neigh_addr
)
1462 struct pim_interface
*pim_ifp
;
1463 struct pim_ifchannel
*ch
;
1465 pim_ifp
= ifp
->info
;
1468 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
1469 /* Is (S,G,I) assert loser ? */
1470 if (ch
->ifassert_state
!= PIM_IFASSERT_I_AM_LOSER
)
1472 /* Dead neighbor was winner ? */
1473 if (pim_addr_cmp(ch
->ifassert_winner
, neigh_addr
))
1476 assert_action_a5(ch
);
1480 void pim_if_update_join_desired(struct pim_interface
*pim_ifp
)
1482 struct pim_ifchannel
*ch
;
1484 /* clear off flag from interface's upstreams */
1485 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
1486 PIM_UPSTREAM_FLAG_UNSET_DR_JOIN_DESIRED_UPDATED(
1487 ch
->upstream
->flags
);
1490 /* scan per-interface (S,G,I) state on this I interface */
1491 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
1492 struct pim_upstream
*up
= ch
->upstream
;
1494 if (PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED_UPDATED(up
->flags
))
1497 /* update join_desired for the global (S,G) state */
1498 pim_upstream_update_join_desired(pim_ifp
->pim
, up
);
1499 PIM_UPSTREAM_FLAG_SET_DR_JOIN_DESIRED_UPDATED(up
->flags
);
1503 void pim_if_update_assert_tracking_desired(struct interface
*ifp
)
1505 struct pim_interface
*pim_ifp
;
1506 struct pim_ifchannel
*ch
;
1508 pim_ifp
= ifp
->info
;
1512 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
1513 pim_ifchannel_update_assert_tracking_desired(ch
);
1518 * PIM wants to have an interface pointer for everything it does.
1519 * The pimreg is a special interface that we have that is not
1520 * quite an interface but a VIF is created for it.
1522 void pim_if_create_pimreg(struct pim_instance
*pim
)
1524 char pimreg_name
[INTERFACE_NAMSIZ
];
1526 if (!pim
->regiface
) {
1527 if (pim
->vrf
->vrf_id
== VRF_DEFAULT
)
1528 strlcpy(pimreg_name
, PIMREG
, sizeof(pimreg_name
));
1530 snprintf(pimreg_name
, sizeof(pimreg_name
), PIMREG
"%u",
1531 pim
->vrf
->data
.l
.table_id
);
1533 pim
->regiface
= if_get_by_name(pimreg_name
, pim
->vrf
->vrf_id
,
1535 pim
->regiface
->ifindex
= PIM_OIF_PIM_REGISTER_VIF
;
1537 if (!pim
->regiface
->info
)
1538 pim_if_new(pim
->regiface
, false, false, true,
1539 false /*vxlan_term*/);
1542 * On vrf moves we delete the interface if there
1543 * is nothing going on with it. We cannot have
1544 * the pimregiface deleted.
1546 pim
->regiface
->configured
= true;
1551 struct prefix
*pim_if_connected_to_source(struct interface
*ifp
, pim_addr src
)
1553 struct listnode
*cnode
;
1554 struct connected
*c
;
1560 pim_addr_to_prefix(&p
, src
);
1562 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, c
)) {
1563 if (c
->address
->family
!= PIM_AF
)
1565 if (prefix_match(c
->address
, &p
))
1567 if (CONNECTED_PEER(c
) && prefix_match(c
->destination
, &p
))
1568 /* this is not a typo, on PtP we need to return the
1569 * *local* address that lines up with src.
1577 bool pim_if_is_vrf_device(struct interface
*ifp
)
1585 int pim_if_ifchannel_count(struct pim_interface
*pim_ifp
)
1587 struct pim_ifchannel
*ch
;
1590 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
1597 static int pim_ifp_create(struct interface
*ifp
)
1599 struct pim_instance
*pim
;
1601 pim
= ifp
->vrf
->info
;
1602 if (PIM_DEBUG_ZEBRA
) {
1604 "%s: %s index %d vrf %s(%u) flags %ld metric %d mtu %d operative %d",
1605 __func__
, ifp
->name
, ifp
->ifindex
, ifp
->vrf
->name
,
1606 ifp
->vrf
->vrf_id
, (long)ifp
->flags
, ifp
->metric
,
1607 ifp
->mtu
, if_is_operative(ifp
));
1610 if (if_is_operative(ifp
)) {
1611 struct pim_interface
*pim_ifp
;
1613 pim_ifp
= ifp
->info
;
1615 * If we have a pim_ifp already and this is an if_add
1616 * that means that we probably have a vrf move event
1617 * If that is the case, set the proper vrfness.
1621 pim_if_addr_add_all(ifp
);
1624 * Due to ordering issues based upon when
1625 * a command is entered we should ensure that
1626 * the pim reg is created for this vrf if we
1627 * have configuration for it already.
1629 * this is a no-op if it's already been done.
1631 pim_if_create_pimreg(pim
);
1636 * If we are a vrf device that is up, open up the pim_socket for
1638 * to incoming pim messages irrelevant if the user has configured us
1641 if (pim_if_is_vrf_device(ifp
)) {
1642 struct pim_interface
*pim_ifp
;
1645 pim_ifp
= pim_if_new(ifp
, false, false, false,
1646 false /*vxlan_term*/);
1647 ifp
->info
= pim_ifp
;
1653 if (!strncmp(ifp
->name
, PIM_VXLAN_TERM_DEV_NAME
,
1654 sizeof(PIM_VXLAN_TERM_DEV_NAME
))) {
1655 if (pim
->mcast_if_count
< MAXVIFS
)
1656 pim_vxlan_add_term_dev(pim
, ifp
);
1659 "%s: Cannot enable pim on %s. MAXVIFS(%d) reached. Deleting and readding the vxlan termimation device after unconfiguring pim from other interfaces may succeed.",
1660 __func__
, ifp
->name
, MAXVIFS
);
1667 static int pim_ifp_up(struct interface
*ifp
)
1670 struct pim_interface
*pim_ifp
;
1671 struct pim_instance
*pim
;
1673 if (PIM_DEBUG_ZEBRA
) {
1675 "%s: %s index %d vrf %s(%u) flags %ld metric %d mtu %d operative %d",
1676 __func__
, ifp
->name
, ifp
->ifindex
, ifp
->vrf
->name
,
1677 ifp
->vrf
->vrf_id
, (long)ifp
->flags
, ifp
->metric
,
1678 ifp
->mtu
, if_is_operative(ifp
));
1681 pim
= ifp
->vrf
->info
;
1683 pim_ifp
= ifp
->info
;
1685 * If we have a pim_ifp already and this is an if_add
1686 * that means that we probably have a vrf move event
1687 * If that is the case, set the proper vrfness.
1693 pim_if_addr_add_all() suffices for bringing up both IGMP and
1696 pim_if_addr_add_all(ifp
);
1699 * If we have a pimreg device callback and it's for a specific
1700 * table set the master appropriately
1702 if (sscanf(ifp
->name
, "" PIMREG
"%" SCNu32
, &table_id
) == 1) {
1704 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
1705 if ((table_id
== vrf
->data
.l
.table_id
)
1706 && (ifp
->vrf
->vrf_id
!= vrf
->vrf_id
)) {
1707 struct interface
*master
= if_lookup_by_name(
1708 vrf
->name
, vrf
->vrf_id
);
1712 "%s: Unable to find Master interface for %s",
1713 __func__
, vrf
->name
);
1716 pim_zebra_interface_set_master(master
, ifp
);
1723 static int pim_ifp_down(struct interface
*ifp
)
1725 if (PIM_DEBUG_ZEBRA
) {
1727 "%s: %s index %d vrf %s(%u) flags %ld metric %d mtu %d operative %d",
1728 __func__
, ifp
->name
, ifp
->ifindex
, ifp
->vrf
->name
,
1729 ifp
->vrf
->vrf_id
, (long)ifp
->flags
, ifp
->metric
,
1730 ifp
->mtu
, if_is_operative(ifp
));
1733 if (!if_is_operative(ifp
)) {
1734 pim_ifchannel_delete_all(ifp
);
1736 pim_if_addr_del_all() suffices for shutting down IGMP,
1737 but not for shutting down PIM
1739 pim_if_addr_del_all(ifp
);
1742 pim_sock_delete() closes the socket, stops read and timer
1744 and kills all neighbors.
1747 pim_sock_delete(ifp
, "link down");
1752 pim_if_del_vif(ifp
);
1753 pim_ifstat_reset(ifp
);
1759 static int pim_ifp_destroy(struct interface
*ifp
)
1761 if (PIM_DEBUG_ZEBRA
) {
1763 "%s: %s index %d vrf %s(%u) flags %ld metric %d mtu %d operative %d",
1764 __func__
, ifp
->name
, ifp
->ifindex
, ifp
->vrf
->name
,
1765 ifp
->vrf
->vrf_id
, (long)ifp
->flags
, ifp
->metric
,
1766 ifp
->mtu
, if_is_operative(ifp
));
1769 if (!if_is_operative(ifp
))
1770 pim_if_addr_del_all(ifp
);
1773 struct pim_instance
*pim
;
1775 pim
= ifp
->vrf
->info
;
1776 if (pim
&& pim
->vxlan
.term_if
== ifp
)
1777 pim_vxlan_del_term_dev(pim
);
1783 static int pim_if_new_hook(struct interface
*ifp
)
1788 static int pim_if_delete_hook(struct interface
*ifp
)
1796 void pim_iface_init(void)
1798 hook_register_prio(if_add
, 0, pim_if_new_hook
);
1799 hook_register_prio(if_del
, 0, pim_if_delete_hook
);
1801 if_zapi_callbacks(pim_ifp_create
, pim_ifp_up
, pim_ifp_down
,