netlink: implement nla_put_in_addr and nla_put_in6_addr

IP addresses are often stored in netlink attributes. Add generic functions
to do that.

For nla_put_in_addr, it would be nicer to pass struct in_addr but this is
not used universally throughout the kernel, in way too many places __be32 is
used to store IPv4 address.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Jiri Benc 2015-03-29 16:59:25 +02:00 committed by David S. Miller
parent 15e318bdc6
commit 930345ea63
29 changed files with 139 additions and 124 deletions

View file

@ -786,19 +786,19 @@ static int tcp_metrics_fill_info(struct sk_buff *msg,
switch (tm->tcpm_daddr.family) {
case AF_INET:
if (nla_put_be32(msg, TCP_METRICS_ATTR_ADDR_IPV4,
tm->tcpm_daddr.addr.a4) < 0)
if (nla_put_in_addr(msg, TCP_METRICS_ATTR_ADDR_IPV4,
tm->tcpm_daddr.addr.a4) < 0)
goto nla_put_failure;
if (nla_put_be32(msg, TCP_METRICS_ATTR_SADDR_IPV4,
tm->tcpm_saddr.addr.a4) < 0)
if (nla_put_in_addr(msg, TCP_METRICS_ATTR_SADDR_IPV4,
tm->tcpm_saddr.addr.a4) < 0)
goto nla_put_failure;
break;
case AF_INET6:
if (nla_put(msg, TCP_METRICS_ATTR_ADDR_IPV6, 16,
tm->tcpm_daddr.addr.a6) < 0)
if (nla_put_in6_addr(msg, TCP_METRICS_ATTR_ADDR_IPV6,
&tm->tcpm_daddr.addr.in6) < 0)
goto nla_put_failure;
if (nla_put(msg, TCP_METRICS_ATTR_SADDR_IPV6, 16,
tm->tcpm_saddr.addr.a6) < 0)
if (nla_put_in6_addr(msg, TCP_METRICS_ATTR_SADDR_IPV6,
&tm->tcpm_saddr.addr.in6) < 0)
goto nla_put_failure;
break;
default: