From 2935f618e6c5c63772dca8b548119e0919c45b98 Mon Sep 17 00:00:00 2001 From: zhousiqi Date: Mon, 3 Jul 2023 07:57:23 +0000 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: zhousiqi93 --- 0001-Patch-busybox-udhcpc6-support-sntp.patch | 189 ++++++++++++++++++ busybox.spec | 8 +- 2 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 0001-Patch-busybox-udhcpc6-support-sntp.patch diff --git a/0001-Patch-busybox-udhcpc6-support-sntp.patch b/0001-Patch-busybox-udhcpc6-support-sntp.patch new file mode 100644 index 0000000..d9370d5 --- /dev/null +++ b/0001-Patch-busybox-udhcpc6-support-sntp.patch @@ -0,0 +1,189 @@ +From 57e404b2a227e40fffe4d56045885939fa0e00d6 Mon Sep 17 00:00:00 2001 +From: Zhou Siqi +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 +--- + 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 + diff --git a/busybox.spec b/busybox.spec index 7cc53e2..6d0678a 100644 --- a/busybox.spec +++ b/busybox.spec @@ -4,7 +4,7 @@ %endif %if "%{!?RELEASE:1}" -%define RELEASE 19 +%define RELEASE 20 %endif Epoch: 1 @@ -20,6 +20,8 @@ Source1: busybox-static.config Source2: busybox-petitboot.config Source3: busybox-dynamic.config +Patch0001: 0001-Patch-busybox-udhcpc6-support-sntp.patch + Patch6000: backport-CVE-2022-28391.patch Patch6001: backport-CVE-2022-30065.patch Patch6002: backport-fix-use-after-free-in-bc-module.patch @@ -99,6 +101,10 @@ install -m 644 docs/busybox.dynamic.1 $RPM_BUILD_ROOT/%{_mandir}/man1/busybox.1 %{_mandir}/man1/busybox.petitboot.1.gz %changelog +* Mon Jul 3 2023 zhousiqi - 1:1.34.1-19 +- This modification enables udhcpc6 to support the function of obtaining the + SNTP server. + * Fri Dec 16 2022 cf_zhao - 1:1.34.1-19 - Backport generalize "const trick" which commited in 1f925038ab9c6bd8f6b3cd40ed7aab0ef10d898e -- Gitee