summaryrefslogtreecommitdiff
path: root/pimd/pim_igmp_mtrace.c
diff options
context:
space:
mode:
authoranlan_cs <vic.lan@pica8.com>2022-11-09 03:53:11 -0500
committeranlan_cs <vic.lan@pica8.com>2022-11-09 04:11:23 -0500
commitb46fd5002938aa1c985ddf7af9ab22bd4c17c033 (patch)
tree2467e6ca147b9891731c8e84c7f6b8caffe88cf3 /pimd/pim_igmp_mtrace.c
parent25bc53234d8e8c341108c16689a68b5b3bf735ce (diff)
pimd: delay creating the socket
Bring error handling up front and delay creating socket so that we don't think too much about closing the socket in error cases. Signed-off-by: anlan_cs <vic.lan@pica8.com>
Diffstat (limited to 'pimd/pim_igmp_mtrace.c')
-rw-r--r--pimd/pim_igmp_mtrace.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/pimd/pim_igmp_mtrace.c b/pimd/pim_igmp_mtrace.c
index 1a90b46dec..259c34c819 100644
--- a/pimd/pim_igmp_mtrace.c
+++ b/pimd/pim_igmp_mtrace.c
@@ -365,19 +365,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 +379,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) {