3 * Copyright (C) 2016 Cumulus Networks, Inc.
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
23 #include <lib/jhash.h>
25 #include <lib/prefix.h>
26 #include <lib/sockunion.h>
27 #include <lib/stream.h>
28 #include <lib/thread.h>
30 #include <lib/plist.h>
31 #include <lib/lib_errors.h>
34 #include "pim_memory.h"
35 #include "pim_instance.h"
36 #include "pim_iface.h"
40 #include "pim_upstream.h"
44 #include "pim_msdp_packet.h"
45 #include "pim_msdp_socket.h"
47 // struct pim_msdp pim_msdp, *msdp = &pim_msdp;
49 static void pim_msdp_peer_listen(struct pim_msdp_peer
*mp
);
50 static void pim_msdp_peer_cr_timer_setup(struct pim_msdp_peer
*mp
, bool start
);
51 static void pim_msdp_peer_ka_timer_setup(struct pim_msdp_peer
*mp
, bool start
);
52 static void pim_msdp_peer_hold_timer_setup(struct pim_msdp_peer
*mp
,
54 static void pim_msdp_peer_free(struct pim_msdp_peer
*mp
);
55 static void pim_msdp_enable(struct pim_instance
*pim
);
56 static void pim_msdp_sa_adv_timer_setup(struct pim_instance
*pim
, bool start
);
57 static void pim_msdp_sa_deref(struct pim_msdp_sa
*sa
,
58 enum pim_msdp_sa_flags flags
);
59 static int pim_msdp_mg_mbr_comp(const void *p1
, const void *p2
);
60 static void pim_msdp_mg_mbr_free(struct pim_msdp_mg_mbr
*mbr
);
62 /************************ SA cache management ******************************/
63 static void pim_msdp_sa_timer_expiry_log(struct pim_msdp_sa
*sa
,
64 const char *timer_str
)
66 zlog_debug("MSDP SA %s %s timer expired", sa
->sg_str
, timer_str
);
69 /* RFC-3618:Sec-5.1 - global active source advertisement timer */
70 static void pim_msdp_sa_adv_timer_cb(struct thread
*t
)
72 struct pim_instance
*pim
= THREAD_ARG(t
);
74 if (PIM_DEBUG_MSDP_EVENTS
) {
75 zlog_debug("MSDP SA advertisement timer expired");
78 pim_msdp_sa_adv_timer_setup(pim
, true /* start */);
79 pim_msdp_pkt_sa_tx(pim
);
82 static void pim_msdp_sa_adv_timer_setup(struct pim_instance
*pim
, bool start
)
84 THREAD_OFF(pim
->msdp
.sa_adv_timer
);
86 thread_add_timer(pim
->msdp
.master
, pim_msdp_sa_adv_timer_cb
,
87 pim
, PIM_MSDP_SA_ADVERTISMENT_TIME
,
88 &pim
->msdp
.sa_adv_timer
);
92 /* RFC-3618:Sec-5.3 - SA cache state timer */
93 static void pim_msdp_sa_state_timer_cb(struct thread
*t
)
95 struct pim_msdp_sa
*sa
;
99 if (PIM_DEBUG_MSDP_EVENTS
) {
100 pim_msdp_sa_timer_expiry_log(sa
, "state");
103 pim_msdp_sa_deref(sa
, PIM_MSDP_SAF_PEER
);
106 static void pim_msdp_sa_state_timer_setup(struct pim_msdp_sa
*sa
, bool start
)
108 THREAD_OFF(sa
->sa_state_timer
);
110 thread_add_timer(sa
->pim
->msdp
.master
,
111 pim_msdp_sa_state_timer_cb
, sa
,
112 PIM_MSDP_SA_HOLD_TIME
, &sa
->sa_state_timer
);
116 static void pim_msdp_sa_upstream_del(struct pim_msdp_sa
*sa
)
118 struct pim_upstream
*up
= sa
->up
;
124 if (PIM_UPSTREAM_FLAG_TEST_SRC_MSDP(up
->flags
)) {
125 PIM_UPSTREAM_FLAG_UNSET_SRC_MSDP(up
->flags
);
126 sa
->flags
|= PIM_MSDP_SAF_UP_DEL_IN_PROG
;
127 up
= pim_upstream_del(sa
->pim
, up
, __func__
);
128 /* re-eval joinDesired; clearing peer-msdp-sa flag can
132 pim_upstream_update_join_desired(sa
->pim
, up
);
133 sa
->flags
&= ~PIM_MSDP_SAF_UP_DEL_IN_PROG
;
136 if (PIM_DEBUG_MSDP_EVENTS
) {
137 zlog_debug("MSDP SA %s de-referenced SPT", sa
->sg_str
);
141 static bool pim_msdp_sa_upstream_add_ok(struct pim_msdp_sa
*sa
,
142 struct pim_upstream
*xg_up
)
144 if (!(sa
->flags
& PIM_MSDP_SAF_PEER
)) {
145 /* SA should have been rxed from a peer */
148 /* check if we are RP */
149 if (!I_am_RP(sa
->pim
, sa
->sg
.grp
)) {
153 /* check if we have a (*, G) with a non-empty immediate OIL */
157 memset(&sg
, 0, sizeof(sg
));
160 xg_up
= pim_upstream_find(sa
->pim
, &sg
);
162 if (!xg_up
|| (xg_up
->join_state
!= PIM_UPSTREAM_JOINED
)) {
163 /* join desired will be true for such (*, G) entries so we will
164 * just look at join_state and let the PIM state machine do the
173 /* Upstream add evaluation needs to happen everytime -
174 * 1. Peer reference is added or removed.
175 * 2. The RP for a group changes.
176 * 3. joinDesired for the associated (*, G) changes
177 * 4. associated (*, G) is removed - this seems like a bit redundant
178 * (considering #4); but just in case an entry gets nuked without
179 * upstream state transition
181 static void pim_msdp_sa_upstream_update(struct pim_msdp_sa
*sa
,
182 struct pim_upstream
*xg_up
,
185 struct pim_upstream
*up
;
187 if (!pim_msdp_sa_upstream_add_ok(sa
, xg_up
)) {
188 pim_msdp_sa_upstream_del(sa
);
197 up
= pim_upstream_find(sa
->pim
, &sa
->sg
);
198 if (up
&& (PIM_UPSTREAM_FLAG_TEST_SRC_MSDP(up
->flags
))) {
199 /* somehow we lost track of the upstream ptr? best log it */
201 if (PIM_DEBUG_MSDP_EVENTS
) {
202 zlog_debug("MSDP SA %s SPT reference missing",
208 /* RFC3618: "RP triggers a (S, G) join event towards the data source
209 * as if a JP message was rxed addressed to the RP itself." */
210 up
= pim_upstream_add(sa
->pim
, &sa
->sg
, NULL
/* iif */,
211 PIM_UPSTREAM_FLAG_MASK_SRC_MSDP
, __func__
, NULL
);
215 /* update inherited oil */
216 pim_upstream_inherited_olist(sa
->pim
, up
);
217 /* should we also start the kat in parallel? we will need it
220 if (PIM_DEBUG_MSDP_EVENTS
) {
221 zlog_debug("MSDP SA %s referenced SPT", sa
->sg_str
);
224 if (PIM_DEBUG_MSDP_EVENTS
) {
225 zlog_debug("MSDP SA %s SPT reference failed",
231 /* release all mem associated with a sa */
232 static void pim_msdp_sa_free(struct pim_msdp_sa
*sa
)
234 pim_msdp_sa_state_timer_setup(sa
, false);
236 XFREE(MTYPE_PIM_MSDP_SA
, sa
);
239 static struct pim_msdp_sa
*pim_msdp_sa_new(struct pim_instance
*pim
,
240 pim_sgaddr
*sg
, struct in_addr rp
)
242 struct pim_msdp_sa
*sa
;
244 sa
= XCALLOC(MTYPE_PIM_MSDP_SA
, sizeof(*sa
));
248 snprintfrr(sa
->sg_str
, sizeof(sa
->sg_str
), "%pSG", sg
);
250 sa
->uptime
= pim_time_monotonic_sec();
252 /* insert into misc tables for easy access */
253 sa
= hash_get(pim
->msdp
.sa_hash
, sa
, hash_alloc_intern
);
254 listnode_add_sort(pim
->msdp
.sa_list
, sa
);
256 if (PIM_DEBUG_MSDP_EVENTS
) {
257 zlog_debug("MSDP SA %s created", sa
->sg_str
);
263 static struct pim_msdp_sa
*pim_msdp_sa_find(struct pim_instance
*pim
,
266 struct pim_msdp_sa lookup
;
269 return hash_lookup(pim
->msdp
.sa_hash
, &lookup
);
272 static struct pim_msdp_sa
*pim_msdp_sa_add(struct pim_instance
*pim
,
273 pim_sgaddr
*sg
, struct in_addr rp
)
275 struct pim_msdp_sa
*sa
;
277 sa
= pim_msdp_sa_find(pim
, sg
);
282 return pim_msdp_sa_new(pim
, sg
, rp
);
285 static void pim_msdp_sa_del(struct pim_msdp_sa
*sa
)
287 /* this is somewhat redundant - still want to be careful not to leave
288 * stale upstream references */
289 pim_msdp_sa_upstream_del(sa
);
292 pim_msdp_sa_state_timer_setup(sa
, false /* start */);
294 /* remove the entry from various tables */
295 listnode_delete(sa
->pim
->msdp
.sa_list
, sa
);
296 hash_release(sa
->pim
->msdp
.sa_hash
, sa
);
298 if (PIM_DEBUG_MSDP_EVENTS
) {
299 zlog_debug("MSDP SA %s deleted", sa
->sg_str
);
302 /* free up any associated memory */
303 pim_msdp_sa_free(sa
);
306 static void pim_msdp_sa_peer_ip_set(struct pim_msdp_sa
*sa
,
307 struct pim_msdp_peer
*mp
, struct in_addr rp
)
309 struct pim_msdp_peer
*old_mp
;
311 /* optimize the "no change" case as it will happen
312 * frequently/periodically */
313 if (mp
&& (sa
->peer
.s_addr
== mp
->peer
.s_addr
)) {
317 /* any time the peer ip changes also update the rp address */
318 if (sa
->peer
.s_addr
!= INADDR_ANY
) {
319 old_mp
= pim_msdp_peer_find(sa
->pim
, sa
->peer
);
320 if (old_mp
&& old_mp
->sa_cnt
) {
329 sa
->peer
.s_addr
= PIM_NET_INADDR_ANY
;
334 /* When a local active-source is removed there is no way to withdraw the
335 * source from peers. We will simply remove it from the SA cache so it will
336 * not be sent in supsequent SA updates. Peers will consequently timeout the
338 * Similarly a "peer-added" SA is never explicitly deleted. It is simply
339 * aged out overtime if not seen in the SA updates from the peers.
340 * XXX: should we provide a knob to drop entries learnt from a peer when the
342 static void pim_msdp_sa_deref(struct pim_msdp_sa
*sa
,
343 enum pim_msdp_sa_flags flags
)
345 bool update_up
= false;
347 if ((sa
->flags
& PIM_MSDP_SAF_LOCAL
)) {
348 if (flags
& PIM_MSDP_SAF_LOCAL
) {
349 if (PIM_DEBUG_MSDP_EVENTS
) {
350 zlog_debug("MSDP SA %s local reference removed",
353 if (sa
->pim
->msdp
.local_cnt
)
354 --sa
->pim
->msdp
.local_cnt
;
358 if ((sa
->flags
& PIM_MSDP_SAF_PEER
)) {
359 if (flags
& PIM_MSDP_SAF_PEER
) {
362 if (PIM_DEBUG_MSDP_EVENTS
) {
363 zlog_debug("MSDP SA %s peer reference removed",
366 pim_msdp_sa_state_timer_setup(sa
, false /* start */);
367 rp
.s_addr
= INADDR_ANY
;
368 pim_msdp_sa_peer_ip_set(sa
, NULL
/* mp */, rp
);
369 /* if peer ref was removed we need to remove the msdp
378 pim_msdp_sa_upstream_update(sa
, NULL
/* xg_up */, "sa-deref");
381 if (!(sa
->flags
& PIM_MSDP_SAF_REF
)) {
386 void pim_msdp_sa_ref(struct pim_instance
*pim
, struct pim_msdp_peer
*mp
,
387 pim_sgaddr
*sg
, struct in_addr rp
)
389 struct pim_msdp_sa
*sa
;
391 sa
= pim_msdp_sa_add(pim
, sg
, rp
);
398 if (!(sa
->flags
& PIM_MSDP_SAF_PEER
)) {
399 sa
->flags
|= PIM_MSDP_SAF_PEER
;
400 if (PIM_DEBUG_MSDP_EVENTS
) {
401 zlog_debug("MSDP SA %s added by peer",
405 pim_msdp_sa_peer_ip_set(sa
, mp
, rp
);
406 /* start/re-start the state timer to prevent cache expiry */
407 pim_msdp_sa_state_timer_setup(sa
, true /* start */);
408 /* We re-evaluate SA "SPT-trigger" everytime we hear abt it from
410 * peer. XXX: If this becomes too much of a periodic overhead we
411 * can make it event based */
412 pim_msdp_sa_upstream_update(sa
, NULL
/* xg_up */, "peer-ref");
414 if (!(sa
->flags
& PIM_MSDP_SAF_LOCAL
)) {
415 sa
->flags
|= PIM_MSDP_SAF_LOCAL
;
416 ++sa
->pim
->msdp
.local_cnt
;
417 if (PIM_DEBUG_MSDP_EVENTS
) {
418 zlog_debug("MSDP SA %s added locally",
421 /* send an immediate SA update to peers */
422 sa
->rp
= pim
->msdp
.originator_id
;
423 pim_msdp_pkt_sa_tx_one(sa
);
425 sa
->flags
&= ~PIM_MSDP_SAF_STALE
;
429 /* The following criteria must be met to originate an SA from the MSDP
431 * 1. KAT must be running i.e. source is active.
432 * 2. We must be RP for the group.
433 * 3. Source must be registrable to the RP (this is where the RFC is vague
434 * and especially ambiguous in CLOS networks; with anycast RP all sources
435 * are potentially registrable to all RPs in the domain). We assume #3 is
437 * a. We are also the FHR-DR for the source (OR)
438 * b. We rxed a pim register (null or data encapsulated) within the last
439 * (3 * (1.5 * register_suppression_timer))).
441 static bool pim_msdp_sa_local_add_ok(struct pim_upstream
*up
)
443 struct pim_instance
*pim
= up
->channel_oil
->pim
;
445 if (!(pim
->msdp
.flags
& PIM_MSDPF_ENABLE
)) {
449 if (!pim_upstream_is_kat_running(up
))
450 /* stream is not active */
453 if (!I_am_RP(pim
, up
->sg
.grp
)) {
454 /* we are not RP for the group */
458 /* we are the FHR-DR for this stream or we are RP and have seen
460 * from a FHR for this source */
461 if (PIM_UPSTREAM_FLAG_TEST_FHR(up
->flags
) || up
->t_msdp_reg_timer
) {
468 static void pim_msdp_sa_local_add(struct pim_instance
*pim
, pim_sgaddr
*sg
)
471 rp
.s_addr
= INADDR_ANY
;
472 pim_msdp_sa_ref(pim
, NULL
/* mp */, sg
, rp
);
475 void pim_msdp_sa_local_del(struct pim_instance
*pim
, pim_sgaddr
*sg
)
477 struct pim_msdp_sa
*sa
;
479 sa
= pim_msdp_sa_find(pim
, sg
);
481 pim_msdp_sa_deref(sa
, PIM_MSDP_SAF_LOCAL
);
485 /* we need to be very cautious with this API as SA del too can trigger an
486 * upstream del and we will get stuck in a simple loop */
487 static void pim_msdp_sa_local_del_on_up_del(struct pim_instance
*pim
,
490 struct pim_msdp_sa
*sa
;
492 sa
= pim_msdp_sa_find(pim
, sg
);
494 if (PIM_DEBUG_MSDP_INTERNAL
) {
495 zlog_debug("MSDP local sa %s del on up del",
499 /* if there is no local reference escape */
500 if (!(sa
->flags
& PIM_MSDP_SAF_LOCAL
)) {
501 if (PIM_DEBUG_MSDP_INTERNAL
) {
502 zlog_debug("MSDP local sa %s del; no local ref",
508 if (sa
->flags
& PIM_MSDP_SAF_UP_DEL_IN_PROG
) {
509 /* MSDP is the one that triggered the upstream del. if
511 * we most certainly have a bug in the PIM upstream
513 * will not have a local reference unless the KAT is
514 * running. And if the
515 * KAT is running there MUST be an additional
516 * source-stream reference to
517 * the flow. Accounting for such cases requires lot of
519 * address this in the next release? - XXX */
522 "MSDP sa %s SPT teardown is causing the local entry to be removed",
527 /* we are dropping the sa on upstream del we should not have an
528 * upstream reference */
530 if (PIM_DEBUG_MSDP_INTERNAL
) {
531 zlog_debug("MSDP local sa %s del; up non-NULL",
536 pim_msdp_sa_deref(sa
, PIM_MSDP_SAF_LOCAL
);
540 /* Local SA qualification needs to be re-evaluated when -
541 * 1. KAT is started or stopped
543 * 3. Whenever FHR status changes for a (S,G) - XXX - currently there
544 * is no clear path to transition an entry out of "MASK_FHR" need
545 * to discuss this with Donald. May result in some strangeness if the
546 * FHR is also the RP.
547 * 4. When msdp_reg timer is started or stopped
549 void pim_msdp_sa_local_update(struct pim_upstream
*up
)
551 struct pim_instance
*pim
= up
->channel_oil
->pim
;
553 if (pim_msdp_sa_local_add_ok(up
)) {
554 pim_msdp_sa_local_add(pim
, &up
->sg
);
556 pim_msdp_sa_local_del(pim
, &up
->sg
);
560 static void pim_msdp_sa_local_setup(struct pim_instance
*pim
)
562 struct pim_upstream
*up
;
564 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
)
565 pim_msdp_sa_local_update(up
);
568 /* whenever the RP changes we need to re-evaluate the "local" SA-cache */
569 /* XXX: needs to be tested */
570 void pim_msdp_i_am_rp_changed(struct pim_instance
*pim
)
572 struct listnode
*sanode
;
573 struct listnode
*nextnode
;
574 struct pim_msdp_sa
*sa
;
576 if (!(pim
->msdp
.flags
& PIM_MSDPF_ENABLE
)) {
577 /* if the feature is not enabled do nothing */
581 if (PIM_DEBUG_MSDP_INTERNAL
) {
582 zlog_debug("MSDP i_am_rp changed");
585 /* mark all local entries as stale */
586 for (ALL_LIST_ELEMENTS_RO(pim
->msdp
.sa_list
, sanode
, sa
)) {
587 if (sa
->flags
& PIM_MSDP_SAF_LOCAL
) {
588 sa
->flags
|= PIM_MSDP_SAF_STALE
;
592 /* re-setup local SA entries */
593 pim_msdp_sa_local_setup(pim
);
595 for (ALL_LIST_ELEMENTS(pim
->msdp
.sa_list
, sanode
, nextnode
, sa
)) {
596 /* purge stale SA entries */
597 if (sa
->flags
& PIM_MSDP_SAF_STALE
) {
598 /* clear the stale flag; the entry may be kept even
601 sa
->flags
&= ~PIM_MSDP_SAF_STALE
;
602 /* sa_deref can end up freeing the sa; so don't access
604 pim_msdp_sa_deref(sa
, PIM_MSDP_SAF_LOCAL
);
606 /* if the souce is still active check if we can
608 pim_msdp_sa_upstream_update(sa
, NULL
/* xg_up */,
614 /* We track the join state of (*, G) entries. If G has sources in the SA-cache
615 * we need to setup or teardown SPT when the JoinDesired status changes for
617 void pim_msdp_up_join_state_changed(struct pim_instance
*pim
,
618 struct pim_upstream
*xg_up
)
620 struct listnode
*sanode
;
621 struct pim_msdp_sa
*sa
;
623 if (PIM_DEBUG_MSDP_INTERNAL
) {
624 zlog_debug("MSDP join state changed for %s", xg_up
->sg_str
);
627 /* If this is not really an XG entry just move on */
628 if (!pim_addr_is_any(xg_up
->sg
.src
) || pim_addr_is_any(xg_up
->sg
.grp
)) {
632 /* XXX: Need to maintain SAs per-group to avoid all this unnecessary
634 for (ALL_LIST_ELEMENTS_RO(pim
->msdp
.sa_list
, sanode
, sa
)) {
635 if (pim_addr_cmp(sa
->sg
.grp
, xg_up
->sg
.grp
)) {
638 pim_msdp_sa_upstream_update(sa
, xg_up
, "up-jp-change");
642 static void pim_msdp_up_xg_del(struct pim_instance
*pim
, pim_sgaddr
*sg
)
644 struct listnode
*sanode
;
645 struct pim_msdp_sa
*sa
;
647 if (PIM_DEBUG_MSDP_INTERNAL
) {
648 zlog_debug("MSDP %pSG del", sg
);
651 /* If this is not really an XG entry just move on */
652 if (!pim_addr_is_any(sg
->src
) || pim_addr_is_any(sg
->grp
)) {
656 /* XXX: Need to maintain SAs per-group to avoid all this unnecessary
658 for (ALL_LIST_ELEMENTS_RO(pim
->msdp
.sa_list
, sanode
, sa
)) {
659 if (pim_addr_cmp(sa
->sg
.grp
, sg
->grp
)) {
662 pim_msdp_sa_upstream_update(sa
, NULL
/* xg */, "up-jp-change");
666 void pim_msdp_up_del(struct pim_instance
*pim
, pim_sgaddr
*sg
)
668 if (PIM_DEBUG_MSDP_INTERNAL
) {
669 zlog_debug("MSDP up %pSG del", sg
);
671 if (pim_addr_is_any(sg
->src
)) {
672 pim_msdp_up_xg_del(pim
, sg
);
674 pim_msdp_sa_local_del_on_up_del(pim
, sg
);
678 /* sa hash and peer list helpers */
679 static unsigned int pim_msdp_sa_hash_key_make(const void *p
)
681 const struct pim_msdp_sa
*sa
= p
;
683 return pim_sgaddr_hash(sa
->sg
, 0);
686 static bool pim_msdp_sa_hash_eq(const void *p1
, const void *p2
)
688 const struct pim_msdp_sa
*sa1
= p1
;
689 const struct pim_msdp_sa
*sa2
= p2
;
691 return !pim_sgaddr_cmp(sa1
->sg
, sa2
->sg
);
694 static int pim_msdp_sa_comp(const void *p1
, const void *p2
)
696 const struct pim_msdp_sa
*sa1
= p1
;
697 const struct pim_msdp_sa
*sa2
= p2
;
699 return pim_sgaddr_cmp(sa1
->sg
, sa2
->sg
);
702 /* RFC-3618:Sec-10.1.3 - Peer-RPF forwarding */
703 /* XXX: this can use a bit of refining and extensions */
704 bool pim_msdp_peer_rpf_check(struct pim_msdp_peer
*mp
, struct in_addr rp
)
706 struct pim_nexthop nexthop
= {0};
708 if (mp
->peer
.s_addr
== rp
.s_addr
) {
712 /* check if the MSDP peer is the nexthop for the RP */
713 if (pim_nexthop_lookup(mp
->pim
, &nexthop
, rp
, 0) &&
714 nexthop
.mrib_nexthop_addr
.s_addr
== mp
->peer
.s_addr
) {
721 /************************ Peer session management **************************/
722 char *pim_msdp_state_dump(enum pim_msdp_peer_state state
, char *buf
,
726 case PIM_MSDP_DISABLED
:
727 snprintf(buf
, buf_size
, "%s", "disabled");
729 case PIM_MSDP_INACTIVE
:
730 snprintf(buf
, buf_size
, "%s", "inactive");
732 case PIM_MSDP_LISTEN
:
733 snprintf(buf
, buf_size
, "%s", "listen");
735 case PIM_MSDP_CONNECTING
:
736 snprintf(buf
, buf_size
, "%s", "connecting");
738 case PIM_MSDP_ESTABLISHED
:
739 snprintf(buf
, buf_size
, "%s", "established");
742 snprintf(buf
, buf_size
, "unk-%d", state
);
747 static void pim_msdp_peer_state_chg_log(struct pim_msdp_peer
*mp
)
749 char state_str
[PIM_MSDP_STATE_STRLEN
];
751 pim_msdp_state_dump(mp
->state
, state_str
, sizeof(state_str
));
752 zlog_debug("MSDP peer %s state chg to %s", mp
->key_str
, state_str
);
755 /* MSDP Connection State Machine actions (defined in RFC-3618:Sec-11.2) */
756 /* 11.2.A2: active peer - start connect retry timer; when the timer fires
757 * a tcp connection will be made */
758 static void pim_msdp_peer_connect(struct pim_msdp_peer
*mp
)
760 mp
->state
= PIM_MSDP_CONNECTING
;
761 if (PIM_DEBUG_MSDP_EVENTS
) {
762 pim_msdp_peer_state_chg_log(mp
);
765 pim_msdp_peer_cr_timer_setup(mp
, true /* start */);
768 /* 11.2.A3: passive peer - just listen for connections */
769 static void pim_msdp_peer_listen(struct pim_msdp_peer
*mp
)
771 mp
->state
= PIM_MSDP_LISTEN
;
772 if (PIM_DEBUG_MSDP_EVENTS
) {
773 pim_msdp_peer_state_chg_log(mp
);
776 /* this is interntionally asymmetric i.e. we set up listen-socket when
778 * first listening peer is configured; but don't bother tearing it down
780 * all the peers go down */
781 pim_msdp_sock_listen(mp
->pim
);
784 /* 11.2.A4 and 11.2.A5: transition active or passive peer to
785 * established state */
786 void pim_msdp_peer_established(struct pim_msdp_peer
*mp
)
788 if (mp
->state
!= PIM_MSDP_ESTABLISHED
) {
792 mp
->state
= PIM_MSDP_ESTABLISHED
;
793 mp
->uptime
= pim_time_monotonic_sec();
795 if (PIM_DEBUG_MSDP_EVENTS
) {
796 pim_msdp_peer_state_chg_log(mp
);
799 /* stop retry timer on active peers */
800 pim_msdp_peer_cr_timer_setup(mp
, false /* start */);
802 /* send KA; start KA and hold timers */
803 pim_msdp_pkt_ka_tx(mp
);
804 pim_msdp_peer_ka_timer_setup(mp
, true /* start */);
805 pim_msdp_peer_hold_timer_setup(mp
, true /* start */);
807 pim_msdp_pkt_sa_tx_to_one_peer(mp
);
809 PIM_MSDP_PEER_WRITE_ON(mp
);
810 PIM_MSDP_PEER_READ_ON(mp
);
813 /* 11.2.A6, 11.2.A7 and 11.2.A8: shutdown the peer tcp connection */
814 void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer
*mp
, bool chg_state
)
817 if (mp
->state
== PIM_MSDP_ESTABLISHED
) {
820 mp
->state
= PIM_MSDP_INACTIVE
;
821 if (PIM_DEBUG_MSDP_EVENTS
) {
822 pim_msdp_peer_state_chg_log(mp
);
826 if (PIM_DEBUG_MSDP_INTERNAL
) {
827 zlog_debug("MSDP peer %s pim_msdp_peer_stop_tcp_conn",
830 /* stop read and write threads */
831 PIM_MSDP_PEER_READ_OFF(mp
);
832 PIM_MSDP_PEER_WRITE_OFF(mp
);
837 stream_reset(mp
->ibuf
);
839 stream_fifo_clean(mp
->obuf
);
841 /* stop all peer timers */
842 pim_msdp_peer_ka_timer_setup(mp
, false /* start */);
843 pim_msdp_peer_cr_timer_setup(mp
, false /* start */);
844 pim_msdp_peer_hold_timer_setup(mp
, false /* start */);
846 /* close connection */
853 /* RFC-3618:Sec-5.6 - stop the peer tcp connection and startover */
854 void pim_msdp_peer_reset_tcp_conn(struct pim_msdp_peer
*mp
, const char *rc_str
)
856 if (PIM_DEBUG_EVENTS
) {
857 zlog_debug("MSDP peer %s tcp reset %s", mp
->key_str
, rc_str
);
858 snprintf(mp
->last_reset
, sizeof(mp
->last_reset
), "%s", rc_str
);
861 /* close the connection and transition to listening or connecting */
862 pim_msdp_peer_stop_tcp_conn(mp
, true /* chg_state */);
863 if (PIM_MSDP_PEER_IS_LISTENER(mp
)) {
864 pim_msdp_peer_listen(mp
);
866 pim_msdp_peer_connect(mp
);
870 static void pim_msdp_peer_timer_expiry_log(struct pim_msdp_peer
*mp
,
871 const char *timer_str
)
873 zlog_debug("MSDP peer %s %s timer expired", mp
->key_str
, timer_str
);
876 /* RFC-3618:Sec-5.4 - peer hold timer */
877 static void pim_msdp_peer_hold_timer_cb(struct thread
*t
)
879 struct pim_msdp_peer
*mp
;
883 if (PIM_DEBUG_MSDP_EVENTS
) {
884 pim_msdp_peer_timer_expiry_log(mp
, "hold");
887 if (mp
->state
!= PIM_MSDP_ESTABLISHED
) {
891 if (PIM_DEBUG_MSDP_EVENTS
) {
892 pim_msdp_peer_state_chg_log(mp
);
894 pim_msdp_peer_reset_tcp_conn(mp
, "ht-expired");
897 static void pim_msdp_peer_hold_timer_setup(struct pim_msdp_peer
*mp
, bool start
)
899 struct pim_instance
*pim
= mp
->pim
;
900 THREAD_OFF(mp
->hold_timer
);
902 thread_add_timer(pim
->msdp
.master
, pim_msdp_peer_hold_timer_cb
,
903 mp
, pim
->msdp
.hold_time
, &mp
->hold_timer
);
908 /* RFC-3618:Sec-5.5 - peer keepalive timer */
909 static void pim_msdp_peer_ka_timer_cb(struct thread
*t
)
911 struct pim_msdp_peer
*mp
;
915 if (PIM_DEBUG_MSDP_EVENTS
) {
916 pim_msdp_peer_timer_expiry_log(mp
, "ka");
919 pim_msdp_pkt_ka_tx(mp
);
920 pim_msdp_peer_ka_timer_setup(mp
, true /* start */);
923 static void pim_msdp_peer_ka_timer_setup(struct pim_msdp_peer
*mp
, bool start
)
925 THREAD_OFF(mp
->ka_timer
);
927 thread_add_timer(mp
->pim
->msdp
.master
,
928 pim_msdp_peer_ka_timer_cb
, mp
,
929 mp
->pim
->msdp
.keep_alive
, &mp
->ka_timer
);
933 static void pim_msdp_peer_active_connect(struct pim_msdp_peer
*mp
)
937 rc
= pim_msdp_sock_connect(mp
);
939 if (PIM_DEBUG_MSDP_INTERNAL
) {
940 zlog_debug("MSDP peer %s pim_msdp_peer_active_connect: %d",
947 /* connect failed restart the connect-retry timer */
948 pim_msdp_peer_cr_timer_setup(mp
, true /* start */);
951 case connect_success
:
952 /* connect was sucessful move to established */
953 pim_msdp_peer_established(mp
);
956 case connect_in_progress
:
957 /* for NB content we need to wait till sock is readable or
959 PIM_MSDP_PEER_WRITE_ON(mp
);
960 PIM_MSDP_PEER_READ_ON(mp
);
961 /* also restart connect-retry timer to reset the socket if
964 pim_msdp_peer_cr_timer_setup(mp
, true /* start */);
969 /* RFC-3618:Sec-5.6 - connection retry on active peer */
970 static void pim_msdp_peer_cr_timer_cb(struct thread
*t
)
972 struct pim_msdp_peer
*mp
;
976 if (PIM_DEBUG_MSDP_EVENTS
) {
977 pim_msdp_peer_timer_expiry_log(mp
, "connect-retry");
980 if (mp
->state
!= PIM_MSDP_CONNECTING
|| PIM_MSDP_PEER_IS_LISTENER(mp
)) {
984 pim_msdp_peer_active_connect(mp
);
987 static void pim_msdp_peer_cr_timer_setup(struct pim_msdp_peer
*mp
, bool start
)
989 THREAD_OFF(mp
->cr_timer
);
991 thread_add_timer(mp
->pim
->msdp
.master
,
992 pim_msdp_peer_cr_timer_cb
, mp
,
993 mp
->pim
->msdp
.connection_retry
, &mp
->cr_timer
);
997 /* if a valid packet is rxed from the peer we can restart hold timer */
998 void pim_msdp_peer_pkt_rxed(struct pim_msdp_peer
*mp
)
1000 if (mp
->state
== PIM_MSDP_ESTABLISHED
) {
1001 pim_msdp_peer_hold_timer_setup(mp
, true /* start */);
1005 /* if a valid packet is txed to the peer we can restart ka timer and avoid
1006 * unnecessary ka noise in the network */
1007 void pim_msdp_peer_pkt_txed(struct pim_msdp_peer
*mp
)
1009 if (mp
->state
== PIM_MSDP_ESTABLISHED
) {
1010 pim_msdp_peer_ka_timer_setup(mp
, true /* start */);
1011 if (PIM_DEBUG_MSDP_INTERNAL
) {
1012 zlog_debug("MSDP ka timer restart on pkt tx to %s",
1018 static void pim_msdp_addr2su(union sockunion
*su
, struct in_addr addr
)
1021 su
->sin
.sin_addr
= addr
;
1022 su
->sin
.sin_family
= AF_INET
;
1023 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
1024 su
->sin
.sin_len
= sizeof(struct sockaddr_in
);
1025 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
1028 /* 11.2.A1: create a new peer and transition state to listen or connecting */
1029 struct pim_msdp_peer
*pim_msdp_peer_add(struct pim_instance
*pim
,
1030 const struct in_addr
*peer
,
1031 const struct in_addr
*local
,
1032 const char *mesh_group_name
)
1034 struct pim_msdp_peer
*mp
;
1036 pim_msdp_enable(pim
);
1038 mp
= XCALLOC(MTYPE_PIM_MSDP_PEER
, sizeof(*mp
));
1042 pim_inet4_dump("<peer?>", mp
->peer
, mp
->key_str
, sizeof(mp
->key_str
));
1043 pim_msdp_addr2su(&mp
->su_peer
, mp
->peer
);
1045 /* XXX: originator_id setting needs to move to the mesh group */
1046 pim
->msdp
.originator_id
= *local
;
1047 pim_msdp_addr2su(&mp
->su_local
, mp
->local
);
1048 if (mesh_group_name
)
1049 mp
->mesh_group_name
=
1050 XSTRDUP(MTYPE_PIM_MSDP_MG_NAME
, mesh_group_name
);
1052 mp
->state
= PIM_MSDP_INACTIVE
;
1054 strlcpy(mp
->last_reset
, "-", sizeof(mp
->last_reset
));
1055 /* higher IP address is listener */
1056 if (ntohl(mp
->local
.s_addr
) > ntohl(mp
->peer
.s_addr
)) {
1057 mp
->flags
|= PIM_MSDP_PEERF_LISTENER
;
1060 /* setup packet buffers */
1061 mp
->ibuf
= stream_new(PIM_MSDP_MAX_PACKET_SIZE
);
1062 mp
->obuf
= stream_fifo_new();
1064 /* insert into misc tables for easy access */
1065 mp
= hash_get(pim
->msdp
.peer_hash
, mp
, hash_alloc_intern
);
1066 listnode_add_sort(pim
->msdp
.peer_list
, mp
);
1068 if (PIM_DEBUG_MSDP_EVENTS
) {
1069 zlog_debug("MSDP peer %s created", mp
->key_str
);
1071 pim_msdp_peer_state_chg_log(mp
);
1074 /* fireup the connect state machine */
1075 if (PIM_MSDP_PEER_IS_LISTENER(mp
)) {
1076 pim_msdp_peer_listen(mp
);
1078 pim_msdp_peer_connect(mp
);
1083 struct pim_msdp_peer
*pim_msdp_peer_find(struct pim_instance
*pim
,
1084 struct in_addr peer_addr
)
1086 struct pim_msdp_peer lookup
;
1088 lookup
.peer
= peer_addr
;
1089 return hash_lookup(pim
->msdp
.peer_hash
, &lookup
);
1092 /* release all mem associated with a peer */
1093 static void pim_msdp_peer_free(struct pim_msdp_peer
*mp
)
1096 * Let's make sure we are not running when we delete
1097 * the underlying data structure
1099 pim_msdp_peer_stop_tcp_conn(mp
, false);
1102 stream_free(mp
->ibuf
);
1106 stream_fifo_free(mp
->obuf
);
1109 XFREE(MTYPE_PIM_MSDP_MG_NAME
, mp
->mesh_group_name
);
1112 XFREE(MTYPE_PIM_MSDP_PEER
, mp
);
1115 /* delete the peer config */
1116 void pim_msdp_peer_del(struct pim_msdp_peer
**mp
)
1121 /* stop the tcp connection and shutdown all timers */
1122 pim_msdp_peer_stop_tcp_conn(*mp
, true /* chg_state */);
1124 /* remove the session from various tables */
1125 listnode_delete((*mp
)->pim
->msdp
.peer_list
, *mp
);
1126 hash_release((*mp
)->pim
->msdp
.peer_hash
, *mp
);
1128 if (PIM_DEBUG_MSDP_EVENTS
) {
1129 zlog_debug("MSDP peer %s deleted", (*mp
)->key_str
);
1132 /* free up any associated memory */
1133 pim_msdp_peer_free(*mp
);
1137 void pim_msdp_peer_change_source(struct pim_msdp_peer
*mp
,
1138 const struct in_addr
*addr
)
1140 pim_msdp_peer_stop_tcp_conn(mp
, true);
1144 if (PIM_MSDP_PEER_IS_LISTENER(mp
))
1145 pim_msdp_peer_listen(mp
);
1147 pim_msdp_peer_connect(mp
);
1150 /* peer hash and peer list helpers */
1151 static unsigned int pim_msdp_peer_hash_key_make(const void *p
)
1153 const struct pim_msdp_peer
*mp
= p
;
1154 return (jhash_1word(mp
->peer
.s_addr
, 0));
1157 static bool pim_msdp_peer_hash_eq(const void *p1
, const void *p2
)
1159 const struct pim_msdp_peer
*mp1
= p1
;
1160 const struct pim_msdp_peer
*mp2
= p2
;
1162 return (mp1
->peer
.s_addr
== mp2
->peer
.s_addr
);
1165 static int pim_msdp_peer_comp(const void *p1
, const void *p2
)
1167 const struct pim_msdp_peer
*mp1
= p1
;
1168 const struct pim_msdp_peer
*mp2
= p2
;
1170 if (ntohl(mp1
->peer
.s_addr
) < ntohl(mp2
->peer
.s_addr
))
1173 if (ntohl(mp1
->peer
.s_addr
) > ntohl(mp2
->peer
.s_addr
))
1179 /************************** Mesh group management **************************/
1180 void pim_msdp_mg_free(struct pim_instance
*pim
, struct pim_msdp_mg
**mgp
)
1182 struct pim_msdp_mg_mbr
*mbr
;
1183 struct listnode
*n
, *nn
;
1188 /* SIP is being removed - tear down all active peer sessions */
1189 for (ALL_LIST_ELEMENTS((*mgp
)->mbr_list
, n
, nn
, mbr
))
1190 pim_msdp_mg_mbr_del((*mgp
), mbr
);
1192 if (PIM_DEBUG_MSDP_EVENTS
) {
1193 zlog_debug("MSDP mesh-group %s deleted",
1194 (*mgp
)->mesh_group_name
);
1197 XFREE(MTYPE_PIM_MSDP_MG_NAME
, (*mgp
)->mesh_group_name
);
1199 if ((*mgp
)->mbr_list
)
1200 list_delete(&(*mgp
)->mbr_list
);
1202 SLIST_REMOVE(&pim
->msdp
.mglist
, (*mgp
), pim_msdp_mg
, mg_entry
);
1203 XFREE(MTYPE_PIM_MSDP_MG
, (*mgp
));
1206 struct pim_msdp_mg
*pim_msdp_mg_new(struct pim_instance
*pim
,
1207 const char *mesh_group_name
)
1209 struct pim_msdp_mg
*mg
;
1211 mg
= XCALLOC(MTYPE_PIM_MSDP_MG
, sizeof(*mg
));
1213 mg
->mesh_group_name
= XSTRDUP(MTYPE_PIM_MSDP_MG_NAME
, mesh_group_name
);
1214 mg
->mbr_list
= list_new();
1215 mg
->mbr_list
->del
= (void (*)(void *))pim_msdp_mg_mbr_free
;
1216 mg
->mbr_list
->cmp
= (int (*)(void *, void *))pim_msdp_mg_mbr_comp
;
1218 if (PIM_DEBUG_MSDP_EVENTS
) {
1219 zlog_debug("MSDP mesh-group %s created", mg
->mesh_group_name
);
1222 SLIST_INSERT_HEAD(&pim
->msdp
.mglist
, mg
, mg_entry
);
1227 static int pim_msdp_mg_mbr_comp(const void *p1
, const void *p2
)
1229 const struct pim_msdp_mg_mbr
*mbr1
= p1
;
1230 const struct pim_msdp_mg_mbr
*mbr2
= p2
;
1232 if (ntohl(mbr1
->mbr_ip
.s_addr
) < ntohl(mbr2
->mbr_ip
.s_addr
))
1235 if (ntohl(mbr1
->mbr_ip
.s_addr
) > ntohl(mbr2
->mbr_ip
.s_addr
))
1241 static void pim_msdp_mg_mbr_free(struct pim_msdp_mg_mbr
*mbr
)
1243 XFREE(MTYPE_PIM_MSDP_MG_MBR
, mbr
);
1246 void pim_msdp_mg_mbr_del(struct pim_msdp_mg
*mg
, struct pim_msdp_mg_mbr
*mbr
)
1248 /* Delete active peer session if any */
1250 pim_msdp_peer_del(&mbr
->mp
);
1253 listnode_delete(mg
->mbr_list
, mbr
);
1254 if (PIM_DEBUG_MSDP_EVENTS
) {
1255 char ip_str
[INET_ADDRSTRLEN
];
1256 pim_inet4_dump("<mbr?>", mbr
->mbr_ip
, ip_str
, sizeof(ip_str
));
1257 zlog_debug("MSDP mesh-group %s mbr %s deleted",
1258 mg
->mesh_group_name
, ip_str
);
1260 pim_msdp_mg_mbr_free(mbr
);
1266 static void pim_msdp_src_del(struct pim_msdp_mg
*mg
)
1268 struct pim_msdp_mg_mbr
*mbr
;
1269 struct listnode
*mbr_node
;
1271 /* SIP is being removed - tear down all active peer sessions */
1272 for (ALL_LIST_ELEMENTS_RO(mg
->mbr_list
, mbr_node
, mbr
)) {
1274 pim_msdp_peer_del(&mbr
->mp
);
1276 if (PIM_DEBUG_MSDP_EVENTS
) {
1277 zlog_debug("MSDP mesh-group %s src cleared",
1278 mg
->mesh_group_name
);
1282 /*********************** MSDP feature APIs *********************************/
1283 int pim_msdp_config_write(struct pim_instance
*pim
, struct vty
*vty
,
1286 struct pim_msdp_mg
*mg
;
1287 struct listnode
*mbrnode
;
1288 struct pim_msdp_mg_mbr
*mbr
;
1289 char src_str
[INET_ADDRSTRLEN
];
1292 if (SLIST_EMPTY(&pim
->msdp
.mglist
))
1295 SLIST_FOREACH (mg
, &pim
->msdp
.mglist
, mg_entry
) {
1296 if (mg
->src_ip
.s_addr
!= INADDR_ANY
) {
1297 pim_inet4_dump("<src?>", mg
->src_ip
, src_str
,
1299 vty_out(vty
, "%sip msdp mesh-group %s source %s\n",
1300 spaces
, mg
->mesh_group_name
, src_str
);
1304 for (ALL_LIST_ELEMENTS_RO(mg
->mbr_list
, mbrnode
, mbr
)) {
1305 vty_out(vty
, "%sip msdp mesh-group %s member %pI4\n",
1306 spaces
, mg
->mesh_group_name
, &mbr
->mbr_ip
);
1314 bool pim_msdp_peer_config_write(struct vty
*vty
, struct pim_instance
*pim
,
1317 struct pim_msdp_peer
*mp
;
1318 struct listnode
*node
;
1319 bool written
= false;
1321 for (ALL_LIST_ELEMENTS_RO(pim
->msdp
.peer_list
, node
, mp
)) {
1322 /* Skip meshed group peers. */
1323 if (mp
->flags
& PIM_MSDP_PEERF_IN_GROUP
)
1326 vty_out(vty
, "%sip msdp peer %pI4 source %pI4\n", spaces
,
1327 &mp
->peer
, &mp
->local
);
1334 /* Enable feature including active/periodic timers etc. on the first peer
1335 * config. Till then MSDP should just stay quiet. */
1336 static void pim_msdp_enable(struct pim_instance
*pim
)
1338 if (pim
->msdp
.flags
& PIM_MSDPF_ENABLE
) {
1339 /* feature is already enabled */
1342 pim
->msdp
.flags
|= PIM_MSDPF_ENABLE
;
1343 pim
->msdp
.work_obuf
= stream_new(PIM_MSDP_MAX_PACKET_SIZE
);
1344 pim_msdp_sa_adv_timer_setup(pim
, true /* start */);
1345 /* setup sa cache based on local sources */
1346 pim_msdp_sa_local_setup(pim
);
1350 void pim_msdp_init(struct pim_instance
*pim
, struct thread_master
*master
)
1352 pim
->msdp
.master
= master
;
1355 snprintf(hash_name
, sizeof(hash_name
), "PIM %s MSDP Peer Hash",
1357 pim
->msdp
.peer_hash
= hash_create(pim_msdp_peer_hash_key_make
,
1358 pim_msdp_peer_hash_eq
, hash_name
);
1359 pim
->msdp
.peer_list
= list_new();
1360 pim
->msdp
.peer_list
->del
= (void (*)(void *))pim_msdp_peer_free
;
1361 pim
->msdp
.peer_list
->cmp
= (int (*)(void *, void *))pim_msdp_peer_comp
;
1363 snprintf(hash_name
, sizeof(hash_name
), "PIM %s MSDP SA Hash",
1365 pim
->msdp
.sa_hash
= hash_create(pim_msdp_sa_hash_key_make
,
1366 pim_msdp_sa_hash_eq
, hash_name
);
1367 pim
->msdp
.sa_list
= list_new();
1368 pim
->msdp
.sa_list
->del
= (void (*)(void *))pim_msdp_sa_free
;
1369 pim
->msdp
.sa_list
->cmp
= (int (*)(void *, void *))pim_msdp_sa_comp
;
1372 /* counterpart to MSDP init; XXX: unused currently */
1373 void pim_msdp_exit(struct pim_instance
*pim
)
1375 struct pim_msdp_mg
*mg
;
1377 pim_msdp_sa_adv_timer_setup(pim
, false);
1379 /* Stop listener and delete all peer sessions */
1380 while ((mg
= SLIST_FIRST(&pim
->msdp
.mglist
)) != NULL
)
1381 pim_msdp_mg_free(pim
, &mg
);
1383 if (pim
->msdp
.peer_hash
) {
1384 hash_clean(pim
->msdp
.peer_hash
, NULL
);
1385 hash_free(pim
->msdp
.peer_hash
);
1386 pim
->msdp
.peer_hash
= NULL
;
1389 if (pim
->msdp
.peer_list
) {
1390 list_delete(&pim
->msdp
.peer_list
);
1393 if (pim
->msdp
.sa_hash
) {
1394 hash_clean(pim
->msdp
.sa_hash
, NULL
);
1395 hash_free(pim
->msdp
.sa_hash
);
1396 pim
->msdp
.sa_hash
= NULL
;
1399 if (pim
->msdp
.sa_list
) {
1400 list_delete(&pim
->msdp
.sa_list
);
1403 if (pim
->msdp
.work_obuf
)
1404 stream_free(pim
->msdp
.work_obuf
);
1405 pim
->msdp
.work_obuf
= NULL
;
1408 void pim_msdp_mg_src_add(struct pim_instance
*pim
, struct pim_msdp_mg
*mg
,
1411 struct pim_msdp_mg_mbr
*mbr
;
1412 struct listnode
*mbr_node
;
1414 /* Stop all connections and remove data structures. */
1415 pim_msdp_src_del(mg
);
1417 /* Set new address. */
1420 /* No new address, disable everyone. */
1421 if (ai
->s_addr
== INADDR_ANY
) {
1422 if (PIM_DEBUG_MSDP_EVENTS
)
1423 zlog_debug("MSDP mesh-group %s src unset",
1424 mg
->mesh_group_name
);
1428 /* Create data structures and start TCP connection. */
1429 for (ALL_LIST_ELEMENTS_RO(mg
->mbr_list
, mbr_node
, mbr
))
1430 mbr
->mp
= pim_msdp_peer_add(pim
, &mbr
->mbr_ip
, &mg
->src_ip
,
1431 mg
->mesh_group_name
);
1433 if (PIM_DEBUG_MSDP_EVENTS
)
1434 zlog_debug("MSDP mesh-group %s src %pI4 set",
1435 mg
->mesh_group_name
, &mg
->src_ip
);
1438 struct pim_msdp_mg_mbr
*pim_msdp_mg_mbr_add(struct pim_instance
*pim
,
1439 struct pim_msdp_mg
*mg
,
1442 struct pim_msdp_mg_mbr
*mbr
;
1444 mbr
= XCALLOC(MTYPE_PIM_MSDP_MG_MBR
, sizeof(*mbr
));
1446 listnode_add_sort(mg
->mbr_list
, mbr
);
1448 /* if valid SIP has been configured add peer session */
1449 if (mg
->src_ip
.s_addr
!= INADDR_ANY
)
1450 mbr
->mp
= pim_msdp_peer_add(pim
, &mbr
->mbr_ip
, &mg
->src_ip
,
1451 mg
->mesh_group_name
);
1453 if (PIM_DEBUG_MSDP_EVENTS
)
1454 zlog_debug("MSDP mesh-group %s mbr %pI4 created",
1455 mg
->mesh_group_name
, &mbr
->mbr_ip
);