[U-Boot] [RFC PATCH 7/7] env: Automatically mark dynamic configuration info as "do not export"

Bernhard Nortmann bernhard.nortmann at web.de
Mon Jul 11 20:14:54 CEST 2016


This is an attempt to prevent such information from ending up
in exported environment data, especially when doing "saveenv".
(http://lists.denx.de/pipermail/u-boot/2015-September/227611.html)

The patch makes use of the new setenv_transient() helper for
environment variables that get updated via network configuration:
BOOTP/DHCP (netboot_update_env), CDP (cdp_update_env) and
link-local protocol (do_link_local).

Signed-off-by: Bernhard Nortmann <bernhard.nortmann at web.de>
---

 cmd/net.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/cmd/net.c b/cmd/net.c
index b2f3c7b..84b34ce 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -116,23 +116,23 @@ static void netboot_update_env(void)
 
 	if (net_gateway.s_addr) {
 		ip_to_string(net_gateway, tmp);
-		setenv("gatewayip", tmp);
+		setenv_transient("gatewayip", tmp);
 	}
 
 	if (net_netmask.s_addr) {
 		ip_to_string(net_netmask, tmp);
-		setenv("netmask", tmp);
+		setenv_transient("netmask", tmp);
 	}
 
 	if (net_hostname[0])
-		setenv("hostname", net_hostname);
+		setenv_transient("hostname", net_hostname);
 
 	if (net_root_path[0])
-		setenv("rootpath", net_root_path);
+		setenv_transient("rootpath", net_root_path);
 
 	if (net_ip.s_addr) {
 		ip_to_string(net_ip, tmp);
-		setenv("ipaddr", tmp);
+		setenv_transient("ipaddr", tmp);
 	}
 #if !defined(CONFIG_BOOTP_SERVERIP)
 	/*
@@ -141,32 +141,32 @@ static void netboot_update_env(void)
 	 */
 	if (net_server_ip.s_addr) {
 		ip_to_string(net_server_ip, tmp);
-		setenv("serverip", tmp);
+		setenv_transient("serverip", tmp);
 	}
 #endif
 	if (net_dns_server.s_addr) {
 		ip_to_string(net_dns_server, tmp);
-		setenv("dnsip", tmp);
+		setenv_transient("dnsip", tmp);
 	}
 #if defined(CONFIG_BOOTP_DNS2)
 	if (net_dns_server2.s_addr) {
 		ip_to_string(net_dns_server2, tmp);
-		setenv("dnsip2", tmp);
+		setenv_transient("dnsip2", tmp);
 	}
 #endif
 	if (net_nis_domain[0])
-		setenv("domain", net_nis_domain);
+		setenv_transient("domain", net_nis_domain);
 
 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
 	if (net_ntp_time_offset) {
 		sprintf(tmp, "%d", net_ntp_time_offset);
-		setenv("timeoffset", tmp);
+		setenv_transient("timeoffset", tmp);
 	}
 #endif
 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
 	if (net_ntp_server.s_addr) {
 		ip_to_string(net_ntp_server, tmp);
-		setenv("ntpserverip", tmp);
+		setenv_transient("ntpserverip", tmp);
 	}
 #endif
 }
@@ -294,14 +294,14 @@ static void cdp_update_env(void)
 		printf("CDP offered appliance VLAN %d\n",
 		       ntohs(cdp_appliance_vlan));
 		vlan_to_string(cdp_appliance_vlan, tmp);
-		setenv("vlan", tmp);
+		setenv_transient("vlan", tmp);
 		net_our_vlan = cdp_appliance_vlan;
 	}
 
 	if (cdp_native_vlan != htons(-1)) {
 		printf("CDP offered native VLAN %d\n", ntohs(cdp_native_vlan));
 		vlan_to_string(cdp_native_vlan, tmp);
-		setenv("nvlan", tmp);
+		setenv_transient("nvlan", tmp);
 		net_native_vlan = cdp_native_vlan;
 	}
 }
@@ -426,14 +426,14 @@ static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc,
 
 	net_gateway.s_addr = 0;
 	ip_to_string(net_gateway, tmp);
-	setenv("gatewayip", tmp);
+	setenv_transient("gatewayip", tmp);
 
 	ip_to_string(net_netmask, tmp);
-	setenv("netmask", tmp);
+	setenv_transient("netmask", tmp);
 
 	ip_to_string(net_ip, tmp);
-	setenv("ipaddr", tmp);
-	setenv("llipaddr", tmp); /* store this for next time */
+	setenv_transient("ipaddr", tmp);
+	setenv_transient("llipaddr", tmp); /* store this for next time */
 
 	return CMD_RET_SUCCESS;
 }
-- 
2.7.3



More information about the U-Boot mailing list