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>
35 #include "pim_memory.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 int 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 int 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 struct prefix_sg
*sg
,
243 struct pim_msdp_sa
*sa
;
245 sa
= XCALLOC(MTYPE_PIM_MSDP_SA
, sizeof(*sa
));
249 pim_str_sg_set(sg
, sa
->sg_str
);
251 sa
->uptime
= pim_time_monotonic_sec();
253 /* insert into misc tables for easy access */
254 sa
= hash_get(pim
->msdp
.sa_hash
, sa
, hash_alloc_intern
);
255 listnode_add_sort(pim
->msdp
.sa_list
, sa
);
257 if (PIM_DEBUG_MSDP_EVENTS
) {
258 zlog_debug("MSDP SA %s created", sa
->sg_str
);
264 static struct pim_msdp_sa
*pim_msdp_sa_find(struct pim_instance
*pim
,
265 struct prefix_sg
*sg
)
267 struct pim_msdp_sa lookup
;
270 return hash_lookup(pim
->msdp
.sa_hash
, &lookup
);
273 static struct pim_msdp_sa
*pim_msdp_sa_add(struct pim_instance
*pim
,
274 struct prefix_sg
*sg
,
277 struct pim_msdp_sa
*sa
;
279 sa
= pim_msdp_sa_find(pim
, sg
);
284 return pim_msdp_sa_new(pim
, sg
, rp
);
287 static void pim_msdp_sa_del(struct pim_msdp_sa
*sa
)
289 /* this is somewhat redundant - still want to be careful not to leave
290 * stale upstream references */
291 pim_msdp_sa_upstream_del(sa
);
294 pim_msdp_sa_state_timer_setup(sa
, false /* start */);
296 /* remove the entry from various tables */
297 listnode_delete(sa
->pim
->msdp
.sa_list
, sa
);
298 hash_release(sa
->pim
->msdp
.sa_hash
, sa
);
300 if (PIM_DEBUG_MSDP_EVENTS
) {
301 zlog_debug("MSDP SA %s deleted", sa
->sg_str
);
304 /* free up any associated memory */
305 pim_msdp_sa_free(sa
);
308 static void pim_msdp_sa_peer_ip_set(struct pim_msdp_sa
*sa
,
309 struct pim_msdp_peer
*mp
, struct in_addr rp
)
311 struct pim_msdp_peer
*old_mp
;
313 /* optimize the "no change" case as it will happen
314 * frequently/periodically */
315 if (mp
&& (sa
->peer
.s_addr
== mp
->peer
.s_addr
)) {
319 /* any time the peer ip changes also update the rp address */
320 if (PIM_INADDR_ISNOT_ANY(sa
->peer
)) {
321 old_mp
= pim_msdp_peer_find(sa
->pim
, sa
->peer
);
322 if (old_mp
&& old_mp
->sa_cnt
) {
331 sa
->peer
.s_addr
= PIM_NET_INADDR_ANY
;
336 /* When a local active-source is removed there is no way to withdraw the
337 * source from peers. We will simply remove it from the SA cache so it will
338 * not be sent in supsequent SA updates. Peers will consequently timeout the
340 * Similarly a "peer-added" SA is never explicitly deleted. It is simply
341 * aged out overtime if not seen in the SA updates from the peers.
342 * XXX: should we provide a knob to drop entries learnt from a peer when the
344 static void pim_msdp_sa_deref(struct pim_msdp_sa
*sa
,
345 enum pim_msdp_sa_flags flags
)
347 bool update_up
= false;
349 if ((sa
->flags
& PIM_MSDP_SAF_LOCAL
)) {
350 if (flags
& PIM_MSDP_SAF_LOCAL
) {
351 if (PIM_DEBUG_MSDP_EVENTS
) {
352 zlog_debug("MSDP SA %s local reference removed",
355 if (sa
->pim
->msdp
.local_cnt
)
356 --sa
->pim
->msdp
.local_cnt
;
360 if ((sa
->flags
& PIM_MSDP_SAF_PEER
)) {
361 if (flags
& PIM_MSDP_SAF_PEER
) {
364 if (PIM_DEBUG_MSDP_EVENTS
) {
365 zlog_debug("MSDP SA %s peer reference removed",
368 pim_msdp_sa_state_timer_setup(sa
, false /* start */);
369 rp
.s_addr
= INADDR_ANY
;
370 pim_msdp_sa_peer_ip_set(sa
, NULL
/* mp */, rp
);
371 /* if peer ref was removed we need to remove the msdp
380 pim_msdp_sa_upstream_update(sa
, NULL
/* xg_up */, "sa-deref");
383 if (!(sa
->flags
& PIM_MSDP_SAF_REF
)) {
388 void pim_msdp_sa_ref(struct pim_instance
*pim
, struct pim_msdp_peer
*mp
,
389 struct prefix_sg
*sg
, struct in_addr rp
)
391 struct pim_msdp_sa
*sa
;
393 sa
= pim_msdp_sa_add(pim
, sg
, rp
);
400 if (!(sa
->flags
& PIM_MSDP_SAF_PEER
)) {
401 sa
->flags
|= PIM_MSDP_SAF_PEER
;
402 if (PIM_DEBUG_MSDP_EVENTS
) {
403 zlog_debug("MSDP SA %s added by peer",
407 pim_msdp_sa_peer_ip_set(sa
, mp
, rp
);
408 /* start/re-start the state timer to prevent cache expiry */
409 pim_msdp_sa_state_timer_setup(sa
, true /* start */);
410 /* We re-evaluate SA "SPT-trigger" everytime we hear abt it from
412 * peer. XXX: If this becomes too much of a periodic overhead we
413 * can make it event based */
414 pim_msdp_sa_upstream_update(sa
, NULL
/* xg_up */, "peer-ref");
416 if (!(sa
->flags
& PIM_MSDP_SAF_LOCAL
)) {
417 sa
->flags
|= PIM_MSDP_SAF_LOCAL
;
418 ++sa
->pim
->msdp
.local_cnt
;
419 if (PIM_DEBUG_MSDP_EVENTS
) {
420 zlog_debug("MSDP SA %s added locally",
423 /* send an immediate SA update to peers */
424 sa
->rp
= pim
->msdp
.originator_id
;
425 pim_msdp_pkt_sa_tx_one(sa
);
427 sa
->flags
&= ~PIM_MSDP_SAF_STALE
;
431 /* The following criteria must be met to originate an SA from the MSDP
433 * 1. KAT must be running i.e. source is active.
434 * 2. We must be RP for the group.
435 * 3. Source must be registrable to the RP (this is where the RFC is vague
436 * and especially ambiguous in CLOS networks; with anycast RP all sources
437 * are potentially registrable to all RPs in the domain). We assume #3 is
439 * a. We are also the FHR-DR for the source (OR)
440 * b. We rxed a pim register (null or data encapsulated) within the last
441 * (3 * (1.5 * register_suppression_timer))).
443 static bool pim_msdp_sa_local_add_ok(struct pim_upstream
*up
)
445 struct pim_instance
*pim
= up
->channel_oil
->pim
;
447 if (!(pim
->msdp
.flags
& PIM_MSDPF_ENABLE
)) {
451 if (!pim_upstream_is_kat_running(up
))
452 /* stream is not active */
455 if (!I_am_RP(pim
, up
->sg
.grp
)) {
456 /* we are not RP for the group */
460 /* we are the FHR-DR for this stream or we are RP and have seen
462 * from a FHR for this source */
463 if (PIM_UPSTREAM_FLAG_TEST_FHR(up
->flags
) || up
->t_msdp_reg_timer
) {
470 static void pim_msdp_sa_local_add(struct pim_instance
*pim
,
471 struct prefix_sg
*sg
)
474 rp
.s_addr
= INADDR_ANY
;
475 pim_msdp_sa_ref(pim
, NULL
/* mp */, sg
, rp
);
478 void pim_msdp_sa_local_del(struct pim_instance
*pim
, struct prefix_sg
*sg
)
480 struct pim_msdp_sa
*sa
;
482 sa
= pim_msdp_sa_find(pim
, sg
);
484 pim_msdp_sa_deref(sa
, PIM_MSDP_SAF_LOCAL
);
488 /* we need to be very cautious with this API as SA del too can trigger an
489 * upstream del and we will get stuck in a simple loop */
490 static void pim_msdp_sa_local_del_on_up_del(struct pim_instance
*pim
,
491 struct prefix_sg
*sg
)
493 struct pim_msdp_sa
*sa
;
495 sa
= pim_msdp_sa_find(pim
, sg
);
497 if (PIM_DEBUG_MSDP_INTERNAL
) {
498 zlog_debug("MSDP local sa %s del on up del",
502 /* if there is no local reference escape */
503 if (!(sa
->flags
& PIM_MSDP_SAF_LOCAL
)) {
504 if (PIM_DEBUG_MSDP_INTERNAL
) {
505 zlog_debug("MSDP local sa %s del; no local ref",
511 if (sa
->flags
& PIM_MSDP_SAF_UP_DEL_IN_PROG
) {
512 /* MSDP is the one that triggered the upstream del. if
514 * we most certainly have a bug in the PIM upstream
516 * will not have a local reference unless the KAT is
517 * running. And if the
518 * KAT is running there MUST be an additional
519 * source-stream reference to
520 * the flow. Accounting for such cases requires lot of
522 * address this in the next release? - XXX */
525 "MSDP sa %s SPT teardown is causing the local entry to be removed",
530 /* we are dropping the sa on upstream del we should not have an
531 * upstream reference */
533 if (PIM_DEBUG_MSDP_INTERNAL
) {
534 zlog_debug("MSDP local sa %s del; up non-NULL",
539 pim_msdp_sa_deref(sa
, PIM_MSDP_SAF_LOCAL
);
543 /* Local SA qualification needs to be re-evaluated when -
544 * 1. KAT is started or stopped
546 * 3. Whenever FHR status changes for a (S,G) - XXX - currently there
547 * is no clear path to transition an entry out of "MASK_FHR" need
548 * to discuss this with Donald. May result in some strangeness if the
549 * FHR is also the RP.
550 * 4. When msdp_reg timer is started or stopped
552 void pim_msdp_sa_local_update(struct pim_upstream
*up
)
554 struct pim_instance
*pim
= up
->channel_oil
->pim
;
556 if (pim_msdp_sa_local_add_ok(up
)) {
557 pim_msdp_sa_local_add(pim
, &up
->sg
);
559 pim_msdp_sa_local_del(pim
, &up
->sg
);
563 static void pim_msdp_sa_local_setup(struct pim_instance
*pim
)
565 struct pim_upstream
*up
;
567 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
)
568 pim_msdp_sa_local_update(up
);
571 /* whenever the RP changes we need to re-evaluate the "local" SA-cache */
572 /* XXX: needs to be tested */
573 void pim_msdp_i_am_rp_changed(struct pim_instance
*pim
)
575 struct listnode
*sanode
;
576 struct listnode
*nextnode
;
577 struct pim_msdp_sa
*sa
;
579 if (!(pim
->msdp
.flags
& PIM_MSDPF_ENABLE
)) {
580 /* if the feature is not enabled do nothing */
584 if (PIM_DEBUG_MSDP_INTERNAL
) {
585 zlog_debug("MSDP i_am_rp changed");
588 /* mark all local entries as stale */
589 for (ALL_LIST_ELEMENTS_RO(pim
->msdp
.sa_list
, sanode
, sa
)) {
590 if (sa
->flags
& PIM_MSDP_SAF_LOCAL
) {
591 sa
->flags
|= PIM_MSDP_SAF_STALE
;
595 /* re-setup local SA entries */
596 pim_msdp_sa_local_setup(pim
);
598 for (ALL_LIST_ELEMENTS(pim
->msdp
.sa_list
, sanode
, nextnode
, sa
)) {
599 /* purge stale SA entries */
600 if (sa
->flags
& PIM_MSDP_SAF_STALE
) {
601 /* clear the stale flag; the entry may be kept even
604 sa
->flags
&= ~PIM_MSDP_SAF_STALE
;
605 /* sa_deref can end up freeing the sa; so don't access
607 pim_msdp_sa_deref(sa
, PIM_MSDP_SAF_LOCAL
);
609 /* if the souce is still active check if we can
611 pim_msdp_sa_upstream_update(sa
, NULL
/* xg_up */,
617 /* We track the join state of (*, G) entries. If G has sources in the SA-cache
618 * we need to setup or teardown SPT when the JoinDesired status changes for
620 void pim_msdp_up_join_state_changed(struct pim_instance
*pim
,
621 struct pim_upstream
*xg_up
)
623 struct listnode
*sanode
;
624 struct pim_msdp_sa
*sa
;
626 if (PIM_DEBUG_MSDP_INTERNAL
) {
627 zlog_debug("MSDP join state changed for %s", xg_up
->sg_str
);
630 /* If this is not really an XG entry just move on */
631 if ((xg_up
->sg
.src
.s_addr
!= INADDR_ANY
)
632 || (xg_up
->sg
.grp
.s_addr
== INADDR_ANY
)) {
636 /* XXX: Need to maintain SAs per-group to avoid all this unnecessary
638 for (ALL_LIST_ELEMENTS_RO(pim
->msdp
.sa_list
, sanode
, sa
)) {
639 if (sa
->sg
.grp
.s_addr
!= xg_up
->sg
.grp
.s_addr
) {
642 pim_msdp_sa_upstream_update(sa
, xg_up
, "up-jp-change");
646 static void pim_msdp_up_xg_del(struct pim_instance
*pim
, struct prefix_sg
*sg
)
648 struct listnode
*sanode
;
649 struct pim_msdp_sa
*sa
;
651 if (PIM_DEBUG_MSDP_INTERNAL
) {
652 zlog_debug("MSDP %s del", pim_str_sg_dump(sg
));
655 /* If this is not really an XG entry just move on */
656 if ((sg
->src
.s_addr
!= INADDR_ANY
) || (sg
->grp
.s_addr
== INADDR_ANY
)) {
660 /* XXX: Need to maintain SAs per-group to avoid all this unnecessary
662 for (ALL_LIST_ELEMENTS_RO(pim
->msdp
.sa_list
, sanode
, sa
)) {
663 if (sa
->sg
.grp
.s_addr
!= sg
->grp
.s_addr
) {
666 pim_msdp_sa_upstream_update(sa
, NULL
/* xg */, "up-jp-change");
670 void pim_msdp_up_del(struct pim_instance
*pim
, struct prefix_sg
*sg
)
672 if (PIM_DEBUG_MSDP_INTERNAL
) {
673 zlog_debug("MSDP up %s del", pim_str_sg_dump(sg
));
675 if (sg
->src
.s_addr
== INADDR_ANY
) {
676 pim_msdp_up_xg_del(pim
, sg
);
678 pim_msdp_sa_local_del_on_up_del(pim
, sg
);
682 /* sa hash and peer list helpers */
683 static unsigned int pim_msdp_sa_hash_key_make(const void *p
)
685 const struct pim_msdp_sa
*sa
= p
;
687 return (jhash_2words(sa
->sg
.src
.s_addr
, sa
->sg
.grp
.s_addr
, 0));
690 static bool pim_msdp_sa_hash_eq(const void *p1
, const void *p2
)
692 const struct pim_msdp_sa
*sa1
= p1
;
693 const struct pim_msdp_sa
*sa2
= p2
;
695 return ((sa1
->sg
.src
.s_addr
== sa2
->sg
.src
.s_addr
)
696 && (sa1
->sg
.grp
.s_addr
== sa2
->sg
.grp
.s_addr
));
699 static int pim_msdp_sa_comp(const void *p1
, const void *p2
)
701 const struct pim_msdp_sa
*sa1
= p1
;
702 const struct pim_msdp_sa
*sa2
= p2
;
704 if (ntohl(sa1
->sg
.grp
.s_addr
) < ntohl(sa2
->sg
.grp
.s_addr
))
707 if (ntohl(sa1
->sg
.grp
.s_addr
) > ntohl(sa2
->sg
.grp
.s_addr
))
710 if (ntohl(sa1
->sg
.src
.s_addr
) < ntohl(sa2
->sg
.src
.s_addr
))
713 if (ntohl(sa1
->sg
.src
.s_addr
) > ntohl(sa2
->sg
.src
.s_addr
))
719 /* RFC-3618:Sec-10.1.3 - Peer-RPF forwarding */
720 /* XXX: this can use a bit of refining and extensions */
721 bool pim_msdp_peer_rpf_check(struct pim_msdp_peer
*mp
, struct in_addr rp
)
723 struct pim_nexthop nexthop
= {0};
725 if (mp
->peer
.s_addr
== rp
.s_addr
) {
729 /* check if the MSDP peer is the nexthop for the RP */
730 if (pim_nexthop_lookup(mp
->pim
, &nexthop
, rp
, 0)
731 && nexthop
.mrib_nexthop_addr
.u
.prefix4
.s_addr
== mp
->peer
.s_addr
) {
738 /************************ Peer session management **************************/
739 char *pim_msdp_state_dump(enum pim_msdp_peer_state state
, char *buf
,
743 case PIM_MSDP_DISABLED
:
744 snprintf(buf
, buf_size
, "%s", "disabled");
746 case PIM_MSDP_INACTIVE
:
747 snprintf(buf
, buf_size
, "%s", "inactive");
749 case PIM_MSDP_LISTEN
:
750 snprintf(buf
, buf_size
, "%s", "listen");
752 case PIM_MSDP_CONNECTING
:
753 snprintf(buf
, buf_size
, "%s", "connecting");
755 case PIM_MSDP_ESTABLISHED
:
756 snprintf(buf
, buf_size
, "%s", "established");
759 snprintf(buf
, buf_size
, "unk-%d", state
);
764 static void pim_msdp_peer_state_chg_log(struct pim_msdp_peer
*mp
)
766 char state_str
[PIM_MSDP_STATE_STRLEN
];
768 pim_msdp_state_dump(mp
->state
, state_str
, sizeof(state_str
));
769 zlog_debug("MSDP peer %s state chg to %s", mp
->key_str
, state_str
);
772 /* MSDP Connection State Machine actions (defined in RFC-3618:Sec-11.2) */
773 /* 11.2.A2: active peer - start connect retry timer; when the timer fires
774 * a tcp connection will be made */
775 static void pim_msdp_peer_connect(struct pim_msdp_peer
*mp
)
777 mp
->state
= PIM_MSDP_CONNECTING
;
778 if (PIM_DEBUG_MSDP_EVENTS
) {
779 pim_msdp_peer_state_chg_log(mp
);
782 pim_msdp_peer_cr_timer_setup(mp
, true /* start */);
785 /* 11.2.A3: passive peer - just listen for connections */
786 static void pim_msdp_peer_listen(struct pim_msdp_peer
*mp
)
788 mp
->state
= PIM_MSDP_LISTEN
;
789 if (PIM_DEBUG_MSDP_EVENTS
) {
790 pim_msdp_peer_state_chg_log(mp
);
793 /* this is interntionally asymmetric i.e. we set up listen-socket when
795 * first listening peer is configured; but don't bother tearing it down
797 * all the peers go down */
798 pim_msdp_sock_listen(mp
->pim
);
801 /* 11.2.A4 and 11.2.A5: transition active or passive peer to
802 * established state */
803 void pim_msdp_peer_established(struct pim_msdp_peer
*mp
)
805 if (mp
->state
!= PIM_MSDP_ESTABLISHED
) {
809 mp
->state
= PIM_MSDP_ESTABLISHED
;
810 mp
->uptime
= pim_time_monotonic_sec();
812 if (PIM_DEBUG_MSDP_EVENTS
) {
813 pim_msdp_peer_state_chg_log(mp
);
816 /* stop retry timer on active peers */
817 pim_msdp_peer_cr_timer_setup(mp
, false /* start */);
819 /* send KA; start KA and hold timers */
820 pim_msdp_pkt_ka_tx(mp
);
821 pim_msdp_peer_ka_timer_setup(mp
, true /* start */);
822 pim_msdp_peer_hold_timer_setup(mp
, true /* start */);
824 pim_msdp_pkt_sa_tx_to_one_peer(mp
);
826 PIM_MSDP_PEER_WRITE_ON(mp
);
827 PIM_MSDP_PEER_READ_ON(mp
);
830 /* 11.2.A6, 11.2.A7 and 11.2.A8: shutdown the peer tcp connection */
831 void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer
*mp
, bool chg_state
)
834 if (mp
->state
== PIM_MSDP_ESTABLISHED
) {
837 mp
->state
= PIM_MSDP_INACTIVE
;
838 if (PIM_DEBUG_MSDP_EVENTS
) {
839 pim_msdp_peer_state_chg_log(mp
);
843 if (PIM_DEBUG_MSDP_INTERNAL
) {
844 zlog_debug("MSDP peer %s pim_msdp_peer_stop_tcp_conn",
847 /* stop read and write threads */
848 PIM_MSDP_PEER_READ_OFF(mp
);
849 PIM_MSDP_PEER_WRITE_OFF(mp
);
854 stream_reset(mp
->ibuf
);
856 stream_fifo_clean(mp
->obuf
);
858 /* stop all peer timers */
859 pim_msdp_peer_ka_timer_setup(mp
, false /* start */);
860 pim_msdp_peer_cr_timer_setup(mp
, false /* start */);
861 pim_msdp_peer_hold_timer_setup(mp
, false /* start */);
863 /* close connection */
870 /* RFC-3618:Sec-5.6 - stop the peer tcp connection and startover */
871 void pim_msdp_peer_reset_tcp_conn(struct pim_msdp_peer
*mp
, const char *rc_str
)
873 if (PIM_DEBUG_EVENTS
) {
874 zlog_debug("MSDP peer %s tcp reset %s", mp
->key_str
, rc_str
);
875 snprintf(mp
->last_reset
, sizeof(mp
->last_reset
), "%s", rc_str
);
878 /* close the connection and transition to listening or connecting */
879 pim_msdp_peer_stop_tcp_conn(mp
, true /* chg_state */);
880 if (PIM_MSDP_PEER_IS_LISTENER(mp
)) {
881 pim_msdp_peer_listen(mp
);
883 pim_msdp_peer_connect(mp
);
887 static void pim_msdp_peer_timer_expiry_log(struct pim_msdp_peer
*mp
,
888 const char *timer_str
)
890 zlog_debug("MSDP peer %s %s timer expired", mp
->key_str
, timer_str
);
893 /* RFC-3618:Sec-5.4 - peer hold timer */
894 static int pim_msdp_peer_hold_timer_cb(struct thread
*t
)
896 struct pim_msdp_peer
*mp
;
900 if (PIM_DEBUG_MSDP_EVENTS
) {
901 pim_msdp_peer_timer_expiry_log(mp
, "hold");
904 if (mp
->state
!= PIM_MSDP_ESTABLISHED
) {
908 if (PIM_DEBUG_MSDP_EVENTS
) {
909 pim_msdp_peer_state_chg_log(mp
);
911 pim_msdp_peer_reset_tcp_conn(mp
, "ht-expired");
915 static void pim_msdp_peer_hold_timer_setup(struct pim_msdp_peer
*mp
, bool start
)
917 struct pim_instance
*pim
= mp
->pim
;
918 THREAD_OFF(mp
->hold_timer
);
920 thread_add_timer(pim
->msdp
.master
, pim_msdp_peer_hold_timer_cb
,
921 mp
, pim
->msdp
.hold_time
, &mp
->hold_timer
);
926 /* RFC-3618:Sec-5.5 - peer keepalive timer */
927 static int pim_msdp_peer_ka_timer_cb(struct thread
*t
)
929 struct pim_msdp_peer
*mp
;
933 if (PIM_DEBUG_MSDP_EVENTS
) {
934 pim_msdp_peer_timer_expiry_log(mp
, "ka");
937 pim_msdp_pkt_ka_tx(mp
);
938 pim_msdp_peer_ka_timer_setup(mp
, true /* start */);
941 static void pim_msdp_peer_ka_timer_setup(struct pim_msdp_peer
*mp
, bool start
)
943 THREAD_OFF(mp
->ka_timer
);
945 thread_add_timer(mp
->pim
->msdp
.master
,
946 pim_msdp_peer_ka_timer_cb
, mp
,
947 mp
->pim
->msdp
.keep_alive
, &mp
->ka_timer
);
951 static void pim_msdp_peer_active_connect(struct pim_msdp_peer
*mp
)
955 rc
= pim_msdp_sock_connect(mp
);
957 if (PIM_DEBUG_MSDP_INTERNAL
) {
958 zlog_debug("MSDP peer %s pim_msdp_peer_active_connect: %d",
965 /* connect failed restart the connect-retry timer */
966 pim_msdp_peer_cr_timer_setup(mp
, true /* start */);
969 case connect_success
:
970 /* connect was sucessful move to established */
971 pim_msdp_peer_established(mp
);
974 case connect_in_progress
:
975 /* for NB content we need to wait till sock is readable or
977 PIM_MSDP_PEER_WRITE_ON(mp
);
978 PIM_MSDP_PEER_READ_ON(mp
);
979 /* also restart connect-retry timer to reset the socket if
982 pim_msdp_peer_cr_timer_setup(mp
, true /* start */);
987 /* RFC-3618:Sec-5.6 - connection retry on active peer */
988 static int pim_msdp_peer_cr_timer_cb(struct thread
*t
)
990 struct pim_msdp_peer
*mp
;
994 if (PIM_DEBUG_MSDP_EVENTS
) {
995 pim_msdp_peer_timer_expiry_log(mp
, "connect-retry");
998 if (mp
->state
!= PIM_MSDP_CONNECTING
|| PIM_MSDP_PEER_IS_LISTENER(mp
)) {
1002 pim_msdp_peer_active_connect(mp
);
1005 static void pim_msdp_peer_cr_timer_setup(struct pim_msdp_peer
*mp
, bool start
)
1007 THREAD_OFF(mp
->cr_timer
);
1009 thread_add_timer(mp
->pim
->msdp
.master
,
1010 pim_msdp_peer_cr_timer_cb
, mp
,
1011 mp
->pim
->msdp
.connection_retry
, &mp
->cr_timer
);
1015 /* if a valid packet is rxed from the peer we can restart hold timer */
1016 void pim_msdp_peer_pkt_rxed(struct pim_msdp_peer
*mp
)
1018 if (mp
->state
== PIM_MSDP_ESTABLISHED
) {
1019 pim_msdp_peer_hold_timer_setup(mp
, true /* start */);
1023 /* if a valid packet is txed to the peer we can restart ka timer and avoid
1024 * unnecessary ka noise in the network */
1025 void pim_msdp_peer_pkt_txed(struct pim_msdp_peer
*mp
)
1027 if (mp
->state
== PIM_MSDP_ESTABLISHED
) {
1028 pim_msdp_peer_ka_timer_setup(mp
, true /* start */);
1029 if (PIM_DEBUG_MSDP_INTERNAL
) {
1030 zlog_debug("MSDP ka timer restart on pkt tx to %s",
1036 static void pim_msdp_addr2su(union sockunion
*su
, struct in_addr addr
)
1039 su
->sin
.sin_addr
= addr
;
1040 su
->sin
.sin_family
= AF_INET
;
1041 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
1042 su
->sin
.sin_len
= sizeof(struct sockaddr_in
);
1043 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
1046 /* 11.2.A1: create a new peer and transition state to listen or connecting */
1047 struct pim_msdp_peer
*pim_msdp_peer_add(struct pim_instance
*pim
,
1048 const struct in_addr
*peer
,
1049 const struct in_addr
*local
,
1050 const char *mesh_group_name
)
1052 struct pim_msdp_peer
*mp
;
1054 pim_msdp_enable(pim
);
1056 mp
= XCALLOC(MTYPE_PIM_MSDP_PEER
, sizeof(*mp
));
1060 pim_inet4_dump("<peer?>", mp
->peer
, mp
->key_str
, sizeof(mp
->key_str
));
1061 pim_msdp_addr2su(&mp
->su_peer
, mp
->peer
);
1063 /* XXX: originator_id setting needs to move to the mesh group */
1064 pim
->msdp
.originator_id
= *local
;
1065 pim_msdp_addr2su(&mp
->su_local
, mp
->local
);
1066 if (mesh_group_name
)
1067 mp
->mesh_group_name
=
1068 XSTRDUP(MTYPE_PIM_MSDP_MG_NAME
, mesh_group_name
);
1070 mp
->state
= PIM_MSDP_INACTIVE
;
1072 strlcpy(mp
->last_reset
, "-", sizeof(mp
->last_reset
));
1073 /* higher IP address is listener */
1074 if (ntohl(mp
->local
.s_addr
) > ntohl(mp
->peer
.s_addr
)) {
1075 mp
->flags
|= PIM_MSDP_PEERF_LISTENER
;
1078 /* setup packet buffers */
1079 mp
->ibuf
= stream_new(PIM_MSDP_MAX_PACKET_SIZE
);
1080 mp
->obuf
= stream_fifo_new();
1082 /* insert into misc tables for easy access */
1083 mp
= hash_get(pim
->msdp
.peer_hash
, mp
, hash_alloc_intern
);
1084 listnode_add_sort(pim
->msdp
.peer_list
, mp
);
1086 if (PIM_DEBUG_MSDP_EVENTS
) {
1087 zlog_debug("MSDP peer %s created", mp
->key_str
);
1089 pim_msdp_peer_state_chg_log(mp
);
1092 /* fireup the connect state machine */
1093 if (PIM_MSDP_PEER_IS_LISTENER(mp
)) {
1094 pim_msdp_peer_listen(mp
);
1096 pim_msdp_peer_connect(mp
);
1101 struct pim_msdp_peer
*pim_msdp_peer_find(struct pim_instance
*pim
,
1102 struct in_addr peer_addr
)
1104 struct pim_msdp_peer lookup
;
1106 lookup
.peer
= peer_addr
;
1107 return hash_lookup(pim
->msdp
.peer_hash
, &lookup
);
1110 /* release all mem associated with a peer */
1111 static void pim_msdp_peer_free(struct pim_msdp_peer
*mp
)
1114 * Let's make sure we are not running when we delete
1115 * the underlying data structure
1117 pim_msdp_peer_stop_tcp_conn(mp
, false);
1120 stream_free(mp
->ibuf
);
1124 stream_fifo_free(mp
->obuf
);
1127 XFREE(MTYPE_PIM_MSDP_MG_NAME
, mp
->mesh_group_name
);
1130 XFREE(MTYPE_PIM_MSDP_PEER
, mp
);
1133 /* delete the peer config */
1134 void pim_msdp_peer_del(struct pim_msdp_peer
**mp
)
1139 /* stop the tcp connection and shutdown all timers */
1140 pim_msdp_peer_stop_tcp_conn(*mp
, true /* chg_state */);
1142 /* remove the session from various tables */
1143 listnode_delete((*mp
)->pim
->msdp
.peer_list
, *mp
);
1144 hash_release((*mp
)->pim
->msdp
.peer_hash
, *mp
);
1146 if (PIM_DEBUG_MSDP_EVENTS
) {
1147 zlog_debug("MSDP peer %s deleted", (*mp
)->key_str
);
1150 /* free up any associated memory */
1151 pim_msdp_peer_free(*mp
);
1155 void pim_msdp_peer_change_source(struct pim_msdp_peer
*mp
,
1156 const struct in_addr
*addr
)
1158 pim_msdp_peer_stop_tcp_conn(mp
, true);
1162 if (PIM_MSDP_PEER_IS_LISTENER(mp
))
1163 pim_msdp_peer_listen(mp
);
1165 pim_msdp_peer_connect(mp
);
1168 /* peer hash and peer list helpers */
1169 static unsigned int pim_msdp_peer_hash_key_make(const void *p
)
1171 const struct pim_msdp_peer
*mp
= p
;
1172 return (jhash_1word(mp
->peer
.s_addr
, 0));
1175 static bool pim_msdp_peer_hash_eq(const void *p1
, const void *p2
)
1177 const struct pim_msdp_peer
*mp1
= p1
;
1178 const struct pim_msdp_peer
*mp2
= p2
;
1180 return (mp1
->peer
.s_addr
== mp2
->peer
.s_addr
);
1183 static int pim_msdp_peer_comp(const void *p1
, const void *p2
)
1185 const struct pim_msdp_peer
*mp1
= p1
;
1186 const struct pim_msdp_peer
*mp2
= p2
;
1188 if (ntohl(mp1
->peer
.s_addr
) < ntohl(mp2
->peer
.s_addr
))
1191 if (ntohl(mp1
->peer
.s_addr
) > ntohl(mp2
->peer
.s_addr
))
1197 /************************** Mesh group management **************************/
1198 void pim_msdp_mg_free(struct pim_instance
*pim
, struct pim_msdp_mg
**mgp
)
1200 struct pim_msdp_mg_mbr
*mbr
;
1201 struct listnode
*n
, *nn
;
1206 /* SIP is being removed - tear down all active peer sessions */
1207 for (ALL_LIST_ELEMENTS((*mgp
)->mbr_list
, n
, nn
, mbr
))
1208 pim_msdp_mg_mbr_del((*mgp
), mbr
);
1210 if (PIM_DEBUG_MSDP_EVENTS
) {
1211 zlog_debug("MSDP mesh-group %s deleted",
1212 (*mgp
)->mesh_group_name
);
1215 XFREE(MTYPE_PIM_MSDP_MG_NAME
, (*mgp
)->mesh_group_name
);
1217 if ((*mgp
)->mbr_list
)
1218 list_delete(&(*mgp
)->mbr_list
);
1220 SLIST_REMOVE(&pim
->msdp
.mglist
, (*mgp
), pim_msdp_mg
, mg_entry
);
1221 XFREE(MTYPE_PIM_MSDP_MG
, (*mgp
));
1224 struct pim_msdp_mg
*pim_msdp_mg_new(struct pim_instance
*pim
,
1225 const char *mesh_group_name
)
1227 struct pim_msdp_mg
*mg
;
1229 mg
= XCALLOC(MTYPE_PIM_MSDP_MG
, sizeof(*mg
));
1231 mg
->mesh_group_name
= XSTRDUP(MTYPE_PIM_MSDP_MG_NAME
, mesh_group_name
);
1232 mg
->mbr_list
= list_new();
1233 mg
->mbr_list
->del
= (void (*)(void *))pim_msdp_mg_mbr_free
;
1234 mg
->mbr_list
->cmp
= (int (*)(void *, void *))pim_msdp_mg_mbr_comp
;
1236 if (PIM_DEBUG_MSDP_EVENTS
) {
1237 zlog_debug("MSDP mesh-group %s created", mg
->mesh_group_name
);
1240 SLIST_INSERT_HEAD(&pim
->msdp
.mglist
, mg
, mg_entry
);
1245 static int pim_msdp_mg_mbr_comp(const void *p1
, const void *p2
)
1247 const struct pim_msdp_mg_mbr
*mbr1
= p1
;
1248 const struct pim_msdp_mg_mbr
*mbr2
= p2
;
1250 if (ntohl(mbr1
->mbr_ip
.s_addr
) < ntohl(mbr2
->mbr_ip
.s_addr
))
1253 if (ntohl(mbr1
->mbr_ip
.s_addr
) > ntohl(mbr2
->mbr_ip
.s_addr
))
1259 static void pim_msdp_mg_mbr_free(struct pim_msdp_mg_mbr
*mbr
)
1261 XFREE(MTYPE_PIM_MSDP_MG_MBR
, mbr
);
1264 void pim_msdp_mg_mbr_del(struct pim_msdp_mg
*mg
, struct pim_msdp_mg_mbr
*mbr
)
1266 /* Delete active peer session if any */
1268 pim_msdp_peer_del(&mbr
->mp
);
1271 listnode_delete(mg
->mbr_list
, mbr
);
1272 if (PIM_DEBUG_MSDP_EVENTS
) {
1273 char ip_str
[INET_ADDRSTRLEN
];
1274 pim_inet4_dump("<mbr?>", mbr
->mbr_ip
, ip_str
, sizeof(ip_str
));
1275 zlog_debug("MSDP mesh-group %s mbr %s deleted",
1276 mg
->mesh_group_name
, ip_str
);
1278 pim_msdp_mg_mbr_free(mbr
);
1284 static void pim_msdp_src_del(struct pim_msdp_mg
*mg
)
1286 struct pim_msdp_mg_mbr
*mbr
;
1287 struct listnode
*mbr_node
;
1289 /* SIP is being removed - tear down all active peer sessions */
1290 for (ALL_LIST_ELEMENTS_RO(mg
->mbr_list
, mbr_node
, mbr
)) {
1292 pim_msdp_peer_del(&mbr
->mp
);
1294 if (PIM_DEBUG_MSDP_EVENTS
) {
1295 zlog_debug("MSDP mesh-group %s src cleared",
1296 mg
->mesh_group_name
);
1300 /*********************** MSDP feature APIs *********************************/
1301 int pim_msdp_config_write(struct pim_instance
*pim
, struct vty
*vty
,
1304 struct pim_msdp_mg
*mg
;
1305 struct listnode
*mbrnode
;
1306 struct pim_msdp_mg_mbr
*mbr
;
1307 char mbr_str
[INET_ADDRSTRLEN
];
1308 char src_str
[INET_ADDRSTRLEN
];
1311 if (SLIST_EMPTY(&pim
->msdp
.mglist
))
1314 SLIST_FOREACH (mg
, &pim
->msdp
.mglist
, mg_entry
) {
1315 if (mg
->src_ip
.s_addr
!= INADDR_ANY
) {
1316 pim_inet4_dump("<src?>", mg
->src_ip
, src_str
,
1318 vty_out(vty
, "%sip msdp mesh-group %s source %s\n",
1319 spaces
, mg
->mesh_group_name
, src_str
);
1323 for (ALL_LIST_ELEMENTS_RO(mg
->mbr_list
, mbrnode
, mbr
)) {
1324 pim_inet4_dump("<mbr?>", mbr
->mbr_ip
, mbr_str
,
1326 vty_out(vty
, "%sip msdp mesh-group %s member %s\n",
1327 spaces
, mg
->mesh_group_name
, mbr_str
);
1335 bool pim_msdp_peer_config_write(struct vty
*vty
, struct pim_instance
*pim
,
1338 struct pim_msdp_peer
*mp
;
1339 struct listnode
*node
;
1340 bool written
= false;
1342 for (ALL_LIST_ELEMENTS_RO(pim
->msdp
.peer_list
, node
, mp
)) {
1343 /* Skip meshed group peers. */
1344 if (mp
->flags
& PIM_MSDP_PEERF_IN_GROUP
)
1347 vty_out(vty
, "%sip msdp peer %pI4 source %pI4\n", spaces
,
1348 &mp
->peer
, &mp
->local
);
1355 /* Enable feature including active/periodic timers etc. on the first peer
1356 * config. Till then MSDP should just stay quiet. */
1357 static void pim_msdp_enable(struct pim_instance
*pim
)
1359 if (pim
->msdp
.flags
& PIM_MSDPF_ENABLE
) {
1360 /* feature is already enabled */
1363 pim
->msdp
.flags
|= PIM_MSDPF_ENABLE
;
1364 pim
->msdp
.work_obuf
= stream_new(PIM_MSDP_MAX_PACKET_SIZE
);
1365 pim_msdp_sa_adv_timer_setup(pim
, true /* start */);
1366 /* setup sa cache based on local sources */
1367 pim_msdp_sa_local_setup(pim
);
1371 void pim_msdp_init(struct pim_instance
*pim
, struct thread_master
*master
)
1373 pim
->msdp
.master
= master
;
1376 snprintf(hash_name
, sizeof(hash_name
), "PIM %s MSDP Peer Hash",
1378 pim
->msdp
.peer_hash
= hash_create(pim_msdp_peer_hash_key_make
,
1379 pim_msdp_peer_hash_eq
, hash_name
);
1380 pim
->msdp
.peer_list
= list_new();
1381 pim
->msdp
.peer_list
->del
= (void (*)(void *))pim_msdp_peer_free
;
1382 pim
->msdp
.peer_list
->cmp
= (int (*)(void *, void *))pim_msdp_peer_comp
;
1384 snprintf(hash_name
, sizeof(hash_name
), "PIM %s MSDP SA Hash",
1386 pim
->msdp
.sa_hash
= hash_create(pim_msdp_sa_hash_key_make
,
1387 pim_msdp_sa_hash_eq
, hash_name
);
1388 pim
->msdp
.sa_list
= list_new();
1389 pim
->msdp
.sa_list
->del
= (void (*)(void *))pim_msdp_sa_free
;
1390 pim
->msdp
.sa_list
->cmp
= (int (*)(void *, void *))pim_msdp_sa_comp
;
1393 /* counterpart to MSDP init; XXX: unused currently */
1394 void pim_msdp_exit(struct pim_instance
*pim
)
1396 struct pim_msdp_mg
*mg
;
1398 pim_msdp_sa_adv_timer_setup(pim
, false);
1400 /* Stop listener and delete all peer sessions */
1401 while ((mg
= SLIST_FIRST(&pim
->msdp
.mglist
)) != NULL
)
1402 pim_msdp_mg_free(pim
, &mg
);
1404 if (pim
->msdp
.peer_hash
) {
1405 hash_clean(pim
->msdp
.peer_hash
, NULL
);
1406 hash_free(pim
->msdp
.peer_hash
);
1407 pim
->msdp
.peer_hash
= NULL
;
1410 if (pim
->msdp
.peer_list
) {
1411 list_delete(&pim
->msdp
.peer_list
);
1414 if (pim
->msdp
.sa_hash
) {
1415 hash_clean(pim
->msdp
.sa_hash
, NULL
);
1416 hash_free(pim
->msdp
.sa_hash
);
1417 pim
->msdp
.sa_hash
= NULL
;
1420 if (pim
->msdp
.sa_list
) {
1421 list_delete(&pim
->msdp
.sa_list
);
1424 if (pim
->msdp
.work_obuf
)
1425 stream_free(pim
->msdp
.work_obuf
);
1426 pim
->msdp
.work_obuf
= NULL
;
1429 void pim_msdp_mg_src_add(struct pim_instance
*pim
, struct pim_msdp_mg
*mg
,
1432 struct pim_msdp_mg_mbr
*mbr
;
1433 struct listnode
*mbr_node
;
1435 /* Stop all connections and remove data structures. */
1436 pim_msdp_src_del(mg
);
1438 /* Set new address. */
1441 /* No new address, disable everyone. */
1442 if (ai
->s_addr
== INADDR_ANY
) {
1443 if (PIM_DEBUG_MSDP_EVENTS
)
1444 zlog_debug("MSDP mesh-group %s src unset",
1445 mg
->mesh_group_name
);
1449 /* Create data structures and start TCP connection. */
1450 for (ALL_LIST_ELEMENTS_RO(mg
->mbr_list
, mbr_node
, mbr
))
1451 mbr
->mp
= pim_msdp_peer_add(pim
, &mbr
->mbr_ip
, &mg
->src_ip
,
1452 mg
->mesh_group_name
);
1454 if (PIM_DEBUG_MSDP_EVENTS
)
1455 zlog_debug("MSDP mesh-group %s src %pI4 set",
1456 mg
->mesh_group_name
, &mg
->src_ip
);
1459 struct pim_msdp_mg_mbr
*pim_msdp_mg_mbr_add(struct pim_instance
*pim
,
1460 struct pim_msdp_mg
*mg
,
1463 struct pim_msdp_mg_mbr
*mbr
;
1465 mbr
= XCALLOC(MTYPE_PIM_MSDP_MG_MBR
, sizeof(*mbr
));
1467 listnode_add_sort(mg
->mbr_list
, mbr
);
1469 /* if valid SIP has been configured add peer session */
1470 if (mg
->src_ip
.s_addr
!= INADDR_ANY
)
1471 mbr
->mp
= pim_msdp_peer_add(pim
, &mbr
->mbr_ip
, &mg
->src_ip
,
1472 mg
->mesh_group_name
);
1474 if (PIM_DEBUG_MSDP_EVENTS
)
1475 zlog_debug("MSDP mesh-group %s mbr %pI4 created",
1476 mg
->mesh_group_name
, &mbr
->mbr_ip
);