changeset 2942:e4ebe44debc7 draft

Store lease files per interface per ssid.
author Roy Marples <roy@marples.name>
date Mon, 09 Feb 2015 15:35:49 +0000
parents 9ff2470c1bcd
children 8fd60c6f6672
files defs.h dhcp-common.c dhcp-common.h dhcp.c dhcp6.c dhcpcd.8.in
diffstat 6 files changed, 42 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/defs.h	Sun Feb 08 13:24:14 2015 +0000
+++ b/defs.h	Mon Feb 09 15:35:49 2015 +0000
@@ -46,10 +46,10 @@
 # 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"
--- a/dhcp-common.c	Sun Feb 08 13:24:14 2015 +0000
+++ b/dhcp-common.c	Mon Feb 09 15:35:49 2015 +0000
@@ -730,6 +730,33 @@
 	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,
--- a/dhcp-common.h	Sun Feb 08 13:24:14 2015 +0000
+++ b/dhcp-common.h	Mon Feb 09 15:35:49 2015 +0000
@@ -101,6 +101,8 @@
 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 *,
--- a/dhcp.c	Sun Feb 08 13:24:14 2015 +0000
+++ b/dhcp.c	Mon Feb 09 15:35:49 2015 +0000
@@ -2915,8 +2915,8 @@
 		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 @@
 	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
--- a/dhcp6.c	Sun Feb 08 13:24:14 2015 +0000
+++ b/dhcp6.c	Mon Feb 09 15:35:49 2015 +0000
@@ -3212,8 +3212,8 @@
 
 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 @@
 	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) {
--- a/dhcpcd.8.in	Sun Feb 08 13:24:14 2015 +0000
+++ b/dhcpcd.8.in	Mon Feb 09 15:35:49 2015 +0000
@@ -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 @@
 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.