netlink: implement nla_get_in_addr and nla_get_in6_addr
authorJiri Benc <jbenc@redhat.com>
Sun, 29 Mar 2015 14:59:26 +0000 (16:59 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 31 Mar 2015 17:58:35 +0000 (13:58 -0400)
Those are counterparts to nla_put_in_addr and nla_put_in6_addr.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
21 files changed:
drivers/net/vxlan.c
include/net/netlink.h
net/ipv4/devinet.c
net/ipv4/fib_rules.c
net/ipv4/fib_semantics.c
net/ipv4/ip_gre.c
net/ipv4/ip_vti.c
net/ipv4/ipip.c
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
net/ipv4/route.c
net/ipv4/tcp_metrics.c
net/ipv6/fib6_rules.c
net/ipv6/ip6_gre.c
net/ipv6/ip6_tunnel.c
net/ipv6/ip6_vti.c
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
net/ipv6/route.c
net/ipv6/sit.c
net/l2tp/l2tp_netlink.c
net/openvswitch/flow_netlink.c
net/wireless/nl80211.c

index 86f085f..a8d3450 100644 (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)
 {
        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;
                return 0;
        } 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;
                return 0;
        } else {
@@ -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)) {
                return -EAFNOSUPPORT;
        } 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;
                return 0;
        } else {
@@ -2602,27 +2602,25 @@ static int vxlan_newlink(struct net *src_net, struct net_device *dev,
        /* Unless IPv6 is explicitly requested, assume IPv4 */
        dst->remote_ip.sa.sa_family = AF_INET;
        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]) {
                if (!IS_ENABLED(CONFIG_IPV6))
                        return -EPFNOSUPPORT;
 
-               nla_memcpy(&dst->remote_ip.sin6.sin6_addr, data[IFLA_VXLAN_GROUP6],
-                          sizeof(struct in6_addr));
+               dst->remote_ip.sin6.sin6_addr = nla_get_in6_addr(data[IFLA_VXLAN_GROUP6]);
                dst->remote_ip.sa.sa_family = AF_INET6;
                use_ipv6 = true;
        }
 
        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;
        } else if (data[IFLA_VXLAN_LOCAL6]) {
                if (!IS_ENABLED(CONFIG_IPV6))
                        return -EPFNOSUPPORT;
 
                /* TODO: respect scope id */
-               nla_memcpy(&vxlan->saddr.sin6.sin6_addr, data[IFLA_VXLAN_LOCAL6],
-                          sizeof(struct in6_addr));
+               vxlan->saddr.sin6.sin6_addr = nla_get_in6_addr(data[IFLA_VXLAN_LOCAL6]);
                vxlan->saddr.sa.sa_family = AF_INET6;
                use_ipv6 = true;
        }
index 17fc76e..2a5dbcc 100644 (file)
@@ -1127,6 +1127,27 @@ static inline unsigned long nla_get_msecs(const struct nlattr *nla)
        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
  * @skb: socket buffer to add attributes to
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc net/ipv4/ipip.c
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc net/ipv6/sit.c
Simple merge
Simple merge
Simple merge
Simple merge