]> 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 1a90b46dec516c50a15eff9e2727b2f3031b65b4..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) {