]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_register.c
Merge pull request #11158 from cyberstormdotmu/master
[mirror_frr.git] / pimd / pim_register.c
1 /*
2 * PIM for Quagga
3 * Copyright (C) 2015 Cumulus Networks, Inc.
4 * Donald Sharp
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "log.h"
24 #include "if.h"
25 #include "thread.h"
26 #include "prefix.h"
27 #include "vty.h"
28 #include "plist.h"
29
30 #include "pimd.h"
31 #include "pim_mroute.h"
32 #include "pim_iface.h"
33 #include "pim_msg.h"
34 #include "pim_pim.h"
35 #include "pim_str.h"
36 #include "pim_rp.h"
37 #include "pim_register.h"
38 #include "pim_upstream.h"
39 #include "pim_br.h"
40 #include "pim_rpf.h"
41 #include "pim_oil.h"
42 #include "pim_zebra.h"
43 #include "pim_join.h"
44 #include "pim_util.h"
45 #include "pim_ssm.h"
46 #include "pim_vxlan.h"
47 #include "pim_addr.h"
48
49 struct thread *send_test_packet_timer = NULL;
50
51 void pim_register_join(struct pim_upstream *up)
52 {
53 struct pim_instance *pim = up->channel_oil->pim;
54
55 if (pim_is_grp_ssm(pim, up->sg.grp)) {
56 if (PIM_DEBUG_PIM_EVENTS)
57 zlog_debug("%s register setup skipped as group is SSM",
58 up->sg_str);
59 return;
60 }
61
62 pim_channel_add_oif(up->channel_oil, pim->regiface,
63 PIM_OIF_FLAG_PROTO_PIM, __func__);
64 up->reg_state = PIM_REG_JOIN;
65 pim_vxlan_update_sg_reg_state(pim, up, true);
66 }
67
68 void pim_register_stop_send(struct interface *ifp, pim_sgaddr *sg, pim_addr src,
69 pim_addr originator)
70 {
71 struct pim_interface *pinfo;
72 unsigned char buffer[10000];
73 unsigned int b1length = 0;
74 unsigned int length;
75 uint8_t *b1;
76
77 if (PIM_DEBUG_PIM_REG) {
78 zlog_debug("Sending Register stop for %pSG to %pPA on %s", sg,
79 &originator, ifp->name);
80 }
81
82 memset(buffer, 0, 10000);
83 b1 = (uint8_t *)buffer + PIM_MSG_REGISTER_STOP_LEN;
84
85 length = pim_encode_addr_group(b1, AFI_IP, 0, 0, sg->grp);
86 b1length += length;
87 b1 += length;
88
89 length = pim_encode_addr_ucast(b1, sg->src);
90 b1length += length;
91
92 pim_msg_build_header(src, originator, buffer,
93 b1length + PIM_MSG_REGISTER_STOP_LEN,
94 PIM_MSG_TYPE_REG_STOP, false);
95
96 pinfo = (struct pim_interface *)ifp->info;
97 if (!pinfo) {
98 if (PIM_DEBUG_PIM_TRACE)
99 zlog_debug("%s: No pinfo!", __func__);
100 return;
101 }
102 if (pim_msg_send(pinfo->pim_sock_fd, src, originator, buffer,
103 b1length + PIM_MSG_REGISTER_STOP_LEN, ifp)) {
104 if (PIM_DEBUG_PIM_TRACE) {
105 zlog_debug(
106 "%s: could not send PIM register stop message on interface %s",
107 __func__, ifp->name);
108 }
109 }
110
111 if (!pinfo->pim_passive_enable)
112 ++pinfo->pim_ifstat_reg_stop_send;
113 }
114
115 static void pim_reg_stop_upstream(struct pim_instance *pim,
116 struct pim_upstream *up)
117 {
118 switch (up->reg_state) {
119 case PIM_REG_NOINFO:
120 case PIM_REG_PRUNE:
121 return;
122 case PIM_REG_JOIN:
123 up->reg_state = PIM_REG_PRUNE;
124 pim_channel_del_oif(up->channel_oil, pim->regiface,
125 PIM_OIF_FLAG_PROTO_PIM, __func__);
126 pim_upstream_start_register_stop_timer(up, 0);
127 pim_vxlan_update_sg_reg_state(pim, up, false);
128 break;
129 case PIM_REG_JOIN_PENDING:
130 up->reg_state = PIM_REG_PRUNE;
131 pim_upstream_start_register_stop_timer(up, 0);
132 return;
133 }
134 }
135
136 int pim_register_stop_recv(struct interface *ifp, uint8_t *buf, int buf_size)
137 {
138 struct pim_interface *pim_ifp = ifp->info;
139 struct pim_instance *pim = pim_ifp->pim;
140 struct pim_upstream *up = NULL;
141 struct pim_rpf *rp;
142 pim_addr rpf_addr;
143 pim_sgaddr sg;
144 struct listnode *up_node;
145 struct pim_upstream *child;
146 bool wrong_af = false;
147 bool handling_star = false;
148 int l;
149
150 if (pim_ifp->pim_passive_enable) {
151 if (PIM_DEBUG_PIM_PACKETS)
152 zlog_debug(
153 "skip receiving PIM message on passive interface %s",
154 ifp->name);
155 return 0;
156 }
157
158 ++pim_ifp->pim_ifstat_reg_stop_recv;
159
160 memset(&sg, 0, sizeof(sg));
161 l = pim_parse_addr_group(&sg, buf, buf_size);
162 buf += l;
163 buf_size -= l;
164 pim_parse_addr_ucast(&sg.src, buf, buf_size, &wrong_af);
165
166 if (wrong_af) {
167 zlog_err("invalid AF in Register-Stop on %s", ifp->name);
168 return -1;
169 }
170
171
172 if (PIM_DEBUG_PIM_REG)
173 zlog_debug("Received Register stop for %pSG", &sg);
174
175 rp = RP(pim_ifp->pim, sg.grp);
176 if (rp) {
177 rpf_addr = pim_addr_from_prefix(&rp->rpf_addr);
178 if (pim_addr_cmp(sg.src, rpf_addr) == 0) {
179 handling_star = true;
180 sg.src = PIMADDR_ANY;
181 }
182 }
183
184 /*
185 * RFC 7761 Sec 4.4.1
186 * Handling Register-Stop(*,G) Messages at the DR:
187 * A Register-Stop(*,G) should be treated as a
188 * Register-Stop(S,G) for all (S,G) Register state
189 * machines that are not in the NoInfo state.
190 */
191 up = pim_upstream_find(pim, &sg);
192 if (up) {
193 /*
194 * If the upstream find actually found a particular
195 * S,G then we *know* that the following for loop
196 * is not going to execute and this is ok
197 */
198 for (ALL_LIST_ELEMENTS_RO(up->sources, up_node, child)) {
199 if (PIM_DEBUG_PIM_REG)
200 zlog_debug("Executing Reg stop for %s",
201 child->sg_str);
202
203 pim_reg_stop_upstream(pim, child);
204 }
205
206 if (PIM_DEBUG_PIM_REG)
207 zlog_debug("Executing Reg stop for %s", up->sg_str);
208 pim_reg_stop_upstream(pim, up);
209 } else {
210 if (!handling_star)
211 return 0;
212 /*
213 * Unfortunately pim was unable to find a *,G
214 * but pim may still actually have individual
215 * S,G's that need to be processed. In that
216 * case pim must do the expensive walk to find
217 * and stop
218 */
219 frr_each (rb_pim_upstream, &pim->upstream_head, up) {
220 if (pim_addr_cmp(up->sg.grp, sg.grp) == 0) {
221 if (PIM_DEBUG_PIM_REG)
222 zlog_debug("Executing Reg stop for %s",
223 up->sg_str);
224 pim_reg_stop_upstream(pim, up);
225 }
226 }
227 }
228
229 return 0;
230 }
231
232 void pim_register_send(const uint8_t *buf, int buf_size, pim_addr src,
233 struct pim_rpf *rpg, int null_register,
234 struct pim_upstream *up)
235 {
236 unsigned char buffer[10000];
237 unsigned char *b1;
238 struct pim_interface *pinfo;
239 struct interface *ifp;
240 pim_addr dst = pim_addr_from_prefix(&rpg->rpf_addr);
241
242 if (PIM_DEBUG_PIM_REG) {
243 zlog_debug("Sending %s %sRegister Packet to %pPA", up->sg_str,
244 null_register ? "NULL " : "", &dst);
245 }
246
247 ifp = rpg->source_nexthop.interface;
248 if (!ifp) {
249 if (PIM_DEBUG_PIM_REG)
250 zlog_debug("%s: No interface to transmit register on",
251 __func__);
252 return;
253 }
254 pinfo = (struct pim_interface *)ifp->info;
255 if (!pinfo) {
256 if (PIM_DEBUG_PIM_REG)
257 zlog_debug(
258 "%s: Interface: %s not configured for pim to transmit on!",
259 __func__, ifp->name);
260 return;
261 }
262
263 if (PIM_DEBUG_PIM_REG) {
264 zlog_debug("%s: Sending %s %sRegister Packet to %pPA on %s",
265 __func__, up->sg_str, null_register ? "NULL " : "",
266 &dst, ifp->name);
267 }
268
269 memset(buffer, 0, 10000);
270 b1 = buffer + PIM_MSG_HEADER_LEN;
271 *b1 |= null_register << 6;
272 b1 = buffer + PIM_MSG_REGISTER_LEN;
273
274 memcpy(b1, (const unsigned char *)buf, buf_size);
275
276 pim_msg_build_header(src, dst, buffer, buf_size + PIM_MSG_REGISTER_LEN,
277 PIM_MSG_TYPE_REGISTER, false);
278
279 if (!pinfo->pim_passive_enable)
280 ++pinfo->pim_ifstat_reg_send;
281
282 if (pim_msg_send(pinfo->pim_sock_fd, src, dst, buffer,
283 buf_size + PIM_MSG_REGISTER_LEN, ifp)) {
284 if (PIM_DEBUG_PIM_TRACE) {
285 zlog_debug(
286 "%s: could not send PIM register message on interface %s",
287 __func__, ifp->name);
288 }
289 return;
290 }
291 }
292
293 #if PIM_IPV == 4
294 void pim_null_register_send(struct pim_upstream *up)
295 {
296 struct ip ip_hdr;
297 struct pim_interface *pim_ifp;
298 struct pim_rpf *rpg;
299 pim_addr src;
300
301 pim_ifp = up->rpf.source_nexthop.interface->info;
302 if (!pim_ifp) {
303 if (PIM_DEBUG_PIM_TRACE)
304 zlog_debug(
305 "%s: Cannot send null-register for %s no valid iif",
306 __func__, up->sg_str);
307 return;
308 }
309
310 rpg = RP(pim_ifp->pim, up->sg.grp);
311 if (!rpg) {
312 if (PIM_DEBUG_PIM_TRACE)
313 zlog_debug(
314 "%s: Cannot send null-register for %s no RPF to the RP",
315 __func__, up->sg_str);
316 return;
317 }
318
319 memset(&ip_hdr, 0, sizeof(ip_hdr));
320 ip_hdr.ip_p = PIM_IP_PROTO_PIM;
321 ip_hdr.ip_hl = 5;
322 ip_hdr.ip_v = 4;
323 ip_hdr.ip_src = up->sg.src;
324 ip_hdr.ip_dst = up->sg.grp;
325 ip_hdr.ip_len = htons(20);
326
327 /* checksum is broken */
328 src = pim_ifp->primary_address;
329 if (PIM_UPSTREAM_FLAG_TEST_SRC_VXLAN_ORIG(up->flags)) {
330 if (!pim_vxlan_get_register_src(pim_ifp->pim, up, &src)) {
331 if (PIM_DEBUG_PIM_TRACE)
332 zlog_debug(
333 "%s: Cannot send null-register for %s vxlan-aa PIP unavailable",
334 __func__, up->sg_str);
335 return;
336 }
337 }
338 pim_register_send((uint8_t *)&ip_hdr, sizeof(struct ip), src, rpg, 1,
339 up);
340 }
341 #else
342 void pim_null_register_send(struct pim_upstream *up)
343 {
344 struct ip6_hdr ip6_hdr;
345 struct pim_msg_header pim_msg_header;
346 struct pim_interface *pim_ifp;
347 struct pim_rpf *rpg;
348 pim_addr src;
349 unsigned char buffer[sizeof(ip6_hdr) + sizeof(pim_msg_header)];
350 struct ipv6_ph ph;
351
352 pim_ifp = up->rpf.source_nexthop.interface->info;
353 if (!pim_ifp) {
354 if (PIM_DEBUG_PIM_TRACE)
355 zlog_debug(
356 "Cannot send null-register for %s no valid iif",
357 up->sg_str);
358 return;
359 }
360
361 rpg = RP(pim_ifp->pim, up->sg.grp);
362 if (!rpg) {
363 if (PIM_DEBUG_PIM_TRACE)
364 zlog_debug(
365 "Cannot send null-register for %s no RPF to the RP",
366 up->sg_str);
367 return;
368 }
369
370 memset(&ip6_hdr, 0, sizeof(ip6_hdr));
371 ip6_hdr.ip6_nxt = PIM_IP_PROTO_PIM;
372 ip6_hdr.ip6_plen = PIM_MSG_HEADER_LEN;
373 ip6_hdr.ip6_vfc = 6 << 4;
374 ip6_hdr.ip6_hlim = MAXTTL;
375 ip6_hdr.ip6_src = up->sg.src;
376 ip6_hdr.ip6_dst = up->sg.grp;
377
378 memset(buffer, 0, (sizeof(ip6_hdr) + sizeof(pim_msg_header)));
379 memcpy(buffer, &ip6_hdr, sizeof(ip6_hdr));
380
381 pim_msg_header.ver = 0;
382 pim_msg_header.type = 0;
383 pim_msg_header.reserved = 0;
384
385 pim_msg_header.checksum = 0;
386
387 ph.src = up->sg.src;
388 ph.dst = up->sg.grp;
389 ph.ulpl = htonl(PIM_MSG_HEADER_LEN);
390 ph.next_hdr = IPPROTO_PIM;
391 pim_msg_header.checksum =
392 in_cksum_with_ph6(&ph, &pim_msg_header, PIM_MSG_HEADER_LEN);
393
394 memcpy(buffer + sizeof(ip6_hdr), &pim_msg_header, PIM_MSG_HEADER_LEN);
395
396
397 src = pim_ifp->primary_address;
398 pim_register_send((uint8_t *)buffer,
399 sizeof(ip6_hdr) + PIM_MSG_HEADER_LEN, src, rpg, 1,
400 up);
401 }
402 #endif
403
404 /*
405 * 4.4.2 Receiving Register Messages at the RP
406 *
407 * When an RP receives a Register message, the course of action is
408 * decided according to the following pseudocode:
409 *
410 * packet_arrives_on_rp_tunnel( pkt ) {
411 * if( outer.dst is not one of my addresses ) {
412 * drop the packet silently.
413 * # Note: this may be a spoofing attempt
414 * }
415 * if( I_am_RP(G) AND outer.dst == RP(G) ) {
416 * sentRegisterStop = false;
417 * if ( register.borderbit == true ) {
418 * if ( PMBR(S,G) == unknown ) {
419 * PMBR(S,G) = outer.src
420 * } else if ( outer.src != PMBR(S,G) ) {
421 * send Register-Stop(S,G) to outer.src
422 * drop the packet silently.
423 * }
424 * }
425 * if ( SPTbit(S,G) OR
426 * ( SwitchToSptDesired(S,G) AND
427 * ( inherited_olist(S,G) == NULL ))) {
428 * send Register-Stop(S,G) to outer.src
429 * sentRegisterStop = true;
430 * }
431 * if ( SPTbit(S,G) OR SwitchToSptDesired(S,G) ) {
432 * if ( sentRegisterStop == true ) {
433 * set KeepaliveTimer(S,G) to RP_Keepalive_Period;
434 * } else {
435 * set KeepaliveTimer(S,G) to Keepalive_Period;
436 * }
437 * }
438 * if( !SPTbit(S,G) AND ! pkt.NullRegisterBit ) {
439 * decapsulate and forward the inner packet to
440 * inherited_olist(S,G,rpt) # Note (+)
441 * }
442 * } else {
443 * send Register-Stop(S,G) to outer.src
444 * # Note (*)
445 * }
446 * }
447 */
448 int pim_register_recv(struct interface *ifp, pim_addr dest_addr,
449 pim_addr src_addr, uint8_t *tlv_buf, int tlv_buf_size)
450 {
451 int sentRegisterStop = 0;
452 const void *ip_hdr;
453 pim_sgaddr sg;
454 uint32_t *bits;
455 int i_am_rp = 0;
456 struct pim_interface *pim_ifp = ifp->info;
457 struct pim_instance *pim = pim_ifp->pim;
458 pim_addr rp_addr;
459
460 if (pim_ifp->pim_passive_enable) {
461 if (PIM_DEBUG_PIM_PACKETS)
462 zlog_debug(
463 "skip receiving PIM message on passive interface %s",
464 ifp->name);
465 return 0;
466 }
467
468 #define PIM_MSG_REGISTER_BIT_RESERVED_LEN 4
469 ip_hdr = (tlv_buf + PIM_MSG_REGISTER_BIT_RESERVED_LEN);
470
471 if (!if_address_is_local(&dest_addr, PIM_AF, pim->vrf->vrf_id)) {
472 if (PIM_DEBUG_PIM_REG)
473 zlog_debug(
474 "%s: Received Register message for destination address: %pPA that I do not own",
475 __func__, &dest_addr);
476 return 0;
477 }
478
479 ++pim_ifp->pim_ifstat_reg_recv;
480
481 /*
482 * Please note this is not drawn to get the correct bit/data size
483 *
484 * The entirety of the REGISTER packet looks like this:
485 * -------------------------------------------------------------
486 * | Ver | Type | Reserved | Checksum |
487 * |-----------------------------------------------------------|
488 * |B|N| Reserved 2 |
489 * |-----------------------------------------------------------|
490 * | Encap | IP HDR |
491 * | Mcast | |
492 * | Packet |--------------------------------------------------|
493 * | | Mcast Data |
494 * | | |
495 * ...
496 *
497 * tlv_buf when received from the caller points at the B bit
498 * We need to know the inner source and dest
499 */
500 bits = (uint32_t *)tlv_buf;
501
502 /*
503 * tlv_buf points to the start of the |B|N|... Reserved
504 * Line above. So we need to add 4 bytes to get to the
505 * start of the actual Encapsulated data.
506 */
507 memset(&sg, 0, sizeof(sg));
508 sg = pim_sgaddr_from_iphdr(ip_hdr);
509
510 #if PIM_IPV == 6
511 /*
512 * According to RFC section 4.9.3, If Dummy PIM Header is included
513 * in NULL Register as a payload there would be two PIM headers.
514 * The inner PIM Header's checksum field should also be validated
515 * in addition to the outer PIM Header's checksum. Validation of
516 * inner PIM header checksum is done here.
517 */
518 if ((*bits & PIM_REGISTER_NR_BIT) &&
519 ((tlv_buf_size - PIM_MSG_REGISTER_BIT_RESERVED_LEN) >
520 (int)sizeof(struct ip6_hdr))) {
521 uint16_t computed_checksum;
522 uint16_t received_checksum;
523 struct ipv6_ph ph;
524 struct pim_msg_header *header;
525
526 header = (struct pim_msg_header
527 *)(tlv_buf +
528 PIM_MSG_REGISTER_BIT_RESERVED_LEN +
529 sizeof(struct ip6_hdr));
530 ph.src = sg.src;
531 ph.dst = sg.grp;
532 ph.ulpl = htonl(PIM_MSG_HEADER_LEN);
533 ph.next_hdr = IPPROTO_PIM;
534
535 received_checksum = header->checksum;
536
537 header->checksum = 0;
538 computed_checksum = in_cksum_with_ph6(
539 &ph, header, htonl(PIM_MSG_HEADER_LEN));
540
541 if (computed_checksum != received_checksum) {
542 if (PIM_DEBUG_PIM_PACKETS)
543 zlog_debug(
544 "Ignoring Null Register message%pSG from %pPA due to bad checksum in Encapsulated dummy PIM header",
545 &sg, &src_addr);
546 return 0;
547 }
548 }
549 #endif
550 i_am_rp = I_am_RP(pim, sg.grp);
551
552 if (PIM_DEBUG_PIM_REG)
553 zlog_debug(
554 "Received Register message%pSG from %pPA on %s, rp: %d",
555 &sg, &src_addr, ifp->name, i_am_rp);
556
557 if (pim_is_grp_ssm(pim_ifp->pim, sg.grp)) {
558 if (pim_addr_is_any(sg.src)) {
559 zlog_warn(
560 "%s: Received Register message for Group(%pPA) is now in SSM, dropping the packet",
561 __func__, &sg.grp);
562 /* Drop Packet Silently */
563 return 0;
564 }
565 }
566
567 rp_addr = pim_addr_from_prefix(&(RP(pim, sg.grp))->rpf_addr);
568 if (i_am_rp && (!pim_addr_cmp(dest_addr, rp_addr))) {
569 sentRegisterStop = 0;
570
571 if (pim->register_plist) {
572 struct prefix_list *plist;
573 struct prefix src;
574
575 plist = prefix_list_lookup(PIM_AFI,
576 pim->register_plist);
577
578 pim_addr_to_prefix(&src, sg.src);
579
580 if (prefix_list_apply(plist, &src) == PREFIX_DENY) {
581 pim_register_stop_send(ifp, &sg, dest_addr,
582 src_addr);
583 if (PIM_DEBUG_PIM_PACKETS)
584 zlog_debug(
585 "%s: Sending register-stop to %pPA for %pSG due to prefix-list denial, dropping packet",
586 __func__, &src_addr, &sg);
587
588 return 0;
589 }
590 }
591
592 if (*bits & PIM_REGISTER_BORDER_BIT) {
593 pim_addr pimbr = pim_br_get_pmbr(&sg);
594 if (PIM_DEBUG_PIM_PACKETS)
595 zlog_debug(
596 "%s: Received Register message with Border bit set",
597 __func__);
598
599 if (pim_addr_is_any(pimbr))
600 pim_br_set_pmbr(&sg, src_addr);
601 else if (pim_addr_cmp(src_addr, pimbr)) {
602 pim_register_stop_send(ifp, &sg, dest_addr,
603 src_addr);
604 if (PIM_DEBUG_PIM_PACKETS)
605 zlog_debug(
606 "%s: Sending register-Stop to %s and dropping mr. packet",
607 __func__, "Sender");
608 /* Drop Packet Silently */
609 return 0;
610 }
611 }
612
613 struct pim_upstream *upstream = pim_upstream_find(pim, &sg);
614 /*
615 * If we don't have a place to send ignore the packet
616 */
617 if (!upstream) {
618 upstream = pim_upstream_add(
619 pim, &sg, ifp,
620 PIM_UPSTREAM_FLAG_MASK_SRC_STREAM, __func__,
621 NULL);
622 if (!upstream) {
623 zlog_warn("Failure to create upstream state");
624 return 1;
625 }
626
627 upstream->upstream_register = src_addr;
628 } else {
629 /*
630 * If the FHR has set a very very fast register timer
631 * there exists a possibility that the incoming NULL
632 * register
633 * is happening before we set the spt bit. If so
634 * Do a quick check to update the counters and
635 * then set the spt bit as appropriate
636 */
637 if (upstream->sptbit != PIM_UPSTREAM_SPTBIT_TRUE) {
638 pim_mroute_update_counters(
639 upstream->channel_oil);
640 /*
641 * Have we seen packets?
642 */
643 if (upstream->channel_oil->cc.oldpktcnt
644 < upstream->channel_oil->cc.pktcnt)
645 pim_upstream_set_sptbit(
646 upstream,
647 upstream->rpf.source_nexthop
648 .interface);
649 }
650 }
651
652 if ((upstream->sptbit == PIM_UPSTREAM_SPTBIT_TRUE)
653 || ((SwitchToSptDesiredOnRp(pim, &sg))
654 && pim_upstream_inherited_olist(pim, upstream) == 0)) {
655 pim_register_stop_send(ifp, &sg, dest_addr, src_addr);
656 sentRegisterStop = 1;
657 } else {
658 if (PIM_DEBUG_PIM_REG)
659 zlog_debug("(%s) sptbit: %d", upstream->sg_str,
660 upstream->sptbit);
661 }
662 if ((upstream->sptbit == PIM_UPSTREAM_SPTBIT_TRUE)
663 || (SwitchToSptDesiredOnRp(pim, &sg))) {
664 if (sentRegisterStop) {
665 pim_upstream_keep_alive_timer_start(
666 upstream, pim->rp_keep_alive_time);
667 } else {
668 pim_upstream_keep_alive_timer_start(
669 upstream, pim->keep_alive_time);
670 }
671 }
672
673 if (!(upstream->sptbit == PIM_UPSTREAM_SPTBIT_TRUE)
674 && !(*bits & PIM_REGISTER_NR_BIT)) {
675 // decapsulate and forward the iner packet to
676 // inherited_olist(S,G,rpt)
677 // This is taken care of by the kernel for us
678 }
679 pim_upstream_msdp_reg_timer_start(upstream);
680 } else {
681 if (PIM_DEBUG_PIM_REG) {
682 if (!i_am_rp)
683 zlog_debug("Received Register packet for %pSG, Rejecting packet because I am not the RP configured for group",
684 &sg);
685 else
686 zlog_debug("Received Register packet for %pSG, Rejecting packet because the dst ip address is not the actual RP",
687 &sg);
688 }
689 pim_register_stop_send(ifp, &sg, dest_addr, src_addr);
690 }
691
692 return 0;
693 }
694
695 /*
696 * This routine scan all upstream and update register state and remove pimreg
697 * when couldreg becomes false.
698 */
699 void pim_reg_del_on_couldreg_fail(struct interface *ifp)
700 {
701 struct pim_interface *pim_ifp = ifp->info;
702 struct pim_instance *pim;
703 struct pim_upstream *up;
704
705 if (!pim_ifp)
706 return;
707
708 pim = pim_ifp->pim;
709
710 frr_each (rb_pim_upstream, &pim->upstream_head, up) {
711 if (ifp != up->rpf.source_nexthop.interface)
712 continue;
713
714 if (!pim_upstream_could_register(up)
715 && (up->reg_state != PIM_REG_NOINFO)) {
716 pim_channel_del_oif(up->channel_oil, pim->regiface,
717 PIM_OIF_FLAG_PROTO_PIM, __func__);
718 THREAD_OFF(up->t_rs_timer);
719 up->reg_state = PIM_REG_NOINFO;
720 }
721 }
722 }