2 * Multicast traceroute for FRRouting
3 * Copyright (C) 2017 Mladen Sablic
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 /* based on draft-ietf-idmr-traceroute-ipm-07 */
25 #include "pim_instance.h"
30 #include "pim_ifchannel.h"
31 #include "pim_macro.h"
32 #include "pim_igmp_mtrace.h"
34 static struct in_addr
mtrace_primary_address(struct interface
*ifp
)
36 struct connected
*ifc
;
37 struct listnode
*node
;
39 struct pim_interface
*pim_ifp
;
43 return pim_ifp
->primary_address
;
46 any
.s_addr
= INADDR_ANY
;
48 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, ifc
)) {
49 struct prefix
*p
= ifc
->address
;
51 if (p
->family
!= AF_INET
)
54 if (!CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
))
56 /* in case no primary found, return a secondary */
62 static bool mtrace_fwd_info_weak(struct pim_instance
*pim
,
63 struct igmp_mtrace
*mtracep
,
64 struct igmp_mtrace_rsp
*rspp
,
65 struct interface
**ifpp
)
67 struct pim_nexthop nexthop
;
68 struct interface
*ifp_in
;
69 struct in_addr nh_addr
;
71 nh_addr
.s_addr
= INADDR_ANY
;
73 memset(&nexthop
, 0, sizeof(nexthop
));
75 if (!pim_nexthop_lookup(pim
, &nexthop
, mtracep
->src_addr
, 1)) {
77 zlog_debug("mtrace not found neighbor");
82 zlog_debug("mtrace pim_nexthop_lookup OK");
85 zlog_debug("mtrace next_hop=%pPAs", &nexthop
.mrib_nexthop_addr
);
87 nh_addr
= nexthop
.mrib_nexthop_addr
;
89 ifp_in
= nexthop
.interface
;
91 /* return interface for forwarding mtrace packets */
94 /* 6.2.2. 4. Fill in the Incoming Interface Address... */
95 rspp
->incoming
= mtrace_primary_address(ifp_in
);
96 rspp
->prev_hop
= nh_addr
;
97 rspp
->in_count
= htonl(MTRACE_UNKNOWN_COUNT
);
98 rspp
->total
= htonl(MTRACE_UNKNOWN_COUNT
);
99 rspp
->rtg_proto
= MTRACE_RTG_PROTO_PIM
;
103 static bool mtrace_fwd_info(struct pim_instance
*pim
,
104 struct igmp_mtrace
*mtracep
,
105 struct igmp_mtrace_rsp
*rspp
,
106 struct interface
**ifpp
)
109 struct pim_upstream
*up
;
110 struct interface
*ifp_in
;
111 struct in_addr nh_addr
;
114 memset(&sg
, 0, sizeof(sg
));
115 sg
.src
= mtracep
->src_addr
;
116 sg
.grp
= mtracep
->grp_addr
;
118 up
= pim_upstream_find(pim
, &sg
);
121 sg
.src
= PIMADDR_ANY
;
122 up
= pim_upstream_find(pim
, &sg
);
128 if (!up
->rpf
.source_nexthop
.interface
) {
130 zlog_debug("%s: up %s RPF is not present", __func__
,
135 ifp_in
= up
->rpf
.source_nexthop
.interface
;
136 nh_addr
= up
->rpf
.source_nexthop
.mrib_nexthop_addr
;
137 total
= htonl(MTRACE_UNKNOWN_COUNT
);
139 if (PIM_DEBUG_MTRACE
)
140 zlog_debug("fwd_info: upstream next hop=%pI4", &nh_addr
);
143 total
= up
->channel_oil
->cc
.pktcnt
;
145 /* return interface for forwarding mtrace packets */
148 /* 6.2.2. 4. Fill in the Incoming Interface Address... */
149 rspp
->incoming
= mtrace_primary_address(ifp_in
);
150 rspp
->prev_hop
= nh_addr
;
151 rspp
->in_count
= htonl(MTRACE_UNKNOWN_COUNT
);
153 rspp
->rtg_proto
= MTRACE_RTG_PROTO_PIM
;
155 /* 6.2.2. 4. Fill in ... S, and Src Mask */
156 if (!pim_addr_is_any(sg
.src
)) {
158 rspp
->src_mask
= MTRACE_SRC_MASK_SOURCE
;
161 rspp
->src_mask
= MTRACE_SRC_MASK_GROUP
;
167 static void mtrace_rsp_set_fwd_code(struct igmp_mtrace_rsp
*mtrace_rspp
,
168 enum mtrace_fwd_code fwd_code
)
170 if (mtrace_rspp
->fwd_code
== MTRACE_FWD_CODE_NO_ERROR
)
171 mtrace_rspp
->fwd_code
= fwd_code
;
174 static void mtrace_rsp_init(struct igmp_mtrace_rsp
*mtrace_rspp
)
176 mtrace_rspp
->arrival
= 0;
177 mtrace_rspp
->incoming
.s_addr
= INADDR_ANY
;
178 mtrace_rspp
->outgoing
.s_addr
= INADDR_ANY
;
179 mtrace_rspp
->prev_hop
.s_addr
= INADDR_ANY
;
180 mtrace_rspp
->in_count
= htonl(MTRACE_UNKNOWN_COUNT
);
181 mtrace_rspp
->out_count
= htonl(MTRACE_UNKNOWN_COUNT
);
182 mtrace_rspp
->total
= htonl(MTRACE_UNKNOWN_COUNT
);
183 mtrace_rspp
->rtg_proto
= 0;
184 mtrace_rspp
->fwd_ttl
= 0;
185 mtrace_rspp
->mbz
= 0;
187 mtrace_rspp
->src_mask
= 0;
188 mtrace_rspp
->fwd_code
= MTRACE_FWD_CODE_NO_ERROR
;
191 static void mtrace_rsp_debug(uint32_t qry_id
, int rsp
,
192 struct igmp_mtrace_rsp
*mrspp
)
194 struct in_addr incoming
= mrspp
->incoming
;
195 struct in_addr outgoing
= mrspp
->outgoing
;
196 struct in_addr prev_hop
= mrspp
->prev_hop
;
199 "Rx mt(%d) qid=%ud arr=%x in=%pI4 out=%pI4 prev=%pI4 proto=%d fwd=%d",
200 rsp
, ntohl(qry_id
), mrspp
->arrival
, &incoming
, &outgoing
,
201 &prev_hop
, mrspp
->rtg_proto
, mrspp
->fwd_code
);
204 static void mtrace_debug(struct pim_interface
*pim_ifp
,
205 struct igmp_mtrace
*mtracep
, int mtrace_len
)
207 struct in_addr ga
, sa
, da
, ra
;
209 ga
= mtracep
->grp_addr
;
210 sa
= mtracep
->src_addr
;
211 da
= mtracep
->dst_addr
;
212 ra
= mtracep
->rsp_addr
;
215 "Rx mtrace packet incoming on %pI4: hops=%d type=%d size=%d, grp=%pI4, src=%pI4, dst=%pI4 rsp=%pI4 ttl=%d qid=%ud",
216 &pim_ifp
->primary_address
, mtracep
->hops
, mtracep
->type
,
217 mtrace_len
, &ga
, &sa
, &da
, &ra
, mtracep
->rsp_ttl
,
218 ntohl(mtracep
->qry_id
));
219 if (mtrace_len
> (int)sizeof(struct igmp_mtrace
)) {
223 int responses
= mtrace_len
- sizeof(struct igmp_mtrace
);
225 if ((responses
% sizeof(struct igmp_mtrace_rsp
)) != 0)
226 if (PIM_DEBUG_MTRACE
)
228 "Mtrace response block of wrong length");
230 responses
= responses
/ sizeof(struct igmp_mtrace_rsp
);
232 for (i
= 0; i
< responses
; i
++)
233 mtrace_rsp_debug(mtracep
->qry_id
, i
, &mtracep
->rsp
[i
]);
237 /* 5.1 Query Arrival Time */
238 static uint32_t query_arrival_time(void)
243 if (gettimeofday(&tv
, NULL
) < 0) {
244 if (PIM_DEBUG_MTRACE
)
245 zlog_debug("Query arrival time lookup failed: errno=%d: %s",
246 errno
, safe_strerror(errno
));
249 /* not sure second offset correct, as I get different value */
250 qat
= ((tv
.tv_sec
+ 32384) << 16) + ((tv
.tv_usec
<< 10) / 15625);
255 static int mtrace_send_packet(struct interface
*ifp
,
256 struct igmp_mtrace
*mtracep
,
257 size_t mtrace_buf_len
, struct in_addr dst_addr
,
258 struct in_addr group_addr
)
260 struct sockaddr_in to
;
267 memset(&to
, 0, sizeof(to
));
268 to
.sin_family
= AF_INET
;
269 to
.sin_addr
= dst_addr
;
272 if (PIM_DEBUG_MTRACE
) {
273 struct in_addr if_addr
;
274 struct in_addr rsp_addr
= mtracep
->rsp_addr
;
276 if_addr
= mtrace_primary_address(ifp
);
277 zlog_debug("Sending mtrace packet to %pI4 on %pI4", &rsp_addr
,
281 fd
= pim_socket_raw(IPPROTO_IGMP
);
286 ret
= pim_socket_bind(fd
, ifp
);
293 if (IPV4_CLASS_DE(ntohl(dst_addr
.s_addr
))) {
294 if (IPV4_MC_LINKLOCAL(ntohl(dst_addr
.s_addr
))) {
297 if (mtracep
->type
== PIM_IGMP_MTRACE_RESPONSE
)
298 ttl
= mtracep
->rsp_ttl
;
302 ret
= setsockopt(fd
, IPPROTO_IP
, IP_MULTICAST_TTL
, &ttl
,
306 if (PIM_DEBUG_MTRACE
)
307 zlog_debug("Failed to set socket multicast TTL");
313 sent
= sendto(fd
, (char *)mtracep
, mtrace_buf_len
, MSG_DONTWAIT
,
314 (struct sockaddr
*)&to
, tolen
);
316 if (sent
!= (ssize_t
)mtrace_buf_len
) {
317 char dst_str
[INET_ADDRSTRLEN
];
318 char group_str
[INET_ADDRSTRLEN
];
320 pim_inet4_dump("<dst?>", dst_addr
, dst_str
, sizeof(dst_str
));
321 pim_inet4_dump("<group?>", group_addr
, group_str
,
324 if (PIM_DEBUG_MTRACE
)
326 "Send mtrace request failed for %s on%s: group=%s msg_size=%zd: errno=%d: %s",
327 dst_str
, ifp
->name
, group_str
,
328 mtrace_buf_len
, errno
,
329 safe_strerror(errno
));
331 if (PIM_DEBUG_MTRACE
)
333 "Send mtrace request failed for %s on %s: group=%s msg_size=%zd: sent=%zd",
334 dst_str
, ifp
->name
, group_str
,
335 mtrace_buf_len
, sent
);
346 static int mtrace_un_forward_packet(struct pim_instance
*pim
, struct ip
*ip_hdr
,
347 struct interface
*interface
)
349 struct pim_nexthop nexthop
;
350 struct sockaddr_in to
;
351 struct interface
*if_out
;
358 checksum
= ip_hdr
->ip_sum
;
362 if (checksum
!= in_cksum(ip_hdr
, ip_hdr
->ip_hl
* 4))
365 if (ip_hdr
->ip_ttl
-- <= 1)
368 if (interface
== NULL
) {
369 memset(&nexthop
, 0, sizeof(nexthop
));
370 if (!pim_nexthop_lookup(pim
, &nexthop
, ip_hdr
->ip_dst
, 0)) {
371 if (PIM_DEBUG_MTRACE
)
373 "Dropping mtrace packet, no route to destination");
377 if_out
= nexthop
.interface
;
382 ip_hdr
->ip_sum
= in_cksum(ip_hdr
, ip_hdr
->ip_hl
* 4);
384 fd
= pim_socket_raw(IPPROTO_RAW
);
389 pim_socket_ip_hdr(fd
);
391 ret
= pim_socket_bind(fd
, if_out
);
398 memset(&to
, 0, sizeof(to
));
399 to
.sin_family
= AF_INET
;
400 to
.sin_addr
= ip_hdr
->ip_dst
;
403 sent
= sendto(fd
, ip_hdr
, ntohs(ip_hdr
->ip_len
), 0,
404 (struct sockaddr
*)&to
, tolen
);
409 if (PIM_DEBUG_MTRACE
)
411 "Failed to forward mtrace packet: sendto errno=%d, %s",
412 errno
, safe_strerror(errno
));
416 if (PIM_DEBUG_MTRACE
) {
417 zlog_debug("Fwd mtrace packet len=%u to %pI4 ttl=%u",
418 ntohs(ip_hdr
->ip_len
), &ip_hdr
->ip_dst
,
425 static int mtrace_mc_forward_packet(struct pim_instance
*pim
, struct ip
*ip_hdr
)
428 struct channel_oil
*c_oil
;
429 struct listnode
*chnode
;
430 struct listnode
*chnextnode
;
431 struct pim_ifchannel
*ch
= NULL
;
434 memset(&sg
, 0, sizeof(sg
));
435 sg
.grp
= ip_hdr
->ip_dst
;
437 c_oil
= pim_find_channel_oil(pim
, &sg
);
440 if (PIM_DEBUG_MTRACE
) {
442 "Dropping mtrace multicast packet len=%u to %pI4 ttl=%u",
443 ntohs(ip_hdr
->ip_len
),
444 &ip_hdr
->ip_dst
, ip_hdr
->ip_ttl
);
448 if (c_oil
->up
== NULL
)
450 if (c_oil
->up
->ifchannels
== NULL
)
452 for (ALL_LIST_ELEMENTS(c_oil
->up
->ifchannels
, chnode
, chnextnode
, ch
)) {
453 if (pim_macro_chisin_oiflist(ch
)) {
456 r
= mtrace_un_forward_packet(pim
, ip_hdr
,
466 static int mtrace_forward_packet(struct pim_instance
*pim
, struct ip
*ip_hdr
)
468 if (IPV4_CLASS_DE(ntohl(ip_hdr
->ip_dst
.s_addr
)))
469 return mtrace_mc_forward_packet(pim
, ip_hdr
);
471 return mtrace_un_forward_packet(pim
, ip_hdr
, NULL
);
474 static int mtrace_send_mc_response(struct pim_instance
*pim
,
475 struct igmp_mtrace
*mtracep
,
479 struct channel_oil
*c_oil
;
480 struct listnode
*chnode
;
481 struct listnode
*chnextnode
;
482 struct pim_ifchannel
*ch
= NULL
;
485 memset(&sg
, 0, sizeof(sg
));
486 sg
.grp
= mtracep
->rsp_addr
;
488 c_oil
= pim_find_channel_oil(pim
, &sg
);
491 if (PIM_DEBUG_MTRACE
) {
492 struct in_addr rsp_addr
= mtracep
->rsp_addr
;
495 "Dropping mtrace multicast response packet len=%u to %pI4",
496 (unsigned int)mtrace_len
, &rsp_addr
);
500 if (c_oil
->up
== NULL
)
502 if (c_oil
->up
->ifchannels
== NULL
)
504 for (ALL_LIST_ELEMENTS(c_oil
->up
->ifchannels
, chnode
, chnextnode
, ch
)) {
505 if (pim_macro_chisin_oiflist(ch
)) {
508 r
= mtrace_send_packet(ch
->interface
, mtracep
,
509 mtrace_len
, mtracep
->rsp_addr
,
518 /* 6.5 Sending Traceroute Responses */
519 static int mtrace_send_response(struct pim_instance
*pim
,
520 struct igmp_mtrace
*mtracep
, size_t mtrace_len
)
522 struct pim_nexthop nexthop
;
524 mtracep
->type
= PIM_IGMP_MTRACE_RESPONSE
;
526 mtracep
->checksum
= 0;
527 mtracep
->checksum
= in_cksum((char *)mtracep
, mtrace_len
);
529 if (IPV4_CLASS_DE(ntohl(mtracep
->rsp_addr
.s_addr
))) {
530 struct pim_rpf
*p_rpf
;
532 if (pim_rp_i_am_rp(pim
, mtracep
->rsp_addr
))
533 return mtrace_send_mc_response(pim
, mtracep
,
536 p_rpf
= pim_rp_g(pim
, mtracep
->rsp_addr
);
539 if (PIM_DEBUG_MTRACE
) {
540 struct in_addr rsp_addr
= mtracep
->rsp_addr
;
542 zlog_debug("mtrace no RP for %pI4", &rsp_addr
);
546 nexthop
= p_rpf
->source_nexthop
;
547 if (PIM_DEBUG_MTRACE
)
548 zlog_debug("mtrace response to RP");
550 memset(&nexthop
, 0, sizeof(nexthop
));
551 /* TODO: should use unicast rib lookup */
552 if (!pim_nexthop_lookup(pim
, &nexthop
, mtracep
->rsp_addr
, 1)) {
553 if (PIM_DEBUG_MTRACE
)
555 "Dropped response qid=%ud, no route to response address",
561 return mtrace_send_packet(nexthop
.interface
, mtracep
, mtrace_len
,
562 mtracep
->rsp_addr
, mtracep
->grp_addr
);
565 int igmp_mtrace_recv_qry_req(struct gm_sock
*igmp
, struct ip
*ip_hdr
,
566 struct in_addr from
, const char *from_str
,
567 char *igmp_msg
, int igmp_msg_len
)
569 static uint32_t qry_id
, qry_src
;
570 char mtrace_buf
[MTRACE_HDR_SIZE
+ MTRACE_MAX_HOPS
* MTRACE_RSP_SIZE
];
571 struct interface
*ifp
;
572 struct interface
*out_ifp
= NULL
;
573 struct pim_interface
*pim_ifp
;
574 struct pim_instance
*pim
;
575 struct igmp_mtrace
*mtracep
;
576 struct igmp_mtrace_rsp
*rspp
;
577 struct in_addr nh_addr
;
578 enum mtrace_fwd_code fwd_code
= MTRACE_FWD_CODE_NO_ERROR
;
580 int last_rsp_ind
= 0;
582 uint16_t recv_checksum
;
587 ifp
= igmp
->interface
;
592 * 6. Router Behaviour
593 * Check if mtrace packet is addressed elsewhere and forward,
596 if (!IPV4_CLASS_DE(ntohl(ip_hdr
->ip_dst
.s_addr
)))
597 if (!if_address_is_local(&ip_hdr
->ip_dst
, AF_INET
,
599 return mtrace_forward_packet(pim
, ip_hdr
);
601 if (igmp_msg_len
< (int)sizeof(struct igmp_mtrace
)) {
602 if (PIM_DEBUG_MTRACE
)
604 "Recv mtrace packet from %s on %s: too short, len=%d, min=%zu",
605 from_str
, ifp
->name
, igmp_msg_len
,
606 sizeof(struct igmp_mtrace
));
610 mtracep
= (struct igmp_mtrace
*)igmp_msg
;
612 recv_checksum
= mtracep
->checksum
;
614 mtracep
->checksum
= 0;
616 checksum
= in_cksum(igmp_msg
, igmp_msg_len
);
618 if (recv_checksum
!= checksum
) {
619 if (PIM_DEBUG_MTRACE
)
621 "Recv mtrace packet from %s on %s: checksum mismatch: received=%x computed=%x",
622 from_str
, ifp
->name
, recv_checksum
, checksum
);
626 /* Collecting IGMP Rx stats */
627 igmp
->igmp_stats
.mtrace_req
++;
629 if (PIM_DEBUG_MTRACE
)
630 mtrace_debug(pim_ifp
, mtracep
, igmp_msg_len
);
632 /* subtract header from message length */
633 r_len
= igmp_msg_len
- sizeof(struct igmp_mtrace
);
635 /* Classify mtrace packet, check if it is a query */
637 if (PIM_DEBUG_MTRACE
)
638 zlog_debug("Received IGMP multicast traceroute query");
640 /* 6.1.1 Packet verification */
641 if (!pim_if_connected_to_source(ifp
, mtracep
->dst_addr
)) {
642 if (IPV4_CLASS_DE(ntohl(ip_hdr
->ip_dst
.s_addr
))) {
643 if (PIM_DEBUG_MTRACE
)
645 "Dropping multicast query on wrong interface");
648 /* Unicast query on wrong interface */
649 fwd_code
= MTRACE_FWD_CODE_WRONG_IF
;
650 if (PIM_DEBUG_MTRACE
)
651 zlog_debug("Multicast query on wrong interface");
653 if (qry_id
== mtracep
->qry_id
&& qry_src
== from
.s_addr
) {
654 if (PIM_DEBUG_MTRACE
)
656 "Dropping multicast query with duplicate source and id");
659 qry_id
= mtracep
->qry_id
;
660 qry_src
= from
.s_addr
;
662 /* if response fields length is equal to a whole number of responses */
663 else if ((r_len
% sizeof(struct igmp_mtrace_rsp
)) == 0) {
664 r_len
= igmp_msg_len
- sizeof(struct igmp_mtrace
);
667 last_rsp_ind
= r_len
/ sizeof(struct igmp_mtrace_rsp
);
668 if (last_rsp_ind
> MTRACE_MAX_HOPS
) {
669 if (PIM_DEBUG_MTRACE
)
670 zlog_debug("Mtrace request of excessive size");
674 if (PIM_DEBUG_MTRACE
)
676 "Recv mtrace packet from %s on %s: invalid length %d",
677 from_str
, ifp
->name
, igmp_msg_len
);
681 /* 6.2.1 Packet Verification - drop not link-local multicast */
682 if (IPV4_CLASS_DE(ntohl(ip_hdr
->ip_dst
.s_addr
))
683 && !IPV4_MC_LINKLOCAL(ntohl(ip_hdr
->ip_dst
.s_addr
))) {
684 if (PIM_DEBUG_MTRACE
)
686 "Recv mtrace packet from %s on %s: not link-local multicast %pI4",
687 from_str
, ifp
->name
, &ip_hdr
->ip_dst
);
691 /* 6.2.2. Normal Processing */
693 /* 6.2.2. 1. If there is room in the current buffer? */
695 if (last_rsp_ind
== MTRACE_MAX_HOPS
) {
696 /* ...there was no room... */
697 mtracep
->rsp
[MTRACE_MAX_HOPS
- 1].fwd_code
=
698 MTRACE_FWD_CODE_NO_SPACE
;
699 return mtrace_send_response(pim_ifp
->pim
, mtracep
,
703 /* ...insert new response block... */
705 /* calculate new mtrace lenght with extra response */
706 mtrace_len
= igmp_msg_len
+ sizeof(struct igmp_mtrace_rsp
);
708 /* copy received query/request */
709 memcpy(mtrace_buf
, igmp_msg
, igmp_msg_len
);
711 /* repoint mtracep pointer to copy */
712 mtracep
= (struct igmp_mtrace
*)mtrace_buf
;
714 /* pointer for extra response field to be filled in */
715 rspp
= &mtracep
->rsp
[last_rsp_ind
];
717 /* initialize extra response field */
718 mtrace_rsp_init(rspp
);
720 /* carry over any error noted when receiving the query */
721 rspp
->fwd_code
= fwd_code
;
723 /* ...and fill in Query Arrival Time... */
724 rspp
->arrival
= htonl(query_arrival_time());
725 rspp
->outgoing
= pim_ifp
->primary_address
;
726 rspp
->out_count
= htonl(MTRACE_UNKNOWN_COUNT
);
729 /* 6.2.2. 2. Attempt to determine the forwarding information... */
731 if (mtracep
->grp_addr
.s_addr
!= INADDR_ANY
)
732 fwd_info
= mtrace_fwd_info(pim
, mtracep
, rspp
, &out_ifp
);
734 fwd_info
= mtrace_fwd_info_weak(pim
, mtracep
, rspp
, &out_ifp
);
736 /* 6.2.2 3. If no forwarding information... */
738 if (PIM_DEBUG_MTRACE
)
739 zlog_debug("mtrace not found multicast state");
740 mtrace_rsp_set_fwd_code(rspp
, MTRACE_FWD_CODE_NO_ROUTE
);
741 /* 6.2.2. 3. forward the packet to requester */
742 return mtrace_send_response(pim
, mtracep
, mtrace_len
);
745 nh_addr
= rspp
->prev_hop
;
747 reached_source
= false;
749 if (nh_addr
.s_addr
== INADDR_ANY
) {
750 /* no pim? i.e. 7.5.3. No Previous Hop */
751 if (!out_ifp
->info
) {
752 if (PIM_DEBUG_MTRACE
)
753 zlog_debug("mtrace not found incoming if w/ pim");
754 mtrace_rsp_set_fwd_code(rspp
,
755 MTRACE_FWD_CODE_NO_MULTICAST
);
756 return mtrace_send_response(pim
, mtracep
, mtrace_len
);
758 /* reached source? i.e. 7.5.1 Arriving at source */
759 if (pim_if_connected_to_source(out_ifp
, mtracep
->src_addr
)) {
760 reached_source
= true;
761 rspp
->prev_hop
= mtracep
->src_addr
;
764 * 6.4 Forwarding Traceroute Requests:
765 * Previous-hop router not known,
766 * packet is sent to an appropriate multicast address
768 (void)inet_aton(MCAST_ALL_ROUTERS
, &nh_addr
);
771 /* 6.2.2 8. If this router is the Rendez-vous Point */
772 if (mtracep
->grp_addr
.s_addr
!= INADDR_ANY
&&
773 pim_rp_i_am_rp(pim
, mtracep
->grp_addr
)) {
774 mtrace_rsp_set_fwd_code(rspp
, MTRACE_FWD_CODE_REACHED_RP
);
775 /* 7.7.1. PIM-SM ...RP has not performed source-specific join */
776 if (rspp
->src_mask
== MTRACE_SRC_MASK_GROUP
)
777 return mtrace_send_response(pim
, mtracep
, mtrace_len
);
781 * 6.4 Forwarding Traceroute Requests: the number of response
782 * blocks exceeds number of responses, so forward to the requester.
784 if (mtracep
->hops
<= (last_rsp_ind
+ 1))
785 return mtrace_send_response(pim
, mtracep
, mtrace_len
);
787 /* 7.5.1. Arriving at source: terminate trace */
789 return mtrace_send_response(pim
, mtracep
, mtrace_len
);
791 mtracep
->checksum
= 0;
793 mtracep
->checksum
= in_cksum(mtrace_buf
, mtrace_len
);
795 /* 6.4 Forwarding Traceroute Requests: response blocks less than req. */
796 return mtrace_send_packet(out_ifp
, mtracep
, mtrace_len
, nh_addr
,
800 /* 6.3. Traceroute responses */
801 int igmp_mtrace_recv_response(struct gm_sock
*igmp
, struct ip
*ip_hdr
,
802 struct in_addr from
, const char *from_str
,
803 char *igmp_msg
, int igmp_msg_len
)
805 static uint32_t qry_id
, rsp_dst
;
806 struct interface
*ifp
;
807 struct pim_interface
*pim_ifp
;
808 struct pim_instance
*pim
;
809 struct igmp_mtrace
*mtracep
;
810 uint16_t recv_checksum
;
813 ifp
= igmp
->interface
;
817 if (igmp_msg_len
< (int)sizeof(struct igmp_mtrace
)) {
818 if (PIM_DEBUG_MTRACE
)
820 "Recv mtrace packet from %s on %s: too short, len=%d, min=%zu",
821 from_str
, ifp
->name
, igmp_msg_len
,
822 sizeof(struct igmp_mtrace
));
826 mtracep
= (struct igmp_mtrace
*)igmp_msg
;
828 recv_checksum
= mtracep
->checksum
;
830 mtracep
->checksum
= 0;
832 checksum
= in_cksum(igmp_msg
, igmp_msg_len
);
834 if (recv_checksum
!= checksum
) {
835 if (PIM_DEBUG_MTRACE
)
837 "Recv mtrace response from %s on %s: checksum mismatch: received=%x computed=%x",
838 from_str
, ifp
->name
, recv_checksum
, checksum
);
842 mtracep
->checksum
= checksum
;
844 /* Collecting IGMP Rx stats */
845 igmp
->igmp_stats
.mtrace_rsp
++;
847 if (PIM_DEBUG_MTRACE
)
848 mtrace_debug(pim_ifp
, mtracep
, igmp_msg_len
);
850 /* Drop duplicate packets */
851 if (qry_id
== mtracep
->qry_id
&& rsp_dst
== ip_hdr
->ip_dst
.s_addr
) {
852 if (PIM_DEBUG_MTRACE
)
853 zlog_debug("duplicate mtrace response packet dropped");
857 qry_id
= mtracep
->qry_id
;
858 rsp_dst
= ip_hdr
->ip_dst
.s_addr
;
860 return mtrace_forward_packet(pim
, ip_hdr
);