net: Remove env_get_ip helper() function
Currently, we have the function env_get_ip which takes an IP address in string form and returns a struct in_addr representation of that address. It is however little used and means that a number of places indirectly (and unclearly) get <env.h> via <net.h>. To clean this up start by replacing env_get_ip() calls with string_to_ip() calls. This is generally a no-op as env_get_ip(str) is an inline of string_to_ip(env_get(str)) but in a few cases we can or already have stored the result of env_get(str) and can save the additional call. Signed-off-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
@@ -247,7 +247,7 @@ int do_bootvx(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
||||
ptr += sprintf(build_buf + ptr, "e=%s", tmp);
|
||||
tmp = env_get("netmask");
|
||||
if (tmp) {
|
||||
u32 mask = env_get_ip("netmask").s_addr;
|
||||
u32 mask = string_to_ip(tmp).s_addr;
|
||||
ptr += sprintf(build_buf + ptr,
|
||||
":%08x ", ntohl(mask));
|
||||
} else {
|
||||
|
||||
@@ -564,7 +564,7 @@ int do_sntp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
||||
char *toff;
|
||||
|
||||
if (argc < 2) {
|
||||
net_ntp_server = env_get_ip("ntpserverip");
|
||||
net_ntp_server = string_to_ip(env_get("ntpserverip"));
|
||||
if (net_ntp_server.s_addr == 0) {
|
||||
printf("ntpserverip not set\n");
|
||||
return CMD_RET_FAILURE;
|
||||
|
||||
@@ -61,8 +61,8 @@ static int is_broadcast(struct in_addr ip)
|
||||
|
||||
/* update only when the environment has changed */
|
||||
if (env_changed_id != env_id) {
|
||||
netmask = env_get_ip("netmask");
|
||||
our_ip = env_get_ip("ipaddr");
|
||||
netmask = string_to_ip(env_get("netmask"));
|
||||
our_ip = string_to_ip(env_get("ipaddr"));
|
||||
|
||||
env_changed_id = env_id;
|
||||
}
|
||||
@@ -81,11 +81,12 @@ static int refresh_settings_from_env(void)
|
||||
|
||||
/* update only when the environment has changed */
|
||||
if (env_changed_id != env_id) {
|
||||
if (env_get("ncip")) {
|
||||
nc_ip = env_get_ip("ncip");
|
||||
char *tmp = env_get("ncip");
|
||||
if (tmp) {
|
||||
nc_ip = string_to_ip(tmp);
|
||||
if (!nc_ip.s_addr)
|
||||
return -1; /* ncip is 0.0.0.0 */
|
||||
p = strchr(env_get("ncip"), ':');
|
||||
p = strchr(tmp, ':');
|
||||
if (p != NULL) {
|
||||
nc_out_port = dectoul(p + 1, NULL);
|
||||
nc_in_port = nc_out_port;
|
||||
|
||||
@@ -456,19 +456,6 @@ void net_process_received_packet(uchar *in_packet, int len);
|
||||
*/
|
||||
int update_tftp(ulong addr, char *interface, char *devstring);
|
||||
|
||||
/**
|
||||
* env_get_ip() - Convert an environment value to an ip address
|
||||
*
|
||||
* @var: Environment variable to convert. The value of this variable must be
|
||||
* in the format a.b.c.d, where each value is a decimal number from
|
||||
* 0 to 255
|
||||
* Return: IP address, or 0 if invalid
|
||||
*/
|
||||
static inline struct in_addr env_get_ip(char *var)
|
||||
{
|
||||
return string_to_ip(env_get(var));
|
||||
}
|
||||
|
||||
int net_init(void);
|
||||
|
||||
/* Called when a network operation fails to know if it should be re-tried */
|
||||
|
||||
@@ -106,7 +106,7 @@ static void configure_wait(void)
|
||||
|
||||
void link_local_start(void)
|
||||
{
|
||||
ip = env_get_ip("llipaddr");
|
||||
ip = string_to_ip(env_get("llipaddr"));
|
||||
if (ip.s_addr != 0 &&
|
||||
(ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
|
||||
puts("invalid link address");
|
||||
|
||||
Reference in New Issue
Block a user