1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-11-02 03:17:29 +01:00

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>
This commit is contained in:
Viacheslav Mitrofanov
2022-12-02 12:18:02 +03:00
committed by Tom Rini
parent c6610e1d90
commit 2f7f2f2aa9
2 changed files with 113 additions and 0 deletions

View File

@@ -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