]> 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 f6c23c8e89a184bc442b530e8cd3125757c16c4c..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 */
@@ -365,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");
@@ -389,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) {
@@ -770,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)