From: Roy Marples Date: Tue, 12 Nov 2013 15:00:22 +0000 (+0000) Subject: Cleanup IPv4 fd opening and closing. X-Git-Tag: v6.2.0~58 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fd598623dffd8a340eda8b9802dc613f9137c2f6;p=thirdparty%2Fdhcpcd.git Cleanup IPv4 fd opening and closing. --- diff --git a/arp.c b/arp.c index f9e49cc5..46230905 100644 --- a/arp.c +++ b/arp.c @@ -220,7 +220,11 @@ arp_announce(void *arg) if (state->new == NULL) return; if (state->arp_fd == -1) { - ipv4_opensocket(ifp, ETHERTYPE_ARP); + state->arp_fd = ipv4_opensocket(ifp, ETHERTYPE_ARP); + if (state->arp_fd == -1) { + syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name); + return; + } eloop_event_add(state->arp_fd, arp_packet, ifp); } if (++state->claims < ANNOUNCE_NUM) @@ -267,8 +271,11 @@ arp_probe(void *arg) int arping = 0; if (state->arp_fd == -1) { - if (ipv4_opensocket(ifp, ETHERTYPE_ARP) == -1) + state->arp_fd = ipv4_opensocket(ifp, ETHERTYPE_ARP); + if (state->arp_fd == -1) { + syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name); return; + } eloop_event_add(state->arp_fd, arp_packet, ifp); } diff --git a/bpf.c b/bpf.c index 835c353a..826de227 100644 --- a/bpf.c +++ b/bpf.c @@ -53,7 +53,6 @@ ipv4_opensocket(struct interface *ifp, int protocol) { struct dhcp_state *state; int fd = -1; - int *fdp = NULL; struct ifreq ifr; int buf_len = 0; struct bpf_version pv; @@ -117,21 +116,14 @@ ipv4_opensocket(struct interface *ifp, int protocol) if (protocol == ETHERTYPE_ARP) { pf.bf_insns = UNCONST(arp_bpf_filter); pf.bf_len = arp_bpf_filter_len; - fdp = &state->arp_fd; } else { pf.bf_insns = UNCONST(dhcp_bpf_filter); pf.bf_len = dhcp_bpf_filter_len; - fdp = &state->raw_fd; } if (ioctl(fd, BIOCSETF, &pf) == -1) goto eexit; if (set_cloexec(fd) == -1) goto eexit; - if (fdp) { - if (*fdp != -1) - close(*fdp); - *fdp = fd; - } return fd; eexit: diff --git a/dhcp.c b/dhcp.c index 18f44a77..c46a7f8c 100644 --- a/dhcp.c +++ b/dhcp.c @@ -2423,12 +2423,12 @@ dhcp_handlepacket(void *arg) static int dhcp_open(struct interface *ifp) { - int r = 0; struct dhcp_state *state; state = D_STATE(ifp); if (state->raw_fd == -1) { - if ((r = ipv4_opensocket(ifp, ETHERTYPE_IP)) == -1) { + state->raw_fd = ipv4_opensocket(ifp, ETHERTYPE_IP); + if (state->raw_fd == -1) { syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name); return -1; } diff --git a/lpf.c b/lpf.c index 099fb58f..de5cc957 100644 --- a/lpf.c +++ b/lpf.c @@ -76,8 +76,6 @@ ipv4_opensocket(struct interface *ifp, int protocol) struct sockaddr_storage ss; } su; struct sock_fprog pf; - int *fd; - struct dhcp_state *state; #ifdef PACKET_AUXDATA int n; #endif @@ -113,14 +111,6 @@ ipv4_opensocket(struct interface *ifp, int protocol) goto eexit; if (bind(s, &su.sa, sizeof(su)) == -1) goto eexit; - state = D_STATE(ifp); - if (protocol == ETHERTYPE_ARP) - fd = &state->arp_fd; - else - fd = &state->raw_fd; - if (*fd != -1) - close(*fd); - *fd = s; return s; eexit: