summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorViacheslav Mitrofanov <v.v.mitrofanov@yadro.com>2022-12-02 12:18:02 +0300
committerTom Rini <trini@konsulko.com>2022-12-05 20:47:16 +0300
commit2f7f2f2aa9d310c2937bd753df1a2bd6953194d1 (patch)
treeb13dcd80d9cba3c62de972dbcf85da06bb95f644 /include
parentc6610e1d90ea56711204b4d7a773f8e38976c87b (diff)
downloadu-boot-2f7f2f2aa9d310c2937bd753df1a2bd6953194d1.tar.xz
net: ipv6: Add string_to_ip6 converter
This functions is used as a converter from IPv6 address string notation to struct ip6_addr that is used everywhere in IPv6 implementation. For example it is used to parse and convert IPv6 address from tftpboot command. Conversion algorithm uses two passes, first to verify syntax and locate colons and second pass to read the address. In case of valid IPv6 address it returns 0. Examples of valid strings: 2001:db8::0:1234:1 2001:0db8:0000:0000:0000:0000:1234:0001 ::1 ::ffff:192.168.1.1 Examples of invalid strings 2001:db8::0::0 (:: can only appear once) 2001:db8:192.168.1.1::1 (v4 part can only appear at the end) 192.168.1.1 (we don't implicity map v4) Series-changes: 3 - Added function description - Added length parameter to string_to_ip6() Series-changes: 4 - Fixed function description style 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 'include')
-rw-r--r--include/net6.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/include/net6.h b/include/net6.h
index 78981877ce..50b7120ca3 100644
--- a/include/net6.h
+++ b/include/net6.h
@@ -174,6 +174,7 @@ extern u32 net_prefix_length; /* Our prefixlength (0 = unknown) */
extern struct in6_addr net_server_ip6; /* Server IPv6 addr (0 = unknown) */
extern bool use_ip6;
+#if IS_ENABLED(CONFIG_IPV6)
/**
* string_to_ip6() - Convert IPv6 string addr to inner IPV6 addr format
*
@@ -193,11 +194,14 @@ extern bool use_ip6;
* @addr: converted IPv6 addr
* Return: 0 if conversion successful, -EINVAL if fail
*/
+int string_to_ip6(const char *s, size_t len, struct in6_addr *addr);
+#else
static inline int
string_to_ip6(const char *s, size_t len, struct in6_addr *addr)
{
return -EINVAL;
}
+#endif
/**
* ip6_is_unspecified_addr() - Check if IPv6 addr is not set i.e. is zero