nlattr: provide common AF_INET{,6} address decoders

Rename decode_ifla_inet6_token to decode_nla_in6_addr,
add a sister function decode_nla_in_addr for future use.

* nlattr.c (decode_nla_in_addr, decode_nla_in6_addr): New functions.
* nlattr.h (DECL_NLA(in_addr), DECL_NLA(in6_addr)): New declarations.
* rtnl_link.c (decode_ifla_inet6_token): Remove.
(ifla_inet6_nla_decoders) <[IFLA_INET6_TOKEN]>: Use decode_nla_in6_addr.
This commit is contained in:
Eugene Syromyatnikov 2018-08-19 14:37:12 +02:00 committed by Dmitry V. Levin
parent 1d7b8edda9
commit 288b872266
3 changed files with 35 additions and 17 deletions

View File

@ -357,6 +357,38 @@ decode_nla_ip_proto(struct tcb *const tcp,
return decode_nla_xval(tcp, addr, len, &opts);
}
bool
decode_nla_in_addr(struct tcb *const tcp,
const kernel_ulong_t addr,
const unsigned int len,
const void *const opaque_data)
{
struct in_addr in;
if (len < sizeof(in))
return false;
else if (!umove_or_printaddr(tcp, addr, &in))
print_inet_addr(AF_INET, &in, sizeof(in), NULL);
return true;
}
bool
decode_nla_in6_addr(struct tcb *const tcp,
const kernel_ulong_t addr,
const unsigned int len,
const void *const opaque_data)
{
struct in6_addr in6;
if (len < sizeof(in6))
return false;
else if (!umove_or_printaddr(tcp, addr, &in6))
print_inet_addr(AF_INET6, &in6, sizeof(in6), NULL);
return true;
}
bool
decode_nla_flags(struct tcb *const tcp,
const kernel_ulong_t addr,

View File

@ -102,6 +102,8 @@ DECL_NLA(gid);
DECL_NLA(ifindex);
DECL_NLA(ether_proto);
DECL_NLA(ip_proto);
DECL_NLA(in_addr);
DECL_NLA(in6_addr);
DECL_NLA(meminfo);
DECL_NLA(rt_class);
DECL_NLA(rt_proto);

View File

@ -761,22 +761,6 @@ decode_ifla_inet6_icmp6_stats(struct tcb *const tcp,
return true;
}
static bool
decode_ifla_inet6_token(struct tcb *const tcp,
const kernel_ulong_t addr,
const unsigned int len,
const void *const opaque_data)
{
struct in6_addr in6;
if (len < sizeof(in6))
return false;
else if (!umove_or_printaddr(tcp, addr, &in6))
print_inet_addr(AF_INET6, &in6, sizeof(in6), NULL);
return true;
}
static bool
decode_ifla_inet6_agm(struct tcb *const tcp,
const kernel_ulong_t addr,
@ -799,7 +783,7 @@ static const nla_decoder_t ifla_inet6_nla_decoders[] = {
[IFLA_INET6_MCAST] = NULL, /* unused */
[IFLA_INET6_CACHEINFO] = decode_ifla_inet6_cacheinfo,
[IFLA_INET6_ICMP6STATS] = decode_ifla_inet6_icmp6_stats,
[IFLA_INET6_TOKEN] = decode_ifla_inet6_token,
[IFLA_INET6_TOKEN] = decode_nla_in6_addr,
[IFLA_INET6_ADDR_GEN_MODE] = decode_ifla_inet6_agm,
};