Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Benc and committed by
David S. Miller
930345ea 15e318bd

+139 -124
+11 -11
drivers/net/vxlan.c
··· 187 187 const union vxlan_addr *ip) 188 188 { 189 189 if (ip->sa.sa_family == AF_INET6) 190 - return nla_put(skb, attr, sizeof(struct in6_addr), &ip->sin6.sin6_addr); 190 + return nla_put_in6_addr(skb, attr, &ip->sin6.sin6_addr); 191 191 else 192 - return nla_put_be32(skb, attr, ip->sin.sin_addr.s_addr); 192 + return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); 193 193 } 194 194 195 195 #else /* !CONFIG_IPV6 */ ··· 226 226 static int vxlan_nla_put_addr(struct sk_buff *skb, int attr, 227 227 const union vxlan_addr *ip) 228 228 { 229 - return nla_put_be32(skb, attr, ip->sin.sin_addr.s_addr); 229 + return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); 230 230 } 231 231 #endif 232 232 ··· 2807 2807 2808 2808 if (!vxlan_addr_any(&dst->remote_ip)) { 2809 2809 if (dst->remote_ip.sa.sa_family == AF_INET) { 2810 - if (nla_put_be32(skb, IFLA_VXLAN_GROUP, 2811 - dst->remote_ip.sin.sin_addr.s_addr)) 2810 + if (nla_put_in_addr(skb, IFLA_VXLAN_GROUP, 2811 + dst->remote_ip.sin.sin_addr.s_addr)) 2812 2812 goto nla_put_failure; 2813 2813 #if IS_ENABLED(CONFIG_IPV6) 2814 2814 } else { 2815 - if (nla_put(skb, IFLA_VXLAN_GROUP6, sizeof(struct in6_addr), 2816 - &dst->remote_ip.sin6.sin6_addr)) 2815 + if (nla_put_in6_addr(skb, IFLA_VXLAN_GROUP6, 2816 + &dst->remote_ip.sin6.sin6_addr)) 2817 2817 goto nla_put_failure; 2818 2818 #endif 2819 2819 } ··· 2824 2824 2825 2825 if (!vxlan_addr_any(&vxlan->saddr)) { 2826 2826 if (vxlan->saddr.sa.sa_family == AF_INET) { 2827 - if (nla_put_be32(skb, IFLA_VXLAN_LOCAL, 2828 - vxlan->saddr.sin.sin_addr.s_addr)) 2827 + if (nla_put_in_addr(skb, IFLA_VXLAN_LOCAL, 2828 + vxlan->saddr.sin.sin_addr.s_addr)) 2829 2829 goto nla_put_failure; 2830 2830 #if IS_ENABLED(CONFIG_IPV6) 2831 2831 } else { 2832 - if (nla_put(skb, IFLA_VXLAN_LOCAL6, sizeof(struct in6_addr), 2833 - &vxlan->saddr.sin6.sin6_addr)) 2832 + if (nla_put_in6_addr(skb, IFLA_VXLAN_LOCAL6, 2833 + &vxlan->saddr.sin6.sin6_addr)) 2834 2834 goto nla_put_failure; 2835 2835 #endif 2836 2836 }
+2 -3
include/linux/netfilter/ipset/ip_set.h
··· 483 483 484 484 if (!__nested) 485 485 return -EMSGSIZE; 486 - ret = nla_put_net32(skb, IPSET_ATTR_IPADDR_IPV4, ipaddr); 486 + ret = nla_put_in_addr(skb, IPSET_ATTR_IPADDR_IPV4, ipaddr); 487 487 if (!ret) 488 488 ipset_nest_end(skb, __nested); 489 489 return ret; ··· 497 497 498 498 if (!__nested) 499 499 return -EMSGSIZE; 500 - ret = nla_put(skb, IPSET_ATTR_IPADDR_IPV6, 501 - sizeof(struct in6_addr), ipaddrptr); 500 + ret = nla_put_in6_addr(skb, IPSET_ATTR_IPADDR_IPV6, ipaddrptr); 502 501 if (!ret) 503 502 ipset_nest_end(skb, __nested); 504 503 return ret;
+29
include/net/netlink.h
··· 4 4 #include <linux/types.h> 5 5 #include <linux/netlink.h> 6 6 #include <linux/jiffies.h> 7 + #include <linux/in6.h> 7 8 8 9 /* ======================================================================== 9 10 * Netlink Messages and Attributes Interface (As Seen On TV) ··· 106 105 * nla_put_string(skb, type, str) add string attribute to skb 107 106 * nla_put_flag(skb, type) add flag attribute to skb 108 107 * nla_put_msecs(skb, type, jiffies) add msecs attribute to skb 108 + * nla_put_in_addr(skb, type, addr) add IPv4 address attribute to skb 109 + * nla_put_in6_addr(skb, type, addr) add IPv6 address attribute to skb 109 110 * 110 111 * Nested Attributes Construction: 111 112 * nla_nest_start(skb, type) start a nested attribute ··· 957 954 { 958 955 u64 tmp = jiffies_to_msecs(njiffies); 959 956 return nla_put(skb, attrtype, sizeof(u64), &tmp); 957 + } 958 + 959 + /** 960 + * nla_put_in_addr - Add an IPv4 address netlink attribute to a socket 961 + * buffer 962 + * @skb: socket buffer to add attribute to 963 + * @attrtype: attribute type 964 + * @addr: IPv4 address 965 + */ 966 + static inline int nla_put_in_addr(struct sk_buff *skb, int attrtype, 967 + __be32 addr) 968 + { 969 + return nla_put_be32(skb, attrtype, addr); 970 + } 971 + 972 + /** 973 + * nla_put_in6_addr - Add an IPv6 address netlink attribute to a socket 974 + * buffer 975 + * @skb: socket buffer to add attribute to 976 + * @attrtype: attribute type 977 + * @addr: IPv6 address 978 + */ 979 + static inline int nla_put_in6_addr(struct sk_buff *skb, int attrtype, 980 + const struct in6_addr *addr) 981 + { 982 + return nla_put(skb, attrtype, sizeof(*addr), addr); 960 983 } 961 984 962 985 /**
+3 -3
net/ipv4/devinet.c
··· 1541 1541 valid = INFINITY_LIFE_TIME; 1542 1542 } 1543 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 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 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 1549 (ifa->ifa_label[0] && 1550 1550 nla_put_string(skb, IFA_LABEL, ifa->ifa_label)) || 1551 1551 nla_put_u32(skb, IFA_FLAGS, ifa->ifa_flags) ||
+2 -2
net/ipv4/fib_rules.c
··· 279 279 frh->tos = rule4->tos; 280 280 281 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 283 (rule4->src_len && 284 - nla_put_be32(skb, FRA_SRC, rule4->src))) 284 + nla_put_in_addr(skb, FRA_SRC, rule4->src))) 285 285 goto nla_put_failure; 286 286 #ifdef CONFIG_IP_ROUTE_CLASSID 287 287 if (rule4->tclassid &&
+4 -4
net/ipv4/fib_semantics.c
··· 1015 1015 rtm->rtm_protocol = fi->fib_protocol; 1016 1016 1017 1017 if (rtm->rtm_dst_len && 1018 - nla_put_be32(skb, RTA_DST, dst)) 1018 + nla_put_in_addr(skb, RTA_DST, dst)) 1019 1019 goto nla_put_failure; 1020 1020 if (fi->fib_priority && 1021 1021 nla_put_u32(skb, RTA_PRIORITY, fi->fib_priority)) ··· 1024 1024 goto nla_put_failure; 1025 1025 1026 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 1028 goto nla_put_failure; 1029 1029 if (fi->fib_nhs == 1) { 1030 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 1032 goto nla_put_failure; 1033 1033 if (fi->fib_nh->nh_oif && 1034 1034 nla_put_u32(skb, RTA_OIF, fi->fib_nh->nh_oif)) ··· 1058 1058 rtnh->rtnh_ifindex = nh->nh_oif; 1059 1059 1060 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 1062 goto nla_put_failure; 1063 1063 #ifdef CONFIG_IP_ROUTE_CLASSID 1064 1064 if (nh->nh_tclassid &&
+2 -2
net/ipv4/ip_gre.c
··· 776 776 nla_put_be16(skb, IFLA_GRE_OFLAGS, tnl_flags_to_gre_flags(p->o_flags)) || 777 777 nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) || 778 778 nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) || 779 - nla_put_be32(skb, IFLA_GRE_LOCAL, p->iph.saddr) || 780 - nla_put_be32(skb, IFLA_GRE_REMOTE, p->iph.daddr) || 779 + nla_put_in_addr(skb, IFLA_GRE_LOCAL, p->iph.saddr) || 780 + nla_put_in_addr(skb, IFLA_GRE_REMOTE, p->iph.daddr) || 781 781 nla_put_u8(skb, IFLA_GRE_TTL, p->iph.ttl) || 782 782 nla_put_u8(skb, IFLA_GRE_TOS, p->iph.tos) || 783 783 nla_put_u8(skb, IFLA_GRE_PMTUDISC,
+2 -2
net/ipv4/ip_vti.c
··· 505 505 nla_put_u32(skb, IFLA_VTI_LINK, p->link); 506 506 nla_put_be32(skb, IFLA_VTI_IKEY, p->i_key); 507 507 nla_put_be32(skb, IFLA_VTI_OKEY, p->o_key); 508 - nla_put_be32(skb, IFLA_VTI_LOCAL, p->iph.saddr); 509 - nla_put_be32(skb, IFLA_VTI_REMOTE, p->iph.daddr); 508 + nla_put_in_addr(skb, IFLA_VTI_LOCAL, p->iph.saddr); 509 + nla_put_in_addr(skb, IFLA_VTI_REMOTE, p->iph.daddr); 510 510 511 511 return 0; 512 512 }
+2 -2
net/ipv4/ipip.c
··· 450 450 struct ip_tunnel_parm *parm = &tunnel->parms; 451 451 452 452 if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || 453 - nla_put_be32(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) || 454 - nla_put_be32(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) || 453 + nla_put_in_addr(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) || 454 + nla_put_in_addr(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) || 455 455 nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) || 456 456 nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos) || 457 457 nla_put_u8(skb, IFLA_IPTUN_PMTUDISC,
+2 -2
net/ipv4/ipmr.c
··· 2281 2281 rtm->rtm_protocol = RTPROT_MROUTED; 2282 2282 rtm->rtm_flags = 0; 2283 2283 2284 - if (nla_put_be32(skb, RTA_SRC, c->mfc_origin) || 2285 - nla_put_be32(skb, RTA_DST, c->mfc_mcastgrp)) 2284 + if (nla_put_in_addr(skb, RTA_SRC, c->mfc_origin) || 2285 + nla_put_in_addr(skb, RTA_DST, c->mfc_mcastgrp)) 2286 2286 goto nla_put_failure; 2287 2287 err = __ipmr_fill_mroute(mrt, skb, c, rtm); 2288 2288 /* do not break the dump if cache is unresolved */
+2 -2
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
··· 322 322 static int ipv4_tuple_to_nlattr(struct sk_buff *skb, 323 323 const struct nf_conntrack_tuple *tuple) 324 324 { 325 - if (nla_put_be32(skb, CTA_IP_V4_SRC, tuple->src.u3.ip) || 326 - nla_put_be32(skb, CTA_IP_V4_DST, tuple->dst.u3.ip)) 325 + if (nla_put_in_addr(skb, CTA_IP_V4_SRC, tuple->src.u3.ip) || 326 + nla_put_in_addr(skb, CTA_IP_V4_DST, tuple->dst.u3.ip)) 327 327 goto nla_put_failure; 328 328 return 0; 329 329
+4 -4
net/ipv4/route.c
··· 2319 2319 if (IPCB(skb)->flags & IPSKB_DOREDIRECT) 2320 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 2323 goto nla_put_failure; 2324 2324 if (src) { 2325 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 2327 goto nla_put_failure; 2328 2328 } 2329 2329 if (rt->dst.dev && ··· 2336 2336 #endif 2337 2337 if (!rt_is_input_route(rt) && 2338 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 2340 goto nla_put_failure; 2341 2341 } 2342 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 2344 goto nla_put_failure; 2345 2345 2346 2346 expires = rt->dst.expires;
+8 -8
net/ipv4/tcp_metrics.c
··· 786 786 787 787 switch (tm->tcpm_daddr.family) { 788 788 case AF_INET: 789 - if (nla_put_be32(msg, TCP_METRICS_ATTR_ADDR_IPV4, 790 - tm->tcpm_daddr.addr.a4) < 0) 789 + if (nla_put_in_addr(msg, TCP_METRICS_ATTR_ADDR_IPV4, 790 + tm->tcpm_daddr.addr.a4) < 0) 791 791 goto nla_put_failure; 792 - if (nla_put_be32(msg, TCP_METRICS_ATTR_SADDR_IPV4, 793 - tm->tcpm_saddr.addr.a4) < 0) 792 + if (nla_put_in_addr(msg, TCP_METRICS_ATTR_SADDR_IPV4, 793 + tm->tcpm_saddr.addr.a4) < 0) 794 794 goto nla_put_failure; 795 795 break; 796 796 case AF_INET6: 797 - if (nla_put(msg, TCP_METRICS_ATTR_ADDR_IPV6, 16, 798 - tm->tcpm_daddr.addr.a6) < 0) 797 + if (nla_put_in6_addr(msg, TCP_METRICS_ATTR_ADDR_IPV6, 798 + &tm->tcpm_daddr.addr.in6) < 0) 799 799 goto nla_put_failure; 800 - if (nla_put(msg, TCP_METRICS_ATTR_SADDR_IPV6, 16, 801 - tm->tcpm_saddr.addr.a6) < 0) 800 + if (nla_put_in6_addr(msg, TCP_METRICS_ATTR_SADDR_IPV6, 801 + &tm->tcpm_saddr.addr.in6) < 0) 802 802 goto nla_put_failure; 803 803 break; 804 804 default:
+5 -5
net/ipv6/addrconf.c
··· 4237 4237 } 4238 4238 4239 4239 if (!ipv6_addr_any(&ifa->peer_addr)) { 4240 - if (nla_put(skb, IFA_LOCAL, 16, &ifa->addr) < 0 || 4241 - nla_put(skb, IFA_ADDRESS, 16, &ifa->peer_addr) < 0) 4240 + if (nla_put_in6_addr(skb, IFA_LOCAL, &ifa->addr) < 0 || 4241 + nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->peer_addr) < 0) 4242 4242 goto error; 4243 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 4245 goto error; 4246 4246 4247 4247 if (put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0) ··· 4273 4273 return -EMSGSIZE; 4274 4274 4275 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 4277 put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp, 4278 4278 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) { 4279 4279 nlmsg_cancel(skb, nlh); ··· 4299 4299 return -EMSGSIZE; 4300 4300 4301 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 4303 put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp, 4304 4304 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) { 4305 4305 nlmsg_cancel(skb, nlh);
+1 -1
net/ipv6/addrlabel.c
··· 477 477 478 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 481 nla_put_u32(skb, IFAL_LABEL, p->label) < 0) { 482 482 nlmsg_cancel(skb, nlh); 483 483 return -EMSGSIZE;
+2 -4
net/ipv6/fib6_rules.c
··· 250 250 frh->tos = rule6->tclass; 251 251 252 252 if ((rule6->dst.plen && 253 - nla_put(skb, FRA_DST, sizeof(struct in6_addr), 254 - &rule6->dst.addr)) || 253 + nla_put_in6_addr(skb, FRA_DST, &rule6->dst.addr)) || 255 254 (rule6->src.plen && 256 - nla_put(skb, FRA_SRC, sizeof(struct in6_addr), 257 - &rule6->src.addr))) 255 + nla_put_in6_addr(skb, FRA_SRC, &rule6->src.addr))) 258 256 goto nla_put_failure; 259 257 return 0; 260 258
+2 -2
net/ipv6/ip6_gre.c
··· 1622 1622 nla_put_be16(skb, IFLA_GRE_OFLAGS, p->o_flags) || 1623 1623 nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) || 1624 1624 nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) || 1625 - nla_put(skb, IFLA_GRE_LOCAL, sizeof(struct in6_addr), &p->laddr) || 1626 - nla_put(skb, IFLA_GRE_REMOTE, sizeof(struct in6_addr), &p->raddr) || 1625 + nla_put_in6_addr(skb, IFLA_GRE_LOCAL, &p->laddr) || 1626 + nla_put_in6_addr(skb, IFLA_GRE_REMOTE, &p->raddr) || 1627 1627 nla_put_u8(skb, IFLA_GRE_TTL, p->hop_limit) || 1628 1628 /*nla_put_u8(skb, IFLA_GRE_TOS, t->priority) ||*/ 1629 1629 nla_put_u8(skb, IFLA_GRE_ENCAP_LIMIT, p->encap_limit) ||
+2 -4
net/ipv6/ip6_tunnel.c
··· 1739 1739 struct __ip6_tnl_parm *parm = &tunnel->parms; 1740 1740 1741 1741 if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || 1742 - nla_put(skb, IFLA_IPTUN_LOCAL, sizeof(struct in6_addr), 1743 - &parm->laddr) || 1744 - nla_put(skb, IFLA_IPTUN_REMOTE, sizeof(struct in6_addr), 1745 - &parm->raddr) || 1742 + nla_put_in6_addr(skb, IFLA_IPTUN_LOCAL, &parm->laddr) || 1743 + nla_put_in6_addr(skb, IFLA_IPTUN_REMOTE, &parm->raddr) || 1746 1744 nla_put_u8(skb, IFLA_IPTUN_TTL, parm->hop_limit) || 1747 1745 nla_put_u8(skb, IFLA_IPTUN_ENCAP_LIMIT, parm->encap_limit) || 1748 1746 nla_put_be32(skb, IFLA_IPTUN_FLOWINFO, parm->flowinfo) ||
+2 -4
net/ipv6/ip6_vti.c
··· 983 983 struct __ip6_tnl_parm *parm = &tunnel->parms; 984 984 985 985 if (nla_put_u32(skb, IFLA_VTI_LINK, parm->link) || 986 - nla_put(skb, IFLA_VTI_LOCAL, sizeof(struct in6_addr), 987 - &parm->laddr) || 988 - nla_put(skb, IFLA_VTI_REMOTE, sizeof(struct in6_addr), 989 - &parm->raddr) || 986 + nla_put_in6_addr(skb, IFLA_VTI_LOCAL, &parm->laddr) || 987 + nla_put_in6_addr(skb, IFLA_VTI_REMOTE, &parm->raddr) || 990 988 nla_put_be32(skb, IFLA_VTI_IKEY, parm->i_key) || 991 989 nla_put_be32(skb, IFLA_VTI_OKEY, parm->o_key)) 992 990 goto nla_put_failure;
+2 -2
net/ipv6/ip6mr.c
··· 2378 2378 rtm->rtm_protocol = RTPROT_MROUTED; 2379 2379 rtm->rtm_flags = 0; 2380 2380 2381 - if (nla_put(skb, RTA_SRC, 16, &c->mf6c_origin) || 2382 - nla_put(skb, RTA_DST, 16, &c->mf6c_mcastgrp)) 2381 + if (nla_put_in6_addr(skb, RTA_SRC, &c->mf6c_origin) || 2382 + nla_put_in6_addr(skb, RTA_DST, &c->mf6c_mcastgrp)) 2383 2383 goto nla_put_failure; 2384 2384 err = __ip6mr_fill_mroute(mrt, skb, c, rtm); 2385 2385 /* do not break the dump if cache is unresolved */
+1 -2
net/ipv6/ndisc.c
··· 1049 1049 1050 1050 memcpy(ndmsg + 1, opt, opt->nd_opt_len << 3); 1051 1051 1052 - if (nla_put(skb, NDUSEROPT_SRCADDR, sizeof(struct in6_addr), 1053 - &ipv6_hdr(ra)->saddr)) 1052 + if (nla_put_in6_addr(skb, NDUSEROPT_SRCADDR, &ipv6_hdr(ra)->saddr)) 1054 1053 goto nla_put_failure; 1055 1054 nlmsg_end(skb, nlh); 1056 1055
+2 -4
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
··· 290 290 static int ipv6_tuple_to_nlattr(struct sk_buff *skb, 291 291 const struct nf_conntrack_tuple *tuple) 292 292 { 293 - if (nla_put(skb, CTA_IP_V6_SRC, sizeof(u_int32_t) * 4, 294 - &tuple->src.u3.ip6) || 295 - nla_put(skb, CTA_IP_V6_DST, sizeof(u_int32_t) * 4, 296 - &tuple->dst.u3.ip6)) 293 + if (nla_put_in6_addr(skb, CTA_IP_V6_SRC, &tuple->src.u3.in6) || 294 + nla_put_in6_addr(skb, CTA_IP_V6_DST, &tuple->dst.u3.in6)) 297 295 goto nla_put_failure; 298 296 return 0; 299 297
+7 -7
net/ipv6/route.c
··· 2669 2669 rtm->rtm_flags |= RTM_F_CLONED; 2670 2670 2671 2671 if (dst) { 2672 - if (nla_put(skb, RTA_DST, 16, dst)) 2672 + if (nla_put_in6_addr(skb, RTA_DST, dst)) 2673 2673 goto nla_put_failure; 2674 2674 rtm->rtm_dst_len = 128; 2675 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 2677 goto nla_put_failure; 2678 2678 #ifdef CONFIG_IPV6_SUBTREES 2679 2679 if (src) { 2680 - if (nla_put(skb, RTA_SRC, 16, src)) 2680 + if (nla_put_in6_addr(skb, RTA_SRC, src)) 2681 2681 goto nla_put_failure; 2682 2682 rtm->rtm_src_len = 128; 2683 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 2685 goto nla_put_failure; 2686 2686 #endif 2687 2687 if (iif) { ··· 2705 2705 } else if (dst) { 2706 2706 struct in6_addr saddr_buf; 2707 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 2709 goto nla_put_failure; 2710 2710 } 2711 2711 2712 2712 if (rt->rt6i_prefsrc.plen) { 2713 2713 struct in6_addr saddr_buf; 2714 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 2716 goto nla_put_failure; 2717 2717 } 2718 2718 ··· 2720 2720 goto nla_put_failure; 2721 2721 2722 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 2724 goto nla_put_failure; 2725 2725 } 2726 2726
+6 -6
net/ipv6/sit.c
··· 1683 1683 struct ip_tunnel_parm *parm = &tunnel->parms; 1684 1684 1685 1685 if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || 1686 - nla_put_be32(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) || 1687 - nla_put_be32(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) || 1686 + nla_put_in_addr(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) || 1687 + nla_put_in_addr(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) || 1688 1688 nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) || 1689 1689 nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos) || 1690 1690 nla_put_u8(skb, IFLA_IPTUN_PMTUDISC, ··· 1694 1694 goto nla_put_failure; 1695 1695 1696 1696 #ifdef CONFIG_IPV6_SIT_6RD 1697 - if (nla_put(skb, IFLA_IPTUN_6RD_PREFIX, sizeof(struct in6_addr), 1698 - &tunnel->ip6rd.prefix) || 1699 - nla_put_be32(skb, IFLA_IPTUN_6RD_RELAY_PREFIX, 1700 - tunnel->ip6rd.relay_prefix) || 1697 + if (nla_put_in6_addr(skb, IFLA_IPTUN_6RD_PREFIX, 1698 + &tunnel->ip6rd.prefix) || 1699 + nla_put_in_addr(skb, IFLA_IPTUN_6RD_RELAY_PREFIX, 1700 + tunnel->ip6rd.relay_prefix) || 1701 1701 nla_put_u16(skb, IFLA_IPTUN_6RD_PREFIXLEN, 1702 1702 tunnel->ip6rd.prefixlen) || 1703 1703 nla_put_u16(skb, IFLA_IPTUN_6RD_RELAY_PREFIXLEN,
+8 -6
net/l2tp/l2tp_netlink.c
··· 376 376 case L2TP_ENCAPTYPE_IP: 377 377 #if IS_ENABLED(CONFIG_IPV6) 378 378 if (np) { 379 - if (nla_put(skb, L2TP_ATTR_IP6_SADDR, sizeof(np->saddr), 380 - &np->saddr) || 381 - nla_put(skb, L2TP_ATTR_IP6_DADDR, sizeof(sk->sk_v6_daddr), 382 - &sk->sk_v6_daddr)) 379 + if (nla_put_in6_addr(skb, L2TP_ATTR_IP6_SADDR, 380 + &np->saddr) || 381 + nla_put_in6_addr(skb, L2TP_ATTR_IP6_DADDR, 382 + &sk->sk_v6_daddr)) 383 383 goto nla_put_failure; 384 384 } else 385 385 #endif 386 - if (nla_put_be32(skb, L2TP_ATTR_IP_SADDR, inet->inet_saddr) || 387 - nla_put_be32(skb, L2TP_ATTR_IP_DADDR, inet->inet_daddr)) 386 + if (nla_put_in_addr(skb, L2TP_ATTR_IP_SADDR, 387 + inet->inet_saddr) || 388 + nla_put_in_addr(skb, L2TP_ATTR_IP_DADDR, 389 + inet->inet_daddr)) 388 390 goto nla_put_failure; 389 391 break; 390 392 }
+8 -12
net/netlabel/netlabel_mgmt.c
··· 293 293 return -ENOMEM; 294 294 295 295 addr_struct.s_addr = iter4->addr; 296 - ret_val = nla_put(skb, NLBL_MGMT_A_IPV4ADDR, 297 - sizeof(struct in_addr), 298 - &addr_struct); 296 + ret_val = nla_put_in_addr(skb, NLBL_MGMT_A_IPV4ADDR, 297 + addr_struct.s_addr); 299 298 if (ret_val != 0) 300 299 return ret_val; 301 300 addr_struct.s_addr = iter4->mask; 302 - ret_val = nla_put(skb, NLBL_MGMT_A_IPV4MASK, 303 - sizeof(struct in_addr), 304 - &addr_struct); 301 + ret_val = nla_put_in_addr(skb, NLBL_MGMT_A_IPV4MASK, 302 + addr_struct.s_addr); 305 303 if (ret_val != 0) 306 304 return ret_val; 307 305 map4 = netlbl_domhsh_addr4_entry(iter4); ··· 326 328 if (nla_b == NULL) 327 329 return -ENOMEM; 328 330 329 - ret_val = nla_put(skb, NLBL_MGMT_A_IPV6ADDR, 330 - sizeof(struct in6_addr), 331 - &iter6->addr); 331 + ret_val = nla_put_in6_addr(skb, NLBL_MGMT_A_IPV6ADDR, 332 + &iter6->addr); 332 333 if (ret_val != 0) 333 334 return ret_val; 334 - ret_val = nla_put(skb, NLBL_MGMT_A_IPV6MASK, 335 - sizeof(struct in6_addr), 336 - &iter6->mask); 335 + ret_val = nla_put_in6_addr(skb, NLBL_MGMT_A_IPV6MASK, 336 + &iter6->mask); 337 337 if (ret_val != 0) 338 338 return ret_val; 339 339 map6 = netlbl_domhsh_addr6_entry(iter6);
+12 -16
net/netlabel/netlabel_unlabeled.c
··· 1117 1117 struct in_addr addr_struct; 1118 1118 1119 1119 addr_struct.s_addr = addr4->list.addr; 1120 - ret_val = nla_put(cb_arg->skb, 1121 - NLBL_UNLABEL_A_IPV4ADDR, 1122 - sizeof(struct in_addr), 1123 - &addr_struct); 1120 + ret_val = nla_put_in_addr(cb_arg->skb, 1121 + NLBL_UNLABEL_A_IPV4ADDR, 1122 + addr_struct.s_addr); 1124 1123 if (ret_val != 0) 1125 1124 goto list_cb_failure; 1126 1125 1127 1126 addr_struct.s_addr = addr4->list.mask; 1128 - ret_val = nla_put(cb_arg->skb, 1129 - NLBL_UNLABEL_A_IPV4MASK, 1130 - sizeof(struct in_addr), 1131 - &addr_struct); 1127 + ret_val = nla_put_in_addr(cb_arg->skb, 1128 + NLBL_UNLABEL_A_IPV4MASK, 1129 + addr_struct.s_addr); 1132 1130 if (ret_val != 0) 1133 1131 goto list_cb_failure; 1134 1132 1135 1133 secid = addr4->secid; 1136 1134 } else { 1137 - ret_val = nla_put(cb_arg->skb, 1138 - NLBL_UNLABEL_A_IPV6ADDR, 1139 - sizeof(struct in6_addr), 1140 - &addr6->list.addr); 1135 + ret_val = nla_put_in6_addr(cb_arg->skb, 1136 + NLBL_UNLABEL_A_IPV6ADDR, 1137 + &addr6->list.addr); 1141 1138 if (ret_val != 0) 1142 1139 goto list_cb_failure; 1143 1140 1144 - ret_val = nla_put(cb_arg->skb, 1145 - NLBL_UNLABEL_A_IPV6MASK, 1146 - sizeof(struct in6_addr), 1147 - &addr6->list.mask); 1141 + ret_val = nla_put_in6_addr(cb_arg->skb, 1142 + NLBL_UNLABEL_A_IPV6MASK, 1143 + &addr6->list.mask); 1148 1144 if (ret_val != 0) 1149 1145 goto list_cb_failure; 1150 1146
+4 -2
net/openvswitch/flow_netlink.c
··· 648 648 nla_put_be64(skb, OVS_TUNNEL_KEY_ATTR_ID, output->tun_id)) 649 649 return -EMSGSIZE; 650 650 if (output->ipv4_src && 651 - nla_put_be32(skb, OVS_TUNNEL_KEY_ATTR_IPV4_SRC, output->ipv4_src)) 651 + nla_put_in_addr(skb, OVS_TUNNEL_KEY_ATTR_IPV4_SRC, 652 + output->ipv4_src)) 652 653 return -EMSGSIZE; 653 654 if (output->ipv4_dst && 654 - nla_put_be32(skb, OVS_TUNNEL_KEY_ATTR_IPV4_DST, output->ipv4_dst)) 655 + nla_put_in_addr(skb, OVS_TUNNEL_KEY_ATTR_IPV4_DST, 656 + output->ipv4_dst)) 655 657 return -EMSGSIZE; 656 658 if (output->ipv4_tos && 657 659 nla_put_u8(skb, OVS_TUNNEL_KEY_ATTR_TOS, output->ipv4_tos))
+2 -2
net/wireless/nl80211.c
··· 8761 8761 if (!nl_tcp) 8762 8762 return -ENOBUFS; 8763 8763 8764 - if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || 8765 - nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || 8764 + if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || 8765 + nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || 8766 8766 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || 8767 8767 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || 8768 8768 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||