diff options
author | KUMAAN <9maaan@gmail.com> | 2011-08-23 14:55:54 +0900 |
---|---|---|
committer | maximilian attems <max@stro.at> | 2012-05-19 00:25:59 +0200 |
commit | 8c239c1b5144f7ded9fd9737b0d1c64ce1777a30 (patch) | |
tree | faba0d072b1e59917e9244329d6ffe94959fa77c | |
parent | 90c0f08093a76c6e65bc0ed1db04e25826b4edfb (diff) | |
download | klibc-8c239c1b5144f7ded9fd9737b0d1c64ce1777a30.tar.gz |
[klibc] ipconfig: Write $DHCPLEASETIME as dhcp-lease-time
This patch parses dhcp-lease-time option value in DHCP ACK packet when
ipconfig uses DHCP. This patch writes $DHCPLEASETIME as the value to
/tmp/net-$DEVICE.conf file.
> ipconfig: ignores dhcp options
> http://bugs.debian.org/627166
This Debian Bug report requests the option value.
For example, $DHCPLEASETIME is equal to '3600' which means 3600 seconds.
If $PROTO is not equal to 'dhcp', $DHCPLEASETIME should be ignored.
Signed-off-by: KUMAAN <9maaan@gmail.com>
Acked-by: H. Peter Anvin <hpa@linux.intel.com>
Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r-- | usr/kinit/ipconfig/dhcp_proto.c | 4 | ||||
-rw-r--r-- | usr/kinit/ipconfig/main.c | 2 | ||||
-rw-r--r-- | usr/kinit/ipconfig/netdev.h | 1 |
3 files changed, 7 insertions, 0 deletions
diff --git a/usr/kinit/ipconfig/dhcp_proto.c b/usr/kinit/ipconfig/dhcp_proto.c index afd2eca5b1351..a461c6d039830 100644 --- a/usr/kinit/ipconfig/dhcp_proto.c +++ b/usr/kinit/ipconfig/dhcp_proto.c @@ -84,6 +84,7 @@ static int dhcp_parse(struct netdev *dev, struct bootp_hdr *hdr, { uint8_t type = 0; uint32_t serverid = INADDR_NONE; + uint32_t leasetime = 0; int ret = 0; if (extlen >= 4 && exts[0] == 99 && exts[1] == 130 && @@ -99,6 +100,8 @@ static int dhcp_parse(struct netdev *dev, struct bootp_hdr *hdr, ext += len; + if (*opt == 51 && len == 4) + leasetime = ntohl(*(uint32_t *)(opt + 2)); if (*opt == 53) type = opt[2]; if (*opt == 54) @@ -115,6 +118,7 @@ static int dhcp_parse(struct netdev *dev, struct bootp_hdr *hdr, break; case DHCPACK: + dev->dhcpleasetime = leasetime; ret = bootp_parse(dev, hdr, exts, extlen) ? DHCPACK : 0; dprintf("\n dhcp ack\n"); break; diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c index 215e27c1c2a9f..3832921c47c4f 100644 --- a/usr/kinit/ipconfig/main.c +++ b/usr/kinit/ipconfig/main.c @@ -155,6 +155,8 @@ static void dump_device_config(struct netdev *dev) write_option(f, "filename", dev->filename); sprintf(buf21, "%ld", (long)dev->uptime); write_option(f, "UPTIME", buf21); + sprintf(buf21, "%u", (unsigned int)dev->dhcpleasetime); + write_option(f, "DHCPLEASETIME", buf21); fclose(f); } } diff --git a/usr/kinit/ipconfig/netdev.h b/usr/kinit/ipconfig/netdev.h index 9dd8ec5d0664e..d1903dcd6e59b 100644 --- a/usr/kinit/ipconfig/netdev.h +++ b/usr/kinit/ipconfig/netdev.h @@ -35,6 +35,7 @@ struct netdev { uint32_t ip_gateway; /* my gateway */ uint32_t ip_nameserver[2]; /* two nameservers */ uint32_t serverid; /* dhcp serverid */ + uint32_t dhcpleasetime; /* duration in seconds */ char reqhostname[SYS_NMLN]; /* requested hostname */ char hostname[SYS_NMLN]; /* hostname */ char dnsdomainname[SYS_NMLN]; /* dns domain name */ |