]> git.proxmox.com Git - mirror_frr.git/blobdiff - pimd/pim_igmp_mtrace.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / pimd / pim_igmp_mtrace.c
index 11bb2db7eba019e8328da90ebcc71da7f7fd3c81..4d3f6022a1d6418b4417c0a9b7c8e8dac740c4bf 100644 (file)
@@ -1,20 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Multicast traceroute for FRRouting
  * Copyright (C) 2017  Mladen Sablic
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /* based on draft-ietf-idmr-traceroute-ipm-07 */
@@ -22,6 +9,7 @@
 #include <zebra.h>
 
 #include "pimd.h"
+#include "pim_instance.h"
 #include "pim_util.h"
 #include "pim_sock.h"
 #include "pim_rp.h"
@@ -81,11 +69,9 @@ static bool mtrace_fwd_info_weak(struct pim_instance *pim,
                zlog_debug("mtrace pim_nexthop_lookup OK");
 
        if (PIM_DEBUG_MTRACE)
-               zlog_debug("mtrace next_hop=%pI4",
-                          &nexthop.mrib_nexthop_addr.u.prefix4);
+               zlog_debug("mtrace next_hop=%pPAs", &nexthop.mrib_nexthop_addr);
 
-       if (nexthop.mrib_nexthop_addr.family == AF_INET)
-               nh_addr = nexthop.mrib_nexthop_addr.u.prefix4;
+       nh_addr = nexthop.mrib_nexthop_addr;
 
        ifp_in = nexthop.interface;
 
@@ -134,7 +120,7 @@ static bool mtrace_fwd_info(struct pim_instance *pim,
        }
 
        ifp_in = up->rpf.source_nexthop.interface;
-       nh_addr = up->rpf.source_nexthop.mrib_nexthop_addr.u.prefix4;
+       nh_addr = up->rpf.source_nexthop.mrib_nexthop_addr;
        total = htonl(MTRACE_UNKNOWN_COUNT);
 
        if (PIM_DEBUG_MTRACE)
@@ -366,19 +352,9 @@ static int mtrace_un_forward_packet(struct pim_instance *pim, struct ip *ip_hdr,
        if (ip_hdr->ip_ttl-- <= 1)
                return -1;
 
-       ip_hdr->ip_sum = in_cksum(ip_hdr, ip_hdr->ip_hl * 4);
-
-       fd = pim_socket_raw(IPPROTO_RAW);
-
-       if (fd < 0)
-               return -1;
-
-       pim_socket_ip_hdr(fd);
-
        if (interface == NULL) {
                memset(&nexthop, 0, sizeof(nexthop));
                if (!pim_nexthop_lookup(pim, &nexthop, ip_hdr->ip_dst, 0)) {
-                       close(fd);
                        if (PIM_DEBUG_MTRACE)
                                zlog_debug(
                                        "Dropping mtrace packet, no route to destination");
@@ -390,6 +366,15 @@ static int mtrace_un_forward_packet(struct pim_instance *pim, struct ip *ip_hdr,
                if_out = interface;
        }
 
+       ip_hdr->ip_sum = in_cksum(ip_hdr, ip_hdr->ip_hl * 4);
+
+       fd = pim_socket_raw(IPPROTO_RAW);
+
+       if (fd < 0)
+               return -1;
+
+       pim_socket_ip_hdr(fd);
+
        ret = pim_socket_bind(fd, if_out);
 
        if (ret < 0) {
@@ -771,7 +756,8 @@ int igmp_mtrace_recv_qry_req(struct gm_sock *igmp, struct ip *ip_hdr,
        }
 
        /* 6.2.2 8. If this router is the Rendez-vous Point */
-       if (pim_rp_i_am_rp(pim, mtracep->grp_addr)) {
+       if (mtracep->grp_addr.s_addr != INADDR_ANY &&
+           pim_rp_i_am_rp(pim, mtracep->grp_addr)) {
                mtrace_rsp_set_fwd_code(rspp, MTRACE_FWD_CODE_REACHED_RP);
                /* 7.7.1. PIM-SM ...RP has not performed source-specific join */
                if (rspp->src_mask == MTRACE_SRC_MASK_GROUP)