path: root/kernel
diff options
authorJiri Benc <>2015-06-13 21:46:47 +0200
committerJozsef Kadlecsik <>2015-06-13 21:46:47 +0200
commit01a13aa4fe0cb668fc535d38d6f9383433923874 (patch)
treec173f64894115c330c0b2468835ff05a1158218a /kernel
parent5e1734cedd68725dbcda83626c25a15c812e4eb4 (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 <> Signed-off-by: David S. Miller <> Compatibility part added. Signed-off-by: Jozsef Kadlecsik <>
Diffstat (limited to 'kernel')
2 files changed, 17 insertions, 3 deletions
diff --git a/kernel/include/linux/netfilter/ipset/ip_set.h b/kernel/include/linux/netfilter/ipset/ip_set.h
index 30f8ba8..f54389b 100644
--- a/kernel/include/linux/netfilter/ipset/ip_set.h
+++ b/kernel/include/linux/netfilter/ipset/ip_set.h
@@ -396,7 +396,7 @@ static inline int nla_put_ipaddr4(struct sk_buff *skb, int type, __be32 ipaddr)
if (!__nested)
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)
ipset_nest_end(skb, __nested);
return ret;
@@ -410,8 +410,7 @@ static inline int nla_put_ipaddr6(struct sk_buff *skb, int type,
if (!__nested)
return -EMSGSIZE;
- ret = nla_put(skb, IPSET_ATTR_IPADDR_IPV6,
- sizeof(struct in6_addr), ipaddrptr);
+ ret = nla_put_in6_addr(skb, IPSET_ATTR_IPADDR_IPV6, ipaddrptr);
if (!ret)
ipset_nest_end(skb, __nested);
return ret;
diff --git a/kernel/include/linux/netfilter/ipset/ b/kernel/include/linux/netfilter/ipset/
index 02c2a37..8c0b346 100644
--- a/kernel/include/linux/netfilter/ipset/
+++ b/kernel/include/linux/netfilter/ipset/
@@ -44,6 +44,7 @@
/* Not everything could be moved here. Compatibility stuffs can be found in
* xt_set.c, ip_set_core.c, ip_set_getport.c, pfxlen.c too.
@@ -226,6 +227,20 @@ nf_bridge_get_physoutdev(const struct sk_buff *skb)
+static inline int nla_put_in_addr(struct sk_buff *skb, int attrtype,
+ __be32 addr)
+ return nla_put_be32(skb, attrtype, addr);
+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);
#ifndef smp_mb__before_atomic
#define smp_mb__before_atomic() smp_mb()
#define smp_mb__after_atomic() smp_mb()