net: ipv6: Add string_to_ip6 converter
authorViacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Fri, 2 Dec 2022 09:18:02 +0000 (12:18 +0300)
committerTom Rini <trini@konsulko.com>
Mon, 5 Dec 2022 17:47:16 +0000 (12:47 -0500)
commit2f7f2f2aa9d310c2937bd753df1a2bd6953194d1
treeb13dcd80d9cba3c62de972dbcf85da06bb95f644
parentc6610e1d90ea56711204b4d7a773f8e38976c87b
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>
include/net6.h
lib/net_utils.c