• Daniel Borkmann's avatar
    lib: vsprintf: add IPv4/v6 generic %p[Ii]S[pfs] format specifier · 10679643
    Daniel Borkmann authored
    In order to avoid making code that deals with printing both, IPv4 and
    IPv6 addresses, unnecessary complicated as for example ...
    
      if (sa.sa_family == AF_INET6)
        printk("... %pI6 ...", ..sin6_addr);
      else
        printk("... %pI4 ...", ..sin_addr.s_addr);
    
    ... it would be better to introduce a format specifier that can deal
    with those kind of situations internally; just as we have a "struct
    sockaddr" for generic mapping into "struct sockaddr_in" or "struct
    sockaddr_in6" as e.g. done in "union sctp_addr". Then, we could
    reduce the above statement into something like:
    
      printk("... %pIS ..", &sockaddr);
    
    In case our pointer is NULL, pointer() then deals with that already at
    an earlier point in time internally. While we're at it, support for both
    %piS/%pIS, where 'S' stands for sockaddr, comes (almost) for free.
    
    Additionally to that, postfix specifiers 'p', 'f' and 's' are supported
    as suggested and initially implemented in 2009 by Joe Perches [1].
    Handling of those additional specifiers orientate on the initial RFC that
    was proposed. Also we support IPv6 compressed format specified by 'c' and
    various other IPv4 extensions as stated in the documentation part.
    
    Likely, there are many other areas than just SCTP in the kernel to make
    use of this extension as well.
    
     [1] http://patchwork.ozlabs.org/patch/31480/Signed-off-by: default avatarDaniel Borkmann <dborkman@redhat.com>
    CC: Joe Perches <joe@perches.com>
    CC: linux-kernel@vger.kernel.org
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    10679643
vsprintf.c 56 KB