]> git.ipfire.org Git - thirdparty/ipset.git/commitdiff
netlink: implement nla_put_in_addr and nla_put_in6_addr
authorJiri Benc <jbenc@redhat.com>
Sat, 13 Jun 2015 19:46:47 +0000 (21:46 +0200)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Sat, 13 Jun 2015 19:46:47 +0000 (21:46 +0200)
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>
Compatibility part added.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
configure.ac
kernel/include/linux/netfilter/ipset/ip_set.h
kernel/include/linux/netfilter/ipset/ip_set_compat.h.in

index c032bf609879c277c2f3acd42a4e0b263bf9f8a4..6b6ba1fb0ff4c8312797ff2f60cfdc762732cf57 100644 (file)
@@ -416,6 +416,16 @@ else
        AC_SUBST(HAVE_NF_BRIDGE_GET_PHYSDEV, undef)
 fi
 
+AC_MSG_CHECKING([kernel source for nla_put_in_addr])
+if test -f $ksourcedir/include/net/netlink.h && \
+   $GREP -q 'nla_put_in_add' $ksourcedir/include/net/netlink.h; then
+       AC_MSG_RESULT(yes)
+       AC_SUBST(HAVE_NLA_PUT_IN_ADDR, define)
+else
+       AC_MSG_RESULT(no)
+       AC_SUBST(HAVE_NLA_PUT_IN_ADDR, undef)
+fi
+
 AC_MSG_CHECKING([kernel source for struct net_generic])
 if test -f $ksourcedir/include/net/netns/generic.h && \
    $GREP -q 'struct net_generic' $ksourcedir/include/net/netns/generic.h; then
index 30f8ba8e918833ef944c181e26591071dcab3616..f54389b85fd1218b8b44d8f83dafe06ba14b8e1b 100644 (file)
@@ -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;
index 02c2a37188b4be82bbeff701494344b4ddf57407..8c0b34672e7fe6d3ac943389d2d0e6bb0ca8c4da 100644 (file)
@@ -44,6 +44,7 @@
 #@HAVE_LIST_NEXT_ENTRY@ HAVE_LIST_NEXT_ENTRY
 #@HAVE_ETHER_ADDR_COPY@ HAVE_ETHER_ADDR_COPY
 #@HAVE_NF_BRIDGE_GET_PHYSDEV@ HAVE_NF_BRIDGE_GET_PHYSDEV
+#@HAVE_NLA_PUT_IN_ADDR@ HAVE_NLA_PUT_IN_ADDR
 
 /* 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)
 #endif
 #endif
 
+#ifndef HAVE_NLA_PUT_IN_ADDR
+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);
+}
+#endif
+
 #ifndef smp_mb__before_atomic
 #define smp_mb__before_atomic()        smp_mb()
 #define smp_mb__after_atomic() smp_mb()