]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_register.c
Merge pull request #10629 from leonshaw/fix/mp-evpn-nh
[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 /* As per RFC 7761, Section 4.9.4:
179 * A special wildcard value consisting of an address field of
180 * all zeros can be used to indicate any source.
181 */
182 if ((pim_addr_cmp(sg.src, rpf_addr) == 0) ||
183 pim_addr_is_any(sg.src)) {
184 handling_star = true;
185 sg.src = PIMADDR_ANY;
186 }
187 }
188
189 /*
190 * RFC 7761 Sec 4.4.1
191 * Handling Register-Stop(*,G) Messages at the DR:
192 * A Register-Stop(*,G) should be treated as a
193 * Register-Stop(S,G) for all (S,G) Register state
194 * machines that are not in the NoInfo state.
195 */
196 up = pim_upstream_find(pim, &sg);
197 if (up) {
198 /*
199 * If the upstream find actually found a particular
200 * S,G then we *know* that the following for loop
201 * is not going to execute and this is ok
202 */
203 for (ALL_LIST_ELEMENTS_RO(up->sources, up_node, child)) {
204 if (PIM_DEBUG_PIM_REG)
205 zlog_debug("Executing Reg stop for %s",
206 child->sg_str);
207
208 pim_reg_stop_upstream(pim, child);
209 }
210
211 if (PIM_DEBUG_PIM_REG)
212 zlog_debug("Executing Reg stop for %s", up->sg_str);
213 pim_reg_stop_upstream(pim, up);
214 } else {
215 if (!handling_star)
216 return 0;
217 /*
218 * Unfortunately pim was unable to find a *,G
219 * but pim may still actually have individual
220 * S,G's that need to be processed. In that
221 * case pim must do the expensive walk to find
222 * and stop
223 */
224 frr_each (rb_pim_upstream, &pim->upstream_head, up) {
225 if (pim_addr_cmp(up->sg.grp, sg.grp) == 0) {
226 if (PIM_DEBUG_PIM_REG)
227 zlog_debug("Executing Reg stop for %s",
228 up->sg_str);
229 pim_reg_stop_upstream(pim, up);
230 }
231 }
232 }
233
234 return 0;
235 }
236
237 #if PIM_IPV == 6
238 struct in6_addr pim_register_get_unicast_v6_addr(struct pim_interface *p_ifp)
239 {
240 struct listnode *node;
241 struct listnode *nextnode;
242 struct pim_secondary_addr *sec_addr;
243 struct pim_interface *pim_ifp;
244 struct interface *ifp;
245 struct pim_instance *pim = p_ifp->pim;
246
247 /* Trying to get the unicast address from the RPF interface first */
248 for (ALL_LIST_ELEMENTS(p_ifp->sec_addr_list, node, nextnode,
249 sec_addr)) {
250 if (!is_ipv6_global_unicast(&sec_addr->addr.u.prefix6))
251 continue;
252
253 return sec_addr->addr.u.prefix6;
254 }
255
256 /* Loop through all the pim interface and try to return a global
257 * unicast ipv6 address
258 */
259 FOR_ALL_INTERFACES (pim->vrf, ifp) {
260 pim_ifp = ifp->info;
261
262 if (!pim_ifp)
263 continue;
264
265 for (ALL_LIST_ELEMENTS(pim_ifp->sec_addr_list, node, nextnode,
266 sec_addr)) {
267 if (!is_ipv6_global_unicast(&sec_addr->addr.u.prefix6))
268 continue;
269
270 return sec_addr->addr.u.prefix6;
271 }
272 }
273
274 zlog_warn("No global address found for use to send register message");
275 return PIMADDR_ANY;
276 }
277 #endif
278
279 void pim_register_send(const uint8_t *buf, int buf_size, pim_addr src,
280 struct pim_rpf *rpg, int null_register,
281 struct pim_upstream *up)
282 {
283 unsigned char buffer[10000];
284 unsigned char *b1;
285 struct pim_interface *pinfo;
286 struct interface *ifp;
287 pim_addr dst = pim_addr_from_prefix(&rpg->rpf_addr);
288
289 if (PIM_DEBUG_PIM_REG) {
290 zlog_debug("Sending %s %sRegister Packet to %pPA", up->sg_str,
291 null_register ? "NULL " : "", &dst);
292 }
293
294 ifp = rpg->source_nexthop.interface;
295 if (!ifp) {
296 if (PIM_DEBUG_PIM_REG)
297 zlog_debug("%s: No interface to transmit register on",
298 __func__);
299 return;
300 }
301 pinfo = (struct pim_interface *)ifp->info;
302 if (!pinfo) {
303 if (PIM_DEBUG_PIM_REG)
304 zlog_debug(
305 "%s: Interface: %s not configured for pim to transmit on!",
306 __func__, ifp->name);
307 return;
308 }
309
310 if (PIM_DEBUG_PIM_REG) {
311 zlog_debug("%s: Sending %s %sRegister Packet to %pPA on %s",
312 __func__, up->sg_str, null_register ? "NULL " : "",
313 &dst, ifp->name);
314 }
315
316 memset(buffer, 0, 10000);
317 b1 = buffer + PIM_MSG_HEADER_LEN;
318 *b1 |= null_register << 6;
319 b1 = buffer + PIM_MSG_REGISTER_LEN;
320
321 memcpy(b1, (const unsigned char *)buf, buf_size);
322
323 #if PIM_IPV == 6
324 /* While sending Register message to RP, we cannot use link-local
325 * address therefore using unicast ipv6 address here, choosing it
326 * from the RPF Interface
327 */
328 src = pim_register_get_unicast_v6_addr(pinfo);
329 #endif
330 pim_msg_build_header(src, dst, buffer, buf_size + PIM_MSG_REGISTER_LEN,
331 PIM_MSG_TYPE_REGISTER, false);
332
333 if (!pinfo->pim_passive_enable)
334 ++pinfo->pim_ifstat_reg_send;
335
336 if (pim_msg_send(pinfo->pim_sock_fd, src, dst, buffer,
337 buf_size + PIM_MSG_REGISTER_LEN, ifp)) {
338 if (PIM_DEBUG_PIM_TRACE) {
339 zlog_debug(
340 "%s: could not send PIM register message on interface %s",
341 __func__, ifp->name);
342 }
343 return;
344 }
345 }
346
347 #if PIM_IPV == 4
348 void pim_null_register_send(struct pim_upstream *up)
349 {
350 struct ip ip_hdr;
351 struct pim_interface *pim_ifp;
352 struct pim_rpf *rpg;
353 pim_addr src;
354
355 pim_ifp = up->rpf.source_nexthop.interface->info;
356 if (!pim_ifp) {
357 if (PIM_DEBUG_PIM_TRACE)
358 zlog_debug(
359 "%s: Cannot send null-register for %s no valid iif",
360 __func__, up->sg_str);
361 return;
362 }
363
364 rpg = RP(pim_ifp->pim, up->sg.grp);
365 if (!rpg) {
366 if (PIM_DEBUG_PIM_TRACE)
367 zlog_debug(
368 "%s: Cannot send null-register for %s no RPF to the RP",
369 __func__, up->sg_str);
370 return;
371 }
372
373 memset(&ip_hdr, 0, sizeof(ip_hdr));
374 ip_hdr.ip_p = PIM_IP_PROTO_PIM;
375 ip_hdr.ip_hl = 5;
376 ip_hdr.ip_v = 4;
377 ip_hdr.ip_src = up->sg.src;
378 ip_hdr.ip_dst = up->sg.grp;
379 ip_hdr.ip_len = htons(20);
380
381 /* checksum is broken */
382 src = pim_ifp->primary_address;
383 if (PIM_UPSTREAM_FLAG_TEST_SRC_VXLAN_ORIG(up->flags)) {
384 if (!pim_vxlan_get_register_src(pim_ifp->pim, up, &src)) {
385 if (PIM_DEBUG_PIM_TRACE)
386 zlog_debug(
387 "%s: Cannot send null-register for %s vxlan-aa PIP unavailable",
388 __func__, up->sg_str);
389 return;
390 }
391 }
392 pim_register_send((uint8_t *)&ip_hdr, sizeof(struct ip), src, rpg, 1,
393 up);
394 }
395 #else
396 void pim_null_register_send(struct pim_upstream *up)
397 {
398 struct ip6_hdr ip6_hdr;
399 struct pim_msg_header pim_msg_header;
400 struct pim_interface *pim_ifp;
401 struct pim_rpf *rpg;
402 pim_addr src;
403 unsigned char buffer[sizeof(ip6_hdr) + sizeof(pim_msg_header)];
404 struct ipv6_ph ph;
405
406 pim_ifp = up->rpf.source_nexthop.interface->info;
407 if (!pim_ifp) {
408 if (PIM_DEBUG_PIM_TRACE)
409 zlog_debug(
410 "Cannot send null-register for %s no valid iif",
411 up->sg_str);
412 return;
413 }
414
415 rpg = RP(pim_ifp->pim, up->sg.grp);
416 if (!rpg) {
417 if (PIM_DEBUG_PIM_TRACE)
418 zlog_debug(
419 "Cannot send null-register for %s no RPF to the RP",
420 up->sg_str);
421 return;
422 }
423
424 memset(&ip6_hdr, 0, sizeof(ip6_hdr));
425 ip6_hdr.ip6_nxt = PIM_IP_PROTO_PIM;
426 ip6_hdr.ip6_plen = PIM_MSG_HEADER_LEN;
427 ip6_hdr.ip6_vfc = 6 << 4;
428 ip6_hdr.ip6_hlim = MAXTTL;
429 ip6_hdr.ip6_src = up->sg.src;
430 ip6_hdr.ip6_dst = up->sg.grp;
431
432 memset(buffer, 0, (sizeof(ip6_hdr) + sizeof(pim_msg_header)));
433 memcpy(buffer, &ip6_hdr, sizeof(ip6_hdr));
434
435 pim_msg_header.ver = 0;
436 pim_msg_header.type = 0;
437 pim_msg_header.reserved = 0;
438
439 pim_msg_header.checksum = 0;
440
441 ph.src = up->sg.src;
442 ph.dst = up->sg.grp;
443 ph.ulpl = htonl(PIM_MSG_HEADER_LEN);
444 ph.next_hdr = IPPROTO_PIM;
445 pim_msg_header.checksum =
446 in_cksum_with_ph6(&ph, &pim_msg_header, PIM_MSG_HEADER_LEN);
447
448 memcpy(buffer + sizeof(ip6_hdr), &pim_msg_header, PIM_MSG_HEADER_LEN);
449
450
451 src = pim_ifp->primary_address;
452 pim_register_send((uint8_t *)buffer,
453 sizeof(ip6_hdr) + PIM_MSG_HEADER_LEN, src, rpg, 1,
454 up);
455 }
456 #endif
457
458 /*
459 * 4.4.2 Receiving Register Messages at the RP
460 *
461 * When an RP receives a Register message, the course of action is
462 * decided according to the following pseudocode:
463 *
464 * packet_arrives_on_rp_tunnel( pkt ) {
465 * if( outer.dst is not one of my addresses ) {
466 * drop the packet silently.
467 * # Note: this may be a spoofing attempt
468 * }
469 * if( I_am_RP(G) AND outer.dst == RP(G) ) {
470 * sentRegisterStop = false;
471 * if ( register.borderbit == true ) {
472 * if ( PMBR(S,G) == unknown ) {
473 * PMBR(S,G) = outer.src
474 * } else if ( outer.src != PMBR(S,G) ) {
475 * send Register-Stop(S,G) to outer.src
476 * drop the packet silently.
477 * }
478 * }
479 * if ( SPTbit(S,G) OR
480 * ( SwitchToSptDesired(S,G) AND
481 * ( inherited_olist(S,G) == NULL ))) {
482 * send Register-Stop(S,G) to outer.src
483 * sentRegisterStop = true;
484 * }
485 * if ( SPTbit(S,G) OR SwitchToSptDesired(S,G) ) {
486 * if ( sentRegisterStop == true ) {
487 * set KeepaliveTimer(S,G) to RP_Keepalive_Period;
488 * } else {
489 * set KeepaliveTimer(S,G) to Keepalive_Period;
490 * }
491 * }
492 * if( !SPTbit(S,G) AND ! pkt.NullRegisterBit ) {
493 * decapsulate and forward the inner packet to
494 * inherited_olist(S,G,rpt) # Note (+)
495 * }
496 * } else {
497 * send Register-Stop(S,G) to outer.src
498 * # Note (*)
499 * }
500 * }
501 */
502 int pim_register_recv(struct interface *ifp, pim_addr dest_addr,
503 pim_addr src_addr, uint8_t *tlv_buf, int tlv_buf_size)
504 {
505 int sentRegisterStop = 0;
506 const void *ip_hdr;
507 pim_sgaddr sg;
508 uint32_t *bits;
509 int i_am_rp = 0;
510 struct pim_interface *pim_ifp = ifp->info;
511 struct pim_instance *pim = pim_ifp->pim;
512 pim_addr rp_addr;
513
514 if (pim_ifp->pim_passive_enable) {
515 if (PIM_DEBUG_PIM_PACKETS)
516 zlog_debug(
517 "skip receiving PIM message on passive interface %s",
518 ifp->name);
519 return 0;
520 }
521
522 #define PIM_MSG_REGISTER_BIT_RESERVED_LEN 4
523 ip_hdr = (tlv_buf + PIM_MSG_REGISTER_BIT_RESERVED_LEN);
524
525 if (!if_address_is_local(&dest_addr, PIM_AF, pim->vrf->vrf_id)) {
526 if (PIM_DEBUG_PIM_REG)
527 zlog_debug(
528 "%s: Received Register message for destination address: %pPA that I do not own",
529 __func__, &dest_addr);
530 return 0;
531 }
532
533 ++pim_ifp->pim_ifstat_reg_recv;
534
535 /*
536 * Please note this is not drawn to get the correct bit/data size
537 *
538 * The entirety of the REGISTER packet looks like this:
539 * -------------------------------------------------------------
540 * | Ver | Type | Reserved | Checksum |
541 * |-----------------------------------------------------------|
542 * |B|N| Reserved 2 |
543 * |-----------------------------------------------------------|
544 * | Encap | IP HDR |
545 * | Mcast | |
546 * | Packet |--------------------------------------------------|
547 * | | Mcast Data |
548 * | | |
549 * ...
550 *
551 * tlv_buf when received from the caller points at the B bit
552 * We need to know the inner source and dest
553 */
554 bits = (uint32_t *)tlv_buf;
555
556 /*
557 * tlv_buf points to the start of the |B|N|... Reserved
558 * Line above. So we need to add 4 bytes to get to the
559 * start of the actual Encapsulated data.
560 */
561 memset(&sg, 0, sizeof(sg));
562 sg = pim_sgaddr_from_iphdr(ip_hdr);
563
564 #if PIM_IPV == 6
565 /*
566 * According to RFC section 4.9.3, If Dummy PIM Header is included
567 * in NULL Register as a payload there would be two PIM headers.
568 * The inner PIM Header's checksum field should also be validated
569 * in addition to the outer PIM Header's checksum. Validation of
570 * inner PIM header checksum is done here.
571 */
572 if ((*bits & PIM_REGISTER_NR_BIT) &&
573 ((tlv_buf_size - PIM_MSG_REGISTER_BIT_RESERVED_LEN) >
574 (int)sizeof(struct ip6_hdr))) {
575 uint16_t computed_checksum;
576 uint16_t received_checksum;
577 struct ipv6_ph ph;
578 struct pim_msg_header *header;
579
580 header = (struct pim_msg_header
581 *)(tlv_buf +
582 PIM_MSG_REGISTER_BIT_RESERVED_LEN +
583 sizeof(struct ip6_hdr));
584 ph.src = sg.src;
585 ph.dst = sg.grp;
586 ph.ulpl = htonl(PIM_MSG_HEADER_LEN);
587 ph.next_hdr = IPPROTO_PIM;
588
589 received_checksum = header->checksum;
590
591 header->checksum = 0;
592 computed_checksum = in_cksum_with_ph6(
593 &ph, header, htonl(PIM_MSG_HEADER_LEN));
594
595 if (computed_checksum != received_checksum) {
596 if (PIM_DEBUG_PIM_PACKETS)
597 zlog_debug(
598 "Ignoring Null Register message%pSG from %pPA due to bad checksum in Encapsulated dummy PIM header",
599 &sg, &src_addr);
600 return 0;
601 }
602 }
603 #endif
604 i_am_rp = I_am_RP(pim, sg.grp);
605
606 if (PIM_DEBUG_PIM_REG)
607 zlog_debug(
608 "Received Register message%pSG from %pPA on %s, rp: %d",
609 &sg, &src_addr, ifp->name, i_am_rp);
610
611 if (pim_is_grp_ssm(pim_ifp->pim, sg.grp)) {
612 if (pim_addr_is_any(sg.src)) {
613 zlog_warn(
614 "%s: Received Register message for Group(%pPA) is now in SSM, dropping the packet",
615 __func__, &sg.grp);
616 /* Drop Packet Silently */
617 return 0;
618 }
619 }
620
621 rp_addr = pim_addr_from_prefix(&(RP(pim, sg.grp))->rpf_addr);
622 if (i_am_rp && (!pim_addr_cmp(dest_addr, rp_addr))) {
623 sentRegisterStop = 0;
624
625 if (pim->register_plist) {
626 struct prefix_list *plist;
627 struct prefix src;
628
629 plist = prefix_list_lookup(PIM_AFI,
630 pim->register_plist);
631
632 pim_addr_to_prefix(&src, sg.src);
633
634 if (prefix_list_apply(plist, &src) == PREFIX_DENY) {
635 pim_register_stop_send(ifp, &sg, dest_addr,
636 src_addr);
637 if (PIM_DEBUG_PIM_PACKETS)
638 zlog_debug(
639 "%s: Sending register-stop to %pPA for %pSG due to prefix-list denial, dropping packet",
640 __func__, &src_addr, &sg);
641
642 return 0;
643 }
644 }
645
646 if (*bits & PIM_REGISTER_BORDER_BIT) {
647 pim_addr pimbr = pim_br_get_pmbr(&sg);
648 if (PIM_DEBUG_PIM_PACKETS)
649 zlog_debug(
650 "%s: Received Register message with Border bit set",
651 __func__);
652
653 if (pim_addr_is_any(pimbr))
654 pim_br_set_pmbr(&sg, src_addr);
655 else if (pim_addr_cmp(src_addr, pimbr)) {
656 pim_register_stop_send(ifp, &sg, dest_addr,
657 src_addr);
658 if (PIM_DEBUG_PIM_PACKETS)
659 zlog_debug(
660 "%s: Sending register-Stop to %s and dropping mr. packet",
661 __func__, "Sender");
662 /* Drop Packet Silently */
663 return 0;
664 }
665 }
666
667 struct pim_upstream *upstream = pim_upstream_find(pim, &sg);
668 /*
669 * If we don't have a place to send ignore the packet
670 */
671 if (!upstream) {
672 upstream = pim_upstream_add(
673 pim, &sg, ifp,
674 PIM_UPSTREAM_FLAG_MASK_SRC_STREAM, __func__,
675 NULL);
676 if (!upstream) {
677 zlog_warn("Failure to create upstream state");
678 return 1;
679 }
680
681 upstream->upstream_register = src_addr;
682 } else {
683 /*
684 * If the FHR has set a very very fast register timer
685 * there exists a possibility that the incoming NULL
686 * register
687 * is happening before we set the spt bit. If so
688 * Do a quick check to update the counters and
689 * then set the spt bit as appropriate
690 */
691 if (upstream->sptbit != PIM_UPSTREAM_SPTBIT_TRUE) {
692 pim_mroute_update_counters(
693 upstream->channel_oil);
694 /*
695 * Have we seen packets?
696 */
697 if (upstream->channel_oil->cc.oldpktcnt
698 < upstream->channel_oil->cc.pktcnt)
699 pim_upstream_set_sptbit(
700 upstream,
701 upstream->rpf.source_nexthop
702 .interface);
703 }
704 }
705
706 if ((upstream->sptbit == PIM_UPSTREAM_SPTBIT_TRUE)
707 || ((SwitchToSptDesiredOnRp(pim, &sg))
708 && pim_upstream_inherited_olist(pim, upstream) == 0)) {
709 pim_register_stop_send(ifp, &sg, dest_addr, src_addr);
710 sentRegisterStop = 1;
711 } else {
712 if (PIM_DEBUG_PIM_REG)
713 zlog_debug("(%s) sptbit: %d", upstream->sg_str,
714 upstream->sptbit);
715 }
716 if ((upstream->sptbit == PIM_UPSTREAM_SPTBIT_TRUE)
717 || (SwitchToSptDesiredOnRp(pim, &sg))) {
718 if (sentRegisterStop) {
719 pim_upstream_keep_alive_timer_start(
720 upstream, pim->rp_keep_alive_time);
721 } else {
722 pim_upstream_keep_alive_timer_start(
723 upstream, pim->keep_alive_time);
724 }
725 }
726
727 if (!(upstream->sptbit == PIM_UPSTREAM_SPTBIT_TRUE)
728 && !(*bits & PIM_REGISTER_NR_BIT)) {
729 // decapsulate and forward the iner packet to
730 // inherited_olist(S,G,rpt)
731 // This is taken care of by the kernel for us
732 }
733 pim_upstream_msdp_reg_timer_start(upstream);
734 } else {
735 if (PIM_DEBUG_PIM_REG) {
736 if (!i_am_rp)
737 zlog_debug("Received Register packet for %pSG, Rejecting packet because I am not the RP configured for group",
738 &sg);
739 else
740 zlog_debug("Received Register packet for %pSG, Rejecting packet because the dst ip address is not the actual RP",
741 &sg);
742 }
743 pim_register_stop_send(ifp, &sg, dest_addr, src_addr);
744 }
745
746 return 0;
747 }
748
749 /*
750 * This routine scan all upstream and update register state and remove pimreg
751 * when couldreg becomes false.
752 */
753 void pim_reg_del_on_couldreg_fail(struct interface *ifp)
754 {
755 struct pim_interface *pim_ifp = ifp->info;
756 struct pim_instance *pim;
757 struct pim_upstream *up;
758
759 if (!pim_ifp)
760 return;
761
762 pim = pim_ifp->pim;
763
764 frr_each (rb_pim_upstream, &pim->upstream_head, up) {
765 if (ifp != up->rpf.source_nexthop.interface)
766 continue;
767
768 if (!pim_upstream_could_register(up)
769 && (up->reg_state != PIM_REG_NOINFO)) {
770 pim_channel_del_oif(up->channel_oil, pim->regiface,
771 PIM_OIF_FLAG_PROTO_PIM, __func__);
772 THREAD_OFF(up->t_rs_timer);
773 up->reg_state = PIM_REG_NOINFO;
774 }
775 }
776 }