On 14 June 2017 at 20:52, tiggersWelt.net (Support)
<[email protected]> wrote:
> 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 <[email protected]>
> ---
> 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.
you mean as literal string or as (DNS-)encoded domain name?
> + */
> if (option[4] & 0xf8) {
> olen = ((option[2] << 8) | option[3]);
> - dlist = xmalloc(olen);
> + dlist = xmalloc(olen + 5);
Wouldn't you want to cap olen a bit?
> //fixme:
> -//- explain
> //- add len error check
exactly
> -//- 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=");
Why is the above argument to dname_dec not using olen from above?
> @@ -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);
cap?
> + 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);
cap?
> + memcpy(dlist, "tz_name=", 8);
> + memcpy(dlist + 8, option + 4, olen);
> + *new_env() = dlist;
> + break;
> }
> len_m4 -= 4 + option[3];
> option += 4 + option[3];
thanks,
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox