diff options
author | Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com> | 2022-12-02 12:18:04 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-12-05 12:47:16 -0500 |
commit | 43ab8ecc7deecb54fe8838fb61fa559196e68b4e (patch) | |
tree | d89d4da7c2efd506b7be72be48b70895c81d8a26 /net/net6.c | |
parent | d807199da7a85dd299b25b380ba820a68d6a0db5 (diff) | |
download | u-boot-43ab8ecc7deecb54fe8838fb61fa559196e68b4e.tar.gz |
net: ipv6: Add ip6addr, gatewayip6, serverip6 variables callbacks
Implement actions on ip6addr, gatewayip6, serverip6 varaibles.
on_ip6addr - convert IPv6 string addr to struct ip6_addr
on_gatewayip6 - convert IPv6 string addr to struct ip6_addr
on_serverip6 - convert IPv6 string addr to struct ip6_addr
Series-changes: 3
- Removed memory allocation
- Substituted -1 for error code
Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'net/net6.c')
-rw-r--r-- | net/net6.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/net/net6.c b/net/net6.c index 7cd442e6e2..cfbd4f5827 100644 --- a/net/net6.c +++ b/net/net6.c @@ -29,3 +29,51 @@ struct in6_addr net_server_ip6 = ZERO_IPV6_ADDR; u32 net_prefix_length; bool use_ip6; + +static int on_ip6addr(const char *name, const char *value, enum env_op op, + int flags) +{ + char *mask; + size_t len; + + if (flags & H_PROGRAMMATIC) + return 0; + + if (op == env_op_delete) { + net_prefix_length = 0; + net_copy_ip6(&net_ip6, &net_null_addr_ip6); + return 0; + } + + mask = strchr(value, '/'); + len = strlen(value); + + if (mask) + net_prefix_length = simple_strtoul(value + len, NULL, 10); + + return string_to_ip6(value, len, &net_ip6); +} + +U_BOOT_ENV_CALLBACK(ip6addr, on_ip6addr); + +static int on_gatewayip6(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + return string_to_ip6(value, strlen(value), &net_gateway6); +} + +U_BOOT_ENV_CALLBACK(gatewayip6, on_gatewayip6); + +static int on_serverip6(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + return string_to_ip6(value, strlen(value), &net_server_ip6); +} + +U_BOOT_ENV_CALLBACK(serverip6, on_serverip6); |