diff options
| author | Breno Leitao <leitao@debian.org> | 2025-08-11 11:13:26 -0700 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2025-08-12 17:32:42 -0700 |
| commit | 364213b736e313fab963b272ebe5a2ffeb888831 (patch) | |
| tree | 165a209069ff224851cdcddd30e44d3c4b573135 /drivers/net/netconsole.c | |
| parent | netconsole: move netpoll_parse_ip_addr() earlier for reuse (diff) | |
| download | linux-364213b736e313fab963b272ebe5a2ffeb888831.tar.gz linux-364213b736e313fab963b272ebe5a2ffeb888831.zip | |
netconsole: add support for strings with new line in netpoll_parse_ip_addr
The current IP address parsing logic fails when the input string
contains a trailing newline character. This can occur when IP
addresses are provided through configfs, which contains newlines in
a const buffer.
Teach netpoll_parse_ip_addr() how to ignore newlines at the end of the
IPs. Also, simplify the code by:
* No need to check for separators. Try to parse ipv4, if it fails try
ipv6 similarly to ceph_pton()
* If ipv6 is not supported, don't call in6_pton() at all.
Signed-off-by: Breno Leitao <leitao@debian.org>
Link: https://patch.msgid.link/20250811-netconsole_ref-v4-2-9c510d8713a2@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'drivers/net/netconsole.c')
| -rw-r--r-- | drivers/net/netconsole.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 8d1b93264e0f..2919522d963e 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -300,23 +300,30 @@ static void netconsole_print_banner(struct netpoll *np) np_info(np, "remote ethernet address %pM\n", np->remote_mac); } +/* Parse the string and populate the `inet_addr` union. Return 0 if IPv4 is + * populated, 1 if IPv6 is populated, and -1 upon failure. + */ static int netpoll_parse_ip_addr(const char *str, union inet_addr *addr) { - const char *end; + const char *end = NULL; + int len; - if (!strchr(str, ':') && - in4_pton(str, -1, (void *)addr, -1, &end) > 0) { - if (!*end) - return 0; - } - if (in6_pton(str, -1, addr->in6.s6_addr, -1, &end) > 0) { -#if IS_ENABLED(CONFIG_IPV6) - if (!*end) - return 1; -#else + len = strlen(str); + if (!len) return -1; -#endif - } + + if (str[len - 1] == '\n') + len -= 1; + + if (in4_pton(str, len, (void *)addr, -1, &end) > 0 && + (!end || *end == 0 || *end == '\n')) + return 0; + + if (IS_ENABLED(CONFIG_IPV6) && + in6_pton(str, len, (void *)addr, -1, &end) > 0 && + (!end || *end == 0 || *end == '\n')) + return 1; + return -1; } |
