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 */
29 #include "pim_ifchannel.h"
30 #include "pim_macro.h"
31 #include "pim_igmp_mtrace.h"
33 static struct in_addr
mtrace_primary_address(struct interface
*ifp
)
35 struct connected
*ifc
;
36 struct listnode
*node
;
38 struct pim_interface
*pim_ifp
;
42 return pim_ifp
->primary_address
;
45 any
.s_addr
= INADDR_ANY
;
47 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, ifc
)) {
48 struct prefix
*p
= ifc
->address
;
50 if (p
->family
!= AF_INET
)
53 if (!CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
))
55 /* in case no primary found, return a secondary */
61 static bool mtrace_fwd_info_weak(struct pim_instance
*pim
,
62 struct igmp_mtrace
*mtracep
,
63 struct igmp_mtrace_rsp
*rspp
,
64 struct interface
**ifpp
)
66 struct pim_nexthop nexthop
;
67 struct interface
*ifp_in
;
68 struct in_addr nh_addr
;
70 nh_addr
.s_addr
= INADDR_ANY
;
72 memset(&nexthop
, 0, sizeof(nexthop
));
74 if (!pim_nexthop_lookup(pim
, &nexthop
, mtracep
->src_addr
, 1)) {
76 zlog_debug("mtrace not found neighbor");
81 zlog_debug("mtrace pim_nexthop_lookup OK");
84 zlog_debug("mtrace next_hop=%pI4",
85 &nexthop
.mrib_nexthop_addr
.u
.prefix4
);
87 if (nexthop
.mrib_nexthop_addr
.family
== AF_INET
)
88 nh_addr
= nexthop
.mrib_nexthop_addr
.u
.prefix4
;
90 ifp_in
= nexthop
.interface
;
92 /* return interface for forwarding mtrace packets */
95 /* 6.2.2. 4. Fill in the Incoming Interface Address... */
96 rspp
->incoming
= mtrace_primary_address(ifp_in
);
97 rspp
->prev_hop
= nh_addr
;
98 rspp
->in_count
= htonl(MTRACE_UNKNOWN_COUNT
);
99 rspp
->total
= htonl(MTRACE_UNKNOWN_COUNT
);
100 rspp
->rtg_proto
= MTRACE_RTG_PROTO_PIM
;
104 static bool mtrace_fwd_info(struct pim_instance
*pim
,
105 struct igmp_mtrace
*mtracep
,
106 struct igmp_mtrace_rsp
*rspp
,
107 struct interface
**ifpp
)
110 struct pim_upstream
*up
;
111 struct interface
*ifp_in
;
112 struct in_addr nh_addr
;
115 memset(&sg
, 0, sizeof(sg
));
116 sg
.src
= mtracep
->src_addr
;
117 sg
.grp
= mtracep
->grp_addr
;
119 up
= pim_upstream_find(pim
, &sg
);
122 sg
.src
= PIMADDR_ANY
;
123 up
= pim_upstream_find(pim
, &sg
);
129 if (!up
->rpf
.source_nexthop
.interface
) {
131 zlog_debug("%s: up %s RPF is not present", __func__
,
136 ifp_in
= up
->rpf
.source_nexthop
.interface
;
137 nh_addr
= up
->rpf
.source_nexthop
.mrib_nexthop_addr
.u
.prefix4
;
138 total
= htonl(MTRACE_UNKNOWN_COUNT
);
140 if (PIM_DEBUG_MTRACE
)
141 zlog_debug("fwd_info: upstream next hop=%pI4", &nh_addr
);
144 total
= up
->channel_oil
->cc
.pktcnt
;
146 /* return interface for forwarding mtrace packets */
149 /* 6.2.2. 4. Fill in the Incoming Interface Address... */
150 rspp
->incoming
= mtrace_primary_address(ifp_in
);
151 rspp
->prev_hop
= nh_addr
;
152 rspp
->in_count
= htonl(MTRACE_UNKNOWN_COUNT
);
154 rspp
->rtg_proto
= MTRACE_RTG_PROTO_PIM
;
156 /* 6.2.2. 4. Fill in ... S, and Src Mask */
157 if (!pim_addr_is_any(sg
.src
)) {
159 rspp
->src_mask
= MTRACE_SRC_MASK_SOURCE
;
162 rspp
->src_mask
= MTRACE_SRC_MASK_GROUP
;
168 static void mtrace_rsp_set_fwd_code(struct igmp_mtrace_rsp
*mtrace_rspp
,
169 enum mtrace_fwd_code fwd_code
)
171 if (mtrace_rspp
->fwd_code
== MTRACE_FWD_CODE_NO_ERROR
)
172 mtrace_rspp
->fwd_code
= fwd_code
;
175 static void mtrace_rsp_init(struct igmp_mtrace_rsp
*mtrace_rspp
)
177 mtrace_rspp
->arrival
= 0;
178 mtrace_rspp
->incoming
.s_addr
= INADDR_ANY
;
179 mtrace_rspp
->outgoing
.s_addr
= INADDR_ANY
;
180 mtrace_rspp
->prev_hop
.s_addr
= INADDR_ANY
;
181 mtrace_rspp
->in_count
= htonl(MTRACE_UNKNOWN_COUNT
);
182 mtrace_rspp
->out_count
= htonl(MTRACE_UNKNOWN_COUNT
);
183 mtrace_rspp
->total
= htonl(MTRACE_UNKNOWN_COUNT
);
184 mtrace_rspp
->rtg_proto
= 0;
185 mtrace_rspp
->fwd_ttl
= 0;
186 mtrace_rspp
->mbz
= 0;
188 mtrace_rspp
->src_mask
= 0;
189 mtrace_rspp
->fwd_code
= MTRACE_FWD_CODE_NO_ERROR
;
192 static void mtrace_rsp_debug(uint32_t qry_id
, int rsp
,
193 struct igmp_mtrace_rsp
*mrspp
)
195 struct in_addr incoming
= mrspp
->incoming
;
196 struct in_addr outgoing
= mrspp
->outgoing
;
197 struct in_addr prev_hop
= mrspp
->prev_hop
;
200 "Rx mt(%d) qid=%ud arr=%x in=%pI4 out=%pI4 prev=%pI4 proto=%d fwd=%d",
201 rsp
, ntohl(qry_id
), mrspp
->arrival
, &incoming
, &outgoing
,
202 &prev_hop
, mrspp
->rtg_proto
, mrspp
->fwd_code
);
205 static void mtrace_debug(struct pim_interface
*pim_ifp
,
206 struct igmp_mtrace
*mtracep
, int mtrace_len
)
208 struct in_addr ga
, sa
, da
, ra
;
210 ga
= mtracep
->grp_addr
;
211 sa
= mtracep
->src_addr
;
212 da
= mtracep
->dst_addr
;
213 ra
= mtracep
->rsp_addr
;
216 "Rx mtrace packet incoming on %pI4: hops=%d type=%d size=%d, grp=%pI4, src=%pI4, dst=%pI4 rsp=%pI4 ttl=%d qid=%ud",
217 &pim_ifp
->primary_address
, mtracep
->hops
, mtracep
->type
,
218 mtrace_len
, &ga
, &sa
, &da
, &ra
, mtracep
->rsp_ttl
,
219 ntohl(mtracep
->qry_id
));
220 if (mtrace_len
> (int)sizeof(struct igmp_mtrace
)) {
224 int responses
= mtrace_len
- sizeof(struct igmp_mtrace
);
226 if ((responses
% sizeof(struct igmp_mtrace_rsp
)) != 0)
227 if (PIM_DEBUG_MTRACE
)
229 "Mtrace response block of wrong length");
231 responses
= responses
/ sizeof(struct igmp_mtrace_rsp
);
233 for (i
= 0; i
< responses
; i
++)
234 mtrace_rsp_debug(mtracep
->qry_id
, i
, &mtracep
->rsp
[i
]);
238 /* 5.1 Query Arrival Time */
239 static uint32_t query_arrival_time(void)
244 if (gettimeofday(&tv
, NULL
) < 0) {
245 if (PIM_DEBUG_MTRACE
)
246 zlog_debug("Query arrival time lookup failed: errno=%d: %s",
247 errno
, safe_strerror(errno
));
250 /* not sure second offset correct, as I get different value */
251 qat
= ((tv
.tv_sec
+ 32384) << 16) + ((tv
.tv_usec
<< 10) / 15625);
256 static int mtrace_send_packet(struct interface
*ifp
,
257 struct igmp_mtrace
*mtracep
,
258 size_t mtrace_buf_len
, struct in_addr dst_addr
,
259 struct in_addr group_addr
)
261 struct sockaddr_in to
;
268 memset(&to
, 0, sizeof(to
));
269 to
.sin_family
= AF_INET
;
270 to
.sin_addr
= dst_addr
;
273 if (PIM_DEBUG_MTRACE
) {
274 struct in_addr if_addr
;
275 struct in_addr rsp_addr
= mtracep
->rsp_addr
;
277 if_addr
= mtrace_primary_address(ifp
);
278 zlog_debug("Sending mtrace packet to %pI4 on %pI4", &rsp_addr
,
282 fd
= pim_socket_raw(IPPROTO_IGMP
);
287 ret
= pim_socket_bind(fd
, ifp
);
294 if (IPV4_CLASS_DE(ntohl(dst_addr
.s_addr
))) {
295 if (IPV4_MC_LINKLOCAL(ntohl(dst_addr
.s_addr
))) {
298 if (mtracep
->type
== PIM_IGMP_MTRACE_RESPONSE
)
299 ttl
= mtracep
->rsp_ttl
;
303 ret
= setsockopt(fd
, IPPROTO_IP
, IP_MULTICAST_TTL
, &ttl
,
307 if (PIM_DEBUG_MTRACE
)
308 zlog_debug("Failed to set socket multicast TTL");
314 sent
= sendto(fd
, (char *)mtracep
, mtrace_buf_len
, MSG_DONTWAIT
,
315 (struct sockaddr
*)&to
, tolen
);
317 if (sent
!= (ssize_t
)mtrace_buf_len
) {
318 char dst_str
[INET_ADDRSTRLEN
];
319 char group_str
[INET_ADDRSTRLEN
];
321 pim_inet4_dump("<dst?>", dst_addr
, dst_str
, sizeof(dst_str
));
322 pim_inet4_dump("<group?>", group_addr
, group_str
,
325 if (PIM_DEBUG_MTRACE
)
327 "Send mtrace request failed for %s on%s: group=%s msg_size=%zd: errno=%d: %s",
328 dst_str
, ifp
->name
, group_str
,
329 mtrace_buf_len
, errno
,
330 safe_strerror(errno
));
332 if (PIM_DEBUG_MTRACE
)
334 "Send mtrace request failed for %s on %s: group=%s msg_size=%zd: sent=%zd",
335 dst_str
, ifp
->name
, group_str
,
336 mtrace_buf_len
, sent
);
347 static int mtrace_un_forward_packet(struct pim_instance
*pim
, struct ip
*ip_hdr
,
348 struct interface
*interface
)
350 struct pim_nexthop nexthop
;
351 struct sockaddr_in to
;
352 struct interface
*if_out
;
359 checksum
= ip_hdr
->ip_sum
;
363 if (checksum
!= in_cksum(ip_hdr
, ip_hdr
->ip_hl
* 4))
366 if (ip_hdr
->ip_ttl
-- <= 1)
369 ip_hdr
->ip_sum
= in_cksum(ip_hdr
, ip_hdr
->ip_hl
* 4);
371 fd
= pim_socket_raw(IPPROTO_RAW
);
376 pim_socket_ip_hdr(fd
);
378 if (interface
== NULL
) {
379 memset(&nexthop
, 0, sizeof(nexthop
));
380 if (!pim_nexthop_lookup(pim
, &nexthop
, ip_hdr
->ip_dst
, 0)) {
382 if (PIM_DEBUG_MTRACE
)
384 "Dropping mtrace packet, no route to destination");
388 if_out
= nexthop
.interface
;
393 ret
= pim_socket_bind(fd
, if_out
);
400 memset(&to
, 0, sizeof(to
));
401 to
.sin_family
= AF_INET
;
402 to
.sin_addr
= ip_hdr
->ip_dst
;
405 sent
= sendto(fd
, ip_hdr
, ntohs(ip_hdr
->ip_len
), 0,
406 (struct sockaddr
*)&to
, tolen
);
411 if (PIM_DEBUG_MTRACE
)
413 "Failed to forward mtrace packet: sendto errno=%d, %s",
414 errno
, safe_strerror(errno
));
418 if (PIM_DEBUG_MTRACE
) {
419 zlog_debug("Fwd mtrace packet len=%u to %pI4 ttl=%u",
420 ntohs(ip_hdr
->ip_len
), &ip_hdr
->ip_dst
,
427 static int mtrace_mc_forward_packet(struct pim_instance
*pim
, struct ip
*ip_hdr
)
430 struct channel_oil
*c_oil
;
431 struct listnode
*chnode
;
432 struct listnode
*chnextnode
;
433 struct pim_ifchannel
*ch
= NULL
;
436 memset(&sg
, 0, sizeof(sg
));
437 sg
.grp
= ip_hdr
->ip_dst
;
439 c_oil
= pim_find_channel_oil(pim
, &sg
);
442 if (PIM_DEBUG_MTRACE
) {
444 "Dropping mtrace multicast packet len=%u to %pI4 ttl=%u",
445 ntohs(ip_hdr
->ip_len
),
446 &ip_hdr
->ip_dst
, ip_hdr
->ip_ttl
);
450 if (c_oil
->up
== NULL
)
452 if (c_oil
->up
->ifchannels
== NULL
)
454 for (ALL_LIST_ELEMENTS(c_oil
->up
->ifchannels
, chnode
, chnextnode
, ch
)) {
455 if (pim_macro_chisin_oiflist(ch
)) {
458 r
= mtrace_un_forward_packet(pim
, ip_hdr
,
468 static int mtrace_forward_packet(struct pim_instance
*pim
, struct ip
*ip_hdr
)
470 if (IPV4_CLASS_DE(ntohl(ip_hdr
->ip_dst
.s_addr
)))
471 return mtrace_mc_forward_packet(pim
, ip_hdr
);
473 return mtrace_un_forward_packet(pim
, ip_hdr
, NULL
);
476 static int mtrace_send_mc_response(struct pim_instance
*pim
,
477 struct igmp_mtrace
*mtracep
,
481 struct channel_oil
*c_oil
;
482 struct listnode
*chnode
;
483 struct listnode
*chnextnode
;
484 struct pim_ifchannel
*ch
= NULL
;
487 memset(&sg
, 0, sizeof(sg
));
488 sg
.grp
= mtracep
->rsp_addr
;
490 c_oil
= pim_find_channel_oil(pim
, &sg
);
493 if (PIM_DEBUG_MTRACE
) {
494 struct in_addr rsp_addr
= mtracep
->rsp_addr
;
497 "Dropping mtrace multicast response packet len=%u to %pI4",
498 (unsigned int)mtrace_len
, &rsp_addr
);
502 if (c_oil
->up
== NULL
)
504 if (c_oil
->up
->ifchannels
== NULL
)
506 for (ALL_LIST_ELEMENTS(c_oil
->up
->ifchannels
, chnode
, chnextnode
, ch
)) {
507 if (pim_macro_chisin_oiflist(ch
)) {
510 r
= mtrace_send_packet(ch
->interface
, mtracep
,
511 mtrace_len
, mtracep
->rsp_addr
,
520 /* 6.5 Sending Traceroute Responses */
521 static int mtrace_send_response(struct pim_instance
*pim
,
522 struct igmp_mtrace
*mtracep
, size_t mtrace_len
)
524 struct pim_nexthop nexthop
;
526 mtracep
->type
= PIM_IGMP_MTRACE_RESPONSE
;
528 mtracep
->checksum
= 0;
529 mtracep
->checksum
= in_cksum((char *)mtracep
, mtrace_len
);
531 if (IPV4_CLASS_DE(ntohl(mtracep
->rsp_addr
.s_addr
))) {
532 struct pim_rpf
*p_rpf
;
534 if (pim_rp_i_am_rp(pim
, mtracep
->rsp_addr
))
535 return mtrace_send_mc_response(pim
, mtracep
,
538 p_rpf
= pim_rp_g(pim
, mtracep
->rsp_addr
);
541 if (PIM_DEBUG_MTRACE
) {
542 struct in_addr rsp_addr
= mtracep
->rsp_addr
;
544 zlog_debug("mtrace no RP for %pI4", &rsp_addr
);
548 nexthop
= p_rpf
->source_nexthop
;
549 if (PIM_DEBUG_MTRACE
)
550 zlog_debug("mtrace response to RP");
552 memset(&nexthop
, 0, sizeof(nexthop
));
553 /* TODO: should use unicast rib lookup */
554 if (!pim_nexthop_lookup(pim
, &nexthop
, mtracep
->rsp_addr
, 1)) {
555 if (PIM_DEBUG_MTRACE
)
557 "Dropped response qid=%ud, no route to response address",
563 return mtrace_send_packet(nexthop
.interface
, mtracep
, mtrace_len
,
564 mtracep
->rsp_addr
, mtracep
->grp_addr
);
567 int igmp_mtrace_recv_qry_req(struct gm_sock
*igmp
, struct ip
*ip_hdr
,
568 struct in_addr from
, const char *from_str
,
569 char *igmp_msg
, int igmp_msg_len
)
571 static uint32_t qry_id
, qry_src
;
572 char mtrace_buf
[MTRACE_HDR_SIZE
+ MTRACE_MAX_HOPS
* MTRACE_RSP_SIZE
];
573 struct interface
*ifp
;
574 struct interface
*out_ifp
= NULL
;
575 struct pim_interface
*pim_ifp
;
576 struct pim_instance
*pim
;
577 struct igmp_mtrace
*mtracep
;
578 struct igmp_mtrace_rsp
*rspp
;
579 struct in_addr nh_addr
;
580 enum mtrace_fwd_code fwd_code
= MTRACE_FWD_CODE_NO_ERROR
;
582 int last_rsp_ind
= 0;
584 uint16_t recv_checksum
;
589 ifp
= igmp
->interface
;
594 * 6. Router Behaviour
595 * Check if mtrace packet is addressed elsewhere and forward,
598 if (!IPV4_CLASS_DE(ntohl(ip_hdr
->ip_dst
.s_addr
)))
599 if (!if_address_is_local(&ip_hdr
->ip_dst
, AF_INET
,
601 return mtrace_forward_packet(pim
, ip_hdr
);
603 if (igmp_msg_len
< (int)sizeof(struct igmp_mtrace
)) {
604 if (PIM_DEBUG_MTRACE
)
606 "Recv mtrace packet from %s on %s: too short, len=%d, min=%zu",
607 from_str
, ifp
->name
, igmp_msg_len
,
608 sizeof(struct igmp_mtrace
));
612 mtracep
= (struct igmp_mtrace
*)igmp_msg
;
614 recv_checksum
= mtracep
->checksum
;
616 mtracep
->checksum
= 0;
618 checksum
= in_cksum(igmp_msg
, igmp_msg_len
);
620 if (recv_checksum
!= checksum
) {
621 if (PIM_DEBUG_MTRACE
)
623 "Recv mtrace packet from %s on %s: checksum mismatch: received=%x computed=%x",
624 from_str
, ifp
->name
, recv_checksum
, checksum
);
628 /* Collecting IGMP Rx stats */
629 igmp
->igmp_stats
.mtrace_req
++;
631 if (PIM_DEBUG_MTRACE
)
632 mtrace_debug(pim_ifp
, mtracep
, igmp_msg_len
);
634 /* subtract header from message length */
635 r_len
= igmp_msg_len
- sizeof(struct igmp_mtrace
);
637 /* Classify mtrace packet, check if it is a query */
639 if (PIM_DEBUG_MTRACE
)
640 zlog_debug("Received IGMP multicast traceroute query");
642 /* 6.1.1 Packet verification */
643 if (!pim_if_connected_to_source(ifp
, mtracep
->dst_addr
)) {
644 if (IPV4_CLASS_DE(ntohl(ip_hdr
->ip_dst
.s_addr
))) {
645 if (PIM_DEBUG_MTRACE
)
647 "Dropping multicast query on wrong interface");
650 /* Unicast query on wrong interface */
651 fwd_code
= MTRACE_FWD_CODE_WRONG_IF
;
652 if (PIM_DEBUG_MTRACE
)
653 zlog_debug("Multicast query on wrong interface");
655 if (qry_id
== mtracep
->qry_id
&& qry_src
== from
.s_addr
) {
656 if (PIM_DEBUG_MTRACE
)
658 "Dropping multicast query with duplicate source and id");
661 qry_id
= mtracep
->qry_id
;
662 qry_src
= from
.s_addr
;
664 /* if response fields length is equal to a whole number of responses */
665 else if ((r_len
% sizeof(struct igmp_mtrace_rsp
)) == 0) {
666 r_len
= igmp_msg_len
- sizeof(struct igmp_mtrace
);
669 last_rsp_ind
= r_len
/ sizeof(struct igmp_mtrace_rsp
);
670 if (last_rsp_ind
> MTRACE_MAX_HOPS
) {
671 if (PIM_DEBUG_MTRACE
)
672 zlog_debug("Mtrace request of excessive size");
676 if (PIM_DEBUG_MTRACE
)
678 "Recv mtrace packet from %s on %s: invalid length %d",
679 from_str
, ifp
->name
, igmp_msg_len
);
683 /* 6.2.1 Packet Verification - drop not link-local multicast */
684 if (IPV4_CLASS_DE(ntohl(ip_hdr
->ip_dst
.s_addr
))
685 && !IPV4_MC_LINKLOCAL(ntohl(ip_hdr
->ip_dst
.s_addr
))) {
686 if (PIM_DEBUG_MTRACE
)
688 "Recv mtrace packet from %s on %s: not link-local multicast %pI4",
689 from_str
, ifp
->name
, &ip_hdr
->ip_dst
);
693 /* 6.2.2. Normal Processing */
695 /* 6.2.2. 1. If there is room in the current buffer? */
697 if (last_rsp_ind
== MTRACE_MAX_HOPS
) {
698 /* ...there was no room... */
699 mtracep
->rsp
[MTRACE_MAX_HOPS
- 1].fwd_code
=
700 MTRACE_FWD_CODE_NO_SPACE
;
701 return mtrace_send_response(pim_ifp
->pim
, mtracep
,
705 /* ...insert new response block... */
707 /* calculate new mtrace lenght with extra response */
708 mtrace_len
= igmp_msg_len
+ sizeof(struct igmp_mtrace_rsp
);
710 /* copy received query/request */
711 memcpy(mtrace_buf
, igmp_msg
, igmp_msg_len
);
713 /* repoint mtracep pointer to copy */
714 mtracep
= (struct igmp_mtrace
*)mtrace_buf
;
716 /* pointer for extra response field to be filled in */
717 rspp
= &mtracep
->rsp
[last_rsp_ind
];
719 /* initialize extra response field */
720 mtrace_rsp_init(rspp
);
722 /* carry over any error noted when receiving the query */
723 rspp
->fwd_code
= fwd_code
;
725 /* ...and fill in Query Arrival Time... */
726 rspp
->arrival
= htonl(query_arrival_time());
727 rspp
->outgoing
= pim_ifp
->primary_address
;
728 rspp
->out_count
= htonl(MTRACE_UNKNOWN_COUNT
);
731 /* 6.2.2. 2. Attempt to determine the forwarding information... */
733 if (mtracep
->grp_addr
.s_addr
!= INADDR_ANY
)
734 fwd_info
= mtrace_fwd_info(pim
, mtracep
, rspp
, &out_ifp
);
736 fwd_info
= mtrace_fwd_info_weak(pim
, mtracep
, rspp
, &out_ifp
);
738 /* 6.2.2 3. If no forwarding information... */
740 if (PIM_DEBUG_MTRACE
)
741 zlog_debug("mtrace not found multicast state");
742 mtrace_rsp_set_fwd_code(rspp
, MTRACE_FWD_CODE_NO_ROUTE
);
743 /* 6.2.2. 3. forward the packet to requester */
744 return mtrace_send_response(pim
, mtracep
, mtrace_len
);
747 nh_addr
= rspp
->prev_hop
;
749 reached_source
= false;
751 if (nh_addr
.s_addr
== INADDR_ANY
) {
752 /* no pim? i.e. 7.5.3. No Previous Hop */
753 if (!out_ifp
->info
) {
754 if (PIM_DEBUG_MTRACE
)
755 zlog_debug("mtrace not found incoming if w/ pim");
756 mtrace_rsp_set_fwd_code(rspp
,
757 MTRACE_FWD_CODE_NO_MULTICAST
);
758 return mtrace_send_response(pim
, mtracep
, mtrace_len
);
760 /* reached source? i.e. 7.5.1 Arriving at source */
761 if (pim_if_connected_to_source(out_ifp
, mtracep
->src_addr
)) {
762 reached_source
= true;
763 rspp
->prev_hop
= mtracep
->src_addr
;
766 * 6.4 Forwarding Traceroute Requests:
767 * Previous-hop router not known,
768 * packet is sent to an appropriate multicast address
770 (void)inet_aton(MCAST_ALL_ROUTERS
, &nh_addr
);
773 /* 6.2.2 8. If this router is the Rendez-vous Point */
774 if (pim_rp_i_am_rp(pim
, mtracep
->grp_addr
)) {
775 mtrace_rsp_set_fwd_code(rspp
, MTRACE_FWD_CODE_REACHED_RP
);
776 /* 7.7.1. PIM-SM ...RP has not performed source-specific join */
777 if (rspp
->src_mask
== MTRACE_SRC_MASK_GROUP
)
778 return mtrace_send_response(pim
, mtracep
, mtrace_len
);
782 * 6.4 Forwarding Traceroute Requests: the number of response
783 * blocks exceeds number of responses, so forward to the requester.
785 if (mtracep
->hops
<= (last_rsp_ind
+ 1))
786 return mtrace_send_response(pim
, mtracep
, mtrace_len
);
788 /* 7.5.1. Arriving at source: terminate trace */
790 return mtrace_send_response(pim
, mtracep
, mtrace_len
);
792 mtracep
->checksum
= 0;
794 mtracep
->checksum
= in_cksum(mtrace_buf
, mtrace_len
);
796 /* 6.4 Forwarding Traceroute Requests: response blocks less than req. */
797 return mtrace_send_packet(out_ifp
, mtracep
, mtrace_len
, nh_addr
,
801 /* 6.3. Traceroute responses */
802 int igmp_mtrace_recv_response(struct gm_sock
*igmp
, struct ip
*ip_hdr
,
803 struct in_addr from
, const char *from_str
,
804 char *igmp_msg
, int igmp_msg_len
)
806 static uint32_t qry_id
, rsp_dst
;
807 struct interface
*ifp
;
808 struct pim_interface
*pim_ifp
;
809 struct pim_instance
*pim
;
810 struct igmp_mtrace
*mtracep
;
811 uint16_t recv_checksum
;
814 ifp
= igmp
->interface
;
818 if (igmp_msg_len
< (int)sizeof(struct igmp_mtrace
)) {
819 if (PIM_DEBUG_MTRACE
)
821 "Recv mtrace packet from %s on %s: too short, len=%d, min=%zu",
822 from_str
, ifp
->name
, igmp_msg_len
,
823 sizeof(struct igmp_mtrace
));
827 mtracep
= (struct igmp_mtrace
*)igmp_msg
;
829 recv_checksum
= mtracep
->checksum
;
831 mtracep
->checksum
= 0;
833 checksum
= in_cksum(igmp_msg
, igmp_msg_len
);
835 if (recv_checksum
!= checksum
) {
836 if (PIM_DEBUG_MTRACE
)
838 "Recv mtrace response from %s on %s: checksum mismatch: received=%x computed=%x",
839 from_str
, ifp
->name
, recv_checksum
, checksum
);
843 mtracep
->checksum
= checksum
;
845 /* Collecting IGMP Rx stats */
846 igmp
->igmp_stats
.mtrace_rsp
++;
848 if (PIM_DEBUG_MTRACE
)
849 mtrace_debug(pim_ifp
, mtracep
, igmp_msg_len
);
851 /* Drop duplicate packets */
852 if (qry_id
== mtracep
->qry_id
&& rsp_dst
== ip_hdr
->ip_dst
.s_addr
) {
853 if (PIM_DEBUG_MTRACE
)
854 zlog_debug("duplicate mtrace response packet dropped");
858 qry_id
= mtracep
->qry_id
;
859 rsp_dst
= ip_hdr
->ip_dst
.s_addr
;
861 return mtrace_forward_packet(pim
, ip_hdr
);