]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Cleanup IPv4 fd opening and closing.
authorRoy Marples <roy@marples.name>
Tue, 12 Nov 2013 15:00:22 +0000 (15:00 +0000)
committerRoy Marples <roy@marples.name>
Tue, 12 Nov 2013 15:00:22 +0000 (15:00 +0000)
arp.c
bpf.c
dhcp.c
lpf.c

diff --git a/arp.c b/arp.c
index f9e49cc525399805e6165c32a7a024f2a76b4134..462309057ffcb63c61d8ea10fa3d0d9060934c86 100644 (file)
--- 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 835c353ad5e767e1622be6a4e199af5ecc67210a..826de227d6feb7497f15e03619f5aa1bf2d7ff56 100644 (file)
--- 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 18f44a771318dfe342291f4bfd2deee21f2c9f85..c46a7f8c4486b7ad699f2c56903ed3991a714bca 100644 (file)
--- 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 099fb58f4019b24ca66088864e5f3ec958663688..de5cc957c7622e2f7ac0957995efc404138e1e19 100644 (file)
--- 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: