Merge branch 'nla_in_addr'

Jiri Benc says:

====================
netlink: access functions for IP address attributes

There are many places that read or write IP addresses to netlink attributes.
With IPv6 addresses, every such place currently has to use generic nla_put
and nla_memcpy. Implementing IPv6 address access functions simplify things
and makes the code more intelligible. IPv4 address access functions has
lesser value but it would be better to be consistent between IPv6 and IPv4
and they still serve as documentation.

The conversion is straightforward and the resulting patches are not that
large, thus I kept all the changes in the patches that introduce the access
functions. If anyone prefers to split the definition of access functions and
the conversion and/or break it out by network protocols, please let me know.

While doing the conversion, I came across ugly typecasting in
inetpeer_addr_base and xfrm_address_t when dealing with IPv6 addresses.
Instead of introducing more of this, I cleaned it up. Those are the first
two patches, serving as a prerequisite to the latter two.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
David S. Miller 2015-03-31 13:58:36 -04:00
commit 8e1fa36b3f
36 changed files with 234 additions and 214 deletions

View File

@ -171,11 +171,11 @@ static inline bool vxlan_addr_multicast(const union vxlan_addr *ipa)
static int vxlan_nla_get_addr(union vxlan_addr *ip, struct nlattr *nla) static int vxlan_nla_get_addr(union vxlan_addr *ip, struct nlattr *nla)
{ {
if (nla_len(nla) >= sizeof(struct in6_addr)) { if (nla_len(nla) >= sizeof(struct in6_addr)) {
nla_memcpy(&ip->sin6.sin6_addr, nla, sizeof(struct in6_addr)); ip->sin6.sin6_addr = nla_get_in6_addr(nla);
ip->sa.sa_family = AF_INET6; ip->sa.sa_family = AF_INET6;
return 0; return 0;
} else if (nla_len(nla) >= sizeof(__be32)) { } else if (nla_len(nla) >= sizeof(__be32)) {
ip->sin.sin_addr.s_addr = nla_get_be32(nla); ip->sin.sin_addr.s_addr = nla_get_in_addr(nla);
ip->sa.sa_family = AF_INET; ip->sa.sa_family = AF_INET;
return 0; return 0;
} else { } else {
@ -187,9 +187,9 @@ static int vxlan_nla_put_addr(struct sk_buff *skb, int attr,
const union vxlan_addr *ip) const union vxlan_addr *ip)
{ {
if (ip->sa.sa_family == AF_INET6) if (ip->sa.sa_family == AF_INET6)
return nla_put(skb, attr, sizeof(struct in6_addr), &ip->sin6.sin6_addr); return nla_put_in6_addr(skb, attr, &ip->sin6.sin6_addr);
else else
return nla_put_be32(skb, attr, ip->sin.sin_addr.s_addr); return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr);
} }
#else /* !CONFIG_IPV6 */ #else /* !CONFIG_IPV6 */
@ -215,7 +215,7 @@ static int vxlan_nla_get_addr(union vxlan_addr *ip, struct nlattr *nla)
if (nla_len(nla) >= sizeof(struct in6_addr)) { if (nla_len(nla) >= sizeof(struct in6_addr)) {
return -EAFNOSUPPORT; return -EAFNOSUPPORT;
} else if (nla_len(nla) >= sizeof(__be32)) { } else if (nla_len(nla) >= sizeof(__be32)) {
ip->sin.sin_addr.s_addr = nla_get_be32(nla); ip->sin.sin_addr.s_addr = nla_get_in_addr(nla);
ip->sa.sa_family = AF_INET; ip->sa.sa_family = AF_INET;
return 0; return 0;
} else { } else {
@ -226,7 +226,7 @@ static int vxlan_nla_get_addr(union vxlan_addr *ip, struct nlattr *nla)
static int vxlan_nla_put_addr(struct sk_buff *skb, int attr, static int vxlan_nla_put_addr(struct sk_buff *skb, int attr,
const union vxlan_addr *ip) const union vxlan_addr *ip)
{ {
return nla_put_be32(skb, attr, ip->sin.sin_addr.s_addr); return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr);
} }
#endif #endif
@ -2602,27 +2602,25 @@ static int vxlan_newlink(struct net *src_net, struct net_device *dev,
/* Unless IPv6 is explicitly requested, assume IPv4 */ /* Unless IPv6 is explicitly requested, assume IPv4 */
dst->remote_ip.sa.sa_family = AF_INET; dst->remote_ip.sa.sa_family = AF_INET;
if (data[IFLA_VXLAN_GROUP]) { if (data[IFLA_VXLAN_GROUP]) {
dst->remote_ip.sin.sin_addr.s_addr = nla_get_be32(data[IFLA_VXLAN_GROUP]); dst->remote_ip.sin.sin_addr.s_addr = nla_get_in_addr(data[IFLA_VXLAN_GROUP]);
} else if (data[IFLA_VXLAN_GROUP6]) { } else if (data[IFLA_VXLAN_GROUP6]) {
if (!IS_ENABLED(CONFIG_IPV6)) if (!IS_ENABLED(CONFIG_IPV6))
return -EPFNOSUPPORT; return -EPFNOSUPPORT;
nla_memcpy(&dst->remote_ip.sin6.sin6_addr, data[IFLA_VXLAN_GROUP6], dst->remote_ip.sin6.sin6_addr = nla_get_in6_addr(data[IFLA_VXLAN_GROUP6]);
sizeof(struct in6_addr));
dst->remote_ip.sa.sa_family = AF_INET6; dst->remote_ip.sa.sa_family = AF_INET6;
use_ipv6 = true; use_ipv6 = true;
} }
if (data[IFLA_VXLAN_LOCAL]) { if (data[IFLA_VXLAN_LOCAL]) {
vxlan->saddr.sin.sin_addr.s_addr = nla_get_be32(data[IFLA_VXLAN_LOCAL]); vxlan->saddr.sin.sin_addr.s_addr = nla_get_in_addr(data[IFLA_VXLAN_LOCAL]);
vxlan->saddr.sa.sa_family = AF_INET; vxlan->saddr.sa.sa_family = AF_INET;
} else if (data[IFLA_VXLAN_LOCAL6]) { } else if (data[IFLA_VXLAN_LOCAL6]) {
if (!IS_ENABLED(CONFIG_IPV6)) if (!IS_ENABLED(CONFIG_IPV6))
return -EPFNOSUPPORT; return -EPFNOSUPPORT;
/* TODO: respect scope id */ /* TODO: respect scope id */
nla_memcpy(&vxlan->saddr.sin6.sin6_addr, data[IFLA_VXLAN_LOCAL6], vxlan->saddr.sin6.sin6_addr = nla_get_in6_addr(data[IFLA_VXLAN_LOCAL6]);
sizeof(struct in6_addr));
vxlan->saddr.sa.sa_family = AF_INET6; vxlan->saddr.sa.sa_family = AF_INET6;
use_ipv6 = true; use_ipv6 = true;
} }
@ -2807,13 +2805,13 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev)
if (!vxlan_addr_any(&dst->remote_ip)) { if (!vxlan_addr_any(&dst->remote_ip)) {
if (dst->remote_ip.sa.sa_family == AF_INET) { if (dst->remote_ip.sa.sa_family == AF_INET) {
if (nla_put_be32(skb, IFLA_VXLAN_GROUP, if (nla_put_in_addr(skb, IFLA_VXLAN_GROUP,
dst->remote_ip.sin.sin_addr.s_addr)) dst->remote_ip.sin.sin_addr.s_addr))
goto nla_put_failure; goto nla_put_failure;
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
} else { } else {
if (nla_put(skb, IFLA_VXLAN_GROUP6, sizeof(struct in6_addr), if (nla_put_in6_addr(skb, IFLA_VXLAN_GROUP6,
&dst->remote_ip.sin6.sin6_addr)) &dst->remote_ip.sin6.sin6_addr))
goto nla_put_failure; goto nla_put_failure;
#endif #endif
} }
@ -2824,13 +2822,13 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev)
if (!vxlan_addr_any(&vxlan->saddr)) { if (!vxlan_addr_any(&vxlan->saddr)) {
if (vxlan->saddr.sa.sa_family == AF_INET) { if (vxlan->saddr.sa.sa_family == AF_INET) {
if (nla_put_be32(skb, IFLA_VXLAN_LOCAL, if (nla_put_in_addr(skb, IFLA_VXLAN_LOCAL,
vxlan->saddr.sin.sin_addr.s_addr)) vxlan->saddr.sin.sin_addr.s_addr))
goto nla_put_failure; goto nla_put_failure;
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
} else { } else {
if (nla_put(skb, IFLA_VXLAN_LOCAL6, sizeof(struct in6_addr), if (nla_put_in6_addr(skb, IFLA_VXLAN_LOCAL6,
&vxlan->saddr.sin6.sin6_addr)) &vxlan->saddr.sin6.sin6_addr))
goto nla_put_failure; goto nla_put_failure;
#endif #endif
} }

View File

@ -483,7 +483,7 @@ static inline int nla_put_ipaddr4(struct sk_buff *skb, int type, __be32 ipaddr)
if (!__nested) if (!__nested)
return -EMSGSIZE; return -EMSGSIZE;
ret = nla_put_net32(skb, IPSET_ATTR_IPADDR_IPV4, ipaddr); ret = nla_put_in_addr(skb, IPSET_ATTR_IPADDR_IPV4, ipaddr);
if (!ret) if (!ret)
ipset_nest_end(skb, __nested); ipset_nest_end(skb, __nested);
return ret; return ret;
@ -497,8 +497,7 @@ static inline int nla_put_ipaddr6(struct sk_buff *skb, int type,
if (!__nested) if (!__nested)
return -EMSGSIZE; return -EMSGSIZE;
ret = nla_put(skb, IPSET_ATTR_IPADDR_IPV6, ret = nla_put_in6_addr(skb, IPSET_ATTR_IPADDR_IPV6, ipaddrptr);
sizeof(struct in6_addr), ipaddrptr);
if (!ret) if (!ret)
ipset_nest_end(skb, __nested); ipset_nest_end(skb, __nested);
return ret; return ret;

View File

@ -19,6 +19,7 @@ struct inetpeer_addr_base {
union { union {
__be32 a4; __be32 a4;
__be32 a6[4]; __be32 a6[4];
struct in6_addr in6;
}; };
}; };
@ -151,7 +152,7 @@ static inline struct inet_peer *inet_getpeer_v6(struct inet_peer_base *base,
{ {
struct inetpeer_addr daddr; struct inetpeer_addr daddr;
*(struct in6_addr *)daddr.addr.a6 = *v6daddr; daddr.addr.in6 = *v6daddr;
daddr.family = AF_INET6; daddr.family = AF_INET6;
return inet_getpeer(base, &daddr, create); return inet_getpeer(base, &daddr, create);
} }

View File

@ -4,6 +4,7 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/netlink.h> #include <linux/netlink.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/in6.h>
/* ======================================================================== /* ========================================================================
* Netlink Messages and Attributes Interface (As Seen On TV) * Netlink Messages and Attributes Interface (As Seen On TV)
@ -105,6 +106,8 @@
* nla_put_string(skb, type, str) add string attribute to skb * nla_put_string(skb, type, str) add string attribute to skb
* nla_put_flag(skb, type) add flag attribute to skb * nla_put_flag(skb, type) add flag attribute to skb
* nla_put_msecs(skb, type, jiffies) add msecs attribute to skb * nla_put_msecs(skb, type, jiffies) add msecs attribute to skb
* nla_put_in_addr(skb, type, addr) add IPv4 address attribute to skb
* nla_put_in6_addr(skb, type, addr) add IPv6 address attribute to skb
* *
* Nested Attributes Construction: * Nested Attributes Construction:
* nla_nest_start(skb, type) start a nested attribute * nla_nest_start(skb, type) start a nested attribute
@ -956,6 +959,32 @@ static inline int nla_put_msecs(struct sk_buff *skb, int attrtype,
return nla_put(skb, attrtype, sizeof(u64), &tmp); return nla_put(skb, attrtype, sizeof(u64), &tmp);
} }
/**
* nla_put_in_addr - Add an IPv4 address netlink attribute to a socket
* buffer
* @skb: socket buffer to add attribute to
* @attrtype: attribute type
* @addr: IPv4 address
*/
static inline int nla_put_in_addr(struct sk_buff *skb, int attrtype,
__be32 addr)
{
return nla_put_be32(skb, attrtype, addr);
}
/**
* nla_put_in6_addr - Add an IPv6 address netlink attribute to a socket
* buffer
* @skb: socket buffer to add attribute to
* @attrtype: attribute type
* @addr: IPv6 address
*/
static inline int nla_put_in6_addr(struct sk_buff *skb, int attrtype,
const struct in6_addr *addr)
{
return nla_put(skb, attrtype, sizeof(*addr), addr);
}
/** /**
* nla_get_u32 - return payload of u32 attribute * nla_get_u32 - return payload of u32 attribute
* @nla: u32 netlink attribute * @nla: u32 netlink attribute
@ -1098,6 +1127,27 @@ static inline unsigned long nla_get_msecs(const struct nlattr *nla)
return msecs_to_jiffies((unsigned long) msecs); return msecs_to_jiffies((unsigned long) msecs);
} }
/**
* nla_get_in_addr - return payload of IPv4 address attribute
* @nla: IPv4 address netlink attribute
*/
static inline __be32 nla_get_in_addr(const struct nlattr *nla)
{
return *(__be32 *) nla_data(nla);
}
/**
* nla_get_in6_addr - return payload of IPv6 address attribute
* @nla: IPv6 address netlink attribute
*/
static inline struct in6_addr nla_get_in6_addr(const struct nlattr *nla)
{
struct in6_addr tmp;
nla_memcpy(&tmp, nla, sizeof(tmp));
return tmp;
}
/** /**
* nla_nest_start - Start a new level of nested attributes * nla_nest_start - Start a new level of nested attributes
* @skb: socket buffer to add attributes to * @skb: socket buffer to add attributes to

View File

@ -1025,7 +1025,7 @@ xfrm_addr_any(const xfrm_address_t *addr, unsigned short family)
case AF_INET: case AF_INET:
return addr->a4 == 0; return addr->a4 == 0;
case AF_INET6: case AF_INET6:
return ipv6_addr_any((struct in6_addr *)&addr->a6); return ipv6_addr_any(&addr->in6);
} }
return 0; return 0;
} }
@ -1238,8 +1238,8 @@ void xfrm_flowi_addr_get(const struct flowi *fl,
memcpy(&daddr->a4, &fl->u.ip4.daddr, sizeof(daddr->a4)); memcpy(&daddr->a4, &fl->u.ip4.daddr, sizeof(daddr->a4));
break; break;
case AF_INET6: case AF_INET6:
*(struct in6_addr *)saddr->a6 = fl->u.ip6.saddr; saddr->in6 = fl->u.ip6.saddr;
*(struct in6_addr *)daddr->a6 = fl->u.ip6.daddr; daddr->in6 = fl->u.ip6.daddr;
break; break;
} }
} }

View File

@ -1,6 +1,7 @@
#ifndef _LINUX_XFRM_H #ifndef _LINUX_XFRM_H
#define _LINUX_XFRM_H #define _LINUX_XFRM_H
#include <linux/in6.h>
#include <linux/types.h> #include <linux/types.h>
/* All of the structures in this file may not change size as they are /* All of the structures in this file may not change size as they are
@ -13,6 +14,7 @@
typedef union { typedef union {
__be32 a4; __be32 a4;
__be32 a6[4]; __be32 a6[4];
struct in6_addr in6;
} xfrm_address_t; } xfrm_address_t;
/* Ident of a specific xfrm_state. It is used on input to lookup /* Ident of a specific xfrm_state. It is used on input to lookup

View File

@ -593,7 +593,7 @@ static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh)
for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL; for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
ifap = &ifa->ifa_next) { ifap = &ifa->ifa_next) {
if (tb[IFA_LOCAL] && if (tb[IFA_LOCAL] &&
ifa->ifa_local != nla_get_be32(tb[IFA_LOCAL])) ifa->ifa_local != nla_get_in_addr(tb[IFA_LOCAL]))
continue; continue;
if (tb[IFA_LABEL] && nla_strcmp(tb[IFA_LABEL], ifa->ifa_label)) if (tb[IFA_LABEL] && nla_strcmp(tb[IFA_LABEL], ifa->ifa_label))
@ -601,7 +601,7 @@ static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh)
if (tb[IFA_ADDRESS] && if (tb[IFA_ADDRESS] &&
(ifm->ifa_prefixlen != ifa->ifa_prefixlen || (ifm->ifa_prefixlen != ifa->ifa_prefixlen ||
!inet_ifa_match(nla_get_be32(tb[IFA_ADDRESS]), ifa))) !inet_ifa_match(nla_get_in_addr(tb[IFA_ADDRESS]), ifa)))
continue; continue;
if (ipv4_is_multicast(ifa->ifa_address)) if (ipv4_is_multicast(ifa->ifa_address))
@ -791,11 +791,11 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
ifa->ifa_scope = ifm->ifa_scope; ifa->ifa_scope = ifm->ifa_scope;
ifa->ifa_dev = in_dev; ifa->ifa_dev = in_dev;
ifa->ifa_local = nla_get_be32(tb[IFA_LOCAL]); ifa->ifa_local = nla_get_in_addr(tb[IFA_LOCAL]);
ifa->ifa_address = nla_get_be32(tb[IFA_ADDRESS]); ifa->ifa_address = nla_get_in_addr(tb[IFA_ADDRESS]);
if (tb[IFA_BROADCAST]) if (tb[IFA_BROADCAST])
ifa->ifa_broadcast = nla_get_be32(tb[IFA_BROADCAST]); ifa->ifa_broadcast = nla_get_in_addr(tb[IFA_BROADCAST]);
if (tb[IFA_LABEL]) if (tb[IFA_LABEL])
nla_strlcpy(ifa->ifa_label, tb[IFA_LABEL], IFNAMSIZ); nla_strlcpy(ifa->ifa_label, tb[IFA_LABEL], IFNAMSIZ);
@ -1541,11 +1541,11 @@ static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa,
valid = INFINITY_LIFE_TIME; valid = INFINITY_LIFE_TIME;
} }
if ((ifa->ifa_address && if ((ifa->ifa_address &&
nla_put_be32(skb, IFA_ADDRESS, ifa->ifa_address)) || nla_put_in_addr(skb, IFA_ADDRESS, ifa->ifa_address)) ||
(ifa->ifa_local && (ifa->ifa_local &&
nla_put_be32(skb, IFA_LOCAL, ifa->ifa_local)) || nla_put_in_addr(skb, IFA_LOCAL, ifa->ifa_local)) ||
(ifa->ifa_broadcast && (ifa->ifa_broadcast &&
nla_put_be32(skb, IFA_BROADCAST, ifa->ifa_broadcast)) || nla_put_in_addr(skb, IFA_BROADCAST, ifa->ifa_broadcast)) ||
(ifa->ifa_label[0] && (ifa->ifa_label[0] &&
nla_put_string(skb, IFA_LABEL, ifa->ifa_label)) || nla_put_string(skb, IFA_LABEL, ifa->ifa_label)) ||
nla_put_u32(skb, IFA_FLAGS, ifa->ifa_flags) || nla_put_u32(skb, IFA_FLAGS, ifa->ifa_flags) ||

View File

@ -194,10 +194,10 @@ static int fib4_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
} }
if (frh->src_len) if (frh->src_len)
rule4->src = nla_get_be32(tb[FRA_SRC]); rule4->src = nla_get_in_addr(tb[FRA_SRC]);
if (frh->dst_len) if (frh->dst_len)
rule4->dst = nla_get_be32(tb[FRA_DST]); rule4->dst = nla_get_in_addr(tb[FRA_DST]);
#ifdef CONFIG_IP_ROUTE_CLASSID #ifdef CONFIG_IP_ROUTE_CLASSID
if (tb[FRA_FLOW]) { if (tb[FRA_FLOW]) {
@ -260,10 +260,10 @@ static int fib4_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh,
return 0; return 0;
#endif #endif
if (frh->src_len && (rule4->src != nla_get_be32(tb[FRA_SRC]))) if (frh->src_len && (rule4->src != nla_get_in_addr(tb[FRA_SRC])))
return 0; return 0;
if (frh->dst_len && (rule4->dst != nla_get_be32(tb[FRA_DST]))) if (frh->dst_len && (rule4->dst != nla_get_in_addr(tb[FRA_DST])))
return 0; return 0;
return 1; return 1;
@ -279,9 +279,9 @@ static int fib4_rule_fill(struct fib_rule *rule, struct sk_buff *skb,
frh->tos = rule4->tos; frh->tos = rule4->tos;
if ((rule4->dst_len && if ((rule4->dst_len &&
nla_put_be32(skb, FRA_DST, rule4->dst)) || nla_put_in_addr(skb, FRA_DST, rule4->dst)) ||
(rule4->src_len && (rule4->src_len &&
nla_put_be32(skb, FRA_SRC, rule4->src))) nla_put_in_addr(skb, FRA_SRC, rule4->src)))
goto nla_put_failure; goto nla_put_failure;
#ifdef CONFIG_IP_ROUTE_CLASSID #ifdef CONFIG_IP_ROUTE_CLASSID
if (rule4->tclassid && if (rule4->tclassid &&

View File

@ -468,7 +468,7 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
struct nlattr *nla, *attrs = rtnh_attrs(rtnh); struct nlattr *nla, *attrs = rtnh_attrs(rtnh);
nla = nla_find(attrs, attrlen, RTA_GATEWAY); nla = nla_find(attrs, attrlen, RTA_GATEWAY);
nexthop_nh->nh_gw = nla ? nla_get_be32(nla) : 0; nexthop_nh->nh_gw = nla ? nla_get_in_addr(nla) : 0;
#ifdef CONFIG_IP_ROUTE_CLASSID #ifdef CONFIG_IP_ROUTE_CLASSID
nla = nla_find(attrs, attrlen, RTA_FLOW); nla = nla_find(attrs, attrlen, RTA_FLOW);
nexthop_nh->nh_tclassid = nla ? nla_get_u32(nla) : 0; nexthop_nh->nh_tclassid = nla ? nla_get_u32(nla) : 0;
@ -523,7 +523,7 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi)
struct nlattr *nla, *attrs = rtnh_attrs(rtnh); struct nlattr *nla, *attrs = rtnh_attrs(rtnh);
nla = nla_find(attrs, attrlen, RTA_GATEWAY); nla = nla_find(attrs, attrlen, RTA_GATEWAY);
if (nla && nla_get_be32(nla) != nh->nh_gw) if (nla && nla_get_in_addr(nla) != nh->nh_gw)
return 1; return 1;
#ifdef CONFIG_IP_ROUTE_CLASSID #ifdef CONFIG_IP_ROUTE_CLASSID
nla = nla_find(attrs, attrlen, RTA_FLOW); nla = nla_find(attrs, attrlen, RTA_FLOW);
@ -1015,7 +1015,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
rtm->rtm_protocol = fi->fib_protocol; rtm->rtm_protocol = fi->fib_protocol;
if (rtm->rtm_dst_len && if (rtm->rtm_dst_len &&
nla_put_be32(skb, RTA_DST, dst)) nla_put_in_addr(skb, RTA_DST, dst))
goto nla_put_failure; goto nla_put_failure;
if (fi->fib_priority && if (fi->fib_priority &&
nla_put_u32(skb, RTA_PRIORITY, fi->fib_priority)) nla_put_u32(skb, RTA_PRIORITY, fi->fib_priority))
@ -1024,11 +1024,11 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
goto nla_put_failure; goto nla_put_failure;
if (fi->fib_prefsrc && if (fi->fib_prefsrc &&
nla_put_be32(skb, RTA_PREFSRC, fi->fib_prefsrc)) nla_put_in_addr(skb, RTA_PREFSRC, fi->fib_prefsrc))
goto nla_put_failure; goto nla_put_failure;
if (fi->fib_nhs == 1) { if (fi->fib_nhs == 1) {
if (fi->fib_nh->nh_gw && if (fi->fib_nh->nh_gw &&
nla_put_be32(skb, RTA_GATEWAY, fi->fib_nh->nh_gw)) nla_put_in_addr(skb, RTA_GATEWAY, fi->fib_nh->nh_gw))
goto nla_put_failure; goto nla_put_failure;
if (fi->fib_nh->nh_oif && if (fi->fib_nh->nh_oif &&
nla_put_u32(skb, RTA_OIF, fi->fib_nh->nh_oif)) nla_put_u32(skb, RTA_OIF, fi->fib_nh->nh_oif))
@ -1058,7 +1058,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
rtnh->rtnh_ifindex = nh->nh_oif; rtnh->rtnh_ifindex = nh->nh_oif;
if (nh->nh_gw && if (nh->nh_gw &&
nla_put_be32(skb, RTA_GATEWAY, nh->nh_gw)) nla_put_in_addr(skb, RTA_GATEWAY, nh->nh_gw))
goto nla_put_failure; goto nla_put_failure;
#ifdef CONFIG_IP_ROUTE_CLASSID #ifdef CONFIG_IP_ROUTE_CLASSID
if (nh->nh_tclassid && if (nh->nh_tclassid &&

View File

@ -621,10 +621,10 @@ static void ipgre_netlink_parms(struct nlattr *data[], struct nlattr *tb[],
parms->o_key = nla_get_be32(data[IFLA_GRE_OKEY]); parms->o_key = nla_get_be32(data[IFLA_GRE_OKEY]);
if (data[IFLA_GRE_LOCAL]) if (data[IFLA_GRE_LOCAL])
parms->iph.saddr = nla_get_be32(data[IFLA_GRE_LOCAL]); parms->iph.saddr = nla_get_in_addr(data[IFLA_GRE_LOCAL]);
if (data[IFLA_GRE_REMOTE]) if (data[IFLA_GRE_REMOTE])
parms->iph.daddr = nla_get_be32(data[IFLA_GRE_REMOTE]); parms->iph.daddr = nla_get_in_addr(data[IFLA_GRE_REMOTE]);
if (data[IFLA_GRE_TTL]) if (data[IFLA_GRE_TTL])
parms->iph.ttl = nla_get_u8(data[IFLA_GRE_TTL]); parms->iph.ttl = nla_get_u8(data[IFLA_GRE_TTL]);
@ -776,8 +776,8 @@ static int ipgre_fill_info(struct sk_buff *skb, const struct net_device *dev)
nla_put_be16(skb, IFLA_GRE_OFLAGS, tnl_flags_to_gre_flags(p->o_flags)) || nla_put_be16(skb, IFLA_GRE_OFLAGS, tnl_flags_to_gre_flags(p->o_flags)) ||
nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) || nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) ||
nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) || nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) ||
nla_put_be32(skb, IFLA_GRE_LOCAL, p->iph.saddr) || nla_put_in_addr(skb, IFLA_GRE_LOCAL, p->iph.saddr) ||
nla_put_be32(skb, IFLA_GRE_REMOTE, p->iph.daddr) || nla_put_in_addr(skb, IFLA_GRE_REMOTE, p->iph.daddr) ||
nla_put_u8(skb, IFLA_GRE_TTL, p->iph.ttl) || nla_put_u8(skb, IFLA_GRE_TTL, p->iph.ttl) ||
nla_put_u8(skb, IFLA_GRE_TOS, p->iph.tos) || nla_put_u8(skb, IFLA_GRE_TOS, p->iph.tos) ||
nla_put_u8(skb, IFLA_GRE_PMTUDISC, nla_put_u8(skb, IFLA_GRE_PMTUDISC,

View File

@ -456,10 +456,10 @@ static void vti_netlink_parms(struct nlattr *data[],
parms->o_key = nla_get_be32(data[IFLA_VTI_OKEY]); parms->o_key = nla_get_be32(data[IFLA_VTI_OKEY]);
if (data[IFLA_VTI_LOCAL]) if (data[IFLA_VTI_LOCAL])
parms->iph.saddr = nla_get_be32(data[IFLA_VTI_LOCAL]); parms->iph.saddr = nla_get_in_addr(data[IFLA_VTI_LOCAL]);
if (data[IFLA_VTI_REMOTE]) if (data[IFLA_VTI_REMOTE])
parms->iph.daddr = nla_get_be32(data[IFLA_VTI_REMOTE]); parms->iph.daddr = nla_get_in_addr(data[IFLA_VTI_REMOTE]);
} }
@ -505,8 +505,8 @@ static int vti_fill_info(struct sk_buff *skb, const struct net_device *dev)
nla_put_u32(skb, IFLA_VTI_LINK, p->link); nla_put_u32(skb, IFLA_VTI_LINK, p->link);
nla_put_be32(skb, IFLA_VTI_IKEY, p->i_key); nla_put_be32(skb, IFLA_VTI_IKEY, p->i_key);
nla_put_be32(skb, IFLA_VTI_OKEY, p->o_key); nla_put_be32(skb, IFLA_VTI_OKEY, p->o_key);
nla_put_be32(skb, IFLA_VTI_LOCAL, p->iph.saddr); nla_put_in_addr(skb, IFLA_VTI_LOCAL, p->iph.saddr);
nla_put_be32(skb, IFLA_VTI_REMOTE, p->iph.daddr); nla_put_in_addr(skb, IFLA_VTI_REMOTE, p->iph.daddr);
return 0; return 0;
} }

View File

@ -325,10 +325,10 @@ static void ipip_netlink_parms(struct nlattr *data[],
parms->link = nla_get_u32(data[IFLA_IPTUN_LINK]); parms->link = nla_get_u32(data[IFLA_IPTUN_LINK]);
if (data[IFLA_IPTUN_LOCAL]) if (data[IFLA_IPTUN_LOCAL])
parms->iph.saddr = nla_get_be32(data[IFLA_IPTUN_LOCAL]); parms->iph.saddr = nla_get_in_addr(data[IFLA_IPTUN_LOCAL]);
if (data[IFLA_IPTUN_REMOTE]) if (data[IFLA_IPTUN_REMOTE])
parms->iph.daddr = nla_get_be32(data[IFLA_IPTUN_REMOTE]); parms->iph.daddr = nla_get_in_addr(data[IFLA_IPTUN_REMOTE]);
if (data[IFLA_IPTUN_TTL]) { if (data[IFLA_IPTUN_TTL]) {
parms->iph.ttl = nla_get_u8(data[IFLA_IPTUN_TTL]); parms->iph.ttl = nla_get_u8(data[IFLA_IPTUN_TTL]);
@ -450,8 +450,8 @@ static int ipip_fill_info(struct sk_buff *skb, const struct net_device *dev)
struct ip_tunnel_parm *parm = &tunnel->parms; struct ip_tunnel_parm *parm = &tunnel->parms;
if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) ||
nla_put_be32(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) || nla_put_in_addr(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) ||
nla_put_be32(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) || nla_put_in_addr(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) ||
nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) || nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) ||
nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos) || nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos) ||
nla_put_u8(skb, IFLA_IPTUN_PMTUDISC, nla_put_u8(skb, IFLA_IPTUN_PMTUDISC,

View File

@ -2281,8 +2281,8 @@ static int ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
rtm->rtm_protocol = RTPROT_MROUTED; rtm->rtm_protocol = RTPROT_MROUTED;
rtm->rtm_flags = 0; rtm->rtm_flags = 0;
if (nla_put_be32(skb, RTA_SRC, c->mfc_origin) || if (nla_put_in_addr(skb, RTA_SRC, c->mfc_origin) ||
nla_put_be32(skb, RTA_DST, c->mfc_mcastgrp)) nla_put_in_addr(skb, RTA_DST, c->mfc_mcastgrp))
goto nla_put_failure; goto nla_put_failure;
err = __ipmr_fill_mroute(mrt, skb, c, rtm); err = __ipmr_fill_mroute(mrt, skb, c, rtm);
/* do not break the dump if cache is unresolved */ /* do not break the dump if cache is unresolved */

View File

@ -322,8 +322,8 @@ getorigdst(struct sock *sk, int optval, void __user *user, int *len)
static int ipv4_tuple_to_nlattr(struct sk_buff *skb, static int ipv4_tuple_to_nlattr(struct sk_buff *skb,
const struct nf_conntrack_tuple *tuple) const struct nf_conntrack_tuple *tuple)
{ {
if (nla_put_be32(skb, CTA_IP_V4_SRC, tuple->src.u3.ip) || if (nla_put_in_addr(skb, CTA_IP_V4_SRC, tuple->src.u3.ip) ||
nla_put_be32(skb, CTA_IP_V4_DST, tuple->dst.u3.ip)) nla_put_in_addr(skb, CTA_IP_V4_DST, tuple->dst.u3.ip))
goto nla_put_failure; goto nla_put_failure;
return 0; return 0;
@ -342,8 +342,8 @@ static int ipv4_nlattr_to_tuple(struct nlattr *tb[],
if (!tb[CTA_IP_V4_SRC] || !tb[CTA_IP_V4_DST]) if (!tb[CTA_IP_V4_SRC] || !tb[CTA_IP_V4_DST])
return -EINVAL; return -EINVAL;
t->src.u3.ip = nla_get_be32(tb[CTA_IP_V4_SRC]); t->src.u3.ip = nla_get_in_addr(tb[CTA_IP_V4_SRC]);
t->dst.u3.ip = nla_get_be32(tb[CTA_IP_V4_DST]); t->dst.u3.ip = nla_get_in_addr(tb[CTA_IP_V4_DST]);
return 0; return 0;
} }

View File

@ -2319,11 +2319,11 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
if (IPCB(skb)->flags & IPSKB_DOREDIRECT) if (IPCB(skb)->flags & IPSKB_DOREDIRECT)
r->rtm_flags |= RTCF_DOREDIRECT; r->rtm_flags |= RTCF_DOREDIRECT;
if (nla_put_be32(skb, RTA_DST, dst)) if (nla_put_in_addr(skb, RTA_DST, dst))
goto nla_put_failure; goto nla_put_failure;
if (src) { if (src) {
r->rtm_src_len = 32; r->rtm_src_len = 32;
if (nla_put_be32(skb, RTA_SRC, src)) if (nla_put_in_addr(skb, RTA_SRC, src))
goto nla_put_failure; goto nla_put_failure;
} }
if (rt->dst.dev && if (rt->dst.dev &&
@ -2336,11 +2336,11 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
#endif #endif
if (!rt_is_input_route(rt) && if (!rt_is_input_route(rt) &&
fl4->saddr != src) { fl4->saddr != src) {
if (nla_put_be32(skb, RTA_PREFSRC, fl4->saddr)) if (nla_put_in_addr(skb, RTA_PREFSRC, fl4->saddr))
goto nla_put_failure; goto nla_put_failure;
} }
if (rt->rt_uses_gateway && if (rt->rt_uses_gateway &&
nla_put_be32(skb, RTA_GATEWAY, rt->rt_gateway)) nla_put_in_addr(skb, RTA_GATEWAY, rt->rt_gateway))
goto nla_put_failure; goto nla_put_failure;
expires = rt->dst.expires; expires = rt->dst.expires;
@ -2436,8 +2436,8 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh)
ip_hdr(skb)->protocol = IPPROTO_ICMP; ip_hdr(skb)->protocol = IPPROTO_ICMP;
skb_reserve(skb, MAX_HEADER + sizeof(struct iphdr)); skb_reserve(skb, MAX_HEADER + sizeof(struct iphdr));
src = tb[RTA_SRC] ? nla_get_be32(tb[RTA_SRC]) : 0; src = tb[RTA_SRC] ? nla_get_in_addr(tb[RTA_SRC]) : 0;
dst = tb[RTA_DST] ? nla_get_be32(tb[RTA_DST]) : 0; dst = tb[RTA_DST] ? nla_get_in_addr(tb[RTA_DST]) : 0;
iif = tb[RTA_IIF] ? nla_get_u32(tb[RTA_IIF]) : 0; iif = tb[RTA_IIF] ? nla_get_u32(tb[RTA_IIF]) : 0;
mark = tb[RTA_MARK] ? nla_get_u32(tb[RTA_MARK]) : 0; mark = tb[RTA_MARK] ? nla_get_u32(tb[RTA_MARK]) : 0;

View File

@ -80,17 +80,11 @@ static void tcp_metric_set(struct tcp_metrics_block *tm,
static bool addr_same(const struct inetpeer_addr *a, static bool addr_same(const struct inetpeer_addr *a,
const struct inetpeer_addr *b) const struct inetpeer_addr *b)
{ {
const struct in6_addr *a6, *b6;
if (a->family != b->family) if (a->family != b->family)
return false; return false;
if (a->family == AF_INET) if (a->family == AF_INET)
return a->addr.a4 == b->addr.a4; return a->addr.a4 == b->addr.a4;
return ipv6_addr_equal(&a->addr.in6, &b->addr.in6);
a6 = (const struct in6_addr *) &a->addr.a6[0];
b6 = (const struct in6_addr *) &b->addr.a6[0];
return ipv6_addr_equal(a6, b6);
} }
struct tcpm_hash_bucket { struct tcpm_hash_bucket {
@ -256,8 +250,8 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req,
break; break;
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
case AF_INET6: case AF_INET6:
*(struct in6_addr *)saddr.addr.a6 = inet_rsk(req)->ir_v6_loc_addr; saddr.addr.in6 = inet_rsk(req)->ir_v6_loc_addr;
*(struct in6_addr *)daddr.addr.a6 = inet_rsk(req)->ir_v6_rmt_addr; daddr.addr.in6 = inet_rsk(req)->ir_v6_rmt_addr;
hash = ipv6_addr_hash(&inet_rsk(req)->ir_v6_rmt_addr); hash = ipv6_addr_hash(&inet_rsk(req)->ir_v6_rmt_addr);
break; break;
#endif #endif
@ -304,9 +298,9 @@ static struct tcp_metrics_block *__tcp_get_metrics_tw(struct inet_timewait_sock
hash = (__force unsigned int) daddr.addr.a4; hash = (__force unsigned int) daddr.addr.a4;
} else { } else {
saddr.family = AF_INET6; saddr.family = AF_INET6;
*(struct in6_addr *)saddr.addr.a6 = tw->tw_v6_rcv_saddr; saddr.addr.in6 = tw->tw_v6_rcv_saddr;
daddr.family = AF_INET6; daddr.family = AF_INET6;
*(struct in6_addr *)daddr.addr.a6 = tw->tw_v6_daddr; daddr.addr.in6 = tw->tw_v6_daddr;
hash = ipv6_addr_hash(&tw->tw_v6_daddr); hash = ipv6_addr_hash(&tw->tw_v6_daddr);
} }
} }
@ -354,9 +348,9 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,
hash = (__force unsigned int) daddr.addr.a4; hash = (__force unsigned int) daddr.addr.a4;
} else { } else {
saddr.family = AF_INET6; saddr.family = AF_INET6;
*(struct in6_addr *)saddr.addr.a6 = sk->sk_v6_rcv_saddr; saddr.addr.in6 = sk->sk_v6_rcv_saddr;
daddr.family = AF_INET6; daddr.family = AF_INET6;
*(struct in6_addr *)daddr.addr.a6 = sk->sk_v6_daddr; daddr.addr.in6 = sk->sk_v6_daddr;
hash = ipv6_addr_hash(&sk->sk_v6_daddr); hash = ipv6_addr_hash(&sk->sk_v6_daddr);
} }
} }
@ -792,19 +786,19 @@ static int tcp_metrics_fill_info(struct sk_buff *msg,
switch (tm->tcpm_daddr.family) { switch (tm->tcpm_daddr.family) {
case AF_INET: case AF_INET:
if (nla_put_be32(msg, TCP_METRICS_ATTR_ADDR_IPV4, if (nla_put_in_addr(msg, TCP_METRICS_ATTR_ADDR_IPV4,
tm->tcpm_daddr.addr.a4) < 0) tm->tcpm_daddr.addr.a4) < 0)
goto nla_put_failure; goto nla_put_failure;
if (nla_put_be32(msg, TCP_METRICS_ATTR_SADDR_IPV4, if (nla_put_in_addr(msg, TCP_METRICS_ATTR_SADDR_IPV4,
tm->tcpm_saddr.addr.a4) < 0) tm->tcpm_saddr.addr.a4) < 0)
goto nla_put_failure; goto nla_put_failure;
break; break;
case AF_INET6: case AF_INET6:
if (nla_put(msg, TCP_METRICS_ATTR_ADDR_IPV6, 16, if (nla_put_in6_addr(msg, TCP_METRICS_ATTR_ADDR_IPV6,
tm->tcpm_daddr.addr.a6) < 0) &tm->tcpm_daddr.addr.in6) < 0)
goto nla_put_failure; goto nla_put_failure;
if (nla_put(msg, TCP_METRICS_ATTR_SADDR_IPV6, 16, if (nla_put_in6_addr(msg, TCP_METRICS_ATTR_SADDR_IPV6,
tm->tcpm_saddr.addr.a6) < 0) &tm->tcpm_saddr.addr.in6) < 0)
goto nla_put_failure; goto nla_put_failure;
break; break;
default: default:
@ -954,7 +948,7 @@ static int __parse_nl_addr(struct genl_info *info, struct inetpeer_addr *addr,
a = info->attrs[v4]; a = info->attrs[v4];
if (a) { if (a) {
addr->family = AF_INET; addr->family = AF_INET;
addr->addr.a4 = nla_get_be32(a); addr->addr.a4 = nla_get_in_addr(a);
if (hash) if (hash)
*hash = (__force unsigned int) addr->addr.a4; *hash = (__force unsigned int) addr->addr.a4;
return 0; return 0;
@ -964,9 +958,9 @@ static int __parse_nl_addr(struct genl_info *info, struct inetpeer_addr *addr,
if (nla_len(a) != sizeof(struct in6_addr)) if (nla_len(a) != sizeof(struct in6_addr))
return -EINVAL; return -EINVAL;
addr->family = AF_INET6; addr->family = AF_INET6;
memcpy(addr->addr.a6, nla_data(a), sizeof(addr->addr.a6)); addr->addr.in6 = nla_get_in6_addr(a);
if (hash) if (hash)
*hash = ipv6_addr_hash((struct in6_addr *) addr->addr.a6); *hash = ipv6_addr_hash(&addr->addr.in6);
return 0; return 0;
} }
return optional ? 1 : -EAFNOSUPPORT; return optional ? 1 : -EAFNOSUPPORT;

View File

@ -4237,11 +4237,11 @@ static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
} }
if (!ipv6_addr_any(&ifa->peer_addr)) { if (!ipv6_addr_any(&ifa->peer_addr)) {
if (nla_put(skb, IFA_LOCAL, 16, &ifa->addr) < 0 || if (nla_put_in6_addr(skb, IFA_LOCAL, &ifa->addr) < 0 ||
nla_put(skb, IFA_ADDRESS, 16, &ifa->peer_addr) < 0) nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->peer_addr) < 0)
goto error; goto error;
} else } else
if (nla_put(skb, IFA_ADDRESS, 16, &ifa->addr) < 0) if (nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->addr) < 0)
goto error; goto error;
if (put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0) if (put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0)
@ -4273,7 +4273,7 @@ static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca,
return -EMSGSIZE; return -EMSGSIZE;
put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex); put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
if (nla_put(skb, IFA_MULTICAST, 16, &ifmca->mca_addr) < 0 || if (nla_put_in6_addr(skb, IFA_MULTICAST, &ifmca->mca_addr) < 0 ||
put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp, put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp,
INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) { INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
nlmsg_cancel(skb, nlh); nlmsg_cancel(skb, nlh);
@ -4299,7 +4299,7 @@ static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca,
return -EMSGSIZE; return -EMSGSIZE;
put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex); put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
if (nla_put(skb, IFA_ANYCAST, 16, &ifaca->aca_addr) < 0 || if (nla_put_in6_addr(skb, IFA_ANYCAST, &ifaca->aca_addr) < 0 ||
put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp, put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp,
INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) { INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
nlmsg_cancel(skb, nlh); nlmsg_cancel(skb, nlh);

View File

@ -477,7 +477,7 @@ static int ip6addrlbl_fill(struct sk_buff *skb,
ip6addrlbl_putmsg(nlh, p->prefixlen, p->ifindex, lseq); ip6addrlbl_putmsg(nlh, p->prefixlen, p->ifindex, lseq);
if (nla_put(skb, IFAL_ADDRESS, 16, &p->prefix) < 0 || if (nla_put_in6_addr(skb, IFAL_ADDRESS, &p->prefix) < 0 ||
nla_put_u32(skb, IFAL_LABEL, p->label) < 0) { nla_put_u32(skb, IFAL_LABEL, p->label) < 0) {
nlmsg_cancel(skb, nlh); nlmsg_cancel(skb, nlh);
return -EMSGSIZE; return -EMSGSIZE;

View File

@ -199,12 +199,10 @@ static int fib6_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
} }
if (frh->src_len) if (frh->src_len)
nla_memcpy(&rule6->src.addr, tb[FRA_SRC], rule6->src.addr = nla_get_in6_addr(tb[FRA_SRC]);
sizeof(struct in6_addr));
if (frh->dst_len) if (frh->dst_len)
nla_memcpy(&rule6->dst.addr, tb[FRA_DST], rule6->dst.addr = nla_get_in6_addr(tb[FRA_DST]);
sizeof(struct in6_addr));
rule6->src.plen = frh->src_len; rule6->src.plen = frh->src_len;
rule6->dst.plen = frh->dst_len; rule6->dst.plen = frh->dst_len;
@ -250,11 +248,9 @@ static int fib6_rule_fill(struct fib_rule *rule, struct sk_buff *skb,
frh->tos = rule6->tclass; frh->tos = rule6->tclass;
if ((rule6->dst.plen && if ((rule6->dst.plen &&
nla_put(skb, FRA_DST, sizeof(struct in6_addr), nla_put_in6_addr(skb, FRA_DST, &rule6->dst.addr)) ||
&rule6->dst.addr)) ||
(rule6->src.plen && (rule6->src.plen &&
nla_put(skb, FRA_SRC, sizeof(struct in6_addr), nla_put_in6_addr(skb, FRA_SRC, &rule6->src.addr)))
&rule6->src.addr)))
goto nla_put_failure; goto nla_put_failure;
return 0; return 0;

View File

@ -1412,7 +1412,7 @@ static int ip6gre_tap_validate(struct nlattr *tb[], struct nlattr *data[])
goto out; goto out;
if (data[IFLA_GRE_REMOTE]) { if (data[IFLA_GRE_REMOTE]) {
nla_memcpy(&daddr, data[IFLA_GRE_REMOTE], sizeof(struct in6_addr)); daddr = nla_get_in6_addr(data[IFLA_GRE_REMOTE]);
if (ipv6_addr_any(&daddr)) if (ipv6_addr_any(&daddr))
return -EINVAL; return -EINVAL;
} }
@ -1446,10 +1446,10 @@ static void ip6gre_netlink_parms(struct nlattr *data[],
parms->o_key = nla_get_be32(data[IFLA_GRE_OKEY]); parms->o_key = nla_get_be32(data[IFLA_GRE_OKEY]);
if (data[IFLA_GRE_LOCAL]) if (data[IFLA_GRE_LOCAL])
nla_memcpy(&parms->laddr, data[IFLA_GRE_LOCAL], sizeof(struct in6_addr)); parms->laddr = nla_get_in6_addr(data[IFLA_GRE_LOCAL]);
if (data[IFLA_GRE_REMOTE]) if (data[IFLA_GRE_REMOTE])
nla_memcpy(&parms->raddr, data[IFLA_GRE_REMOTE], sizeof(struct in6_addr)); parms->raddr = nla_get_in6_addr(data[IFLA_GRE_REMOTE]);
if (data[IFLA_GRE_TTL]) if (data[IFLA_GRE_TTL])
parms->hop_limit = nla_get_u8(data[IFLA_GRE_TTL]); parms->hop_limit = nla_get_u8(data[IFLA_GRE_TTL]);
@ -1622,8 +1622,8 @@ static int ip6gre_fill_info(struct sk_buff *skb, const struct net_device *dev)
nla_put_be16(skb, IFLA_GRE_OFLAGS, p->o_flags) || nla_put_be16(skb, IFLA_GRE_OFLAGS, p->o_flags) ||
nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) || nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) ||
nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) || nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) ||
nla_put(skb, IFLA_GRE_LOCAL, sizeof(struct in6_addr), &p->laddr) || nla_put_in6_addr(skb, IFLA_GRE_LOCAL, &p->laddr) ||
nla_put(skb, IFLA_GRE_REMOTE, sizeof(struct in6_addr), &p->raddr) || nla_put_in6_addr(skb, IFLA_GRE_REMOTE, &p->raddr) ||
nla_put_u8(skb, IFLA_GRE_TTL, p->hop_limit) || nla_put_u8(skb, IFLA_GRE_TTL, p->hop_limit) ||
/*nla_put_u8(skb, IFLA_GRE_TOS, t->priority) ||*/ /*nla_put_u8(skb, IFLA_GRE_TOS, t->priority) ||*/
nla_put_u8(skb, IFLA_GRE_ENCAP_LIMIT, p->encap_limit) || nla_put_u8(skb, IFLA_GRE_ENCAP_LIMIT, p->encap_limit) ||

View File

@ -1640,12 +1640,10 @@ static void ip6_tnl_netlink_parms(struct nlattr *data[],
parms->link = nla_get_u32(data[IFLA_IPTUN_LINK]); parms->link = nla_get_u32(data[IFLA_IPTUN_LINK]);
if (data[IFLA_IPTUN_LOCAL]) if (data[IFLA_IPTUN_LOCAL])
nla_memcpy(&parms->laddr, data[IFLA_IPTUN_LOCAL], parms->laddr = nla_get_in6_addr(data[IFLA_IPTUN_LOCAL]);
sizeof(struct in6_addr));
if (data[IFLA_IPTUN_REMOTE]) if (data[IFLA_IPTUN_REMOTE])
nla_memcpy(&parms->raddr, data[IFLA_IPTUN_REMOTE], parms->raddr = nla_get_in6_addr(data[IFLA_IPTUN_REMOTE]);
sizeof(struct in6_addr));
if (data[IFLA_IPTUN_TTL]) if (data[IFLA_IPTUN_TTL])
parms->hop_limit = nla_get_u8(data[IFLA_IPTUN_TTL]); parms->hop_limit = nla_get_u8(data[IFLA_IPTUN_TTL]);
@ -1739,10 +1737,8 @@ static int ip6_tnl_fill_info(struct sk_buff *skb, const struct net_device *dev)
struct __ip6_tnl_parm *parm = &tunnel->parms; struct __ip6_tnl_parm *parm = &tunnel->parms;
if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) ||
nla_put(skb, IFLA_IPTUN_LOCAL, sizeof(struct in6_addr), nla_put_in6_addr(skb, IFLA_IPTUN_LOCAL, &parm->laddr) ||
&parm->laddr) || nla_put_in6_addr(skb, IFLA_IPTUN_REMOTE, &parm->raddr) ||
nla_put(skb, IFLA_IPTUN_REMOTE, sizeof(struct in6_addr),
&parm->raddr) ||
nla_put_u8(skb, IFLA_IPTUN_TTL, parm->hop_limit) || nla_put_u8(skb, IFLA_IPTUN_TTL, parm->hop_limit) ||
nla_put_u8(skb, IFLA_IPTUN_ENCAP_LIMIT, parm->encap_limit) || nla_put_u8(skb, IFLA_IPTUN_ENCAP_LIMIT, parm->encap_limit) ||
nla_put_be32(skb, IFLA_IPTUN_FLOWINFO, parm->flowinfo) || nla_put_be32(skb, IFLA_IPTUN_FLOWINFO, parm->flowinfo) ||

View File

@ -897,12 +897,10 @@ static void vti6_netlink_parms(struct nlattr *data[],
parms->link = nla_get_u32(data[IFLA_VTI_LINK]); parms->link = nla_get_u32(data[IFLA_VTI_LINK]);
if (data[IFLA_VTI_LOCAL]) if (data[IFLA_VTI_LOCAL])
nla_memcpy(&parms->laddr, data[IFLA_VTI_LOCAL], parms->laddr = nla_get_in6_addr(data[IFLA_VTI_LOCAL]);
sizeof(struct in6_addr));
if (data[IFLA_VTI_REMOTE]) if (data[IFLA_VTI_REMOTE])
nla_memcpy(&parms->raddr, data[IFLA_VTI_REMOTE], parms->raddr = nla_get_in6_addr(data[IFLA_VTI_REMOTE]);
sizeof(struct in6_addr));
if (data[IFLA_VTI_IKEY]) if (data[IFLA_VTI_IKEY])
parms->i_key = nla_get_be32(data[IFLA_VTI_IKEY]); parms->i_key = nla_get_be32(data[IFLA_VTI_IKEY]);
@ -983,10 +981,8 @@ static int vti6_fill_info(struct sk_buff *skb, const struct net_device *dev)
struct __ip6_tnl_parm *parm = &tunnel->parms; struct __ip6_tnl_parm *parm = &tunnel->parms;
if (nla_put_u32(skb, IFLA_VTI_LINK, parm->link) || if (nla_put_u32(skb, IFLA_VTI_LINK, parm->link) ||
nla_put(skb, IFLA_VTI_LOCAL, sizeof(struct in6_addr), nla_put_in6_addr(skb, IFLA_VTI_LOCAL, &parm->laddr) ||
&parm->laddr) || nla_put_in6_addr(skb, IFLA_VTI_REMOTE, &parm->raddr) ||
nla_put(skb, IFLA_VTI_REMOTE, sizeof(struct in6_addr),
&parm->raddr) ||
nla_put_be32(skb, IFLA_VTI_IKEY, parm->i_key) || nla_put_be32(skb, IFLA_VTI_IKEY, parm->i_key) ||
nla_put_be32(skb, IFLA_VTI_OKEY, parm->o_key)) nla_put_be32(skb, IFLA_VTI_OKEY, parm->o_key))
goto nla_put_failure; goto nla_put_failure;

View File

@ -2378,8 +2378,8 @@ static int ip6mr_fill_mroute(struct mr6_table *mrt, struct sk_buff *skb,
rtm->rtm_protocol = RTPROT_MROUTED; rtm->rtm_protocol = RTPROT_MROUTED;
rtm->rtm_flags = 0; rtm->rtm_flags = 0;
if (nla_put(skb, RTA_SRC, 16, &c->mf6c_origin) || if (nla_put_in6_addr(skb, RTA_SRC, &c->mf6c_origin) ||
nla_put(skb, RTA_DST, 16, &c->mf6c_mcastgrp)) nla_put_in6_addr(skb, RTA_DST, &c->mf6c_mcastgrp))
goto nla_put_failure; goto nla_put_failure;
err = __ip6mr_fill_mroute(mrt, skb, c, rtm); err = __ip6mr_fill_mroute(mrt, skb, c, rtm);
/* do not break the dump if cache is unresolved */ /* do not break the dump if cache is unresolved */

View File

@ -1049,8 +1049,7 @@ static void ndisc_ra_useropt(struct sk_buff *ra, struct nd_opt_hdr *opt)
memcpy(ndmsg + 1, opt, opt->nd_opt_len << 3); memcpy(ndmsg + 1, opt, opt->nd_opt_len << 3);
if (nla_put(skb, NDUSEROPT_SRCADDR, sizeof(struct in6_addr), if (nla_put_in6_addr(skb, NDUSEROPT_SRCADDR, &ipv6_hdr(ra)->saddr))
&ipv6_hdr(ra)->saddr))
goto nla_put_failure; goto nla_put_failure;
nlmsg_end(skb, nlh); nlmsg_end(skb, nlh);

View File

@ -290,10 +290,8 @@ ipv6_getorigdst(struct sock *sk, int optval, void __user *user, int *len)
static int ipv6_tuple_to_nlattr(struct sk_buff *skb, static int ipv6_tuple_to_nlattr(struct sk_buff *skb,
const struct nf_conntrack_tuple *tuple) const struct nf_conntrack_tuple *tuple)
{ {
if (nla_put(skb, CTA_IP_V6_SRC, sizeof(u_int32_t) * 4, if (nla_put_in6_addr(skb, CTA_IP_V6_SRC, &tuple->src.u3.in6) ||
&tuple->src.u3.ip6) || nla_put_in6_addr(skb, CTA_IP_V6_DST, &tuple->dst.u3.in6))
nla_put(skb, CTA_IP_V6_DST, sizeof(u_int32_t) * 4,
&tuple->dst.u3.ip6))
goto nla_put_failure; goto nla_put_failure;
return 0; return 0;
@ -312,10 +310,8 @@ static int ipv6_nlattr_to_tuple(struct nlattr *tb[],
if (!tb[CTA_IP_V6_SRC] || !tb[CTA_IP_V6_DST]) if (!tb[CTA_IP_V6_SRC] || !tb[CTA_IP_V6_DST])
return -EINVAL; return -EINVAL;
memcpy(&t->src.u3.ip6, nla_data(tb[CTA_IP_V6_SRC]), t->src.u3.in6 = nla_get_in6_addr(tb[CTA_IP_V6_SRC]);
sizeof(u_int32_t) * 4); t->dst.u3.in6 = nla_get_in6_addr(tb[CTA_IP_V6_DST]);
memcpy(&t->dst.u3.ip6, nla_data(tb[CTA_IP_V6_DST]),
sizeof(u_int32_t) * 4);
return 0; return 0;
} }

View File

@ -2438,7 +2438,7 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
cfg->fc_nlinfo.nl_net = sock_net(skb->sk); cfg->fc_nlinfo.nl_net = sock_net(skb->sk);
if (tb[RTA_GATEWAY]) { if (tb[RTA_GATEWAY]) {
nla_memcpy(&cfg->fc_gateway, tb[RTA_GATEWAY], 16); cfg->fc_gateway = nla_get_in6_addr(tb[RTA_GATEWAY]);
cfg->fc_flags |= RTF_GATEWAY; cfg->fc_flags |= RTF_GATEWAY;
} }
@ -2461,7 +2461,7 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
} }
if (tb[RTA_PREFSRC]) if (tb[RTA_PREFSRC])
nla_memcpy(&cfg->fc_prefsrc, tb[RTA_PREFSRC], 16); cfg->fc_prefsrc = nla_get_in6_addr(tb[RTA_PREFSRC]);
if (tb[RTA_OIF]) if (tb[RTA_OIF])
cfg->fc_ifindex = nla_get_u32(tb[RTA_OIF]); cfg->fc_ifindex = nla_get_u32(tb[RTA_OIF]);
@ -2519,7 +2519,7 @@ beginning:
nla = nla_find(attrs, attrlen, RTA_GATEWAY); nla = nla_find(attrs, attrlen, RTA_GATEWAY);
if (nla) { if (nla) {
nla_memcpy(&r_cfg.fc_gateway, nla, 16); r_cfg.fc_gateway = nla_get_in6_addr(nla);
r_cfg.fc_flags |= RTF_GATEWAY; r_cfg.fc_flags |= RTF_GATEWAY;
} }
} }
@ -2669,19 +2669,19 @@ static int rt6_fill_node(struct net *net,
rtm->rtm_flags |= RTM_F_CLONED; rtm->rtm_flags |= RTM_F_CLONED;
if (dst) { if (dst) {
if (nla_put(skb, RTA_DST, 16, dst)) if (nla_put_in6_addr(skb, RTA_DST, dst))
goto nla_put_failure; goto nla_put_failure;
rtm->rtm_dst_len = 128; rtm->rtm_dst_len = 128;
} else if (rtm->rtm_dst_len) } else if (rtm->rtm_dst_len)
if (nla_put(skb, RTA_DST, 16, &rt->rt6i_dst.addr)) if (nla_put_in6_addr(skb, RTA_DST, &rt->rt6i_dst.addr))
goto nla_put_failure; goto nla_put_failure;
#ifdef CONFIG_IPV6_SUBTREES #ifdef CONFIG_IPV6_SUBTREES
if (src) { if (src) {
if (nla_put(skb, RTA_SRC, 16, src)) if (nla_put_in6_addr(skb, RTA_SRC, src))
goto nla_put_failure; goto nla_put_failure;
rtm->rtm_src_len = 128; rtm->rtm_src_len = 128;
} else if (rtm->rtm_src_len && } else if (rtm->rtm_src_len &&
nla_put(skb, RTA_SRC, 16, &rt->rt6i_src.addr)) nla_put_in6_addr(skb, RTA_SRC, &rt->rt6i_src.addr))
goto nla_put_failure; goto nla_put_failure;
#endif #endif
if (iif) { if (iif) {
@ -2705,14 +2705,14 @@ static int rt6_fill_node(struct net *net,
} else if (dst) { } else if (dst) {
struct in6_addr saddr_buf; struct in6_addr saddr_buf;
if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 && if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
nla_put(skb, RTA_PREFSRC, 16, &saddr_buf)) nla_put_in6_addr(skb, RTA_PREFSRC, &saddr_buf))
goto nla_put_failure; goto nla_put_failure;
} }
if (rt->rt6i_prefsrc.plen) { if (rt->rt6i_prefsrc.plen) {
struct in6_addr saddr_buf; struct in6_addr saddr_buf;
saddr_buf = rt->rt6i_prefsrc.addr; saddr_buf = rt->rt6i_prefsrc.addr;
if (nla_put(skb, RTA_PREFSRC, 16, &saddr_buf)) if (nla_put_in6_addr(skb, RTA_PREFSRC, &saddr_buf))
goto nla_put_failure; goto nla_put_failure;
} }
@ -2720,7 +2720,7 @@ static int rt6_fill_node(struct net *net,
goto nla_put_failure; goto nla_put_failure;
if (rt->rt6i_flags & RTF_GATEWAY) { if (rt->rt6i_flags & RTF_GATEWAY) {
if (nla_put(skb, RTA_GATEWAY, 16, &rt->rt6i_gateway) < 0) if (nla_put_in6_addr(skb, RTA_GATEWAY, &rt->rt6i_gateway) < 0)
goto nla_put_failure; goto nla_put_failure;
} }

View File

@ -1530,8 +1530,7 @@ static bool ipip6_netlink_6rd_parms(struct nlattr *data[],
if (data[IFLA_IPTUN_6RD_PREFIX]) { if (data[IFLA_IPTUN_6RD_PREFIX]) {
ret = true; ret = true;
nla_memcpy(&ip6rd->prefix, data[IFLA_IPTUN_6RD_PREFIX], ip6rd->prefix = nla_get_in6_addr(data[IFLA_IPTUN_6RD_PREFIX]);
sizeof(struct in6_addr));
} }
if (data[IFLA_IPTUN_6RD_RELAY_PREFIX]) { if (data[IFLA_IPTUN_6RD_RELAY_PREFIX]) {
@ -1683,8 +1682,8 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev)
struct ip_tunnel_parm *parm = &tunnel->parms; struct ip_tunnel_parm *parm = &tunnel->parms;
if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) ||
nla_put_be32(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) || nla_put_in_addr(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) ||
nla_put_be32(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) || nla_put_in_addr(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) ||
nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) || nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) ||
nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos) || nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos) ||
nla_put_u8(skb, IFLA_IPTUN_PMTUDISC, nla_put_u8(skb, IFLA_IPTUN_PMTUDISC,
@ -1694,10 +1693,10 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev)
goto nla_put_failure; goto nla_put_failure;
#ifdef CONFIG_IPV6_SIT_6RD #ifdef CONFIG_IPV6_SIT_6RD
if (nla_put(skb, IFLA_IPTUN_6RD_PREFIX, sizeof(struct in6_addr), if (nla_put_in6_addr(skb, IFLA_IPTUN_6RD_PREFIX,
&tunnel->ip6rd.prefix) || &tunnel->ip6rd.prefix) ||
nla_put_be32(skb, IFLA_IPTUN_6RD_RELAY_PREFIX, nla_put_in_addr(skb, IFLA_IPTUN_6RD_RELAY_PREFIX,
tunnel->ip6rd.relay_prefix) || tunnel->ip6rd.relay_prefix) ||
nla_put_u16(skb, IFLA_IPTUN_6RD_PREFIXLEN, nla_put_u16(skb, IFLA_IPTUN_6RD_PREFIXLEN,
tunnel->ip6rd.prefixlen) || tunnel->ip6rd.prefixlen) ||
nla_put_u16(skb, IFLA_IPTUN_6RD_RELAY_PREFIXLEN, nla_put_u16(skb, IFLA_IPTUN_6RD_RELAY_PREFIXLEN,

View File

@ -95,8 +95,8 @@ static int xfrm6_beet_input(struct xfrm_state *x, struct sk_buff *skb)
ip6h = ipv6_hdr(skb); ip6h = ipv6_hdr(skb);
ip6h->payload_len = htons(skb->len - size); ip6h->payload_len = htons(skb->len - size);
ip6h->daddr = *(struct in6_addr *)&x->sel.daddr.a6; ip6h->daddr = x->sel.daddr.in6;
ip6h->saddr = *(struct in6_addr *)&x->sel.saddr.a6; ip6h->saddr = x->sel.saddr.in6;
err = 0; err = 0;
out: out:
return err; return err;

View File

@ -61,9 +61,7 @@ static int xfrm6_get_saddr(struct net *net,
return -EHOSTUNREACH; return -EHOSTUNREACH;
dev = ip6_dst_idev(dst)->dev; dev = ip6_dst_idev(dst)->dev;
ipv6_dev_get_saddr(dev_net(dev), dev, ipv6_dev_get_saddr(dev_net(dev), dev, &daddr->in6, 0, &saddr->in6);
(struct in6_addr *)&daddr->a6, 0,
(struct in6_addr *)&saddr->a6);
dst_release(dst); dst_release(dst);
return 0; return 0;
} }

View File

@ -709,7 +709,7 @@ static unsigned int pfkey_sockaddr_fill(const xfrm_address_t *xaddr, __be16 port
sin6->sin6_family = AF_INET6; sin6->sin6_family = AF_INET6;
sin6->sin6_port = port; sin6->sin6_port = port;
sin6->sin6_flowinfo = 0; sin6->sin6_flowinfo = 0;
sin6->sin6_addr = *(struct in6_addr *)xaddr->a6; sin6->sin6_addr = xaddr->in6;
sin6->sin6_scope_id = 0; sin6->sin6_scope_id = 0;
return 128; return 128;
} }

View File

@ -205,9 +205,9 @@ static int l2tp_nl_cmd_tunnel_create(struct sk_buff *skb, struct genl_info *info
#endif #endif
if (info->attrs[L2TP_ATTR_IP_SADDR] && if (info->attrs[L2TP_ATTR_IP_SADDR] &&
info->attrs[L2TP_ATTR_IP_DADDR]) { info->attrs[L2TP_ATTR_IP_DADDR]) {
cfg.local_ip.s_addr = nla_get_be32( cfg.local_ip.s_addr = nla_get_in_addr(
info->attrs[L2TP_ATTR_IP_SADDR]); info->attrs[L2TP_ATTR_IP_SADDR]);
cfg.peer_ip.s_addr = nla_get_be32( cfg.peer_ip.s_addr = nla_get_in_addr(
info->attrs[L2TP_ATTR_IP_DADDR]); info->attrs[L2TP_ATTR_IP_DADDR]);
} else { } else {
ret = -EINVAL; ret = -EINVAL;
@ -376,15 +376,17 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int fla
case L2TP_ENCAPTYPE_IP: case L2TP_ENCAPTYPE_IP:
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
if (np) { if (np) {
if (nla_put(skb, L2TP_ATTR_IP6_SADDR, sizeof(np->saddr), if (nla_put_in6_addr(skb, L2TP_ATTR_IP6_SADDR,
&np->saddr) || &np->saddr) ||
nla_put(skb, L2TP_ATTR_IP6_DADDR, sizeof(sk->sk_v6_daddr), nla_put_in6_addr(skb, L2TP_ATTR_IP6_DADDR,
&sk->sk_v6_daddr)) &sk->sk_v6_daddr))
goto nla_put_failure; goto nla_put_failure;
} else } else
#endif #endif
if (nla_put_be32(skb, L2TP_ATTR_IP_SADDR, inet->inet_saddr) || if (nla_put_in_addr(skb, L2TP_ATTR_IP_SADDR,
nla_put_be32(skb, L2TP_ATTR_IP_DADDR, inet->inet_daddr)) inet->inet_saddr) ||
nla_put_in_addr(skb, L2TP_ATTR_IP_DADDR,
inet->inet_daddr))
goto nla_put_failure; goto nla_put_failure;
break; break;
} }

View File

@ -293,15 +293,13 @@ static int netlbl_mgmt_listentry(struct sk_buff *skb,
return -ENOMEM; return -ENOMEM;
addr_struct.s_addr = iter4->addr; addr_struct.s_addr = iter4->addr;
ret_val = nla_put(skb, NLBL_MGMT_A_IPV4ADDR, ret_val = nla_put_in_addr(skb, NLBL_MGMT_A_IPV4ADDR,
sizeof(struct in_addr), addr_struct.s_addr);
&addr_struct);
if (ret_val != 0) if (ret_val != 0)
return ret_val; return ret_val;
addr_struct.s_addr = iter4->mask; addr_struct.s_addr = iter4->mask;
ret_val = nla_put(skb, NLBL_MGMT_A_IPV4MASK, ret_val = nla_put_in_addr(skb, NLBL_MGMT_A_IPV4MASK,
sizeof(struct in_addr), addr_struct.s_addr);
&addr_struct);
if (ret_val != 0) if (ret_val != 0)
return ret_val; return ret_val;
map4 = netlbl_domhsh_addr4_entry(iter4); map4 = netlbl_domhsh_addr4_entry(iter4);
@ -328,14 +326,12 @@ static int netlbl_mgmt_listentry(struct sk_buff *skb,
if (nla_b == NULL) if (nla_b == NULL)
return -ENOMEM; return -ENOMEM;
ret_val = nla_put(skb, NLBL_MGMT_A_IPV6ADDR, ret_val = nla_put_in6_addr(skb, NLBL_MGMT_A_IPV6ADDR,
sizeof(struct in6_addr), &iter6->addr);
&iter6->addr);
if (ret_val != 0) if (ret_val != 0)
return ret_val; return ret_val;
ret_val = nla_put(skb, NLBL_MGMT_A_IPV6MASK, ret_val = nla_put_in6_addr(skb, NLBL_MGMT_A_IPV6MASK,
sizeof(struct in6_addr), &iter6->mask);
&iter6->mask);
if (ret_val != 0) if (ret_val != 0)
return ret_val; return ret_val;
map6 = netlbl_domhsh_addr6_entry(iter6); map6 = netlbl_domhsh_addr6_entry(iter6);

View File

@ -1117,34 +1117,30 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd,
struct in_addr addr_struct; struct in_addr addr_struct;
addr_struct.s_addr = addr4->list.addr; addr_struct.s_addr = addr4->list.addr;
ret_val = nla_put(cb_arg->skb, ret_val = nla_put_in_addr(cb_arg->skb,
NLBL_UNLABEL_A_IPV4ADDR, NLBL_UNLABEL_A_IPV4ADDR,
sizeof(struct in_addr), addr_struct.s_addr);
&addr_struct);
if (ret_val != 0) if (ret_val != 0)
goto list_cb_failure; goto list_cb_failure;
addr_struct.s_addr = addr4->list.mask; addr_struct.s_addr = addr4->list.mask;
ret_val = nla_put(cb_arg->skb, ret_val = nla_put_in_addr(cb_arg->skb,
NLBL_UNLABEL_A_IPV4MASK, NLBL_UNLABEL_A_IPV4MASK,
sizeof(struct in_addr), addr_struct.s_addr);
&addr_struct);
if (ret_val != 0) if (ret_val != 0)
goto list_cb_failure; goto list_cb_failure;
secid = addr4->secid; secid = addr4->secid;
} else { } else {
ret_val = nla_put(cb_arg->skb, ret_val = nla_put_in6_addr(cb_arg->skb,
NLBL_UNLABEL_A_IPV6ADDR, NLBL_UNLABEL_A_IPV6ADDR,
sizeof(struct in6_addr), &addr6->list.addr);
&addr6->list.addr);
if (ret_val != 0) if (ret_val != 0)
goto list_cb_failure; goto list_cb_failure;
ret_val = nla_put(cb_arg->skb, ret_val = nla_put_in6_addr(cb_arg->skb,
NLBL_UNLABEL_A_IPV6MASK, NLBL_UNLABEL_A_IPV6MASK,
sizeof(struct in6_addr), &addr6->list.mask);
&addr6->list.mask);
if (ret_val != 0) if (ret_val != 0)
goto list_cb_failure; goto list_cb_failure;

View File

@ -535,11 +535,11 @@ static int ipv4_tun_from_nlattr(const struct nlattr *attr,
break; break;
case OVS_TUNNEL_KEY_ATTR_IPV4_SRC: case OVS_TUNNEL_KEY_ATTR_IPV4_SRC:
SW_FLOW_KEY_PUT(match, tun_key.ipv4_src, SW_FLOW_KEY_PUT(match, tun_key.ipv4_src,
nla_get_be32(a), is_mask); nla_get_in_addr(a), is_mask);
break; break;
case OVS_TUNNEL_KEY_ATTR_IPV4_DST: case OVS_TUNNEL_KEY_ATTR_IPV4_DST:
SW_FLOW_KEY_PUT(match, tun_key.ipv4_dst, SW_FLOW_KEY_PUT(match, tun_key.ipv4_dst,
nla_get_be32(a), is_mask); nla_get_in_addr(a), is_mask);
break; break;
case OVS_TUNNEL_KEY_ATTR_TOS: case OVS_TUNNEL_KEY_ATTR_TOS:
SW_FLOW_KEY_PUT(match, tun_key.ipv4_tos, SW_FLOW_KEY_PUT(match, tun_key.ipv4_tos,
@ -648,10 +648,12 @@ static int __ipv4_tun_to_nlattr(struct sk_buff *skb,
nla_put_be64(skb, OVS_TUNNEL_KEY_ATTR_ID, output->tun_id)) nla_put_be64(skb, OVS_TUNNEL_KEY_ATTR_ID, output->tun_id))
return -EMSGSIZE; return -EMSGSIZE;
if (output->ipv4_src && if (output->ipv4_src &&
nla_put_be32(skb, OVS_TUNNEL_KEY_ATTR_IPV4_SRC, output->ipv4_src)) nla_put_in_addr(skb, OVS_TUNNEL_KEY_ATTR_IPV4_SRC,
output->ipv4_src))
return -EMSGSIZE; return -EMSGSIZE;
if (output->ipv4_dst && if (output->ipv4_dst &&
nla_put_be32(skb, OVS_TUNNEL_KEY_ATTR_IPV4_DST, output->ipv4_dst)) nla_put_in_addr(skb, OVS_TUNNEL_KEY_ATTR_IPV4_DST,
output->ipv4_dst))
return -EMSGSIZE; return -EMSGSIZE;
if (output->ipv4_tos && if (output->ipv4_tos &&
nla_put_u8(skb, OVS_TUNNEL_KEY_ATTR_TOS, output->ipv4_tos)) nla_put_u8(skb, OVS_TUNNEL_KEY_ATTR_TOS, output->ipv4_tos))

View File

@ -8761,8 +8761,8 @@ static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
if (!nl_tcp) if (!nl_tcp)
return -ENOBUFS; return -ENOBUFS;
if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
@ -8993,8 +8993,8 @@ static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
cfg = kzalloc(size, GFP_KERNEL); cfg = kzalloc(size, GFP_KERNEL);
if (!cfg) if (!cfg)
return -ENOMEM; return -ENOMEM;
cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
ETH_ALEN); ETH_ALEN);
if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) if (tb[NL80211_WOWLAN_TCP_SRC_PORT])

View File

@ -1043,12 +1043,12 @@ static struct xfrm_state *__find_acq_core(struct net *net,
break; break;
case AF_INET6: case AF_INET6:
*(struct in6_addr *)x->sel.daddr.a6 = *(struct in6_addr *)daddr; x->sel.daddr.in6 = daddr->in6;
*(struct in6_addr *)x->sel.saddr.a6 = *(struct in6_addr *)saddr; x->sel.saddr.in6 = saddr->in6;
x->sel.prefixlen_d = 128; x->sel.prefixlen_d = 128;
x->sel.prefixlen_s = 128; x->sel.prefixlen_s = 128;
*(struct in6_addr *)x->props.saddr.a6 = *(struct in6_addr *)saddr; x->props.saddr.in6 = saddr->in6;
*(struct in6_addr *)x->id.daddr.a6 = *(struct in6_addr *)daddr; x->id.daddr.in6 = daddr->in6;
break; break;
} }