Re: Per-SSID lease file?
Pierre-Hugues Husson
Sun Feb 08 18:33:00 2015
Hi
2015-02-08 12:55 GMT+01:00 Roy Marples <roy@xxxxxxxxxxxx>:
>
> That's a good idea.
> We probably want to set the leasefile in dhcp_start() and dhcp6_start().
>
Damn, I initially believed you, and didn't understand why I couldn't get an
IP...
I had to do it in dhcp_start1, because else state is not yet allocated, and
I had a if(state==NULL) return;
> However, we also want to consider dhcp_dump() and dhcp6_dump() as well -
> maybe add code there to read the ssid and apply if needed.
>
> Can you modify your patch for that and submit it?
>
Attached is a first quick draft, ipv4-only:
I kept only one LEASEFILE, and use "wired" as "ssid". dumplease forces to
wired.
I made a if_cleanssid functions, which is over-paranoid (but easier to
write), and that assumes proper buffer size.
I'm not too sure how to handle dumplease
I see three ways:
- Force ssid to wired, and warn the user he'll have to do a symlink from
-ssid to -wired, halfly annoying for every user
- Use current ssid, really annoying for users who want to dump other ssid's
leases.
- Add an option to set ssid (environment variable ?)
> > What is your advice on that ?
> > Should I implement an option to dhcpcd for that ?
>
> I don't think it needs to be an option.
> You could say dhcpcd already has too many options :)
Oops, I was going to suggest even more options...
diff --git a/defs.h b/defs.h
index 7fd4edc..2caa94f 100644
--- a/defs.h
+++ b/defs.h
@@ -46,7 +46,7 @@
# define SECRET SYSCONFDIR "/" PACKAGE ".secret"
#endif
#ifndef LEASEFILE
-# define LEASEFILE DBDIR "/" PACKAGE "-%s.lease"
+# define LEASEFILE DBDIR "/" PACKAGE "-%s-%s.lease"
#endif
#ifndef LEASEFILE6
# define LEASEFILE6 DBDIR "/" PACKAGE "-%s%s.lease6"
diff --git a/dhcp.c b/dhcp.c
index 2d73de0..5f9b744 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -2916,7 +2916,7 @@ dhcp_dump(struct interface *ifp)
state->raw_fd = state->arp_fd = -1;
TAILQ_INIT(&state->arp_states);
snprintf(state->leasefile, sizeof(state->leasefile),
- LEASEFILE, ifp->name);
+ LEASEFILE, ifp->name, "wired");
state->new = read_lease(ifp);
if (state->new == NULL && errno == ENOENT) {
strlcpy(state->leasefile, ifp->name, sizeof(state->leasefile));
@@ -2999,7 +2999,7 @@ dhcp_init(struct interface *ifp)
state->reason = "PREINIT";
state->nakoff = 0;
snprintf(state->leasefile, sizeof(state->leasefile),
- LEASEFILE, ifp->name);
+ LEASEFILE, ifp->name, "wired");
ifo = ifp->options;
/* We need to drop the leasefile so that dhcp_start
@@ -3096,6 +3096,11 @@ dhcp_start1(void *arg)
free(state->offer);
state->offer = NULL;
+ char ssid[IF_SSIDSIZE];
+ if_cleanssid(ifp, ssid);
+ snprintf(state->leasefile, sizeof(state->leasefile),
+ LEASEFILE, ifp->name, ssid);
+
if (state->arping_index < ifo->arping_len) {
struct arp_state *astate;
diff --git a/dhcp.h b/dhcp.h
index 8e847a7..c38fdb2 100644
--- a/dhcp.h
+++ b/dhcp.h
@@ -223,7 +223,7 @@ struct dhcp_state {
struct in_addr dst;
uint8_t added;
- char leasefile[sizeof(LEASEFILE) + IF_NAMESIZE];
+ char leasefile[sizeof(LEASEFILE) + IF_NAMESIZE + IF_SSIDSIZE];
time_t start_uptime;
unsigned char *clientid;
diff --git a/if.c b/if.c
index 26d0386..2bc2d5f 100644
--- a/if.c
+++ b/if.c
@@ -578,3 +578,20 @@ if_domtu(const char *ifname, short int mtu)
return -1;
return ifr.ifr_mtu;
}
+
+/* Requires ssid to be at least IF_SSIDSIZE */
+void
+if_cleanssid(struct interface *ifp, char *ssid) {
+ if(!ifp->wireless || !ifp->ssid[0]) {
+ strcpy(ssid, "wired");
+ return;
+ }
+ uint8_t *orig = ifp->ssid;
+ for(int i=0; orig[i] && i<IF_SSIDSIZE; ++i) {
+ if(!isalnum(orig[i]))
+ continue;
+ *ssid=orig[i];
+ ssid++;
+ }
+ *ssid=0;
+}
diff --git a/if.h b/if.h
index c44aed6..5306486 100644
--- a/if.h
+++ b/if.h
@@ -93,6 +93,7 @@ int if_domtu(const char *, short int);
#define if_getmtu(iface) if_domtu(iface, 0)
#define if_setmtu(iface, mtu) if_domtu(iface, mtu)
int if_carrier(struct interface *);
+void if_cleanssid(struct interface*, char*);
/* The below functions are provided by if-KERNEL.c */
int if_conf(struct interface *);
Archive administrator: postmaster@marples.name