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_iface.h"
39 #include "pim_upstream.h"
43 #include "pim_msdp_packet.h"
44 #include "pim_msdp_socket.h"
46 // struct pim_msdp pim_msdp, *msdp = &pim_msdp;
48 static void pim_msdp_peer_listen(struct pim_msdp_peer
*mp
);
49 static void pim_msdp_peer_cr_timer_setup(struct pim_msdp_peer
*mp
, bool start
);
50 static void pim_msdp_peer_ka_timer_setup(struct pim_msdp_peer
*mp
, bool start
);
51 static void pim_msdp_peer_hold_timer_setup(struct pim_msdp_peer
*mp
,
53 static void pim_msdp_peer_free(struct pim_msdp_peer
*mp
);
54 static void pim_msdp_enable(struct pim_instance
*pim
);
55 static void pim_msdp_sa_adv_timer_setup(struct pim_instance
*pim
, bool start
);
56 static void pim_msdp_sa_deref(struct pim_msdp_sa
*sa
,
57 enum pim_msdp_sa_flags flags
);
58 static int pim_msdp_mg_mbr_comp(const void *p1
, const void *p2
);
59 static void pim_msdp_mg_mbr_free(struct pim_msdp_mg_mbr
*mbr
);
61 /************************ SA cache management ******************************/
62 static void pim_msdp_sa_timer_expiry_log(struct pim_msdp_sa
*sa
,
63 const char *timer_str
)
65 zlog_debug("MSDP SA %s %s timer expired", sa
->sg_str
, timer_str
);
68 /* RFC-3618:Sec-5.1 - global active source advertisement timer */
69 static int pim_msdp_sa_adv_timer_cb(struct thread
*t
)
71 struct pim_instance
*pim
= THREAD_ARG(t
);
73 if (PIM_DEBUG_MSDP_EVENTS
) {
74 zlog_debug("MSDP SA advertisement timer expired");
77 pim_msdp_sa_adv_timer_setup(pim
, true /* start */);
78 pim_msdp_pkt_sa_tx(pim
);
81 static void pim_msdp_sa_adv_timer_setup(struct pim_instance
*pim
, bool start
)
83 THREAD_OFF(pim
->msdp
.sa_adv_timer
);
85 thread_add_timer(pim
->msdp
.master
, pim_msdp_sa_adv_timer_cb
,
86 pim
, PIM_MSDP_SA_ADVERTISMENT_TIME
,
87 &pim
->msdp
.sa_adv_timer
);
91 /* RFC-3618:Sec-5.3 - SA cache state timer */
92 static int pim_msdp_sa_state_timer_cb(struct thread
*t
)
94 struct pim_msdp_sa
*sa
;
98 if (PIM_DEBUG_MSDP_EVENTS
) {
99 pim_msdp_sa_timer_expiry_log(sa
, "state");
102 pim_msdp_sa_deref(sa
, PIM_MSDP_SAF_PEER
);
105 static void pim_msdp_sa_state_timer_setup(struct pim_msdp_sa
*sa
, bool start
)
107 THREAD_OFF(sa
->sa_state_timer
);
109 thread_add_timer(sa
->pim
->msdp
.master
,
110 pim_msdp_sa_state_timer_cb
, sa
,
111 PIM_MSDP_SA_HOLD_TIME
, &sa
->sa_state_timer
);
115 static void pim_msdp_sa_upstream_del(struct pim_msdp_sa
*sa
)
117 struct pim_upstream
*up
= sa
->up
;
123 if (PIM_UPSTREAM_FLAG_TEST_SRC_MSDP(up
->flags
)) {
124 PIM_UPSTREAM_FLAG_UNSET_SRC_MSDP(up
->flags
);
125 sa
->flags
|= PIM_MSDP_SAF_UP_DEL_IN_PROG
;
126 up
= pim_upstream_del(sa
->pim
, up
, __func__
);
127 /* re-eval joinDesired; clearing peer-msdp-sa flag can
131 pim_upstream_update_join_desired(sa
->pim
, up
);
132 sa
->flags
&= ~PIM_MSDP_SAF_UP_DEL_IN_PROG
;
135 if (PIM_DEBUG_MSDP_EVENTS
) {
136 zlog_debug("MSDP SA %s de-referenced SPT", sa
->sg_str
);
140 static bool pim_msdp_sa_upstream_add_ok(struct pim_msdp_sa
*sa
,
141 struct pim_upstream
*xg_up
)
143 if (!(sa
->flags
& PIM_MSDP_SAF_PEER
)) {
144 /* SA should have been rxed from a peer */
147 /* check if we are RP */
148 if (!I_am_RP(sa
->pim
, sa
->sg
.grp
)) {
152 /* check if we have a (*, G) with a non-empty immediate OIL */
156 memset(&sg
, 0, sizeof(sg
));
159 xg_up
= pim_upstream_find(sa
->pim
, &sg
);
161 if (!xg_up
|| (xg_up
->join_state
!= PIM_UPSTREAM_JOINED
)) {
162 /* join desired will be true for such (*, G) entries so we will
163 * just look at join_state and let the PIM state machine do the
172 /* Upstream add evaluation needs to happen everytime -
173 * 1. Peer reference is added or removed.
174 * 2. The RP for a group changes.
175 * 3. joinDesired for the associated (*, G) changes
176 * 4. associated (*, G) is removed - this seems like a bit redundant
177 * (considering #4); but just in case an entry gets nuked without
178 * upstream state transition
180 static void pim_msdp_sa_upstream_update(struct pim_msdp_sa
*sa
,
181 struct pim_upstream
*xg_up
,
184 struct pim_upstream
*up
;
186 if (!pim_msdp_sa_upstream_add_ok(sa
, xg_up
)) {
187 pim_msdp_sa_upstream_del(sa
);
196 up
= pim_upstream_find(sa
->pim
, &sa
->sg
);
197 if (up
&& (PIM_UPSTREAM_FLAG_TEST_SRC_MSDP(up
->flags
))) {
198 /* somehow we lost track of the upstream ptr? best log it */
200 if (PIM_DEBUG_MSDP_EVENTS
) {
201 zlog_debug("MSDP SA %s SPT reference missing",
207 /* RFC3618: "RP triggers a (S, G) join event towards the data source
208 * as if a JP message was rxed addressed to the RP itself." */
209 up
= pim_upstream_add(sa
->pim
, &sa
->sg
, NULL
/* iif */,
210 PIM_UPSTREAM_FLAG_MASK_SRC_MSDP
, __func__
, NULL
);
214 /* update inherited oil */
215 pim_upstream_inherited_olist(sa
->pim
, up
);
216 /* should we also start the kat in parallel? we will need it
219 if (PIM_DEBUG_MSDP_EVENTS
) {
220 zlog_debug("MSDP SA %s referenced SPT", sa
->sg_str
);
223 if (PIM_DEBUG_MSDP_EVENTS
) {
224 zlog_debug("MSDP SA %s SPT reference failed",
230 /* release all mem associated with a sa */
231 static void pim_msdp_sa_free(struct pim_msdp_sa
*sa
)
233 pim_msdp_sa_state_timer_setup(sa
, false);
235 XFREE(MTYPE_PIM_MSDP_SA
, sa
);
238 static struct pim_msdp_sa
*pim_msdp_sa_new(struct pim_instance
*pim
,
239 pim_sgaddr
*sg
, struct in_addr rp
)
241 struct pim_msdp_sa
*sa
;
243 sa
= XCALLOC(MTYPE_PIM_MSDP_SA
, sizeof(*sa
));
247 pim_str_sg_set(sg
, sa
->sg_str
);
249 sa
->uptime
= pim_time_monotonic_sec();
251 /* insert into misc tables for easy access */
252 sa
= hash_get(pim
->msdp
.sa_hash
, sa
, hash_alloc_intern
);
253 listnode_add_sort(pim
->msdp
.sa_list
, sa
);
255 if (PIM_DEBUG_MSDP_EVENTS
) {
256 zlog_debug("MSDP SA %s created", sa
->sg_str
);
262 static struct pim_msdp_sa
*pim_msdp_sa_find(struct pim_instance
*pim
,
265 struct pim_msdp_sa lookup
;
268 return hash_lookup(pim
->msdp
.sa_hash
, &lookup
);
271 static struct pim_msdp_sa
*pim_msdp_sa_add(struct pim_instance
*pim
,
272 pim_sgaddr
*sg
, struct in_addr rp
)
274 struct pim_msdp_sa
*sa
;
276 sa
= pim_msdp_sa_find(pim
, sg
);
281 return pim_msdp_sa_new(pim
, sg
, rp
);
284 static void pim_msdp_sa_del(struct pim_msdp_sa
*sa
)
286 /* this is somewhat redundant - still want to be careful not to leave
287 * stale upstream references */
288 pim_msdp_sa_upstream_del(sa
);
291 pim_msdp_sa_state_timer_setup(sa
, false /* start */);
293 /* remove the entry from various tables */
294 listnode_delete(sa
->pim
->msdp
.sa_list
, sa
);
295 hash_release(sa
->pim
->msdp
.sa_hash
, sa
);
297 if (PIM_DEBUG_MSDP_EVENTS
) {
298 zlog_debug("MSDP SA %s deleted", sa
->sg_str
);
301 /* free up any associated memory */
302 pim_msdp_sa_free(sa
);
305 static void pim_msdp_sa_peer_ip_set(struct pim_msdp_sa
*sa
,
306 struct pim_msdp_peer
*mp
, struct in_addr rp
)
308 struct pim_msdp_peer
*old_mp
;
310 /* optimize the "no change" case as it will happen
311 * frequently/periodically */
312 if (mp
&& (sa
->peer
.s_addr
== mp
->peer
.s_addr
)) {
316 /* any time the peer ip changes also update the rp address */
317 if (PIM_INADDR_ISNOT_ANY(sa
->peer
)) {
318 old_mp
= pim_msdp_peer_find(sa
->pim
, sa
->peer
);
319 if (old_mp
&& old_mp
->sa_cnt
) {
328 sa
->peer
.s_addr
= PIM_NET_INADDR_ANY
;
333 /* When a local active-source is removed there is no way to withdraw the
334 * source from peers. We will simply remove it from the SA cache so it will
335 * not be sent in supsequent SA updates. Peers will consequently timeout the
337 * Similarly a "peer-added" SA is never explicitly deleted. It is simply
338 * aged out overtime if not seen in the SA updates from the peers.
339 * XXX: should we provide a knob to drop entries learnt from a peer when the
341 static void pim_msdp_sa_deref(struct pim_msdp_sa
*sa
,
342 enum pim_msdp_sa_flags flags
)
344 bool update_up
= false;
346 if ((sa
->flags
& PIM_MSDP_SAF_LOCAL
)) {
347 if (flags
& PIM_MSDP_SAF_LOCAL
) {
348 if (PIM_DEBUG_MSDP_EVENTS
) {
349 zlog_debug("MSDP SA %s local reference removed",
352 if (sa
->pim
->msdp
.local_cnt
)
353 --sa
->pim
->msdp
.local_cnt
;
357 if ((sa
->flags
& PIM_MSDP_SAF_PEER
)) {
358 if (flags
& PIM_MSDP_SAF_PEER
) {
361 if (PIM_DEBUG_MSDP_EVENTS
) {
362 zlog_debug("MSDP SA %s peer reference removed",
365 pim_msdp_sa_state_timer_setup(sa
, false /* start */);
366 rp
.s_addr
= INADDR_ANY
;
367 pim_msdp_sa_peer_ip_set(sa
, NULL
/* mp */, rp
);
368 /* if peer ref was removed we need to remove the msdp
377 pim_msdp_sa_upstream_update(sa
, NULL
/* xg_up */, "sa-deref");
380 if (!(sa
->flags
& PIM_MSDP_SAF_REF
)) {
385 void pim_msdp_sa_ref(struct pim_instance
*pim
, struct pim_msdp_peer
*mp
,
386 pim_sgaddr
*sg
, struct in_addr rp
)
388 struct pim_msdp_sa
*sa
;
390 sa
= pim_msdp_sa_add(pim
, sg
, rp
);
397 if (!(sa
->flags
& PIM_MSDP_SAF_PEER
)) {
398 sa
->flags
|= PIM_MSDP_SAF_PEER
;
399 if (PIM_DEBUG_MSDP_EVENTS
) {
400 zlog_debug("MSDP SA %s added by peer",
404 pim_msdp_sa_peer_ip_set(sa
, mp
, rp
);
405 /* start/re-start the state timer to prevent cache expiry */
406 pim_msdp_sa_state_timer_setup(sa
, true /* start */);
407 /* We re-evaluate SA "SPT-trigger" everytime we hear abt it from
409 * peer. XXX: If this becomes too much of a periodic overhead we
410 * can make it event based */
411 pim_msdp_sa_upstream_update(sa
, NULL
/* xg_up */, "peer-ref");
413 if (!(sa
->flags
& PIM_MSDP_SAF_LOCAL
)) {
414 sa
->flags
|= PIM_MSDP_SAF_LOCAL
;
415 ++sa
->pim
->msdp
.local_cnt
;
416 if (PIM_DEBUG_MSDP_EVENTS
) {
417 zlog_debug("MSDP SA %s added locally",
420 /* send an immediate SA update to peers */
421 sa
->rp
= pim
->msdp
.originator_id
;
422 pim_msdp_pkt_sa_tx_one(sa
);
424 sa
->flags
&= ~PIM_MSDP_SAF_STALE
;
428 /* The following criteria must be met to originate an SA from the MSDP
430 * 1. KAT must be running i.e. source is active.
431 * 2. We must be RP for the group.
432 * 3. Source must be registrable to the RP (this is where the RFC is vague
433 * and especially ambiguous in CLOS networks; with anycast RP all sources
434 * are potentially registrable to all RPs in the domain). We assume #3 is
436 * a. We are also the FHR-DR for the source (OR)
437 * b. We rxed a pim register (null or data encapsulated) within the last
438 * (3 * (1.5 * register_suppression_timer))).
440 static bool pim_msdp_sa_local_add_ok(struct pim_upstream
*up
)
442 struct pim_instance
*pim
= up
->channel_oil
->pim
;
444 if (!(pim
->msdp
.flags
& PIM_MSDPF_ENABLE
)) {
448 if (!pim_upstream_is_kat_running(up
))
449 /* stream is not active */
452 if (!I_am_RP(pim
, up
->sg
.grp
)) {
453 /* we are not RP for the group */
457 /* we are the FHR-DR for this stream or we are RP and have seen
459 * from a FHR for this source */
460 if (PIM_UPSTREAM_FLAG_TEST_FHR(up
->flags
) || up
->t_msdp_reg_timer
) {
467 static void pim_msdp_sa_local_add(struct pim_instance
*pim
, pim_sgaddr
*sg
)
470 rp
.s_addr
= INADDR_ANY
;
471 pim_msdp_sa_ref(pim
, NULL
/* mp */, sg
, rp
);
474 void pim_msdp_sa_local_del(struct pim_instance
*pim
, pim_sgaddr
*sg
)
476 struct pim_msdp_sa
*sa
;
478 sa
= pim_msdp_sa_find(pim
, sg
);
480 pim_msdp_sa_deref(sa
, PIM_MSDP_SAF_LOCAL
);
484 /* we need to be very cautious with this API as SA del too can trigger an
485 * upstream del and we will get stuck in a simple loop */
486 static void pim_msdp_sa_local_del_on_up_del(struct pim_instance
*pim
,
489 struct pim_msdp_sa
*sa
;
491 sa
= pim_msdp_sa_find(pim
, sg
);
493 if (PIM_DEBUG_MSDP_INTERNAL
) {
494 zlog_debug("MSDP local sa %s del on up del",
498 /* if there is no local reference escape */
499 if (!(sa
->flags
& PIM_MSDP_SAF_LOCAL
)) {
500 if (PIM_DEBUG_MSDP_INTERNAL
) {
501 zlog_debug("MSDP local sa %s del; no local ref",
507 if (sa
->flags
& PIM_MSDP_SAF_UP_DEL_IN_PROG
) {
508 /* MSDP is the one that triggered the upstream del. if
510 * we most certainly have a bug in the PIM upstream
512 * will not have a local reference unless the KAT is
513 * running. And if the
514 * KAT is running there MUST be an additional
515 * source-stream reference to
516 * the flow. Accounting for such cases requires lot of
518 * address this in the next release? - XXX */
521 "MSDP sa %s SPT teardown is causing the local entry to be removed",
526 /* we are dropping the sa on upstream del we should not have an
527 * upstream reference */
529 if (PIM_DEBUG_MSDP_INTERNAL
) {
530 zlog_debug("MSDP local sa %s del; up non-NULL",
535 pim_msdp_sa_deref(sa
, PIM_MSDP_SAF_LOCAL
);
539 /* Local SA qualification needs to be re-evaluated when -
540 * 1. KAT is started or stopped
542 * 3. Whenever FHR status changes for a (S,G) - XXX - currently there
543 * is no clear path to transition an entry out of "MASK_FHR" need
544 * to discuss this with Donald. May result in some strangeness if the
545 * FHR is also the RP.
546 * 4. When msdp_reg timer is started or stopped
548 void pim_msdp_sa_local_update(struct pim_upstream
*up
)
550 struct pim_instance
*pim
= up
->channel_oil
->pim
;
552 if (pim_msdp_sa_local_add_ok(up
)) {
553 pim_msdp_sa_local_add(pim
, &up
->sg
);
555 pim_msdp_sa_local_del(pim
, &up
->sg
);
559 static void pim_msdp_sa_local_setup(struct pim_instance
*pim
)
561 struct pim_upstream
*up
;
563 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
)
564 pim_msdp_sa_local_update(up
);
567 /* whenever the RP changes we need to re-evaluate the "local" SA-cache */
568 /* XXX: needs to be tested */
569 void pim_msdp_i_am_rp_changed(struct pim_instance
*pim
)
571 struct listnode
*sanode
;
572 struct listnode
*nextnode
;
573 struct pim_msdp_sa
*sa
;
575 if (!(pim
->msdp
.flags
& PIM_MSDPF_ENABLE
)) {
576 /* if the feature is not enabled do nothing */
580 if (PIM_DEBUG_MSDP_INTERNAL
) {
581 zlog_debug("MSDP i_am_rp changed");
584 /* mark all local entries as stale */
585 for (ALL_LIST_ELEMENTS_RO(pim
->msdp
.sa_list
, sanode
, sa
)) {
586 if (sa
->flags
& PIM_MSDP_SAF_LOCAL
) {
587 sa
->flags
|= PIM_MSDP_SAF_STALE
;
591 /* re-setup local SA entries */
592 pim_msdp_sa_local_setup(pim
);
594 for (ALL_LIST_ELEMENTS(pim
->msdp
.sa_list
, sanode
, nextnode
, sa
)) {
595 /* purge stale SA entries */
596 if (sa
->flags
& PIM_MSDP_SAF_STALE
) {
597 /* clear the stale flag; the entry may be kept even
600 sa
->flags
&= ~PIM_MSDP_SAF_STALE
;
601 /* sa_deref can end up freeing the sa; so don't access
603 pim_msdp_sa_deref(sa
, PIM_MSDP_SAF_LOCAL
);
605 /* if the souce is still active check if we can
607 pim_msdp_sa_upstream_update(sa
, NULL
/* xg_up */,
613 /* We track the join state of (*, G) entries. If G has sources in the SA-cache
614 * we need to setup or teardown SPT when the JoinDesired status changes for
616 void pim_msdp_up_join_state_changed(struct pim_instance
*pim
,
617 struct pim_upstream
*xg_up
)
619 struct listnode
*sanode
;
620 struct pim_msdp_sa
*sa
;
622 if (PIM_DEBUG_MSDP_INTERNAL
) {
623 zlog_debug("MSDP join state changed for %s", xg_up
->sg_str
);
626 /* If this is not really an XG entry just move on */
627 if ((xg_up
->sg
.src
.s_addr
!= INADDR_ANY
)
628 || (xg_up
->sg
.grp
.s_addr
== INADDR_ANY
)) {
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 (sa
->sg
.grp
.s_addr
!= xg_up
->sg
.grp
.s_addr
) {
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 %s del", pim_str_sg_dump(sg
));
651 /* If this is not really an XG entry just move on */
652 if ((sg
->src
.s_addr
!= INADDR_ANY
) || (sg
->grp
.s_addr
== INADDR_ANY
)) {
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 (sa
->sg
.grp
.s_addr
!= sg
->grp
.s_addr
) {
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 %s del", pim_str_sg_dump(sg
));
671 if (sg
->src
.s_addr
== INADDR_ANY
) {
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 (jhash_2words(sa
->sg
.src
.s_addr
, sa
->sg
.grp
.s_addr
, 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 ((sa1
->sg
.src
.s_addr
== sa2
->sg
.src
.s_addr
)
692 && (sa1
->sg
.grp
.s_addr
== sa2
->sg
.grp
.s_addr
));
695 static int pim_msdp_sa_comp(const void *p1
, const void *p2
)
697 const struct pim_msdp_sa
*sa1
= p1
;
698 const struct pim_msdp_sa
*sa2
= p2
;
700 if (ntohl(sa1
->sg
.grp
.s_addr
) < ntohl(sa2
->sg
.grp
.s_addr
))
703 if (ntohl(sa1
->sg
.grp
.s_addr
) > ntohl(sa2
->sg
.grp
.s_addr
))
706 if (ntohl(sa1
->sg
.src
.s_addr
) < ntohl(sa2
->sg
.src
.s_addr
))
709 if (ntohl(sa1
->sg
.src
.s_addr
) > ntohl(sa2
->sg
.src
.s_addr
))
715 /* RFC-3618:Sec-10.1.3 - Peer-RPF forwarding */
716 /* XXX: this can use a bit of refining and extensions */
717 bool pim_msdp_peer_rpf_check(struct pim_msdp_peer
*mp
, struct in_addr rp
)
719 struct pim_nexthop nexthop
= {0};
721 if (mp
->peer
.s_addr
== rp
.s_addr
) {
725 /* check if the MSDP peer is the nexthop for the RP */
726 if (pim_nexthop_lookup(mp
->pim
, &nexthop
, rp
, 0)
727 && nexthop
.mrib_nexthop_addr
.u
.prefix4
.s_addr
== mp
->peer
.s_addr
) {
734 /************************ Peer session management **************************/
735 char *pim_msdp_state_dump(enum pim_msdp_peer_state state
, char *buf
,
739 case PIM_MSDP_DISABLED
:
740 snprintf(buf
, buf_size
, "%s", "disabled");
742 case PIM_MSDP_INACTIVE
:
743 snprintf(buf
, buf_size
, "%s", "inactive");
745 case PIM_MSDP_LISTEN
:
746 snprintf(buf
, buf_size
, "%s", "listen");
748 case PIM_MSDP_CONNECTING
:
749 snprintf(buf
, buf_size
, "%s", "connecting");
751 case PIM_MSDP_ESTABLISHED
:
752 snprintf(buf
, buf_size
, "%s", "established");
755 snprintf(buf
, buf_size
, "unk-%d", state
);
760 static void pim_msdp_peer_state_chg_log(struct pim_msdp_peer
*mp
)
762 char state_str
[PIM_MSDP_STATE_STRLEN
];
764 pim_msdp_state_dump(mp
->state
, state_str
, sizeof(state_str
));
765 zlog_debug("MSDP peer %s state chg to %s", mp
->key_str
, state_str
);
768 /* MSDP Connection State Machine actions (defined in RFC-3618:Sec-11.2) */
769 /* 11.2.A2: active peer - start connect retry timer; when the timer fires
770 * a tcp connection will be made */
771 static void pim_msdp_peer_connect(struct pim_msdp_peer
*mp
)
773 mp
->state
= PIM_MSDP_CONNECTING
;
774 if (PIM_DEBUG_MSDP_EVENTS
) {
775 pim_msdp_peer_state_chg_log(mp
);
778 pim_msdp_peer_cr_timer_setup(mp
, true /* start */);
781 /* 11.2.A3: passive peer - just listen for connections */
782 static void pim_msdp_peer_listen(struct pim_msdp_peer
*mp
)
784 mp
->state
= PIM_MSDP_LISTEN
;
785 if (PIM_DEBUG_MSDP_EVENTS
) {
786 pim_msdp_peer_state_chg_log(mp
);
789 /* this is interntionally asymmetric i.e. we set up listen-socket when
791 * first listening peer is configured; but don't bother tearing it down
793 * all the peers go down */
794 pim_msdp_sock_listen(mp
->pim
);
797 /* 11.2.A4 and 11.2.A5: transition active or passive peer to
798 * established state */
799 void pim_msdp_peer_established(struct pim_msdp_peer
*mp
)
801 if (mp
->state
!= PIM_MSDP_ESTABLISHED
) {
805 mp
->state
= PIM_MSDP_ESTABLISHED
;
806 mp
->uptime
= pim_time_monotonic_sec();
808 if (PIM_DEBUG_MSDP_EVENTS
) {
809 pim_msdp_peer_state_chg_log(mp
);
812 /* stop retry timer on active peers */
813 pim_msdp_peer_cr_timer_setup(mp
, false /* start */);
815 /* send KA; start KA and hold timers */
816 pim_msdp_pkt_ka_tx(mp
);
817 pim_msdp_peer_ka_timer_setup(mp
, true /* start */);
818 pim_msdp_peer_hold_timer_setup(mp
, true /* start */);
820 pim_msdp_pkt_sa_tx_to_one_peer(mp
);
822 PIM_MSDP_PEER_WRITE_ON(mp
);
823 PIM_MSDP_PEER_READ_ON(mp
);
826 /* 11.2.A6, 11.2.A7 and 11.2.A8: shutdown the peer tcp connection */
827 void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer
*mp
, bool chg_state
)
830 if (mp
->state
== PIM_MSDP_ESTABLISHED
) {
833 mp
->state
= PIM_MSDP_INACTIVE
;
834 if (PIM_DEBUG_MSDP_EVENTS
) {
835 pim_msdp_peer_state_chg_log(mp
);
839 if (PIM_DEBUG_MSDP_INTERNAL
) {
840 zlog_debug("MSDP peer %s pim_msdp_peer_stop_tcp_conn",
843 /* stop read and write threads */
844 PIM_MSDP_PEER_READ_OFF(mp
);
845 PIM_MSDP_PEER_WRITE_OFF(mp
);
850 stream_reset(mp
->ibuf
);
852 stream_fifo_clean(mp
->obuf
);
854 /* stop all peer timers */
855 pim_msdp_peer_ka_timer_setup(mp
, false /* start */);
856 pim_msdp_peer_cr_timer_setup(mp
, false /* start */);
857 pim_msdp_peer_hold_timer_setup(mp
, false /* start */);
859 /* close connection */
866 /* RFC-3618:Sec-5.6 - stop the peer tcp connection and startover */
867 void pim_msdp_peer_reset_tcp_conn(struct pim_msdp_peer
*mp
, const char *rc_str
)
869 if (PIM_DEBUG_EVENTS
) {
870 zlog_debug("MSDP peer %s tcp reset %s", mp
->key_str
, rc_str
);
871 snprintf(mp
->last_reset
, sizeof(mp
->last_reset
), "%s", rc_str
);
874 /* close the connection and transition to listening or connecting */
875 pim_msdp_peer_stop_tcp_conn(mp
, true /* chg_state */);
876 if (PIM_MSDP_PEER_IS_LISTENER(mp
)) {
877 pim_msdp_peer_listen(mp
);
879 pim_msdp_peer_connect(mp
);
883 static void pim_msdp_peer_timer_expiry_log(struct pim_msdp_peer
*mp
,
884 const char *timer_str
)
886 zlog_debug("MSDP peer %s %s timer expired", mp
->key_str
, timer_str
);
889 /* RFC-3618:Sec-5.4 - peer hold timer */
890 static int pim_msdp_peer_hold_timer_cb(struct thread
*t
)
892 struct pim_msdp_peer
*mp
;
896 if (PIM_DEBUG_MSDP_EVENTS
) {
897 pim_msdp_peer_timer_expiry_log(mp
, "hold");
900 if (mp
->state
!= PIM_MSDP_ESTABLISHED
) {
904 if (PIM_DEBUG_MSDP_EVENTS
) {
905 pim_msdp_peer_state_chg_log(mp
);
907 pim_msdp_peer_reset_tcp_conn(mp
, "ht-expired");
911 static void pim_msdp_peer_hold_timer_setup(struct pim_msdp_peer
*mp
, bool start
)
913 struct pim_instance
*pim
= mp
->pim
;
914 THREAD_OFF(mp
->hold_timer
);
916 thread_add_timer(pim
->msdp
.master
, pim_msdp_peer_hold_timer_cb
,
917 mp
, pim
->msdp
.hold_time
, &mp
->hold_timer
);
922 /* RFC-3618:Sec-5.5 - peer keepalive timer */
923 static int pim_msdp_peer_ka_timer_cb(struct thread
*t
)
925 struct pim_msdp_peer
*mp
;
929 if (PIM_DEBUG_MSDP_EVENTS
) {
930 pim_msdp_peer_timer_expiry_log(mp
, "ka");
933 pim_msdp_pkt_ka_tx(mp
);
934 pim_msdp_peer_ka_timer_setup(mp
, true /* start */);
937 static void pim_msdp_peer_ka_timer_setup(struct pim_msdp_peer
*mp
, bool start
)
939 THREAD_OFF(mp
->ka_timer
);
941 thread_add_timer(mp
->pim
->msdp
.master
,
942 pim_msdp_peer_ka_timer_cb
, mp
,
943 mp
->pim
->msdp
.keep_alive
, &mp
->ka_timer
);
947 static void pim_msdp_peer_active_connect(struct pim_msdp_peer
*mp
)
951 rc
= pim_msdp_sock_connect(mp
);
953 if (PIM_DEBUG_MSDP_INTERNAL
) {
954 zlog_debug("MSDP peer %s pim_msdp_peer_active_connect: %d",
961 /* connect failed restart the connect-retry timer */
962 pim_msdp_peer_cr_timer_setup(mp
, true /* start */);
965 case connect_success
:
966 /* connect was sucessful move to established */
967 pim_msdp_peer_established(mp
);
970 case connect_in_progress
:
971 /* for NB content we need to wait till sock is readable or
973 PIM_MSDP_PEER_WRITE_ON(mp
);
974 PIM_MSDP_PEER_READ_ON(mp
);
975 /* also restart connect-retry timer to reset the socket if
978 pim_msdp_peer_cr_timer_setup(mp
, true /* start */);
983 /* RFC-3618:Sec-5.6 - connection retry on active peer */
984 static int pim_msdp_peer_cr_timer_cb(struct thread
*t
)
986 struct pim_msdp_peer
*mp
;
990 if (PIM_DEBUG_MSDP_EVENTS
) {
991 pim_msdp_peer_timer_expiry_log(mp
, "connect-retry");
994 if (mp
->state
!= PIM_MSDP_CONNECTING
|| PIM_MSDP_PEER_IS_LISTENER(mp
)) {
998 pim_msdp_peer_active_connect(mp
);
1001 static void pim_msdp_peer_cr_timer_setup(struct pim_msdp_peer
*mp
, bool start
)
1003 THREAD_OFF(mp
->cr_timer
);
1005 thread_add_timer(mp
->pim
->msdp
.master
,
1006 pim_msdp_peer_cr_timer_cb
, mp
,
1007 mp
->pim
->msdp
.connection_retry
, &mp
->cr_timer
);
1011 /* if a valid packet is rxed from the peer we can restart hold timer */
1012 void pim_msdp_peer_pkt_rxed(struct pim_msdp_peer
*mp
)
1014 if (mp
->state
== PIM_MSDP_ESTABLISHED
) {
1015 pim_msdp_peer_hold_timer_setup(mp
, true /* start */);
1019 /* if a valid packet is txed to the peer we can restart ka timer and avoid
1020 * unnecessary ka noise in the network */
1021 void pim_msdp_peer_pkt_txed(struct pim_msdp_peer
*mp
)
1023 if (mp
->state
== PIM_MSDP_ESTABLISHED
) {
1024 pim_msdp_peer_ka_timer_setup(mp
, true /* start */);
1025 if (PIM_DEBUG_MSDP_INTERNAL
) {
1026 zlog_debug("MSDP ka timer restart on pkt tx to %s",
1032 static void pim_msdp_addr2su(union sockunion
*su
, struct in_addr addr
)
1035 su
->sin
.sin_addr
= addr
;
1036 su
->sin
.sin_family
= AF_INET
;
1037 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
1038 su
->sin
.sin_len
= sizeof(struct sockaddr_in
);
1039 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
1042 /* 11.2.A1: create a new peer and transition state to listen or connecting */
1043 struct pim_msdp_peer
*pim_msdp_peer_add(struct pim_instance
*pim
,
1044 const struct in_addr
*peer
,
1045 const struct in_addr
*local
,
1046 const char *mesh_group_name
)
1048 struct pim_msdp_peer
*mp
;
1050 pim_msdp_enable(pim
);
1052 mp
= XCALLOC(MTYPE_PIM_MSDP_PEER
, sizeof(*mp
));
1056 pim_inet4_dump("<peer?>", mp
->peer
, mp
->key_str
, sizeof(mp
->key_str
));
1057 pim_msdp_addr2su(&mp
->su_peer
, mp
->peer
);
1059 /* XXX: originator_id setting needs to move to the mesh group */
1060 pim
->msdp
.originator_id
= *local
;
1061 pim_msdp_addr2su(&mp
->su_local
, mp
->local
);
1062 if (mesh_group_name
)
1063 mp
->mesh_group_name
=
1064 XSTRDUP(MTYPE_PIM_MSDP_MG_NAME
, mesh_group_name
);
1066 mp
->state
= PIM_MSDP_INACTIVE
;
1068 strlcpy(mp
->last_reset
, "-", sizeof(mp
->last_reset
));
1069 /* higher IP address is listener */
1070 if (ntohl(mp
->local
.s_addr
) > ntohl(mp
->peer
.s_addr
)) {
1071 mp
->flags
|= PIM_MSDP_PEERF_LISTENER
;
1074 /* setup packet buffers */
1075 mp
->ibuf
= stream_new(PIM_MSDP_MAX_PACKET_SIZE
);
1076 mp
->obuf
= stream_fifo_new();
1078 /* insert into misc tables for easy access */
1079 mp
= hash_get(pim
->msdp
.peer_hash
, mp
, hash_alloc_intern
);
1080 listnode_add_sort(pim
->msdp
.peer_list
, mp
);
1082 if (PIM_DEBUG_MSDP_EVENTS
) {
1083 zlog_debug("MSDP peer %s created", mp
->key_str
);
1085 pim_msdp_peer_state_chg_log(mp
);
1088 /* fireup the connect state machine */
1089 if (PIM_MSDP_PEER_IS_LISTENER(mp
)) {
1090 pim_msdp_peer_listen(mp
);
1092 pim_msdp_peer_connect(mp
);
1097 struct pim_msdp_peer
*pim_msdp_peer_find(struct pim_instance
*pim
,
1098 struct in_addr peer_addr
)
1100 struct pim_msdp_peer lookup
;
1102 lookup
.peer
= peer_addr
;
1103 return hash_lookup(pim
->msdp
.peer_hash
, &lookup
);
1106 /* release all mem associated with a peer */
1107 static void pim_msdp_peer_free(struct pim_msdp_peer
*mp
)
1110 * Let's make sure we are not running when we delete
1111 * the underlying data structure
1113 pim_msdp_peer_stop_tcp_conn(mp
, false);
1116 stream_free(mp
->ibuf
);
1120 stream_fifo_free(mp
->obuf
);
1123 XFREE(MTYPE_PIM_MSDP_MG_NAME
, mp
->mesh_group_name
);
1126 XFREE(MTYPE_PIM_MSDP_PEER
, mp
);
1129 /* delete the peer config */
1130 void pim_msdp_peer_del(struct pim_msdp_peer
**mp
)
1135 /* stop the tcp connection and shutdown all timers */
1136 pim_msdp_peer_stop_tcp_conn(*mp
, true /* chg_state */);
1138 /* remove the session from various tables */
1139 listnode_delete((*mp
)->pim
->msdp
.peer_list
, *mp
);
1140 hash_release((*mp
)->pim
->msdp
.peer_hash
, *mp
);
1142 if (PIM_DEBUG_MSDP_EVENTS
) {
1143 zlog_debug("MSDP peer %s deleted", (*mp
)->key_str
);
1146 /* free up any associated memory */
1147 pim_msdp_peer_free(*mp
);
1151 void pim_msdp_peer_change_source(struct pim_msdp_peer
*mp
,
1152 const struct in_addr
*addr
)
1154 pim_msdp_peer_stop_tcp_conn(mp
, true);
1158 if (PIM_MSDP_PEER_IS_LISTENER(mp
))
1159 pim_msdp_peer_listen(mp
);
1161 pim_msdp_peer_connect(mp
);
1164 /* peer hash and peer list helpers */
1165 static unsigned int pim_msdp_peer_hash_key_make(const void *p
)
1167 const struct pim_msdp_peer
*mp
= p
;
1168 return (jhash_1word(mp
->peer
.s_addr
, 0));
1171 static bool pim_msdp_peer_hash_eq(const void *p1
, const void *p2
)
1173 const struct pim_msdp_peer
*mp1
= p1
;
1174 const struct pim_msdp_peer
*mp2
= p2
;
1176 return (mp1
->peer
.s_addr
== mp2
->peer
.s_addr
);
1179 static int pim_msdp_peer_comp(const void *p1
, const void *p2
)
1181 const struct pim_msdp_peer
*mp1
= p1
;
1182 const struct pim_msdp_peer
*mp2
= p2
;
1184 if (ntohl(mp1
->peer
.s_addr
) < ntohl(mp2
->peer
.s_addr
))
1187 if (ntohl(mp1
->peer
.s_addr
) > ntohl(mp2
->peer
.s_addr
))
1193 /************************** Mesh group management **************************/
1194 void pim_msdp_mg_free(struct pim_instance
*pim
, struct pim_msdp_mg
**mgp
)
1196 struct pim_msdp_mg_mbr
*mbr
;
1197 struct listnode
*n
, *nn
;
1202 /* SIP is being removed - tear down all active peer sessions */
1203 for (ALL_LIST_ELEMENTS((*mgp
)->mbr_list
, n
, nn
, mbr
))
1204 pim_msdp_mg_mbr_del((*mgp
), mbr
);
1206 if (PIM_DEBUG_MSDP_EVENTS
) {
1207 zlog_debug("MSDP mesh-group %s deleted",
1208 (*mgp
)->mesh_group_name
);
1211 XFREE(MTYPE_PIM_MSDP_MG_NAME
, (*mgp
)->mesh_group_name
);
1213 if ((*mgp
)->mbr_list
)
1214 list_delete(&(*mgp
)->mbr_list
);
1216 SLIST_REMOVE(&pim
->msdp
.mglist
, (*mgp
), pim_msdp_mg
, mg_entry
);
1217 XFREE(MTYPE_PIM_MSDP_MG
, (*mgp
));
1220 struct pim_msdp_mg
*pim_msdp_mg_new(struct pim_instance
*pim
,
1221 const char *mesh_group_name
)
1223 struct pim_msdp_mg
*mg
;
1225 mg
= XCALLOC(MTYPE_PIM_MSDP_MG
, sizeof(*mg
));
1227 mg
->mesh_group_name
= XSTRDUP(MTYPE_PIM_MSDP_MG_NAME
, mesh_group_name
);
1228 mg
->mbr_list
= list_new();
1229 mg
->mbr_list
->del
= (void (*)(void *))pim_msdp_mg_mbr_free
;
1230 mg
->mbr_list
->cmp
= (int (*)(void *, void *))pim_msdp_mg_mbr_comp
;
1232 if (PIM_DEBUG_MSDP_EVENTS
) {
1233 zlog_debug("MSDP mesh-group %s created", mg
->mesh_group_name
);
1236 SLIST_INSERT_HEAD(&pim
->msdp
.mglist
, mg
, mg_entry
);
1241 static int pim_msdp_mg_mbr_comp(const void *p1
, const void *p2
)
1243 const struct pim_msdp_mg_mbr
*mbr1
= p1
;
1244 const struct pim_msdp_mg_mbr
*mbr2
= p2
;
1246 if (ntohl(mbr1
->mbr_ip
.s_addr
) < ntohl(mbr2
->mbr_ip
.s_addr
))
1249 if (ntohl(mbr1
->mbr_ip
.s_addr
) > ntohl(mbr2
->mbr_ip
.s_addr
))
1255 static void pim_msdp_mg_mbr_free(struct pim_msdp_mg_mbr
*mbr
)
1257 XFREE(MTYPE_PIM_MSDP_MG_MBR
, mbr
);
1260 void pim_msdp_mg_mbr_del(struct pim_msdp_mg
*mg
, struct pim_msdp_mg_mbr
*mbr
)
1262 /* Delete active peer session if any */
1264 pim_msdp_peer_del(&mbr
->mp
);
1267 listnode_delete(mg
->mbr_list
, mbr
);
1268 if (PIM_DEBUG_MSDP_EVENTS
) {
1269 char ip_str
[INET_ADDRSTRLEN
];
1270 pim_inet4_dump("<mbr?>", mbr
->mbr_ip
, ip_str
, sizeof(ip_str
));
1271 zlog_debug("MSDP mesh-group %s mbr %s deleted",
1272 mg
->mesh_group_name
, ip_str
);
1274 pim_msdp_mg_mbr_free(mbr
);
1280 static void pim_msdp_src_del(struct pim_msdp_mg
*mg
)
1282 struct pim_msdp_mg_mbr
*mbr
;
1283 struct listnode
*mbr_node
;
1285 /* SIP is being removed - tear down all active peer sessions */
1286 for (ALL_LIST_ELEMENTS_RO(mg
->mbr_list
, mbr_node
, mbr
)) {
1288 pim_msdp_peer_del(&mbr
->mp
);
1290 if (PIM_DEBUG_MSDP_EVENTS
) {
1291 zlog_debug("MSDP mesh-group %s src cleared",
1292 mg
->mesh_group_name
);
1296 /*********************** MSDP feature APIs *********************************/
1297 int pim_msdp_config_write(struct pim_instance
*pim
, struct vty
*vty
,
1300 struct pim_msdp_mg
*mg
;
1301 struct listnode
*mbrnode
;
1302 struct pim_msdp_mg_mbr
*mbr
;
1303 char src_str
[INET_ADDRSTRLEN
];
1306 if (SLIST_EMPTY(&pim
->msdp
.mglist
))
1309 SLIST_FOREACH (mg
, &pim
->msdp
.mglist
, mg_entry
) {
1310 if (mg
->src_ip
.s_addr
!= INADDR_ANY
) {
1311 pim_inet4_dump("<src?>", mg
->src_ip
, src_str
,
1313 vty_out(vty
, "%sip msdp mesh-group %s source %s\n",
1314 spaces
, mg
->mesh_group_name
, src_str
);
1318 for (ALL_LIST_ELEMENTS_RO(mg
->mbr_list
, mbrnode
, mbr
)) {
1319 vty_out(vty
, "%sip msdp mesh-group %s member %pI4\n",
1320 spaces
, mg
->mesh_group_name
, &mbr
->mbr_ip
);
1328 bool pim_msdp_peer_config_write(struct vty
*vty
, struct pim_instance
*pim
,
1331 struct pim_msdp_peer
*mp
;
1332 struct listnode
*node
;
1333 bool written
= false;
1335 for (ALL_LIST_ELEMENTS_RO(pim
->msdp
.peer_list
, node
, mp
)) {
1336 /* Skip meshed group peers. */
1337 if (mp
->flags
& PIM_MSDP_PEERF_IN_GROUP
)
1340 vty_out(vty
, "%sip msdp peer %pI4 source %pI4\n", spaces
,
1341 &mp
->peer
, &mp
->local
);
1348 /* Enable feature including active/periodic timers etc. on the first peer
1349 * config. Till then MSDP should just stay quiet. */
1350 static void pim_msdp_enable(struct pim_instance
*pim
)
1352 if (pim
->msdp
.flags
& PIM_MSDPF_ENABLE
) {
1353 /* feature is already enabled */
1356 pim
->msdp
.flags
|= PIM_MSDPF_ENABLE
;
1357 pim
->msdp
.work_obuf
= stream_new(PIM_MSDP_MAX_PACKET_SIZE
);
1358 pim_msdp_sa_adv_timer_setup(pim
, true /* start */);
1359 /* setup sa cache based on local sources */
1360 pim_msdp_sa_local_setup(pim
);
1364 void pim_msdp_init(struct pim_instance
*pim
, struct thread_master
*master
)
1366 pim
->msdp
.master
= master
;
1369 snprintf(hash_name
, sizeof(hash_name
), "PIM %s MSDP Peer Hash",
1371 pim
->msdp
.peer_hash
= hash_create(pim_msdp_peer_hash_key_make
,
1372 pim_msdp_peer_hash_eq
, hash_name
);
1373 pim
->msdp
.peer_list
= list_new();
1374 pim
->msdp
.peer_list
->del
= (void (*)(void *))pim_msdp_peer_free
;
1375 pim
->msdp
.peer_list
->cmp
= (int (*)(void *, void *))pim_msdp_peer_comp
;
1377 snprintf(hash_name
, sizeof(hash_name
), "PIM %s MSDP SA Hash",
1379 pim
->msdp
.sa_hash
= hash_create(pim_msdp_sa_hash_key_make
,
1380 pim_msdp_sa_hash_eq
, hash_name
);
1381 pim
->msdp
.sa_list
= list_new();
1382 pim
->msdp
.sa_list
->del
= (void (*)(void *))pim_msdp_sa_free
;
1383 pim
->msdp
.sa_list
->cmp
= (int (*)(void *, void *))pim_msdp_sa_comp
;
1386 /* counterpart to MSDP init; XXX: unused currently */
1387 void pim_msdp_exit(struct pim_instance
*pim
)
1389 struct pim_msdp_mg
*mg
;
1391 pim_msdp_sa_adv_timer_setup(pim
, false);
1393 /* Stop listener and delete all peer sessions */
1394 while ((mg
= SLIST_FIRST(&pim
->msdp
.mglist
)) != NULL
)
1395 pim_msdp_mg_free(pim
, &mg
);
1397 if (pim
->msdp
.peer_hash
) {
1398 hash_clean(pim
->msdp
.peer_hash
, NULL
);
1399 hash_free(pim
->msdp
.peer_hash
);
1400 pim
->msdp
.peer_hash
= NULL
;
1403 if (pim
->msdp
.peer_list
) {
1404 list_delete(&pim
->msdp
.peer_list
);
1407 if (pim
->msdp
.sa_hash
) {
1408 hash_clean(pim
->msdp
.sa_hash
, NULL
);
1409 hash_free(pim
->msdp
.sa_hash
);
1410 pim
->msdp
.sa_hash
= NULL
;
1413 if (pim
->msdp
.sa_list
) {
1414 list_delete(&pim
->msdp
.sa_list
);
1417 if (pim
->msdp
.work_obuf
)
1418 stream_free(pim
->msdp
.work_obuf
);
1419 pim
->msdp
.work_obuf
= NULL
;
1422 void pim_msdp_mg_src_add(struct pim_instance
*pim
, struct pim_msdp_mg
*mg
,
1425 struct pim_msdp_mg_mbr
*mbr
;
1426 struct listnode
*mbr_node
;
1428 /* Stop all connections and remove data structures. */
1429 pim_msdp_src_del(mg
);
1431 /* Set new address. */
1434 /* No new address, disable everyone. */
1435 if (ai
->s_addr
== INADDR_ANY
) {
1436 if (PIM_DEBUG_MSDP_EVENTS
)
1437 zlog_debug("MSDP mesh-group %s src unset",
1438 mg
->mesh_group_name
);
1442 /* Create data structures and start TCP connection. */
1443 for (ALL_LIST_ELEMENTS_RO(mg
->mbr_list
, mbr_node
, mbr
))
1444 mbr
->mp
= pim_msdp_peer_add(pim
, &mbr
->mbr_ip
, &mg
->src_ip
,
1445 mg
->mesh_group_name
);
1447 if (PIM_DEBUG_MSDP_EVENTS
)
1448 zlog_debug("MSDP mesh-group %s src %pI4 set",
1449 mg
->mesh_group_name
, &mg
->src_ip
);
1452 struct pim_msdp_mg_mbr
*pim_msdp_mg_mbr_add(struct pim_instance
*pim
,
1453 struct pim_msdp_mg
*mg
,
1456 struct pim_msdp_mg_mbr
*mbr
;
1458 mbr
= XCALLOC(MTYPE_PIM_MSDP_MG_MBR
, sizeof(*mbr
));
1460 listnode_add_sort(mg
->mbr_list
, mbr
);
1462 /* if valid SIP has been configured add peer session */
1463 if (mg
->src_ip
.s_addr
!= INADDR_ANY
)
1464 mbr
->mp
= pim_msdp_peer_add(pim
, &mbr
->mbr_ip
, &mg
->src_ip
,
1465 mg
->mesh_group_name
);
1467 if (PIM_DEBUG_MSDP_EVENTS
)
1468 zlog_debug("MSDP mesh-group %s mbr %pI4 created",
1469 mg
->mesh_group_name
, &mbr
->mbr_ip
);