[PATCH] Added support for timezones on dhcp6-client (RFC 4833)

tiggersWelt.net (Support) support at tiggerswelt.net
Wed Jun 14 18:52:55 UTC 2017


Hi there,

I've added support for POSIX Timezones to udhcpc6 (RFC 4833) as it was
useful for our setup. I would love to see this on busybox.
I also added a bit of documentation to my previous commit and replaced
the double allocation by two memcpys.

Signed-off-by: Bernd Holzmüller <bernd.holzmueller at tiggerswelt.net>
---
 networking/udhcp/d6_common.h |  3 +++
 networking/udhcp/d6_dhcpc.c  | 39 ++++++++++++++++++++++++++++++---------
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/networking/udhcp/d6_common.h b/networking/udhcp/d6_common.h
index fcec8c15a..ca5788390 100644
--- a/networking/udhcp/d6_common.h
+++ b/networking/udhcp/d6_common.h
@@ -89,6 +89,9 @@ struct d6_option {

 #define D6_OPT_CLIENT_FQDN   39

+#define D6_OPT_TZ_POSIX      41
+#define D6_OPT_TZ_NAME       42
+
 /*** Other shared functions ***/

 struct client6_data_t {
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index 18a104c61..601ed41c9 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -90,10 +90,12 @@ enum {

 static const char opt_req[] = {
 	(D6_OPT_ORO >> 8), (D6_OPT_ORO & 0xff),
-	0, 6,
+	0, 10,
 	(D6_OPT_DNS_SERVERS >> 8), (D6_OPT_DNS_SERVERS & 0xff),
 	(D6_OPT_DOMAIN_LIST >> 8), (D6_OPT_DOMAIN_LIST & 0xff),
-	(D6_OPT_CLIENT_FQDN >> 8), (D6_OPT_CLIENT_FQDN & 0xff)
+	(D6_OPT_CLIENT_FQDN >> 8), (D6_OPT_CLIENT_FQDN & 0xff),
+	(D6_OPT_TZ_POSIX >> 8), (D6_OPT_TZ_POSIX & 0xff),
+	(D6_OPT_TZ_NAME >> 8), (D6_OPT_TZ_NAME & 0xff)
 };

 static const char opt_fqdn_req[] = {
@@ -261,17 +263,21 @@ static void option_to_env(uint8_t *option, uint8_t *option_end)
 			*new_env() = dlist;
 			break;
 		case D6_OPT_CLIENT_FQDN:
-			// Work around broken ISC DHCPD6
+			/* Work around broken ISC DHCPD6
+			 * ISC DHCPD6 does not implement RFC 4704 correctly: It says the first
+			 * byte of option-payload should contain flags where the bits 4-8 are
+			 * reserved for future use and MUST be zero. Instead ISC DHCPD6 just
+			 * writes the entire FQDN as string to option-payload. We assume a
+			 * broken server here if any of the reserved bits is set.
+			 */
 			if (option[4] & 0xf8) {
 				olen = ((option[2] << 8) | option[3]);
-				dlist = xmalloc(olen);
+				dlist = xmalloc(olen + 5);
 //fixme:
-//- explain
 //- add len error check
-//- merge two allocs into one
-				memcpy(dlist, option + 4, olen);
-				*new_env() = xasprintf("fqdn=%s", dlist);
-				free(dlist);
+				memcpy(dlist,"fqdn=",5);
+				memcpy(dlist + 5, option + 4, olen);
+				*new_env() = dlist;
 				break;
 			}
 			dlist = dname_dec(option + 5, ((option[2] << 8) | option[3]) - 1, "fqdn=");
@@ -279,6 +285,21 @@ static void option_to_env(uint8_t *option, uint8_t *option_end)
 				break;
 			*new_env() = dlist;
 			break;
+		/* RFC 4833 Timezones */
+		case D6_OPT_TZ_POSIX:
+			olen = ((option[2] << 8) | option[3]);
+			dlist = xmalloc(olen + 3);
+			memcpy(dlist, "tz=", 3);
+			memcpy(dlist + 3, option + 4, olen);
+			*new_env() = dlist;
+			break;
+		case D6_OPT_TZ_NAME:
+			olen = ((option[2] << 8) | option[3]);
+			dlist = xmalloc(olen + 8);
+			memcpy(dlist, "tz_name=", 8);
+			memcpy(dlist + 8, option + 4, olen);
+			*new_env() = dlist;
+			break;
 		}
 		len_m4 -= 4 + option[3];
 		option += 4 + option[3];
-- 
2.12.2


-- 
    \\\||///
  \\  - -  //
   (  @ @  )
-oOo--( )--oOo-------------------------------------------------------
 tiggersWelt.net                                 www.tiggersWelt.net
 Inhaber Bernd Holzmüller                       info at tiggerswelt.net
                                            Büro: 07 11 / 550 425-90
 Marktstraße 57                              Fax: 07 11 / 550 425-99
 70372 Stuttgart

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3310 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20170614/e118a31d/attachment.p7s>


More information about the busybox mailing list