]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Store lease files per interface per ssid.
authorRoy Marples <roy@marples.name>
Mon, 9 Feb 2015 15:35:49 +0000 (15:35 +0000)
committerRoy Marples <roy@marples.name>
Mon, 9 Feb 2015 15:35:49 +0000 (15:35 +0000)
defs.h
dhcp-common.c
dhcp-common.h
dhcp.c
dhcp6.c
dhcpcd.8.in

diff --git a/defs.h b/defs.h
index 7fd4edcebb8efb353b33408824361ed4066db01e..e8bfbd386977addcce154f1d650addae3c77c1ea 100644 (file)
--- a/defs.h
+++ b/defs.h
 # define SECRET                        SYSCONFDIR "/" PACKAGE ".secret"
 #endif
 #ifndef LEASEFILE
-# define LEASEFILE             DBDIR "/" PACKAGE "-%s.lease"
+# define LEASEFILE             DBDIR "/" PACKAGE "-%s%s%s.lease"
 #endif
 #ifndef LEASEFILE6
-# define LEASEFILE6            DBDIR "/" PACKAGE "-%s%s.lease6"
+# define LEASEFILE6            LEASEFILE "6"
 #endif
 #ifndef PIDFILE
 # define PIDFILE               RUNDIR "/" PACKAGE "%s%s%s.pid"
index 109120f1f2269b1fc3fbcb2bbb5e300f74ccc4c0..1b87b720d2a0385c71b4a9d5374eabd2556986dd 100644 (file)
@@ -730,6 +730,33 @@ print_option(char *s, size_t len, int type, const uint8_t *data, size_t dl,
        return bytes;
 }
 
+int
+dhcp_set_leasefile(char *leasefile, size_t len, int family,
+    const struct interface *ifp, const char *extra)
+{
+       char ssid[len];
+
+       switch (family) {
+       case AF_INET:
+       case AF_INET6:
+               break;
+       default:
+               errno = EINVAL;
+               return -1;
+       }
+
+       if (ifp->wireless) {
+               ssid[0] = '-';
+               print_string(ssid + 1, sizeof(ssid) - 1,
+                   ESCSTRING,
+                   (const uint8_t *)ifp->ssid, ifp->ssid_len);
+       } else
+               ssid[0] = '\0';
+       return snprintf(leasefile, len,
+           family == AF_INET ? LEASEFILE : LEASEFILE6,
+           ifp->name, ssid, extra);
+}
+
 static size_t
 dhcp_envoption1(char **env, const char *prefix,
     const struct dhcp_opt *opt, int vname, const uint8_t *od, size_t ol,
index edd08774fb741f8d5befbcb38232c9d50b333423..e4c89f502443b189a19e3115ddedf88fa37977e8 100644 (file)
@@ -101,6 +101,8 @@ ssize_t decode_rfc3397(char *, size_t, const uint8_t *, size_t);
 ssize_t print_string(char *, size_t, int, const uint8_t *, size_t);
 ssize_t print_option(char *, size_t, int, const uint8_t *, size_t,
     const char *);
+int dhcp_set_leasefile(char *, size_t, int,
+    const struct interface *, const char *);
 
 size_t dhcp_envoption(struct dhcpcd_ctx *,
     char **, const char *, const char *, struct dhcp_opt *,
diff --git a/dhcp.c b/dhcp.c
index 2d73de0cefbd891141907d18eebc0518c41f7ed8..fabbad8bb1c92d2ef4e2ddd98852f08e79c57a19 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -2915,8 +2915,8 @@ dhcp_dump(struct interface *ifp)
                goto eexit;
        state->raw_fd = state->arp_fd = -1;
        TAILQ_INIT(&state->arp_states);
-       snprintf(state->leasefile, sizeof(state->leasefile),
-           LEASEFILE, ifp->name);
+       dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
+           AF_INET, ifp, "");
        state->new = read_lease(ifp);
        if (state->new == NULL && errno == ENOENT) {
                strlcpy(state->leasefile, ifp->name, sizeof(state->leasefile));
@@ -2998,8 +2998,8 @@ dhcp_init(struct interface *ifp)
        state->state = DHS_INIT;
        state->reason = "PREINIT";
        state->nakoff = 0;
-       snprintf(state->leasefile, sizeof(state->leasefile),
-           LEASEFILE, ifp->name);
+       dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
+           AF_INET, ifp, "");
 
        ifo = ifp->options;
        /* We need to drop the leasefile so that dhcp_start
diff --git a/dhcp6.c b/dhcp6.c
index 30696cc2080a126a7c3722cc5b0db8c36e8ac792..5735fe180a7f8631d7996827308c0886ebb5d757 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -3212,8 +3212,8 @@ dhcp6_start(struct interface *ifp, enum DH6S init_state)
 
 gogogo:
        state->state = init_state;
-       snprintf(state->leasefile, sizeof(state->leasefile),
-           LEASEFILE6, ifp->name,
+       dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
+           AF_INET6, ifp,
            ifp->options->options & DHCPCD_PFXDLGONLY ? ".pd" : "");
        if (ipv6_linklocal(ifp) == NULL) {
                syslog(LOG_DEBUG,
@@ -3533,8 +3533,8 @@ dhcp6_dump(struct interface *ifp)
        if (state == NULL)
                goto eexit;
        TAILQ_INIT(&state->addrs);
-       snprintf(state->leasefile, sizeof(state->leasefile),
-           LEASEFILE6, ifp->name,
+       dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
+           AF_INET6, ifp,
            ifp->options->options & DHCPCD_PFXDLGONLY ? ".pd" : "");
        r = dhcp6_readlease(ifp);
        if (r == -1 && errno == ENOENT) {
index 9ca613b22ddda850c22bdecece4d523a8b37a58a..8ad18ac566724906cde6fc2ea50ff35e88d5762a 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd January 15, 2015
+.Dd February 9, 2015
 .Dt DHCPCD 8
 .Os
 .Sh NAME
@@ -668,11 +668,11 @@ A directory containing bourne shell scripts that are run by the above script.
 Each script can be disabled by using the
 .Fl C , Fl Fl nohook
 option described above.
-.It Pa @DBDIR@/dhcpcd\- Ns Ar interface Ns .lease
+.It Pa @DBDIR@/dhcpcd\- Ns Ar interface Ns Ar -ssid Ns .lease
 The actual DHCP message sent by the server.
 We use this when reading the last
 lease and use the files mtime as when it was issued.
-.It Pa @DBDIR@/dhcpcd\- Ns Ar interface Ns .lease6
+.It Pa @DBDIR@/dhcpcd\- Ns Ar interface Ns Ar -ssid Ns .lease6
 The actual DHCPv6 message sent by the server.
 We use this when reading the last
 lease and use the files mtime as when it was issued.