On Nov 25, 2008, at 1:01 AM, Harvey Harrison wrote:
In the NFS and RPC kernel implementation we often need to print an
address in debugging messages.
It would be so much easier to have a so-called dynamic formatter for
multiple address types. Then you can avoid this kind of code in a
whole lot of places:
switch (sap->sa_family) {
case AF_INET:
dprintk("NFS: connected to address %pI4\n",
&((struct sockaddr_in *)sap)->sin_addr.s_addr);
break;
case AF_INET6:
/* maybe add some logic here to recognize mapped IPv4
* and display it as dotted quad... */
dprintk("NFS: connected to address %pI6\n",
&((struct sockaddr_in6 *)sap)->sin6_addr);
break;
default:
dprintk("NFS: bad address\n");
}
Especially since there is a conditional inside the dprintk() macro
that skips all of the dprintk() logic if rpc_debug is not set. This
could be reduced to:
dprintk("NFS: connected to address %pS\n", sap);
What we end up doing to make printk() and sprintf() convenient is
generate the address strings in a buffer, and using "%s" to print
them. It consumes memory to keep these buffers around, or a lot of
stack space to generate the presentation format addresses as needed.
And, as mentioned above, for debugging messages, the additional buffer
and conversion logic isn't even needed until debugging is enabled.
The sin6_scope_id field is an unsigned value that specifies an index
into an array of network interfaces.
It can be converted to presentation format by appending '%' and the
integer to the IPv6 address. The scope ID is important for link-local
addresses. Without it, a link-local address cannot be used for
anything but display.
Having the ability to handle a scope ID formatter would be useful for
putting addresses in buffers too, but you may have only touched
printk() for now?
There are several places in the NFS client that handle an address
string -- usually these strings are put on the network or come from
the network. The NFSv4 client ID string is composed of at least two
address strings. NFSv4 referrals can arrive from a server as a
hostname or an address string. Universal addresses, used by rpcbind
versions 3 and 4, are strings that contain an address and a port
number in a special format. All of these things would benefit from
having the ability to use the address formatters with sprintf() and
friends.
For systems built with modern kernels but running in legacy
distributions or with only IPv4 addresses configured, the sudden
appearance of an IPv6 presentation format address in the kernel log,
for example, might be pretty confusing.
It would also be handy if %pI6 could produce the double-colon format.
I seem to recall there was some talk of having another format
specifier that could remove contiguous zeros and replace them with "::".
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html