aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6
diff options
context:
space:
mode:
authorJiri Benc <jbenc@redhat.com>2015-03-29 10:59:25 -0400
committerDavid S. Miller <davem@davemloft.net>2015-03-31 13:58:35 -0400
commit930345ea630405aa6e6f42efcb149c3f360a6b67 (patch)
treec88d0858785c246038fddac3ca51571b371416b0 /net/ipv6
parent15e318bdc6dfb82914c82fb7ad00badaa8387d8e (diff)
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>
Diffstat (limited to 'net/ipv6')
-rw-r--r--net/ipv6/addrconf.c10
-rw-r--r--net/ipv6/addrlabel.c2
-rw-r--r--net/ipv6/fib6_rules.c6
-rw-r--r--net/ipv6/ip6_gre.c4
-rw-r--r--net/ipv6/ip6_tunnel.c6
-rw-r--r--net/ipv6/ip6_vti.c6
-rw-r--r--net/ipv6/ip6mr.c4
-rw-r--r--net/ipv6/ndisc.c3
-rw-r--r--net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c6
-rw-r--r--net/ipv6/route.c14
-rw-r--r--net/ipv6/sit.c12
11 files changed, 32 insertions, 41 deletions
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index e86f7434e3c3..5c9e94cb1b2c 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -4237,11 +4237,11 @@ static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
4237 } 4237 }
4238 4238
4239 if (!ipv6_addr_any(&ifa->peer_addr)) { 4239 if (!ipv6_addr_any(&ifa->peer_addr)) {
4240 if (nla_put(skb, IFA_LOCAL, 16, &ifa->addr) < 0 || 4240 if (nla_put_in6_addr(skb, IFA_LOCAL, &ifa->addr) < 0 ||
4241 nla_put(skb, IFA_ADDRESS, 16, &ifa->peer_addr) < 0) 4241 nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->peer_addr) < 0)
4242 goto error; 4242 goto error;
4243 } else 4243 } else
4244 if (nla_put(skb, IFA_ADDRESS, 16, &ifa->addr) < 0) 4244 if (nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->addr) < 0)
4245 goto error; 4245 goto error;
4246 4246
4247 if (put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0) 4247 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,
4273 return -EMSGSIZE; 4273 return -EMSGSIZE;
4274 4274
4275 put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex); 4275 put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
4276 if (nla_put(skb, IFA_MULTICAST, 16, &ifmca->mca_addr) < 0 || 4276 if (nla_put_in6_addr(skb, IFA_MULTICAST, &ifmca->mca_addr) < 0 ||
4277 put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp, 4277 put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp,
4278 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) { 4278 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
4279 nlmsg_cancel(skb, nlh); 4279 nlmsg_cancel(skb, nlh);
@@ -4299,7 +4299,7 @@ static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca,
4299 return -EMSGSIZE; 4299 return -EMSGSIZE;
4300 4300
4301 put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex); 4301 put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
4302 if (nla_put(skb, IFA_ANYCAST, 16, &ifaca->aca_addr) < 0 || 4302 if (nla_put_in6_addr(skb, IFA_ANYCAST, &ifaca->aca_addr) < 0 ||
4303 put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp, 4303 put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp,
4304 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) { 4304 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
4305 nlmsg_cancel(skb, nlh); 4305 nlmsg_cancel(skb, nlh);
diff --git a/net/ipv6/addrlabel.c b/net/ipv6/addrlabel.c
index 3cc50e2d3bf5..882124ebb438 100644
--- a/net/ipv6/addrlabel.c
+++ b/net/ipv6/addrlabel.c
@@ -477,7 +477,7 @@ static int ip6addrlbl_fill(struct sk_buff *skb,
477 477
478 ip6addrlbl_putmsg(nlh, p->prefixlen, p->ifindex, lseq); 478 ip6addrlbl_putmsg(nlh, p->prefixlen, p->ifindex, lseq);
479 479
480 if (nla_put(skb, IFAL_ADDRESS, 16, &p->prefix) < 0 || 480 if (nla_put_in6_addr(skb, IFAL_ADDRESS, &p->prefix) < 0 ||
481 nla_put_u32(skb, IFAL_LABEL, p->label) < 0) { 481 nla_put_u32(skb, IFAL_LABEL, p->label) < 0) {
482 nlmsg_cancel(skb, nlh); 482 nlmsg_cancel(skb, nlh);
483 return -EMSGSIZE; 483 return -EMSGSIZE;
diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c
index 273eb26cd6d4..d313bfd88512 100644
--- a/net/ipv6/fib6_rules.c
+++ b/net/ipv6/fib6_rules.c
@@ -250,11 +250,9 @@ static int fib6_rule_fill(struct fib_rule *rule, struct sk_buff *skb,
250 frh->tos = rule6->tclass; 250 frh->tos = rule6->tclass;
251 251
252 if ((rule6->dst.plen && 252 if ((rule6->dst.plen &&
253 nla_put(skb, FRA_DST, sizeof(struct in6_addr), 253 nla_put_in6_addr(skb, FRA_DST, &rule6->dst.addr)) ||
254 &rule6->dst.addr)) ||
255 (rule6->src.plen && 254 (rule6->src.plen &&
256 nla_put(skb, FRA_SRC, sizeof(struct in6_addr), 255 nla_put_in6_addr(skb, FRA_SRC, &rule6->src.addr)))
257 &rule6->src.addr)))
258 goto nla_put_failure; 256 goto nla_put_failure;
259 return 0; 257 return 0;
260 258
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 67e014d88e55..f61f7ad2d045 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -1622,8 +1622,8 @@ static int ip6gre_fill_info(struct sk_buff *skb, const struct net_device *dev)
1622 nla_put_be16(skb, IFLA_GRE_OFLAGS, p->o_flags) || 1622 nla_put_be16(skb, IFLA_GRE_OFLAGS, p->o_flags) ||
1623 nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) || 1623 nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) ||
1624 nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) || 1624 nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) ||
1625 nla_put(skb, IFLA_GRE_LOCAL, sizeof(struct in6_addr), &p->laddr) || 1625 nla_put_in6_addr(skb, IFLA_GRE_LOCAL, &p->laddr) ||
1626 nla_put(skb, IFLA_GRE_REMOTE, sizeof(struct in6_addr), &p->raddr) || 1626 nla_put_in6_addr(skb, IFLA_GRE_REMOTE, &p->raddr) ||
1627 nla_put_u8(skb, IFLA_GRE_TTL, p->hop_limit) || 1627 nla_put_u8(skb, IFLA_GRE_TTL, p->hop_limit) ||
1628 /*nla_put_u8(skb, IFLA_GRE_TOS, t->priority) ||*/ 1628 /*nla_put_u8(skb, IFLA_GRE_TOS, t->priority) ||*/
1629 nla_put_u8(skb, IFLA_GRE_ENCAP_LIMIT, p->encap_limit) || 1629 nla_put_u8(skb, IFLA_GRE_ENCAP_LIMIT, p->encap_limit) ||
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 0c68012b6d6e..80543d13ea7c 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1739,10 +1739,8 @@ static int ip6_tnl_fill_info(struct sk_buff *skb, const struct net_device *dev)
1739 struct __ip6_tnl_parm *parm = &tunnel->parms; 1739 struct __ip6_tnl_parm *parm = &tunnel->parms;
1740 1740
1741 if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || 1741 if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) ||
1742 nla_put(skb, IFLA_IPTUN_LOCAL, sizeof(struct in6_addr), 1742 nla_put_in6_addr(skb, IFLA_IPTUN_LOCAL, &parm->laddr) ||
1743 &parm->laddr) || 1743 nla_put_in6_addr(skb, IFLA_IPTUN_REMOTE, &parm->raddr) ||
1744 nla_put(skb, IFLA_IPTUN_REMOTE, sizeof(struct in6_addr),
1745 &parm->raddr) ||
1746 nla_put_u8(skb, IFLA_IPTUN_TTL, parm->hop_limit) || 1744 nla_put_u8(skb, IFLA_IPTUN_TTL, parm->hop_limit) ||
1747 nla_put_u8(skb, IFLA_IPTUN_ENCAP_LIMIT, parm->encap_limit) || 1745 nla_put_u8(skb, IFLA_IPTUN_ENCAP_LIMIT, parm->encap_limit) ||
1748 nla_put_be32(skb, IFLA_IPTUN_FLOWINFO, parm->flowinfo) || 1746 nla_put_be32(skb, IFLA_IPTUN_FLOWINFO, parm->flowinfo) ||
diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
index 1ec5b4a530d0..87a262b0f07b 100644
--- a/net/ipv6/ip6_vti.c
+++ b/net/ipv6/ip6_vti.c
@@ -983,10 +983,8 @@ static int vti6_fill_info(struct sk_buff *skb, const struct net_device *dev)
983 struct __ip6_tnl_parm *parm = &tunnel->parms; 983 struct __ip6_tnl_parm *parm = &tunnel->parms;
984 984
985 if (nla_put_u32(skb, IFLA_VTI_LINK, parm->link) || 985 if (nla_put_u32(skb, IFLA_VTI_LINK, parm->link) ||
986 nla_put(skb, IFLA_VTI_LOCAL, sizeof(struct in6_addr), 986 nla_put_in6_addr(skb, IFLA_VTI_LOCAL, &parm->laddr) ||
987 &parm->laddr) || 987 nla_put_in6_addr(skb, IFLA_VTI_REMOTE, &parm->raddr) ||
988 nla_put(skb, IFLA_VTI_REMOTE, sizeof(struct in6_addr),
989 &parm->raddr) ||
990 nla_put_be32(skb, IFLA_VTI_IKEY, parm->i_key) || 988 nla_put_be32(skb, IFLA_VTI_IKEY, parm->i_key) ||
991 nla_put_be32(skb, IFLA_VTI_OKEY, parm->o_key)) 989 nla_put_be32(skb, IFLA_VTI_OKEY, parm->o_key))
992 goto nla_put_failure; 990 goto nla_put_failure;
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index ff883c9d0e3c..caf6b99374e6 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -2378,8 +2378,8 @@ static int ip6mr_fill_mroute(struct mr6_table *mrt, struct sk_buff *skb,
2378 rtm->rtm_protocol = RTPROT_MROUTED; 2378 rtm->rtm_protocol = RTPROT_MROUTED;
2379 rtm->rtm_flags = 0; 2379 rtm->rtm_flags = 0;
2380 2380
2381 if (nla_put(skb, RTA_SRC, 16, &c->mf6c_origin) || 2381 if (nla_put_in6_addr(skb, RTA_SRC, &c->mf6c_origin) ||
2382 nla_put(skb, RTA_DST, 16, &c->mf6c_mcastgrp)) 2382 nla_put_in6_addr(skb, RTA_DST, &c->mf6c_mcastgrp))
2383 goto nla_put_failure; 2383 goto nla_put_failure;
2384 err = __ip6mr_fill_mroute(mrt, skb, c, rtm); 2384 err = __ip6mr_fill_mroute(mrt, skb, c, rtm);
2385 /* do not break the dump if cache is unresolved */ 2385 /* do not break the dump if cache is unresolved */
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 482dfb9f0f7e..c283827d60e2 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -1049,8 +1049,7 @@ static void ndisc_ra_useropt(struct sk_buff *ra, struct nd_opt_hdr *opt)
1049 1049
1050 memcpy(ndmsg + 1, opt, opt->nd_opt_len << 3); 1050 memcpy(ndmsg + 1, opt, opt->nd_opt_len << 3);
1051 1051
1052 if (nla_put(skb, NDUSEROPT_SRCADDR, sizeof(struct in6_addr), 1052 if (nla_put_in6_addr(skb, NDUSEROPT_SRCADDR, &ipv6_hdr(ra)->saddr))
1053 &ipv6_hdr(ra)->saddr))
1054 goto nla_put_failure; 1053 goto nla_put_failure;
1055 nlmsg_end(skb, nlh); 1054 nlmsg_end(skb, nlh);
1056 1055
diff --git a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
index b68d0e59c1f8..78284a697439 100644
--- a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
+++ b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
@@ -290,10 +290,8 @@ ipv6_getorigdst(struct sock *sk, int optval, void __user *user, int *len)
290static int ipv6_tuple_to_nlattr(struct sk_buff *skb, 290static int ipv6_tuple_to_nlattr(struct sk_buff *skb,
291 const struct nf_conntrack_tuple *tuple) 291 const struct nf_conntrack_tuple *tuple)
292{ 292{
293 if (nla_put(skb, CTA_IP_V6_SRC, sizeof(u_int32_t) * 4, 293 if (nla_put_in6_addr(skb, CTA_IP_V6_SRC, &tuple->src.u3.in6) ||
294 &tuple->src.u3.ip6) || 294 nla_put_in6_addr(skb, CTA_IP_V6_DST, &tuple->dst.u3.in6))
295 nla_put(skb, CTA_IP_V6_DST, sizeof(u_int32_t) * 4,
296 &tuple->dst.u3.ip6))
297 goto nla_put_failure; 295 goto nla_put_failure;
298 return 0; 296 return 0;
299 297
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index fe742fa0f7ff..385e9bd4f218 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2669,19 +2669,19 @@ static int rt6_fill_node(struct net *net,
2669 rtm->rtm_flags |= RTM_F_CLONED; 2669 rtm->rtm_flags |= RTM_F_CLONED;
2670 2670
2671 if (dst) { 2671 if (dst) {
2672 if (nla_put(skb, RTA_DST, 16, dst)) 2672 if (nla_put_in6_addr(skb, RTA_DST, dst))
2673 goto nla_put_failure; 2673 goto nla_put_failure;
2674 rtm->rtm_dst_len = 128; 2674 rtm->rtm_dst_len = 128;
2675 } else if (rtm->rtm_dst_len) 2675 } else if (rtm->rtm_dst_len)
2676 if (nla_put(skb, RTA_DST, 16, &rt->rt6i_dst.addr)) 2676 if (nla_put_in6_addr(skb, RTA_DST, &rt->rt6i_dst.addr))
2677 goto nla_put_failure; 2677 goto nla_put_failure;
2678#ifdef CONFIG_IPV6_SUBTREES 2678#ifdef CONFIG_IPV6_SUBTREES
2679 if (src) { 2679 if (src) {
2680 if (nla_put(skb, RTA_SRC, 16, src)) 2680 if (nla_put_in6_addr(skb, RTA_SRC, src))
2681 goto nla_put_failure; 2681 goto nla_put_failure;
2682 rtm->rtm_src_len = 128; 2682 rtm->rtm_src_len = 128;
2683 } else if (rtm->rtm_src_len && 2683 } else if (rtm->rtm_src_len &&
2684 nla_put(skb, RTA_SRC, 16, &rt->rt6i_src.addr)) 2684 nla_put_in6_addr(skb, RTA_SRC, &rt->rt6i_src.addr))
2685 goto nla_put_failure; 2685 goto nla_put_failure;
2686#endif 2686#endif
2687 if (iif) { 2687 if (iif) {
@@ -2705,14 +2705,14 @@ static int rt6_fill_node(struct net *net,
2705 } else if (dst) { 2705 } else if (dst) {
2706 struct in6_addr saddr_buf; 2706 struct in6_addr saddr_buf;
2707 if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 && 2707 if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
2708 nla_put(skb, RTA_PREFSRC, 16, &saddr_buf)) 2708 nla_put_in6_addr(skb, RTA_PREFSRC, &saddr_buf))
2709 goto nla_put_failure; 2709 goto nla_put_failure;
2710 } 2710 }
2711 2711
2712 if (rt->rt6i_prefsrc.plen) { 2712 if (rt->rt6i_prefsrc.plen) {
2713 struct in6_addr saddr_buf; 2713 struct in6_addr saddr_buf;
2714 saddr_buf = rt->rt6i_prefsrc.addr; 2714 saddr_buf = rt->rt6i_prefsrc.addr;
2715 if (nla_put(skb, RTA_PREFSRC, 16, &saddr_buf)) 2715 if (nla_put_in6_addr(skb, RTA_PREFSRC, &saddr_buf))
2716 goto nla_put_failure; 2716 goto nla_put_failure;
2717 } 2717 }
2718 2718
@@ -2720,7 +2720,7 @@ static int rt6_fill_node(struct net *net,
2720 goto nla_put_failure; 2720 goto nla_put_failure;
2721 2721
2722 if (rt->rt6i_flags & RTF_GATEWAY) { 2722 if (rt->rt6i_flags & RTF_GATEWAY) {
2723 if (nla_put(skb, RTA_GATEWAY, 16, &rt->rt6i_gateway) < 0) 2723 if (nla_put_in6_addr(skb, RTA_GATEWAY, &rt->rt6i_gateway) < 0)
2724 goto nla_put_failure; 2724 goto nla_put_failure;
2725 } 2725 }
2726 2726
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 92692a7e8a2b..0e2bb538a556 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -1683,8 +1683,8 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev)
1683 struct ip_tunnel_parm *parm = &tunnel->parms; 1683 struct ip_tunnel_parm *parm = &tunnel->parms;
1684 1684
1685 if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || 1685 if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) ||
1686 nla_put_be32(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) || 1686 nla_put_in_addr(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) ||
1687 nla_put_be32(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) || 1687 nla_put_in_addr(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) ||
1688 nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) || 1688 nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) ||
1689 nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos) || 1689 nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos) ||
1690 nla_put_u8(skb, IFLA_IPTUN_PMTUDISC, 1690 nla_put_u8(skb, IFLA_IPTUN_PMTUDISC,
@@ -1694,10 +1694,10 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev)
1694 goto nla_put_failure; 1694 goto nla_put_failure;
1695 1695
1696#ifdef CONFIG_IPV6_SIT_6RD 1696#ifdef CONFIG_IPV6_SIT_6RD
1697 if (nla_put(skb, IFLA_IPTUN_6RD_PREFIX, sizeof(struct in6_addr), 1697 if (nla_put_in6_addr(skb, IFLA_IPTUN_6RD_PREFIX,
1698 &tunnel->ip6rd.prefix) || 1698 &tunnel->ip6rd.prefix) ||
1699 nla_put_be32(skb, IFLA_IPTUN_6RD_RELAY_PREFIX, 1699 nla_put_in_addr(skb, IFLA_IPTUN_6RD_RELAY_PREFIX,
1700 tunnel->ip6rd.relay_prefix) || 1700 tunnel->ip6rd.relay_prefix) ||
1701 nla_put_u16(skb, IFLA_IPTUN_6RD_PREFIXLEN, 1701 nla_put_u16(skb, IFLA_IPTUN_6RD_PREFIXLEN,
1702 tunnel->ip6rd.prefixlen) || 1702 tunnel->ip6rd.prefixlen) ||
1703 nla_put_u16(skb, IFLA_IPTUN_6RD_RELAY_PREFIXLEN, 1703 nla_put_u16(skb, IFLA_IPTUN_6RD_RELAY_PREFIXLEN,