Project

General

Profile

Feature #5980

in-kernel inet_ntop should format IPv4 addresses like userland one

Added by Gordon Ross over 4 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
kernel
Start date:
2015-06-03
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:

Description

The in-kernel inet_ntop() formats 10.10.0.4 like this:
010.010.000.004

The leading zeros are different from how the standard inet_ntop() formats IPv4 addresses.
The old behavior is not "wrong" but is inconvenient, so this is an RFE.


Related issues

Related to illumos gate - Bug #6026: Zero-padded IP address strings returned by SMBClosed2015-06-21

Actions
Related to illumos gate - Bug #8488: mdb: idm module doesn't need a copy of kernel's inet_ntopNew2017-07-13

Actions
Related to illumos gate - Bug #11647: 6026 regressed after 5980Closed

Actions
Precedes illumos gate - Bug #8474: inet_ntop's addrlen argument should be socklen_tNew2015-06-042015-06-04

Actions

History

#1

Updated by Gordon Ross over 4 years ago

  • Description updated (diff)
#2

Updated by Joshua M. Clulow over 4 years ago

In the past we made some changes to the behaviour of inet_pton in the kernel, as well. We retained the old behaviour for binary modules that could not be rebuilt, and used #pragma redefine_extname to enable the fixed behaviour for newly compiled modules. We could do the same thing here, with a structure like:

#define    ERROR_BAD_ADDRESS    "<badaddr>" 
#define    ERROR_BAD_FAMILY    "<badfamily>" 

#define    IPV4_PAD        "%03d.%03d.%03d.%03d" 
#define    IPV4_NOPAD        "%d.%d.%d.%d" 

#define    UC(b)            (((int)b) & 0xff)

/*
 * Common implementation.
 */
static char *
inet_ntop_common(int af, const void *addr, char *buf, int addrlen, boolean_t ipv4_padding)
{
        in6_addr_t *v6addr;
        uchar_t *v4addr;
        char *caddr;

    VERIFY(buf != NULL);
    VERIFY(addr != NULL);

    switch (af) {
    case AF_INET:
        VERIFY(addrlen >= INET_ADDRSTRLEN);
        v4addr = (uchar_t *)addr;
        (void) sprintf(buf, ipv4_padding ? IPV4_PAD : IPV4_NOPAD,
            UC(v4addr[0]), UC(v4addr[1]), UC(v4addr[2]), UC(v4addr[3]));
        return (buf);

    ...

    default:
        return (ERROR_BAD_FAMILY);
    }
}

/*
 * New wrapper.  Using "#pragma redefine_extname" in the header to make this the
 * function that new users of "inet_ntop()" get.
 */
char *
_inet_ntop(int af, const void *addr, char *buf, int addrlen)
{
    return (inet_ntop_common(af, addr, buf, addrlen, B_FALSE));
}

/*
 * Old wrapper.
 */
char *
inet_ntop(int af, const void *addr, char *buf, int addrlen)
{
    static char local_buf[INET6_ADDRSTRLEN];

    ASSERT(buf != NULL);
    if (buf == NULL) {
        buf = local_buf;
    }

    return (inet_ntop_common(af, addr, buf, addrlen, B_TRUE));
}

Noting, of course, that if we're going to do this then we should scrub out all of the latent sadness in the current implementation (e.g. the static buffer, out-of-date comments, poorly defined macros, etc).

#3

Updated by Marcel Telka over 4 years ago

  • Related to Bug #6026: Zero-padded IP address strings returned by SMB added
#4

Updated by Yuri Pankov over 2 years ago

  • Subject changed from In-kernel inet_ntop should format IPv4 addresses like libnsl:inet_ntop to in-kernel inet_ntop should format IPv4 addresses like userland one
  • Category set to kernel
  • Status changed from New to In Progress
  • Assignee set to Yuri Pankov
  • % Done changed from 0 to 30
  • Tags deleted (needs-triage)
#5

Updated by Yuri Pankov over 2 years ago

  • Precedes Bug #8474: inet_ntop's addrlen argument should be socklen_t added
#6

Updated by Yuri Pankov over 2 years ago

  • Related to Bug #8488: mdb: idm module doesn't need a copy of kernel's inet_ntop added
#7

Updated by Electric Monk about 2 years ago

  • Status changed from In Progress to Closed
  • % Done changed from 30 to 100

git commit 0b905b49d460a57773d88d714cd880ffe0182b7c

commit  0b905b49d460a57773d88d714cd880ffe0182b7c
Author: Yuri Pankov <yuri.pankov@nexenta.com>
Date:   2017-07-29T17:41:44.000Z

    5980 in-kernel inet_ntop should format IPv4 addresses like userland one
    Reviewed by: Igor Kozhukhov <igor@dilos.org>
    Reviewed by: Dan McDonald <danmcd@joyent.com>
    Reviewed by: Vitaliy Gusev <gusev.vitaliy@icloud.com>
    Approved by: Richard Lowe <richlowe@richlowe.net>

#8

Updated by Yuri Pankov about 2 months ago

  • Related to Bug #11647: 6026 regressed after 5980 added

Also available in: Atom PDF