diff options
author | Jiri Benc <jbenc@redhat.com> | 2015-03-29 10:59:25 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-31 13:58:35 -0400 |
commit | 930345ea630405aa6e6f42efcb149c3f360a6b67 (patch) | |
tree | c88d0858785c246038fddac3ca51571b371416b0 /net/ipv4 | |
parent | 15e318bdc6dfb82914c82fb7ad00badaa8387d8e (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/ipv4')
-rw-r--r-- | net/ipv4/devinet.c | 6 | ||||
-rw-r--r-- | net/ipv4/fib_rules.c | 4 | ||||
-rw-r--r-- | net/ipv4/fib_semantics.c | 8 | ||||
-rw-r--r-- | net/ipv4/ip_gre.c | 4 | ||||
-rw-r--r-- | net/ipv4/ip_vti.c | 4 | ||||
-rw-r--r-- | net/ipv4/ipip.c | 4 | ||||
-rw-r--r-- | net/ipv4/ipmr.c | 4 | ||||
-rw-r--r-- | net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 4 | ||||
-rw-r--r-- | net/ipv4/route.c | 8 | ||||
-rw-r--r-- | net/ipv4/tcp_metrics.c | 16 |
10 files changed, 31 insertions, 31 deletions
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 975ee5e30c64..66cd85973056 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c | |||
@@ -1541,11 +1541,11 @@ static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa, | |||
1541 | valid = INFINITY_LIFE_TIME; | 1541 | valid = INFINITY_LIFE_TIME; |
1542 | } | 1542 | } |
1543 | if ((ifa->ifa_address && | 1543 | if ((ifa->ifa_address && |
1544 | nla_put_be32(skb, IFA_ADDRESS, ifa->ifa_address)) || | 1544 | nla_put_in_addr(skb, IFA_ADDRESS, ifa->ifa_address)) || |
1545 | (ifa->ifa_local && | 1545 | (ifa->ifa_local && |
1546 | nla_put_be32(skb, IFA_LOCAL, ifa->ifa_local)) || | 1546 | nla_put_in_addr(skb, IFA_LOCAL, ifa->ifa_local)) || |
1547 | (ifa->ifa_broadcast && | 1547 | (ifa->ifa_broadcast && |
1548 | nla_put_be32(skb, IFA_BROADCAST, ifa->ifa_broadcast)) || | 1548 | nla_put_in_addr(skb, IFA_BROADCAST, ifa->ifa_broadcast)) || |
1549 | (ifa->ifa_label[0] && | 1549 | (ifa->ifa_label[0] && |
1550 | nla_put_string(skb, IFA_LABEL, ifa->ifa_label)) || | 1550 | nla_put_string(skb, IFA_LABEL, ifa->ifa_label)) || |
1551 | nla_put_u32(skb, IFA_FLAGS, ifa->ifa_flags) || | 1551 | nla_put_u32(skb, IFA_FLAGS, ifa->ifa_flags) || |
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c index e9bc5e42cf43..edfea0deec43 100644 --- a/net/ipv4/fib_rules.c +++ b/net/ipv4/fib_rules.c | |||
@@ -279,9 +279,9 @@ static int fib4_rule_fill(struct fib_rule *rule, struct sk_buff *skb, | |||
279 | frh->tos = rule4->tos; | 279 | frh->tos = rule4->tos; |
280 | 280 | ||
281 | if ((rule4->dst_len && | 281 | if ((rule4->dst_len && |
282 | nla_put_be32(skb, FRA_DST, rule4->dst)) || | 282 | nla_put_in_addr(skb, FRA_DST, rule4->dst)) || |
283 | (rule4->src_len && | 283 | (rule4->src_len && |
284 | nla_put_be32(skb, FRA_SRC, rule4->src))) | 284 | nla_put_in_addr(skb, FRA_SRC, rule4->src))) |
285 | goto nla_put_failure; | 285 | goto nla_put_failure; |
286 | #ifdef CONFIG_IP_ROUTE_CLASSID | 286 | #ifdef CONFIG_IP_ROUTE_CLASSID |
287 | if (rule4->tclassid && | 287 | if (rule4->tclassid && |
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index 66c1e4fbf884..453b24e5322c 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c | |||
@@ -1015,7 +1015,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, | |||
1015 | rtm->rtm_protocol = fi->fib_protocol; | 1015 | rtm->rtm_protocol = fi->fib_protocol; |
1016 | 1016 | ||
1017 | if (rtm->rtm_dst_len && | 1017 | if (rtm->rtm_dst_len && |
1018 | nla_put_be32(skb, RTA_DST, dst)) | 1018 | nla_put_in_addr(skb, RTA_DST, dst)) |
1019 | goto nla_put_failure; | 1019 | goto nla_put_failure; |
1020 | if (fi->fib_priority && | 1020 | if (fi->fib_priority && |
1021 | nla_put_u32(skb, RTA_PRIORITY, fi->fib_priority)) | 1021 | 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, | |||
1024 | goto nla_put_failure; | 1024 | goto nla_put_failure; |
1025 | 1025 | ||
1026 | if (fi->fib_prefsrc && | 1026 | if (fi->fib_prefsrc && |
1027 | nla_put_be32(skb, RTA_PREFSRC, fi->fib_prefsrc)) | 1027 | nla_put_in_addr(skb, RTA_PREFSRC, fi->fib_prefsrc)) |
1028 | goto nla_put_failure; | 1028 | goto nla_put_failure; |
1029 | if (fi->fib_nhs == 1) { | 1029 | if (fi->fib_nhs == 1) { |
1030 | if (fi->fib_nh->nh_gw && | 1030 | if (fi->fib_nh->nh_gw && |
1031 | nla_put_be32(skb, RTA_GATEWAY, fi->fib_nh->nh_gw)) | 1031 | nla_put_in_addr(skb, RTA_GATEWAY, fi->fib_nh->nh_gw)) |
1032 | goto nla_put_failure; | 1032 | goto nla_put_failure; |
1033 | if (fi->fib_nh->nh_oif && | 1033 | if (fi->fib_nh->nh_oif && |
1034 | nla_put_u32(skb, RTA_OIF, fi->fib_nh->nh_oif)) | 1034 | 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, | |||
1058 | rtnh->rtnh_ifindex = nh->nh_oif; | 1058 | rtnh->rtnh_ifindex = nh->nh_oif; |
1059 | 1059 | ||
1060 | if (nh->nh_gw && | 1060 | if (nh->nh_gw && |
1061 | nla_put_be32(skb, RTA_GATEWAY, nh->nh_gw)) | 1061 | nla_put_in_addr(skb, RTA_GATEWAY, nh->nh_gw)) |
1062 | goto nla_put_failure; | 1062 | goto nla_put_failure; |
1063 | #ifdef CONFIG_IP_ROUTE_CLASSID | 1063 | #ifdef CONFIG_IP_ROUTE_CLASSID |
1064 | if (nh->nh_tclassid && | 1064 | if (nh->nh_tclassid && |
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index 6207275fc749..2e878df46075 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c | |||
@@ -776,8 +776,8 @@ static int ipgre_fill_info(struct sk_buff *skb, const struct net_device *dev) | |||
776 | nla_put_be16(skb, IFLA_GRE_OFLAGS, tnl_flags_to_gre_flags(p->o_flags)) || | 776 | nla_put_be16(skb, IFLA_GRE_OFLAGS, tnl_flags_to_gre_flags(p->o_flags)) || |
777 | nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) || | 777 | nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) || |
778 | nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) || | 778 | nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) || |
779 | nla_put_be32(skb, IFLA_GRE_LOCAL, p->iph.saddr) || | 779 | nla_put_in_addr(skb, IFLA_GRE_LOCAL, p->iph.saddr) || |
780 | nla_put_be32(skb, IFLA_GRE_REMOTE, p->iph.daddr) || | 780 | nla_put_in_addr(skb, IFLA_GRE_REMOTE, p->iph.daddr) || |
781 | nla_put_u8(skb, IFLA_GRE_TTL, p->iph.ttl) || | 781 | nla_put_u8(skb, IFLA_GRE_TTL, p->iph.ttl) || |
782 | nla_put_u8(skb, IFLA_GRE_TOS, p->iph.tos) || | 782 | nla_put_u8(skb, IFLA_GRE_TOS, p->iph.tos) || |
783 | nla_put_u8(skb, IFLA_GRE_PMTUDISC, | 783 | nla_put_u8(skb, IFLA_GRE_PMTUDISC, |
diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c index 94efe148181c..f189f2a8aaa5 100644 --- a/net/ipv4/ip_vti.c +++ b/net/ipv4/ip_vti.c | |||
@@ -505,8 +505,8 @@ static int vti_fill_info(struct sk_buff *skb, const struct net_device *dev) | |||
505 | nla_put_u32(skb, IFLA_VTI_LINK, p->link); | 505 | nla_put_u32(skb, IFLA_VTI_LINK, p->link); |
506 | nla_put_be32(skb, IFLA_VTI_IKEY, p->i_key); | 506 | nla_put_be32(skb, IFLA_VTI_IKEY, p->i_key); |
507 | nla_put_be32(skb, IFLA_VTI_OKEY, p->o_key); | 507 | nla_put_be32(skb, IFLA_VTI_OKEY, p->o_key); |
508 | nla_put_be32(skb, IFLA_VTI_LOCAL, p->iph.saddr); | 508 | nla_put_in_addr(skb, IFLA_VTI_LOCAL, p->iph.saddr); |
509 | nla_put_be32(skb, IFLA_VTI_REMOTE, p->iph.daddr); | 509 | nla_put_in_addr(skb, IFLA_VTI_REMOTE, p->iph.daddr); |
510 | 510 | ||
511 | return 0; | 511 | return 0; |
512 | } | 512 | } |
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c index 915d215a7d14..17df8d38bbbd 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c | |||
@@ -450,8 +450,8 @@ static int ipip_fill_info(struct sk_buff *skb, const struct net_device *dev) | |||
450 | struct ip_tunnel_parm *parm = &tunnel->parms; | 450 | struct ip_tunnel_parm *parm = &tunnel->parms; |
451 | 451 | ||
452 | if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || | 452 | if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || |
453 | nla_put_be32(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) || | 453 | nla_put_in_addr(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) || |
454 | nla_put_be32(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) || | 454 | nla_put_in_addr(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) || |
455 | nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) || | 455 | nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) || |
456 | nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos) || | 456 | nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos) || |
457 | nla_put_u8(skb, IFLA_IPTUN_PMTUDISC, | 457 | nla_put_u8(skb, IFLA_IPTUN_PMTUDISC, |
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index c688cd1b2110..b4a545d24adb 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c | |||
@@ -2281,8 +2281,8 @@ static int ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, | |||
2281 | rtm->rtm_protocol = RTPROT_MROUTED; | 2281 | rtm->rtm_protocol = RTPROT_MROUTED; |
2282 | rtm->rtm_flags = 0; | 2282 | rtm->rtm_flags = 0; |
2283 | 2283 | ||
2284 | if (nla_put_be32(skb, RTA_SRC, c->mfc_origin) || | 2284 | if (nla_put_in_addr(skb, RTA_SRC, c->mfc_origin) || |
2285 | nla_put_be32(skb, RTA_DST, c->mfc_mcastgrp)) | 2285 | nla_put_in_addr(skb, RTA_DST, c->mfc_mcastgrp)) |
2286 | goto nla_put_failure; | 2286 | goto nla_put_failure; |
2287 | err = __ipmr_fill_mroute(mrt, skb, c, rtm); | 2287 | err = __ipmr_fill_mroute(mrt, skb, c, rtm); |
2288 | /* do not break the dump if cache is unresolved */ | 2288 | /* do not break the dump if cache is unresolved */ |
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c index 5c61328b7704..b36ebfc6b812 100644 --- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | |||
@@ -322,8 +322,8 @@ getorigdst(struct sock *sk, int optval, void __user *user, int *len) | |||
322 | static int ipv4_tuple_to_nlattr(struct sk_buff *skb, | 322 | static int ipv4_tuple_to_nlattr(struct sk_buff *skb, |
323 | const struct nf_conntrack_tuple *tuple) | 323 | const struct nf_conntrack_tuple *tuple) |
324 | { | 324 | { |
325 | if (nla_put_be32(skb, CTA_IP_V4_SRC, tuple->src.u3.ip) || | 325 | if (nla_put_in_addr(skb, CTA_IP_V4_SRC, tuple->src.u3.ip) || |
326 | nla_put_be32(skb, CTA_IP_V4_DST, tuple->dst.u3.ip)) | 326 | nla_put_in_addr(skb, CTA_IP_V4_DST, tuple->dst.u3.ip)) |
327 | goto nla_put_failure; | 327 | goto nla_put_failure; |
328 | return 0; | 328 | return 0; |
329 | 329 | ||
diff --git a/net/ipv4/route.c b/net/ipv4/route.c index be8703d02ef0..1f147204f1f3 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c | |||
@@ -2319,11 +2319,11 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src, | |||
2319 | if (IPCB(skb)->flags & IPSKB_DOREDIRECT) | 2319 | if (IPCB(skb)->flags & IPSKB_DOREDIRECT) |
2320 | r->rtm_flags |= RTCF_DOREDIRECT; | 2320 | r->rtm_flags |= RTCF_DOREDIRECT; |
2321 | 2321 | ||
2322 | if (nla_put_be32(skb, RTA_DST, dst)) | 2322 | if (nla_put_in_addr(skb, RTA_DST, dst)) |
2323 | goto nla_put_failure; | 2323 | goto nla_put_failure; |
2324 | if (src) { | 2324 | if (src) { |
2325 | r->rtm_src_len = 32; | 2325 | r->rtm_src_len = 32; |
2326 | if (nla_put_be32(skb, RTA_SRC, src)) | 2326 | if (nla_put_in_addr(skb, RTA_SRC, src)) |
2327 | goto nla_put_failure; | 2327 | goto nla_put_failure; |
2328 | } | 2328 | } |
2329 | if (rt->dst.dev && | 2329 | if (rt->dst.dev && |
@@ -2336,11 +2336,11 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src, | |||
2336 | #endif | 2336 | #endif |
2337 | if (!rt_is_input_route(rt) && | 2337 | if (!rt_is_input_route(rt) && |
2338 | fl4->saddr != src) { | 2338 | fl4->saddr != src) { |
2339 | if (nla_put_be32(skb, RTA_PREFSRC, fl4->saddr)) | 2339 | if (nla_put_in_addr(skb, RTA_PREFSRC, fl4->saddr)) |
2340 | goto nla_put_failure; | 2340 | goto nla_put_failure; |
2341 | } | 2341 | } |
2342 | if (rt->rt_uses_gateway && | 2342 | if (rt->rt_uses_gateway && |
2343 | nla_put_be32(skb, RTA_GATEWAY, rt->rt_gateway)) | 2343 | nla_put_in_addr(skb, RTA_GATEWAY, rt->rt_gateway)) |
2344 | goto nla_put_failure; | 2344 | goto nla_put_failure; |
2345 | 2345 | ||
2346 | expires = rt->dst.expires; | 2346 | expires = rt->dst.expires; |
diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c index f62c2c68ced0..32e36ea6bc0f 100644 --- a/net/ipv4/tcp_metrics.c +++ b/net/ipv4/tcp_metrics.c | |||
@@ -786,19 +786,19 @@ static int tcp_metrics_fill_info(struct sk_buff *msg, | |||
786 | 786 | ||
787 | switch (tm->tcpm_daddr.family) { | 787 | switch (tm->tcpm_daddr.family) { |
788 | case AF_INET: | 788 | case AF_INET: |
789 | if (nla_put_be32(msg, TCP_METRICS_ATTR_ADDR_IPV4, | 789 | if (nla_put_in_addr(msg, TCP_METRICS_ATTR_ADDR_IPV4, |
790 | tm->tcpm_daddr.addr.a4) < 0) | 790 | tm->tcpm_daddr.addr.a4) < 0) |
791 | goto nla_put_failure; | 791 | goto nla_put_failure; |
792 | if (nla_put_be32(msg, TCP_METRICS_ATTR_SADDR_IPV4, | 792 | if (nla_put_in_addr(msg, TCP_METRICS_ATTR_SADDR_IPV4, |
793 | tm->tcpm_saddr.addr.a4) < 0) | 793 | tm->tcpm_saddr.addr.a4) < 0) |
794 | goto nla_put_failure; | 794 | goto nla_put_failure; |
795 | break; | 795 | break; |
796 | case AF_INET6: | 796 | case AF_INET6: |
797 | if (nla_put(msg, TCP_METRICS_ATTR_ADDR_IPV6, 16, | 797 | if (nla_put_in6_addr(msg, TCP_METRICS_ATTR_ADDR_IPV6, |
798 | tm->tcpm_daddr.addr.a6) < 0) | 798 | &tm->tcpm_daddr.addr.in6) < 0) |
799 | goto nla_put_failure; | 799 | goto nla_put_failure; |
800 | if (nla_put(msg, TCP_METRICS_ATTR_SADDR_IPV6, 16, | 800 | if (nla_put_in6_addr(msg, TCP_METRICS_ATTR_SADDR_IPV6, |
801 | tm->tcpm_saddr.addr.a6) < 0) | 801 | &tm->tcpm_saddr.addr.in6) < 0) |
802 | goto nla_put_failure; | 802 | goto nla_put_failure; |
803 | break; | 803 | break; |
804 | default: | 804 | default: |