]> git.ipfire.org Git - thirdparty/ipset.git/commitdiff
netfilter: ipset: Improve skbinfo get/init helpers
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Tue, 5 May 2015 15:13:28 +0000 (17:13 +0200)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Tue, 5 May 2015 15:13:28 +0000 (17:13 +0200)
Use struct ip_set_skbinfo in struct ip_set_ext instead of open
coded fields and assign structure members in get/init helpers
instead of copying members one by one.

Ported from a patch proposed by Sergey Popovich <popovich_sergei@mail.ua>.

Suggested-by: Sergey Popovich <popovich_sergei@mail.ua>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
kernel/include/linux/netfilter/ipset/ip_set.h
kernel/net/netfilter/ipset/ip_set_core.c
kernel/net/netfilter/xt_set.c

index 4bb08e1bc7d1ad7ff0cac4e26d8fa8f9a11644fe..a70712cae7c485baf36c657258de4defd1bd446c 100644 (file)
@@ -93,17 +93,6 @@ struct ip_set_ext_type {
 
 extern const struct ip_set_ext_type ip_set_extensions[];
 
-struct ip_set_ext {
-       u64 packets;
-       u64 bytes;
-       u32 timeout;
-       u32 skbmark;
-       u32 skbmarkmask;
-       u32 skbprio;
-       u16 skbqueue;
-       char *comment;
-};
-
 struct ip_set_counter {
        atomic64_t bytes;
        atomic64_t packets;
@@ -123,6 +112,15 @@ struct ip_set_skbinfo {
        u32 skbmarkmask;
        u32 skbprio;
        u16 skbqueue;
+       u16 __pad;
+};
+
+struct ip_set_ext {
+       struct ip_set_skbinfo skbinfo;
+       u64 packets;
+       u64 bytes;
+       char *comment;
+       u32 timeout;
 };
 
 struct ip_set;
@@ -355,10 +353,7 @@ ip_set_get_skbinfo(struct ip_set_skbinfo *skbinfo,
                   const struct ip_set_ext *ext,
                   struct ip_set_ext *mext, u32 flags)
 {
-       mext->skbmark = skbinfo->skbmark;
-       mext->skbmarkmask = skbinfo->skbmarkmask;
-       mext->skbprio = skbinfo->skbprio;
-       mext->skbqueue = skbinfo->skbqueue;
+       mext->skbinfo = *skbinfo;
 }
 
 static inline bool
@@ -381,10 +376,7 @@ static inline void
 ip_set_init_skbinfo(struct ip_set_skbinfo *skbinfo,
                    const struct ip_set_ext *ext)
 {
-       skbinfo->skbmark = ext->skbmark;
-       skbinfo->skbmarkmask = ext->skbmarkmask;
-       skbinfo->skbprio = ext->skbprio;
-       skbinfo->skbqueue = ext->skbqueue;
+       *skbinfo = ext->skbinfo;
 }
 
 /* Netlink CB args */
index 63ef89f132f3dc7f0ad188404eb9f34ed2c6642e..bdb86a706964648e7eec98419ae9f61489b1e09b 100644 (file)
@@ -429,20 +429,20 @@ ip_set_get_extensions(struct ip_set *set, struct nlattr *tb[],
                if (!SET_WITH_SKBINFO(set))
                        return -IPSET_ERR_SKBINFO;
                fullmark = be64_to_cpu(nla_get_be64(tb[IPSET_ATTR_SKBMARK]));
-               ext->skbmark = fullmark >> 32;
-               ext->skbmarkmask = fullmark & 0xffffffff;
+               ext->skbinfo.skbmark = fullmark >> 32;
+               ext->skbinfo.skbmarkmask = fullmark & 0xffffffff;
        }
        if (tb[IPSET_ATTR_SKBPRIO]) {
                if (!SET_WITH_SKBINFO(set))
                        return -IPSET_ERR_SKBINFO;
-               ext->skbprio = be32_to_cpu(nla_get_be32(
-                                           tb[IPSET_ATTR_SKBPRIO]));
+               ext->skbinfo.skbprio =
+                       be32_to_cpu(nla_get_be32(tb[IPSET_ATTR_SKBPRIO]));
        }
        if (tb[IPSET_ATTR_SKBQUEUE]) {
                if (!SET_WITH_SKBINFO(set))
                        return -IPSET_ERR_SKBINFO;
-               ext->skbqueue = be16_to_cpu(nla_get_be16(
-                                           tb[IPSET_ATTR_SKBQUEUE]));
+               ext->skbinfo.skbqueue =
+                       be16_to_cpu(nla_get_be16(tb[IPSET_ATTR_SKBQUEUE]));
        }
        return 0;
 }
index f0596b3acf5563818ab8a1a1014d1eb489a6b0e3..10196cee664ed131b23b69c9838eca7de77cf537 100644 (file)
@@ -460,6 +460,8 @@ set_target_v2(struct sk_buff *skb, const struct xt_action_param *par)
 
 /* Revision 3 target */
 
+#define MOPT(opt, member)      ((opt).ext.skbinfo.member)
+
 static unsigned int
 set_target_v3(struct sk_buff *skb, const struct xt_action_param *par)
 {
@@ -494,14 +496,14 @@ set_target_v3(struct sk_buff *skb, const struct xt_action_param *par)
                if (!ret)
                        return XT_CONTINUE;
                if (map_opt.cmdflags & IPSET_FLAG_MAP_SKBMARK)
-                       skb->mark = (skb->mark & ~(map_opt.ext.skbmarkmask))
-                                   ^ (map_opt.ext.skbmark);
+                       skb->mark = (skb->mark & ~MOPT(map_opt,skbmarkmask))
+                                   ^ MOPT(map_opt, skbmark);
                if (map_opt.cmdflags & IPSET_FLAG_MAP_SKBPRIO)
-                       skb->priority = map_opt.ext.skbprio;
+                       skb->priority = MOPT(map_opt, skbprio);
                if ((map_opt.cmdflags & IPSET_FLAG_MAP_SKBQUEUE) &&
                    skb->dev &&
-                   skb->dev->real_num_tx_queues > map_opt.ext.skbqueue)
-                       skb_set_queue_mapping(skb, map_opt.ext.skbqueue);
+                   skb->dev->real_num_tx_queues > MOPT(map_opt, skbqueue))
+                       skb_set_queue_mapping(skb, MOPT(map_opt, skbqueue));
        }
        return XT_CONTINUE;
 }