diff mbox series

[06/17] net: ipv6: Enable IPv6 typeconversion specifier

Message ID 20220906150955.505100-7-v.v.mitrofanov@yadro.com
State Superseded
Delegated to: Ramon Fried
Headers show
Series IPv6 support | expand

Commit Message

Vyacheslav V. Mitrofanov Sept. 6, 2022, 3:09 p.m. UTC
Add the possibility to recognize IPv6 address in print function.
To output IPv6 address use %pI6 specifier.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
---
 lib/vsprintf.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Ramon Fried Sept. 12, 2022, 6:59 a.m. UTC | #1
On Tue, Sep 6, 2022 at 6:10 PM Viacheslav Mitrofanov
<v.v.mitrofanov@yadro.com> wrote:
>
> Add the possibility to recognize IPv6 address in print function.
> To output IPv6 address use %pI6 specifier.
>
> Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
> ---
>  lib/vsprintf.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index fe06aa2d71..c194052563 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -346,6 +346,7 @@ static char *mac_address_string(char *buf, char *end, u8 *addr, int field_width,
>                       flags & ~SPECIAL);
>  }
>
> +#if IS_ENABLED(CONFIG_IPV6)
>  static char *ip6_addr_string(char *buf, char *end, u8 *addr, int field_width,
>                          int precision, int flags)
>  {
> @@ -365,6 +366,7 @@ static char *ip6_addr_string(char *buf, char *end, u8 *addr, int field_width,
>         return string(buf, end, ip6_addr, field_width, precision,
>                       flags & ~SPECIAL);
>  }
> +#endif
>
>  static char *ip4_addr_string(char *buf, char *end, u8 *addr, int field_width,
>                          int precision, int flags)
> @@ -450,10 +452,6 @@ static char *uuid_string(char *buf, char *end, u8 *addr, int field_width,
>   *       decimal for v4 and colon separated network-order 16 bit hex for v6)
>   * - 'i' [46] for 'raw' IPv4/IPv6 addresses, IPv6 omits the colons, IPv4 is
>   *       currently the same
> - *
> - * Note: IPv6 support is currently if(0)'ed out. If you ever need
> - * %pI6, please add an IPV6 Kconfig knob, make your code select or
> - * depend on that, and change the 0 below to CONFIG_IS_ENABLED(IPV6).
>   */
>  static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
>                 int field_width, int precision, int flags)
> @@ -498,8 +496,7 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
>                 flags |= SPECIAL;
>                 /* Fallthrough */
>         case 'I':
> -               /* %pI6 currently unused */
> -               if (0 && fmt[1] == '6')
> +               if (IS_ENABLED(CONFIG_IPV6) && fmt[1] == '6')
>                         return ip6_addr_string(buf, end, ptr, field_width,
>                                                precision, flags);
>                 if (fmt[1] == '4')
> --
> 2.25.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
diff mbox series

Patch

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index fe06aa2d71..c194052563 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -346,6 +346,7 @@  static char *mac_address_string(char *buf, char *end, u8 *addr, int field_width,
 		      flags & ~SPECIAL);
 }
 
+#if IS_ENABLED(CONFIG_IPV6)
 static char *ip6_addr_string(char *buf, char *end, u8 *addr, int field_width,
 			 int precision, int flags)
 {
@@ -365,6 +366,7 @@  static char *ip6_addr_string(char *buf, char *end, u8 *addr, int field_width,
 	return string(buf, end, ip6_addr, field_width, precision,
 		      flags & ~SPECIAL);
 }
+#endif
 
 static char *ip4_addr_string(char *buf, char *end, u8 *addr, int field_width,
 			 int precision, int flags)
@@ -450,10 +452,6 @@  static char *uuid_string(char *buf, char *end, u8 *addr, int field_width,
  *       decimal for v4 and colon separated network-order 16 bit hex for v6)
  * - 'i' [46] for 'raw' IPv4/IPv6 addresses, IPv6 omits the colons, IPv4 is
  *       currently the same
- *
- * Note: IPv6 support is currently if(0)'ed out. If you ever need
- * %pI6, please add an IPV6 Kconfig knob, make your code select or
- * depend on that, and change the 0 below to CONFIG_IS_ENABLED(IPV6).
  */
 static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 		int field_width, int precision, int flags)
@@ -498,8 +496,7 @@  static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 		flags |= SPECIAL;
 		/* Fallthrough */
 	case 'I':
-		/* %pI6 currently unused */
-		if (0 && fmt[1] == '6')
+		if (IS_ENABLED(CONFIG_IPV6) && fmt[1] == '6')
 			return ip6_addr_string(buf, end, ptr, field_width,
 					       precision, flags);
 		if (fmt[1] == '4')