]> git.proxmox.com Git - mirror_frr.git/blame - pimd/pim_msdp.c
Merge branch 'stable/3.0' into tmp-3.0-master-merge
[mirror_frr.git] / pimd / pim_msdp.c
CommitLineData
11128587 1/*
2a333e0f 2 * IP MSDP for Quagga
11128587 3 * Copyright (C) 2016 Cumulus Networks, Inc.
11128587
DS
4 *
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.
9 *
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.
14 *
896014f4
DL
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
11128587
DS
18 */
19
20#include <zebra.h>
21
2a333e0f 22#include <lib/hash.h>
23#include <lib/jhash.h>
24#include <lib/log.h>
3c72d654 25#include <lib/prefix.h>
2a333e0f 26#include <lib/sockunion.h>
27#include <lib/stream.h>
28#include <lib/thread.h>
3c72d654 29#include <lib/vty.h>
30#include <lib/plist.h>
11128587 31
2a333e0f 32#include "pimd.h"
33#include "pim_cmd.h"
34#include "pim_memory.h"
7176984f 35#include "pim_iface.h"
3c72d654 36#include "pim_rp.h"
2a333e0f 37#include "pim_str.h"
38#include "pim_time.h"
1bf16443 39#include "pim_upstream.h"
472ad383 40#include "pim_oil.h"
11128587 41
2a333e0f 42#include "pim_msdp.h"
43#include "pim_msdp_packet.h"
44#include "pim_msdp_socket.h"
45
2ad78035 46// struct pim_msdp pim_msdp, *msdp = &pim_msdp;
2a333e0f 47
48static void pim_msdp_peer_listen(struct pim_msdp_peer *mp);
49static void pim_msdp_peer_cr_timer_setup(struct pim_msdp_peer *mp, bool start);
50static void pim_msdp_peer_ka_timer_setup(struct pim_msdp_peer *mp, bool start);
d62a17ae 51static void pim_msdp_peer_hold_timer_setup(struct pim_msdp_peer *mp,
52 bool start);
2a333e0f 53static void pim_msdp_peer_free(struct pim_msdp_peer *mp);
472ad383
DS
54static void pim_msdp_enable(struct pim_instance *pim);
55static void pim_msdp_sa_adv_timer_setup(struct pim_instance *pim, bool start);
d62a17ae 56static void pim_msdp_sa_deref(struct pim_msdp_sa *sa,
57 enum pim_msdp_sa_flags flags);
977d71cc 58static int pim_msdp_mg_mbr_comp(const void *p1, const void *p2);
59static void pim_msdp_mg_mbr_free(struct pim_msdp_mg_mbr *mbr);
d62a17ae 60static void pim_msdp_mg_mbr_do_del(struct pim_msdp_mg *mg,
61 struct pim_msdp_mg_mbr *mbr);
2a333e0f 62
3c72d654 63/************************ SA cache management ******************************/
d62a17ae 64static void pim_msdp_sa_timer_expiry_log(struct pim_msdp_sa *sa,
65 const char *timer_str)
3c72d654 66{
d62a17ae 67 zlog_debug("MSDP SA %s %s timer expired", sa->sg_str, timer_str);
3c72d654 68}
69
70/* RFC-3618:Sec-5.1 - global active source advertisement timer */
d62a17ae 71static int pim_msdp_sa_adv_timer_cb(struct thread *t)
3c72d654 72{
472ad383
DS
73 struct pim_instance *pim = THREAD_ARG(t);
74
d62a17ae 75 if (PIM_DEBUG_MSDP_EVENTS) {
76 zlog_debug("MSDP SA advertisment timer expired");
77 }
3c72d654 78
472ad383
DS
79 pim_msdp_sa_adv_timer_setup(pim, true /* start */);
80 pim_msdp_pkt_sa_tx(pim);
d62a17ae 81 return 0;
3c72d654 82}
472ad383 83static void pim_msdp_sa_adv_timer_setup(struct pim_instance *pim, bool start)
3c72d654 84{
472ad383 85 THREAD_OFF(pim->msdp.sa_adv_timer);
d62a17ae 86 if (start) {
472ad383
DS
87 thread_add_timer(pim->msdp.master, pim_msdp_sa_adv_timer_cb,
88 pim, PIM_MSDP_SA_ADVERTISMENT_TIME,
89 &pim->msdp.sa_adv_timer);
d62a17ae 90 }
3c72d654 91}
92
93/* RFC-3618:Sec-5.3 - SA cache state timer */
d62a17ae 94static int pim_msdp_sa_state_timer_cb(struct thread *t)
3c72d654 95{
d62a17ae 96 struct pim_msdp_sa *sa;
3c72d654 97
d62a17ae 98 sa = THREAD_ARG(t);
3c72d654 99
d62a17ae 100 if (PIM_DEBUG_MSDP_EVENTS) {
101 pim_msdp_sa_timer_expiry_log(sa, "state");
102 }
3c72d654 103
d62a17ae 104 pim_msdp_sa_deref(sa, PIM_MSDP_SAF_PEER);
105 return 0;
3c72d654 106}
d62a17ae 107static void pim_msdp_sa_state_timer_setup(struct pim_msdp_sa *sa, bool start)
3c72d654 108{
d62a17ae 109 THREAD_OFF(sa->sa_state_timer);
110 if (start) {
472ad383
DS
111 thread_add_timer(sa->pim->msdp.master,
112 pim_msdp_sa_state_timer_cb, sa,
113 PIM_MSDP_SA_HOLD_TIME, &sa->sa_state_timer);
d62a17ae 114 }
3c72d654 115}
116
d62a17ae 117static void pim_msdp_sa_upstream_del(struct pim_msdp_sa *sa)
7667c556 118{
d62a17ae 119 struct pim_upstream *up = sa->up;
120 if (!up) {
121 return;
122 }
7667c556 123
d62a17ae 124 sa->up = NULL;
125 if (PIM_UPSTREAM_FLAG_TEST_SRC_MSDP(up->flags)) {
126 PIM_UPSTREAM_FLAG_UNSET_SRC_MSDP(up->flags);
127 sa->flags |= PIM_MSDP_SAF_UP_DEL_IN_PROG;
472ad383 128 pim_upstream_del(sa->pim, up, __PRETTY_FUNCTION__);
d62a17ae 129 sa->flags &= ~PIM_MSDP_SAF_UP_DEL_IN_PROG;
130 }
7667c556 131
d62a17ae 132 if (PIM_DEBUG_MSDP_EVENTS) {
133 zlog_debug("MSDP SA %s de-referenced SPT", sa->sg_str);
134 }
7667c556 135}
136
d62a17ae 137static bool pim_msdp_sa_upstream_add_ok(struct pim_msdp_sa *sa,
138 struct pim_upstream *xg_up)
7667c556 139{
d62a17ae 140 if (!(sa->flags & PIM_MSDP_SAF_PEER)) {
141 /* SA should have been rxed from a peer */
142 return false;
143 }
144 /* check if we are RP */
472ad383 145 if (!I_am_RP(sa->pim, sa->sg.grp)) {
d62a17ae 146 return false;
147 }
7667c556 148
d62a17ae 149 /* check if we have a (*, G) with a non-empty immediate OIL */
150 if (!xg_up) {
151 struct prefix_sg sg;
7667c556 152
d62a17ae 153 memset(&sg, 0, sizeof(sg));
154 sg.grp = sa->sg.grp;
7667c556 155
472ad383 156 xg_up = pim_upstream_find(sa->pim, &sg);
d62a17ae 157 }
158 if (!xg_up || (xg_up->join_state != PIM_UPSTREAM_JOINED)) {
159 /* join desired will be true for such (*, G) entries so we will
160 * just look at join_state and let the PIM state machine do the
161 * rest of
162 * the magic */
163 return false;
164 }
7667c556 165
d62a17ae 166 return true;
7667c556 167}
168
169/* Upstream add evaluation needs to happen everytime -
170 * 1. Peer reference is added or removed.
1bf16443 171 * 2. The RP for a group changes.
172 * 3. joinDesired for the associated (*, G) changes
173 * 4. associated (*, G) is removed - this seems like a bit redundant
7667c556 174 * (considering #4); but just in case an entry gets nuked without
175 * upstream state transition
176 * */
d62a17ae 177static void pim_msdp_sa_upstream_update(struct pim_msdp_sa *sa,
178 struct pim_upstream *xg_up,
179 const char *ctx)
180{
181 struct pim_upstream *up;
182
183 if (!pim_msdp_sa_upstream_add_ok(sa, xg_up)) {
184 pim_msdp_sa_upstream_del(sa);
185 return;
186 }
187
188 if (sa->up) {
189 /* nothing to do */
190 return;
191 }
192
472ad383 193 up = pim_upstream_find(sa->pim, &sa->sg);
d62a17ae 194 if (up && (PIM_UPSTREAM_FLAG_TEST_SRC_MSDP(up->flags))) {
195 /* somehow we lost track of the upstream ptr? best log it */
196 sa->up = up;
197 if (PIM_DEBUG_MSDP_EVENTS) {
198 zlog_debug("MSDP SA %s SPT reference missing",
199 sa->sg_str);
200 }
201 return;
202 }
203
204 /* RFC3618: "RP triggers a (S, G) join event towards the data source
205 * as if a JP message was rxed addressed to the RP itself." */
2002dcdb 206 up = pim_upstream_add(sa->pim, &sa->sg, NULL /* iif */,
d62a17ae 207 PIM_UPSTREAM_FLAG_MASK_SRC_MSDP,
0885a9f1 208 __PRETTY_FUNCTION__, NULL);
d62a17ae 209
210 sa->up = up;
211 if (up) {
212 /* update inherited oil */
472ad383 213 pim_upstream_inherited_olist(sa->pim, up);
d62a17ae 214 /* should we also start the kat in parallel? we will need it
215 * when the
216 * SA ages out */
217 if (PIM_DEBUG_MSDP_EVENTS) {
218 zlog_debug("MSDP SA %s referenced SPT", sa->sg_str);
219 }
220 } else {
221 if (PIM_DEBUG_MSDP_EVENTS) {
222 zlog_debug("MSDP SA %s SPT reference failed",
223 sa->sg_str);
224 }
225 }
7667c556 226}
227
3c72d654 228/* release all mem associated with a sa */
d62a17ae 229static void pim_msdp_sa_free(struct pim_msdp_sa *sa)
3c72d654 230{
d62a17ae 231 XFREE(MTYPE_PIM_MSDP_SA, sa);
3c72d654 232}
233
472ad383
DS
234static struct pim_msdp_sa *pim_msdp_sa_new(struct pim_instance *pim,
235 struct prefix_sg *sg,
d62a17ae 236 struct in_addr rp)
3c72d654 237{
d62a17ae 238 struct pim_msdp_sa *sa;
3c72d654 239
d62a17ae 240 sa = XCALLOC(MTYPE_PIM_MSDP_SA, sizeof(*sa));
241 if (!sa) {
242 zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__,
243 sizeof(*sa));
244 return NULL;
245 }
3c72d654 246
472ad383 247 sa->pim = pim;
d62a17ae 248 sa->sg = *sg;
249 pim_str_sg_set(sg, sa->sg_str);
250 sa->rp = rp;
251 sa->uptime = pim_time_monotonic_sec();
3c72d654 252
d62a17ae 253 /* insert into misc tables for easy access */
472ad383 254 sa = hash_get(pim->msdp.sa_hash, sa, hash_alloc_intern);
d62a17ae 255 if (!sa) {
256 zlog_err("%s: PIM hash get failure", __PRETTY_FUNCTION__);
257 pim_msdp_sa_free(sa);
258 return NULL;
259 }
472ad383 260 listnode_add_sort(pim->msdp.sa_list, sa);
3c72d654 261
d62a17ae 262 if (PIM_DEBUG_MSDP_EVENTS) {
263 zlog_debug("MSDP SA %s created", sa->sg_str);
264 }
3c72d654 265
d62a17ae 266 return sa;
3c72d654 267}
268
472ad383
DS
269static struct pim_msdp_sa *pim_msdp_sa_find(struct pim_instance *pim,
270 struct prefix_sg *sg)
3c72d654 271{
d62a17ae 272 struct pim_msdp_sa lookup;
3c72d654 273
d62a17ae 274 lookup.sg = *sg;
472ad383 275 return hash_lookup(pim->msdp.sa_hash, &lookup);
3c72d654 276}
277
472ad383
DS
278static struct pim_msdp_sa *pim_msdp_sa_add(struct pim_instance *pim,
279 struct prefix_sg *sg,
d62a17ae 280 struct in_addr rp)
3c72d654 281{
d62a17ae 282 struct pim_msdp_sa *sa;
3c72d654 283
472ad383 284 sa = pim_msdp_sa_find(pim, sg);
d62a17ae 285 if (sa) {
286 return sa;
287 }
3c72d654 288
472ad383 289 return pim_msdp_sa_new(pim, sg, rp);
3c72d654 290}
291
d62a17ae 292static void pim_msdp_sa_del(struct pim_msdp_sa *sa)
3c72d654 293{
d62a17ae 294 /* this is somewhat redundant - still want to be careful not to leave
295 * stale upstream references */
296 pim_msdp_sa_upstream_del(sa);
7667c556 297
d62a17ae 298 /* stop timers */
299 pim_msdp_sa_state_timer_setup(sa, false /* start */);
3c72d654 300
d62a17ae 301 /* remove the entry from various tables */
472ad383
DS
302 listnode_delete(sa->pim->msdp.sa_list, sa);
303 hash_release(sa->pim->msdp.sa_hash, sa);
3c72d654 304
d62a17ae 305 if (PIM_DEBUG_MSDP_EVENTS) {
306 zlog_debug("MSDP SA %s deleted", sa->sg_str);
307 }
3c72d654 308
d62a17ae 309 /* free up any associated memory */
310 pim_msdp_sa_free(sa);
3c72d654 311}
312
d62a17ae 313static void pim_msdp_sa_peer_ip_set(struct pim_msdp_sa *sa,
314 struct pim_msdp_peer *mp, struct in_addr rp)
15ad0c71 315{
d62a17ae 316 struct pim_msdp_peer *old_mp;
15ad0c71 317
d62a17ae 318 /* optimize the "no change" case as it will happen
319 * frequently/periodically */
320 if (mp && (sa->peer.s_addr == mp->peer.s_addr)) {
321 return;
322 }
15ad0c71 323
d62a17ae 324 /* any time the peer ip changes also update the rp address */
325 if (PIM_INADDR_ISNOT_ANY(sa->peer)) {
472ad383 326 old_mp = pim_msdp_peer_find(sa->pim, sa->peer);
d62a17ae 327 if (old_mp && old_mp->sa_cnt) {
328 --old_mp->sa_cnt;
329 }
330 }
15ad0c71 331
d62a17ae 332 if (mp) {
333 ++mp->sa_cnt;
334 sa->peer = mp->peer;
335 } else {
336 sa->peer.s_addr = PIM_NET_INADDR_ANY;
337 }
338 sa->rp = rp;
15ad0c71 339}
340
3c72d654 341/* When a local active-source is removed there is no way to withdraw the
342 * source from peers. We will simply remove it from the SA cache so it will
343 * not be sent in supsequent SA updates. Peers will consequently timeout the
344 * SA.
345 * Similarly a "peer-added" SA is never explicitly deleted. It is simply
d62a17ae 346 * aged out overtime if not seen in the SA updates from the peers.
3c72d654 347 * XXX: should we provide a knob to drop entries learnt from a peer when the
348 * peer goes down? */
d62a17ae 349static void pim_msdp_sa_deref(struct pim_msdp_sa *sa,
350 enum pim_msdp_sa_flags flags)
351{
352 bool update_up = false;
353
354 if ((sa->flags & PIM_MSDP_SAF_LOCAL)) {
355 if (flags & PIM_MSDP_SAF_LOCAL) {
356 if (PIM_DEBUG_MSDP_EVENTS) {
357 zlog_debug("MSDP SA %s local reference removed",
358 sa->sg_str);
359 }
472ad383
DS
360 if (sa->pim->msdp.local_cnt)
361 --sa->pim->msdp.local_cnt;
d62a17ae 362 }
363 }
364
365 if ((sa->flags & PIM_MSDP_SAF_PEER)) {
366 if (flags & PIM_MSDP_SAF_PEER) {
367 struct in_addr rp;
368
369 if (PIM_DEBUG_MSDP_EVENTS) {
370 zlog_debug("MSDP SA %s peer reference removed",
371 sa->sg_str);
372 }
373 pim_msdp_sa_state_timer_setup(sa, false /* start */);
374 rp.s_addr = INADDR_ANY;
375 pim_msdp_sa_peer_ip_set(sa, NULL /* mp */, rp);
376 /* if peer ref was removed we need to remove the msdp
377 * reference on the
378 * msdp entry */
379 update_up = true;
380 }
381 }
382
383 sa->flags &= ~flags;
384 if (update_up) {
385 pim_msdp_sa_upstream_update(sa, NULL /* xg_up */, "sa-deref");
386 }
387
388 if (!(sa->flags & PIM_MSDP_SAF_REF)) {
389 pim_msdp_sa_del(sa);
390 }
391}
392
472ad383
DS
393void pim_msdp_sa_ref(struct pim_instance *pim, struct pim_msdp_peer *mp,
394 struct prefix_sg *sg, struct in_addr rp)
d62a17ae 395{
396 struct pim_msdp_sa *sa;
397
472ad383 398 sa = pim_msdp_sa_add(pim, sg, rp);
d62a17ae 399 if (!sa) {
400 return;
401 }
402
403 /* reference it */
404 if (mp) {
405 if (!(sa->flags & PIM_MSDP_SAF_PEER)) {
406 sa->flags |= PIM_MSDP_SAF_PEER;
407 if (PIM_DEBUG_MSDP_EVENTS) {
408 zlog_debug("MSDP SA %s added by peer",
409 sa->sg_str);
410 }
411 }
412 pim_msdp_sa_peer_ip_set(sa, mp, rp);
413 /* start/re-start the state timer to prevent cache expiry */
414 pim_msdp_sa_state_timer_setup(sa, true /* start */);
415 /* We re-evaluate SA "SPT-trigger" everytime we hear abt it from
416 * a
417 * peer. XXX: If this becomes too much of a periodic overhead we
418 * can make it event based */
419 pim_msdp_sa_upstream_update(sa, NULL /* xg_up */, "peer-ref");
420 } else {
421 if (!(sa->flags & PIM_MSDP_SAF_LOCAL)) {
422 sa->flags |= PIM_MSDP_SAF_LOCAL;
472ad383 423 ++sa->pim->msdp.local_cnt;
d62a17ae 424 if (PIM_DEBUG_MSDP_EVENTS) {
425 zlog_debug("MSDP SA %s added locally",
426 sa->sg_str);
427 }
428 /* send an immediate SA update to peers */
429 pim_msdp_pkt_sa_tx_one(sa);
430 }
431 sa->flags &= ~PIM_MSDP_SAF_STALE;
432 }
3c72d654 433}
434
1bf16443 435/* The following criteria must be met to originate an SA from the MSDP
436 * speaker -
437 * 1. KAT must be running i.e. source is active.
438 * 2. We must be RP for the group.
439 * 3. Source must be registrable to the RP (this is where the RFC is vague
440 * and especially ambiguous in CLOS networks; with anycast RP all sources
441 * are potentially registrable to all RPs in the domain). We assume #3 is
442 * satisfied if -
443 * a. We are also the FHR-DR for the source (OR)
444 * b. We rxed a pim register (null or data encapsulated) within the last
445 * (3 * (1.5 * register_suppression_timer))).
446 */
d62a17ae 447static bool pim_msdp_sa_local_add_ok(struct pim_upstream *up)
3c72d654 448{
472ad383
DS
449 struct pim_instance *pim = up->channel_oil->pim;
450
451 if (!(pim->msdp.flags & PIM_MSDPF_ENABLE)) {
d62a17ae 452 return false;
453 }
3c72d654 454
d62a17ae 455 if (!up->t_ka_timer) {
456 /* stream is not active */
457 return false;
458 }
1bf16443 459
472ad383 460 if (!I_am_RP(pim, up->sg.grp)) {
d62a17ae 461 /* we are not RP for the group */
462 return false;
463 }
1bf16443 464
d62a17ae 465 /* we are the FHR-DR for this stream or we are RP and have seen
466 * registers
467 * from a FHR for this source */
468 if (PIM_UPSTREAM_FLAG_TEST_FHR(up->flags) || up->t_msdp_reg_timer) {
469 return true;
470 }
1bf16443 471
d62a17ae 472 return false;
1bf16443 473}
474
472ad383
DS
475static void pim_msdp_sa_local_add(struct pim_instance *pim,
476 struct prefix_sg *sg)
1bf16443 477{
d62a17ae 478 struct in_addr rp;
479 rp.s_addr = 0;
472ad383 480 pim_msdp_sa_ref(pim, NULL /* mp */, sg, rp);
3c72d654 481}
482
472ad383 483void pim_msdp_sa_local_del(struct pim_instance *pim, struct prefix_sg *sg)
3c72d654 484{
d62a17ae 485 struct pim_msdp_sa *sa;
3c72d654 486
472ad383 487 sa = pim_msdp_sa_find(pim, sg);
d62a17ae 488 if (sa) {
489 pim_msdp_sa_deref(sa, PIM_MSDP_SAF_LOCAL);
490 }
3c72d654 491}
492
36e466fe 493/* we need to be very cautious with this API as SA del too can trigger an
494 * upstream del and we will get stuck in a simple loop */
472ad383
DS
495static void pim_msdp_sa_local_del_on_up_del(struct pim_instance *pim,
496 struct prefix_sg *sg)
d62a17ae 497{
498 struct pim_msdp_sa *sa;
499
472ad383 500 sa = pim_msdp_sa_find(pim, sg);
d62a17ae 501 if (sa) {
502 if (PIM_DEBUG_MSDP_INTERNAL) {
503 zlog_debug("MSDP local sa %s del on up del",
504 sa->sg_str);
505 }
506
507 /* if there is no local reference escape */
508 if (!(sa->flags & PIM_MSDP_SAF_LOCAL)) {
509 if (PIM_DEBUG_MSDP_INTERNAL) {
510 zlog_debug("MSDP local sa %s del; no local ref",
511 sa->sg_str);
512 }
513 return;
514 }
515
516 if (sa->flags & PIM_MSDP_SAF_UP_DEL_IN_PROG) {
517 /* MSDP is the one that triggered the upstream del. if
518 * this happens
519 * we most certainly have a bug in the PIM upstream
520 * state machine. We
521 * will not have a local reference unless the KAT is
522 * running. And if the
523 * KAT is running there MUST be an additional
524 * source-stream reference to
525 * the flow. Accounting for such cases requires lot of
526 * changes; perhaps
527 * address this in the next release? - XXX */
528 zlog_err(
529 "MSDP sa %s SPT teardown is causing the local entry to be removed",
530 sa->sg_str);
531 return;
532 }
533
534 /* we are dropping the sa on upstream del we should not have an
535 * upstream reference */
536 if (sa->up) {
537 if (PIM_DEBUG_MSDP_INTERNAL) {
538 zlog_debug("MSDP local sa %s del; up non-NULL",
539 sa->sg_str);
540 }
541 sa->up = NULL;
542 }
543 pim_msdp_sa_deref(sa, PIM_MSDP_SAF_LOCAL);
544 }
36e466fe 545}
546
1bf16443 547/* Local SA qualification needs to be re-evaluated when -
548 * 1. KAT is started or stopped
549 * 2. on RP changes
550 * 3. Whenever FHR status changes for a (S,G) - XXX - currently there
551 * is no clear path to transition an entry out of "MASK_FHR" need
552 * to discuss this with Donald. May result in some strangeness if the
553 * FHR is also the RP.
554 * 4. When msdp_reg timer is started or stopped
555 */
d62a17ae 556void pim_msdp_sa_local_update(struct pim_upstream *up)
1bf16443 557{
472ad383
DS
558 struct pim_instance *pim = up->channel_oil->pim;
559
d62a17ae 560 if (pim_msdp_sa_local_add_ok(up)) {
472ad383 561 pim_msdp_sa_local_add(pim, &up->sg);
d62a17ae 562 } else {
472ad383 563 pim_msdp_sa_local_del(pim, &up->sg);
d62a17ae 564 }
1bf16443 565}
566
472ad383 567static void pim_msdp_sa_local_setup(struct pim_instance *pim)
3c72d654 568{
d62a17ae 569 struct pim_upstream *up;
570 struct listnode *up_node;
3c72d654 571
472ad383 572 for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, up_node, up)) {
d62a17ae 573 pim_msdp_sa_local_update(up);
574 }
3c72d654 575}
576
7667c556 577/* whenever the RP changes we need to re-evaluate the "local" SA-cache */
578/* XXX: needs to be tested */
472ad383 579void pim_msdp_i_am_rp_changed(struct pim_instance *pim)
d62a17ae 580{
581 struct listnode *sanode;
582 struct listnode *nextnode;
583 struct pim_msdp_sa *sa;
584
472ad383 585 if (!(pim->msdp.flags & PIM_MSDPF_ENABLE)) {
d62a17ae 586 /* if the feature is not enabled do nothing */
587 return;
588 }
589
590 if (PIM_DEBUG_MSDP_INTERNAL) {
591 zlog_debug("MSDP i_am_rp changed");
592 }
593
594 /* mark all local entries as stale */
472ad383 595 for (ALL_LIST_ELEMENTS_RO(pim->msdp.sa_list, sanode, sa)) {
d62a17ae 596 if (sa->flags & PIM_MSDP_SAF_LOCAL) {
597 sa->flags |= PIM_MSDP_SAF_STALE;
598 }
599 }
600
601 /* re-setup local SA entries */
472ad383 602 pim_msdp_sa_local_setup(pim);
d62a17ae 603
472ad383 604 for (ALL_LIST_ELEMENTS(pim->msdp.sa_list, sanode, nextnode, sa)) {
d62a17ae 605 /* purge stale SA entries */
606 if (sa->flags & PIM_MSDP_SAF_STALE) {
607 /* clear the stale flag; the entry may be kept even
608 * after
609 * "local-deref" */
610 sa->flags &= ~PIM_MSDP_SAF_STALE;
611 /* sa_deref can end up freeing the sa; so don't access
612 * contents after */
613 pim_msdp_sa_deref(sa, PIM_MSDP_SAF_LOCAL);
614 } else {
615 /* if the souce is still active check if we can
616 * influence SPT */
617 pim_msdp_sa_upstream_update(sa, NULL /* xg_up */,
618 "rp-change");
619 }
620 }
7667c556 621}
622
623/* We track the join state of (*, G) entries. If G has sources in the SA-cache
624 * we need to setup or teardown SPT when the JoinDesired status changes for
625 * (*, G) */
1eca8576
DS
626void pim_msdp_up_join_state_changed(struct pim_instance *pim,
627 struct pim_upstream *xg_up)
d62a17ae 628{
629 struct listnode *sanode;
630 struct pim_msdp_sa *sa;
631
632 if (PIM_DEBUG_MSDP_INTERNAL) {
633 zlog_debug("MSDP join state changed for %s", xg_up->sg_str);
634 }
635
636 /* If this is not really an XG entry just move on */
637 if ((xg_up->sg.src.s_addr != INADDR_ANY)
638 || (xg_up->sg.grp.s_addr == INADDR_ANY)) {
639 return;
640 }
641
642 /* XXX: Need to maintain SAs per-group to avoid all this unnecessary
643 * walking */
472ad383 644 for (ALL_LIST_ELEMENTS_RO(pim->msdp.sa_list, sanode, sa)) {
d62a17ae 645 if (sa->sg.grp.s_addr != xg_up->sg.grp.s_addr) {
646 continue;
647 }
648 pim_msdp_sa_upstream_update(sa, xg_up, "up-jp-change");
649 }
650}
651
472ad383 652static void pim_msdp_up_xg_del(struct pim_instance *pim, struct prefix_sg *sg)
d62a17ae 653{
654 struct listnode *sanode;
655 struct pim_msdp_sa *sa;
656
657 if (PIM_DEBUG_MSDP_INTERNAL) {
658 zlog_debug("MSDP %s del", pim_str_sg_dump(sg));
659 }
660
661 /* If this is not really an XG entry just move on */
662 if ((sg->src.s_addr != INADDR_ANY) || (sg->grp.s_addr == INADDR_ANY)) {
663 return;
664 }
665
666 /* XXX: Need to maintain SAs per-group to avoid all this unnecessary
667 * walking */
472ad383 668 for (ALL_LIST_ELEMENTS_RO(pim->msdp.sa_list, sanode, sa)) {
d62a17ae 669 if (sa->sg.grp.s_addr != sg->grp.s_addr) {
670 continue;
671 }
672 pim_msdp_sa_upstream_update(sa, NULL /* xg */, "up-jp-change");
673 }
674}
675
472ad383 676void pim_msdp_up_del(struct pim_instance *pim, struct prefix_sg *sg)
d62a17ae 677{
678 if (PIM_DEBUG_MSDP_INTERNAL) {
679 zlog_debug("MSDP up %s del", pim_str_sg_dump(sg));
680 }
681 if (sg->src.s_addr == INADDR_ANY) {
472ad383 682 pim_msdp_up_xg_del(pim, sg);
d62a17ae 683 } else {
472ad383 684 pim_msdp_sa_local_del_on_up_del(pim, sg);
d62a17ae 685 }
36e466fe 686}
687
3c72d654 688/* sa hash and peer list helpers */
d62a17ae 689static unsigned int pim_msdp_sa_hash_key_make(void *p)
3c72d654 690{
d62a17ae 691 struct pim_msdp_sa *sa = p;
3c72d654 692
d62a17ae 693 return (jhash_2words(sa->sg.src.s_addr, sa->sg.grp.s_addr, 0));
3c72d654 694}
695
d62a17ae 696static int pim_msdp_sa_hash_eq(const void *p1, const void *p2)
3c72d654 697{
d62a17ae 698 const struct pim_msdp_sa *sa1 = p1;
699 const struct pim_msdp_sa *sa2 = p2;
3c72d654 700
d62a17ae 701 return ((sa1->sg.src.s_addr == sa2->sg.src.s_addr)
702 && (sa1->sg.grp.s_addr == sa2->sg.grp.s_addr));
3c72d654 703}
704
d62a17ae 705static int pim_msdp_sa_comp(const void *p1, const void *p2)
3c72d654 706{
d62a17ae 707 const struct pim_msdp_sa *sa1 = p1;
708 const struct pim_msdp_sa *sa2 = p2;
3c72d654 709
d62a17ae 710 if (ntohl(sa1->sg.grp.s_addr) < ntohl(sa2->sg.grp.s_addr))
711 return -1;
3c72d654 712
d62a17ae 713 if (ntohl(sa1->sg.grp.s_addr) > ntohl(sa2->sg.grp.s_addr))
714 return 1;
3c72d654 715
d62a17ae 716 if (ntohl(sa1->sg.src.s_addr) < ntohl(sa2->sg.src.s_addr))
717 return -1;
3c72d654 718
d62a17ae 719 if (ntohl(sa1->sg.src.s_addr) > ntohl(sa2->sg.src.s_addr))
720 return 1;
3c72d654 721
d62a17ae 722 return 0;
3c72d654 723}
724
725/* RFC-3618:Sec-10.1.3 - Peer-RPF forwarding */
726/* XXX: this can use a bit of refining and extensions */
d62a17ae 727bool pim_msdp_peer_rpf_check(struct pim_msdp_peer *mp, struct in_addr rp)
3c72d654 728{
d62a17ae 729 if (mp->peer.s_addr == rp.s_addr) {
730 return true;
731 }
3c72d654 732
d62a17ae 733 return false;
3c72d654 734}
d62a17ae 735
3c72d654 736/************************ Peer session management **************************/
d62a17ae 737char *pim_msdp_state_dump(enum pim_msdp_peer_state state, char *buf,
738 int buf_size)
739{
740 switch (state) {
741 case PIM_MSDP_DISABLED:
742 snprintf(buf, buf_size, "%s", "disabled");
743 break;
744 case PIM_MSDP_INACTIVE:
745 snprintf(buf, buf_size, "%s", "inactive");
746 break;
747 case PIM_MSDP_LISTEN:
748 snprintf(buf, buf_size, "%s", "listen");
749 break;
750 case PIM_MSDP_CONNECTING:
751 snprintf(buf, buf_size, "%s", "connecting");
752 break;
753 case PIM_MSDP_ESTABLISHED:
754 snprintf(buf, buf_size, "%s", "established");
755 break;
756 default:
757 snprintf(buf, buf_size, "unk-%d", state);
758 }
759 return buf;
760}
761
762char *pim_msdp_peer_key_dump(struct pim_msdp_peer *mp, char *buf, int buf_size,
763 bool long_format)
764{
765 char peer_str[INET_ADDRSTRLEN];
766 char local_str[INET_ADDRSTRLEN];
767
768 pim_inet4_dump("<peer?>", mp->peer, peer_str, sizeof(peer_str));
769 if (long_format) {
770 pim_inet4_dump("<local?>", mp->local, local_str,
771 sizeof(local_str));
772 snprintf(buf, buf_size, "MSDP peer %s local %s mg %s", peer_str,
773 local_str, mp->mesh_group_name);
774 } else {
775 snprintf(buf, buf_size, "MSDP peer %s", peer_str);
776 }
777
778 return buf;
779}
780
781static void pim_msdp_peer_state_chg_log(struct pim_msdp_peer *mp)
782{
783 char state_str[PIM_MSDP_STATE_STRLEN];
784
785 pim_msdp_state_dump(mp->state, state_str, sizeof(state_str));
786 zlog_debug("MSDP peer %s state chg to %s", mp->key_str, state_str);
2a333e0f 787}
788
789/* MSDP Connection State Machine actions (defined in RFC-3618:Sec-11.2) */
790/* 11.2.A2: active peer - start connect retry timer; when the timer fires
791 * a tcp connection will be made */
d62a17ae 792static void pim_msdp_peer_connect(struct pim_msdp_peer *mp)
2a333e0f 793{
d62a17ae 794 mp->state = PIM_MSDP_CONNECTING;
795 if (PIM_DEBUG_MSDP_EVENTS) {
796 pim_msdp_peer_state_chg_log(mp);
797 }
2a333e0f 798
d62a17ae 799 pim_msdp_peer_cr_timer_setup(mp, true /* start */);
2a333e0f 800}
801
802/* 11.2.A3: passive peer - just listen for connections */
d62a17ae 803static void pim_msdp_peer_listen(struct pim_msdp_peer *mp)
2a333e0f 804{
d62a17ae 805 mp->state = PIM_MSDP_LISTEN;
806 if (PIM_DEBUG_MSDP_EVENTS) {
807 pim_msdp_peer_state_chg_log(mp);
808 }
2a333e0f 809
d62a17ae 810 /* this is interntionally asymmetric i.e. we set up listen-socket when
9d303b37
DL
811 * the
812 * first listening peer is configured; but don't bother tearing it down
813 * when
814 * all the peers go down */
472ad383 815 pim_msdp_sock_listen(mp->pim);
2a333e0f 816}
817
818/* 11.2.A4 and 11.2.A5: transition active or passive peer to
819 * established state */
d62a17ae 820void pim_msdp_peer_established(struct pim_msdp_peer *mp)
2a333e0f 821{
d62a17ae 822 if (mp->state != PIM_MSDP_ESTABLISHED) {
823 ++mp->est_flaps;
824 }
977d71cc 825
d62a17ae 826 mp->state = PIM_MSDP_ESTABLISHED;
827 mp->uptime = pim_time_monotonic_sec();
2a333e0f 828
d62a17ae 829 if (PIM_DEBUG_MSDP_EVENTS) {
830 pim_msdp_peer_state_chg_log(mp);
831 }
2a333e0f 832
d62a17ae 833 /* stop retry timer on active peers */
834 pim_msdp_peer_cr_timer_setup(mp, false /* start */);
2a333e0f 835
d62a17ae 836 /* send KA; start KA and hold timers */
837 pim_msdp_pkt_ka_tx(mp);
838 pim_msdp_peer_ka_timer_setup(mp, true /* start */);
839 pim_msdp_peer_hold_timer_setup(mp, true /* start */);
2a333e0f 840
d62a17ae 841 pim_msdp_pkt_sa_tx_to_one_peer(mp);
3c72d654 842
d62a17ae 843 PIM_MSDP_PEER_WRITE_ON(mp);
844 PIM_MSDP_PEER_READ_ON(mp);
2a333e0f 845}
846
847/* 11.2.A6, 11.2.A7 and 11.2.A8: shutdown the peer tcp connection */
d62a17ae 848void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer *mp, bool chg_state)
849{
850 if (chg_state) {
851 if (mp->state == PIM_MSDP_ESTABLISHED) {
852 ++mp->est_flaps;
853 }
854 mp->state = PIM_MSDP_INACTIVE;
855 if (PIM_DEBUG_MSDP_EVENTS) {
856 pim_msdp_peer_state_chg_log(mp);
857 }
858 }
859
860 if (PIM_DEBUG_MSDP_INTERNAL) {
861 zlog_debug("MSDP peer %s pim_msdp_peer_stop_tcp_conn",
862 mp->key_str);
863 }
864 /* stop read and write threads */
865 PIM_MSDP_PEER_READ_OFF(mp);
866 PIM_MSDP_PEER_WRITE_OFF(mp);
867
868 /* reset buffers */
869 mp->packet_size = 0;
870 if (mp->ibuf)
871 stream_reset(mp->ibuf);
872 if (mp->obuf)
873 stream_fifo_clean(mp->obuf);
874
875 /* stop all peer timers */
876 pim_msdp_peer_ka_timer_setup(mp, false /* start */);
877 pim_msdp_peer_cr_timer_setup(mp, false /* start */);
878 pim_msdp_peer_hold_timer_setup(mp, false /* start */);
879
880 /* close connection */
881 if (mp->fd >= 0) {
882 close(mp->fd);
883 mp->fd = -1;
884 }
2a333e0f 885}
886
887/* RFC-3618:Sec-5.6 - stop the peer tcp connection and startover */
d62a17ae 888void pim_msdp_peer_reset_tcp_conn(struct pim_msdp_peer *mp, const char *rc_str)
2a333e0f 889{
d62a17ae 890 if (PIM_DEBUG_EVENTS) {
891 zlog_debug("MSDP peer %s tcp reset %s", mp->key_str, rc_str);
892 snprintf(mp->last_reset, sizeof(mp->last_reset), "%s", rc_str);
893 }
2a333e0f 894
d62a17ae 895 /* close the connection and transition to listening or connecting */
896 pim_msdp_peer_stop_tcp_conn(mp, true /* chg_state */);
897 if (PIM_MSDP_PEER_IS_LISTENER(mp)) {
898 pim_msdp_peer_listen(mp);
899 } else {
900 pim_msdp_peer_connect(mp);
901 }
2a333e0f 902}
903
d62a17ae 904static void pim_msdp_peer_timer_expiry_log(struct pim_msdp_peer *mp,
905 const char *timer_str)
2a333e0f 906{
d62a17ae 907 zlog_debug("MSDP peer %s %s timer expired", mp->key_str, timer_str);
2a333e0f 908}
909
910/* RFC-3618:Sec-5.4 - peer hold timer */
d62a17ae 911static int pim_msdp_peer_hold_timer_cb(struct thread *t)
2a333e0f 912{
d62a17ae 913 struct pim_msdp_peer *mp;
2a333e0f 914
d62a17ae 915 mp = THREAD_ARG(t);
2a333e0f 916
d62a17ae 917 if (PIM_DEBUG_MSDP_EVENTS) {
918 pim_msdp_peer_timer_expiry_log(mp, "hold");
919 }
2a333e0f 920
d62a17ae 921 if (mp->state != PIM_MSDP_ESTABLISHED) {
922 return 0;
923 }
2a333e0f 924
d62a17ae 925 if (PIM_DEBUG_MSDP_EVENTS) {
926 pim_msdp_peer_state_chg_log(mp);
927 }
928 pim_msdp_peer_reset_tcp_conn(mp, "ht-expired");
929 return 0;
2a333e0f 930}
472ad383 931
d62a17ae 932static void pim_msdp_peer_hold_timer_setup(struct pim_msdp_peer *mp, bool start)
2a333e0f 933{
472ad383 934 struct pim_instance *pim = mp->pim;
d62a17ae 935 THREAD_OFF(mp->hold_timer);
936 if (start) {
472ad383 937 thread_add_timer(pim->msdp.master, pim_msdp_peer_hold_timer_cb,
2ad78035 938 mp, PIM_MSDP_PEER_HOLD_TIME, &mp->hold_timer);
d62a17ae 939 }
2a333e0f 940}
941
942
943/* RFC-3618:Sec-5.5 - peer keepalive timer */
d62a17ae 944static int pim_msdp_peer_ka_timer_cb(struct thread *t)
2a333e0f 945{
d62a17ae 946 struct pim_msdp_peer *mp;
2a333e0f 947
d62a17ae 948 mp = THREAD_ARG(t);
2a333e0f 949
d62a17ae 950 if (PIM_DEBUG_MSDP_EVENTS) {
951 pim_msdp_peer_timer_expiry_log(mp, "ka");
952 }
2a333e0f 953
d62a17ae 954 pim_msdp_pkt_ka_tx(mp);
955 pim_msdp_peer_ka_timer_setup(mp, true /* start */);
956 return 0;
2a333e0f 957}
d62a17ae 958static void pim_msdp_peer_ka_timer_setup(struct pim_msdp_peer *mp, bool start)
2a333e0f 959{
d62a17ae 960 THREAD_OFF(mp->ka_timer);
961 if (start) {
472ad383
DS
962 thread_add_timer(mp->pim->msdp.master,
963 pim_msdp_peer_ka_timer_cb, mp,
964 PIM_MSDP_PEER_KA_TIME, &mp->ka_timer);
d62a17ae 965 }
2a333e0f 966}
967
d62a17ae 968static void pim_msdp_peer_active_connect(struct pim_msdp_peer *mp)
2a333e0f 969{
d62a17ae 970 int rc;
971 ++mp->conn_attempts;
972 rc = pim_msdp_sock_connect(mp);
2a333e0f 973
d62a17ae 974 if (PIM_DEBUG_MSDP_INTERNAL) {
975 zlog_debug("MSDP peer %s pim_msdp_peer_active_connect: %d",
976 mp->key_str, rc);
977 }
2a333e0f 978
d62a17ae 979 switch (rc) {
980 case connect_error:
981 case -1:
982 /* connect failed restart the connect-retry timer */
983 pim_msdp_peer_cr_timer_setup(mp, true /* start */);
984 break;
2a333e0f 985
d62a17ae 986 case connect_success:
987 /* connect was sucessful move to established */
988 pim_msdp_peer_established(mp);
989 break;
2a333e0f 990
d62a17ae 991 case connect_in_progress:
992 /* for NB content we need to wait till sock is readable or
993 * writeable */
994 PIM_MSDP_PEER_WRITE_ON(mp);
995 PIM_MSDP_PEER_READ_ON(mp);
996 /* also restart connect-retry timer to reset the socket if
997 * connect is
998 * not sucessful */
999 pim_msdp_peer_cr_timer_setup(mp, true /* start */);
1000 break;
1001 }
2a333e0f 1002}
1003
1004/* RFC-3618:Sec-5.6 - connection retry on active peer */
d62a17ae 1005static int pim_msdp_peer_cr_timer_cb(struct thread *t)
2a333e0f 1006{
d62a17ae 1007 struct pim_msdp_peer *mp;
2a333e0f 1008
d62a17ae 1009 mp = THREAD_ARG(t);
2a333e0f 1010
d62a17ae 1011 if (PIM_DEBUG_MSDP_EVENTS) {
1012 pim_msdp_peer_timer_expiry_log(mp, "connect-retry");
1013 }
2a333e0f 1014
d62a17ae 1015 if (mp->state != PIM_MSDP_CONNECTING || PIM_MSDP_PEER_IS_LISTENER(mp)) {
1016 return 0;
1017 }
2a333e0f 1018
d62a17ae 1019 pim_msdp_peer_active_connect(mp);
1020 return 0;
2a333e0f 1021}
d62a17ae 1022static void pim_msdp_peer_cr_timer_setup(struct pim_msdp_peer *mp, bool start)
2a333e0f 1023{
d62a17ae 1024 THREAD_OFF(mp->cr_timer);
1025 if (start) {
472ad383
DS
1026 thread_add_timer(
1027 mp->pim->msdp.master, pim_msdp_peer_cr_timer_cb, mp,
1028 PIM_MSDP_PEER_CONNECT_RETRY_TIME, &mp->cr_timer);
d62a17ae 1029 }
2a333e0f 1030}
1031
1032/* if a valid packet is rxed from the peer we can restart hold timer */
d62a17ae 1033void pim_msdp_peer_pkt_rxed(struct pim_msdp_peer *mp)
2a333e0f 1034{
d62a17ae 1035 if (mp->state == PIM_MSDP_ESTABLISHED) {
1036 pim_msdp_peer_hold_timer_setup(mp, true /* start */);
1037 }
2a333e0f 1038}
1039
3c72d654 1040/* if a valid packet is txed to the peer we can restart ka timer and avoid
1041 * unnecessary ka noise in the network */
d62a17ae 1042void pim_msdp_peer_pkt_txed(struct pim_msdp_peer *mp)
3c72d654 1043{
d62a17ae 1044 if (mp->state == PIM_MSDP_ESTABLISHED) {
1045 pim_msdp_peer_ka_timer_setup(mp, true /* start */);
1046 if (PIM_DEBUG_MSDP_INTERNAL) {
1047 zlog_debug("MSDP ka timer restart on pkt tx to %s",
1048 mp->key_str);
1049 }
1050 }
3c72d654 1051}
1052
2a333e0f 1053static void pim_msdp_addr2su(union sockunion *su, struct in_addr addr)
1054{
d62a17ae 1055 sockunion_init(su);
1056 su->sin.sin_addr = addr;
1057 su->sin.sin_family = AF_INET;
2a333e0f 1058#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
d62a17ae 1059 su->sin.sin_len = sizeof(struct sockaddr_in);
2a333e0f 1060#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
1061}
1062
1063/* 11.2.A1: create a new peer and transition state to listen or connecting */
472ad383
DS
1064static enum pim_msdp_err pim_msdp_peer_new(struct pim_instance *pim,
1065 struct in_addr peer_addr,
d62a17ae 1066 struct in_addr local_addr,
1067 const char *mesh_group_name,
1068 struct pim_msdp_peer **mp_p)
1069{
1070 struct pim_msdp_peer *mp;
1071
472ad383 1072 pim_msdp_enable(pim);
d62a17ae 1073
1074 mp = XCALLOC(MTYPE_PIM_MSDP_PEER, sizeof(*mp));
1075 if (!mp) {
1076 zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__,
1077 sizeof(*mp));
1078 return PIM_MSDP_ERR_OOM;
1079 }
1080
472ad383 1081 mp->pim = pim;
d62a17ae 1082 mp->peer = peer_addr;
1083 pim_inet4_dump("<peer?>", mp->peer, mp->key_str, sizeof(mp->key_str));
1084 pim_msdp_addr2su(&mp->su_peer, mp->peer);
1085 mp->local = local_addr;
1086 /* XXX: originator_id setting needs to move to the mesh group */
472ad383 1087 pim->msdp.originator_id = local_addr;
d62a17ae 1088 pim_msdp_addr2su(&mp->su_local, mp->local);
1089 mp->mesh_group_name = XSTRDUP(MTYPE_PIM_MSDP_MG_NAME, mesh_group_name);
1090 mp->state = PIM_MSDP_INACTIVE;
1091 mp->fd = -1;
1092 strcpy(mp->last_reset, "-");
1093 /* higher IP address is listener */
1094 if (ntohl(mp->local.s_addr) > ntohl(mp->peer.s_addr)) {
1095 mp->flags |= PIM_MSDP_PEERF_LISTENER;
1096 }
1097
1098 /* setup packet buffers */
1099 mp->ibuf = stream_new(PIM_MSDP_MAX_PACKET_SIZE);
1100 mp->obuf = stream_fifo_new();
1101
1102 /* insert into misc tables for easy access */
472ad383
DS
1103 mp = hash_get(pim->msdp.peer_hash, mp, hash_alloc_intern);
1104 listnode_add_sort(pim->msdp.peer_list, mp);
d62a17ae 1105
1106 if (PIM_DEBUG_MSDP_EVENTS) {
1107 zlog_debug("MSDP peer %s created", mp->key_str);
1108
1109 pim_msdp_peer_state_chg_log(mp);
1110 }
1111
1112 /* fireup the connect state machine */
1113 if (PIM_MSDP_PEER_IS_LISTENER(mp)) {
1114 pim_msdp_peer_listen(mp);
1115 } else {
1116 pim_msdp_peer_connect(mp);
1117 }
1118 if (mp_p) {
1119 *mp_p = mp;
1120 }
1121 return PIM_MSDP_ERR_NONE;
1122}
1123
472ad383
DS
1124struct pim_msdp_peer *pim_msdp_peer_find(struct pim_instance *pim,
1125 struct in_addr peer_addr)
d62a17ae 1126{
1127 struct pim_msdp_peer lookup;
1128
1129 lookup.peer = peer_addr;
472ad383 1130 return hash_lookup(pim->msdp.peer_hash, &lookup);
2a333e0f 1131}
1132
1133/* add peer configuration if it doesn't already exist */
472ad383
DS
1134enum pim_msdp_err pim_msdp_peer_add(struct pim_instance *pim,
1135 struct in_addr peer_addr,
d62a17ae 1136 struct in_addr local_addr,
1137 const char *mesh_group_name,
1138 struct pim_msdp_peer **mp_p)
2a333e0f 1139{
d62a17ae 1140 struct pim_msdp_peer *mp;
2a333e0f 1141
d62a17ae 1142 if (mp_p) {
1143 *mp_p = NULL;
1144 }
977d71cc 1145
d62a17ae 1146 if (peer_addr.s_addr == local_addr.s_addr) {
1147 /* skip session setup if config is invalid */
1148 if (PIM_DEBUG_MSDP_EVENTS) {
1149 char peer_str[INET_ADDRSTRLEN];
977d71cc 1150
d62a17ae 1151 pim_inet4_dump("<peer?>", peer_addr, peer_str,
1152 sizeof(peer_str));
1153 zlog_debug("%s add skipped as DIP=SIP", peer_str);
1154 }
1155 return PIM_MSDP_ERR_SIP_EQ_DIP;
1156 }
977d71cc 1157
472ad383 1158 mp = pim_msdp_peer_find(pim, peer_addr);
d62a17ae 1159 if (mp) {
1160 if (mp_p) {
1161 *mp_p = mp;
1162 }
1163 return PIM_MSDP_ERR_PEER_EXISTS;
1164 }
2a333e0f 1165
472ad383
DS
1166 return pim_msdp_peer_new(pim, peer_addr, local_addr, mesh_group_name,
1167 mp_p);
2a333e0f 1168}
1169
1170/* release all mem associated with a peer */
d62a17ae 1171static void pim_msdp_peer_free(struct pim_msdp_peer *mp)
11128587 1172{
d62a17ae 1173 if (mp->ibuf) {
1174 stream_free(mp->ibuf);
1175 }
2a333e0f 1176
d62a17ae 1177 if (mp->obuf) {
1178 stream_fifo_free(mp->obuf);
1179 }
2a333e0f 1180
d62a17ae 1181 if (mp->mesh_group_name) {
1182 XFREE(MTYPE_PIM_MSDP_MG_NAME, mp->mesh_group_name);
1183 }
1184 XFREE(MTYPE_PIM_MSDP_PEER, mp);
2a333e0f 1185}
1186
1187/* delete the peer config */
d62a17ae 1188static enum pim_msdp_err pim_msdp_peer_do_del(struct pim_msdp_peer *mp)
2a333e0f 1189{
d62a17ae 1190 /* stop the tcp connection and shutdown all timers */
1191 pim_msdp_peer_stop_tcp_conn(mp, true /* chg_state */);
2a333e0f 1192
d62a17ae 1193 /* remove the session from various tables */
472ad383
DS
1194 listnode_delete(mp->pim->msdp.peer_list, mp);
1195 hash_release(mp->pim->msdp.peer_hash, mp);
2a333e0f 1196
d62a17ae 1197 if (PIM_DEBUG_MSDP_EVENTS) {
1198 zlog_debug("MSDP peer %s deleted", mp->key_str);
1199 }
2a333e0f 1200
d62a17ae 1201 /* free up any associated memory */
1202 pim_msdp_peer_free(mp);
2a333e0f 1203
d62a17ae 1204 return PIM_MSDP_ERR_NONE;
2a333e0f 1205}
1206
472ad383
DS
1207enum pim_msdp_err pim_msdp_peer_del(struct pim_instance *pim,
1208 struct in_addr peer_addr)
977d71cc 1209{
d62a17ae 1210 struct pim_msdp_peer *mp;
977d71cc 1211
472ad383 1212 mp = pim_msdp_peer_find(pim, peer_addr);
d62a17ae 1213 if (!mp) {
1214 return PIM_MSDP_ERR_NO_PEER;
1215 }
977d71cc 1216
d62a17ae 1217 return pim_msdp_peer_do_del(mp);
977d71cc 1218}
1219
2a333e0f 1220/* peer hash and peer list helpers */
d62a17ae 1221static unsigned int pim_msdp_peer_hash_key_make(void *p)
2a333e0f 1222{
d62a17ae 1223 struct pim_msdp_peer *mp = p;
1224 return (jhash_1word(mp->peer.s_addr, 0));
2a333e0f 1225}
1226
d62a17ae 1227static int pim_msdp_peer_hash_eq(const void *p1, const void *p2)
2a333e0f 1228{
d62a17ae 1229 const struct pim_msdp_peer *mp1 = p1;
1230 const struct pim_msdp_peer *mp2 = p2;
2a333e0f 1231
d62a17ae 1232 return (mp1->peer.s_addr == mp2->peer.s_addr);
2a333e0f 1233}
1234
d62a17ae 1235static int pim_msdp_peer_comp(const void *p1, const void *p2)
2a333e0f 1236{
d62a17ae 1237 const struct pim_msdp_peer *mp1 = p1;
1238 const struct pim_msdp_peer *mp2 = p2;
2a333e0f 1239
d62a17ae 1240 if (ntohl(mp1->peer.s_addr) < ntohl(mp2->peer.s_addr))
1241 return -1;
2a333e0f 1242
d62a17ae 1243 if (ntohl(mp1->peer.s_addr) > ntohl(mp2->peer.s_addr))
1244 return 1;
2a333e0f 1245
d62a17ae 1246 return 0;
2a333e0f 1247}
1248
977d71cc 1249/************************** Mesh group management **************************/
472ad383 1250static void pim_msdp_mg_free(struct pim_instance *pim, struct pim_msdp_mg *mg)
977d71cc 1251{
d62a17ae 1252 /* If the mesh-group has valid member or src_ip don't delete it */
1253 if (!mg || mg->mbr_cnt || (mg->src_ip.s_addr != INADDR_ANY)) {
1254 return;
1255 }
977d71cc 1256
d62a17ae 1257 if (PIM_DEBUG_MSDP_EVENTS) {
1258 zlog_debug("MSDP mesh-group %s deleted", mg->mesh_group_name);
1259 }
1260 if (mg->mesh_group_name)
1261 XFREE(MTYPE_PIM_MSDP_MG_NAME, mg->mesh_group_name);
977d71cc 1262
d62a17ae 1263 if (mg->mbr_list)
69ccd63e 1264 list_delete(mg->mbr_list);
b9b1e1f2 1265
d62a17ae 1266 XFREE(MTYPE_PIM_MSDP_MG, mg);
472ad383 1267 pim->msdp.mg = NULL;
977d71cc 1268}
1269
d62a17ae 1270static struct pim_msdp_mg *pim_msdp_mg_new(const char *mesh_group_name)
977d71cc 1271{
d62a17ae 1272 struct pim_msdp_mg *mg;
977d71cc 1273
d62a17ae 1274 mg = XCALLOC(MTYPE_PIM_MSDP_MG, sizeof(*mg));
1275 if (!mg) {
1276 zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__,
1277 sizeof(*mg));
1278 return NULL;
1279 }
977d71cc 1280
d62a17ae 1281 mg->mesh_group_name = XSTRDUP(MTYPE_PIM_MSDP_MG_NAME, mesh_group_name);
1282 mg->mbr_list = list_new();
1283 mg->mbr_list->del = (void (*)(void *))pim_msdp_mg_mbr_free;
1284 mg->mbr_list->cmp = (int (*)(void *, void *))pim_msdp_mg_mbr_comp;
977d71cc 1285
d62a17ae 1286 if (PIM_DEBUG_MSDP_EVENTS) {
1287 zlog_debug("MSDP mesh-group %s created", mg->mesh_group_name);
1288 }
1289 return mg;
977d71cc 1290}
1291
472ad383
DS
1292enum pim_msdp_err pim_msdp_mg_del(struct pim_instance *pim,
1293 const char *mesh_group_name)
977d71cc 1294{
472ad383 1295 struct pim_msdp_mg *mg = pim->msdp.mg;
d62a17ae 1296 struct pim_msdp_mg_mbr *mbr;
977d71cc 1297
d62a17ae 1298 if (!mg || strcmp(mg->mesh_group_name, mesh_group_name)) {
1299 return PIM_MSDP_ERR_NO_MG;
1300 }
977d71cc 1301
d62a17ae 1302 /* delete all the mesh-group members */
1303 while (!list_isempty(mg->mbr_list)) {
1304 mbr = listnode_head(mg->mbr_list);
1305 pim_msdp_mg_mbr_do_del(mg, mbr);
1306 }
977d71cc 1307
d62a17ae 1308 /* clear src ip */
1309 mg->src_ip.s_addr = INADDR_ANY;
977d71cc 1310
d62a17ae 1311 /* free up the mesh-group */
472ad383 1312 pim_msdp_mg_free(pim, mg);
d62a17ae 1313 return PIM_MSDP_ERR_NONE;
977d71cc 1314}
1315
472ad383
DS
1316static enum pim_msdp_err pim_msdp_mg_add(struct pim_instance *pim,
1317 const char *mesh_group_name)
977d71cc 1318{
472ad383
DS
1319 if (pim->msdp.mg) {
1320 if (!strcmp(pim->msdp.mg->mesh_group_name, mesh_group_name)) {
d62a17ae 1321 return PIM_MSDP_ERR_NONE;
1322 }
1323 /* currently only one mesh-group can exist at a time */
1324 return PIM_MSDP_ERR_MAX_MESH_GROUPS;
1325 }
977d71cc 1326
472ad383
DS
1327 pim->msdp.mg = pim_msdp_mg_new(mesh_group_name);
1328 if (!pim->msdp.mg) {
d62a17ae 1329 return PIM_MSDP_ERR_OOM;
1330 }
977d71cc 1331
d62a17ae 1332 return PIM_MSDP_ERR_NONE;
977d71cc 1333}
1334
d62a17ae 1335static int pim_msdp_mg_mbr_comp(const void *p1, const void *p2)
977d71cc 1336{
d62a17ae 1337 const struct pim_msdp_mg_mbr *mbr1 = p1;
1338 const struct pim_msdp_mg_mbr *mbr2 = p2;
977d71cc 1339
d62a17ae 1340 if (ntohl(mbr1->mbr_ip.s_addr) < ntohl(mbr2->mbr_ip.s_addr))
1341 return -1;
977d71cc 1342
d62a17ae 1343 if (ntohl(mbr1->mbr_ip.s_addr) > ntohl(mbr2->mbr_ip.s_addr))
1344 return 1;
977d71cc 1345
d62a17ae 1346 return 0;
977d71cc 1347}
1348
d62a17ae 1349static void pim_msdp_mg_mbr_free(struct pim_msdp_mg_mbr *mbr)
977d71cc 1350{
d62a17ae 1351 XFREE(MTYPE_PIM_MSDP_MG_MBR, mbr);
977d71cc 1352}
1353
472ad383
DS
1354static struct pim_msdp_mg_mbr *pim_msdp_mg_mbr_find(struct pim_instance *pim,
1355 struct in_addr mbr_ip)
977d71cc 1356{
d62a17ae 1357 struct pim_msdp_mg_mbr *mbr;
1358 struct listnode *mbr_node;
977d71cc 1359
472ad383 1360 if (!pim->msdp.mg) {
d62a17ae 1361 return NULL;
1362 }
1363 /* we can move this to a hash but considering that number of peers in
1364 * a mesh-group that seems like bit of an overkill */
472ad383 1365 for (ALL_LIST_ELEMENTS_RO(pim->msdp.mg->mbr_list, mbr_node, mbr)) {
d62a17ae 1366 if (mbr->mbr_ip.s_addr == mbr_ip.s_addr) {
1367 return mbr;
1368 }
1369 }
1370 return mbr;
977d71cc 1371}
1372
472ad383
DS
1373enum pim_msdp_err pim_msdp_mg_mbr_add(struct pim_instance *pim,
1374 const char *mesh_group_name,
d62a17ae 1375 struct in_addr mbr_ip)
977d71cc 1376{
d62a17ae 1377 int rc;
1378 struct pim_msdp_mg_mbr *mbr;
1379 struct pim_msdp_mg *mg;
977d71cc 1380
472ad383 1381 rc = pim_msdp_mg_add(pim, mesh_group_name);
d62a17ae 1382 if (rc != PIM_MSDP_ERR_NONE) {
1383 return rc;
1384 }
977d71cc 1385
472ad383
DS
1386 mg = pim->msdp.mg;
1387 mbr = pim_msdp_mg_mbr_find(pim, mbr_ip);
d62a17ae 1388 if (mbr) {
1389 return PIM_MSDP_ERR_MG_MBR_EXISTS;
1390 }
977d71cc 1391
d62a17ae 1392 mbr = XCALLOC(MTYPE_PIM_MSDP_MG_MBR, sizeof(*mbr));
1393 if (!mbr) {
1394 zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__,
1395 sizeof(*mbr));
1396 /* if there are no references to the mg free it */
472ad383 1397 pim_msdp_mg_free(pim, mg);
d62a17ae 1398 return PIM_MSDP_ERR_OOM;
1399 }
1400 mbr->mbr_ip = mbr_ip;
1401 listnode_add_sort(mg->mbr_list, mbr);
977d71cc 1402
d62a17ae 1403 /* if valid SIP has been configured add peer session */
1404 if (mg->src_ip.s_addr != INADDR_ANY) {
472ad383 1405 pim_msdp_peer_add(pim, mbr_ip, mg->src_ip, mesh_group_name,
d62a17ae 1406 &mbr->mp);
1407 }
977d71cc 1408
d62a17ae 1409 if (PIM_DEBUG_MSDP_EVENTS) {
1410 char ip_str[INET_ADDRSTRLEN];
1411 pim_inet4_dump("<mbr?>", mbr->mbr_ip, ip_str, sizeof(ip_str));
1412 zlog_debug("MSDP mesh-group %s mbr %s created",
1413 mg->mesh_group_name, ip_str);
1414 }
1415 ++mg->mbr_cnt;
1416 return PIM_MSDP_ERR_NONE;
977d71cc 1417}
1418
d62a17ae 1419static void pim_msdp_mg_mbr_do_del(struct pim_msdp_mg *mg,
1420 struct pim_msdp_mg_mbr *mbr)
977d71cc 1421{
d62a17ae 1422 /* Delete active peer session if any */
1423 if (mbr->mp) {
1424 pim_msdp_peer_do_del(mbr->mp);
1425 }
977d71cc 1426
d62a17ae 1427 listnode_delete(mg->mbr_list, mbr);
1428 if (PIM_DEBUG_MSDP_EVENTS) {
1429 char ip_str[INET_ADDRSTRLEN];
1430 pim_inet4_dump("<mbr?>", mbr->mbr_ip, ip_str, sizeof(ip_str));
1431 zlog_debug("MSDP mesh-group %s mbr %s deleted",
1432 mg->mesh_group_name, ip_str);
1433 }
1434 pim_msdp_mg_mbr_free(mbr);
1435 if (mg->mbr_cnt) {
1436 --mg->mbr_cnt;
1437 }
977d71cc 1438}
1439
472ad383
DS
1440enum pim_msdp_err pim_msdp_mg_mbr_del(struct pim_instance *pim,
1441 const char *mesh_group_name,
d62a17ae 1442 struct in_addr mbr_ip)
1443{
1444 struct pim_msdp_mg_mbr *mbr;
472ad383 1445 struct pim_msdp_mg *mg = pim->msdp.mg;
d62a17ae 1446
1447 if (!mg || strcmp(mg->mesh_group_name, mesh_group_name)) {
1448 return PIM_MSDP_ERR_NO_MG;
1449 }
1450
472ad383 1451 mbr = pim_msdp_mg_mbr_find(pim, mbr_ip);
d62a17ae 1452 if (!mbr) {
1453 return PIM_MSDP_ERR_NO_MG_MBR;
1454 }
1455
1456 pim_msdp_mg_mbr_do_del(mg, mbr);
1457 /* if there are no references to the mg free it */
472ad383 1458 pim_msdp_mg_free(pim, mg);
d62a17ae 1459
1460 return PIM_MSDP_ERR_NONE;
1461}
1462
472ad383 1463static void pim_msdp_mg_src_do_del(struct pim_instance *pim)
d62a17ae 1464{
1465 struct pim_msdp_mg_mbr *mbr;
1466 struct listnode *mbr_node;
472ad383 1467 struct pim_msdp_mg *mg = pim->msdp.mg;
d62a17ae 1468
1469 /* SIP is being removed - tear down all active peer sessions */
1470 for (ALL_LIST_ELEMENTS_RO(mg->mbr_list, mbr_node, mbr)) {
1471 if (mbr->mp) {
1472 pim_msdp_peer_do_del(mbr->mp);
1473 mbr->mp = NULL;
1474 }
1475 }
1476 if (PIM_DEBUG_MSDP_EVENTS) {
1477 zlog_debug("MSDP mesh-group %s src cleared",
1478 mg->mesh_group_name);
1479 }
1480}
1481
472ad383
DS
1482enum pim_msdp_err pim_msdp_mg_src_del(struct pim_instance *pim,
1483 const char *mesh_group_name)
d62a17ae 1484{
472ad383 1485 struct pim_msdp_mg *mg = pim->msdp.mg;
d62a17ae 1486
1487 if (!mg || strcmp(mg->mesh_group_name, mesh_group_name)) {
1488 return PIM_MSDP_ERR_NO_MG;
1489 }
1490
1491 if (mg->src_ip.s_addr != INADDR_ANY) {
1492 mg->src_ip.s_addr = INADDR_ANY;
472ad383 1493 pim_msdp_mg_src_do_del(pim);
d62a17ae 1494 /* if there are no references to the mg free it */
472ad383 1495 pim_msdp_mg_free(pim, mg);
d62a17ae 1496 }
1497 return PIM_MSDP_ERR_NONE;
1498}
1499
472ad383
DS
1500enum pim_msdp_err pim_msdp_mg_src_add(struct pim_instance *pim,
1501 const char *mesh_group_name,
d62a17ae 1502 struct in_addr src_ip)
1503{
1504 int rc;
1505 struct pim_msdp_mg_mbr *mbr;
1506 struct listnode *mbr_node;
1507 struct pim_msdp_mg *mg;
1508
1509 if (src_ip.s_addr == INADDR_ANY) {
472ad383 1510 pim_msdp_mg_src_del(pim, mesh_group_name);
d62a17ae 1511 return PIM_MSDP_ERR_NONE;
1512 }
1513
472ad383 1514 rc = pim_msdp_mg_add(pim, mesh_group_name);
d62a17ae 1515 if (rc != PIM_MSDP_ERR_NONE) {
1516 return rc;
1517 }
1518
472ad383 1519 mg = pim->msdp.mg;
d62a17ae 1520 if (mg->src_ip.s_addr != INADDR_ANY) {
472ad383 1521 pim_msdp_mg_src_do_del(pim);
d62a17ae 1522 }
1523 mg->src_ip = src_ip;
977d71cc 1524
d62a17ae 1525 for (ALL_LIST_ELEMENTS_RO(mg->mbr_list, mbr_node, mbr)) {
472ad383 1526 pim_msdp_peer_add(pim, mbr->mbr_ip, mg->src_ip, mesh_group_name,
d62a17ae 1527 &mbr->mp);
1528 }
977d71cc 1529
d62a17ae 1530 if (PIM_DEBUG_MSDP_EVENTS) {
1531 char ip_str[INET_ADDRSTRLEN];
1532 pim_inet4_dump("<src?>", mg->src_ip, ip_str, sizeof(ip_str));
1533 zlog_debug("MSDP mesh-group %s src %s set", mg->mesh_group_name,
1534 ip_str);
1535 }
1536 return PIM_MSDP_ERR_NONE;
977d71cc 1537}
1538
3c72d654 1539/*********************** MSDP feature APIs *********************************/
c9657fdc
DS
1540int pim_msdp_config_write_helper(struct pim_instance *pim, struct vty *vty,
1541 const char *spaces)
d62a17ae 1542{
1543 struct listnode *mbrnode;
1544 struct pim_msdp_mg_mbr *mbr;
472ad383 1545 struct pim_msdp_mg *mg = pim->msdp.mg;
d62a17ae 1546 char mbr_str[INET_ADDRSTRLEN];
1547 char src_str[INET_ADDRSTRLEN];
1548 int count = 0;
1549
1550 if (!mg) {
1551 return count;
1552 }
1553
1554 if (mg->src_ip.s_addr != INADDR_ANY) {
1555 pim_inet4_dump("<src?>", mg->src_ip, src_str, sizeof(src_str));
c9657fdc 1556 vty_out(vty, "%sip msdp mesh-group %s source %s\n", spaces,
d62a17ae 1557 mg->mesh_group_name, src_str);
1558 ++count;
1559 }
1560
1561 for (ALL_LIST_ELEMENTS_RO(mg->mbr_list, mbrnode, mbr)) {
1562 pim_inet4_dump("<mbr?>", mbr->mbr_ip, mbr_str, sizeof(mbr_str));
c9657fdc 1563 vty_out(vty, "%sip msdp mesh-group %s member %s\n", spaces,
d62a17ae 1564 mg->mesh_group_name, mbr_str);
1565 ++count;
1566 }
1567 return count;
3c72d654 1568}
1569
472ad383
DS
1570int pim_msdp_config_write(struct vty *vty)
1571{
c9657fdc 1572 return pim_msdp_config_write_helper(pimg, vty, "");
472ad383
DS
1573}
1574
3c72d654 1575/* Enable feature including active/periodic timers etc. on the first peer
1576 * config. Till then MSDP should just stay quiet. */
472ad383 1577static void pim_msdp_enable(struct pim_instance *pim)
3c72d654 1578{
472ad383 1579 if (pim->msdp.flags & PIM_MSDPF_ENABLE) {
d62a17ae 1580 /* feature is already enabled */
1581 return;
1582 }
472ad383
DS
1583 pim->msdp.flags |= PIM_MSDPF_ENABLE;
1584 pim->msdp.work_obuf = stream_new(PIM_MSDP_MAX_PACKET_SIZE);
1585 pim_msdp_sa_adv_timer_setup(pim, true /* start */);
d62a17ae 1586 /* setup sa cache based on local sources */
472ad383 1587 pim_msdp_sa_local_setup(pim);
3c72d654 1588}
1589
2a333e0f 1590/* MSDP init */
64c86530 1591void pim_msdp_init(struct pim_instance *pim, struct thread_master *master)
2a333e0f 1592{
472ad383 1593 pim->msdp.master = master;
9fb302f4 1594 char hash_name[64];
3c72d654 1595
9fb302f4 1596 snprintf(hash_name, 64, "PIM %s MSDP Peer Hash", pim->vrf->name);
2ad78035 1597 pim->msdp.peer_hash = hash_create(pim_msdp_peer_hash_key_make,
9fb302f4 1598 pim_msdp_peer_hash_eq, hash_name);
2ad78035
DS
1599 pim->msdp.peer_list = list_new();
1600 pim->msdp.peer_list->del = (void (*)(void *))pim_msdp_peer_free;
1601 pim->msdp.peer_list->cmp = (int (*)(void *, void *))pim_msdp_peer_comp;
3c72d654 1602
9fb302f4 1603 snprintf(hash_name, 64, "PIM %s MSDP SA Hash", pim->vrf->name);
2ad78035 1604 pim->msdp.sa_hash = hash_create(pim_msdp_sa_hash_key_make,
9fb302f4 1605 pim_msdp_sa_hash_eq, hash_name);
2ad78035
DS
1606 pim->msdp.sa_list = list_new();
1607 pim->msdp.sa_list->del = (void (*)(void *))pim_msdp_sa_free;
1608 pim->msdp.sa_list->cmp = (int (*)(void *, void *))pim_msdp_sa_comp;
2a333e0f 1609}
1610
1611/* counterpart to MSDP init; XXX: unused currently */
2ad78035 1612void pim_msdp_exit(struct pim_instance *pim)
2a333e0f 1613{
d62a17ae 1614 /* XXX: stop listener and delete all peer sessions */
2a333e0f 1615
2ad78035
DS
1616 if (pim->msdp.peer_hash) {
1617 hash_free(pim->msdp.peer_hash);
1618 pim->msdp.peer_hash = NULL;
d62a17ae 1619 }
2a333e0f 1620
2ad78035 1621 if (pim->msdp.peer_list) {
3da8a099 1622 list_delete(pim->msdp.peer_list);
2ad78035 1623 pim->msdp.peer_list = NULL;
d62a17ae 1624 }
3da8a099
DS
1625
1626 if (pim->msdp.sa_hash) {
1627 hash_free(pim->msdp.sa_hash);
1628 pim->msdp.sa_hash = NULL;
1629 }
1630
1631 if (pim->msdp.sa_list) {
1632 list_delete(pim->msdp.sa_list);
1633 pim->msdp.sa_list = NULL;
1634 }
11128587 1635}