From: Roy Marples Date: Mon, 9 Feb 2015 15:35:49 +0000 (+0000) Subject: Store lease files per interface per ssid. X-Git-Tag: v6.8.0~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb1e13195e9bfbe4eb7140e7f66df316f424da9a;p=thirdparty%2Fdhcpcd.git Store lease files per interface per ssid. --- diff --git a/defs.h b/defs.h index 7fd4edce..e8bfbd38 100644 --- a/defs.h +++ b/defs.h @@ -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" diff --git a/dhcp-common.c b/dhcp-common.c index 109120f1..1b87b720 100644 --- a/dhcp-common.c +++ b/dhcp-common.c @@ -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, diff --git a/dhcp-common.h b/dhcp-common.h index edd08774..e4c89f50 100644 --- a/dhcp-common.h +++ b/dhcp-common.h @@ -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 2d73de0c..fabbad8b 100644 --- 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 30696cc2..5735fe18 100644 --- 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) { diff --git a/dhcpcd.8.in b/dhcpcd.8.in index 9ca613b2..8ad18ac5 100644 --- a/dhcpcd.8.in +++ b/dhcpcd.8.in @@ -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.