答复: [Patch] Enable udhcpc6 in the busybox to obtain the SNTP server.
zhousiqi (A)
zhousiqi5 at huawei.com
Fri May 31 01:15:37 UTC 2024
Gentle ping...
Please check if the community accepts this submission.
> -----邮件原件-----
> 发件人: zhousiqi (A)
> 发送时间: 2023年7月3日 11:23
> 收件人: 'busybox at busybox.net' <busybox at busybox.net>
> 主题: Re: [Patch] Enable udhcpc6 in the busybox to obtain the SNTP server.
>
> Gentle ping... Is this function easy to use and is the community willing to accept
> it?
> In addition, can the community provide a default6.script for udhcpc6?
> ------------------------------------------------------
>
> Dear BusyBox maintainers,
>
> I am writing to propose a patch for udhcpc6 that adds support for retrieving
> SNTP (Simple Network Time Protocol) servers. Currently, udhcpc6 does not
> support this function, which limits its usefulness in certain environments.
> My patch extends the existing -O option in udhcpc6 to include a new option, -O
> sntpsrv. When the -O sntpsrv option is used, udhcpc6 will request SNTP servers
> from the DHCPv6 server, and will configure the system's time accordingly.
> I have tested this patch on my own system, and have verified that it works as
> expected. I believe that this patch will be useful to other users who need to
> retrieve SNTP servers using udhcpc6.
> Thank you for your time and consideration.
>
> Best regards,
>
> Zhou
>
> From 57e404b2a227e40fffe4d56045885939fa0e00d6 Mon Sep 17 00:00:00
> 2001
> From: Zhou Siqi <zhousiqi5 at huawei.com>
> Date: Tue, 6 Jun 2023 15:46:36 +0800
> Subject: [PATCH] The sntp server helps synchronize clock signals between the
> client and the server. Most DHCP software in the industry supports this
> function.Currently, udhcpc6 does not support the function of obtaining the
> SNTP server.This modification enables udhcpc6 to support this function.
>
> Signed-off-by: Zhou Siqi <zhousiqi5 at huawei.com>
> ---
> examples/var_service/dhcp_if/convert2sntpconf | 30 +++++++++++++
> networking/udhcp/Config.src | 8 ++++
> networking/udhcp/d6_common.h | 3 ++
> networking/udhcp/d6_dhcpc.c | 61
> +++++++++++++++++----------
> 4 files changed, 79 insertions(+), 23 deletions(-) create mode 100644
> examples/var_service/dhcp_if/convert2sntpconf
>
> diff --git a/examples/var_service/dhcp_if/convert2sntpconf
> b/examples/var_service/dhcp_if/convert2sntpconf
> new file mode 100644
> index 0000000..c23e914
> --- /dev/null
> +++ b/examples/var_service/dhcp_if/convert2sntpconf
> @@ -0,0 +1,30 @@
> +#!/bin/sh
> +# This example shows how to obtain the SNTP server information from the
> configuration information obtained by the client.
> +# convert:
> +# (Client configuration information)
> +# dhcptype=5
> +# lease=97200
> +# interface=eth0
> +# ip=2000:192:168::64:84/64
> +# mask=64
> +# dns=fec0:70:4000::22:33:40 fec0:70:4000::22:33:41
> +fec0:70:4000::22:33:42 # domain=lab.example.com example.com #
> +sntpsrv=fec0:0:0:23::43 fec0:0:0:23::44
> +
> +# into:
> +
> +#let cfg=cfg+1
> +#sntpip[$cfg]=...
> +
> +exec >/dev/null
> +exec 2>&1
> +
> +test "$interface" || exit 1
> +test "$ip" || exit 1
> +
> +{
> +for n in $sntpsrv; do
> + echo "let cfg=cfg+1"
> + echo "sntpip[\$cfg]='$n'"
> +done
> +} >"$1"
> diff --git a/networking/udhcp/Config.src b/networking/udhcp/Config.src index
> 8c8c11c..574c33c 100644
> --- a/networking/udhcp/Config.src
> +++ b/networking/udhcp/Config.src
> @@ -171,3 +171,11 @@ config FEATURE_UDHCP_8021Q
> help
> If selected, both client and server will support passing of VLAN
> ID and priority via options 132 and 133 as per 802.1Q.
> +
> +config FEATURE_UDHCPC6_RFC4075
> + bool "Support udhcpc6 obtain the SNTP servers."
> + default y
> + depends on UDHCPC6
> + help
> + If selected, the IPv6 client udhcpc6 can obtain the SNTP servers.
> +
> diff --git a/networking/udhcp/d6_common.h
> b/networking/udhcp/d6_common.h index 9dfde77..49e1b5b 100644
> --- a/networking/udhcp/d6_common.h
> +++ b/networking/udhcp/d6_common.h
> @@ -87,6 +87,9 @@ struct d6_option {
> #define D6_OPT_IA_PD 25
> #define D6_OPT_IAPREFIX 26
>
> +/* Adapted from dhcp */
> +#define D6_OPT_SNTP_SERVERS 31
> +
> /* RFC 4704 "The DHCPv6 Client FQDN Option"
> * uint16 option-code OPTION_CLIENT_FQDN (39)
> * uint16 option-len 1 + length of domain name
> diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
> index 8d11a75..8707da1 100644
> --- a/networking/udhcp/d6_dhcpc.c
> +++ b/networking/udhcp/d6_dhcpc.c
> @@ -81,6 +81,9 @@ static const struct dhcp_optflag d6_optflags[] = {
> { OPTION_STRING,
> D6_OPT_BOOT_URL },
> { OPTION_STRING,
> D6_OPT_BOOT_PARAM },
> #endif
> +#if ENABLE_FEATURE_UDHCPC6_RFC4075
> + { OPTION_6RD | OPTION_LIST | OPTION_REQ,
> D6_OPT_SNTP_SERVERS },
> +#endif
> { OPTION_STRING, 0xd1 }, /*
> DHCP_PXE_CONF_FILE */
> { OPTION_STRING, 0xd2 }, /*
> DHCP_PXE_PATH_PREFIX */
> { 0, 0 }
> @@ -102,6 +105,9 @@ static const char d6_option_strings[] ALIGN1 =
> "bootfile_url" "\0" /* D6_OPT_BOOT_URL */
> "bootfile_param" "\0" /* D6_OPT_BOOT_PARAM */ #endif
> +#if ENABLE_FEATURE_UDHCPC6_RFC4075
> + "sntpsrv" "\0" /* D6_OPT_SNTP_SERVERS */
> +#endif
> "pxeconffile" "\0" /* DHCP_PXE_CONF_FILE */
> "pxepathprefix" "\0" /* DHCP_PXE_PATH_PREFIX */
> "\0";
> @@ -243,10 +249,34 @@ static char *string_option_to_env(const uint8_t
> *option,
> return xasprintf("%s=%.*s", name, val_len, (char*)option + 4); }
>
> +static void handle_server_info(char *dev_key, const uint8_t *option,
> +int addrs, int option_offset) {
> + char *dlist;
> +
> + /* Make sure payload-size is a multiple of 16 */
> + if ((option[3] & 0x0f) != 0)
> + return;
> +
> + /* Get the number of addresses on the option */
> + addrs = option[3] >> 4;
> +
> + /* Setup environment variable */
> + *new_env() = dlist = xmalloc(strlen(dev_key) + addrs * 40 - 1);
> + dlist = stpcpy(dlist, dev_key);
> + option_offset = 0;
> +
> + while (addrs--) {
> + dlist += sprint_nip6(dlist, option + 4 + option_offset);
> + option_offset += 16;
> + if (addrs)
> + *dlist++ = ' ';
> + }
> +}
> +
> /* put all the parameters into the environment */ static void
> option_to_env(const uint8_t *option, const uint8_t *option_end) { -#if
> ENABLE_FEATURE_UDHCPC6_RFC3646
> +#if ENABLE_FEATURE_UDHCPC6_RFC3646 ||
> ENABLE_FEATURE_UDHCPC6_RFC4075
> int addrs, option_offset;
> #endif
> /* "length minus 4" */
> @@ -339,28 +369,7 @@ static void option_to_env(const uint8_t *option, const
> uint8_t *option_end)
> break;
> #if ENABLE_FEATURE_UDHCPC6_RFC3646
> case D6_OPT_DNS_SERVERS: {
> - char *dlist;
> -
> - /* Make sure payload-size is a multiple of 16 */
> - if ((option[3] & 0x0f) != 0)
> - break;
> -
> - /* Get the number of addresses on the option */
> - addrs = option[3] >> 4;
> -
> - /* Setup environment variable */
> - *new_env() = dlist = xmalloc(4 + addrs * 40 - 1);
> - dlist = stpcpy(dlist, "dns=");
> - option_offset = 0;
> -
> - while (addrs--) {
> - sprint_nip6(dlist, option + 4 + option_offset);
> - dlist += 39;
> - option_offset += 16;
> - if (addrs)
> - *dlist++ = ' ';
> - }
> -
> + handle_server_info("dns=",option,addrs,option_offset);
> break;
> }
> case D6_OPT_DOMAIN_LIST: {
> @@ -406,6 +415,12 @@ static void option_to_env(const uint8_t *option, const
> uint8_t *option_end)
> *new_env() = xasprintf("tz_name=%.*s", (int)option[3],
> (char*)option + 4);
> break;
> #endif
> +#if ENABLE_FEATURE_UDHCPC6_RFC4075
> + case D6_OPT_SNTP_SERVERS: {
> + handle_server_info("sntpsrv=",option,addrs,option_offset);
> + break;
> + }
> +#endif
> case D6_OPT_BOOT_URL:
> case D6_OPT_BOOT_PARAM:
> case 0xd1: /* DHCP_PXE_CONF_FILE */
> --
> 2.12.3
More information about the busybox
mailing list