- ip_hdr = (struct ip *)(tlv_buf + PIM_MSG_REGISTER_BIT_RESERVED_LEN);
-
- if (!pim_rp_check_is_my_ip_address (ip_hdr->ip_dst, dest_addr)) {
- if (PIM_DEBUG_PIM_REG) {
- char dest[INET_ADDRSTRLEN];
-
- pim_inet4_dump ("<dst?>", dest_addr, dest, sizeof(dest));
- zlog_debug ("%s: Received Register message for %s that I do not own", __func__,
- dest);
- }
- return 0;
- }
-
- pim_ifp = ifp->info;
- zassert(pim_ifp);
- ++pim_ifp->pim_ifstat_reg_recv;
-
- /*
- * Please note this is not drawn to get the correct bit/data size
- *
- * The entirety of the REGISTER packet looks like this:
- * -------------------------------------------------------------
- * | Ver | Type | Reserved | Checksum |
- * |-----------------------------------------------------------|
- * |B|N| Reserved 2 |
- * |-----------------------------------------------------------|
- * | Encap | IP HDR |
- * | Mcast | |
- * | Packet |--------------------------------------------------|
- * | | Mcast Data |
- * | | |
- * ...
- *
- * tlv_buf when received from the caller points at the B bit
- * We need to know the inner source and dest
- */
- bits = (uint32_t *)tlv_buf;
-
- /*
- * tlv_buf points to the start of the |B|N|... Reserved
- * Line above. So we need to add 4 bytes to get to the
- * start of the actual Encapsulated data.
- */
- memset (&sg, 0, sizeof (struct prefix_sg));
- sg.src = ip_hdr->ip_src;
- sg.grp = ip_hdr->ip_dst;
-
- i_am_rp = I_am_RP (sg.grp);
-
- if (PIM_DEBUG_PIM_REG)
- {
- char src_str[INET_ADDRSTRLEN];
-
- pim_inet4_dump ("<src?>", src_addr, src_str, sizeof (src_str));
- zlog_debug ("Received Register message(%s) from %s on %s, rp: %d",
- pim_str_sg_dump (&sg), src_str, ifp->name, i_am_rp);
- }
-
- if (i_am_rp && (dest_addr.s_addr == ((RP (sg.grp))->rpf_addr.u.prefix4.s_addr))) {
- sentRegisterStop = 0;
-
- if (*bits & PIM_REGISTER_BORDER_BIT) {
- struct in_addr pimbr = pim_br_get_pmbr (&sg);
- if (PIM_DEBUG_PIM_PACKETS)
- zlog_debug("%s: Received Register message with Border bit set", __func__);
-
- if (pimbr.s_addr == pim_br_unknown.s_addr)
- pim_br_set_pmbr(&sg, src_addr);
- else if (src_addr.s_addr != pimbr.s_addr) {
- pim_register_stop_send (ifp, &sg, dest_addr, src_addr);
- if (PIM_DEBUG_PIM_PACKETS)
- zlog_debug("%s: Sending register-Stop to %s and dropping mr. packet",
- __func__, "Sender");
- /* Drop Packet Silently */
- return 1;
- }
- }
-
- struct pim_upstream *upstream = pim_upstream_find (&sg);
- /*
- * If we don't have a place to send ignore the packet
- */
- if (!upstream)
- {
- upstream = pim_upstream_add (&sg, ifp,
- PIM_UPSTREAM_FLAG_MASK_SRC_STREAM,
- __PRETTY_FUNCTION__);
- if (!upstream)
- {
- zlog_warn ("Failure to create upstream state");
- return 1;
- }
-
- upstream->upstream_register = src_addr;
- }
-
- if ((upstream->sptbit == PIM_UPSTREAM_SPTBIT_TRUE) ||
- ((SwitchToSptDesired(&sg)) &&
- pim_upstream_inherited_olist (upstream) == 0)) {
- //pim_scan_individual_oil (upstream->channel_oil);
- pim_register_stop_send (ifp, &sg, dest_addr, src_addr);
- sentRegisterStop = 1;
- } else {
- if (PIM_DEBUG_PIM_REG)
- zlog_debug ("(%s) sptbit: %d", upstream->sg_str, upstream->sptbit);
- }
- if ((upstream->sptbit == PIM_UPSTREAM_SPTBIT_TRUE) ||
- (SwitchToSptDesired(&sg))) {
- if (sentRegisterStop) {
- pim_upstream_keep_alive_timer_start (upstream, qpim_rp_keep_alive_time);
- } else {
- pim_upstream_keep_alive_timer_start (upstream, qpim_keep_alive_time);
- }
- }
-
- if (!(upstream->sptbit == PIM_UPSTREAM_SPTBIT_TRUE) &&
- !(*bits & PIM_REGISTER_NR_BIT))
- {
- //decapsulate and forward the iner packet to
- //inherited_olist(S,G,rpt)
- // This is taken care of by the kernel for us
- }
- pim_upstream_msdp_reg_timer_start(upstream);
- } else {
- if (PIM_DEBUG_PIM_REG)
- {
- if (!i_am_rp)
- zlog_debug ("Received Register packet for %s, Rejecting packet because I am not the RP configured for group",
- pim_str_sg_dump (&sg));
- else
- zlog_debug ("Received Register packet for %s, Rejecting packet because the dst ip address is not the actual RP",
- pim_str_sg_dump (&sg));
- }
- pim_register_stop_send (ifp, &sg, dest_addr, src_addr);
- }
-
- return 1;
+ ip_hdr = (struct ip *)(tlv_buf + PIM_MSG_REGISTER_BIT_RESERVED_LEN);
+
+ if (!pim_rp_check_is_my_ip_address(pim_ifp->pim, ip_hdr->ip_dst,
+ dest_addr)) {
+ if (PIM_DEBUG_PIM_REG) {
+ char dest[INET_ADDRSTRLEN];
+
+ pim_inet4_dump("<dst?>", dest_addr, dest, sizeof(dest));
+ zlog_debug(
+ "%s: Received Register message for %s that I do not own",
+ __func__, dest);
+ }
+ return 0;
+ }
+
+ ++pim_ifp->pim_ifstat_reg_recv;
+
+ /*
+ * Please note this is not drawn to get the correct bit/data size
+ *
+ * The entirety of the REGISTER packet looks like this:
+ * -------------------------------------------------------------
+ * | Ver | Type | Reserved | Checksum |
+ * |-----------------------------------------------------------|
+ * |B|N| Reserved 2 |
+ * |-----------------------------------------------------------|
+ * | Encap | IP HDR |
+ * | Mcast | |
+ * | Packet |--------------------------------------------------|
+ * | | Mcast Data |
+ * | | |
+ * ...
+ *
+ * tlv_buf when received from the caller points at the B bit
+ * We need to know the inner source and dest
+ */
+ bits = (uint32_t *)tlv_buf;
+
+ /*
+ * tlv_buf points to the start of the |B|N|... Reserved
+ * Line above. So we need to add 4 bytes to get to the
+ * start of the actual Encapsulated data.
+ */
+ memset(&sg, 0, sizeof(struct prefix_sg));
+ sg.src = ip_hdr->ip_src;
+ sg.grp = ip_hdr->ip_dst;
+
+ i_am_rp = I_am_RP(pim_ifp->pim, sg.grp);
+
+ if (PIM_DEBUG_PIM_REG) {
+ char src_str[INET_ADDRSTRLEN];
+
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_debug(
+ "Received Register message(%s) from %s on %s, rp: %d",
+ pim_str_sg_dump(&sg), src_str, ifp->name, i_am_rp);
+ }
+
+ if (i_am_rp
+ && (dest_addr.s_addr
+ == ((RP(pim_ifp->pim, sg.grp))->rpf_addr.u.prefix4.s_addr))) {
+ sentRegisterStop = 0;
+
+ if (*bits & PIM_REGISTER_BORDER_BIT) {
+ struct in_addr pimbr = pim_br_get_pmbr(&sg);
+ if (PIM_DEBUG_PIM_PACKETS)
+ zlog_debug(
+ "%s: Received Register message with Border bit set",
+ __func__);
+
+ if (pimbr.s_addr == pim_br_unknown.s_addr)
+ pim_br_set_pmbr(&sg, src_addr);
+ else if (src_addr.s_addr != pimbr.s_addr) {
+ pim_register_stop_send(ifp, &sg, dest_addr,
+ src_addr);
+ if (PIM_DEBUG_PIM_PACKETS)
+ zlog_debug(
+ "%s: Sending register-Stop to %s and dropping mr. packet",
+ __func__, "Sender");
+ /* Drop Packet Silently */
+ return 0;
+ }
+ }
+
+ struct pim_upstream *upstream =
+ pim_upstream_find(pim_ifp->pim, &sg);
+ /*
+ * If we don't have a place to send ignore the packet
+ */
+ if (!upstream) {
+ upstream = pim_upstream_add(
+ pim_ifp->pim, &sg, ifp,
+ PIM_UPSTREAM_FLAG_MASK_SRC_STREAM,
+ __PRETTY_FUNCTION__, NULL);
+ if (!upstream) {
+ zlog_warn("Failure to create upstream state");
+ return 1;
+ }
+
+ upstream->upstream_register = src_addr;
+ } else {
+ /*
+ * If the FHR has set a very very fast register timer
+ * there exists a possibility that the incoming NULL
+ * register
+ * is happening before we set the spt bit. If so
+ * Do a quick check to update the counters and
+ * then set the spt bit as appropriate
+ */
+ if (upstream->sptbit != PIM_UPSTREAM_SPTBIT_TRUE) {
+ pim_mroute_update_counters(
+ upstream->channel_oil);
+ /*
+ * Have we seen packets?
+ */
+ if (upstream->channel_oil->cc.oldpktcnt
+ < upstream->channel_oil->cc.pktcnt)
+ pim_upstream_set_sptbit(
+ upstream,
+ upstream->rpf.source_nexthop
+ .interface);
+ }
+ }
+
+ if ((upstream->sptbit == PIM_UPSTREAM_SPTBIT_TRUE)
+ || ((SwitchToSptDesired(pim_ifp->pim, &sg))
+ && pim_upstream_inherited_olist(pim_ifp->pim, upstream)
+ == 0)) {
+ // pim_scan_individual_oil (upstream->channel_oil);
+ pim_register_stop_send(ifp, &sg, dest_addr, src_addr);
+ sentRegisterStop = 1;
+ } else {
+ if (PIM_DEBUG_PIM_REG)
+ zlog_debug("(%s) sptbit: %d", upstream->sg_str,
+ upstream->sptbit);
+ }
+ if ((upstream->sptbit == PIM_UPSTREAM_SPTBIT_TRUE)
+ || (SwitchToSptDesired(pim_ifp->pim, &sg))) {
+ if (sentRegisterStop) {
+ pim_upstream_keep_alive_timer_start(
+ upstream,
+ pim_ifp->pim->rp_keep_alive_time);
+ } else {
+ pim_upstream_keep_alive_timer_start(
+ upstream,
+ pim_ifp->pim->keep_alive_time);
+ }
+ }
+
+ if (!(upstream->sptbit == PIM_UPSTREAM_SPTBIT_TRUE)
+ && !(*bits & PIM_REGISTER_NR_BIT)) {
+ // decapsulate and forward the iner packet to
+ // inherited_olist(S,G,rpt)
+ // This is taken care of by the kernel for us
+ }
+ pim_upstream_msdp_reg_timer_start(upstream);
+ } else {
+ if (PIM_DEBUG_PIM_REG) {
+ if (!i_am_rp)
+ zlog_debug(
+ "Received Register packet for %s, Rejecting packet because I am not the RP configured for group",
+ pim_str_sg_dump(&sg));
+ else
+ zlog_debug(
+ "Received Register packet for %s, Rejecting packet because the dst ip address is not the actual RP",
+ pim_str_sg_dump(&sg));
+ }
+ pim_register_stop_send(ifp, &sg, dest_addr, src_addr);
+ }
+
+ return 0;