History

netfilter: inline four headers files into another one.

linux/netfilter/ipset/ip_set.h included four other header files: include/linux/netfilter/ipset/ip_set_comment.h include/linux/netfilter/ipset/ip_set_counter.h include/linux/netfilter/ipset/ip_set_skbinfo.h include/linux/netfilter/ipset/ip_set_timeout.h Of these the first three were not included anywhere else. The last, ip_set_timeout.h, was included in a couple of other places, but defined inline functions which call other inline functions defined in ip_set.h, so ip_set.h had to be included before it. Inlined all four into ip_set.h, and updated the other files that included ip_set_timeout.h.

Jeremy Sowden committed 7 years ago

Commit bd96b4c1 parent 43dd16e7 files · +235 −282Browse files

Unified · Split

7 files
  1. include/linux/netfilter/ipset/ip_set.h +234 −4
  2. include/linux/netfilter/ipset/ip_set_comment.h +0 −73
  3. include/linux/netfilter/ipset/ip_set_counter.h +0 −84
  4. include/linux/netfilter/ipset/ip_set_skbinfo.h +0 −42
  5. include/linux/netfilter/ipset/ip_set_timeout.h +0 −77
  6. net/netfilter/ipset/ip_set_hash_gen.h +1 −1
  7. net/netfilter/xt_set.c +0 −1
include/linux/netfilter/ipset/ip_set.h+234−4
@@ -452,10 +452,240 @@ bitmap_bytes(u32 a, u32 b) · 451 unmodified lines
452452 return 4 * ((((b - a + 8) / 8) + 3) / 4);
453453 }
454454
455−#include <linux/netfilter/ipset/ip_set_timeout.h>
456−#include <linux/netfilter/ipset/ip_set_comment.h>
457−#include <linux/netfilter/ipset/ip_set_counter.h>
458−#include <linux/netfilter/ipset/ip_set_skbinfo.h>
455+/* How often should the gc be run by default */
456+#define IPSET_GC_TIME (3 * 60)
457+
458+/* Timeout period depending on the timeout value of the given set */
459+#define IPSET_GC_PERIOD(timeout) \
460+ ((timeout/3) ? min_t(u32, (timeout)/3, IPSET_GC_TIME) : 1)
461+
462+/* Entry is set with no timeout value */
463+#define IPSET_ELEM_PERMANENT 0
464+
465+/* Set is defined with timeout support: timeout value may be 0 */
466+#define IPSET_NO_TIMEOUT UINT_MAX
467+
468+/* Max timeout value, see msecs_to_jiffies() in jiffies.h */
469+#define IPSET_MAX_TIMEOUT (UINT_MAX >> 1)/MSEC_PER_SEC
470+
471+#define ip_set_adt_opt_timeout(opt, set) \
472+((opt)->ext.timeout != IPSET_NO_TIMEOUT ? (opt)->ext.timeout : (set)->timeout)
473+
474+static inline unsigned int
475+ip_set_timeout_uget(struct nlattr *tb)
476+{
477+ unsigned int timeout = ip_set_get_h32(tb);
478+
479+ /* Normalize to fit into jiffies */
480+ if (timeout > IPSET_MAX_TIMEOUT)
481+ timeout = IPSET_MAX_TIMEOUT;
482+
483+ return timeout;
484+}
485+
486+static inline bool
487+ip_set_timeout_expired(const unsigned long *t)
488+{
489+ return *t != IPSET_ELEM_PERMANENT && time_is_before_jiffies(*t);
490+}
491+
492+static inline void
493+ip_set_timeout_set(unsigned long *timeout, u32 value)
494+{
495+ unsigned long t;
496+
497+ if (!value) {
498+ *timeout = IPSET_ELEM_PERMANENT;
499+ return;
500+ }
501+
502+ t = msecs_to_jiffies(value * MSEC_PER_SEC) + jiffies;
503+ if (t == IPSET_ELEM_PERMANENT)
504+ /* Bingo! :-) */
505+ t--;
506+ *timeout = t;
507+}
508+
509+static inline u32
510+ip_set_timeout_get(const unsigned long *timeout)
511+{
512+ u32 t;
513+
514+ if (*timeout == IPSET_ELEM_PERMANENT)
515+ return 0;
516+
517+ t = jiffies_to_msecs(*timeout - jiffies)/MSEC_PER_SEC;
518+ /* Zero value in userspace means no timeout */
519+ return t == 0 ? 1 : t;
520+}
521+
522+static inline char*
523+ip_set_comment_uget(struct nlattr *tb)
524+{
525+ return nla_data(tb);
526+}
527+
528+/* Called from uadd only, protected by the set spinlock.
529+ * The kadt functions don't use the comment extensions in any way.
530+ */
531+static inline void
532+ip_set_init_comment(struct ip_set *set, struct ip_set_comment *comment,
533+ const struct ip_set_ext *ext)
534+{
535+ struct ip_set_comment_rcu *c = rcu_dereference_protected(comment->c, 1);
536+ size_t len = ext->comment ? strlen(ext->comment) : 0;
537+
538+ if (unlikely(c)) {
539+ set->ext_size -= sizeof(*c) + strlen(c->str) + 1;
540+ kfree_rcu(c, rcu);
541+ rcu_assign_pointer(comment->c, NULL);
542+ }
543+ if (!len)
544+ return;
545+ if (unlikely(len > IPSET_MAX_COMMENT_SIZE))
546+ len = IPSET_MAX_COMMENT_SIZE;
547+ c = kmalloc(sizeof(*c) + len + 1, GFP_ATOMIC);
548+ if (unlikely(!c))
549+ return;
550+ strlcpy(c->str, ext->comment, len + 1);
551+ set->ext_size += sizeof(*c) + strlen(c->str) + 1;
552+ rcu_assign_pointer(comment->c, c);
553+}
554+
555+/* Used only when dumping a set, protected by rcu_read_lock() */
556+static inline int
557+ip_set_put_comment(struct sk_buff *skb, const struct ip_set_comment *comment)
558+{
559+ struct ip_set_comment_rcu *c = rcu_dereference(comment->c);
560+
561+ if (!c)
562+ return 0;
563+ return nla_put_string(skb, IPSET_ATTR_COMMENT, c->str);
564+}
565+
566+/* Called from uadd/udel, flush or the garbage collectors protected
567+ * by the set spinlock.
568+ * Called when the set is destroyed and when there can't be any user
569+ * of the set data anymore.
570+ */
571+static inline void
572+ip_set_comment_free(struct ip_set *set, struct ip_set_comment *comment)
573+{
574+ struct ip_set_comment_rcu *c;
575+
576+ c = rcu_dereference_protected(comment->c, 1);
577+ if (unlikely(!c))
578+ return;
579+ set->ext_size -= sizeof(*c) + strlen(c->str) + 1;
580+ kfree_rcu(c, rcu);
581+ rcu_assign_pointer(comment->c, NULL);
582+}
583+
584+static inline void
585+ip_set_add_bytes(u64 bytes, struct ip_set_counter *counter)
586+{
587+ atomic64_add((long long)bytes, &(counter)->bytes);
588+}
589+
590+static inline void
591+ip_set_add_packets(u64 packets, struct ip_set_counter *counter)
592+{
593+ atomic64_add((long long)packets, &(counter)->packets);
594+}
595+
596+static inline u64
597+ip_set_get_bytes(const struct ip_set_counter *counter)
598+{
599+ return (u64)atomic64_read(&(counter)->bytes);
600+}
601+
602+static inline u64
603+ip_set_get_packets(const struct ip_set_counter *counter)
604+{
605+ return (u64)atomic64_read(&(counter)->packets);
606+}
607+
608+static inline bool
609+ip_set_match_counter(u64 counter, u64 match, u8 op)
610+{
611+ switch (op) {
612+ case IPSET_COUNTER_NONE:
613+ return true;
614+ case IPSET_COUNTER_EQ:
615+ return counter == match;
616+ case IPSET_COUNTER_NE:
617+ return counter != match;
618+ case IPSET_COUNTER_LT:
619+ return counter < match;
620+ case IPSET_COUNTER_GT:
621+ return counter > match;
622+ }
623+ return false;
624+}
625+
626+static inline void
627+ip_set_update_counter(struct ip_set_counter *counter,
628+ const struct ip_set_ext *ext, u32 flags)
629+{
630+ if (ext->packets != ULLONG_MAX &&
631+ !(flags & IPSET_FLAG_SKIP_COUNTER_UPDATE)) {
632+ ip_set_add_bytes(ext->bytes, counter);
633+ ip_set_add_packets(ext->packets, counter);
634+ }
635+}
636+
637+static inline bool
638+ip_set_put_counter(struct sk_buff *skb, const struct ip_set_counter *counter)
639+{
640+ return nla_put_net64(skb, IPSET_ATTR_BYTES,
641+ cpu_to_be64(ip_set_get_bytes(counter)),
642+ IPSET_ATTR_PAD) ||
643+ nla_put_net64(skb, IPSET_ATTR_PACKETS,
644+ cpu_to_be64(ip_set_get_packets(counter)),
645+ IPSET_ATTR_PAD);
646+}
647+
648+static inline void
649+ip_set_init_counter(struct ip_set_counter *counter,
650+ const struct ip_set_ext *ext)
651+{
652+ if (ext->bytes != ULLONG_MAX)
653+ atomic64_set(&(counter)->bytes, (long long)(ext->bytes));
654+ if (ext->packets != ULLONG_MAX)
655+ atomic64_set(&(counter)->packets, (long long)(ext->packets));
656+}
657+
658+static inline void
659+ip_set_get_skbinfo(struct ip_set_skbinfo *skbinfo,
660+ const struct ip_set_ext *ext,
661+ struct ip_set_ext *mext, u32 flags)
662+{
663+ mext->skbinfo = *skbinfo;
664+}
665+
666+static inline bool
667+ip_set_put_skbinfo(struct sk_buff *skb, const struct ip_set_skbinfo *skbinfo)
668+{
669+ /* Send nonzero parameters only */
670+ return ((skbinfo->skbmark || skbinfo->skbmarkmask) &&
671+ nla_put_net64(skb, IPSET_ATTR_SKBMARK,
672+ cpu_to_be64((u64)skbinfo->skbmark << 32 |
673+ skbinfo->skbmarkmask),
674+ IPSET_ATTR_PAD)) ||
675+ (skbinfo->skbprio &&
676+ nla_put_net32(skb, IPSET_ATTR_SKBPRIO,
677+ cpu_to_be32(skbinfo->skbprio))) ||
678+ (skbinfo->skbqueue &&
679+ nla_put_net16(skb, IPSET_ATTR_SKBQUEUE,
680+ cpu_to_be16(skbinfo->skbqueue)));
681+}
682+
683+static inline void
684+ip_set_init_skbinfo(struct ip_set_skbinfo *skbinfo,
685+ const struct ip_set_ext *ext)
686+{
687+ *skbinfo = ext->skbinfo;
688+}
459689
460690 #define IP_SET_INIT_KEXT(skb, opt, set) \
461691 { .bytes = (skb)->len, .packets = 1, \
include/linux/netfilter/ipset/ip_set_comment.h+0−73
@@ -1,73 +0,0 @@
1−/* SPDX-License-Identifier: GPL-2.0-only */
2−#ifndef _IP_SET_COMMENT_H
3−#define _IP_SET_COMMENT_H
4−
5−/* Copyright (C) 2013 Oliver Smith <oliver@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa>
6− */
7−
8−#ifdef __KERNEL__
9−
10−static inline char*
11−ip_set_comment_uget(struct nlattr *tb)
12−{
13− return nla_data(tb);
14−}
15−
16−/* Called from uadd only, protected by the set spinlock.
17− * The kadt functions don't use the comment extensions in any way.
18− */
19−static inline void
20−ip_set_init_comment(struct ip_set *set, struct ip_set_comment *comment,
21− const struct ip_set_ext *ext)
22−{
23− struct ip_set_comment_rcu *c = rcu_dereference_protected(comment->c, 1);
24− size_t len = ext->comment ? strlen(ext->comment) : 0;
25−
26− if (unlikely(c)) {
27− set->ext_size -= sizeof(*c) + strlen(c->str) + 1;
28− kfree_rcu(c, rcu);
29− rcu_assign_pointer(comment->c, NULL);
30− }
31− if (!len)
32− return;
33− if (unlikely(len > IPSET_MAX_COMMENT_SIZE))
34− len = IPSET_MAX_COMMENT_SIZE;
35− c = kmalloc(sizeof(*c) + len + 1, GFP_ATOMIC);
36− if (unlikely(!c))
37− return;
38− strlcpy(c->str, ext->comment, len + 1);
39− set->ext_size += sizeof(*c) + strlen(c->str) + 1;
40− rcu_assign_pointer(comment->c, c);
41−}
42−
43−/* Used only when dumping a set, protected by rcu_read_lock() */
44−static inline int
45−ip_set_put_comment(struct sk_buff *skb, const struct ip_set_comment *comment)
46−{
47− struct ip_set_comment_rcu *c = rcu_dereference(comment->c);
48−
49− if (!c)
50− return 0;
51− return nla_put_string(skb, IPSET_ATTR_COMMENT, c->str);
52−}
53−
54−/* Called from uadd/udel, flush or the garbage collectors protected
55− * by the set spinlock.
56− * Called when the set is destroyed and when there can't be any user
57− * of the set data anymore.
58− */
59−static inline void
60−ip_set_comment_free(struct ip_set *set, struct ip_set_comment *comment)
61−{
62− struct ip_set_comment_rcu *c;
63−
64− c = rcu_dereference_protected(comment->c, 1);
65− if (unlikely(!c))
66− return;
67− set->ext_size -= sizeof(*c) + strlen(c->str) + 1;
68− kfree_rcu(c, rcu);
69− rcu_assign_pointer(comment->c, NULL);
70−}
71−
72−#endif
73−#endif
include/linux/netfilter/ipset/ip_set_counter.h+0−84
@@ -1,84 +0,0 @@
1−/* SPDX-License-Identifier: GPL-2.0-only */
2−#ifndef _IP_SET_COUNTER_H
3−#define _IP_SET_COUNTER_H
4−
5−/* Copyright (C) 2015 Jozsef Kadlecsik <kadlec@netfilter.org> */
6−
7−#ifdef __KERNEL__
8−
9−static inline void
10−ip_set_add_bytes(u64 bytes, struct ip_set_counter *counter)
11−{
12− atomic64_add((long long)bytes, &(counter)->bytes);
13−}
14−
15−static inline void
16−ip_set_add_packets(u64 packets, struct ip_set_counter *counter)
17−{
18− atomic64_add((long long)packets, &(counter)->packets);
19−}
20−
21−static inline u64
22−ip_set_get_bytes(const struct ip_set_counter *counter)
23−{
24− return (u64)atomic64_read(&(counter)->bytes);
25−}
26−
27−static inline u64
28−ip_set_get_packets(const struct ip_set_counter *counter)
29−{
30− return (u64)atomic64_read(&(counter)->packets);
31−}
32−
33−static inline bool
34−ip_set_match_counter(u64 counter, u64 match, u8 op)
35−{
36− switch (op) {
37− case IPSET_COUNTER_NONE:
38− return true;
39− case IPSET_COUNTER_EQ:
40− return counter == match;
41− case IPSET_COUNTER_NE:
42− return counter != match;
43− case IPSET_COUNTER_LT:
44− return counter < match;
45− case IPSET_COUNTER_GT:
46− return counter > match;
47− }
48− return false;
49−}
50−
51−static inline void
52−ip_set_update_counter(struct ip_set_counter *counter,
53− const struct ip_set_ext *ext, u32 flags)
54−{
55− if (ext->packets != ULLONG_MAX &&
56− !(flags & IPSET_FLAG_SKIP_COUNTER_UPDATE)) {
57− ip_set_add_bytes(ext->bytes, counter);
58− ip_set_add_packets(ext->packets, counter);
59− }
60−}
61−
62−static inline bool
63−ip_set_put_counter(struct sk_buff *skb, const struct ip_set_counter *counter)
64−{
65− return nla_put_net64(skb, IPSET_ATTR_BYTES,
66− cpu_to_be64(ip_set_get_bytes(counter)),
67− IPSET_ATTR_PAD) ||
68− nla_put_net64(skb, IPSET_ATTR_PACKETS,
69− cpu_to_be64(ip_set_get_packets(counter)),
70− IPSET_ATTR_PAD);
71−}
72−
73−static inline void
74−ip_set_init_counter(struct ip_set_counter *counter,
75− const struct ip_set_ext *ext)
76−{
77− if (ext->bytes != ULLONG_MAX)
78− atomic64_set(&(counter)->bytes, (long long)(ext->bytes));
79− if (ext->packets != ULLONG_MAX)
80− atomic64_set(&(counter)->packets, (long long)(ext->packets));
81−}
82−
83−#endif /* __KERNEL__ */
84−#endif /* _IP_SET_COUNTER_H */
include/linux/netfilter/ipset/ip_set_skbinfo.h+0−42
@@ -1,42 +0,0 @@
1−/* SPDX-License-Identifier: GPL-2.0-only */
2−#ifndef _IP_SET_SKBINFO_H
3−#define _IP_SET_SKBINFO_H
4−
5−/* Copyright (C) 2015 Jozsef Kadlecsik <kadlec@netfilter.org> */
6−
7−#ifdef __KERNEL__
8−
9−static inline void
10−ip_set_get_skbinfo(struct ip_set_skbinfo *skbinfo,
11− const struct ip_set_ext *ext,
12− struct ip_set_ext *mext, u32 flags)
13−{
14− mext->skbinfo = *skbinfo;
15−}
16−
17−static inline bool
18−ip_set_put_skbinfo(struct sk_buff *skb, const struct ip_set_skbinfo *skbinfo)
19−{
20− /* Send nonzero parameters only */
21− return ((skbinfo->skbmark || skbinfo->skbmarkmask) &&
22− nla_put_net64(skb, IPSET_ATTR_SKBMARK,
23− cpu_to_be64((u64)skbinfo->skbmark << 32 |
24− skbinfo->skbmarkmask),
25− IPSET_ATTR_PAD)) ||
26− (skbinfo->skbprio &&
27− nla_put_net32(skb, IPSET_ATTR_SKBPRIO,
28− cpu_to_be32(skbinfo->skbprio))) ||
29− (skbinfo->skbqueue &&
30− nla_put_net16(skb, IPSET_ATTR_SKBQUEUE,
31− cpu_to_be16(skbinfo->skbqueue)));
32−}
33−
34−static inline void
35−ip_set_init_skbinfo(struct ip_set_skbinfo *skbinfo,
36− const struct ip_set_ext *ext)
37−{
38− *skbinfo = ext->skbinfo;
39−}
40−
41−#endif /* __KERNEL__ */
42−#endif /* _IP_SET_SKBINFO_H */
include/linux/netfilter/ipset/ip_set_timeout.h+0−77
@@ -1,77 +0,0 @@
1−/* SPDX-License-Identifier: GPL-2.0-only */
2−#ifndef _IP_SET_TIMEOUT_H
3−#define _IP_SET_TIMEOUT_H
4−
5−/* Copyright (C) 2003-2013 Jozsef Kadlecsik <kadlec@netfilter.org> */
6−
7−#ifdef __KERNEL__
8−
9−/* How often should the gc be run by default */
10−#define IPSET_GC_TIME (3 * 60)
11−
12−/* Timeout period depending on the timeout value of the given set */
13−#define IPSET_GC_PERIOD(timeout) \
14− ((timeout/3) ? min_t(u32, (timeout)/3, IPSET_GC_TIME) : 1)
15−
16−/* Entry is set with no timeout value */
17−#define IPSET_ELEM_PERMANENT 0
18−
19−/* Set is defined with timeout support: timeout value may be 0 */
20−#define IPSET_NO_TIMEOUT UINT_MAX
21−
22−/* Max timeout value, see msecs_to_jiffies() in jiffies.h */
23−#define IPSET_MAX_TIMEOUT (UINT_MAX >> 1)/MSEC_PER_SEC
24−
25−#define ip_set_adt_opt_timeout(opt, set) \
26−((opt)->ext.timeout != IPSET_NO_TIMEOUT ? (opt)->ext.timeout : (set)->timeout)
27−
28−static inline unsigned int
29−ip_set_timeout_uget(struct nlattr *tb)
30−{
31− unsigned int timeout = ip_set_get_h32(tb);
32−
33− /* Normalize to fit into jiffies */
34− if (timeout > IPSET_MAX_TIMEOUT)
35− timeout = IPSET_MAX_TIMEOUT;
36−
37− return timeout;
38−}
39−
40−static inline bool
41−ip_set_timeout_expired(const unsigned long *t)
42−{
43− return *t != IPSET_ELEM_PERMANENT && time_is_before_jiffies(*t);
44−}
45−
46−static inline void
47−ip_set_timeout_set(unsigned long *timeout, u32 value)
48−{
49− unsigned long t;
50−
51− if (!value) {
52− *timeout = IPSET_ELEM_PERMANENT;
53− return;
54− }
55−
56− t = msecs_to_jiffies(value * MSEC_PER_SEC) + jiffies;
57− if (t == IPSET_ELEM_PERMANENT)
58− /* Bingo! :-) */
59− t--;
60− *timeout = t;
61−}
62−
63−static inline u32
64−ip_set_timeout_get(const unsigned long *timeout)
65−{
66− u32 t;
67−
68− if (*timeout == IPSET_ELEM_PERMANENT)
69− return 0;
70−
71− t = jiffies_to_msecs(*timeout - jiffies)/MSEC_PER_SEC;
72− /* Zero value in userspace means no timeout */
73− return t == 0 ? 1 : t;
74−}
75−
76−#endif /* __KERNEL__ */
77−#endif /* _IP_SET_TIMEOUT_H */
net/netfilter/ipset/ip_set_hash_gen.h+1−1
@@ -7,7 +7,7 @@ · 6 unmodified lines
77 #include <linux/rcupdate.h>
88 #include <linux/jhash.h>
99 #include <linux/types.h>
10−#include <linux/netfilter/ipset/ip_set_timeout.h>
10+#include <linux/netfilter/ipset/ip_set.h>
1111
1212 #define __ipset_dereference_protected(p, c) rcu_dereference_protected(p, c)
1313 #define ipset_dereference_protected(p, set) \
net/netfilter/xt_set.c+0−1
@@ -14,7 +14,6 @@ · 13 unmodified lines
1414
1515 #include <linux/netfilter/x_tables.h>
1616 #include <linux/netfilter/ipset/ip_set.h>
17−#include <linux/netfilter/ipset/ip_set_timeout.h>
1817 #include <uapi/linux/netfilter/xt_set.h>
1918
2019 MODULE_LICENSE("GPL");